OgreSkeleton.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-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 
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 #include "OgreHeaderPrefix.h"
00040 
00041 namespace Ogre {
00050     enum SkeletonAnimationBlendMode {
00052         ANIMBLEND_AVERAGE = 0,
00054         ANIMBLEND_CUMULATIVE = 1
00055     };
00056 
00057 #define OGRE_MAX_NUM_BONES 256
00058 
00059     
00060     struct LinkedSkeletonAnimationSource;
00061 
00087     class _OgreExport Skeleton : public Resource, public AnimationContainer
00088     {
00089         friend class SkeletonInstance;
00090     protected:
00092         Skeleton();
00093 
00094     public:
00100         Skeleton(ResourceManager* creator, const String& name, ResourceHandle handle,
00101             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
00102         virtual ~Skeleton();
00103 
00104 
00118         virtual Bone* createBone(void);
00119 
00133         virtual Bone* createBone(unsigned short handle);
00134 
00148         virtual Bone* createBone(const String& name);
00149 
00160         virtual Bone* createBone(const String& name, unsigned short handle);
00161 
00163         virtual unsigned short getNumBones(void) const;
00164 
00176         virtual Bone* getRootBone(void) const;
00177 
00178         typedef vector<Bone*>::type BoneList;
00179         typedef VectorIterator<BoneList> BoneIterator;
00181         virtual BoneIterator getRootBoneIterator(void);
00183         virtual BoneIterator getBoneIterator(void);
00184 
00186         virtual Bone* getBone(unsigned short handle) const;
00187 
00189         virtual Bone* getBone(const String& name) const;
00190 
00192         virtual bool hasBone(const String& name) const;
00193 
00197         virtual void setBindingPose(void);
00198 
00208         virtual void reset(bool resetManualBones = false);
00209 
00214         virtual Animation* createAnimation(const String& name, Real length);
00215 
00224         virtual Animation* getAnimation(const String& name, 
00225             const LinkedSkeletonAnimationSource** linker) const;
00226 
00233         virtual Animation* getAnimation(const String& name) const;
00234 
00236         virtual Animation* _getAnimationImpl(const String& name, 
00237             const LinkedSkeletonAnimationSource** linker = 0) const;
00238 
00239 
00241         virtual bool hasAnimation(const String& name) const;
00242 
00244         virtual void removeAnimation(const String& name);
00245 
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;
00461 
00462     };
00463 
00464     typedef SharedPtr<Skeleton> SkeletonPtr;
00465 
00467     struct LinkedSkeletonAnimationSource
00468     {
00469         String skeletonName;
00470         SkeletonPtr pSkeleton;
00471         Real scale;
00472         LinkedSkeletonAnimationSource(const String& skelName, Real scl)
00473             : skeletonName(skelName), scale(scl) {}
00474             LinkedSkeletonAnimationSource(const String& skelName, Real scl, 
00475                 SkeletonPtr skelPtr)
00476                 : skeletonName(skelName), pSkeleton(skelPtr), scale(scl) {}
00477     };
00481 }
00482 
00483 #include "OgreHeaderSuffix.h"
00484 
00485 #endif
00486 

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 Mon Jul 27 2020 13:40:47