beek
beek

Reputation: 3750

Three.js light object3d and tween

I'm struggling in my attempt to light an object, make it tween towards camera and have the light follow the tween.

Basically I want to darken the background and tween a 3D object towards the camera, and set a directional light pointing at it so it has nice, smooth, uniform lighting.

Directional lights i add to the object don't show up, latest I've tried is:

  var directionalLight = new THREE.DirectionalLight( 0xffffff, 1 );
    directionalLight.position.set( 0, 0, -100);
    directionalLight.lookAt(object);
    directionalLight.shadowCameraVisible = true;
    object.add( directionalLight );

I've also tried PointLights near the camera, these kind of work but it's a very sharp light, not smooth and doesn't seem to light all the objects the same.

Using something like this

 hslight1 = new THREE.PointLight( 0xffffff,0.9,100 );
   hslight1.position.set(0,10,0);
   scene.add( hslight1 );
   hslight2 = new THREE.PointLight( 0xffffff,0.9,100 );
   hslight2.position.set(0,0,0);
   scene.add( hslight2 );

Anyone get any ideas on any way to uniformly light an object3D that is tweening towards the camera using

var dist = (size/screen) * (object.scale.x * 2); 

    var pLocal = new THREE.Vector3( 0, 0, -dist );
    var target = pLocal.applyMatrix4( camera.matrixWorld );
    var tweenMove = new TWEEN.Tween(object.position).to(target,        1500).easing(TWEEN.Easing.Cubic.InOut);
    tweenMove.onUpdate(function(){object.lookAt(camera.position);});

Upvotes: 1

Views: 365

Answers (1)

beek
beek

Reputation: 3750

Fixed this by adding the light to the camera

camera.add( light );

Upvotes: 0

Related Questions