• Advertisement
Sign in to follow this  

Changing a mesh texture.

This topic is 3560 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 = tempMaterials.MatD3D; Model->Material.Ambient = Model->Material.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
Advertisement
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
Sign in to follow this  

  • Advertisement