Dependency graph plug-ins

This section introduces the Dependency Graph (DG), and shows how to use the Maya API to write plug-ins that extend and integrate with it.

The dependency graph lies at the heart of Maya. It maintains the construction history of the scene: a record of what operations you have applied in what order. The graph is made up of a series of interconnected nodes, each of which encapsulates a single operation or a single set of calculations. Each node accepts a limited set of well-defined input data, performs its calculations based on that data, and produces one or more output values. For more background information about nodes, connections, and how the dependency graph works, see About the dependency graph.

You can use the Maya API to create your own custom dependency graph nodes, which carry out custom operations based on their incoming data. Each kind of node you write is represented by a class that derives from the base MPxNode class, which provides the main interface needed in order to hook up to the dependency graph. The Maya API also provides several other base classes that derive from MPxNode, but that specialize its behavior for different uses. For example, you can derive your custom node class from MPxDeformerNode instead of MPxNode in order to implement a custom deformer. Maya will treat your custom node in the same way that it treats built-in types of deformers. For a description of these base classes, see Base dependency node classes.

Every node class needs to be set up with some attributes, which define the types of input data the node accepts and the types of output data that the node produces. For more information, see Attributes and plugs and Complex and Dynamic Attributes.

The main work done by each dependency graph node is typically done in its virtual compute() method, which you must implement in your custom class. For considerations to keep in mind when writing your implementation, see Implementing the compute() method for a dependency graph node. Maya maintains all data related to each node in a dedicated data block, which it passes to this method each time an output value for the node needs to be re-computed. You need to use handles to read the input data from this block, and to write the output data to the block. For details, see Working with data blocks.

For working examples of plug-ins that define new types of dependency graph nodes, see A basic dependency node example and A more complex dependency graph example.