Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Ogre::Mesh Class Reference

Resource holding data about 3D mesh. More...

#include <OgreMesh.h>

Inheritance diagram for Ogre::Mesh:

Ogre::Resource List of all members.

Public Types

typedef std::multimap< unsigned
short, VertexBoneAssignment
VertexBoneAssignmentList
 Multimap of vertex bone assignments (orders by vertex index). More...

typedef MapIterator< VertexBoneAssignmentListBoneAssignmentIterator
typedef std::vector< RealLodDistanceList

Public Methods

 Mesh (String name)
 Default constructor - used by MeshManager. More...

 ~Mesh ()
virtual void load (void)
 Generic load - called by MeshManager. More...

virtual void unload (void)
 Generic unload - called by MeshManager. More...

SubMeshcreateSubMesh (void)
 Creates a new SubMesh. More...

unsigned short getNumSubMeshes (void) const
 Gets the number of sub meshes which comprise this mesh. More...

SubMeshgetSubMesh (unsigned short index) const
 Gets a pointer to the submesh indicated by the index. More...

void setManuallyDefined (bool manuallyDefined)
 Call this to indicate that this Mesh will be manually defined rather than loaded from a file. More...

Mesh * clone (String newName)
 Makes a copy of this mesh object and gives it a new name. More...

const AxisAlignedBoxgetBounds (void)
 Get the axis-aligned bounding box for this mesh. More...

void _dumpContents (String filename)
 Debugging method - dump contents to a readable text file. More...

void _dumpGeometry (GeometryData &g, std::ofstream &of)
void _updateBounds (void)
 Updates the local bounding box of this mesh. More...

void _setBounds (const AxisAlignedBox &bounds)
 Manually set the bounding box for this Mesh. More...

void setSkeletonName (const String &skelName)
 Sets the name of the skeleton this Mesh uses for animation. More...

bool hasSkeleton (void) const
 Returns true if this Mesh has a linked Skeleton. More...

SkeletongetSkeleton (void) const
 Gets a pointer to any linked Skeleton. More...

const StringgetSkeletonName (void) const
 Gets the name of any linked Skeleton. More...

void _initAnimationState (AnimationStateSet *animSet)
 Initialise an animation set suitable for use with this mesh. More...

void addBoneAssignment (const VertexBoneAssignment &vertBoneAssign)
 Assigns a vertex to a bone with a given weight, for skeletal animation. More...

void clearBoneAssignments (void)
 Removes all bone assignments for this mesh. More...

unsigned short _getNumBoneMatrices (void)
 Returns the number of bone matrices this mesh uses. More...

void _getBoneMatrices (const AnimationStateSet &animSet, Matrix4 *pMatrices)
 Applies the animation set passed in, and populates the passed in array of bone matrices. More...

void _notifySkeleton (Skeleton *pSkel)
 Internal notification, used to tell the Mesh which Skeleton to use without loading it. More...

BoneAssignmentIterator getBoneAssignmentIterator (void)
 Gets an iterator for access all bone assignments. More...

void generateLodLevels (const LodDistanceList &lodDistances, ProgressiveMesh::VertexReductionQuota reductionMethod, Real reductionValue)
 Automatically generates lower level of detail versions of this mesh for use when a simpler version of the model is acceptable for rendering. More...

ushort getNumLodLevels (void) const
 Returns the number of levels of detail that this mesh supports. More...

const MeshLodUsagegetLodLevel (ushort index) const
 Gets details of the numbered level of detail entry. More...

void createManualLodLevel (Real fromDepth, const String &meshName)
 Adds a new manual level-of-detail entry to this Mesh. More...

void updateManualLodLevel (ushort index, const String &meshName)
 Changes the alternate mesh to use as a manual LOD at the given index. More...

ushort getLodIndex (Real depth) const
 Retrieves the level of detail index for the given depth value. More...

ushort getLodIndexSquaredDepth (Real squaredDepth) const
 Retrieves the level of detail index for the given squared depth value. More...

bool isLodManual (void) const
 Returns true if this mesh is using manual LOD. More...

void _setLodInfo (unsigned short numLevels, bool isManual)
 Internal methods for loading LOD, do not use. More...

