Public Types | Public Member Functions | Public Attributes | Protected Attributes

ObjectWrapper Class Reference

Search for all occurrences

Detailed Description

See also:
Class Mesh, Class MNMesh, Class PatchMesh
Description:
ObjectWrapper providing a common interface to Mesh, MNMesh, and PatchMesh objects.
All methods of this class are implemented by the system.

The ObjectWrapper provides a common interface to three common classes of geometry objects, Mesh, MNMesh and PatchMesh, and is helpful when writing reusable code that is not type-dependant. Specifically, the ObjectWrapper is intended for use in Modifier plug-ins, when a developer wants to avoid writing three versions of code for the three object types. Note that objects of other types, such as NURBS and Particle Systems, are not directly supported by the ObjectWrapper, although the wrapper can attempt to convert them to a supported type.

The ObjectWrapper defines an abstracted concept of vertices, faces, and edges. Vertices are defined as points in space; for PatchMesh objects, these are the patch knots. Faces are defined as either triangles, polygons or patches, according to the object type. For MNMesh objects, no access is provided to the flag values of the vertices. For PatchMesh objects, no access is provided to the patch handles; methods which set the position of a vertex will move the patch knot and attempt to maintain the position of the handles relative to the knot.

ObjectWrappers do not have a class ID or a class descriptor, and are not part of the reference hierarchy. They can be instantiated like primitive types using new() and delete(). The Init() method assigns a specific object to the wrapper after the wrapper is created.

Note that using ObjectWrappers may incur a small performance penalty, because every method of the class must branch into the appropriate type-specific method, and is therefore slower than calling type-specific methods directly.

#include <ObjectWrapper.h>

Inheritance diagram for ObjectWrapper:
Inheritance graph
[legend]

List of all members.

Public Types

enum   { empty = 0, triObject, polyObject, patchObject }
 

The type of the underlying object, triObject for Mesh, polyObject for MNMesh, and patchObject for PatchMesh.

More...
enum   {
  noneEnable = 0, triEnable = 1, polyEnable = 2, patchEnable = 4,
  allEnable = 0x7
}
enum   { iv_none = 0x000, iv_verts = 0x001, iv_faces = 0x002, iv_edges = 0x004 }
enum   { SEL_OBJECT, SEL_VERT, SEL_FACE, SEL_ELEM }
 

Selection enum values.

More...
enum   { SUBHIT_IGNOREBACKFACING = (1<<5) }

Public Member Functions

CoreExport  ObjectWrapper ()
  Constructor. The wrapper is set to an empty, uninitialized state.
CoreExport  ~ObjectWrapper ()
  Destructor. Calls the Release() method to free any memory used by the wrapper.
CoreExport void  Zero ()
  For internal use only.
CoreExport BOOL  Init (TimeValue t, ObjectState &os, BOOL copy=FALSE, int enable=allEnable, int nativeType=polyObject)
CoreExport void  Release ()
CoreExport BOOL  IsEmpty ()
CoreExport int  Type ()
CoreExport Mesh GetTriMesh ()
CoreExport MNMesh GetPolyMesh ()
CoreExport PatchMesh GetPatchMesh ()
CoreExport void  Invalidate (int iInvalid)
CoreExport void  InvalidateGeomCache ()
CoreExport int  NumVerts ()
CoreExport int  NumFaces ()
CoreExport int  NumEdges ()
CoreExport Point3 Verts ()
CoreExport GenFace Faces ()
CoreExport GenEdge Edges ()
CoreExport Point3 GetVert (int index)
CoreExport void  SetVert (int index, Point3 &p)
CoreExport void  SetNumVerts (int num)
CoreExport GenFace  GetFace (int index)
CoreExport void  SetFace (int index, GenFace &face)
CoreExport void  SetNumFaces (int num)
CoreExport GenEdge  GetEdge (int index)
CoreExport int  NumFaceEdges (int faceIndex)
CoreExport int  GetFaceEdgeIndex (int faceIndex, int edgeIndex)
CoreExport void  GetVertexSpace (int index, Matrix3 &tm)
CoreExport Point3 GetVertexNormal (int index)
CoreExport BOOL  GetFaceHidden (int faceIndex)
CoreExport void  SetFaceHidden (int faceIndex, BOOL hidden)
CoreExport BOOL  GetChannelSupport (int mapChannel)
CoreExport void  SetChannelSupport (int mapChannel, BOOL b)
CoreExport int  NumMapVerts (int channel)
CoreExport void  SetNumMapVerts (int channel, int num)
CoreExport Point3 GetMapVert (int channel, int index)
CoreExport void  SetMapVert (int channel, int index, Point3 &p)
CoreExport GenFace  GetMapFace (int channel, int index)
CoreExport void  SetMapFace (int channel, int index, GenFace &face)
CoreExport MtlID  GetMtlID (int index)
CoreExport void  SetMtlID (int index, MtlID mtlID)
CoreExport DWORD  GetSmoothingGroup (int index)
CoreExport void  SetSmoothingGroup (int index, DWORD smGrp)
CoreExport int  GetSelLevel ()
CoreExport void  SetSelLevel (int selLevel)
CoreExport BitArray GetVertSel ()
CoreExport void  SetVertSel (BitArray &)
CoreExport BitArray GetFaceSel ()
CoreExport void  SetFaceSel (BitArray &sel)
CoreExport BitArray GetElemSel ()
CoreExport void  SetElemSel (BitArray &sel)
CoreExport BitArray GetSel (int selLevel)
CoreExport void  SetSel (int selLevel, BitArray &sel)
CoreExport void  FaceToElemSel (BitArray &elemSel, BitArray &faceSel)
  Converts the bits representing a face selection into bits representing an element selection, and expands the selection accordingly.
