AmbientLight(环境光):
这个光的最大作用就是物体背对着光就不会一片黑怎么都看不见
const light = new THREE.AmbientLight(oxffffff, 0.2) //oxffffff是环境光 0.2是光的强度
DirectionalLight(平行光):
const light = new THREE.DirectionalLight(oxffffff) //oxffffff 光的颜色 light.position.set(2, 2, 2) // 设置光的位置 scene.add(light) // 添加场景
如图:
SpotLight(台灯光):
const spotLight = new THREE.SpotLight(0xffffff) spotLight.position.set(1, 1, 1) //光源的位置 注意:光源越近就越亮 spotLight.angle = 60 / 180 * Math.PI //台灯照射的角度 当前值为60 spotLight.distance = 2 //锥体照射到的范围 超过这个范围就照不到了 scene.add(spotLight) const spotLightHelper = new THREE.SporLightHelper(spotLight) //台灯灯光照射辅助 scene.add(spotLightHelper)
如图:
PointLight(点光源):
光照向四面八方
const pointLight = new THREE.PointLight(0xffffff) pointLight.position.y = 2 //设置光源的位置 pointLight.intensity = 1 //光亮强度 pointLight.distance = 2 //光照射范围 超过这个范围就不会被照射 scene.add(pointLight) const pointLightHelper = new THREE.PointLightHelper(pointLight) scene.add(pointLightHelper)
如图:
RectAreaLight(范围光):
注意:范围光只针对 MeshStanardMaterial 和MeshPhysicalMaterial这两种材料
const rectAreaLight = new THREE.RectAreaLight(0xffffff, 1, 1, 1) //参数:颜色、光强度、长、宽 rectAreaLight.position.set(0, 1, 0) rectAreaLight.rotation.x = -0.5 * Math.PI scene.add(rectAreaLight) const helper = new THREE.RectAreaLightHelper(rectAreaLight) scene.add(helper)
如图:
HemisphereLight:
const hLight = new THREE.HemisphereLight(0xff0000, 0x0000ff, 1) //参数:天空的颜色 地面的颜色、光的强度 scene.add(hLight)
总结光种类图: