javascript 我怎样才能破坏 THREEJS 场景?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21453309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I destroy THREEJS Scene?
提问by Luca Davanzo
I created a Threejs Scene, adding camera, lights and various objects.
我创建了一个 Threejs 场景,添加了相机、灯光和各种对象。
The question is simple: how can I destroy scene? Removing from scene all components?
问题很简单:我怎样才能破坏场景?从场景中移除所有组件?
I need to destroy scene because and I do notwant to delegate the task to the garbage collector.
我需要破坏的场景,因为我也没有想委派任务的垃圾收集器。
回答by phemt.latd
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:
方法 empty 是 jQuery empty 的替代品,你可以使用它:
function empty(elem) {
while (elem.lastChild) elem.removeChild(elem.lastChild);
}