Hi
The current version of VGal, the small project Im developing (see it here) uses LoadAssetContainer to get an initial glb file. The scene is updated by calling addalltoscene. As the action of the user takes you to a different virtual place a new asset-container is loaded and the former one is kept in memory. Calling addalltoscene/removeallfromscene I update the scene.
Im trying to have an alternative approach (to reduce the download size) in which all the images/materials are downloaded separately and the scene is rendered on the fly from scratch. The initial idea was to save the items in a container using moveAllFromScene and then add the new elements, but that does not seem to work. The items are not removed from the scene and the new ones are not visible.
Is this approach conceptually correct, or otherwise what should be the right way to do it? Shall I have to dispose the scene and recreate it?
LB
Sounds like you are not pointing to the correct references or have something happening that is mutating them. I can confirm that I use this same methodology on multiple projects to great effect.
What browser are you using? Is it a React front end? Can you give some more specifics to your setup?
It is actually pure javascript and I’ve been testing it with desktop versions of chrome and firefox. I was expecting that after calling moveallfromscene, the elements in the scene object get disposed but they dont (checking it in the browser debugger). Maybe it is something related to asynchronicity that Im not getting right.
just wanted some reassurance that Im not missing something basic (like the scene needs to be disposed and recreated …). I’ll keep on testing and if does not work put some live code on a server for demo.
Disposed from the scene and moved to the asset container. This is how it reads the documentation for the method: Removes all the assets contained in the scene and adds them to the container.
You were right,. The issue was (as almost always) in my code. I have found, however a small problem loading and removing assets from an the asset container array. The sequence is something like:
setup scene
asset_container_array[0].moveallfromscene()
setup another scene elements
asset_container_array[1].moveallfromscene()
asset_container_array[0].movealltoscene()
asset_container_array[0].removefromscene()
asset_container_array[1].movealltoscene()
the problem is that the movealltoscene call triggers that the assetcontainer internal variable _wasAddedToScene is set to true. The removefromscene does not cause to be back to false, and that seems to prevent that subsequent calls to movealltoscene have any effect.
I can fix it by resetting that internal variable, and then it works, but it seems something is not right in my code or in babylon. Any ideas?
Thanks @sebavan, now I fully understand what you meant. Yes, using removeallfrom scene sets the internal variable properly. I will change it. My final question would be whether this different behaviour is evident? I would have not guessed it.