MPxGeometryFilter Class Reference

#include <MPxGeometryFilter.h>

Class Description

Base class for user-defined deformers.

MPxGeometryFilter allows the creation of user-defined deformers. A deformer is a node which takes any number of input geometries, deforms them, and places the output into the output geometry attribute.

If you write a deformer by deriving from MPxGeometryFilter, your deformer will derive the benefit of Maya's internal deformer functionality, namely:

  • The Set Editing Tool and the Set Editor Window can be used to modify the membership of the deformer.
  • "Has No Effect" mode is implemented in the base class, and disables the node.
  • When the deformer node is deleted, its inputs and outputs will be correctly reconnected in the dependency graph.
  • Reordering of the deformer node with other deformers via the Complete List window.
  • Placement and connection of the deformer node in the dependency graph via the "deformer -type" command. The deformer command also has the standard deformer options such as exclusive membership and parallel mode.

Deformers are full dependency nodes and can have attributes and a deform() method. In general, to derive the full benefit of the Maya deformer base class, it is suggested that you do not write your own compute() method. Instead, write the deform() method, which is called by the MPxGeometryFilter's compute() method. However, there are some exceptions when you would instead write your own compute(), namely:

  • Your node's deformation algorithm depends on the geometry type, which is not available in the deform() method.
  • Your node's deformation algorithm requires computing all of the output geometries simultaneously.

In the case where you cannot simply override the deform() method, the following example code shows one possible compute() method implementation. This compute() example creates an iterator for the deformer set corresponding to the output geometry being computed. Note that this sample compute() implementation does not do any deformation, and does not implement handling of the nodeState attribute. If you do choose to override compute() in your node, there is no reason to implement the deform() method, since it will not be called by the base class.

MStatus exampleDeformer::compute(const MPlug& plug, MDataBlock& dataBlock)
{
if (plug.attribute() == outputGeom) {
// get the input corresponding to this output
//
unsigned int index = plug.logicalIndex();
MObject thisNode = this->thisMObject();
MPlug inPlug(thisNode,input);
inPlug.selectAncestorLogicalIndex(index,input);
MDataHandle hInput = dataBlock.inputValue(inPlug);
// get the input geometry and input groupId
//
MDataHandle hGeom = hInput.child(inputGeom);
MDataHandle hGroup = hInput.child(groupId);
unsigned int groupId = hGroup.asLong();
MDataHandle hOutput = dataBlock.outputValue(plug);
hOutput.copy(hGeom);
// do the deformation
//
MItGeometry iter(hOutput,groupId,false);
for ( ; !iter.isDone(); iter.next()) {
MPoint pt = iter.position();
//
// insert deformation code here
//
iter.setPosition(pt);
}
}
return status;
}

For most deformers, implementing compute() is unnecessary. To create a deformer, derive from this class and override the deform() method as demonstrated in the "offsetNode.cpp" example plug-in. The other methods of the parent class MPxNode may also be overridden to perform standard dependency node capabilities.

When implementing the compute method for a deformer, another consideration is that the input geometry attribute is not cached. This means that all of the inputs will evaluate each time MDataBlock::inputArrayValue is called on "inputGeom". If you only want a single inputGeometry, you can prevent unneeded evaluations by avoiding calls to MDataBlock.inputArrayValue. For example, use the technique shown in the above example or use MDataBlock::outputArrayValue.

+ Examples:
+ Inheritance diagram for MPxGeometryFilter:

Public Types

enum  DeformationDetails { kDeformsUVs = (1<<1), kDeformsColors = (1<<2) }
 Deformation details. More...
 
- Public Types inherited from MPxNode
enum  Type {
  kDependNode, kLocatorNode, kDeformerNode, kManipContainer,
  kSurfaceShape, kFieldNode, kEmitterNode, kSpringNode,
  kIkSolverNode, kHardwareShader, kHwShaderNode, kTransformNode,
  kObjectSet, kFluidEmitterNode, kImagePlaneNode, kParticleAttributeMapperNode,
  kCameraSetNode, kConstraintNode, kManipulatorNode, kMotionPathNode,
  kClientDeviceNode, kThreadedDeviceNode, kAssembly, kSkinCluster,
  kGeometryFilter, kBlendShape, kLast
}
 Defines the type of node. More...
 
