我今天开始使用THREE.js并设法用太空船和一些盒子渲染一个场景。太空船应该在盒子上投下阴影,但阴影只在我使用OrbitControls时显示。如果我使用自己的相机,一切都很好,但不是影子。如何设置PerspectiveCamera以显示阴影?
我是初学者,无法使用我的jsfiddle代码,但代码为here
var spotLight = new THREE.SpotLight(0xffffff);
spotLight.position.copy(ship.position);
spotLight.position.z += 5;
spotLight.shadowDarkness = 0.7;
spotLight.target = ship;
spotLight.castShadow = true;
spotLight.shadowMapWidth = 1024;
spotLight.shadowMapHeight = 1024;
spotLight.shadowCameraNear = 1;
spotLight.shadowCameraFar = 20;
spotLight.intensity = 0.2;
spotLight.shadowCameraFov = 30;
spotLight.shadowCameraNear = true;
scene.add(spotLight);
if (useOrbitControls) {
controls = new THREE.OrbitControls(camera);
controls.center.clone(ship.position);
controls.addEventListener('change', render);
}

答案 0 :(得分:0)
我终于解决了它。由于OBJLoader的异步特性,在完全加载3D模型之前,首先调用animate()。通过将第一个animate()调用移动到OBJLoader回调中,一切都突然按预期工作。