super-three 0.171.0 → 0.173.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 (455) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/build/three.cjs +594 -427
  4. package/build/three.core.js +515 -81
  5. package/build/three.core.min.js +2 -2
  6. package/build/three.module.js +79 -350
  7. package/build/three.module.min.js +2 -2
  8. package/build/three.tsl.js +20 -7
  9. package/build/three.tsl.min.js +2 -2
  10. package/build/three.webgpu.js +29362 -3427
  11. package/build/three.webgpu.min.js +2 -2
  12. package/build/three.webgpu.nodes.js +29361 -3427
  13. package/build/three.webgpu.nodes.min.js +2 -2
  14. package/examples/jsm/Addons.js +0 -5
  15. package/examples/jsm/animation/CCDIKSolver.js +9 -7
  16. package/examples/jsm/capabilities/WebGPU.js +1 -1
  17. package/examples/jsm/controls/ArcballControls.js +48 -37
  18. package/examples/jsm/controls/OrbitControls.js +5 -4
  19. package/examples/jsm/csm/CSMShadowNode.js +16 -11
  20. package/examples/jsm/curves/NURBSCurve.js +1 -1
  21. package/examples/jsm/curves/NURBSUtils.js +3 -0
  22. package/examples/jsm/effects/OutlineEffect.js +1 -1
  23. package/examples/jsm/exporters/GLTFExporter.js +34 -29
  24. package/examples/jsm/exporters/KTX2Exporter.js +1 -1
  25. package/examples/jsm/exporters/PLYExporter.js +2 -2
  26. package/examples/jsm/geometries/TextGeometry.js +1 -12
  27. package/examples/jsm/helpers/TextureHelperGPU.js +15 -5
  28. package/examples/jsm/helpers/VertexNormalsHelper.js +2 -0
  29. package/examples/jsm/interactive/InteractiveGroup.js +108 -51
  30. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  31. package/examples/jsm/lights/LightProbeGenerator.js +3 -3
  32. package/examples/jsm/lines/webgpu/LineSegments2.js +15 -6
  33. package/examples/jsm/loaders/3MFLoader.js +6 -3
  34. package/examples/jsm/loaders/BVHLoader.js +1 -1
  35. package/examples/jsm/loaders/ColladaLoader.js +5 -5
  36. package/examples/jsm/loaders/DDSLoader.js +42 -0
  37. package/examples/jsm/loaders/GCodeLoader.js +4 -2
  38. package/examples/jsm/loaders/GLTFLoader.js +22 -4
  39. package/examples/jsm/loaders/KTX2Loader.js +6 -1
  40. package/examples/jsm/loaders/KTXLoader.js +4 -4
  41. package/examples/jsm/loaders/LDrawLoader.js +1 -1
  42. package/examples/jsm/loaders/LottieLoader.js +1 -1
  43. package/examples/jsm/loaders/MTLLoader.js +1 -0
  44. package/examples/jsm/loaders/NRRDLoader.js +1 -1
  45. package/examples/jsm/loaders/PLYLoader.js +7 -7
  46. package/examples/jsm/loaders/PVRLoader.js +1 -1
  47. package/examples/jsm/loaders/SVGLoader.js +2 -2
  48. package/examples/jsm/loaders/TDSLoader.js +1 -2
  49. package/examples/jsm/loaders/VRMLLoader.js +7 -7
  50. package/examples/jsm/loaders/lwo/IFFParser.js +4 -4
  51. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +1 -1
  52. package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
  53. package/examples/jsm/math/ConvexHull.js +1 -1
  54. package/examples/jsm/math/OBB.js +17 -0
  55. package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
  56. package/examples/jsm/misc/ProgressiveLightMap.js +4 -3
  57. package/examples/jsm/misc/ProgressiveLightMapGPU.js +14 -13
  58. package/examples/jsm/misc/Volume.js +27 -17
  59. package/examples/jsm/misc/VolumeSlice.js +7 -5
  60. package/examples/jsm/modifiers/CurveModifier.js +10 -8
  61. package/examples/jsm/modifiers/CurveModifierGPU.js +9 -7
  62. package/examples/jsm/modifiers/SimplifyModifier.js +2 -2
  63. package/examples/jsm/objects/GroundedSkybox.js +4 -4
  64. package/examples/jsm/objects/Sky.js +2 -2
  65. package/examples/jsm/objects/SkyMesh.js +3 -3
  66. package/examples/jsm/objects/Water2.js +1 -1
  67. package/examples/jsm/objects/Water2Mesh.js +2 -2
  68. package/examples/jsm/objects/WaterMesh.js +29 -24
  69. package/examples/jsm/physics/JoltPhysics.js +7 -7
  70. package/examples/jsm/physics/RapierPhysics.js +4 -4
  71. package/examples/jsm/postprocessing/BloomPass.js +2 -2
  72. package/examples/jsm/postprocessing/EffectComposer.js +1 -2
  73. package/examples/jsm/postprocessing/OutlinePass.js +4 -4
  74. package/examples/jsm/postprocessing/OutputPass.js +2 -0
  75. package/examples/jsm/postprocessing/SAOPass.js +1 -2
  76. package/examples/jsm/postprocessing/SMAAPass.js +1 -3
  77. package/examples/jsm/postprocessing/SSAOPass.js +2 -4
  78. package/examples/jsm/postprocessing/SSRPass.js +2 -4
  79. package/examples/jsm/postprocessing/UnrealBloomPass.js +2 -2
  80. package/examples/jsm/renderers/SVGRenderer.js +6 -4
  81. package/examples/jsm/shaders/BokehShader2.js +1 -1
  82. package/examples/jsm/shaders/GodRaysShader.js +3 -3
  83. package/examples/jsm/shaders/OutputShader.js +5 -1
  84. package/examples/jsm/shaders/SobelOperatorShader.js +1 -1
  85. package/examples/jsm/transpiler/GLSLDecoder.js +2 -2
  86. package/examples/jsm/transpiler/TSLEncoder.js +2 -0
  87. package/examples/jsm/tsl/display/AfterImageNode.js +93 -4
  88. package/examples/jsm/tsl/display/AnaglyphPassNode.js +46 -2
  89. package/examples/jsm/tsl/display/AnamorphicNode.js +118 -5
  90. package/examples/jsm/tsl/display/BleachBypass.js +10 -0
  91. package/examples/jsm/tsl/display/BloomNode.js +233 -26
  92. package/examples/jsm/tsl/display/DenoiseNode.js +141 -25
  93. package/examples/jsm/tsl/display/DepthOfFieldNode.js +80 -1
  94. package/examples/jsm/tsl/display/DotScreenNode.js +50 -5
  95. package/examples/jsm/tsl/display/FXAANode.js +52 -3
  96. package/examples/jsm/tsl/display/FilmNode.js +47 -1
  97. package/examples/jsm/tsl/display/GTAONode.js +210 -14
  98. package/examples/jsm/tsl/display/GaussianBlurNode.js +152 -8
  99. package/examples/jsm/tsl/display/LensflareNode.js +131 -13
  100. package/examples/jsm/tsl/display/Lut3DNode.js +55 -1
  101. package/examples/jsm/tsl/display/MotionBlur.js +12 -2
  102. package/examples/jsm/tsl/display/OutlineNode.js +343 -26
  103. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +36 -2
  104. package/examples/jsm/tsl/display/PixelationPassNode.js +142 -9
  105. package/examples/jsm/tsl/display/RGBShiftNode.js +49 -2
  106. package/examples/jsm/tsl/display/SMAANode.js +187 -46
  107. package/examples/jsm/tsl/display/SSAAPassNode.js +110 -25
  108. package/examples/jsm/tsl/display/SSRNode.js +194 -21
  109. package/examples/jsm/tsl/display/Sepia.js +9 -0
  110. package/examples/jsm/tsl/display/SobelOperatorNode.js +54 -4
  111. package/examples/jsm/tsl/display/StereoCompositePassNode.js +79 -3
  112. package/examples/jsm/tsl/display/StereoPassNode.js +41 -3
  113. package/examples/jsm/tsl/display/TRAAPassNode.js +116 -21
  114. package/examples/jsm/tsl/display/TransitionNode.js +71 -6
  115. package/examples/jsm/tsl/display/hashBlur.js +14 -3
  116. package/examples/jsm/tsl/lighting/TiledLightsNode.js +40 -34
  117. package/examples/jsm/utils/BufferGeometryUtils.js +1 -1
  118. package/examples/jsm/utils/CameraUtils.js +4 -1
  119. package/examples/jsm/utils/GeometryUtils.js +22 -19
  120. package/examples/jsm/utils/SceneUtils.js +2 -2
  121. package/examples/jsm/webxr/XRControllerModelFactory.js +6 -1
  122. package/examples/jsm/webxr/XREstimatedLight.js +1 -1
  123. package/package.json +8 -3
  124. package/src/Three.Core.js +4 -0
  125. package/src/Three.Legacy.js +0 -21
  126. package/src/Three.TSL.js +18 -5
  127. package/src/Three.WebGPU.Nodes.js +2 -2
  128. package/src/Three.WebGPU.js +2 -2
  129. package/src/animation/PropertyBinding.js +2 -2
  130. package/src/cameras/ArrayCamera.js +1 -0
  131. package/src/cameras/PerspectiveCamera.js +18 -2
  132. package/src/constants.js +6 -1
  133. package/src/core/BufferAttribute.js +4 -0
  134. package/src/core/EventDispatcher.js +8 -6
  135. package/src/core/RenderTarget.js +18 -0
  136. package/src/core/RenderTarget3D.js +22 -0
  137. package/src/core/RenderTargetArray.js +22 -0
  138. package/src/extras/Earcut.js +1 -1
  139. package/src/extras/ImageUtils.js +1 -11
  140. package/src/extras/PMREMGenerator.js +20 -0
  141. package/src/extras/TextureUtils.js +6 -0
  142. package/src/helpers/CameraHelper.js +16 -13
  143. package/src/loaders/nodes/NodeLoader.js +59 -0
  144. package/src/loaders/nodes/NodeMaterialLoader.js +45 -0
  145. package/src/loaders/nodes/NodeObjectLoader.js +61 -0
  146. package/src/materials/nodes/Line2NodeMaterial.js +128 -34
  147. package/src/materials/nodes/LineBasicNodeMaterial.js +17 -2
  148. package/src/materials/nodes/LineDashedNodeMaterial.js +78 -5
  149. package/src/materials/nodes/MeshBasicNodeMaterial.js +56 -0
  150. package/src/materials/nodes/MeshLambertNodeMaterial.js +35 -0
  151. package/src/materials/nodes/MeshMatcapNodeMaterial.js +22 -2
  152. package/src/materials/nodes/MeshNormalNodeMaterial.js +21 -2
  153. package/src/materials/nodes/MeshPhongNodeMaterial.js +64 -1
  154. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +269 -0
  155. package/src/materials/nodes/MeshSSSNodeMaterial.js +97 -6
  156. package/src/materials/nodes/MeshStandardNodeMaterial.js +78 -0
  157. package/src/materials/nodes/MeshToonNodeMaterial.js +28 -0
  158. package/src/materials/nodes/NodeMaterial.js +476 -23
  159. package/src/materials/nodes/NodeMaterials.js +0 -1
  160. package/src/materials/nodes/PointsNodeMaterial.js +121 -10
  161. package/src/materials/nodes/ShadowNodeMaterial.js +29 -0
  162. package/src/materials/nodes/SpriteNodeMaterial.js +78 -20
  163. package/src/materials/nodes/VolumeNodeMaterial.js +80 -4
  164. package/src/materials/nodes/manager/NodeMaterialObserver.js +95 -0
  165. package/src/nodes/Nodes.js +5 -6
  166. package/src/nodes/TSL.js +6 -3
  167. package/src/nodes/accessors/AccessorsUtils.js +27 -0
  168. package/src/nodes/accessors/Arrays.js +47 -6
  169. package/src/nodes/accessors/BatchNode.js +42 -6
  170. package/src/nodes/accessors/Bitangent.js +37 -0
  171. package/src/nodes/accessors/BufferAttributeNode.js +178 -5
  172. package/src/nodes/accessors/BufferNode.js +63 -0
  173. package/src/nodes/accessors/BuiltinNode.js +38 -0
  174. package/src/nodes/accessors/Camera.js +113 -3
  175. package/src/nodes/accessors/ClippingNode.js +71 -2
  176. package/src/nodes/accessors/CubeTextureNode.js +64 -0
  177. package/src/nodes/accessors/InstanceNode.js +85 -2
  178. package/src/nodes/accessors/InstancedMeshNode.js +28 -3
  179. package/src/nodes/accessors/Lights.js +50 -1
  180. package/src/nodes/accessors/MaterialNode.js +306 -12
  181. package/src/nodes/accessors/MaterialProperties.js +7 -0
  182. package/src/nodes/accessors/MaterialReferenceNode.js +53 -13
  183. package/src/nodes/accessors/ModelNode.js +100 -5
  184. package/src/nodes/accessors/ModelViewProjectionNode.js +10 -38
  185. package/src/nodes/accessors/MorphNode.js +48 -4
  186. package/src/nodes/accessors/Normal.js +65 -5
  187. package/src/nodes/accessors/Object3DNode.js +101 -1
  188. package/src/nodes/accessors/PointUVNode.js +26 -0
  189. package/src/nodes/accessors/Position.js +56 -7
  190. package/src/nodes/accessors/ReferenceBaseNode.js +186 -0
  191. package/src/nodes/accessors/ReferenceNode.js +201 -2
  192. package/src/nodes/accessors/ReflectVector.js +24 -0
  193. package/src/nodes/accessors/RendererReferenceNode.js +46 -1
  194. package/src/nodes/accessors/SceneNode.js +54 -0
  195. package/src/nodes/accessors/SkinningNode.js +127 -1
  196. package/src/nodes/accessors/StorageBufferNode.js +209 -8
  197. package/src/nodes/accessors/StorageTextureNode.js +118 -0
  198. package/src/nodes/accessors/Tangent.js +38 -2
  199. package/src/nodes/accessors/Texture3DNode.js +91 -7
  200. package/src/nodes/accessors/TextureBicubic.js +12 -2
  201. package/src/nodes/accessors/TextureNode.js +316 -10
  202. package/src/nodes/accessors/TextureSizeNode.js +42 -0
  203. package/src/nodes/accessors/UV.js +10 -1
  204. package/src/nodes/accessors/UniformArrayNode.js +231 -25
  205. package/src/nodes/accessors/UserDataNode.js +46 -0
  206. package/src/nodes/accessors/VelocityNode.js +80 -0
  207. package/src/nodes/accessors/VertexColorNode.js +39 -2
  208. package/src/nodes/code/CodeNode.js +95 -1
  209. package/src/nodes/code/ExpressionNode.js +28 -0
  210. package/src/nodes/code/FunctionCallNode.js +37 -0
  211. package/src/nodes/code/FunctionNode.js +45 -0
  212. package/src/nodes/code/ScriptableNode.js +223 -1
  213. package/src/nodes/code/ScriptableValueNode.js +85 -1
  214. package/src/nodes/core/ArrayNode.js +125 -0
  215. package/src/nodes/core/AssignNode.js +48 -2
  216. package/src/nodes/core/AttributeNode.js +43 -0
  217. package/src/nodes/core/BypassNode.js +47 -2
  218. package/src/nodes/core/CacheNode.js +53 -2
  219. package/src/nodes/core/ConstNode.js +32 -0
  220. package/src/nodes/core/ContextNode.js +65 -0
  221. package/src/nodes/core/IndexNode.js +68 -7
  222. package/src/nodes/core/InputNode.js +48 -0
  223. package/src/nodes/core/LightingModel.js +60 -0
  224. package/src/nodes/core/MRTNode.js +66 -0
  225. package/src/nodes/core/Node.js +350 -12
  226. package/src/nodes/core/NodeAttribute.js +38 -0
  227. package/src/nodes/core/NodeBuilder.js +1166 -26
  228. package/src/nodes/core/NodeCache.js +41 -2
  229. package/src/nodes/core/NodeCode.js +31 -0
  230. package/src/nodes/core/NodeFrame.js +123 -2
  231. package/src/nodes/core/NodeFunction.js +46 -0
  232. package/src/nodes/core/NodeFunctionInput.js +44 -0
  233. package/src/nodes/core/NodeParser.js +11 -0
  234. package/src/nodes/core/NodeUniform.js +52 -0
  235. package/src/nodes/core/NodeUtils.js +152 -1
  236. package/src/nodes/core/NodeVar.js +47 -1
  237. package/src/nodes/core/NodeVarying.js +28 -0
  238. package/src/nodes/core/OutputStructNode.js +51 -10
  239. package/src/nodes/core/ParameterNode.js +28 -0
  240. package/src/nodes/core/PropertyNode.js +232 -0
  241. package/src/nodes/core/StackNode.js +98 -1
  242. package/src/nodes/core/StructNode.js +121 -0
  243. package/src/nodes/core/StructType.js +13 -0
  244. package/src/nodes/core/StructTypeNode.js +105 -6
  245. package/src/nodes/core/TempNode.js +31 -5
  246. package/src/nodes/core/UniformGroupNode.js +82 -7
  247. package/src/nodes/core/UniformNode.js +66 -0
  248. package/src/nodes/core/VarNode.js +146 -7
  249. package/src/nodes/core/VaryingNode.js +100 -3
  250. package/src/nodes/core/constants.js +36 -0
  251. package/src/nodes/display/BlendModes.js +88 -1
  252. package/src/nodes/display/BumpMapNode.js +37 -0
  253. package/src/nodes/display/ColorAdjustment.js +53 -11
  254. package/src/nodes/display/ColorSpaceFunctions.js +16 -0
  255. package/src/nodes/display/ColorSpaceNode.js +82 -0
  256. package/src/nodes/display/FrontFacingNode.js +29 -0
  257. package/src/nodes/display/NormalMapNode.js +43 -0
  258. package/src/nodes/display/PassNode.js +300 -7
  259. package/src/nodes/display/PosterizeNode.js +33 -0
  260. package/src/nodes/display/RenderOutputNode.js +66 -1
  261. package/src/nodes/display/ScreenNode.js +96 -0
  262. package/src/nodes/display/ToneMappingFunctions.js +58 -10
  263. package/src/nodes/display/ToneMappingNode.js +55 -2
  264. package/src/nodes/display/ToonOutlinePassNode.js +73 -0
  265. package/src/nodes/display/ViewportDepthNode.js +122 -8
  266. package/src/nodes/display/ViewportDepthTextureNode.js +23 -0
  267. package/src/nodes/display/ViewportSharedTextureNode.js +23 -0
  268. package/src/nodes/display/ViewportTextureNode.js +57 -0
  269. package/src/nodes/fog/Fog.js +110 -0
  270. package/src/nodes/functions/BasicLightingModel.js +24 -0
  271. package/src/nodes/functions/PhongLightingModel.js +34 -2
  272. package/src/nodes/functions/PhysicalLightingModel.js +167 -8
  273. package/src/nodes/functions/ShadowMaskModel.js +23 -0
  274. package/src/nodes/functions/ToonLightingModel.js +20 -0
  275. package/src/nodes/functions/material/getAlphaHashThreshold.js +1 -3
  276. package/src/nodes/functions/material/getParallaxCorrectNormal.js +16 -1
  277. package/src/nodes/geometry/RangeNode.js +54 -2
  278. package/src/nodes/gpgpu/AtomicFunctionNode.js +174 -2
  279. package/src/nodes/gpgpu/BarrierNode.js +47 -0
  280. package/src/nodes/gpgpu/ComputeBuiltinNode.js +134 -0
  281. package/src/nodes/gpgpu/ComputeNode.js +106 -2
  282. package/src/nodes/gpgpu/WorkgroupInfoNode.js +115 -6
  283. package/src/nodes/lighting/AONode.js +18 -0
  284. package/src/nodes/lighting/AmbientLightNode.js +10 -0
  285. package/src/nodes/lighting/AnalyticLightNode.js +97 -2
  286. package/src/nodes/lighting/BasicEnvironmentNode.js +19 -0
  287. package/src/nodes/lighting/BasicLightMapNode.js +17 -0
  288. package/src/nodes/lighting/DirectionalLightNode.js +10 -0
  289. package/src/nodes/lighting/EnvironmentNode.js +18 -0
  290. package/src/nodes/lighting/HemisphereLightNode.js +31 -0
  291. package/src/nodes/lighting/IESSpotLightNode.js +11 -0
  292. package/src/nodes/lighting/IrradianceNode.js +17 -0
  293. package/src/nodes/lighting/LightProbeNode.js +20 -0
  294. package/src/nodes/lighting/LightUtils.js +12 -0
  295. package/src/nodes/lighting/LightingContextNode.js +48 -0
  296. package/src/nodes/lighting/LightingNode.js +15 -6
  297. package/src/nodes/lighting/LightsNode.js +132 -1
  298. package/src/nodes/lighting/PointLightNode.js +32 -1
  299. package/src/nodes/lighting/PointShadowNode.js +54 -1
  300. package/src/nodes/lighting/RectAreaLightNode.js +44 -6
  301. package/src/nodes/lighting/ShadowBaseNode.js +93 -0
  302. package/src/nodes/lighting/ShadowNode.js +241 -35
  303. package/src/nodes/lighting/SpotLightNode.js +43 -0
  304. package/src/nodes/math/ConditionalNode.js +78 -4
  305. package/src/nodes/math/Hash.js +9 -0
  306. package/src/nodes/math/MathNode.js +627 -11
  307. package/src/nodes/math/MathUtils.js +45 -1
  308. package/src/nodes/math/OperatorNode.js +329 -18
  309. package/src/nodes/math/TriNoise3D.js +18 -7
  310. package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
  311. package/src/nodes/parsers/GLSLNodeParser.js +11 -0
  312. package/src/nodes/pmrem/PMREMNode.js +133 -0
  313. package/src/nodes/pmrem/PMREMUtils.js +2 -2
  314. package/src/nodes/procedural/Checker.js +9 -0
  315. package/src/nodes/shapes/Shapes.js +33 -0
  316. package/src/nodes/tsl/TSLBase.js +3 -2
  317. package/src/nodes/tsl/TSLCore.js +22 -2
  318. package/src/nodes/utils/ArrayElementNode.js +39 -3
  319. package/src/nodes/utils/ConvertNode.js +31 -0
  320. package/src/nodes/utils/CubeMapNode.js +78 -0
  321. package/src/nodes/utils/Discard.js +16 -0
  322. package/src/nodes/utils/EquirectUVNode.js +31 -1
  323. package/src/nodes/utils/FlipNode.js +38 -0
  324. package/src/nodes/utils/FunctionOverloadingNode.js +53 -1
  325. package/src/nodes/utils/JoinNode.js +25 -0
  326. package/src/nodes/utils/LoopNode.js +82 -2
  327. package/src/nodes/utils/MatcapUVNode.js +17 -0
  328. package/src/nodes/utils/MaxMipLevelNode.js +49 -0
  329. package/src/nodes/utils/MemberNode.js +68 -0
  330. package/src/nodes/utils/Oscillators.js +33 -0
  331. package/src/nodes/utils/Packing.js +17 -0
  332. package/src/nodes/utils/PostProcessingUtils.js +28 -23
  333. package/src/nodes/utils/RTTNode.js +123 -2
  334. package/src/nodes/utils/ReflectorNode.js +174 -4
  335. package/src/nodes/utils/RemapNode.js +79 -0
  336. package/src/nodes/utils/RotateNode.js +41 -0
  337. package/src/nodes/utils/SetNode.js +44 -1
  338. package/src/nodes/utils/SplitNode.js +55 -3
  339. package/src/nodes/utils/SpriteSheetUVNode.js +46 -0
  340. package/src/nodes/utils/SpriteUtils.js +17 -0
  341. package/src/nodes/utils/StorageArrayElementNode.js +54 -0
  342. package/src/nodes/utils/Timer.js +40 -0
  343. package/src/nodes/utils/TriplanarTexturesNode.js +84 -0
  344. package/src/nodes/utils/UVUtils.js +20 -0
  345. package/src/nodes/utils/ViewportUtils.js +13 -0
  346. package/src/objects/BatchedMesh.js +2 -3
  347. package/src/objects/ClippingGroup.js +49 -0
  348. package/src/objects/Line.js +6 -6
  349. package/src/renderers/WebGLRenderer.js +30 -4
  350. package/src/renderers/common/Animation.js +85 -0
  351. package/src/renderers/common/Attributes.js +36 -0
  352. package/src/renderers/common/Backend.js +502 -44
  353. package/src/renderers/common/Background.js +48 -1
  354. package/src/renderers/common/BindGroup.js +43 -0
  355. package/src/renderers/common/Binding.js +35 -0
  356. package/src/renderers/common/Bindings.js +93 -1
  357. package/src/renderers/common/Buffer.js +49 -0
  358. package/src/renderers/common/BufferUtils.js +27 -0
  359. package/src/renderers/common/BundleGroup.js +57 -0
  360. package/src/renderers/common/ChainMap.js +45 -6
  361. package/src/renderers/common/ClippingContext.js +108 -15
  362. package/src/renderers/common/Color4.js +40 -0
  363. package/src/renderers/common/ComputePipeline.js +24 -0
  364. package/src/renderers/common/CubeRenderTarget.js +13 -0
  365. package/src/renderers/common/DataMap.js +37 -1
  366. package/src/renderers/common/Geometries.js +91 -14
  367. package/src/renderers/common/IndirectStorageBufferAttribute.js +25 -2
  368. package/src/renderers/common/Info.js +78 -35
  369. package/src/renderers/common/Lighting.js +34 -6
  370. package/src/renderers/common/Pipeline.js +22 -0
  371. package/src/renderers/common/Pipelines.js +148 -5
  372. package/src/renderers/common/PostProcessing.js +99 -11
  373. package/src/renderers/common/ProgrammableStage.js +60 -2
  374. package/src/renderers/common/QuadMesh.js +54 -5
  375. package/src/renderers/common/RenderBundle.js +14 -8
  376. package/src/renderers/common/RenderBundles.js +39 -10
  377. package/src/renderers/common/RenderContext.js +201 -2
  378. package/src/renderers/common/RenderContexts.js +59 -6
  379. package/src/renderers/common/RenderList.js +178 -0
  380. package/src/renderers/common/RenderLists.js +40 -3
  381. package/src/renderers/common/RenderObject.js +400 -17
  382. package/src/renderers/common/RenderObjects.js +103 -7
  383. package/src/renderers/common/RenderPipeline.js +24 -0
  384. package/src/renderers/common/Renderer.js +1170 -86
  385. package/src/renderers/common/RendererUtils.js +193 -0
  386. package/src/renderers/common/SampledTexture.js +120 -0
  387. package/src/renderers/common/Sampler.js +30 -0
  388. package/src/renderers/common/StorageBuffer.js +24 -0
  389. package/src/renderers/common/StorageBufferAttribute.js +31 -2
  390. package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
  391. package/src/renderers/common/StorageTexture.js +38 -0
  392. package/src/renderers/common/Textures.js +97 -7
  393. package/src/renderers/common/TimestampQueryPool.js +39 -0
  394. package/src/renderers/common/Uniform.js +225 -3
  395. package/src/renderers/common/UniformBuffer.js +19 -0
  396. package/src/renderers/common/UniformsGroup.js +141 -2
  397. package/src/renderers/common/XRManager.js +1193 -0
  398. package/src/renderers/common/XRRenderTarget.js +74 -0
  399. package/src/renderers/common/extras/PMREMGenerator.js +76 -10
  400. package/src/renderers/common/nodes/NodeBuilderState.js +99 -5
  401. package/src/renderers/common/nodes/NodeLibrary.js +89 -0
  402. package/src/renderers/common/nodes/NodeSampledTexture.js +90 -2
  403. package/src/renderers/common/nodes/NodeSampler.js +28 -0
  404. package/src/renderers/common/nodes/NodeStorageBuffer.js +35 -0
  405. package/src/renderers/common/nodes/NodeUniform.js +243 -2
  406. package/src/renderers/common/nodes/NodeUniformBuffer.js +29 -0
  407. package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
  408. package/src/renderers/common/nodes/Nodes.js +352 -78
  409. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
  410. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
  411. package/src/renderers/webgl/WebGLBackground.js +4 -0
  412. package/src/renderers/webgl-fallback/WebGLBackend.js +819 -116
  413. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +347 -18
  414. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +58 -1
  415. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
  416. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
  417. package/src/renderers/webgl-fallback/utils/WebGLState.js +323 -11
  418. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +168 -22
  419. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +359 -0
  420. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
  421. package/src/renderers/webgpu/WebGPUBackend.js +578 -164
  422. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +36 -0
  423. package/src/renderers/webgpu/WebGPURenderer.js +36 -0
  424. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +20 -8
  425. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +21 -8
  426. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +674 -52
  427. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +17 -0
  428. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
  429. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +95 -14
  430. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +94 -1
  431. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +102 -3
  432. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +98 -1
  433. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +262 -18
  434. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +274 -0
  435. package/src/renderers/webgpu/utils/WebGPUUtils.js +116 -4
  436. package/src/renderers/webxr/WebXRDepthSensing.js +1 -1
  437. package/src/renderers/webxr/WebXRManager.js +19 -2
  438. package/src/textures/Data3DTexture.js +2 -2
  439. package/src/textures/Texture.js +4 -0
  440. package/src/textures/VideoFrameTexture.js +35 -0
  441. package/examples/jsm/animation/MMDAnimationHelper.js +0 -1209
  442. package/examples/jsm/animation/MMDPhysics.js +0 -1408
  443. package/examples/jsm/exporters/MMDExporter.js +0 -223
  444. package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -176
  445. package/examples/jsm/libs/mmdparser.module.js +0 -11530
  446. package/examples/jsm/loaders/MMDLoader.js +0 -2298
  447. package/examples/jsm/objects/InstancedPoints.js +0 -19
  448. package/examples/jsm/shaders/MMDToonShader.js +0 -134
  449. package/src/materials/nodes/InstancedPointsNodeMaterial.js +0 -156
  450. package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -24
  451. package/src/nodes/core/UniformGroup.js +0 -13
  452. package/src/nodes/fog/FogExp2Node.js +0 -35
  453. package/src/nodes/fog/FogNode.js +0 -50
  454. package/src/nodes/fog/FogRangeNode.js +0 -36
  455. package/src/renderers/common/PostProcessingUtils.js +0 -86
