Graphics Reference
In-Depth Information
specular: 0xa9fcff,
color: 0x00abb1,
emissive: 0x006063,
shininess: 10
}
var sphereMaterial = new
THREE.MeshPhongMaterial(matProps);
var sphereMesh = new
THREE.Mesh(sphereGeometry,
sphereMaterial);sphereMesh.name =
'sphere'; scene.add(sphereMesh);
2. Next, we create and add THREE.SpotLight to the scene:
spotLight = new THREE.SpotLight();
spotLight.position.set(20, 80, 30);
spotLight.castShadow = true;
spotLight.angle = 0.15;
spotLight.distance = 160;
scene.add(spotLight);
Note that at this step, we don't point the created light to the sphere. We'll do
this in the next step in the render loop.
3. To keep the light pointed at the sphere, we need to set the target property
to the correct value. We do this in the render function of the scene:
var step = 0;
function render() {
step += 0.02;
renderer.render(scene, camera);
var sphere =
scene.getObjectByName('sphere');
sphere.position.x = 0 + (10 *
(Math.cos(step)));
sphere.position.y = 0.75 * Math.PI /
2 + (6 * Math.abs(Math.sin(step)));
spotLight.target = sphere;
Search WWH ::




Custom Search