Notifications
Clear all

[Closed] Get transforms of each node relative to parent

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?

4 Replies

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.

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.

Heh heh, I guess this is what happens with moderated forums. Anyway, thanks for the reply.

 eek

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
)