Jump to content
  • Advertisement
Sign in to follow this  
Thomo

D3D x mesh problem

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

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.

Share this post


Link to post
Share on other sites
Advertisement
try turning of lighting
pD3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );

but also if you do not supply diffuse colors they will be black

Share this post


Link to post
Share on other sites
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??

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!