Use of Assetcontainers in memory

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?

2 Likes

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.

Elements are not disposed, they are kept in container for later use so you won’t need to load them again.

1 Like

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.

Removes, not disposes.

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:

  1. setup scene
  2. asset_container_array[0].moveallfromscene()
  3. setup another scene elements
  4. asset_container_array[1].moveallfromscene()
  5. asset_container_array[0].movealltoscene()
  6. asset_container_array[0].removefromscene()
  7. 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?

LB

Anybody has any clue of the (aparent) issue with assetcontainers?

1 Like

Only removeAllFromScene and moveAllFromScene will reset it back as it is to track operation concerning the whole lot.

I guess in your case the fix is to rely on removeAll ?

Sorry, I dont know what you mean. I would assume that removeallfromscene sets that internal variable to False, but that is not what it happens

It is or should if you use removeAllFromScene:

It does not happen by design in the function you mentioned in your post

If it does not happen in removeAllFromScene, please share a repro so that we can fix it

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.

You are right, do you want to make a PR to improve the related code doc ?

1 Like