| Flutter Impeller |

property_resolver.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_SCENE_ANIMATION_PROPERTY_RESOLVER_H_
6 #define FLUTTER_IMPELLER_SCENE_ANIMATION_PROPERTY_RESOLVER_H_
7
8 #include <memory>
9 #include <string>
10 #include <vector>
11
12 #include "flutter/fml/hash_combine.h"
13 #include "flutter/fml/macros.h"
14 #include "impeller/base/timing.h"
15 #include "impeller/geometry/matrix_decomposition.h"
16 #include "impeller/geometry/quaternion.h"
17 #include "impeller/geometry/scalar.h"
18 #include "impeller/geometry/vector.h"
19 #include "impeller/scene/animation/animation_transforms.h"
20
21 namespace impeller {
22 namespace scene {
23
24 class Node;
25 class TranslationTimelineResolver;
26 class RotationTimelineResolver;
27 class ScaleTimelineResolver;
28
29 class PropertyResolver {
30 public:
31 static std::unique_ptr<TranslationTimelineResolver> MakeTranslationTimeline(
32 std::vector<Scalar> times,
33 std::vector<Vector3> values);
34
35 static std::unique_ptr<RotationTimelineResolver> MakeRotationTimeline(
36 std::vector<Scalar> times,
37 std::vector<Quaternion> values);
38
39 static std::unique_ptr<ScaleTimelineResolver> MakeScaleTimeline(
40 std::vector<Scalar> times,
41 std::vector<Vector3> values);
42
43 virtual ~PropertyResolver();
44
45 virtual SecondsF GetEndTime() = 0;
46
47 /// @brief Resolve and apply the property value to a target node. This
48 /// operation is additive; a given node property may be amended by
49 /// many different PropertyResolvers prior to rendering. For example,
50 /// an AnimationPlayer may blend multiple Animations together by
51 /// applying several AnimationClips.
52 virtual void Apply(AnimationTransforms& target,
53 SecondsF time,
54 Scalar weight) = 0;
55 };
56
57 class TimelineResolver : public PropertyResolver {
58 public:
59 virtual ~TimelineResolver();
60
61 // |Resolver|
62 SecondsF GetEndTime();
63
64 protected:
65 struct TimelineKey {
66 /// The index of the closest previous keyframe.
67 size_t index = 0;
68 /// Used to interpolate between the resolved values for `timeline_index - 1`
69 /// and `timeline_index`. The range of this value should always be `0>N>=1`.
70 Scalar lerp = 1;
71 };
72 TimelineKey GetTimelineKey(SecondsF time);
73
74 std::vector<Scalar> times_;
75 };
76
77 class TranslationTimelineResolver final : public TimelineResolver {
78 public:
79 ~TranslationTimelineResolver();
80
81 // |Resolver|
82 void Apply(AnimationTransforms& target,
83 SecondsF time,
84 Scalar weight) override;
85
86 private:
87 TranslationTimelineResolver();
88
89 std::vector<Vector3> values_;
90
91 TranslationTimelineResolver(const TranslationTimelineResolver&) = delete;
92
93 TranslationTimelineResolver& operator=(const TranslationTimelineResolver&) =
94 delete;
95
96 friend PropertyResolver;
97 };
98
99 class RotationTimelineResolver final : public TimelineResolver {
100 public:
101 ~RotationTimelineResolver();
102
103 // |Resolver|
104 void Apply(AnimationTransforms& target,
105 SecondsF time,
106 Scalar weight) override;
107
108 private:
109 RotationTimelineResolver();
110
111 std::vector<Quaternion> values_;
112
113 RotationTimelineResolver(const RotationTimelineResolver&) = delete;
114
115 RotationTimelineResolver& operator=(const RotationTimelineResolver&) = delete;
116
117 friend PropertyResolver;
118 };
119
120 class ScaleTimelineResolver final : public TimelineResolver {
121 public:
122 ~ScaleTimelineResolver();
123
124 // |Resolver|
125 void Apply(AnimationTransforms& target,
126 SecondsF time,
127 Scalar weight) override;
128
129 private:
130 ScaleTimelineResolver();
131
132 std::vector<Vector3> values_;
133
134 ScaleTimelineResolver(const ScaleTimelineResolver&) = delete;
135
136 ScaleTimelineResolver& operator=(const ScaleTimelineResolver&) = delete;
137
138 friend PropertyResolver;
139 };
140
141 } // namespace scene
142 } // namespace impeller
143
144 #endif // FLUTTER_IMPELLER_SCENE_ANIMATION_PROPERTY_RESOLVER_H_
timing.h
impeller::scene::AnimationTransforms
Definition: animation_transforms.h:13
impeller::scene::PropertyResolver::Apply
virtual void Apply(AnimationTransforms &target, SecondsF time, Scalar weight)=0
Resolve and apply the property value to a target node. This operation is additive; a given node prope...
impeller::scene::ScaleTimelineResolver
Definition: property_resolver.h:120
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::scene::TimelineResolver::GetEndTime
SecondsF GetEndTime()
Definition: property_resolver.cc:55
impeller::scene::TimelineResolver::TimelineKey
Definition: property_resolver.h:65
impeller::scene::PropertyResolver::~PropertyResolver
virtual ~PropertyResolver()
quaternion.h
impeller::scene::TimelineResolver::times_
std::vector< Scalar > times_
Definition: property_resolver.h:74
impeller::scene::TimelineResolver::TimelineKey::lerp
Scalar lerp
Definition: property_resolver.h:70
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::RotationTimelineResolver
Definition: property_resolver.h:99
impeller::SecondsF
std::chrono::duration< float > SecondsF
Definition: timing.h:13
impeller::scene::TimelineResolver
Definition: property_resolver.h:57
animation_transforms.h
impeller::scene::TimelineResolver::TimelineKey::index
size_t index
The index of the closest previous keyframe.
Definition: property_resolver.h:67
impeller::scene::TranslationTimelineResolver
Definition: property_resolver.h:77
impeller::scene::RotationTimelineResolver::~RotationTimelineResolver
~RotationTimelineResolver()
impeller::scene::TranslationTimelineResolver::~TranslationTimelineResolver
~TranslationTimelineResolver()
scalar.h
impeller::scene::PropertyResolver::MakeScaleTimeline
static std::unique_ptr< ScaleTimelineResolver > MakeScaleTimeline(std::vector< Scalar > times, std::vector< Vector3 > values)
Definition: property_resolver.cc:40
vector.h
impeller::scene::RotationTimelineResolver::Apply
void Apply(AnimationTransforms &target, SecondsF time, Scalar weight) override
Resolve and apply the property value to a target node. This operation is additive; a given node prope...
Definition: property_resolver.cc:102
impeller::scene::PropertyResolver::GetEndTime
virtual SecondsF GetEndTime()=0
impeller::scene::PropertyResolver::MakeRotationTimeline
static std::unique_ptr< RotationTimelineResolver > MakeRotationTimeline(std::vector< Scalar > times, std::vector< Quaternion > values)
Definition: property_resolver.cc:30
matrix_decomposition.h
impeller::scene::ScaleTimelineResolver::Apply
void Apply(AnimationTransforms &target, SecondsF time, Scalar weight) override
Resolve and apply the property value to a target node. This operation is additive; a given node prope...
Definition: property_resolver.cc:123
impeller::scene::PropertyResolver
Definition: property_resolver.h:29
impeller::scene::TranslationTimelineResolver::Apply
void Apply(AnimationTransforms &target, SecondsF time, Scalar weight) override
Resolve and apply the property value to a target node. This operation is additive; a given node prope...
Definition: property_resolver.cc:82
impeller
Definition: aiks_blur_unittests.cc:20
impeller::scene::TimelineResolver::GetTimelineKey
TimelineKey GetTimelineKey(SecondsF time)
Definition: property_resolver.cc:62
impeller::scene::TimelineResolver::~TimelineResolver
virtual ~TimelineResolver()
impeller::scene::ScaleTimelineResolver::~ScaleTimelineResolver
~ScaleTimelineResolver()