Game Development Community

3DS Loader & Viewer

by Matt Fairfax · 02/17/2001 (11:18 am) · 25 comments

Download Code File

This is a simple 3D studio model loader/viewer class that can be easily used with your projects. It isn't the most efficient way to load a 3DS model but I find it a lot easier to read and debug. I have included my simple Texture class to support texturing of the models. I know it is crude and doesn't port well to non-Windows platforms so just replace it with your favorite texture class and have fun! Feel free to use this code in any project. I just ask that you let me know if you decide to use it. This code stands as is but I would like to know of any bugs so that I can address them in later releases. I have a mostly working Direct3D 8.0 port of this code (haven't finished the texture part) if anyone is interested.

Description from file:
// This is a simple class for loading and viewing
// 3D Studio model files (.3ds). It supports models
// with multiple objects. It also supports multiple
// textures per object. It does not support the animation
// for 3D Studio models b/c there are simply too many
// ways for an artist to animate a 3D Studio model and
// I didn't want to impose huge limitations on the artists.
// However, I have imposed a limitation on how the models are
// textured:
// 1) Every faces must be assigned a material
// 2) If you want the face to be textured assign the
// texture to the Diffuse Color map
// 3) The texture must be supported by the GLTexture class
// which only supports bitmap and targa right now
// 4) The texture must be located in the same directory as
// the model

// Support for non-textured faces is done by reading the color
// from the material's diffuse color.

// Some models have problems loading even if you follow all of
// the restrictions I have stated and I don't know why. If you
// can import the 3D Studio file into Milkshape 3D
// (http://www.swissquake.ch/chumbalum-soft) and then export it
// to a new 3D Studio file, it seems to fix many of the problems
// but there is a limit on the number of faces and vertices Milkshape 3D
// can read.

Usage:
Model_3DS m;

m.Load("model.3ds"); // Load the model
m.Draw(); // Renders the model to the screen

// If you want to show the model's normals
m.shownormals = true;

// If the model is not going to be lit then set the lit
// variable to false. It defaults to true.
m.lit = false;

// You can disable the rendering of the model
m.visible = false;

// You can move and rotate the model like this:
m.rot.x = 90.0f;
m.rot.y = 30.0f;
m.rot.z = 0.0f;

m.pos.x = 10.0f;
m.pos.y = 0.0f;
m.pos.z = 0.0f;

// If you want to move or rotate individual objects
m.Objects[0].rot.x = 90.0f;
m.Objects[0].rot.y = 30.0f;
m.Objects[0].rot.z = 0.0f;

m.Objects[0].pos.x = 10.0f;
m.Objects[0].pos.y = 0.0f;
m.Objects[0].pos.z = 0.0f;

About the author

By day, I am a senior programmer at The Playforge, makers of the popular iPhone game Zombie Farm. By night, I work on my own games as Night Heron Games. I am an ex-GarageGames employee who helped ship TGE, TGEA, Torque 3D, and Constructor.

Page«First 1 2 Next»
#21
10/08/2008 (5:11 pm)
Hello Everyone .. I have been strugling with this library for like one week or so but still cant make it work.. my problems are...

1) I am using MicroSoft Visual Studio 2005
2) I did not have glaux library and could not find it so i did the same solution as mentioned by _veto_ and used BMP.H fromt the given link...
3) Now i get the Following RUN TIME ERROR it its caused during the model loading process

Windows has triggered a breakpoint in DataProj.exe.

This may be due to a corruption of the heap, and indicates a bug in DataProj.exe or any of the DLLs it has loaded.
HEAP[DataProj.exe]: Invalid Address specified to RtlFreeHeap( 00B70000, 01378698 )
Windows has triggered a breakpoint in DataProj.exe


Does anyone have any clue about it?What could be the problem??
#22
01/12/2009 (6:42 pm)
Well I was Just passing by so thought it would be better for new users to know that there is a small bug in this LIB...

glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
are enabled but not disabled after used.. So if you use your own Display Arrays without texture or Normal pointer then it would might cause you a run time error
#23
04/22/2009 (7:15 pm)
Hello there..



#24
04/22/2009 (7:18 pm)
Hello there..
I'm using your code but I'm not very good in opengl, so I have 2 questions:

1- I can load any .3ds model with your code?

2- I have a model but i don't know how I draw it.
I put the m.draw() in my renderscene()?

my project compiles fine but the model doesn't appear.

P.S - Sorry my bad English:)




#25
10/16/2009 (6:06 pm)
The file I load is being displayed but i just cant get the textures to work. The mesh is completely white.

Could someone please post a simple 3ds plane or box with a texture that is being shown correctly by the 3ds loader.

It would help me a lot.
Page«First 1 2 Next»