0

我有这个代码:

  var other_phongMaterial   = new THREE.MeshPhongMaterial({ color: 0xf455f4 });      
  var other_sphere = new THREE.Mesh(new THREE.SphereGeometry(50, 50, 50), other_phongMaterial );
  var other_cube = new THREE.Mesh(new THREE.CubeGeometry(200, 200, 200), other_phongMaterial );

  var phongMaterial = new THREE.MeshPhongMaterial({ color: 0xcccccc });
  var sphere = new THREE.Mesh(new THREE.SphereGeometry(50, 50, 50), phongMaterial );
  var cube = new THREE.Mesh(new THREE.CubeGeometry(200, 200, 200), phongMaterial );


  sphere.castShadow = true;
  cube.receiveShadow = true;
  other_sphere.castShadow = true;
  other_cube.receiveShadow = true;

  sphere.position.set(0,250,-130);
  other_cube.position.set(0,50,-150);

  other_sphere.position.set(0,250,130);
  cube.position.set(0,50,150);

  scene.add(cube);
  scene.add(sphere);
  scene.add(other_sphere);
  scene.add(other_cube);    

  var spotLight = new THREE.SpotLight( 0xffffff );
  spotLight.position.set( 100, 1000, 100 );

  spotLight.castShadow = true;
  spotLight.shadowMapWidth = 1024;
  spotLight.shadowMapHeight = 1024;

  spotLight.shadowCameraNear = 500;
  spotLight.shadowCameraFar = 4000;
  spotLight.shadowCameraFov = 30;

  scene.add( spotLight );

而且,我不明白为什么阴影投射只适用于一个。我注意到以下几点:
- 如果我尝试交换立方体,阴影会投射到一个上,但仍然不会投射到另一个上。
- 如果我使用与 other_cube 相同的材料,它会起作用,这意味着就像现在这样写的那样对我有用,相反,如果我使用两种不同的材料,它只会投射在 other_cube 上。
但是这些形状的设置是完全相等的!所以..我不知道,真的..提前谢谢!

编辑:可能还有其他我不记得提出的异常情况,所以请在每种情况下告诉我。

4

1 回答 1

0

也许您的 other_cube 不在阴影相机截锥体内。您应该能够通过设置来查看阴影相机尺寸spotLight.shadowCameraVisible = true;。只有该圆锥内的对象才会计算阴影。然后移动立方体或相应地调整阴影相机属性。阴影可能有点棘手,问题可能完全是另外一回事。但我会先检查一下。

于 2013-08-02T11:31:48.247 回答