@@ -5,6 +5,7 @@ import NodeVar from './NodeVar.js';
5
5
  import NodeCode from './NodeCode.js';
6
6
  import NodeCache from './NodeCache.js';
7
7
  import ParameterNode from './ParameterNode.js';
8
+ import StructType from './StructType.js';
8
9
  import FunctionNode from '../code/FunctionNode.js';
9
10
  import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
10
11
  import { getTypeFromLength } from './NodeUtils.js';
@@ -12,7 +13,7 @@ import { NodeUpdateType, defaultBuildStages, shaderStages } from './constants.js
12
13
 
13
14
  import {
14
15
  NumberNodeUniform, Vector2NodeUniform, Vector3NodeUniform, Vector4NodeUniform,
15
- ColorNodeUniform, Matrix3NodeUniform, Matrix4NodeUniform
16
+ ColorNodeUniform, Matrix2NodeUniform, Matrix3NodeUniform, Matrix4NodeUniform
16
17
  } from '../../renderers/common/nodes/NodeUniform.js';
17
18
 
18
19
  import { stack } from './StackNode.js';
@@ -25,14 +26,13 @@ import PMREMGenerator from '../../renderers/common/extras/PMREMGenerator.js';
25
26
 
26
27
  import BindGroup from '../../renderers/common/BindGroup.js';
