OGRE  1.8
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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-2013 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 #include "OgreAnimation.h"
39 #include "OgreHeaderPrefix.h"
40 
41 namespace Ogre {
55  };
56 
57 #define OGRE_MAX_NUM_BONES 256
58 
59 
60  struct LinkedSkeletonAnimationSource;
61 
88  {
89  friend class SkeletonInstance;
90  protected:
92  Skeleton();
93 
94  public:
100  Skeleton(ResourceManager* creator, const String& name, ResourceHandle handle,
101  const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
102  virtual ~Skeleton();
103 
104 
118  virtual Bone* createBone(void);
119 
133  virtual Bone* createBone(unsigned short handle);
134 
148  virtual Bone* createBone(const String& name);
149 
160  virtual Bone* createBone(const String& name, unsigned short handle);
161 
163  virtual unsigned short getNumBones(void) const;
164 
176  virtual Bone* getRootBone(void) const;
177 
181  virtual BoneIterator getRootBoneIterator(void);
183  virtual BoneIterator getBoneIterator(void);
184 
186  virtual Bone* getBone(unsigned short handle) const;
187 
189  virtual Bone* getBone(const String& name) const;
190 
192  virtual bool hasBone(const String& name) const;
193 
197  virtual void setBindingPose(void);
198 
208  virtual void reset(bool resetManualBones = false);
209 
214  virtual Animation* createAnimation(const String& name, Real length);
215 
224  virtual Animation* getAnimation(const String& name,
225  const LinkedSkeletonAnimationSource** linker) const;
226 
233  virtual Animation* getAnimation(const String& name) const;
234 
236  virtual Animation* _getAnimationImpl(const String& name,
237  const LinkedSkeletonAnimationSource** linker = 0) const;
238 
239 
241  virtual bool hasAnimation(const String& name) const;
242 
244  virtual void removeAnimation(const String& name);
245 
257  virtual void setAnimationState(const AnimationStateSet& animSet);
258 
259 
264  virtual void _initAnimationState(AnimationStateSet* animSet);
265 
270  virtual void _refreshAnimationState(AnimationStateSet* animSet);
271 
278  virtual void _getBoneMatrices(Matrix4* pMatrices);
279 
281  virtual unsigned short getNumAnimations(void) const;
282 
288  virtual Animation* getAnimation(unsigned short index) const;
289 
290 
292  virtual SkeletonAnimationBlendMode getBlendMode() const;
294  virtual void setBlendMode(SkeletonAnimationBlendMode state);
295 
297  virtual void _updateTransforms(void);
298 
304  virtual void optimiseAllAnimations(bool preservingIdentityNodeTracks = false);
305 
339  virtual void addLinkedSkeletonAnimationSource(const String& skelName,
340  Real scale = 1.0f);
342  virtual void removeAllLinkedSkeletonAnimationSources(void);
343 
350  getLinkedSkeletonAnimationSourceIterator(void) const;
351 
353  virtual void _notifyManualBonesDirty(void);
355  virtual void _notifyManualBoneStateChange(Bone* bone);
356 
358  virtual bool getManualBonesDirty(void) const { return mManualBonesDirty; }
360  virtual bool hasManualBones(void) const { return !mManualBones.empty(); }
361 
364 
398  virtual void _mergeSkeletonAnimations(const Skeleton* source,
399  const BoneHandleMap& boneHandleMap,
400  const StringVector& animations = StringVector());
401 
406  virtual void _buildMapBoneByHandle(const Skeleton* source,
407  BoneHandleMap& boneHandleMap) const;
408 
413  virtual void _buildMapBoneByName(const Skeleton* source,
414  BoneHandleMap& boneHandleMap) const;
415 
416  protected:
423 
424 
428  unsigned short mNextAutoHandle;
434 
435 
439 
442 
448  void deriveRootBone(void) const;
449 
451  void _dumpContents(const String& filename);
452 
455  void loadImpl(void);
456 
459  void unloadImpl(void);
461  size_t calculateSize(void) const { return 0; } // TODO
462 
463  };
464 
471  class _OgreExport SkeletonPtr : public SharedPtr<Skeleton>
472  {
473  public:
475  explicit SkeletonPtr(Skeleton* rep) : SharedPtr<Skeleton>(rep) {}
478  {
479  // lock & copy other mutex pointer
480  OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
481  {
482  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
483  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
484  pRep = static_cast<Skeleton*>(r.getPointer());
485  pUseCount = r.useCountPointer();
486  if (pUseCount)
487  {
488  ++(*pUseCount);
489  }
490  }
491  }
492 
495  {
496  if (pRep == static_cast<Skeleton*>(r.getPointer()))
497  return *this;
498  release();
499  // lock & copy other mutex pointer
500  OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
501  {
502  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
503  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
504  pRep = static_cast<Skeleton*>(r.getPointer());
505  pUseCount = r.useCountPointer();
506  if (pUseCount)
507  {
508  ++(*pUseCount);
509  }
510  }
511  else
512  {
513  // RHS must be a null pointer
514  assert(r.isNull() && "RHS must be null if it has no mutex!");
515  setNull();
516  }
517  return *this;
518  }
519  };
520 
523  {
528  : skeletonName(skelName), scale(scl) {}
530  SkeletonPtr skelPtr)
531  : skeletonName(skelName), pSkeleton(skelPtr), scale(scl) {}
532  };
536 }
537 
538 #include "OgreHeaderSuffix.h"
539 
540 #endif
541 
Class encapsulating a set of AnimationState objects.
set< Bone * >::type BoneSet
Definition: OgreSkeleton.h:429
SkeletonAnimationBlendMode
Definition: OgreSkeleton.h:50
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
VectorIterator< BoneList > BoneIterator
Definition: OgreSkeleton.h:179
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:494
#define _OgreExport
Definition: OgrePlatform.h:233
AnimationList mAnimationsList
Definition: OgreSkeleton.h:438
#define OGRE_MUTEX_CONDITIONAL(name)
vector< ushort >::type BoneHandleMap
Map to translate bone handle from one skeleton to another skeleton.
Definition: OgreSkeleton.h:363
SkeletonAnimationBlendMode mBlendState
Definition: OgreSkeleton.h:417
LinkedSkeletonAnimationSource(const String &skelName, Real scl)
Definition: OgreSkeleton.h:527
BoneList mBoneList
Storage of bones, indexed by bone handle.
Definition: OgreSkeleton.h:419
LinkedSkeletonAnimationSource(const String &skelName, Real scl, SkeletonPtr skelPtr)
Definition: OgreSkeleton.h:529
Interface describing a manual resource loader.
Definition: OgreResource.h:513
BoneList mRootBones
Pointer to root bones (can now have multiple roots)
Definition: OgreSkeleton.h:426
SkeletonPtr(const ResourcePtr &r)
Definition: OgreSkeleton.h:477
SkeletonPtr(const SkeletonPtr &r)
Definition: OgreSkeleton.h:476
vector< Bone * >::type BoneList
Definition: OgreSkeleton.h:178
SkeletonPtr(Skeleton *rep)
Definition: OgreSkeleton.h:475
vector< LinkedSkeletonAnimationSource >::type LinkedSkeletonAnimSourceList
Definition: OgreSkeleton.h:345
virtual bool getManualBonesDirty(void) const
Have manual bones been modified since the skeleton was last updated?
Definition: OgreSkeleton.h:358
Animations are applied by calculating a weighted cumulative total.
Definition: OgreSkeleton.h:54
unsigned short mNextAutoHandle
Bone automatic handles.
Definition: OgreSkeleton.h:428
Concrete IteratorWrapper for const access to the underlying container.
map< String, Animation * >::type AnimationList
Storage of animations, lookup by name.
Definition: OgreSkeleton.h:437
vector< String >::type StringVector
Link to another skeleton to share animations.
Definition: OgreSkeleton.h:522
Animations are applied by calculating a weighted average of all animations.
Definition: OgreSkeleton.h:52
ConstVectorIterator< LinkedSkeletonAnimSourceList > LinkedSkeletonAnimSourceIterator
Definition: OgreSkeleton.h:347
bool mManualBonesDirty
Manual bones dirty?
Definition: OgreSkeleton.h:433
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:78
unsigned long long int ResourceHandle
Definition: OgreResource.h:40
LinkedSkeletonAnimSourceList mLinkedSkeletonAnimSourceList
List of references to other skeletons to use animations from.
Definition: OgreSkeleton.h:441
#define OGRE_LOCK_MUTEX(name)
BoneListByName mBoneListByName
Definition: OgreSkeleton.h:422
An animation container interface, which allows generic access to sibling animations.
Definition: OgreAnimation.h:58
virtual bool hasManualBones(void) const
Are there any manually controlled bones?
Definition: OgreSkeleton.h:360
map< String, Bone * >::type BoneListByName
Lookup by bone name.
Definition: OgreSkeleton.h:421
Defines a generic resource handler.
unsigned int * useCountPointer() const
Specialisation of SharedPtr to allow SharedPtr to be assigned to SkeletonPtr.
Definition: OgreSkeleton.h:471
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:431
size_t calculateSize(void) const
Calculate the size of a resource; this will only be called after 'load'.
Definition: OgreSkeleton.h:461
Concrete IteratorWrapper for nonconst access to the underlying container.
An animation sequence.
Definition: OgreAnimation.h:90
A bone in a skeleton.
Definition: OgreBone.h:51
A collection of Bone objects used to animate a skinned mesh.
Definition: OgreSkeleton.h:87
#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