super-three 0.177.0 → 0.179.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.
Files changed (211) hide show
  1. package/README.md +1 -1
  2. package/build/three.cjs +959 -231
  3. package/build/three.core.js +751 -170
  4. package/build/three.core.min.js +1 -1
  5. package/build/three.module.js +210 -64
  6. package/build/three.module.min.js +1 -1
  7. package/build/three.tsl.js +78 -29
  8. package/build/three.tsl.min.js +1 -1
  9. package/build/three.webgpu.js +3269 -1545
  10. package/build/three.webgpu.min.js +1 -1
  11. package/build/three.webgpu.nodes.js +3093 -1545
  12. package/build/three.webgpu.nodes.min.js +1 -1
  13. package/examples/jsm/Addons.js +1 -2
  14. package/examples/jsm/capabilities/WebGL.js +0 -27
  15. package/examples/jsm/capabilities/WebGPU.js +1 -1
  16. package/examples/jsm/controls/ArcballControls.js +1 -1
  17. package/examples/jsm/controls/TransformControls.js +61 -14
  18. package/examples/jsm/csm/CSMShadowNode.js +4 -4
  19. package/examples/jsm/environments/RoomEnvironment.js +8 -3
  20. package/examples/jsm/exporters/USDZExporter.js +676 -299
  21. package/examples/jsm/geometries/RoundedBoxGeometry.js +47 -8
  22. package/examples/jsm/interactive/HTMLMesh.js +5 -3
  23. package/examples/jsm/libs/meshopt_decoder.module.js +75 -58
  24. package/examples/jsm/lights/LightProbeGenerator.js +14 -3
  25. package/examples/jsm/loaders/ColladaLoader.js +1 -1
  26. package/examples/jsm/loaders/EXRLoader.js +210 -22
  27. package/examples/jsm/loaders/FBXLoader.js +2 -2
  28. package/examples/jsm/loaders/MaterialXLoader.js +212 -30
  29. package/examples/jsm/loaders/TTFLoader.js +13 -1
  30. package/examples/jsm/loaders/USDLoader.js +219 -0
  31. package/examples/jsm/loaders/USDZLoader.js +4 -892
  32. package/examples/jsm/loaders/usd/USDAParser.js +741 -0
  33. package/examples/jsm/loaders/usd/USDCParser.js +17 -0
  34. package/examples/jsm/objects/LensflareMesh.js +3 -3
  35. package/examples/jsm/objects/SkyMesh.js +2 -2
  36. package/examples/jsm/physics/RapierPhysics.js +95 -16
  37. package/examples/jsm/postprocessing/GTAOPass.js +10 -9
  38. package/examples/jsm/postprocessing/OutlinePass.js +17 -17
  39. package/examples/jsm/postprocessing/SSAOPass.js +10 -9
  40. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +11 -2
  41. package/examples/jsm/transpiler/AST.js +381 -30
  42. package/examples/jsm/transpiler/GLSLDecoder.js +226 -86
  43. package/examples/jsm/transpiler/Linker.js +327 -0
  44. package/examples/jsm/transpiler/TSLEncoder.js +197 -92
  45. package/examples/jsm/transpiler/Transpiler.js +17 -1
  46. package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
  47. package/examples/jsm/transpiler/WGSLEncoder.js +788 -0
  48. package/examples/jsm/tsl/display/BloomNode.js +8 -7
  49. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +206 -0
  50. package/examples/jsm/tsl/display/GaussianBlurNode.js +8 -10
  51. package/examples/jsm/tsl/display/SSAAPassNode.js +2 -2
  52. package/examples/jsm/tsl/display/{TRAAPassNode.js → TRAANode.js} +181 -172
  53. package/examples/jsm/tsl/display/hashBlur.js +3 -3
  54. package/examples/jsm/tsl/lighting/TiledLightsNode.js +1 -1
  55. package/package.json +1 -1
  56. package/src/Three.Core.js +1 -0
  57. package/src/Three.TSL.js +77 -28
  58. package/src/Three.WebGPU.js +2 -0
  59. package/src/animation/KeyframeTrack.js +1 -1
  60. package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
  61. package/src/animation/tracks/StringKeyframeTrack.js +1 -1
  62. package/src/cameras/Camera.js +14 -0
  63. package/src/cameras/OrthographicCamera.js +1 -1
  64. package/src/cameras/PerspectiveCamera.js +1 -1
  65. package/src/constants.js +3 -3
  66. package/src/core/BufferAttribute.js +3 -3
  67. package/src/core/Clock.js +2 -8
  68. package/src/core/GLBufferAttribute.js +13 -1
  69. package/src/core/Object3D.js +1 -1
  70. package/{examples/jsm/misc → src/core}/Timer.js +4 -42
  71. package/src/extras/PMREMGenerator.js +11 -0
  72. package/src/extras/core/Path.js +22 -22
  73. package/src/helpers/CameraHelper.js +41 -11
  74. package/src/helpers/SkeletonHelper.js +35 -6
  75. package/src/lights/LightShadow.js +21 -8
  76. package/src/lights/PointLightShadow.js +1 -1
  77. package/src/loaders/FileLoader.js +27 -4
  78. package/src/loaders/ImageBitmapLoader.js +27 -4
  79. package/src/loaders/ImageLoader.js +55 -8
  80. package/src/loaders/Loader.js +14 -0
  81. package/src/loaders/LoadingManager.js +23 -0
  82. package/src/materials/MeshBasicMaterial.js +1 -1
  83. package/src/materials/nodes/Line2NodeMaterial.js +0 -8
  84. package/src/materials/nodes/MeshBasicNodeMaterial.js +4 -3
  85. package/src/materials/nodes/MeshMatcapNodeMaterial.js +1 -1
  86. package/src/materials/nodes/MeshNormalNodeMaterial.js +2 -2
  87. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +2 -1
  88. package/src/materials/nodes/MeshSSSNodeMaterial.js +2 -2
  89. package/src/materials/nodes/NodeMaterial.js +28 -5
  90. package/src/materials/nodes/PointsNodeMaterial.js +5 -0
  91. package/src/materials/nodes/manager/NodeMaterialObserver.js +87 -2
  92. package/src/math/Frustum.js +25 -9
  93. package/src/math/FrustumArray.js +10 -5
  94. package/src/math/Line3.js +129 -2
  95. package/src/math/Matrix4.js +48 -27
  96. package/src/math/Quaternion.js +1 -1
  97. package/src/math/Spherical.js +2 -2
  98. package/src/nodes/Nodes.js +2 -3
  99. package/src/nodes/TSL.js +5 -3
  100. package/src/nodes/accessors/AccessorsUtils.js +7 -8
  101. package/src/nodes/accessors/Bitangent.js +31 -25
  102. package/src/nodes/accessors/Camera.js +12 -12
  103. package/src/nodes/accessors/Normal.js +95 -29
  104. package/src/nodes/accessors/Object3DNode.js +1 -1
  105. package/src/nodes/accessors/Position.js +7 -7
  106. package/src/nodes/accessors/ReferenceNode.js +18 -3
  107. package/src/nodes/accessors/ReflectVector.js +3 -3
  108. package/src/nodes/accessors/SceneNode.js +1 -1
  109. package/src/nodes/accessors/StorageTextureNode.js +1 -1
  110. package/src/nodes/accessors/Tangent.js +25 -17
  111. package/src/nodes/accessors/TangentUtils.js +46 -0
  112. package/src/nodes/accessors/TextureBicubic.js +21 -3
  113. package/src/nodes/accessors/TextureNode.js +12 -0
  114. package/src/nodes/accessors/UniformArrayNode.js +0 -16
  115. package/src/nodes/core/ArrayNode.js +12 -0
  116. package/src/nodes/core/AssignNode.js +3 -0
  117. package/src/nodes/core/CacheNode.js +0 -14
  118. package/src/nodes/core/ContextNode.js +20 -1
  119. package/src/nodes/core/Node.js +15 -3
  120. package/src/nodes/core/NodeBuilder.js +228 -92
  121. package/src/nodes/core/NodeUtils.js +4 -1
  122. package/src/nodes/core/StackNode.js +49 -29
  123. package/src/nodes/core/SubBuildNode.js +89 -0
  124. package/src/nodes/core/UniformNode.js +63 -5
  125. package/src/nodes/core/VarNode.js +91 -2
  126. package/src/nodes/core/VaryingNode.js +6 -4
  127. package/src/nodes/display/BlendModes.js +2 -2
  128. package/src/nodes/display/FrontFacingNode.js +34 -2
  129. package/src/nodes/display/NormalMapNode.js +19 -50
  130. package/src/nodes/display/PassNode.js +157 -9
  131. package/src/nodes/display/ScreenNode.js +0 -26
  132. package/src/nodes/display/ViewportTextureNode.js +67 -7
  133. package/src/nodes/functions/BSDF/BRDF_GGX.js +2 -6
  134. package/src/nodes/functions/BSDF/BRDF_Sheen.js +4 -4
  135. package/src/nodes/functions/PhongLightingModel.js +3 -3
  136. package/src/nodes/functions/PhysicalLightingModel.js +16 -16
  137. package/src/nodes/functions/material/getGeometryRoughness.js +2 -2
  138. package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
  139. package/src/nodes/gpgpu/ComputeNode.js +67 -23
  140. package/src/nodes/gpgpu/WorkgroupInfoNode.js +28 -3
  141. package/src/nodes/lighting/EnvironmentNode.js +5 -5
  142. package/src/nodes/lighting/LightsNode.js +4 -4
  143. package/src/nodes/lighting/ProjectorLightNode.js +19 -6
  144. package/src/nodes/lighting/ShadowFilterNode.js +1 -1
  145. package/src/nodes/lighting/ShadowNode.js +2 -2
  146. package/src/nodes/materialx/MaterialXNodes.js +131 -2
  147. package/src/nodes/materialx/lib/mx_noise.js +165 -1
  148. package/src/nodes/math/ConditionalNode.js +1 -20
  149. package/src/nodes/math/MathNode.js +90 -55
  150. package/src/nodes/math/OperatorNode.js +22 -39
  151. package/src/nodes/tsl/TSLBase.js +1 -0
  152. package/src/nodes/tsl/TSLCore.js +114 -55
  153. package/src/nodes/utils/DebugNode.js +1 -1
  154. package/src/nodes/utils/EquirectUV.js +27 -0
  155. package/src/nodes/utils/EventNode.js +83 -0
  156. package/src/nodes/utils/LoopNode.js +0 -17
  157. package/src/nodes/utils/MatcapUV.js +22 -0
  158. package/src/nodes/utils/RTTNode.js +22 -5
  159. package/src/nodes/utils/ReflectorNode.js +11 -4
  160. package/src/nodes/utils/SampleNode.js +81 -0
  161. package/src/nodes/utils/TriplanarTextures.js +65 -0
  162. package/src/objects/BatchedMesh.js +4 -2
  163. package/src/renderers/WebGLRenderer.js +26 -24
  164. package/src/renderers/common/Background.js +2 -2
  165. package/src/renderers/common/Bindings.js +19 -18
  166. package/src/renderers/common/Color4.js +2 -2
  167. package/src/renderers/common/CubeRenderTarget.js +1 -1
  168. package/src/renderers/common/PostProcessing.js +60 -5
  169. package/src/renderers/common/RenderObject.js +68 -3
  170. package/src/renderers/common/Renderer.js +19 -16
  171. package/src/renderers/common/SampledTexture.js +3 -71
  172. package/src/renderers/common/Sampler.js +79 -0
  173. package/src/renderers/common/Storage3DTexture.js +100 -0
  174. package/src/renderers/common/StorageArrayTexture.js +84 -0
  175. package/src/renderers/common/StorageTexture.js +19 -0
  176. package/src/renderers/common/Textures.js +19 -3
  177. package/src/renderers/common/XRManager.js +31 -12
  178. package/src/renderers/common/XRRenderTarget.js +21 -4
  179. package/src/renderers/common/extras/PMREMGenerator.js +1 -1
  180. package/src/renderers/common/nodes/NodeSampledTexture.js +0 -12
  181. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +20 -2
  182. package/src/renderers/shaders/ShaderLib/depth.glsl.js +11 -2
  183. package/src/renderers/webgl/WebGLAttributes.js +4 -0
  184. package/src/renderers/webgl/WebGLCapabilities.js +2 -2
  185. package/src/renderers/webgl/WebGLProgram.js +12 -6
  186. package/src/renderers/webgl/WebGLPrograms.js +6 -4
  187. package/src/renderers/webgl/WebGLShadowMap.js +11 -1
  188. package/src/renderers/webgl/WebGLState.js +4 -4
  189. package/src/renderers/webgl/WebGLTextures.js +19 -7
  190. package/src/renderers/webgl-fallback/WebGLBackend.js +103 -72
  191. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +3 -5
  192. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +4 -0
  193. package/src/renderers/webgl-fallback/utils/WebGLState.js +4 -4
  194. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +2 -0
  195. package/src/renderers/webgpu/WebGPUBackend.js +63 -16
  196. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +64 -79
  197. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +6 -0
  198. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +45 -31
  199. package/src/renderers/webgpu/utils/WebGPUConstants.js +7 -1
  200. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +5 -5
  201. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +12 -65
  202. package/src/renderers/webgpu/utils/WebGPUUtils.js +2 -17
  203. package/src/renderers/webxr/WebXRDepthSensing.js +6 -10
  204. package/src/renderers/webxr/WebXRManager.js +68 -6
  205. package/src/textures/ExternalTexture.js +45 -0
  206. package/src/textures/FramebufferTexture.js +2 -2
  207. package/src/textures/Source.js +11 -1
  208. package/src/textures/VideoTexture.js +30 -2
  209. package/src/nodes/utils/EquirectUVNode.js +0 -65
  210. package/src/nodes/utils/MatcapUVNode.js +0 -49
  211. package/src/nodes/utils/TriplanarTexturesNode.js +0 -148
