Start animation from specific frame
#1
Hello

How to start the animation from the specific frame?
I tried next:

assimpAnimationController.StopAnimation();
assimpAnimationController.GoToFrame(frame);
assimpAnimationController.StartAnimation();
// animation starts from first frame

But it always animates from the first frame
Pause/Resume also doesn't work as I wish
Thanks
#2
Good question. Currently there is no easy way to do that.

But you can derive your own class from AssimpAnimationController and then override the GetFrameNumber to provide a custom frame number based on the animation time. This allows you to add an offset to the frame number. The following code shows an example:


Code:
public class MyAnimationController : AssimpAnimationController
{
    public double FrameNumberOffset { get; set; }

    public MyAnimationController(AssimpWpfImporter assimpWpfImporter)
        : base(assimpWpfImporter)
    {
    }

    public override double GetFrameNumber(double animationTimeInSeconds)
    {
        double frameNumber = base.GetFrameNumber(animationTimeInSeconds);

        frameNumber = (frameNumber + FrameNumberOffset) % LastFrameNumber;

        return frameNumber;
    }
}

// then start animation by:
_assimpAnimationController.FrameNumberOffset = startFrameNumber;
_assimpAnimationController.StartAnimation();



To provide an easier way to support that case in the future I have added an overload to the StartAnimation method that takes the start frame number as a parameter. This will be available in the next version.
Andrej Benedik
#3
Thank you!
In general, it works, but if the animation has been paused, then you need to call the StopAnimation () method before StartAnimation ();

In another case, a frame will jump.

Code:
if (_assimpAnimationController.IsAnimationPaused)
{
    // Have to stop for starting from required frame
    _assimpAnimationController.StopAnimation();
    Debug.WriteLine(_assimpAnimationController.CurrentFrameNumber);
    Debug.WriteLine(AnimationSlider.Value);
    _assimpAnimationController.FrameNumberOffset = AnimationSlider.Value;
}
  


Forum Jump:


Users browsing this thread:
1 Guest(s)