void _setLodUsage (unsigned short level, Mesh::MeshLodUsage &usage)
 Internal methods for loading LOD, do not use. More...

void _setSubMeshLodFaceList (unsigned short subIdx, unsigned short level, ProgressiveMesh::LODFaceData &facedata)
 Internal methods for loading LOD, do not use. More...

virtual size_t getSize (void)
 Retrieves info about the size of the resource. More...

void touch (void)
 'Touches' the resource to indicate it has been used. More...

time_t getLastAccess (void) const
 Gets the last time the resource was 'touched'. More...

const StringgetName (void) const
 Gets resource name. More...

bool isLoaded (void) const
 Returns true if the Resource has been loaded, false otherwise. More...

virtual void destroy ()
 A method to make the resource delete itself. More...


Public Attributes

GeometryData sharedGeometry
 Shared geometry data. More...


Protected Attributes

String mName
bool mIsLoaded
time_t mLastAccess
size_t mSize

Private Types

typedef std::vector< SubMesh * > SubMeshList
typedef std::vector< MeshLodUsageMeshLodUsageList

Private Methods

void cloneGeometry (GeometryData &source, GeometryData &dest)
 Internal method used by clone(). More...

void compileBoneAssignments (void)
 Must be called once to compile bone assignments into geometry buffer. More...


Private Attributes

SubMeshList mSubMeshList
 A list of submeshes which make up this mesh. More...

AxisAlignedBox mAABB
 Local bounding box volume. More...

bool mManuallyDefined
bool mUpdateBounds
 Flag to indicate that bounds need updating. More...

String mSkeletonName
 Optional linked skeleton. More...

SkeletonmSkeleton
VertexBoneAssignmentList mBoneAssignments
bool mBoneAssignmentsOutOfDate
 Flag indicating that bone assignments need to be recompiled. More...

bool mIsLodManual
ushort mNumLods
MeshLodUsageList mMeshLodUsageList

Friends

class MeshSerializer

Detailed Description

Resource holding data about 3D mesh.

Remarks:
This class holds the data used to represent a discrete 3-dimensional object. Mesh data usually contains more than just vertices and triangle information; it also includes references to materials (and the faces which use them), level-of-detail reduction information, convex hull definition, skeleton/bones information, keyframe animation etc. However, it is important to note the emphasis on the word 'discrete' here. This class does not cover the large-scale sprawling geometry found in level / landscape data.

Multiple world objects can (indeed should) be created from a single mesh object - see the Entity class for more info. The mesh object will have it's own default material properties, but potentially each world instance may wish to customise the materials from the original. When the object is instantiated into a scene node, the mesh material properties will be taken by default but may be changed. These properties are actually held at the SubMesh level since a single mesh may have parts with different materials.

As described above, because the mesh may have sections of differing material properties, a mesh is inherently a compound contruct, consisting of one or more SubMesh objects. However, it strongly 'owns' it's SubMeshes such that they are loaded / unloaded at the same time. This is contrary to the approach taken to hierarchically related (but loosely owned) scene nodes, where data is loaded / unloaded separately. Note also that mesh sub-sections (when used in an instantiated object) share the same scene node as the parent.


Member Typedef Documentation

typedef MapIterator<VertexBoneAssignmentList> Ogre::Mesh::BoneAssignmentIterator
 

typedef std::vector<Real> Ogre::Mesh::LodDistanceList
 

typedef std::vector<MeshLodUsage> Ogre::Mesh::MeshLodUsageList [private]
 

typedef std::vector<SubMesh*> Ogre::Mesh::SubMeshList [private]
 

typedef std::multimap<unsigned short, VertexBoneAssignment> Ogre::Mesh::VertexBoneAssignmentList
 

Multimap of vertex bone assignments (orders by vertex index).


Constructor & Destructor Documentation

Ogre::Mesh::Mesh String    name
 

Default constructor - used by MeshManager.

Warning:
Do not call this method directly.

Ogre::Mesh::~Mesh  
 


Member Function Documentation

void Ogre::Mesh::_dumpContents String    filename
 

Debugging method - dump contents to a readable text file.

