三个js破坏了渲染器

Ben*_*way 6 javascript three.js

破坏三个js实例的最佳方法是什么?
我发现当我删除画布并重新添加时,我的第一个渲染器仍然存在而且我有两个.

目前我是

  1. 删除所有事件侦听器
  2. 取消requestAnimationFrame
  3. 从其父级删除渲染器实例

Kal*_*a J 4

类似的东西怎么样?

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

function empty(elem) {
    while (elem.lastChild) elem.removeChild(elem.lastChild);
}
Run Code Online (Sandbox Code Playgroud)

这是对这个旧的 SO 帖子的引用:How can I destroy THREEJS Scene?