Compose & Decompose Matrix Data

Compose & Decompose Matrix Data

Anonymous
Not applicable
1,780 Views
2 Replies
Message 1 of 3

Compose & Decompose Matrix Data

Anonymous
Not applicable

Greetings.

I am slowly learning maya's API, general programming and I've been looking at all the known API and maya resources I can find, including the maya documentation, c++ api documentation, paid courses but I am struggling to figure it all out.

 

To learn the deeper functions of maya, I am looking to write a couple of nodes to compose, the other to decompose the matrix. I am unsure how to use an inputMatrix plug, grab its data as translate, rotate, scale, etc, how to then use tranforms and turn into a usable outputMatrix.

 

I apologize if an answer is hidden here already, I may have skipped over or it. I wish there was more clear information or an easy way to look at native maya nodes to examine them.

 

Cheers.

 

0 Likes
1,781 Views
2 Replies
Replies (2)
Message 2 of 3

jmreinhart
Advisor
Advisor

So you'll never be able to look at the code for default Maya nodes, but most Maya API classes have examples that you can find by going to the documentation page and clicking on examples.

 

In case you didn't already know there are composeMatrix and decomposeMatrix nodes in Maya, you just need to load the included matrixNodes plugin. But you're probably trying to recreate them for practice so here's some info:

 

To create a custom node you'll need to use the MPxNode class

https://help.autodesk.com/view/MAYAUL/2016/ENU/?guid=__files_Dependency_graph_plugins_The_basics_htm

https://download.autodesk.com/us/maya/2011help/API/class_m_px_node.html 

To have a matrix input you'll need to create a matrix attribute in the initialize step of your MPxNode using the MFnMatrixAttribute class.

https://download.autodesk.com/us/maya/2011help/API/class_m_fn_matrix_attribute.html

You'll also need to create translate, rotate, scale, shear outputs using the MFnNumericAttribute class.

https://download.autodesk.com/us/maya/2011help/API/class_m_fn_numeric_attribute.html 

 

Inside of the compute method you'll need to get the matrix data as a MMatrix from the dataBlock, then you can use the MTransformationMatrix class to turn it into a transformation matrix.

http://download.autodesk.com/us/maya/2010help/api/class_m_transformation_matrix.html

 

Then you can use these methods on the MTransformationMatrix  class to get the translate,rotate, scale and shear.

MTransformationMatrix::translation()
MTransformationMatrix::rotation( 
MTransformationMatrix::getScale()

 

MTransformationMatrix::getShear()

 

And then you can output them, but be aware of rotateOrder.

 

I skimmed over how the MPxNode and compute stuff works but that first link is a great tutorial for how to create an MPxNode.

 

Hope that points you in the right direction let me know if you get stuck.

 

 

 

 

Message 3 of 3

ssedoff
Participant
Participant

Decompose Matrix does not appear to be an option in Maya 2020.4. Was it replaced by something else? I've turned on all of the plug ins in Maya and still nothing.

 

The Matrix nodes only contain InverseMatrix and TransposeMatrix, nothing else.

 

I cannot find anyone online discussing this though and I'm not alone in the group I am working with seeing that this is missing.

 

Any help would be appreciated.

0 Likes