| Flutter Impeller |

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

`#include <animation_player.h>`

## Public Member Functions
| AnimationPlayer ()
| ~AnimationPlayer ()
| AnimationPlayer (AnimationPlayer &&)
AnimationPlayer & | operator= (AnimationPlayer &&)
AnimationClip * | AddAnimation (const std::shared_ptr< Animation > &animation, Node *bind_target)
AnimationClip * | GetClip (const std::string &name) const
void | Update ()
| Advanced all clips and updates animated properties in the scene. More...

## Detailed Description

Definition at line 25 of file animation_player.h.

## Constructor & Destructor Documentation

## ◆ AnimationPlayer() [1/2]

impeller::scene::AnimationPlayer::AnimationPlayer | ( |  | ) |
| default

## ◆ ~AnimationPlayer()

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

## ◆ AnimationPlayer() [2/2]

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

## Member Function Documentation

## ◆ AddAnimation()

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

Definition at line 23 of file animation_player.cc.

25 {
26 if (!animation) {
27 VALIDATION_LOG << "Cannot add null animation.";
28 return nullptr;
29 }
30
31 AnimationClip clip(animation, bind_target);
32
33 // Record all of the unique default transforms that this AnimationClip
34 // will mutate.
35 for (const auto& binding : clip.bindings_) {
36 auto decomp = binding.node->GetLocalTransform().Decompose();
37 if (!decomp.has_value()) {
38 continue;
39 }
40 target_transforms_.insert(
41 {binding.node, AnimationTransforms{.bind_pose = decomp.value()}});
42 }
43
44 auto result = clips_.insert({animation->GetName(), std::move(clip)});
45 return &result.first->second;
46 }

References impeller::scene::AnimationTransforms::bind_pose, and VALIDATION_LOG.

## ◆ GetClip()

AnimationClip * impeller::scene::AnimationPlayer::GetClip | ( | const std::string & | name | ) | const

Definition at line 48 of file animation_player.cc.

48 {
49 auto result = clips_.find(name);
50 if (result == clips_.end()) {
51 return nullptr;
52 }
53 return const_cast<AnimationClip*>(&result->second);
54 }

## ◆ operator=()

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

## ◆ Update()

void impeller::scene::AnimationPlayer::Update | ( |  | ) |

Advanced all clips and updates animated properties in the scene.

Definition at line 56 of file animation_player.cc.

56 {
57 if (!previous_time_.has_value()) {
58 previous_time_ = Clock::now();
59 }
60 auto new_time = Clock::now();
61 auto delta_time = new_time - previous_time_.value();
62 previous_time_ = new_time;
63
64 // Reset the animated pose state.
65 for (auto& [node, transforms] : target_transforms_) {
66 transforms.animated_pose = transforms.bind_pose;
67 }
68
69 // Compute a weight multiplier for normalizing the animation.
70 Scalar total_weight = 0;
71 for (auto& [_, clip] : clips_) {
72 total_weight += clip.GetWeight();
73 }
74 Scalar weight_multiplier = total_weight > 1 ? 1 / total_weight : 1;
75
76 // Update and apply all clips to the animation pose state.
77 for (auto& [_, clip] : clips_) {
78 clip.Advance(delta_time);
79 clip.ApplyToBindings(target_transforms_, weight_multiplier);
80 }
81
82 // Apply the animated pose to the bound joints.
83 for (auto& [node, transforms] : target_transforms_) {
84 node->SetLocalTransform(Matrix(transforms.animated_pose));
85 }
86 }

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

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

impeller::Scalar
float Scalar
Definition: scalar.h:15
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60