@@ -196,7 +196,7 @@ class NodeBuilder {
196
196
  /**
197
197
  * A reference to the current fog node.
198
198
  *
199
- * @type {?FogNode}
199
+ * @type {?Node}
200
200
  * @default null
201
201
  */
202
202
  this.fogNode = null;
@@ -419,6 +419,30 @@ class NodeBuilder {
419
419
  */
420
420
  this.buildStage = null;
421
421
 
422
+ /**
423
+ * The sub-build layers.
424
+ *
425
+ * @type {Array<SubBuildNode>}
426
+ * @default []
427
+ */
428
+ this.subBuildLayers = [];
429
+
430
+ /**
431
+ * The current stack of nodes.
432
+ *
433
+ * @type {?StackNode}
434
+ * @default null
435
+ */
436
+ this.currentStack = null;
437
+
438
+ /**
439
+ * The current sub-build TSL function(Fn).
440
+ *
441
+ * @type {?string}
442
+ * @default null
443
+ */
444
+ this.subBuildFn = null;
445
+
422
446
  }
423
447
 
424
448
  /**
@@ -1577,7 +1601,23 @@ class NodeBuilder {
1577
1601
 
1578
1602
  if ( nodeData[ shaderStage ] === undefined ) nodeData[ shaderStage ] = {};
1579
1603
 
1580
- return nodeData[ shaderStage ];
1604
+ //
1605
+
1606
+ let data = nodeData[ shaderStage ];
1607
+
1608
+ const subBuilds = nodeData.any ? nodeData.any.subBuilds : null;
1609
+ const subBuild = this.getClosestSubBuild( subBuilds );
1610
+
1611
+ if ( subBuild ) {
1612
+
1613
+ if ( data.subBuildsCache === undefined ) data.subBuildsCache = {};
1614
+
1615
+ data = data.subBuildsCache[ subBuild ] || ( data.subBuildsCache[ subBuild ] = {} );
1616
+ data.subBuilds = subBuilds;
1617
+
1618
+ }
1619
+
1620
+ return data;
1581
1621
 
1582
1622
  }
1583
1623
 
@@ -1707,23 +1747,6 @@ class NodeBuilder {
1707
1747
 
1708
1748
  }
1709
1749
 
1710
- /**
1711
- * Returns the array length.
1712
- *
1713
- * @param {Node} node - The node.
1714
- * @return {?number} The array length.
1715
- */
1716
- getArrayCount( node ) {
1717
-
1718
- let count = null;
1719
-
1720
- if ( node.isArrayNode ) count = node.count;
1721
- else if ( node.isVarNode && node.node.isArrayNode ) count = node.node.count;
1722
-
1723
- return count;
1724
-
1725
- }
1726
-
1727
1750
  /**
1728
1751
  * Returns an instance of {@link NodeVar} for the given variable node.
1729
1752
  *
@@ -1738,8 +1761,9 @@ class NodeBuilder {
1738
1761
  getVarFromNode( node, name = null, type = node.getNodeType( this ), shaderStage = this.shaderStage, readOnly = false ) {
1739
1762
 
1740
1763
  const nodeData = this.getDataFromNode( node, shaderStage );
1764
+ const subBuildVariable = this.getSubBuildProperty( 'variable', nodeData.subBuilds );
1741
1765
 
1742
- let nodeVar = nodeData.variable;
1766
+ let nodeVar = nodeData[ subBuildVariable ];
1743
1767
 
1744
1768
  if ( nodeVar === undefined ) {
1745
1769
 
@@ -1758,7 +1782,15 @@ class NodeBuilder {
1758
1782
 
1759
1783
  //
1760
1784
 
1761
- const count = this.getArrayCount( node );
1785
+ if ( subBuildVariable !== 'variable' ) {
1786
+
1787
+ name = this.getSubBuildProperty( name, nodeData.subBuilds );
1788
+
1789
+ }
1790
+
1791
+ //
1792
+
1793
+ const count = node.getArrayCount( this );
1762
1794
 
1763
1795
  nodeVar = new NodeVar( name, type, readOnly, count );
1764
1796
 
@@ -1770,7 +1802,7 @@ class NodeBuilder {
1770
1802
 
1771
1803
  this.registerDeclaration( nodeVar );
1772
1804
 
1773
- nodeData.variable = nodeVar;
1805
+ nodeData[ subBuildVariable ] = nodeVar;
1774
1806
 
1775
1807
  }
1776
1808
 
@@ -1838,8 +1870,9 @@ class NodeBuilder {
1838
1870
  getVaryingFromNode( node, name = null, type = node.getNodeType( this ), interpolationType = null, interpolationSampling = null ) {
1839
1871
 
1840
1872
  const nodeData = this.getDataFromNode( node, 'any' );
1873
+ const subBuildVarying = this.getSubBuildProperty( 'varying', nodeData.subBuilds );
1841
1874
 
1842
- let nodeVarying = nodeData.varying;
1875
+ let nodeVarying = nodeData[ subBuildVarying ];
1843
1876
 
1844
1877
  if ( nodeVarying === undefined ) {
1845
1878
 
@@ -1848,69 +1881,27 @@ class NodeBuilder {
1848
1881
 
1849
1882
  if ( name === null ) name = 'nodeVarying' + index;
1850
1883
 
1851
- nodeVarying = new NodeVarying( name, type, interpolationType, interpolationSampling );
1852
-
1853
- varyings.push( nodeVarying );
1854
-
1855
- this.registerDeclaration( nodeVarying );
1856
-
1857
- nodeData.varying = nodeVarying;
1858
-
1859
- }
1860
-
1861
- return nodeVarying;
1862
-
1863
- }
1864
-
1865
- /**
1866
- * Returns the current namespace for the node builder.
1867
- *
1868
- * @return {string} The current namespace.
1869
- */
1870
- get namespace() {
1871
-
1872
- return this.context.namespace;
1873
-
1874
- }
1875
-
1876
- /**
1877
- * Returns the output namespace for the node builder, which is used for the current output node.
1878
- *
1879
- * @return {string} The output namespace.
1880
- */
1881
- getOutputNamespace() {
1882
-
1883
- return this.getNamespace( 'outputNode' );
1884
+ //
1884
1885
 
1885
- }
1886
+ if ( subBuildVarying !== 'varying' ) {
1886
1887
 
1887
- /**
1888
- * Returns the namespace for the given property.
1889
- *
1890
- * If the property name is not set, it returns the namespace only.
1891
- * If the namespace is not set, it returns the property name.
1892
- * If the namespace is set, it returns the namespace concatenated with the property name.
1893
- *
1894
- * @param {string} [property=''] - The property name.
1895
- * @return {string} The namespace for the property.
1896
- */
1897
- getNamespace( property = '' ) {
1888
+ name = this.getSubBuildProperty( name, nodeData.subBuilds );
1898
1889
 
1899
- const ns = this.namespace;
1890
+ }
1900
1891
 
1901
- let nsName;
1892
+ //
1902
1893
 
1903
- if ( ns ) {
1894
+ nodeVarying = new NodeVarying( name, type, interpolationType, interpolationSampling );
1904
1895
 
1905
- nsName = property ? ( ns + '_' + property ) : ns;
1896
+ varyings.push( nodeVarying );
1906
1897
 
1907
- } else {
1898
+ this.registerDeclaration( nodeVarying );
1908
1899
 
1909
- nsName = property;
1900
+ nodeData[ subBuildVarying ] = nodeVarying;
1910
1901
 
1911
1902
  }
1912
1903
 
1913
- return nsName;
1904
+ return nodeVarying;
1914
1905
 
1915
1906
  }
1916
1907
 
@@ -2225,6 +2216,28 @@ class NodeBuilder {
2225
2216
 
2226
2217
  }
2227
2218
 
2219
+ /**
2220
+ * Executes the node in a specific build stage.
2221
+ *
2222
+ * @param {Node} node - The node to execute.
2223
+ * @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.
2226
+ */
2227
+ flowBuildStage( node, buildStage, output = null ) {
2228
+
2229
+ const previousBuildStage = this.getBuildStage();
2230
+
2231
+ this.setBuildStage( buildStage );
2232
+
2233
+ const result = node.build( this, output );
2234
+
2235
+ this.setBuildStage( previousBuildStage );
2236
+
2237
+ return result;
2238
+
2239
+ }
2240
+
2228
2241
  /**
2229
2242
  * Runs the node flow through all the steps of creation, 'setup', 'analyze', 'generate'.
2230
2243
  *
@@ -2567,6 +2580,145 @@ class NodeBuilder {
2567
2580
 
2568
2581
  }
2569
2582
 
2583
+ /**
2584
+ * Returns the current sub-build layer.
2585
+ *
2586
+ * @return {SubBuildNode} The current sub-build layers.
2587
+ */
2588
+ get subBuild() {
2589
+
2590
+ return this.subBuildLayers[ this.subBuildLayers.length - 1 ] || null;
2591
+
2592
+ }
2593
+
2594
+ /**
2595
+ * Adds a sub-build layer to the node builder.
2596
+ *
2597
+ * @param {SubBuildNode} subBuild - The sub-build layer to add.
2598
+ */
2599
+ addSubBuild( subBuild ) {
2600
+
2601
+ this.subBuildLayers.push( subBuild );
2602
+
2603
+ }
2604
+
2605
+ /**
2606
+ * Removes the last sub-build layer from the node builder.
2607
+ *
2608
+ * @return {SubBuildNode} The removed sub-build layer.
2609
+ */
2610
+ removeSubBuild() {
2611
+
2612
+ return this.subBuildLayers.pop();
2613
+
2614
+ }
2615
+
2616
+ /**
2617
+ * Returns the closest sub-build layer for the given data.
2618
+ *
2619
+ * @param {Node|Set|Array} data - The data to get the closest sub-build layer from.
2620
+ * @return {?string} The closest sub-build name or null if none found.
2621
+ */
2622
+ getClosestSubBuild( data ) {
2623
+
2624
+ let subBuilds;
2625
+
2626
+ if ( data && data.isNode ) {
2627
+
2628
+ if ( data.isShaderCallNodeInternal ) {
2629
+
2630
+ subBuilds = data.shaderNode.subBuilds;
2631
+
2632
+ } else if ( data.isStackNode ) {
2633
+
2634
+ subBuilds = [ data.subBuild ];
2635
+
2636
+ } else {
2637
+
2638
+ subBuilds = this.getDataFromNode( data, 'any' ).subBuilds;
2639
+
2640
+ }
2641
+
2642
+ } else if ( data instanceof Set ) {
2643
+
2644
+ subBuilds = [ ...data ];
2645
+
2646
+ } else {
2647
+
2648
+ subBuilds = data;
2649
+
2650
+ }
2651
+
2652
+ if ( ! subBuilds ) return null;
2653
+
2654
+ const subBuildLayers = this.subBuildLayers;
2655
+
2656
+ for ( let i = subBuilds.length - 1; i >= 0; i -- ) {
2657
+
2658
+ const subBuild = subBuilds[ i ];
2659
+
2660
+ if ( subBuildLayers.includes( subBuild ) ) {
2661
+
2662
+ return subBuild;
2663
+
2664
+ }
2665
+
2666
+ }
2667
+
2668
+ return null;
2669
+
2670
+ }
2671
+
2672
+
2673
+ /**
2674
+ * Returns the output node of a sub-build layer.
2675
+ *
2676
+ * @param {Node} node - The node to get the output from.
2677
+ * @return {string} The output node name.
2678
+ */
2679
+ getSubBuildOutput( node ) {
2680
+
2681
+ return this.getSubBuildProperty( 'outputNode', node );
2682
+
2683
+ }
2684
+
2685
+ /**
2686
+ * Returns the sub-build property name for the given property and node.
2687
+ *
2688
+ * @param {string} [property=''] - The property name.
2689
+ * @param {?Node} [node=null] - The node to get the sub-build from.
2690
+ * @return {string} The sub-build property name.
2691
+ */
2692
+ getSubBuildProperty( property = '', node = null ) {
2693
+
2694
+ let subBuild;
2695
+
2696
+ if ( node !== null ) {
2697
+
2698
+ subBuild = this.getClosestSubBuild( node );
2699
+
2700
+ } else {
2701
+
2702
+ subBuild = this.subBuildFn;
2703
+
2704
+ }
2705
+
2706
+ let result;
2707
+
2708
+ if ( subBuild ) {
2709
+
2710
+ result = property ? ( subBuild + '_' + property ) : subBuild;
2711
+
2712
+ } else {
2713
+
2714
+ result = property;
2715
+
2716
+ }
2717
+
2718
+ return result;
2719
+
2720
+ }
2721
+
2570
2722
  /**
2571
2723
  * Central build method which controls the build for the given object.
2572
2724
  *
@@ -2596,7 +2748,7 @@ class NodeBuilder {
2596
2748
 
2597
2749
  }
2598
2750
 
2599
- // setup() -> stage 1: create possible new nodes and returns an output reference node
2751
+ // setup() -> stage 1: create possible new nodes and/or return an output reference node
2600
2752
  // analyze() -> stage 2: analyze nodes to possible optimization and validation
2601
2753
  // generate() -> stage 3: generate shader
2602
2754
 
@@ -2776,22 +2928,6 @@ class NodeBuilder {
2776
2928
  */
2777
2929
  *[ Symbol.iterator ]() { }
2778
2930
 
2779
- // Deprecated
2780
-
2781
- /**
2782
- * @function
2783
- * @deprecated since r168. Use `new NodeMaterial()` instead, with targeted node material name.
2784
- *
2785
- * @param {string} [type='NodeMaterial'] - The node material type.
2786
- * @throws {Error}
2787
- */
2788
- createNodeMaterial( type = 'NodeMaterial' ) { // @deprecated, r168
2789
-
2790
- throw new Error( `THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${ type }() instead.` );
2791
-
2792
- }
2793
-
2794
-
2795
2931
  }
