Profile Picture

Python Script Rotation Performs Unexpected Rotations

Posted By Lord Ashes 4 Years Ago
You don't have permission to rate!
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: Last Week
Posts: 1.3K, Visits: 1.6K
I have created a rope like object which is a long cylinder that consists of a 100 bones allowing the role/cable/pipe to be bend in any direction along the length.
I have written a script which curls the object by successively rotating each bone by 20 degrees starting at frame 10 and jumping by 5 frames each time. Thus at frame 10 it rotates the last bone by 20 degrees. At frame 15 it rotates the second last bone by 20 degrees. At frame 20 it rotates the third last bone by 20 degrees and so on. So by frame 30 it should have only rotated the last 5 bones.
However, when I run the script at frame 30 it is obvious that more than the last 5 bones have been affected because the bend on the rope can be seen as going at least half way down the rope.
For comparison, I added a second rope which I manually manipulated the last 5 bones. The manual rotations may not have been 20 degrees but it is evident how, when done manually, only the end of the rope (last 5 bones) are affected (as expected).

As I see it, there are two possibilities:
1. My script does not do what I think it is doing
2. The scripting is causing some undesired rotation effect

https://forum.reallusion.com/uploads/images/407e7b25-e2ec-4b0c-907f-2efe.png

The Python Script that I am using is:


import RLPy

RLPy.RGlobal.Stop()

print("Get Rope Object")
avatar = RLPy.RScene.GetSelectedObjects()[0]

print("Get Bones")
motion_bones = avatar.GetSkeletonComponent().GetSkinBones()

frame = 10
angle = 20
deflection = 3

print("Clips: %d"%(avatar.GetSkeletonComponent().GetClipCount()))
clip = avatar.GetSkeletonComponent().GetClip(0)
clip.SetLength(RLPy.RTime(550/60*1000, RLPy.kMilliseconds))

for loop in range(3,103):
    index = 106-loop
    bone = motion_bones[index]
    print("Frame %d : %s ( Index %d)"%(frame,bone.GetName(),index))
    layer = clip.GetControl("Layer", bone)
    data_block = layer.GetDataBlock()
    x = data_block.GetControl("Rotation/RotationX")
    y = data_block.GetControl("Rotation/RotationY")
    z = data_block.GetControl("Rotation/RotationZ")
    x.SetValue(RLPy.RTime(frame/60*1000, RLPy.kMilliseconds), 0 / 180 * RLPy.RMath.CONST_PI)
    y.SetValue(RLPy.RTime(frame/60*1000, RLPy.kMilliseconds), angle  / 180 * RLPy.RMath.CONST_PI)
    z.SetValue(RLPy.RTime(frame/60*1000, RLPy.kMilliseconds), deflection / 180 * RLPy.RMath.CONST_PI)
    frame = frame + 5


Does anyone know why I am getting this odd effect?

"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