Hi Joseph,
The animation can be created with Reader3ds library.
For the most simple way to read a 3ds file and play its animation use the following code:
Reader3ds newReader3ds;
newReader3ds = new Reader3ds();
newReader3ds.UseModelTransforms = true; // this will change only transformations when animating and not the object positions
newReader3ds.ReadFile("c:\\models\\simple_animation.3ds");
for (int frameNo=0; frameNo<newReader3ds.FramesCount; frameNo++)
{
newReader3ds.GetFrame(frameNo, Viewport1);
System.Threading.Thread.Sleep(100); // app. 10 frames per second
}
The ReadFile method reads the 3ds file. The GetFrame method shows the frameNo on the Viewport1 (a Viewport3D defined in the XAML).
Note that it is also possible to show non-integer frames - for example:
GetFrame(0.5, Viewport1)
will show the 3D objects that are between the 1st (frameNo=0) and 2nd frame (frameNo=1) - a linear interpolation is used to show the frames in between the defined frames. This way it is possible to show much smoother animation as when only the frames defined in 3ds file would be used.
If you need to play animations from different 3ds files, I would advice you to read the all the 3ds files into their own Reader3ds instances before playing the animation. After all the 3ds file are read, use the previous code to show the desired frames - switch the Reader3ds instance when needed.
The previous code is only a very simple way to play animation.
I would advice you to use the CompositionTarget.Rendering event - it is called on each WPF rendering pass (each WPF frame). In the event handler the GetFrame method should be called based on the current time and the time difference from the previously displayed frame. To play animation in this way there is already an Animator3ds helper class in Reader3ds library. The following code shows how to use it:
private Reader3ds _newReader3ds;
void StartAnimation()
{
_newReader3ds= new Reader3ds();
_newReader3ds.Animator.AnimationDuration = new TimeSpan(0, 0, 10); // 10 seconds
// _newReader3ds.Animator.ModelFramesPerSecond = 10; // instead of AnimationDuration it is possible to define how many 3ds frames per second are played
_newReader3ds.Animator.AutoRepeat = true;
_newReader3ds.Animator.AutoReverse = false;
_newReader3ds.ReadFile("c:\\models\\simple_animation.3ds", Viewport1);
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 more information please use the Animator sample that comes with the Reader3ds library. There is also a help file with additional documentation available.
Note that getting animation information is available only in Reader3ds Pro version (not in basic).
If you have any more questions, please ask.
Best regards,
Andrej