Getting normals from models

Started by
3 comments, last by Andreas Persson 18 years, 4 months ago
Hi I was wondering how to get a .x models normals (they are created in modeling program) so I can use them. Thanks
Casual game dev www.apgames.se
Advertisement
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

ok thanks yes that was what I was looking for. I´ll try it
Casual game dev www.apgames.se
you could always just recalculate them
with D3DXComputeNormals?
Hm maybe that is better I am making an AI who is supposed to avoid hitting walls and I need to check it every frame
Casual game dev www.apgames.se

This topic is closed to new replies.

Advertisement