我怎样才能破坏 THREEJS 场景?

编程入门 行业动态 更新时间:2024-10-26 02:37:30
本文介绍了我怎样才能破坏 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屋!

更多推荐

[db:关键词]

本文发布于:2023-03-28 15:44:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/733723.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:场景   THREEJS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!