Click or drag to resize
Animator3ds Class
Animator3ds is a helper class for playing animations stored in 3ds file
Inheritance Hierarchy
SystemObject
  Ab3dAnimator3ds

Namespace: Ab3d
Assembly: Ab3d.Reader3ds (in Ab3d.Reader3ds.dll) Version: 9.0.5590.1040
Syntax
C#
public class Animator3ds

The Animator3ds type exposes the following members.

Constructors
  NameDescription
Public methodAnimator3ds(Reader3ds)
Constructor
Public methodAnimator3ds(Reader3ds, Double)
Constructor
Public methodAnimator3ds(Reader3ds, TimeSpan)
Constructor
Top
Properties
  NameDescription
Public propertyAnimationDuration
Gets or sets the time in second how long will the whole animation be playing (once from the first to the last frame). Setting this value also changes ModelFramesPerSecond accordingly.
Public propertyAutoRepeat
Gets or set if the animation should automatically repeat itself or not. Default value is true.
Public propertyAutoReverse
Gets or sets if animation should go backwards when coming to the last frame or should it start from beginning. Default value is false.
Public propertyAverageFramesPerSecond
Gets the average rendered frames per second. The value is calculated from the data in the last played animation.
Public propertyLastFrame
Gets the last rendered frame number
Public propertyModelFramesPerSecond
Gets or sets how many 3ds file frames per second are played - faster (bigger value) or slower (smaller value) animation. Setting ModelFramesPerSecond also changes AnimationDuration accordingly. Note that this is not the same as rendered frames per second that means more or less smooth animation. Default value is 10
Top
Methods
  NameDescription
Public methodDoAnimate
The main method that does the animation. This method should be called every time user wants to show the next frame. This method is usually called from a CompositionTarget.Rendering or DispatherTimerevent handler.
Public methodGoToFrame
Goes to the frameNo. This method can be called when the animation is running or when it is stopped.
Public methodReset
Resets the animation and shows the first frame.
Public methodStop
Stops the animation. After stopping animation can continue from the current frame on - with just calling DoAnimate method.
Top
Events
  NameDescription
Public eventFramesPerSecondUpdated
Event that can be used to display the current frames per second.
Top
Remarks

Animator3ds simplifies playing animations from 3ds files by simply setting some animation properties (for example AnimationDuration, AutoRepeat, AutoReverse, etc) and simply calling DoAnimate method each time the new frame should be rendered. In DoAnimate method the frame that is renders is calculated from the time difference between previous and this DoAnimate calls. This way the animation is played according to the set AnimationDuration or ModelFramesPerSecond regardless of the computer on which it is run. That means that on slower computers there would be less frames per seconds rendered, and on faster computer more - but the animation would last the same amount of time.

Because Animator3ds relays on Reader3ds (it is calling its GetFrame(Int32, Viewport3D) method) it must be constructed with an instance of Reader3ds. This can be simplified with using the Animator property on Reader3ds class.

Examples
The following example shows how to use CompositionTarget.Rendering event for creating a frame-base animation with Reader3ds and Animator3ds.
private Reader3ds _newReader3ds;

void StartAnimation()
{
    _newReader3ds= new Reader3ds();
    _newReader3ds.Animator.AutoRepeat = true;
    _newReader3ds.Animator.AutoReverse = false;
    _newReader3ds.Animator.AnimationDuration = new TimeSpan(0, 0, 10); // 10 seconds
    // instead of AnimationDuration it is possible to define how many 3ds frames per second are played
    //_newReader3ds.Animator.ModelFramesPerSecond = 10; 

    _newReader3ds.ReadFile("SampleAnimation.3ds", myViewport);

    CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
}

void EndAnimation()
{
    CompositionTarget.Rendering -= new EventHandler(CompositionTarget_Rendering);
       _newReader3ds.Animator.Stop();
}     

void CompositionTarget_Rendering(object sender, EventArgs e)
{
    _newReader3ds.Animator.DoAnimate();
}
For a full sample see the Player3ds sample.
See Also