I have some code that gets the rotate pivot of a control in world space:
cmds.xform(ctrlName, q=True, rotatePivot=True, worldSpace=True)
Now would like to get the same information for a different frame/time, without changing the current time. Some people on the internet suggest using getAttr for the .worldMatrix[0] attribute, but the numbers do not match up for me.
The closest I have come is this:
worldMatrix = cmds.getAttr(ctrlName+'.worldMatrix[0]', time=frameNumber)
rotPivot = cmds.getAttr(ctrlName+'.rotatePivot, time=frameNumber)
#
# Lots of code here to multiply rotPivot by worldMatrix
But that adds a lot of extra code.
Is there some easier way that I am missing?
Edit: Forgot to mention that the “xform” command does not have a “time” parameter, which is why I’m having so much trouble.
Can you use pymel? Or the maya api? They both have built in support to matrix multiplication that would turn that into one extra call. Either that or just throw a matrix multiplication method into a math library and call that? I don’t know of a way to get at what you want with just a couple calls aside from doing the math.
Originally, I thought the Maya API would be too much set up code. But I tried again after you suggested it. It turns out to be not as many lines as I thought:
wm = cmds.getAttr(nodeName+'.worldMatrix[0]', time=frameNumber)
rotPiv = cmds.getAttr(nodeName+'.rotatePivot', time=frameNumber)[0]
worldMatrix = om.MMatrix()
om.MScriptUtil.createMatrixFromList(wm, worldMatrix)
rotPiv = cmds.getAttr(nodeName+'.rotatePivot')[0]
rotPivVec = om.MPoint(rotPiv[0], rotPiv[1], rotPiv[2], 1.0)
rotPivWorld = rotPivVec * worldMatrix
I also got it working by doing the math manually:
wm = cmds.getAttr(nodeName+'.worldMatrix[0]', time=frameNumber)
rotPiv = cmds.getAttr(nodeName+'.rotatePivot', time=frameNumber)[0]
rotPivWorld = [wm[0]*rotPiv[0] + wm[4]*rotPiv[1] + wm[8]*rotPiv[2] + wm[12],
wm[1]*rotPiv[0] + wm[5]*rotPiv[1] + wm[9]*rotPiv[2] + wm[13],
wm[2]*rotPiv[0] + wm[6]*rotPiv[1] + wm[10]*rotPiv[2] + wm[14]]