Animator3ds Class |
Namespace: Ab3d
public class Animator3ds
The Animator3ds type exposes the following members.
Name | Description | |
---|---|---|
Animator3ds(Reader3ds) |
Constructor
| |
Animator3ds(Reader3ds, Double) |
Constructor
| |
Animator3ds(Reader3ds, TimeSpan) |
Constructor
|
Name | Description | |
---|---|---|
AnimationDuration |
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.
| |
AutoRepeat |
Gets or set if the animation should automatically repeat itself or not.
Default value is true.
| |
AutoReverse |
Gets or sets if animation should go backwards when coming to the last frame or should it start from beginning.
Default value is false.
| |
AverageFramesPerSecond |
Gets the average rendered frames per second. The value is calculated from the data in the last played animation.
| |
LastFrame |
Gets the last rendered frame number
| |
ModelFramesPerSecond |
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
|
Name | Description | |
---|---|---|
DoAnimate |
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.
| |
GoToFrame |
Goes to the frameNo. This method can be called when the animation is running or when it is stopped.
| |
Reset |
Resets the animation and shows the first frame.
| |
Stop |
Stops the animation. After stopping animation can continue from the current frame on - with just calling DoAnimate method.
|
Name | Description | |
---|---|---|
FramesPerSecondUpdated |
Event that can be used to display the current frames per second.
|
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.
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(); }