DirectX Load 3D Model

Started by
7 comments, last by GameDev.net 18 years, 1 month ago
Ok I've been looking for a while and just can't seem to find this. I'm looking for a tutorial that * uses Visual Studio .NET (C plus plus, it won't let me display simbols) * has source code that isn't completely bloated * can load and display a simple 3D object in Direct3D Nothing else please, no animations, no motion blur, no super awesome lighting effects. I've been trying to read the DirectX SDK tutorials and I want to rip my hair out. Basically I'm looking for a Direct3D version of the NeHe "Lesson 10". http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=10 Please someone help me out here. I want to get back into programming and every time I try to start up I just get overwhelmed and completely lose interest. Thanks in advance.
Advertisement
I believe that if you want to open a .X model file all you need to do is load up the D3DXLibrary (which should already be included in your DirectX library) and then call the LoadMesh function.
Viola - you're done loading a mesh WITH animations, complex lighting, and material data - and you had to use one line of code to do it.

Isn't D3DX great?
I definitely understand your frustration since I went through the same thing regarding .X files when I was writing my game over a year ago for my final year's project. Unfortunately if you can't go through the DX SDK examples there's really not much else out there for loading .X file formats but your second best bet is to look at the source code for the .X file viewer included with the SDK to get you going but again you're going to have to search through bloated code. Lookup D3DXLoadMeshFromX in the SDK documentation...this is how you load in geometry, etc. from a .X file and get your mesh loaded. From there you should be able to step through the SDK documentation to find the methods you need to render (DrawSubset( x ) if I remember correctly), etc.

EDIT:

Here's a link to the online documentation so you know what you're looking for :)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/d3dxloadmeshfromx.asp

and a quick example:

ID3DXMesh* pMesh = 0;// very basic load method, read doc regarding parameters, would take too// long to explain them all here :)D3DXCreateMeshFromX( L"NameOfFile.x",                     D3DXMESH_MANAGED,   <-- same as D3DPOOL_MANAGED                     pD3DDevice,         <-- IDirect3DDevice9*                     NULL,                     NULL,                     NULL,                     NULL,                     &pMesh );// now to draw it assuming the mesh is not broken into individual// subsets, to simplify things I'm assuming it's not but lookup// ID3DXMesh in the SDK documentation (within BeginScene() )pMesh->DrawSubset( 0 );


That's a REALLY basic example of loading the rendering a model loaded from a .X file. Hopefully it's enough to get you started :).

Best of luck
Quote:Original post by Anonymous Poster
I believe that if you want to open a .X model file all you need to do is load up the D3DXLibrary (which should already be included in your DirectX library) and then call the LoadMesh function.
Viola - you're done loading a mesh WITH animations, complex lighting, and material data - and you had to use one line of code to do it.

Isn't D3DX great?


A single function called LoadMesh that loads up all animations, complex lighting and material data?

Could you kindly point me towards this wonderful function? From what iv found, displaying animations from .X files is no fun...

EDIT - Sorry, forgot my reply to the OP!

The code given by Permafried is pretty much it. Just be sure not to forget to put some lighting in the scene as well =)
"Leave it to the computer programmers to shorten the "Year 2000 Millennium Bug" to "Y2K." Isn't that what caused this problem in the first place?"
You can try stop being lazy and read the source code. If that's too much then maybe programming isn't for you.
Quote:Original post by Tesl
Quote:Original post by Anonymous Poster
I believe that if you want to open a .X model file all you need to do is load up the D3DXLibrary (which should already be included in your DirectX library) and then call the LoadMesh function.
Viola - you're done loading a mesh WITH animations, complex lighting, and material data - and you had to use one line of code to do it.

Isn't D3DX great?


A single function called LoadMesh that loads up all animations, complex lighting and material data?

Could you kindly point me towards this wonderful function? From what iv found, displaying animations from .X files is no fun...

EDIT - Sorry, forgot my reply to the OP!

The code given by Permafried is pretty much it. Just be sure not to forget to put some lighting in the scene as well =)

We actually managed to get mesh animation working using the animation controller but you're not kidding...it's an excessively large pain in the butt especially since the documentation on it is sketchy at best. I think I would have been better off taking a round-about route and using my own linked list of transformations to animate the models but being a 4 month project for school I didn't have any time to spare.

Since my example was incredibly basic he should also be optimizing the mesh and storing off the materials should they serve his needs (though the pathing using a .x file doesn't fill the need quite as well as I'd hoped the first time I used it). The mesh interface serves it's purpose if you want to get something up and running quickly (that of course after you've picked through the docs) but in the long run I think you're much better off implementing your own loaders and rendering them using standard vertex and index buffers.
Quote:Original post by Anonymous Poster
You can try stop being lazy and read the source code. If that's too much then maybe programming isn't for you.


Not attempting to start a flame war, but that's exactly (IMHO) what they shouldn't be doing. Reading source code just makes people want to copy line for line the source, without thinking about what's actually going on. I went through this with Win32 programming, OpenGL programming, and now some OS programming. If I look at someone else's bootloader code, sure it'll help some, but I can almost guarantee that because I'm lazy, a lot of that code will end up in mine. Reading SDK docs, or even better, tutorials or theory papers are MUCH more effective, because it makes you think about the implementation, not the procedure. Which, again, IMHO, is much less lazy than just source skimming.

Just my two cents,
Aviosity

EDIT: Sorry, forgot to even include something useful to the OP. Here's a link with some relevant info, but the part I found informative was the section entitled "Loading .x files", where it describes 2 methods (the LoadMesh as easy, the hierarchical fashion as more difficult) for use in D3D. Good luck!
Thanks for the help guys. I think I've found a solution... I found a very stripped down "full screen" demo and just started slowly adding stuff to it. That's basically all I wanted, a clean slate to work from.

I really like those tutorials aviosity. Simple and straight forward. I'll start working on them when I get home from work.
My friend, one can gain many insights by debugging the code and last time I checked all the DX samples compiled and ran by pressing one button. No one ever said anything about copying code and it is quite hard to cut and paste DX samples because there is a heavy framework underneath.

This topic is closed to new replies.

Advertisement