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-2012 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 "OgreHardwareVertexBuffer.h"
00039 #include "OgreSkeleton.h"
00040 #include "OgreAnimation.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, public AnimationContainer
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 mSharedVertexDataAnimationIncludesNormals;
00182         mutable bool mAnimationTypesDirty;
00183 
00185         PoseList mPoseList;
00186         mutable bool mPosesIncludeNormals;
00187 
00188 
00194         void prepareImpl(void);
00197         void unprepareImpl(void);
00199         void loadImpl(void);
00201         void postLoadImpl(void);
00203         void unloadImpl(void);
00205         size_t calculateSize(void) const;
00206 
00207 
00208 
00209     public:
00214         Mesh(ResourceManager* creator, const String& name, ResourceHandle handle,
00215             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
00216         ~Mesh();
00217 
00218         // NB All methods below are non-virtual since they will be
00219         // called in the rendering loop - speed is of the essence.
00220 
00227         SubMesh* createSubMesh(void);
00228 
00231         SubMesh* createSubMesh(const String& name);
00232         
00235         void nameSubMesh(const String& name, ushort index);
00236 
00239         void unnameSubMesh(const String& name);
00240         
00246         ushort _getSubMeshIndex(const String& name) const;
00247 
00250         unsigned short getNumSubMeshes(void) const;
00251 
00254         SubMesh* getSubMesh(unsigned short index) const;
00255 
00258         SubMesh* getSubMesh(const String& name) const ;
00259         
00265         void destroySubMesh(unsigned short index);
00266 
00272         void destroySubMesh(const String& name);
00273         
00274         typedef VectorIterator<SubMeshList> SubMeshIterator;
00276         SubMeshIterator getSubMeshIterator(void)
00277         { return SubMeshIterator(mSubMeshList.begin(), mSubMeshList.end()); }
00278       
00287         VertexData *sharedVertexData;
00288 
00309         IndexMap sharedBlendIndexToBoneIndexMap;
00310 
00320         MeshPtr clone(const String& newName, const String& newGroup = StringUtil::BLANK);
00321 
00324         const AxisAlignedBox& getBounds(void) const;
00325 
00327         Real getBoundingSphereRadius(void) const;
00328 
00337         void _setBounds(const AxisAlignedBox& bounds, bool pad = true);
00338 
00346         void _setBoundingSphereRadius(Real radius);
00347 
00358         void setSkeletonName(const String& skelName);
00359 
00361         bool hasSkeleton(void) const;
00362 
00365         bool hasVertexAnimation(void) const;
00366         
00370         const SkeletonPtr& getSkeleton(void) const;
00371 
00373         const String& getSkeletonName(void) const;
00378         void _initAnimationState(AnimationStateSet* animSet);
00379 
00384         void _refreshAnimationState(AnimationStateSet* animSet);
00397         void addBoneAssignment(const VertexBoneAssignment& vertBoneAssign);
00398 
00404         void clearBoneAssignments(void);
00405 
00412         void _notifySkeleton(SkeletonPtr& pSkel);
00413 
00414 
00417         BoneAssignmentIterator getBoneAssignmentIterator(void);
00418 
00421         const VertexBoneAssignmentList& getBoneAssignments() const { return mBoneAssignments; }
00422 
00423 
00428         ushort getNumLodLevels(void) const;
00430         const MeshLodUsage& getLodLevel(ushort index) const;
00444         void createManualLodLevel(Real value, const String& meshName, const String& groupName = Ogre::String());
00445 
00453         void updateManualLodLevel(ushort index, const String& meshName);
00454 
00460         ushort getLodIndex(Real value) const;
00461 
00468         bool isLodManual(void) const { return mIsLodManual; }
00469 
00471         void _setLodInfo(unsigned short numLevels, bool isManual);
00473         void _setLodUsage(unsigned short level, MeshLodUsage& usage);
00475         void _setSubMeshLodFaceList(unsigned short subIdx, unsigned short level, IndexData* facedata);
00476 
00478         void removeLodLevels(void);
00479 
00502         void setVertexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
00525         void setIndexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false);
00527         HardwareBuffer::Usage getVertexBufferUsage(void) const { return mVertexBufferUsage; }
00529         HardwareBuffer::Usage getIndexBufferUsage(void) const { return mIndexBufferUsage; }
00531         bool isVertexBufferShadowed(void) const { return mVertexBufferShadowBuffer; }
00533         bool isIndexBufferShadowed(void) const { return mIndexBufferShadowBuffer; }
00534        
00535 
00549         unsigned short _rationaliseBoneAssignments(size_t vertexCount, VertexBoneAssignmentList& assignments);
00550 
00558         void _compileBoneAssignments(void);
00559 
00565         void _updateCompiledBoneAssignments(void);
00566 
00593         void buildTangentVectors(VertexElementSemantic targetSemantic = VES_TANGENT,
00594             unsigned short sourceTexCoordSet = 0, unsigned short index = 0, 
00595             bool splitMirrored = false, bool splitRotated = false, bool storeParityInW = false);
00596 
00615         bool suggestTangentVectorBuildParams(VertexElementSemantic targetSemantic,
00616             unsigned short& outSourceCoordSet, unsigned short& outIndex);
00617 
00621         void buildEdgeList(void);
00623         void freeEdgeList(void);
00624 
00643         void prepareForShadowVolume(void);
00644 
00651         EdgeData* getEdgeList(unsigned short lodIndex = 0);
00652 
00659         const EdgeData* getEdgeList(unsigned short lodIndex = 0) const;
00660 
00663         bool isPreparedForShadowVolumes(void) const { return mPreparedForShadowVolumes; }
00664 
00666         bool isEdgeListBuilt(void) const { return mEdgeListsBuilt; }
00667 
00679         static void prepareMatricesForVertexBlend(const Matrix4** blendMatrices,
00680             const Matrix4* boneMatrices, const IndexMap& indexMap);
00681 
00700         static void softwareVertexBlend(const VertexData* sourceVertexData, 
00701             const VertexData* targetVertexData,
00702             const Matrix4* const* blendMatrices, size_t numMatrices,
00703             bool blendNormals);
00704 
00717         static void softwareVertexMorph(Real t, 
00718             const HardwareVertexBufferSharedPtr& b1, 
00719             const HardwareVertexBufferSharedPtr& b2, 
00720             VertexData* targetVertexData);
00721 
00737         static void softwareVertexPoseBlend(Real weight, 
00738             const map<size_t, Vector3>::type& vertexOffsetMap,
00739             const map<size_t, Vector3>::type& normalsMap,
00740             VertexData* targetVertexData);
00742         const SubMeshNameMap& getSubMeshNameMap(void) const { return mSubMeshNameMap; }
00743 
00754         void setAutoBuildEdgeLists(bool autobuild) { mAutoBuildEdgeLists = autobuild; }
00759         bool getAutoBuildEdgeLists(void) const { return mAutoBuildEdgeLists; }
00760 
00763         virtual VertexAnimationType getSharedVertexDataAnimationType(void) const;
00764 
00766         bool getSharedVertexDataAnimationIncludesNormals() const { return mSharedVertexDataAnimationIncludesNormals; }
00767 
00772         virtual Animation* createAnimation(const String& name, Real length);
00773 
00777         virtual Animation* getAnimation(const String& name) const;
00778 
00783         virtual Animation* _getAnimationImpl(const String& name) const;
00784 
00786         virtual bool hasAnimation(const String& name) const;
00787 
00789         virtual void removeAnimation(const String& name);
00790 
00792         virtual unsigned short getNumAnimations(void) const;
00793 
00796         virtual Animation* getAnimation(unsigned short index) const;
00797 
00799         virtual void removeAllAnimations(void);
00805         VertexData* getVertexDataByTrackHandle(unsigned short handle);
00817         void updateMaterialForAllSubMeshes(void);
00818 
00823         void _determineAnimationTypes(void) const;
00825         bool _getAnimationTypesDirty(void) const { return mAnimationTypesDirty; }
00826 
00833         Pose* createPose(ushort target, const String& name = StringUtil::BLANK);
00835         size_t getPoseCount(void) const { return mPoseList.size(); }
00837         Pose* getPose(ushort index);
00839         Pose* getPose(const String& name);
00843         void removePose(ushort index);
00847         void removePose(const String& name);
00849         void removeAllPoses(void);
00850 
00851         typedef VectorIterator<PoseList> PoseIterator;
00852         typedef ConstVectorIterator<PoseList> ConstPoseIterator;
00853 
00855         PoseIterator getPoseIterator(void);
00857         ConstPoseIterator getPoseIterator(void) const;
00859         const PoseList& getPoseList(void) const;
00860 
00862         const LodStrategy *getLodStrategy() const;
00864         void setLodStrategy(LodStrategy *lodStrategy);
00865 
00866     };
00867 
00874     class _OgreExport MeshPtr : public SharedPtr<Mesh> 
00875     {
00876     public:
00877         MeshPtr() : SharedPtr<Mesh>() {}
00878         explicit MeshPtr(Mesh* rep) : SharedPtr<Mesh>(rep) {}
00879         MeshPtr(const MeshPtr& r) : SharedPtr<Mesh>(r) {} 
00880         MeshPtr(const ResourcePtr& r);
00882         MeshPtr& operator=(const ResourcePtr& r);
00883     protected:
00885         void destroy(void);
00886     };
00887 
00889     struct MeshLodUsage
00890     {
00895         Real userValue;
00896 
00902         Real value;
00903         
00905         String manualName;
00907         String manualGroup;
00909         mutable MeshPtr manualMesh;
00911         mutable EdgeData* edgeData;
00912 
00913         MeshLodUsage() : userValue(0.0), value(0.0), edgeData(0) {}
00914     };
00915 
00920 } // namespace
00921 
00922 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:24 2012