Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class 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 (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 
00346         void addBoneAssignment(const VertexBoneAssignment& vertBoneAssign);
00347 
00353         void clearBoneAssignments(void);
00354 
00361         void _notifySkeleton(SkeletonPtr& pSkel);
00362 
00363 
00366         BoneAssignmentIterator getBoneAssignmentIterator(void);
00367 
00368 
00392         void generateLodLevels(const LodDistanceList& lodDistances, 
00393             ProgressiveMesh::VertexReductionQuota reductionMethod, Real reductionValue);
00394 
00399         ushort getNumLodLevels(void) const;
00401         const MeshLodUsage& getLodLevel(ushort index) const;
00415         void createManualLodLevel(Real fromDepth, const String& meshName);
00416 
00424         void updateManualLodLevel(ushort index, const String& meshName);
00425 
00428         ushort getLodIndex(Real depth) const;
00429 
00436         ushort getLodIndexSquaredDepth(Real squaredDepth) const;
00437 
00444         bool isLodManual(void) const { return mIsLodManual; }
00445 
00447         void _setLodInfo(unsigned short numLevels, bool isManual);
00449         void _setLodUsage(unsigned short level, MeshLodUsage& usage);
00451         void _setSubMeshLodFaceList(unsigned short subIdx, unsigned short level, IndexData* facedata);
00452 
00454         void removeLodLevels(void);
00455 
00478         void setVertexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
00501         void setIndexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
00503         HardwareBuffer::Usage getVertexBufferUsage(void) const { return mVertexBufferUsage; }
00505         HardwareBuffer::Usage getIndexBufferUsage(void) const { return mIndexBufferUsage; }
00507         bool isVertexBufferShadowed(void) const { return mVertexBufferShadowBuffer; }
00509         bool isIndexBufferShadowed(void) const { return mIndexBufferShadowBuffer; }
00510        
00511 
00525         unsigned short _rationaliseBoneAssignments(size_t vertexCount, VertexBoneAssignmentList& assignments);
00526 
00534         void _compileBoneAssignments(void);
00535 
00541         void _updateCompiledBoneAssignments(void);
00542 
00560         void buildTangentVectors(unsigned short sourceTexCoordSet = 0, unsigned short destTexCoordSet = 1);
00561 
00574         bool suggestTangentVectorBuildParams(unsigned short& outSourceCoordSet, unsigned short& outDestCoordSet);
00575 
00579         void buildEdgeList(void);
00581         void freeEdgeList(void);
00582 
00601         void prepareForShadowVolume(void);
00602 
00609         EdgeData* getEdgeList(unsigned int lodIndex = 0);
00610 
00617         const EdgeData* getEdgeList(unsigned int lodIndex = 0) const;
00618 
00621         bool isPreparedForShadowVolumes(void) const { return mPreparedForShadowVolumes; }
00622 
00624         bool isEdgeListBuilt(void) const { return mEdgeListsBuilt; }
00625 
00643         static void softwareVertexBlend(const VertexData* sourceVertexData, 
00644             const VertexData* targetVertexData, const Matrix4* pMatrices, 
00645             const unsigned short* pIndexMap,
00646             bool blendNormals);
00647 
00660         static void softwareVertexMorph(Real t, 
00661             const HardwareVertexBufferSharedPtr& b1, 
00662             const HardwareVertexBufferSharedPtr& b2, 
00663             VertexData* targetVertexData);
00664 
00679         static void softwareVertexPoseBlend(Real weight, 
00680             const std::map<size_t, Vector3>& vertexOffsetMap,
00681             VertexData* targetVertexData);
00683         const SubMeshNameMap& getSubMeshNameMap(void) const { return mSubMeshNameMap; }
00684 
00695         void setAutoBuildEdgeLists(bool autobuild) { mAutoBuildEdgeLists = autobuild; }
00700         bool getAutoBuildEdgeLists(void) const { return mAutoBuildEdgeLists; }
00701 
00704         virtual VertexAnimationType getSharedVertexDataAnimationType(void) const;
00705 
00710         virtual Animation* createAnimation(const String& name, Real length);
00711 
00715         virtual Animation* getAnimation(const String& name) const;
00716 
00721         virtual Animation* _getAnimationImpl(const String& name) const;
00722 
00724         virtual bool hasAnimation(const String& name);
00725 
00727         virtual void removeAnimation(const String& name);
00728 
00730         virtual unsigned short getNumAnimations(void) const;
00731 
00734         virtual Animation* getAnimation(unsigned short index) const;
00735 
00737         virtual void removeAllAnimations(void);
00743         VertexData* getVertexDataByTrackHandle(unsigned short handle);
00755         void updateMaterialForAllSubMeshes(void);
00756 
00761         void _determineAnimationTypes(void) const;
00763         bool _getAnimationTypesDirty(void) const { return mAnimationTypesDirty; }
00764 
00771         Pose* createPose(ushort target, const String& name = StringUtil::BLANK);
00773         size_t getPoseCount(void) const { return mPoseList.size(); }
00775         Pose* getPose(ushort index);
00777         Pose* getPose(const String& name);
00781         void removePose(ushort index);
00785         void removePose(const String& name);
00787         void removeAllPoses(void);
00788 
00789         typedef VectorIterator<PoseList> PoseIterator;
00790         typedef ConstVectorIterator<PoseList> ConstPoseIterator;
00791 
00793         PoseIterator getPoseIterator(void);
00795         ConstPoseIterator getPoseIterator(void) const;
00797         const PoseList& getPoseList(void) const;
00798 
00799     };
00800 
00807     class _OgreExport MeshPtr : public SharedPtr<Mesh> 
00808     {
00809     public:
00810         MeshPtr() : SharedPtr<Mesh>() {}
00811         explicit MeshPtr(Mesh* rep) : SharedPtr<Mesh>(rep) {}
00812         MeshPtr(const MeshPtr& r) : SharedPtr<Mesh>(r) {} 
00813         MeshPtr(const ResourcePtr& r);
00815         MeshPtr& operator=(const ResourcePtr& r);
00816     protected:
00818         void destroy(void);
00819     };
00820 
00822     struct MeshLodUsage
00823     {
00825         Real fromDepthSquared;
00827         String manualName;
00829         mutable MeshPtr manualMesh;
00831         mutable EdgeData* edgeData;
00832     };
00833 
00834 
00835 
00836 } // namespace
00837 
00838 #endif

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:44 2006