http://hi.baidu.com/zyb_debug/blog/item/f70d834dbd626ff0d62afc0a.html
复习了下mesh,在max上建了个模型,然后在程序中我想看看效果。
半个小时候,我无语了。
3dsmax中的 茶壶
![](http://www.cppblog.com/images/cppblog_com/zybdebug/34cd86318cd9b3b3ab018e7a.jpg)
下面是我程序中的茶壶
![](http://www.cppblog.com/images/cppblog_com/zybdebug/6f051b0363aaa8254afb5141.jpg)
关键代码
1
hr = D3DXLoadMeshFromXA(
2
"teapot.X",
3
D3DXMESH_MANAGED,
4
DXUTGetD3D9Device(),
5
&adjBuffer,
6
&mtrlBuffer,
7
0,
8
&numMtrls,
9
&mesh);
10![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
11
if (FAILED(hr))
12![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
13
::MessageBoxA(0,"load mesh failed",0,0);
14
return false;
15
}
16![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
17![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
18
if (mtrlBuffer != 0 && numMtrls != 0)
19![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
20
D3DXMATERIAL* mtrls = (D3DXMATERIAL*) mtrlBuffer->GetBufferPointer();
21
for(int i = 0;i<numMtrls;i++)
22![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
23
mtrls[i].MatD3D.Ambient = mtrls[i].MatD3D.Diffuse;
24
Mtrls.push_back(mtrls[i].MatD3D);
25
if (mtrls[i].pTextureFilename != 0)
26![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
27
IDirect3DTexture9* tex = 0;
28
HRESULT hr = D3DXCreateTextureFromFileA(
29
DXUTGetD3D9Device(),mtrls[i].pTextureFilename,&tex);
30
Textures.push_back(tex);
31
}
32
else
33![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
34
Textures.push_back(0);
35
}
36![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
37
}
38
}
39![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
40
//render的时候
41![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
42
for (int i = 0;i<Mtrls.size();i++)
43![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
44![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
45
DXUTGetD3D9Device()->SetMaterial(&Mtrls[i]);
46
DXUTGetD3D9Device()->SetTexture(0,Textures[i]);
47![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
48
49
mesh->DrawSubset(i);
50
}
51![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)