Model Load Time

Part of the game I am creating involves placing buildings much like most real time strategy games. When I click a button, a model appears by he mouse cursor until it is placed. The problem I am have is with the amount of time it takes the model to show up. The model takes at least 5 seconds to show up on the screen.

The only way I can think of solving this problem is to always keep a model of each building type loaded and then when I build the building, I just reparent the loaded model to ‘render’ and load another model of the building for future placement.

Is my method the ‘correct’ way of doing things or do better options exist.

You could do it your way, but your app will take quite some RAM then.
You should convert your models to .bam (using the egg2bam tool) which really speeds up loading.

Also consider enabling the model cache, simply by placing the config variable:

model-cache-dir $TEMP/cache

in your Config.prc file. Name any particular temporary directory you like. This will automatically generate a bam file and store it in the cache the first time you load a particular egg file; then subsequent sessions will load that cached version instead.


I don’t know why I didn’t think of converting the models to .bam first. I read some material about the .bam files a long time ago and it just never popped into my head to try that out. Thanks!

I tried converting the models to .bam files and loading those instead. It still seems to take about the same amount of time to load them in as it takes to load the .egg files.

Normally, it shouldn’t take more than a moment for a bam file to load and appear. There may be something else going wrong. It surprises me that you say “the game does not lag”, do you mean that frames continue to render and the game continues to be responsive while you’re waiting for the model to appear?


Sorry about that. I didn’t notice it lagging earlier but after you brought it up, I double checked and the game does freeze up until the model is done loading.

OK, well, that makes more sense then. But 5 seconds is still a long time. How big are these models you’re talking about? Maybe it’s an issue with the textures–how big are your textures? Try setting:

textures-header-only 1

in your Config.prc file. This will prevent it from loading textures at all (everything will be blue instead). Does it still take 5 seconds to load up in this mode, or is it very fast?


It does seem to be mostly a texture issue. After trying what you specified, it took less than one second for the model to load. I’m not sure how big the models are since an artist created them. I do not know the dimensions. After looking the texture files, I saw that many textures used were 1500 x 2000 or more. This seems to be very large for a texture. Could this most likely be the cause of my problem?

I need to find a way to have absolutely no load time when placing buildings in my game because even a 1/4 second delay would be very annoying to the player. It seems that I will have to load the model in at the beginning of the game?

These are indeed very large texture sizes. Furthermore, to make matters worse, it sounds like they are not a power of two–1500 is not a power of two, it should be exactly one of 256, 512, 1024, or 2048. This means that Panda is forced to resize these textures at load time, which can make it take even longer.

So, yeah, you can preload your models to reduce the load time. You only need to call loader.loadModel(‘myModel.egg’) at startup for each of your models, and you can even throw away the return value; you don’t need to change the rest of your code. This works because Panda automatically caches every model load internally the first time you load it, and subsequent calls to loadModel() on the same model file will return the cached version very quickly.

On the other hand, another very easy thing to do is to put:

model-cache-textures 1

in your Config.prc file as well. This tells Panda to also cache textures in the model-cache-dir, in addition to egg files. The textures are saved in the rescaled form, so that after the first session, Panda doesn’t need to rescale the textures on subsequent sessions.

Of course, it would probably be even better if you revisited your texture sizes to make them a power of two, and checked that they were not needlessly large.


One more observation…

I have preloaded a model at the beginning of a game. When I load the model for the first time after preloading it and reparent it to ‘render’, the game lags for about one second while it is either loading the model or putting it in ‘render’. If I try to load the model again, it will happen instantly with no visible pause. Any ideas of why the speed would be different between those two cases?

Because the same model is still in memory and will thus be reused.

If you preloaded it and didn’t store it somewhere, it could be that there wasn’t a reference to it anymore and its memory got free’d, and the next time you loaded the model it was loaded from disk again, (but I don’t know for sure).