@plastic-software/three 0.179.0 → 0.180.1

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.
Files changed (173) hide show
  1. package/build/three.cjs +167 -107
  2. package/build/three.core.js +112 -20
  3. package/build/three.core.min.js +1 -1
  4. package/build/three.module.js +56 -90
  5. package/build/three.module.min.js +1 -1
  6. package/build/three.tsl.js +30 -5
  7. package/build/three.tsl.min.js +1 -1
  8. package/build/three.webgpu.js +2896 -1048
  9. package/build/three.webgpu.min.js +1 -1
  10. package/build/three.webgpu.nodes.js +2896 -1048
  11. package/build/three.webgpu.nodes.min.js +1 -1
  12. package/examples/jsm/Addons.js +1 -1
  13. package/examples/jsm/controls/ArcballControls.js +7 -7
  14. package/examples/jsm/controls/DragControls.js +6 -56
  15. package/examples/jsm/controls/FirstPersonControls.js +2 -2
  16. package/examples/jsm/controls/PointerLockControls.js +0 -8
  17. package/examples/jsm/exporters/GLTFExporter.js +30 -22
  18. package/examples/jsm/exporters/KTX2Exporter.js +4 -2
  19. package/examples/jsm/exporters/PLYExporter.js +1 -1
  20. package/examples/jsm/libs/ktx-parse.module.js +1 -1
  21. package/examples/jsm/lines/Line2.js +3 -3
  22. package/examples/jsm/lines/LineGeometry.js +1 -1
  23. package/examples/jsm/lines/LineSegments2.js +2 -2
  24. package/examples/jsm/lines/Wireframe.js +2 -2
  25. package/examples/jsm/lines/WireframeGeometry2.js +1 -1
  26. package/examples/jsm/lines/webgpu/LineSegments2.js +1 -1
  27. package/examples/jsm/lines/webgpu/Wireframe.js +1 -1
  28. package/examples/jsm/loaders/ColladaLoader.js +1 -1
  29. package/examples/jsm/loaders/EXRLoader.js +5 -5
  30. package/examples/jsm/loaders/GLTFLoader.js +9 -5
  31. package/examples/jsm/loaders/HDRCubeTextureLoader.js +5 -5
  32. package/examples/jsm/loaders/HDRLoader.js +486 -0
  33. package/examples/jsm/loaders/KTX2Loader.js +112 -32
  34. package/examples/jsm/loaders/RGBELoader.js +7 -473
  35. package/examples/jsm/loaders/TTFLoader.js +4 -4
  36. package/examples/jsm/loaders/UltraHDRLoader.js +1 -1
  37. package/examples/jsm/loaders/lwo/IFFParser.js +1 -1
  38. package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
  39. package/examples/jsm/math/ColorSpaces.js +19 -1
  40. package/examples/jsm/math/ConvexHull.js +2 -2
  41. package/examples/jsm/math/Lut.js +2 -2
  42. package/examples/jsm/misc/MD2CharacterComplex.js +1 -1
  43. package/examples/jsm/misc/ProgressiveLightMap.js +1 -1
  44. package/examples/jsm/misc/Volume.js +1 -1
  45. package/examples/jsm/postprocessing/OutlinePass.js +1 -1
  46. package/examples/jsm/postprocessing/SSRPass.js +37 -8
  47. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +1 -1
  48. package/examples/jsm/transpiler/GLSLDecoder.js +22 -19
  49. package/examples/jsm/transpiler/TSLEncoder.js +2 -10
  50. package/examples/jsm/transpiler/WGSLEncoder.js +24 -0
  51. package/examples/jsm/tsl/display/AnamorphicNode.js +27 -4
  52. package/examples/jsm/tsl/display/BloomNode.js +3 -3
  53. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +2 -1
  54. package/examples/jsm/tsl/display/DepthOfFieldNode.js +439 -90
  55. package/examples/jsm/tsl/display/GTAONode.js +8 -0
  56. package/examples/jsm/tsl/display/GaussianBlurNode.js +47 -35
  57. package/examples/jsm/tsl/display/OutlineNode.js +2 -2
  58. package/examples/jsm/tsl/display/SSRNode.js +180 -65
  59. package/examples/jsm/tsl/display/TRAANode.js +1 -1
  60. package/examples/jsm/tsl/display/boxBlur.js +64 -0
  61. package/examples/jsm/tsl/display/hashBlur.js +15 -18
  62. package/examples/jsm/utils/BufferGeometryUtils.js +1 -1
  63. package/examples/jsm/utils/ShadowMapViewerGPU.js +12 -5
  64. package/examples/jsm/webxr/OculusHandModel.js +1 -1
  65. package/package.json +1 -1
  66. package/src/Three.Core.js +1 -0
  67. package/src/Three.TSL.js +29 -4
  68. package/src/animation/AnimationClip.js +17 -2
  69. package/src/constants.js +11 -3
  70. package/src/core/BufferGeometry.js +2 -2
  71. package/src/extras/TextureUtils.js +2 -1
  72. package/src/extras/lib/earcut.js +1 -1
  73. package/src/lights/webgpu/ProjectorLight.js +1 -1
  74. package/src/materials/Material.js +12 -0
  75. package/src/materials/MeshDistanceMaterial.js +1 -1
  76. package/src/materials/nodes/PointsNodeMaterial.js +81 -28
  77. package/src/materials/nodes/SpriteNodeMaterial.js +3 -15
  78. package/src/materials/nodes/manager/NodeMaterialObserver.js +1 -1
  79. package/src/math/ColorManagement.js +7 -1
  80. package/src/nodes/Nodes.js +3 -0
  81. package/src/nodes/TSL.js +3 -0
  82. package/src/nodes/accessors/BufferNode.js +1 -1
  83. package/src/nodes/accessors/Camera.js +133 -7
  84. package/src/nodes/accessors/ClippingNode.js +6 -5
  85. package/src/nodes/accessors/CubeTextureNode.js +2 -2
  86. package/src/nodes/accessors/InstanceNode.js +3 -1
  87. package/src/nodes/accessors/Object3DNode.js +1 -1
  88. package/src/nodes/accessors/ReferenceBaseNode.js +1 -1
  89. package/src/nodes/accessors/ReferenceNode.js +1 -1
  90. package/src/nodes/accessors/Texture3DNode.js +13 -0
  91. package/src/nodes/accessors/TextureNode.js +71 -19
  92. package/src/nodes/code/FunctionCallNode.js +19 -0
  93. package/src/nodes/code/FunctionNode.js +23 -0
  94. package/src/nodes/core/AssignNode.js +4 -3
  95. package/src/nodes/core/ContextNode.js +24 -0
  96. package/src/nodes/core/Node.js +16 -20
  97. package/src/nodes/core/NodeBuilder.js +48 -14
  98. package/src/nodes/core/NodeFrame.js +1 -1
  99. package/src/nodes/core/NodeUniform.js +1 -1
  100. package/src/nodes/core/NodeUtils.js +1 -2
  101. package/src/nodes/core/StackNode.js +29 -4
  102. package/src/nodes/core/StructNode.js +5 -5
  103. package/src/nodes/core/StructTypeNode.js +1 -0
  104. package/src/nodes/core/SubBuildNode.js +2 -2
  105. package/src/nodes/core/UniformNode.js +16 -9
  106. package/src/nodes/core/VarNode.js +0 -21
  107. package/src/nodes/display/FrontFacingNode.js +4 -8
  108. package/src/nodes/display/PassNode.js +1 -1
  109. package/src/nodes/display/ScreenNode.js +42 -13
  110. package/src/nodes/display/ViewportDepthTextureNode.js +16 -4
  111. package/src/nodes/display/ViewportSharedTextureNode.js +12 -0
  112. package/src/nodes/display/ViewportTextureNode.js +42 -12
  113. package/src/nodes/gpgpu/SubgroupFunctionNode.js +430 -0
  114. package/src/nodes/lighting/LightsNode.js +1 -1
  115. package/src/nodes/math/BitcastNode.js +156 -0
  116. package/src/nodes/math/ConditionalNode.js +18 -2
  117. package/src/nodes/math/MathNode.js +3 -15
  118. package/src/nodes/math/OperatorNode.js +4 -3
  119. package/src/nodes/tsl/TSLCore.js +432 -152
  120. package/src/nodes/utils/JoinNode.js +3 -1
  121. package/src/nodes/utils/MemberNode.js +58 -7
  122. package/src/nodes/utils/RTTNode.js +1 -1
  123. package/src/nodes/utils/ReflectorNode.js +51 -7
  124. package/src/nodes/utils/SampleNode.js +12 -2
  125. package/src/nodes/utils/SplitNode.js +11 -0
  126. package/src/nodes/utils/Timer.js +0 -47
  127. package/src/objects/BatchedMesh.js +2 -2
  128. package/src/objects/LOD.js +1 -1
  129. package/src/objects/Sprite.js +2 -2
  130. package/src/renderers/WebGLRenderer.js +1 -10
  131. package/src/renderers/common/Attributes.js +1 -1
  132. package/src/renderers/common/Backend.js +19 -1
  133. package/src/renderers/common/Bindings.js +2 -0
  134. package/src/renderers/common/ChainMap.js +1 -1
  135. package/src/renderers/common/DataMap.js +1 -1
  136. package/src/renderers/common/Pipelines.js +1 -1
  137. package/src/renderers/common/RenderContext.js +2 -2
  138. package/src/renderers/common/RenderObject.js +14 -2
  139. package/src/renderers/common/Renderer.js +39 -19
  140. package/src/renderers/common/SampledTexture.js +1 -1
  141. package/src/renderers/common/Sampler.js +25 -13
  142. package/src/renderers/common/Textures.js +34 -12
  143. package/src/renderers/common/TimestampQueryPool.js +3 -3
  144. package/src/renderers/common/XRManager.js +35 -19
  145. package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
  146. package/src/renderers/common/nodes/NodeLibrary.js +5 -5
  147. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +1 -1
  148. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
  149. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +1 -1
  150. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +1 -1
  151. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +7 -15
  152. package/src/renderers/shaders/ShaderLib/depth.glsl.js +1 -1
  153. package/src/renderers/webgl/WebGLProgram.js +4 -4
  154. package/src/renderers/webgl/WebGLShadowMap.js +1 -1
  155. package/src/renderers/webgl/WebGLTextures.js +1 -0
  156. package/src/renderers/webgl/WebGLUtils.js +3 -2
  157. package/src/renderers/webgl-fallback/WebGLBackend.js +186 -135
  158. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +110 -17
  159. package/src/renderers/webgl-fallback/utils/WebGLState.js +1 -1
  160. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +52 -3
  161. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -10
  162. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +3 -2
  163. package/src/renderers/webgpu/WebGPUBackend.js +35 -31
  164. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +124 -34
  165. package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -2
  166. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +9 -18
  167. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +114 -25
  168. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +3 -3
  169. package/src/renderers/webxr/WebXRManager.js +39 -24
  170. package/src/textures/ExternalTexture.js +15 -4
  171. package/src/textures/Source.js +1 -1
  172. package/src/textures/VideoTexture.js +0 -3
  173. package/examples/jsm/loaders/RGBMLoader.js +0 -1148