CoreExport void  GrowSelection (int selLevel, BitArray &newSel)
CoreExport void  ShrinkSelection (int selLevel, BitArray &newSel)
CoreExport void  GetSoftSel (GenSoftSelData &softSelData)
CoreExport void  SetSoftSel (GenSoftSelData &softSelData)
CoreExport void  UpdateSoftSel ()
CoreExport float *  SoftSelWeights ()
CoreExport Point3  SoftSelColor (float f)
CoreExport BOOL  SubObjectHitTest (int selLevel, GraphicsWindow *gw, Material *ma, HitRegion *hr, DWORD flags, HitListWrapper &hitList, int numMat=1, Matrix3 *mat=NULL)
CoreExport int  IntersectRay (Ray &ray, float &intersectAt, Point3 &norm, int &fi, FloatTab &bary)
CoreExport void  Render (GraphicsWindow *gw, Material *ma, RECT *rp, int compFlags, int numMat=1)
CoreExport int  SelLevel (int selLevel)
CoreExport int  HitLevel (int selLevel)

Public Attributes

enum ObjectWrapper:: { ... }   type
Mesh mesh
MNMesh poly
PatchMesh patch
MeshTempData meshTempData
MNTempData polyTempData

Protected Attributes

TimeValue  t
union {
   Mesh *   mesh
   MNMesh *   poly
   PatchMesh *   patch
}; 
union {
   MeshTempData *   meshTempData
   MNTempData *   polyTempData
}; 
BOOL  isCopy
Point3 verts
GenFace faces
GenEdge edges
GeomObject collapsedObj
BitArray  faceSel
BitArray  vertSel
GenSoftSelData  softSelData
int  invalidMask

Member Enumeration Documentation

anonymous enum

The type of the underlying object, triObject for Mesh, polyObject for MNMesh, and patchObject for PatchMesh.

Enumerator:
empty 
triObject 
polyObject 
patchObject 
anonymous enum
anonymous enum
anonymous enum

Selection enum values.

Enumerator:
SEL_OBJECT 

indicates the object selection level.

SEL_VERT 

indicates the face selection level.

SEL_FACE 

indicates the vertex selection level.

SEL_ELEM 

indicates the element selection level.

             {
            SEL_OBJECT, 
            SEL_VERT, 
            SEL_FACE,
            SEL_ELEM
        }; //selection enum values
anonymous enum
Enumerator:
SUBHIT_IGNOREBACKFACING 
{ SUBHIT_IGNOREBACKFACING=(1<<5) }; //other SUBHIT_... values defined in Mesh.h are also supported

Constructor & Destructor Documentation

CoreExport ObjectWrapper ( )

Constructor. The wrapper is set to an empty, uninitialized state.

CoreExport ~ObjectWrapper ( ) [inline]

