在DirectX3D程序中加载3DMAX的模型(后缀为.X的文件)

 要想从3DMAX中导出设计好的模型,通常需要自己用3DS Max SDK来创建自己的导出器, 而微软提供了一种导出格式.X,这种格式主要用于DirectX9, Directx10及以后都不支持这种格式。

 

第一步: 导出模型

首先我们需要将模型从3DMAX中导出来,这里推荐Pandasoft  - 将下载的插件放到3DS plugins目录下。这样你就可以在3DMAX中将模型保存成X类型的文件。

 

第二步:加载

我们使用D3DX的Mesh对象和接口。

 

LPD3DXBUFFER materialBuffer;
DWORD        numMaterials;           
LPD3DXMESH   mesh;

HRESULT hr=D3DXLoadMeshFromX(

                             filename,

                             D3DXMESH_SYSTEMMEM,
                             gD3dDevice,

                             NULL,
                             &materialBuffer,

                             NULL,

                             &numMaterials,
                             &mesh

                            );

D3DXMATERIAL* d3dxMaterials       = (D3DXMATERIAL*)materialBuffer->GetBufferPointer();

D3DMATERIAL9 *meshMaterials       = new D3DMATERIAL9[numMaterials];
LPDIRECT3DTEXTURE9 *meshTextures  = new LPDIRECT3DTEXTURE9[numMaterials];

 

第三步:渲染

for (DWORD i=0; i<m_numMaterials; i++)
{
  gD3dDevice->SetMaterial(&meshMaterials[i]);
  gD3dDevice->SetTexture(0,meshTextures[i]);
  m_mesh->DrawSubset( i );
}

for (DWORD i=0; i<m_numMaterials; i++)
{

  •  // 导出Material
     meshMaterials[i] = d3dxMaterials[i].MatD3D;

     // 设置ambient color 

     meshMaterials[i].Ambient = meshMaterials[i].Diffuse;
        
     // 如果有Texture存在,则创建

     meshTextures[i] = NULL;
     if (d3dxMaterials[i].pTextureFilename)
         D3DXCreateTextureFromFile(

                                   gD3dDevice,

                                   d3dxMaterials[i].pTextureFilename,    

                                   &meshTextures[i]

                                  )

}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
包含 for 3DS MAX3 for 3DS MAX4 0 for 3DS MAX4 0+ CS3 1 for 3DS MAX4 2 CS3 2+ or MAX 5 0 for 3DS Max 6 0+ CS4 2 and 3DS Max 7 0 for 3DS Max 8 0 for 3DS Max 9 0 Panda Directx Exporter x64 5 9 67 0 for 3DS Max 9 64 bit Panda Directx Exporter x64 5 2008 67 0 for 3DS Max 2008 64 bit Panda Directx Exporter x64 5 2009 67 0 for 3DS Max 2009 64 bit Panda Directx Exporter x64 6 9 72 0 for 3DS Max 9 64 bit Panda Directx Exporter x64 6 2008 71 0 for 3DS Max 2008 64 bit Panda Directx Exporter x64 6 2009 72 0 for 3DS Max 2009 64 bit Panda Directx Exporter x64 6 2010 72 0 for 3DS Max 2010 64 bit Panda Directx Exporter x64 6 2011 72 0 for 3DS Max 2011 64 bit Panda Directx Exporter x64 6 2012 72 0 for 3DS Max 2012 64 bit Panda Directx Exporter x86 5 8 66 0 for 3DS Max 8 32 bit Panda Directx Exporter x86 5 9 67 0 for 3DS Max 9 32 bit Panda Directx Exporter x86 5 2008 67 0 for 3DS Max 2008 32 bit Panda Directx Exporter x86 5 2009 67 0 for 3DS Max 2009 32 bit Panda Directx Exporter x86 6 9 72 0 for 3DS Max 9 32 bit Panda Directx Exporter x86 6 2008 71 0 for 3DS Max 2008 32 bit Panda Directx Exporter x86 6 2009 72 0 for 3DS Max 2009 32 bit Panda Directx Exporter x86 6 2010 72 0 for 3DS Max 2010 32 bit Panda Directx Exporter x86 6 2011 72 0 for 3DS Max 2011 32 bit Panda Directx Exporter x86 6 2012 72 0 for 3DS Max 2012 32 bit ">包含 for 3DS MAX3 for 3DS MAX4 0 for 3DS MAX4 0+ CS3 1 for 3DS MAX4 2 CS3 2+ or MAX 5 0 for 3DS Max 6 0+ CS4 2 and 3DS Max 7 0 for 3DS Max 8 0 for 3DS Max 9 0 Panda Directx Exporter x64 5 9 67 0 for 3DS Max 9 64 bit Panda Directx Exporter x64 5 2008 67 0 for 3DS Max 2008 64 bit Panda Direc [更多]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值