msj121
msj121

Reputation: 2842

Remove PointLight in ThreeJS Model Loader

I am trying to remove the point light (or preferrably any light source), but I am new to ThreeJS... I tried babylonScene.remove(object); but I get an error that "cannot call traverse on undefined" or something to that affect. Happy to post the error if that is the suggested approach.

The code below is taken from the ThreeJS example code with the additional removal code.

https://github.com/mrdoob/three.js/blob/master/examples/webgl_loader_babylon.html

  var loader = new THREE.BabylonLoader( manager );
    loader.load( data.src, function ( babylonScene ) {
        babylonScene.traverse( function ( object ) {
            if ( object instanceof THREE.Mesh ) {
                object.material = new THREE.MeshPhongMaterial( {
                    color: Math.random() * 0xffffff
                });
            }
    else if(object instanceof THREE.PointLight){
      console.log("Removing PointLight");
      object.remove();
    }
   });
   ...
    }, onProgress, onError );

Upvotes: 0

Views: 252

Answers (1)

Griffin M.
Griffin M.

Reputation: 196

The best idea would be to set the light intensity at 0, this means you won't see it anymore:

var loader = new THREE.BabylonLoader( manager );
loader.load( data.src, function ( babylonScene ) {
    babylonScene.traverse( function ( object ) {
        if ( object instanceof THREE.Mesh ) {
            object.material = new THREE.MeshPhongMaterial( {
                color: Math.random() * 0xffffff
            });
        }
else if(object instanceof THREE.PointLight){
  console.log("Removing PointLight");
  object.intensity = 0
}
});
...
}, onProgress, onError );

Hope this helps!

Upvotes: 1

Related Questions