georage Posted August 1, 2016 Share Posted August 1, 2016 http://www.babylonjs-playground.com/#PFCYT#1 This playground makes 9 meshes and tries to delete them all at once in a loop. It does not work. Am I missing something? I defeated the problem via this unholy function ... function deleteAllMeshes(scene){ var countMesh = 0; scene.meshes.forEach(function(m) { countMesh++; console.log(m.name); m.dispose(); }); console.log(countMesh + " meshes deleted"); var x = countMeshes(scene); if(x > 0) { deleteAllMeshes(scene); } } Here is the output of the unholy function proving only half of the meshes are deleted per function call. Quote Link to comment Share on other sites More sharing options...
georage Posted August 1, 2016 Author Share Posted August 1, 2016 Hey, I meant to post this in Q&A! Sorry. Quote Link to comment Share on other sites More sharing options...
Temechon Posted August 1, 2016 Share Posted August 1, 2016 It works better now http://www.babylonjs-playground.com/#PFCYT#2 georage 1 Quote Link to comment Share on other sites More sharing options...
georage Posted August 1, 2016 Author Share Posted August 1, 2016 thanks! i appreciate your showing me the light. I guess I will have to change my functions to use your method, but in every case except disposing of meshes it seems to work with "scene.meshes.forEach" Is there a reason why your method is more reliable? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 2, 2016 Share Posted August 2, 2016 The problem with foreach is that it cannot work if you modify the array (which is the case everytime you dispose a mesh :)) Quote Link to comment Share on other sites More sharing options...
legallon Posted April 10, 2018 Share Posted April 10, 2018 Hi, Old topic but this helped me ! However, is there a way to do this without "disposing" the ground, as it's a mesh too ? Because I have a scene where I can create boxes and spheres thanks to 2 create buttons, and i'd like to press a clear button and have all my meshes deleted except my ground. Thanks for your time On 01/08/2016 at 7:12 PM, Temechon said: It works better now http://www.babylonjs-playground.com/#PFCYT#2 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted April 10, 2018 Share Posted April 10, 2018 Simply add a condition if(!ground) meshes[i].dispose(); // If the mesh is not a ground, delete legallon 1 Quote Link to comment Share on other sites More sharing options...
legallon Posted April 10, 2018 Share Posted April 10, 2018 Thanks a lot , I should've thought about that ! 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.