Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

D3DXLoadHierarchyFromX

This topic is 3661 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

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]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
MESHCONTAINER and other stuff inside m_pFrameRoot did not get loaded.
I got all ???'s in the watches.

How do you know the mesh container did not get loaded?

Did you expand the watch tree to look at individual values? Did you test the value in some other way?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!