| Flutter Impeller |

Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
impeller::scene::Animation Class Referencefinal

`#include <animation.h>`

## Classes
struct | BindKey
struct | Channel

## Public Types
enum | Property { Property::kTranslation, Property::kRotation, Property::kScale }

## Public Member Functions
| ~Animation ()
const std::string & | GetName () const
const std::vector< Channel > & | GetChannels () const
SecondsF | GetEndTime () const

## Static Public Member Functions
static std::shared_ptr< Animation > | MakeFromFlatbuffer (const fb::Animation &animation, const std::vector< std::shared_ptr< Node >> &scene_nodes)

## Detailed Description

Definition at line 26 of file animation.h.

## Member Enumeration Documentation

## ◆ Property

enum impeller::scene::Animation::Property
| strong

Enumerator
kTranslation |
kRotation |
kScale |

Definition at line 32 of file animation.h.

32 {
33 kTranslation,
34 kRotation,
35 kScale,
36 };

## Constructor & Destructor Documentation

## ◆ ~Animation()

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

## Member Function Documentation

## ◆ GetChannels()

const std::vector< Animation::Channel > & impeller::scene::Animation::GetChannels | ( |  | ) | const

Definition at line 116 of file animation.cc.

116 {
117 return channels_;
118 }

## ◆ GetEndTime()

SecondsF impeller::scene::Animation::GetEndTime | ( |  | ) | const

Definition at line 120 of file animation.cc.

120 {
121 return end_time_;
122 }

## ◆ GetName()

const std::string & impeller::scene::Animation::GetName | ( |  | ) | const

Definition at line 112 of file animation.cc.

112 {
113 return name_;
114 }

## ◆ MakeFromFlatbuffer()

std::shared_ptr< Animation > impeller::scene::Animation::MakeFromFlatbuffer | ( | const fb::Animation & | animation,
|  | const std::vector< std::shared_ptr< Node >> & | scene_nodes
| ) |  |
| static

Definition at line 19 of file animation.cc.

21 {
22 auto result = std::shared_ptr<Animation>(new Animation());
23
24 result->name_ = animation.name()->str();
25 for (auto channel : *animation.channels()) {
26 if (channel->node() < 0 ||
27 static_cast<size_t>(channel->node()) >= scene_nodes.size() ||
28 !channel->timeline()) {
29 continue;
30 }
31
32 Animation::Channel out_channel;
33 out_channel.bind_target.node_name = scene_nodes[channel->node()]->GetName();
34
35 auto* times = channel->timeline();
36 std::vector<Scalar> out_times;
37 out_times.resize(channel->timeline()->size());
38 std::copy(times->begin(), times->end(), out_times.begin());
39
40 // TODO(bdero): Why are the entries in the keyframe value arrays not
41 // contiguous in the flatbuffer? We should be able to get rid
42 // of the subloops below and just memcpy instead.
43 switch (channel->keyframes_type()) {
44 case fb::Keyframes::TranslationKeyframes: {
45 out_channel.bind_target.property = Animation::Property::kTranslation;
46 auto* keyframes = channel->keyframes_as_TranslationKeyframes();
47 if (!keyframes->values()) {
48 continue;
49 }
50 std::vector<Vector3> out_values;
51 out_values.resize(keyframes->values()->size());
52 for (size_t value_i = 0; value_i < keyframes->values()->size();
53 value_i++) {
54 auto val = (*keyframes->values())[value_i];
55 out_values[value_i] = Vector3(val->x(), val->y(), val->z());
56 }
57 out_channel.resolver = PropertyResolver::MakeTranslationTimeline(
58 std::move(out_times), std::move(out_values));
59 break;
60 }
61 case fb::Keyframes::RotationKeyframes: {
62 out_channel.bind_target.property = Animation::Property::kRotation;
63 auto* keyframes = channel->keyframes_as_RotationKeyframes();
64 if (!keyframes->values()) {
65 continue;
66 }
67 std::vector<Quaternion> out_values;
68 out_values.resize(keyframes->values()->size());
69 for (size_t value_i = 0; value_i < keyframes->values()->size();
70 value_i++) {
71 auto val = (*keyframes->values())[value_i];
72 out_values[value_i] =
73 Quaternion(val->x(), val->y(), val->z(), val->w());
74 }
75 out_channel.resolver = PropertyResolver::MakeRotationTimeline(
76 std::move(out_times), std::move(out_values));
77 break;
78 }
79 case fb::Keyframes::ScaleKeyframes: {
80 out_channel.bind_target.property = Animation::Property::kScale;
81 auto* keyframes = channel->keyframes_as_ScaleKeyframes();
82 if (!keyframes->values()) {
83 continue;
84 }
85 std::vector<Vector3> out_values;
86 out_values.resize(keyframes->values()->size());
87 for (size_t value_i = 0; value_i < keyframes->values()->size();
88 value_i++) {
89 auto val = (*keyframes->values())[value_i];
90 out_values[value_i] = Vector3(val->x(), val->y(), val->z());
91 }
92 out_channel.resolver = PropertyResolver::MakeScaleTimeline(
93 std::move(out_times), std::move(out_values));
94 break;
95 }
96 case fb::Keyframes::NONE:
97 continue;
98 }
99
100 result->end_time_ =
101 std::max(result->end_time_, out_channel.resolver->GetEndTime());
102 result->channels_.push_back(std::move(out_channel));
103 }
104
105 return result;
106 }

References impeller::scene::Animation::Channel::bind_target, kRotation, kScale, kTranslation, impeller::scene::PropertyResolver::MakeRotationTimeline(), impeller::scene::PropertyResolver::MakeScaleTimeline(), impeller::scene::PropertyResolver::MakeTranslationTimeline(), impeller::scene::Animation::BindKey::node_name, impeller::scene::Animation::BindKey::property, and impeller::scene::Animation::Channel::resolver.

Referenced by impeller::scene::Node::MakeFromFlatbuffer().

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

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

impeller::scene::PropertyResolver::MakeTranslationTimeline
static std::unique_ptr< TranslationTimelineResolver > MakeTranslationTimeline(std::vector< Scalar > times, std::vector< Vector3 > values)
Definition: property_resolver.cc:19
impeller::scene::Animation::Property::kTranslation
@ kTranslation
impeller::scene::Animation::Property::kScale
@ kScale
impeller::scene::PropertyResolver::MakeScaleTimeline
static std::unique_ptr< ScaleTimelineResolver > MakeScaleTimeline(std::vector< Scalar > times, std::vector< Vector3 > values)
Definition: property_resolver.cc:40
impeller::scene::PropertyResolver::MakeRotationTimeline
static std::unique_ptr< RotationTimelineResolver > MakeRotationTimeline(std::vector< Scalar > times, std::vector< Quaternion > values)
Definition: property_resolver.cc:30
impeller::scene::Animation::Property::kRotation
@ kRotation