Difference between revisions of "IC Python API:Animating A Character"

From Reallusion Wiki!
Jump to: navigation, search
m (Animating a Character)
m
 
(One intermediate revision by the same user not shown)
Line 10: Line 10:
 
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.  
 
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.  
  
[[File:Python_api_motionbone_skinbone.png|500px]]
+
{{Single_Illustration|Python_api_motionbone_skinbone.png}}
  
 
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.
  
{{code|<nowiki>
+
<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())
</nowiki>}}
+
</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.
  
{{code|<nowiki>
+
<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))
</nowiki>}}
+
</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.
  
[[File:Python_api_edit_motion_layer_ik.png|350px]]
+
{{Single_Illustration|Python_api_edit_motion_layer_ik.png}}

Latest revision as of 01: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.

Python api motionbone skinbone.png

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.

Python api edit motion layer ik.png