I'm having trouble getting the Three.js shadow effect to work in version r82.
I believe I have everything set up correctly, but for some reason it's not working.
Can anyone point out what I might be missing?
Here is an example link for reference: https://jsfiddle.net/JesseLuo/z1m6uffu/
var scene = new THREE.Scene()
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth /
window.innerHeight, 0.1, 1000 )
var renderer = new THREE.WebGLRenderer()
camera.position.set(2,2,2)
camera.lookAt(scene.position)
renderer.setSize(window.innerWidth, window.innerHeight)
renderer.shadowMap.enabled = true
renderer.shadowMap.type = THREE.PCFSoftShadowMap
document.body.appendChild(renderer.domElement)
var directionalLight = new THREE.DirectionalLight( 0xffffff, 0.6 );
directionalLight.position.set( 3, 10, 5 );
directionalLight.castShadow = true
directionalLight.shadowCameraVisible = true;
scene.add( directionalLight );
directionalLight.shadow.mapSize.width = 512; // default
directionalLight.shadow.mapSize.height = 512; // default
directionalLight.shadow.camera.near = 0.1; // default
directionalLight.shadow.camera.far = 500;
var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshPhongMaterial( { color: 0x00ff00 } );
var cube = new THREE.Mesh( geometry, material );
cube.castShadow = true
scene.add( cube );
var planeGeometry = new THREE.PlaneGeometry(10,10,10)
var plane = new THREE.Mesh(planeGeometry, material)
plane.rotateX(-0.5*Math.PI)
plane.position.y = -0.5
plane.receiveShadow = true
scene.add(plane)
var animate = function () {
requestAnimationFrame( animate );
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render(scene, camera);
};
animate()