3D model format / C++ loader?


lulzfish

Pandora Defense Squad
Joined
Jan 14, 2009
Messages
3,502
Website
troyanonymous.homelinux.com
I'm trying to figure out a good way to connect Blender with my OpenGL programs.

The Wavefront .obj format looks pretty good, and Blender imports and exports it well, but I don't have a loader for it yet.
Does anybody know of a good C++ loader for this format, or of a reason why I should look into a different format?
If I can't find one here or on Google, I'll probably just write my own.
 
obj is the easiest model format since it's just a plaintext series of coords.
If you investigate the format, you should be able to write an obj loader.
3DS works well, and there is lib3DS which will load the models for you, I think it's LGPL.

You're own format might be good in terms of writing a loaer, but it's not going to be great in terms of making the models...
 
That's the problem, Blender can export a lot of formats but none of them quite match what I want to import.
MD2 also looks like a good option, but it seems limited since it's so old.

obj is bothering me because it doesn't list the vertex / face count anywhere, and it will be much simpler to load data if I can just allocate vertex arrays and load a given number of vertexes, rather than using a dynamic data structure and continually adding more vertexes.

So I was thinking I might either write a small program to search through an obj file and write out a header file for it, or I might modify the obj export script in Blender to make my own format.
 
There also doesn't seem to be any simple way to express offsets for models that have multiple connected parts.
Like, if I design a car, I need to somehow figure out where to mount the wheels.
 
OBJ files are one of the simplest 3D file formats to parse, but the are pretty basic in what they can hold as well. When I read OBJs, I read the entire file at once. Then I scan through all the lines, and check the first letters of each. Add up all the lines that begin with "v " and you have your vertex count. Add up all the lines that being with "vn " and you have your normal count. Add up all the lines that begin with "vt " and you have your texture coord count. Likewise with "f " and the face count. Then you can pre-allocate your arrays, go back to the beginning of the buffer, and actually parse the data into your arrays.

OBJ files don't contain any sort of heirarchy info or pivot information. But that should actually be part of your rig, not your geometry. OBJs also have very basic material support; the "usemtl" line signals that all the following faces should use the named material until you come across another usemtl line. The actual material specification is stored in a separate .mat file per obj, and it is pretty simple/restricted as well. But there's no reason your engine can't use a .mat file in its own format, and still use the OBJ exporter from your 3D package.

I don't know about Blender, but Maya's OBJ importer/exporter really kinda sucks. I wrote my own OBJ plugin for Maya for importing/exporting, which could then be modified/expanded to export something specific to an engine should I need it. But OBJ files are a good standard to start with to make sure everything is working correctly.

Cheers,
Michael
 
Back
Top