Jump to content
  • Advertisement
Sign in to follow this  
Denzin

Instances of skinned mesh's animating the same Dx9.0 c++

This topic is 2972 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'm still having an unnaturally hard time separating animation from the mesh object. Its at the point when one instance triggers an animation state, the rest follow it.

to set the skinned mesh to its instance it

skinnedMesh = sM;

//clone the anim controller
sM->CopyAnim(&animationController);

for(DWORD i = 0; i < animationController->GetMaxNumTracks(); ++i)
{
animationController->SetTrackEnable(i, false);
}

numAnimationSets = animationController->GetMaxNumAnimationSets();

maxBones = sM->MaxBones();

boneMatrices = new D3DXMATRIX[maxBones];



at each update the instances simply

currentTime += dT;

elapsedTime = dT;



then for the render each instance gets queued into the renderer and..

if(animationController)
animationController->AdvanceTime(elapsedTime, NULL);

skinnedMesh->UpdateFrameMatrices(NULL, worldMat);

sD3DXMeshContainerEx* mesh = skinnedMesh->FirstMesh();

if(mesh && mesh->pSkinInfo)
{
unsigned bones = mesh->pSkinInfo->GetNumBones();

for(unsigned i = 0; i < bones; ++i)
{
D3DXMatrixMultiply(&boneMatrices, &mesh->exBoneOffsets, mesh->exFrameCombinedMatrixPointer);
}

void* source = NULL;
void* dest = NULL;

mesh->MeshData.pMesh->LockVertexBuffer(D3DLOCK_READONLY,&source);
mesh->exSkinMesh->LockVertexBuffer(0,&dest);
mesh->pSkinInfo->UpdateSkinnedMesh(boneMatrices, NULL, source, dest);

mesh->MeshData.pMesh->UnlockVertexBuffer();
mesh->exSkinMesh->UnlockVertexBuffer();
}




DrawFrame(sFrameEx* frame)
{
if(frame->pMeshContainer)
DrawMeshFrame(frame);

if(frame->pFrameSibling)
DrawFrame((sFrameEx*)frame->pFrameSibling);
if(frame->pFrameFirstChild)
DrawFrame((sFrameEx*)frame->pFrameFirstChild);
}



void DrawMeshFrame(sFrameEx* frame)
{
sD3DXMeshContainerEx* mc = (sD3DXMeshContainerEx*)frame->pMeshContainer;

m_pD3DDevice->SetTransform(D3DTS_WORLD, &frame->exCombinedTransformationMatrix);

for(unsigned i = 0; i < mc->NumMaterials; ++i)
{
m_pD3DDevice->SetMaterial(&mc->exMaterials);
m_pD3DDevice->SetTexture(NULL,mc->exTextures);

LPD3DXMESH pDrawMesh = (mc->pSkinInfo) ? mc->exSkinMesh : mc->MeshData.pMesh;

pDrawMesh->DrawSubset(i);
}

}



so every time the instance gets rendered it re skins the mesh for its bone matrices then draws it. however animations still are shown on all instances.
Anything i'm missing?

Share this post


Link to post
Share on other sites
Advertisement
I've had this problem as well and couldn't figure it out so I ended up copying the frame and creating new matrices for it. It might not be what you are after but it could save you some headache at the cost of a little memory.

Share this post


Link to post
Share on other sites
Quote:
I'm still having an unnaturally hard time separating animation from the mesh object.

It's not clear exactly what you're trying to do. Are you trying to use one animation controller for different meshes? An animation controller has a pointer to the frame hierarchy for the mesh with which it was created. That's how it updates the transformation matrix for each bone when you call AdvanceTime.

Are you somehow changing that pointer?

Share this post


Link to post
Share on other sites
Multiple animation controllers for a single mesh. Cloning the original animation controller among many instances..

Share this post


Link to post
Share on other sites
Issue has been resolved. It had nothing to do with the code, just the fact the model I was using only had one animation state. With models with multiple states, its fine, all instances get triggered to the single state if there is only one.

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!