three.js源码翻译-RectAreaLight.js

本文翻译并解析了three.js库中的RectAreaLight.js源码,重点介绍了RectAreaLight——一种用于模拟明亮窗户或条形灯的平面光光源。内容包括光源参数、创建方法以及使用注意事项,如需看到灯光效果,需配合pbr材质和特定渲染器设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

three.js源码翻译-RectAreaLight.js

说明

PointLight平面光光源从一个矩形平面上均匀地发射光线。这种光源可以用来模拟像明亮的窗户或者条状灯光光源。
接受四个参数分别为光的颜色,强度,光的宽和高。这是一个新出的光源,需要用到pbr渲染的材质,否则没有灯光效果。

源码位置及翻译

源码位置

src/light/RectAreaLight.js

源码翻译

/**
 *	平面光光源从一个矩形平面上均匀地发射光线。这种光源可以用来模拟像明亮的窗户或者条状灯光光源。
 *	接受四个参数分别为光的颜色,强度,光的宽和高
 * 	不支持阴影。	只支持 MeshStandardMaterial 和 MeshPhysicalMaterial 两种材质。
 *	你必须在你的场景中加入 RectAreaLightUniformsLib ,并调用init()。
 * @param {Color} color 光源颜色
 * @param {Number} intensity 光源强度
 * @param {Number} width 光源的宽
 * @param {Number} height 光源的高
 */
function RectAreaLight( color, intensity, width, height ) {

	Light.call( this, color, intensity );

	this.type = 'RectAreaLight';
	//设置宽高默认为10
	this.width = ( width !== undefined ) ? width : 10;
	this.height = ( height !== undefined ) ? height : 10;

}

RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {

	constructor: RectAreaLight,

	isRectAreaLight: true,
	//复制方法
	copy: function ( source ) {

		Light.prototype.copy.call( this, source );

		this.width = source.width;
		this.height = source.height;

		return this;

	},

	toJSON: function ( meta ) {

		var data = Light.prototype.toJSON.call( this, meta );

		data.object.width = this.width;
		data.object.height = this.height;

		return data;

	}

} );

示例及案例

创建

let rectLight = new THREE.RectAreaLight(0xffffff, 1.5, 30, 30);
rectLight.position.set(50, 50, 0);
rectLight.lookAt(0, 0, 0);
scene.add(rectLight);

注意的点

  • 没有阴影,可能后面会加上。
  • 需要引入一个RectAreaLightUniformsLib.js的文件,否则场景中只有光源,没有物体啥的了。
  • 需要MeshStandardMaterial/MeshPhysicalMaterial材质,否则没有效果。
  • 需要把THREE.Renderer的.gammaInput和.gammaOutput设置为true。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值