Jump to content
  • Advertisement
Sign in to follow this  
Big_Bear_Scot

Saving to a .X file

This topic is 4830 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everybody I have created a simple level editor which loads in X files and allows the user to place these meshes, I now want to save all these Meshes into one X file so that it can be loaded into a game. What I am considering is the various methods I could use to do this,
  1. Use the D3DXSaveMeshToX function
  2. Create my own X File Saver
  3. Go with my own Custom Map Format
Now option (1) seems the most appealing, all I need to do is supply a pointer to the Mesh structure(in effect), and the function takes care of the dirty work for me. But the major problem is that I have multiple meshes I want to save to a file. The Idea I had was to combine all the Meshes into one Mesh, I would do this be retrieving the Vertex Buffer of the various meshes and apply the various translation to the vertices contained in the buffer and then put these transformed verts into a the final map mesh vertex buffer(repeat for every mesh in the editor) and then save that Mesh to the X file. Is this even possible ? Or I am over complicating my problem ? On option 2, I would not need to create a class that would do the following steps detailed in the DX docs, Save to X File. Now these steps seem pretty straight forward, has anybody implemented such a X file save/loader ? if so could you give me some pointers to help me along ? Option 3 seems to be one of the best options, but I am unsure where to start in creating my own format. I would guess the best idea would to look at the structure of existing map file formats such as Quake 2/3 bsp or Half life 1/2 map format ? Now what would you guys recommend ? or have you guys got any better ideas ? Thanks in advance Big_Bear

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Quote:
Original post by Big_Bear_Scot
Hi everybody

I have created a simple level editor which loads in X files and allows the user to place these meshes, I now want to save all these Meshes into one X file so that it can be loaded into a game.

What I am considering is the various methods I could use to do this,


Use the D3DXSaveMeshToX function
Create my own X File Saver
Go with my own Custom Map Format


Now option (1) seems the most appealing, all I need to do is supply a pointer to the Mesh structure(in effect), and the function takes care of the dirty work for me. But the major problem is that I have multiple meshes I want to save to a file.
The Idea I had was to combine all the Meshes into one Mesh, I would do this be retrieving the Vertex Buffer of the various meshes and apply the various translation to the vertices contained in the buffer and then put these transformed verts into a the final map mesh vertex buffer(repeat for every mesh in the editor) and then save that Mesh to the X file.

Is this even possible ? Or I am over complicating my problem ?


You might look at the function D3DXConcatenateMeshes for baking multiple meshes into one mesh. Then you might still be able to use the stock X file saver.

Share this post


Link to post
Share on other sites
In the long run, you are better off making your own format. It is difficult and inefficent (though not impossible) to do certain terrain things with X meshes, such as dividing it up into a quadtree or finding collisions.

Practice by first dumping all the vertex data to a file. Once you can read it in again correctly, you are ready for something a little more practical. What I would do is give each mesh an index. Then you can simply say "mesh 1 at (x, y)". It will make your files much smaller. Also, by having your program know what each submesh actually is (it's still possible, but a little harder), you can just run a collision using the bounding box of that mesh (if it's a square). In the actual program is the place to combine the meshes together. It is fairly important that you keep the original design intact instead of clumping everything together.

Share this post


Link to post
Share on other sites
I'd say that in the end, I agree with Raloth and your own format is probably going to be best for your 'final' work. However, at any stage before that I would advocate using what is easiest for you at the time. I use X meshes loads when I'm starting a new project to test things out and so forth. You can do almost anything you want with X meshes, the only problem is that it isn't always *fast* (e.g. collision checking large meshes using the D3DX functions).

Another options is to make use of X meshes at every intermediate stage you can such as level/model creation and editing (D3DX has a load of useful functions that you can abuse, why bother rewriting it?) and then convert to your own specific format during an asset build process, pulling out all the data that has been nicely computed for you.

It's up to you in the end, and should really be defined by your own requirements for meshes.

-Mezz

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!