# d3dxmesh / x file rendering problem

This topic is 4331 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am trying to render a .x file in my engine and there is a problem that i cant seem to nail down. when i render the mesh and it goes through the rendering pipeline the result is an all black mesh. i ran it through PIX and it seems like all of my diffuse values are 0 which i suspect is the problem. whats confusing the hell out of me is that the materials diffuse is not 0, its actually 0.8. i have no idea whats going on, is there some other diffuse value that the D3DXMesh could be grabbing? if anyone has any information or suggestions please let me know! here are some debugging screenshots PIX Screenshot material values Black model rendering here is all my x model loading / rendering code
#include "XModel.h"

{
return false;

LPD3DXBUFFER	pMatBuffer;
D3DXMATERIAL	*pMatPtr;

HRESULT res;
&pMatBuffer, 0, &m_nNumMaterials, &m_pMesh);

if (res == S_OK)
{
//get material pointer
pMatPtr = (D3DXMATERIAL *)pMatBuffer->GetBufferPointer();

//create material array
m_pMaterials = new D3DMATERIAL9[m_nNumMaterials];
//create tex array
m_ppTexArray = new LPDIRECT3DTEXTURE9[m_nNumMaterials];

//fill out material array
for (DWORD i = 0; i < m_nNumMaterials; i++)
{
m_pMaterials = pMatPtr.MatD3D;
m_pMaterials.Ambient = m_pMaterials.Diffuse;

m_ppTexArray = 0;
if (pMatPtr.pTextureFilename)
D3DXCreateTextureFromFile(GEAR_RENDER_DEVICE, pMatPtr.pTextureFilename, &m_ppTexArray);

}

pMatBuffer->Release();

return true;
}
else
return false;
}

void CXModel::ReleaseData()
{
m_pMesh->Release();
for (DWORD i = 0; i < m_nNumMaterials; i++)
{
if (m_ppTexArray)
m_ppTexArray->Release();
}
delete[] m_ppTexArray;
delete[] m_pMaterials;
}

void CXModel::Draw(CAppearance *pAppearance)
{
int stage = 0;
for (DWORD i = 0; i < m_nNumMaterials; i++)
{
GEAR_RENDER_DEVICE->SetMaterial(&m_pMaterials);
GEAR_RENDER_DEVICE->SetTexture(0, m_ppTexArray);
//pAppearance->BindData(0, stage);
m_pMesh->DrawSubset(i);

}
}



##### Share on other sites
Try to use some default material to see if thats definetely where the problem lies. For example this is a part of my code
[source lang ="cpp"]for(unsigned int i = 0 ; i < num_mat ; i++)	{		// The default mat being a single shaded material                arr_mesh_materials         =   default_mat9;   		arr_mesh_materials.Ambient =   arr_mesh_materials.Diffuse;		//other code        }

If this works than the mesh will be any color that you specify in the default_mat.

I think I also had a similar problem except my models used to be all white, that might be an exporting issue from whichever modeler you used. I used Maya, and I had a hard time of exporting any other material than the standard lambert. Also, does your model show up correctly in the DxViewer?

##### Share on other sites
ok i figured out the problem... its that damn maya exporter! my friend just sent me an x file and it loaded right up, textured and all! the only problem is that i dont know what im doing wrong with this exporter. the exporter im using is the one that comes with the DX SDK. you mentioned you had problems getting it to work right? what did you do to fix them? oh and also the model that is "broken" works perfectly fine in the DX model viewer, which is what caused me to believe my problem was code related, and not the actual model >:|

##### Share on other sites
Have you tried to print out the material diffuse values of your friends model?
Are they too in 0..1 range?
I guess it is just an option in the exporter how it would interpret color values either in byte range ( 0...255 ) or in floating point range (0...1).

I am not familiar with d3d and did not look at your code. It's just the first thing that came to my mind.

H.

1. 1
2. 2
3. 3
Rutin
14
4. 4
frob
12
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633670
• Total Posts
3013262
×