2013-08-02 44 views
0

我有这样的代码:three.js所 - 有异常阴影投射

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上。
但这些形状的设置是完全相同的!所以..我无法弄清楚,真的..在此先感谢!

编辑:有可能有其他异常我不记得放,所以请告诉我在任何情况下。

回答

0

也许你的other_cube不在阴影镜头里面。您应该能够通过设置spotLight.shadowCameraVisible = true;来查看影子相机的尺寸。只有该锥体内的物体才会计算阴影。然后移动立方体或相应地调整阴影照相机属性。阴影可能有点棘手,问题可能完全是其他问题。但我会先检查一下。

+0

对不起,我想这不是。在开发过程中,我始终保持它,这里被删除,以尽可能少的代码。在某些情况下,阴影可以起作用,所以我认为问题出在变量,引用或类似的东西中。 – LowFieldTheory