Closed dhritzkiv closed 8 years ago
I'd definitely say using Array.forEach in the array you're modifying by removing items might yield some counterintuitive (but correct) results. Try with an old and tried while():
`while( scene.children.length ) scene.remove( scene.children[ 0 ] )``
Also, remember that this would remove everything added to the scene: meshes, lights, helpers... You'd better keep an array of elements you want to remove at some point.
using Array.forEach in the array you're modifying by removing items…
duh, of course!
this would remove everything added to the scene
yep. my plan was to use an if
statement to only remove MeshLines.
Anyway, I ultimately achieved it using filter (to create a copy) and forEach to then remove the objects:
scene.children
.filter(child => child.type === "Mesh")
.forEach(scene.remove, scene);
The same result occurs with for loops and using scene.traverse. However, doing this:
…does work. Weirdness. Try opening the main demo and copying+pasting the above pieces of code to see the results.
Am I doing something incorrectly?
r73