enum  SchedulingType {
  kParallel, kSerial, kGloballySerial, kUntrusted,
  kDefaultScheduling = kSerial
}
 Defines the degree of parallelism of a node. More...
 

Public Member Functions

 MPxGeometryFilter ()
 Class constructor.
 
virtual ~MPxGeometryFilter ()
 Class destructor.
 
virtual MPxNode::Type type () const
 This method returns the type of the node. More...
 
virtual MStatus deform (MDataBlock &block, MItGeometry &iter, const MMatrix &mat, unsigned int multiIndex)
 This method performs the deformation algorithm. More...
 
virtual MObjectaccessoryAttribute () const
 This method returns an MObject for the attribute to which an accessory shape is connected. More...
 
virtual MStatus accessoryNodeSetup (MDagModifier &cmd)
 This method is called by the "deformer -type" command when your node is specified. More...
 
void setUseExistingConnectionWhenSetEditing (bool state)
 This method allows the plugin node to request special treatment during set editing. More...
 
MStatus setDeformationDetails (unsigned int flags)
 This method allows the plug-in node to inform the system that it intends to deform components other than just positions. More...
 
unsigned int getDeformationDetails (MStatus *ReturnStatus=NULL)
 Retrieves the value set by setDeformationDetails(). More...
 
virtual void setModifiedCallback (MSelectionList &list, bool listAdded)
 This callback method can be overriden and is called whenever the set this deformer is operating on is modified. More...
 
- Public Member Functions inherited from MPxNode
 MPxNode ()
 Constructor. More...
 
virtual ~MPxNode ()
 Destructor.
 
virtual void postConstructor ()
 Post constructor. More...
 
virtual MStatus compute (const MPlug &plug, MDataBlock &dataBlock)
 This method should be overridden in user defined nodes. More...
 
virtual bool getInternalValueInContext (const MPlug &plug, MDataHandle &dataHandle, MDGContext &ctx)
 This method is overridden by nodes that store attribute data in some internal format. More...
 
virtual bool setInternalValueInContext (const MPlug &plug, const MDataHandle &dataHandle, MDGContext &ctx)
 This method is overridden by nodes that store attribute data in some internal format. More...
 
virtual bool getInternalValue (const MPlug &plug, MDataHandle &dataHandle)
 This method is obsolete. More...
 
virtual bool setInternalValue (const MPlug &plug, const MDataHandle &dataHandle)
 This method is obsolete. More...
 
virtual int internalArrayCount (const MPlug &plug, const MDGContext &ctx) const
 This method is overridden by nodes that have internal array attributes which are not stored in Maya's datablock. More...
 
virtual void copyInternalData (MPxNode *)
 This method is overridden by nodes that store attribute data in some internal format. More...
 
virtual MStatus legalConnection (const MPlug &plug, const MPlug &otherPlug, bool asSrc, bool &isLegal) const
 This method allows you to check for legal connections being made to attributes of this node. More...
 
virtual MStatus legalDisconnection (const MPlug &plug, const MPlug &otherPlug, bool asSrc, bool &isLegal) const
 This method allows you to check for legal disconnections being made to attributes of this node. More...
 
virtual MStatus setDependentsDirty (const MPlug &plug, MPlugArray &plugArray)
 This method can be overridden in user defined nodes to specify which plugs should be set dirty based upon an input plug {plugBeingDirtied} which Maya is marking dirty. More...
 
virtual MStatus preEvaluation (const MDGContext &context, const MEvaluationNode &evaluationNode)
 Prepare a node's internal state for threaded evaluation. More...
 
virtual MStatus postEvaluation (const MDGContext &context, const MEvaluationNode &evaluationNode, PostEvaluationType evalType)
 Clean up node's internal state after threaded evaluation. More...
 
virtual SchedulingType schedulingType () const
 When overridden this method controls the degree of parallelism supported by the node during threaded evaluation. More...
 
virtual MStatus connectionMade (const MPlug &plug, const MPlug &otherPlug, bool asSrc)
 This method gets called when connections are made to attributes of this node. More...
 