Destructor. Calls the Release() method to free any memory used by the wrapper.

{Release();}

Member Function Documentation

CoreExport void Zero ( )

For internal use only.

CoreExport BOOL Init ( TimeValue  t,
ObjectState os,
BOOL  copy = FALSE,
int  enable = allEnable,
int  nativeType = polyObject 
)
Remarks:
Assign an object to the ObjectWrapper. If the object is not a supported type (specified by the enable flags), it will be converted, and a copy of the converted object is held internally.
Parameters:
t - The current slider time
os - The object
copy - True to make a duplicate of the object, False otherwise
enable - Flags indicating which types should be supported. The object will be converted to the native type (and a copy maintained) unless it is one of these supported types. For Mesh objects, set the bit ObjectWrapper::triEnable. For MNMesh objects, set the bit ObjectWrapper::polyEnable. For Patch objects, set the bit ObjectWrapper::patchEnable.
nativeType - Indicates which type to convert to, if the object is not already a supported type. For Mesh, pass ObjectWrapper::triObject. For MNMesh, pass ObjectWrapper::polyObject. For PatchMesh, pass ObjectWrapper::patchObject.
Returns:
True if the operation succeeds, False otherwise.
CoreExport void Release ( )
Remarks:
Release internal data, and reset to an empty state. If the underlying object was copied or converted to a different type by the Init() method, then the ObjectWrapper maintains a copy internally, consuming a significant amount of memory. Calling this method is important to free the internal copy.
CoreExport BOOL IsEmpty ( ) [inline]
Remarks:
Indicates whether the wrapper is currently empty
Returns:
True if no object is assigned to the wrapper, False otherwise
{return type==empty;}
CoreExport int Type ( ) [inline]
Remarks:
Indicates the type of the underlying object
Returns:
For Mesh, returns ObjectWrapper::triObject. For MNMesh, returns ObjectWrapper::polyObject. For PatchMesh, returns ObjectWrapper::patchObject.
{return type;}
CoreExport Mesh* GetTriMesh ( ) [inline]
Remarks:
Returns the Mesh object pointer, or NULL if the underlying object is not type Mesh
{return type==triObject? mesh:NULL;}
CoreExport MNMesh* GetPolyMesh ( ) [inline]
Remarks:
Returns the Mesh object pointer, or NULL if the underlying object is not type MNMesh
{return type==polyObject? poly:NULL;}
CoreExport PatchMesh* GetPatchMesh ( ) [inline]
Remarks:
Returns the PatchMesh object pointer, or NULL if the underlying object is not type PatchMesh
{return type==patchObject? patch:NULL;}
CoreExport void Invalidate ( int  iInvalid )
Remarks:
Clear the validity mask for verts, faces, or edges. The validity mask applies when calling the methods Verts(), Faces() and Edges(). These methods maintain internal copies of data from the underlying object. Clearing the validity flags ensures that the next call to one of these methods will allocate a new, updated list instead of returning a stale list. The validity flag for a channel should be cleared whenever the channel is modifier. However, ObjectWrapper methods will mark the flags automatically, so it is not necessary to call this method unless the underlying object is being modified outside of the ObjectWrapper.
Parameters:
iInvalid - The validity flags to clear. To clear the vertex channel, pass ObjectWrapper::iv_verts. To clear the face channel, pass ObjectWrapper::iv_faces. To clear the edge channel, pass ObjectWrapper::iv_edges.
CoreExport void InvalidateGeomCache ( )
Remarks:
Calls the method InvalidateGeomCache() on the underlying object
CoreExport int NumVerts ( )
Remarks:
Returns the number of geometric vertices
CoreExport int NumFaces ( )
Remarks:
Returns the number of geometric faces
CoreExport int NumEdges ( )
Remarks:
Returns the number of geometry edges
CoreExport Point3* Verts ( )
Remarks:
Returns an array of the geometric vertices. Note that this method incurs a memory usage penalty because it allocates an internal cache. If this method is called when the vertex channel has been invalidated, it will update the cache, which incurs an additional performance penalty
CoreExport GenFace* Faces ( )
Remarks:
Returns an array of the geometric faces. Note that this method incurs a memory usage penalty because it allocates an internal cache. If this method is called when the face channel has been invalidated, it will update the cache, which incurs an additional performance penalty.
See also:
Class GenFace
CoreExport GenEdge* Edges ( )
Remarks:
Returns an array of the geometric edges. Note that this method incurs a memory usage penalty because it allocates an internal cache. If this method is called when the edge channel has been invalidated, it will update the cache, which incurs an additional performance penalty.
See also:
Class GenEdge
CoreExport Point3* GetVert ( int  index )
Remarks:
Returns an individual geometric vertex
Parameters:
index - The index of the vertex to retrieve
CoreExport void SetVert ( int  index,
Point3 p 
)
Remarks:
Sets the position of a geometric vertex
Parameters:
index - The index of the vertex to set
p - The position of the vertex
CoreExport void SetNumVerts ( int  num )
Remarks:
Sets the number of geometric verts in the object
Parameters:
num - The vertex count
CoreExport GenFace GetFace ( int  index )
Remarks:
Returns an individual geometric face
Parameters:
index - The index of the face to retrieve
CoreExport void SetFace ( int  index,
GenFace face 
)
Remarks:
Sets the data for geometric face
Parameters:
index - The index of the face to set
face - The data for the face
CoreExport void SetNumFaces ( int  num )
Remarks:
Sets the number of geometric faces in the object
Parameters:
num - The face count
CoreExport GenEdge GetEdge ( int  index )
Remarks:
Returns an individual geometric edge
Parameters:
index - The index of the edge to retrieve
CoreExport int NumFaceEdges ( int  faceIndex )
Remarks:
Returns the number of edges bordering a specified geometric face
Parameters:
faceIndex - The index of the face
CoreExport int GetFaceEdgeIndex ( int  faceIndex,
int  edgeIndex 
)
Remarks:
Returns the index number of an edge bordering a specified geometric face
Parameters:
faceIndex - The index of the face
edgeIndex - The index of the edge relative to the face
CoreExport void GetVertexSpace ( int  index,
Matrix3 tm 
)
Remarks:
For MNMesh objects, this calls MNMesh::GetVertexSpace(). For other types, this calls MatrixFromNormal() on the vertex normal.
Parameters:
index - The index of the vertex
[out] tm - The vertex space matrix
CoreExport Point3* GetVertexNormal ( int  index )
Remarks:
Returns the geometric normal of a vertex
Parameters:
index - The index of the vertex
CoreExport BOOL GetFaceHidden ( int  faceIndex )
CoreExport void SetFaceHidden ( int  faceIndex,
BOOL  hidden 
)
CoreExport BOOL GetChannelSupport ( int  mapChannel )
Remarks:
Returns TRUE if the specified mapping channel is supported; otherwise FALSE.
See also:
List of Mapping Channel Index Values.
Parameters:
mapChannel - The index of the map channel
CoreExport void SetChannelSupport ( int  mapChannel,
BOOL  b 
)
Remarks:
Sets whether the specified mapping channel is supported or not.
See also:
List of Mapping Channel Index Values.
Parameters:
mapChannel - The index of the map channel
b - TRUE to indicate the channel is supported; otherwise FALSE.
CoreExport int NumMapVerts ( int  channel )
Remarks:
Returns the number of texture or vertex color vertices for the specified mapping channel.
Parameters:
channel - The index of the map channel
CoreExport void SetNumMapVerts ( int  channel,
int  num 
)
Remarks:
Sets the number of texture or vertex color vertices for the specified mapping channel.
Parameters:
channel - The index of the map channel
num - The number of vertices to allocate.
CoreExport Point3* GetMapVert ( int  channel,
int  index 
)
Remarks:
Returns a single texture or vertex color value for the specified mapping channel.
Parameters:
channel - The index of the map channel
index - The index of the texture vertex
CoreExport void SetMapVert ( int  channel,
int  index,
Point3 p 
)
Remarks:
Sets a single texture or vertex color value for the specified mapping channel.
Parameters:
channel - The index of the map channel
index - The index of the texture vertex
p - The value to set
CoreExport GenFace GetMapFace ( int  channel,
int  index 
)
Remarks:
Returns an individual texture mapping face for the specified mapping channel
See also:
GenFace
Parameters:
channel - The index of the map channel
index - The index of the texture face
CoreExport void SetMapFace ( int  channel,
int  index,
GenFace face 
)
Remarks:
Sets an individual texture mapping face for the specified mapping channel
See also:
Class GenFace
Parameters:
channel - The index of the map channel
index - The index of the texture face
face - The data for the face
CoreExport MtlID GetMtlID ( int  index )
Remarks:
Returns the zero based material ID for the specified face
Parameters:
index - The index of the face
CoreExport void SetMtlID ( int  index,
MtlID  mtlID 
)
Remarks:
Sets the material ID for the specified face
Parameters:
index - The index of the face
mtlID - The zero based material ID
CoreExport DWORD GetSmoothingGroup ( int  index )
Remarks:
Returns the smoothing group bits for the specified face
Parameters:
index - The index of the face
CoreExport void SetSmoothingGroup ( int  index,
DWORD  smGrp 
)
Remarks:
Sets the smoothing group bits for the specified face
Parameters:
index - The index of the face
smGrp - The smoothing group bits
CoreExport int GetSelLevel ( )
Remarks:
Returns the current level of selection for the object. See the selection enum values above
CoreExport void SetSelLevel ( int  selLevel )
Remarks:
Sets the current level of selection for the object.
Parameters:
selLevel - The selection level. See the selection enum values above
CoreExport BitArray& GetVertSel ( )
Remarks:
Returns the bits representing the vertex selection status
CoreExport void SetVertSel ( BitArray )
Remarks:
Sets the bits representing the vertex selection status
Parameters:
sel - The selection bits
CoreExport BitArray& GetFaceSel ( )
Remarks:
Returns the bits representing the face selection status
CoreExport void SetFaceSel ( BitArray sel )
Remarks:
Sets the bits representing the face selection status
Parameters:
sel - The selection bits
CoreExport BitArray& GetElemSel ( )
Remarks:
Returns the bits representing the element selection status. For all currently supported types, this is identical to the face selection, because the underlying types do not natively support the element selection level.
CoreExport void SetElemSel ( BitArray sel )
Remarks:
Sets the bits representing the element selection status. For all currently supported types, this is identical to setting the face selection, because the underlying types do not natively support the element selection level.
Parameters:
sel - The selection bits
CoreExport BitArray* GetSel ( int  selLevel )
Remarks:
Returns the bits representing the specified selection status
Parameters:
selLevel - The selection level. See the selection enum values above
CoreExport void SetSel ( int  selLevel,
BitArray sel 
)
Remarks:
Returns the bits representing the specified selection status
Parameters:
selLevel - The selection level. See the selection enum values above
sel - The selection bits
CoreExport void FaceToElemSel ( BitArray elemSel,
BitArray faceSel 
)

