MGeometryManager Class Reference
[OpenMayaRender - API module for rendering]

#include <MGeometryManager.h>

List of all members.

Detailed Description

Geometry cache management.

This class provides methods for managing MGeometry resources.

It provides an interface for loading and using hardware textures.

Public Types

enum   GeometricShape { kDefaultSphere = 0, kDefaultPlane, kDefaultCube }
  Default geometry shapes. More...

Static Public Member Functions

static MGeometry  getGeometry (const MDagPath &shape, const MGeometryRequirements &requirements, MObject *components=NULL)
static MGeometryList referenceDefaultGeometry (const MGeometryManager::GeometricShape geomShape, const MGeometryRequirements &requirements)
static MStatus  dereferenceDefaultGeometry (MGeometryList *data)

Member Enumeration Documentation

Default geometry shapes.

kDefaultSphere  Sphere with radius 1, centered at 0,0,0.
kDefaultPlane  Plane with width and height of 1, centered at 0,0,0. Assuming "Y-Up" orientation: width = x-axis, and height = y-axis.
kDefaultCube  Cube with width, height and depth of 1, centered at 0,0,0.

Member Function Documentation

MGeometry MGeometryManager::getGeometry ( const MDagPath shape,
const MGeometryRequirements requirements,
MObject components = NULL  
) [static]

Access the Geometry cache for a shape.

[in]  shape  the surface
[in]  requirements  the surface data you want in the cache. Attempting to access cache data not included in the requirements will fail.
[in]  components  an optional component group, for accessing a sub-selection of faces (e.g. the faces assigned to a material)
The cached geometry.

MGeometryList * MGeometryManager::referenceDefaultGeometry ( const MGeometryManager::GeometricShape  geomShape,
const MGeometryRequirements requirements  
) [static]

Obtain a reference to geometry for some "default" shapes maintained by the manager such that the geometry returned will match a set of geometric requirements (MGeometryRequirements). The actual form is a geometric iterator (MGeometryList), which can be used to iterate over the internal data kept (MGeometry).

Note that all data is assumed to be "read-only", as the data is not owned by the caller. To maintain proper reference counting of internal data, the user must "deference" the data when no longer using it via the MGeometryManager::dereferenceGeometry() calls. It is recommended to immediately dereference the data after each use. There is negligable overhead to reference and dereference data in this manner.

Available default shapes include:

  • A polygonal sphere : Sphere has radius of 1 and is centered at the origin (0,0,0) in object space.
  • A polygonal cube : Cube has dimensions of 1 and is centered at the origin (0,0,0) in object space.
  • A polygonal plane : Plane has dimensions of 1 is centered at the origin (0,0,0) in object space. Assuming "Y-Up" orientation, the width is the along the x-axis and the height is along the y-axis.
The following is an example usage via a hardware shader plugin for swatch rendering:
                // Set up a NULL path
                MDagPath path;

                // Get the requirements from the hardware shader
                MGeometryRequirements requirements;
                populateRequirements(path, requirements);

                // Ask for a default sphere
                MGeometryManager::GeometricShape shape = MGeometryManager::kDefaultSphere;
                MGeometryList* geomIter = MGeometryManager::referenceDefaultGeometry(shape, requirements);

                if(geomIter == NULL) {
                        return MStatus::kFailure;

                // Set up where to draw to ....

                // Now draw using the geometry iterator returned.
                for( ; !geomIter->isDone(); geomIter->next())
                        // Get the current geometry
                        MGeometry& geometry = geomIter->geometry(MGeometryList::kNone);

                        // Get the current object to world matrix
                        const MMatrix& mtm = geomIter->objectToWorldMatrix();


                        // Get some data tro draw
                        MGeometryPrimitive primitives = geometry.primitiveArray(0);
                        const MGeometryData pos = geometry.position();
                        const MGeometryData normal = geometry.normal();

                        if ( != NULL && != NULL)
                                // Set up position and normals for drawing
                                glVertexPointer(3, GL_FLOAT, 0, (float*);

                                if ( {
                                        glNormalPointer(GL_FLOAT, 0,;

                                // Draw with the current indexing structure
                                MGeometryPrimitive primitives = geometry.primitiveArray(0);
                                glDrawElements(GL_TRIANGLES, primitives.elementCount(), GL_UNSIGNED_INT,;

                                if (

                // Now dereference the geometry iterator used.
[in]  geomShape  Desired geometry shape.
[in]  requirements  Geometry requirements (MGeometryRequirements).
  • A pointer to a geometry iterator (MGeometryList), which contains a reference to the geometric data (MGeometry). The MGeometry information which tries to match the requirements passed in. ( e.g. position, normal, texture coordinates, tangents, and binormals etc). It can be assumed that all data is floating point such that:
    • Positions are 3 float (x,y,z) positions
    • Normals are 3 float (x,y,z) vectors.
    • Texture coordinates are 2 float (u,v) tuples.
    • Tangents are 3 float (x,y,z) vectors.
    • Binormals are 3 float (x,y,z) vectors.

MStatus MGeometryManager::dereferenceDefaultGeometry ( MGeometryList geomIterator  )  [static]

This is the companion method to referenceDefaultGeometry() and must always be called immediately after usage of data supplied by the reference call.

This call simply maintains proper internal state for any data used.

[in]  geomIterator  The geometry iterator returned from referenceDefaultGeometry().
MStatus::kSuccess if successfull, otherwise MStatus::kFailure.

Autodesk® Maya® 2011 © 1997-2010 Autodesk, Inc. All rights reserved. Generated with doxygen 1.5.6