All pastes #437755 Raw Edit

Something

public text v1 · immutable
·published 2007-04-13 07:29 UTC
rendered paste body
#include "Globals.h"


HRESULT LoadD3DMeshNew(
					IDirect3DDevice9* g_pDirect3DDevice,
					DWORD dwNumMaterials,
					LPD3DXMESH pMesh,
					D3DMATERIAL9* pMeshMaterials,
					LPDIRECT3DTEXTURE9* pMeshTextures
					) 
{ 



    LPD3DXBUFFER pD3DXMtrlBuffer; 

	if( FAILED( D3DXLoadMeshFromX( "airplane 2.x", D3DXMESH_SYSTEMMEM, 
            g_pDirect3DDevice, NULL, &pD3DXMtrlBuffer, NULL,
            &dwNumMaterials, &pMesh ) ) )
	
    {
     MessageBox(NULL, "Could not find tiger.x","Meshes.exe", MB_OK);
      return E_FAIL;
    }
	else
	{
   //  MessageBox(NULL, "Loaded tiger.x","Meshes.exe", MB_OK);
      
	}

  // We need to extract the material properties and texture names from the 
 //  pD3DXMtrlBuffer 
   D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer(); 
   pMeshMaterials = new D3DMATERIAL9[dwNumMaterials]; 
   pMeshTextures = new LPDIRECT3DTEXTURE9[dwNumMaterials]; 

    char buf[64];
    sprintf(buf , "%s %d" , "dwNumMaterials is" , dwNumMaterials);
//	MessageBox(NULL, buf,buf, MB_OK);



    for( DWORD i=0; i<dwNumMaterials; i++ ) 
    { 
        // Copy the material 
        pMeshMaterials[i] = d3dxMaterials[i].MatD3D; 

        // Set the ambient color for the material (D3DX does not do this) 
        pMeshMaterials[i].Ambient = pMeshMaterials[i].Diffuse; 

        // Create the texture 
        if( FAILED( D3DXCreateTextureFromFile( g_pDirect3DDevice, 
            d3dxMaterials[i].pTextureFilename, 
            &pMeshTextures[i] ) ) ) 
        { 
            pMeshTextures[i] = NULL; 
        } 
    } 

    // Done with the material buffer 
    pD3DXMtrlBuffer->Release(); 

    return S_OK; 
}