我还是新手,为什么模型没有投射任何阴影?我启用了环境光和定向光
// import model
const loader = new THREE.GLTFLoader();
loader.load( 'object/GalaxyS10.gltf', function ( gltf ) {
scene.add( gltf.scene );
}, undefined, function ( error ) {
console.error( error );
}
);
loader.castShadow = true;
答案 0 :(得分:3)
很遗憾,您的帖子遗漏了很多细节。通常,您必须执行以下操作才能获得适当的阴影:
GLTFLoader.castShadow
不存在。设置它没有效果。renderer.shadowMap.enabled = true;
才能全局启用阴影。CameraHelper
直观地调试视锥体。const light = new THREE.DirectionalLight( 0xffffff );
light.position.set( 0, 10, - 10 );
light.castShadow = true;
light.shadow.camera.top = 2;
light.shadow.camera.bottom = - 2;
light.shadow.camera.left = - 2;
light.shadow.camera.right = 2;
light.shadow.camera.near = 0.1;
light.shadow.camera.far = 10;
scene.add( light );
// scene.add( new THREE.CameraHelper( light.shadow.camera ) );
receiveShadow
设置为 true
。true
来定义哪些对象应该投射阴影。您没有在代码片段中执行此操作。它应该是这样的:gltf.scene.traverse( function ( object ) {
if ( object.isMesh ) object.castShadow = true;
} );