MultiAnim sdk sample and the "Wave" anim

Started by
3 comments, last by peter_b 19 years, 4 months ago
Must.. stop.. crying... ..... .... There, just comming back from spending 2 days of my life trying to get multiple animations working using the same D3DXFRAME hierarchy. It was a problem without solution tough, i got it to work as far as the sdk sample does. However the "Wave" animation in tiny_4anim.x never wanted to work, it wouldnt display correctly since only the arm was animated not the rest of the body (in the other animation sets the whole body is animated). Same thing happend when an animation was stopped. I spent alot of time trying to get this to work and was on the brink of insanity. But i was like, "Hey, it works in the sdk sample, there must be a way.". But! It turns out there is not, the sdk sample will show the same bug, the truth is that the wave animation is never displayed in the sample, and tiny is always animating. Damn bastards, there could have been a note or something. Damnit! I just assumed the sdk sample was working as intended. This post is as much to be informative for people in the future who might search for it as it is for my question: Is there a way to share the D3DXFRAME hierarchy between multiple animation controllers? Since they support cloning, one would think thats the intention, but they all write to the original D3DXFRAME and interfer with eachother, "hacks" can solve this to the point when you want to render the D3DXFRAME hierachy when no animation is running, then it hits the wall. Im clueless. There must be a way. Help.. Please...
Shields up! Rrrrred alert!
Advertisement
To answer your question as it is phrased, there isn't a way NOT to. All aniumation controllers HAVE to share their frame hierarchy.

To answer what I think you're trying to ask (how to get multiple animations to affect a single body), there is. Look up the track functions in ID3DXAnimationController and play with them. Look in the MultiAnimation sample for some good stuff on using them.
Quote:Original post by Karl G
To answer your question as it is phrased, there isn't a way NOT to. All aniumation controllers HAVE to share their frame hierarchy.

To answer what I think you're trying to ask (how to get multiple animations to affect a single body), there is. Look up the track functions in ID3DXAnimationController and play with them. Look in the MultiAnimation sample for some good stuff on using them.


Thanks for your anwser, im sorry i worded my post badly, i was very frustrated at the time.

I will try again, this is what is my problem:
When multiple animation controllers share the same frame hierarchy there becomes complications when some of the frames dont have animation data. For instance, in the "Wave" animation of tiny_4anim.x only the left arm has animation data, not the rest of the body. An other example is if all tracks are stopped.

What will happen when something isnt animating is that it wont show up, im guessing that this is because the transformation matrix in each frame gets filled with junk by the previous animation controllers AdvanceTime() call. The thing is, there dosnt seem to be a solution (other than always animaiting everything, like having an "idle" anim when standing still)

