I am using a “loading manager”, which (I think) shouldn’t allow the program to proceed to initialization until everything is loaded:
//- Loading Manager
// Create a loading manager to set RESOURCES_LOADED when appropriate.
// Pass loadingManager to all resource loaders.
let loadingManager = new THREE.LoadingManager();
let RESOURCES_LOADED = false;
loadingManager.onLoad = function(){
console.log("loaded all resources");
RESOURCES_LOADED = true;
initAll();
};
let txtrLoader = new THREE.TextureLoader(loadingManager);
let imagLoader = new THREE.ImageLoader(loadingManager);
let cubeLoader = new THREE.CubeTextureLoader(loadingManager); // new
But I could be wrong.
Consistent with the above, I now load the SkyBox, with CubeTextureLoader, like this:
let envMap = cubeLoader
.setPath(SBPath)
.load(["px.jpg", "nx.jpg", "py.jpg", "ny.jpg", "pz.jpg", "nz.jpg"]);
But this will accept neither await before the cubeLoader (reserved word error) or loadAsync.
I had added an async before the entire loading function, but that did help.
ALSO (and this may be beyond what you want to discuss) …
On my larger programs, I set up a separate loading screen which displays until everything is loaded. The render function includes this:
if(RESOURCES_LOADED == false){
renderer.render(loadingScreen.scene, loadingScreen.camera);
return; // Stop the function here.
}
and the initialization routine sets a LodFlg when it is done, so that I do not allow the various subroutines called by render function routines to run unless that flag is set.
That may all be a bit kludgy, but it seems to work. It seems to force everything to be loaded and initialized before things display and the render subroutines starts working. If there a better overall approach, I would appreciate your thoughts.
I just have the feeling that the better approach is to use await and async to handle these tasks.