我有一个Meshes数组,每个Mesh都在name属性中存储了它的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
}
这样的事情可能吗?
谢谢!
答案 0 :(得分:7)
是的:
function remove(id) {
scene.remove(scene.getObjectByName(id));
}