How to load Maya Models and Animation?

Started by
4 comments, last by Buckeye 10 years ago

Hi all,

I am currently making a 3d game, and I have managed to make a program that run on OpenGL and C++. Everything that is needed to make a windows pop out has been done, I also have a .obj loader. However, I realized that I have no idea how to load animations. I did some research online, but there were a lot of things I didn't understand...some said use MD5 files, some said FBX files, and some even just did animation with the codes using the OBJ models.

Can anyone tell what kind of file would be easy to use for a beginner like me? And just to emphasize, I am really a beginner. I learn C++ and OpenGL as modules in my school for the past two years, and all I have been doing is 2D games most of the time. This is my third time doing a 3D project, but on a bigger scale. The previous projects are just simulations that have nothing but non-moving models and "hard-coded" objects. Even the environment was done in OpenGL codes.

Advertisement

Skeletal animation != easy !

Some thoughts considering formats:

obj:

Very easy text format, but it does not support animation data.

FBX & Collada:

Both formats are interchange formats for different modelling tools, games etc. They both contain skeletal bone animation data, but although contain a lot of stuff not really necessary for games. FBX is from autodesk, but is the better, more simple format and better supported format. Collada is a open format, but it is harder to get warm with it, and support is laking somewhat.

MD5:

Is a game animation format used in id-tech engines (a long time back). Not as powerful as FBX or Collada, but have some good support including libs to read them.

The simplest way would be to use MD5, the best way would be FBX or Collada and a converter to transform it into your own format. But nevertheless, skeletal animaton is really not trivial to implement in your engine.

Although consider assimp, an open source assert lib, it might be useful.

Thanks for the reply Ashaman73!

Though I would like to ask, what did you mean by "a converter to transform it into your own format"?

The part that I don't get is the transformation part, just to clarify...do you mean get a converter software or something?

And "my own format" meaning ACSII or something?

Appreciate your help btw.

Take a look at this topic. That link's question actually has nothing to do with DirectX and is applicable to most applications that may use more than one import file format. Even if you only import from one format, the approach still provides flexibility in revising your code.

The approach of having a file importer program separate from a data saver program is particularly applicable if you're not sure how you're going to use data for animations. Write a file importer and load in all the data that format has to offer, and stuff it into a custom structure of your design. The data converter/saver program will load data from that custom structure and convert it to your animation program's needs, the best being a binary file with data in just the form needed by the mesh builder part of your program, and by the animation controller part of your program, which should be separate processes/objects.

It may seem like a pain in the rear-end having all those separate pieces. But, if you have a file importer that works, you can (and will be) revising the data converter/saver without having to change working code. It will likely be a little iterative - you may want to change the custom structure from time to time - but you'll thank yourself if you take the time now to create a flexible process.

Once you get it working, the entire back end of the process never needs to be revised. Note: obj format doesn't support animation, but can still store it in the same structure and you just create meshes from it. Also, the better you separate all the tasks from one another, you'll later be able to write other programs using some or all of the pieces without having to worry about importing data again! With a binary file on disk, whose structure you know, you can write in other APIs (DirectX, etc.) with previously converted files.

file importer (MD3) ---> custom data structure (maybe ASCII on disk) ---> convert/save (binary) to disk ---> quick load and mesh creation / animation creation.

file importer (Maya) ---> custom data structure (maybe ASCII on disk) ---> convert/save (binary) to disk ---> quick load and mesh creation / animation creation.

file importer (obj) ---> custom data structure (maybe on ASCII disk) ---> convert/save to (binary) disk ---> quick load and mesh creation / animation creation.

If you're not comfortable passing the data structure in memory from one program to another, write a routine that takes a pointer to the data structure and writes the data in that structure configuration to disk. That routine can then be copy/pasted into each file importer. If you're just starting out doing this sort of thing, write the custom structure data to disk in ASCII, so you can open it in Notepad (or even in your IDE - Visual Studio, etc.) as you'll likely be debugging the import process. Remember, the time to load/save/convert, etc., for this process is all outside your realtime animation program, so, if it takes a couple seconds to read this file or that, and a few more seconds to save it, load it again, etc., there's no impact on your animation program.

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.


Though I would like to ask, what did you mean by "a converter to transform it into your own format"?

The common problem is, that you have an internal format to render your models (eg. a simple array to store your vertices etc.) and an external tool to edit your content (modelling tool). Here are some way to transform the modelling tool representation to your internal tool representation:

1. write a custom exporter

You can write a custom exporter for your modelling tool to export it to a file format, which suits your internal requirements best (e.g. write all vertices as a comma separated list of floats). This has some charm, but has lot of disadvantages, therefor I would never sugguest to write your own exporter as hobby/indie developer (too time consuming). The reasons are, that the exporter is often bound to a single tool, written in a tool specific language (which you need to learn) and with an API which might change with a newer tool version.

2. write a custom importer

This is the other way around, export content to a common format (obj,fbx,collada) and write an importer to this format. This works great for small projects, but have some disadvantages too: You need to map the format structure to your own, you need too load and parse often really large files, which is memory/disc consuming and slow. For larger projects this could be a showstopper.

3. write a converter between a common format and your internal file format

This is the best solution in my opinion. As input you take a common file format and maps it to your own fileformat, much like the importer in 2, but instead of using it directly, you save it as file much like an exporter in 1 . This way you avoid the tool dependency from 1 and the performance hit from 2.

smile.png


3. write a converter between a common format and your internal file format

Just to make it clear, that "internal file format" isn't what your game application will read in. It's an intermediate file, which is designed to hold just about anything Maya or MD3 can export that you ever think you'll need, which is then converted by an independent routine to (e.g.) a binary file that's used by the game application.

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.

This topic is closed to new replies.

Advertisement