@@ -78,6 +78,19 @@ class ContextNode extends Node {
78
78
 
79
79
  }
80
80
 
81
+ /**
82
+ * This method is overwritten to ensure it returns the member type of {@link ContextNode#node}.
83
+ *
84
+ * @param {NodeBuilder} builder - The current node builder.
85
+ * @param {string} name - The member name.
86
+ * @returns {string} The member type.
87
+ */
88
+ getMemberType( builder, name ) {
89
+
90
+ return this.node.getMemberType( builder, name );
91
+
92
+ }
93
+
81
94
  analyze( builder ) {
82
95
 
83
96
  const previousContext = builder.getContext();
@@ -131,6 +144,16 @@ export default ContextNode;
131
144
  */
132
145
  export const context = /*@__PURE__*/ nodeProxy( ContextNode ).setParameterLength( 1, 2 );
133
146
 
147
+ /**
148
+ * TSL function for defining a uniformFlow context value for a given node.
149
+ *
150
+ * @tsl
151
+ * @function
152
+ * @param {Node} node - The node whose dependencies should all execute within a uniform control-flow path.
153
+ * @returns {ContextNode}
154
+ */
155
+ export const uniformFlow = ( node ) => context( node, { uniformFlow: true } );
156
+
134
157
  /**
135
158
  * TSL function for defining a name for the context value for a given node.
136
159
  *
@@ -162,4 +185,5 @@ export function label( node, name ) {
162
185
 
163
186
  addMethodChaining( 'context', context );
164
187
  addMethodChaining( 'label', label );
188
+ addMethodChaining( 'uniformFlow', uniformFlow );
165
189
  addMethodChaining( 'setName', setName );
@@ -172,7 +172,7 @@ class Node extends EventDispatcher {
172
172
  onUpdate( callback, updateType ) {
173
173
 
174
174
  this.updateType = updateType;
175
- this.update = callback.bind( this.getSelf() );
175
+ this.update = callback.bind( this );
176
176
 
177
177
  return this;
178
178
 
@@ -225,26 +225,12 @@ class Node extends EventDispatcher {
225
225
  */
226
226
  onReference( callback ) {
227
227
 
228
- this.updateReference = callback.bind( this.getSelf() );
228
+ this.updateReference = callback.bind( this );
229
229
 
230
230
  return this;
231
231
 
232
232
  }
233
233
 
234
- /**
235
- * The `this` reference might point to a Proxy so this method can be used
236
- * to get the reference to the actual node instance.
237
- *
238
- * @return {Node} A reference to the node.
239
- */
240
- getSelf() {
241
-
242
- // Returns non-node object.
243
-
244
- return this.self || this;
245
-
246
- }
247
-
248
234
  /**
249
235
  * Nodes might refer to other objects like materials. This method allows to dynamically update the reference
250
236
  * to such objects based on a given state (e.g. the current node frame or builder).
@@ -563,7 +549,7 @@ class Node extends EventDispatcher {
563
549
  * This state builds the output node and returns the resulting shader string.
564
550
  *
565
551
  * @param {NodeBuilder} builder - The current node builder.
566
- * @param {?string} output - Can be used to define the output type.
552
+ * @param {?string} [output] - Can be used to define the output type.
567
553
  * @return {?string} The generated shader string.
568
554
  */
569
555
  generate( builder, output ) {
@@ -627,8 +613,8 @@ class Node extends EventDispatcher {
627
613
  * - **generate**: Generates the shader code for the node. Returns the generated shader string.
628
614
  *
629
615
  * @param {NodeBuilder} builder - The current node builder.
630
- * @param {string|Node|null} [output=null] - Can be used to define the output type.
631
- * @return {Node|string|null} The result of the build process, depending on the build stage.
616
+ * @param {?(string|Node)} [output=null] - Can be used to define the output type.
617
+ * @return {?(Node|string)} The result of the build process, depending on the build stage.
632
618
  */
633
619
  build( builder, output = null ) {
634
620
 
@@ -765,6 +751,16 @@ class Node extends EventDispatcher {
765
751
 
766
752
  }
767
753
 
754
+ if ( result === '' && output !== null && output !== 'void' && output !== 'OutputType' ) {
755
+
756
+ // if no snippet is generated, return a default value
757
+
758
+ console.error( `THREE.TSL: Invalid generated code, expected a "${ output }".` );
759
+
760
+ result = builder.generateConst( output );
761
+
762
+ }
763
+
768
764
  }
769
765
 
770
766
  builder.removeChain( this );
@@ -777,7 +773,7 @@ class Node extends EventDispatcher {
777
773
  /**
778
774
  * Returns the child nodes as a JSON object.
779
775
  *
780
- * @return {Array<Object>} An iterable list of serialized child objects as JSON.
776
+ * @return {Generator<Object>} An iterable list of serialized child objects as JSON.
781
777
  */
782
778
  getSerializeChildren() {
783
779
 
@@ -259,6 +259,13 @@ class NodeBuilder {
259
259
  */
260
260
  this.structs = { vertex: [], fragment: [], compute: [], index: 0 };
261
261
 
262
+ /**
263
+ * This dictionary holds the types of the builder.
264
+ *
265
+ * @type {Object}
266
+ */
267
+ this.types = { vertex: [], fragment: [], compute: [], index: 0 };
268
+
262
269
  /**
263
270
  * This dictionary holds the bindings for each shader stage.
264
271
  *
@@ -722,7 +729,7 @@ class NodeBuilder {
722
729
 
723
730
  if ( updateType !== NodeUpdateType.NONE ) {
724
731
 
725
- this.updateNodes.push( node.getSelf() );
732
+ this.updateNodes.push( node );
726
733
 
727
734
  }
728
735
 
@@ -735,13 +742,13 @@ class NodeBuilder {
735
742
 
736
743
  if ( updateBeforeType !== NodeUpdateType.NONE ) {
737
744
 
738
- this.updateBeforeNodes.push( node.getSelf() );
745
+ this.updateBeforeNodes.push( node );
739
746
 
740
747
  }
741
748
 
742
749
  if ( updateAfterType !== NodeUpdateType.NONE ) {
743
750
 
744
- this.updateAfterNodes.push( node.getSelf() );
751
+ this.updateAfterNodes.push( node );
745
752
 
746
753
  }
747
754
 
@@ -826,6 +833,22 @@ class NodeBuilder {
826
833
 
827
834
  }
828
835
 
836
+ /**
837
+ * Returns the native snippet for a ternary operation. E.g. GLSL would output
838
+ * a ternary op as `cond ? x : y` whereas WGSL would output it as `select(y, x, cond)`
839
+ *
840
+ * @abstract
841
+ * @param {string} condSnippet - The condition determining which expression gets resolved.
842
+ * @param {string} ifSnippet - The expression to resolve to if the condition is true.
843
+ * @param {string} elseSnippet - The expression to resolve to if the condition is false.
844
+ * @return {string} The resolved method name.
845
+ */
846
+ getTernary( /* condSnippet, ifSnippet, elseSnippet*/ ) {
847
+
848
+ return null;
849
+
850
+ }
851
+
829
852
  /**
830
853
  * Returns a node for the given hash, see {@link NodeBuilder#setHashNode}.
831
854
  *
@@ -1144,7 +1167,6 @@ class NodeBuilder {
1144
1167
 
1145
1168
  }
1146
1169
 
1147
-
1148
1170
  /**
1149
1171
  * Generates the shader string for the given type and value.
1150
1172
  *
@@ -1553,7 +1575,9 @@ class NodeBuilder {
1553
1575
 
1554
1576
  this.stack = stack( this.stack );
1555
1577
 
1556
- this.stacks.push( getCurrentStack() || this.stack );
1578
+ const previousStack = getCurrentStack();
1579
+
1580
+ this.stacks.push( previousStack );
1557
1581
  setCurrentStack( this.stack );
1558
1582
 
1559
1583
  return this.stack;
@@ -1665,6 +1689,20 @@ class NodeBuilder {
1665
1689
 
1666
1690
  }
1667
1691
 
1692
+ /**
1693
+ * Returns an instance of {@link StructType} for the given struct name and shader stage
1694
+ * or null if not found.
1695
+ *
1696
+ * @param {string} name - The name of the struct.
1697
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
1698
+ * @return {?StructType} The struct type or null if not found.
1699
+ */
1700
+ getStructTypeNode( name, shaderStage = this.shaderStage ) {
1701
+
1702
+ return this.types[ shaderStage ][ name ] || null;
1703
+
1704
+ }
1705
+
1668
1706
  /**
1669
1707
  * Returns an instance of {@link StructType} for the given output struct node.
1670
1708
  *
@@ -1689,6 +1727,7 @@ class NodeBuilder {
1689
1727
  structType = new StructType( name, membersLayout );
1690
1728
 
1691
1729
  this.structs[ shaderStage ].push( structType );
1730
+ this.types[ shaderStage ][ name ] = node;
1692
1731
 
1693
1732
  nodeData.structType = structType;
1694
1733
 
@@ -2221,8 +2260,8 @@ class NodeBuilder {
2221
2260
  *
2222
2261
  * @param {Node} node - The node to execute.
2223
2262
  * @param {string} buildStage - The build stage to execute the node in.
2224
- * @param {Node|string|null} output - Expected output type. For example 'vec3'.
2225
- * @return {Node|string|null} The result of the node build.
2263
+ * @param {?(Node|string)} [output=null] - Expected output type. For example 'vec3'.
2264
+ * @return {?(Node|string)} The result of the node build.
2226
2265
  */
2227
2266
  flowBuildStage( node, buildStage, output = null ) {
2228
2267
 
@@ -2348,7 +2387,7 @@ class NodeBuilder {
2348
2387
  * @param {Node} node - The node to execute.
2349
2388
  * @param {?string} output - Expected output type. For example 'vec3'.
2350
2389
  * @param {?string} propertyName - The property name to assign the result.
2351
- * @return {Object|Node|null} The code flow or node.build() result.
2390
+ * @return {?(Object|Node)} The code flow or node.build() result.
2352
2391
  */
2353
2392
  flowNodeFromShaderStage( shaderStage, node, output = null, propertyName = null ) {
2354
2393
 
@@ -2616,7 +2655,7 @@ class NodeBuilder {
2616
2655
  /**
2617
2656
  * Returns the closest sub-build layer for the given data.
2618
2657
  *
2619
- * @param {Node|Set|Array} data - The data to get the closest sub-build layer from.
2658
+ * @param {Node|Set<string>|Array<string>} data - The data to get the closest sub-build layer from.
2620
2659
  * @return {?string} The closest sub-build name or null if none found.
2621
2660
  */
2622
2661
  getClosestSubBuild( data ) {
@@ -2923,11 +2962,6 @@ class NodeBuilder {
2923
2962
 
2924
2963
  }
2925
2964
 
2926
- /**
2927
- * Prevents the node builder from being used as an iterable in TSL.Fn(), avoiding potential runtime errors.
2928
- */
2929
- *[ Symbol.iterator ]() { }
2930
-
2931
2965
  }
2932
2966
 
2933
2967
  export default NodeBuilder;
@@ -115,7 +115,7 @@ class NodeFrame {
115
115
  * @private
116
116
  * @param {WeakMap<Node, Object>} referenceMap - The reference weak map.
117
117
  * @param {Node} nodeRef - The reference to the current node.
118
- * @return {Object<string,WeakMap>} The dictionary.
118
+ * @return {Object<string,WeakMap<Object, number>>} The dictionary.
119
119
  */
120
120
  _getMaps( referenceMap, nodeRef ) {
121
121
 
@@ -43,7 +43,7 @@ class NodeUniform {
43
43
  *
44
44
  * @type {UniformNode}
45
45
  */
46
- this.node = node.getSelf();
46
+ this.node = node;
47
47
 
48
48
  }
49
49
 
@@ -88,7 +88,6 @@ export function getCacheKey( object, force = false ) {
88
88
  if ( object.isNode === true ) {
89
89
 
90
90
  values.push( object.id );
91
- object = object.getSelf();
92
91
 
93
92
  }
94
93
 
@@ -113,7 +112,7 @@ export function getCacheKey( object, force = false ) {
113
112
  */
114
113
  export function* getNodeChildren( node, toJSON = false ) {
115
114
 
116
- for ( const property in node ) {
115
+ for ( const property of Object.getOwnPropertyNames( node ) ) {
117
116
 
118
117
  // Ignore private properties.
119
118
  if ( property.startsWith( '_' ) === true ) continue;
@@ -80,13 +80,13 @@ class StackNode extends Node {
80
80
 
81
81
  getNodeType( builder ) {
82
82
 
83
- return this.outputNode ? this.outputNode.getNodeType( builder ) : 'void';
83
+ return this.hasOutput ? this.outputNode.getNodeType( builder ) : 'void';
84
84
 
85
85
  }
86
86
 
87
87
  getMemberType( builder, name ) {
88
88
 
89
- return this.outputNode ? this.outputNode.getMemberType( builder, name ) : 'void';
89
+ return this.hasOutput ? this.outputNode.getMemberType( builder, name ) : 'void';
90
90
 
91
91
  }
92
92
 
@@ -98,6 +98,13 @@ class StackNode extends Node {
98
98
  */
99
99
  add( node ) {
100
100
 
101
+ if ( node.isNode !== true ) {
102
+
103
+ console.error( 'THREE.TSL: Invalid node added to stack.' );
104
+ return this;
105
+
106
+ }
107
+
101
108
  this.nodes.push( node );
102
109
 
103
110
  return this;
@@ -191,7 +198,7 @@ class StackNode extends Node {
191
198
 
192
199
  } else {
193
200
 
194
- throw new Error( 'TSL: Invalid parameter length. Case() requires at least two parameters.' );
201
+ console.error( 'THREE.TSL: Invalid parameter length. Case() requires at least two parameters.' );
195
202
 
196
203
  }
197
204
 
@@ -275,6 +282,12 @@ class StackNode extends Node {
275
282
 
276
283
  }
277
284
 
285
+ get hasOutput() {
286
+
287
+ return this.outputNode && this.outputNode.isNode;
288
+
289
+ }
290
+
278
291
  build( builder, ...params ) {
279
292
 
280
293
  const previousBuildStack = builder.currentStack;
@@ -325,7 +338,19 @@ class StackNode extends Node {
325
338
 
326
339
  }
327
340
 
328
- const result = this.outputNode ? this.outputNode.build( builder, ...params ) : super.build( builder, ...params );
341
+ //
342
+
343
+ let result;
344
+
345
+ if ( this.hasOutput ) {
346
+
347
+ result = this.outputNode.build( builder, ...params );
348
+
349
+ } else {
350
+
351
+ result = super.build( builder, ...params );
352
+
353
+ }
329
354
 
330
355
  setCurrentStack( previousStack );
331
356
 
@@ -30,11 +30,11 @@ class StructNode extends Node {
30
30
 
31
31
  }
32
32
 
33
- constructor( structLayoutNode, values ) {
33
+ constructor( structTypeNode, values ) {
34
34
 
35
35
  super( 'vec3' );
36
36
 
37
- this.structLayoutNode = structLayoutNode;
37
+ this.structTypeNode = structTypeNode;
38
38
  this.values = values;
39
39
 
40
40
  this.isStructNode = true;
@@ -43,13 +43,13 @@ class StructNode extends Node {
43
43
 
44
44
  getNodeType( builder ) {
45
45
 
46
- return this.structLayoutNode.getNodeType( builder );
46
+ return this.structTypeNode.getNodeType( builder );
47
47
 
48
48
  }
49
49
 
50
50
  getMemberType( builder, name ) {
51
51
 
52
- return this.structLayoutNode.getMemberType( builder, name );
52
+ return this.structTypeNode.getMemberType( builder, name );
53
53
 
54
54
  }
55
55
 
@@ -59,7 +59,7 @@ class StructNode extends Node {
59
59
  const structType = nodeVar.type;
60
60
  const propertyName = builder.getPropertyName( nodeVar );
61
61
 
62
- builder.addLineFlowCode( `${ propertyName } = ${ builder.generateStruct( structType, this.structLayoutNode.membersLayout, this.values ) }`, this );
62
+ builder.addLineFlowCode( `${ propertyName } = ${ builder.generateStruct( structType, this.structTypeNode.membersLayout, this.values ) }`, this );
63
63
 
64
64
  return nodeVar.name;
65
65
 
@@ -138,6 +138,7 @@ class StructTypeNode extends Node {
138
138
 
139
139
  setup( builder ) {
140
140
 
141
+ builder.getStructTypeFromNode( this, this.membersLayout, this.name );
141
142
  builder.addInclude( this );
142
143
 
143
144
  }
@@ -7,7 +7,7 @@ import { nodeObject } from '../tsl/TSLCore.js';
7
7
  * @augments Node
8
8
  * @param {Node} node - The node to be built in the sub-build.
9
9
  * @param {string} name - The name of the sub-build.
10
- * @param {string|null} [nodeType=null] - The type of the node, if known.
10
+ * @param {?string} [nodeType=null] - The type of the node, if known.
11
11
  */
12
12
  class SubBuildNode extends Node {
13
13
 
@@ -83,7 +83,7 @@ export default SubBuildNode;
83
83
  * @function
84
84
  * @param {Node} node - The node to be built in the sub-build.
85
85
  * @param {string} name - The name of the sub-build.
86
- * @param {string|null} [type=null] - The type of the node, if known.
86
+ * @param {?string} [type=null] - The type of the node, if known.
87
87
  * @returns {Node} A node object wrapping the SubBuildNode instance.
88
88
  */
89
89
  export const subBuild = ( node, name, type = null ) => nodeObject( new SubBuildNode( nodeObject( node ), name, type ) );
@@ -1,6 +1,7 @@
1
1
  import InputNode from './InputNode.js';
2
2
  import { objectGroup } from './UniformGroupNode.js';
3
3
  import { nodeObject, getConstNodeType } from '../tsl/TSLCore.js';
4
+ import { getValueFromType } from './NodeUtils.js';
4
5
 
5
6
  /**
6
7
  * Class for representing a uniform.
@@ -122,13 +123,11 @@ class UniformNode extends InputNode {
122
123
 
123
124
  onUpdate( callback, updateType ) {
124
125
 
125
- const self = this.getSelf();
126
-
127
- callback = callback.bind( self );
126
+ callback = callback.bind( this );
128
127
 
129
128
  return super.onUpdate( ( frame ) => {
130
129
 
131
- const value = callback( frame, self );
130
+ const value = callback( frame, this );
132
131
 
133
132
  if ( value !== undefined ) {
134
133
 
@@ -219,16 +218,24 @@ export default UniformNode;
219
218
  *
220
219
  * @tsl
221
220
  * @function
222
- * @param {any} arg1 - The value of this node. Usually a JS primitive or three.js object (vector, matrix, color, texture).
223
- * @param {string} [arg2] - The node type. If no explicit type is defined, the node tries to derive the type from its value.
221
+ * @param {any|string} value - The value of this uniform or your type. Usually a JS primitive or three.js object (vector, matrix, color, texture).
222
+ * @param {string} [type] - The node type. If no explicit type is defined, the node tries to derive the type from its value.
224
223
  * @returns {UniformNode}
225
224
  */
226
- export const uniform = ( arg1, arg2 ) => {
225
+ export const uniform = ( value, type ) => {
226
+
227
+ const nodeType = getConstNodeType( type || value );
228
+
229
+ if ( nodeType === value ) {
227
230
 
228
- const nodeType = getConstNodeType( arg2 || arg1 );
231
+ // if the value is a type but no having a value
232
+
233
+ value = getValueFromType( nodeType );
234
+
235
+ }
229
236
 
230
237
  // @TODO: get ConstNode from .traverse() in the future
231
- const value = ( arg1 && arg1.isNode === true ) ? ( arg1.node && arg1.node.value ) || arg1.value : arg1;
238
+ value = ( value && value.isNode === true ) ? ( value.node && value.node.value ) || value.value : value;
232
239
 
233
240
  return nodeObject( new UniformNode( value, nodeType ) );
234
241
 
@@ -282,24 +282,3 @@ export const VarIntent = ( node ) => {
282
282
  addMethodChaining( 'toVar', Var );
283
283
  addMethodChaining( 'toConst', Const );
284
284
  addMethodChaining( 'toVarIntent', VarIntent );
285
-
286
- // Deprecated
287
-
288
- /**
289
- * @tsl
290
- * @function
291
- * @deprecated since r170. Use `Var( node )` or `node.toVar()` instead.
292
- *
293
- * @param {any} node
294
- * @returns {VarNode}
295
- */
296
- export const temp = ( node ) => { // @deprecated, r170
297
-
298
- console.warn( 'TSL: "temp( node )" is deprecated. Use "Var( node )" or "node.toVar()" instead.' );
299
-
300
- return createVar( node );
301
-
302
- };
303
-
304
- addMethodChaining( 'temp', temp );
305
-
@@ -1,7 +1,7 @@
1
1
  import Node from '../core/Node.js';
2
2
  import { nodeImmutable, float, Fn } from '../tsl/TSLBase.js';
3
3
 
4
- import { BackSide, DoubleSide, WebGLCoordinateSystem } from '../../constants.js';
4
+ import { BackSide, DoubleSide } from '../../constants.js';
5
5
 
6
6
  /**
7
7
  * This node can be used to evaluate whether a primitive is front or back facing.
@@ -40,15 +40,11 @@ class FrontFacingNode extends Node {
40
40
 
41
41
  //
42
42
 
43
- const { renderer, material } = builder;
43
+ const { material } = builder;
44
44
 
45
- if ( renderer.coordinateSystem === WebGLCoordinateSystem ) {
45
+ if ( material.side === BackSide ) {
46
46
 
47
- if ( material.side === BackSide ) {
48
-
49
- return 'false';
50
-
51
- }
47
+ return 'false';
52
48
 
53
49
  }
54
50
 
@@ -638,7 +638,7 @@ class PassNode extends TempNode {
638
638
  /**
639
639
  * Precompiles the pass.
640
640
  *
641
- * Note that this method must be called after the pass configuartion is complete.
641
+ * Note that this method must be called after the pass configuration is complete.
642
642
  * So calls like `setMRT()` and `getTextureNode()` must proceed the precompilation.
643
643
  *
644
644
  * @async