If I create objects in the following way:
var group = new THREE.Object3D();
for (var i = 0; i < 10; i++) {
geometry = new THREE.BoxGeometry(1, 1, 1);
material = new THREE.MeshNormalMaterial();
mesh = new THREE.Mesh(geometry, material);
group.add(mesh);
}
scene.add(group);
How, then, do I remove those objects from that group?
I tried doing this...
for (var i = group.children.length - 1; i >= 0; i--) {
scene.remove(group.children[i]);
}
...but it outputs as 'undefined'. What am I doing wrong here?
for (var i = group.children.length - 1; i >= 0; i--) {
group.remove(group.children[i]);
}
In one line you can do this.
group.remove(...group.children);
You can use
object.children = [];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With