OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreSkeleton.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2011 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 
29 #ifndef __Skeleton_H__
30 #define __Skeleton_H__
31 
32 #include "OgrePrerequisites.h"
33 #include "OgreResource.h"
34 #include "OgreQuaternion.h"
35 #include "OgreVector3.h"
36 #include "OgreIteratorWrappers.h"
37 #include "OgreStringVector.h"
38 
39 namespace Ogre {
53  };
54 
55 #define OGRE_MAX_NUM_BONES 256
56 
57 
58  struct LinkedSkeletonAnimationSource;
59 
85  class _OgreExport Skeleton : public Resource
86  {
87  friend class SkeletonInstance;
88  protected:
90  Skeleton();
91 
92  public:
98  Skeleton(ResourceManager* creator, const String& name, ResourceHandle handle,
99  const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
100  virtual ~Skeleton();
101 
102 
116  virtual Bone* createBone(void);
117 
131  virtual Bone* createBone(unsigned short handle);
132 
146  virtual Bone* createBone(const String& name);
147 
158  virtual Bone* createBone(const String& name, unsigned short handle);
159 
161  virtual unsigned short getNumBones(void) const;
162 
174  virtual Bone* getRootBone(void) const;
175 
179  virtual BoneIterator getRootBoneIterator(void);
181  virtual BoneIterator getBoneIterator(void);
182 
184  virtual Bone* getBone(unsigned short handle) const;
185 
187  virtual Bone* getBone(const String& name) const;
188 
190  virtual bool hasBone(const String& name) const;
191 
195  virtual void setBindingPose(void);
196 
206  virtual void reset(bool resetManualBones = false);
207 
212  virtual Animation* createAnimation(const String& name, Real length);
213 
222  virtual Animation* getAnimation(const String& name,
223  const LinkedSkeletonAnimationSource** linker = 0) const;
224 
226  virtual Animation* _getAnimationImpl(const String& name,
227  const LinkedSkeletonAnimationSource** linker = 0) const;
228 
229 
231  virtual bool hasAnimation(const String& name);
232 
234  virtual void removeAnimation(const String& name);
235 
247  virtual void setAnimationState(const AnimationStateSet& animSet);
248 
249 
254  virtual void _initAnimationState(AnimationStateSet* animSet);
255 
260  virtual void _refreshAnimationState(AnimationStateSet* animSet);
261 
268  virtual void _getBoneMatrices(Matrix4* pMatrices);
269 
271  virtual unsigned short getNumAnimations(void) const;
272 
278  virtual Animation* getAnimation(unsigned short index) const;
279 
280 
282  virtual SkeletonAnimationBlendMode getBlendMode() const;
284  virtual void setBlendMode(SkeletonAnimationBlendMode state);
285 
287  virtual void _updateTransforms(void);
288 
294  virtual void optimiseAllAnimations(bool preservingIdentityNodeTracks = false);
295 
329  virtual void addLinkedSkeletonAnimationSource(const String& skelName,
330  Real scale = 1.0f);
332  virtual void removeAllLinkedSkeletonAnimationSources(void);
333 
340  getLinkedSkeletonAnimationSourceIterator(void) const;
341 
343  virtual void _notifyManualBonesDirty(void);
345  virtual void _notifyManualBoneStateChange(Bone* bone);
346 
348  virtual bool getManualBonesDirty(void) const { return mManualBonesDirty; }
350  virtual bool hasManualBones(void) const { return !mManualBones.empty(); }
351 
354 
388  virtual void _mergeSkeletonAnimations(const Skeleton* source,
389  const BoneHandleMap& boneHandleMap,
390  const StringVector& animations = StringVector());
391 
396  virtual void _buildMapBoneByHandle(const Skeleton* source,
397  BoneHandleMap& boneHandleMap) const;
398 
403  virtual void _buildMapBoneByName(const Skeleton* source,
404  BoneHandleMap& boneHandleMap) const;
405 
406  protected:
413 
414 
418  unsigned short mNextAutoHandle;
424 
425 
429 
432 
438  void deriveRootBone(void) const;
439 
441  void _dumpContents(const String& filename);
442 
445  void loadImpl(void);
446 
449  void unloadImpl(void);
451  size_t calculateSize(void) const { return 0; } // TODO
452 
453  };
454 
461  class _OgreExport SkeletonPtr : public SharedPtr<Skeleton>
462  {
463  public:
465  explicit SkeletonPtr(Skeleton* rep) : SharedPtr<Skeleton>(rep) {}
468  {
469  // lock & copy other mutex pointer
470  OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
471  {
472  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
473  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
474  pRep = static_cast<Skeleton*>(r.getPointer());
475  pUseCount = r.useCountPointer();
476  if (pUseCount)
477  {
478  ++(*pUseCount);
479  }
480  }
481  }
482 
485  {
486  if (pRep == static_cast<Skeleton*>(r.getPointer()))
487  return *this;
488  release();
489  // lock & copy other mutex pointer
490  OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
491  {
492  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
493  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
494  pRep = static_cast<Skeleton*>(r.getPointer());
495  pUseCount = r.useCountPointer();
496  if (pUseCount)
497  {
498  ++(*pUseCount);
499  }
500  }
501  else
502  {
503  // RHS must be a null pointer
504  assert(r.isNull() && "RHS must be null if it has no mutex!");
505  setNull();
506  }
507  return *this;
508  }
509  };
510 
513  {
518  : skeletonName(skelName), scale(scl) {}
520  SkeletonPtr skelPtr)
521  : skeletonName(skelName), pSkeleton(skelPtr), scale(scl) {}
522  };
526 }
527 
528 
529 #endif
530 
Class encapsulating a set of AnimationState objects.
set< Bone * >::type BoneSet
Definition: OgreSkeleton.h:419
SkeletonAnimationBlendMode
Definition: OgreSkeleton.h:48
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
VectorIterator< BoneList > BoneIterator
Definition: OgreSkeleton.h:177
T * getPointer() const
float Real
Software floating point type.
SkeletonPtr & operator=(const ResourcePtr &r)
Operator used to convert a ResourcePtr to a SkeletonPtr.
Definition: OgreSkeleton.h:484
#define _OgreExport
Definition: OgrePlatform.h:203
AnimationList mAnimationsList
Definition: OgreSkeleton.h:428
#define OGRE_MUTEX_CONDITIONAL(name)
vector< ushort >::type BoneHandleMap
Map to translate bone handle from one skeleton to another skeleton.
Definition: OgreSkeleton.h:353
SkeletonAnimationBlendMode mBlendState
Definition: OgreSkeleton.h:407
LinkedSkeletonAnimationSource(const String &skelName, Real scl)
Definition: OgreSkeleton.h:517
BoneList mBoneList
Storage of bones, indexed by bone handle.
Definition: OgreSkeleton.h:409
LinkedSkeletonAnimationSource(const String &skelName, Real scl, SkeletonPtr skelPtr)
Definition: OgreSkeleton.h:519
Interface describing a manual resource loader.
Definition: OgreResource.h:512
BoneList mRootBones
Pointer to root bones (can now have multiple roots)
Definition: OgreSkeleton.h:416
SkeletonPtr(const ResourcePtr &r)
Definition: OgreSkeleton.h:467
SkeletonPtr(const SkeletonPtr &r)
Definition: OgreSkeleton.h:466
vector< Bone * >::type BoneList
Definition: OgreSkeleton.h:176
SkeletonPtr(Skeleton *rep)
Definition: OgreSkeleton.h:465
vector< LinkedSkeletonAnimationSource >::type LinkedSkeletonAnimSourceList
Definition: OgreSkeleton.h:335
virtual bool getManualBonesDirty(void) const
Have manual bones been modified since the skeleton was last updated?
Definition: OgreSkeleton.h:348
Animations are applied by calculating a weighted cumulative total.
Definition: OgreSkeleton.h:52
unsigned short mNextAutoHandle
Bone automatic handles.
Definition: OgreSkeleton.h:418
Concrete IteratorWrapper for const access to the underlying container.
map< String, Animation * >::type AnimationList
Storage of animations, lookup by name.
Definition: OgreSkeleton.h:427
vector< String >::type StringVector
Link to another skeleton to share animations.
Definition: OgreSkeleton.h:512
Animations are applied by calculating a weighted average of all animations.
Definition: OgreSkeleton.h:50
ConstVectorIterator< LinkedSkeletonAnimSourceList > LinkedSkeletonAnimSourceIterator
Definition: OgreSkeleton.h:337
bool mManualBonesDirty
Manual bones dirty?
Definition: OgreSkeleton.h:423
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:77
unsigned long long int ResourceHandle
Definition: OgreResource.h:39
LinkedSkeletonAnimSourceList mLinkedSkeletonAnimSourceList
List of references to other skeletons to use animations from.
Definition: OgreSkeleton.h:431
#define OGRE_LOCK_MUTEX(name)
BoneListByName mBoneListByName
Definition: OgreSkeleton.h:412
virtual bool hasManualBones(void) const
Are there any manually controlled bones?
Definition: OgreSkeleton.h:350
map< String, Bone * >::type BoneListByName
Lookup by bone name.
Definition: OgreSkeleton.h:411
Defines a generic resource handler.
unsigned int * useCountPointer() const
Specialisation of SharedPtr to allow SharedPtr to be assigned to SkeletonPtr.
Definition: OgreSkeleton.h:461
Reference-counted shared pointer, used for objects where implicit destruction is required.
Definition: OgreSharedPtr.h:60
_StringBase String
BoneSet mManualBones
Manual bones.
Definition: OgreSkeleton.h:421
size_t calculateSize(void) const
Calculate the size of a resource; this will only be called after 'load'.
Definition: OgreSkeleton.h:451
Concrete IteratorWrapper for nonconst access to the underlying container.
An animation sequence.
Definition: OgreAnimation.h:58
A bone in a skeleton.
Definition: OgreBone.h:51
A collection of Bone objects used to animate a skinned mesh.
Definition: OgreSkeleton.h:85
#define OGRE_COPY_AUTO_SHARED_MUTEX(from)
A SkeletonInstance is a single instance of a Skeleton used by a world object.
bool isNull(void) const