Skip to content

Commit 95c6dcc

Browse files
authored
Merge pull request #16796 from sunag/dev-fix-TextureCubeNode
NodeMaterial revision
2 parents 604925a + 5990dce commit 95c6dcc

34 files changed

+1021
-700
lines changed

examples/files.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ var files = {
159159
"webgl_materials_envmaps",
160160
"webgl_materials_envmaps_exr",
161161
"webgl_materials_envmaps_hdr",
162+
"webgl_materials_envmaps_hdr_nodes",
162163
"webgl_materials_envmaps_parallax",
163164
"webgl_materials_grass",
164165
"webgl_materials_lightmap",

examples/js/nodes/Nodes.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ export { ResolutionNode } from './accessors/ResolutionNode.js';
5050

5151
// math
5252

53-
export { Math1Node } from './math/Math1Node.js';
54-
export { Math2Node } from './math/Math2Node.js';
55-
export { Math3Node } from './math/Math3Node.js';
53+
export { MathNode } from './math/MathNode.js';
5654
export { OperatorNode } from './math/OperatorNode.js';
5755
export { CondNode } from './math/CondNode.js';
5856

examples/js/nodes/THREE.Nodes.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ import {
5050

5151
// math
5252

53-
Math1Node,
54-
Math2Node,
55-
Math3Node,
53+
MathNode,
5654
OperatorNode,
5755
CondNode,
5856

@@ -163,9 +161,7 @@ THREE.ResolutionNode = ResolutionNode;
163161

164162
// math
165163

166-
THREE.Math1Node = Math1Node;
167-
THREE.Math2Node = Math2Node;
168-
THREE.Math3Node = Math3Node;
164+
THREE.MathNode = MathNode;
169165
THREE.OperatorNode = OperatorNode;
170166
THREE.CondNode = CondNode;
171167

examples/js/nodes/core/ConstNode.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function ConstNode( src, useDefine ) {
1010

1111
TempNode.call( this );
1212

13-
this.eval( src || ConstNode.PI, useDefine );
13+
this.parse( src || ConstNode.PI, useDefine );
1414

1515
}
1616

@@ -31,7 +31,7 @@ ConstNode.prototype.getType = function ( builder ) {
3131

3232
};
3333

34-
ConstNode.prototype.eval = function ( src, useDefine ) {
34+
ConstNode.prototype.parse = function ( src, useDefine ) {
3535

3636
this.src = src || '';
3737

@@ -100,7 +100,7 @@ ConstNode.prototype.copy = function ( source ) {
100100

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

103-
this.eval( source.src, source.useDefine );
103+
this.parse( source.src, source.useDefine );
104104

105105
};
106106

examples/js/nodes/core/FunctionNode.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function FunctionNode( src, includes, extensions, keywords, type ) {
1515

1616
TempNode.call( this, type );
1717

18-
this.eval( src, includes, extensions, keywords );
18+
this.parse( src, includes, extensions, keywords );
1919

2020
}
2121

@@ -117,7 +117,7 @@ FunctionNode.prototype.generate = function ( builder, output ) {
117117

118118
}
119119

120-
if ( prop != reference ) {
120+
if ( prop !== reference ) {
121121

122122
src = src.substring( 0, match.index + offset ) + reference + src.substring( match.index + prop.length + offset );
123123

@@ -151,7 +151,7 @@ FunctionNode.prototype.generate = function ( builder, output ) {
151151

152152
};
153153

154-
FunctionNode.prototype.eval = function ( src, includes, extensions, keywords ) {
154+
FunctionNode.prototype.parse = function ( src, includes, extensions, keywords ) {
155155

156156
this.src = src || '';
157157

@@ -222,7 +222,7 @@ FunctionNode.prototype.copy = function ( source ) {
222222
this.isMethod = source.isMethod;
223223
this.useKeywords = source.useKeywords;
224224

225-
this.eval( source.src, source.includes, source.extensions, source.keywords );
225+
this.parse( source.src, source.includes, source.extensions, source.keywords );
226226

227227
if ( source.type !== undefined ) this.type = source.type;
228228

examples/js/nodes/core/Node.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ Node.prototype = {
2020

2121
isNode: true,
2222

23-
parse: function ( builder, settings ) {
23+
analyze: function ( builder, settings ) {
2424

2525
settings = settings || {};
2626

27-
builder.parsing = true;
27+
builder.analyzing = true;
2828

2929
this.build( builder.addFlow( settings.slot, settings.cache, settings.context ), 'v4' );
3030

@@ -33,31 +33,34 @@ Node.prototype = {
3333

3434
builder.removeFlow();
3535

36-
builder.parsing = false;
36+
builder.analyzing = false;
3737

3838
},
3939

40-
parseAndBuildCode: function ( builder, output, settings ) {
40+
analyzeAndFlow: function ( builder, output, settings ) {
4141

4242
settings = settings || {};
4343

44-
this.parse( builder, settings );
44+
this.analyze( builder, settings );
4545

46-
return this.buildCode( builder, output, settings );
46+
return this.flow( builder, output, settings );
4747

4848
},
4949

50-
buildCode: function ( builder, output, settings ) {
50+
flow: function ( builder, output, settings ) {
5151

5252
settings = settings || {};
5353

54-
var data = { result: this.build( builder.addFlow( settings.slot, settings.cache, settings.context ), output ) };
54+
builder.addFlow( settings.slot, settings.cache, settings.context )
5555

56-
data.code = builder.clearNodeCode();
56+
var flow = {};
57+
flow.result = this.build( builder, output );
58+
flow.code = builder.clearNodeCode();
59+
flow.extra = builder.context.extra;
5760

5861
builder.removeFlow();
5962

60-
return data;
63+
return flow;
6164

6265
},
6366

@@ -67,7 +70,7 @@ Node.prototype = {
6770

6871
var data = builder.getNodeData( uuid || this );
6972

70-
if ( builder.parsing ) {
73+
if ( builder.analyzing ) {
7174

7275
this.appendDepsNode( builder, data, output );
7376

examples/js/nodes/core/NodeBuilder.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { Vector3Node } from '../inputs/Vector3Node.js';
1313
import { Vector4Node } from '../inputs/Vector4Node.js';
1414
import { TextureNode } from '../inputs/TextureNode.js';
1515
import { CubeTextureNode } from '../inputs/CubeTextureNode.js';
16+
import { TextureCubeNode } from '../misc/TextureCubeNode.js';
17+
1618

1719
var elements = NodeUtils.elements,
1820
constructors = [ 'float', 'vec2', 'vec3', 'vec4' ],
@@ -140,8 +142,7 @@ function NodeBuilder() {
140142

141143
// --
142144

143-
this.parsing = false;
144-
this.optimize = true;
145+
this.analyzing = false;
145146

146147
}
147148

@@ -278,6 +279,8 @@ NodeBuilder.prototype = {
278279
addContext: function ( context ) {
279280

280281
this.context = Object.assign( {}, this.context, context );
282+
this.context.extra = this.context.extra || {};
283+
281284
this.contexts.push( this.context );
282285

283286
return this;

examples/js/nodes/core/StructNode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function StructNode( src ) {
1111

1212
TempNode.call( this );
1313

14-
this.eval( src );
14+
this.parse( src );
1515

1616
}
1717

@@ -55,7 +55,7 @@ StructNode.prototype.generate = function ( builder, output ) {
5555

5656
};
5757

58-
StructNode.prototype.eval = function ( src ) {
58+
StructNode.prototype.parse = function ( src ) {
5959

6060
this.src = src || '';
6161

examples/js/nodes/core/TempNode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ TempNode.prototype.build = function ( builder, output, uuid, ns ) {
3838
var data = builder.getNodeData( uuid ),
3939
type = data.output || this.getType( builder );
4040

41-
if ( builder.parsing ) {
41+
if ( builder.analyzing ) {
4242

4343
if ( ( data.deps || 0 ) > 0 || this.getLabel() ) {
4444

@@ -56,7 +56,7 @@ TempNode.prototype.build = function ( builder, output, uuid, ns ) {
5656

5757
return data.name;
5858

59-
} else if ( ! this.getLabel() && ( ! this.getShared( builder, type ) || ( ! builder.optimize || data.deps === 1 ) ) ) {
59+
} else if ( ! this.getLabel() && ( ! this.getShared( builder, type ) || ( builder.context.ignoreCache || data.deps === 1 ) ) ) {
6060

6161
return Node.prototype.build.call( this, builder, output, uuid );
6262

examples/js/nodes/inputs/CubeTextureNode.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import { InputNode } from '../core/InputNode.js';
66
import { ReflectNode } from '../accessors/ReflectNode.js';
77
import { ColorSpaceNode } from '../utils/ColorSpaceNode.js';
8+
import { ExpressionNode } from '../core/ExpressionNode.js';
89

910
function CubeTextureNode( value, uv, bias ) {
1011

@@ -49,16 +50,27 @@ CubeTextureNode.prototype.generate = function ( builder, output ) {
4950
if ( bias ) code = 'texCubeBias( ' + cubetex + ', ' + uv + ', ' + bias + ' )';
5051
else code = 'texCube( ' + cubetex + ', ' + uv + ' )';
5152

52-
// add this context to replace ColorSpaceNode.input to code
53+
// add a custom context for fix incompatibility with the core
54+
// include ColorSpace function only for vertex shader (in fragment shader color space functions is added automatically by core)
55+
// this should be removed in the future
56+
// context.include =: is used to include or not functions if used FunctionNode
57+
// context.ignoreCache =: not create variables temp nodeT0..9 to optimize the code
58+
var context = { include: builder.isShader( 'vertex' ), ignoreCache: true };
59+
var outputType = this.getType( builder );
5360

54-
builder.addContext( { input: code, encoding: builder.getTextureEncodingFromMap( this.value ), include: builder.isShader( 'vertex' ) } );
61+
builder.addContext( context );
5562

56-
this.colorSpace = this.colorSpace || new ColorSpaceNode( this );
57-
code = this.colorSpace.build( builder, this.type );
63+
this.colorSpace = this.colorSpace || new ColorSpaceNode( new ExpressionNode('', outputType ) );
64+
this.colorSpace.fromEncoding( builder.getTextureEncodingFromMap( this.value ) );
65+
this.colorSpace.input.parse( code );
66+
67+
code = this.colorSpace.build( builder, outputType );
68+
69+
// end custom context
5870

5971
builder.removeContext();
6072

61-
return builder.format( code, this.type, output );
73+
return builder.format( code, outputType, output );
6274

6375
};
6476

0 commit comments

Comments
 (0)