Sign in to follow this  

Still searching for something that makes sense (Animated Mesh)

Recommended Posts

Does anybody have a simple tutorial for loading and using animated meshes? It is driving me crazy trying to find something that just shows the bare bones code needed to do so, and explains it in a way that is understandable. If anyone can point me in a good direction, i'd appreciate it. Oh, i'm using DX9. Thanks!

Share this post

Link to post
Share on other sites
I don't have a nice tutorial for you, but if you are using DirectX meshes here is some simple code for Tweening between two meshes.

//this handy structure locks the vertex buffer and then makes it avalable for changing,
//useing it for mesh tweening //borrowed from a directx sdk example.
struct VERTEX { D3DXVECTOR3 p, n; FLOAT tu, tv; }; // Same as a Vertex
DWORD dwNumVertices;
VERTEX* pVertices;
pMesh->GetVertexBuffer( &pVB );
pVB->Lock( 0, 0, (VOID**)&pVertices, 0 );
dwNumVertices= pMesh->GetNumVertices();

LPD3DXMESH tweenedMesh;
LPD3DXMESH mesh_one;
LPD3DXMESH mesh_two;

void BlendMeshes(FLOAT fWeight)
// Build convenient objects to access the mesh vertices
MESHTOOL dest( tweenedMesh );
MESHTOOL src2( mesh_one );
MESHTOOL src1( mesh_two );

// The blending factors
FLOAT fWeight1 = fabsf(fWeight);
FLOAT fWeight2 = 1.0f - fWeight1;
// LERP positions and normals
for( DWORD i=0; i<dest.dwNumVertices; i++ )
dest.pVertices[i].p = fWeight1*src1.pVertices[i].p +
dest.pVertices[i].n = fWeight1*src1.pVertices[i].n +

The basic idea is mesh_one and mesh_two are keyframe meshes, and the tweenedMesh is a calculated in-between mesh. The weight value determines how each key frame is weighted in calculating the tweened mesh. 0.0 being entirely mesh_one and 1.0 being entirely mesh_two.

I have found the tweening animation method is easyer to understand than the boned methods. Of course it does have its limitations but it should be an easy place to start.


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