Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I destroy THREEJS Scene?

I created a Threejs Scene, adding camera, lights and various objects.

The question is simple: how can I destroy scene? Removing from scene all components?

I need to destroy scene because and I do not want to delegate the task to the garbage collector.

like image 638
Luca Davanzo Avatar asked Jan 30 '14 10:01

Luca Davanzo


People also ask

What is a scene in three js?

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.

How do you dispose of 3js?

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().


Video Answer


1 Answers

I used this:

    cancelAnimationFrame(this.id);// Stop the animation
    this.renderer.domElement.addEventListener('dblclick', null, false); //remove listener to render
    this.scene = null;
    this.projector = null;
    this.camera = null;
    this.controls = null;
    empty(this.modelContainer);

The method empty is a substitute to jQuery empty, you can use it:

function empty(elem) {
    while (elem.lastChild) elem.removeChild(elem.lastChild);
}
like image 170
phemt.latd Avatar answered Sep 24 '22 02:09

phemt.latd