File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,4 +62,27 @@ namespace our {
6262 animator.play (&animIt->second , clip.loop , clip.speed * speedScale);
6363 }
6464
65+ void AnimationComponent::playDuration (const std::string& clipName, float duration) {
66+ if (!model) {
67+ std::cerr << " \033 [31mCannot play animation: model is not set\033 [0m" << std::endl;
68+ return ;
69+ }
70+
71+ auto clipIt = clips.find (clipName);
72+ if (clipIt == clips.end ()) {
73+ std::cerr << " \033 [31mClip not found: " << clipName << " \033 [0m" << std::endl;
74+ return ;
75+ }
76+ AnimationClip& clip = clipIt->second ;
77+ auto animIt = model->animations .find (clip.clip );
78+ if (animIt == model->animations .end ()) {
79+ std::cerr << " \033 [31mAnimation not found in model: " << clip.clip << " \033 [0m" << std::endl;
80+ return ;
81+ }
82+ float originalSpeed = clip.speed ;
83+ float animDuration = animIt->second .duration / animIt->second .ticksPerSecond ;
84+ float speedScale = animDuration > 0 .0f ? animDuration / duration : 1 .0f ;
85+ animator.play (&animIt->second , false , originalSpeed * speedScale);
86+ }
87+
6588} // namespace our
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ namespace our {
2727 void deserialize (const nlohmann::json& data) override ;
2828
2929 void play (const std::string& clipName, float speedScale = 1 .0f );
30+ void playDuration (const std::string& clipName, float duration);
3031 };
3132
3233} // namespace our
You can’t perform that action at this time.
0 commit comments