Hi,
I am trying to understand a piece of code involving scene.render()
We have a scene. Use click a button. A new mesh appears or disappears from the scene.
When the user click the button and holds it, this makes meshes appear and disappear very fast.
Previously we had
scene.render()
after every event. This was lagging.
Now we have
const renderLoop = () => {
this._scene.render();
};
this._scene.onAfterRenderObservable.addOnce(() => {
this._scene.getEngine().stopRenderLoop(renderLoop);
});
this._scene.getEngine().runRenderLoop(renderLoop);
And it is not lagging.
I am looking at different examples, the documentation and forum posts, but I still can not understand why the first one makes the scene lag and generally what is the difference between scene.render() and calling scene.render() in a renderLoop.
Would scene.render() render the scene if there are 0 render loops in the engine?
Is there are drawback of having 2-3 render loops that are all calling scene.render()?
I read the runRenderLoop and stopRenderLoop are expensive but I could not find more details of how expensive they are. I look at pars of the code for them and it is adding functions to an array. I think it is the content of the loop that is expensive.
I wonder what am I missing? Why could scene.render() be lagging for us and render loop is working?
Thanks