D3D x mesh problem

Started by
5 comments, last by Thomo 17 years, 11 months ago
I have an x mesh which I have loaded into a D3D app along with it's texture map (tga). At some point I will want to pull out the rgb values of each vertex. When I use a custom vertex: #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL), the mesh displays correctly. However, when I change it to #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE), the model comes out black.

The customvertex is defined as: typedef struct 
{
    D3DXVECTOR3		position; // The 3D position for the vertex
	D3DXVECTOR3		normal; // The 3D position for the vertex
	DWORD		diffuse;

} CUSTOMVERTEX ;
With this format, the mesh comes out black when I run the app. Not sure if diffuse values can be pulled from a mesh with a texture map. Or can they?? Can someone help? Thanks.
Advertisement
try turning of lighting
pD3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );

but also if you do not supply diffuse colors they will be black
I think it's probably the value problem rather than the lighting.

I've checked the .x file and the name of the texture map is in place of the diffuse values.

Do you know of a way I can pull the colours of each vertex from the texture map??
There are couple things that could be going on. First of all the D3DX mesh loading functions dont require you to supply an FVF so this makes me think that (a). you are loading the mesh yourself, or (b). you are trying to convert a loaded mesh to a specific FVF. Im not really sure what you are doing.. if you want to post your loading code I can better help you.
I think the mesh loader that comes with D3DX creates a D3DFVF for you. You can put a breakpoint in your app and see what kind of vertex format D3DX mesh loader picked.
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)
Have you tried using D3DXLoadMeshFromX() to load the mesh into a temporary ID3DXMesh* and then using that to call CloneMeshFVF() to create a mesh in the format of your customvertex? From there you can call LockVertexBuffer() to obtain a pointer to the vertex info. Then because you know the data format of the vertices, you can extract all the diffuse info using the offsets from the pointer.

I also think that the reason your mesh is coming out black is because the diffuse has not been set for the mesh. Instead I imagine that directx calls zero memory on any part of the vertex structure that the x file doesnt define, which would result in black.
Yes, you are right. There are no diffuse values set for the mesh in the .x file. The model only has a texture map associated with it.


In fact, you may be able to advise on the root of my problem:

As said, I have a .x mesh and a tga texture map associated with it. Like you have suggested, I have cloned the meshes after loading them into my app so I can have the vertex format the way I desire.

What I actually want, is the rgb values associated with a particular vertex. I thought (incorrectly) that D3D _might_ set the diffuse values of each vertex with from the texture map and the UV coordinates of each vertex.

So my question is, do you know of a way I can get the representative rgb values as described with D3D functionality? Or will I have to do it manually by loading in a bitmap and doing something like...

rgb_value_x = uv_x * bitmap_width (or whatever)...

Thanks,

Thomo.


This topic is closed to new replies.

Advertisement