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 00029 #ifndef __Skeleton_H__ 00030 #define __Skeleton_H__ 00031 00032 #include "OgrePrerequisites.h" 00033 #include "OgreResource.h" 00034 #include "OgreQuaternion.h" 00035 #include "OgreVector3.h" 00036 #include "OgreIteratorWrappers.h" 00037 #include "OgreStringVector.h" 00038 #include "OgreAnimation.h" 00039 00040 namespace Ogre { 00049 enum SkeletonAnimationBlendMode { 00051 ANIMBLEND_AVERAGE = 0, 00053 ANIMBLEND_CUMULATIVE = 1 00054 }; 00055 00056 #define OGRE_MAX_NUM_BONES 256 00057 00058 00059 struct LinkedSkeletonAnimationSource; 00060 00086 class _OgreExport Skeleton : public Resource, public AnimationContainer 00087 { 00088 friend class SkeletonInstance; 00089 protected: 00091 Skeleton(); 00092 00093 public: 00099 Skeleton(ResourceManager* creator, const String& name, ResourceHandle handle, 00100 const String& group, bool isManual = false, ManualResourceLoader* loader = 0); 00101 virtual ~Skeleton(); 00102 00103 00117 virtual Bone* createBone(void); 00118 00132 virtual Bone* createBone(unsigned short handle); 00133 00147 virtual Bone* createBone(const String& name); 00148 00159 virtual Bone* createBone(const String& name, unsigned short handle); 00160 00162 virtual unsigned short getNumBones(void) const; 00163 00175 virtual Bone* getRootBone(void) const; 00176 00177 typedef vector<Bone*>::type BoneList; 00178 typedef VectorIterator<BoneList> BoneIterator; 00180 virtual BoneIterator getRootBoneIterator(void); 00182 virtual BoneIterator getBoneIterator(void); 00183 00185 virtual Bone* getBone(unsigned short handle) const; 00186 00188 virtual Bone* getBone(const String& name) const; 00189 00191 virtual bool hasBone(const String& name) const; 00192 00196 virtual void setBindingPose(void); 00197 00207 virtual void reset(bool resetManualBones = false); 00208 00213 virtual Animation* createAnimation(const String& name, Real length); 00214 00223 virtual Animation* getAnimation(const String& name, 00224 const LinkedSkeletonAnimationSource** linker) const; 00225 00232 virtual Animation* getAnimation(const String& name) const; 00233 00235 virtual Animation* _getAnimationImpl(const String& name, 00236 const LinkedSkeletonAnimationSource** linker = 0) const; 00237 00238 00240 virtual bool hasAnimation(const String& name) const; 00241 00243 virtual void removeAnimation(const String& name); 00244 00256 virtual void setAnimationState(const AnimationStateSet& animSet); 00257 00258 00263 virtual void _initAnimationState(AnimationStateSet* animSet); 00264 00269 virtual void _refreshAnimationState(AnimationStateSet* animSet); 00270 00277 virtual void _getBoneMatrices(Matrix4* pMatrices); 00278 00280 virtual unsigned short getNumAnimations(void) const; 00281 00287 virtual Animation* getAnimation(unsigned short index) const; 00288 00289 00291 virtual SkeletonAnimationBlendMode getBlendMode() const; 00293 virtual void setBlendMode(SkeletonAnimationBlendMode state); 00294 00296 virtual void _updateTransforms(void); 00297 00303 virtual void optimiseAllAnimations(bool preservingIdentityNodeTracks = false); 00304 00338 virtual void addLinkedSkeletonAnimationSource(const String& skelName, 00339 Real scale = 1.0f); 00341 virtual void removeAllLinkedSkeletonAnimationSources(void); 00342 00343 typedef vector<LinkedSkeletonAnimationSource>::type 00344 LinkedSkeletonAnimSourceList; 00345 typedef ConstVectorIterator<LinkedSkeletonAnimSourceList> 00346 LinkedSkeletonAnimSourceIterator; 00348 virtual LinkedSkeletonAnimSourceIterator 00349 getLinkedSkeletonAnimationSourceIterator(void) const; 00350 00352 virtual void _notifyManualBonesDirty(void); 00354 virtual void _notifyManualBoneStateChange(Bone* bone); 00355 00357 virtual bool getManualBonesDirty(void) const { return mManualBonesDirty; } 00359 virtual bool hasManualBones(void) const { return !mManualBones.empty(); } 00360 00362 typedef vector<ushort>::type BoneHandleMap; 00363 00397 virtual void _mergeSkeletonAnimations(const Skeleton* source, 00398 const BoneHandleMap& boneHandleMap, 00399 const StringVector& animations = StringVector()); 00400 00405 virtual void _buildMapBoneByHandle(const Skeleton* source, 00406 BoneHandleMap& boneHandleMap) const; 00407 00412 virtual void _buildMapBoneByName(const Skeleton* source, 00413 BoneHandleMap& boneHandleMap) const; 00414 00415 protected: 00416 SkeletonAnimationBlendMode mBlendState; 00418 BoneList mBoneList; 00420 typedef map<String, Bone*>::type BoneListByName; 00421 BoneListByName mBoneListByName; 00422 00423 00425 mutable BoneList mRootBones; 00427 unsigned short mNextAutoHandle; 00428 typedef set<Bone*>::type BoneSet; 00430 BoneSet mManualBones; 00432 bool mManualBonesDirty; 00433 00434 00436 typedef map<String, Animation*>::type AnimationList; 00437 AnimationList mAnimationsList; 00438 00440 mutable LinkedSkeletonAnimSourceList mLinkedSkeletonAnimSourceList; 00441 00447 void deriveRootBone(void) const; 00448 00450 void _dumpContents(const String& filename); 00451 00454 void loadImpl(void); 00455 00458 void unloadImpl(void); 00460 size_t calculateSize(void) const { return 0; } // TODO 00461 00462 }; 00463 00470 class _OgreExport SkeletonPtr : public SharedPtr<Skeleton> 00471 { 00472 public: 00473 SkeletonPtr() : SharedPtr<Skeleton>() {} 00474 explicit SkeletonPtr(Skeleton* rep) : SharedPtr<Skeleton>(rep) {} 00475 SkeletonPtr(const SkeletonPtr& r) : SharedPtr<Skeleton>(r) {} 00476 SkeletonPtr(const ResourcePtr& r) : SharedPtr<Skeleton>() 00477 { 00478 // lock & copy other mutex pointer 00479 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00480 { 00481 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00482 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00483 pRep = static_cast<Skeleton*>(r.getPointer()); 00484 pUseCount = r.useCountPointer(); 00485 if (pUseCount) 00486 { 00487 ++(*pUseCount); 00488 } 00489 } 00490 } 00491 00493 SkeletonPtr& operator=(const ResourcePtr& r) 00494 { 00495 if (pRep == static_cast<Skeleton*>(r.getPointer())) 00496 return *this; 00497 release(); 00498 // lock & copy other mutex pointer 00499 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00500 { 00501 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00502 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00503 pRep = static_cast<Skeleton*>(r.getPointer()); 00504 pUseCount = r.useCountPointer(); 00505 if (pUseCount) 00506 { 00507 ++(*pUseCount); 00508 } 00509 } 00510 else 00511 { 00512 // RHS must be a null pointer 00513 assert(r.isNull() && "RHS must be null if it has no mutex!"); 00514 setNull(); 00515 } 00516 return *this; 00517 } 00518 }; 00519 00521 struct LinkedSkeletonAnimationSource 00522 { 00523 String skeletonName; 00524 SkeletonPtr pSkeleton; 00525 Real scale; 00526 LinkedSkeletonAnimationSource(const String& skelName, Real scl) 00527 : skeletonName(skelName), scale(scl) {} 00528 LinkedSkeletonAnimationSource(const String& skelName, Real scl, 00529 SkeletonPtr skelPtr) 00530 : skeletonName(skelName), pSkeleton(skelPtr), scale(scl) {} 00531 }; 00535 } 00536 00537 00538 #endif 00539
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:27 2012