Monday, December 15, 2008

3D Models as C Header Files

If you've downloaded any of the OpenGL-related sample code from Apple, like GLGravity or TouchFighter, you may have noticed that instead of using OBJ, MD2, or Maya files, they tend to store the 3D data in C header files that contain a vertex array, a normal array, an index of faces, and a count of faces. Pretty much the same approached I used in porting the NeHe lessons, just with a lot more vertices.

There's something to be said for this approach - it's efficient because the data is already in the format OpenGL needs. But how did they create those header files?

Well, I don't know for sure what tool they used, but what they might have used is this Perl script written by Margeret Geroch It will take an OBJ file and convert it into a C header file that you can feed directly to OpenGL without having to do messy conversion work. For the impatient, here's a direct link to the script.

One thing this script doesn't do, however, is convert the texture coordinates, so if anybody out there knows of a similar tool that also handles texture mapping, please let me know.

I've started working on converting the normals for the OBJ loader, and hope to post it within a few days. If your models are going to be complex, you probably want to look at the header file approach, as it will probably be faster.



5 comments:

JS said...

I think that those C header files are the product of a "save as" function in most 3D modeling apps.

Nice site BTW

Jeff LaMarche said...

What 3D program do you know that has a "save as" to C header file feature? I know that Espressosoft makes an export script for Blender, but I don't know of any 3D program that creates header files out of the box.

But, I'm no guru when it comes to 3D programs.

papillon68 said...

Hi Jeff, I often used Deep Exploration (http://www.righthemisphere.com/products/dexp/de_std.html), time before I wrote my own 3ds loader class. However it is not free ...

Edwin said...

scrub m65 kamagra attorney lawyer body scrub field jacket lovegra marijuana attorney injury lawyer

h4ns said...

What youre saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I also love the images you put in here. They fit so well with what youre trying to say. Im sure youll reach so many people with what youve got to say.

Arsenal vs Huddersfield Town live streaming
Arsenal vs Huddersfield Town live streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Notts County vs Manchester City Live Streaming
Notts County vs Manchester City Live Streaming
Bologna vs AS Roma Live Streaming
Bologna vs AS Roma Live Streaming
Juventus vs Udinese Live Streaming
Juventus vs Udinese Live Streaming
Napoli vs Sampdoria Live Streaming
Napoli vs Sampdoria Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
AS Monaco vs Marseille Live Streaming
AS Monaco vs Marseille Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Technology News | News Today | Live Streaming TV Channels