This topic is now archived and is closed to further replies.


3DS File Loading 0x4130 Material Indices Help!

Recommended Posts

TerraX    180
Hiya, just wondering if there''s someone out there who can help me I''m currently writing a 3DS class, I''ve got the vertex list, unique vertices, texcoords, hell, everything loaded that I need to render, apart from one thing, the index list for each face which points to the unique materials I''m having trouble finding information on that chunk. I believe it''s a sub chunk of 0x4120 (AKA the faces array) and I have confirmed this by reading in the header ID. It''s just that I don''t know how the indices are stored in this little pup. Please help Dave.

Share this post

Link to post
Share on other sites
Kippesoep    892
It''s quite simple. This chunk contains a list of 16bit (i.e. unsigned short) indices. One for each face. These index the list of materials you load from the material chunk (0xAFFF).

Share this post

Link to post
Share on other sites
TerraX    180
I think get ya...

so for each face in an object
Loop through each face
fread(&FaceMaterialIndex, sizeof(unsigned int), 1, file)


I do this after reading and confiming the ID and length of the sub chunk, but all that's contained is...
That's if I use unsigned shorts, whoops!

If I use unsigned ints, I get stupid numbers like...
and so on

Which is silly, as there's only 4 materials.

I think I better look into this a bit more, see where I'm going wrong.

If (I_Sort_This_Out == true)
Ill_Post_Source = true;

PS. If someone could look at the source, tell me where I'm screwing up, I'd be very pleased!

(The offending method is in CGL3DS.cpp, right at the bottom)
PPS Please excuse the mess, I've run out of caffeine

[edited by - TerraX on March 5, 2003 6:21:57 AM]

Share this post

Link to post
Share on other sites
Kippesoep    892
Oh, sorry, it's the other way around, actually.
There are several material chunks in a row, like this:

+ ASCIIZ string (name of material)
+ num (number of faces that use this material)
+ num*idx (indices of faces that use this material)

0x4130 (another TRI_MATERIAL)

So, load the name of the material. From that, determine the index of the material, then, assign that material to all the listed faces.

Sorry again for the misinformation.

[edited by - Kippesoep on March 5, 2003 6:45:52 AM]

Share this post

Link to post
Share on other sites
Jolle    178
it lies in:
0x4D4D -> 0x3D3D -> 0x4000 -> 0x4100 -> 0x4120 -> 0x4130

and after (short)id(=0x4130) and (long)size it goes like this:

and for i = 0; i < nrOfPolys
// here you can like set:
// poly[triPolyIndex].matName = nameOfMaterial)
// or something...

and that's it.

things worth to note is that there is one 0x4130 for every material that is used by the TriPolyList (0x4120)

hope i got it right

[edited by - Jolle on March 11, 2003 2:11:39 PM]

Share this post

Link to post
Share on other sites
TerraX    180
Thanks for the help peepz (Esp. Kippesoep ),
Got it working a lastnite while at work on my laptop

What I was doing wrong, was just reading whatever was in that chunk, as a material index for each face, wrong way around

As promised, once I complete this class (Already got it loading, texturing, calc norms, just lots of little fun things to add like stencil buffer shadows), I'll post link to it in this here forum.

Thanks again everyone!

EDIT: Source in CGL3DS.h/cpp
(Sorry about the delay)

Excert from old CGL history log...
"CGL3DS has been optimized... now sorts triangle faces by material to reduce texture bindings, also uses vertex arrays.
Used to render a high density mesh (50000 faces) at approx 5fps, now it's speeding along at over 100!

[edited by - TerraX on July 21, 2003 6:02:21 AM]

Share this post

Link to post
Share on other sites