three.js源碼翻譯-DirectionalLight.js
說明
DirectionalLight爲方向光,方向光的就是類似於很遠的太陽照射出的平行光源,並且光源的強度不會隨着具體的遠近而變化,換句話說被照射的地方的光強是一樣的。
源碼位置及翻譯
源碼位置
src/light/DirectionalLight.js
源碼翻譯
/**
* 方向光對象,繼承自light基類,接受兩個參數分別爲燈光的顏色和強度
*
* @param {Color} color
* @param {Number} intensity
*/
function DirectionalLight( color, intensity ) {
Light.call( this, color, intensity );
this.type = 'DirectionalLight';
//複製位置信息
this.position.copy( Object3D.DefaultUp );
//更新矩陣
this.updateMatrix();
//設置方向光的朝向
this.target = new Object3D();
//設置陰影
this.shadow = new DirectionalLightShadow();
}
//也是隻有一個copy方法,但是不同的是複製的信息不一樣
DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
constructor: DirectionalLight,
isDirectionalLight: true,
copy: function ( source ) {
Light.prototype.copy.call( this, source );
this.target = source.target.clone();
this.shadow = source.shadow.clone();
return this;
}
} );
示例及案例
創建
//燈光
let directionLight = new THREE.DirectionalLight(0xffffff)
directionLight.position.set(0, 100, 50);
scene.add(directionLight);
注意的點
- 方向光有陰影,具體陰影的設置會在DirectionLightShadow中展示