Luc*_*nzo 15 javascript garbage-collection three.js
我创建了一个Threejs场景,添加了相机,灯光和各种物体.
问题很简单:我怎么能摧毁场景?从场景中删除所有组件?
我需要破坏的场景,因为我也没有想委派任务的垃圾收集器.
phe*_*atd 23
我用过这个:
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);
Run Code Online (Sandbox Code Playgroud)
方法empty是jQuery的替代空,你可以使用它:
function empty(elem) {
while (elem.lastChild) elem.removeChild(elem.lastChild);
}
Run Code Online (Sandbox Code Playgroud)