如何销毁 THREEJS 场景? [英] How can I destroy THREEJS Scene?

查看:143
本文介绍了如何销毁 THREEJS 场景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

我用这个:

    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的替代品,可以使用:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