Sign in to follow this  

Changing a mesh texture.

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

What I want to do is "in theory" is change a mesh texture from say blue to red at the press of a button for example. This is the code i'm using to load the and draw the meshes. LOAD METHOD void LoadModel(Model* Model,LPCTSTR File) { LPD3DXBUFFER bufMaterial; D3DXLoadMeshFromX(File, D3DXMESH_SYSTEMMEM, d3ddev, NULL, &bufMaterial, NULL, &Model->numMaterials, &Model->Mesh); D3DXMATERIAL* tempMaterials = (D3DXMATERIAL*)bufMaterial->GetBufferPointer(); Model->Material = new D3DMATERIAL9[Model->numMaterials]; for(DWORD i = 0; i < Model->numMaterials; i++) { Model->Material[i] = tempMaterials[i].MatD3D; Model->Material[i].Ambient = Model->Material[i].Diffuse; } return; } DRAW METHOD void DrawModel(Model* Model,float x,float y,float z) { D3DXMATRIX matTranslate; D3DXMatrixTranslation(&matTranslate,x,y,z); d3ddev->SetTransform(D3DTS_WORLD, &matTranslate); for(DWORD index = 0; index < Model->numMaterials;index++) { d3ddev->SetMaterial(&Model->Material[index]); Model->Mesh->DrawSubset(index); } return; }

Share this post


Link to post
Share on other sites
Just change the diffuse colour of the materian in the subset(s) you want to change.

E.g.

for(DWORD index = 0; index < Model->numMaterials;index++)
{
Model->Material[index].Diffuse = D3DCOLOR_XRGB(255, 0, 0);
}




Then render the mesh.

Share this post


Link to post
Share on other sites

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