1.材质需要满足对光照反应,一般用MeshStandardMeterial即可,MeshBasicMeterial不行
2.光照投射
(1)环境光(整体亮一些,不会产生阴影)
const ambientLight = new THREE.AmbientLight(0xffffff, 0.8);
this.scene.add(ambientLight);
(2)平行光(产生阴影)
const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
directionalLight.position.set(10, 3, 10);
directionalLight.castShadow = true;//重点
this.scene.add(directionalLight);
3.渲染器开展阴影计算
this.renderer.shadowMap.enabled = true
4.物体投射阴影(例如柜子)
mesh.castShadow = true;
5.物体接收阴影(例如地板)
floor.receiveShadow = true