开发者

Loading meshes from .obj (or any other) File into DirectX9/C++ project

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"(I开发者_运维问答t'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?


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 implementation XMesh deriving from it. Later on, you can than add other implementations like OBJMesh or anything similar.

I hope I could help you a bit :) Happy Coding!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