Sign in to follow this  

UV Texture Coordinates

This topic is 4282 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

Hi, I try to show a box that is in an X file. I exported the box with using SoftImage XSI 5. I am loading this x file like following:
bool LoadFromXFile(LPWSTR FileName)
{
	ID3DXBuffer* MaterialBuffer = NULL;
	DWORD MaterialCount = 0;

	if (FAILED(D3DXLoadMeshFromXW(FileName, D3DXMESH_MANAGED, Device, 
		NULL, &MaterialBuffer, 0, &MaterialCount, &Mesh)))
		return false;
	
	if ((MaterialBuffer) && (MaterialCount != 0))
	{
		D3DXMATERIAL* materials = (D3DXMATERIAL*)MaterialBuffer->GetBufferPointer();

		for (UINT32 i = 0; i < MaterialCount; i++)
		{
			materials[i].MatD3D.Ambient = materials[i].MatD3D.Diffuse;

			_Materials.push_back(materials[i].MatD3D);
			if (materials[i].pTextureFilename)
			{
				IDirect3DTexture9* texture = NULL;
				D3DXCreateTextureFromFileA(Device, materials[i].pTextureFilename,
					&texture);
				_Textures.push_back(texture);
			}
			else 
				_Textures.push_back(NULL);
		}
	}

	ReleaseInterface(MaterialBuffer);
	return true;
}
Everything is okay with these codes, but the texture coordinates are wrong. I designed UVs very simple. But the UVs of texture are wrong. DirectX X File Viewer program shows the texture same as my program. But in XSI, UVs are correct. I don't understand why it doesn't. I didn't change any FVF or TextureStageState. What can I do? thanks.

Share this post


Link to post
Share on other sites
Are the UV just upside down? If so, then XSI loads the image file format differently from your program (and differently from the X viewer).

In both DirectX and OpenGL, the V coordinate is defined as being from 0 at the first row of bytes of the image, to 1 at the last row of bytes in the image. In DirectX, you often load BMP or TGA files, which are usually stored lowest-row-first, so people believe DirectX means "V=0 is the lowest row" but that's a mistake. Meanwhile, in OpenGL you often load JPG or PNG files, and the popular libraries for these files happen to return the images in highest-row-first order. Thus, there's a mis-conception that OpenGL uses "V=0 is the highest row" convention. Again, this is inaccurate -- V=0 is the first byte, in both APIs.

So, with that said, it's probably the case that XSI loads the texture image you're using differently from the .X loader, and you're seeing the texture upside down. Is someone "right" or "wrong"? No. They just use different conventions.

Share this post


Link to post
Share on other sites
Quote:
Original post by hplus0603
So, with that said, it's probably the case that XSI loads the texture image you're using differently from the .X loader, and you're seeing the texture upside down. Is someone "right" or "wrong"? No. They just use different conventions.


Hi, thanks for reply.

Firstly, I tried a lot. But I can't find where is problem. I decided to show you difference between XSI and DirectX X File Viewer, also my program too. However, you can see following that every face of the cube is B6 only except one face, but in X File, every face is B3 except one face. I suppose that, every face shows opposite half of image in X File. For example, if I put a face of cube on A2 in XSI, DirectX shows that is A7, or for example, if I put on B1, DirectX shows B8. What can I do?

in XSI:


in DX Viewer:


this is the X file:

xof 0303txt 0032
template XSkinMeshHeader {
<3cf169ce-ff7c-44ab-93c0-f78f62d172e2>
WORD nMaxSkinWeightsPerVertex;
WORD nMaxSkinWeightsPerFace;
WORD nBones;
}

template VertexDuplicationIndices {
<b8d65549-d7c9-4995-89cf-53a9a8b031e3>
DWORD nIndices;
DWORD nOriginalVertices;
array DWORD indices[nIndices];
}

template SkinWeights {
<6f0d123b-bad2-4167-a0d0-80224f25fabb>
STRING transformNodeName;
DWORD nWeights;
array DWORD vertexIndices[nWeights];
array FLOAT weights[nWeights];
Matrix4x4 matrixOffset;
}


