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