Cloning Animations problem

Started by
5 comments, last by adebacker 16 years, 6 months ago
I have been trying to clone meshes with animations so we do not have to load from file everytime we want a new model. I have gotten it to clone the models but it does not animate at all. Does anyone have any ideas how to fix it?

void LPGModel::Clone(LPGModel * _pModel)
{
	*this = *_pModel;

	CloneFrames((LPFRAME)_pModel->m_lpRootFrame, (LPFRAME*)&m_lpRootFrame);

	_pModel->m_lpAnimControl->CloneAnimationController(_pModel->m_lpAnimControl->GetMaxNumAnimationOutputs(), _pModel->m_lpAnimControl->GetMaxNumAnimationSets(), 
		_pModel->m_lpAnimControl->GetMaxNumTracks(), _pModel->m_lpAnimControl->GetMaxNumEvents(), &(m_lpAnimControl));

	m_lpBones = new D3DXMATRIX[m_unMaxNumBones];
	ZeroMemory(m_lpBones, sizeof(D3DXMATRIX) * m_unMaxNumBones);

	HRESULT hr = D3DXFrameRegisterNamedMatrices(m_lpRootFrame, m_lpAnimControl);

	SetBoneMatrices((LPFRAME)m_lpRootFrame, NULL, m_lpD3DDevice);
}

void LPGModel::CloneFrames(LPFRAME _lpFrame, LPFRAME* _lpCFrame)
{
	if (!_lpFrame)
		return;

	*_lpCFrame = new _D3DXFRAME_DERIVED;
	**_lpCFrame = *_lpFrame;
	(*_lpCFrame)->Name = new char[256];
	strcpy((*_lpCFrame)->Name, _lpFrame->Name);
	
	CloneMesh((LPMESHCONTAINER)_lpFrame->pMeshContainer, (LPMESHCONTAINER *)&((*_lpCFrame)->pMeshContainer));

	CloneFrames((LPFRAME)_lpFrame->pFrameSibling, (LPFRAME*)&((*_lpCFrame)->pFrameSibling));
	CloneFrames((LPFRAME)_lpFrame->pFrameFirstChild, (LPFRAME*)&((*_lpCFrame)->pFrameFirstChild));
}

void LPGModel::CloneMesh(LPMESHCONTAINER _lpSrcMesh, LPMESHCONTAINER* _lppDestMesh)
{
	if (!_lpSrcMesh)
		return;

	LPGCreateHierarchy hier;
	hier.CreateMeshContainer(_lpSrcMesh->Name, &_lpSrcMesh->MeshData, NULL, _lpSrcMesh->pEffects, _lpSrcMesh->NumMaterials,
		_lpSrcMesh->pAdjacency, _lpSrcMesh->pSkinInfo, (LPD3DXMESHCONTAINER*)_lppDestMesh);

	for (int i = 0; i < _lpSrcMesh->NumMaterials; ++i)
	{
		(*_lppDestMesh)->m_pMaterials = _lpSrcMesh->m_pMaterials;
		(*_lppDestMesh)->m_lpTextures = _lpSrcMesh->m_lpTextures;
	}

	CloneMesh((LPMESHCONTAINER)_lpSrcMesh->pNextMeshContainer, (LPMESHCONTAINER *)&((*_lppDestMesh)->pNextMeshContainer));
}

Advertisement
How are you setting the animation sets on the original controller? That seems to be the missing element here.

My free book on Direct3D: "The Direct3D Graphics Pipeline"
My blog on programming, vintage computing, music, politics, etc.: Legalize Adulthood!

This doesn't answer your question, but are you sure you need to clone the mesh? Unless you are planning on modifying the mesh itself, you can achieve this effect by rendering the same mesh several times, applying different transformations. The ID3DXAnimationController is happy to be fed many sets of tracks and weights per frame. This way, you'd save yourself some video memory and possibly some VPU performance in the form of page-faults (if that ever were a problem [rolleyes]).

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
If I do not clone the animations the animations all play at the same time they all animate the same way if you get my drift. But if I clone the meshes the animations do not play at all.
Quote:Original post by adebacker
If I do not clone the animations the animations all play at the same time they all animate the same way if you get my drift.
This isn't the case. In have, right in front of me, a Direct3D application with one mesh instance containing one collection of animation-sets, that supports arbitrarily many asynchronous animations.

Just in the same way you may call ID3DXMesh::DrawSubset several times per frame with different transformation's set, it is possible to call ID3DXAminationController::SetTrackWeight, ID3DXAminationController::SetTrackAnimationSet, ID3DXAminationController::SetTrackPosition and ID3DXAminationController::AdvanceTime many times. The only extra work you have to do is keep track of the track weights and positions for each instance.

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
Quote:Original post by TheAdmiral
Quote:Original post by adebacker
If I do not clone the animations the animations all play at the same time they all animate the same way if you get my drift.
This isn't the case. In have, right in front of me, a Direct3D application with one mesh instance containing one collection of animation-sets, that supports arbitrarily many asynchronous animations.

Just in the same way you may call ID3DXMesh::DrawSubset several times per frame with different transformation's set, it is possible to call ID3DXAminationController::SetTrackWeight, ID3DXAminationController::SetTrackAnimationSet, ID3DXAminationController::SetTrackPosition and ID3DXAminationController::AdvanceTime many times. The only extra work you have to do is keep track of the track weights and positions for each instance.

Admiral


Really? Well I will give that a try, in all my searching around on the web I have never heard this. All the tutorials I have read said you have to clone the frames and one showed cloning the meshes.

Thanks for all the help, I got it to work and now I can move on to other problems.

This topic is closed to new replies.

Advertisement