将网格从 .obj(或任何其他)文件加载到 DirectX9/C++项目
目前我有一个通过书写坐标绘制的 3D 立方体,它可以在黑屏上旋转和移动。 现在我有一个在“3Ds Max”中创建的模型(这是一个有高高石墙的小后院,所以我尝试将它用作我的世界对象。)我想将此模型加载到我的 DirectX9/C++ 项目中。 据我在 DirectX SDK 示例中看到,此代码用于加载 .X 模型(需要一个“3Ds Max”插件来导出此类扩展。我'我不确定这一点。)
将 .X 文件加载到 DX9/C++ 中的代码:
D3DXLoadMeshFromX( "Tiger.x", D3DXMESH_SYSTEMMEM,
g_pd3dDevice, NULL, &pD3DXMtrlBuffer, NULL,
&g_dwNumMaterials, &g_pMesh )
是否有类似 "D3DXLoadMeshFromOBJ(.....)" 的函数来加载目的?如何加载和渲染 .OBJ 文件? 8(
我的另一个问题是 .X 文件和 .OBJ 文件之间有什么区别,我应该使用它们中的哪一个?
Currently I have a 3D Cube that I drew by writing coordinates, that can rotate and move on a black screen.
Now I have a Model that I created in "3Ds Max"(It's a little backyard with high stonewalls, so I'm trying to use it as my world object.) and I want to load this model into my DirectX9/C++ project.
As far as I see in DirectX SDK examples this code is for loading .X model (which needs a plugin for "3Ds Max" to export that kind of extension. I'm not sure of this.)
Code for loading .X files into DX9/C++:
D3DXLoadMeshFromX( "Tiger.x", D3DXMESH_SYSTEMMEM,
g_pd3dDevice, NULL, &pD3DXMtrlBuffer, NULL,
&g_dwNumMaterials, &g_pMesh )
Is there a function like "D3DXLoadMeshFromOBJ(.....)" to load an Object? How do I load and render .OBJ files? 8(
Another question of mine is what is the difference between an .X file and an .OBJ file and which of them should I use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AFAIK,DirectX 不支持开箱即用的波前对象文件。为此,您将需要一个外部网格加载器。
我记得,在DX 10 SDK中有一个如何加载.obj文件的示例,我认为该示例称为MeshFromOBJ10。我不知道它在 DirectX 9 中是否有任何用处。
据我所知,标准 .x 仅支持基本网格,没有动画等增强功能。如果您想尝试图形编程,这还不错,但如果您的目标是更高的概念,您可以稍后切换。我想您可以在此处查找 .obj 文件的优点。
为您正在使用的输入数据创建抽象总是一个好主意。例如,您可以创建一个
AbstractMesh
类和一个从它派生的实现XMesh
。稍后,您可以添加其他实现,例如 OBJMesh 或类似的东西。我希望我能帮到你一点:) 快乐编码!
AFAIK, DirectX does not support wavefront object files out of the box. You will need an external mesh loader for that purpose.
I can remember, that in the DX 10 SDK is a sample of how to load an .obj file, I think the sample is called MeshFromOBJ10. I don't know if it is of any use in DirectX 9.
As far as I know, the standard .x just supports basic meshes with no enhancements such as animation. If you want to try out graphical programming it is not bad, but if you are aiming for higher concepts you can later switch. I guess you can look up the advantages of the .obj files here.
It is always a good idea to create an abstraction for the input data you are using. For example, you could create a class
AbstractMesh
and an implementationXMesh
deriving from it. Later on, you can than add other implementations likeOBJMesh
or anything similar.I hope I could help you a bit :) Happy Coding!
动画完全支持 x 文件格式,此外,当您想使用着色器时,它还支持 fx 文件。您可以从此页面下载导出器插件和示例:
http://www.cgdev.net/download.php
Animation is full supported in x file format, and furthermore, it support fx files when you want to use shaders. A exporter plugin and samples you can download from this page:
http://www.cgdev.net/download.php