Sign in to follow this  
Dragon_Strike

adding tangents to a model

Recommended Posts

ive loaded a model from an .x file to a LPD3DXMESH using "d3dMesh.h"... however the mesh doesnt have tangents... which could add with the "SetVertexDecl" function... but i have to change the vertex declaration for that... how would i add an entry at the end of the vertex declaration without changing the others?

Share this post


Link to post
Share on other sites
This is the general procedure I use for the rare occasion where I load .X meshes, its basically taken straight from the SDK samples:

-Load the mesh from the .X file
-Check the vertex declaration from the mesh, see if it contains normals/tangents/binormals
-If they're not there, create a new vertex declaration containing all of those things
-Clone the mesh with the new vertex declaration (using ID3DXBaseMesh::CloneMesh)
-If necessary, use D3DXComputeNormals to compute the normals
-If necessary, use D3DXComputeTangentFrame or D3DXComputeTangentFrameEx to compute the tangents and binormals
-Make sure to release the old mesh

I don't remember which sample exactly used this process...I think it was the ParallaxOcclusionMapping sample.

As for adding entries to the old declaration, I would suppose you would loop through the old declaration and copy the entries to your new declaration until you got to the end. Then, you could add an entry to the new declaration at the next index with the Offset set according to the last entry in the old declaration.

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