# 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-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029
    00030 #ifndef __Skeleton_H__
    00031 #define __Skeleton_H__
    00032
    00033 #include "OgrePrerequisites.h"
    00034 #include "OgreResource.h"
    00035 #include "OgreQuaternion.h"
    00036 #include "OgreVector3.h"
    00037 #include "OgreIteratorWrappers.h"
    00038 #include "OgreStringVector.h"
    00039
    00040 namespace Ogre {
    00041
    00043     enum SkeletonAnimationBlendMode {
    00045         ANIMBLEND_AVERAGE,
    00047         ANIMBLEND_CUMULATIVE
    00048     };
    00049
    00050 #define OGRE_MAX_NUM_BONES 256
    00051
    00052
    00053     struct LinkedSkeletonAnimationSource;
    00054
    00080     class _OgreExport Skeleton : public Resource
    00081     {
    00082         friend class SkeletonInstance;
    00083     protected:
    00085         Skeleton();
    00086
    00087     public:
    00093         Skeleton(ResourceManager* creator, const String& name, ResourceHandle handle,
    00094             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    00095         virtual ~Skeleton();
    00096
    00097
    00111         virtual Bone* createBone(void);
    00112
    00126         virtual Bone* createBone(unsigned short handle);
    00127
    00141         virtual Bone* createBone(const String& name);
    00142
    00153         virtual Bone* createBone(const String& name, unsigned short handle);
    00154
    00156         virtual unsigned short getNumBones(void) const;
    00157
    00169         virtual Bone* getRootBone(void) const;
    00170
    00171         typedef std::vector<Bone*> BoneList;
    00172         typedef VectorIterator<BoneList> BoneIterator;
    00174         virtual BoneIterator getRootBoneIterator(void);
    00176         virtual BoneIterator getBoneIterator(void);
    00177
    00179         virtual Bone* getBone(unsigned short handle) const;
    00180
    00182         virtual Bone* getBone(const String& name) const;
    00183
    00185         virtual bool hasBone(const String& name) const;
    00186
    00190         virtual void setBindingPose(void);
    00191
    00201         virtual void reset(bool resetManualBones = false);
    00202
    00207         virtual Animation* createAnimation(const String& name, Real length);
    00208
    00217         virtual Animation* getAnimation(const String& name,
    00218             const LinkedSkeletonAnimationSource** linker = 0) const;
    00219
    00221         virtual Animation* _getAnimationImpl(const String& name,
    00222             const LinkedSkeletonAnimationSource** linker = 0) const;
    00223
    00224
    00226         virtual bool hasAnimation(const String& name);
    00227
    00229         virtual void removeAnimation(const String& name);
    00230
    00242         virtual void setAnimationState(const AnimationStateSet& animSet);
    00243
    00244
    00249         virtual void _initAnimationState(AnimationStateSet* animSet);
    00250
    00255         virtual void _refreshAnimationState(AnimationStateSet* animSet);
    00256
    00263         virtual void _getBoneMatrices(Matrix4* pMatrices);
    00264
    00266         virtual unsigned short getNumAnimations(void) const;
    00267
    00273         virtual Animation* getAnimation(unsigned short index) const;
    00274
    00275
    00277         virtual SkeletonAnimationBlendMode getBlendMode() const;
    00279         virtual void setBlendMode(SkeletonAnimationBlendMode state);
    00280
    00282         virtual void _updateTransforms(void);
    00283
    00289         virtual void optimiseAllAnimations(bool preservingIdentityNodeTracks = false);
    00290
    00324         virtual void addLinkedSkeletonAnimationSource(const String& skelName,
    00325             Real scale = 1.0f);
    00327         virtual void removeAllLinkedSkeletonAnimationSources(void);
    00328
    00329         typedef std::vector<LinkedSkeletonAnimationSource>
    00330             LinkedSkeletonAnimSourceList;
    00331         typedef ConstVectorIterator<LinkedSkeletonAnimSourceList>
    00332             LinkedSkeletonAnimSourceIterator;
    00334         virtual LinkedSkeletonAnimSourceIterator
    00335             getLinkedSkeletonAnimationSourceIterator(void) const;
    00336
    00338         virtual void _notifyManualBonesDirty(void);
    00340         virtual void _notifyManualBoneStateChange(Bone* bone);
    00341
    00343         virtual bool getManualBonesDirty(void) const { return mManualBonesDirty; }
    00345         virtual bool hasManualBones(void) const { return !mManualBones.empty(); }
    00346
    00348         typedef std::vector<ushort> BoneHandleMap;
    00349
    00383         virtual void _mergeSkeletonAnimations(const Skeleton* source,
    00384             const BoneHandleMap& boneHandleMap,
    00385             const StringVector& animations = StringVector());
    00386
    00391         virtual void _buildMapBoneByHandle(const Skeleton* source,
    00392             BoneHandleMap& boneHandleMap) const;
    00393
    00398         virtual void _buildMapBoneByName(const Skeleton* source,
    00399             BoneHandleMap& boneHandleMap) const;
    00400
    00401     protected:
    00402         SkeletonAnimationBlendMode mBlendState;
    00404         BoneList mBoneList;
    00406         typedef std::map<String, Bone*> BoneListByName;
    00407         BoneListByName mBoneListByName;
    00408
    00409
    00411         mutable BoneList mRootBones;
    00413         unsigned short mNextAutoHandle;
    00414         typedef std::set<Bone*> BoneSet;
    00416         BoneSet mManualBones;
    00418         bool mManualBonesDirty;
    00419
    00420
    00422         typedef std::map<String, Animation*> AnimationList;
    00423         AnimationList mAnimationsList;
    00424
    00426         mutable LinkedSkeletonAnimSourceList mLinkedSkeletonAnimSourceList;
    00427
    00433         void deriveRootBone(void) const;
    00434
    00436         void _dumpContents(const String& filename);
    00437
    00440         void loadImpl(void);
    00441
    00444         void unloadImpl(void);
    00446         size_t calculateSize(void) const { return 0; } // TODO
    00447
    00448     };
    00449
    00456     class _OgreExport SkeletonPtr : public SharedPtr<Skeleton>
    00457     {
    00458     public:
    00459         SkeletonPtr() : SharedPtr<Skeleton>() {}
    00460         explicit SkeletonPtr(Skeleton* rep) : SharedPtr<Skeleton>(rep) {}
    00461         SkeletonPtr(const SkeletonPtr& r) : SharedPtr<Skeleton>(r) {}
    00462         SkeletonPtr(const ResourcePtr& r) : SharedPtr<Skeleton>()
    00463         {
    00464             // lock & copy other mutex pointer
    00465             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00466             {
    00467                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00468                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00469                 pRep = static_cast<Skeleton*>(r.getPointer());
    00470                 pUseCount = r.useCountPointer();
    00471                 if (pUseCount)
    00472                 {
    00473                     ++(*pUseCount);
    00474                 }
    00475             }
    00476         }
    00477
    00479         SkeletonPtr& operator=(const ResourcePtr& r)
    00480         {
    00481             if (pRep == static_cast<Skeleton*>(r.getPointer()))
    00482                 return *this;
    00483             release();
    00484             // lock & copy other mutex pointer
    00485             OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
    00486             {
    00487                 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00488                 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00489                 pRep = static_cast<Skeleton*>(r.getPointer());
    00490                 pUseCount = r.useCountPointer();
    00491                 if (pUseCount)
    00492                 {
    00493                     ++(*pUseCount);
    00494                 }
    00495             }
    00496             else
    00497             {
    00498                 // RHS must be a null pointer
    00499                 assert(r.isNull() && "RHS must be null if it has no mutex!");
    00500                 setNull();
    00501             }
    00502             return *this;
    00503         }
    00504     };
    00505
    00507     struct LinkedSkeletonAnimationSource
    00508     {
    00509         String skeletonName;
    00510         SkeletonPtr pSkeleton;
    00511         Real scale;
    00512         LinkedSkeletonAnimationSource(const String& skelName, Real scl)
    00513             : skeletonName(skelName), scale(scl) {}
    00514             LinkedSkeletonAnimationSource(const String& skelName, Real scl,
    00515                 SkeletonPtr skelPtr)
    00516                 : skeletonName(skelName), pSkeleton(skelPtr), scale(scl) {}
    00517     };
    00518 }
    00519
    00520
    00521 #endif
    00522

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Dec 27 17:31:08 2009