void Ogre::Mesh::_dumpGeometry GeometryData   g,
std::ofstream &    of
 

void Ogre::Mesh::_getBoneMatrices const AnimationStateSet   animSet,
Matrix4   pMatrices
 

Applies the animation set passed in, and populates the passed in array of bone matrices.

Remarks:
Internal use only. The array pointed to by the passed in Matrix4 pointer must have enough 'slots' for the number of bone matrices required (see _getNumBoneMatrices).

unsigned short Ogre::Mesh::_getNumBoneMatrices void   
 

Returns the number of bone matrices this mesh uses.

Remarks:
Only applicable if hasSkeleton() is true, for internal use only.

void Ogre::Mesh::_initAnimationState AnimationStateSet   animSet
 

Initialise an animation set suitable for use with this mesh.

Remarks:
Only recommended for use inside the engine, not by applications.

void Ogre::Mesh::_notifySkeleton Skeleton   pSkel
 

Internal notification, used to tell the Mesh which Skeleton to use without loading it.

Remarks:
This is only here for unusual situation where you want to manually set up a Skeleton. Best to let OGRE deal with this, don't call it yourself unless you really know what you're doing.

void Ogre::Mesh::_setBounds const AxisAlignedBox   bounds
 

Manually set the bounding box for this Mesh.

Remarks:
Use with care, designed only for internal engine usage. By calling this method you set the bounds of the mesh manually rather than letting the Mesh scan it's own geometry to derive it. This is most useful if you are building the Mesh geometry procedurally (e.g. see PatchSurface) and you have a simpler hull which you know it falls within.

void Ogre::Mesh::_setLodInfo unsigned short    numLevels,
bool    isManual
 

Internal methods for loading LOD, do not use.

void Ogre::Mesh::_setLodUsage unsigned short    level,
Mesh::MeshLodUsage   usage
 

Internal methods for loading LOD, do not use.

void Ogre::Mesh::_setSubMeshLodFaceList unsigned short    subIdx,
unsigned short    level,
ProgressiveMesh::LODFaceData   facedata
 

Internal methods for loading LOD, do not use.

void Ogre::Mesh::_updateBounds void   
 

Updates the local bounding box of this mesh.

Remarks:
Only needs to be called for manually modified meshes, loaded meshes do this automatically.

void Ogre::Mesh::addBoneAssignment const VertexBoneAssignment   vertBoneAssign
 

Assigns a vertex to a bone with a given weight, for skeletal animation.

Remarks:
This method is only valid after calling setSkeletonName. Since this is a one-off process there exists only 'addBoneAssignment' and 'clearBoneAssignments' methods, no 'editBoneAssignment'. You should not need to modify bone assignments during rendering (only the positions of bones) and OGRE reserves the right to do some internal data reformatting of this information, depending on render system requirements.

This method is for assigning weights to the shared geometry of the Mesh. To assign weights to the per-SubMesh geometry, see the equivalent methods on SubMesh.

void Ogre::Mesh::clearBoneAssignments void   
 

Removes all bone assignments for this mesh.

Remarks:
This method is for modifying weights to the shared geometry of the Mesh. To assign weights to the per-SubMesh geometry, see the equivalent methods on SubMesh.

Mesh * Ogre::Mesh::clone String    newName
 

Makes a copy of this mesh object and gives it a new name.

Remarks:
This is useful if you want to tweak an existing mesh without affecting the original one. The newly cloned mesh is registered with the MeshManager under the new name.

void Ogre::Mesh::cloneGeometry GeometryData   source,
GeometryData   dest
[private]
 

Internal method used by clone().

void Ogre::Mesh::compileBoneAssignments void    [private]
 

Must be called once to compile bone assignments into geometry buffer.

void Ogre::Mesh::createManualLodLevel Real    fromDepth,
const String   meshName
 

Adds a new manual level-of-detail entry to this Mesh.

