Jump to content
  • Advertisement
Sign in to follow this  
Mehdi_H

Dynamic Loading a .X file

This topic is 3660 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 every body I want to read some introductory tutorials about loading a .x file at run-time into memory to avoid long loading times. I googled the subject & found nothing useful. Is there any body to know where can I begin ? any websites ,articles , code samples , book etc... will be helpful. thanx bye

Share this post


Link to post
Share on other sites
Advertisement
I'm not really sure what you want to do. I assume you mean that instead of loading your model at level loading time you want to load it when you first need to display it (or just before that).

So are you asking about strategies of loading the object such that there's as small an interruption to rendering as possible, or are you asking something else entirely?

Share this post


Link to post
Share on other sites
yep! you've got the point!
I want to load some of 3D-models at display-Time instead of level-loading-Time. This is more useful when you have a large scene containing several models ,that all of them are not needed to be loaded at once before playing begins. There must be some strategies to load objects just when they needed to be rendered, with minimum effect on frame-rate.

Share this post


Link to post
Share on other sites
First, what kind of game/application are you talking about ? Not all of them needs this feature.

Second, I believe what you want is a continuous 3D world ala-Dungeon Siege. Is that correct ?

Loading .x at runtime is similar to loading it once. What you need here is camera location awareness so that your model loader knows when the camera changes position and a new model is needed.

You also need to take into account the max velocity of your camera and loading time, and load a number models outside of the camera as well. This is kind of a cache so that when the camera moves, you are sure that all models have been loaded and prepared to be drawn. Otherwise you might see houses popping out of nowhere :D

Also, depending on your resource pool implementation, you might have to free up the old hidden models to allows space for the new displayed ones.



If you are talking about loading one .x file partially and continuously.. you can't really do that I think..

Share this post


Link to post
Share on other sites
Do not load XFiles then. For minimizing loading times it's important to have the data ready in the format you need for rendering. So the usual way is to import the data once, for example from XFiles, and store it in your own format. Then read these files at runtime. The difference in loading time is usually around factor 10, might be even larger if you have to do additional processing on the imported data, e.g. calculating tangents.

For reading XFiles there are some resources on the net, even one article here on GameDev.net. If you want a fire-and-forget solution, try Assimp - an open source project for which I maintain the XFile loader.

Share this post


Link to post
Share on other sites
The Idea of storing processed data as a file & reading it at run-Time is great. But let me ask another related question:
Can I load my models with another thread? I heard from someone that we can't use graphical functions like IDirect3DDevice9::LoadXXX in a multiThreaded way. Is it true?
I tested this but I've got some problems... models were loaded partially & unknown heap,etc... errors happened! I think there might be some tricks that I didn't care. For example I didn't put IDirect3DDevice9 in a critical section!

Can you introduce me a procedural approach to load something like a .x file Multi-Threaded? May be if I see some source-codes or tutorial , I can make my own code complete.

Share this post


Link to post
Share on other sites
Using D3D from multiple threads usually isn't a good idea - it requires use of D3DCREATE_MULTITHREADED which adds significant locking overhead.

What I'd suggest instead is have the thread load the file from disc into memory, and add it to some kind of thread safe queue. The main thread can then take the data off the queue and call the appropriate D3D functions to create what you need (meshes, textures, vertex buffers, etc). You'll also want to limit the amount of work you do in one frame as resource creation can be slow.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mehdi_H
The Idea of storing processed data as a file & reading it at run-Time is great. But let me ask another related question:
Can I load my models with another thread? I heard from someone that we can't use graphical functions like IDirect3DDevice9::LoadXXX in a multiThreaded way. Is it true?
I tested this but I've got some problems... models were loaded partially & unknown heap,etc... errors happened! I think there might be some tricks that I didn't care. For example I didn't put IDirect3DDevice9 in a critical section!

Can you introduce me a procedural approach to load something like a .x file Multi-Threaded? May be if I see some source-codes or tutorial , I can make my own code complete.
It's a very bad idea to do multithreading in D3D9. You can however load the file, and create a in-memory buffer of the contents of the index buffer, vertex buffer and textures, and then create the IDirect3DIndexBuffer9, IDirect3DVertexBuffer9 and IDirect3DTexture9 interfaces, Lock(), memcpy() and Unlock() them in the main thread, which should minimize stalling. If you prefer, you can split that over several frames (Create IB on frame 0, VB on frame 1, texture on frame 2, lock, fill and unlock IB on frame 3, and so on), or do an async lock of the resources (Although they'll probably complete immediately anyway).

EDIT: Bah, too slow [smile]

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!