Jump to content
  • Advertisement
Sign in to follow this  
ktuluorion

Still searching for something that makes sense (Animated Mesh)

This topic is 4790 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

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
Advertisement
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 MESHTOOL
{
struct VERTEX { D3DXVECTOR3 p, n; FLOAT tu, tv; }; // Same as a Vertex
LPDIRECT3DVERTEXBUFFER9 pVB;
DWORD dwNumVertices;
VERTEX* pVertices;
MESHTOOL( LPD3DXMESH pMesh )
{
pMesh->GetVertexBuffer( &pVB );
pVB->Lock( 0, 0, (VOID**)&pVertices, 0 );
dwNumVertices= pMesh->GetNumVertices();
}
~MESHTOOL()
{
pVB->Unlock();
pVB->Release();
}
};


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.p = fWeight1*src1.pVertices.p +
fWeight2*src2.pVertices.p;
dest.pVertices.n = fWeight1*src1.pVertices.n +
fWeight2*src2.pVertices.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.

-Greytone

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!