Skip to main content
GameDev.net gamedev.net
🔒 Locked

Loading Multiple Meshes

Started by akira111 Mar 27, 2009 at 6:27 PM 1 replies 750+ views
Original Post
akira111
akira111
Hi im having some trouble loading more than one mesh with directx. ill show you what ive donefor 1 mesh which is working and maybe you can help me with two. to load the mesh ive ued LPD3DXBUFFER pD3DXMtrlBuffer; if( FAILED(D3DXLoadMeshFromX( "house.x",D3DXMESH_SYSTEMMEM,g_pd3dDevice,NULL,&pD3DXMtrlBuffer, NULL, &g_dwNumMaterials, &g_pMesh))) { if( FAILED(D3DXLoadMeshFromX( "..\\Toyota.x",D3DXMESH_SYSTEMMEM, g_pd3dDevice,NULL, &pD3DXMtrlBuffer, NULL, &g_dwNumMaterials, &g_pMesh))) { return E_FAIL; } } D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer(); g_pMeshMaterials = new D3DMATERIAL9[g_dwNumMaterials]; g_pMeshTextures = new LPDIRECT3DTEXTURE9[g_dwNumMaterials]; for(DWORD i=0; i = d3dxMaterials.MatD3D; g_pMeshMaterials.Ambient = g_pMeshMaterials.Diffuse; g_pMeshMaterials.Diffuse = g_pMeshMaterials.Diffuse; g_pMeshMaterials.Specular = g_pMeshMaterials.Specular; g_pMeshTextures = NULL; if(d3dxMaterials.pTextureFilename != NULL && lstrlen(d3dxMaterials.pTextureFilename)>0) { if(FAILED(D3DXCreateTextureFromFile(g_pd3dDevice, d3dxMaterials.pTextureFilename, &g_pMeshTextures))) { const TCHAR* strPrefix = TEXT("..\\"); const int lenPrefix = lstrlen( strPrefix); TCHAR strTexture[MAX_PATH]; lstrcpyn( strTexture, strPrefix,MAX_PATH); lstrcpyn( strTexture + lenPrefix, d3dxMaterials.pTextureFilename, MAX_PATH - lenPrefix); if(FAILED(D3DXCreateTextureFromFile(g_pd3dDevice, strTexture, &g_pMeshTextures))) { MessageBox(NULL, "Could not find texture map", "Meshes.exe", MB_OK); } } } } // pD3DXMtrlBuffer->Release(); and to render my object im using for( DWORD i=0; iSetMaterial(&g_pMeshMaterials); g_pd3dDevice->SetTexture(0,g_pMeshTextures); //draw mesh subset g_pMesh->DrawSubset(i); } looking at the way ive loaded one meh is anyone able to give some advice on loading two, ive tried a few things but nto working. thanks in advance
akira111
akira111
What ive tried is to add a function to load the 2nd mesh

i call this function after i load the first mesh and release the buffer. but after compiling i get a error at line

g_pd3dDevice->SetTexture(0,g_pMeshTextures);

heres my loadtree function

void loadtree(){

LPD3DXBUFFER ppD3DXMtrlBuffer;

if( FAILED(D3DXLoadMeshFromX( "tree.x",D3DXMESH_SYSTEMMEM,g_pd3dDevice,NULL,&ppD3DXMtrlBuffer, NULL, &g_dwNumMaterials,
&g_pTree)))
{
if( FAILED(D3DXLoadMeshFromX( "..\\tree.x",D3DXMESH_SYSTEMMEM,
g_pd3dDevice,NULL,
&ppD3DXMtrlBuffer, NULL, &g_dwNumMaterials,
&g_pTree)))
{
MessageBox(NULL, "Could not find Toy.x", "BooBall,exe", MB_OK);
// return E_FAIL;
}
}


D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)ppD3DXMtrlBuffer->GetBufferPointer();
g_pTreeMaterials = new D3DMATERIAL9[g_dwSkyNumMaterials];
g_pTreeTextures = new LPDIRECT3DTEXTURE9[g_dwSkyNumMaterials];

for(DWORD i=0; i {
g_pMeshMaterials = d3dxMaterials.MatD3D;

g_pTreeMaterials.Ambient = g_pTreeMaterials.Diffuse;
g_pTreeMaterials.Diffuse = g_pTreeMaterials.Diffuse;
g_pTreeMaterials.Specular = g_pTreeMaterials.Specular;
g_pTreeTextures = NULL;
if(d3dxMaterials.pTextureFilename != NULL && lstrlen(d3dxMaterials.pTextureFilename)>0)
{

if(FAILED(D3DXCreateTextureFromFile(g_pd3dDevice,
d3dxMaterials.pTextureFilename,
&g_pTreeTextures)))
{
const TCHAR* strPrefix = TEXT("..\\");
const int lenPrefix = lstrlen( strPrefix);
TCHAR strTexture[MAX_PATH];
lstrcpyn( strTexture, strPrefix,MAX_PATH);
lstrcpyn( strTexture + lenPrefix, d3dxMaterials.pTextureFilename,
MAX_PATH - lenPrefix);
if(FAILED(D3DXCreateTextureFromFile(g_pd3dDevice,
strTexture,
&g_pTreeTextures)))
{
MessageBox(NULL, "Could not find texture map", "Meshes.exe", MB_OK);
}
}
}
}


ppD3DXMtrlBuffer->Release();

}

havent tried to render the 2nd mesh yet.
akira111
akira111
Found a few mistakes which was stopping my second mesh from loading soive fixed it, mne to gt bth my mse loded and rederingusng the metod i posted.

but what ive notice is with 3 simple models my scene seems alot slower( no animaions but my cmea is vey jerky). is this normal with direct x or is his to do with the way ive loaded and displayed mymeshes.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.