Sign in to follow this  
Andreas Persson

Getting normals from models

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]

hth
Jack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this