Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f28d200

Browse files
authored
Revert "[Impeller Scene] Change how property resolution works to fix Animation blending; add mutation log to nodes; enable backface culling; add vertex color contribution back to meshes (#38766)"
This reverts commit 2b024cb.
1 parent a512ceb commit f28d200

22 files changed

+93
-416
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,6 @@ ORIGIN: ../../../flutter/impeller/scene/animation/animation_clip.cc + ../../../f
16411641
ORIGIN: ../../../flutter/impeller/scene/animation/animation_clip.h + ../../../flutter/LICENSE
16421642
ORIGIN: ../../../flutter/impeller/scene/animation/animation_player.cc + ../../../flutter/LICENSE
16431643
ORIGIN: ../../../flutter/impeller/scene/animation/animation_player.h + ../../../flutter/LICENSE
1644-
ORIGIN: ../../../flutter/impeller/scene/animation/animation_transforms.h + ../../../flutter/LICENSE
16451644
ORIGIN: ../../../flutter/impeller/scene/animation/property_resolver.cc + ../../../flutter/LICENSE
16461645
ORIGIN: ../../../flutter/impeller/scene/animation/property_resolver.h + ../../../flutter/LICENSE
16471646
ORIGIN: ../../../flutter/impeller/scene/camera.cc + ../../../flutter/LICENSE
@@ -4122,7 +4121,6 @@ FILE: ../../../flutter/impeller/scene/animation/animation_clip.cc
41224121
FILE: ../../../flutter/impeller/scene/animation/animation_clip.h
41234122
FILE: ../../../flutter/impeller/scene/animation/animation_player.cc
41244123
FILE: ../../../flutter/impeller/scene/animation/animation_player.h
4125-
FILE: ../../../flutter/impeller/scene/animation/animation_transforms.h
41264124
FILE: ../../../flutter/impeller/scene/animation/property_resolver.cc
41274125
FILE: ../../../flutter/impeller/scene/animation/property_resolver.h
41284126
FILE: ../../../flutter/impeller/scene/camera.cc

impeller/geometry/quaternion.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ struct Quaternion {
4545
return {x * m, y * m, z * m, w * m};
4646
}
4747

48-
Quaternion Invert() const { return {-x, -y, -z, w}; }
49-
5048
Quaternion Slerp(const Quaternion& to, double time) const;
5149

