Getting animation from Maya to DirectX app

Started by
6 comments, last by dmtuan 9 years, 1 month ago

Hi everyone, I am starting a project with SharpDX and I have been over some basics. Yes, SharpDX, since this is experiment, that I am doing for my Master's thesis.

I've just finished loading a static 3D model (modeled in Maya) to my game. Now I am thinking about how to get an animation created in Maya. I am not asking for code or anything specific. I was just thinking some advices to get me the right idea, how the whole process looks like.

What format do I use to export model and animation data from Maya (or any other modelling software)? How is it different to load animation data from loading static mesh data? Or how do those animation data look like, for that matter?

Advertisement

I think the best format to use would be the FBX format by Autodesk. It is supported by many modelling tools and you can use the provided SDK to import the model into your application. Unfortunately, they doesn't offer any bindings for .NET so you need to either write a wrapper yourself or maybe you are lucky some someone else already did this.

The loading process depends on the type of animation you use. You can store the whole mesh for each frame, so you basically store n meshes per file and you have to chose the right one before rendering or you use skeletal animation. Skeletal animation reduces the file size by creating a hierarchical bone structure and assigning each vertex to one or multiple bones. For each frame, you now only have to store the transformation for each bone. This approach is a little bit more complicated as you have to calculate and apply the correct transformation for each vertex, but there are many tutorials and examples on this topic out there.

I think the best format to use would be the FBX format by Autodesk. It is supported by many modelling tools and you can use the provided SDK to import the model into your application. Unfortunately, they doesn't offer any bindings for .NET so you need to either write a wrapper yourself or maybe you are lucky some someone else already did this.

The loading process depends on the type of animation you use. You can store the whole mesh for each frame, so you basically store n meshes per file and you have to chose the right one before rendering or you use skeletal animation. Skeletal animation reduces the file size by creating a hierarchical bone structure and assigning each vertex to one or multiple bones. For each frame, you now only have to store the transformation for each bone. This approach is a little bit more complicated as you have to calculate and apply the correct transformation for each vertex, but there are many tutorials and examples on this topic out there.

Thank you for your reply. I have already considered your 1st approach.. I've tried to export an animation as n meshes in n .obj files. Thou this is a naive solution. I wanna be able to use the same animation for more models. It seems I will have to look into the skeletal animation problem. Do u have any particular tutorial on your mind for this matter?

Have a look at theese:

http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/how-to-work-with-fbx-sdk-r3582

http://mathinfo.univ-reims.fr/image/dxMesh/extra/d3dx_skinnedmesh.pdf

The first one is a tutorial on how to load the data using the FBX SDK. The second one is more animation oriented, but it uses the .X file format and the corresponding functions from the DirectX 9 SDK. However, the general concept should be the same.


I've tried to export an animation as n meshes ... I wanna be able to use the same animation for more models.

Without referring to a specific modeling program or the export format, think in terms of meshes and animations being separate data sets and you're on your way to a solution.

Animations are arrays of data, providing time related transformations (commonly a rotation and a translation). Each bone (joint, reference frame, pick-one) has a related set of animation data, used to orient the bone with respect to its parent. There is nothing in that data that requires information about a particular mesh to which it will be applied.

A mesh is an array of vertices (normally indexed), each vertex having an associated set of 1 or more bone indices, and a set of bone weights (1 weight per bone). Those bone indices and weights are what relate the mesh data to the animation data.

Various export formats may or may not support exporting only animation data. However, you can, for instance, import a mesh and animations from a single file, and save the animation data only to file in a format convenient for later loading. That's a common approach.

That is, it's quite common to import mesh and animation data (perhaps with routines supporting import from several modeling formats), convert/rearrange the data in a way that's more efficient for loading and rendering by your rendering app, and store that data in a custom format to file.

Your rendering app can then load a model from one file, and animations from another. The primary consideration is that the mesh vertex bone indices/weights must have a correct correspondence to the arrangement of bones in the animation file.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

FBX SDK is really flexible solution but it has really complicated API. For a start I suggest you to go with Assimp and *.DAE files. I'm suggesting this because FBX SDK is developed to serve as a complete scene file used for storing "WorkInProgess" data, rather than completely modeled scene. I suggest the ASSIMP library in order to skip all those UNIMPORTANT details that are introduced by FBX SDK.

The over all thing: There are a lot of different methods for animating a 3d scene/object.

If you look closely to 3DSMax/Maya you will notice that each mesh is attached to a 'node'. Each node represents a location in space.

Those nodes are connected to form a 'hierarchy tree'. Each node may or may not have attached meshes to it. If a mesh is attached to a node that means that you must draw the attached mesh at the location the node.

So lets imagine that we have a scene with 2 similar boxes and a sphere. Our scene would look like this.

Contained meshes : Box, Sphere.

RootNode(Transform:Z, no meshes are attached to that node)

|

|\------Body(Transform:TBody, AttachedMeshes Sphere)

|

|\------Feet0(Transform:TFeet0, AttachedMeshes Box)

|

\------Feet1(Transform: TFeet1, AttachedMeshes Box)

Basically all nodes are children of The root node.

so the 1st methods is to animate the transforms . if you imagine that our scene is a very simple character (feets are represented by those 2 boxes, and the sphere is the body of the character).

So if we want to create a waking animation we must add KEY FRAMES to the transform parameter. A KEY Frame is just a pair of (time-in-some-metric(second, ticks milisecond, value)

If we want to represent the bouncy motion of the body the key-frames will would look something like this :

Transform TBody :

Frame0( 0 second, translation(0, 0, 0) , rotation (...) scaling(...) ....)

Frame1( 0.5 second, translation(0, 5, 0) , rotation (...) scaling(...) ....)

Frame2( 1 second, translation(0, 0, 0) , rotation (...) scaling(...) ....)

// a similar thing for the legs ....

Only thing that we must do to play the animation is to Evaluate the transform for the current time of the animation, draw the mashes using the newly evaluated transforms, advance the time and repeat process.

The second type of animation that is closely related to the Node based animation is called Skeletal animation. This animation type works by deforming the mesh. Basically the artist creates few nodes that will be used to (called bones) deform the mesh. Each bone has a list of vertices/indices that are influenced by that bone. In order to evaluate that transform use again just need to revaluate the node transforms an then manually modify the vertex positions for each frame. You can search the web for more details around that method. Feel free to ask if you need more help.

Keep in mind that there are much more methods for animating a model/scene but this one is the most commonly used method.

Thank you all for you response. I'll be sure to study up! Thanks again

Oh, by the way, does any of you come across this book:

https://www.packtpub.com/game-development/direct3d-rendering-cookbook

It's called Direct3D Rendering Cookbook. From the book reviews, that I read, it seems to be a good studying material for learning Direct3D11 and SharpDX. There should also be a chapter about skeletal animation. I am asking because I am thinking about buying the book, but I don't know if it's worth those 40 Euro.

This topic is closed to new replies.

Advertisement