three.js源码翻译-DirectionalLight.js

本文翻译并解析了three.js库中的DirectionalLight.js源码,详细介绍了方向光的概念,即类似太阳的平行光源,其强度不随距离改变。同时,提到了光源阴影的设置将在DirectionLightShadow部分讨论。
摘要由CSDN通过智能技术生成

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中展示
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值