deni Posted November 11, 2014 Share Posted November 11, 2014 How can I remove mesh from scene in Babylon.js in runtime? Tried to search, didn't find, also tried to view the scene methods in debugger, also can't find. Quote Link to comment Share on other sites More sharing options...
Samuel Girardin Posted November 11, 2014 Share Posted November 11, 2014 Hi, You can try : yourMesh.dispose() ; Dieterich and DevDJ 2 Quote Link to comment Share on other sites More sharing options...
nittrus Posted February 27, 2017 Share Posted February 27, 2017 This seems to no longer work in 2.5 release, I was having an issue with to many draw calls and tracked it to the call I had to remove meshes no longer working, works fine in 2.5 beta though, so weird. Quote Link to comment Share on other sites More sharing options...
RaananW Posted February 27, 2017 Share Posted February 27, 2017 If mesh.dispose() doesn't work, it is a bug. But as we haven't heard of it yet (this is one of BJS's basic functionalities), I assume there is something wrong in the implementation. But! this is just an assumption Care to share a playground reproducing the bug? Quote Link to comment Share on other sites More sharing options...
nittrus Posted February 27, 2017 Share Posted February 27, 2017 It seems I was wrong in my understanding of the dispose function, it doesn't remove the object it's self only it's data from the scene, the object is still there, I can not find a way to remove the object, I set it to null for garbage collection but I am still having the draw calls going up so must be something else, back to debugging my code.. fun times.. Does BJS have a method for completely destroying an object by chance? Thanks! Quote Link to comment Share on other sites More sharing options...
RaananW Posted February 27, 2017 Share Posted February 27, 2017 dispose. Care to show how you use the function? Quote Link to comment Share on other sites More sharing options...
nittrus Posted February 27, 2017 Share Posted February 27, 2017 var terratiles = scene.getMeshesByTags("terra"); var meshes = scene.getMeshesByTags("mesh"); for(var index=0; index < terratiles.length; index++){ //remove tiles outside of max range var tt = terratiles[index]; var ttid = tt.id; //Remove if(phys){ if(Math.round(getdist({x: tt.position.x, y: tt.position.y, z: tt.position.z},{x: actor.physicsImpostor.getObjectCenter().x, y: actor.physicsImpostor.getObjectCenter().y, z: actor.physicsImpostor.getObjectCenter().z})/terrasize)*terrasize > terrasize*6){ var ttobs = scene.getMeshesByTags(tt.id+'_mesh'); ttobs.filter(function(e){ var eid = e.id; if(eid.indexOf(ttid) > -1){e.dispose();} }); if(ttobs.length <= 0){tt.dispose();} eid=ttobs=ttid=null; } } tt=ttid=null; } At this point I have discovered for sure it isn't my problem however and it appears to be functioning just fine. But basically what is going on there is it is checking distance from camera to the terrain tile, if it falls outside the max distance it removes all items associated with the tile then it removes the tile. Then I leave all variables used as null for GC. I am still trying to hunt down my draw call / memory leak, so frustrating.. I thought .dispose completely removes the object but it doesn't, I think it leaves the rest to GC, I can simply add tt=null for that, which I do already, so no issue there. Quote Link to comment Share on other sites More sharing options...
yLacaute Posted March 5, 2018 Share Posted March 5, 2018 Hi, I think there is a bug with dispose() with physicsImpostor => in STABLE release, NOT in latest I can reproduce it : https://www.babylonjs-playground.com/indexstable#JS6FR6#1 If we comment the impostor, it works, otherwise it freeze and we got this in console : Uncaught TypeError: Cannot read property 'copyFrom' of undefined at r.i.computeWorldMatrix (babylon.js:8) at r.i.getPositionExpressedInLocalSpace (babylon.js:7) at r.i.translate (babylon.js:8) at World.beforeStep (babylon.js:39) at World.dispatchEvent (cannon.js:10576) at World.internalStep (cannon.js:13557) at World.BJSCANNON.World.step (babylon.js:40) at t.executeStep (babylon.js:40) at t._step (babylon.js:40) at i.render (babylon.js:12) I opened an issue on github Quote Link to comment Share on other sites More sharing options...
Raggar Posted March 5, 2018 Share Posted March 5, 2018 It seems to be because the impostor is linked to the sphere, without being in the physicsImpostor property. You can do this: https://www.babylonjs-playground.com/indexstable#JS6FR6#2 Or this: https://www.babylonjs-playground.com/indexstable#JS6FR6#3 But yeah. This is a bug. Quote Link to comment Share on other sites More sharing options...
Guest Posted March 6, 2018 Share Posted March 6, 2018 Please file an issue on the repo @RaananW should be able to look at it Quote Link to comment Share on other sites More sharing options...
RaananW Posted March 6, 2018 Share Posted March 6, 2018 is this the same issue? https://github.com/BabylonJS/Babylon.js/issues/3876 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.