I’m running into an issue I have been asking myself quite a while. Is there a recommend way to switch .glb-model (dispose old and load another) on runtime using buttons. My problem is I have to wait for assetsManager.onFinish and then I can start runRenderLoop that steadily moves the mesh, because the glb-mesh is not loaded and is accessed by renderLoop. I thought about a simple boolean to check if glb-mesh is ready, but is this the recommended way? I looked into Observables a bit but it seems to be for more rare occurings like playing an animation on certain trigger?
I see, thanks for the idea, I will change it accordingly. I assume this solves the “loading screen”-issue?
But how do I solve the runRenderLoop issue? Do I call it outside onFinish and add an if-statement with ship.root, because I get “ship.root is undefined”-error when old ship is removed and before new is loaded?
Here is one of possible solutions - https://playground.babylonjs.com/#JA1ND3#678
Press ‘z’ to switch to another model.
Not sure that I understand your runRenderLoop issues, there are no such issues at this example.
If you want to wait to start a new render loop function when the new ship is ready then you should remove the old one, otherwise there will be extra code running, moving the ship multiple times per frame. There was also a runtime error that I fixed by changing the for of loop to a for in loop on line 20.
Personally I would prob create a class for the ship and call ship.update(dt) from the render loop if the ship isn’t null, for example.
Thank you I learned important stuff, so I can combine your solutions. Here is the PG, it seems to be slightly “lagging”, when I switch?
Also does it matter if engine.runRenderLoop is called more than once like on playground plus with scene.render(). Will it be overwritten or add the statement afterwards?
I’m not noticing any lag when I run your new playground and nothing in the code jumped out that would cause it… For the other question, the existing render loop functions aren’t overwritten (that’s why the old one needs to be removed in this case).