to set the skinned mesh to its instance it
skinnedMesh = sM;//clone the anim controllersM->CopyAnim(&animationController);for(DWORD i = 0; i < animationController->GetMaxNumTracks(); ++i){ animationController->SetTrackEnable(i, false);}numAnimationSets = animationController->GetMaxNumAnimationSets();maxBones = sM->MaxBones();boneMatrices = new D3DXMATRIX[maxBones];
at each update the instances simply
currentTime += dT;elapsedTime = dT;
then for the render each instance gets queued into the renderer and..
if(animationController) animationController->AdvanceTime(elapsedTime, NULL); skinnedMesh->UpdateFrameMatrices(NULL, worldMat); sD3DXMeshContainerEx* mesh = skinnedMesh->FirstMesh(); if(mesh && mesh->pSkinInfo) { unsigned bones = mesh->pSkinInfo->GetNumBones(); for(unsigned i = 0; i < bones; ++i) { D3DXMatrixMultiply(&boneMatrices, &mesh->exBoneOffsets, mesh->exFrameCombinedMatrixPointer); } void* source = NULL; void* dest = NULL; mesh->MeshData.pMesh->LockVertexBuffer(D3DLOCK_READONLY,&source); mesh->exSkinMesh->LockVertexBuffer(0,&dest); mesh->pSkinInfo->UpdateSkinnedMesh(boneMatrices, NULL, source, dest); mesh->MeshData.pMesh->UnlockVertexBuffer(); mesh->exSkinMesh->UnlockVertexBuffer(); }
DrawFrame(sFrameEx* frame){ if(frame->pMeshContainer) DrawMeshFrame(frame); if(frame->pFrameSibling) DrawFrame((sFrameEx*)frame->pFrameSibling); if(frame->pFrameFirstChild) DrawFrame((sFrameEx*)frame->pFrameFirstChild);}
void DrawMeshFrame(sFrameEx* frame) { sD3DXMeshContainerEx* mc = (sD3DXMeshContainerEx*)frame->pMeshContainer; m_pD3DDevice->SetTransform(D3DTS_WORLD, &frame->exCombinedTransformationMatrix); for(unsigned i = 0; i < mc->NumMaterials; ++i) { m_pD3DDevice->SetMaterial(&mc->exMaterials); m_pD3DDevice->SetTexture(NULL,mc->exTextures); LPD3DXMESH pDrawMesh = (mc->pSkinInfo) ? mc->exSkinMesh : mc->MeshData.pMesh; pDrawMesh->DrawSubset(i); } }
so every time the instance gets rendered it re skins the mesh for its bone matrices then draws it. however animations still are shown on all instances.
Anything i'm missing?