| Flutter Impeller |

Classes | Public Member Functions | List of all members
impeller::scene::AnimationClip Class Referencefinal

`#include <animation_clip.h>`

## Public Member Functions
| AnimationClip (std::shared_ptr< Animation > animation, Node *bind_target)
| ~AnimationClip ()
| AnimationClip (AnimationClip &&)
AnimationClip & | operator= (AnimationClip &&)
bool | IsPlaying () const
void | SetPlaying (bool playing)
void | Play ()
void | Pause ()
void | Stop ()
bool | GetLoop () const
void | SetLoop (bool looping)
Scalar | GetPlaybackTimeScale () const
void | SetPlaybackTimeScale (Scalar playback_speed)
| Sets the animation playback speed. Negative values make the clip play in reverse. More...
Scalar | GetWeight () const
void | SetWeight (Scalar weight)
SecondsF | GetPlaybackTime () const
| Get the current playback time of the animation. More...
void | Seek (SecondsF time)
| Move the animation to the specified time. The given `time` is clamped to the animation's playback range. More...
void | Advance (SecondsF delta_time)
| Advance the animation by `delta_time` seconds. Negative `delta_time` values do nothing. More...
void | ApplyToBindings (std::unordered_map< Node *, AnimationTransforms > &transform_decomps, Scalar weight_multiplier) const
| Applies the animation to all binded properties in the scene. More...

## Detailed Description

Definition at line 22 of file animation_clip.h.

## Constructor & Destructor Documentation

## ◆ AnimationClip() [1/2]

impeller::scene::AnimationClip::AnimationClip | ( | std::shared_ptr< Animation > | animation,
|  | Node * | bind_target
| ) |  |

Definition at line 17 of file animation_clip.cc.

19 : animation_(std::move(animation)) {
20 BindToTarget(bind_target);
21 }

## ◆ ~AnimationClip()

impeller::scene::AnimationClip::~AnimationClip | ( |  | ) |
| default

## ◆ AnimationClip() [2/2]

impeller::scene::AnimationClip::AnimationClip | ( | AnimationClip && |  | ) |
| default

## Member Function Documentation

## ◆ Advance()

void impeller::scene::AnimationClip::Advance | ( | SecondsF | delta_time | ) |

Advance the animation by `delta_time` seconds. Negative `delta_time` values do nothing.

Handle looping behavior.

Definition at line 81 of file animation_clip.cc.

81 {
82 if (!playing_ || delta_time <= SecondsF::zero()) {
83 return;
84 }
85 delta_time *= playback_time_scale_;
86 playback_time_ += delta_time;
87
88 /// Handle looping behavior.
89
90 auto end_time = animation_->GetEndTime();
91 if (end_time == SecondsF::zero()) {
92 playback_time_ = SecondsF::zero();
93 return;
94 }
95 if (!loop_ &&
96 (playback_time_ < SecondsF::zero() || playback_time_ > end_time)) {
97 // If looping is disabled, clamp to the end (or beginning, if playing in
98 // reverse) and pause.
99 Pause();
100 playback_time_ = std::clamp(playback_time_, SecondsF::zero(), end_time);
101 } else if (/* loop && */ playback_time_ > end_time) {
102 // If looping is enabled and we ran off the end, loop to the beginning.
103 playback_time_ =
104 SecondsF(std::fmod(std::abs(playback_time_.count()), end_time.count()));
105 } else if (/* loop && */ playback_time_ < SecondsF::zero()) {
106 // If looping is enabled and we ran off the beginning, loop to the end.
107 playback_time_ =
108 end_time -
109 SecondsF(std::fmod(std::abs(playback_time_.count()), end_time.count()));
110 }
111 }

References Pause().

## ◆ ApplyToBindings()

void impeller::scene::AnimationClip::ApplyToBindings | ( | std::unordered_map< Node *, AnimationTransforms > & | transform_decomps,
|  | Scalar | weight_multiplier
| ) |  | const

Applies the animation to all binded properties in the scene.

Definition at line 113 of file animation_clip.cc.

115 {
116 for (auto& binding : bindings_) {
117 auto transforms = transform_decomps.find(binding.node);
118 if (transforms == transform_decomps.end()) {
119 continue;
120 }
121 binding.channel.resolver->Apply(transforms->second, playback_time_,
122 weight_ * weight_multiplier);
123 }
124 }

## ◆ GetLoop()

bool impeller::scene::AnimationClip::GetLoop | ( |  | ) | const

Definition at line 49 of file animation_clip.cc.

49 {
50 return loop_;
51 }

## ◆ GetPlaybackTime()

SecondsF impeller::scene::AnimationClip::GetPlaybackTime | ( |  | ) | const

Get the current playback time of the animation.

Definition at line 73 of file animation_clip.cc.

73 {
74 return playback_time_;
75 }

## ◆ GetPlaybackTimeScale()

Scalar impeller::scene::AnimationClip::GetPlaybackTimeScale | ( |  | ) | const

Definition at line 57 of file animation_clip.cc.

57 {
58 return playback_time_scale_;
59 }

## ◆ GetWeight()

Scalar impeller::scene::AnimationClip::GetWeight | ( |  | ) | const

Definition at line 65 of file animation_clip.cc.

65 {
66 return weight_;
67 }

## ◆ IsPlaying()

bool impeller::scene::AnimationClip::IsPlaying | ( |  | ) | const

Definition at line 28 of file animation_clip.cc.

28 {
29 return playing_;
30 }

## ◆ operator=()

AnimationClip & impeller::scene::AnimationClip::operator= | ( | AnimationClip && |  | ) |
| default

## ◆ Pause()

void impeller::scene::AnimationClip::Pause | ( |  | ) |

Definition at line 40 of file animation_clip.cc.

40 {
41 SetPlaying(false);
42 }

References SetPlaying().

Referenced by Advance(), and impeller::scene::testing::TEST_P().

## ◆ Play()

void impeller::scene::AnimationClip::Play | ( |  | ) |

Definition at line 36 of file animation_clip.cc.

36 {
37 SetPlaying(true);
38 }

References SetPlaying().

Referenced by impeller::scene::testing::TEST_P().

## ◆ Seek()

void impeller::scene::AnimationClip::Seek | ( | SecondsF | time | ) |

Move the animation to the specified time. The given `time` is clamped to the animation's playback range.

Definition at line 77 of file animation_clip.cc.

77 {
78 playback_time_ = std::clamp(time, SecondsF::zero(), animation_->GetEndTime());
79 }

Referenced by impeller::scene::Node::Render(), and Stop().

## ◆ SetLoop()

void impeller::scene::AnimationClip::SetLoop | ( | bool | looping | ) |

Definition at line 53 of file animation_clip.cc.

53 {
54 loop_ = looping;
55 }

Referenced by impeller::scene::Node::Render(), and impeller::scene::testing::TEST_P().

## ◆ SetPlaybackTimeScale()

void impeller::scene::AnimationClip::SetPlaybackTimeScale | ( | Scalar | playback_speed | ) |

Sets the animation playback speed. Negative values make the clip play in reverse.

Definition at line 61 of file animation_clip.cc.

61 {
62 playback_time_scale_ = playback_speed;
63 }

Referenced by impeller::scene::Node::Render(), and impeller::scene::testing::TEST_P().

## ◆ SetPlaying()

void impeller::scene::AnimationClip::SetPlaying | ( | bool | playing | ) |

Definition at line 32 of file animation_clip.cc.

32 {
33 playing_ = playing;
34 }

Referenced by Pause(), Play(), impeller::scene::Node::Render(), and Stop().

## ◆ SetWeight()

void impeller::scene::AnimationClip::SetWeight | ( | Scalar | weight | ) |

Definition at line 69 of file animation_clip.cc.

69 {
70 weight_ = std::max(0.0f, weight);
71 }

Referenced by impeller::scene::Node::Render(), and impeller::scene::testing::TEST_P().

## ◆ Stop()

void impeller::scene::AnimationClip::Stop | ( |  | ) |

Definition at line 44 of file animation_clip.cc.

44 {
45 SetPlaying(false);
46 Seek(SecondsF::zero());
47 }

References Seek(), and SetPlaying().

Referenced by impeller::scene::testing::TEST_P().

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

- impeller/scene/animation/animation_clip.h
- impeller/scene/animation/animation_clip.cc

impeller::SecondsF
std::chrono::duration< float > SecondsF
Definition: timing.h:13
impeller::scene::AnimationClip::Pause
void Pause()
Definition: animation_clip.cc:40
impeller::scene::AnimationClip::Seek
void Seek(SecondsF time)
Move the animation to the specified time. The given time is clamped to the animation's playback range...
Definition: animation_clip.cc:77
impeller::scene::AnimationClip::SetPlaying
void SetPlaying(bool playing)
Definition: animation_clip.cc:32