About Store Forum Documentation Contact
Donations:
327$/mo



Post Reply 
[RESOLVED] Looped animations
Author Message
aceio76 Offline
Silver Supporter

Post: #1
[RESOLVED] Looped animations
Guys, what would you recommend to be the best way to handle playing an animation that is looped, and played for xx number of seconds. Once the xx number of seconds is done, stop the looped animation.

Using void Chr::playAnimation(Str anim) will only play the animation once, as you may already know. I can create a new method in the Chr object that will keep adding the animation in the motions list up to xx number of seconds, but that seems to be messy as I'd have to find the animation length and track the completion of the animation so I can add it again. I'm new to this part of the code and I wanted to see if anyone has enough experience in this and can provide pointers.

Thanks,

It looks like I can use Bool updateAuto(Flt blend_in_speed, Flt blend_out_speed, Flt time_speed=1); to check if the animation is done and, while tracking time duration, can keep playing the same animation. This of course is going to be a separate method. I will give this a shot.

www.thinkplaystudios.com
(This post was last modified: 12-21-2011 04:26 AM by aceio76.)
12-19-2011 04:21 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Fab4 Offline
Member

Post: #2
RE: Looped animations
If you open the animation with model editor you can toggle it to looped animation.
Model Editor -> Animation
Animation-> Toggle Looping
If the animation is set to loop and the time variable is bigger than the animation length it will repeat automatically
[edit]
sry I think i missunderstood you.
why dont you just add a if-function that sets the time variable to a maximum valume as soon as it reaches this value.
Following exapmle: animationlenght is 1.5 seconds and you want to run it five times 1.5*5 = 7.5

Code:
if(time_anim>7.5)time_anim=7.5;

you just have to use time_anim as your animation variable
(This post was last modified: 12-19-2011 02:44 PM by Fab4.)
12-19-2011 08:56 AM
Find all posts by this user Quote this message in a reply
aceio76 Offline
Silver Supporter

Post: #3
RE: Looped animations
I've actually extended the struct Motion, and override the Bool updateAuto(Flt blend_in_speed, Flt blend_out_speed, Flt time_speed=1) function where it has a time stamp of when the animation is suppose to end. I haven't had the chance to test it, I will let you know.

As per your example, I cannot use that approach since the designer won't know how long an animation is. He will just plug in settings as text. But he will know that he will want the animation to play xx seconds.

www.thinkplaystudios.com
12-19-2011 11:40 PM
Visit this user's website Find all posts by this user Quote this message in a reply
aceio76 Offline
Silver Supporter

Post: #4
RE: Looped animations
So extending Motion.cpp will do the job. This way, all I need to do is tell it how long to play the animation, it is take the current time and add the length I desire, and continue playing the animation until I reach the desired time. I don't need to worry about playing an animation file with loop setting turned on, this will just keep playing the animation with blending. Of course playing an animation that is loop friendly is always a good thing, but with this approach, I can take any animation and interrupt it in the middle of the animation and still get blended fairly well.

Code:
STRUCT(Gesture , Motion)
//{
   Flt stoptime;  // play animation until stop time (in real-time)

   Motion& set(CSkeleton &cskel, C Str &animation, C Flt playlen=0)
   {
      clear(); stoptime=0;
      skel_anim=cskel.findSkelAnim(animation);
      if(skel_anim) stoptime=Time.realTime()+playlen;
      return T;
   }
   virtual Bool updateAuto(Flt blend_in_speed, Flt blend_out_speed, Flt time_speed=1)
   {
      if(!is() || !stoptime) return false; // gesture has been cleared

      Bool notdone=true;
      if(time < skel_anim->length()) // if not finished
      {
         blend+=blend_in_speed*Time.d(); // blend in
         if(blend>=1) // if fully blended
         {
            blend     =1;
            time_prev =time;
            time_delta=time_speed*Time.d();
            time     +=time_delta;
         }
      } else // if finished
      {
         blend-=blend_out_speed*Time.d(); // blend out
         if(blend<=0) // if blended out
         {
            blend    =0;
            notdone=false;    // finished animation
         }
      }
      if(Time.realTime()>=stoptime) // reached the stop time
      {
         clear();
         stoptime=0;
         return false; // gesture complete
      } else                        // play time still remaining
      {
         if(!notdone)                   // reset animation time to play again
         {
            time     =0;
            blend    =0;
            time_prev=time_delta=0;
         }
      }
      return true; // continuing animation
   }

private:
   Flt time_prev, time_delta;
};

www.thinkplaystudios.com
(This post was last modified: 12-21-2011 06:32 AM by aceio76.)
12-21-2011 04:26 AM
Visit this user's website Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #5
RE: [RESOLVED] Looped animations
Thanks for sharing your implementation.
12-21-2011 06:24 AM
Find all posts by this user Quote this message in a reply
aceio76 Offline
Silver Supporter

Post: #6
RE: [RESOLVED] Looped animations
I'd do it more often but oftentimes to do this sort of thing right, you have to go thru different sections and post it as code, and I'm always impatient to do so.

www.thinkplaystudios.com
12-21-2011 06:28 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply