OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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-2014 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 "OgreAxisAlignedBox.h"
36 #include "OgreAnimation.h"
37 #include "OgreAnimationTrack.h"
38 #include "OgreHeaderPrefix.h"
39 
40 
41 namespace Ogre {
42 
43 
51  struct MeshLodUsage;
52  class LodStrategy;
53 
87  {
88  friend class SubMesh;
89  friend class MeshSerializerImpl;
95 
96  public:
104 
105  protected:
113 
115  void organiseTangentsBuffer(VertexData *vertexData,
116  VertexElementSemantic targetSemantic, unsigned short index,
117  unsigned short sourceTexCoordSet);
118 
119  public:
123  typedef HashMap<String, ushort> SubMeshNameMap ;
124 
125 
126  protected:
127 
129 
131 
138 
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 
164 
169 
173 
182  mutable bool mAnimationTypesDirty;
183 
186  mutable bool mPosesIncludeNormals;
187 
188 
194  void prepareImpl(void);
197  void unprepareImpl(void);
199  void loadImpl(void);
201  void postLoadImpl(void);
203  void unloadImpl(void);
205  size_t calculateSize(void) const;
206 
207  void mergeAdjacentTexcoords( unsigned short finalTexCoordSet,
208  unsigned short texCoordSetToDestroy, VertexData *vertexData );
209 
210 
211  public:
216  Mesh(ResourceManager* creator, const String& name, ResourceHandle handle,
217  const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
218  ~Mesh();
219 
220  // NB All methods below are non-virtual since they will be
221  // called in the rendering loop - speed is of the essence.
222 
229  SubMesh* createSubMesh(void);
230 
233  SubMesh* createSubMesh(const String& name);
234 
237  void nameSubMesh(const String& name, ushort index);
238 
241  void unnameSubMesh(const String& name);
242 
248  ushort _getSubMeshIndex(const String& name) const;
249 
252  unsigned short getNumSubMeshes(void) const;
253 
256  SubMesh* getSubMesh(unsigned short index) const;
257 
260  SubMesh* getSubMesh(const String& name) const ;
261 
268  void destroySubMesh(unsigned short index);
269 
276  void destroySubMesh(const String& name);
277 
281  { return SubMeshIterator(mSubMeshList.begin(), mSubMeshList.end()); }
282 
292 
314 
326  MeshPtr clone(const String& newName, const String& newGroup = BLANKSTRING);
327 
330  const AxisAlignedBox& getBounds(void) const;
331 
333  Real getBoundingSphereRadius(void) const;
334 
336  Real getBoneBoundingRadius() const;
337 
346  void _setBounds(const AxisAlignedBox& bounds, bool pad = true);
347 
355  void _setBoundingSphereRadius(Real radius);
356 
361  void _setBoneBoundingRadius(Real radius);
362 
368  void _computeBoneBoundingRadius();
369 
377  void _updateBoundsFromVertexBuffers(bool pad = false);
378 
385  void _calcBoundsFromVertexBuffer(VertexData* vertexData, AxisAlignedBox& outAABB, Real& outRadius, bool updateOnly = false);
397  void setSkeletonName(const String& skelName);
398 
400  bool hasSkeleton(void) const;
401 
404  bool hasVertexAnimation(void) const;
405 
410  const SkeletonPtr& getOldSkeleton(void) const;
411  const SkeletonDefPtr& getSkeleton(void) const { return mSkeleton; }
412 
414  const String& getSkeletonName(void) const;
419  void _initAnimationState(AnimationStateSet* animSet);
420 
425  void _refreshAnimationState(AnimationStateSet* animSet);
438  void addBoneAssignment(const VertexBoneAssignment& vertBoneAssign);
439 
445  void clearBoneAssignments(void);
446 
453  void _notifySkeleton(SkeletonPtr& pSkel);
454 
455 
458  BoneAssignmentIterator getBoneAssignmentIterator(void);
459 
462  const VertexBoneAssignmentList& getBoneAssignments() const { return mBoneAssignments; }
463 
464  void setLodStrategyName( const String &name ) { mLodStrategyName = name; }
465 
467  const String& getLodStrategyName(void) const { return mLodStrategyName; }
468 
473  ushort getNumLodLevels(void) const;
475  const MeshLodUsage& getLodLevel(ushort index) const;
476 
483  ushort getLodIndex(Real value) const;
484 
490  bool hasManualLodLevel(void) const { return mHasManualLodLevel; }
491 
501  void updateManualLodLevel(ushort index, const String& meshName);
502 
504  void _setLodInfo(unsigned short numLevels);
506  void _setLodUsage(unsigned short level, MeshLodUsage& usage);
508  void _setSubMeshLodFaceList(unsigned short subIdx, unsigned short level, IndexData* facedata);
510  bool _isManualLodLevel(unsigned short level) const;
511 
513  void removeLodLevels(void);
514 
539  void setVertexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
564  void setIndexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
566  HardwareBuffer::Usage getVertexBufferUsage(void) const { return mVertexBufferUsage; }
568  HardwareBuffer::Usage getIndexBufferUsage(void) const { return mIndexBufferUsage; }
570  bool isVertexBufferShadowed(void) const { return mVertexBufferShadowBuffer; }
572  bool isIndexBufferShadowed(void) const { return mIndexBufferShadowBuffer; }
573 
574 
591  unsigned short _rationaliseBoneAssignments(size_t vertexCount, VertexBoneAssignmentList& assignments);
592 
600  void _compileBoneAssignments(void);
601 
607  void _updateCompiledBoneAssignments(void);
608 
624  void mergeAdjacentTexcoords( unsigned short finalTexCoordSet, unsigned short texCoordSetToDestroy );
625 
658  void buildTangentVectors(VertexElementSemantic targetSemantic = VES_TANGENT,
659  unsigned short sourceTexCoordSet = 0, unsigned short index = 0,
660  bool splitMirrored = false, bool splitRotated = false, bool storeParityInW = false);
661 
683  bool suggestTangentVectorBuildParams(VertexElementSemantic targetSemantic,
684  unsigned short& outSourceCoordSet, unsigned short& outIndex);
685 
689  void buildEdgeList(void);
691  void freeEdgeList(void);
692 
711  void prepareForShadowVolume(void);
712 
720  EdgeData* getEdgeList(unsigned short lodIndex = 0);
721 
729  const EdgeData* getEdgeList(unsigned short lodIndex = 0) const;
730 
733  bool isPreparedForShadowVolumes(void) const { return mPreparedForShadowVolumes; }
734 
736  bool isEdgeListBuilt(void) const { return mEdgeListsBuilt; }
737 
752  static void prepareMatricesForVertexBlend(const Matrix4** blendMatrices,
753  const Matrix4* boneMatrices, const IndexMap& indexMap);
754 
778  static void softwareVertexBlend(const VertexData* sourceVertexData,
779  const VertexData* targetVertexData,
780  const Matrix4* const* blendMatrices, size_t numMatrices,
781  bool blendNormals);
782 
799  static void softwareVertexMorph(Real t,
802  VertexData* targetVertexData);
803 
823  static void softwareVertexPoseBlend(Real weight,
824  const map<size_t, Vector3>::type& vertexOffsetMap,
825  const map<size_t, Vector3>::type& normalsMap,
826  VertexData* targetVertexData);
828  const SubMeshNameMap& getSubMeshNameMap(void) const { return mSubMeshNameMap; }
829 
840  void setAutoBuildEdgeLists(bool autobuild) { mAutoBuildEdgeLists = autobuild; }
845  bool getAutoBuildEdgeLists(void) const { return mAutoBuildEdgeLists; }
846 
849  virtual VertexAnimationType getSharedVertexDataAnimationType(void) const;
850 
852  bool getSharedVertexDataAnimationIncludesNormals() const { return mSharedVertexDataAnimationIncludesNormals; }
853 
860  virtual Animation* createAnimation(const String& name, Real length);
861 
866  virtual Animation* getAnimation(const String& name) const;
867 
873  virtual Animation* _getAnimationImpl(const String& name) const;
874 
876  virtual bool hasAnimation(const String& name) const;
877 
879  virtual void removeAnimation(const String& name);
880 
882  virtual unsigned short getNumAnimations(void) const;
883 
886  virtual Animation* getAnimation(unsigned short index) const;
887 
889  virtual void removeAllAnimations(void);
895  VertexData* getVertexDataByTrackHandle(unsigned short handle);
907  void updateMaterialForAllSubMeshes(void);
908 
913  void _determineAnimationTypes(void) const;
915  bool _getAnimationTypesDirty(void) const { return mAnimationTypesDirty; }
916 
926  Pose* createPose(ushort target, const String& name = BLANKSTRING);
928  size_t getPoseCount(void) const { return mPoseList.size(); }
930  Pose* getPose(ushort index);
932  Pose* getPose(const String& name);
937  void removePose(ushort index);
942  void removePose(const String& name);
944  void removeAllPoses(void);
945 
948 
950  PoseIterator getPoseIterator(void);
952  ConstPoseIterator getPoseIterator(void) const;
954  const PoseList& getPoseList(void) const;
955 
956  const LodValueArray* _getLodValueArray(void) const { return &mLodValues; }
957 
958  };
959 
962  {
968 
975 
976 
982  mutable EdgeData* edgeData;
983 
984  MeshLodUsage() : userValue(0.0), value(0.0), edgeData(0) {}
985  };
986 
991 } // namespace Ogre
992 
993 #include "OgreHeaderSuffix.h"
994 
995 #endif // __Mesh_H__
Class encapsulating a set of AnimationState objects.
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
bool mPosesIncludeNormals
Definition: OgreMesh.h:186
bool mEdgeListsBuilt
Definition: OgreMesh.h:171
Real mBoneBoundingRadius
Largest bounding radius of any bone in the skeleton (centered on each bone, only considering verts we...
Definition: OgreMesh.h:137
float Real
Software floating point type.
#define _OgreExport
Definition: OgrePlatform.h:255
AxisAlignedBox mAABB
Local bounding box volume.
Definition: OgreMesh.h:133
bool _getAnimationTypesDirty(void) const
Are the derived animation types out of date?
Definition: OgreMesh.h:915
HardwareBuffer::Usage mIndexBufferUsage
Definition: OgreMesh.h:166
LodValueArray mLodValues
Definition: OgreMesh.h:163
Real mBoundRadius
Local bounding sphere radius (centered on object).
Definition: OgreMesh.h:135
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:961
const String & getLodStrategyName(void) const
Returns the name of the Lod strategy the user lod values have been calibrated for.
Definition: OgreMesh.h:467
MapIterator< VertexBoneAssignmentList > BoneAssignmentIterator
Definition: OgreMesh.h:101
bool mSharedVertexDataAnimationIncludesNormals
Whether vertex animation includes normals.
Definition: OgreMesh.h:180
SkeletonPtr mOldSkeleton
Definition: OgreMesh.h:141
bool mAnimationTypesDirty
Do we need to scan animations for animation types?
Definition: OgreMesh.h:182
bool getSharedVertexDataAnimationIncludesNormals() const
Returns whether animation on shared vertex data includes normals.
Definition: OgreMesh.h:852
IndexMap sharedBlendIndexToBoneIndexMap
Shared index map for translating blend index to bone index.
Definition: OgreMesh.h:313
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 vertex 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:498
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:112
MeshLodUsageList mMeshLodUsageList
Definition: OgreMesh.h:162
HardwareBuffer::Usage mVertexBufferUsage
Definition: OgreMesh.h:165
bool mIndexBufferShadowBuffer
Definition: OgreMesh.h:168
const String BLANKSTRING
Constant blank string, useful for returning by ref where local does not exist.
Definition: OgreCommon.h:574
const SkeletonDefPtr & getSkeleton(void) const
Definition: OgreMesh.h:411
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
bool mVertexBufferShadowBuffer
Definition: OgreMesh.h:167
vector< Pose * >::type PoseList
Definition: OgrePose.h:134
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:828
bool isIndexBufferShadowed(void) const
Gets whether or not this meshes index buffers are shadowed.
Definition: OgreMesh.h:572
bool getAutoBuildEdgeLists(void) const
Sets whether or not this Mesh should automatically build edge lists when asked for them...
Definition: OgreMesh.h:845
VertexData * sharedVertexData
Shared vertex data.
Definition: OgreMesh.h:291
void setAutoBuildEdgeLists(bool autobuild)
Sets whether or not this Mesh should automatically build edge lists when asked for them...
Definition: OgreMesh.h:840
bool mHasManualLodLevel
Definition: OgreMesh.h:160
DataStreamPtr mFreshFromDisk
Definition: OgreMesh.h:128
bool isPreparedForShadowVolumes(void) const
Returns whether this mesh has already had it's geometry prepared for use in rendering shadow volumes...
Definition: OgreMesh.h:733
Concrete IteratorWrapper for const access to the underlying container.
vector< SubMesh * >::type SubMeshList
Definition: OgreMesh.h:102
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:566
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:982
HashMap< String, ushort > SubMeshNameMap
A hashmap used to store optional SubMesh names.
Definition: OgreMesh.h:123
void setLodStrategyName(const String &name)
Definition: OgreMesh.h:464
Defines a part of a complete mesh.
Definition: OgreSubMesh.h:60
Real value
Value used by to determine when this LOD applies.
Definition: OgreMesh.h:974
SubMeshIterator getSubMeshIterator(void)
Gets an iterator over the available submeshes.
Definition: OgreMesh.h:280
MeshPtr manualMesh
Hard link to mesh to avoid looking up each time.
Definition: OgreMesh.h:980
unsigned short ushort
const VertexBoneAssignmentList & getBoneAssignments() const
Gets a const reference to the list of bone assignments.
Definition: OgreMesh.h:462
Real userValue
User-supplied values used to determine on which distance the lod is applies.
Definition: OgreMesh.h:967
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:77
unsigned long long int ResourceHandle
Definition: OgreResource.h:39
FastArray< unsigned short > IndexMap
Definition: OgreMesh.h:103
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:978
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:185
const LodValueArray * _getLodValueArray(void) const
Definition: OgreMesh.h:956
multimap< size_t, VertexBoneAssignment >::type VertexBoneAssignmentList
Multimap of vertex bone assignments (orders by vertex index).
Definition: OgreMesh.h:100
An animation container interface, which allows generic access to sibling animations.
Definition: OgreAnimation.h:56
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:947
Class for providing backwards-compatibility for loading version 1.4 of the .mesh format.
SkeletonDefPtr mSkeleton
Definition: OgreMesh.h:142
This class contains the information required to describe the edge connectivity of a given set of vert...
Defines a generic resource handler.
bool isVertexBufferShadowed(void) const
Gets whether or not this meshes vertex buffers are shadowed.
Definition: OgreMesh.h:570
VertexBoneAssignmentList mBoneAssignments
Definition: OgreMesh.h:145
_StringBase String
Definition: OgreCommon.h:53
HardwareBuffer::Usage getIndexBufferUsage(void) const
Gets the usage setting for this meshes index buffers.
Definition: OgreMesh.h:568
size_t getPoseCount(void) const
Get the number of poses.
Definition: OgreMesh.h:928
Resource holding data about 3D mesh.
Definition: OgreMesh.h:86
VectorIterator< SubMeshList > SubMeshIterator
Definition: OgreMesh.h:278
Concrete IteratorWrapper for nonconst access to the underlying container.
vector< MeshLodUsage >::type MeshLodUsageList
Definition: OgreMesh.h:98
bool isEdgeListBuilt(void) const
Returns whether this mesh has an attached edge list.
Definition: OgreMesh.h:736
Class for providing backwards-compatibility for loading version 1.8 of the .mesh format.
VertexAnimationType
Type of vertex animation.
VectorIterator< PoseList > PoseIterator
Definition: OgreMesh.h:946
String mSkeletonName
Optional linked skeleton.
Definition: OgreMesh.h:140
An animation sequence.
Definition: OgreAnimation.h:90
String mLodStrategyName
Definition: OgreMesh.h:159
SubMeshNameMap mSubMeshNameMap
Definition: OgreMesh.h:130
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
Class for providing backwards-compatibility for loading version 1.3 of the .mesh format.
bool hasManualLodLevel(void) const
Returns true if this mesh has a manual LOD level.
Definition: OgreMesh.h:490
FastArray< Real > LodValueArray
Definition: OgreMesh.h:97