00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2005 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 #ifndef __Mesh_H__ 00026 #define __Mesh_H__ 00027 00028 #include "OgrePrerequisites.h" 00029 00030 #include "OgreResource.h" 00031 #include "OgreVertexIndexData.h" 00032 #include "OgreAxisAlignedBox.h" 00033 #include "OgreVertexBoneAssignment.h" 00034 #include "OgreIteratorWrappers.h" 00035 #include "OgreProgressiveMesh.h" 00036 #include "OgreHardwareVertexBuffer.h" 00037 #include "OgreSkeleton.h" 00038 #include "OgreAnimationTrack.h" 00039 #include "OgrePose.h" 00040 00041 00042 namespace Ogre { 00043 00044 00079 struct MeshLodUsage; 00080 00081 class _OgreExport Mesh: public Resource 00082 { 00083 friend class SubMesh; 00084 friend class MeshSerializerImpl; 00085 friend class MeshSerializerImpl_v1_2; 00086 friend class MeshSerializerImpl_v1_1; 00087 00088 public: 00089 typedef std::vector<Real> LodDistanceList; 00091 typedef std::multimap<size_t, VertexBoneAssignment> VertexBoneAssignmentList; 00092 typedef MapIterator<VertexBoneAssignmentList> BoneAssignmentIterator; 00093 typedef std::vector<SubMesh*> SubMeshList; 00094 typedef std::vector<unsigned short> IndexMap; 00095 00096 protected: 00103 SubMeshList mSubMeshList; 00104 00106 void organiseTangentsBuffer(VertexData *vertexData, unsigned short destCoordSet); 00107 00108 public: 00112 typedef HashMap<String, ushort> SubMeshNameMap ; 00113 00114 00115 protected: 00116 SubMeshNameMap mSubMeshNameMap ; 00117 00119 AxisAlignedBox mAABB; 00121 Real mBoundRadius; 00122 00124 String mSkeletonName; 00125 SkeletonPtr mSkeleton; 00126 00127 00128 VertexBoneAssignmentList mBoneAssignments; 00129 00131 bool mBoneAssignmentsOutOfDate; 00132 00134 void buildIndexMap(const VertexBoneAssignmentList& boneAssignments, 00135 IndexMap& boneIndexToBlendIndexMap, IndexMap& blendIndexToBoneIndexMap); 00137 void compileBoneAssignments(const VertexBoneAssignmentList& boneAssignments, 00138 unsigned short numBlendWeightsPerVertex, 00139 IndexMap& blendIndexToBoneIndexMap, 00140 VertexData* targetVertexData); 00141 00142 bool mIsLodManual; 00143 ushort mNumLods; 00144 typedef std::vector<MeshLodUsage> MeshLodUsageList; 00145 MeshLodUsageList mMeshLodUsageList; 00146 00147 HardwareBuffer::Usage mVertexBufferUsage; 00148 HardwareBuffer::Usage mIndexBufferUsage; 00149 bool mVertexBufferShadowBuffer; 00150 bool mIndexBufferShadowBuffer; 00151 00152 00153 bool mPreparedForShadowVolumes; 00154 bool mEdgeListsBuilt; 00155 bool mAutoBuildEdgeLists; 00156 00158 typedef std::map<String, Animation*> AnimationList; 00159 AnimationList mAnimationsList; 00161 mutable VertexAnimationType mSharedVertexDataAnimationType; 00163 mutable bool mAnimationTypesDirty; 00164 00166 PoseList mPoseList; 00167 00168 00170 void loadImpl(void); 00172 void unloadImpl(void); 00174 size_t calculateSize(void) const; 00175 00176 00177 00178 public: 00183 Mesh(ResourceManager* creator, const String& name, ResourceHandle handle, 00184 const String& group, bool isManual = false, ManualResourceLoader* loader = 0); 00185 ~Mesh(); 00186 00188 void load(void); 00189 00190 // NB All methods below are non-virtual since they will be 00191 // called in the rendering loop - speed is of the essence. 00192 00199 SubMesh* createSubMesh(void); 00200 00203 SubMesh* createSubMesh(const String& name); 00204 00207 void nameSubMesh(const String& name, ushort index); 00208 00214 ushort _getSubMeshIndex(const String& name) const; 00215 00218 unsigned short getNumSubMeshes(void) const; 00219 00222 SubMesh* getSubMesh(unsigned short index) const; 00223 00226 SubMesh* getSubMesh(const String& name) const ; 00227 00228 typedef VectorIterator<SubMeshList> SubMeshIterator; 00230 SubMeshIterator getSubMeshIterator(void) 00231 { return SubMeshIterator(mSubMeshList.begin(), mSubMeshList.end()); } 00232 00241 VertexData *sharedVertexData; 00242 00263 IndexMap sharedBlendIndexToBoneIndexMap; 00264 00274 MeshPtr clone(const String& newName, const String& newGroup = StringUtil::BLANK); 00275 00278 const AxisAlignedBox& getBounds(void) const; 00279 00281 Real getBoundingSphereRadius(void) const; 00282 00291 void _setBounds(const AxisAlignedBox& bounds, bool pad = true); 00292 00300 void _setBoundingSphereRadius(Real radius); 00301 00312 void setSkeletonName(const String& skelName); 00313 00315 bool hasSkeleton(void) const; 00316 00319 bool hasVertexAnimation(void) const; 00320 00324 const SkeletonPtr& getSkeleton(void) const; 00325 00327 const String& getSkeletonName(void) const; 00332 void _initAnimationState(AnimationStateSet* animSet); 00333 00338 void _refreshAnimationState(AnimationStateSet* animSet); 00351 void addBoneAssignment(const VertexBoneAssignment& vertBoneAssign); 00352 00358 void clearBoneAssignments(void); 00359 00366 void _notifySkeleton(SkeletonPtr& pSkel); 00367 00368 00371 BoneAssignmentIterator getBoneAssignmentIterator(void); 00372 00373 00397 void generateLodLevels(const LodDistanceList& lodDistances, 00398 ProgressiveMesh::VertexReductionQuota reductionMethod, Real reductionValue); 00399 00404 ushort getNumLodLevels(void) const; 00406 const MeshLodUsage& getLodLevel(ushort index) const; 00420 void createManualLodLevel(Real fromDepth, const String& meshName); 00421 00429 void updateManualLodLevel(ushort index, const String& meshName); 00430 00433 ushort getLodIndex(Real depth) const; 00434 00441 ushort getLodIndexSquaredDepth(Real squaredDepth) const; 00442 00449 bool isLodManual(void) const { return mIsLodManual; } 00450 00452 void _setLodInfo(unsigned short numLevels, bool isManual); 00454 void _setLodUsage(unsigned short level, MeshLodUsage& usage); 00456 void _setSubMeshLodFaceList(unsigned short subIdx, unsigned short level, IndexData* facedata); 00457 00459 void removeLodLevels(void); 00460 00483 void setVertexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false); 00506 void setIndexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false); 00508 HardwareBuffer::Usage getVertexBufferUsage(void) const { return mVertexBufferUsage; } 00510 HardwareBuffer::Usage getIndexBufferUsage(void) const { return mIndexBufferUsage; } 00512 bool isVertexBufferShadowed(void) const { return mVertexBufferShadowBuffer; } 00514 bool isIndexBufferShadowed(void) const { return mIndexBufferShadowBuffer; } 00515 00516 00530 unsigned short _rationaliseBoneAssignments(size_t vertexCount, VertexBoneAssignmentList& assignments); 00531 00539 void _compileBoneAssignments(void); 00540 00546 void _updateCompiledBoneAssignments(void); 00547 00565 void buildTangentVectors(unsigned short sourceTexCoordSet = 0, unsigned short destTexCoordSet = 1); 00566 00579 bool suggestTangentVectorBuildParams(unsigned short& outSourceCoordSet, unsigned short& outDestCoordSet); 00580 00584 void buildEdgeList(void); 00586 void freeEdgeList(void); 00587 00606 void prepareForShadowVolume(void); 00607 00614 EdgeData* getEdgeList(unsigned int lodIndex = 0); 00615 00622 const EdgeData* getEdgeList(unsigned int lodIndex = 0) const; 00623 00626 bool isPreparedForShadowVolumes(void) const { return mPreparedForShadowVolumes; } 00627 00629 bool isEdgeListBuilt(void) const { return mEdgeListsBuilt; } 00630 00648 static void softwareVertexBlend(const VertexData* sourceVertexData, 00649 const VertexData* targetVertexData, const Matrix4* pMatrices, 00650 const unsigned short* pIndexMap, 00651 bool blendNormals); 00652 00665 static void softwareVertexMorph(Real t, 00666 const HardwareVertexBufferSharedPtr& b1, 00667 const HardwareVertexBufferSharedPtr& b2, 00668 VertexData* targetVertexData); 00669 00684 static void softwareVertexPoseBlend(Real weight, 00685 const std::map<size_t, Vector3>& vertexOffsetMap, 00686 VertexData* targetVertexData); 00688 const SubMeshNameMap& getSubMeshNameMap(void) const { return mSubMeshNameMap; } 00689 00700 void setAutoBuildEdgeLists(bool autobuild) { mAutoBuildEdgeLists = autobuild; } 00705 bool getAutoBuildEdgeLists(void) const { return mAutoBuildEdgeLists; } 00706 00709 virtual VertexAnimationType getSharedVertexDataAnimationType(void) const; 00710 00715 virtual Animation* createAnimation(const String& name, Real length); 00716 00720 virtual Animation* getAnimation(const String& name) const; 00721 00726 virtual Animation* _getAnimationImpl(const String& name) const; 00727 00729 virtual bool hasAnimation(const String& name); 00730 00732 virtual void removeAnimation(const String& name); 00733 00735 virtual unsigned short getNumAnimations(void) const; 00736 00739 virtual Animation* getAnimation(unsigned short index) const; 00740 00742 virtual void removeAllAnimations(void); 00748 VertexData* getVertexDataByTrackHandle(unsigned short handle); 00760 void updateMaterialForAllSubMeshes(void); 00761 00766 void _determineAnimationTypes(void) const; 00768 bool _getAnimationTypesDirty(void) const { return mAnimationTypesDirty; } 00769 00776 Pose* createPose(ushort target, const String& name = StringUtil::BLANK); 00778 size_t getPoseCount(void) const { return mPoseList.size(); } 00780 Pose* getPose(ushort index); 00782 Pose* getPose(const String& name); 00786 void removePose(ushort index); 00790 void removePose(const String& name); 00792 void removeAllPoses(void); 00793 00794 typedef VectorIterator<PoseList> PoseIterator; 00795 typedef ConstVectorIterator<PoseList> ConstPoseIterator; 00796 00798 PoseIterator getPoseIterator(void); 00800 ConstPoseIterator getPoseIterator(void) const; 00802 const PoseList& getPoseList(void) const; 00803 00804 }; 00805 00812 class _OgreExport MeshPtr : public SharedPtr<Mesh> 00813 { 00814 public: 00815 MeshPtr() : SharedPtr<Mesh>() {} 00816 explicit MeshPtr(Mesh* rep) : SharedPtr<Mesh>(rep) {} 00817 MeshPtr(const MeshPtr& r) : SharedPtr<Mesh>(r) {} 00818 MeshPtr(const ResourcePtr& r); 00820 MeshPtr& operator=(const ResourcePtr& r); 00821 protected: 00823 void destroy(void); 00824 }; 00825 00827 struct MeshLodUsage 00828 { 00830 Real fromDepthSquared; 00832 String manualName; 00834 mutable MeshPtr manualMesh; 00836 mutable EdgeData* edgeData; 00837 }; 00838 00839 00840 00841 } // namespace 00842 00843 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 17 15:39:10 2006