virtual MStatus connectionBroken (const MPlug &plug, const MPlug &otherPlug, bool asSrc)
 This method gets called when connections are broken with attributes of this node. More...
 
virtual MStatus dependsOn (const MPlug &plug, const MPlug &otherPlug, bool &depends) const
 This method may be overridden by the user defined node. More...
 
virtual bool isPassiveOutput (const MPlug &plug) const
 This method may be overridden by the user defined node if it wants to provide output attributes which do not prevent value modifications to the destination attribute. More...
 
virtual MStatus shouldSave (const MPlug &plug, bool &isSaving)
 This method may be overridden by the user defined node. More...
 
virtual MPlug passThroughToOne (const MPlug &plug) const
 This method may be overridden by nodes that have a one-to-one relationship between an input attribute and a corresponding output attribute. More...
 
virtual bool passThroughToMany (const MPlug &plug, MPlugArray &plugArray) const
 This method is overridden by nodes that want to control the traversal behavior of some Maya search algorithms which traverse the history/future of shape nodes looking for directly related nodes. More...
 
virtual bool isAbstractClass () const
 Override this class to return true if this node is an abstract node. More...
 
virtual MStringArray getFilesToArchive (bool shortName=false, bool unresolvedName=false, bool markCouldBeImageSequence=false) const
 Use this method to return all external files used by this node. More...
 
virtual void getExternalContent (MExternalContentInfoTable &table) const
 Returns the external content (files) that this node depends on. More...
 
bool addExternalContentForFileAttr (MExternalContentInfoTable &table, const MObject &attr) const
 Adds content info to the specified table from a file path attribute. More...
 
bool setExternalContentForFileAttr (const MObject &attr, const MExternalContentLocationTable &table)
 Sets content info in the specified attribute from the table. More...
 
virtual void setExternalContent (const MExternalContentLocationTable &table)
 Changes the location of external content in batch. More...
 
virtual MTypeId typeId () const
 Returns the TYPEID of this node. More...
 
virtual MString typeName () const
 Returns the type name of this node. More...
 
virtual MString name () const
 Returns the name of this particular instance of this class. More...
 
virtual MObject thisMObject () const
 Returns the MObject associated with this user defined node. More...
 
virtual MStatus setExistWithoutInConnections (bool flag)
 This method specifies whether or not the node can exist without input connections. More...
 
virtual bool existWithoutInConnections (MStatus *ReturnStatus=NULL) const
 Determines whether or not this node can exist without input connections. More...
 
virtual MStatus setExistWithoutOutConnections (bool flag)
 This method specifies whether or not the node can exist without output connections. More...
 
virtual bool existWithoutOutConnections (MStatus *ReturnStatus=NULL) const
 Determines whether or not this node can exist without output connections. More...
 

Static Public Member Functions

static const char * className ()
 Returns the name of this class. More...
 
- Static Public Member Functions inherited from MPxNode
static MStatus addAttribute (const MObject &attr)
 This method adds a new attribute to a user defined node type during the type's initialization. More...
 
static MStatus inheritAttributesFrom (const MString &parentClassName)
 This method allows a class of plugin node to inherit all of the attributes of a second class of plugin node. More...
 
static MStatus attributeAffects (const MObject &whenChanges, const MObject &isAffected)
 This method specifies that a particular input attribute affects a specific output attribute. More...
 
static const char * className ()
 Returns the name of this class. More...
 

Static Public Attributes

static MObject input
 input attribute, multi
 
static MObject inputGeom
 input geometry attribute
 
static MObject groupId
 input group id attribute
 
static MObject outputGeom
 geometry output attribute
 
static MObject envelope
 envelope attribute
 
- Static Public Attributes inherited from MPxNode
static MObject message
 message attribute
 
static MObject isHistoricallyInteresting
 is historically interesting attribute
 
static MObject caching
 caching attribute
 
static MObject state
 state attribute
 
static MObject frozen
 frozen attribute
 

Additional Inherited Members

- Protected Member Functions inherited from MPxNode
virtual MDataBlock forceCache (MDGContext &ctx=MDGContext::fsNormal)
 USE _forceCache() IN SCRIPT. More...
 
