Getting matrix values from a custom transform node using Maya API


Need help getting correct matrix values in a custom Maya transform node. I am subclassing Maya’s transform node to compute and output custom translate\rotate values.

if I try to get the node’s matrix values (worldMatrix or parentInverseMatrix) in the compute function of the transform node, those values are not correct. This is how I try to get the data:

def compute(self, plug, data):
    handle = data.inputValue(self.parentInverseMatrix)
    transformMatrix = OpenMayaMPx.MPxTransformationMatrix(handle.asMatrix())

Using self.baseTransformationMatrix does return a matrix with expected values. However, how would I go about getting the parentInverseMatrix of the node?

Getting values from other properties such as translate, and rotate does return the values I expect to get.

handle = data.inputValue(self.translate)
vector = handle.asVector()

Thanks in advance for the help!


I think you have to inherit your node from MPxTransform class, and use it in conjunction with MPxTransformationMatrix, like descrive here.

MPxTransform is already derived from MPxNode, which has access to parentMatrix and parentInverseMatrix properties.

You can have a look at these examples to set up a custom transform node.

Cheers !