PDA

View Full Version : Get transforms of each node relative to parent


Martoon
03-02-2007, 03:31 PM
First, background and context: I'm relatively new to MaxScript, and using Max 8.

I'm iterating through all of the nodes in the scene and for each node, I need to get its pos/rot/scale relative to its parent. I can use

in coordsys parent thisPos = thisNode.position

But for nodes having controllers without a position subcontroller (IK, etc.), this gives an "Unknown property" error. To avoid this error, instead of <node>.position I can use <node>.transform.position, which always gives a position (regardless of controller type). But <node>.transform.position always gives position in world coordinates, even if I use in coordsys parent.

So my question is; How do I get the pos/rot/scale of a node relative to its parent, regardless of controller type?

Martoon
03-02-2007, 07:53 PM
I still haven't dug up a direct way to get the parent-relative transform for a node, so I'm just doing this:
if thisNode.parent = undefined
then parentTransform = matrix 1
else parentTransform = thisNode.parent.transform
xform = thisNode.transform * inverse parentTransform
I then just get the pos/rot/scale from xform.

JHaywood
03-02-2007, 08:14 PM
I'm still trying to get my head around transforms myself, but I believe this will work:

($.transform * (inverse $.parent.transform)).position

And you might want to add a check to see if there actually is a parent first.

Oh, and replace ".position" with ".rotation" or ".scale" for the other properties. Or, save the transform as a new variable, like "tm = $.transform * (inverse $.parent.transform)", and then use "tm.position, tm.rotation, or tm.scale" to get the info you need.

Martoon
03-02-2007, 10:30 PM
Heh heh, I guess this is what happens with moderated forums. Anyway, thanks for the reply.

eek
03-03-2007, 07:00 AM
Controllers work in local space so if the object has a parent you can just type:


$.pos.controller.value
$.pos
$.transform.row4
$.transform[1].value

etc,etc, with things like position constraints, ik etc you have to transform there space relative to a target for example:

($.transform * inverse $target.transform).pos

(quatToEuler ($.transform * inverse $target.transform)).x etc

(($.transform * inverse $target.transform)as eulerangles).value

if $.parent != undefined do
(
rotVal = (($.transform *inverse $.parent.transform) as eulerAngles).value

posVal = ($.transform * inverse $.parent.transform).row4/.pos etc
)

CGTalk Moderation
03-03-2007, 07:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.