1
votes

I need to redraw axis labels (implemented as sprites) on a 3D plot and for that purpose need to remove the old labels before adding the updated ones. This is giving me grief however: The old labels simply refuse to leave the scene! I'm using Three.js release 66.

Testing this with the Three.js example scene here: http://threejs.org/examples/#webgl_sprites I simply add the following code:

setInterval(removesprites, 1000);

So every second we're removing all sprites:

function removesprites() {
  for ( var i = group.children.length-1; i>=0 ; i-- ) {
      var sprite = group.children[ i ];
      console.log("removing");
      scene.remove(sprite);
  }
}

The sprites are all in a Object3D group. I read in another post that objects need to be removed in reverse (hence the backwards loop for the removal), but regardless of which way I loop through this, the labels do not get removed.

Any ideas anyone?

1

1 Answers

2
votes

Instead of

scene.remove( sprite );

use

group.remove( sprite );

See Object3D.remove().

three.js r.67