SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLAnimSkeleton.h
Go to the documentation of this file.
1 /**
2  * \file SLAnimSkeleton.h
3  * \date Autumn 2014
4 // Codestyle: https://code.google.com/p/slproject/wiki/CodingStyleGuidelines
5  * \authors Marc Wacker, Marcus Hudritsch
6  * \copyright http://opensource.org/licenses/GPL-3.0
7 */
8 
9 #ifndef SLSKELETON_H
10 #define SLSKELETON_H
11 
12 #include <SLAnimPlayback.h>
13 #include <SLAnimation.h>
14 #include <SLJoint.h>
15 
16 class SLAnimManager;
17 class SLSceneView;
18 
19 //-----------------------------------------------------------------------------
20 //! SLAnimSkeleton keeps track of a skeletons joints and animations
21 /*!
22 An SLAnimSkeleton is used to animate a hierarchical object like a human being.
23 An SLAnimSkeleton keeps track of its bones (SLJoints) in a tree structure and
24 points with _root to the root node of the skeleton hierarchy.
25 An SLAnimSkeleton is not actively transforming any SLNode in the scenegraph.
26 It just keeps track of its transformed SLJoint.
27 A mesh that is associated with a skeleton transforms all its vertices every
28 frame by the joint weights. Every vertex of a mesh has weights for four joints
29 by which it can be influenced.
30 
31 SLAnimations for this skeleton are also kept in this class. The SLAnimations
32 have tracks corresponding to the individual SLJoints in the skeleton.
33 
34 @note The current implementation doesn't support multiple instances of the same
35  skeleton animation. It is however not that far away from supporting it.
36  Currently the SLAnimSkeleton class keeps both a SLAnimation map
37  and an SLAnimPlayback map. We can split this into two classes
38  by creating an SLSkeletonInstance class we that keeps the
39  SLAnimPlayback map that references its parent SLAnimSkeleton
40  we would be able to create multiple SLSkeletonInstance instances
41  that use the same SLAnimations but with different states.
42 
43  This leaves the problem of SLMesh that is not able to be instantiated
44  without copying the data into a completely separate SLMesh. But the
45  solution for SLMesh would take the same approach by creating a
46  mesh instance class that is able to use SLSkeletonInstance.
47 
48 @note The current version of the SLAssimpImporter only supports the loading of a single animation.
49  This limitation is mainly because there are very few 3D programs
50  that make use of the possibility to export multiple animations in
51  a single file. This means we would need to extend our importer to
52  be able to load more animations for an already loaded skeleton.
53 */
55 {
56 public:
59 
61  SLJoint* createJoint(const SLstring& name, SLuint id);
62  SLAnimation* createAnimation(SLAnimManager& aniMan, const SLstring& name, SLfloat duration);
63 
64  void loadAnimation(const SLstring& file);
66  void getJointMatrices(SLVMat4f& jointWM);
67  void reset();
68 
69  // Getters
70  SLAnimPlayback* animPlayback(const SLstring& name);
72  SLint numAnimations() const { return (SLint)_animations.size(); }
73  SLJoint* getJoint(SLuint id);
74  SLJoint* getJoint(const SLstring& name);
75  SLint numJoints() const { return (SLint)_joints.size(); }
76  const SLVJoint& joints() const { return _joints; }
77  SLJoint* rootJoint() { return _rootJoint; }
78  SLbool changed() const { return _changed; }
79  const SLVec3f& minOS();
80  const SLVec3f& maxOS();
81 
82  // Setters
83  void rootJoint(SLJoint* joint) { _rootJoint = joint; }
85  {
86  _changed = changed;
87  _minMaxOutOfDate = true;
88  }
89 
90  SLbool updateAnimations(SLfloat elapsedTimeSec);
91 
92 protected:
93  void updateMinMax();
94 
95  SLJoint* _rootJoint; //!< pointer to the root joint of skeleton
96  SLVJoint _joints; //!< joint vector for fast access and index to joint mapping
97  SLMAnimation _animations; //!< map of animations for this skeleton
98  SLMAnimPlayback _animPlaybacks; //!< map of animation playbacks for this skeleton
99  SLbool _changed; //!< did this skeleton change this frame (attribute for skeleton instance)
100  SLVec3f _minOS; //!< min point in os for this skeleton (attribute for skeleton instance)
101  SLVec3f _maxOS; //!< max point in os for this skeleton (attribute for skeleton instance)
102  SLbool _minMaxOutOfDate; //!< dirty flag aabb rebuild
103 };
104 //-----------------------------------------------------------------------------
105 typedef vector<SLAnimSkeleton*> SLVSkeleton;
106 //-----------------------------------------------------------------------------
107 
108 #endif
float SLfloat
Definition: SL.h:173
unsigned int SLuint
Definition: SL.h:171
bool SLbool
Definition: SL.h:175
string SLstring
Definition: SL.h:158
int SLint
Definition: SL.h:170
std::map< SLstring, SLAnimPlayback * > SLMAnimPlayback
vector< SLAnimSkeleton * > SLVSkeleton
std::map< SLstring, SLAnimation * > SLMAnimation
Definition: SLAnimation.h:85
vector< SLJoint * > SLVJoint
Definition: SLJoint.h:58
vector< SLMat4f > SLVMat4f
Definition: SLMat4.h:1585
SLAnimManager is the central class for all animation handling.
Definition: SLAnimManager.h:27
Manages the playback of an SLAnimation.
SLAnimSkeleton keeps track of a skeletons joints and animations.
SLint numJoints() const
const SLVec3f & maxOS()
SLbool changed() const
SLMAnimPlayback _animPlaybacks
map of animation playbacks for this skeleton
void addAnimation(SLAnimation *anim)
SLJoint * rootJoint()
void getJointMatrices(SLVMat4f &jointWM)
SLVec3f _minOS
min point in os for this skeleton (attribute for skeleton instance)
SLAnimPlayback * animPlayback(const SLstring &name)
SLJoint * _rootJoint
pointer to the root joint of skeleton
void loadAnimation(const SLstring &file)
const SLVJoint & joints() const
SLbool updateAnimations(SLfloat elapsedTimeSec)
SLbool _changed
did this skeleton change this frame (attribute for skeleton instance)
SLbool _minMaxOutOfDate
dirty flag aabb rebuild
SLint numAnimations() const
SLMAnimation _animations
map of animations for this skeleton
SLVec3f _maxOS
max point in os for this skeleton (attribute for skeleton instance)
SLMAnimation animations()
SLJoint * createJoint(SLuint id)
SLAnimation * createAnimation(SLAnimManager &aniMan, const SLstring &name, SLfloat duration)
void rootJoint(SLJoint *joint)
SLJoint * getJoint(SLuint id)
SLVJoint _joints
joint vector for fast access and index to joint mapping
const SLVec3f & minOS()
void changed(SLbool changed)
SLAnimation is the base container for all animation data.
Definition: SLAnimation.h:33
Specialized SLNode that represents a single joint (or bone) in a skeleton.
Definition: SLJoint.h:27
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69