Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreMesh.h

Go to the documentation of this file.
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;
00083         friend class SubMesh;
00084     public:
00086         struct MeshLodUsage
00087         {
00089             Real fromDepthSquared;
00091             String manualName;
00093             mutable Mesh* manualMesh;
00095             EdgeData* edgeData;
00096         };
00097 
00098         typedef std::vector<Real> LodDistanceList;
00100         typedef std::multimap<size_t, VertexBoneAssignment> VertexBoneAssignmentList;
00101         typedef MapIterator<VertexBoneAssignmentList> BoneAssignmentIterator;
00102         typedef std::vector<SubMesh*> SubMeshList;
00103 
00104     protected:
00111         SubMeshList mSubMeshList;
00112     
00114         HardwareVertexBufferSharedPtr getTangentsBuffer(VertexData *vertexData, unsigned short texCoordSet);
00115 
00116     public:
00120         typedef HashMap<String, ushort, _StringHash> SubMeshNameMap ;
00121     protected:
00122         SubMeshNameMap mSubMeshNameMap ;
00123 
00125         AxisAlignedBox mAABB;
00127         Real mBoundRadius;
00128 
00129         bool mManuallyDefined;
00130 
00131 
00133         //bool mUpdateBounds;
00134 
00136         String mSkeletonName;
00137         Skeleton* mSkeleton;
00138 
00139        
00140         VertexBoneAssignmentList mBoneAssignments;
00141 
00143         bool mBoneAssignmentsOutOfDate;
00144 
00146         void compileBoneAssignments(const VertexBoneAssignmentList& boneAssignments,
00147             unsigned short numBlendWeightsPerVertex, 
00148             VertexData* targetVertexData);
00150         void compileBoneAssignmentsSoftware(const VertexBoneAssignmentList& boneAssignments,
00151             unsigned short numBlendWeightsPerVertex, VertexData* targetVertexData);
00152 
00153 
00154         bool mIsLodManual;
00155         ushort mNumLods;
00156         typedef std::vector<MeshLodUsage> MeshLodUsageList;
00157         MeshLodUsageList mMeshLodUsageList;
00158 
00159         HardwareBuffer::Usage mVertexBufferUsage;
00160         HardwareBuffer::Usage mIndexBufferUsage;
00161         bool mVertexBufferShadowBuffer;
00162         bool mIndexBufferShadowBuffer;
00163 
00164 
00165         bool mPreparedForShadowVolumes;
00166         bool mEdgeListsBuilt;
00167 
00168     public:
00173         Mesh(const String& name);
00174         ~Mesh();
00175 
00178         virtual void load(void);
00179 
00182         virtual void unload(void);
00183 
00184         // NB All methods below are non-virtual since they will be
00185         // called in the rendering loop - speed is of the essence.
00186 
00193         SubMesh* createSubMesh(void);
00194 
00197         SubMesh* createSubMesh(const String& name);
00198         
00201         void nameSubMesh(const String& name, ushort index);
00202         
00208         ushort _getSubMeshIndex(const String& name) const;
00209 
00212         unsigned short getNumSubMeshes(void) const;
00213 
00216         SubMesh* getSubMesh(unsigned short index) const;
00217 
00220         SubMesh* getSubMesh(const String& name) const ;
00221 
00222         typedef VectorIterator<SubMeshList> SubMeshIterator;
00224         SubMeshIterator getSubMeshIterator(void)
00225         { return SubMeshIterator(mSubMeshList.begin(), mSubMeshList.end()); }
00226       
00235         VertexData *sharedVertexData;
00236 
00244         void setManuallyDefined(bool manuallyDefined);
00245 
00251         Mesh* clone(const String& newName);
00252 
00255         const AxisAlignedBox& getBounds(void) const;
00256 
00258         Real getBoundingSphereRadius(void) const;
00259 
00275         void _setBounds(const AxisAlignedBox& bounds);
00276 
00284         void _setBoundingSphereRadius(Real radius);
00285 
00296         void setSkeletonName(const String& skelName);
00297 
00299         bool hasSkeleton(void) const;
00300 
00302         Skeleton* getSkeleton(void) const;
00303 
00305         const String& getSkeletonName(void) const;
00310         void _initAnimationState(AnimationStateSet* animSet);
00311 
00324         void addBoneAssignment(const VertexBoneAssignment& vertBoneAssign);
00325 
00331         void clearBoneAssignments(void);
00332 
00339         void _notifySkeleton(Skeleton* pSkel);
00340 
00341 
00344         BoneAssignmentIterator getBoneAssignmentIterator(void);
00345 
00346 
00370         void generateLodLevels(const LodDistanceList& lodDistances, 
00371             ProgressiveMesh::VertexReductionQuota reductionMethod, Real reductionValue);
00372 
00377         ushort getNumLodLevels(void) const;
00379         const MeshLodUsage& getLodLevel(ushort index) const;
00393         void createManualLodLevel(Real fromDepth, const String& meshName);
00394 
00402         void updateManualLodLevel(ushort index, const String& meshName);
00403 
00406         ushort getLodIndex(Real depth) const;
00407 
00414         ushort getLodIndexSquaredDepth(Real squaredDepth) const;
00415 
00422         bool isLodManual(void) const { return mIsLodManual; }
00423 
00425         void _setLodInfo(unsigned short numLevels, bool isManual);
00427         void _setLodUsage(unsigned short level, Mesh::MeshLodUsage& usage);
00429         void _setSubMeshLodFaceList(unsigned short subIdx, unsigned short level, IndexData* facedata);
00430 
00432         void removeLodLevels(void);
00433 
00456         void setVertexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
00479         void setIndexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
00481         HardwareBuffer::Usage getVertexBufferUsage(void) const { return mVertexBufferUsage; }
00483         HardwareBuffer::Usage getIndexBufferUsage(void) const { return mIndexBufferUsage; }
00485         bool isVertexBufferShadowed(void) const { return mVertexBufferShadowBuffer; }
00487         bool isIndexBufferShadowed(void) const { return mIndexBufferShadowBuffer; }
00488        
00489 
00503         unsigned short _rationaliseBoneAssignments(size_t vertexCount, VertexBoneAssignmentList& assignments);
00504 
00512         void _compileBoneAssignments(void);
00513 
00531         void buildTangentVectors(unsigned short sourceTexCoordSet = 0, unsigned short destTexCoordSet = 1);
00532 
00536         void buildEdgeList(void);
00538         void freeEdgeList(void);
00539 
00558         void prepareForShadowVolume(void);
00559 
00566         EdgeData* getEdgeList(unsigned int lodIndex = 0);
00567 
00570         bool isPreparedForShadowVolumes(void) { return mPreparedForShadowVolumes; }
00571 
00572 
00588         static void softwareVertexBlend(const VertexData* sourceVertexData, 
00589             const VertexData* targetVertexData, const Matrix4* pMatrices, 
00590             bool blendNormals);
00591 
00593         const SubMeshNameMap& getSubMeshNameMap(void) const { return mSubMeshNameMap; }
00594 
00595     };
00596 
00597 
00598 } // namespace
00599 
00600 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:25 2004