SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLAnimManager Class Reference

SLAnimManager is the central class for all animation handling. More...

#include <SLAnimManager.h>

Public Member Functions

 ~SLAnimManager ()
 destructor More...
 
void addSkeleton (SLAnimSkeleton *skel)
 Add a skeleton to the skeleton vector. More...
 
void addNodeAnimation (SLAnimation *anim)
 
SLAnimationcreateNodeAnimation (SLfloat duration)
 
SLAnimationcreateNodeAnimation (const SLstring &name, SLfloat duration)
 
SLAnimationcreateNodeAnimation (const SLstring &name, SLfloat duration, SLbool enabled, SLEasingCurve easing, SLAnimLooping looping)
 
SLbool hasNodeAnimations ()
 
SLVSkeletonskeletons ()
 
SLMAnimationanimationNamesMap ()
 
SLMAnimPlaybackanimPlaybackNamesMap ()
 
SLVstringanimationNames ()
 
SLVAnimPlaybackanimPlaybacks ()
 
SLAnimPlaybackanimPlaybackByName (const SLstring &name)
 Returns the playback of a node animation or skeleton by name if it exists. More...
 
SLAnimPlaybackanimPlaybackByIndex (SLuint ix)
 
SLAnimPlaybackanimPlaybacksBack ()
 
SLbool update (SLfloat elapsedTimeSec)
 Advances the time of all enabled animation plays. More...
 
void drawVisuals (SLSceneView *sv)
 Draws the animation visualizations. More...
 
void clear ()
 Clears and deletes all node animations and skeletons. More...
 

Private Attributes

SLVSkeleton _skeletons
 all skeleton instances More...
 
SLMAnimation _animationNamesMap
 map name to animation More...
 
SLMAnimPlayback _animPlaybackNamesMap
 map name to animation playbacks More...
 
SLVstring _animationNames
 vector with all animation names More...
 
SLVAnimPlayback _animPlaybacks
 vector with all animation playbacks More...
 

Detailed Description

SLAnimManager is the central class for all animation handling.

A single instance of this class is hold by the SLScene instance and is responsible for updating the enabled animations and to manage their life time. If keeps a list of all skeletons and node animations and also holds a list of all animation playback controllers. The update of all animations is done before the rendering of all SLSceneView in SLScene::updateIfAllViewsGotPainted by calling the SLAnimManager::update.

Definition at line 26 of file SLAnimManager.h.

Constructor & Destructor Documentation

◆ ~SLAnimManager()

SLAnimManager::~SLAnimManager ( )

destructor

Definition at line 14 of file SLAnimManager.cpp.

15 {
16  clear();
17 }
void clear()
Clears and deletes all node animations and skeletons.

Member Function Documentation

◆ addNodeAnimation()

void SLAnimManager::addNodeAnimation ( SLAnimation anim)

◆ addSkeleton()

void SLAnimManager::addSkeleton ( SLAnimSkeleton skel)

Add a skeleton to the skeleton vector.

Definition at line 40 of file SLAnimManager.cpp.

41 {
42  _skeletons.push_back(skel);
43 }
SLVSkeleton _skeletons
all skeleton instances
Definition: SLAnimManager.h:57

◆ animationNames()

SLVstring& SLAnimManager::animationNames ( )
inline

Definition at line 46 of file SLAnimManager.h.

46 { return _animationNames; }
SLVstring _animationNames
vector with all animation names
Definition: SLAnimManager.h:60

◆ animationNamesMap()

SLMAnimation& SLAnimManager::animationNamesMap ( )
inline

Definition at line 44 of file SLAnimManager.h.

44 { return _animationNamesMap; }
SLMAnimation _animationNamesMap
map name to animation
Definition: SLAnimManager.h:58

◆ animPlaybackByIndex()

SLAnimPlayback* SLAnimManager::animPlaybackByIndex ( SLuint  ix)
inline

Definition at line 49 of file SLAnimManager.h.

49 { return _animPlaybacks[ix]; }
SLVAnimPlayback _animPlaybacks
vector with all animation playbacks
Definition: SLAnimManager.h:61

