Difference between revisions of "IC Python API:Animating A Character"
Chuck (RL) (Talk | contribs) (Created page with "{{TOC}} {{Parent|IC_Python_API|iClone Python API}} This page will cover iClone's Character Animation System and ways to control it. == Motion Bone vs Skin Bone == In iClone...") |
Chuck (RL) (Talk | contribs) m |
||
(3 intermediate revisions by the same user not shown) | |||
Line 14: | Line 14: | ||
Before running the script below, be sure to have a Character loaded in your iClone scene. | Before running the script below, be sure to have a Character loaded in your iClone scene. | ||
− | + | <syntaxhighlight lang="Python"> | |
import math, RLPy | import math, RLPy | ||
Line 31: | Line 31: | ||
for bone in motion_bone: | for bone in motion_bone: | ||
print ("Motion Bone: " + bone.GetName()) | print ("Motion Bone: " + bone.GetName()) | ||
− | </ | + | </syntaxhighlight> |
== Animating a Character == | == Animating a Character == | ||
Line 37: | Line 37: | ||
If you want to animate a character, make sure to apply a Motion Clip in order for us to add keys. | If you want to animate a character, make sure to apply a Motion Clip in order for us to add keys. | ||
− | + | <syntaxhighlight lang="Python"> | |
import math, RLPy | import math, RLPy | ||
Line 63: | Line 63: | ||
#-- Set Key in current time to rotate the head bone to 90 degree --# | #-- Set Key in current time to rotate the head bone to 90 degree --# | ||
float_control_rotate_x.SetValue(RLPy.RGlobal.GetTime(), math.radians(90)) | float_control_rotate_x.SetValue(RLPy.RGlobal.GetTime(), math.radians(90)) | ||
− | </ | + | </syntaxhighlight> |
Run the script above and you should see the character is looking down. Open Edit Motion Layer, click on FK Mode and pick on the Head bone - you'll notice that the value for X is 90. | Run the script above and you should see the character is looking down. Open Edit Motion Layer, click on FK Mode and pick on the Head bone - you'll notice that the value for X is 90. | ||
{{Single_Illustration|Python_api_edit_motion_layer_ik.png}} | {{Single_Illustration|Python_api_edit_motion_layer_ik.png}} |
Latest revision as of 00:28, 9 April 2019
- Main article: iClone Python API.
This page will cover iClone's Character Animation System and ways to control it.
Motion Bone vs Skin Bone
In iClone, all character actions are driven by Motion Bones which have fixed structure and names that can't be changed. Motion Bones are where all the motion data are stored - if you are familiar with MotionBuilder, you can think of it as the "Source Character".
So any motion applied to the Character, are in fact, applied to the Motion Bones then retargeted onto the Characters' Skin Bones in real-time. Therefore, there are two separate functions for retrieving each bone type as illustrated in the sample code below.
Before running the script below, be sure to have a Character loaded in your iClone scene.
import math, RLPy
#-- Get Characters from current scene --#
avatar_list = RLPy.RScene.GetAvatars()
#-- Get First Character --#
avatar = avatar_list[0]
#-- Get Skin Bone Data --#
skin_bone = avatar.GetSkeletonComponent().GetSkinBones()
#-- Get Motion Bone Data --#
motion_bone = avatar.GetSkeletonComponent().GetMotionBones()
for bone in skin_bone:
print ("Skin Bone: " + bone.GetName())
for bone in motion_bone:
print ("Motion Bone: " + bone.GetName())
Animating a Character
If you want to animate a character, make sure to apply a Motion Clip in order for us to add keys.
import math, RLPy
#-- Get Characters from current scene --#
avatar_list = RLPy.RScene.GetAvatars()
#-- Get First Character --#
avatar = avatar_list[0]
#-- Get Skin Bone Data --#
skin_bone = avatar.GetSkeletonComponent().GetSkinBones()
#-- Get Motion Bone Data --#
motion_bone = avatar.GetSkeletonComponent().GetMotionBones()
#-- Get First Clip --#
animation_clip = avatar.GetSkeletonComponent().GetClip(0)
#-- Extend the Clip length --#
animation_clip.SetLength(RLPy.RTime(5000))
#-- Find head bone --#
for bone in motion_bone:
if bone.GetName() == "RL_Head":
#-- Get Key from Layer --#
head_control = animation_clip.GetControl("Layer", bone)
data_block = head_control.GetDataBlock()
float_control_rotate_x = data_block.GetControl("Rotation/RotationX")
#-- Set Key in current time to rotate the head bone to 90 degree --#
float_control_rotate_x.SetValue(RLPy.RGlobal.GetTime(), math.radians(90))
Run the script above and you should see the character is looking down. Open Edit Motion Layer, click on FK Mode and pick on the Head bone - you'll notice that the value for X is 90.