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