Jump to content
  • Advertisement
Sign in to follow this  
adebacker

Cloning Animations problem

This topic is 4091 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 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));
}

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!