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-2011 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 00039 namespace Ogre { 00048 enum SkeletonAnimationBlendMode { 00050 ANIMBLEND_AVERAGE, 00052 ANIMBLEND_CUMULATIVE 00053 }; 00054 00055 #define OGRE_MAX_NUM_BONES 256 00056 00057 00058 struct LinkedSkeletonAnimationSource; 00059 00085 class _OgreExport Skeleton : public Resource 00086 { 00087 friend class SkeletonInstance; 00088 protected: 00090 Skeleton(); 00091 00092 public: 00098 Skeleton(ResourceManager* creator, const String& name, ResourceHandle handle, 00099 const String& group, bool isManual = false, ManualResourceLoader* loader = 0); 00100 virtual ~Skeleton(); 00101 00102 00116 virtual Bone* createBone(void); 00117 00131 virtual Bone* createBone(unsigned short handle); 00132 00146 virtual Bone* createBone(const String& name); 00147 00158 virtual Bone* createBone(const String& name, unsigned short handle); 00159 00161 virtual unsigned short getNumBones(void) const; 00162 00174 virtual Bone* getRootBone(void) const; 00175 00176 typedef vector<Bone*>::type BoneList; 00177 typedef VectorIterator<BoneList> BoneIterator; 00179 virtual BoneIterator getRootBoneIterator(void); 00181 virtual BoneIterator getBoneIterator(void); 00182 00184 virtual Bone* getBone(unsigned short handle) const; 00185 00187 virtual Bone* getBone(const String& name) const; 00188 00190 virtual bool hasBone(const String& name) const; 00191 00195 virtual void setBindingPose(void); 00196 00206 virtual void reset(bool resetManualBones = false); 00207 00212 virtual Animation* createAnimation(const String& name, Real length); 00213 00222 virtual Animation* getAnimation(const String& name, 00223 const LinkedSkeletonAnimationSource** linker = 0) const; 00224 00226 virtual Animation* _getAnimationImpl(const String& name, 00227 const LinkedSkeletonAnimationSource** linker = 0) const; 00228 00229 00231 virtual bool hasAnimation(const String& name); 00232 00234 virtual void removeAnimation(const String& name); 00235 00247 virtual void setAnimationState(const AnimationStateSet& animSet); 00248 00249 00254 virtual void _initAnimationState(AnimationStateSet* animSet); 00255 00260 virtual void _refreshAnimationState(AnimationStateSet* animSet); 00261 00268 virtual void _getBoneMatrices(Matrix4* pMatrices); 00269 00271 virtual unsigned short getNumAnimations(void) const; 00272 00278 virtual Animation* getAnimation(unsigned short index) const; 00279 00280 00282 virtual SkeletonAnimationBlendMode getBlendMode() const; 00284 virtual void setBlendMode(SkeletonAnimationBlendMode state); 00285 00287 virtual void _updateTransforms(void); 00288 00294 virtual void optimiseAllAnimations(bool preservingIdentityNodeTracks = false); 00295 00329 virtual void addLinkedSkeletonAnimationSource(const String& skelName, 00330 Real scale = 1.0f); 00332 virtual void removeAllLinkedSkeletonAnimationSources(void); 00333 00334 typedef vector<LinkedSkeletonAnimationSource>::type 00335 LinkedSkeletonAnimSourceList; 00336 typedef ConstVectorIterator<LinkedSkeletonAnimSourceList> 00337 LinkedSkeletonAnimSourceIterator; 00339 virtual LinkedSkeletonAnimSourceIterator 00340 getLinkedSkeletonAnimationSourceIterator(void) const; 00341 00343 virtual void _notifyManualBonesDirty(void); 00345 virtual void _notifyManualBoneStateChange(Bone* bone); 00346 00348 virtual bool getManualBonesDirty(void) const { return mManualBonesDirty; } 00350 virtual bool hasManualBones(void) const { return !mManualBones.empty(); } 00351 00353 typedef vector<ushort>::type BoneHandleMap; 00354 00388 virtual void _mergeSkeletonAnimations(const Skeleton* source, 00389 const BoneHandleMap& boneHandleMap, 00390 const StringVector& animations = StringVector()); 00391 00396 virtual void _buildMapBoneByHandle(const Skeleton* source, 00397 BoneHandleMap& boneHandleMap) const; 00398 00403 virtual void _buildMapBoneByName(const Skeleton* source, 00404 BoneHandleMap& boneHandleMap) const; 00405 00406 protected: 00407 SkeletonAnimationBlendMode mBlendState; 00409 BoneList mBoneList; 00411 typedef map<String, Bone*>::type BoneListByName; 00412 BoneListByName mBoneListByName; 00413 00414 00416 mutable BoneList mRootBones; 00418 unsigned short mNextAutoHandle; 00419 typedef set<Bone*>::type BoneSet; 00421 BoneSet mManualBones; 00423 bool mManualBonesDirty; 00424 00425 00427 typedef map<String, Animation*>::type AnimationList; 00428 AnimationList mAnimationsList; 00429 00431 mutable LinkedSkeletonAnimSourceList mLinkedSkeletonAnimSourceList; 00432 00438 void deriveRootBone(void) const; 00439 00441 void _dumpContents(const String& filename); 00442 00445 void loadImpl(void); 00446 00449 void unloadImpl(void); 00451 size_t calculateSize(void) const { return 0; } // TODO 00452 00453 }; 00454 00461 class _OgreExport SkeletonPtr : public SharedPtr<Skeleton> 00462 { 00463 public: 00464 SkeletonPtr() : SharedPtr<Skeleton>() {} 00465 explicit SkeletonPtr(Skeleton* rep) : SharedPtr<Skeleton>(rep) {} 00466 SkeletonPtr(const SkeletonPtr& r) : SharedPtr<Skeleton>(r) {} 00467 SkeletonPtr(const ResourcePtr& r) : SharedPtr<Skeleton>() 00468 { 00469 // lock & copy other mutex pointer 00470 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00471 { 00472 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00473 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00474 pRep = static_cast<Skeleton*>(r.getPointer()); 00475 pUseCount = r.useCountPointer(); 00476 if (pUseCount) 00477 { 00478 ++(*pUseCount); 00479 } 00480 } 00481 } 00482 00484 SkeletonPtr& operator=(const ResourcePtr& r) 00485 { 00486 if (pRep == static_cast<Skeleton*>(r.getPointer())) 00487 return *this; 00488 release(); 00489 // lock & copy other mutex pointer 00490 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00491 { 00492 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00493 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00494 pRep = static_cast<Skeleton*>(r.getPointer()); 00495 pUseCount = r.useCountPointer(); 00496 if (pUseCount) 00497 { 00498 ++(*pUseCount); 00499 } 00500 } 00501 else 00502 { 00503 // RHS must be a null pointer 00504 assert(r.isNull() && "RHS must be null if it has no mutex!"); 00505 setNull(); 00506 } 00507 return *this; 00508 } 00509 }; 00510 00512 struct LinkedSkeletonAnimationSource 00513 { 00514 String skeletonName; 00515 SkeletonPtr pSkeleton; 00516 Real scale; 00517 LinkedSkeletonAnimationSource(const String& skelName, Real scl) 00518 : skeletonName(skelName), scale(scl) {} 00519 LinkedSkeletonAnimationSource(const String& skelName, Real scl, 00520 SkeletonPtr skelPtr) 00521 : skeletonName(skelName), pSkeleton(skelPtr), scale(scl) {} 00522 }; 00526 } 00527 00528 00529 #endif 00530
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sat Jan 14 2012 18:40:44