Jim Adams RPG book: X-file load

Started by
12 comments, last by Habox 20 years, 10 months ago
I am currently reading the book "programming role playing games with directx" by Jim Adams. In chapter 6 he discusses how to load an X-file and he gives an example on the CD. My problem is that with this example (and also other examples later in the book) I can only see the X-file if they are using a texture. A normal material always seems to be displayed completely white. Why is this happening and how can I make it display the X-files with their normal materials, to make it look the same as in Milkshape 3d? This is what I did exactly: - Use milkshape to draw a sphere and assign a red material to it - Export it with the x-file exporter supplied by Jim Adams on the CD - Make the example use this new .x file and added ambient lighting -> result is a white circle, where it should show a red one.
Advertisement
I don''t actually have the book, but:

Did you make sure to set the ambient of each material equal to the diffuse of each material after loading the mesh? DirectX doesn''t do this.
Co-creator of Star Bandits -- a graphical Science Fiction multiplayer online game, in the style of "Trade Wars'.
You''re problem lies in how you set up your FVF for your mesh.


or D3DFVF_TEX0 for textures. If you''re not using textures, take this out.

D3DFVF_DIFFUSE for color.


I had the same prob when I was starting out. Jim''s examples all have textures. So if you try to use his exact code without textures, you''ll get a white or black shape.

Check out the sdk docs for FVF flags

Hope this helps


I had a look at the x-file load example and searched for the vertexFVF, but it is nowhere to be found. Somehow it is done automatically when loading meshes? Can you point me where to look?

Ambient is set to diffuse by the way.
If you are using the XFile example from the book, the parsing funtion should gather all of the material information for the sphere to be rendered as red, and not white. However, if you have added your own lighting to this example (if I understand you correctly), make sure that you haven''t turned the ambiant light up too bright.


On the other hand, after reading your second post it got me to thinking about that piece of code that parses the xfile. In my app, I have meshes that I have created myself and ones that are loaded from and x file( Jim''s cMesh class from the gamecore). With my code, you have to set the FVF flags to D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE. In Jim''s cMesh class the FVF is read out of the xfile.

I can create a red box (settings the diffuse material in milkshape 3d) and have it displayed(using cMesh class) lit and shaded properly (FYI using a point light), but found that I would have problems loading the same xfiles in the "XFile sample" from the book. After comparing the two peices of code (the cMesh class and the "Xfile sample"), I found only a few differeces. All x files loaded into the mesh view fine. So I can only conclude that their are differeces in how the xfiles materials are parsed or how the material is affected by light(I didn''t add any light to the Xfile example). So my adivce to you is the use the load one of your xfiles into another example in the book,( try meshLvl chapter 11 I think) or just move on and use the cMesh class from the GameCore, I''ve had no problems with it, you''ll probably want the animation routines our of it anyway.

One last thing to try is to open your xfiles from the mesh viewer utility, possibly you''re not even working with what you think you are.
Thanks for trying it out, I appreciate it.

Not all of my files load into the meshviewer properly. When I use Jim''s exporter it often displays without any color or texture. Which milkshape exporter do you use?

What I am thinking is that perhaps the diffuse colors aren''t shown due to the order of setting the material and updating the mesh. I''m not sure though, so maybe you can send me the code that you used to display this red box (including the .x file?).

meshLvl has the same problem by the way.
When you loaded your xfile mesh into meshlvl, was it at least lit or shaded?

I believe that I''m using the same Milkshape version that came with the book. I''m at work right now, so I can''t tell you for sure. I''ll let you know when I get home.

I''ve should also mention that I upgraded to directx 8.1, I think I''ve read that there is a problem with the mesh viewer in 8.0 ( but don''t quote me on this). My code has been adapted to work with 8.1, if you do this, you''ll have to change a couple of calls (very easy, adding NULL, to gernerateskinnedmesh and updateskinnedmesh).

When I get home from work, I''ll try to load some of my own meshes into meshlvl and see If I have the same problem. And you''re sure you''re adding the color properly to your model in milkshape? Also, did you add your own light? The XFILE and MeshLvl examples, don''t use light at all, so you won''t see any shading in either of those.

I''ll get back to you when I get home.
P.S. you''ll probably want to use diffuse for your xfile mesh color instead of ambient.


Thanks again.

In meshlvl it looks the same as in the x-file load example, you get a completely white image. In milkshape I have set ambient and diffuse both to red.

Milkshape normally comes with an x-file exporter, but Jim also gives his own exporter on the cd. Which one are you using?

I''ll use a pointlight in future to get shading. At the moment I picked ambient, because its not even showing the color at the moment.

Hear from you later then. Thanks in advance. Maybe you can send me your code to display a properly shaded box, so i can compare it with my stuff?
Yep, I''ll send it off to you when I get home, but like I said be aware that my code is using 8.1.

I''m using the DirectX 8.1 Exporter by John Thompson found at the Milkshape 3d download site. I''ll double check this though.



This topic is closed to new replies.

Advertisement