How to save an object's transforms relative to another object?

How to save an object's transforms relative to another object?

Anonymous
Not applicable
1,383 Views
1 Reply
Message 1 of 2

How to save an object's transforms relative to another object?

Anonymous
Not applicable

In mel, how would you save object x's transform data (translation and rotation) relative to another object y, and put this into a variable?

 

In maxscript, I could get this relationship by:

 

matrix = x.transform * inverse y.transform

 

Then:

 

z.transform = matrix * y.transform

 

Obj z would snap to the translation and rotation of x relative to y.

 

It is not clear how to do this in mel, using the xform, getAttr or setAttr commands. Does anybody know how?

 

Thanks!

0 Likes
1,384 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

First of all you need to make sure that node's type is 'transform'

if(`nodeType  $node` == "transform"){
  //grab matrix there
}

if node is not transform but shape you may try to find its transfomation node:

string $parents[] = `listRelatives -fullPath -parent $node`;
$transform = $parents[0];

and then grab the matrix from the attribute 

float $m[] = `getAttr ($transform+".xformMatrix")`;

you can also grab this way inverseMatrix, worldInverseMatrix or parentInverseMatrix.
or you can use xfrom command

 

float $m[] = `xform -q -m $transform`;

however in both cases you get an array of 16 floats and you need to 
convert it to MEL matrix to perform maxtrix*point multiplication

matrix $mt[4][4] = <<$m[0], $m[1], $m[2], $m[3];
$m[4], $m[5], $m[6], $m[7];
$m[8], $m[9], $m[10], $m[11];
$m[12], $m[13], $m[14], $m[15]>>;

Hope it helps. Not so handy as in MaxScript 😉





0 Likes