使用ObjLoader加载的对象不会在three.js中接收阴影

时间:2018-05-31 22:01:23

标签: three.js shadows objloader

模型在地平面上投射阴影,但它不会从前面的另一个小平面接收阴影(这会在地平面上投下阴影),更不用说自己了。任何想法???

   var light = new THREE.DirectionalLight( 0xffefee, 1.2 );
   light.position.set( 0, 40, 100 );
   light.shadow.camera.left = -100; 
   light.shadow.camera.right = 100;
   light.shadow.camera.top = 100;
   light.shadow.camera.bottom = -100;
   light.shadow.camera.far = 1000;
   light.shadow.camera.near = 1;

   light.shadow.mapSize.width = 512;  
   light.shadow.mapSize.height = 512;

   light.castShadow = true;
   light.shadowDarkness = 0.5;

   renderer.shadowMap.enabled = true;
   renderer.shadowMap.type = THREE.PCFSoftShadowMap; 


    var femModel = null;  

    mtlLoader.setMaterialOptions({ side:THREE.DoubleSide });
    mtlLoader.load( 'female02.mtl', function( materials ) {     
    materials.preload();
    var objLoader = new THREE.OBJLoader();
    objLoader.setMaterials( materials );
    objLoader.setPath( 'female02/' );
    objLoader.load( 'female02.obj', function ( object ) {

        femModel = object; 

        femModel.position.set( 0, -80, 0 );
        sceneRTTA.add( femModel );
    }, onProgress, onError );

});

完全加载后调用setup函数:

function setupmodel(){
    femModel.traverse( function ( child ) {
        if ( child instanceof THREE.Mesh ) {
            child.castShadow = true;
            child.receiveShadow = true; 
        }   
    } );    
}

three.js 0.91.0

0 个答案:

没有答案