问DirectX里如何把载入X文件封装成一个函数
代码太多了。。如果载入一个X文件就写一次代码太长。。想封装成一个函数。。各位高手帮帮忙
//载入部分
bool XSetup(ID3DXMesh* objMesh,
std::vector<D3DMATERIAL9> objMtrls,
std::vector<IDirect3DTexture9*> objTextures,
HRESULT objhr,
ID3DXBuffer* objadjBuffer,ID3DXBuffer* objmtrlBuffer,DWORD objnumMtrls,
LPCTSTR pFilename)
{
objhr = 0;
objadjBuffer = 0;
objmtrlBuffer = 0;
objnumMtrls = 0;
objhr = D3DXLoadMeshFromX(
pFilename,
D3DXMESH_MANAGED,
Device,
&objadjBuffer,
&objmtrlBuffer,
0,
&objnumMtrls,
&objMesh);
if(FAILED(objhr))
{
::MessageBox(0, "D3DXLoadMeshFromX() - FAILED", 0, 0);
return false;
}
if( objmtrlBuffer != 0 && objnumMtrls != 0 )
{
D3DXMATERIAL* objmtrls = (D3DXMATERIAL*)objmtrlBuffer->GetBufferPointer();
for(int i = 0; i < objnumMtrls; i++)
{
// the MatD3D property doesn't have an ambient value set
// when its loaded, so set it now:
objmtrls[i].MatD3D.Ambient = objmtrls[i].MatD3D.Diffuse;
// save the ith material
objMtrls.push_back( objmtrls[i].MatD3D );
// check if the ith material has an associative texture
if( objmtrls[i].pTextureFilename != 0 )
{
// yes, load the texture for the ith subset
IDirect3DTexture9* tex = 0;
D3DXCreateTextureFromFile(
Device,
objmtrls[i].pTextureFilename,
&tex);
// save the loaded texture
objTextures.push_back( tex );
}
else
{
// no texture for the ith subset
objTextures.push_back( 0 );
}
}
}
d3d::Release<ID3DXBuffer*>(objmtrlBuffer); // done w/ buffer
objhr = objMesh->OptimizeInplace(
D3DXMESHOPT_ATTRSORT |
D3DXMESHOPT_COMPACT |
D3DXMESHOPT_VERTEXCACHE,
(DWORD*)objadjBuffer->GetBufferPointer(),
0, 0, 0);
d3d::Release<ID3DXBuffer*>(objadjBuffer); // done w/ buffer
}
//显示
void RenderOBJ()
{
for(int i = 0; i < objMtrls.size(); i++)
{
Device->SetMaterial( &objMtrls[i] );
Device->SetTexture(0, objTextures[i]);
objMesh->DrawSubset(i);
}
}
但是这两个函数如何关联起来。。。不要用友元。。。
[解决办法]
http://www.xbdev.net/3dformats/x/xfileformat.php
这里 有.x file model loader
你下载看看人家怎么写的。