View Full Version : how know what texture have to be associated to an object ? (explanation inside)

02-09-2005, 10:35 AM
Hi !
i have made a .3ds loader and i don't know how i could know what texture file i have to map to what object. For instance, if i have two texture to map to one object and if the texture coordinates are different i should not map the a texture with coordinates that are not its, how can i do the good mapping ?
idem if i have several objects and severals textures for the same file, how can i know which texture is associated to which object ?
please help me and don't hesitate to tell me if i'm not clear enough.

02-09-2005, 02:03 PM
what do you mean by object? texture objects and by file? do you mean texture image?

02-09-2005, 02:13 PM
what do you mean by object? texture objects and by file? do you mean texture image?

02-10-2005, 01:31 AM
Originally posted by marco:
what do you mean by object? texture objects and by file? do you mean texture image?by object i mean a mesh, and by texture i mean a 2d image :)

02-10-2005, 02:27 AM
For each material used on an object there should be a 0x4130 chunk (following the list of triangles). It tells you a material name and the list of triangles that use that material.

02-10-2005, 02:54 AM
thanks but i try to read in that chunk and i don't manage to get the texture name( a .jpg)and there is few documentation about that chunk.
this is what i do (there is something that i don't read but i don't know what), it gives me an ascii string but it's not the name of the file (the texture):

case 0x4130: short int tmp ;
cout<<dec<<"chunkSize "<<chunkSize<<endl ;
file.read(&amp;tempChar , sizeof (char));
cout<<tempChar ;
while(tempChar != '\0');
file.read((char*) &amp;(myObjects[counterObj].nbPoly), sizeof (short int));
cout<<"nbPoly "<<dec<<myObjects[counterObj].nbPoly<<endl ;
for (polyCounter = 0 ; polyCounter< myObjects[counterObj].nbPoly ; polyCounter++)
file.read((char*) &amp;(tmp), sizeof (short int));


break ;

02-10-2005, 03:25 AM
I think it's the name of the material. There is a list of materials (including what textures they use) in chunk 0xAFFF and it's sub-chunks.

For a documentation describing this look here (http://www.jalix.org/ressources/graphics/3DS/_specifications/3ds-0.1.htm) and here (http://astronomy.swin.edu.au/~pbourke/geomformats/3ds/) .

For an example look here. (http://www.gamedev.net/reference/articles/article1259.asp)

Maybe I should also mention lib3ds (http://lib3ds.sourceforge.net/) which does all of this and more. Even if you still want to do it yourself, it's a good place to find out what chunk does what.

02-10-2005, 04:10 AM
ok thanks !
but i try to read the 0xafff chunk (for materials)by displaying to the screen a message when it's read but nothing is displayed. The chunk 0xafff is found but the program don't "go" in the switch case where is the cout.
can you help me ?
while (!file.eof())
file.read((char*) &amp;(chunk), sizeof (short int));

cout<<hex<<"chunk "<<chunk<<endl ;// !!!display the chunk 0xafff !!!
file.read((char*)&amp;chunkSize, sizeof(unsigned int));
//cout<<dec<<"chunkSize "<<chunkSize<<endl ;

case 0x4D4D: break;

case 0x3D3D: break;

case 0xafff: cout<<"afff found "<<endl ;// !!!!this message is not displayed !!!

break ;
case 0xa000: cout<<"a000 trouvé "<<endl ;
break ;

02-10-2005, 04:36 AM
Can't see why it would do that. Set a breakpoint at the first "cout" and single-step from there in the debugger looking at the chunk variable to see where it starts going wrong.

02-10-2005, 06:09 AM
thanks, it was reading a negative value instead of afff.