Sign in to follow this  
jeffason

Problem with Software Skinning and Multiple Anim Instances

Recommended Posts

***UPDATE -- READ BOTTOM OF THREAD*** Well, I began writing my animation manager by simply supporting non-skinned animations. Once I had that working I moved on to supporting multiple instances of the same animation for improved performance. Everything was working fine until I added software skinning support. I've been stuck on this problem a while and I'm afraid I don't have much helpful information regarding it.. I just hope that something jumps out at one of you when I describe the problem and you can possible point me in the right direction. Well, here's a scenario: I have two skeletal anim instances on screen, one swings to attack, the others head moves/bobs as if part of the other instances animation is being applied or affecting its own. here's another scenario: I have two pirate anim instances, when one does a swing sword animation the other stays standing still BUT his sword does a very weird motion during the other instances completion of the animation. I've been double checking my code against several examples I've found online, as well as, the MultiAnim example included in the DirectX SDK. If anyone can please help me find this bug/error, please do so! If you'd like to see some of my code segments let me know! Thanks. [Edited by - jeffason on November 5, 2005 10:19:43 AM]

Share this post


Link to post
Share on other sites
A brief description of your implementation could be a bit helpful[grin]

How do you store matrices for model's bones' transformations? Do you always entirely recompute them before applying each instance of animation?

Share this post


Link to post
Share on other sites
Here's some snippets of code.. Let me know if you need to see anything else, Thanks!
struct tD3DXFRAMEex : public D3DXFRAME
{
D3DXMATRIX exCombinedTransformationMatrix;
};

struct tD3DXMESHCONTAINERex : public D3DXMESHCONTAINER
{
IDirect3DTexture9** exTextures; // Array of texture pointers
D3DMATERIAL9* exMaterials; // Array of materials

ID3DXMesh* exSkinMesh; // The skin mesh
D3DXMATRIX* exBoneOffsets; // The bone matrix Offsets, one per bone
D3DXMATRIX** exFrameCombinedMatrixPointer; // Array of frame matrix pointers
};

class CMultiAnim : public CMMBase
{
friend class C3DManager;
friend class CAnimInstance;

private:

LPDIRECT3DDEVICE9 m_pD3DDevice; // our d3d device
std::vector<CAnimInstance*> m_vpAnimInstances; // stores all instances of this animation

D3DXMATRIX *m_pBoneMatrices; // our bones
unsigned int m_uiMaxBones; // max bones for hierarchy

LPD3DXFRAME m_pRootFrame; // root frame of hierarchy, shared between instances
tD3DXMESHCONTAINERex *m_pFirstMesh; // first mesh in the hierarchy
LPD3DXANIMATIONCONTROLLER m_pAC; // ac that all children clone from
unsigned int m_uiNumAnimSets; // number of animation sets
...};

///////////////////////////////////////////////////////////////////
// I THINK THE PROBLEM LIES SOMEWHERE IN HOW I IMPLEMENTED THIS...
void CAnimInstance::AdvanceTime(double dTimeDelta)
{
// apply all the animations to the bones in the frame hierarchy.
if(FAILED(m_pAC->AdvanceTime(dTimeDelta, NULL)))
DEBUG_LOG("Advance time failed");

// update current times
m_dCurGlobalTime += dTimeDelta;

D3DXMATRIX mxIdent;
D3DXMatrixIdentity(&mxIdent);

// apply the animations to the frames
UpdateFrames(m_pMA->m_pRootFrame,&mxIdent);

// If the model contains a skinned mesh update the vertices
tD3DXMESHCONTAINERex* pMesh = m_pMA->m_pFirstMesh;
if(pMesh && pMesh->pSkinInfo)
{
UINT uiBones = pMesh->pSkinInfo->GetNumBones();

for (UINT i = 0; i < uiBones; ++i)
D3DXMatrixMultiply(&m_pMA->m_pBoneMatrices[i],&pMesh->exBoneOffsets[i], pMesh->exFrameCombinedMatrixPointer[i]);

void *srcPtr;
pMesh->MeshData.pMesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&srcPtr);

void *destPtr;
pMesh->exSkinMesh->LockVertexBuffer(0, (void**)&destPtr);

pMesh->pSkinInfo->UpdateSkinnedMesh(m_pMA->m_pBoneMatrices, NULL, srcPtr, destPtr);

pMesh->exSkinMesh->UnlockVertexBuffer();
pMesh->MeshData.pMesh->UnlockVertexBuffer();
}

UpdateFrames(m_pMA->m_pRootFrame,&m_mxWorld);
}

void CAnimInstance::UpdateFrames(D3DXFRAME * pFrame, D3DXMATRIX * pmxBase)
{
tD3DXFRAMEex *pCurFrame = (tD3DXFRAMEex*)pFrame;

if (pmxBase != NULL)
D3DXMatrixMultiply(&pCurFrame->exCombinedTransformationMatrix, &pCurFrame->TransformationMatrix, pmxBase);
else
pCurFrame->exCombinedTransformationMatrix = pCurFrame->TransformationMatrix;

if (pCurFrame->pFrameSibling != NULL)
UpdateFrames(pCurFrame->pFrameSibling, pmxBase);

if (pCurFrame->pFrameFirstChild != NULL)
UpdateFrames(pCurFrame->pFrameFirstChild, &pCurFrame->exCombinedTransformationMatrix);
}

Share this post


Link to post
Share on other sites
Well, I decided to strip the animation system from my game and move it into a test environment. I rewrote most of the core functionality of the system and I'm now at a dead end and can't find my way out.

If someone could please help me I would appreciate it very much.

Currently when I load skinned or non-skinned animations, they seem to load correctly with no problems. I've stepped through all the code in debug and haven't been able to find the fault. When I try to render these animations, I can't see them.

I did have these animations rendering correctly before the changes, but as stated in my first post the instancing was a bit screwy. After the revamp of the system I cannot get anything to display. I looked at the transformation matrices they seem good too.

I think after my changes to the system the instancing might be working, too bad I can't see anything to test.. grr! I'm sure its a stupid mistake on my part, as I am king of those. So, please someone lend me a second pair of eyes!

Here is a test app I created for the purpose of getting help from someone:
http://smitjef.beigetower.org/help/AnimationTest.zip
I tried to clean it up as much as I could and strip any unnecessary code while maintaining cleanliness and readability. There is a ReadMe.txt file included in this .zip that helps explain the architecture of the system, as well as, user input keys.

Thanks a ton for taking time to help me! Please leave feedback on here or e-mail me at jeffason@gmail.com


***NOTE*** I INCLUDED TWO TEST ANIMATIONS(ONE SKINNED, ONE NON-SKINNED) IN THE .ZIP, THIS IS WHY THE SIZE SEEMS BIG.

Share this post


Link to post
Share on other sites
*IF YOU DOWNLOADED THE TEST SCENARIO BEFORE THIS MESSAGE APPEARED, PLEASE GET THE NEWER VERSION..

Sorry if I confused anyone.. I actually introduced a bug while cleaning the code up that caused nonskinned animated meshes to crash the system. Its fixed now. It appears the same problem is affecting both skinned and nonskinned again.

I still need help, if someone could lend me a bit of their time. Thanks everyone!


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