get world position from matrix

60 views
Skip to first unread message

email...@gmail.com

unread,
Jul 20, 2020, 6:10:06 PM7/20/20
to Python Programming for Autodesk Maya
hello.
Suppose I have local position and rotate and scale of child node, I also have world position and rotate
 and scale of parent node.

now How can I have local matrix of child and parent world matrix? and From these two matrices, I get the child world matrix and world position and rotate of child node.
please help me. thanks!

Roland Reyer

unread,
Jul 21, 2020, 5:12:08 PM7/21/20
to Python Programming for Autodesk Maya
What’s your goal?
Do you want to query the world position/rotation of the child? —> xform -q -ws ...

Roy Nieterau

unread,
Jul 22, 2020, 5:24:32 AM7/22/20
to Python Programming for Autodesk Maya
Not sure I understand. but you could build up the matrix with MTransformationMatrix in the API if you really need to:

import maya.api.OpenMaya as om

translate
= [0, 0, 0]
rotate
= [0, 0, 0]
scale
= [1, 1, 1]

trans
= om.MTransformationMatrix()
trans
.setTranslation(om.MVector(translate), om.MSpace.kObject)
trans
.setRotation(om.MEulerRotation(rotate, om.MTransformationMatrix.kXYZ))
trans
.setScale(scale, om.MSpace.kObject)
matrix
= trans.asMatrix()

But like Roland states if you're just interested in matrices of nodes in Maya you can just as easily query them.

from maya import cmds

selection
= cmds.ls(sl=1)
node
= selection[0]

world_space
= cmds.xform(node, query=True, matrix=True, worldSpace=True)
object_space
= cmds.xform(node, query=True, matrix=True, objectSpace=True)
print world_space
print object_space

Reply all
Reply to author
Forward
0 new messages