Remarks:
As an alternative to generating lower level of detail versions of a mesh, you can use your own manually modelled meshes as lower level versions. This lets you have complete control over the LOD, and in addition lets you scale down other aspects of the model which cannot be done using the generated method; for example, you could use less detailed materials and / or use less bones in the skeleton if this is an animated mesh. Therefore for complex models you are likely to be better off modelling your LODs yourself and using this method, whilst for models with fairly simple materials and no animation you can just use the generateLodLevels method.
Parameters:
fromDepth  The z value from which this Lod will apply.
meshName  The name of the mesh which will be the lower level detail version.

SubMesh * Ogre::Mesh::createSubMesh void   
 

Creates a new SubMesh.

Remarks:
Method for manually creating geometry for the mesh. Note - use with extreme caution - you must be sure that you have set up the geometry properly.

virtual void Ogre::Resource::destroy void    [inline, virtual, inherited]
 

A method to make the resource delete itself.

Note:
This exists because Resource objects could be created in other processes, and they need to be destroyed in the process that created them.

void Ogre::Mesh::generateLodLevels const LodDistanceList   lodDistances,
ProgressiveMesh::VertexReductionQuota    reductionMethod,
Real    reductionValue
 

Automatically generates lower level of detail versions of this mesh for use when a simpler version of the model is acceptable for rendering.

Remarks:
There are 2 ways that you can create level-of-detail (LOD) versions of a mesh; the first is to call this method, which does fairly extensive calculations to work out how to simplify the mesh whilst having the minimum affect on the model. The alternative is to actually create simpler versions of the mesh yourself in a modelling tool, and having exported them, tell the 'master' mesh to use these alternative meshes for lower detail versions; this is done by calling the createManualLodLevel method.

As well as creating the lower detail versions of the mesh, this method will also associate them with depth values. As soon as an object is at least as far away from the camera as the depth value associated with it's LOD, it will drop to that level of detail.

I recommend calling this method before mesh export, not at runtime.

Parameters:
lodDistances  A list of depth values indicating the distances at which new lods should be generated.
reductionMethod  The way to determine the number of vertices collapsed per LOD
reductionValue  Meaning depends on reductionMethod, typically either the proportion of remaining vertices to collapse or a fixed number of vertices.

Mesh::BoneAssignmentIterator Ogre::Mesh::getBoneAssignmentIterator void   
 

Gets an iterator for access all bone assignments.

const AxisAlignedBox & Ogre::Mesh::getBounds void   
 

Get the axis-aligned bounding box for this mesh.

time_t Ogre::Resource::getLastAccess void    const [inline, inherited]
 

Gets the last time the resource was 'touched'.

ushort Ogre::Mesh::getLodIndex Real    depth const
 

Retrieves the level of detail index for the given depth value.

ushort Ogre::Mesh::getLodIndexSquaredDepth Real    squaredDepth const
 

Retrieves the level of detail index for the given squared depth value.

Remarks:
Internally the lods are stored at squared depths to avoid having to perform square roots when determining the lod. This method allows you to provide a squared length depth value to avoid having to do your own square roots.

const Mesh::MeshLodUsage & Ogre::Mesh::getLodLevel ushort    index const
 

Gets details of the numbered level of detail entry.

const String& Ogre::Resource::getName void    const [inline, inherited]
 

Gets resource name.

Reimplemented in Ogre::Material.

ushort Ogre::Mesh::getNumLodLevels void    const
 

Returns the number of levels of detail that this mesh supports.

Remarks:
This number includes the original model.

unsigned short Ogre::Mesh::getNumSubMeshes void    const
 

Gets the number of sub meshes which comprise this mesh.

virtual size_t Ogre::Resource::getSize void    [inline, virtual, inherited]
 

Retrieves info about the size of the resource.

Skeleton * Ogre::Mesh::getSkeleton void    const
 

Gets a pointer to any linked Skeleton.

const String & Ogre::Mesh::getSkeletonName void    const
 

Gets the name of any linked Skeleton.

SubMesh * Ogre::Mesh::getSubMesh unsigned short    index const
 

Gets a pointer to the submesh indicated by the index.

bool Ogre::Mesh::hasSkeleton void    const
 

Returns true if this Mesh has a linked Skeleton.

bool Ogre::Resource::isLoaded void    const [inline, inherited]
 

Returns true if the Resource has been loaded, false otherwise.

