@plastic-software/three 0.179.0 → 0.180.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/three.cjs +166 -106
- package/build/three.core.js +112 -20
- package/build/three.core.min.js +1 -1
- package/build/three.module.js +55 -89
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +30 -5
- package/build/three.tsl.min.js +1 -1
- package/build/three.webgpu.js +2896 -1048
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +2896 -1048
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/Addons.js +1 -1
- package/examples/jsm/controls/ArcballControls.js +7 -7
- package/examples/jsm/controls/DragControls.js +6 -56
- package/examples/jsm/controls/FirstPersonControls.js +2 -2
- package/examples/jsm/controls/PointerLockControls.js +0 -8
- package/examples/jsm/exporters/GLTFExporter.js +30 -22
- package/examples/jsm/exporters/KTX2Exporter.js +4 -2
- package/examples/jsm/exporters/PLYExporter.js +1 -1
- package/examples/jsm/libs/ktx-parse.module.js +1 -1
- package/examples/jsm/lines/Line2.js +3 -3
- package/examples/jsm/lines/LineGeometry.js +1 -1
- package/examples/jsm/lines/LineSegments2.js +2 -2
- package/examples/jsm/lines/Wireframe.js +2 -2
- package/examples/jsm/lines/WireframeGeometry2.js +1 -1
- package/examples/jsm/lines/webgpu/LineSegments2.js +1 -1
- package/examples/jsm/lines/webgpu/Wireframe.js +1 -1
- package/examples/jsm/loaders/ColladaLoader.js +1 -1
- package/examples/jsm/loaders/EXRLoader.js +5 -5
- package/examples/jsm/loaders/GLTFLoader.js +9 -5
- package/examples/jsm/loaders/HDRCubeTextureLoader.js +5 -5
- package/examples/jsm/loaders/HDRLoader.js +486 -0
- package/examples/jsm/loaders/KTX2Loader.js +112 -32
- package/examples/jsm/loaders/RGBELoader.js +7 -473
- package/examples/jsm/loaders/TTFLoader.js +4 -4
- package/examples/jsm/loaders/UltraHDRLoader.js +1 -1
- package/examples/jsm/loaders/lwo/IFFParser.js +1 -1
- package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
- package/examples/jsm/math/ColorSpaces.js +19 -1
- package/examples/jsm/math/ConvexHull.js +2 -2
- package/examples/jsm/math/Lut.js +2 -2
- package/examples/jsm/misc/MD2CharacterComplex.js +1 -1
- package/examples/jsm/misc/ProgressiveLightMap.js +1 -1
- package/examples/jsm/misc/Volume.js +1 -1
- package/examples/jsm/postprocessing/OutlinePass.js +1 -1
- package/examples/jsm/postprocessing/SSRPass.js +37 -8
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +1 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +22 -19
- package/examples/jsm/transpiler/TSLEncoder.js +2 -10
- package/examples/jsm/transpiler/WGSLEncoder.js +24 -0
- package/examples/jsm/tsl/display/AnamorphicNode.js +27 -4
- package/examples/jsm/tsl/display/BloomNode.js +3 -3
- package/examples/jsm/tsl/display/ChromaticAberrationNode.js +2 -1
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +439 -90
- package/examples/jsm/tsl/display/GTAONode.js +8 -0
- package/examples/jsm/tsl/display/GaussianBlurNode.js +47 -35
- package/examples/jsm/tsl/display/OutlineNode.js +2 -2
- package/examples/jsm/tsl/display/SSRNode.js +180 -65
- package/examples/jsm/tsl/display/TRAANode.js +1 -1
- package/examples/jsm/tsl/display/boxBlur.js +64 -0
- package/examples/jsm/tsl/display/hashBlur.js +15 -18
- package/examples/jsm/utils/BufferGeometryUtils.js +1 -1
- package/examples/jsm/utils/ShadowMapViewerGPU.js +12 -5
- package/examples/jsm/webxr/OculusHandModel.js +1 -1
- package/package.json +1 -1
- package/src/Three.Core.js +1 -0
- package/src/Three.TSL.js +29 -4
- package/src/animation/AnimationClip.js +17 -2
- package/src/constants.js +11 -3
- package/src/core/BufferGeometry.js +2 -2
- package/src/extras/TextureUtils.js +2 -1
- package/src/extras/lib/earcut.js +1 -1
- package/src/lights/webgpu/ProjectorLight.js +1 -1
- package/src/materials/Material.js +12 -0
- package/src/materials/MeshDistanceMaterial.js +1 -1
- package/src/materials/nodes/PointsNodeMaterial.js +81 -28
- package/src/materials/nodes/SpriteNodeMaterial.js +3 -15
- package/src/materials/nodes/manager/NodeMaterialObserver.js +1 -1
- package/src/math/ColorManagement.js +7 -1
- package/src/nodes/Nodes.js +3 -0
- package/src/nodes/TSL.js +3 -0
- package/src/nodes/accessors/BufferNode.js +1 -1
- package/src/nodes/accessors/Camera.js +133 -7
- package/src/nodes/accessors/ClippingNode.js +6 -5
- package/src/nodes/accessors/CubeTextureNode.js +2 -2
- package/src/nodes/accessors/InstanceNode.js +3 -1
- package/src/nodes/accessors/Object3DNode.js +1 -1
- package/src/nodes/accessors/ReferenceBaseNode.js +1 -1
- package/src/nodes/accessors/ReferenceNode.js +1 -1
- package/src/nodes/accessors/Texture3DNode.js +13 -0
- package/src/nodes/accessors/TextureNode.js +71 -19
- package/src/nodes/code/FunctionCallNode.js +19 -0
- package/src/nodes/code/FunctionNode.js +23 -0
- package/src/nodes/core/AssignNode.js +4 -3
- package/src/nodes/core/ContextNode.js +24 -0
- package/src/nodes/core/Node.js +16 -20
- package/src/nodes/core/NodeBuilder.js +48 -14
- package/src/nodes/core/NodeFrame.js +1 -1
- package/src/nodes/core/NodeUniform.js +1 -1
- package/src/nodes/core/NodeUtils.js +1 -2
- package/src/nodes/core/StackNode.js +29 -4
- package/src/nodes/core/StructNode.js +5 -5
- package/src/nodes/core/StructTypeNode.js +1 -0
- package/src/nodes/core/SubBuildNode.js +2 -2
- package/src/nodes/core/UniformNode.js +16 -9
- package/src/nodes/core/VarNode.js +0 -21
- package/src/nodes/display/FrontFacingNode.js +4 -8
- package/src/nodes/display/PassNode.js +1 -1
- package/src/nodes/display/ScreenNode.js +42 -13
- package/src/nodes/display/ViewportDepthTextureNode.js +16 -4
- package/src/nodes/display/ViewportSharedTextureNode.js +12 -0
- package/src/nodes/display/ViewportTextureNode.js +42 -12
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +430 -0
- package/src/nodes/lighting/LightsNode.js +1 -1
- package/src/nodes/math/BitcastNode.js +156 -0
- package/src/nodes/math/ConditionalNode.js +18 -2
- package/src/nodes/math/MathNode.js +3 -15
- package/src/nodes/math/OperatorNode.js +4 -3
- package/src/nodes/tsl/TSLCore.js +432 -152
- package/src/nodes/utils/JoinNode.js +3 -1
- package/src/nodes/utils/MemberNode.js +58 -7
- package/src/nodes/utils/RTTNode.js +1 -1
- package/src/nodes/utils/ReflectorNode.js +51 -7
- package/src/nodes/utils/SampleNode.js +12 -2
- package/src/nodes/utils/SplitNode.js +11 -0
- package/src/nodes/utils/Timer.js +0 -47
- package/src/objects/BatchedMesh.js +2 -2
- package/src/objects/LOD.js +1 -1
- package/src/objects/Sprite.js +2 -2
- package/src/renderers/WebGLRenderer.js +0 -9
- package/src/renderers/common/Attributes.js +1 -1
- package/src/renderers/common/Backend.js +19 -1
- package/src/renderers/common/Bindings.js +2 -0
- package/src/renderers/common/ChainMap.js +1 -1
- package/src/renderers/common/DataMap.js +1 -1
- package/src/renderers/common/Pipelines.js +1 -1
- package/src/renderers/common/RenderContext.js +2 -2
- package/src/renderers/common/RenderObject.js +14 -2
- package/src/renderers/common/Renderer.js +39 -19
- package/src/renderers/common/SampledTexture.js +1 -1
- package/src/renderers/common/Sampler.js +25 -13
- package/src/renderers/common/Textures.js +34 -12
- package/src/renderers/common/TimestampQueryPool.js +3 -3
- package/src/renderers/common/XRManager.js +35 -19
- package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
- package/src/renderers/common/nodes/NodeLibrary.js +5 -5
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +7 -15
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +1 -1
- package/src/renderers/webgl/WebGLProgram.js +4 -4
- package/src/renderers/webgl/WebGLShadowMap.js +1 -1
- package/src/renderers/webgl/WebGLTextures.js +1 -0
- package/src/renderers/webgl/WebGLUtils.js +3 -2
- package/src/renderers/webgl-fallback/WebGLBackend.js +186 -135
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +110 -17
- package/src/renderers/webgl-fallback/utils/WebGLState.js +1 -1
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +52 -3
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -10
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +3 -2
- package/src/renderers/webgpu/WebGPUBackend.js +35 -31
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +124 -34
- package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -2
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +9 -18
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +114 -25
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +3 -3
- package/src/renderers/webxr/WebXRManager.js +39 -24
- package/src/textures/ExternalTexture.js +15 -4
- package/src/textures/Source.js +1 -1
- package/src/textures/VideoTexture.js +0 -3
- package/examples/jsm/loaders/RGBMLoader.js +0 -1148
package/src/nodes/tsl/TSLCore.js
CHANGED
|
@@ -13,6 +13,8 @@ let currentStack = null;
|
|
|
13
13
|
|
|
14
14
|
const NodeElements = new Map();
|
|
15
15
|
|
|
16
|
+
// Extend Node Class for TSL using prototype
|
|
17
|
+
|
|
16
18
|
export function addMethodChaining( name, nodeElement ) {
|
|
17
19
|
|
|
18
20
|
if ( NodeElements.has( name ) ) {
|
|
@@ -26,152 +28,274 @@ export function addMethodChaining( name, nodeElement ) {
|
|
|
26
28
|
|
|
27
29
|
NodeElements.set( name, nodeElement );
|
|
28
30
|
|
|
31
|
+
if ( name !== 'assign' ) {
|
|
32
|
+
|
|
33
|
+
// Changing Node prototype to add method chaining
|
|
34
|
+
|
|
35
|
+
Node.prototype[ name ] = function ( ...params ) {
|
|
36
|
+
|
|
37
|
+
//if ( name === 'toVarIntent' ) return this;
|
|
38
|
+
|
|
39
|
+
return this.isStackNode ? this.add( nodeElement( ...params ) ) : nodeElement( this, ...params );
|
|
40
|
+
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Adding assign method chaining
|
|
44
|
+
|
|
45
|
+
Node.prototype[ name + 'Assign' ] = function ( ...params ) {
|
|
46
|
+
|
|
47
|
+
return this.isStackNode ? this.assign( params[ 0 ], nodeElement( ...params ) ) : this.assign( nodeElement( this, ...params ) );
|
|
48
|
+
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
29
53
|
}
|
|
30
54
|
|
|
31
55
|
const parseSwizzle = ( props ) => props.replace( /r|s/g, 'x' ).replace( /g|t/g, 'y' ).replace( /b|p/g, 'z' ).replace( /a|q/g, 'w' );
|
|
32
56
|
const parseSwizzleAndSort = ( props ) => parseSwizzle( props ).split( '' ).sort().join( '' );
|
|
33
57
|
|
|
34
|
-
|
|
58
|
+
Node.prototype.assign = function ( ...params ) {
|
|
59
|
+
|
|
60
|
+
if ( this.isStackNode !== true ) {
|
|
35
61
|
|
|
36
|
-
|
|
62
|
+
if ( currentStack !== null ) {
|
|
37
63
|
|
|
38
|
-
|
|
64
|
+
currentStack.assign( this, ...params );
|
|
39
65
|
|
|
40
|
-
|
|
66
|
+
} else {
|
|
67
|
+
|
|
68
|
+
console.error( 'THREE.TSL: No stack defined for assign operation. Make sure the assign is inside a Fn().' );
|
|
41
69
|
|
|
42
|
-
|
|
70
|
+
}
|
|
43
71
|
|
|
44
|
-
|
|
72
|
+
return this;
|
|
45
73
|
|
|
46
|
-
|
|
74
|
+
} else {
|
|
47
75
|
|
|
48
|
-
|
|
76
|
+
const nodeElement = NodeElements.get( 'assign' );
|
|
49
77
|
|
|
50
|
-
|
|
78
|
+
return this.add( nodeElement( ...params ) );
|
|
51
79
|
|
|
52
|
-
|
|
80
|
+
}
|
|
53
81
|
|
|
54
|
-
|
|
82
|
+
};
|
|
55
83
|
|
|
56
|
-
|
|
84
|
+
Node.prototype.toVarIntent = function () {
|
|
85
|
+
|
|
86
|
+
return this;
|
|
87
|
+
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
Node.prototype.get = function ( value ) {
|
|
91
|
+
|
|
92
|
+
return new MemberNode( this, value );
|
|
93
|
+
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// Cache prototype for TSL
|
|
57
97
|
|
|
58
|
-
|
|
98
|
+
const proto = {};
|
|
59
99
|
|
|
60
|
-
|
|
100
|
+
// Set swizzle properties for xyzw, rgba, and stpq.
|
|
61
101
|
|
|
62
|
-
|
|
102
|
+
function setProtoSwizzle( property, altA, altB ) {
|
|
63
103
|
|
|
64
|
-
|
|
104
|
+
// swizzle properties
|
|
65
105
|
|
|
66
|
-
|
|
106
|
+
proto[ property ] = proto[ altA ] = proto[ altB ] = {
|
|
67
107
|
|
|
68
|
-
|
|
108
|
+
get() {
|
|
69
109
|
|
|
70
|
-
|
|
110
|
+
this._cache = this._cache || {};
|
|
71
111
|
|
|
72
|
-
|
|
112
|
+
//
|
|
73
113
|
|
|
74
|
-
|
|
114
|
+
let split = this._cache[ property ];
|
|
75
115
|
|
|
76
|
-
|
|
116
|
+
if ( split === undefined ) {
|
|
77
117
|
|
|
78
|
-
|
|
118
|
+
split = new SplitNode( this, property );
|
|
79
119
|
|
|
80
|
-
|
|
120
|
+
this._cache[ property ] = split;
|
|
81
121
|
|
|
82
|
-
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return split;
|
|
125
|
+
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
set( value ) {
|
|
129
|
+
|
|
130
|
+
this[ property ].assign( nodeObject( value ) );
|
|
131
|
+
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// set properties ( swizzle ) and sort to xyzw sequence
|
|
137
|
+
|
|
138
|
+
const propUpper = property.toUpperCase();
|
|
139
|
+
const altAUpper = altA.toUpperCase();
|
|
140
|
+
const altBUpper = altB.toUpperCase();
|
|
141
|
+
|
|
142
|
+
// Set methods for swizzle properties
|
|
143
|
+
|
|
144
|
+
Node.prototype[ 'set' + propUpper ] = Node.prototype[ 'set' + altAUpper ] = Node.prototype[ 'set' + altBUpper ] = function ( value ) {
|
|
145
|
+
|
|
146
|
+
const swizzle = parseSwizzleAndSort( property );
|
|
147
|
+
|
|
148
|
+
return new SetNode( this, swizzle, nodeObject( value ) );
|
|
149
|
+
|
|
150
|
+
};
|
|
83
151
|
|
|
84
|
-
|
|
152
|
+
// Set methods for flip properties
|
|
85
153
|
|
|
86
|
-
|
|
154
|
+
Node.prototype[ 'flip' + propUpper ] = Node.prototype[ 'flip' + altAUpper ] = Node.prototype[ 'flip' + altBUpper ] = function () {
|
|
87
155
|
|
|
88
|
-
|
|
156
|
+
const swizzle = parseSwizzleAndSort( property );
|
|
89
157
|
|
|
90
|
-
|
|
158
|
+
return new FlipNode( this, swizzle );
|
|
91
159
|
|
|
92
|
-
|
|
160
|
+
};
|
|
93
161
|
|
|
94
|
-
|
|
162
|
+
}
|
|
95
163
|
|
|
96
|
-
|
|
164
|
+
const swizzleA = [ 'x', 'y', 'z', 'w' ];
|
|
165
|
+
const swizzleB = [ 'r', 'g', 'b', 'a' ];
|
|
166
|
+
const swizzleC = [ 's', 't', 'p', 'q' ];
|
|
97
167
|
|
|
98
|
-
|
|
168
|
+
for ( let a = 0; a < 4; a ++ ) {
|
|
99
169
|
|
|
100
|
-
|
|
170
|
+
let prop = swizzleA[ a ];
|
|
171
|
+
let altA = swizzleB[ a ];
|
|
172
|
+
let altB = swizzleC[ a ];
|
|
101
173
|
|
|
102
|
-
|
|
174
|
+
setProtoSwizzle( prop, altA, altB );
|
|
103
175
|
|
|
104
|
-
|
|
176
|
+
for ( let b = 0; b < 4; b ++ ) {
|
|
105
177
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
178
|
+
prop = swizzleA[ a ] + swizzleA[ b ];
|
|
179
|
+
altA = swizzleB[ a ] + swizzleB[ b ];
|
|
180
|
+
altB = swizzleC[ a ] + swizzleC[ b ];
|
|
109
181
|
|
|
110
|
-
|
|
182
|
+
setProtoSwizzle( prop, altA, altB );
|
|
111
183
|
|
|
112
|
-
|
|
184
|
+
for ( let c = 0; c < 4; c ++ ) {
|
|
113
185
|
|
|
114
|
-
|
|
186
|
+
prop = swizzleA[ a ] + swizzleA[ b ] + swizzleA[ c ];
|
|
187
|
+
altA = swizzleB[ a ] + swizzleB[ b ] + swizzleB[ c ];
|
|
188
|
+
altB = swizzleC[ a ] + swizzleC[ b ] + swizzleC[ c ];
|
|
115
189
|
|
|
116
|
-
|
|
190
|
+
setProtoSwizzle( prop, altA, altB );
|
|
117
191
|
|
|
118
|
-
|
|
192
|
+
for ( let d = 0; d < 4; d ++ ) {
|
|
119
193
|
|
|
120
|
-
|
|
194
|
+
prop = swizzleA[ a ] + swizzleA[ b ] + swizzleA[ c ] + swizzleA[ d ];
|
|
195
|
+
altA = swizzleB[ a ] + swizzleB[ b ] + swizzleB[ c ] + swizzleB[ d ];
|
|
196
|
+
altB = swizzleC[ a ] + swizzleC[ b ] + swizzleC[ c ] + swizzleC[ d ];
|
|
121
197
|
|
|
122
|
-
|
|
198
|
+
setProtoSwizzle( prop, altA, altB );
|
|
123
199
|
|
|
124
200
|
}
|
|
125
201
|
|
|
126
202
|
}
|
|
127
203
|
|
|
128
|
-
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Set/get static properties for array elements (0-31).
|
|
209
|
+
|
|
210
|
+
for ( let i = 0; i < 32; i ++ ) {
|
|
129
211
|
|
|
130
|
-
|
|
212
|
+
proto[ i ] = {
|
|
131
213
|
|
|
132
|
-
|
|
214
|
+
get() {
|
|
133
215
|
|
|
134
|
-
|
|
216
|
+
this._cache = this._cache || {};
|
|
135
217
|
|
|
136
|
-
//
|
|
218
|
+
//
|
|
137
219
|
|
|
138
|
-
|
|
220
|
+
let element = this._cache[ i ];
|
|
139
221
|
|
|
140
|
-
|
|
222
|
+
if ( element === undefined ) {
|
|
141
223
|
|
|
142
|
-
|
|
224
|
+
element = new ArrayElementNode( this, new ConstNode( i, 'uint' ) );
|
|
225
|
+
|
|
226
|
+
this._cache[ i ] = element;
|
|
143
227
|
|
|
144
228
|
}
|
|
145
229
|
|
|
230
|
+
return element;
|
|
231
|
+
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
set( value ) {
|
|
235
|
+
|
|
236
|
+
this[ i ].assign( nodeObject( value ) );
|
|
237
|
+
|
|
146
238
|
}
|
|
147
239
|
|
|
148
|
-
|
|
240
|
+
};
|
|
149
241
|
|
|
150
|
-
|
|
242
|
+
}
|
|
151
243
|
|
|
152
|
-
|
|
244
|
+
/*
|
|
245
|
+
// Set properties for width, height, and depth.
|
|
153
246
|
|
|
154
|
-
|
|
155
|
-
const nodeBuilderFunctionsCacheMap = new WeakMap();
|
|
247
|
+
function setProtoProperty( property, target ) {
|
|
156
248
|
|
|
157
|
-
|
|
249
|
+
proto[ property ] = {
|
|
158
250
|
|
|
159
|
-
|
|
251
|
+
get() {
|
|
160
252
|
|
|
161
|
-
|
|
253
|
+
this._cache = this._cache || {};
|
|
254
|
+
|
|
255
|
+
//
|
|
256
|
+
|
|
257
|
+
let split = this._cache[ target ];
|
|
258
|
+
|
|
259
|
+
if ( split === undefined ) {
|
|
162
260
|
|
|
163
|
-
|
|
261
|
+
split = new SplitNode( this, target );
|
|
164
262
|
|
|
165
|
-
|
|
263
|
+
this._cache[ target ] = split;
|
|
166
264
|
|
|
167
|
-
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return split;
|
|
268
|
+
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
set( value ) {
|
|
168
272
|
|
|
169
|
-
|
|
170
|
-
nodeObjectsCacheMap.set( nodeObject, nodeObject );
|
|
273
|
+
this[ target ].assign( nodeObject( value ) );
|
|
171
274
|
|
|
172
275
|
}
|
|
173
276
|
|
|
174
|
-
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
setProtoProperty( 'width', 'x' );
|
|
282
|
+
setProtoProperty( 'height', 'y' );
|
|
283
|
+
setProtoProperty( 'depth', 'z' );
|
|
284
|
+
*/
|
|
285
|
+
|
|
286
|
+
Object.defineProperties( Node.prototype, proto );
|
|
287
|
+
|
|
288
|
+
// --- FINISH ---
|
|
289
|
+
|
|
290
|
+
const nodeBuilderFunctionsCacheMap = new WeakMap();
|
|
291
|
+
|
|
292
|
+
const ShaderNodeObject = function ( obj, altType = null ) {
|
|
293
|
+
|
|
294
|
+
const type = getValueType( obj );
|
|
295
|
+
|
|
296
|
+
if ( type === 'node' ) {
|
|
297
|
+
|
|
298
|
+
return obj;
|
|
175
299
|
|
|
176
300
|
} else if ( ( altType === null && ( type === 'float' || type === 'boolean' ) ) || ( type && type !== 'shader' && type !== 'string' ) ) {
|
|
177
301
|
|
|
@@ -322,12 +446,12 @@ const ShaderNodeImmutable = function ( NodeClass, ...params ) {
|
|
|
322
446
|
|
|
323
447
|
class ShaderCallNodeInternal extends Node {
|
|
324
448
|
|
|
325
|
-
constructor( shaderNode,
|
|
449
|
+
constructor( shaderNode, rawInputs ) {
|
|
326
450
|
|
|
327
451
|
super();
|
|
328
452
|
|
|
329
453
|
this.shaderNode = shaderNode;
|
|
330
|
-
this.
|
|
454
|
+
this.rawInputs = rawInputs;
|
|
331
455
|
|
|
332
456
|
this.isShaderCallNodeInternal = true;
|
|
333
457
|
|
|
@@ -347,7 +471,7 @@ class ShaderCallNodeInternal extends Node {
|
|
|
347
471
|
|
|
348
472
|
call( builder ) {
|
|
349
473
|
|
|
350
|
-
const { shaderNode,
|
|
474
|
+
const { shaderNode, rawInputs } = this;
|
|
351
475
|
|
|
352
476
|
const properties = builder.getNodeProperties( shaderNode );
|
|
353
477
|
|
|
@@ -392,40 +516,48 @@ class ShaderCallNodeInternal extends Node {
|
|
|
392
516
|
|
|
393
517
|
builder.addInclude( functionNode );
|
|
394
518
|
|
|
395
|
-
|
|
519
|
+
//
|
|
396
520
|
|
|
397
|
-
|
|
521
|
+
const inputs = rawInputs ? getLayoutParameters( rawInputs ) : null;
|
|
398
522
|
|
|
399
|
-
|
|
523
|
+
result = nodeObject( functionNode.call( inputs ) );
|
|
400
524
|
|
|
401
|
-
|
|
525
|
+
} else {
|
|
402
526
|
|
|
403
|
-
|
|
404
|
-
// so we can call TSL functions using the syntax `Fn( ( { r, g, b } ) => { ... } )`
|
|
405
|
-
// and call through `fn( 0, 1, 0 )` or `fn( { r: 0, g: 1, b: 0 } )`
|
|
527
|
+
const secureNodeBuilder = new Proxy( builder, {
|
|
406
528
|
|
|
407
|
-
|
|
529
|
+
get: ( target, property, receiver ) => {
|
|
408
530
|
|
|
409
|
-
|
|
410
|
-
get: ( target, property, receiver ) => {
|
|
531
|
+
let value;
|
|
411
532
|
|
|
412
|
-
|
|
533
|
+
if ( Symbol.iterator === property ) {
|
|
413
534
|
|
|
414
|
-
|
|
535
|
+
value = function* () {
|
|
415
536
|
|
|
416
|
-
|
|
537
|
+
yield undefined;
|
|
417
538
|
|
|
418
|
-
|
|
539
|
+
};
|
|
419
540
|
|
|
420
|
-
|
|
541
|
+
} else {
|
|
542
|
+
|
|
543
|
+
value = Reflect.get( target, property, receiver );
|
|
421
544
|
|
|
422
545
|
}
|
|
423
|
-
} );
|
|
424
546
|
|
|
425
|
-
|
|
547
|
+
return value;
|
|
548
|
+
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
} );
|
|
552
|
+
|
|
553
|
+
//
|
|
554
|
+
|
|
555
|
+
const inputs = rawInputs ? getProxyParameters( rawInputs ) : null;
|
|
556
|
+
|
|
557
|
+
const hasParameters = Array.isArray( rawInputs ) ? rawInputs.length > 0 : rawInputs !== null;
|
|
426
558
|
|
|
427
559
|
const jsFunc = shaderNode.jsFunc;
|
|
428
|
-
const outputNode =
|
|
560
|
+
const outputNode = hasParameters || jsFunc.length > 1 ? jsFunc( inputs, secureNodeBuilder ) : jsFunc( secureNodeBuilder );
|
|
429
561
|
|
|
430
562
|
result = nodeObject( outputNode );
|
|
431
563
|
|
|
@@ -528,6 +660,110 @@ class ShaderCallNodeInternal extends Node {
|
|
|
528
660
|
|
|
529
661
|
}
|
|
530
662
|
|
|
663
|
+
function getLayoutParameters( params ) {
|
|
664
|
+
|
|
665
|
+
let output;
|
|
666
|
+
|
|
667
|
+
nodeObjects( params );
|
|
668
|
+
|
|
669
|
+
const isArrayAsParameter = params[ 0 ] && ( params[ 0 ].isNode || Object.getPrototypeOf( params[ 0 ] ) !== Object.prototype );
|
|
670
|
+
|
|
671
|
+
if ( isArrayAsParameter ) {
|
|
672
|
+
|
|
673
|
+
output = [ ...params ];
|
|
674
|
+
|
|
675
|
+
} else {
|
|
676
|
+
|
|
677
|
+
output = params[ 0 ];
|
|
678
|
+
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
return output;
|
|
682
|
+
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
function getProxyParameters( params ) {
|
|
686
|
+
|
|
687
|
+
let index = 0;
|
|
688
|
+
|
|
689
|
+
nodeObjects( params );
|
|
690
|
+
|
|
691
|
+
return new Proxy( params, {
|
|
692
|
+
|
|
693
|
+
get: ( target, property, receiver ) => {
|
|
694
|
+
|
|
695
|
+
let value;
|
|
696
|
+
|
|
697
|
+
if ( property === 'length' ) {
|
|
698
|
+
|
|
699
|
+
value = params.length;
|
|
700
|
+
|
|
701
|
+
return value;
|
|
702
|
+
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
if ( Symbol.iterator === property ) {
|
|
706
|
+
|
|
707
|
+
value = function* () {
|
|
708
|
+
|
|
709
|
+
for ( const inputNode of params ) {
|
|
710
|
+
|
|
711
|
+
yield nodeObject( inputNode );
|
|
712
|
+
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
} else {
|
|
718
|
+
|
|
719
|
+
if ( params.length > 0 ) {
|
|
720
|
+
|
|
721
|
+
if ( Object.getPrototypeOf( params[ 0 ] ) === Object.prototype ) {
|
|
722
|
+
|
|
723
|
+
const objectTarget = params[ 0 ];
|
|
724
|
+
|
|
725
|
+
if ( objectTarget[ property ] === undefined ) {
|
|
726
|
+
|
|
727
|
+
value = objectTarget[ index ++ ];
|
|
728
|
+
|
|
729
|
+
} else {
|
|
730
|
+
|
|
731
|
+
value = Reflect.get( objectTarget, property, receiver );
|
|
732
|
+
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
} else if ( params[ 0 ] instanceof Node ) {
|
|
736
|
+
|
|
737
|
+
if ( params[ property ] === undefined ) {
|
|
738
|
+
|
|
739
|
+
value = params[ index ++ ];
|
|
740
|
+
|
|
741
|
+
} else {
|
|
742
|
+
|
|
743
|
+
value = Reflect.get( params, property, receiver );
|
|
744
|
+
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
} else {
|
|
750
|
+
|
|
751
|
+
value = Reflect.get( target, property, receiver );
|
|
752
|
+
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
value = nodeObject( value );
|
|
756
|
+
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
return value;
|
|
760
|
+
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
} );
|
|
764
|
+
|
|
765
|
+
}
|
|
766
|
+
|
|
531
767
|
class ShaderNodeInternal extends Node {
|
|
532
768
|
|
|
533
769
|
constructor( jsFunc, nodeType ) {
|
|
@@ -551,11 +787,9 @@ class ShaderNodeInternal extends Node {
|
|
|
551
787
|
|
|
552
788
|
}
|
|
553
789
|
|
|
554
|
-
call(
|
|
790
|
+
call( rawInputs = null ) {
|
|
555
791
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
return nodeObject( new ShaderCallNodeInternal( this, inputs ) );
|
|
792
|
+
return nodeObject( new ShaderCallNodeInternal( this, rawInputs ) );
|
|
559
793
|
|
|
560
794
|
}
|
|
561
795
|
|
|
@@ -611,7 +845,25 @@ const ConvertType = function ( type, cacheMap = null ) {
|
|
|
611
845
|
|
|
612
846
|
return ( ...params ) => {
|
|
613
847
|
|
|
614
|
-
|
|
848
|
+
for ( const param of params ) {
|
|
849
|
+
|
|
850
|
+
if ( param === undefined ) {
|
|
851
|
+
|
|
852
|
+
console.error( `THREE.TSL: Invalid parameter for the type "${ type }".` );
|
|
853
|
+
|
|
854
|
+
return nodeObject( new ConstNode( 0, type ) );
|
|
855
|
+
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
if ( params.length === 0 || ( ! [ 'bool', 'float', 'int', 'uint' ].includes( type ) && params.every( param => {
|
|
861
|
+
|
|
862
|
+
const paramType = typeof param;
|
|
863
|
+
|
|
864
|
+
return paramType !== 'object' && paramType !== 'function';
|
|
865
|
+
|
|
866
|
+
} ) ) ) {
|
|
615
867
|
|
|
616
868
|
params = [ getValueFromType( type, ...params ) ];
|
|
617
869
|
|
|
@@ -650,7 +902,7 @@ export const getConstNodeType = ( value ) => ( value !== undefined && value !==
|
|
|
650
902
|
|
|
651
903
|
export function ShaderNode( jsFunc, nodeType ) {
|
|
652
904
|
|
|
653
|
-
return new
|
|
905
|
+
return new ShaderNodeInternal( jsFunc, nodeType );
|
|
654
906
|
|
|
655
907
|
}
|
|
656
908
|
|
|
@@ -664,119 +916,147 @@ export const nodeProxyIntent = ( NodeClass, scope = null, factor = null, setting
|
|
|
664
916
|
|
|
665
917
|
let fnId = 0;
|
|
666
918
|
|
|
667
|
-
|
|
919
|
+
class FnNode extends Node {
|
|
668
920
|
|
|
669
|
-
|
|
921
|
+
constructor( jsFunc, layout = null ) {
|
|
670
922
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
if ( typeof layout === 'object' ) {
|
|
923
|
+
super();
|
|
674
924
|
|
|
675
|
-
|
|
925
|
+
let nodeType = null;
|
|
676
926
|
|
|
677
|
-
|
|
927
|
+
if ( layout !== null ) {
|
|
678
928
|
|
|
679
|
-
if ( typeof layout === '
|
|
929
|
+
if ( typeof layout === 'object' ) {
|
|
680
930
|
|
|
681
|
-
nodeType = layout;
|
|
931
|
+
nodeType = layout.return;
|
|
682
932
|
|
|
683
933
|
} else {
|
|
684
934
|
|
|
685
|
-
|
|
935
|
+
if ( typeof layout === 'string' ) {
|
|
936
|
+
|
|
937
|
+
nodeType = layout;
|
|
938
|
+
|
|
939
|
+
} else {
|
|
940
|
+
|
|
941
|
+
console.error( 'THREE.TSL: Invalid layout type.' );
|
|
942
|
+
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
layout = null;
|
|
686
946
|
|
|
687
947
|
}
|
|
688
948
|
|
|
689
|
-
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
this.shaderNode = new ShaderNode( jsFunc, nodeType );
|
|
952
|
+
|
|
953
|
+
if ( layout !== null ) {
|
|
954
|
+
|
|
955
|
+
this.setLayout( layout );
|
|
690
956
|
|
|
691
957
|
}
|
|
692
958
|
|
|
959
|
+
this.isFn = true;
|
|
960
|
+
|
|
693
961
|
}
|
|
694
962
|
|
|
695
|
-
|
|
963
|
+
setLayout( layout ) {
|
|
696
964
|
|
|
697
|
-
|
|
965
|
+
const nodeType = this.shaderNode.nodeType;
|
|
698
966
|
|
|
699
|
-
|
|
967
|
+
if ( typeof layout.inputs !== 'object' ) {
|
|
700
968
|
|
|
701
|
-
|
|
969
|
+
const fullLayout = {
|
|
970
|
+
name: 'fn' + fnId ++,
|
|
971
|
+
type: nodeType,
|
|
972
|
+
inputs: []
|
|
973
|
+
};
|
|
702
974
|
|
|
703
|
-
|
|
975
|
+
for ( const name in layout ) {
|
|
704
976
|
|
|
705
|
-
|
|
977
|
+
if ( name === 'return' ) continue;
|
|
706
978
|
|
|
707
|
-
|
|
979
|
+
fullLayout.inputs.push( {
|
|
980
|
+
name: name,
|
|
981
|
+
type: layout[ name ]
|
|
982
|
+
} );
|
|
708
983
|
|
|
709
|
-
|
|
984
|
+
}
|
|
710
985
|
|
|
711
|
-
|
|
986
|
+
layout = fullLayout;
|
|
712
987
|
|
|
713
988
|
}
|
|
714
989
|
|
|
715
|
-
|
|
990
|
+
this.shaderNode.setLayout( layout );
|
|
991
|
+
|
|
992
|
+
return this;
|
|
993
|
+
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
getNodeType( builder ) {
|
|
997
|
+
|
|
998
|
+
return this.shaderNode.getNodeType( builder ) || 'float';
|
|
999
|
+
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
call( ...params ) {
|
|
716
1003
|
|
|
717
|
-
|
|
1004
|
+
const fnCall = this.shaderNode.call( params );
|
|
1005
|
+
|
|
1006
|
+
if ( this.shaderNode.nodeType === 'void' ) fnCall.toStack();
|
|
718
1007
|
|
|
719
1008
|
return fnCall.toVarIntent();
|
|
720
1009
|
|
|
721
|
-
}
|
|
1010
|
+
}
|
|
722
1011
|
|
|
723
|
-
|
|
724
|
-
fn.id = shaderNode.id;
|
|
1012
|
+
once( subBuilds = null ) {
|
|
725
1013
|
|
|
726
|
-
|
|
1014
|
+
this.shaderNode.once = true;
|
|
1015
|
+
this.shaderNode.subBuilds = subBuilds;
|
|
727
1016
|
|
|
728
|
-
|
|
729
|
-
fn.getCacheKey = ( ...params ) => shaderNode.getCacheKey( ...params );
|
|
1017
|
+
return this;
|
|
730
1018
|
|
|
731
|
-
|
|
1019
|
+
}
|
|
732
1020
|
|
|
733
|
-
|
|
1021
|
+
generate( builder ) {
|
|
734
1022
|
|
|
735
|
-
|
|
1023
|
+
const type = this.getNodeType( builder );
|
|
736
1024
|
|
|
737
|
-
|
|
1025
|
+
console.error( 'THREE.TSL: "Fn()" was declared but not invoked. Try calling it like "Fn()( ...params )".' );
|
|
738
1026
|
|
|
739
|
-
|
|
1027
|
+
return builder.generateConst( type );
|
|
740
1028
|
|
|
741
|
-
|
|
742
|
-
shaderNode.subBuilds = subBuilds;
|
|
1029
|
+
}
|
|
743
1030
|
|
|
744
|
-
|
|
1031
|
+
}
|
|
745
1032
|
|
|
746
|
-
|
|
1033
|
+
export function Fn( jsFunc, layout = null ) {
|
|
747
1034
|
|
|
748
|
-
|
|
1035
|
+
const instance = new FnNode( jsFunc, layout );
|
|
749
1036
|
|
|
750
|
-
|
|
1037
|
+
return new Proxy( () => {}, {
|
|
751
1038
|
|
|
752
|
-
|
|
753
|
-
name: 'fn' + fnId ++,
|
|
754
|
-
type: nodeType,
|
|
755
|
-
inputs: []
|
|
756
|
-
};
|
|
1039
|
+
apply( target, thisArg, params ) {
|
|
757
1040
|
|
|
758
|
-
|
|
1041
|
+
return instance.call( ...params );
|
|
759
1042
|
|
|
760
|
-
|
|
1043
|
+
},
|
|
761
1044
|
|
|
762
|
-
|
|
763
|
-
name: name,
|
|
764
|
-
type: layout[ name ]
|
|
765
|
-
} );
|
|
1045
|
+
get( target, prop, receiver ) {
|
|
766
1046
|
|
|
767
|
-
|
|
1047
|
+
return Reflect.get( instance, prop, receiver );
|
|
768
1048
|
|
|
769
|
-
|
|
1049
|
+
},
|
|
770
1050
|
|
|
771
|
-
|
|
1051
|
+
set( target, prop, value, receiver ) {
|
|
772
1052
|
|
|
773
|
-
|
|
1053
|
+
return Reflect.set( instance, prop, value, receiver );
|
|
774
1054
|
|
|
775
|
-
|
|
1055
|
+
}
|
|
776
1056
|
|
|
777
|
-
|
|
1057
|
+
} );
|
|
778
1058
|
|
|
779
|
-
}
|
|
1059
|
+
}
|
|
780
1060
|
|
|
781
1061
|
//
|
|
782
1062
|
|