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

Started by
3 comments, last by Denzin 13 years, 7 months ago
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 controllersM->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?
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.
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?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Multiple animation controllers for a single mesh. Cloning the original animation controller among many instances..
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.

This topic is closed to new replies.

Advertisement