if (SUCCEEDED (D3DXLoadMeshHierarchyFromX(strFilename.c_str(),
D3DXMESH_MANAGED, m_pDevice, &Alloc, NULL, (LPD3DXFRAME *) &m_pFrameRoot, &m_pAnimController)))
{
..........
}
//////////////////////
HRESULT cAllocateHierarchy::CreateMeshContainer(THIS_
LPCSTR Name,
CONST D3DXMESHDATA *pMeshData,
CONST D3DXMATERIAL *pMaterials,
CONST D3DXEFFECTINSTANCE *pEffectInstances,
DWORD NumMaterials,
CONST DWORD *pAdjacency,
LPD3DXSKININFO pSkinInfo,
LPD3DXMESHCONTAINER *ppNewMeshContainer)
{
*ppNewMeshContainer = NULL;
MESHCONTAINER *pMeshContainer = new MESHCONTAINER;
ZeroMemory(pMeshContainer, sizeof(MESHCONTAINER));
LPDIRECT3DDEVICE9 pDevice;
pMeshData->pMesh->GetDevice(&pDevice);
if (Name != NULL)
{
pMeshContainer->Name = new TCHAR[strlen(Name)+1];
strcpy ((char *)pMeshContainer->Name, (const char *)Name);
}
else
{
pMeshContainer->Name = new TCHAR[10];
strcpy ((char *)pMeshContainer->Name, "Unnamed");
}
pMeshContainer->MeshData.Type = D3DXMESHTYPE_MESH;
if (!(pMeshData->pMesh->GetFVF() & D3DFVF_NORMAL))
{
pMeshData->pMesh->CloneMeshFVF( pMeshData->pMesh->GetOptions(),
pMeshData->pMesh->GetFVF() | D3DFVF_NORMAL,
pDevice, &pMeshContainer->MeshData.pMesh );
D3DXComputeNormals ( pMeshContainer->MeshData.pMesh, NULL );
}
else
{
pMeshContainer->MeshData.pMesh = pMeshData->pMesh;
pMeshContainer->MeshData.pMesh->AddRef();
}
DWORD dwNumFaces = pMeshData->pMesh->GetNumFaces();
pMeshContainer->NumMaterials = max (1, NumMaterials);
pMeshContainer->pMaterials = new D3DXMATERIAL[pMeshContainer->NumMaterials];
pMeshContainer->m_ppTextures = new LPDIRECT3DTEXTURE9[pMeshContainer->NumMaterials];
pMeshContainer->pAdjacency = new DWORD[dwNumFaces * 3];
memcpy (pMeshContainer->pAdjacency, pAdjacency, sizeof(DWORD)*dwNumFaces*3);
memset (pMeshContainer->m_ppTextures, 0, sizeof(LPDIRECT3DTEXTURE9) * pMeshContainer->NumMaterials);
if (NumMaterials > 0)
{
memcpy (pMeshContainer->pMaterials, pMaterials, sizeof(D3DXMATERIAL) * NumMaterials);
for (UINT iMaterial = 0; iMaterial < NumMaterials; iMaterial++)
{
if (pMeshContainer->pMaterials[iMaterial].pTextureFilename != NULL)
{
pMeshContainer->pMaterials[iMaterial].pTextureFilename = new char[strlen(pMaterials[iMaterial].pTextureFilename)+1];
strcpy (pMeshContainer->pMaterials[iMaterial].pTextureFilename, pMaterials[iMaterial].pTextureFilename);
}
}
}
else
{
pMeshContainer->pMaterials[0].pTextureFilename = NULL;
memset (&pMeshContainer->pMaterials[0].MatD3D, 0, sizeof(D3DMATERIAL9));
pMeshContainer->pMaterials[0].MatD3D.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
}
if (pSkinInfo != NULL)
{
pMeshContainer->pSkinInfo = pSkinInfo;
pMeshContainer->pSkinInfo->AddRef();
pMeshContainer->m_pOrigMesh = pMeshData->pMesh;
pMeshContainer->m_pOrigMesh->AddRef();
DWORD dwNumBones = pSkinInfo->GetNumBones();
pMeshContainer->m_pBoneOffsetMatrices = new cMatrix4[dwNumBones];
for (DWORD iBone = 0; iBone < dwNumBones; iBone++)
{
pMeshContainer->m_pBoneOffsetMatrices[iBone] = (cMatrix4)(*pMeshContainer->pSkinInfo->GetBoneOffsetMatrix(iBone));
}
}
*ppNewMeshContainer = pMeshContainer;
pMeshContainer = NULL;
pDevice->Release();
pDevice = NULL;
return S_OK;
}
I don't understand why D3DXLoadMeshHierarchyFromX could run successfully,
but MESHCONTAINER and other stuff inside m_pFrameRoot did not get loaded.
I got all ???'s in the watches.
m_pFrameRoot is inherited from D3DXFRAME
Looks really strange.
Another thing is in the viewport,the mesh does come up.
I have fully implemented CreateFrame, CreateMeshContainer and so on..
Any ideas why?
Thanks
Jack
[Edited by - lucky6969b on June 14, 2008 2:00:26 AM]