bool Ogre::Mesh::isLodManual void    const [inline]
 

Returns true if this mesh is using manual LOD.

Remarks:
A mesh can either use automatically generated LOD, or it can use alternative meshes as provided by an artist. A mesh can only use either all manual LODs or all generated LODs, not a mixture of both.

void Ogre::Mesh::load void    [virtual]
 

Generic load - called by MeshManager.

Implements Ogre::Resource.

void Ogre::Mesh::setManuallyDefined bool    manuallyDefined
 

Call this to indicate that this Mesh will be manually defined rather than loaded from a file.

Remarks:
Normally, when load() is called on a Resource such as a Mesh, a file of data is loaded. However, by calling this method with a parameter of 'true' you are indicating that the contents of this Mesh will be defined programmatically rather than by loading from a file. Note that the load() method must still be called in order to confirm the Mesh's use for the renderer, set up materials etc.

void Ogre::Mesh::setSkeletonName const String   skelName
 

Sets the name of the skeleton this Mesh uses for animation.

Remarks:
Meshes can optionally be assigned a skeleton which can be used to animate the mesh through bone assignments. The default is for the Mesh to use no skeleton. Calling this method with a valid skeleton filename will cause the skeleton to be loaded if it is not already (a single skeleton can be shared by many Mesh objects).
Parameters:
skelName  The name of the .skeleton file to use, or an empty string to use no skeleton

void Ogre::Resource::touch void    [inline, inherited]
 

'Touches' the resource to indicate it has been used.

void Ogre::Mesh::unload void    [virtual]
 

Generic unload - called by MeshManager.

Reimplemented from Ogre::Resource.

void Ogre::Mesh::updateManualLodLevel ushort    index,
const String   meshName
 

Changes the alternate mesh to use as a manual LOD at the given index.

Remarks:
Note that the index of a LOD may change if you insert other LODs. If in doubt, use getLodIndex().
Parameters:
index  The index of the level to be changed
meshName  The name of the mesh which will be the lower level detail version.


Friends And Related Function Documentation

friend class MeshSerializer [friend]
 


Member Data Documentation

AxisAlignedBox Ogre::Mesh::mAABB [private]
 

Local bounding box volume.

VertexBoneAssignmentList Ogre::Mesh::mBoneAssignments [private]
 

bool Ogre::Mesh::mBoneAssignmentsOutOfDate [private]
 

Flag indicating that bone assignments need to be recompiled.

bool Ogre::Resource::mIsLoaded [protected, inherited]
 

bool Ogre::Mesh::mIsLodManual [private]
 

time_t Ogre::Resource::mLastAccess [protected, inherited]
 

bool Ogre::Mesh::mManuallyDefined [private]
 

MeshLodUsageList Ogre::Mesh::mMeshLodUsageList [private]
 

String Ogre::Resource::mName [protected, inherited]
 

ushort Ogre::Mesh::mNumLods [private]
 

size_t Ogre::Resource::mSize [protected, inherited]
 

Skeleton* Ogre::Mesh::mSkeleton [private]
 

String Ogre::Mesh::mSkeletonName [private]
 

Optional linked skeleton.

SubMeshList Ogre::Mesh::mSubMeshList [private]
 

A list of submeshes which make up this mesh.

Each mesh is made up of 1 or more submeshes, which are each based on a single material and can have their own vertex data (they may not - they can share vertex data from the Mesh, depending on preference).

bool Ogre::Mesh::mUpdateBounds [private]
 

Flag to indicate that bounds need updating.

GeometryData Ogre::Mesh::sharedGeometry
 

Shared geometry data.

Remarks:
This vertex data can be shared among multiple submeshes. When a submesh uses a very small subset of the shared geometry it is (processor) inefficient since the whole buffer is sent during the submesh rendering operation. Therefore in this case the SubMesh would use it's own vertex data. For other cases it is more memory efficient to use a shared buffer since vertices are not duplicated, or if hardware vertex buffers are available it can be better to use one set of data.

The use of shared or non-shared buffers is determined when model data is converted to the OGRE .mesh format.

Copyright © 2002 by The OGRE Team