three.js源码翻译及案例(三)-src/scenes/Scene.js

源码位置

  • 该源码位置在three.js源码src/scenes文件夹下

源码翻译

/*
* 本文档为Three.js翻译文档,如有任何疑问请联系:
* pygmalioneffect@aliyun.com
*/
function Scene() {
	//scene 为object3D类型 所以回调到object3D方法创建默认项
	Object3D.call(this);
	//类型为Scene类型
	this.type = 'Scene';
	//scene背景,默认为null
	this.background = null;
	//场景雾,默认为null
	this.fog = null;
	//场景覆盖纹理,意思就是如果不为空且为正确纹理 那么场景中的物体都将使用这个纹理
	this.overrideMaterial = null;
	//场景自动更新,默认为trueF
	this.autoUpdate = true; // checked by the renderer

}

Scene.prototype = Object.assign(Object.create(Object3D.prototype), {

	constructor: Scene,

	isScene: true,

	//场景克隆方法
	copy: function (source, recursive) {
		
		Object3D.prototype.copy.call(this, source, recursive);

		if (source.background !== null) this.background = source.background.clone();
		if (source.fog !== null) this.fog = source.fog.clone();
		if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();

		this.autoUpdate = source.autoUpdate;
		this.matrixAutoUpdate = source.matrixAutoUpdate;

		return this;

	},
	//场景输出为json
	toJSON: function (meta) {

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

		if (this.background !== null) data.object.background = this.background.toJSON(meta);
		if (this.fog !== null) data.object.fog = this.fog.toJSON();

		return data;

	},
	//清除在render中的缓冲
	dispose: function () {

		this.dispatchEvent({ type: 'dispose' });

	}

});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值