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 © 2000-2002 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 00039 00040 namespace Ogre { 00041 00042 00043 00079 class _OgreExport Mesh: public Resource 00080 { 00081 friend class MeshSerializerImpl; 00082 friend class MeshSerializerImpl_v1_1; 00083 friend class MeshSerializerImpl_v1_2; 00084 friend class SubMesh; 00085 public: 00087 struct MeshLodUsage 00088 { 00090 Real fromDepthSquared; 00092 String manualName; 00094 mutable Mesh* manualMesh; 00096 mutable EdgeData* edgeData; 00097 }; 00098 00099 typedef std::vector<Real> LodDistanceList; 00101 typedef std::multimap<size_t, VertexBoneAssignment> VertexBoneAssignmentList; 00102 typedef MapIterator<VertexBoneAssignmentList> BoneAssignmentIterator; 00103 typedef std::vector<SubMesh*> SubMeshList; 00104 00105 protected: 00112 SubMeshList mSubMeshList; 00113 00115 void organiseTangentsBuffer(VertexData *vertexData, unsigned short destCoordSet); 00116 00117 public: 00121 typedef HashMap<String, ushort> SubMeshNameMap ; 00122 protected: 00123 SubMeshNameMap mSubMeshNameMap ; 00124 00126 AxisAlignedBox mAABB; 00128 Real mBoundRadius; 00129 00130 bool mManuallyDefined; 00131 00132 00134 String mSkeletonName; 00135 Skeleton* mSkeleton; 00136 00137 00138 VertexBoneAssignmentList mBoneAssignments; 00139 00141 bool mBoneAssignmentsOutOfDate; 00142 00144 void compileBoneAssignments(const VertexBoneAssignmentList& boneAssignments, 00145 unsigned short numBlendWeightsPerVertex, 00146 VertexData* targetVertexData); 00148 void compileBoneAssignmentsSoftware(const VertexBoneAssignmentList& boneAssignments, 00149 unsigned short numBlendWeightsPerVertex, VertexData* targetVertexData); 00150 00151 00152 bool mIsLodManual; 00153 ushort mNumLods; 00154 typedef std::vector<MeshLodUsage> MeshLodUsageList; 00155 MeshLodUsageList mMeshLodUsageList; 00156 00157 HardwareBuffer::Usage mVertexBufferUsage; 00158 HardwareBuffer::Usage mIndexBufferUsage; 00159 bool mVertexBufferShadowBuffer; 00160 bool mIndexBufferShadowBuffer; 00161 00162 00163 bool mPreparedForShadowVolumes; 00164 bool mEdgeListsBuilt; 00165 bool mAutoBuildEdgeLists; 00166 00167 public: 00172 Mesh(const String& name); 00173 ~Mesh(); 00174 00177 virtual void load(void); 00178 00181 virtual void unload(void); 00182 00183 // NB All methods below are non-virtual since they will be 00184 // called in the rendering loop - speed is of the essence. 00185 00192 SubMesh* createSubMesh(void); 00193 00196 SubMesh* createSubMesh(const String& name); 00197 00200 void nameSubMesh(const String& name, ushort index); 00201 00207 ushort _getSubMeshIndex(const String& name) const; 00208 00211 unsigned short getNumSubMeshes(void) const; 00212 00215 SubMesh* getSubMesh(unsigned short index) const; 00216 00219 SubMesh* getSubMesh(const String& name) const ; 00220 00221 typedef VectorIterator<SubMeshList> SubMeshIterator; 00223 SubMeshIterator getSubMeshIterator(void) 00224 { return SubMeshIterator(mSubMeshList.begin(), mSubMeshList.end()); } 00225 00234 VertexData *sharedVertexData; 00235 00243 void setManuallyDefined(bool manuallyDefined); 00244 00250 Mesh* clone(const String& newName); 00251 00254 const AxisAlignedBox& getBounds(void) const; 00255 00257 Real getBoundingSphereRadius(void) const; 00258 00267 void _setBounds(const AxisAlignedBox& bounds, bool pad = true); 00268 00276 void _setBoundingSphereRadius(Real radius); 00277 00288 void setSkeletonName(const String& skelName); 00289 00291 bool hasSkeleton(void) const; 00292 00294 Skeleton* getSkeleton(void) const; 00295 00297 const String& getSkeletonName(void) const; 00302 void _initAnimationState(AnimationStateSet* animSet); 00303 00316 void addBoneAssignment(const VertexBoneAssignment& vertBoneAssign); 00317 00323 void clearBoneAssignments(void); 00324 00331 void _notifySkeleton(Skeleton* pSkel); 00332 00333 00336 BoneAssignmentIterator getBoneAssignmentIterator(void); 00337 00338 00362 void generateLodLevels(const LodDistanceList& lodDistances, 00363 ProgressiveMesh::VertexReductionQuota reductionMethod, Real reductionValue); 00364 00369 ushort getNumLodLevels(void) const; 00371 const MeshLodUsage& getLodLevel(ushort index) const; 00385 void createManualLodLevel(Real fromDepth, const String& meshName); 00386 00394 void updateManualLodLevel(ushort index, const String& meshName); 00395 00398 ushort getLodIndex(Real depth) const; 00399 00406 ushort getLodIndexSquaredDepth(Real squaredDepth) const; 00407 00414 bool isLodManual(void) const { return mIsLodManual; } 00415 00417 void _setLodInfo(unsigned short numLevels, bool isManual); 00419 void _setLodUsage(unsigned short level, Mesh::MeshLodUsage& usage); 00421 void _setSubMeshLodFaceList(unsigned short subIdx, unsigned short level, IndexData* facedata); 00422 00424 void removeLodLevels(void); 00425 00448 void setVertexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false); 00471 void setIndexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false); 00473 HardwareBuffer::Usage getVertexBufferUsage(void) const { return mVertexBufferUsage; } 00475 HardwareBuffer::Usage getIndexBufferUsage(void) const { return mIndexBufferUsage; } 00477 bool isVertexBufferShadowed(void) const { return mVertexBufferShadowBuffer; } 00479 bool isIndexBufferShadowed(void) const { return mIndexBufferShadowBuffer; } 00480 00481 00495 unsigned short _rationaliseBoneAssignments(size_t vertexCount, VertexBoneAssignmentList& assignments); 00496 00504 void _compileBoneAssignments(void); 00505 00523 void buildTangentVectors(unsigned short sourceTexCoordSet = 0, unsigned short destTexCoordSet = 1); 00524 00537 bool suggestTangentVectorBuildParams(unsigned short& outSourceCoordSet, unsigned short& outDestCoordSet); 00538 00542 void buildEdgeList(void); 00544 void freeEdgeList(void); 00545 00564 void prepareForShadowVolume(void); 00565 00572 EdgeData* getEdgeList(unsigned int lodIndex = 0); 00573 00580 const EdgeData* getEdgeList(unsigned int lodIndex = 0) const; 00581 00584 bool isPreparedForShadowVolumes(void) const { return mPreparedForShadowVolumes; } 00585 00587 bool isEdgeListBuilt(void) const { return mEdgeListsBuilt; } 00588 00604 static void softwareVertexBlend(const VertexData* sourceVertexData, 00605 const VertexData* targetVertexData, const Matrix4* pMatrices, 00606 bool blendNormals); 00607 00609 const SubMeshNameMap& getSubMeshNameMap(void) const { return mSubMeshNameMap; } 00610 00621 void setAutoBuildEdgeLists(bool autobuild) { mAutoBuildEdgeLists = autobuild; } 00626 bool getAutoBuildEdgeLists(void) const { return mAutoBuildEdgeLists; } 00627 00628 00629 }; 00630 00631 00632 } // namespace 00633 00634 #endif
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:34 2004