OBJ Loader

Post: #16
Forum search would turn up dozens of topics on this subject.

I'll save you the work however:
Quote this message in a reply
Posts: 1,199
Joined: 2004.10
Post: #17
FCCovett Wrote:Two hours to write a OBJ loader? Either you guys are full of BS or I am writing the biggest object loader ever. I've been working for 2 days on mine.

Well, I had two things going for me.

1) Over the last two years I've written a reasonably robust C++ string-processing library, oriented towards tokenizing and simple stream processing. So, 90% of the dirty work was done already. Plus, I've written tons of parsers over the last ten years.

2) I'm only interested in triangles/quads and texture coords. I don't support OBJ file material declarations, and I'm not interested in computational surfaces like bezier patches.

Finally, while I only spent about 2 or 3 hours writing the code, I did spend an evening *thinking* about how best to approach it and taking notes on paper. So when I started coding I already had a good design on paper.

EDIT: One more thing, my whole OBJ file parser is only like 800 loc, since it doesn't need to actually do anything other than hand vertices, indices and tex coords to an existing mesh class -- that said, about half of my code is error handling, to gracefully handle malformed declarations.
Quote this message in a reply
Posts: 78
Joined: 2002.06
Post: #18
I use my own OBJ loader in BitRacer, you can have a look at the source here, http://www.uclic.ucl.ac.uk/usr/will/bitracer_src.zip. It is in cocoa using the nsscanner, not much code and handles textures materials and colours. Though only triangles. The code is really fairly simple if you want to look. The real code is about 300 lines long, most of the files are taken up with various rendering, cel-shading, shadow casting, texture loading and creating ODE models. (~900 lines total) Enjoy --will
Quote this message in a reply
Post Reply