Three.js LatheGeometry不会投射阴影

时间:2016-05-03 13:18:34

标签: three.js geometry shadow

车床几何体不会投射阴影,但球体和立方体会投射阴影。这是为什么 ?

Image

我的渲染器:

var webGLRenderer = new THREE.WebGLRenderer();
    webGLRenderer.setClearColor(0xAAAAAA, 1.0);
    webGLRenderer.setSize(window.innerWidth, window.innerHeight);
    webGLRenderer.shadowMapEnabled = true;

车床:

 var latheGeometry = new THREE.LatheGeometry(array, Math.ceil(segments), 0, 2 * Math.PI);

        //var meshMaterial = new THREE.MeshBasicMaterial({color:0x00ff00, transparent:true, opacity:0.6});
var meshMaterial = new THREE.MeshLambertMaterial({color: 0xFFFFFF});
meshMaterial.side = THREE.DoubleSide;
var wireFrameMat = new THREE.MeshBasicMaterial();
wireFrameMat.wireframe = false;

latheMesh = THREE.SceneUtils.createMultiMaterialObject(latheGeometry,[meshMaterial, wireFrameMat]);
latheMesh.rotation.x = Math.PI * -0.5;
        latheMesh.position.z = 0;
    latheMesh.castShadow = true;
        scene.add(latheMesh);

我的照明:

var pointColor = "#ffffff";
    directionalLight = new THREE.DirectionalLight(pointColor);
    directionalLight.position.set(-50,50,50);
    directionalLight.castShadow = true;
    directionalLight.receiveShadow = false;
    directionalLight.shadowCameraVisible = true;

    directionalLight.intensity = 1;
    directionalLight.shadowCameraNear = 50;
    directionalLight.shadowCameraFar = 200;
    directionalLight.shadowCameraLeft = -50;
    directionalLight.shadowCameraRight = 40;
    directionalLight.shadowCameraTop = 50;
    directionalLight.shadowCameraBottom = -50;


    directionalLight.distance = 0;
    directionalLight.shadowMapHeight = 1024;
    directionalLight.shadowMapWidth = 1024;

    //scene.add( new THREE.DirectionalLightHelper(directionalLight, 0.5) );
    scene.add(directionalLight);

如您所见,只有球体可以投射阴影而不是latheGeometry。

1 个答案:

答案 0 :(得分:2)

THREE.SceneUtils.createMultiMaterialObject()为每种材料创建一个THREE.Group个孩子Mesh

您需要指定不属于该组的castShadow属性,而是指定要投射阴影的子网格物体。

three.js r.76