I got some meshes to be loaded or cloned on the fly. The clone time takes about 60ms-100ms of every mesh, which leads to a freeze of the scene render. So my point is if I separate the mesh into smaller one(ideally takes 5-10ms when cloning, which may have little influence on current framerate), is there any method to know how many things to do in the current renderloop and set a queue for all clone tasks, I mean a method like query the task to do of the current renderloop, if there is a lot of things to do this time, then put the new task to the next renderloop.
It is mainly used for simplification task scheduling (so it wouldn’t block the UI thread while simplifying). The basic gist is - you define the number of iterations, the function that will run on each iteration, and it takes care of the rest. In your case, something like this:
const cloneNext = (index, callback) => {
// do whatever you need to do
callback();
}
const cloneObjects = [.....]
const numberOfClonesPerIteration = 2;
AsyncLoop.SyncAsyncForLoop(cloneObjects.length, numberOfClonesPerIteration, (iteration: number) => {
cloneNext(iteration);
}, () => {
//execution ended, run the success callback.
// everything is cloned
});
@RaananW Thank you for your concern. Using AsyncLoop is a great idea, clone part looks better now.
For Loading part, I used Async AssetContainer for loading meshes from glb. It seems to take around 200ms to load texture.
SceneLoader.LoadAssetContainerAsync(path, undefined, this._room.pano.scene).then(((container)=>{
// do clone part
}))
Just make sure I am using the assetContainer properly, I am not using online resource, just load them locally.