gpt4 book ai didi

javascript - 如何销毁 THREEJS Scene?

转载 作者:可可西里 更新时间:2023-11-01 01:30:42 26 4
gpt4 key购买 nike

我创建了一个 Threejs 场景,添加了相机、灯光和各种对象。

问题很简单:如何销毁场景?从场景中移除所有组件?

我需要销毁场景,因为我不想将任务委托(delegate)给垃圾收集器。

最佳答案

我用过这个:

    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);

empty 方法是 jQuery empty 的替代方法,你可以使用它:

function empty(elem) {
while (elem.lastChild) elem.removeChild(elem.lastChild);
}

关于javascript - 如何销毁 THREEJS Scene?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21453309/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com