worldMatrix to Translate/Rotate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I've got a custom node that..
1. Takes a worldMatrix
2. Performs some transformations on it
3. Spits out another worldMatrix
The default Maya worldMatrix is the sum of translate, rotate, rotate/scale pivot, rotate axis and in the case of joints a jointOrient too. The problem I'm having is in extracting only the translate/rotate components out of the resulting worldMatrix.
The transformations in step (2) are guaranteed to only involve translation and rotation, no scale nor shear. And my goal is finding updated translate/rotate of the output worldMatrix, taking into account any pre-existing pivots and axes and joint orients.
Here's an example in psuedo-code.
import cmdx
cmds.file(new=True, force=True)
# Two identical cubes
cube1, _ = map(cmdx.encode, cmds.polyCube(width=3))
cube2, _ = map(cmdx.encode, cmds.polyCube(width=3))
cube1["translate"] = (-3, 2, -1)
cube1["rotate", cmdx.Degrees] = (30, 20, 10)
cube2["translate"] = (1, 2, 3)
cube2["rotate", cmdx.Degrees] = (10, -60, 0)
cube2["rotatePivot"] = (1.5, 0, 0)
cube2["rotatePivotTranslate"] = (0.5, 1, 0)
# Apply matrix from cube1 to cube2, preserving pivot
wmat = cube1["worldMatrix"][0].asMatrix()
tm = cmdx.TransformationMatrix(wmat)
cube2["translate"] = tm.translation()
cube2["rotate"] = tm.rotation()
This results in cube2 being offset to cube1 by the amount of rotatePivot and rotatePivotTranslate is had, as they would be applied on-top of whatever the worldMatrix was.
I've formulated a more elaborate, working example using Maya API 2.0 on the Python-Inside-Maya mailing list a few days ago in search of a solution, without avail.
- https://groups.google.com/g/python_inside_maya/c/x8F417cpato
The Maya docs has a breakdown of how the MTransformationMatrix works, which I expect is how the Transform *node* works as well, given that the MFnTransform documentation is identical.
Along with this excellent write-up about the jointOrient.
But my eyes glaze over, my mind turns to dust and I get nowhere. I expect I'm overlooking a series of inverse matrix multiplications somewhere, but I can't for the life of me figure out where. Help!