OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreMesh.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2011 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __Mesh_H__
29 #define __Mesh_H__
30 
31 #include "OgrePrerequisites.h"
32 
33 #include "OgreResource.h"
34 #include "OgreVertexIndexData.h"
35 #include "OgreAxisAlignedBox.h"
37 #include "OgreIteratorWrappers.h"
38 #include "OgreProgressiveMesh.h"
40 #include "OgreSkeleton.h"
41 #include "OgreAnimationTrack.h"
42 #include "OgrePose.h"
43 #include "OgreDataStream.h"
44 
45 
46 namespace Ogre {
47 
48 
88  struct MeshLodUsage;
89  class LodStrategy;
90 
91  class _OgreExport Mesh: public Resource
92  {
93  friend class SubMesh;
94  friend class MeshSerializerImpl;
98 
99  public:
107 
108  protected:
116 
118  void organiseTangentsBuffer(VertexData *vertexData,
119  VertexElementSemantic targetSemantic, unsigned short index,
120  unsigned short sourceTexCoordSet);
121 
122  public:
126  typedef HashMap<String, ushort> SubMeshNameMap ;
127 
128 
129  protected:
130 
132 
134 
139 
143 
144 
146 
149 
151  void buildIndexMap(const VertexBoneAssignmentList& boneAssignments,
152  IndexMap& boneIndexToBlendIndexMap, IndexMap& blendIndexToBoneIndexMap);
154  void compileBoneAssignments(const VertexBoneAssignmentList& boneAssignments,
155  unsigned short numBlendWeightsPerVertex,
156  IndexMap& blendIndexToBoneIndexMap,
157  VertexData* targetVertexData);
158 
163 
168 
169 
173 
180  mutable bool mAnimationTypesDirty;
181 
184 
185 
191  void prepareImpl(void);
194  void unprepareImpl(void);
196  void loadImpl(void);
198  void postLoadImpl(void);
200  void unloadImpl(void);
202  size_t calculateSize(void) const;
203 
204 
205 
206  public:
211  Mesh(ResourceManager* creator, const String& name, ResourceHandle handle,
212  const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
213  ~Mesh();
214 
215  // NB All methods below are non-virtual since they will be
216  // called in the rendering loop - speed is of the essence.
217 
224  SubMesh* createSubMesh(void);
225 
228  SubMesh* createSubMesh(const String& name);
229 
232  void nameSubMesh(const String& name, ushort index);
233 
236  void unnameSubMesh(const String& name);
237 
243  ushort _getSubMeshIndex(const String& name) const;
244 
247  unsigned short getNumSubMeshes(void) const;
248 
251  SubMesh* getSubMesh(unsigned short index) const;
252 
255  SubMesh* getSubMesh(const String& name) const ;
256 
262  void destroySubMesh(unsigned short index);
263 
269  void destroySubMesh(const String& name);
270 
274  { return SubMeshIterator(mSubMeshList.begin(), mSubMeshList.end()); }
275 
285 
307 
317  MeshPtr clone(const String& newName, const String& newGroup = StringUtil::BLANK);
318 
321  const AxisAlignedBox& getBounds(void) const;
322 
324  Real getBoundingSphereRadius(void) const;
325 
334  void _setBounds(const AxisAlignedBox& bounds, bool pad = true);
335 
343  void _setBoundingSphereRadius(Real radius);
344 
355  void setSkeletonName(const String& skelName);
356 
358  bool hasSkeleton(void) const;
359 
362  bool hasVertexAnimation(void) const;
363 
367  const SkeletonPtr& getSkeleton(void) const;
368 
370  const String& getSkeletonName(void) const;
375  void _initAnimationState(AnimationStateSet* animSet);
376 
381  void _refreshAnimationState(AnimationStateSet* animSet);
394  void addBoneAssignment(const VertexBoneAssignment& vertBoneAssign);
395 
401  void clearBoneAssignments(void);
402 
409  void _notifySkeleton(SkeletonPtr& pSkel);
410 
411 
414  BoneAssignmentIterator getBoneAssignmentIterator(void);
415 
418  const VertexBoneAssignmentList& getBoneAssignments() const { return mBoneAssignments; }
419 
420 
446  void generateLodLevels(const LodValueList& lodValues,
447  ProgressiveMesh::VertexReductionQuota reductionMethod, Real reductionValue);
448 
453  ushort getNumLodLevels(void) const;
455  const MeshLodUsage& getLodLevel(ushort index) const;
469  void createManualLodLevel(Real value, const String& meshName, const String& groupName = Ogre::String());
470 
478  void updateManualLodLevel(ushort index, const String& meshName);
479 
485  ushort getLodIndex(Real value) const;
486 
493  bool isLodManual(void) const { return mIsLodManual; }
494 
496  void _setLodInfo(unsigned short numLevels, bool isManual);
498  void _setLodUsage(unsigned short level, MeshLodUsage& usage);
500  void _setSubMeshLodFaceList(unsigned short subIdx, unsigned short level, IndexData* facedata);
501 
503  void removeLodLevels(void);
504 
527  void setVertexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
550  void setIndexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
552  HardwareBuffer::Usage getVertexBufferUsage(void) const { return mVertexBufferUsage; }
554  HardwareBuffer::Usage getIndexBufferUsage(void) const { return mIndexBufferUsage; }
556  bool isVertexBufferShadowed(void) const { return mVertexBufferShadowBuffer; }
558  bool isIndexBufferShadowed(void) const { return mIndexBufferShadowBuffer; }
559 
560 
574  unsigned short _rationaliseBoneAssignments(size_t vertexCount, VertexBoneAssignmentList& assignments);
575 
583  void _compileBoneAssignments(void);
584 
590  void _updateCompiledBoneAssignments(void);
591 
618  void buildTangentVectors(VertexElementSemantic targetSemantic = VES_TANGENT,
619  unsigned short sourceTexCoordSet = 0, unsigned short index = 0,
620  bool splitMirrored = false, bool splitRotated = false, bool storeParityInW = false);
621 
640  bool suggestTangentVectorBuildParams(VertexElementSemantic targetSemantic,
641  unsigned short& outSourceCoordSet, unsigned short& outIndex);
642 
646  void buildEdgeList(void);
648  void freeEdgeList(void);
649 
668  void prepareForShadowVolume(void);
669 
676  EdgeData* getEdgeList(unsigned short lodIndex = 0);
677 
684  const EdgeData* getEdgeList(unsigned short lodIndex = 0) const;
685 
688  bool isPreparedForShadowVolumes(void) const { return mPreparedForShadowVolumes; }
689 
691  bool isEdgeListBuilt(void) const { return mEdgeListsBuilt; }
692 
704  static void prepareMatricesForVertexBlend(const Matrix4** blendMatrices,
705  const Matrix4* boneMatrices, const IndexMap& indexMap);
706 
725  static void softwareVertexBlend(const VertexData* sourceVertexData,
726  const VertexData* targetVertexData,
727  const Matrix4* const* blendMatrices, size_t numMatrices,
728  bool blendNormals);
729 
742  static void softwareVertexMorph(Real t,
745  VertexData* targetVertexData);
746 
761  static void softwareVertexPoseBlend(Real weight,
762  const map<size_t, Vector3>::type& vertexOffsetMap,
763  VertexData* targetVertexData);
765  const SubMeshNameMap& getSubMeshNameMap(void) const { return mSubMeshNameMap; }
766 
777  void setAutoBuildEdgeLists(bool autobuild) { mAutoBuildEdgeLists = autobuild; }
782  bool getAutoBuildEdgeLists(void) const { return mAutoBuildEdgeLists; }
783 
786  virtual VertexAnimationType getSharedVertexDataAnimationType(void) const;
787 
792  virtual Animation* createAnimation(const String& name, Real length);
793 
797  virtual Animation* getAnimation(const String& name) const;
798 
803  virtual Animation* _getAnimationImpl(const String& name) const;
804 
806  virtual bool hasAnimation(const String& name);
807 
809  virtual void removeAnimation(const String& name);
810 
812  virtual unsigned short getNumAnimations(void) const;
813 
816  virtual Animation* getAnimation(unsigned short index) const;
817 
819  virtual void removeAllAnimations(void);
825  VertexData* getVertexDataByTrackHandle(unsigned short handle);
837  void updateMaterialForAllSubMeshes(void);
838 
843  void _determineAnimationTypes(void) const;
845  bool _getAnimationTypesDirty(void) const { return mAnimationTypesDirty; }
846 
853  Pose* createPose(ushort target, const String& name = StringUtil::BLANK);
855  size_t getPoseCount(void) const { return mPoseList.size(); }
857  Pose* getPose(ushort index);
859  Pose* getPose(const String& name);
863  void removePose(ushort index);
867  void removePose(const String& name);
869  void removeAllPoses(void);
870 
873 
875  PoseIterator getPoseIterator(void);
877  ConstPoseIterator getPoseIterator(void) const;
879  const PoseList& getPoseList(void) const;
880 
882  const LodStrategy *getLodStrategy() const;
884  void setLodStrategy(LodStrategy *lodStrategy);
885 
886  };
887 
894  class _OgreExport MeshPtr : public SharedPtr<Mesh>
895  {
896  public:
898  explicit MeshPtr(Mesh* rep) : SharedPtr<Mesh>(rep) {}
899  MeshPtr(const MeshPtr& r) : SharedPtr<Mesh>(r) {}
900  MeshPtr(const ResourcePtr& r);
902  MeshPtr& operator=(const ResourcePtr& r);
903  protected:
905  void destroy(void);
906  };
907 
910  {
916 
923 
931  mutable EdgeData* edgeData;
932 
933  MeshLodUsage() : userValue(0.0), value(0.0), edgeData(0) {}
934  };
935 
940 } // namespace
941 
942 #endif
Class encapsulating a set of AnimationState objects.
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
bool mEdgeListsBuilt
Definition: OgreMesh.h:171
SkeletonPtr mSkeleton
Definition: OgreMesh.h:142
map< unsigned int, IndexData * >::type IndexMap
float Real
Software floating point type.
vector< unsigned short >::type IndexMap
Definition: OgreMesh.h:106
#define _OgreExport
Definition: OgrePlatform.h:203
AxisAlignedBox mAABB
Local bounding box volume.
Definition: OgreMesh.h:136
bool _getAnimationTypesDirty(void) const
Are the derived animation types out of date?
Definition: OgreMesh.h:845
HardwareBuffer::Usage mIndexBufferUsage
Definition: OgreMesh.h:165
Real mBoundRadius
Local bounding sphere radius (centered on object)
Definition: OgreMesh.h:138
ushort mNumLods
Definition: OgreMesh.h:161
Tangent (X axis if normal is Z)
A way of recording the way each LODs is recorded this Mesh.
Definition: OgreMesh.h:909
MapIterator< VertexBoneAssignmentList > BoneAssignmentIterator
Definition: OgreMesh.h:104
const LodStrategy * mLodStrategy
Definition: OgreMesh.h:159
bool mAnimationTypesDirty
Do we need to scan animations for animation types?
Definition: OgreMesh.h:180
IndexMap sharedBlendIndexToBoneIndexMap
Shared index map for translating blend index to bone index.
Definition: OgreMesh.h:306
A pose is a linked set of vertex offsets applying to one set of vertex data.
Definition: OgrePose.h:54
Shared pointer implementation used to share index buffers.
A 3D box aligned with the x/y/z axes.
bool mPreparedForShadowVolumes
Definition: OgreMesh.h:170
map< String, Animation * >::type AnimationList
Storage of morph animations, lookup by name.
Definition: OgreMesh.h:175
Interface describing a manual resource loader.
Definition: OgreResource.h:512
VertexElementSemantic
Vertex element semantics, used to identify the meaning of vertex buffer contents. ...
SubMeshList mSubMeshList
A list of submeshes which make up this mesh.
Definition: OgreMesh.h:115
Strategy for determining level of detail.
MeshLodUsageList mMeshLodUsageList
Definition: OgreMesh.h:162
HardwareBuffer::Usage mVertexBufferUsage
Definition: OgreMesh.h:164
bool mIndexBufferShadowBuffer
Definition: OgreMesh.h:167
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
bool mVertexBufferShadowBuffer
Definition: OgreMesh.h:166
vector< Pose * >::type PoseList
Definition: OgrePose.h:111
bool mAutoBuildEdgeLists
Definition: OgreMesh.h:172
const SubMeshNameMap & getSubMeshNameMap(void) const
Gets a reference to the optional name assignments of the SubMeshes.
Definition: OgreMesh.h:765
bool isIndexBufferShadowed(void) const
Gets whether or not this meshes index buffers are shadowed.
Definition: OgreMesh.h:558
MeshPtr(Mesh *rep)
Definition: OgreMesh.h:898
bool getAutoBuildEdgeLists(void) const
Sets whether or not this Mesh should automatically build edge lists when asked for them...
Definition: OgreMesh.h:782
VertexData * sharedVertexData
Shared vertex data.
Definition: OgreMesh.h:284
void setAutoBuildEdgeLists(bool autobuild)
Sets whether or not this Mesh should automatically build edge lists when asked for them...
Definition: OgreMesh.h:777
DataStreamPtr mFreshFromDisk
Definition: OgreMesh.h:131
String manualGroup
Only relevant if mIsLodManual is true, the name of the group of the alternative mesh.
Definition: OgreMesh.h:927
MeshPtr(const MeshPtr &r)
Definition: OgreMesh.h:899
bool isPreparedForShadowVolumes(void) const
Returns whether this mesh has already had it's geometry prepared for use in rendering shadow volumes...
Definition: OgreMesh.h:688
Concrete IteratorWrapper for const access to the underlying container.
vector< SubMesh * >::type SubMeshList
Definition: OgreMesh.h:105
Internal implementation of Mesh reading / writing for the latest version of the .mesh format...
HardwareBuffer::Usage getVertexBufferUsage(void) const
Gets the usage setting for this meshes vertex buffers.
Definition: OgreMesh.h:552
VertexReductionQuota
The way to derive the quota of vertices which are reduced at each LOD.
Summary class collecting together index data source information.
Usage
Enums describing buffer usage; not mutually exclusive.
EdgeData * edgeData
Edge list for this LOD level (may be derived from manual mesh)
Definition: OgreMesh.h:931
HashMap< String, ushort > SubMeshNameMap
A hashmap used to store optional SubMesh names.
Definition: OgreMesh.h:126
Defines a part of a complete mesh.
Definition: OgreSubMesh.h:62
Real value
Value used by to determine when this lod applies.
Definition: OgreMesh.h:922
SubMeshIterator getSubMeshIterator(void)
Gets an iterator over the available submeshes.
Definition: OgreMesh.h:273
MeshPtr manualMesh
Hard link to mesh to avoid looking up each time.
Definition: OgreMesh.h:929
unsigned short ushort
const VertexBoneAssignmentList & getBoneAssignments() const
Gets a const reference to the list of bone assignments.
Definition: OgreMesh.h:418
Real userValue
User-supplied values used to determine when th is lod applies.
Definition: OgreMesh.h:915
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:77
unsigned long long int ResourceHandle
Definition: OgreResource.h:39
static const String BLANK
Constant blank string, useful for returning by ref where local does not exist.
Definition: OgreString.h:180
Summary class collecting together vertex source information.
String manualName
Only relevant if mIsLodManual is true, the name of the alternative mesh to use.
Definition: OgreMesh.h:925
bool mBoneAssignmentsOutOfDate
Flag indicating that bone assignments need to be recompiled.
Definition: OgreMesh.h:148
PoseList mPoseList
List of available poses for shared and dedicated geometryPoseList.
Definition: OgreMesh.h:183
multimap< size_t, VertexBoneAssignment >::type VertexBoneAssignmentList
Multimap of vertex bone assignments (orders by vertex index)
Definition: OgreMesh.h:103
vector< Real >::type LodValueList
Definition: OgreMesh.h:100
Class for providing backwards-compatibility for loading version 1.2 of the .mesh format.
AnimationList mAnimationsList
Definition: OgreMesh.h:176
ConstVectorIterator< PoseList > ConstPoseIterator
Definition: OgreMesh.h:872
Class for providing backwards-compatibility for loading version 1.4 of the .mesh format.
This class contains the information required to describe the edge connectivity of a given set of vert...
Defines a generic resource handler.
Specialisation of SharedPtr to allow SharedPtr to be assigned to SkeletonPtr.
Definition: OgreSkeleton.h:461
bool isVertexBufferShadowed(void) const
Gets whether or not this meshes vertex buffers are shadowed.
Definition: OgreMesh.h:556
VertexBoneAssignmentList mBoneAssignments
Definition: OgreMesh.h:145
_StringBase String
bool isLodManual(void) const
Returns true if this mesh is using manual LOD.
Definition: OgreMesh.h:493
HardwareBuffer::Usage getIndexBufferUsage(void) const
Gets the usage setting for this meshes index buffers.
Definition: OgreMesh.h:554
size_t getPoseCount(void) const
Get the number of poses.
Definition: OgreMesh.h:855
bool mIsLodManual
Definition: OgreMesh.h:160
VectorIterator< SubMeshList > SubMeshIterator
Definition: OgreMesh.h:271
Concrete IteratorWrapper for nonconst access to the underlying container.
Specialisation of SharedPtr to allow SharedPtr to be assigned to MeshPtr.
Definition: OgreMesh.h:894
vector< MeshLodUsage >::type MeshLodUsageList
Definition: OgreMesh.h:101
bool isEdgeListBuilt(void) const
Returns whether this mesh has an attached edge list.
Definition: OgreMesh.h:691
VertexAnimationType
Type of vertex animation.
VectorIterator< PoseList > PoseIterator
Definition: OgreMesh.h:871
String mSkeletonName
Optional linked skeleton.
Definition: OgreMesh.h:141
An animation sequence.
Definition: OgreAnimation.h:58
SubMeshNameMap mSubMeshNameMap
Definition: OgreMesh.h:133
Records the assignment of a single vertex to a single bone with the corresponding weight...
Class for providing backwards-compatibility for loading version 1.1 of the .mesh format.
VertexAnimationType mSharedVertexDataAnimationType
The vertex animation type associated with the shared vertex data.
Definition: OgreMesh.h:178