virtual void setMPSafe (bool flag)
 USE _setMPSafe() IN SCRIPT. More...
 
virtual MStatus setDoNotWrite (bool flag)
 USE _setDoNotWrite() IN SCRIPT. More...
 
virtual bool doNotWrite (MStatus *ReturnStatus=NULL) const
 USE _doNotWrite() IN SCRIPT. More...
 

Member Enumeration Documentation

Deformation details.

Enumerator
kDeformsUVs 

The deformer will deform UVs.

kDeformsColors 

The deformer will deform colors.

Member Function Documentation

MPxNode::Type type ( ) const
virtual

This method returns the type of the node.

This method should not be overridden by the user. It will return MPxNode::kGeometryFilter.

Returns
The type of node

Reimplemented from MPxNode.

Reimplemented in MPxBlendShape, MPxSkinCluster, and MPxDeformerNode.

MStatus deform ( MDataBlock block,
MItGeometry iterator,
const MMatrix matrix,
unsigned int  multiIndex 
)
virtual

This method performs the deformation algorithm.

A status code of MS::kSuccess should be returned unless there was a problem during the deformation, such as insufficient memory or required input data is missing or invalid.

NOTE: the geometry iterator passed to this method is in local space and not world space. To convert points to world space use the matrix that is suppied.

Parameters
[in]blockthe node's datablock.
[in]iteratoran iterator for the current geometry being deformed.
[in]matrixthe geometry's world space transformation matrix.
[in]multiIndexthe index corresponding to the requested output geometry.
Returns
Status code
Status Codes:
+ Examples:
MObject & accessoryAttribute ( ) const
virtual

This method returns an MObject for the attribute to which an accessory shape is connected.

If the accessory shape is deleted, the deformer node will automatically be deleted.

If your node has no associated shape, there is no need to override this method.

Returns
The accessory attribute
+ Examples:
MStatus accessoryNodeSetup ( MDagModifier cmd)
virtual

This method is called by the "deformer -type" command when your node is specified.

This method can be used to create and attach accessory nodes if your plugin node requires them. To do so, override this method, and provide the creation and attachment commands to the MDagModifier that is passed as input to the method.

If your node has no associated nodes, there is no need to override this method.

Parameters
[in]cmdthe dag modifier to which the method will add commands
Returns
Status code
+ Examples:
void setUseExistingConnectionWhenSetEditing ( bool  state)

This method allows the plugin node to request special treatment during set editing.

It controls the connection behavior if all of a geometry's points are removed from the deformer set, and then points are subsequently added back in to the set again. By default, Maya will reconnect the deformer to the shape using a new input/output index. If this method is called in the custom deformer's postConstructor method and the state is set to true, the deformer will attempt to use the original input/output index when reconnecting to the shape.

Parameters
[in]statewhether or not to use the existing connection
MStatus setDeformationDetails ( unsigned int  flags)

This method allows the plug-in node to inform the system that it intends to deform components other than just positions.

It should typically be called in advance of any deformation taking place (e.g. in postConstructor()), not in the deform() method. If it is called from deform(), the setting will take effect the next time the DG causes the deformation to be calculated.

Parameters
[in]flagsBitwise OR of flags from the DeformationDetails enum
Returns
Status code
Status Codes:
unsigned int getDeformationDetails ( MStatus ReturnStatus = NULL)

Retrieves the value set by setDeformationDetails().

See the documentation of that method for the interpretation of the value.

Parameters
[out]ReturnStatusStatus code.
Returns
The deformation details
Status Codes:
void setModifiedCallback ( MSelectionList list,
bool  listAdded 
)
virtual

This callback method can be overriden and is called whenever the set this deformer is operating on is modified.

It passes in a selection list of items that are either being added/removed.

Parameters
[in]listlist of items added/removed
[in]listAddedwhether the list is being added or removed to the set.
const char * className ( )
static

Returns the name of this class.

Returns
The name of this class.

The documentation for this class was generated from the following files:
  • MPxGeometryFilter.h
  • MPxGeometryFilter.cpp