Jump to content
  • Advertisement
Sign in to follow this  
chadmv

*solved* - Independant animation instance with same mesh

This topic is 4842 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'm trying to create multiple instances of the same mesh each with their own independent animation. I have a class CMesh that loads in the .x file with D3DXLoadMeshHierarchyFromX. I then have a class CMeshInstance which takes in a *CMesh and clones the animationcontroller with CloneAnimationController. However, I've found that this isn't enough as my two instances are still connected with the same animation. How can a separate the hierarchy into independent instances all while using the same mesh data? Thanks! -Chad [Edited by - chadmv on August 14, 2005 10:23:14 PM]

Share this post


Link to post
Share on other sites
Advertisement
Surely you taking one or more pointers to the same animation controller means you are sharing it?

ace

Share this post


Link to post
Share on other sites
I would think CloneAnimationController would create a new one but I guess you're right, it just copies it. How can I create a new one if the controller is created during the D3DXLoadMeshHierarchyFromX call but I don't want to have to load in the .x file every time I want a new instance?

Do I also have to duplicate all the frames of the mesh?

Share this post


Link to post
Share on other sites
So is an animation controller created by D3DXLoadMeshHierarchyFromX(). If so, cloning the controller into another one would give you another stand-alone controller right?

I am also assuming that a controller link to a mesh selecting the frames to use, from the mesh?

Also is a controller what use to switch animation frames?

If so, can you not have different controllers at different frames.

Sorry, im just guessing here...

ace

Share this post


Link to post
Share on other sites
Heh, you should probably read the .x file notes over at ToyMaker.info. When you call D3DXLoadMeshHierarchyFromX, you get a pointer to the animation controller corresponding to animation in the .x file.

The frames I'm talking about are not the same as animation frames you'd see in a reel of film. The mesh contains a hierarchy of frames which contain mesh data or child/sibling frames.

The animation controller controls which animation set the mesh should be doing so I was hoping by cloning the controller with CloneAnimationController, I would be able to perform independent animation on 2 instances that use the same mesh. However, it appears that the mesh is still connected to both instances and is controlled by the 2 separate animation controllers. I'm trying to figure out how to separate them.

Anyways, thanks for the help

Share this post


Link to post
Share on other sites
Ok, cool.

Well looking at the SDK it appears you can make an animation controller without a mesh if you know the contents of the mesh, through the function D3DXCreateAnimationController().

So it appears that if you cloned the animation controller and cloned the mesh then you could do what you want.

How exactly do you bring an animation controller and a mesh together at render-time? If you bring them together without them being hard-linked to one another then you could probably do what i was mentioning.

Still guessing...[grin]

ace

Share this post


Link to post
Share on other sites
After a bit of experimentation, I've found that the instances do in fact have independant animation controllers. However the order in which I update the instances each frame affects which instance gets rendered:

m_meshInst.UpdateMesh( fElapsedTime );
m_meshInst2.UpdateMesh( fElapsedTime );
// Only m_meshInst2 will render

If I switch them:
m_meshInst2.UpdateMesh( fElapsedTime );
m_meshInst.UpdateMesh( fElapsedTime );
// Only m_meshInst will render

So, obviously the update calls are updating the same mesh.

Some code:

BOOL CMeshInstance::SetMesh( CMesh *pMesh )
{
m_pMesh = pMesh;

LPD3DXANIMATIONCONTROLLER pAnimController = pMesh->GetAnimController();
pAnimController->CloneAnimationController( pAnimController->GetMaxNumAnimationOutputs(),
pAnimController->GetMaxNumAnimationSets(),
pAnimController->GetMaxNumTracks(),
pAnimController->GetMaxNumEvents(),
&m_pAnimController );

return TRUE;
}

BOOL CMeshInstance::UpdateMesh( float fElapsedTime )
{
if ( m_pAnimController )
{
m_pAnimController->AdvanceTime( fElapsedTime, NULL );
}
UpdateFrameMatrices( m_pMesh->GetFrameRoot(), &m_mWorld );
return TRUE;
}

void CMeshInstance::UpdateFrameMatrices( LPD3DXFRAME pFrameBase, LPD3DXMATRIX pParentMatrix )
{
D3DXFRAME_DERIVED *pFrame = (D3DXFRAME_DERIVED*)pFrameBase;
// Combine with parent matrix if it exists.
if ( pParentMatrix )
{
D3DXMatrixMultiply( &pFrame->CombinedTransformationMatrix, &pFrame->TransformationMatrix, pParentMatrix );
}
else
{
pFrame->CombinedTransformationMatrix = pFrame->TransformationMatrix;
}

// Update the list of siblings.
if ( pFrame->pFrameSibling != NULL )
{
UpdateFrameMatrices( pFrame->pFrameSibling, pParentMatrix );
}

// Update the list of children
if ( pFrame->pFrameFirstChild != NULL )
{
UpdateFrameMatrices( pFrame->pFrameFirstChild, &pFrame->CombinedTransformationMatrix );
}
}






Any suggestions?

Share this post


Link to post
Share on other sites
boy do I feel silly...all I did to make it work was render the meshes right after the update:

m_meshInst.UpdateMesh( fElapsedTime );
m_meshInst.RenderHierarchy( m_graphics.GetD3DDevice() );
m_meshInst2.UpdateMesh( fElapsedTime );
m_meshInst2.RenderHierarchy( m_graphics.GetD3DDevice() );


For any interested, a call to ID3DXAnimationController::AdvanceTime will set that controller's animation to the mesh. So you need to call it between renders of the same mesh.

[Edited by - chadmv on August 14, 2005 10:22:05 PM]

Share this post


Link to post
Share on other sites
I had that problem too: if you clone only the animation controller every time you call its AdvanceTime() function it updates the transforms of the original frame hierarchy (after interpolating keyframe data). So every time such function is called you must call immediately after the rendering function to make use of the just updated transformations. Updating another mesh overwrites the frame matrices.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!