Jump to content
  • Advertisement
Sign in to follow this  
QuantumSoul

3ds - exporting objects mapped with Unwrap UVW

This topic is 4413 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm new to the forum, so I wanted to say hi first:) The problem I have is with importing object mesh from .3ds file - the texture coordinates dont load properly whenever I'm importing an object mapped with Unwrap UVW modifier :\ (3ds max 8). I am currently making my first game - an FPP version of dynablaster :) so the object I want to load is a bomb. I made a bomb model with 3ds max, and mapped it with Unwrap UVW. However, when I load it into game (along with texture coordinates) the texture doesn't map properly at all, jus as if the modifier was ignored :\ The type of object in 3ds max is editable poly, I even tried collapsing the modifier (unwrap) before exporting to 3ds. Of course I left the "Preserve MAX's texture coordinates" checkbox checked while exporting (unchecking gives the same effect). The same case is with other objects with Unwrap UVW, but simple objects like boxes are properly textured. Does anyone has some experiences with loading textured models from 3ds? I would be really thankful for help and for any suggestions of what can be wrong. This is how the object looks in 3ds max: And here's in game: Another example - player: Here's my 3ds loading code:
void Object3D::Load3DS(char *FileName)
{
	unsigned short ChunkID;
	unsigned int ChunkLength;
	unsigned short Quantity;	//qty of vertices/indices in chunk
	unsigned short FaceFlags;
	
	int j=0;  //iterator
	unsigned char l_char;

	FILE* file3ds;
	if (fopen_s(&file3ds, FileName, "rb") != 0) 
		engine->Decease("Couldn't open 3ds file.");

	while (ftell(file3ds) < _filelength(_fileno (file3ds)))
	{
		fread (&ChunkID, 2, 1, file3ds);
		fread (&ChunkLength, 4, 1, file3ds);
		j = ftell(file3ds);
		
		switch (ChunkID)
		{
		case 0x4d4d:	//main chunk
			break;

		case 0x3d3d:	//3deditor chunk
			break;

		case 0x4000:	//object block 
			j=0;
			do
			{
				fread (&l_char, 1, 1, file3ds);
                                Name[j]=l_char;
				j++;
                        }while(l_char != '\0' && j<20);
			break;

		case 0x4100:	//object trimesh
			break;

		case 0x4110:	//vertices list
			fread (&Quantity, sizeof (unsigned short), 1, file3ds);

			if (Quantity > MAXVERTICES)
				engine->Decease("Too many vertices in mesh.");

			nVertices = Quantity;
			VertexArray = new VFORMAT [Quantity];

			for (int i=0; i<Quantity; i++)
                {
					fread (&VertexArray.x, sizeof(float), 1, file3ds);
					fread (&VertexArray.y, sizeof(float), 1, file3ds);
					fread (&VertexArray.z, sizeof(float), 1, file3ds);
				}
			break;

		case 0x4120:	//faces desc
			fread (&Quantity, sizeof (unsigned short), 1, file3ds);

			if (Quantity > MAXPOLY)
				engine->Decease("Too many polygons in mesh.");

			nPolys = Quantity;
			PolygonArray = new Poly [Quantity];

            for (int i=0; i<Quantity; i++)
            {
				fread (&PolygonArray.x, sizeof (unsigned short), 1, file3ds);
				fread (&PolygonArray.y, sizeof (unsigned short), 1, file3ds);
				fread (&PolygonArray.z, sizeof (unsigned short), 1, file3ds);
				fread (&FaceFlags, sizeof (unsigned short), 1, file3ds);
			}
			break;

		case 0x4140:	//mapping coord
			if (textured)
			{
				fread (&Quantity, sizeof (unsigned short), 1, file3ds);
				if (Quantity > MAXVERTICES)
					engine->Decease("Too many mapping coordinates in mesh.");

				for (int i=0; i<Quantity; i++)
				{
					fread (&VertexArray.u, sizeof (float), 1, file3ds);
					fread (&VertexArray.v, sizeof (float), 1, file3ds);
				}
			}
			else fseek(file3ds, ChunkLength-6, SEEK_CUR);
			break;

		case 0x4600:	//light - finalizae reading
			return;

		default:		//something else - skipping
			fseek(file3ds, ChunkLength-6, SEEK_CUR);
			break;
		}
	}
	
	if(file3ds)
		if (fclose(file3ds))
			engine->Decease("Error closing 3ds file");
	OwnMesh = true;
}
I'd be grateful for any help! QuantumSoul [Edited by - QuantumSoul on November 18, 2006 7:25:59 PM]

