IC Python API:Animating A Character

From Reallusion Wiki!
Revision as of 00:31, 7 January 2019 by Chuck (RL) (Talk | contribs) (Motion Bone vs Skin Bone)

Jump to: navigation, search
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.

Python api motionbone skinbone.png

Before running the script below, be sure to have a Character loaded in your iClone scene.

Code:
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.

Code:
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.

Python api edit motion layer ik.png