- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Examples

- Class List
- Class Hierarchy
- Class Members

Public Types | Public Member Functions

# MPxPolyTrg Class Reference
OpenMaya - API module for common classes | Proxy classes

This reference page is linked to from the following overview topics: Overview of example plug-ins, Example C++ plug-in descriptions.

Search for all occurrences

## Detailed Description

User defined poly triangulation support.

MPxPolyTrg is the the parent class for nodes which define a custom face triangulation for meshes. In order to override default maya triangulation, the user has to do the following things:

- Derive a new node from MPxPolyTrg class.

- Define a static function on the new node to triangulate a single face in the mesh. The signature of this function is given by polyTrgFnct type. The input to the triangulation function is:

  - *vert - pointer to an array of vertex positions for the face. It size is 3*nbVertices.
  - *norm - pointer to an array of per vertex normals for the face. It size is 3*nbVertices.
  - *loopSizes - pointer to an array of loop sizes. The size of this array is nbLoops
  - nbLoops - number of loops in the face.
  - nbTrg - expected number of triangles to be generated.

  Note: The number of vertices can be calculated by adding all the loop sizes.

  The output of this function is an array of triangle description:

  - *trg - pointer to an integer array. This array is already allocated with the size of 3*nbTrg. It has to be filled with the triangle descriptions given by the face-relative position of vertices i.e.

    nbTrg = 2 trg: 0 1 2 2 3 0

    Tip: Refer to the example plugin: polyTrgNode for more details on how to implement it.

- Register that function when the node is created for the first time (in the postConstructor() method) by calling the registerTrgFunction().

- Unregister the function in the destructor by calling the unregisterTrgFunction.

Once the node is defined, the user has to inform the mesh about it. For each mesh the user wants to override the default triangulation, he has to set the usertTrg attribute on the mesh to the name under which the function has been registered.

Example: /code setAttr mesh.userTrg -type "string" "triangulate"; /endcode

Once that attribute is set, the default maya triangulation is turned off and the one provided by the user is used to draw the mesh.

Examples:

  polyTrgNode.cpp.

`#include <MPxPolyTrg.h>`

Inheritance diagram for MPxPolyTrg:
[legend]

List of all members.

## Public Types
typedef void(* | polyTrgFnct )(const float *vert, const float *norm, const int *loopSizes, const int nbLoop, const int nbTrg, unsigned short *trg)
| Pointer to a function which triangulates a poly face.
## Public Member Functions
| MPxPolyTrg ()
| Constructor. Search for all occurrences
virtual | ~MPxPolyTrg ()
| Destructor.
virtual void | postConstructor ()
| Post constructor.
virtual MStatus | compute (const MPlug &plug, MDataBlock &dataBlock)
| This method should be overridden in user defined nodes.
virtual bool | isAbstractClass () const
| Each new node has to implement that fuction.
MStatus | registerTrgFunction (char *name, polyTrgFnct f)
| Register a triangulation function with maya.
MStatus | unregisterTrgFunction (char *name)

## Constructor & Destructor Documentation

MPxPolyTrg | ( |  | ) |

Constructor.

The constructor should never call any methods from MPxPolyTrg or make any calls that require the existence of the MObject associated with the user defined node. The postConstructor method should be used to do any initialization of this kind.

## Member Function Documentation

void postConstructor | ( |  | ) | `[virtual]`

Search for all occurrences

Post constructor.

Internally maya creates two objects when a user defined node is created, the internal MObject and the user derived object. The association between the these two objects is not made until after the MPxPolyTrg constructor is called. This implies that no MPxPolyTrg member function can be called from the MPxPolyTrg constructor. The postConstructor will get called immediately after the constructor when it is safe to call any MPxPolyTrg member function.

Reimplemented from MPxNode.

Examples:
  polyTrgNode.cpp.

MStatus compute | ( | const MPlug & | plug,
|  | MDataBlock & | block
| ) |  | `[virtual]`

Search for all occurrences

This method should be overridden in user defined nodes.

However, fror this particaular node we don't need to to do anything in the compute functione. Therefore, all we do is return MS:kSuccess in the derive class.

Parameters:

  [in] | plug | plug representing the attribute that needs to be recomputed
  [in] | block | data block containing storage for the node's attributes

Returns:
  Status code

Status Codes:
  - MS::kSuccess Compute was successful
  - MS::kFailure Compute failed

Reimplemented from MPxNode.

Examples:
  polyTrgNode.cpp.

bool isAbstractClass | ( |  | ) | const`[virtual]`

Search for all occurrences

Each new node has to implement that fuction.

It returns false since this is not an abstract class.

Returns:
  False

Reimplemented from MPxNode.

Examples:
  polyTrgNode.cpp.

MStatus registerTrgFunction | ( | char * | functName,
|  | polyTrgFnct | funct
| ) |  |

Search for all occurrences

Register a triangulation function with maya.

The name provided as a first argument is the name under which the function is registered. This name has to be used when setting 'userTrg' attribute on a mesh.

Parameters:

  [in] | functName | Function name under which the function is register with maya.
  [in] | funct | Pointer to the static function which implement a face triangulation.

Returns:
  Status code

Status Codes:
  - MS::kSuccess Compute was successful
  - MS::kFailure Compute failed

MStatus unregisterTrgFunction | ( | char * | functName | ) |

Search for all occurrences

Parameters:

  [in] | functName | Function name under which the function is register with maya.

Returns:
  Status code

Status Codes:
  - MS::kSuccess Compute was successful
  - MS::kFailure Compute failed

MPxPolyTrg MPxPolyTrg MPxPolyTrg MPxPolyTrg MPxPolyTrg MPxPolyTrg MPxPolyTrg MPxPolyTrg MPxPolyTrg MPxPolyTrg
MPxPolyTrg MPxPolyTrg MPxPolyTrg MPxPolyTrg MPxPolyTrg MPxPolyTrg MPxPolyTrg MPxPolyTrg MPxPolyTrg MPxPolyTrg