I'm creating a game using OpenGL (via SDL) and C++ (via Visual Studios 2010 Professional). During the game, I will be using 3D character animation. I'd like to use wavefront *.obj files for all the 3D models (with the exception of terrain). The characters will need to have fluent movements (realistic), with as many as 250-500 frames (for walking, running, sprinting, jumping, crouching, crawling, etc.). I'd like to use either md2 or md3, but the 3D modelling/animation tool I'll be using (Blender 3D 2.57) doesn't support either one. The game will only be running on Windows.

What I need is a small yet powerful *.obj loader and parser that supports animation. It must be written in C++ and be usable by SDL.


Alright, after looking at all the file formats that Blender can export to...I've decided to go with 3DS because it produces the smallest file format when I export the default cube. Thanks @Daniel For recommending 3DS!

  • \$\begingroup\$ Have you googled? Libobj comes to mind. \$\endgroup\$ – deceleratedcaviar Jun 4 '11 at 15:54
  • \$\begingroup\$ Are you sure .obj supports animations? \$\endgroup\$ – Christian Rau Jun 4 '11 at 16:02
  • \$\begingroup\$ @Christian Rau: not in the core but you can export every frame of animation as separate .OBJ file. \$\endgroup\$ – Amir Zadeh Jun 7 '11 at 15:48

OBJ does not support animation, for more information read this.

For a compliant OBJ loader, lib-obj comes to mind.

If you want to home brew, and you can ensure the file only contains triangles; no quads etc, parsing an OBJ is arbitrary (its only text!):

        char prefix[10] = {0};
        stream >> prefix;

        switch (prefix[0]) {
            case 'v' : {
                switch (prefix[1]) {
                    case 't' : {} break; // texcoords
                    case 'n' : {} break; // normals
                    default : { // points
                        float x, y, z;
                        stream >> x >> y >> z;
                        // put in a mesh etc
            } break;
            case 'f' : {
                unsigned short a, b, c;
                stream >> a >> b >> c;

                // etc
            } break;
            default : {} // skip

If in doubt, look to the specification.

  • \$\begingroup\$ I would use lib-obj or homebrew one, but I really need the animation. Do you know of a md2 or md3 file exporter for blender 2.57? I'd love to use one of those...! \$\endgroup\$ – jsvcycling Jun 4 '11 at 16:20
  • \$\begingroup\$ Is there any reason for md2 or md3? There are other formats that can support animation. Maybe look at the 3DS format? \$\endgroup\$ – deceleratedcaviar Jun 4 '11 at 16:25
  • \$\begingroup\$ MD2 and MD3 are respected formats and very popular. I've never heard of 3DS and don't know anything about it. I'll look into it...Thanks. \$\endgroup\$ – jsvcycling Jun 4 '11 at 16:35
  • 2
    \$\begingroup\$ @jsvcycling: In which decade do you live? MD2 and MD3 are from the 1990-ies. These days we use formats like OpenCTM or similar. Today a model not just consists of vertex position, normal and texture coordinate. There are vertex groups, bone weights, additional attributes, etc. MD2 and MD3 are simply not up to the job. \$\endgroup\$ – datenwolf Jun 4 '11 at 20:27
  • 1
    \$\begingroup\$ I don't see any mention of it in the specification? Manual key-framing doesn't count. \$\endgroup\$ – deceleratedcaviar Jun 7 '11 at 23:58

Just because Blender offers you an exporter for Wavefront doesn't mean, that the whole animation will be exported as well. Wavefront OBJ doesn't know animation!

On the other hand it's perfectly possible to implement a exporter Add On for md2 / md3, and AFAIK those already exist.

That being said, as I understood it, you intend to store the full mesh for each animation frame. This is a very inefficient way to do animation. A better approach would be to just store keyframes and interpolate between those. Or even better: Implement a mesh deformation system that's compatible with Blender's animation system, or implement your own mesh deformation system for both Blender and your program. Animating simple whole object transformations is easy. Mesh deformations in Blender typically happen through the builtin Armature modifier, but it's perfectly possible to implement a own mesh deformation operator as stand in replacement for the Armature modifier.

ATM I'm developing an export/import Blender Add-On that dumps all the currently loaded data into JSON format; either one big file or a single file for each data block. The main idea is to use it with WebGL (i.e. implementing a WebGL engine that allows to load stuff originally created for the Blender Game Engine). Maybe I can interest you in using JSON for storing model and information.

  • \$\begingroup\$ Yeah, I forgot to mention that I will be using armatures for the animation... \$\endgroup\$ – jsvcycling Jun 4 '11 at 16:12
  • \$\begingroup\$ But where is the relevance between OBJ loader, SDL and Animation? \$\endgroup\$ – deceleratedcaviar Jun 4 '11 at 16:13
  • \$\begingroup\$ hmm...JSON looks pretty good! And it has a lot of different libraries to choose from (in C++)! I might use that... \$\endgroup\$ – jsvcycling Jun 4 '11 at 16:15
  • \$\begingroup\$ Well, I was thinking of doing something like the way mpeg4 videos work, the parts of the models that don't move in the transition from one scene to the next, will be "Copied Over". So if only a finger is moved in say scene 53, the rest of the body from scene 52 will be copied over to scene 53. Does anyone know of a 3D file format that works like this...? \$\endgroup\$ – jsvcycling Jun 4 '11 at 16:18
  • 1
    \$\begingroup\$ @jsvcycling: This kind of mesh replacement animation is very, very inefficient. It requires to constantly copy large amounts of data to GPU memory, wasting a lot of bandwidth. Also the CPU will be busy all the time bookkeeping. What you really should do is implementing a skeletal animation system. Using vertex shaders this is easy enough: Every bone can be described by a quaternion and neutral transformation. The quaternions are set by uniforms; in the shader the bone heirachy is evaluated, yielding a transformation for each bone, which is then applied to vertices with a weight. \$\endgroup\$ – datenwolf Jun 4 '11 at 20:23

Although the .obj specification doesnt support animations natively, by simply augmenting it with a seperate .anm file you can get brilliant boneless animations.

Have a look at:- http://public.sanguinelabs.co.uk/expose/product.php?id=wastudio

This provides a very easy to use tool to create the animations and also provides an open-source model library (for OpenGL) so you can get the animated models working in your project quickly.

Note: I am the developer of Wavefront Animation Studio and libwavefront so feel free to email me if you have any improvements or bugs to report. The software was developed during my time at university because I found it extremely awkward to create and display animations using the complex tools and libraries currently available.


The answer to what you seek is not *.obj because it is pretty much like a bitmap for animation (you can export it with Blender but you have to tell blender to export every frame as a single *.obj file [NOT EFFICIENT IN ANY ASPECTS], like a movie and it's frames). What you really seek is Collada. There is a mesh loader called assimp, and it loads like a million mesh formats (I am using it for my new engine). And what you said about *.3DS is not always true.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.