2796
2932
 
2797
2933
  export default NodeBuilder;
@@ -138,10 +138,13 @@ export function* getNodeChildren( node, toJSON = false ) {
138
138
 
139
139
  yield { property, childNode: object };
140
140
 
141
- } else if ( typeof object === 'object' ) {
141
+ } else if ( object && Object.getPrototypeOf( object ) === Object.prototype ) {
142
142
 
143
143
  for ( const subProperty in object ) {
144
144
 
145
+ // Ignore private properties.
146
+ if ( subProperty.startsWith( '_' ) === true ) continue;
147
+
145
148
  const child = object[ subProperty ];
146
149
 
147
150
  if ( child && ( child.isNode === true || toJSON && typeof child.toJSON === 'function' ) ) {
@@ -245,16 +245,61 @@ class StackNode extends Node {
245
245
 
246
246
  }
247
247
 
248
+ setup( builder ) {
249
+
250
+ const nodeProperties = builder.getNodeProperties( this );
251
+
252
+ let index = 0;
253
+
254
+ for ( const childNode of this.getChildren() ) {
255
+
256
+ if ( childNode.isVarNode && childNode.intent === true ) {
257
+
258
+ const properties = builder.getNodeProperties( childNode );
259
+
260
+ if ( properties.assign !== true ) {
261
+
262
+ continue;
263
+
264
+ }
265
+
266
+ }
267
+
268
+ nodeProperties[ 'node' + index ++ ] = childNode;
269
+
270
+ }
271
+
272
+ // return a outputNode if exists or null
273
+
274
+ return nodeProperties.outputNode || null;
275
+
276
+ }
277
+
248
278
  build( builder, ...params ) {
249
279
 
280
+ const previousBuildStack = builder.currentStack;
250
281
  const previousStack = getCurrentStack();
251
282
 
252
283
  setCurrentStack( this );
253
284
 
285
+ builder.currentStack = this;
286
+
254
287
  const buildStage = builder.buildStage;
255
288
 
256
289
  for ( const node of this.nodes ) {
257
290
 
291
+ if ( node.isVarNode && node.intent === true ) {
292
+
293
+ const properties = builder.getNodeProperties( node );
294
+
295
+ if ( properties.assign !== true ) {
296
+
297
+ continue;
298
+
299
+ }
300
+
301
+ }
302
+
258
303
  if ( buildStage === 'setup' ) {
259
304
 
260
305
  node.build( builder );
@@ -280,38 +325,13 @@ class StackNode extends Node {
280
325
 
281
326
  }
282
327
 
283
- setCurrentStack( previousStack );
284
-
285
- return this.outputNode ? this.outputNode.build( builder, ...params ) : super.build( builder, ...params );
286
-
287
- }
288
-
289
- // Deprecated
328
+ const result = this.outputNode ? this.outputNode.build( builder, ...params ) : super.build( builder, ...params );
290
329
 
291
- /**
292
- * @function
293
- * @deprecated since r168. Use {@link StackNode#Else} instead.
294
- *
295
- * @param {...any} params
296
- * @returns {StackNode}
297
- */
298
- else( ...params ) { // @deprecated, r168
299
-
300
- console.warn( 'THREE.TSL: .else() has been renamed to .Else().' );
301
- return this.Else( ...params );
302
-
303
- }
330
+ setCurrentStack( previousStack );
304
331
 
305
- /**
306
- * @deprecated since r168. Use {@link StackNode#ElseIf} instead.
307
- *
308
- * @param {...any} params
309
- * @returns {StackNode}
310
- */
311
- elseif( ...params ) { // @deprecated, r168
332
+ builder.currentStack = previousBuildStack;
312
333
 
313
- console.warn( 'THREE.TSL: .elseif() has been renamed to .ElseIf().' );
314
- return this.ElseIf( ...params );
334
+ return result;
315
335
 
316
336
  }
317
337
 
@@ -0,0 +1,89 @@
1
+ import Node from './Node.js';
2
+ import { nodeObject } from '../tsl/TSLCore.js';
3
+
4
+ /**
5
+ * This node is used to build a sub-build in the node system.
6
+ *
7
+ * @augments Node
8
+ * @param {Node} node - The node to be built in the sub-build.
9
+ * @param {string} name - The name of the sub-build.
10
+ * @param {string|null} [nodeType=null] - The type of the node, if known.
11
+ */
12
+ class SubBuildNode extends Node {
13
+
14
+ static get type() {
15
+
16
+ return 'SubBuild';
17
+
18
+ }
19
+
20
+ constructor( node, name, nodeType = null ) {
21
+
22
+ super( nodeType );
23
+
24
+ /**
25
+ * The node to be built in the sub-build.
26
+ *
27
+ * @type {Node}
28
+ */
29
+ this.node = node;
30
+
31
+ /**
32
+ * The name of the sub-build.
33
+ *
34
+ * @type {string}
35
+ */
36
+ this.name = name;
37
+
38
+ /**
39
+ * This flag can be used for type testing.
40
+ *
41
+ * @type {boolean}
42
+ * @readonly
43
+ * @default true
44
+ */
45
+ this.isSubBuildNode = true;
46
+
47
+ }
48
+
49
+ getNodeType( builder ) {
50
+
51
+ if ( this.nodeType !== null ) return this.nodeType;
52
+
53
+ builder.addSubBuild( this.name );
54
+
55
+ const nodeType = this.node.getNodeType( builder );
56
+
57
+ builder.removeSubBuild();
58
+
59
+ return nodeType;
60
+
61
+ }
62
+
63
+ build( builder, ...params ) {
64
+
65
+ builder.addSubBuild( this.name );
66
+
67
+ const data = this.node.build( builder, ...params );
68
+
69
+ builder.removeSubBuild();
70
+
71
+ return data;
72
+
73
+ }
74
+
75
+ }
76
+
77
+ export default SubBuildNode;
78
+
79
+ /**
80
+ * Creates a new sub-build node.
81
+ *
82
+ * @tsl
83
+ * @function
84
+ * @param {Node} node - The node to be built in the sub-build.
85
+ * @param {string} name - The name of the sub-build.
86
+ * @param {string|null} [type=null] - The type of the node, if known.
87
+ * @returns {Node} A node object wrapping the SubBuildNode instance.
88
+ */
89
+ export const subBuild = ( node, name, type = null ) => nodeObject( new SubBuildNode( nodeObject( node ), name, type ) );
@@ -59,7 +59,7 @@ class UniformNode extends InputNode {
59
59
  * @param {string} name - The name of the uniform.
60
60
  * @return {UniformNode} A reference to this node.
61
61
  */
62
- label( name ) {
62
+ setName( name ) {
63
63
 
64
64
  this.name = name;
65
65
 
@@ -67,6 +67,21 @@ class UniformNode extends InputNode {
67
67
 
68
68
  }
69
69
 
70
+ /**
71
+ * Sets the {@link UniformNode#name} property.
72
+ *
73
+ * @deprecated
74
+ * @param {string} name - The name of the uniform.
75
+ * @return {UniformNode} A reference to this node.
76
+ */
77
+ label( name ) {
78
+
79
+ console.warn( 'THREE.TSL: "label()" has been deprecated. Use "setName()" instead.' ); // @deprecated r179
80
+
81
+ return this.setName( name );
82
+
83
+ }
84
+
70
85
  /**
71
86
  * Sets the {@link UniformNode#groupNode} property.
72
87
  *
@@ -125,6 +140,20 @@ class UniformNode extends InputNode {
125
140
 
126
141
  }
127
142
 
143
+ getInputType( builder ) {
144
+
145
+ let type = super.getInputType( builder );
146
+
147
+ if ( type === 'bool' ) {
148
+
149
+ type = 'uint';
150
+
151
+ }
152
+
153
+ return type;
154
+
155
+ }
156
+
128
157
  generate( builder, output ) {
129
158
 
130
159
  const type = this.getNodeType( builder );
@@ -143,12 +172,41 @@ class UniformNode extends InputNode {
143
172
 
144
173
  const sharedNodeType = sharedNode.getInputType( builder );
145
174
 
146
- const nodeUniform = builder.getUniformFromNode( sharedNode, sharedNodeType, builder.shaderStage, this.name || builder.context.label );
147
- const propertyName = builder.getPropertyName( nodeUniform );
175
+ const nodeUniform = builder.getUniformFromNode( sharedNode, sharedNodeType, builder.shaderStage, this.name || builder.context.nodeName );
176
+ const uniformName = builder.getPropertyName( nodeUniform );
177
+
178
+ if ( builder.context.nodeName !== undefined ) delete builder.context.nodeName;
179
+
180
+ //
181
+
182
+ let snippet = uniformName;
183
+
184
+ if ( type === 'bool' ) {
185
+
186
+ // cache to variable
187
+
188
+ const nodeData = builder.getDataFromNode( this );
189
+
190
+ let propertyName = nodeData.propertyName;
148
191
 
149
- if ( builder.context.label !== undefined ) delete builder.context.label;
192
+ if ( propertyName === undefined ) {
193
+
194
+ const nodeVar = builder.getVarFromNode( this, null, 'bool' );
195
+ propertyName = builder.getPropertyName( nodeVar );
196
+
197
+ nodeData.propertyName = propertyName;
198
+
199
+ snippet = builder.format( uniformName, sharedNodeType, type );
200
+
201
+ builder.addLineFlowCode( `${ propertyName } = ${ snippet }`, this );
202
+
203
+ }
204
+
205
+ snippet = propertyName;
206
+
207
+ }
150
208
 
151
- return builder.format( propertyName, type, output );
209
+ return builder.format( snippet, type, output );
152
210
 
153
211
  }
154
212