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-2013 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 #include "OgreHeaderPrefix.h" 00045 00046 00047 namespace Ogre { 00048 00049 00057 struct MeshLodUsage; 00058 struct LodConfig; 00059 class LodStrategy; 00060 00093 class _OgreExport Mesh: public Resource, public AnimationContainer 00094 { 00095 friend class SubMesh; 00096 friend class MeshSerializerImpl; 00097 friend class MeshSerializerImpl_v1_4; 00098 friend class MeshSerializerImpl_v1_2; 00099 friend class MeshSerializerImpl_v1_1; 00100 00101 public: 00102 typedef vector<Real>::type LodValueList; 00103 typedef vector<MeshLodUsage>::type MeshLodUsageList; 00105 typedef multimap<size_t, VertexBoneAssignment>::type VertexBoneAssignmentList; 00106 typedef MapIterator<VertexBoneAssignmentList> BoneAssignmentIterator; 00107 typedef vector<SubMesh*>::type SubMeshList; 00108 typedef vector<unsigned short>::type IndexMap; 00109 00110 protected: 00117 SubMeshList mSubMeshList; 00118 00120 void organiseTangentsBuffer(VertexData *vertexData, 00121 VertexElementSemantic targetSemantic, unsigned short index, 00122 unsigned short sourceTexCoordSet); 00123 00124 public: 00128 typedef HashMap<String, ushort> SubMeshNameMap ; 00129 00130 00131 protected: 00132 00133 DataStreamPtr mFreshFromDisk; 00134 00135 SubMeshNameMap mSubMeshNameMap ; 00136 00138 AxisAlignedBox mAABB; 00140 Real mBoundRadius; 00141 00143 String mSkeletonName; 00144 SkeletonPtr mSkeleton; 00145 00146 00147 VertexBoneAssignmentList mBoneAssignments; 00148 00150 bool mBoneAssignmentsOutOfDate; 00151 00153 void buildIndexMap(const VertexBoneAssignmentList& boneAssignments, 00154 IndexMap& boneIndexToBlendIndexMap, IndexMap& blendIndexToBoneIndexMap); 00156 void compileBoneAssignments(const VertexBoneAssignmentList& boneAssignments, 00157 unsigned short numBlendWeightsPerVertex, 00158 IndexMap& blendIndexToBoneIndexMap, 00159 VertexData* targetVertexData); 00160 00161 const LodStrategy *mLodStrategy; 00162 bool mIsLodManual; 00163 ushort mNumLods; 00164 MeshLodUsageList mMeshLodUsageList; 00165 00166 HardwareBuffer::Usage mVertexBufferUsage; 00167 HardwareBuffer::Usage mIndexBufferUsage; 00168 bool mVertexBufferShadowBuffer; 00169 bool mIndexBufferShadowBuffer; 00170 00171 00172 bool mPreparedForShadowVolumes; 00173 bool mEdgeListsBuilt; 00174 bool mAutoBuildEdgeLists; 00175 00177 typedef map<String, Animation*>::type AnimationList; 00178 AnimationList mAnimationsList; 00180 mutable VertexAnimationType mSharedVertexDataAnimationType; 00182 mutable bool mSharedVertexDataAnimationIncludesNormals; 00184 mutable bool mAnimationTypesDirty; 00185 00187 PoseList mPoseList; 00188 mutable bool mPosesIncludeNormals; 00189 00190 00196 void prepareImpl(void); 00199 void unprepareImpl(void); 00201 void loadImpl(void); 00203 void postLoadImpl(void); 00205 void unloadImpl(void); 00207 size_t calculateSize(void) const; 00208 00209 void mergeAdjacentTexcoords( unsigned short finalTexCoordSet, 00210 unsigned short texCoordSetToDestroy, VertexData *vertexData ); 00211 00212 00213 public: 00218 Mesh(ResourceManager* creator, const String& name, ResourceHandle handle, 00219 const String& group, bool isManual = false, ManualResourceLoader* loader = 0); 00220 ~Mesh(); 00221 00222 // NB All methods below are non-virtual since they will be 00223 // called in the rendering loop - speed is of the essence. 00224 00231 SubMesh* createSubMesh(void); 00232 00235 SubMesh* createSubMesh(const String& name); 00236 00239 void nameSubMesh(const String& name, ushort index); 00240 00243 void unnameSubMesh(const String& name); 00244 00250 ushort _getSubMeshIndex(const String& name) const; 00251 00254 unsigned short getNumSubMeshes(void) const; 00255 00258 SubMesh* getSubMesh(unsigned short index) const; 00259 00262 SubMesh* getSubMesh(const String& name) const ; 00263 00270 void destroySubMesh(unsigned short index); 00271 00278 void destroySubMesh(const String& name); 00279 00280 typedef VectorIterator<SubMeshList> SubMeshIterator; 00282 SubMeshIterator getSubMeshIterator(void) 00283 { return SubMeshIterator(mSubMeshList.begin(), mSubMeshList.end()); } 00284 00293 VertexData *sharedVertexData; 00294 00315 IndexMap sharedBlendIndexToBoneIndexMap; 00316 00328 MeshPtr clone(const String& newName, const String& newGroup = StringUtil::BLANK); 00329 00332 const AxisAlignedBox& getBounds(void) const; 00333 00335 Real getBoundingSphereRadius(void) const; 00336 00345 void _setBounds(const AxisAlignedBox& bounds, bool pad = true); 00346 00354 void _setBoundingSphereRadius(Real radius); 00355 00367 void setSkeletonName(const String& skelName); 00368 00370 bool hasSkeleton(void) const; 00371 00374 bool hasVertexAnimation(void) const; 00375 00380 const SkeletonPtr& getSkeleton(void) const; 00381 00383 const String& getSkeletonName(void) const; 00388 void _initAnimationState(AnimationStateSet* animSet); 00389 00394 void _refreshAnimationState(AnimationStateSet* animSet); 00407 void addBoneAssignment(const VertexBoneAssignment& vertBoneAssign); 00408 00414 void clearBoneAssignments(void); 00415 00422 void _notifySkeleton(SkeletonPtr& pSkel); 00423 00424 00427 BoneAssignmentIterator getBoneAssignmentIterator(void); 00428 00431 const VertexBoneAssignmentList& getBoneAssignments() const { return mBoneAssignments; } 00432 00433 00438 ushort getNumLodLevels(void) const; 00440 const MeshLodUsage& getLodLevel(ushort index) const; 00456 void createManualLodLevel(Real value, const String& meshName, const String& groupName = Ogre::String()); 00457 00467 void updateManualLodLevel(ushort index, const String& meshName); 00468 00475 ushort getLodIndex(Real value) const; 00476 00483 bool isLodManual(void) const { return mIsLodManual; } 00484 00486 void _setLodInfo(unsigned short numLevels, bool isManual); 00488 void _setLodUsage(unsigned short level, MeshLodUsage& usage); 00490 void _setSubMeshLodFaceList(unsigned short subIdx, unsigned short level, IndexData* facedata); 00491 00493 void removeLodLevels(void); 00494 00519 void setVertexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false); 00544 void setIndexBufferPolicy(HardwareBuffer::Usage usage, bool shadowBuffer = false); 00546 HardwareBuffer::Usage getVertexBufferUsage(void) const { return mVertexBufferUsage; } 00548 HardwareBuffer::Usage getIndexBufferUsage(void) const { return mIndexBufferUsage; } 00550 bool isVertexBufferShadowed(void) const { return mVertexBufferShadowBuffer; } 00552 bool isIndexBufferShadowed(void) const { return mIndexBufferShadowBuffer; } 00553 00554 00571 unsigned short _rationaliseBoneAssignments(size_t vertexCount, VertexBoneAssignmentList& assignments); 00572 00580 void _compileBoneAssignments(void); 00581 00587 void _updateCompiledBoneAssignments(void); 00588 00604 void mergeAdjacentTexcoords( unsigned short finalTexCoordSet, unsigned short texCoordSetToDestroy ); 00605 00606 void _configureMeshLodUsage(const LodConfig& lodConfig); 00607 00640 void buildTangentVectors(VertexElementSemantic targetSemantic = VES_TANGENT, 00641 unsigned short sourceTexCoordSet = 0, unsigned short index = 0, 00642 bool splitMirrored = false, bool splitRotated = false, bool storeParityInW = false); 00643 00665 bool suggestTangentVectorBuildParams(VertexElementSemantic targetSemantic, 00666 unsigned short& outSourceCoordSet, unsigned short& outIndex); 00667 00671 void buildEdgeList(void); 00673 void freeEdgeList(void); 00674 00693 void prepareForShadowVolume(void); 00694 00702 EdgeData* getEdgeList(unsigned short lodIndex = 0); 00703 00711 const EdgeData* getEdgeList(unsigned short lodIndex = 0) const; 00712 00715 bool isPreparedForShadowVolumes(void) const { return mPreparedForShadowVolumes; } 00716 00718 bool isEdgeListBuilt(void) const { return mEdgeListsBuilt; } 00719 00734 static void prepareMatricesForVertexBlend(const Matrix4** blendMatrices, 00735 const Matrix4* boneMatrices, const IndexMap& indexMap); 00736 00760 static void softwareVertexBlend(const VertexData* sourceVertexData, 00761 const VertexData* targetVertexData, 00762 const Matrix4* const* blendMatrices, size_t numMatrices, 00763 bool blendNormals); 00764 00781 static void softwareVertexMorph(Real t, 00782 const HardwareVertexBufferSharedPtr& b1, 00783 const HardwareVertexBufferSharedPtr& b2, 00784 VertexData* targetVertexData); 00785 00805 static void softwareVertexPoseBlend(Real weight, 00806 const map<size_t, Vector3>::type& vertexOffsetMap, 00807 const map<size_t, Vector3>::type& normalsMap, 00808 VertexData* targetVertexData); 00810 const SubMeshNameMap& getSubMeshNameMap(void) const { return mSubMeshNameMap; } 00811 00822 void setAutoBuildEdgeLists(bool autobuild) { mAutoBuildEdgeLists = autobuild; } 00827 bool getAutoBuildEdgeLists(void) const { return mAutoBuildEdgeLists; } 00828 00831 virtual VertexAnimationType getSharedVertexDataAnimationType(void) const; 00832 00834 bool getSharedVertexDataAnimationIncludesNormals() const { return mSharedVertexDataAnimationIncludesNormals; } 00835 00842 virtual Animation* createAnimation(const String& name, Real length); 00843 00848 virtual Animation* getAnimation(const String& name) const; 00849 00855 virtual Animation* _getAnimationImpl(const String& name) const; 00856 00858 virtual bool hasAnimation(const String& name) const; 00859 00861 virtual void removeAnimation(const String& name); 00862 00864 virtual unsigned short getNumAnimations(void) const; 00865 00868 virtual Animation* getAnimation(unsigned short index) const; 00869 00871 virtual void removeAllAnimations(void); 00877 VertexData* getVertexDataByTrackHandle(unsigned short handle); 00889 void updateMaterialForAllSubMeshes(void); 00890 00895 void _determineAnimationTypes(void) const; 00897 bool _getAnimationTypesDirty(void) const { return mAnimationTypesDirty; } 00898 00908 Pose* createPose(ushort target, const String& name = StringUtil::BLANK); 00910 size_t getPoseCount(void) const { return mPoseList.size(); } 00912 Pose* getPose(ushort index); 00914 Pose* getPose(const String& name); 00919 void removePose(ushort index); 00924 void removePose(const String& name); 00926 void removeAllPoses(void); 00927 00928 typedef VectorIterator<PoseList> PoseIterator; 00929 typedef ConstVectorIterator<PoseList> ConstPoseIterator; 00930 00932 PoseIterator getPoseIterator(void); 00934 ConstPoseIterator getPoseIterator(void) const; 00936 const PoseList& getPoseList(void) const; 00937 00939 const LodStrategy *getLodStrategy() const; 00941 void setLodStrategy(LodStrategy *lodStrategy); 00942 00943 }; 00944 00946 struct MeshLodUsage 00947 { 00952 Real userValue; 00953 00959 Real value; 00960 00962 String manualName; 00964 String manualGroup; 00966 mutable MeshPtr manualMesh; 00968 mutable EdgeData* edgeData; 00969 00970 MeshLodUsage() : userValue(0.0), value(0.0), edgeData(0) {} 00971 }; 00972 00977 } // namespace Ogre 00978 00979 #include "OgreHeaderSuffix.h" 00980 00981 #endif // __Mesh_H__
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:44