Share this post


Link to post
Share on other sites
Advertisement
in your

case 0x4140: //mapping coord
if (textured) { ... }
else { ... }

code, is it executing the section in if(textured) { ... } or is it skipping it? if it is executing it and you r loading ur uvs, do your uv values make sense? are they all 0.0 <= u, v <= 1.0? if you post your bomb model 3DS (don't need the texture, can use a dummy) i can check it out the file with another program (LightWave) to see if texture coordinates are really being exported out of max, or if they're corrupted somehow.

Share this post


Link to post
Share on other sites
The code is executed ("textured" value is always true), and the uvs are loaded and make sense.

I'm posting the 3ds file:
http://www.lodz.mm.pl/~quantum/graphics/dx/bomb.3DS

Thank you for help :)

Share this post


Link to post
Share on other sites
ok your problem makes sense now... the UVs have not been unwrapped properly. your bomb model has a TON of overlapping uvs. it looks pretty much like you just took a planar map and that's it. you really need to optimize those UVs. since i don't use 3DSMax, i can't help you with the Unwrap UVW modifier, but if that's what it generated, it did a horrible job lol.

how does it look in 3DS Max? this is how it looks like in LightWave (i used a black and white checkered texture):



also, on a side note, for a bomb, that is way too many polygons for a game unless you're using it to generate a normal map. the number of polygons in the fuse alone is insane! make that bomb 100 tris or less and you will see it will be so much easier to unwrap!

[Edited by - yadango on November 18, 2006 9:08:25 PM]

Share this post


Link to post
Share on other sites
Well, I didn't optimize the uvs in any way, because I just wanted to get the code to work at all first:) They're in a overlapping mess because they're on a solid-black area of the texture anyway (except the fuse) so I left them like that.

(here's the texture for reference: http://www.lodz.mm.pl/~quantum/graphics/dx/bomb_tex.jpg - rough but in 3ds max it displays like it should)

As for the checker texture it looks like this in 3ds (tiling 1x1):


Differently from your screenshot (where it looks like with ordinary out-of-the-box spherical mapping). But in the upper right section of your screen uvs are displayed "correctly". If they are then I don't know why the checker texture isn't :
I also have player model with neatly optimized uv for such a texture: http://www.lodz.mm.pl/~quantum/graphics/dx/trooper1024.jpg which also doesn't work - same thing as with the bomb - the result is shown in my first post.

Well, finally: the mapped uvs are included in the .3ds file - you can view them.
My code also loads "some" uvs - as the debugger shows - but as a result texture displays as if with standard spherical mapping.
Then maybe the correct uvs are stored somewhere else in .3ds? It doesnt look like a good idea to store wrong uvs in one place in file and the correct ones in the other, but i cant think of anything else. Maybe (despite the unwrap modifier was collapsed) the'yre stored as a modifier data. I think I'll try looking into .3ds format specs some more (afer I get some sleep) :)

[Edited by - QuantumSoul on November 18, 2006 11:14:27 PM]

Share this post


Link to post
Share on other sites
it shows fine in lightwave with your texture meaning that the UV coordinates are fine. i get something like your messed up version when i flip the image. try messing around inverting your V coordinate. JPEGs are not stored upside-down like bitmaps so if you are loading your JPEGs and rendering the data to BMP format, make sure you invert the image or your V coordinate.

Share this post


Link to post
Share on other sites
At last! It helped 100% :) I already tried rotating it in every direction, but flipping somehow didn't cross my mind. Now everything displays fine :)
Really thanks a lot on that!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!