Frame Scene_Root {


Frame Camera_Root {


FrameTransformMatrix {
1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,2.000000,20.000000,1.000000;;
}

Frame Camera {


FrameTransformMatrix {
1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000;;
}
}
}

Frame light {


FrameTransformMatrix {
1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000;;
}
}

Frame cube {


FrameTransformMatrix {
1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,-7.000000,1.000000;;
}

Mesh cube_obj {
36;
-0.500000;-0.500000;-0.500000;,
-0.500000;0.500000;-0.500000;,
0.500000;0.500000;-0.500000;,
-0.500000;-0.500000;-0.500000;,
0.500000;0.500000;-0.500000;,
0.500000;-0.500000;-0.500000;,
-0.500000;-0.500000;-0.500000;,
0.500000;-0.500000;-0.500000;,
0.500000;-0.500000;0.500000;,
-0.500000;-0.500000;-0.500000;,
0.500000;-0.500000;0.500000;,
-0.500000;-0.500000;0.500000;,
-0.500000;-0.500000;-0.500000;,
-0.500000;-0.500000;0.500000;,
-0.500000;0.500000;0.500000;,
-0.500000;-0.500000;-0.500000;,
-0.500000;0.500000;0.500000;,
-0.500000;0.500000;-0.500000;,
0.500000;-0.500000;-0.500000;,
0.500000;0.500000;-0.500000;,
0.500000;0.500000;0.500000;,
0.500000;-0.500000;-0.500000;,
0.500000;0.500000;0.500000;,
0.500000;-0.500000;0.500000;,
-0.500000;0.500000;-0.500000;,
-0.500000;0.500000;0.500000;,
0.500000;0.500000;0.500000;,
-0.500000;0.500000;-0.500000;,
0.500000;0.500000;0.500000;,
0.500000;0.500000;-0.500000;,
-0.500000;-0.500000;0.500000;,
0.500000;-0.500000;0.500000;,
0.500000;0.500000;0.500000;,
-0.500000;-0.500000;0.500000;,
0.500000;0.500000;0.500000;,
-0.500000;0.500000;0.500000;;
12;
3;0,1,2;,
3;3,4,5;,
3;6,7,8;,
3;9,10,11;,
3;12,13,14;,
3;15,16,17;,
3;18,19,20;,
3;21,22,23;,
3;24,25,26;,
3;27,28,29;,
3;30,31,32;,
3;33,34,35;;

MeshNormals {
36;
0.000000;0.000000;-1.000000;,
0.000000;0.000000;-1.000000;,
0.000000;0.000000;-1.000000;,
0.000000;0.000000;-1.000000;,
0.000000;0.000000;-1.000000;,
0.000000;0.000000;-1.000000;,
0.000000;-1.000000;0.000000;,
0.000000;-1.000000;0.000000;,
0.000000;-1.000000;0.000000;,
0.000000;-1.000000;0.000000;,
0.000000;-1.000000;0.000000;,
0.000000;-1.000000;0.000000;,
-1.000000;0.000000;0.000000;,
-1.000000;0.000000;0.000000;,
-1.000000;0.000000;0.000000;,
-1.000000;0.000000;0.000000;,
-1.000000;0.000000;0.000000;,
-1.000000;0.000000;0.000000;,
1.000000;0.000000;0.000000;,
1.000000;0.000000;0.000000;,
1.000000;0.000000;0.000000;,
1.000000;0.000000;0.000000;,
1.000000;0.000000;0.000000;,
1.000000;0.000000;0.000000;,
0.000000;1.000000;0.000000;,
0.000000;1.000000;0.000000;,
0.000000;1.000000;0.000000;,
0.000000;1.000000;0.000000;,
0.000000;1.000000;0.000000;,
0.000000;1.000000;0.000000;,
0.000000;0.000000;1.000000;,
0.000000;0.000000;1.000000;,
0.000000;0.000000;1.000000;,
0.000000;0.000000;1.000000;,
0.000000;0.000000;1.000000;,
0.000000;0.000000;1.000000;;
12;
3;0,1,2;,
3;3,4,5;,
3;6,7,8;,
3;9,10,11;,
3;12,13,14;,
3;15,16,17;,
3;18,19,20;,
3;21,22,23;,
3;24,25,26;,
3;27,28,29;,
3;30,31,32;,
3;33,34,35;;
}

MeshTextureCoords {
36;
-0.747347;-0.745207;,
-0.747347;-0.851662;,
-0.640892;-0.851662;,
-0.747347;-0.745207;,
-0.640892;-0.851662;,
-0.640892;-0.745207;,
-0.640497;-0.744314;,
-0.746953;-0.744314;,
-0.746953;-0.850770;,
-0.640497;-0.744314;,
-0.746953;-0.850770;,
-0.640497;-0.850770;,
-0.639296;-0.747428;,
-0.745752;-0.747428;,
-0.745752;-0.853883;,
-0.639296;-0.747428;,
-0.745752;-0.853883;,
-0.639296;-0.853883;,
-0.746582;-0.750306;,
-0.746582;-0.856762;,
-0.640127;-0.856762;,
-0.746582;-0.750306;,
-0.640127;-0.856762;,
-0.640127;-0.750306;,
-0.639073;-0.855079;,
-0.639073;-0.748624;,
-0.745529;-0.748624;,
-0.639073;-0.855079;,
-0.745529;-0.748624;,
-0.745529;-0.855079;,
-0.265272;-0.878639;,
-0.371728;-0.878639;,
-0.371728;-0.985094;,
-0.265272;-0.878639;,
-0.371728;-0.985094;,
-0.265272;-0.985094;;
}

MeshMaterialList {
1;
12;
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0;

Material DefaultLib_Scene_Material {
0.700000;0.700000;0.700000;1.000000;;
50.000000;
1.000000;1.000000;1.000000;;
0.000000;0.000000;0.000000;;

TextureFilename {
"noIcon.bmp";
}
}
}
}
}
}

Share this post


Link to post
Share on other sites
Hi. hplus0603 sayed XSI and Direct3D mapping system may be different like 3dsmax. You should multiply U or V values by -1 for invert texture. Try all variations until true result.

Share this post


Link to post
Share on other sites
Hi. hplus0603 sayed XSI and Direct3D mapping system may be different like 3dsmax. You should multiply U or V values by -1 for invert texture. Try all variations until get true result.

Share this post


Link to post
Share on other sites
Quote:
Original post by 3ddreams
You should multiply U or V values by -1 for invert texture. Try all variations until get true result.


thanks.. I try a lot as you said. But I didn't solve this. At last, I found a way, but sometimes this way go wrong. Firstly, I exported my model from SoftImage as dotXSI File. Than I converted this file to .X file with Deep Exploration. Everything is ok, as I said, sometimes, especially after exporting skinnedmesh with a lot of animation set, deep exploration don't define my dotXSI file. I'm still trying another ways :(

thanks.

Share this post


Link to post
Share on other sites

This topic is 4282 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this