我如何销毁THREEJS场景? [英] How can I destroy THREEJS Scene?
本文介绍了我如何销毁THREEJS场景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题很简单:我怎样才能销毁场景?从场景中移除所有组件?
我需要销毁场景,因为我 not 想要将任务委派给垃圾收集器。
解决方案
我使用过这个:
cancelAnimationFrame(this.id); //停止动画
this.renderer.domElement.addEventListener('dblclick',null,false); //删除侦听器来渲染
this.scene = null;
this.projector = null;
this.camera = null;
this.controls = null;
empty(this.modelContainer);
空方法是jQuery空的替代方法,您可以使用它:
function empty(elem){
while(elem.lastChild)elem.removeChild(elem.lastChild);
}
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.
解决方案
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);
}
这篇关于我如何销毁THREEJS场景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文