View Full Version : help with 3ds loader from gametutorials

02-04-2003, 07:17 AM
I realize that mabey this isnt the best question for this forum but the forums over at gametutorials.com are down right now.
Every time I try to use his gametutorials 3ds loader I get the object to load but it looks as though there is no depth testing on because I can see back facing polys through the fron ones. I have enabled depth testing and cleared the buffer so I know thats not the problem. I have almost vituraly copied his code to see if it will work. Also I know its not the object because I have used his and It doesnt work.

02-05-2003, 12:25 AM
Did u test the normal smoothing routine (if I remember it has one), maybe it just invert the order of vertex while creating the normal out of triangle vertexes.

02-05-2003, 06:39 AM
I'm not familiar with the loader code you mentioned, but it sounds like you may need to handle 2-sided materials as read from the 3DS file (chunk ID = 0xA081) and add the attendant extra surfaces that map to those materials at mesh loading time.

See Display3DS (http://p-squared.com/Display3DS.php) for a legible example (Windows (VC++/MFC) and Mac OS X (Objective-C/Cocoa) only).

Compare your loader code with how Display3DS adds an extra surface and computes surface normals when a polygon uses a 2-sided material:

#include "Mesh3DS.h"

void Mesh3DS::AddPolygon (TRIANGLE tri, char *MaterialName)
int MaterialNum;

SURFACE TempSurface;

TempSurface.p0 = tri.p0;
TempSurface.p1 = tri.p1;
TempSurface.p2 = tri.p2;

if (!CalculateSurfaceNormal (&TempSurface)) return; // Ignore degenerate polygons

MaterialNum = FindMaterialIndex (MaterialName); // Find the polygon list index we belong to

POLYGONLIST *poly_entry = (POLYGONLIST*) PolyList[MaterialNum]; // Attach a new triangle to the polygon list

SURFACE *surface_entry = (SURFACE*) poly_entry->TriangleIndexList[poly_entry->TriangleIndexList.Add (new SURFACE())];

surface_entry->p0 = tri.p0;
surface_entry->p1 = tri.p1;
surface_entry->p2 = tri.p2;

CalculateSurfaceNormal (surface_entry);

if (poly_entry->doublesided) // Attach another surface for the second side
SURFACE *surface_entry = (SURFACE*) poly_entry->TriangleIndexList[poly_entry->TriangleIndexList.Add (new SURFACE())];

surface_entry->p0 = tri.p0;
surface_entry->p1 = tri.p2; // Flip polygon orientation for back-facing surface
surface_entry->p2 = tri.p1;

CalculateSurfaceNormal (surface_entry);

Try running your 3DS mesh through Display3DS with & without the 'Force 2-Sided' menu option enabled to see if we're on the right track.


[This message has been edited by ppinter1 (edited 02-05-2003).]

02-05-2003, 03:23 PM
I have faced this problem before.
I just put the glEnable(GL_DEPTH_TEST);
then it work......

02-06-2003, 07:32 AM