# 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-2009 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef __Mesh_H__
    00029 #define __Mesh_H__
    00030
    00031 #include "OgrePrerequisites.h"
    00032
    00033 #include "OgreResource.h"
    00034 #include "OgreVertexIndexData.h"
    00035 #include "OgreAxisAlignedBox.h"
    00036 #include "OgreVertexBoneAssignment.h"
    00037 #include "OgreIteratorWrappers.h"
    00038 #include "OgreProgressiveMesh.h"
    00039 #include "OgreHardwareVertexBuffer.h"
    00040 #include "OgreSkeleton.h"
    00041 #include "OgreAnimationTrack.h"
    00042 #include "OgrePose.h"
    00043 #include "OgreDataStream.h"
    00044
    00045
    00046 namespace Ogre {
    00047
    00048
    00088     struct MeshLodUsage;
    00089     class LodStrategy;
    00090
    00091     class _OgreExport Mesh: public Resource
    00092     {
    00093         friend class SubMesh;
    00094         friend class MeshSerializerImpl;
    00095         friend class MeshSerializerImpl_v1_4;
    00096         friend class MeshSerializerImpl_v1_2;
    00097         friend class MeshSerializerImpl_v1_1;
    00098
    00099     public:
    00100         typedef vector<Real>::type LodValueList;
    00101         typedef vector<MeshLodUsage>::type MeshLodUsageList;
    00103         typedef multimap<size_t, VertexBoneAssignment>::type VertexBoneAssignmentList;
    00104         typedef MapIterator<VertexBoneAssignmentList> BoneAssignmentIterator;
    00105         typedef vector<SubMesh*>::type SubMeshList;
    00106         typedef vector<unsigned short>::type IndexMap;
    00107
    00108     protected:
    00115         SubMeshList mSubMeshList;
    00116
    00118         void organiseTangentsBuffer(VertexData *vertexData,
    00119             VertexElementSemantic targetSemantic, unsigned short index,
    00120             unsigned short sourceTexCoordSet);
    00121
    00122     public:
    00126         typedef HashMap<String, ushort> SubMeshNameMap ;
    00127
    00128
    00129     protected:
    00130
    00131         DataStreamPtr mFreshFromDisk;
    00132
    00133         SubMeshNameMap mSubMeshNameMap ;
    00134
    00136         AxisAlignedBox mAABB;
    00138         Real mBoundRadius;
    00139
    00141         String mSkeletonName;
    00142         SkeletonPtr mSkeleton;
    00143
    00144
    00145         VertexBoneAssignmentList mBoneAssignments;
    00146
    00148         bool mBoneAssignmentsOutOfDate;
    00149
    00151         void buildIndexMap(const VertexBoneAssignmentList& boneAssignments,
    00152             IndexMap& boneIndexToBlendIndexMap, IndexMap& blendIndexToBoneIndexMap);
    00154         void compileBoneAssignments(const VertexBoneAssignmentList& boneAssignments,
    00155             unsigned short numBlendWeightsPerVertex,
    00156             IndexMap& blendIndexToBoneIndexMap,
    00157             VertexData* targetVertexData);
    00158
    00159         const LodStrategy *mLodStrategy;
    00160         bool mIsLodManual;
    00161         ushort mNumLods;
    00162         MeshLodUsageList mMeshLodUsageList;
    00163
    00164         HardwareBuffer::Usage mVertexBufferUsage;
    00165         HardwareBuffer::Usage mIndexBufferUsage;
    00166         bool mVertexBufferShadowBuffer;
    00167         bool mIndexBufferShadowBuffer;
    00168
    00169
    00170         bool mPreparedForShadowVolumes;
    00171         bool mEdgeListsBuilt;
    00172         bool mAutoBuildEdgeLists;
    00173
    00175         typedef map<String, Animation*>::type AnimationList;
    00176         AnimationList mAnimationsList;
    00178         mutable VertexAnimationType mSharedVertexDataAnimationType;
    00180         mutable bool mAnimationTypesDirty;
    00181
    00183         PoseList mPoseList;
    00184
    00185
    00191         void prepareImpl(void);
    00194         void unprepareImpl(void);
    00196         void loadImpl(void);
    00198         void postLoadImpl(void);
    00200         void unloadImpl(void);
    00202         size_t calculateSize(void) const;
    00203
    00204
    00205
    00206     public:
    00211         Mesh(ResourceManager* creator, const String& name, ResourceHandle handle,
    00212             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    00213         ~Mesh();
    00214
    00215         // NB All methods below are non-virtual since they will be
    00216         // called in the rendering loop - speed is of the essence.
    00217
    00224         SubMesh* createSubMesh(void);
    00225
    00228         SubMesh* createSubMesh(const String& name);
    00229
    00232         void nameSubMesh(const String& name, ushort index);
    00233
    00236         void unnameSubMesh(const String& name);
    00237
    00243         ushort _getSubMeshIndex(const String& name) const;
    00244
    00247         unsigned short getNumSubMeshes(void) const;
    00248
    00251         SubMesh* getSubMesh(unsigned short index) const;
    00252
    00255         SubMesh* getSubMesh(const String& name) const ;
    00256
    00262         void destroySubMesh(unsigned short index);
    00263
    00269         void destroySubMesh(const String& name);
    00270
    00271         typedef VectorIterator<SubMeshList> SubMeshIterator;
    00273         SubMeshIterator getSubMeshIterator(void)
    00274         { return SubMeshIterator(mSubMeshList.begin(), mSubMeshList.end()); }
    00275
    00284         VertexData *sharedVertexData;
    00285
    00306         IndexMap sharedBlendIndexToBoneIndexMap;
    00307
    00317         MeshPtr clone(const String& newName, const String& newGroup = StringUtil::BLANK);
    00318
    00321         const AxisAlignedBox& getBounds(void) const;
    00322
    00324         Real getBoundingSphereRadius(void) const;
    00325
    00334         void _setBounds(const AxisAlignedBox& bounds, bool pad = true);
    00335
    00343         void _setBoundingSphereRadius(Real radius);
    00344
    00355         void setSkeletonName(const String& skelName);
    00356
    00358         bool hasSkeleton(void) const;
    00359
    00362         bool hasVertexAnimation(void) const;
    00363
    00367         const SkeletonPtr& getSkeleton(void) const;
    00368
    00370         const String& getSkeletonName(void) const;
    00375         void _initAnimationState(AnimationStateSet* animSet);
    00376
    00381         void _refreshAnimationState(AnimationStateSet* animSet);
    00394         void addBoneAssignment(const VertexBoneAssignment& vertBoneAssign);
    00395
    00401         void clearBoneAssignments(void);
    00402
    00409         void _notifySkeleton(SkeletonPtr& pSkel);
    00410
    00411
    00414         BoneAssignmentIterator getBoneAssignmentIterator(void);
    00415
    00418         const VertexBoneAssignmentList& getBoneAssignments() const { return mBoneAssignments; }
    00419
    00420
    00446         void generateLodLevels(const LodValueList& lodValues,
    00447             ProgressiveMesh::VertexReductionQuota reductionMethod, Real reductionValue);
    00448
    00453         ushort getNumLodLevels(void) const;
    00455         const MeshLodUsage& getLodLevel(ushort index) const;
    00469         void createManualLodLevel(Real value, const String& meshName, const String& groupName = Ogre::String());
    00470
    00478         void updateManualLodLevel(ushort index, const String& meshName);
    00479
    00485         ushort getLodIndex(Real value) const;
    00486
    00493         bool isLodManual(void) const { return mIsLodManual; }
    00494
    00496         void _setLodInfo(unsigned short numLevels, bool isManual);
    00498         void _setLodUsage(unsigned short level, MeshLodUsage& usage);
    00500         void _setSubMeshLodFaceList(unsigned short subIdx, unsigned short level, IndexData* facedata);
    00501
    00503         void removeLodLevels(void);
    00504
    00527         void setVertexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
    00550         void setIndexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
    00552         HardwareBuffer::Usage getVertexBufferUsage(void) const { return mVertexBufferUsage; }
    00554         HardwareBuffer::Usage getIndexBufferUsage(void) const { return mIndexBufferUsage; }
    00556         bool isVertexBufferShadowed(void) const { return mVertexBufferShadowBuffer; }
    00558         bool isIndexBufferShadowed(void) const { return mIndexBufferShadowBuffer; }
    00559
    00560
    00574         unsigned short _rationaliseBoneAssignments(size_t vertexCount, VertexBoneAssignmentList& assignments);
    00575
    00583         void _compileBoneAssignments(void);
    00584
    00590         void _updateCompiledBoneAssignments(void);
    00591
    00618         void buildTangentVectors(VertexElementSemantic targetSemantic = VES_TANGENT,
    00619             unsigned short sourceTexCoordSet = 0, unsigned short index = 0,
    00620             bool splitMirrored = false, bool splitRotated = false, bool storeParityInW = false);
    00621
    00640         bool suggestTangentVectorBuildParams(VertexElementSemantic targetSemantic,
    00641             unsigned short& outSourceCoordSet, unsigned short& outIndex);
    00642
    00646         void buildEdgeList(void);
    00648         void freeEdgeList(void);
    00649
    00668         void prepareForShadowVolume(void);
    00669
    00676         EdgeData* getEdgeList(unsigned short lodIndex = 0);
    00677
    00684         const EdgeData* getEdgeList(unsigned short lodIndex = 0) const;
    00685
    00688         bool isPreparedForShadowVolumes(void) const { return mPreparedForShadowVolumes; }
    00689
    00691         bool isEdgeListBuilt(void) const { return mEdgeListsBuilt; }
    00692
    00704         static void prepareMatricesForVertexBlend(const Matrix4** blendMatrices,
    00705             const Matrix4* boneMatrices, const IndexMap& indexMap);
    00706
    00725         static void softwareVertexBlend(const VertexData* sourceVertexData,
    00726             const VertexData* targetVertexData,
    00727             const Matrix4* const* blendMatrices, size_t numMatrices,
    00728             bool blendNormals);
    00729
    00742         static void softwareVertexMorph(Real t,
    00743             const HardwareVertexBufferSharedPtr& b1,
    00744             const HardwareVertexBufferSharedPtr& b2,
    00745             VertexData* targetVertexData);
    00746
    00761         static void softwareVertexPoseBlend(Real weight,
    00762             const map<size_t, Vector3>::type& vertexOffsetMap,
    00763             VertexData* targetVertexData);
    00765         const SubMeshNameMap& getSubMeshNameMap(void) const { return mSubMeshNameMap; }
    00766
    00777         void setAutoBuildEdgeLists(bool autobuild) { mAutoBuildEdgeLists = autobuild; }
    00782         bool getAutoBuildEdgeLists(void) const { return mAutoBuildEdgeLists; }
    00783
    00786         virtual VertexAnimationType getSharedVertexDataAnimationType(void) const;
    00787
    00792         virtual Animation* createAnimation(const String& name, Real length);
    00793
    00797         virtual Animation* getAnimation(const String& name) const;
    00798
    00803         virtual Animation* _getAnimationImpl(const String& name) const;
    00804
    00806         virtual bool hasAnimation(const String& name);
    00807
    00809         virtual void removeAnimation(const String& name);
    00810
    00812         virtual unsigned short getNumAnimations(void) const;
    00813
    00816         virtual Animation* getAnimation(unsigned short index) const;
    00817
    00819         virtual void removeAllAnimations(void);
    00825         VertexData* getVertexDataByTrackHandle(unsigned short handle);
    00837         void updateMaterialForAllSubMeshes(void);
    00838
    00843         void _determineAnimationTypes(void) const;
    00845         bool _getAnimationTypesDirty(void) const { return mAnimationTypesDirty; }
    00846
    00853         Pose* createPose(ushort target, const String& name = StringUtil::BLANK);
    00855         size_t getPoseCount(void) const { return mPoseList.size(); }
    00857         Pose* getPose(ushort index);
    00859         Pose* getPose(const String& name);
    00863         void removePose(ushort index);
    00867         void removePose(const String& name);
    00869         void removeAllPoses(void);
    00870
    00871         typedef VectorIterator<PoseList> PoseIterator;
    00872         typedef ConstVectorIterator<PoseList> ConstPoseIterator;
    00873
    00875         PoseIterator getPoseIterator(void);
    00877         ConstPoseIterator getPoseIterator(void) const;
    00879         const PoseList& getPoseList(void) const;
    00880
    00882         const LodStrategy *getLodStrategy() const;
    00884         void setLodStrategy(LodStrategy *lodStrategy);
    00885
    00886     };
    00887
    00894     class _OgreExport MeshPtr : public SharedPtr<Mesh>
    00895     {
    00896     public:
    00897         MeshPtr() : SharedPtr<Mesh>() {}
    00898         explicit MeshPtr(Mesh* rep) : SharedPtr<Mesh>(rep) {}
    00899         MeshPtr(const MeshPtr& r) : SharedPtr<Mesh>(r) {}
    00900         MeshPtr(const ResourcePtr& r);
    00902         MeshPtr& operator=(const ResourcePtr& r);
    00903     protected:
    00905         void destroy(void);
    00906     };
    00907
    00909     struct MeshLodUsage
    00910     {
    00915         Real userValue;
    00916
    00922         Real value;
    00923
    00925         String manualName;
    00927         String manualGroup;
    00929         mutable MeshPtr manualMesh;
    00931         mutable EdgeData* edgeData;
    00932
    00933         MeshLodUsage() : userValue(0.0), value(0.0), edgeData(0) {}
    00934     };
    00935
    00940 } // namespace
    00941
    00942 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun May 8 2011 20:28:08