◆ animPlaybackByName()

SLAnimPlayback * SLAnimManager::animPlaybackByName ( const SLstring name)

Returns the playback of a node animation or skeleton by name if it exists.

Definition at line 104 of file SLAnimManager.cpp.

105 {
106  for(auto playback : _animPlaybacks)
107  {
108  if (playback->parentAnimation()->name() == name)
109  return playback;
110  }
111 
112 
113  SL_WARN_MSG("*** SLAnimManager::animPlaybackByName: animation not found ***");
114  return nullptr;
115 }
#define SL_WARN_MSG(message)
Definition: SL.h:241

◆ animPlaybackNamesMap()

SLMAnimPlayback& SLAnimManager::animPlaybackNamesMap ( )
inline

Definition at line 45 of file SLAnimManager.h.

45 { return _animPlaybackNamesMap; }
SLMAnimPlayback _animPlaybackNamesMap
map name to animation playbacks
Definition: SLAnimManager.h:59

◆ animPlaybacks()

SLVAnimPlayback& SLAnimManager::animPlaybacks ( )
inline

Definition at line 47 of file SLAnimManager.h.

47 { return _animPlaybacks; }

◆ animPlaybacksBack()

SLAnimPlayback* SLAnimManager::animPlaybacksBack ( )
inline

Definition at line 50 of file SLAnimManager.h.

50 { return _animPlaybacks.back(); }

◆ clear()

void SLAnimManager::clear ( )

Clears and deletes all node animations and skeletons.

Definition at line 21 of file SLAnimManager.cpp.

22 {
23  for (const auto& it : _animationNamesMap)
24  delete it.second;
25  _animationNamesMap.clear();
26 
27  for (const auto& it : _animPlaybackNamesMap)
28  delete it.second;
29  _animPlaybackNamesMap.clear();
30 
31  for (auto* skeleton : _skeletons)
32  delete skeleton;
33  _skeletons.clear();
34 
35  _animationNames.clear();
36  _animPlaybacks.clear();
37 }

◆ createNodeAnimation() [1/3]

SLAnimation * SLAnimManager::createNodeAnimation ( const SLstring name,
SLfloat  duration 
)

Creates a new node animation

Parameters
namethe animation name
durationlength of the animation

Definition at line 84 of file SLAnimManager.cpp.

86 {
87  assert(_animationNamesMap.find(name) == _animationNamesMap.end() &&
88  "node animation with same name already exists!");
89 
90  SLAnimation* anim = new SLAnimation(name, duration);
91  _animationNamesMap[name] = anim;
92 
93  SLAnimPlayback* playback = new SLAnimPlayback(anim);
94  _animPlaybackNamesMap[name] = playback;
95 
96  // Add node animation to the combined vector
97  _animationNames.push_back(name);
98  _animPlaybacks.push_back(playback);
99 
100  return anim;
101 }
Manages the playback of an SLAnimation.
SLAnimation is the base container for all animation data.
Definition: SLAnimation.h:33

◆ createNodeAnimation() [2/3]

SLAnimation * SLAnimManager::createNodeAnimation ( const SLstring name,
SLfloat  duration,
SLbool  enabled,
SLEasingCurve  easing,
SLAnimLooping  looping 
)

Creates new SLAnimation istance for node animations. It will already create and set parameters for the respective SLAnimPlayback.

Definition at line 66 of file SLAnimManager.cpp.

71 {
72  SLAnimation* anim = createNodeAnimation(name, duration);
73  SLAnimPlayback* playback = animPlaybackByName(name);
74  playback->enabled(enabled);
75  playback->easing(easing);
76  playback->loop(looping);
77  return anim;
78 }
SLAnimPlayback * animPlaybackByName(const SLstring &name)
Returns the playback of a node animation or skeleton by name if it exists.
SLAnimation * createNodeAnimation(SLfloat duration)
SLbool enabled() const
SLAnimLooping loop() const
SLEasingCurve easing() const

