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中展示