Converts the bits representing a face selection into bits representing an element selection, and expands the selection accordingly.

If any face in an element is selected according the input bits, then all faces within that element will be toggled as selected in the output bits. This method does not change the selection on the object; the methods SetFaceSel() or SetElemSel() are needed to apply a selection after it is calculated

Parameters:
[out] elemSel - The output selection bits for the element level
faceSel - The input selection bits for the face level
CoreExport void GrowSelection ( int  selLevel,
BitArray newSel 
)
Remarks:
Grows the selection for the specified level. The perimeter of the selection is expanded by one sub object. The resulting selection is stored in the output bits; This method does not change the selection on the object
Parameters:
selLevel - The selection level. See the selection enum values above
[out] newSel - The output selection bits
CoreExport void ShrinkSelection ( int  selLevel,
BitArray newSel 
)
Remarks:
Shrinks the selection for the specified level. The perimeter of the selection is reduced by one sub object. The resulting selection is stored in the output bits; This method does not change the selection on the object
Parameters:
selLevel - The selection level. See the selection enum values above
[out] newSel - The output selection bits
CoreExport void GetSoftSel ( GenSoftSelData softSelData )
Remarks:
Returns the soft selection parameters
See also:
GenSoftSelData
Parameters:
[out] softSelData - The selection parameters
CoreExport void SetSoftSel ( GenSoftSelData softSelData )
Remarks:
Sets the soft selection parameters. Note that UpdateSoftSel() may be needed to recalculate the soft selection weights.
See also:
GenSoftSelData
Parameters:
softSelData - The selection parameters
CoreExport void UpdateSoftSel ( )
Remarks:
Recalculates the soft selection weights. Use this after setting the soft selection parameters.
CoreExport float* SoftSelWeights ( )
Remarks:
Returns the vertex soft selection weights. If cached, the cache is returned. Otherwise a cache is allocated and computed from the current object and the soft selection parameters.
CoreExport Point3 SoftSelColor ( float  f )
Remarks:
Returns the viewport display color corresponding to the given vertex soft selection weight.
Parameters:
f - The selection weight, ranging from 0 to 1
CoreExport BOOL SubObjectHitTest ( int  selLevel,
GraphicsWindow gw,
Material ma,
HitRegion hr,
DWORD  flags,
HitListWrapper hitList,
int  numMat = 1,
Matrix3 mat = NULL 
)
Remarks:
Performs a viewport hit testing operation against the object
Parameters:
gw - The graphics window associated with the viewport the object is being hit tested in.
ma - The list of materials for the mesh
hr - This describes the properties of a region used for the hit testing. See Class HitRegion.
flags - Flags specifying how the hit testing is performed. Accepted values are SUBHIT_IGNOREBACKFACING to specify the ignore backfacing mode, plus the following values defined in Mesh.h: SUBHIT_UNSELONLY, SUBHIT_ABORTONHIT, SUBHIT_SELSOLID, and SUBHIT_USEFACESEL
[out] hitList - The hit list object to hold the results of the hit test operation. See Class HitListWrapper.
numMat - The number of materials for the mesh.
mat - The object-to-world transform matrix for the object. This needed to calculate backface culling if the underlying object is type Mesh and the flag ObejctWrapper:: SUBHIT_IGNOREBACKFACING is specified return TRUE if any hits were found, FALSE otherwise
CoreExport int IntersectRay ( Ray ray,
float &  intersectAt,
Point3 norm,
int &  fi,
FloatTab bary 
)
Remarks:
Intersects a ray against the object, returning the face and barycentric coordinates of the hit point.
Parameters:
ray - The ray to cast
[out] intersectAt - The distance travelled by the ray to the intersection point.
[out] norm - The surface normal at the intersection point.
[out] fi - The face index of the intersected face
[out] bary - The barycentric coordinates of the hit point. For MNMesh and PatchMesh object, there may be more than three coordinate values return Nonzero if an intersection was found, zero otherwise
CoreExport void Render ( GraphicsWindow gw,
Material ma,
RECT *  rp,
int  compFlags,
int  numMat = 1 
)
Remarks:
Renders the object using the specified graphics window and array of materials.
Parameters:
gw - Points to the graphics window to render to.
ma - The list of materials to use to render the mesh.
rp - Specifies the rectangular region to render. If the mesh should be rendered to the entire viewport pass NULL
compFlags - One or more of the following flags defined in Mesh.h: COMP_TRANSFORM, COMP_IGN_RECT, COMP_LIGHTING, COMP_ALL or COMP_OBJSELECTED
numMat - The number of materials for the mesh
CoreExport int SelLevel ( int  selLevel )
Remarks:
Converts the ObjectWrapper selection level enum values into the type-specific equivalents. For instance, an input of ObjectWrapper::SEL_VERT (integer value 1) would return MESH_VERTEX (integer value 2) if the underlying object was type Mesh.
CoreExport int HitLevel ( int  selLevel )
Remarks:
Converts the ObjectWrapper hit level enum values into the type-specific equivalents. For instance, an input of ObjectWrapper::SEL_VERT (integer value 1) would return SUBHIT_VERTS (integer value 1<< 25) if the underlying object was type Mesh.

Member Data Documentation

TimeValue t [protected]
union { ... } [protected]
union { ... } [protected]
BOOL isCopy [protected]
Point3* verts [protected]
GenFace* faces [protected]
GenEdge* edges [protected]
GeomObject* collapsedObj [protected]
BitArray faceSel [protected]
BitArray vertSel [protected]
int invalidMask [protected]
enum { ... } type

ObjectWrapper ObjectWrapper ObjectWrapper ObjectWrapper ObjectWrapper ObjectWrapper ObjectWrapper ObjectWrapper ObjectWrapper ObjectWrapper
ObjectWrapper ObjectWrapper ObjectWrapper ObjectWrapper ObjectWrapper ObjectWrapper ObjectWrapper ObjectWrapper ObjectWrapper ObjectWrapper