Skip to main content
gamedev.net
🔒 Locked

Loading Meshes

Started by Aram 0 replies 650+ views
Original Post
Aram
Aram
Hi! Trying to make a function that loads meshes but there is one part that doesnt seem to work...Maybe you all have some pointers or advice on my funtion too. the function
  
ID3DXMesh* LoadMesh(LPSTR szFileName, D3DMATERIAL8** MATERIAL, LPDIRECT3DTEXTURE8** TEXTURE, DWORD numMATERIALS )
{

	LPD3DXBUFFER			pD3DXMtrlBuffer;
	LPD3DXMESH              tmpMesh;
	D3DMATERIAL8*           tmpMeshMaterials;
	LPDIRECT3DTEXTURE8*     tmpMeshTextures;

    if( FAILED (D3DXLoadMeshFromX( szFileName, D3DXMESH_SYSTEMMEM,
                                   D3dDevice, NULL,
                                   &pD3DXMtrlBuffer, &numMATERIALS,
                                   &tmpMesh ) ) )
	{
		MessageBox(hWndMain, "Failed loading mesh", "D3d Error", MB_OK | MB_ICONEXCLAMATION);
	}

    D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
    tmpMeshMaterials = new D3DMATERIAL8[numMATERIALS];
    tmpMeshTextures  = new LPDIRECT3DTEXTURE8[numMATERIALS];

    for( DWORD i = 0; i < numMATERIALS; i++ )
    {
        tmpMeshMaterials[i] = d3dxMaterials[i].MatD3D;
        tmpMeshMaterials[i].Ambient = tmpMeshMaterials[i].Diffuse;

        if( FAILED ( D3DXCreateTextureFromFile( D3dDevice, d3dxMaterials[i].pTextureFilename,
															&tmpMeshTextures[i] ) ) )
		{
			tmpMeshTextures[i] = NULL;
		}
	}

	*MATERIAL = new D3DMATERIAL8[numMATERIALS];
	*TEXTURE = new LPDIRECT3DTEXTURE8[numMATERIALS];

//This part seems to malfunction, thats what I think anyway...

	for( i = 0; i < numMATERIALS; i++ )
    {
		*MATERIAL[i] = tmpMeshMaterials[i];
		*TEXTURE[i] = tmpMeshTextures[i];
	}

    pD3DXMtrlBuffer->Release();

    return tmpMesh;
}

Thanks

//Aram

  
True words are not always beautiful, beautiful words are not always truthful.
Aram
Aram
Seems as nobody knows...=(
True words are not always beautiful, beautiful words are not always truthful.

Topic Locked

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

Sign in to reply to this topic.