- Main Page
- Namespaces
- Classes
- Files
- Directories
- 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-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
    00045
    00046 namespace Ogre {
    00047
    00048
    00083     struct MeshLodUsage;
    00084
    00085     class _OgreExport Mesh: public Resource
    00086     {
    00087         friend class SubMesh;
    00088         friend class MeshSerializerImpl;
    00089         friend class MeshSerializerImpl_v1_2;
    00090         friend class MeshSerializerImpl_v1_1;
    00091
    00092     public:
    00093         typedef std::vector<Real> LodDistanceList;
    00095         typedef std::multimap<size_t, VertexBoneAssignment> VertexBoneAssignmentList;
    00096         typedef MapIterator<VertexBoneAssignmentList> BoneAssignmentIterator;
    00097         typedef std::vector<SubMesh*> SubMeshList;
    00098         typedef std::vector<unsigned short> IndexMap;
    00099
    00100     protected:
    00107         SubMeshList mSubMeshList;
    00108
    00110         void organiseTangentsBuffer(VertexData *vertexData,
    00111             VertexElementSemantic targetSemantic, unsigned short index,
    00112             unsigned short sourceTexCoordSet);
    00113
    00114     public:
    00118         typedef HashMap<String, ushort> SubMeshNameMap ;
    00119
    00120
    00121     protected:
    00122         SubMeshNameMap mSubMeshNameMap ;
    00123
    00125         AxisAlignedBox mAABB;
    00127         Real mBoundRadius;
    00128
    00130         String mSkeletonName;
    00131         SkeletonPtr mSkeleton;
    00132
    00133
    00134         VertexBoneAssignmentList mBoneAssignments;
    00135
    00137         bool mBoneAssignmentsOutOfDate;
    00138
    00140         void buildIndexMap(const VertexBoneAssignmentList& boneAssignments,
    00141             IndexMap& boneIndexToBlendIndexMap, IndexMap& blendIndexToBoneIndexMap);
    00143         void compileBoneAssignments(const VertexBoneAssignmentList& boneAssignments,
    00144             unsigned short numBlendWeightsPerVertex,
    00145             IndexMap& blendIndexToBoneIndexMap,
    00146             VertexData* targetVertexData);
    00147
    00148         bool mIsLodManual;
    00149         ushort mNumLods;
    00150         typedef std::vector<MeshLodUsage> MeshLodUsageList;
    00151         MeshLodUsageList mMeshLodUsageList;
    00152
    00153         HardwareBuffer::Usage mVertexBufferUsage;
    00154         HardwareBuffer::Usage mIndexBufferUsage;
    00155         bool mVertexBufferShadowBuffer;
    00156         bool mIndexBufferShadowBuffer;
    00157
    00158
    00159         bool mPreparedForShadowVolumes;
    00160         bool mEdgeListsBuilt;
    00161         bool mAutoBuildEdgeLists;
    00162
    00164         typedef std::map<String, Animation*> AnimationList;
    00165         AnimationList mAnimationsList;
    00167         mutable VertexAnimationType mSharedVertexDataAnimationType;
    00169         mutable bool mAnimationTypesDirty;
    00170
    00172         PoseList mPoseList;
    00173
    00174
    00176         void loadImpl(void);
    00178         void postLoadImpl(void);
    00180         void unloadImpl(void);
    00182         size_t calculateSize(void) const;
    00183
    00184
    00185
    00186     public:
    00191         Mesh(ResourceManager* creator, const String& name, ResourceHandle handle,
    00192             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    00193         ~Mesh();
    00194
    00195         // NB All methods below are non-virtual since they will be
    00196         // called in the rendering loop - speed is of the essence.
    00197
    00204         SubMesh* createSubMesh(void);
    00205
    00208         SubMesh* createSubMesh(const String& name);
    00209
    00212         void nameSubMesh(const String& name, ushort index);
    00213
    00219         ushort _getSubMeshIndex(const String& name) const;
    00220
    00223         unsigned short getNumSubMeshes(void) const;
    00224
    00227         SubMesh* getSubMesh(unsigned short index) const;
    00228
    00231         SubMesh* getSubMesh(const String& name) const ;
    00232
    00233         typedef VectorIterator<SubMeshList> SubMeshIterator;
    00235         SubMeshIterator getSubMeshIterator(void)
    00236         { return SubMeshIterator(mSubMeshList.begin(), mSubMeshList.end()); }
    00237
    00246         VertexData *sharedVertexData;
    00247
    00268         IndexMap sharedBlendIndexToBoneIndexMap;
    00269
    00279         MeshPtr clone(const String& newName, const String& newGroup = StringUtil::BLANK);
    00280
    00283         const AxisAlignedBox& getBounds(void) const;
    00284
    00286         Real getBoundingSphereRadius(void) const;
    00287
    00296         void _setBounds(const AxisAlignedBox& bounds, bool pad = true);
    00297
    00305         void _setBoundingSphereRadius(Real radius);
    00306
    00317         void setSkeletonName(const String& skelName);
    00318
    00320         bool hasSkeleton(void) const;
    00321
    00324         bool hasVertexAnimation(void) const;
    00325
    00329         const SkeletonPtr& getSkeleton(void) const;
    00330
    00332         const String& getSkeletonName(void) const;
    00337         void _initAnimationState(AnimationStateSet* animSet);
    00338
    00343         void _refreshAnimationState(AnimationStateSet* animSet);
    00356         void addBoneAssignment(const VertexBoneAssignment& vertBoneAssign);
    00357
    00363         void clearBoneAssignments(void);
    00364
    00371         void _notifySkeleton(SkeletonPtr& pSkel);
    00372
    00373
    00376         BoneAssignmentIterator getBoneAssignmentIterator(void);
    00377
    00378
    00402         void generateLodLevels(const LodDistanceList& lodDistances,
    00403             ProgressiveMesh::VertexReductionQuota reductionMethod, Real reductionValue);
    00404
    00409         ushort getNumLodLevels(void) const;
    00411         const MeshLodUsage& getLodLevel(ushort index) const;
    00425         void createManualLodLevel(Real fromDepth, const String& meshName);
    00426
    00434         void updateManualLodLevel(ushort index, const String& meshName);
    00435
    00438         ushort getLodIndex(Real depth) const;
    00439
    00446         ushort getLodIndexSquaredDepth(Real squaredDepth) const;
    00447
    00454         bool isLodManual(void) const { return mIsLodManual; }
    00455
    00457         void _setLodInfo(unsigned short numLevels, bool isManual);
    00459         void _setLodUsage(unsigned short level, MeshLodUsage& usage);
    00461         void _setSubMeshLodFaceList(unsigned short subIdx, unsigned short level, IndexData* facedata);
    00462
    00464         void removeLodLevels(void);
    00465
    00488         void setVertexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
    00511         void setIndexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
    00513         HardwareBuffer::Usage getVertexBufferUsage(void) const { return mVertexBufferUsage; }
    00515         HardwareBuffer::Usage getIndexBufferUsage(void) const { return mIndexBufferUsage; }
    00517         bool isVertexBufferShadowed(void) const { return mVertexBufferShadowBuffer; }
    00519         bool isIndexBufferShadowed(void) const { return mIndexBufferShadowBuffer; }
    00520
    00521
    00535         unsigned short _rationaliseBoneAssignments(size_t vertexCount, VertexBoneAssignmentList& assignments);
    00536
    00544         void _compileBoneAssignments(void);
    00545
    00551         void _updateCompiledBoneAssignments(void);
    00552
    00574         void buildTangentVectors(VertexElementSemantic targetSemantic = VES_TANGENT,
    00575             unsigned short sourceTexCoordSet = 0, unsigned short index = 0);
    00576
    00595         bool suggestTangentVectorBuildParams(VertexElementSemantic targetSemantic,
    00596             unsigned short& outSourceCoordSet, unsigned short& outIndex);
    00597
    00601         void buildEdgeList(void);
    00603         void freeEdgeList(void);
    00604
    00623         void prepareForShadowVolume(void);
    00624
    00631         EdgeData* getEdgeList(unsigned int lodIndex = 0);
    00632
    00639         const EdgeData* getEdgeList(unsigned int lodIndex = 0) const;
    00640
    00643         bool isPreparedForShadowVolumes(void) const { return mPreparedForShadowVolumes; }
    00644
    00646         bool isEdgeListBuilt(void) const { return mEdgeListsBuilt; }
    00647
    00659         static void prepareMatricesForVertexBlend(const Matrix4** blendMatrices,
    00660             const Matrix4* boneMatrices, const IndexMap& indexMap);
    00661
    00680         static void softwareVertexBlend(const VertexData* sourceVertexData,
    00681             const VertexData* targetVertexData,
    00682             const Matrix4* const* blendMatrices, size_t numMatrices,
    00683             bool blendNormals);
    00684
    00697         static void softwareVertexMorph(Real t,
    00698             const HardwareVertexBufferSharedPtr& b1,
    00699             const HardwareVertexBufferSharedPtr& b2,
    00700             VertexData* targetVertexData);
    00701
    00716         static void softwareVertexPoseBlend(Real weight,
    00717             const std::map<size_t, Vector3>& vertexOffsetMap,
    00718             VertexData* targetVertexData);
    00720         const SubMeshNameMap& getSubMeshNameMap(void) const { return mSubMeshNameMap; }
    00721
    00732         void setAutoBuildEdgeLists(bool autobuild) { mAutoBuildEdgeLists = autobuild; }
    00737         bool getAutoBuildEdgeLists(void) const { return mAutoBuildEdgeLists; }
    00738
    00741         virtual VertexAnimationType getSharedVertexDataAnimationType(void) const;
    00742
    00747         virtual Animation* createAnimation(const String& name, Real length);
    00748
    00752         virtual Animation* getAnimation(const String& name) const;
    00753
    00758         virtual Animation* _getAnimationImpl(const String& name) const;
    00759
    00761         virtual bool hasAnimation(const String& name);
    00762
    00764         virtual void removeAnimation(const String& name);
    00765
    00767         virtual unsigned short getNumAnimations(void) const;
    00768
    00771         virtual Animation* getAnimation(unsigned short index) const;
    00772
    00774         virtual void removeAllAnimations(void);
    00780         VertexData* getVertexDataByTrackHandle(unsigned short handle);
    00792         void updateMaterialForAllSubMeshes(void);
    00793
    00798         void _determineAnimationTypes(void) const;
    00800         bool _getAnimationTypesDirty(void) const { return mAnimationTypesDirty; }
    00801
    00808         Pose* createPose(ushort target, const String& name = StringUtil::BLANK);
    00810         size_t getPoseCount(void) const { return mPoseList.size(); }
    00812         Pose* getPose(ushort index);
    00814         Pose* getPose(const String& name);
    00818         void removePose(ushort index);
    00822         void removePose(const String& name);
    00824         void removeAllPoses(void);
    00825
    00826         typedef VectorIterator<PoseList> PoseIterator;
    00827         typedef ConstVectorIterator<PoseList> ConstPoseIterator;
    00828
    00830         PoseIterator getPoseIterator(void);
    00832         ConstPoseIterator getPoseIterator(void) const;
    00834         const PoseList& getPoseList(void) const;
    00835
    00836     };
    00837
    00844     class _OgreExport MeshPtr : public SharedPtr<Mesh>
    00845     {
    00846     public:
    00847         MeshPtr() : SharedPtr<Mesh>() {}
    00848         explicit MeshPtr(Mesh* rep) : SharedPtr<Mesh>(rep) {}
    00849         MeshPtr(const MeshPtr& r) : SharedPtr<Mesh>(r) {}
    00850         MeshPtr(const ResourcePtr& r);
    00852         MeshPtr& operator=(const ResourcePtr& r);
    00853     protected:
    00855         void destroy(void);
    00856     };
    00857
    00859     struct MeshLodUsage
    00860     {
    00862         Real fromDepthSquared;
    00864         String manualName;
    00866         mutable MeshPtr manualMesh;
    00868         mutable EdgeData* edgeData;
    00869     };
    00870
    00871
    00872
    00873 } // namespace
    00874
    00875 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Mon Jun 16 12:48:53 2008