Babylon SceneLoader.ImportMeshAsync load same obj but keep all the data in the scene

so I am trying to use houdini update the same obj file, in the meantime update the mesh :
BABYLON.SceneLoader.ImportMeshAsync("", “model/”,“MyBox.obj”, scene,function(newScene){});

I can see Babylon try to load a new mesh(same name and same place) all the time
but it still keep the old one(which doesn’t exist anymore) unless I refresh my web I will always see my old mesh in the scene


A few questions :slight_smile:

  1. Could that be helpful? Optimize using Cached Resources - Babylon.js Documentation
  2. Why do you actually say that the old mesh “doesn’t exist” anymore? are you disposing it?
  3. Why not actually change the mesh, if they are old vs. new?

thanks for the quick reply,
so what I am trying to do is a real-time map web application? I think this might explain a little bit

so I have a <map.obj>which was generated by Houdini base on the drawing:

and every time the users finish the drawing will refresh the <map.obj>, then upload that to
Babylon canvas, I overwrite the old obj file, that’s why I say it doesn’t exist anymore, which lead to your third question, there is only on obj file, but when I use the old mesh still exist in the Babylon canvas and I can see the new mesh has been successfully loaded as well

so I have map1 in canvas, I change the obj auto-update I get map2 but 1 is still there, then I did another change map3 is in, but 1 and 2 still there. Until I hit the refresh button those ‘ghost’ will always be there…

maybe video explain more:

Overwriting the old object does not mean babylon got rid of it. ImportMesh(async) does not create a new scene (as you might think, due to your variable naming in your question), it adds meshes to the existing scene you are already using.

Keep a reference to the old mesh that was created and dispose it in the importmeshasync callback. This way you will see the new mesh and not the old one. I hope this will solve your problem

Thanks man, it make sense !!!

1 Like