Sign in to follow this  

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

This topic is 2662 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[i], &mesh->exBoneOffsets[i], mesh->exFrameCombinedMatrixPointer[i]);
}

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[i]);
m_pD3DDevice->SetTexture(NULL,mc->exTextures[i]);

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
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
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

This topic is 2662 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.

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