Getting XYZ Rotation Data from an IK Bone

Getting XYZ Rotation Data from an IK Bone

joefearstone
Contributor Contributor
2,279 Views
6 Replies
Message 1 of 7

Getting XYZ Rotation Data from an IK Bone

joefearstone
Contributor
Contributor

Let's say I made a typical simple arm joint (UpperArm, LowerArm, Hand), linked as a hierarchy, and assign them an IK Limb Solver.

As I manipulate the IK, What's the best way to access the XYZ Rotations of the LowerArm (in parent space) through a Script Controller in real time?

I tried:

     "in coordsys parent (LowerArm.transform.rotation.z)"

but that produces world space rotation data.

The only solution I came up with was to make an independent Helper Bone, assign it "orientation constraint" to the LowerArm Bone, set its constraint rules to Local->Local. Then, I can read the axis data from that Helper Bone using a Float Script or an Expression Controller.

But, Is there a way to access the parent space XYZ Rotation data directly from the Bone in the IK system?

0 Likes
Accepted solutions (2)
2,280 Views
6 Replies
Replies (6)
Message 2 of 7

leeminardi
Mentor
Mentor

I'm still learning how to work with Max matrices but here's a script that might yield the results you need.  The angles output are the relative angles  of rotation (in degrees) of the lower arm with respect to the upper arm.

 

ua = $UpperArm.transform
la = $LowerArm.transform
XYZrot =  (la * inverse(ua)) as eulerangles
format "\nX Y Z rotation = %" XYZrot

 

lee.minardi
Message 3 of 7

joefearstone
Contributor
Contributor

Thanks for the Reply!

Right, multiplying by the inverse of the parent should give local space rotation of an IK bone.

I had previously tried to implement this approach, but I'm too unfamiliar with the syntax to do it right.

So let's say I wanted an independent object to mimic the parent space Z rotation of the LowerArm.

I would assign a Script Controller to this independent object's Z rotation, and in the ScriptController window I would create variables "ua" and "la". I assign "ua" to the node "upperarm", and "la" to the node "lowerarm".

In the Expression window I should be able to go:

         (la * inverse(ua))

But I get a "no inverse function for upperarm" error.

However, if I avoid setting "ua" and "la" in the Variable section, and make them directly in the Expression window as you have described, I get a different error, "unable to convert euler angles to type matrix"

I just can't tell if I'm doing something wrong or if I'm hitting limitations of the Script Controller.

 

So, how would I set an independent object, or a slider, or whatever to extract only the local Z rotation Value of that LowerArm IK bone?

0 Likes
Message 4 of 7

leeminardi
Mentor
Mentor
Accepted solution

I assigned the following transform script to boxA which will rotate to the angle equal to the z rotation of the lower arm relative to the upper arm.  lat is assigned to the transform of the lower arm bone.  I used the format statement to check the angle value.  I think this is what you wanted.

image.png

rotationAngles = laT as eulerangles
format "\nrotation angles = % " rotationAngles
rotateZMatrix rotationAngles.z

 

lee.minardi
Message 5 of 7

joefearstone
Contributor
Contributor
Accepted solution

Leeminardi, you're a miracle worker. I've spent hours, and there was no way I would have ever found these mystery functions, how to use them, or which of the script controllers to use them in. With just this extracted data alone, one could make muscle bulgers, skin pushers, twister bones, etc...Who knows how many other wonder functions are hidden in these controllers, lost to time.

0 Likes
Message 6 of 7

leeminardi
Mentor
Mentor

@joefearstone thank you for the very kind words.  I'm glad that you will find the solution useful.  I have  to say that the script did not come to me immediately and was surprised that the final code is so concise.

I found the following links were helpful in dealing with matrices and rotations.

Matrix3 values

Euler Angles Values

 

 

lee.minardi
0 Likes
Message 7 of 7

joefearstone
Contributor
Contributor

Awesome, thanks for the info!

0 Likes