LightNode.js 1.0 KB
Newer Older
M
r95  
Mr.doob 已提交
1
import { TempNode } from '../core/TempNode.js';
M
r74  
Mr.doob 已提交
2

M
r95  
Mr.doob 已提交
3
function LightNode( scope ) {
M
r74  
Mr.doob 已提交
4

M
r95  
Mr.doob 已提交
5
	TempNode.call( this, 'v3', { shared: false } );
M
r90  
Mr.doob 已提交
6

M
r95  
Mr.doob 已提交
7 8 9
	this.scope = scope || LightNode.TOTAL;

}
M
r74  
Mr.doob 已提交
10

M
r95  
Mr.doob 已提交
11
LightNode.TOTAL = 'total';
M
r90  
Mr.doob 已提交
12

M
r95  
Mr.doob 已提交
13 14 15
LightNode.prototype = Object.create( TempNode.prototype );
LightNode.prototype.constructor = LightNode;
LightNode.prototype.nodeType = "Light";
M
r74  
Mr.doob 已提交
16

M
r95  
Mr.doob 已提交
17
LightNode.prototype.generate = function ( builder, output ) {
M
r74  
Mr.doob 已提交
18 19 20

	if ( builder.isCache( 'light' ) ) {

M
r95  
Mr.doob 已提交
21
		return builder.format( 'reflectedLight.directDiffuse', this.type, output );
M
r74  
Mr.doob 已提交
22

M
r81  
Mr.doob 已提交
23
	} else {
M
r74  
Mr.doob 已提交
24

M
r77  
Mr.doob 已提交
25
		console.warn( "THREE.LightNode is only compatible in \"light\" channel." );
M
r74  
Mr.doob 已提交
26

M
r95  
Mr.doob 已提交
27
		return builder.format( 'vec3( 0.0 )', this.type, output );
M
r74  
Mr.doob 已提交
28 29 30 31

	}

};
M
r90  
Mr.doob 已提交
32

M
r95  
Mr.doob 已提交
33 34 35 36 37 38
LightNode.prototype.copy = function ( source ) {

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

	this.scope = source.scope;

M
r107  
Mr.doob 已提交
39 40
	return this;

M
r95  
Mr.doob 已提交
41 42 43
};

LightNode.prototype.toJSON = function ( meta ) {
M
r90  
Mr.doob 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57

	var data = this.getJSONNode( meta );

	if ( ! data ) {

		data = this.createJSONNode( meta );

		data.scope = this.scope;

	}

	return data;

};
M
r95  
Mr.doob 已提交
58 59

export { LightNode };