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