Skip to content

Commit 8f95052

Browse files
committed
NodeMaterial: back-compat fixes.
1 parent 6a498fd commit 8f95052

File tree

4 files changed

+67
-16
lines changed

4 files changed

+67
-16
lines changed

examples/js/nodes/materials/MeshStandardNodeMaterial.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ import { MeshStandardNode } from './nodes/MeshStandardNode.js';
66
import { NodeMaterial } from './NodeMaterial.js';
77
import { NodeUtils } from '../core/NodeUtils.js';
88

9-
function MeshStandardNodeMaterial() {
9+
function MeshStandardNodeMaterial( parameters ) {
1010

1111
var node = new MeshStandardNode();
1212

1313
NodeMaterial.call( this, node, node );
1414

1515
this.type = "MeshStandardNodeMaterial";
1616

17-
var options = arguments[ 0 ];
18-
19-
if ( typeof options === 'object' ) Object.assign( this, options );
17+
this.setValues( parameters );
2018

2119
}
2220

@@ -25,6 +23,12 @@ MeshStandardNodeMaterial.prototype.constructor = MeshStandardNodeMaterial;
2523

2624
NodeUtils.addShortcuts( MeshStandardNodeMaterial.prototype, 'properties', [
2725
"color",
26+
"emissive",
27+
"emissiveMap",
28+
"emissiveIntensity",
29+
"ao",
30+
"aoMap",
31+
"aoMapIntensity",
2832
"roughness",
2933
"metalness",
3034
"map",

examples/js/nodes/materials/NodeMaterial.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,30 @@ Object.defineProperties( NodeMaterial.prototype, {
3838

3939
} );
4040

41+
NodeMaterial.prototype.setValues = function( values ) {
42+
43+
if ( values === undefined ) return;
44+
45+
for ( var key in values ) {
46+
47+
var newValue = values[ key ];
48+
49+
if ( newValue === undefined ) {
50+
51+
console.warn( 'THREE.' + this.type + ': "' + key + '" parameter is undefined.' );
52+
continue;
53+
54+
}
55+
56+
// TODO: The base Material class would warn about setting properties that do not have
57+
// a current value, "...not a property of this material".
58+
59+
this[ key ] = newValue;
60+
61+
}
62+
63+
};
64+
4165
NodeMaterial.prototype.updateFrame = function ( frame ) {
4266

4367
for ( var i = 0; i < this.updaters.length; ++ i ) {

examples/js/nodes/materials/nodes/MeshStandardNode.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ function MeshStandardNode() {
1414

1515
this.properties = {
1616
color: new THREE.Color( 0xffffff ),
17+
emissive: new THREE.Color( 0x000000 ),
18+
ao: 1.0,
1719
roughness: 0.5,
1820
metalness: 0.5,
1921
normalScale: new THREE.Vector2( 1, 1 )
2022
};
2123

2224
this.inputs = {
2325
color: new PropertyNode( this.properties, 'color', 'c' ),
26+
emissive: new PropertyNode( this.properties, 'emissive', 'c' ),
27+
ao: new PropertyNode( this.properties, 'ao', 'f' ),
2428
roughness: new PropertyNode( this.properties, 'roughness', 'f' ),
2529
metalness: new PropertyNode( this.properties, 'metalness', 'f' ),
2630
normalScale: new PropertyNode( this.properties, 'normalScale', 'v2' )
@@ -48,15 +52,40 @@ MeshStandardNode.prototype.build = function ( builder ) {
4852

4953
this.color = map ? new OperatorNode( color, map, OperatorNode.MUL ) : color;
5054

55+
// slots
56+
// * emissive
57+
// * emissiveMap
58+
// * emissiveIntensity
59+
60+
var emissive = builder.findNode( props.emissive, inputs.emissive ),
61+
emissiveMap = builder.resolve( props.emissiveMap ),
62+
emissiveIntensity = builder.resolve( props.emissiveIntensity );
63+
64+
this.emissive = emissiveMap ? new OperatorNode( emissive, emissiveMap, OperatorNode.MUL ) : emissive;
65+
66+
if ( emissiveIntensity !== undefined ) {
67+
68+
this.emissive = new OperatorNode( this.emissive, emissiveIntensity, OperatorNode.MUL );
69+
70+
}
71+
5172
// slots
5273
// * ao
5374
// * aoMap
75+
// * aoMapIntensity
5476

5577
var ao = builder.findNode( props.ao, inputs.ao ),
56-
aoMap = builder.resolve( props.aoMap );
78+
aoMap = builder.resolve( props.aoMap ),
79+
aoMapIntensity = builder.resolve( props.aoMapIntensity );
5780

5881
this.ao = aoMap ? new OperatorNode( ao, new SwitchNode( aoMap, "r" ), OperatorNode.MUL ) : ao;
5982

83+
if ( aoMapIntensity !== undefined ) {
84+
85+
this.ao = new OperatorNode( this.ao, aoMapIntensity, OperatorNode.MUL );
86+
87+
}
88+
6089
// slots
6190
// * roughness
6291
// * roughnessMap

examples/js/nodes/utils/ColorSpaceNode.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ function ColorSpaceNode( input, method ) {
1212

1313
this.input = input;
1414

15-
this.method = method;
16-
17-
if ( this.method === undefined ) {
18-
19-
this.method = this.getEncodingMethod( this.input.value.encoding );
20-
21-
}
15+
this.method = method || ColorSpaceNode.LINEAR;
2216

2317
}
2418

@@ -209,15 +203,15 @@ ColorSpaceNode.LOG_LUV_TO_LINEAR = 'LogLuvToLinear';
209203

210204
ColorSpaceNode.prototype = Object.create( TempNode.prototype );
211205
ColorSpaceNode.prototype.constructor = ColorSpaceNode;
212-
ColorSpaceNode.prototype.nodeType = "ColorSpaceNode";
206+
ColorSpaceNode.prototype.nodeType = "ColorSpace";
213207

214208
ColorSpaceNode.prototype.generate = function ( builder, output ) {
215209

216210
var input = builder.context.input || this.input.build( builder, 'v4' ),
217-
encodingMethod = builder.context.encoding !== undefined ? this.getEncodingMethod( builder.context.encoding ) : [ this.method ],
218-
factor = this.factor ? this.factor.build( builder, 'f' ) : encodingMethod[ 1 ];
211+
decodingMethod = builder.context.encoding !== undefined ? this.getDecodingMethod( builder.context.encoding ) : [ this.method ],
212+
factor = this.factor ? this.factor.build( builder, 'f' ) : decodingMethod[ 1 ];
219213

220-
var method = builder.include( ColorSpaceNode.Nodes[ encodingMethod[ 0 ] ] );
214+
var method = builder.include( ColorSpaceNode.Nodes[ decodingMethod[ 0 ] ] );
221215

222216
if ( factor ) {
223217

0 commit comments

Comments
 (0)