Jump to content
  • Advertisement
Sign in to follow this  
bengaltgrs

Multiple texture coordiantes for Xfile?

This topic is 4837 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 wrote an HLSL shader that requires the object to have 3 texture coordinates, but I am having trouble getting a .X file (of type ID3DXMesh) to have 3 texture coordinates. The first two must be the regular texture coordinates * 2 to tile the texture and the third must be just the regular texture coordinates. I thought I might accomplish this with the CloneMeshFVF, but I cannot get it to work. I was debating writing something that reads all the data in from a .X file into a IDirect3DVertexBuffer9 object, but there has really got to be an easier way. If anyone knows how to accomplish this, any help would be greatly appreciated. Thanks, -Chris

Share this post


Link to post
Share on other sites
Advertisement
I've never had any problems with CloneMeshFVF() for this sort of task before. What sort of trouble was it causing you - bad results, or actual errors?

One thing to remember with cloning is that it just widens/narrows the vertex structure as appropriate, it doesn't actually put any (meaningful) data into the newly created fields unless it existed previously.

In your case, cloning to get 2 extra (for 3 total) texture coordinates should have one (presumably the first) with the original/valid data, and 2 with junk in them.

The one time I had to add an extra set of TC's into my mesh, I locked the buffer afterwards and copied all of the first coordinates into the space now allocated for the second coordinates [smile]

hth
Jack

Share this post


Link to post
Share on other sites
Well, this is what I was trying to do:

const DWORD MeshFVF = D3DFVF_XYZ | D3DFVF_TEX3;

LPD3DXMESH temp;
Mesh->CloneMeshFVF(NULL, MeshFVF, Device, &temp);
Mesh = temp;

I assume I would have to then copy all the texture coordinates from the first set into the second and third sets, but I am not sure how to do that. Also, if I tried adding "temp->Release();" after that, I would get a runtime error when it tries to render the Mesh object. Should'nt I be allowed to release it, or is there some reason why I cannot do that?

Thanks,
Chris

Share this post


Link to post
Share on other sites
After the code you placed, Mesh and temp are both pointing at the same mesh, your new one. You did however lose all pointers to your original mesh. Try releasing the original mesh (assuming you no longer need it) and keeping a pointer to the new mesh (temp). Something like this:

const DWORD MeshFVF = D3DFVF_XYZ | D3DFVF_TEX3;

LPD3DXMESH temp;
Mesh->CloneMeshFVF(NULL, MeshFVF, Device, &temp);
Mesh->Release();
Mesh = temp;

You can't release the temp mesh as you'll be using it later on (I think, that why you're doing this whole thing, right?)...


As for modifying the texcoords, you can call Mesh->LockVertexBuffer (check spelling), which would lock the Mesh's VB and allow you to modify the vertex data directly.

Hope this helps :).

Share this post


Link to post
Share on other sites
Ok, so I understand that you lock the vertex buffer with something like this:

void* pData;
Mesh->LockVertexBuffer(0, &pData);

Then copy texture coordinates from the first set to the second and third sets here, then unlock the vertex buffer.

Mesh->UnlockVertexBuffer();

I am just not too sure how to copy over the first set to the second and third sets. I apologize if this is an easy step, I just do not know how to do it.

-Chris

Share this post


Link to post
Share on other sites
In case anyone was curious, I figured out how to create multiple texture coordinates for a mesh by looking through a vetex tweening example. I was just curious as to if there was another way, or if my way can be optimized, just any hints at all. Anyways, here it is:

typedef struct {
D3DXVECTOR3 vecPos;
D3DXVECTOR2 texPos1;
D3DXVECTOR2 texPos2;
D3DXVECTOR2 texPos3;
} TexCopyVertex;

const DWORD MeshFVF = D3DFVF_XYZ | D3DFVF_TEX3;

ID3DXMesh* TempMesh;

char *MeshPtr, *TempMeshPtr;

Mesh->CloneMeshFVF(NULL, MeshFVF, Device, &TempMesh);
Mesh->Release();
Mesh = TempMesh;

DWORD MeshSize = D3DXGetFVFVertexSize(Mesh->GetFVF());
DWORD TempMeshSize = D3DXGetFVFVertexSize(TempMesh->GetFVF());

Mesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&MeshPtr);
TempMesh->LockVertexBuffer(0, (void**)&TempMeshPtr);

for(DWORD i=0; i < Mesh->GetNumVertices(); i++)
{
TexCopyVertex *MeshVertex = (TexCopyVertex*)MeshPtr;
TexCopyVertex *TempMeshVertex = (TexCopyVertex*)TempMeshPtr;

TempMeshVertex->vecPos = MeshVertex->vecPos;
D3DXVECTOR2 temp = MeshVertex->texPos1;
TempMeshVertex->texPos1 = temp * 2;
TempMeshVertex->texPos2 = temp * 2;
TempMeshVertex->texPos3 = temp;

MeshPtr += MeshSize;
TempMeshPtr += TempMeshSize;
}


Mesh->UnlockVertexBuffer();
TempMesh->UnlockVertexBuffer();

Mesh = TempMesh;

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!