Animating x model

Started by
1 comment, last by jpetrie 16 years, 3 months ago
Hi guys! I have a serious problem: i'm able to load a .x file, but i can't understand how to animate it! someone knows how? i tryed using anim->AdvanceTime(time,0); but nothing changes..... heres the code i use to load the model: struct D3DXMESHCONTAINER_DERIVED: public D3DXMESHCONTAINER { LPD3DXMESH pOrigMesh; }; class CMeshHeirarchy : public ID3DXAllocateHierarchy { STDMETHOD( CreateFrame )( THIS_ LPCSTR Name, LPD3DXFRAME *ppNewFrame ); STDMETHOD( CreateMeshContainer )( THIS_ LPCSTR Name, CONST D3DXMESHDATA *pMeshData, CONST D3DXMATERIAL * pMaterials, CONST D3DXEFFECTINSTANCE * pEffectInstances, DWORD NumMaterials, CONST DWORD * pAdjacency, LPD3DXSKININFO pSkinInfo, LPD3DXMESHCONTAINER * ppNewMeshContainer ); STDMETHOD( DestroyFrame )( THIS_ LPD3DXFRAME pFrameToFree ); STDMETHOD( DestroyMeshContainer )( THIS_ LPD3DXMESHCONTAINER pMeshContainerToFree ); }; HRESULT CMeshHeirarchy::CreateFrame(LPCSTR Name, LPD3DXFRAME *ppNewFrame) { D3DXFRAME *frame = new D3DXFRAME; *ppNewFrame=frame; char *nome=new char[strlen(Name)+1]; strcpy(nome,Name); frame->Name=nome; D3DXMatrixIdentity(&frame->TransformationMatrix); frame->pFrameFirstChild=0; frame->pFrameSibling=0; frame->pMeshContainer=0; return D3D_OK; } HRESULT CMeshHeirarchy::CreateMeshContainer( THIS_ LPCSTR Name, CONST D3DXMESHDATA *pMeshData, CONST D3DXMATERIAL * pMaterials, CONST D3DXEFFECTINSTANCE * pEffectInstances, DWORD NumMaterials, CONST DWORD * pAdjacency, LPD3DXSKININFO pSkinInfo, LPD3DXMESHCONTAINER * ppNewMeshContainer ) { UINT NumFaces = pMeshData->pMesh->GetNumFaces(); D3DXMESHCONTAINER_DERIVED *mesh=new D3DXMESHCONTAINER_DERIVED; char *nome=new char[strlen(Name)+1]; strcpy(nome,Name); mesh->Name=nome; mesh->MeshData=*pMeshData; mesh->NumMaterials = 0; //max(1, NumMaterials); mesh->pMaterials = 0; mesh->pAdjacency = new DWORD[NumFaces*3]; memcpy(mesh->pAdjacency, pAdjacency, sizeof(DWORD) * NumFaces*3); if(pSkinInfo) { mesh->pSkinInfo=pSkinInfo; pSkinInfo->AddRef(); } pMeshData->pMesh->AddRef(); (*ppNewMeshContainer)=mesh; return D3D_OK; } HRESULT CMeshHeirarchy::DestroyFrame(LPD3DXFRAME pFrameToFree) { delete pFrameToFree->Name; delete pFrameToFree; return D3D_OK; } HRESULT CMeshHeirarchy::DestroyMeshContainer(LPD3DXMESHCONTAINER pMeshContainerToFree) { pMeshContainerToFree->pSkinInfo->Release(); delete pMeshContainerToFree->Name; delete pMeshContainerToFree; return D3D_OK; } anyone can help me?:(
Advertisement
There's an excellent article here. Also, you might want to read the article on mesh hierarchies (also in that link) before the one on character animation because it covers some of the transformation related material in more detail.
There are examples of X skinning and animation in the SDK samples, as well.

This topic is closed to new replies.

Advertisement