Гружу меш кодом из СДК, основная часть которого приведена ниже, сообственно вопрос, почему при загрузке модели Dwarf из того же СДК, наблюдаеться катастрофическое падение ФПС с 2200 до 150 на довольно неслабой машине. Может кто укажет на пробленый участок кода? Ну и еще вопрос, имеет ли смысл не париться и использовать DXUT, или лучше все писать самому?
HRESULT Mesh::InitGeometry(LPCSTR models, LPDIRECT3DDEVICE9 pDevice)
{
//ResetWindow;
LPD3DXBUFFER pD3DXMtrlBuffer;
// Load the mesh from the specified file
if( FAILED( D3DXLoadMeshFromX(models, D3DXMESH_SYSTEMMEM,
pDevice, NULL,
&pD3DXMtrlBuffer, NULL, &g_dwNumMaterials,
&g_pMesh ) ) )
{
// If model is not in current folder, try parent folder
if( FAILED( D3DXLoadMeshFromX(models, D3DXMESH_SYSTEMMEM,
pDevice, NULL,
&pD3DXMtrlBuffer, NULL, &g_dwNumMaterials,
&g_pMesh ) ) )
{
MessageBox(NULL, «Не найдена модель», «TwinEngine», MB_OK);
return E_FAIL;
}
}
// We need to extract the material properties and texture names from the
// pD3DXMtrlBuffer
D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
g_pMeshMaterials = new D3DMATERIAL9[g_dwNumMaterials];
if( g_pMeshMaterials == NULL )
return E_OUTOFMEMORY;
g_pMeshTextures = new LPDIRECT3DTEXTURE9[g_dwNumMaterials];
if( g_pMeshTextures == NULL )
return E_OUTOFMEMORY;
for( DWORD i=0; i<g_dwNumMaterials; i++ )
{
// Copy the material
g_pMeshMaterials = d3dxMaterials.MatD3D;
// Set the ambient color for the material (D3DX does not do this)
g_pMeshMaterials.Ambient = g_pMeshMaterials.Diffuse;
g_pMeshTextures = NULL;
if( d3dxMaterials.pTextureFilename != NULL &&
lstrlenA(d3dxMaterials.pTextureFilename) > 0 )
{
// Create the texture
if( FAILED( D3DXCreateTextureFromFileA( pDevice,
d3dxMaterials.pTextureFilename,
&g_pMeshTextures ) ) )
{
// If texture is not in current folder, try parent folder
const CHAR* strPrefix = «textures/»;
CHAR strTexture[MAX_PATH];
StringCchCopyA( strTexture, MAX_PATH, strPrefix );
StringCchCatA( strTexture, MAX_PATH, d3dxMaterials.pTextureFilename );
// If texture is not in current folder, try parent folder
if( FAILED( D3DXCreateTextureFromFileA( pDevice,
strTexture,
&g_pMeshTextures ) ) )
{
MessageBox(NULL, «Не найдена текстура», «TwinEngine», MB_OK);
}
}
}
}
// Done with the material buffer
pD3DXMtrlBuffer->Release();
return S_OK;
}

