编程语言
首页 > 编程语言> > ThreeJS源码学习10Light

ThreeJS源码学习10Light

作者:互联网

light解析

light

灯光是三维场景必不可少的元素。threeJS中light是所有灯光的父类,它又继承自Object3D。

function Light(color, intensity) {
		Object3D.call(this);
		this.type = 'Light';
		this.color = new Color(color);
		this.intensity = intensity !== undefined ? intensity : 1;
	}

	Light.prototype = Object.assign(Object.create(Object3D.prototype), {
		constructor: Light,
		isLight: true,
		copy: function copy(source) {
			Object3D.prototype.copy.call(this, source);
			this.color.copy(source.color);
			this.intensity = source.intensity;
			return this;
		},
		toJSON: function toJSON(meta) {
			var data = Object3D.prototype.toJSON.call(this, meta);
			data.object.color = this.color.getHex();
			data.object.intensity = this.intensity;
			if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
			if (this.distance !== undefined) data.object.distance = this.distance;
			if (this.angle !== undefined) data.object.angle = this.angle;
			if (this.decay !== undefined) data.object.decay = this.decay;
			if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
			if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
			return data;
		}
	});

标签:ThreeJS,undefined,color,object,Object3D,intensity,源码,10Light,data
来源: https://blog.csdn.net/weixin_42708521/article/details/117750544