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-2013 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"
39 #include "OgreSkeleton.h"
40 #include "OgreAnimation.h"
41 #include "OgreAnimationTrack.h"
42 #include "OgrePose.h"
43 #include "OgreDataStream.h"
44 #include "OgreHeaderPrefix.h"
45 
46 
47 namespace Ogre {
48 
49 
57  struct MeshLodUsage;
58  struct LodConfig;
59  class LodStrategy;
60 
94  {
95  friend class SubMesh;
96  friend class MeshSerializerImpl;
100 
101  public:
109 
110  protected:
118 
120  void organiseTangentsBuffer(VertexData *vertexData,
121  VertexElementSemantic targetSemantic, unsigned short index,
122  unsigned short sourceTexCoordSet);
123 
124  public:
128  typedef HashMap<String, ushort> SubMeshNameMap ;
129 
130 
131  protected:
132 
134 
136 
141 
145 
146 
148 
151 
153  void buildIndexMap(const VertexBoneAssignmentList& boneAssignments,
154  IndexMap& boneIndexToBlendIndexMap, IndexMap& blendIndexToBoneIndexMap);
156  void compileBoneAssignments(const VertexBoneAssignmentList& boneAssignments,
157  unsigned short numBlendWeightsPerVertex,
158  IndexMap& blendIndexToBoneIndexMap,
159  VertexData* targetVertexData);
160 
165 
170 
171 
175 
184  mutable bool mAnimationTypesDirty;
185 
188  mutable bool mPosesIncludeNormals;
189 
190 
196  void prepareImpl(void);
199  void unprepareImpl(void);
201  void loadImpl(void);
203  void postLoadImpl(void);
205  void unloadImpl(void);
207  size_t calculateSize(void) const;
208 
209  void mergeAdjacentTexcoords( unsigned short finalTexCoordSet,
210  unsigned short texCoordSetToDestroy, VertexData *vertexData );
211 
212 
213  public:
218  Mesh(ResourceManager* creator, const String& name, ResourceHandle handle,
219  const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
220  ~Mesh();
221 
222  // NB All methods below are non-virtual since they will be
223  // called in the rendering loop - speed is of the essence.
224 
231  SubMesh* createSubMesh(void);
232 
235  SubMesh* createSubMesh(const String& name);
236 
239  void nameSubMesh(const String& name, ushort index);
240 
243  void unnameSubMesh(const String& name);
244 
250  ushort _getSubMeshIndex(const String& name) const;
251 
254  unsigned short getNumSubMeshes(void) const;
255 
258  SubMesh* getSubMesh(unsigned short index) const;
259 
262  SubMesh* getSubMesh(const String& name) const ;
263 
270  void destroySubMesh(unsigned short index);
271 
278  void destroySubMesh(const String& name);
279 
283  { return SubMeshIterator(mSubMeshList.begin(), mSubMeshList.end()); }
284 
294 
316 
328  MeshPtr clone(const String& newName, const String& newGroup = StringUtil::BLANK);
329 
332  const AxisAlignedBox& getBounds(void) const;
333 
335  Real getBoundingSphereRadius(void) const;
336 
345  void _setBounds(const AxisAlignedBox& bounds, bool pad = true);
346 
354  void _setBoundingSphereRadius(Real radius);
355 
367  void setSkeletonName(const String& skelName);
368 
370  bool hasSkeleton(void) const;
371 
374  bool hasVertexAnimation(void) const;
375 
380  const SkeletonPtr& getSkeleton(void) const;
381 
383  const String& getSkeletonName(void) const;
388  void _initAnimationState(AnimationStateSet* animSet);
389 
394  void _refreshAnimationState(AnimationStateSet* animSet);
407  void addBoneAssignment(const VertexBoneAssignment& vertBoneAssign);
408 
414  void clearBoneAssignments(void);
415 
422  void _notifySkeleton(SkeletonPtr& pSkel);
423 
424 
427  BoneAssignmentIterator getBoneAssignmentIterator(void);
428 
431  const VertexBoneAssignmentList& getBoneAssignments() const { return mBoneAssignments; }
432 
433 
438  ushort getNumLodLevels(void) const;
440  const MeshLodUsage& getLodLevel(ushort index) const;
456  void createManualLodLevel(Real value, const String& meshName, const String& groupName = Ogre::String());
457 
467  void updateManualLodLevel(ushort index, const String& meshName);
468 
475  ushort getLodIndex(Real value) const;
476 
483  bool isLodManual(void) const { return mIsLodManual; }
484 
486  void _setLodInfo(unsigned short numLevels, bool isManual);
488  void _setLodUsage(unsigned short level, MeshLodUsage& usage);
490  void _setSubMeshLodFaceList(unsigned short subIdx, unsigned short level, IndexData* facedata);
491 
493  void removeLodLevels(void);
494 
519  void setVertexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
544  void setIndexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
546  HardwareBuffer::Usage getVertexBufferUsage(void) const { return mVertexBufferUsage; }
548  HardwareBuffer::Usage getIndexBufferUsage(void) const { return mIndexBufferUsage; }
550  bool isVertexBufferShadowed(void) const { return mVertexBufferShadowBuffer; }
552  bool isIndexBufferShadowed(void) const { return mIndexBufferShadowBuffer; }
553 
554 
571  unsigned short _rationaliseBoneAssignments(size_t vertexCount, VertexBoneAssignmentList& assignments);
572 
580  void _compileBoneAssignments(void);
581 
587  void _updateCompiledBoneAssignments(void);
588 
604  void mergeAdjacentTexcoords( unsigned short finalTexCoordSet, unsigned short texCoordSetToDestroy );
605 
606  void _configureMeshLodUsage(const LodConfig& lodConfig);
607 
640  void buildTangentVectors(VertexElementSemantic targetSemantic = VES_TANGENT,
641  unsigned short sourceTexCoordSet = 0, unsigned short index = 0,
642  bool splitMirrored = false, bool splitRotated = false, bool storeParityInW = false);
643 
665  bool suggestTangentVectorBuildParams(VertexElementSemantic targetSemantic,
666  unsigned short& outSourceCoordSet, unsigned short& outIndex);
667 
671  void buildEdgeList(void);
673  void freeEdgeList(void);
674 
693  void prepareForShadowVolume(void);
694 
702  EdgeData* getEdgeList(unsigned short lodIndex = 0);
703 
711  const EdgeData* getEdgeList(unsigned short lodIndex = 0) const;
712 
715  bool isPreparedForShadowVolumes(void) const { return mPreparedForShadowVolumes; }
716 
718  bool isEdgeListBuilt(void) const { return mEdgeListsBuilt; }
719 
734  static void prepareMatricesForVertexBlend(const Matrix4** blendMatrices,
735  const Matrix4* boneMatrices, const IndexMap& indexMap);
736 
760  static void softwareVertexBlend(const VertexData* sourceVertexData,
761  const VertexData* targetVertexData,
762  const Matrix4* const* blendMatrices, size_t numMatrices,
763  bool blendNormals);
764 
781  static void softwareVertexMorph(Real t,
784  VertexData* targetVertexData);
785 
805  static void softwareVertexPoseBlend(Real weight,
806  const map<size_t, Vector3>::type& vertexOffsetMap,
807  const map<size_t, Vector3>::type& normalsMap,
808  VertexData* targetVertexData);
810  const SubMeshNameMap& getSubMeshNameMap(void) const { return mSubMeshNameMap; }
811 
822  void setAutoBuildEdgeLists(bool autobuild) { mAutoBuildEdgeLists = autobuild; }
827  bool getAutoBuildEdgeLists(void) const { return mAutoBuildEdgeLists; }
828 
831  virtual VertexAnimationType getSharedVertexDataAnimationType(void) const;
832 
834  bool getSharedVertexDataAnimationIncludesNormals() const { return mSharedVertexDataAnimationIncludesNormals; }
835 
842  virtual Animation* createAnimation(const String& name, Real length);
843 
848  virtual Animation* getAnimation(const String& name) const;
849 
855  virtual Animation* _getAnimationImpl(const String& name) const;
856 
858  virtual bool hasAnimation(const String& name) const;
859 
861  virtual void removeAnimation(const String& name);
862 
864  virtual unsigned short getNumAnimations(void) const;
865 
868  virtual Animation* getAnimation(unsigned short index) const;
869 
871  virtual void removeAllAnimations(void);
877  VertexData* getVertexDataByTrackHandle(unsigned short handle);
889  void updateMaterialForAllSubMeshes(void);
890 
895  void _determineAnimationTypes(void) const;
897  bool _getAnimationTypesDirty(void) const { return mAnimationTypesDirty; }
898 
908  Pose* createPose(ushort target, const String& name = StringUtil::BLANK);
910  size_t getPoseCount(void) const { return mPoseList.size(); }
912  Pose* getPose(ushort index);
914  Pose* getPose(const String& name);
919  void removePose(ushort index);
924  void removePose(const String& name);
926  void removeAllPoses(void);
927 
930 
932  PoseIterator getPoseIterator(void);
934  ConstPoseIterator getPoseIterator(void) const;
936  const PoseList& getPoseList(void) const;
937 
939  const LodStrategy *getLodStrategy() const;
941  void setLodStrategy(LodStrategy *lodStrategy);
942 
943  };
944 
947  {
953 
960 
968  mutable EdgeData* edgeData;
969 
970  MeshLodUsage() : userValue(0.0), value(0.0), edgeData(0) {}
971  };
972 
977 } // namespace Ogre
978 
979 #include "OgreHeaderSuffix.h"
980 
981 #endif // __Mesh_H__

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Oct 23 2013 06:57:24