Profile Picture

SOLVED: How To Manipulate Bones Of A Character And Custom Armature Objects/Avatars

Posted By Lord Ashes 4 Years Ago
You don't have permission to rate!

SOLVED: How To Manipulate Bones Of A Character And Custom Armature...

Author
Message
Lord Ashes
Lord Ashes
Posted 4 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (20.8K reputation)Distinguished Member (20.8K reputation)Distinguished Member (20.8K reputation)Distinguished Member (20.8K reputation)Distinguished Member (20.8K reputation)Distinguished Member (20.8K reputation)Distinguished Member (20.8K reputation)Distinguished Member (20.8K reputation)Distinguished Member (20.8K reputation)

Group: Forum Members
Last Active: 2 Weeks Ago
Posts: 1.3K, Visits: 1.6K
The following code can be used to manipulate the bone of a Avatar/Character with a standard RL Armature (e.g. CC or RL character) or a object/avatar with a custom armature:

clip.GetControl("Layer", bone).GetDataBlock().GetControl("Rotation/RotationY").SetValue(RLPy.RTime(frame/60*1000, RLPy.kMilliseconds), rotation_y / 180 * RLPy.RMath.CONST_PI)

However, where the two differ is how to get the initial clip object.

For a Avatar/Character with a RL armature the following code can be used to get a clip object and even set its length:

clip = avatar.GetSkeletonComponent().AddClip(RLPy.RGlobal.GetTime())
clip.SetLength(RLPy.RTime(150*1000, RLPy.kMilliseconds))
However, this does not seem to work for a object/avatar with a custom armature. The script causes an error on the second line because the AddClip() does not generate a valid clip. Printing the value of clip after the AddClip() shows a RlClip object when used with a RL avatar/character but shows none when used with a custom armature object/avatar.

The work around that I found is to do the following:

1. Create a key frame on frame 0 of the Animation Layer track
2. Use clip = avatar.GetSkeletonComponent().GetClip(0)

If anyone can figure out how to get a proper reference to the clip for Animation Layer animations (i.e. animations of custom armature objects/avatars) please post a solution but in the meantime the above work-around should work.

For reference here is a complete script which rotates all bones 10 degrees around the X axis:

import RLPy
print("Get Object")
avatar = RLPy.RScene.GetSelectedObjects()[0]
print("Get Clip")
clip = avatar.GetSkeletonComponent().GetClip(0)
print("Get Bones")
motion_bones = avatar.GetSkeletonComponent().GetSkinBones()
print("Rotate Bones")
frame = 0
for bone in motion_bones:
    print(bone.GetName())
    layer = clip.GetControl("Layer", bone)
    data_block = layer.GetDataBlock()
    rotX = data_block.GetControl("Rotation/RotationX")
    rotX.SetValue(RLPy.RTime(frame/60*1000, RLPy.kMilliseconds), 10 / 180 * RLPy.RMath.CONST_PI)
    
print("Force Key Frame Updates")
RLPy.RGlobal.ObjectModified(avatar, RLPy.EObjectModifiedType_Transform)
The last line was provided by RL and is probably not needed for custom armature objects/avatars. It is used with CC3+ characters to force updating of the generated key frames. Without it, CC3+ characters will add any key frame animations that the script adds but will not display any key frames. Thus if you script is adding animation but you are not seeing any key frames being generated, try adding the last line.

"We often compare ourselves to the U.S. and often they come out the best, but they only have the right to bear arms while we have the right to bare breasts"
Bowser and Blue, Busting The Breast



Reading This Topic