javascript - three.js 从场景中移除特定对象

标签 javascript three.js

我有一个网格数组,每个网格都在名称属性中存储了它的 ID。我想问你,是否可以从场景中删除具有特定 ID 的对象。像这样。

var geo = some geometry;
var mat = some material;
for (var i = 0; i < 10; i++) {
  var object = new THREE.Mesh(geo, mat);
  object.name = i;  // i would serve as ID in this case
}

在此之后,我想删除/删除其中一些对象... 也许有些功能像

 remove(id);

....

 var remove = function (id) {
  ... some magic
  scene.remove(...) // and this would remove that object, with id passed as parameter 
 }

这样的事情可能吗?

谢谢!

最佳答案

是的,它是:

function remove(id) {
  scene.remove(scene.getObjectByName(id));
}

参见:Object3D.remove()Object3D.getObjectByName()

关于javascript - three.js 从场景中移除特定对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39322054/

相关文章:

Javascript parseFloat(number) - parseFloat(number2) 返回 int

javascript - document.querySelectorAll 出现问题; a[href=]' 不是有效的选择器

javascript - 在 requestAnimationFrame 中每隔 x 秒调用一个函数

javascript - threejs 在使用变换控件时禁用轨道相机

three.js - WebGL GL 错误 :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 1

javascript - MVC FileUpload 文件大小客户端验证

javascript - MVC - 使用 POST 参数打开网页

javascript - 谷歌浏览器不在 iframe 中显示 PDF 文件

javascript - 云上的丑陋渲染

javascript - 三.js虚线圆