If you find this article contains errors or problems rendering it unreadable (missing images or files, mangled code, improper text formatting, etc) please contact the editor so corrections can be made. Thank you for helping us improve this resource
So, you have your 3D engine (written in D3DIM or OpenGL) up and running, but you only have 2 or 3 cubes or spheres on the screen. Time to add some more complex models. The code below listed can be used to load a 3D Studio R3 or higher .3DS files. The code loads only the vertex data, face data and materials. It ignores all other information (like camera, light, keyframe data etc), since for my purposes, I only need the mesh loaded.
If you think the code is written badly, I don't care! because it does the job and it was my desperate attempt to load some mesh into my D3DIM 3D Engine. But the code is (I hope!) simple and self explanatory for an average C/C++ programmer (or for that matter any programmer who can read C/C++ code). I have added some comments, see if it helps you. The code reads the .3ds file and creates a material list and mesh object list. The material list contains all the materials used by the mesh. The mesh contains references to the material in the material list (i.e the name).
The flag present along with face data gives the order of the faces for calculating face normals. Only the first (I think!) 3 bits are used. The code ignores the flag because I don't need it, but if you figure out the use of that flag, please let me know. Ignoring the flag in some files inverts the face normals for some faces, so it becomes invisible. But other files it works okay.
BTW the transformation matrix contains the local axis and local origin (if it is of any use 2 you).
If you have any questions about the code, or info about how to load camera/lights and other things.... you can contact me at email@example.com.
Note: You'll need to modify the code in order to make it work with your engine. I had to cut this out of a project that I am working on, so it might or might not compile right away... If anyone else out there is developing a 3-D engine and wants to share code/ideas, feel free to e-mail me at firstname.lastname@example.org. (FYI I'm using Visual C++ 6.0 with DX7.0)