how know what texture have to be associated to an object ? (explanation inside)

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.

what do you mean by object? texture objects and by file? do you mean texture image?

what do you mean by object? texture objects and by file? do you mean texture image?

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 :slight_smile:

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.

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 ;
						 do
						 {
							file.read(&tempChar , sizeof (char));
							cout<<tempChar ;
						 }
						 while(tempChar != '\0');
						 file.read((char*) &(myObjects[counterObj].nbPoly), sizeof (short int));
						 cout<<"nbPoly "<<dec<<myObjects[counterObj].nbPoly<<endl ;
						 for (polyCounter = 0 ; polyCounter< myObjects[counterObj].nbPoly ; polyCounter++)
						 {
							file.read((char*) &(tmp), sizeof (short int));
			
						 }
						
						 break ;

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 and here .

For an example look here.

[edit]Maybe I should also mention lib3ds 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.[/edit]

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*) &(chunk), sizeof (short int));
		
		cout<<hex<<"chunk "<<chunk<<endl ;// !!!display the chunk 0xafff !!!
				file.read((char*)&chunkSize, sizeof(unsigned int));
		//cout<<dec<<"chunkSize "<<chunkSize<<endl ;
		
		switch(chunk) 
		{      
			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 ;

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.

thanks, it was reading a negative value instead of afff.