# 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-2006 Torus Knot Software Ltd
    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 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __Mesh_H__
    00030 #define __Mesh_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033
    00034 #include "OgreResource.h"
    00035 #include "OgreVertexIndexData.h"
    00036 #include "OgreAxisAlignedBox.h"
    00037 #include "OgreVertexBoneAssignment.h"
    00038 #include "OgreIteratorWrappers.h"
    00039 #include "OgreProgressiveMesh.h"
    00040 #include "OgreHardwareVertexBuffer.h"
    00041 #include "OgreSkeleton.h"
    00042 #include "OgreAnimationTrack.h"
    00043 #include "OgrePose.h"
    00044 #include "OgreDataStream.h"
    00045
    00046
    00047 namespace Ogre {
    00048
    00049
    00084     struct MeshLodUsage;
    00085
    00086     class _OgreExport Mesh: public Resource
    00087     {
    00088         friend class SubMesh;
    00089         friend class MeshSerializerImpl;
    00090         friend class MeshSerializerImpl_v1_2;
    00091         friend class MeshSerializerImpl_v1_1;
    00092
    00093     public:
    00094         typedef std::vector<Real> LodDistanceList;
    00096         typedef std::multimap<size_t, VertexBoneAssignment> VertexBoneAssignmentList;
    00097         typedef MapIterator<VertexBoneAssignmentList> BoneAssignmentIterator;
    00098         typedef std::vector<SubMesh*> SubMeshList;
    00099         typedef std::vector<unsigned short> IndexMap;
    00100
    00101     protected:
    00108         SubMeshList mSubMeshList;
    00109
    00111         void organiseTangentsBuffer(VertexData *vertexData,
    00112             VertexElementSemantic targetSemantic, unsigned short index,
    00113             unsigned short sourceTexCoordSet);
    00114
    00115     public:
    00119         typedef HashMap<String, ushort> SubMeshNameMap ;
    00120
    00121
    00122     protected:
    00123
    00124         DataStreamPtr mFreshFromDisk;
    00125
    00126         SubMeshNameMap mSubMeshNameMap ;
    00127
    00129         AxisAlignedBox mAABB;
    00131         Real mBoundRadius;
    00132
    00134         String mSkeletonName;
    00135         SkeletonPtr mSkeleton;
    00136
    00137
    00138         VertexBoneAssignmentList mBoneAssignments;
    00139
    00141         bool mBoneAssignmentsOutOfDate;
    00142
    00144         void buildIndexMap(const VertexBoneAssignmentList& boneAssignments,
    00145             IndexMap& boneIndexToBlendIndexMap, IndexMap& blendIndexToBoneIndexMap);
    00147         void compileBoneAssignments(const VertexBoneAssignmentList& boneAssignments,
    00148             unsigned short numBlendWeightsPerVertex,
    00149             IndexMap& blendIndexToBoneIndexMap,
    00150             VertexData* targetVertexData);
    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
    00168         typedef std::map<String, Animation*> AnimationList;
    00169         AnimationList mAnimationsList;
    00171         mutable VertexAnimationType mSharedVertexDataAnimationType;
    00173         mutable bool mAnimationTypesDirty;
    00174
    00176         PoseList mPoseList;
    00177
    00178
    00184         void prepareImpl(void);
    00187         void unprepareImpl(void);
    00189         void loadImpl(void);
    00191         void postLoadImpl(void);
    00193         void unloadImpl(void);
    00195         size_t calculateSize(void) const;
    00196
    00197
    00198
    00199     public:
    00204         Mesh(ResourceManager* creator, const String& name, ResourceHandle handle,
    00205             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    00206         ~Mesh();
    00207
    00208         // NB All methods below are non-virtual since they will be
    00209         // called in the rendering loop - speed is of the essence.
    00210
    00217         SubMesh* createSubMesh(void);
    00218
    00221         SubMesh* createSubMesh(const String& name);
    00222
    00225         void nameSubMesh(const String& name, ushort index);
    00226
    00232         ushort _getSubMeshIndex(const String& name) const;
    00233
    00236         unsigned short getNumSubMeshes(void) const;
    00237
    00240         SubMesh* getSubMesh(unsigned short index) const;
    00241
    00244         SubMesh* getSubMesh(const String& name) const ;
    00245
    00246         typedef VectorIterator<SubMeshList> SubMeshIterator;
    00248         SubMeshIterator getSubMeshIterator(void)
    00249         { return SubMeshIterator(mSubMeshList.begin(), mSubMeshList.end()); }
    00250
    00259         VertexData *sharedVertexData;
    00260
    00281         IndexMap sharedBlendIndexToBoneIndexMap;
    00282
    00292         MeshPtr clone(const String& newName, const String& newGroup = StringUtil::BLANK);
    00293
    00296         const AxisAlignedBox& getBounds(void) const;
    00297
    00299         Real getBoundingSphereRadius(void) const;
    00300
    00309         void _setBounds(const AxisAlignedBox& bounds, bool pad = true);
    00310
    00318         void _setBoundingSphereRadius(Real radius);
    00319
    00330         void setSkeletonName(const String& skelName);
    00331
    00333         bool hasSkeleton(void) const;
    00334
    00337         bool hasVertexAnimation(void) const;
    00338
    00342         const SkeletonPtr& getSkeleton(void) const;
    00343
    00345         const String& getSkeletonName(void) const;
    00350         void _initAnimationState(AnimationStateSet* animSet);
    00351
    00356         void _refreshAnimationState(AnimationStateSet* animSet);
    00369         void addBoneAssignment(const VertexBoneAssignment& vertBoneAssign);
    00370
    00376         void clearBoneAssignments(void);
    00377
    00384         void _notifySkeleton(SkeletonPtr& pSkel);
    00385
    00386
    00389         BoneAssignmentIterator getBoneAssignmentIterator(void);
    00390
    00393         const VertexBoneAssignmentList& getBoneAssignments() const { return mBoneAssignments; }
    00394
    00395
    00419         void generateLodLevels(const LodDistanceList& lodDistances,
    00420             ProgressiveMesh::VertexReductionQuota reductionMethod, Real reductionValue);
    00421
    00426         ushort getNumLodLevels(void) const;
    00428         const MeshLodUsage& getLodLevel(ushort index) const;
    00442         void createManualLodLevel(Real fromDepth, const String& meshName);
    00443
    00451         void updateManualLodLevel(ushort index, const String& meshName);
    00452
    00455         ushort getLodIndex(Real depth) const;
    00456
    00463         ushort getLodIndexSquaredDepth(Real squaredDepth) const;
    00464
    00471         bool isLodManual(void) const { return mIsLodManual; }
    00472
    00474         void _setLodInfo(unsigned short numLevels, bool isManual);
    00476         void _setLodUsage(unsigned short level, MeshLodUsage& usage);
    00478         void _setSubMeshLodFaceList(unsigned short subIdx, unsigned short level, IndexData* facedata);
    00479
    00481         void removeLodLevels(void);
    00482
    00505         void setVertexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
    00528         void setIndexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
    00530         HardwareBuffer::Usage getVertexBufferUsage(void) const { return mVertexBufferUsage; }
    00532         HardwareBuffer::Usage getIndexBufferUsage(void) const { return mIndexBufferUsage; }
    00534         bool isVertexBufferShadowed(void) const { return mVertexBufferShadowBuffer; }
    00536         bool isIndexBufferShadowed(void) const { return mIndexBufferShadowBuffer; }
    00537
    00538
    00552         unsigned short _rationaliseBoneAssignments(size_t vertexCount, VertexBoneAssignmentList& assignments);
    00553
    00561         void _compileBoneAssignments(void);
    00562
    00568         void _updateCompiledBoneAssignments(void);
    00569
    00596         void buildTangentVectors(VertexElementSemantic targetSemantic = VES_TANGENT,
    00597             unsigned short sourceTexCoordSet = 0, unsigned short index = 0,
    00598             bool splitMirrored = false, bool splitRotated = false, bool storeParityInW = false);
    00599
    00618         bool suggestTangentVectorBuildParams(VertexElementSemantic targetSemantic,
    00619             unsigned short& outSourceCoordSet, unsigned short& outIndex);
    00620
    00624         void buildEdgeList(void);
    00626         void freeEdgeList(void);
    00627
    00646         void prepareForShadowVolume(void);
    00647
    00654         EdgeData* getEdgeList(unsigned int lodIndex = 0);
    00655
    00662         const EdgeData* getEdgeList(unsigned int lodIndex = 0) const;
    00663
    00666         bool isPreparedForShadowVolumes(void) const { return mPreparedForShadowVolumes; }
    00667
    00669         bool isEdgeListBuilt(void) const { return mEdgeListsBuilt; }
    00670
    00682         static void prepareMatricesForVertexBlend(const Matrix4** blendMatrices,
    00683             const Matrix4* boneMatrices, const IndexMap& indexMap);
    00684
    00703         static void softwareVertexBlend(const VertexData* sourceVertexData,
    00704             const VertexData* targetVertexData,
    00705             const Matrix4* const* blendMatrices, size_t numMatrices,
    00706             bool blendNormals);
    00707
    00720         static void softwareVertexMorph(Real t,
    00721             const HardwareVertexBufferSharedPtr& b1,
    00722             const HardwareVertexBufferSharedPtr& b2,
    00723             VertexData* targetVertexData);
    00724
    00739         static void softwareVertexPoseBlend(Real weight,
    00740             const std::map<size_t, Vector3>& vertexOffsetMap,
    00741             VertexData* targetVertexData);
    00743         const SubMeshNameMap& getSubMeshNameMap(void) const { return mSubMeshNameMap; }
    00744
    00755         void setAutoBuildEdgeLists(bool autobuild) { mAutoBuildEdgeLists = autobuild; }
    00760         bool getAutoBuildEdgeLists(void) const { return mAutoBuildEdgeLists; }
    00761
    00764         virtual VertexAnimationType getSharedVertexDataAnimationType(void) const;
    00765
    00770         virtual Animation* createAnimation(const String& name, Real length);
    00771
    00775         virtual Animation* getAnimation(const String& name) const;
    00776
    00781         virtual Animation* _getAnimationImpl(const String& name) const;
    00782
    00784         virtual bool hasAnimation(const String& name);
    00785
    00787         virtual void removeAnimation(const String& name);
    00788
    00790         virtual unsigned short getNumAnimations(void) const;
    00791
    00794         virtual Animation* getAnimation(unsigned short index) const;
    00795
    00797         virtual void removeAllAnimations(void);
    00803         VertexData* getVertexDataByTrackHandle(unsigned short handle);
    00815         void updateMaterialForAllSubMeshes(void);
    00816
    00821         void _determineAnimationTypes(void) const;
    00823         bool _getAnimationTypesDirty(void) const { return mAnimationTypesDirty; }
    00824
    00831         Pose* createPose(ushort target, const String& name = StringUtil::BLANK);
    00833         size_t getPoseCount(void) const { return mPoseList.size(); }
    00835         Pose* getPose(ushort index);
    00837         Pose* getPose(const String& name);
    00841         void removePose(ushort index);
    00845         void removePose(const String& name);
    00847         void removeAllPoses(void);
    00848
    00849         typedef VectorIterator<PoseList> PoseIterator;
    00850         typedef ConstVectorIterator<PoseList> ConstPoseIterator;
    00851
    00853         PoseIterator getPoseIterator(void);
    00855         ConstPoseIterator getPoseIterator(void) const;
    00857         const PoseList& getPoseList(void) const;
    00858
    00859     };
    00860
    00867     class _OgreExport MeshPtr : public SharedPtr<Mesh>
    00868     {
    00869     public:
    00870         MeshPtr() : SharedPtr<Mesh>() {}
    00871         explicit MeshPtr(Mesh* rep) : SharedPtr<Mesh>(rep) {}
    00872         MeshPtr(const MeshPtr& r) : SharedPtr<Mesh>(r) {}
    00873         MeshPtr(const ResourcePtr& r);
    00875         MeshPtr& operator=(const ResourcePtr& r);
    00876     protected:
    00878         void destroy(void);
    00879     };
    00880
    00882     struct MeshLodUsage
    00883     {
    00885         Real fromDepthSquared;
    00887         String manualName;
    00889         mutable MeshPtr manualMesh;
    00891         mutable EdgeData* edgeData;
    00892     };
    00893
    00894
    00895
    00896 } // namespace
    00897
    00898 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sat Apr 11 14:26:42 2009