Jump to content
  • Advertisement
Sign in to follow this  
Hanchy

Get Vertex's Normal

This topic is 4805 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 load a .x file, and I have also generated the normals of vertices. My problem is that I don't know how to get them. Can you help me?

Share this post


Link to post
Share on other sites
Advertisement
A dead simple way is thus:

1. Create a temporary ID3DXMesh
2. Use ID3DXMesh::CloneFVF( D3DFVF_NORMAL ) to clone your .X file based mesh to the temporary one.
3. Use ID3DXMesh::LocVertexBuffer() to gain access to the temporary mesh's data
4. read out all the data, you will have a stream of D3DXVECTOR3's - each of which is the normal for the corresponding vertex.

Because of the cloning/locking it's not the most efficient method, but it'll be plenty good enough for load-time usage.

hth
Jack

Share this post


Link to post
Share on other sites
Just because it's more interesting than my day-job, here's some code off the top of my head. I don't have a compiler to run it through, so no guarantees that it's perfect [smile]


//we'll assume 'mesh' is your original, fully loaded, LPD3DXMESH object
//and that 'device' is your active LPDIRECT3DDEVICE9 object
ID3DXMesh *temporary_mesh;
if( FAILED( mesh->CloneMeshFVF( mesh->GetOptions(), D3DFVF_NORMAL, device, &temporary_mesh ) ) )
{
//hmm, something not right here - possibly your source mesh doesn't
//have the correct information!
}

D3DXVECTOR3 *pNormals = NULL;

if( FAILED( temporary_mesh->LockVertexBuffer( 0, reinterpret_cast< void* >( &pNormals ) ) ) )
{
//couldn't lock the vertex buffer...?!
}

//From here, you should have 'pNormals' containing 'temporary_mesh->GetNumVertices()' elements.




hth
Jack

Share this post


Link to post
Share on other sites
Thanks!
I've already do it. my code is this:

DWORD FVF = g_pWireMesh->GetFVF();
DWORD dwVertSize = D3DXGetFVFVertexSize( FVF );
VOID* pVB = NULL;
if ( SUCCEEDED( g_pWireMesh->LockVertexBuffer( D3DLOCK_DISCARD, &pVB ) ) ) {
DWORD dwNumVertice = g_pWireMesh->GetNumVertices();
for ( DWORD i=0; i < dwNumVertice; ++i ) {
D3DXVECTOR3 *pvPtr = (D3DXVECTOR3 *) pVB;
pvPtr->
}
}
g_pWireMesh->UnlockVertexBuffer();


Can you give me more details??
Thanks a lot.

Share this post


Link to post
Share on other sites
Quote:
Original post by Hanchy
I've already do it. my code is this:
<--snip-->
Can you give me more details??

Details on what exactly?? [smile] does that code you've written not work then?

Cheers,
Jack

Share this post


Link to post
Share on other sites
Ok, the "D3DXVECTOR3 *pvPtr" is the vector. But what is the vertex?
(I am a new comer to the graphics)

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!