View Full Version : Loading .obj models?
Blake
2004.01.16, 12:55 AM
anyone know a good example of how to load and render a .obj model?
kberg
2004.01.16, 06:47 AM
You could try this:
http://www.sfu.ca/~kberg/Code/ObjLoader.tgz
Blake
2004.01.17, 12:32 AM
looks a bit complicated, anything simpler?
kberg
2004.01.17, 01:29 AM
looks a bit complicated, anything simpler?
heh, this is about as simple as could possibly! :p
Include ModelType.h and ModelType.cpp in your project, then all you care about are the following lines in the appropriate places for each model you want...
ModelType myModel;
myModel.LoadObj("my_model.obj", 1.0);
myModel.Draw();
Blake
2004.01.17, 02:41 PM
heh, this is about as simple as could possibly! :p
Include ModelType.h and ModelType.cpp in your project, then all you care about are the following lines in the appropriate places for each model you want...
ModelType myModel;
myModel.LoadObj("my_model.obj", 1.0);
myModel.Draw();
that true, for some reason my brain wasnt working ;)
deekpyro
2004.01.18, 01:17 PM
You could try this:
http://www.sfu.ca/~kberg/Code/ObjLoader.tgz
I use this model loader myself in a game I'm working on, sure seems easy enough once you've combed through the code a few times. I've had to make a number of changes to it myself since it isn't perfect and to fit my needs but I'd gladly help out with using it as much as I can.
Derek
codemattic
2004.01.18, 03:42 PM
if youve made improvements to kberg's code deekpyro - maybe you could send them to him to possibly be added to the next version.
deekpyro
2004.01.18, 10:54 PM
I've spent a good deal of time restructing this model loader so it would be molded into something more specialized for my game. I hope in time to rewrite a lot of it, then with that rewrite for my game go back and make a more public version.
It's not that I don't like the modeler, if I did (frown upon it) I wouldn't be using it. On the other hand it's really messy and downright ugly in some areas :D
Derek
kberg
2004.01.19, 03:04 AM
It's not that I don't like the modeler, if I did (frown upon it) I wouldn't be using it. On the other hand it's really messy and downright ugly in some areas :D
If there are any problems with it I would love to hear about them, especially if you consider any of them bugs. I know there are quite a lot of relatively inexperienced programmers using this code (I get emails all the time), so it's kind of important that this be stable and easy to use.
Since I haven't posted in this thread, yet, its about time to add my two cents.
A couple of weeks ago I have written an .obj loader from scratch, and it took 2 hours to get all the functionality running to parse a single-mesh .obj file, with everything supported except grouping and materials.
So, it might be worthwhile to just roll your own, if you have any idea how to parse a document. The .obj file format is really simple, so it is probably a good exercise. IMO, you can write your own loader in the same time you figure out how to use somebody else's.
codemattic
2004.01.19, 03:35 PM
true DoG, but there are lots of little gotchas - like if the data is broken up into multiple lines - and all the different permutations possible for the data - that kberg has accounted for. The code has gone through a number of revisions, each time someone reported finding an obj file that broke it. Kberg's code seems to be able to handle objs that are exported from a variety of different 3d packages - many of which export slightly differently formats.
Mine handles C4D and Maya files so far, but since I made it after the official file format specs, it should handle just about anything
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.