-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
/
MeshStandardNode.js
118 lines (77 loc) · 2.72 KB
/
MeshStandardNode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* @author sunag / http://www.sunag.com.br/
*/
import {
Color,
Vector2
} from '../../../../../build/three.module.js';
import { StandardNode } from './StandardNode.js';
import { PropertyNode } from '../../inputs/PropertyNode.js';
import { OperatorNode } from '../../math/OperatorNode.js';
import { SwitchNode } from '../../utils/SwitchNode.js';
import { NormalMapNode } from '../../misc/NormalMapNode.js';
function MeshStandardNode() {
StandardNode.call( this );
this.properties = {
color: new Color( 0xffffff ),
roughness: 0.5,
metalness: 0.5,
normalScale: new Vector2( 1, 1 )
};
this.inputs = {
color: new PropertyNode( this.properties, 'color', 'c' ),
roughness: new PropertyNode( this.properties, 'roughness', 'f' ),
metalness: new PropertyNode( this.properties, 'metalness', 'f' ),
normalScale: new PropertyNode( this.properties, 'normalScale', 'v2' )
};
}
MeshStandardNode.prototype = Object.create( StandardNode.prototype );
MeshStandardNode.prototype.constructor = MeshStandardNode;
MeshStandardNode.prototype.nodeType = "MeshStandard";
MeshStandardNode.prototype.build = function ( builder ) {
var props = this.properties,
inputs = this.inputs;
if ( builder.isShader( 'fragment' ) ) {
// slots
// * color
// * map
var color = builder.findNode( props.color, inputs.color ),
map = builder.resolve( props.map );
this.color = map ? new OperatorNode( color, map, OperatorNode.MUL ) : color;
// slots
// * roughness
// * roughnessMap
var roughness = builder.findNode( props.roughness, inputs.roughness ),
roughnessMap = builder.resolve( props.roughnessMap );
this.roughness = roughnessMap ? new OperatorNode( roughness, new SwitchNode( roughnessMap, "g" ), OperatorNode.MUL ) : roughness;
// slots
// * metalness
// * metalnessMap
var metalness = builder.findNode( props.metalness, inputs.metalness ),
metalnessMap = builder.resolve( props.metalnessMap );
this.metalness = metalnessMap ? new OperatorNode( metalness, new SwitchNode( metalnessMap, "b" ), OperatorNode.MUL ) : metalness;
// slots
// * normalMap
// * normalScale
if ( props.normalMap ) {
this.normal = new NormalMapNode( builder.resolve( props.normalMap ) );
this.normal.scale = builder.findNode( props.normalScale, inputs.normalScale );
} else {
this.normal = undefined;
}
// slots
// * envMap
this.environment = builder.resolve( props.envMap );
}
// build code
return StandardNode.prototype.build.call( this, builder );
};
MeshStandardNode.prototype.toJSON = function ( meta ) {
var data = this.getJSONNode( meta );
if ( ! data ) {
data = this.createJSONNode( meta );
console.warn( ".toJSON not implemented in", this );
}
return data;
};
export { MeshStandardNode };