我正在测试版本为r82的Three.js阴影效果,但无效。
似乎我设置了所有必要的东西。
我找不到原因。
有人可以判断我是否忽略了某些内容。
以下是示例: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()
答案 0 :(得分:0)
对plane
和cube
使用相同的材料似乎会导致问题。我不知道为什么会这样。
为飞机添加新材料,应该没问题。
var material2 = new THREE.MeshPhongMaterial({ color: 0x00ffaa });
var plane = new THREE.Mesh(planeGeometry, material2)
顺便说一下,有一个警告:THREE.Light: .shadowCameraVisible has been removed.