Getting normals from models
Hi I was wondering how to get a .x models normals (they are created in modeling program) so I can use them.
Thanks
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement