V
V
Vsevolod Zhdanov2014-07-08 14:16:47
WebGL
Vsevolod Zhdanov, 2014-07-08 14:16:47

Why is there no light in three.js?

Why is PointLight not working?

var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 10000);
camera.position.z = 100;
camera.position.y = 10;

var pointlight = new THREE.PointLight( 0x00ff00, 100, 1000 );
pointlight.position.set( 10, 10, 10 );
pointlight.castShadow = true;
scene.add(pointlight);

var geometry = new THREE.CubeGeometry(45,45,45);
var material = new THREE.MeshLambertMaterial({color: 0xffffff});
var cube = new THREE.Mesh(geometry, material);
cube.receiveShadow = true;
cube.castShadow = true;
scene.add(cube);

var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
renderer.shadowMapEnabled = true;
renderer.setClearColorHex( 0xffffff, 1 );

var render = function () {
  requestAnimationFrame(render);
  cube.rotation.y+=0.01;
  cube.rotation.x+=0.01;
  renderer.render(scene, camera);
};

render();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sozercanie_kosmosa, 2014-07-10
@jobsstar

a very common mistake - you need to change the
line parameters:
at least to:
pointlight.position.set( 100, 100, 100 );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question