Search code examples
pythonc++maya

How does maya know, what the output mesh of your MPxNode is?


When using a PolyModifierNode, the node has a inMesh and a outMesh attribute/plug, where the inMesh is hidden and replaced by the outMesh. But a general MPxNode may have many inputs and outputs, which can be networked in complicated ways.

My problem in understanding the structure of the MPxNode is, that I do not see in which way maya knows, which objects from the input are transformed into which output objects. I would have expected something like the outMesh from the last node in the graph connected to some SceneRenderer.inputMeshes plug, but maya seems to automatically detect in some way which unused outMesh plugs should be rendered.

Finally I want to write a node, which gets an array of input meshes and an additional control mesh and should output an array of modified meshes, which replaces the original meshes.

I am using calculations where all objects in the group influence each other, so it cannot be done one by one. It would be possible to use one node per input, but the compute function would need to trigger the computation on all other input meshes as well.


Solution

  • Maya doesn't detect unconnected plugs. Instead, it evaluates on demand when something in the network of nodes changes and forces re-evaluations where necessary. You set up the conditions it cares about when you initialize a node using MPxNode::attributeAffects() or its Python equivalent. Changes to an input will be pushed downstream by other nodes as needed; when a change comes in to your node it will call the MPxNode::compute compute() passing the appropriate plug as an argument. Your node will then update its outputs, passing them along the chain to other nodes.

    You probably don't want to make your node take an array of input nodes an return an array of outputs. It's simpler and more maya-esque to make a node which modifies only one node at a time. That helps localizes chnges in the dependency graph and makes your scene run faster.