Sign in to follow this  
Andrew1979

.x file colour loading

Recommended Posts

Andrew1979    112
Hi All

I've created a character model in Blender 3D that I have exported to an .x file which displays fine using the X viewer from DirectX.

However I want to now import the model into my Direct3D program. I do already have working code that loads a model with textures (using texture map files (jpg, bmp, etc..).

My character model is just using colours, no texture files, how would I load the colours that character model is in?

Currently in my Direct3D program I just get white, how do I load the colours the character has got?

Current code to load character data
-----------------------------------

D3DXLoadMeshFromX(FLOOR_X_CHARACTER, D3DXMESH_SYSTEMMEM,deviceIn, NULL,&character_MaterialBuffer, NULL, &character_NumMaterials,&character_Mesh);

D3DXMATERIAL* character_Materials = (D3DXMATERIAL*)character_MaterialBuffer->GetBufferPointer();

//Loop for all materials and textures
for(DWORD i=0; i < character_NumMaterials; i++)
{
// Copy the material from the buffer to your array
character_MeshMaterials[i] = character_Materials[i].MatD3D;

character_MeshMaterials[i].Ambient = character_MeshMaterials[i].Diffuse;

//Set the texture to NULL
character_MeshTextures[i] = NULL;
if(character_Materials[i].pTextureFilename != NULL && lstrlen(character_Materials[i].pTextureFilename) > 0)
{
D3DXCreateTextureFromFile(deviceIn,character_Materials[i].pTextureFilename,&character_MeshTextures[i]);
}
}

// Set the identity matrix for the character transform
D3DXMatrixIdentity(&matrix_Boogle);

D3DXMatrixIdentity(&matrix_Boogle_Rotate);

Current code to render / display character model
------------------------------------------------

for(DWORD i=0; i < character_NumMaterials; i++)
{
// Set the material and texture for this subset
deviceIn->SetMaterial(&character_MeshMaterials[i]);
deviceIn->SetTexture(0, character_MeshTextures[i]);
// Draw the mesh subset
character_Mesh->DrawSubset(i);
}


Any help appreciated and sorry for a bit of a long post.

The model of the character is displayed but its all in white. How do I get the character displayed in the colours I assigned it in Blender?

Thank you in advance.

Andrew

Share this post


Link to post
Share on other sites
Buckeye    10747
Do you have lighting* turned on? If so, did you set up a light (D3DLIGHT9 in DX9) and enable it?

*dev->SetRenderState(D3DRS_LIGHTING,TRUE);

Share this post


Link to post
Share on other sites
Andrew1979    112
Hi

I don't have lighting turned on, I'm just using the default lighting settings in Direct3D.

I can see colour with meshes which have actual textures applied but can only see white meshes when only colours have been used on the meshes.

It looks fine in the X viewer tool, just not in my program.

Is switching the lighting on and setting up an essential requirement for this?

Any idea why it works with textured meshes and not untextures meshes?

Thank you for your help and advice in advance.

Andrew

Share this post


Link to post
Share on other sites
Buckeye    10747
Quote:
I don't have lighting turned on

Actually, lighting ON should be the default, but you should check it. However, there are no appropriate lights defined by default.

What happened when you did setup a light? That should have fixed the problem.
Quote:
Is switching the lighting on and setting up an essential requirement for this?

Yes, you need to have lighting on and a light defined to see shades of color, as you probably know by now. (I assume you tried that)

Share this post


Link to post
Share on other sites

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