8 #include <unordered_map>
10 #include "flutter/fml/time/time_point.h"
24 const std::shared_ptr<Animation>& animation,
35 for (
const auto& binding : clip.bindings_) {
36 auto decomp = binding.node->GetLocalTransform().Decompose();
37 if (!decomp.has_value()) {
40 target_transforms_.insert(
44 auto result = clips_.insert({animation->GetName(), std::move(clip)});
45 return &result.first->second;
49 auto result = clips_.find(name);
50 if (result == clips_.end()) {
57 if (!previous_time_.has_value()) {
58 previous_time_ = Clock::now();
60 auto new_time = Clock::now();
61 auto delta_time = new_time - previous_time_.value();
62 previous_time_ = new_time;
65 for (
auto& [node, transforms] : target_transforms_) {
66 transforms.animated_pose = transforms.bind_pose;
71 for (
auto& [_, clip] : clips_) {
72 total_weight += clip.GetWeight();
74 Scalar weight_multiplier = total_weight > 1 ? 1 / total_weight : 1;
77 for (
auto& [_, clip] : clips_) {
78 clip.Advance(delta_time);
79 clip.ApplyToBindings(target_transforms_, weight_multiplier);
83 for (
auto& [node, transforms] : target_transforms_) {
84 node->SetLocalTransform(
Matrix(transforms.animated_pose));