WPF and 3D animation using 3D Max Frames

260 views
Skip to first unread message

Joseph Moraise

unread,
Jul 27, 2009, 9:27:26 AM7/27/09
to WPF Graphics Site group
hi all,

i want to create an animation by reading / rendering several frames
from different 3D max application files(.3ds). How i can do it or
what could be the best approach ? The ".3ds" format is very older
one , can we read the content from ".fbx" file or from a maya file.
any input in this regard very much appreaciated. Looking forward to
all of your valuable inputs.

With Regards

Joseph Moraise
Message has been deleted

Andrej Benedik

unread,
Jul 28, 2009, 2:58:39 AM7/28/09
to wpf-gr...@googlegroups.com
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

Joseph Moraise

unread,
Jul 29, 2009, 9:04:11 AM7/29/09
to WPF Graphics Site group
Dear Andrej ,

Thanks for the reply. Infact i am evaluating the Reader3ds library for
a project purpose. In the project need a simulation of human
activities. The resolution what i am looking for on this is all
animation part required for this done by 3D Max or Maya. Inside the
application we will read the frames and render in side the window. The
posibility is that according to user interaction there must be some
changes in the animation and this will be decided at runtime. So thats
why i thought of reading frames from different files and rendering it.
Please let me know your input on this. Please tell me one more thing
by using Reader3Ds, can we read animation model from .fbx file of 3D
Max or from a Maya File.

With Regards

Joseph Moraise
> On Mon, Jul 27, 2009 at 3:27 PM, Joseph Moraise <josephmora...@gmail.com>wrote:
>
>
>
>
>
> > hi all,
>
> > i want to create an animation by reading / rendering several frames
> > from different 3D max application files(.3ds). How i can do it  or
> > what could be the best approach ? The ".3ds" format is very older
> > one , can we read the content from ".fbx" file or from a maya file.
> > any input in this regard very much appreaciated. Looking forward to
> > all of your valuable inputs.
>
> > With Regards
>
> > Joseph Moraise- Hide quoted text -
>
> - Show quoted text -

Andrej Benedik

unread,
Jul 29, 2009, 9:14:28 AM7/29/09
to wpf-gr...@googlegroups.com
Hello Joseph,

I think that playing / rendering frames from different 3ds file and showing them on UI should not be problematic.

I am a little bit more afraid of storing animations into 3ds file. As you already mentioned the file format is rather old and therefore it is not possible to store more complex data into it - for example bones animations that are common for animating bodies are not supported. Also morphing is not saved. Only simple animations are supported - objects movements, scales and rotations.

Unfortunately currently only reading 3ds files is supported - no fbx.

I would advice you to check the 3ds file limitations - simply by creating the animation in Max exporting it to 3ds and than importing it again into Max to see what is preserved.

I hope the 3ds file will not be too limited.

However some time ago I have created a code to morph one object from one 3ds file to another - to simulate morphing. But the structure of objects must be the same - so it is possible to create a 3d face save it to the 3ds file and than change the face a little bit with moving vertexes and saving the changed face model into another 3ds file. The code than opens both 3ds file and interpolates the positions between the files. If this could be helpful for you, please let me know and I will send you the code.

Best regards
Andrej
Reply all
Reply to author
Forward
0 new messages