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上。
但這些形狀的設置是完全相同的!所以..我無法弄清楚,真的..在此先感謝!
編輯:有可能有其他異常我不記得放,所以請告訴我在任何情況下。
對不起,我想這不是。在開發過程中,我始終保持它,這裏被刪除,以儘可能少的代碼。在某些情況下,陰影可以起作用,所以我認爲問題出在變量,引用或類似的東西中。 – LowFieldTheory