Difference between revisions of "IC Python API:RLPy RINode"

From Reallusion Wiki!
Jump to: navigation, search
m
Line 1: Line 1:
 
{{TOC}}
 
{{TOC}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
== Detailed Description ==
+
{{last_modified}}
This class is the base class of the objects in the scene.
+
 
 +
== Description ==
 +
 
 +
This class is used to access node parameters in a character skeleton or scene object.  Retrievable parameters include name, ID, parent node, list of child nodes, and more. [[#Update ( self )|Update]] to get the world-transform of the bone node for the current point in time.
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 +
# Get root bone
 
avatar_list = RLPy.RScene.GetAvatars()
 
avatar_list = RLPy.RScene.GetAvatars()
 
avatar = avatar_list[0]
 
avatar = avatar_list[0]
 +
skeleton_component = avatar.GetSkeletonComponent()
 +
root_bone = skeleton_component.GetRootBone()
  
# basic information
+
# Get root bone node name
print(avatar.GetName())
+
node_name = root_bone.GetName()
print(avatar.GetID())
+
print(node_name)
print(avatar.GetType()) # RLPy.EObjectType_Avatar
+
  
# get control
+
# Get root bone node ID
transform_control = avatar.GetControl("Transform") # type RTransformControl
+
node_id = root_bone.GetID()
avatar_path_position_control = avatar.GetControl("PathPosition") # type RFloatControl
+
print(node_id)
avatar_path_offset_control = avatar.GetControl("PathOffset") # type RTransformControl
+
 
 +
# Get root bone parent node
 +
parent_node = root_bone.GetParent()
 +
print(parent_node)
 +
 
 +
# Get root bone children node list
 +
children_node_list = root_bone.GetChildren()
 +
print(children_node_list)
 +
 
 +
# Get root bone local transform
 +
local_transform = root_bone.LocalTransform()
 +
print(local_transform)
 +
 
 +
# Get root bone world transform
 +
world_transform = root_bone.WorldTransform()
 +
print(world_transform)
 +
 
 +
# Transfer root bone world transform matrix to local transform matrix
 +
world_transform = root_bone.WorldTransform()
 +
world_matrix = world_transform.Matrix() 
 +
world_to_local = bone.WorldToLocal(world_matrix)
 +
print(world_to_local)
 +
 
 +
# Transfer root bone local transform matrix to world transform matrix
 +
local_transform = root_bone.LocalTransform()
 +
local_matrix = local_transform.Matrix()   
 +
local_to_world = bone.LocalToWorld(local_matrix)
 +
print(local_to_world)
 
</syntaxhighlight>
 
</syntaxhighlight>
==Member Functions==
+
 
===GetControl===
+
== Member Functions ==
 +
 
 +
=== GetName ( self ) ===
 +
 
 +
Get the name of the node in a character skeleton or scene object.
 +
 
 +
==== Returns ====
 +
:Name of the node - str
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RIObject.GetControl ( self, strKey )
+
# Get root bone
 +
avatar_list = RLPy.RScene.GetAvatars()
 +
avatar = avatar_list[0]
 +
skeleton_component = avatar.GetSkeletonComponent()
 +
root_bone = skeleton_component.GetRootBone()
 +
 
 +
# Get root bone node name
 +
node_name = root_bone.GetName()
 +
print(node_name)
 
</syntaxhighlight>
 
</syntaxhighlight>
Get control of the object.
+
 
====Parameters====
+
=== GetID ( self ) ===
<div style="margin-left: 2em;">
+
 
'''strKey''' [IN] Key of the
+
Get the ID of the node in a character skeleton or scene object.
controller, allowing use "Transform" to retrieve the transform control
+
 
of the Transform track, use "PathPosition" to retrieve the float control
+
==== Returns ====
of Path position track, and use "PathOffset" to retrieve the transform
+
:ID of the node - int
control of the Path Offset track, - string
+
 
</div>
+
====Returns====
+
<div style="margin-left: 2em;">
+
The specified control - RLPy.RControl
+
</div>
+
-----
+
===GetID===
+
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RIObject.GetID ( self )
+
# Get root bone
 +
avatar_list = RLPy.RScene.GetAvatars()
 +
avatar = avatar_list[0]
 +
skeleton_component = avatar.GetSkeletonComponent()
 +
root_bone = skeleton_component.GetRootBone()
 +
 
 +
# Get root bone node ID
 +
node_id = root_bone.GetID()
 +
print(node_id)
 
</syntaxhighlight>
 
</syntaxhighlight>
Get unique id of the object.
+
 
====Returns====
+
=== GetParent ( self ) ===
<div style="margin-left: 2em;">
+
 
Object id - int
+
Get the parent node of the bone node in a character skeleton or scene object. If a parent does not exist, then return '''None'''.
</div>
+
 
-----
+
==== Returns ====
===GetMeshNames===
+
:Parent node - [[IC_Python_API:RLPy_RINode|RINode]]
 +
:No parent node - None
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RIObject.GetMeshNames ( self )
+
# Get root bone
 +
avatar_list = RLPy.RScene.GetAvatars()
 +
avatar = avatar_list[0]
 +
skeleton_component = avatar.GetSkeletonComponent()
 +
root_bone = skeleton_component.GetRootBone()
 +
 
 +
# Get root bone parent node
 +
parent_node = root_bone.GetParent()
 +
print(parent_node)
 
</syntaxhighlight>
 
</syntaxhighlight>
Get all mesh names of the object.
+
 
====Returns====
+
=== GetChildren ( self ) ===
<div style="margin-left: 2em;">
+
 
Mesh name list - string
+
Get a list of child nodes for a node in a character skeleton or scene object.  If this node does not have child nodes, then return '''None'''.
</div>
+
 
-----
+
See Also: [[#GetParent ( self )|GetParent]]
===GetName===
+
 
 +
==== Returns ====
 +
:List of child nodes - [[IC_Python_API:RLPy_RINode|RINode]] list
 +
:No child nodes - None
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RIObject.GetName ( self )
+
# Get root bone
 +
avatar_list = RLPy.RScene.GetAvatars()
 +
avatar = avatar_list[0]
 +
skeleton_component = avatar.GetSkeletonComponent()
 +
root_bone = skeleton_component.GetRootBone()
 +
 
 +
# Get root bone children node list
 +
children_node_list = root_bone.GetChildren()
 +
print(children_node_list)
 
</syntaxhighlight>
 
</syntaxhighlight>
Get name of the object.
+
 
====Returns====
+
=== LocalTransform ( self ) ===
<div style="margin-left: 2em;">
+
 
Object name - string
+
Get the local-transform for a node in a character skeleton or scene object.
</div>
+
 
-----
+
See Also: [[#WorldTransform ( self )|WorldTransform]]
===GetType===
+
 
 +
==== Returns ====
 +
:Node local-transform - [[IC_Python_API:RLPy_RTransform|RTransform]]
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RIObject.GetType ( self )
+
# Get root bone
 +
avatar_list = RLPy.RScene.GetAvatars()
 +
avatar = avatar_list[0]
 +
skeleton_component = avatar.GetSkeletonComponent()
 +
root_bone = skeleton_component.GetRootBone()
 +
 
 +
# Get root bone local transform
 +
local_transform = root_bone.LocalTransform()
 +
print(local_transform)
 
</syntaxhighlight>
 
</syntaxhighlight>
Get object type of the object.
+
 
====Returns====
+
=== WorldTransform ( self ) ===
<div style="margin-left: 2em;">
+
 
Object type - RLPy.EObjectType
+
Get the world-transform for a node in a character skeleton or scene object.
*'''RLPy.EObjectType_Object'''
+
 
*'''RLPy.EObjectType_Avatar'''
+
See Also: [[#LocalTransform ( self )|LocalTransform]]
*'''RLPy.EObjectType_Prop'''
+
 
*'''RLPy.EObjectType_Camera'''
+
==== Returns ====
*'''RLPy.EObjectType_Particle'''
+
:Node world-transform - [[IC_Python_API:RLPy_RTransform|RTransform]]
*'''RLPy.EObjectType_Light'''
+
 
*'''RLPy.EObjectType_SpotLight'''
+
*'''RLPy.EObjectType_PointLight'''
+
*'''RLPy.EObjectType_DirectionalLight'''
+
</div>
+
-----
+
===LocalTransform===
+
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RIObject.LocalTransform ( self )
+
# Get root bone
 +
avatar_list = RLPy.RScene.GetAvatars()
 +
avatar = avatar_list[0]
 +
skeleton_component = avatar.GetSkeletonComponent()
 +
root_bone = skeleton_component.GetRootBone()
 +
 
 +
# Get root bone world transform
 +
world_transform = root_bone.WorldTransform()
 +
print(world_transform)
 
</syntaxhighlight>
 
</syntaxhighlight>
Get local transform of the object.
+
 
( Experimental API )
+
=== WorldToLocal ( self, kWorldMatrix ) ===
====Returns====
+
 
<div style="margin-left: 2em;">
+
Convert the world-transform matrix for a node in a character skeleton or scene object to local-transform matrix.
Object transform - RLPy.RTransformf
+
 
</div>
+
See Also: [[#LocalToWorld ( self, kLocalMatrix )|LocalToWorld]]
-----
+
 
===WorldTransform===
+
==== Parameters ====
 +
:kWorldMatrix [IN] Node world-transform matrix - [[IC_Python_API:RLPy_RMatrix4|RMatrix4]]
 +
 
 +
==== Returns ====
 +
:Node local-transform matrix - [[IC_Python_API:RLPy_RMatrix4|RMatrix4]]
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RIObject.WorldTransform ( self )
+
# Get root bone
 +
avatar_list = RLPy.RScene.GetAvatars()
 +
avatar = avatar_list[0]
 +
skeleton_component = avatar.GetSkeletonComponent()
 +
root_bone = skeleton_component.GetRootBone()
 +
 
 +
# Transfer root bone world transform matrix to local transform matrix
 +
world_transform = root_bone.WorldTransform()
 +
world_matrix = world_transform.Matrix() 
 +
world_to_local = bone.WorldToLocal(world_matrix)
 +
print(world_to_local)
 +
</syntaxhighlight>
 +
 
 +
=== LocalToWorld ( self, kLocalMatrix ) ===
 +
 
 +
Convert the local-transform matrix for a node in a character skeleton or scene object to world-transform matrix.
 +
 
 +
See Also: [[#WorldToLocal ( self, kWorldMatrix )|WorldToLocal]]
 +
 
 +
==== Parameters ====
 +
:kLocalMatrix [IN] Node local-transform matrix - [[IC_Python_API:RLPy_RMatrix4|RMatrix4]]
 +
 
 +
==== Returns ====
 +
:Node local-transform matrix - [[IC_Python_API:RLPy_RMatrix4|RMatrix4]]
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Transfer root bone local transform matrix to world transform matrix
 +
local_transform = root_bone.LocalTransform()
 +
local_matrix = local_transform.Matrix()   
 +
local_to_world = bone.LocalToWorld(local_matrix)
 +
print(local_to_world)
 +
</syntaxhighlight>
 +
 
 +
=== Update ( self ) ===
 +
 
 +
Update the Transform Control for a node in a character skeleton or scene object and update the scene.  After the update, the Transform Control's key values will reflect the world-transform values of the node for the current point in time.
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Get root bone
 +
avatar_list = RLPy.RScene.GetAvatars()
 +
avatar = avatar_list[0]
 +
skeleton_component = avatar.GetSkeletonComponent()
 +
root_bone = skeleton_component.GetRootBone()
 +
 
 +
# Get root bone child node world transform rotation x-axis value
 +
motion_bones = skeleton_component.GetMotionBones()
 +
child = motion_bones[1]
 +
child_world = child.WorldTransform()
 +
child_rot_x = child_world.R().x
 +
 
 +
# Set float control rotation x-axis value
 +
RLPy.RGlobal.SetTime(RLPy.RTime(0))
 +
animation_clip = skeleton_component.GetClip(0)
 +
root_control = animation_clip.GetControl("Layer", root_bone)
 +
data_block = root_control.GetDataBlock()
 +
float_control_rotate_x = data_block.GetControl("Rotation/RotationX")
 +
float_control_rotate_x.SetValue(RLPy.RGlobal.GetTime(), math.radians(60))
 +
 
 +
# Update root bone with float control
 +
root_bone.Update()
 +
 
 +
# Get root bone child node world transform rotation x-axis value after updated
 +
new_child_world = child.WorldTransform()
 +
after_update_child_rot_x = new_child_world.R().x
 
</syntaxhighlight>
 
</syntaxhighlight>
Get world transform of the object.
 
( Experimental API )
 
====Returns====
 
<div style="margin-left: 2em;">
 
Object transform - RLPy.RTransformf
 
</div>
 

Revision as of 00:18, 1 April 2020

Main article: Modules.
Last modified: 04/1/2020

Description

This class is used to access node parameters in a character skeleton or scene object. Retrievable parameters include name, ID, parent node, list of child nodes, and more. Update to get the world-transform of the bone node for the current point in time.

# Get root bone
avatar_list = RLPy.RScene.GetAvatars()
avatar = avatar_list[0]
skeleton_component = avatar.GetSkeletonComponent()
root_bone = skeleton_component.GetRootBone()

# Get root bone node name
node_name = root_bone.GetName()
print(node_name)

# Get root bone node ID
node_id = root_bone.GetID()
print(node_id)

# Get root bone parent node
parent_node = root_bone.GetParent()
print(parent_node)

# Get root bone children node list
children_node_list = root_bone.GetChildren()
print(children_node_list)

# Get root bone local transform
local_transform = root_bone.LocalTransform()
print(local_transform)

# Get root bone world transform
world_transform = root_bone.WorldTransform()
print(world_transform)

# Transfer root bone world transform matrix to local transform matrix
world_transform = root_bone.WorldTransform()
world_matrix = world_transform.Matrix()  
world_to_local = bone.WorldToLocal(world_matrix)
print(world_to_local)

# Transfer root bone local transform matrix to world transform matrix
local_transform = root_bone.LocalTransform()
local_matrix = local_transform.Matrix()     
local_to_world = bone.LocalToWorld(local_matrix)
print(local_to_world)

Member Functions

GetName ( self )

Get the name of the node in a character skeleton or scene object.

Returns

Name of the node - str
# Get root bone
avatar_list = RLPy.RScene.GetAvatars()
avatar = avatar_list[0]
skeleton_component = avatar.GetSkeletonComponent()
root_bone = skeleton_component.GetRootBone()

# Get root bone node name
node_name = root_bone.GetName()
print(node_name)

GetID ( self )

Get the ID of the node in a character skeleton or scene object.

Returns

ID of the node - int
# Get root bone
avatar_list = RLPy.RScene.GetAvatars()
avatar = avatar_list[0]
skeleton_component = avatar.GetSkeletonComponent()
root_bone = skeleton_component.GetRootBone()

# Get root bone node ID
node_id = root_bone.GetID()
print(node_id)

GetParent ( self )

Get the parent node of the bone node in a character skeleton or scene object. If a parent does not exist, then return None.

Returns

Parent node - RINode
No parent node - None
# Get root bone
avatar_list = RLPy.RScene.GetAvatars()
avatar = avatar_list[0]
skeleton_component = avatar.GetSkeletonComponent()
root_bone = skeleton_component.GetRootBone()

# Get root bone parent node
parent_node = root_bone.GetParent()
print(parent_node)

GetChildren ( self )

Get a list of child nodes for a node in a character skeleton or scene object. If this node does not have child nodes, then return None.

See Also: GetParent

Returns

List of child nodes - RINode list
No child nodes - None
# Get root bone
avatar_list = RLPy.RScene.GetAvatars()
avatar = avatar_list[0]
skeleton_component = avatar.GetSkeletonComponent()
root_bone = skeleton_component.GetRootBone()

# Get root bone children node list
children_node_list = root_bone.GetChildren()
print(children_node_list)

LocalTransform ( self )

Get the local-transform for a node in a character skeleton or scene object.

See Also: WorldTransform

Returns

Node local-transform - RTransform
# Get root bone
avatar_list = RLPy.RScene.GetAvatars()
avatar = avatar_list[0]
skeleton_component = avatar.GetSkeletonComponent()
root_bone = skeleton_component.GetRootBone()

# Get root bone local transform
local_transform = root_bone.LocalTransform()
print(local_transform)

WorldTransform ( self )

Get the world-transform for a node in a character skeleton or scene object.

See Also: LocalTransform

Returns

Node world-transform - RTransform
# Get root bone
avatar_list = RLPy.RScene.GetAvatars()
avatar = avatar_list[0]
skeleton_component = avatar.GetSkeletonComponent()
root_bone = skeleton_component.GetRootBone()

# Get root bone world transform
world_transform = root_bone.WorldTransform()
print(world_transform)

WorldToLocal ( self, kWorldMatrix )

Convert the world-transform matrix for a node in a character skeleton or scene object to local-transform matrix.

See Also: LocalToWorld

Parameters

kWorldMatrix [IN] Node world-transform matrix - RMatrix4

Returns

Node local-transform matrix - RMatrix4
# Get root bone
avatar_list = RLPy.RScene.GetAvatars()
avatar = avatar_list[0]
skeleton_component = avatar.GetSkeletonComponent()
root_bone = skeleton_component.GetRootBone()

# Transfer root bone world transform matrix to local transform matrix
world_transform = root_bone.WorldTransform()
world_matrix = world_transform.Matrix()  
world_to_local = bone.WorldToLocal(world_matrix)
print(world_to_local)

LocalToWorld ( self, kLocalMatrix )

Convert the local-transform matrix for a node in a character skeleton or scene object to world-transform matrix.

See Also: WorldToLocal

Parameters

kLocalMatrix [IN] Node local-transform matrix - RMatrix4

Returns

Node local-transform matrix - RMatrix4
# Transfer root bone local transform matrix to world transform matrix
local_transform = root_bone.LocalTransform()
local_matrix = local_transform.Matrix()     
local_to_world = bone.LocalToWorld(local_matrix)
print(local_to_world)

Update ( self )

Update the Transform Control for a node in a character skeleton or scene object and update the scene. After the update, the Transform Control's key values will reflect the world-transform values of the node for the current point in time.

# Get root bone
avatar_list = RLPy.RScene.GetAvatars()
avatar = avatar_list[0]
skeleton_component = avatar.GetSkeletonComponent()
root_bone = skeleton_component.GetRootBone()

# Get root bone child node world transform rotation x-axis value
motion_bones = skeleton_component.GetMotionBones()
child = motion_bones[1]
child_world = child.WorldTransform()
child_rot_x = child_world.R().x

# Set float control rotation x-axis value
RLPy.RGlobal.SetTime(RLPy.RTime(0))
animation_clip = skeleton_component.GetClip(0)
root_control = animation_clip.GetControl("Layer", root_bone)
data_block = root_control.GetDataBlock()
float_control_rotate_x = data_block.GetControl("Rotation/RotationX")
float_control_rotate_x.SetValue(RLPy.RGlobal.GetTime(), math.radians(60))

# Update root bone with float control
root_bone.Update()

# Get root bone child node world transform rotation x-axis value after updated
new_child_world = child.WorldTransform()
after_update_child_rot_x = new_child_world.R().x