Sign in to follow this  
peter_b

ID3DXAnimationController problems again

Recommended Posts

peter_b    200
Hello Im having some problem with skinned mesh animations. I have loaded a mesh hierarchy and cloned two new ID3DXAnimationController to use. The problem is that the animation i set for one controller affectes the other, for instance if i set controller nr1 to start playing the run animation, both instance's start playing it.(Or atleast it appears that way). I think this has to do with that the controllers are sharing the same mesh hierarchy, but i cannot figure out what my problem is. I cant find anything that i am doing diffrently from the samples. My code is based on the SkinnedMesh and MultiAnim samples. Every frame i do this: 1. controller->AdvanceTime(); 2. Update the frame matrices (this is what i think messes things up) 3. Draw the mesh hierarchy. I have tried to update all frame's TransformationMatrix to a identity matrix before i call advance time on every controller. This *almost* works, the animations gets independant of each other but instead the entire mesh gets distorted in small intervalls when all the bodyparts are placed on origo. If anyone know a solution to this i would be very greatful, im running out if ideas.. :-( Thanks in advance. Here is my code: the function that updates the frames matrices every tick, the first parent matrix is an identity matrix:
void animation_instance_t::update_frame_matrices(D3DXFRAME* pFrameBase, D3DXMATRIX* pParentMatrix)
	{
		D3DXFRAME_EX *pFrame = (D3DXFRAME_EX*)pFrameBase;

		if(pParentMatrix)
			D3DXMatrixMultiply(&pFrame->CombinedTransformationMatrix, &pFrame->TransformationMatrix, pParentMatrix);
		else
			pFrame->CombinedTransformationMatrix = pFrame->TransformationMatrix;
		if(pFrame->pFrameSibling)
			update_frame_matrices(pFrame->pFrameSibling, pParentMatrix);
		if(pFrame->pFrameFirstChild)
			update_frame_matrices(pFrame->pFrameFirstChild, &pFrame->CombinedTransformationMatrix);
	}

The skinning, called for every mesh container when the hierarchy is drawn, dont think this could be the problem but i post it anyway, u never know:
UINT cBone = pMeshContainer->pSkinInfo->GetNumBones();

			// set up bone transforms
			for(UINT iBone = 0; iBone < cBone; ++iBone)
				D3DXMatrixMultiply(
				&m_multi_animation->m_pBoneMatrices[iBone],
				&pMeshContainer->pBoneOffsetMatrices[iBone],
				pMeshContainer->ppBoneMatrixPtrs[iBone]);
	
			PBYTE       pbVerticesSrc;
			PBYTE       pbVerticesDest;
		
			pMeshContainer->pOrigMesh->LockVertexBuffer(D3DLOCK_READONLY, (LPVOID*)&pbVerticesSrc);
			pMeshContainer->MeshData.pMesh->LockVertexBuffer(0, (LPVOID*)&pbVerticesDest);

			// generate skinned mesh
			pMeshContainer->pSkinInfo->UpdateSkinnedMesh(m_multi_animation->m_pBoneMatrices, NULL, pbVerticesSrc, pbVerticesDest);

			pMeshContainer->pOrigMesh->UnlockVertexBuffer();
			pMeshContainer->MeshData.pMesh->UnlockVertexBuffer();

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