19 : animation_(
std::move(animation)) {
20 BindToTarget(bind_target);
46 Seek(SecondsF::zero());
58 return playback_time_scale_;
62 playback_time_scale_ = playback_speed;
74 return playback_time_;
78 playback_time_ =
std::clamp(
time, SecondsF::zero(), animation_->GetEndTime());
82 if (!playing_ || delta_time <= SecondsF::zero()) {
85 delta_time *= playback_time_scale_;
86 playback_time_ += delta_time;
90 auto end_time = animation_->GetEndTime();
91 if (end_time == SecondsF::zero()) {
92 playback_time_ = SecondsF::zero();
96 (playback_time_ < SecondsF::zero() || playback_time_ > end_time)) {
100 playback_time_ =
std::clamp(playback_time_, SecondsF::zero(), end_time);
101 }
else if ( playback_time_ > end_time) {
105 }
else if ( playback_time_ < SecondsF::zero()) {
114 std::unordered_map<Node*, AnimationTransforms>& transform_decomps,
115 Scalar weight_multiplier)
const {
116 for (
auto& binding : bindings_) {
117 auto transforms = transform_decomps.find(binding.node);
118 if (transforms == transform_decomps.end()) {
121 binding.channel.resolver->Apply(transforms->second, playback_time_,
122 weight_ * weight_multiplier);
126void AnimationClip::BindToTarget(
Node* node) {
127 const auto& channels = animation_->GetChannels();
129 bindings_.reserve(channels.size());
131 for (
const auto& channel : channels) {
132 Node* channel_target;
133 if (channel.bind_target.node_name == node->
GetName()) {
134 channel_target = node;
137 channel_target =
result.get();
142 ChannelBinding{.channel = channel, .node = channel_target});
static unsigned clamp(SkFixed fx, int max)
void SetPlaybackTimeScale(Scalar playback_speed)
Sets the animation playback speed. Negative values make the clip play in reverse.
void SetPlaying(bool playing)
void SetWeight(Scalar weight)
void ApplyToBindings(std::unordered_map< Node *, AnimationTransforms > &transform_decomps, Scalar weight_multiplier) const
Applies the animation to all binded properties in the scene.
Scalar GetPlaybackTimeScale() const
AnimationClip(std::shared_ptr< Animation > animation, Node *bind_target)
SecondsF GetPlaybackTime() const
Get the current playback time of the animation.
void Advance(SecondsF delta_time)
Advance the animation by delta_time seconds. Negative delta_time values do nothing.
AnimationClip & operator=(AnimationClip &&)
void Seek(SecondsF time)
Move the animation to the specified time. The given time is clamped to the animation's playback range...
void SetLoop(bool looping)
const std::string & GetName() const
std::shared_ptr< Node > FindChildByName(const std::string &name, bool exclude_animation_players=false) const
static float max(float r, float g, float b)
std::chrono::duration< float > SecondsF
SIN Vec< N, float > abs(const Vec< N, float > &x)
static double time(int loops, Benchmark *bench, Target *target)