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 "OgreAnimationState.h" 00035 #include "OgreIteratorWrappers.h" 00036 #include "OgreProgressiveMesh.h" 00037 #include "OgreHardwareVertexBuffer.h" 00038 #include "OgreSkeleton.h" 00039 00040 00041 namespace Ogre { 00042 00043 00078 struct MeshLodUsage; 00079 00080 class _OgreExport Mesh: public Resource 00081 { 00082 friend class SubMesh; 00083 friend class MeshSerializerImpl; 00084 friend class MeshSerializerImpl_v1_2; 00085 friend class MeshSerializerImpl_v1_1; 00086 00087 public: 00088 typedef std::vector<Real> LodDistanceList; 00090 typedef std::multimap<size_t, VertexBoneAssignment> VertexBoneAssignmentList; 00091 typedef MapIterator<VertexBoneAssignmentList> BoneAssignmentIterator; 00092 typedef std::vector<SubMesh*> SubMeshList; 00093 00094 protected: 00101 SubMeshList mSubMeshList; 00102 00104 void organiseTangentsBuffer(VertexData *vertexData, unsigned short destCoordSet); 00105 00106 public: 00110 typedef HashMap<String, ushort> SubMeshNameMap ; 00111 protected: 00112 SubMeshNameMap mSubMeshNameMap ; 00113 00115 AxisAlignedBox mAABB; 00117 Real mBoundRadius; 00118 00120 String mSkeletonName; 00121 SkeletonPtr mSkeleton; 00122 00123 00124 VertexBoneAssignmentList mBoneAssignments; 00125 00127 bool mBoneAssignmentsOutOfDate; 00128 00130 void compileBoneAssignments(const VertexBoneAssignmentList& boneAssignments, 00131 unsigned short numBlendWeightsPerVertex, 00132 VertexData* targetVertexData); 00134 void compileBoneAssignmentsSoftware(const VertexBoneAssignmentList& boneAssignments, 00135 unsigned short numBlendWeightsPerVertex, VertexData* targetVertexData); 00136 00137 00138 bool mIsLodManual; 00139 ushort mNumLods; 00140 typedef std::vector<MeshLodUsage> MeshLodUsageList; 00141 MeshLodUsageList mMeshLodUsageList; 00142 00143 HardwareBuffer::Usage mVertexBufferUsage; 00144 HardwareBuffer::Usage mIndexBufferUsage; 00145 bool mVertexBufferShadowBuffer; 00146 bool mIndexBufferShadowBuffer; 00147 00148 00149 bool mPreparedForShadowVolumes; 00150 bool mEdgeListsBuilt; 00151 bool mAutoBuildEdgeLists; 00152 00154 void loadImpl(void); 00156 void unloadImpl(void); 00158 size_t calculateSize(void) const; 00159 00160 public: 00165 Mesh(ResourceManager* creator, const String& name, ResourceHandle handle, 00166 const String& group, bool isManual = false, ManualResourceLoader* loader = 0); 00167 ~Mesh(); 00168 00170 void load(void); 00171 00172 // NB All methods below are non-virtual since they will be 00173 // called in the rendering loop - speed is of the essence. 00174 00181 SubMesh* createSubMesh(void); 00182 00185 SubMesh* createSubMesh(const String& name); 00186 00189 void nameSubMesh(const String& name, ushort index); 00190 00196 ushort _getSubMeshIndex(const String& name) const; 00197 00200 unsigned short getNumSubMeshes(void) const; 00201 00204 SubMesh* getSubMesh(unsigned short index) const; 00205 00208 SubMesh* getSubMesh(const String& name) const ; 00209 00210 typedef VectorIterator<SubMeshList> SubMeshIterator; 00212 SubMeshIterator getSubMeshIterator(void) 00213 { return SubMeshIterator(mSubMeshList.begin(), mSubMeshList.end()); } 00214 00223 VertexData *sharedVertexData; 00224 00234 MeshPtr clone(const String& newName, const String& newGroup = StringUtil::BLANK); 00235 00238 const AxisAlignedBox& getBounds(void) const; 00239 00241 Real getBoundingSphereRadius(void) const; 00242 00251 void _setBounds(const AxisAlignedBox& bounds, bool pad = true); 00252 00260 void _setBoundingSphereRadius(Real radius); 00261 00272 void setSkeletonName(const String& skelName); 00273 00275 bool hasSkeleton(void) const; 00276 00280 const SkeletonPtr& getSkeleton(void) const; 00281 00283 const String& getSkeletonName(void) const; 00288 void _initAnimationState(AnimationStateSet* animSet); 00289 00302 void addBoneAssignment(const VertexBoneAssignment& vertBoneAssign); 00303 00309 void clearBoneAssignments(void); 00310 00317 void _notifySkeleton(SkeletonPtr& pSkel); 00318 00319 00322 BoneAssignmentIterator getBoneAssignmentIterator(void); 00323 00324 00348 void generateLodLevels(const LodDistanceList& lodDistances, 00349 ProgressiveMesh::VertexReductionQuota reductionMethod, Real reductionValue); 00350 00355 ushort getNumLodLevels(void) const; 00357 const MeshLodUsage& getLodLevel(ushort index) const; 00371 void createManualLodLevel(Real fromDepth, const String& meshName); 00372 00380 void updateManualLodLevel(ushort index, const String& meshName); 00381 00384 ushort getLodIndex(Real depth) const; 00385 00392 ushort getLodIndexSquaredDepth(Real squaredDepth) const; 00393 00400 bool isLodManual(void) const { return mIsLodManual; } 00401 00403 void _setLodInfo(unsigned short numLevels, bool isManual); 00405 void _setLodUsage(unsigned short level, MeshLodUsage& usage); 00407 void _setSubMeshLodFaceList(unsigned short subIdx, unsigned short level, IndexData* facedata); 00408 00410 void removeLodLevels(void); 00411 00434 void setVertexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false); 00457 void setIndexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false); 00459 HardwareBuffer::Usage getVertexBufferUsage(void) const { return mVertexBufferUsage; } 00461 HardwareBuffer::Usage getIndexBufferUsage(void) const { return mIndexBufferUsage; } 00463 bool isVertexBufferShadowed(void) const { return mVertexBufferShadowBuffer; } 00465 bool isIndexBufferShadowed(void) const { return mIndexBufferShadowBuffer; } 00466 00467 00481 unsigned short _rationaliseBoneAssignments(size_t vertexCount, VertexBoneAssignmentList& assignments); 00482 00490 void _compileBoneAssignments(void); 00491 00509 void buildTangentVectors(unsigned short sourceTexCoordSet = 0, unsigned short destTexCoordSet = 1); 00510 00523 bool suggestTangentVectorBuildParams(unsigned short& outSourceCoordSet, unsigned short& outDestCoordSet); 00524 00528 void buildEdgeList(void); 00530 void freeEdgeList(void); 00531 00550 void prepareForShadowVolume(void); 00551 00558 EdgeData* getEdgeList(unsigned int lodIndex = 0); 00559 00566 const EdgeData* getEdgeList(unsigned int lodIndex = 0) const; 00567 00570 bool isPreparedForShadowVolumes(void) const { return mPreparedForShadowVolumes; } 00571 00573 bool isEdgeListBuilt(void) const { return mEdgeListsBuilt; } 00574 00590 static void softwareVertexBlend(const VertexData* sourceVertexData, 00591 const VertexData* targetVertexData, const Matrix4* pMatrices, 00592 bool blendNormals); 00593 00595 const SubMeshNameMap& getSubMeshNameMap(void) const { return mSubMeshNameMap; } 00596 00607 void setAutoBuildEdgeLists(bool autobuild) { mAutoBuildEdgeLists = autobuild; } 00612 bool getAutoBuildEdgeLists(void) const { return mAutoBuildEdgeLists; } 00613 00614 00615 }; 00616 00623 class _OgreExport MeshPtr : public SharedPtr<Mesh> 00624 { 00625 public: 00626 MeshPtr() : SharedPtr<Mesh>() {} 00627 explicit MeshPtr(Mesh* rep) : SharedPtr<Mesh>(rep) {} 00628 MeshPtr(const MeshPtr& r) : SharedPtr<Mesh>(r) {} 00629 MeshPtr(const ResourcePtr& r); 00631 MeshPtr& operator=(const ResourcePtr& r); 00632 protected: 00634 void destroy(void); 00635 }; 00636 00638 struct MeshLodUsage 00639 { 00641 Real fromDepthSquared; 00643 String manualName; 00645 mutable MeshPtr manualMesh; 00647 mutable EdgeData* edgeData; 00648 }; 00649 00650 00651 00652 } // namespace 00653 00654 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 12 12:59:48 2006