◆ createNodeAnimation() [3/3]

SLAnimation * SLAnimManager::createNodeAnimation ( SLfloat  duration)

Creates a new node animation

Parameters
durationlength of the animation

Definition at line 48 of file SLAnimManager.cpp.

49 {
50  SLuint index = (SLuint)_animationNamesMap.size();
51  std::ostringstream oss;
52 
53  do
54  {
55  oss.clear();
56  oss << "Node_" << index;
57  index++;
58  } while (_animationNamesMap.find(oss.str()) != _animationNamesMap.end());
59 
60  return createNodeAnimation(oss.str(), duration);
61 }
unsigned int SLuint
Definition: SL.h:171

◆ drawVisuals()

void SLAnimManager::drawVisuals ( SLSceneView sv)

Draws the animation visualizations.

Definition at line 153 of file SLAnimManager.cpp.

154 {
155  for (const auto& it : _animPlaybackNamesMap)
156  {
157  SLAnimPlayback* playback = it.second;
158  playback->parentAnimation()->drawNodeVisuals(sv);
159  }
160 
161  // skeletons are drawn from within SLSceneView per node
162 }
SLAnimation * parentAnimation()
void drawNodeVisuals(SLSceneView *sv)
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69

◆ hasNodeAnimations()

SLbool SLAnimManager::hasNodeAnimations ( )
inline

Definition at line 41 of file SLAnimManager.h.

41 { return (_animationNamesMap.size() > 0); }

◆ skeletons()

SLVSkeleton& SLAnimManager::skeletons ( )
inline

Definition at line 43 of file SLAnimManager.h.

43 { return _skeletons; }

◆ update()

SLbool SLAnimManager::update ( SLfloat  elapsedTimeSec)

Advances the time of all enabled animation plays.

Definition at line 118 of file SLAnimManager.cpp.

119 {
120  // reset the dirty flag on all skeletons
121  for (auto* skeleton : _skeletons)
122  skeleton->changed(false);
123 
124  SLbool updated = false;
125 
126  // advance time for node animations and apply them
127  // @todo currently we can't blend between normal node animations because we
128  // reset them per animation playback. so the last playback that affects a
129  // node will have its animation applied.
130  // We need to save the playback differently if we want to blend them.
131 
132  for (const auto& it : _animPlaybackNamesMap)
133  {
134  SLAnimPlayback* playback = it.second;
135  if (playback->enabled())
136  {
137  playback->parentAnimation()->resetNodes();
138  playback->advanceTime(elapsedTimeSec);
139  playback->parentAnimation()->apply(playback->localTime(),
140  playback->weight());
141  updated = true;
142  }
143  }
144 
145  // update the skeletons separately
146  for (auto* skeleton : _skeletons)
147  updated |= skeleton->updateAnimations(elapsedTimeSec);
148 
149  return updated;
150 }
bool SLbool
Definition: SL.h:175
SLfloat localTime() const
void advanceTime(SLfloat delta)
SLfloat weight() const
void resetNodes()
void apply(SLfloat time, SLfloat weight=1.0f, SLfloat scale=1.0f)

Member Data Documentation

◆ _animationNames

SLVstring SLAnimManager::_animationNames
private

vector with all animation names

Definition at line 60 of file SLAnimManager.h.

◆ _animationNamesMap

SLMAnimation SLAnimManager::_animationNamesMap
private

map name to animation

Definition at line 58 of file SLAnimManager.h.

◆ _animPlaybackNamesMap

SLMAnimPlayback SLAnimManager::_animPlaybackNamesMap
private

map name to animation playbacks

Definition at line 59 of file SLAnimManager.h.

◆ _animPlaybacks

SLVAnimPlayback SLAnimManager::_animPlaybacks
private

vector with all animation playbacks

Definition at line 61 of file SLAnimManager.h.

◆ _skeletons

SLVSkeleton SLAnimManager::_skeletons
private

all skeleton instances

Definition at line 57 of file SLAnimManager.h.


The documentation for this class was generated from the following files: