We need to load a lot of models in realtime. Currently we just let the AssetManager load every model in our game initialization. We thought, this would “preload” the models and the AssetManager would save them in a cache where he could take the models from if we create them at realtime during the game. Unfortunately, loading the models at realtime still causes the game to freeze for a few seconds (for a model with ~12000 vertices) - which indicates that caching isn’t working or enabled by default.
Is this possible in jMonkey?
It does but OpenGL still has to upload the data to the GPU when it really displays it. You could add one frame at the beginning of the game where that happens and you add all models to the scene once, when setting the cull hint to never you can even do it without displaying anything.
After some research I found out that the problem is caused by the LOD generation. Even if the data is already uploaded to the GPU, jMonkey does still recalculate the LOD.
This is the code I use to bake the LOD. I load the Geometry “geom” with the AssetManager right before this code.
LodGenerator lodGenerator = new LodGenerator(geom);
lodGenerator.bakeLods(LodGenerator.TriangleReductionMethod.PROPORTIONAL, 0.5f, 0.75f);
LodControl lc = new LodControl();
Shouldn’t jMonkey recognize that the data of this asset is already in memory and skip the loading of the LOD? What if I only bake the LOD once for every 3D-file? If I generate the LOD for the first Geometry instance using a 3D file, will jMonkey recognize that other instances use the same model and use the LOD generated in the first instance?
Yes. We generate the LODs right after loading an asset. The performance inpact that occurs when generating the LODs would be acceptable if it would only happen once. We didn’t want to generate the LODs in the SDK.