PDA

View Full Version : Frozen transforms and matrix multiplication..


eek
12-10-2011, 06:19 PM
When you freeze an objects transform how are transforms applied to it?

I have two objects 'a' and 'b' at positionally [0,10,0], and I freeze the transform of 'b' back to [0,0,0] essentially freezing its world offset. To get 'b's transform relative to 'a' i'd first get the xform of the two: (using python btw)

import maya.cmds as cmds
import maya.OpenMaya as OpenMaya

mUtil = OpenMaya.MScriptUtil()

# first get the world transforms
p0 = cmds.xform('a', q=True, ws=True, m=True)
p1 = cmds.xform('b', q=True, ws=True, m=True)

# create empty matrices
m0 = OpenMaya.MMatrix()
m1 = OpenMaya.MMatrix()

# create the pointers
mUtil.createMatrixFromList(p0, m0)
mUtil.createMatrixFromList(p1, m1)

# get the inverse
m2 = (m1 * m0.inverse())

# multiply the inverse to get the original position
m3 = (m2 * m0)

Now applying this in a form of a matrix list using an xform does'nt seem to work:

mList = [
m3(0,0), m3(0,1), m3(0,2), m3(0,3),
m3(1,0), m3(1,1), m3(1,2), m3(1,3),
m3(2,0), m3(2,1), m3(2,2), m3(2,3),
m3(3,0), m3(3,1), m3(3,2), m3(3,3)
]

cmds.xform('b', ws=True, m=mList)

Where as applying it via transform property seems to work:

cmds.xform('b', ws=True, t=[m3(3,0), m3(3,1), m3(3,2)]

I could be wrong as i'm just starting to get the hang of the internal math of frozen transforms.

Robert Bateman
12-13-2011, 04:28 PM
When you freeze an objects transform how are transforms applied to it?

They aren't. The transformation is applied to the geometry, and the transform values are zerod. It's not quite as simple as that though, since there are various unpleasant edge cases surrounding instanced transforms & shapes, and negated scale.

theflash
12-14-2011, 08:36 AM
When you freeze the transform, in addition to geometry pivots change as well.

Robert Bateman
12-14-2011, 05:35 PM
When you freeze the transform, in addition to geometry pivots change as well.

That is simply not true. The only values that change on a transform/joint node are: scale, translate, rotate, and joint orient values. Scale and rotational pivots are entirely unaffected.

sciLoop
12-14-2011, 07:24 PM
You should rather not apply the freezeTransform. You loose the object to world transformation data. As Rob stated, when you do that, all values which transform the vertices from its initial object space ( the values in the transform node ) are added to these vertex positions in the shape node and their new true positions are then true worldSpace positions ( in case the transform did not have an additional transform above it ).

Its better to simply duplicate the transform and parent it under the new transform. This way, you also get zeroed out transform values for your transform.

theflash
12-14-2011, 09:33 PM
That is simply not true. The only values that change on a transform/joint node are: scale, translate, rotate, and joint orient values. Scale and rotational pivots are entirely unaffected.

I see. But then why does freezing transform changes the rotate pivot point in the code below?

circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1; objectMoveCommand; move -r -ls -wd 0 14.283177 0 ;
move -r -ls -wd 3.11461 0 0 ;
xform -q -rp;
// Result: 0 0 0 //
FreezeTransformations;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;
xform -q -rp;
// Result: 3.11461 14.283177 0 //

theflash
12-14-2011, 09:40 PM
You should rather not apply the freezeTransform. You loose the object to world transformation data. As Rob stated, when you do that, all values which transform the vertices from its initial object space ( the values in the transform node ) are added to these vertex positions in the shape node and their new true positions are then true worldSpace positions ( in case the transform did not have an additional transform above it ).

Its better to simply duplicate the transform and parent it under the new transform. This way, you also get zeroed out transform values for your transform.

If the transform node does not have any geometric shape as children then you loose the rotation values but translation can still be queried through rotate pivot. For a transform without shape pivot acts like position, just like how joint behaves if you change the pivot location it actually moves the joint.

CGTalk Moderation
12-14-2011, 09:40 PM
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.