27
28
 
28
- import { REVISION } from '../../constants.js';
29
+ import { REVISION, IntType, UnsignedIntType, LinearFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapLinearFilter } from '../../constants.js';
29
30
  import { RenderTarget } from '../../core/RenderTarget.js';
30
31
  import { Color } from '../../math/Color.js';
31
32
  import { Vector2 } from '../../math/Vector2.js';
32
33
  import { Vector3 } from '../../math/Vector3.js';
33
34
  import { Vector4 } from '../../math/Vector4.js';
34
35
  import { Float16BufferAttribute } from '../../core/BufferAttribute.js';
35
- import { IntType, UnsignedIntType, LinearFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapLinearFilter } from '../../constants.js';
36
36
 
37
37
  const rendererCache = new WeakMap();
38
38
 
@@ -62,73 +62,371 @@ const toFloat = ( value ) => {
62
62
 
63
63
  };
64
64
 
65
+ /**
66
+ * Base class for builders which generate a shader program based
67
+ * on a 3D object and its node material definition.
68
+ */
65
69
  class NodeBuilder {
66
70
 
71
+ /**
72
+ * Constructs a new node builder.
73
+ *
74
+ * @param {Object3D} object - The 3D object.
75
+ * @param {Renderer} renderer - The current renderer.
76
+ * @param {NodeParser} parser - A reference to a node parser.
77
+ */
67
78
  constructor( object, renderer, parser ) {
68
79
 
80
+ /**
81
+ * The 3D object.
82
+ *
83
+ * @type {Object3D}
84
+ */
69
85
  this.object = object;
86
+
87
+ /**
88
+ * The material of the 3D object.
89
+ *
90
+ * @type {Material?}
91
+ */
70
92
  this.material = ( object && object.material ) || null;
93
+
94
+ /**
95
+ * The geometry of the 3D object.
96
+ *
97
+ * @type {BufferGeometry?}
98
+ */
71
99
  this.geometry = ( object && object.geometry ) || null;
100
+
101
+ /**
102
+ * The current renderer.
103
+ *
104
+ * @type {Renderer}
105
+ */
72
106
  this.renderer = renderer;
107
+
108
+ /**
109
+ * A reference to a node parser.
110
+ *
111
+ * @type {NodeParser}
112
+ */
73
113
  this.parser = parser;
114
+
115
+ /**
116
+ * The scene the 3D object belongs to.
117
+ *
118
+ * @type {Scene?}
119
+ * @default null
120
+ */
74
121
  this.scene = null;
122
+
123
+ /**
124
+ * The camera the 3D object is rendered with.
125
+ *
126
+ * @type {Camera?}
127
+ * @default null
128
+ */
75
129
  this.camera = null;
76
130
 
131
+ /**
132
+ * A list of all nodes the builder is processing
133
+ * for this 3D object.
134
+ *
135
+ * @type {Array<Node>}
136
+ */
77
137
  this.nodes = [];
138
+
139
+ /**
140
+ * A list of all sequential nodes.
141
+ *
142
+ * @type {Array<Node>}
143
+ */
78
144
  this.sequentialNodes = [];
145
+
146
+ /**
147
+ * A list of all nodes which {@link Node#update} method should be executed.
148
+ *
149
+ * @type {Array<Node>}
150
+ */
79
151
  this.updateNodes = [];
152
+
153
+ /**
154
+ * A list of all nodes which {@link Node#updateBefore} method should be executed.
155
+ *
156
+ * @type {Array<Node>}
157
+ */
80
158
  this.updateBeforeNodes = [];
159
+
160
+ /**
161
+ * A list of all nodes which {@link Node#updateAfter} method should be executed.
162
+ *
163
+ * @type {Array<Node>}
164
+ */
81
165
  this.updateAfterNodes = [];
82
- this.hashNodes = {};
83
166
 
84
- this.monitor = null;
167
+ /**
168
+ * A dictionary that assigns each node to a unique hash.
169
+ *
170
+ * @type {Object<Number,Node>}
171
+ */
172
+ this.hashNodes = {};
85
173
 
174
+ /**
175
+ * A reference to a node material observer.
176
+ *
177
+ * @type {NodeMaterialObserver?}
178
+ * @default null
179
+ */
180
+ this.observer = null;
181
+
182
+ /**
183
+ * A reference to the current lights node.
184
+ *
185
+ * @type {LightsNode?}
186
+ * @default null
187
+ */
86
188
  this.lightsNode = null;
189
+
190
+ /**
191
+ * A reference to the current environment node.
192
+ *
193
+ * @type {Node?}
194
+ * @default null
195
+ */
87
196
  this.environmentNode = null;
197
+
198
+ /**
199
+ * A reference to the current fog node.
200
+ *
201
+ * @type {FogNode?}
202
+ * @default null
203
+ */
88
204
  this.fogNode = null;
89
205
 
206
+ /**
207
+ * The current clipping context.
208
+ *
209
+ * @type {ClippingContext?}
210
+ */
90
211
  this.clippingContext = null;
91
212
 
213
+ /**
214
+ * The generated vertex shader.
215
+ *
216
+ * @type {String?}
217
+ */
92
218
  this.vertexShader = null;
219
+
220
+ /**
221
+ * The generated fragment shader.
222
+ *
223
+ * @type {String?}
224
+ */
93
225
  this.fragmentShader = null;
226
+
227
+ /**
228
+ * The generated compute shader.
229
+ *
230
+ * @type {String?}
231
+ */
94
232
  this.computeShader = null;
95
233
 
234
+ /**
235
+ * Nodes used in the primary flow of code generation.
236
+ *
237
+ * @type {Object<String,Array<Node>>}
238
+ */
96
239
  this.flowNodes = { vertex: [], fragment: [], compute: [] };
240
+
241
+ /**
242
+ * Nodes code from `.flowNodes`.
243
+ *
244
+ * @type {Object<String,String>}
245
+ */
97
246
  this.flowCode = { vertex: '', fragment: '', compute: '' };
247
+
248
+ /**
249
+ * This dictionary holds the node uniforms of the builder.
250
+ * The uniforms are maintained in an array for each shader stage.
251
+ *
252
+ * @type {Object}
253
+ */
98
254
  this.uniforms = { vertex: [], fragment: [], compute: [], index: 0 };
255
+
256
+ /**
257
+ * This dictionary holds the output structs of the builder.
258
+ * The structs are maintained in an array for each shader stage.
259
+ *
260
+ * @type {Object}
261
+ */
99
262
  this.structs = { vertex: [], fragment: [], compute: [], index: 0 };
263
+
264
+ /**
265
+ * This dictionary holds the bindings for each shader stage.
266
+ *
267
+ * @type {Object}
268
+ */
100
269
  this.bindings = { vertex: {}, fragment: {}, compute: {} };
270
+
271
+ /**
272
+ * This dictionary maintains the binding indices per bind group.
273
+ *
274
+ * @type {Object}
275
+ */
101
276
  this.bindingsIndexes = {};
277
+
278
+ /**
279
+ * Reference to the array of bind groups.
280
+ *
281
+ * @type {Array<BindGroup>?}
282
+ */
102
283
  this.bindGroups = null;
284
+
285
+ /**
286
+ * This array holds the node attributes of this builder
287
+ * created via {@link AttributeNode}.
288
+ *
289
+ * @type {Array<NodeAttribute>}
290
+ */
103
291
  this.attributes = [];
292
+
293
+ /**
294
+ * This array holds the node attributes of this builder
295
+ * created via {@link BufferAttributeNode}.
296
+ *
297
+ * @type {Array<NodeAttribute>}
298
+ */
104
299
  this.bufferAttributes = [];
300
+
301
+ /**
302
+ * This array holds the node varyings of this builder.
303
+ *
304
+ * @type {Array<NodeVarying>}
305
+ */
105
306
  this.varyings = [];
307
+
308
+ /**
309
+ * This dictionary holds the (native) node codes of this builder.
310
+ * The codes are maintained in an array for each shader stage.
311
+ *
312
+ * @type {Object<String,Array<NodeCode>>}
313
+ */
106
314
  this.codes = {};
315
+
316
+ /**
317
+ * This dictionary holds the node variables of this builder.
318
+ * The variables are maintained in an array for each shader stage.
319
+ *
320
+ * @type {Object<String,Array<NodeVar>>}
321
+ */
107
322
  this.vars = {};
323
+
324
+ /**
325
+ * Current code flow.
326
+ * All code generated in this stack will be stored in `.flow`.
327
+ *
328
+ * @type {{code: String}}
329
+ */
108
330
  this.flow = { code: '' };
331
+
332
+ /**
333
+ * A chain of nodes.
334
+ * Used to check recursive calls in node-graph.
335
+ *
336
+ * @type {Array<Node>}
337
+ */
109
338
  this.chaining = [];
339
+
340
+ /**
341
+ * The current stack.
342
+ * This reflects the current process in the code block hierarchy,
343
+ * it is useful to know if the current process is inside a conditional for example.
344
+ *
345
+ * @type {StackNode}
346
+ */
110
347
  this.stack = stack();
348
+
349
+ /**
350
+ * List of stack nodes.
351
+ * The current stack hierarchy is stored in an array.
352
+ *
353
+ * @type {Array<StackNode>}
354
+ */
111
355
  this.stacks = [];
356
+
357
+ /**
358
+ * A tab value. Used for shader string generation.
359
+ *
360
+ * @type {String}
361
+ * @default '\t'
362
+ */
112
363
  this.tab = '\t';
113
364
 
365
+ /**
366
+ * Reference to the current function node.
367
+ *
368
+ * @type {FunctionNode?}
369
+ * @default null
370
+ */
114
371
  this.currentFunctionNode = null;
115
372
 
373
+ /**
374
+ * The builder's context.
375
+ *
376
+ * @type {Object}
377
+ */
116
378
  this.context = {
117
379
  material: this.material
118
380
  };
119
381
 
382
+ /**
383
+ * The builder's cache.
384
+ *
385
+ * @type {NodeCache}
386
+ */
120
387
  this.cache = new NodeCache();
388
+
389
+ /**
390
+ * Since the {@link NodeBuilder#cache} might be temporarily
391
+ * overwritten by other caches, this member retains the reference
392
+ * to the builder's own cache.
393
+ *
394
+ * @type {NodeCache}
395
+ * @default this.cache
396
+ */
121
397
  this.globalCache = this.cache;
122
398
 
123
399
  this.flowsData = new WeakMap();
124
400
 
401
+ /**
402
+ * The current shader stage.
403
+ *
404
+ * @type {('vertex'|'fragment'|'compute'|'any')?}
405
+ */
125
406
  this.shaderStage = null;
407
+
408
+ /**
409
+ * The current build stage.
410
+ *
411
+ * @type {('setup'|'analyze'|'generate')?}
412
+ */
126
413
  this.buildStage = null;
127
414
 
415
+ /**
416
+ * Whether comparison in shader code are generated with methods or not.
417
+ *
418
+ * @type {Boolean}
419
+ * @default false
420
+ */
128
421
  this.useComparisonMethod = false;
129
422
 
130
423
  }
131
424
 
425
+ /**
426
+ * Returns the bind groups of the current renderer.
427
+ *
428
+ * @return {ChainMap} The cache.
429
+ */
132
430
  getBindGroupsCache() {
133
431
 
134
432
  let bindGroupsCache = rendererCache.get( this.renderer );
@@ -145,18 +443,40 @@ class NodeBuilder {
145
443
 
146
444
  }
147
445
 
446
+ /**
447
+ * Factory method for creating an instance of {@link RenderTarget} with the given
448
+ * dimensions and options.
449
+ *
450
+ * @param {Number} width - The width of the render target.
451
+ * @param {Number} height - The height of the render target.
452
+ * @param {Object} options - The options of the render target.
453
+ * @return {RenderTarget} The render target.
454
+ */
148
455
  createRenderTarget( width, height, options ) {
149
456
 
150
457
  return new RenderTarget( width, height, options );
151
458
 
152
459
  }
153
460
 
461
+ /**
462
+ * Factory method for creating an instance of {@link CubeRenderTarget} with the given
463
+ * dimensions and options.
464
+ *
465
+ * @param {Number} size - The size of the cube render target.
466
+ * @param {Object} options - The options of the cube render target.
467
+ * @return {CubeRenderTarget} The cube render target.
468
+ */
154
469
  createCubeRenderTarget( size, options ) {
155
470
 
156
471
  return new CubeRenderTarget( size, options );
157
472
 
158
473
  }
159
474
 
475
+ /**
476
+ * Factory method for creating an instance of {@link PMREMGenerator}.
477
+ *
478
+ * @return {PMREMGenerator} The PMREM generator.
479
+ */
160
480
  createPMREMGenerator() {
161
481
 
162
482
  // TODO: Move Materials.js to outside of the Nodes.js in order to remove this function and improve tree-shaking support
@@ -165,12 +485,35 @@ class NodeBuilder {
165
485
 
166
486
  }
167
487
 
488
+ /**
489
+ * Whether the given node is included in the internal array of nodes or not.
490
+ *
491
+ * @param {Node} node - The node to test.
492
+ * @return {Boolean} Whether the given node is included in the internal array of nodes or not.
493
+ */
168
494
  includes( node ) {
169
495
 
170
496
  return this.nodes.includes( node );
171
497
 
172
498
  }
173
499
 
500
+ /**
501
+ * Returns the output struct name which is required by
502
+ * {@link module:OutputStructNode}.
503
+ *
504
+ * @abstract
505
+ * @return {String} The name of the output struct.
506
+ */
507
+ getOutputStructName() {}
508
+
509
+ /**
510
+ * Returns a bind group for the given group name and binding.
511
+ *
512
+ * @private
513
+ * @param {String} groupName - The group name.
514
+ * @param {Array<NodeUniformsGroup>} bindings - List of bindings.
515
+ * @return {BindGroup} The bind group
516
+ */
174
517
  _getBindGroup( groupName, bindings ) {
175
518
 
176
519
  const bindGroupsCache = this.getBindGroupsCache();
@@ -215,6 +558,13 @@ class NodeBuilder {
215
558
 
216
559
  }
217
560
 
561
+ /**
562
+ * Returns an array of node uniform groups for the given group name and shader stage.
563
+ *
564
+ * @param {String} groupName - The group name.
565
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
566
+ * @return {Array<NodeUniformsGroup>} The array of node uniform groups.
567
+ */
218
568
  getBindGroupArray( groupName, shaderStage ) {
219
569
 
220
570
  const bindings = this.bindings[ shaderStage ];
@@ -237,6 +587,11 @@ class NodeBuilder {
237
587
 
238
588
  }
239
589
 
590
+ /**
591
+ * Returns a list bindings of all shader stages separated by groups.
592
+ *
593
+ * @return {Array<BindGroup>} The list of bindings.
594
+ */
240
595
  getBindings() {
241
596
 
242
597
  let bindingsGroups = this.bindGroups;
@@ -279,6 +634,9 @@ class NodeBuilder {
279
634
 
280
635
  }
281
636
 
637
+ /**
638
+ * Sorts the bind groups and updates {@link NodeBuilder#bindingsIndexes}.
639
+ */
282
640
  sortBindingGroups() {
283
641
 
284
642
  const bindingsGroups = this.getBindings();
@@ -296,12 +654,24 @@ class NodeBuilder {
296
654
 
297
655
  }
298
656
 
657
+ /**
658
+ * The builder maintains each node in a hash-based dictionary.
659
+ * This method sets the given node (value) with the given hash (key) into this dictionary.
660
+ *
661
+ * @param {Node} node - The node to add.
662
+ * @param {Number} hash - The hash of the node.
663
+ */
299
664
  setHashNode( node, hash ) {
300
665
 
301
666
  this.hashNodes[ hash ] = node;
302
667
 
303
668
  }
304
669
 
670
+ /**
671
+ * Adds a node to this builder.
672
+ *
673
+ * @param {Node} node - The node to add.
674
+ */
305
675
  addNode( node ) {
306
676
 
307
677
  if ( this.nodes.includes( node ) === false ) {
@@ -314,6 +684,13 @@ class NodeBuilder {
314
684
 
315
685
  }
316
686
 
687
+ /**
688
+ * It is used to add Nodes that will be used as FRAME and RENDER events,
689
+ * and need to follow a certain sequence in the calls to work correctly.
690
+ * This function should be called after 'setup()' in the 'build()' process to ensure that the child nodes are processed first.
691
+ *
692
+ * @param {Node} node - The node to add.
693
+ */
317
694
  addSequentialNode( node ) {
318
695
 
319
696
  if ( this.sequentialNodes.includes( node ) === false ) {
@@ -324,6 +701,9 @@ class NodeBuilder {
324
701
 
325
702
  }
326
703
 
704
+ /**
705
+ * Checks the update types of nodes
706
+ */
327
707
  buildUpdateNodes() {
328
708
 
329
709
  for ( const node of this.nodes ) {
@@ -359,12 +739,24 @@ class NodeBuilder {
359
739
 
360
740
  }
361
741
 
742
+ /**
743
+ * A reference the current node which is the
744
+ * last node in the chain of nodes.
745
+ *
746
+ * @type {Node}
747
+ */
362
748
  get currentNode() {
363
749
 
364
750
  return this.chaining[ this.chaining.length - 1 ];
365
751
 
366
752
  }
367
753
 
754
+ /**
755
+ * Whether the given texture is filtered or not.
756
+ *
757
+ * @param {Texture} texture - The texture to check.
758
+ * @return {Boolean} Whether the given texture is filtered or not.
759
+ */
368
760
  isFilteredTexture( texture ) {
369
761
 
370
762
  return ( texture.magFilter === LinearFilter || texture.magFilter === LinearMipmapNearestFilter || texture.magFilter === NearestMipmapLinearFilter || texture.magFilter === LinearMipmapLinearFilter ||
@@ -372,6 +764,12 @@ class NodeBuilder {
372
764
 
373
765
  }
374
766
 
767
+ /**
768
+ * Adds the given node to the internal node chain.
769
+ * This is used to check recursive calls in node-graph.
770
+ *
771
+ * @param {Node} node - The node to add.
772
+ */
375
773
  addChain( node ) {
376
774
 
377
775
  /*
@@ -386,6 +784,11 @@ class NodeBuilder {
386
784
 
387
785
  }
388
786
 
787
+ /**
788
+ * Removes the given node from the internal node chain.
789
+ *
790
+ * @param {Node} node - The node to remove.
791
+ */
389
792
  removeChain( node ) {
390
793
 
391
794
  const lastChain = this.chaining.pop();
@@ -398,18 +801,40 @@ class NodeBuilder {
398
801
 
399
802
  }
400
803
 
804
+ /**
805
+ * Returns the native shader method name for a given generic name. E.g.
806
+ * the method name `textureDimensions` matches the WGSL name but must be
807
+ * resolved to `textureSize` in GLSL.
808
+ *
809
+ * @abstract
810
+ * @param {String} method - The method name to resolve.
811
+ * @return {String} The resolved method name.
812
+ */
401
813
  getMethod( method ) {
402
814
 
403
815
  return method;
404
816
 
405
817
  }
406
818
 
819
+ /**
820
+ * Returns a node for the given hash, see {@link NodeBuilder#setHashNode}.
821
+ *
822
+ * @param {Number} hash - The hash of the node.
823
+ * @return {Node} The found node.
824
+ */
407
825
  getNodeFromHash( hash ) {
408
826
 
409
827
  return this.hashNodes[ hash ];
410
828
 
411
829
  }
412
830
 
831
+ /**
832
+ * Adds the Node to a target flow so that it can generate code in the 'generate' process.
833
+ *
834
+ * @param {('vertex'|'fragment'|'compute')} shaderStage - The shader stage.
835
+ * @param {Node} node - The node to add.
836
+ * @return {Node} The node.
837
+ */
413
838
  addFlow( shaderStage, node ) {
414
839
 
415
840
  this.flowNodes[ shaderStage ].push( node );
@@ -418,18 +843,34 @@ class NodeBuilder {
418
843
 
419
844
  }
420
845
 
846
+ /**
847
+ * Sets builder's context.
848
+ *
849
+ * @param {Object} context - The context to set.
850
+ */
421
851
  setContext( context ) {
422
852
 
423
853
  this.context = context;
424
854
 
425
855
  }
426
856
 
857
+ /**
858
+ * Returns the builder's current context.
859
+ *
860
+ * @return {Object} The builder's current context.
861
+ */
427
862
  getContext() {
428
863
 
429
864
  return this.context;
430
865
 
431
866
  }
432
867
 
868
+ /**
869
+ * Gets a context used in shader construction that can be shared across different materials.
870
+ * This is necessary since the renderer cache can reuse shaders generated in one material and use them in another.
871
+ *
872
+ * @return {Object} The builder's current context without material.
873
+ */
433
874
  getSharedContext() {
434
875
 
435
876
  const context = { ...this.context };
@@ -440,18 +881,35 @@ class NodeBuilder {
440
881
 
441
882
  }
442
883
 
884
+ /**
885
+ * Sets builder's cache.
886
+ *
887
+ * @param {NodeCache} cache - The cache to set.
888
+ */
443
889
  setCache( cache ) {
444
890
 
445
891
  this.cache = cache;
446
892
 
447
893
  }
448
894
 
895
+ /**
896
+ * Returns the builder's current cache.
897
+ *
898
+ * @return {NodeCache} The builder's current cache.
899
+ */
449
900
  getCache() {
450
901
 
451
902
  return this.cache;
452
903
 
453
904
  }
454
905
 
906
+ /**
907
+ * Returns a cache for the given node.
908
+ *
909
+ * @param {Node} node - The node.
910
+ * @param {Boolean} [parent=true] - Whether this node refers to a shared parent cache or not.
911
+ * @return {NodeCache} The cache.
912
+ */
455
913
  getCacheFromNode( node, parent = true ) {
456
914
 
457
915
  const data = this.getDataFromNode( node );
@@ -461,48 +919,99 @@ class NodeBuilder {
461
919
 
462
920
  }
463
921
 
922
+ /**
923
+ * Whether the requested feature is available or not.
924
+ *
925
+ * @abstract
926
+ * @param {String} name - The requested feature.
927
+ * @return {Boolean} Whether the requested feature is supported or not.
928
+ */
464
929
  isAvailable( /*name*/ ) {
465
930
 
466
931
  return false;
467
932
 
468
933
  }
469
934
 
935
+ /**
936
+ * Returns the vertexIndex input variable as a native shader string.
937
+ *
938
+ * @abstract
939
+ * @return {String} The instanceIndex shader string.
940
+ */
470
941
  getVertexIndex() {
471
942
 
472
943
  console.warn( 'Abstract function.' );
473
944
 
474
945
  }
475
946
 
947
+ /**
948
+ * Returns the instanceIndex input variable as a native shader string.
949
+ *
950
+ * @abstract
951
+ * @return {String} The instanceIndex shader string.
952
+ */
476
953
  getInstanceIndex() {
477
954
 
478
955
  console.warn( 'Abstract function.' );
479
956
 
480
957
  }
481
958
 
959
+ /**
960
+ * Returns the drawIndex input variable as a native shader string.
961
+ * Only relevant for WebGL and its `WEBGL_multi_draw` extension.
962
+ *
963
+ * @abstract
964
+ * @return {String} The drawIndex shader string.
965
+ */
482
966
  getDrawIndex() {
483
967
 
484
968
  console.warn( 'Abstract function.' );
485
969
 
486
970
  }
487
971
 
972
+ /**
973
+ * Returns the frontFacing input variable as a native shader string.
974
+ *
975
+ * @abstract
976
+ * @return {String} The frontFacing shader string.
977
+ */
488
978
  getFrontFacing() {
489
979
 
490
980
  console.warn( 'Abstract function.' );
491
981
 
492
982
  }
493
983
 
984
+ /**
985
+ * Returns the fragCoord input variable as a native shader string.
986
+ *
987
+ * @abstract
988
+ * @return {String} The fragCoord shader string.
989
+ */
494
990
  getFragCoord() {
495
991
 
496
992
  console.warn( 'Abstract function.' );
497
993
 
498
994
  }
499
995
 
996
+ /**
997
+ * Whether to flip texture data along its vertical axis or not. WebGL needs
998
+ * this method evaluate to `true`, WebGPU to `false`.
999
+ *
1000
+ * @abstract
1001
+ * @return {Boolean} Whether to flip texture data along its vertical axis or not.
1002
+ */
500
1003
  isFlipY() {
501
1004
 
502
1005
  return false;
503
1006
 
504
1007
  }
505
1008
 
1009
+ /**
1010
+ * Calling this method increases the usage count for the given node by one.
1011
+ *
1012
+ * @param {Node} node - The node to increase the usage count for.
1013
+ * @return {Number} The updated usage count.
1014
+ */
506
1015
  increaseUsage( node ) {
507
1016
 
508
1017
  const nodeData = this.getDataFromNode( node );
@@ -512,18 +1021,127 @@ class NodeBuilder {
512
1021
 
513
1022
  }
514
1023
 
1024
+ /**
1025
+ * Generates a texture sample shader string for the given texture data.
1026
+ *
1027
+ * @abstract
1028
+ * @param {Texture} texture - The texture.
1029
+ * @param {String} textureProperty - The texture property name.
1030
+ * @param {String} uvSnippet - Snippet defining the texture coordinates.
1031
+ * @return {String} The generated shader string.
1032
+ */
515
1033
  generateTexture( /* texture, textureProperty, uvSnippet */ ) {
516
1034
 
517
1035
  console.warn( 'Abstract function.' );
518
1036
 
519
1037
  }
520
1038
 
521
- generateTextureLod( /* texture, textureProperty, uvSnippet, levelSnippet */ ) {
1039
+ /**
1040
+ * Generates a texture LOD shader string for the given texture data.
1041
+ *
1042
+ * @abstract
1043
+ * @param {Texture} texture - The texture.
1044
+ * @param {String} textureProperty - The texture property name.
1045
+ * @param {String} uvSnippet - Snippet defining the texture coordinates.
1046
+ * @param {String?} depthSnippet - Snippet defining the 0-based texture array index to sample.
1047
+ * @param {String} levelSnippet - Snippet defining the mip level.
1048
+ * @return {String} The generated shader string.
1049
+ */
1050
+ generateTextureLod( /* texture, textureProperty, uvSnippet, depthSnippet, levelSnippet */ ) {
522
1051
 
523
1052
  console.warn( 'Abstract function.' );
524
1053
 
525
1054
  }
526
1055
 
1056
+ /**
1057
+ * Generates the array declaration string.
1058
+ *
1059
+ * @param {String} type - The type.
1060
+ * @param {Number?} [count] - The count.
1061
+ * @return {String} The generated value as a shader string.
1062
+ */
1063
+ generateArrayDeclaration( type, count ) {
1064
+
1065
+ return this.getType( type ) + '[ ' + count + ' ]';
1066
+
1067
+ }
1068
+
1069
+ /**
1070
+ * Generates the array shader string for the given type and value.
1071
+ *
1072
+ * @param {String} type - The type.
1073
+ * @param {Number?} [count] - The count.
1074
+ * @param {Array<Node>?} [values=null] - The default values.
1075
+ * @return {String} The generated value as a shader string.
1076
+ */
1077
+ generateArray( type, count, values = null ) {
1078
+
1079
+ let snippet = this.generateArrayDeclaration( type, count ) + '( ';
1080
+
1081
+ for ( let i = 0; i < count; i ++ ) {
1082
+
1083
+ const value = values ? values[ i ] : null;
1084
+
1085
+ if ( value !== null ) {
1086
+
1087
+ snippet += value.build( this, type );
1088
+
1089
+ } else {
1090
+
1091
+ snippet += this.generateConst( type );
1092
+
1093
+ }
1094
+
1095
+ if ( i < count - 1 ) snippet += ', ';
1096
+
1097
+ }
1098
+
1099
+ snippet += ' )';
1100
+
1101
+ return snippet;
1102
+
1103
+ }
1104
+
1105
+ /**
1106
+ * Generates the struct shader string.
1107
+ *
1108
+ * @param {String} type - The type.
1109
+ * @param {Array<Object>} [membersLayout] - The count.
1110
+ * @param {Array<Node>?} [values=null] - The default values.
1111
+ * @return {String} The generated value as a shader string.
1112
+ */
1113
+ generateStruct( type, membersLayout, values = null ) {
1114
+
1115
+ const snippets = [];
1116
+
1117
+ for ( const member of membersLayout ) {
1118
+
1119
+ const { name, type } = member;
1120
+
1121
+ if ( values && values[ name ] && values[ name ].isNode ) {
1122
+
1123
+ snippets.push( values[ name ].build( this, type ) );
1124
+
1125
+ } else {
1126
+
1127
+ snippets.push( this.generateConst( type ) );
1128
+
1129
+ }
1130
+
1131
+ }
1132
+
1133
+ return type + '( ' + snippets.join( ', ' ) + ' )';
1134
+
1135
+ }
1136
+
1137
+
1138
+ /**
1139
+ * Generates the shader string for the given type and value.
1140
+ *
1141
+ * @param {String} type - The type.
1142
+ * @param {Any?} [value=null] - The value.
1143
+ * @return {String} The generated value as a shader string.
1144
+ */
527
1145
  generateConst( type, value = null ) {
528
1146
 
529
1147
  if ( value === null ) {
@@ -575,6 +1193,13 @@ class NodeBuilder {
575
1193
 
576
1194
  }
577
1195
 
1196
+ /**
1197
+ * It might be necessary to convert certain data types to different ones
1198
+ * so this method can be used to hide the conversion.
1199
+ *
1200
+ * @param {String} type - The type.
1201
+ * @return {String} The updated type.
1202
+ */
578
1203
  getType( type ) {
579
1204
 
580
1205
  if ( type === 'color' ) return 'vec3';
@@ -583,12 +1208,25 @@ class NodeBuilder {
583
1208
 
584
1209
  }
585
1210
 
1211
+ /**
1212
+ * Whether the given attribute name is defined in the geometry or not.
1213
+ *
1214
+ * @param {String} name - The attribute name.
1215
+ * @return {Boolean} Whether the given attribute name is defined in the geometry.
1216
+ */
586
1217
  hasGeometryAttribute( name ) {
587
1218
 
588
1219
  return this.geometry && this.geometry.getAttribute( name ) !== undefined;
589
1220
 
590
1221
  }
591
1222
 
1223
+ /**
1224
+ * Returns a node attribute for the given name and type.
1225
+ *
1226
+ * @param {String} name - The attribute's name.
1227
+ * @param {String} type - The attribute's type.
1228
+ * @return {NodeAttribute} The node attribute.
1229
+ */
592
1230
  getAttribute( name, type ) {
593
1231
 
594
1232
  const attributes = this.attributes;
@@ -615,36 +1253,74 @@ class NodeBuilder {
615
1253
 
616
1254
  }
617
1255
 
1256
+ /**
1257
+ * Returns for the given node and shader stage the property name for the shader.
1258
+ *
1259
+ * @param {Node} node - The node.
1260
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
1261
+ * @return {String} The property name.
1262
+ */
618
1263
  getPropertyName( node/*, shaderStage*/ ) {
619
1264
 
620
1265
  return node.name;
621
1266
 
622
1267
  }
623
1268
 
1269
+ /**
1270
+ * Whether the given type is a vector type or not.
1271
+ *
1272
+ * @param {String} type - The type to check.
1273
+ * @return {Boolean} Whether the given type is a vector type or not.
1274
+ */
624
1275
  isVector( type ) {
625
1276
 
626
1277
  return /vec\d/.test( type );
627
1278
 
628
1279
  }
629
1280
 
1281
+ /**
1282
+ * Whether the given type is a matrix type or not.
1283
+ *
1284
+ * @param {String} type - The type to check.
1285
+ * @return {Boolean} Whether the given type is a matrix type or not.
1286
+ */
630
1287
  isMatrix( type ) {
631
1288
 
632
1289
  return /mat\d/.test( type );
633
1290
 
634
1291
  }
635
1292
 
1293
+ /**
1294
+ * Whether the given type is a reference type or not.
1295
+ *
1296
+ * @param {String} type - The type to check.
1297
+ * @return {Boolean} Whether the given type is a reference type or not.
1298
+ */
636
1299
  isReference( type ) {
637
1300
 
638
1301
  return type === 'void' || type === 'property' || type === 'sampler' || type === 'texture' || type === 'cubeTexture' || type === 'storageTexture' || type === 'depthTexture' || type === 'texture3D';
639
1302
 
640
1303
  }
641
1304
 
1305
+ /**
1306
+ * Checks if the given texture requires a manual conversion to the working color space.
1307
+ *
1308
+ * @abstract
1309
+ * @param {Texture} texture - The texture to check.
1310
+ * @return {Boolean} Whether the given texture requires a conversion to working color space or not.
1311
+ */
642
1312
  needsToWorkingColorSpace( /*texture*/ ) {
643
1313
 
644
1314
  return false;
645
1315
 
646
1316
  }
647
1317
 
1318
+ /**
1319
+ * Returns the component type of a given texture.
1320
+ *
1321
+ * @param {Texture} texture - The texture.
1322
+ * @return {String} The component type.
1323
+ */
648
1324
  getComponentTypeFromTexture( texture ) {
649
1325
 
650
1326
  const type = texture.type;
@@ -660,6 +1336,12 @@ class NodeBuilder {
660
1336
 
661
1337
  }
662
1338
 
1339
+ /**
1340
+ * Returns the element type for a given type.
1341
+ *
1342
+ * @param {String} type - The type.
1343
+ * @return {String} The element type.
1344
+ */
663
1345
  getElementType( type ) {
664
1346
 
665
1347
  if ( type === 'mat2' ) return 'vec2';
@@ -670,6 +1352,12 @@ class NodeBuilder {
670
1352
 
671
1353
  }
672
1354
 
1355
+ /**
1356
+ * Returns the component type for a given type.
1357
+ *
1358
+ * @param {String} type - The type.
1359
+ * @return {String} The component type.
1360
+ */
673
1361
  getComponentType( type ) {
674
1362
 
675
1363
  type = this.getVectorType( type );
@@ -688,6 +1376,12 @@ class NodeBuilder {
688
1376
 
689
1377
  }
690
1378
 
1379
+ /**
1380
+ * Returns the vector type for a given type.
1381
+ *
1382
+ * @param {String} type - The type.
1383
+ * @return {String} The vector type.
1384
+ */
691
1385
  getVectorType( type ) {
692
1386
 
693
1387
  if ( type === 'color' ) return 'vec3';
@@ -697,23 +1391,49 @@ class NodeBuilder {
697
1391
 
698
1392
  }
699
1393
 
1394
+ /**
1395
+ * Returns the data type for the given the length and component type.
1396
+ *
1397
+ * @param {Number} length - The length.
1398
+ * @param {String} [componentType='float'] - The component type.
1399
+ * @return {String} The type.
1400
+ */
700
1401
  getTypeFromLength( length, componentType = 'float' ) {
701
1402
 
702
1403
  if ( length === 1 ) return componentType;
703
1404
 
704
- const baseType = getTypeFromLength( length );
1405
+ let baseType = getTypeFromLength( length );
705
1406
  const prefix = componentType === 'float' ? '' : componentType[ 0 ];
706
1407
 
1408
+ // fix edge case for mat2x2 being same size as vec4
1409
+ if ( /mat2/.test( componentType ) === true ) {
1410
+
1411
+ baseType = baseType.replace( 'vec', 'mat' );
1412
+
1413
+ }
1414
+
707
1415
  return prefix + baseType;
708
1416
 
709
1417
  }
710
1418
 
1419
+ /**
1420
+ * Returns the type for a given typed array.
1421
+ *
1422
+ * @param {TypedArray} array - The typed array.
1423
+ * @return {String} The type.
1424
+ */
711
1425
  getTypeFromArray( array ) {
712
1426
 
713
1427
  return typeFromArray.get( array.constructor );
714
1428
 
715
1429
  }
716
1430
 
1431
+ /**
1432
+ * Returns the type for a given buffer attribute.
1433
+ *
1434
+ * @param {BufferAttribute} attribute - The buffer attribute.
1435
+ * @return {String} The type.
1436
+ */
717
1437
  getTypeFromAttribute( attribute ) {
718
1438
 
719
1439
  let dataAttribute = attribute;
@@ -736,6 +1456,12 @@ class NodeBuilder {
736
1456
 
737
1457
  }
738
1458
 
1459
+ /**
1460
+ * Returns the length for the given data type.
1461
+ *
1462
+ * @param {String} type - The data type.
1463
+ * @return {Number} The length.
1464
+ */
739
1465
  getTypeLength( type ) {
740
1466
 
741
1467
  const vecType = this.getVectorType( type );
@@ -751,18 +1477,39 @@ class NodeBuilder {
751
1477
 
752
1478
  }
753
1479
 
1480
+ /**
1481
+ * Returns the vector type for a given matrix type.
1482
+ *
1483
+ * @param {String} type - The matrix type.
1484
+ * @return {String} The vector type.
1485
+ */
754
1486
  getVectorFromMatrix( type ) {
755
1487
 
756
1488
  return type.replace( 'mat', 'vec' );
757
1489
 
758
1490
  }
759
1491
 
1492
+ /**
1493
+ * For a given type this method changes the component type to the
1494
+ * given value. E.g. `vec4` should be changed to the new component type
1495
+ * `uint` which results in `uvec4`.
1496
+ *
1497
+ * @param {String} type - The type.
1498
+ * @param {String} newComponentType - The new component type.
1499
+ * @return {String} The new type.
1500
+ */
760
1501
  changeComponentType( type, newComponentType ) {
761
1502
 
762
1503
  return this.getTypeFromLength( this.getTypeLength( type ), newComponentType );
763
1504
 
764
1505
  }
765
1506
 
1507
+ /**
1508
+ * Returns the integer type pendant for the given type.
1509
+ *
1510
+ * @param {String} type - The type.
1511
+ * @return {String} The integer type.
1512
+ */
766
1513
  getIntegerType( type ) {
767
1514
 
768
1515
  const componentType = this.getComponentType( type );
@@ -773,6 +1520,11 @@ class NodeBuilder {
773
1520
 
774
1521
  }
775
1522
 
1523
+ /**
1524
+ * Adds a stack node to the internal stack.
1525
+ *
1526
+ * @return {StackNode} The added stack node.
1527
+ */
776
1528
  addStack() {
777
1529
 
778
1530
  this.stack = stack( this.stack );
@@ -784,6 +1536,11 @@ class NodeBuilder {
784
1536
 
785
1537
  }
786
1538
 
1539
+ /**
1540
+ * Removes the last stack node from the internal stack.
1541
+ *
1542
+ * @return {StackNode} The removed stack node.
1543
+ */
787
1544
  removeStack() {
788
1545
 
789
1546
  const lastStack = this.stack;
@@ -795,6 +1552,15 @@ class NodeBuilder {
795
1552
 
796
1553
  }
797
1554
 
1555
+ /**
1556
+ * The builder maintains (cached) data for each node during the building process. This method
1557
+ * can be used to get these data for a specific shader stage and cache.
1558
+ *
1559
+ * @param {Node} node - The node to get the data for.
1560
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
1561
+ * @param {NodeCache?} cache - An optional cache.
1562
+ * @return {Object} The node data.
1563
+ */
798
1564
  getDataFromNode( node, shaderStage = this.shaderStage, cache = null ) {
799
1565
 
800
1566
  cache = cache === null ? ( node.isGlobal( this ) ? this.globalCache : this.cache ) : cache;
@@ -815,6 +1581,13 @@ class NodeBuilder {
815
1581
 
816
1582
  }
817
1583
 
1584
+ /**
1585
+ * Returns the properties for the given node and shader stage.
1586
+ *
1587
+ * @param {Node} node - The node to get the properties for.
1588
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage='any'] - The shader stage.
1589
+ * @return {Object} The node properties.
1590
+ */
818
1591
  getNodeProperties( node, shaderStage = 'any' ) {
819
1592
 
820
1593
  const nodeData = this.getDataFromNode( node, shaderStage );
@@ -823,6 +1596,13 @@ class NodeBuilder {
823
1596
 
824
1597
  }
825
1598
 
1599
+ /**
1600
+ * Returns an instance of {@link NodeAttribute} for the given buffer attribute node.
1601
+ *
1602
+ * @param {BufferAttributeNode} node - The buffer attribute node.
1603
+ * @param {String} type - The node type.
1604
+ * @return {NodeAttribute} The node attribute.
1605
+ */
826
1606
  getBufferAttributeFromNode( node, type ) {
827
1607
 
828
1608
  const nodeData = this.getDataFromNode( node );
@@ -845,25 +1625,64 @@ class NodeBuilder {
845
1625
 
846
1626
  }
847
1627
 
848
- getStructTypeFromNode( node, shaderStage = this.shaderStage ) {
1628
+ /**
1629
+ * Returns an instance of {@link StructType} for the given output struct node.
1630
+ *
1631
+ * @param {OutputStructNode} node - The output struct node.
1632
+ * @param {Array<Object>} membersLayout - The output struct types.
1633
+ * @param {String?} [name=null] - The name of the struct.
1634
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
1635
+ * @return {StructType} The struct type attribute.
1636
+ */
1637
+ getStructTypeFromNode( node, membersLayout, name = null, shaderStage = this.shaderStage ) {
849
1638
 
850
1639
  const nodeData = this.getDataFromNode( node, shaderStage );
851
1640
 
852
- if ( nodeData.structType === undefined ) {
1641
+ let structType = nodeData.structType;
1642
+
1643
+ if ( structType === undefined ) {
853
1644
 
854
1645
  const index = this.structs.index ++;
855
1646
 
856
- node.name = `StructType${ index }`;
857
- this.structs[ shaderStage ].push( node );
1647
+ if ( name === null ) name = 'StructType' + index;
1648
+
1649
+ structType = new StructType( name, membersLayout );
1650
+
1651
+ this.structs[ shaderStage ].push( structType );
858
1652
 
859
- nodeData.structType = node;
1653
+ nodeData.structType = structType;
860
1654
 
861
1655
  }
862
1656
 
863
- return node;
1657
+ return structType;
864
1658
 
865
1659
  }
866
1660
 
1661
+ /**
1662
+ * Returns an instance of {@link StructType} for the given output struct node.
1663
+ *
1664
+ * @param {OutputStructNode} node - The output struct node.
1665
+ * @param {Array<Object>} membersLayout - The output struct types.
1666
+ * @return {StructType} The struct type attribute.
1667
+ */
1668
+ getOutputStructTypeFromNode( node, membersLayout ) {
1669
+
1670
+ const structType = this.getStructTypeFromNode( node, membersLayout, 'OutputType', 'fragment' );
1671
+ structType.output = true;
1672
+
1673
+ return structType;
1674
+
1675
+ }
1676
+
1677
+ /**
1678
+ * Returns an instance of {@link NodeUniform} for the given uniform node.
1679
+ *
1680
+ * @param {UniformNode} node - The uniform node.
1681
+ * @param {String} type - The uniform type.
1682
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
1683
+ * @param {String?} name - The name of the uniform.
1684
+ * @return {NodeUniform} The node uniform.
1685
+ */
867
1686
  getUniformFromNode( node, type, shaderStage = this.shaderStage, name = null ) {
868
1687
 
869
1688
  const nodeData = this.getDataFromNode( node, shaderStage, this.globalCache );
@@ -886,7 +1705,35 @@ class NodeBuilder {
886
1705
 
887
1706
  }
888
1707
 
889
- getVarFromNode( node, name = null, type = node.getNodeType( this ), shaderStage = this.shaderStage ) {
1708
+ /**
1709
+ * Returns the array length.
1710
+ *
1711
+ * @param {Node} node - The node.
1712
+ * @return {Number?} The array length.
1713
+ */
1714
+ getArrayCount( node ) {
1715
+
1716
+ let count = null;
1717
+
1718
+ if ( node.isArrayNode ) count = node.count;
1719
+ else if ( node.isVarNode && node.node.isArrayNode ) count = node.node.count;
1720
+
1721
+ return count;
1722
+
1723
+ }
1724
+
1725
+ /**
1726
+ * Returns an instance of {@link NodeVar} for the given variable node.
1727
+ *
1728
+ * @param {VarNode} node - The variable node.
1729
+ * @param {String?} name - The variable's name.
1730
+ * @param {String} [type=node.getNodeType( this )] - The variable's type.
1731
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
1732
+ * @param {Boolean} [readOnly=false] - Whether the variable is read-only or not.
1733
+ *
1734
+ * @return {NodeVar} The node variable.
1735
+ */
1736
+ getVarFromNode( node, name = null, type = node.getNodeType( this ), shaderStage = this.shaderStage, readOnly = false ) {
890
1737
 
891
1738
  const nodeData = this.getDataFromNode( node, shaderStage );
892
1739
 
@@ -894,13 +1741,30 @@ class NodeBuilder {
894
1741
 
895
1742
  if ( nodeVar === undefined ) {
896
1743
 
1744
+ const idNS = readOnly ? '_const' : '_var';
1745
+
897
1746
  const vars = this.vars[ shaderStage ] || ( this.vars[ shaderStage ] = [] );
1747
+ const id = this.vars[ idNS ] || ( this.vars[ idNS ] = 0 );
1748
+
1749
+ if ( name === null ) {
1750
+
1751
+ name = ( readOnly ? 'nodeConst' : 'nodeVar' ) + id;
1752
+
1753
+ this.vars[ idNS ] ++;
1754
+
1755
+ }
898
1756
 
899
- if ( name === null ) name = 'nodeVar' + vars.length;
1757
+ //
900
1758
 
901
- nodeVar = new NodeVar( name, type );
1759
+ const count = this.getArrayCount( node );
902
1760
 
903
- vars.push( nodeVar );
1761
+ nodeVar = new NodeVar( name, type, readOnly, count );
1762
+
1763
+ if ( ! readOnly ) {
1764
+
1765
+ vars.push( nodeVar );
1766
+
1767
+ }
904
1768
 
905
1769
  nodeData.variable = nodeVar;
906
1770
 
@@ -910,6 +1774,61 @@ class NodeBuilder {
910
1774
 
911
1775
  }
912
1776
 
1777
+ /**
1778
+ * Returns whether a Node or its flow is deterministic, useful for use in `const`.
1779
+ *
1780
+ * @param {Node} node - The varying node.
1781
+ * @return {Boolean} Returns true if deterministic.
1782
+ */
1783
+ isDeterministic( node ) {
1784
+
1785
+ if ( node.isMathNode ) {
1786
+
1787
+ return this.isDeterministic( node.aNode ) &&
1788
+ ( node.bNode ? this.isDeterministic( node.bNode ) : true ) &&
1789
+ ( node.cNode ? this.isDeterministic( node.cNode ) : true );
1790
+
1791
+ } else if ( node.isOperatorNode ) {
1792
+
1793
+ return this.isDeterministic( node.aNode ) &&
1794
+ ( node.bNode ? this.isDeterministic( node.bNode ) : true );
1795
+
1796
+ } else if ( node.isArrayNode ) {
1797
+
1798
+ if ( node.values !== null ) {
1799
+
1800
+ for ( const n of node.values ) {
1801
+
1802
+ if ( ! this.isDeterministic( n ) ) {
1803
+
1804
+ return false;
1805
+
1806
+ }
1807
+
1808
+ }
1809
+
1810
+ }
1811
+
1812
+ return true;
1813
+
1814
+ } else if ( node.isConstNode ) {
1815
+
1816
+ return true;
1817
+
1818
+ }
1819
+
1820
+ return false;
1821
+
1822
+ }
1823
+
1824
+ /**
1825
+ * Returns an instance of {@link NodeVarying} for the given varying node.
1826
+ *
1827
+ * @param {(VaryingNode|PropertyNode)} node - The varying node.
1828
+ * @param {String?} name - The varying's name.
1829
+ * @param {String} [type=node.getNodeType( this )] - The varying's type.
1830
+ * @return {NodeVar} The node varying.
1831
+ */
913
1832
  getVaryingFromNode( node, name = null, type = node.getNodeType( this ) ) {
914
1833
 
915
1834
  const nodeData = this.getDataFromNode( node, 'any' );
@@ -935,6 +1854,14 @@ class NodeBuilder {
935
1854
 
936
1855
  }
937
1856
 
1857
+ /**
1858
+ * Returns an instance of {@link NodeCode} for the given code node.
1859
+ *
1860
+ * @param {CodeNode} node - The code node.
1861
+ * @param {String} type - The node type.
1862
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
1863
+ * @return {NodeCode} The node code.
1864
+ */
938
1865
  getCodeFromNode( node, type, shaderStage = this.shaderStage ) {
939
1866
 
940
1867
  const nodeData = this.getDataFromNode( node );
@@ -958,6 +1885,15 @@ class NodeBuilder {
958
1885
 
959
1886
  }
960
1887
 
1888
+ /**
1889
+ * Adds a code flow based on the code-block hierarchy.
1890
+
1891
+ * This is used so that code-blocks like If,Else create their variables locally if the Node
1892
+ * is only used inside one of these conditionals in the current shader stage.
1893
+ *
1894
+ * @param {Node} node - The node to add.
1895
+ * @param {Node} nodeBlock - Node-based code-block. Usually 'ConditionalNode'.
1896
+ */
961
1897
  addFlowCodeHierarchy( node, nodeBlock ) {
962
1898
 
963
1899
  const { flowCodes, flowCodeBlock } = this.getDataFromNode( node );
@@ -990,6 +1926,13 @@ class NodeBuilder {
990
1926
 
991
1927
  }
992
1928
 
1929
+ /**
1930
+ * Add a inline-code to the current flow code-block.
1931
+ *
1932
+ * @param {Node} node - The node to add.
1933
+ * @param {String} code - The code to add.
1934
+ * @param {Node} nodeBlock - Current ConditionalNode
1935
+ */
993
1936
  addLineFlowCodeBlock( node, code, nodeBlock ) {
994
1937
 
995
1938
  const nodeData = this.getDataFromNode( node );
@@ -1001,6 +1944,13 @@ class NodeBuilder {
1001
1944
 
1002
1945
  }
1003
1946
 
1947
+ /**
1948
+ * Add a inline-code to the current flow.
1949
+ *
1950
+ * @param {String} code - The code to add.
1951
+ * @param {Node?} [node= null] - Optional Node, can help the system understand if the Node is part of a code-block.
1952
+ * @return {NodeBuilder} A reference to this node builder.
1953
+ */
1004
1954
  addLineFlowCode( code, node = null ) {
1005
1955
 
1006
1956
  if ( code === '' ) return this;
@@ -1025,6 +1975,12 @@ class NodeBuilder {
1025
1975
 
1026
1976
  }
1027
1977
 
1978
+ /**
1979
+ * Adds a code to the current code flow.
1980
+ *
1981
+ * @param {String} code - Shader code.
1982
+ * @return {NodeBuilder} A reference to this node builder.
1983
+ */
1028
1984
  addFlowCode( code ) {
1029
1985
 
1030
1986
  this.flow.code += code;
@@ -1033,6 +1989,12 @@ class NodeBuilder {
1033
1989
 
1034
1990
  }
1035
1991
 
1992
+ /**
1993
+ * Add tab in the code that will be generated so that other snippets respect the current tabulation.
1994
+ * Typically used in codes with If,Else.
1995
+ *
1996
+ * @return {NodeBuilder} A reference to this node builder.
1997
+ */
1036
1998
  addFlowTab() {
1037
1999
 
1038
2000
  this.tab += '\t';
@@ -1041,6 +2003,11 @@ class NodeBuilder {
1041
2003
 
1042
2004
  }
1043
2005
 
2006
+ /**
2007
+ * Removes a tab.
2008
+ *
2009
+ * @return {NodeBuilder} A reference to this node builder.
2010
+ */
1044
2011
  removeFlowTab() {
1045
2012
 
1046
2013
  this.tab = this.tab.slice( 0, - 1 );
@@ -1049,12 +2016,25 @@ class NodeBuilder {
1049
2016
 
1050
2017
  }
1051
2018
 
2019
+ /**
2020
+ * Gets the current flow data based on a Node.
2021
+ *
2022
+ * @param {Node} node - Node that the flow was started.
2023
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2024
+ * @return {Object} The flow data.
2025
+ */
1052
2026
  getFlowData( node/*, shaderStage*/ ) {
1053
2027
 
1054
2028
  return this.flowsData.get( node );
1055
2029
 
1056
2030
  }
1057
2031
 
2032
+ /**
2033
+ * Executes the node flow based on a root node to generate the final shader code.
2034
+ *
2035
+ * @param {Node} node - The node to execute.
2036
+ * @return {Object} The code flow.
2037
+ */
1058
2038
  flowNode( node ) {
1059
2039
 
1060
2040
  const output = node.getNodeType( this );
@@ -1067,6 +2047,13 @@ class NodeBuilder {
1067
2047
 
1068
2048
  }
1069
2049
 
2050
+ /**
2051
+ * Returns the native shader operator name for a given generic name.
2052
+ * It is a similar type of method like {@link NodeBuilder#getMethod}.
2053
+ *
2054
+ * @param {ShaderNodeInternal} shaderNode - The shader node to build the function node with.
2055
+ * @return {FunctionNode} The build function node.
2056
+ */
1070
2057
  buildFunctionNode( shaderNode ) {
1071
2058
 
1072
2059
  const fn = new FunctionNode();
@@ -1083,6 +2070,12 @@ class NodeBuilder {
1083
2070
 
1084
2071
  }
1085
2072
 
2073
+ /**
2074
+ * Generates a code flow based on a TSL function: Fn().
2075
+ *
2076
+ * @param {ShaderNodeInternal} shaderNode - A function code will be generated based on the input.
2077
+ * @return {Object}
2078
+ */
1086
2079
  flowShaderNode( shaderNode ) {
1087
2080
 
1088
2081
  const layout = shaderNode.layout;
@@ -1121,6 +2114,13 @@ class NodeBuilder {
1121
2114
 
1122
2115
  }
1123
2116
 
2117
+ /**
2118
+ * Runs the node flow through all the steps of creation, 'setup', 'analyze', 'generate'.
2119
+ *
2120
+ * @param {Node} node - The node to execute.
2121
+ * @param {String?} output - Expected output type. For example 'vec3'.
2122
+ * @return {Object}
2123
+ */
1124
2124
  flowStagesNode( node, output = null ) {
1125
2125
 
1126
2126
  const previousFlow = this.flow;
@@ -1159,12 +2159,27 @@ class NodeBuilder {
1159
2159
 
1160
2160
  }
1161
2161
 
1162
- getFunctionOperator() {
2162
+ /**
2163
+ * Returns the native shader operator name for a given generic name.
2164
+ * It is a similar type of method like {@link NodeBuilder#getMethod}.
2165
+ *
2166
+ * @abstract
2167
+ * @param {String} op - The operator name to resolve.
2168
+ * @return {String} The resolved operator name.
2169
+ */
2170
+ getFunctionOperator( /* op */ ) {
1163
2171
 
1164
2172
  return null;
1165
2173
 
1166
2174
  }
1167
2175
 
2176
+ /**
2177
+ * Generates a code flow based on a child Node.
2178
+ *
2179
+ * @param {Node} node - The node to execute.
2180
+ * @param {String?} output - Expected output type. For example 'vec3'.
2181
+ * @return {Object} The code flow.
2182
+ */
1168
2183
  flowChildNode( node, output = null ) {
1169
2184
 
1170
2185
  const previousFlow = this.flow;
@@ -1183,6 +2198,18 @@ class NodeBuilder {
1183
2198
 
1184
2199
  }
1185
2200
 
2201
+ /**
2202
+ * Executes a flow of code in a different stage.
2203
+ *
2204
+ * Some nodes like `varying()` have the ability to compute code in vertex-stage and
2205
+ * return the value in fragment-stage even if it is being executed in an input fragment.
2206
+ *
2207
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2208
+ * @param {Node} node - The node to execute.
2209
+ * @param {String?} output - Expected output type. For example 'vec3'.
2210
+ * @param {String?} propertyName - The property name to assign the result.
2211
+ * @return {Object}
2212
+ */
1186
2213
  flowNodeFromShaderStage( shaderStage, node, output = null, propertyName = null ) {
1187
2214
 
1188
2215
  const previousShaderStage = this.shaderStage;
@@ -1205,30 +2232,63 @@ class NodeBuilder {
1205
2232
 
1206
2233
  }
1207
2234
 
2235
+ /**
2236
+ * Returns an array holding all node attributes of this node builder.
2237
+ *
2238
+ * @return {Array<NodeAttribute>} The node attributes of this builder.
2239
+ */
1208
2240
  getAttributesArray() {
1209
2241
 
1210
2242
  return this.attributes.concat( this.bufferAttributes );
1211
2243
 
1212
2244
  }
1213
2245
 
2246
+ /**
2247
+ * Returns the attribute definitions as a shader string for the given shader stage.
2248
+ *
2249
+ * @abstract
2250
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2251
+ * @return {String} The attribute code section.
2252
+ */
1214
2253
  getAttributes( /*shaderStage*/ ) {
1215
2254
 
1216
2255
  console.warn( 'Abstract function.' );
1217
2256
 
1218
2257
  }
1219
2258
 
2259
+ /**
2260
+ * Returns the varying definitions as a shader string for the given shader stage.
2261
+ *
2262
+ * @abstract
2263
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2264
+ * @return {String} The varying code section.
2265
+ */
1220
2266
  getVaryings( /*shaderStage*/ ) {
1221
2267
 
1222
2268
  console.warn( 'Abstract function.' );
1223
2269
 
1224
2270
  }
1225
2271
 
1226
- getVar( type, name ) {
2272
+ /**
2273
+ * Returns a single variable definition as a shader string for the given variable type and name.
2274
+ *
2275
+ * @param {String} type - The variable's type.
2276
+ * @param {String} name - The variable's name.
2277
+ * @param {Number?} [count=null] - The array length.
2278
+ * @return {String} The shader string.
2279
+ */
2280
+ getVar( type, name, count = null ) {
1227
2281
 
1228
- return `${ this.getType( type ) } ${ name }`;
2282
+ return `${ count !== null ? this.generateArrayDeclaration( type, count ) : this.getType( type ) } ${ name }`;
1229
2283
 
1230
2284
  }
1231
2285
 
2286
+ /**
2287
+ * Returns the variable definitions as a shader string for the given shader stage.
2288
+ *
2289
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2290
+ * @return {String} The variable code section.
2291
+ */
1232
2292
  getVars( shaderStage ) {
1233
2293
 
1234
2294
  let snippet = '';
@@ -1249,12 +2309,25 @@ class NodeBuilder {
1249
2309
 
1250
2310
  }
1251
2311
 
2312
+ /**
2313
+ * Returns the uniform definitions as a shader string for the given shader stage.
2314
+ *
2315
+ * @abstract
2316
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2317
+ * @return {String} The uniform code section.
2318
+ */
1252
2319
  getUniforms( /*shaderStage*/ ) {
1253
2320
 
1254
2321
  console.warn( 'Abstract function.' );
1255
2322
 
1256
2323
  }
1257
2324
 
2325
+ /**
2326
+ * Returns the native code definitions as a shader string for the given shader stage.
2327
+ *
2328
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2329
+ * @return {String} The native code section.
2330
+ */
1258
2331
  getCodes( shaderStage ) {
1259
2332
 
1260
2333
  const codes = this.codes[ shaderStage ];
@@ -1275,42 +2348,77 @@ class NodeBuilder {
1275
2348
 
1276
2349
  }
1277
2350
 
2351
+ /**
2352
+ * Returns the hash of this node builder.
2353
+ *
2354
+ * @return {String} The hash.
2355
+ */
1278
2356
  getHash() {
1279
2357
 
1280
2358
  return this.vertexShader + this.fragmentShader + this.computeShader;
1281
2359
 
1282
2360
  }
1283
2361
 
2362
+ /**
2363
+ * Sets the current shader stage.
2364
+ *
2365
+ * @param {('vertex'|'fragment'|'compute'|'any')?} shaderStage - The shader stage to set.
2366
+ */
1284
2367
  setShaderStage( shaderStage ) {
1285
2368
 
1286
2369
  this.shaderStage = shaderStage;
1287
2370
 
1288
2371
  }
1289
2372
 
2373
+ /**
2374
+ * Returns the current shader stage.
2375
+ *
2376
+ * @return {('vertex'|'fragment'|'compute'|'any')?} The current shader stage.
2377
+ */
1290
2378
  getShaderStage() {
1291
2379
 
1292
2380
  return this.shaderStage;
1293
2381
 
1294
2382
  }
1295
2383
 
2384
+ /**
2385
+ * Sets the current build stage.
2386
+ *
2387
+ * @param {('setup'|'analyze'|'generate')?} buildStage - The build stage to set.
2388
+ */
1296
2389
  setBuildStage( buildStage ) {
1297
2390
 
1298
2391
  this.buildStage = buildStage;
1299
2392
 
1300
2393
  }
1301
2394
 
2395
+ /**
2396
+ * Returns the current build stage.
2397
+ *
2398
+ * @return {('setup'|'analyze'|'generate')?} The current build stage.
2399
+ */
1302
2400
  getBuildStage() {
1303
2401
 
1304
2402
  return this.buildStage;
1305
2403
 
1306
2404
  }
1307
2405
 
2406
+ /**
2407
+ * Controls the code build of the shader stages.
2408
+ *
2409
+ * @abstract
2410
+ */
1308
2411
  buildCode() {
1309
2412
 
1310
2413
  console.warn( 'Abstract function.' );
1311
2414
 
1312
2415
  }
1313
2416
 
2417
+ /**
2418
+ * Central build method which controls the build for the given object.
2419
+ *
2420
+ * @return {NodeBuilder} A reference to this node builder.
2421
+ */
1314
2422
  build() {
1315
2423
 
1316
2424
  const { object, material, renderer } = this;
@@ -1385,6 +2493,13 @@ class NodeBuilder {
1385
2493
 
1386
2494
  }
1387
2495
 
2496
+ /**
2497
+ * Returns a uniform representation which is later used for UBO generation and rendering.
2498
+ *
2499
+ * @param {NodeUniform} uniformNode - The uniform node.
2500
+ * @param {String} type - The requested type.
2501
+ * @return {Uniform} The uniform.
2502
+ */
1388
2503
  getNodeUniform( uniformNode, type ) {
1389
2504
 
1390
2505
  if ( type === 'float' || type === 'int' || type === 'uint' ) return new NumberNodeUniform( uniformNode );
@@ -1392,6 +2507,7 @@ class NodeBuilder {
1392
2507
  if ( type === 'vec3' || type === 'ivec3' || type === 'uvec3' ) return new Vector3NodeUniform( uniformNode );
1393
2508
  if ( type === 'vec4' || type === 'ivec4' || type === 'uvec4' ) return new Vector4NodeUniform( uniformNode );
1394
2509
  if ( type === 'color' ) return new ColorNodeUniform( uniformNode );
2510
+ if ( type === 'mat2' ) return new Matrix2NodeUniform( uniformNode );
1395
2511
  if ( type === 'mat3' ) return new Matrix3NodeUniform( uniformNode );
1396
2512
  if ( type === 'mat4' ) return new Matrix4NodeUniform( uniformNode );
1397
2513
 
@@ -1399,12 +2515,16 @@ class NodeBuilder {
1399
2515
 
1400
2516
  }
1401
2517
 
1402
- createNodeMaterial( type = 'NodeMaterial' ) { // @deprecated, r168
1403
-
1404
- throw new Error( `THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${ type }() instead.` );
1405
-
1406
- }
1407
-
2518
+ /**
2519
+ * Formats the given shader snippet from a given type into another one. E.g.
2520
+ * this method might be used to convert a simple float string `"1.0"` into a
2521
+ * `vec3` representation: `"vec3<f32>( 1.0 )"`.
2522
+ *
2523
+ * @param {String} snippet - The shader snippet.
2524
+ * @param {String} fromType - The source type.
2525
+ * @param {String} toType - The target type.
2526
+ * @return {String} The updated shader string.
2527
+ */
1408
2528
  format( snippet, fromType, toType ) {
1409
2529
 
1410
2530
  fromType = this.getVectorType( fromType );
@@ -1485,12 +2605,32 @@ class NodeBuilder {
1485
2605
 
1486
2606
  }
1487
2607
 
2608
+ /**
2609
+ * Returns a signature with the engine's current revision.
2610
+ *
2611
+ * @return {String} The signature.
2612
+ */
1488
2613
  getSignature() {
1489
2614
 
1490
2615
  return `// Three.js r${ REVISION } - Node System\n`;
1491
2616
 
1492
2617
  }
1493
2618
 
2619
+ // Deprecated
2620
+
2621
+ /**
2622
+ * @function
2623
+ * @deprecated since r168. Use `new NodeMaterial()` instead, with targeted node material name.
2624
+ *
2625
+ * @param {String} [type='NodeMaterial'] - The node material type.
2626
+ * @throws {Error}
2627
+ */
2628
+ createNodeMaterial( type = 'NodeMaterial' ) { // @deprecated, r168
2629
+
2630
+ throw new Error( `THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${ type }() instead.` );
2631
+
2632
+ }
2633
+
1494
2634
  }
1495
2635
 
1496
2636
  export default NodeBuilder;