我在ThreeJS上遇到了麻烦。我有一些立方体,应该在下面的平面上投射阴影,但它们却不能-我已经使用Google搜索了一个解决方案几个小时,并尝试了我能找到的一切,但我无法工作。

我在所有对象上使用MeshPhongMaterial,并且已将.castShadow.receiveShadow添加到所有适当的对象。我使用指向地面的SpotLight-它照亮了立方体和地面,但是立方体没有投射阴影。这是一个立方体和地面的示例:

  var cubeGeometry = new THREE.CubeGeometry(20, 20, 20);
  cube1 = new THREE.Mesh(cubeGeometry, material);
  cube1.shading = THREE.FlatShading;
  cube1.castShadow = true;
  cube1.receiveShadow = true;
  var groundGeometry = new THREE.PlaneGeometry(200, 200);
  var groundMaterial = new THREE.MeshPhongMaterial({color: 0xf0dc3f});
  ground = new THREE.Mesh(groundGeometry, groundMaterial);
  ground.shading = THREE.FlatShading;
  ground.position.y = -30;
  ground.rotation.x = Math.PI / 2;
  ground.rotation.z = Math.PI / 4;
  ground.receiveShadow = true;


还有我的JsFiddle:https://jsfiddle.net/fggjp2n9/

最佳答案

您不见了:

renderer.shadowMap.enabled = true;

https://jsfiddle.net/fggjp2n9/1/

09-13 01:18