Threads & generating the scene

I’m still a bit unclear about the limitations of using threads with JME3.



Here is the deal.

I am generating and/or loading my scenery on the fly. I do this in parts I call Chunks. The Chunks surrounding the avatar are attached to the scene, obviously, but further away I like to generate or load Chunks, and then cache them so I can quickly add them to the scene when the avatar gets close enough.



Can i use a seperate (non-rendering-) thread to

  • load or build my materials
  • load or generate my meshes/geometries

    and keep them cached in memory so i can attach them quickly in the render thread?



    My assumption here is that attach/detach is quick, and that it’s better to generate or load the world in a seperate thread.



    Anything else i should keep in mind?



    Thanks

When you load an asset once it is cached in the DesktopAssetManager, meaning you can simply load them once to “preload” the models. Loading assets on the AssetManager is threadsafe, so you can create multiple threads to load models, however you have to attach the models on the OpenGL thread:

[snippet id=“10”]



Attaching/detaching is quick, yes.

1 Like

Thanks, normen, i’ll give it a go.