5250
Quaternion operator*(const Quaternion& o) const {

impeller/scene/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ impeller_component("scene") {
1212
"animation/animation_clip.h",
1313
"animation/animation_player.cc",
1414
"animation/animation_player.h",
15-
"animation/animation_transforms.h",
1615
"animation/property_resolver.cc",
1716
"animation/property_resolver.h",
1817
"camera.cc",

impeller/scene/animation/animation_clip.cc

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Scalar AnimationClip::GetWeight() const {
6767
}
6868

6969
void AnimationClip::SetWeight(Scalar weight) {
70-
weight_ = std::max(0.0f, weight);
70+
weight_ = weight;
7171
}
7272

7373
SecondsF AnimationClip::GetPlaybackTime() const {
@@ -110,16 +110,9 @@ void AnimationClip::Advance(SecondsF delta_time) {
110110
}
111111
}
112112

113-
void AnimationClip::ApplyToBindings(
114-
std::unordered_map<Node*, AnimationTransforms>& transform_decomps,
115-
Scalar weight_multiplier) const {
113+
void AnimationClip::ApplyToBindings() const {
116114
for (auto& binding : bindings_) {
117-
auto transforms = transform_decomps.find(binding.node);
118-
if (transforms == transform_decomps.end()) {
119-
continue;
120-
}
121-
binding.channel.resolver->Apply(transforms->second, playback_time_,
122-
weight_ * weight_multiplier);
115+
binding.channel.resolver->Apply(*binding.node, playback_time_, weight_);
123116
}
124117
}
125118

impeller/scene/animation/animation_clip.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include "flutter/fml/macros.h"
1111
#include "impeller/scene/animation/animation.h"
12-
#include "impeller/scene/animation/animation_transforms.h"
1312

1413
namespace impeller {
1514
namespace scene {
@@ -61,9 +60,7 @@ class AnimationClip final {
6160
void Advance(SecondsF delta_time);
6261

6362
/// @brief Applies the animation to all binded properties in the scene.
64-
void ApplyToBindings(
65-
std::unordered_map<Node*, AnimationTransforms>& transform_decomps,
66-
Scalar weight_multiplier) const;
63+
void ApplyToBindings() const;
6764

6865
private:
6966
void BindToTarget(Node* node);

impeller/scene/animation/animation_player.cc

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "impeller/scene/animation/animation_player.h"
66

77
#include <memory>
8-
#include <unordered_map>
98

109
#include "flutter/fml/time/time_point.h"
1110
#include "impeller/base/timing.h"
@@ -20,37 +19,20 @@ AnimationPlayer::~AnimationPlayer() = default;
2019
AnimationPlayer::AnimationPlayer(AnimationPlayer&&) = default;
2120
AnimationPlayer& AnimationPlayer::operator=(AnimationPlayer&&) = default;
2221

23-
AnimationClip* AnimationPlayer::AddAnimation(
24-
const std::shared_ptr<Animation>& animation,
22+
AnimationClip& AnimationPlayer::AddAnimation(
23+
std::shared_ptr<Animation> animation,
2524
Node* bind_target) {
26-
if (!animation) {
27-
VALIDATION_LOG << "Cannot add null animation.";
28-
return nullptr;
29-
}
30-
31-
AnimationClip clip(animation, bind_target);
25+
AnimationClip clip(std::move(animation), bind_target);
3226

3327
// Record all of the unique default transforms that this AnimationClip
3428
// will mutate.
3529
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()}});
30+
default_target_transforms_.insert(
31+
{binding.node, binding.node->GetLocalTransform()});
4232
}
4333

44-
auto result = clips_.insert({animation->GetName(), std::move(clip)});
45-
return &result.first->second;
46-
}
47-
48-
AnimationClip* AnimationPlayer::GetClip(const std::string& name) const {
49-
auto result = clips_.find(name);
50-
if (result == clips_.end()) {
51-
return nullptr;
52-
}
53-
return const_cast<AnimationClip*>(&result->second);
34+
clips_.push_back(std::move(clip));
35+
return clips_.back();
5436
}
5537

5638
void AnimationPlayer::Update() {
@@ -61,27 +43,18 @@ void AnimationPlayer::Update() {
6143
auto delta_time = new_time - previous_time_.value();
6244
previous_time_ = new_time;
6345

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;
46+
Reset();
7547

76-
// Update and apply all clips to the animation pose state.
77-
for (auto& [_, clip] : clips_) {
48+
// Update and apply all clips.
49+
for (auto& clip : clips_) {
7850
clip.Advance(delta_time);
79-
clip.ApplyToBindings(target_transforms_, weight_multiplier);
51+
clip.ApplyToBindings();
8052
}
53+
}
8154

82-
// Apply the animated pose to the bound joints.
83-
for (auto& [node, transforms] : target_transforms_) {
84-
node->SetLocalTransform(Matrix(transforms.animated_pose));
55+
void AnimationPlayer::Reset() {
56+
for (auto& [node, transform] : default_target_transforms_) {
57+
node->SetLocalTransform(Matrix());
8558
}
8659
}
8760

impeller/scene/animation/animation_player.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44

55
#pragma once
66

7-
#include <map>
87
#include <memory>
98
#include <optional>
9+
#include <unordered_map>
1010
#include <vector>
1111

1212
#include "flutter/fml/hash_combine.h"
1313
#include "flutter/fml/macros.h"
1414
#include "flutter/fml/time/time_delta.h"
1515
#include "impeller/base/timing.h"
1616
#include "impeller/geometry/matrix.h"
17-
#include "impeller/geometry/matrix_decomposition.h"
1817
#include "impeller/scene/animation/animation_clip.h"
1918

2019
namespace impeller {
@@ -30,18 +29,19 @@ class AnimationPlayer final {
3029
AnimationPlayer(AnimationPlayer&&);
3130
AnimationPlayer& operator=(AnimationPlayer&&);
3231

33-
AnimationClip* AddAnimation(const std::shared_ptr<Animation>& animation,
32+
AnimationClip& AddAnimation(std::shared_ptr<Animation> animation,
3433
Node* bind_target);
3534

36-
AnimationClip* GetClip(const std::string& name) const;
37-
3835
/// @brief Advanced all clips and updates animated properties in the scene.
3936
void Update();
4037

38+
/// @brief Reset all bound animation target transforms.
39+
void Reset();
40+
4141
private:
42-
std::unordered_map<Node*, AnimationTransforms> target_transforms_;
42+
std::unordered_map<Node*, Matrix> default_target_transforms_;
4343

44-
std::map<std::string, AnimationClip> clips_;
44+
std::vector<AnimationClip> clips_;
4545

4646
std::optional<TimePoint> previous_time_;
4747

impeller/scene/animation/animation_transforms.h

Lines changed: 0 additions & 18 deletions
This file was deleted.

impeller/scene/animation/property_resolver.cc

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <iterator>
99
#include <memory>
1010

11-
#include "impeller/geometry/matrix_decomposition.h"
1211
#include "impeller/geometry/point.h"
1312
#include "impeller/scene/node.h"
1413

@@ -79,7 +78,7 @@ TranslationTimelineResolver::TranslationTimelineResolver() = default;
7978

8079
TranslationTimelineResolver::~TranslationTimelineResolver() = default;
8180

82-
void TranslationTimelineResolver::Apply(AnimationTransforms& target,
81+
void TranslationTimelineResolver::Apply(Node& target,
8382
SecondsF time,
8483
Scalar weight) {
8584
if (values_.empty()) {
@@ -90,16 +89,15 @@ void TranslationTimelineResolver::Apply(AnimationTransforms& target,
9089
if (key.lerp < 1) {
9190
value = values_[key.index - 1].Lerp(value, key.lerp);
9291
}
93-
94-
target.animated_pose.translation +=
95-
(value - target.bind_pose.translation) * weight;
92+
target.SetLocalTransform(target.GetLocalTransform() *
93+
Matrix::MakeTranslation(value * weight));
9694
}
9795

9896
RotationTimelineResolver::RotationTimelineResolver() = default;
9997

10098
RotationTimelineResolver::~RotationTimelineResolver() = default;
10199

102-
void RotationTimelineResolver::Apply(AnimationTransforms& target,
100+
void RotationTimelineResolver::Apply(Node& target,
103101
SecondsF time,
104102
Scalar weight) {
105103
if (values_.empty()) {
@@ -110,19 +108,15 @@ void RotationTimelineResolver::Apply(AnimationTransforms& target,
110108
if (key.lerp < 1) {
111109
value = values_[key.index - 1].Slerp(value, key.lerp);
112110
}
113-
114-
target.animated_pose.rotation =
115-
target.animated_pose.rotation *
116-
Quaternion().Slerp(target.bind_pose.rotation.Invert() * value, weight);
111+
target.SetLocalTransform(target.GetLocalTransform() *
112+
Matrix::MakeRotation(value * weight));
117113
}
118114

119115
ScaleTimelineResolver::ScaleTimelineResolver() = default;
120116

121117
ScaleTimelineResolver::~ScaleTimelineResolver() = default;
122118

123-
void ScaleTimelineResolver::Apply(AnimationTransforms& target,
124-
SecondsF time,
125-
Scalar weight) {
119+
void ScaleTimelineResolver::Apply(Node& target, SecondsF time, Scalar weight) {
126120
if (values_.empty()) {
127121
return;
128122
}
@@ -131,9 +125,8 @@ void ScaleTimelineResolver::Apply(AnimationTransforms& target,
131125
if (key.lerp < 1) {
132126
value = values_[key.index - 1].Lerp(value, key.lerp);
133127
}
134-
135-
target.animated_pose.scale *=
136-
Vector3(1, 1, 1).Lerp(value / target.bind_pose.scale, weight);
128+
target.SetLocalTransform(target.GetLocalTransform() *
129+
Matrix::MakeScale(value * weight));
137130
}
138131

139132
} // namespace scene

impeller/scene/animation/property_resolver.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
#include "flutter/fml/hash_combine.h"
1212
#include "flutter/fml/macros.h"
1313
#include "impeller/base/timing.h"
14-
#include "impeller/geometry/matrix_decomposition.h"
1514
#include "impeller/geometry/quaternion.h"
1615
#include "impeller/geometry/scalar.h"
1716
#include "impeller/geometry/vector.h"
18-
#include "impeller/scene/animation/animation_transforms.h"
1917

2018
namespace impeller {
2119
namespace scene {
@@ -48,9 +46,7 @@ class PropertyResolver {
4846
/// many different PropertyResolvers prior to rendering. For example,
4947
/// an AnimationPlayer may blend multiple Animations together by
5048
/// applying several AnimationClips.
51-
virtual void Apply(AnimationTransforms& target,
52-
SecondsF time,
53-
Scalar weight) = 0;
49+
virtual void Apply(Node& target, SecondsF time, Scalar weight) = 0;
5450
};
5551

5652
class TimelineResolver : public PropertyResolver {
@@ -78,9 +74,7 @@ class TranslationTimelineResolver final : public TimelineResolver {
7874
~TranslationTimelineResolver();
7975

8076
// |Resolver|
81-
void Apply(AnimationTransforms& target,
82-
SecondsF time,
83-
Scalar weight) override;
77+
void Apply(Node& target, SecondsF time, Scalar weight) override;
8478

8579
private:
8680
TranslationTimelineResolver();
@@ -97,9 +91,7 @@ class RotationTimelineResolver final : public TimelineResolver {
9791
~RotationTimelineResolver();
9892

9993
// |Resolver|
100-
void Apply(AnimationTransforms& target,
101-
SecondsF time,
102-
Scalar weight) override;
94+
void Apply(Node& target, SecondsF time, Scalar weight) override;
10395

10496
private:
10597
RotationTimelineResolver();
@@ -116,9 +108,7 @@ class ScaleTimelineResolver final : public TimelineResolver {
116108
~ScaleTimelineResolver();
117109

118110
// |Resolver|
119-
void Apply(AnimationTransforms& target,
120-
SecondsF time,
121-
Scalar weight) override;
111+
void Apply(Node& target, SecondsF time, Scalar weight) override;
122112

123113
private:
124114
ScaleTimelineResolver();

0 commit comments

Comments
 (0)