I tried to make a function to remove all object from scene in one shoot but it removes only one object for invocation.
GeometryModel.prototype.clearScene = function(scene) {
var i;
for(i=0; i < scene.children.length; i++){
obj = scene.children[i];
scene.remove(obj);
}
}
another solution I tried and that works is this:
scene.children={};
but I am not sure if it is correct.
Whenever you create an instance of Texture, three. js internally creates an instance of WebGLTexture. Similar to buffers, this object can only be deleted by calling Texture. dispose().
Scenes allow you to set up what and where is to be rendered by three. js. This is where you place objects, lights and cameras.
You have to do the opposite:
for( var i = scene.children.length - 1; i >= 0; i--) {
obj = scene.children[i];
scene.remove(obj);
}
because in each iteration the .children
array changes once you do a .remove()
from the start and the indexing of that array changes.
If you want to understand it better, unroll the for loop and follow what the index into the array is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With