Archived

This topic is now archived and is closed to further replies.

getting normals out of vertexbuffer

This topic is 5306 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 vertex buffer from D3DXMesh. I have FVF for it. How do I get normals of this vertex buffer? I want to know offset of normal component in each vertex in buffer. The FVF is not constant, so I have to caclulate offset of normal. How?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Just clone the mesh to a KNOWN FVF, then it will be the same everytime.

Share this post


Link to post
Share on other sites
Hi - even though the FVF will change, the relative position of the normals in the vertex structure will not.

For example, if the FVF flag is D3DFVF_XYZ Or D3DFVF_NORMAL Or D3DFVF_TEX1

Then the structure that holds the vertex definition will look like this:


Type CustomVertex
x as single ''(0-3)
y as single ''(4-7)
z as single ''(8-11)
nx as single ''(12-15)
ny as single ''(16-19)
nz as single ''(20-23)
tu as single ''(24-27)
tv as single ''(28-31)
end type

Since each element takes up four bytes, then you can extract the normals by copying bytes 12-15, 16-19, and 20-23 respectively.

The same would hold true for difference variations on the FVF structure. Although the members of the structure can change, they always have to be in the same relative order (if you declared a structure that put the texture members before the position members, then the structure wouldn''t work correctly).

Once you figure out what elements the FVF structure has, then you can easily figure out where the normal info is stored.

See this page for more information.

Hope this helps-

BM

Share this post


Link to post
Share on other sites