Wavefront *.obj loader in C++

Josh Vega
  • Wavefront *.obj loader in C++ Josh Vega

    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.

    Thanks

    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!

  • 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.

  • 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.

  • 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.

Tags
c++ opengl animation sdl
Related questions and answers
  • I'm creating an FPS game. I'm writing my own game engine. So far all the backend stuff is going great. I'd like to support md2 as the native file format for 3D Objects, but I also want to use skeletal meshes. Does anyone know if the md2 file format supports skeletal meshes? In-case you need to know, I'm going to use blender as my Mesh creation tool and C++ as my programming language... Thanks... you some help on writing a parser (see bottom of link), but the example doesn't support lighting and texture mapping (the second set of example code allows for animation). Thanks @Neverender

  • The problem is that I'm trying to use my meshes with Bullet Physics for the collision part of my game. When I attempted doing this method with my GLM(model loading library by nate robins) model, I get a segmentation fault in the debug, so I figured that it doesnt like the coordinate variables of the model. If i use blender to export my model as a collision file, what type of file should I use? I have heard of a .bullet exporter, but i dont know hot to integrate this python script into my Blender 2.5 program.

  • Say I develop a game for mobile platform running OpenGL ES 2.0. I have done 2D part, and now I wish to import some 3D objects. The imported 3D objects must contain the following: Vertices positions Normals UVs Texturing information Animation information Collision mesh Maybe some other things... I am aware, that I could and (maybe should) create my own file format that brings these data from..., that will let me import 3d meshes into my game, ready to use? The solution/middleware should be: easy to use easy to port efficient not consuming too much memory with unnecessary things containing all

  • After careful consideration to use middleware, I have decided on creating my own 3d file format format to export meshes from 3D authoring application (Softimage) into my game. I will need to export the following: Vertices Indices Normals UVs Material Information Animation information (no clue, how to import it) Collision mesh Game Properties defined within 3D authoring tool (object... of wasting it on incorrect approaches. I use Softimage as my 3D authoring tool. Target platform is OpenGL ES 2.0 running on mobile devices (iOS, Android). Programming language: C++.

  • I been working in the animation of a 2D platformer game in C++/SDL/OpenGL, and my team and I reach the point where we need to establish that every animation of the player (Walking, Running, etc..) needs a different framerate for our concept, but I use as a guideline the Game Programming All In One as a example for the smooth animation, and in the book recommend have variables that limits...; int frameCount; And in the function that animates I do the following, much like the MoveX in Sprite: int Animation::animate() { if( oldTime + frameRate > SDL_GetTicks() ) { return -1

  • I have created a model in Blender. Now i want to read that 3D model in my c++ program. I figured that a model can be exported to various file formats e.g. .obj, .3ds or COLLADA and then can be read... which I don't want to use in my program. And the remaining tutorials use md2 which is not supported by Blender. So can anyone guide me which file format to use for exporting 3D model and how to load that in my OpenGL program? Also how can I animate that model? Is it possible to add extra effects like tone mapping after it has been loaded in the c++ program using OpenGL? if yes then how? P.S. I am

  • I'm currently writing a 3D game in C++ with OpenGL and I'm coming to the part where to load 3D models in. Therefore I'm looking for popular file formats and techniques to display static meshs and render animated meshs. I've already found quite a large number of possible formats and techniques, like keyframe animations, skeletal animation, MD2 up to MD5, 3DS, X, Collada etc. pp. For simplicity I'd like to use a format (and technique) that allows both, namely static and animated meshs. So my question is if one format is suitable for that task and which one you'd suggest. And to clarify

  • . The libraries that I would need are ones that fit the criteria of making a simple 3d game(online): 3D Graphics(including a model loader of some sort(if it works with blender that would be even...) Also if there are any other libraries that work well with these I would like to know. Any answers would be very helpful. and details would be even nicer =) Thanks in advance. -Molma ...Lately I have been working on a game that i plan to make online. I have used different libraries to make this game as far as i could, but I feel that I should rethink on how Im sertting this game up

  • want to have fun, and c# is fun ;) SDL. Quite frankly, I'd still need to port to all those different SDL implementations. And I don't like OpenGL style programming, it's just plain ugly. And it needs...? I prefer: C#, Actionscript. I don't mind using c++ if the toolset is above average, but I highly doubt that there is something out there like that. Please prove me wrong :) So summary: I'd like... don't need 3D, and it is quite ...a lot of work to learn. I also don't like that it is so expensive to use for different platforms and that I can only code for it through scripting. You have to buy each

Data information