Jump to content
  • Advertisement
Sign in to follow this  
Andreas Persson

Getting normals from models

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

Well if they were exported as part of your whatever -> .X conversion then ID3DXMesh should export them.

If that's not the problem, and you just want to pull them from the ID3DXMesh owned buffers then there are a couple of routes...

1. Decode the vertex declaration (better than going for the FVF as it's more robust!), lock the vertex buffer (ID3DXMesh::LockVertexBuffer()) and manually step through the raw data and pull out the normals.

2. Use a clever trick with ID3DXMesh::CloneMesh() and create a temporary ID3DXMesh with ONLY normals (ID3DXMesh::CloneMeshFVF() using D3DFVF_NORMAL should suffice) and then lock the vertex buffer (ID3DXMesh::LockVertexBuffer()) and you'll be presented with a stream of D3DXVECTOR3 (or just float triplets) that you can read out straight away.

#1 is easier to get wrong, but usually much faster - good if you need access to (or want to manipulate) the normals in performance-sensitive code.

#2 is much easier to implement, but the whole mesh-cloning business means resource allocation and de-allocation, which isn't good for performance-sensive code.

Pick the ones that suits your usage [smile]


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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!