Try yourself to switch the string "Loiter" or "Walk" to "Wave" in the MultiAnim sample(it's in 2 places so search for it). It dosnt work there either. Either that or try to stop all animation tracks, the mesh will go *poof*, i guess this is because all parts are translated way off screen.

Anyhow, iv tried to recursivly update all frame's transformation matrices to identity matrices after each draw. The only thing this does is that when something isnt animated it is drawn around origo instead of not showing up, so there must be some transformation data in the matrices which is nessecery, but i cant figureout a way to get to it.

But iv come up with a solution i think, im gonna try to clone the entire frame hierarchy so that each controller can have its own set of matrices. MeshContainers and meshes can still be shared, its only the matrices that needs to be cloned.
Il post how it goes when im done with it (incase anyone in the future have this problem).
Shields up! Rrrrred alert!
Thanks for the info. I was wondering why WAVE animation would cause the tiny to disappear. It used to work fine when I blended it with other animations like Walk, Jog and Loiter.
ok iv gotten it to work now so il post how.

I ended up cloning the frame hierarchy for each animation controller. Maybe not what you want to do, but i couldnt find another way atleast.. The mesh data is still shared so its only really the transformation matrices and a few pointers that are cloned with each controller.




Anyhow this is the cloning:

//-----------------------------------------------------------------------------	// Name: clone_frame_hierarchy	// Desc: clones a frame hierarchy	//-----------------------------------------------------------------------------	void animation_instance_t::clone_frame_hierarchy(D3DXFRAME* pFrameSrc, D3DXFRAME** pFrameDest)	{		if(pFrameSrc)		{			(*pFrameDest) = new D3DXFRAME_EX;			*(D3DXFRAME_EX*)(*pFrameDest) = *(D3DXFRAME_EX*)pFrameSrc;			if(pFrameSrc->pMeshContainer)			{				(*pFrameDest)->pMeshContainer = new D3DXMESHCONTAINER_EX;				*(D3DXMESHCONTAINER_EX*)(*pFrameDest)->pMeshContainer = *(D3DXMESHCONTAINER_EX*)pFrameSrc->pMeshContainer;			}				}		else			(*pFrameDest) = 0;		if(pFrameSrc->pFrameSibling)			clone_frame_hierarchy(pFrameSrc->pFrameSibling, &(*pFrameDest)->pFrameSibling);		else			(*pFrameDest)->pFrameSibling = 0;		if(pFrameSrc->pFrameFirstChild)			clone_frame_hierarchy(pFrameSrc->pFrameFirstChild, &(*pFrameDest)->pFrameFirstChild);			else			(*pFrameDest)->pFrameFirstChild = 0;	}//-----------------------------------------------------------------------------	// Name: delete_frame_hierarchy	// Desc: Deletes a frame hierarchy	//-----------------------------------------------------------------------------	void animation_instance_t::free_frame_hierarchy(D3DXFRAME* pFrame)	{		if(!pFrame)			return;		if(pFrame->pFrameSibling)			free_frame_hierarchy(pFrame->pFrameSibling);		if(pFrame->pFrameFirstChild)			free_frame_hierarchy(pFrame->pFrameFirstChild);		if(pFrame->pMeshContainer)		{			delete [] ((D3DXMESHCONTAINER_EX*)pFrame->pMeshContainer)->ppBoneMatrixPtrs;			delete pFrame->pMeshContainer;			}		delete pFrame;	}



when cloning, do this:
if(m_pAnimController)			if(FAILED(hr = m_pAnimController->CloneAnimationController( m_pAnimController->GetMaxNumAnimationOutputs(),				m_pAnimController->GetMaxNumAnimationSets(),				m_pAnimController->GetMaxNumTracks(),				m_pAnimController->GetMaxNumEvents(),				&animation_instance->m_pAnimController)))				logprintf(LOG_FILE, "Error: %s\nLine: %d\nFile: %s", DXGetErrorString9(hr), __LINE__, __FILE__);		// clone the frame hierarchy so the animation instances dont mess with the original matrices.		// the instances still share the mesh data.		animation_instance->clone_frame_hierarchy(m_pFrameRoot, &animation_instance->m_pFrameRoot);		// setup matrices		if(FAILED(hr = animation_instance->setup_bone_matrix_pointers(animation_instance->m_pFrameRoot)))			logprintf(LOG_FILE, "Error: %s\nLine: %d\nFile: %s", DXGetErrorString9(hr), __LINE__, __FILE__);		// switch frame hierarchy to work on		hr = D3DXFrameRegisterNamedMatrices(animation_instance->m_pFrameRoot, animation_instance->m_pAnimController);


This works. No animations interfer with eachother, and they can be renderd when they have no animation data aswell. Doing it like this is actually somewhat mentioned in the dx sdk document for the MultiAnim sample.


From dx multianim docs:
Quote:
Because all instances of Tiny share the same frame hierarchy matrices, the sample must advance time on a specific instance and render it before moving on to another instance. Generally, this does not present a problem. However, if an application wishes to update the matrices for all of the instances first then render them, it can make new animation controllers point to a different set of matrices when cloning. This way, each animation controller has its own set of matrices to work with, and overwriting will not occur, at the expense of more memory usage.


Hope this helps someone sometime..
Shields up! Rrrrred alert!

This topic is closed to new replies.

Advertisement