super-three 0.171.0 → 0.172.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 (413) hide show
  1. package/README.md +1 -1
  2. package/build/three.cjs +157 -49
  3. package/build/three.core.js +104 -42
  4. package/build/three.core.min.js +1 -1
  5. package/build/three.module.js +53 -8
  6. package/build/three.module.min.js +1 -1
  7. package/build/three.tsl.js +10 -5
  8. package/build/three.tsl.min.js +1 -1
  9. package/build/three.webgpu.js +21191 -1008
  10. package/build/three.webgpu.min.js +1 -1
  11. package/build/three.webgpu.nodes.js +21189 -1008
  12. package/build/three.webgpu.nodes.min.js +1 -1
  13. package/examples/jsm/Addons.js +0 -5
  14. package/examples/jsm/animation/CCDIKSolver.js +3 -2
  15. package/examples/jsm/controls/ArcballControls.js +28 -19
  16. package/examples/jsm/controls/OrbitControls.js +5 -4
  17. package/examples/jsm/csm/CSMShadowNode.js +16 -11
  18. package/examples/jsm/curves/NURBSCurve.js +1 -1
  19. package/examples/jsm/curves/NURBSUtils.js +3 -0
  20. package/examples/jsm/effects/OutlineEffect.js +1 -1
  21. package/examples/jsm/exporters/GLTFExporter.js +11 -7
  22. package/examples/jsm/exporters/KTX2Exporter.js +1 -1
  23. package/examples/jsm/exporters/PLYExporter.js +2 -2
  24. package/examples/jsm/helpers/TextureHelperGPU.js +15 -5
  25. package/examples/jsm/helpers/VertexNormalsHelper.js +2 -0
  26. package/examples/jsm/lights/LightProbeGenerator.js +3 -3
  27. package/examples/jsm/lines/webgpu/LineSegments2.js +15 -6
  28. package/examples/jsm/loaders/3MFLoader.js +6 -3
  29. package/examples/jsm/loaders/BVHLoader.js +1 -1
  30. package/examples/jsm/loaders/ColladaLoader.js +5 -5
  31. package/examples/jsm/loaders/DDSLoader.js +42 -0
  32. package/examples/jsm/loaders/GCodeLoader.js +1 -1
  33. package/examples/jsm/loaders/GLTFLoader.js +22 -2
  34. package/examples/jsm/loaders/KTX2Loader.js +6 -1
  35. package/examples/jsm/loaders/KTXLoader.js +4 -4
  36. package/examples/jsm/loaders/LDrawLoader.js +1 -1
  37. package/examples/jsm/loaders/LottieLoader.js +1 -1
  38. package/examples/jsm/loaders/MTLLoader.js +1 -0
  39. package/examples/jsm/loaders/NRRDLoader.js +1 -1
  40. package/examples/jsm/loaders/PLYLoader.js +7 -7
  41. package/examples/jsm/loaders/PVRLoader.js +1 -1
  42. package/examples/jsm/loaders/SVGLoader.js +2 -2
  43. package/examples/jsm/loaders/TDSLoader.js +1 -1
  44. package/examples/jsm/loaders/VRMLLoader.js +7 -7
  45. package/examples/jsm/loaders/lwo/IFFParser.js +4 -4
  46. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +1 -1
  47. package/examples/jsm/math/ConvexHull.js +1 -1
  48. package/examples/jsm/math/OBB.js +17 -0
  49. package/examples/jsm/misc/ProgressiveLightMapGPU.js +10 -10
  50. package/examples/jsm/misc/Volume.js +20 -12
  51. package/examples/jsm/misc/VolumeSlice.js +2 -2
  52. package/examples/jsm/modifiers/CurveModifier.js +10 -8
  53. package/examples/jsm/modifiers/CurveModifierGPU.js +9 -7
  54. package/examples/jsm/modifiers/SimplifyModifier.js +2 -2
  55. package/examples/jsm/objects/GroundedSkybox.js +4 -4
  56. package/examples/jsm/objects/Sky.js +2 -2
  57. package/examples/jsm/objects/SkyMesh.js +3 -3
  58. package/examples/jsm/objects/Water2.js +1 -1
  59. package/examples/jsm/objects/Water2Mesh.js +2 -2
  60. package/examples/jsm/objects/WaterMesh.js +4 -4
  61. package/examples/jsm/postprocessing/BloomPass.js +2 -2
  62. package/examples/jsm/postprocessing/EffectComposer.js +1 -2
  63. package/examples/jsm/postprocessing/OutlinePass.js +4 -4
  64. package/examples/jsm/postprocessing/SAOPass.js +1 -2
  65. package/examples/jsm/postprocessing/SMAAPass.js +1 -3
  66. package/examples/jsm/postprocessing/SSAOPass.js +2 -4
  67. package/examples/jsm/postprocessing/SSRPass.js +2 -4
  68. package/examples/jsm/postprocessing/UnrealBloomPass.js +2 -2
  69. package/examples/jsm/renderers/SVGRenderer.js +6 -4
  70. package/examples/jsm/shaders/BokehShader2.js +1 -1
  71. package/examples/jsm/shaders/GodRaysShader.js +3 -3
  72. package/examples/jsm/shaders/SobelOperatorShader.js +1 -1
  73. package/examples/jsm/tsl/display/AfterImageNode.js +93 -4
  74. package/examples/jsm/tsl/display/AnaglyphPassNode.js +46 -2
  75. package/examples/jsm/tsl/display/AnamorphicNode.js +118 -5
  76. package/examples/jsm/tsl/display/BleachBypass.js +10 -0
  77. package/examples/jsm/tsl/display/BloomNode.js +233 -26
  78. package/examples/jsm/tsl/display/DenoiseNode.js +141 -25
  79. package/examples/jsm/tsl/display/DepthOfFieldNode.js +80 -1
  80. package/examples/jsm/tsl/display/DotScreenNode.js +50 -5
  81. package/examples/jsm/tsl/display/FXAANode.js +52 -3
  82. package/examples/jsm/tsl/display/FilmNode.js +47 -1
  83. package/examples/jsm/tsl/display/GTAONode.js +210 -14
  84. package/examples/jsm/tsl/display/GaussianBlurNode.js +152 -8
  85. package/examples/jsm/tsl/display/LensflareNode.js +131 -13
  86. package/examples/jsm/tsl/display/Lut3DNode.js +55 -1
  87. package/examples/jsm/tsl/display/MotionBlur.js +12 -2
  88. package/examples/jsm/tsl/display/OutlineNode.js +343 -26
  89. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +36 -2
  90. package/examples/jsm/tsl/display/PixelationPassNode.js +142 -9
  91. package/examples/jsm/tsl/display/RGBShiftNode.js +49 -2
  92. package/examples/jsm/tsl/display/SMAANode.js +187 -46
  93. package/examples/jsm/tsl/display/SSAAPassNode.js +110 -25
  94. package/examples/jsm/tsl/display/SSRNode.js +194 -21
  95. package/examples/jsm/tsl/display/Sepia.js +9 -0
  96. package/examples/jsm/tsl/display/SobelOperatorNode.js +54 -4
  97. package/examples/jsm/tsl/display/StereoCompositePassNode.js +79 -3
  98. package/examples/jsm/tsl/display/StereoPassNode.js +41 -3
  99. package/examples/jsm/tsl/display/TRAAPassNode.js +116 -21
  100. package/examples/jsm/tsl/display/TransitionNode.js +71 -6
  101. package/examples/jsm/tsl/display/hashBlur.js +14 -3
  102. package/examples/jsm/tsl/lighting/TiledLightsNode.js +40 -34
  103. package/examples/jsm/utils/BufferGeometryUtils.js +1 -1
  104. package/examples/jsm/utils/CameraUtils.js +4 -1
  105. package/examples/jsm/utils/GeometryUtils.js +22 -19
  106. package/examples/jsm/utils/SceneUtils.js +2 -2
  107. package/examples/jsm/webxr/XRControllerModelFactory.js +6 -1
  108. package/examples/jsm/webxr/XREstimatedLight.js +1 -1
  109. package/package.json +8 -3
  110. package/src/Three.Core.js +2 -0
  111. package/src/Three.Legacy.js +0 -21
  112. package/src/Three.TSL.js +9 -4
  113. package/src/Three.WebGPU.Nodes.js +2 -2
  114. package/src/Three.WebGPU.js +2 -2
  115. package/src/animation/PropertyBinding.js +2 -2
  116. package/src/cameras/PerspectiveCamera.js +18 -2
  117. package/src/constants.js +1 -1
  118. package/src/core/RenderTarget.js +18 -0
  119. package/src/core/RenderTarget3D.js +22 -0
  120. package/src/core/RenderTargetArray.js +22 -0
  121. package/src/extras/Earcut.js +1 -1
  122. package/src/extras/PMREMGenerator.js +20 -0
  123. package/src/extras/TextureUtils.js +6 -0
  124. package/src/helpers/CameraHelper.js +16 -13
  125. package/src/loaders/nodes/NodeLoader.js +59 -0
  126. package/src/loaders/nodes/NodeMaterialLoader.js +45 -0
  127. package/src/loaders/nodes/NodeObjectLoader.js +61 -0
  128. package/src/materials/nodes/InstancedPointsNodeMaterial.js +72 -19
  129. package/src/materials/nodes/Line2NodeMaterial.js +128 -34
  130. package/src/materials/nodes/LineBasicNodeMaterial.js +17 -2
  131. package/src/materials/nodes/LineDashedNodeMaterial.js +78 -5
  132. package/src/materials/nodes/MeshBasicNodeMaterial.js +56 -0
  133. package/src/materials/nodes/MeshLambertNodeMaterial.js +35 -0
  134. package/src/materials/nodes/MeshMatcapNodeMaterial.js +22 -2
  135. package/src/materials/nodes/MeshNormalNodeMaterial.js +21 -2
  136. package/src/materials/nodes/MeshPhongNodeMaterial.js +64 -1
  137. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +269 -0
  138. package/src/materials/nodes/MeshSSSNodeMaterial.js +97 -6
  139. package/src/materials/nodes/MeshStandardNodeMaterial.js +78 -0
  140. package/src/materials/nodes/MeshToonNodeMaterial.js +28 -0
  141. package/src/materials/nodes/NodeMaterial.js +474 -21
  142. package/src/materials/nodes/PointsNodeMaterial.js +22 -13
  143. package/src/materials/nodes/ShadowNodeMaterial.js +29 -0
  144. package/src/materials/nodes/SpriteNodeMaterial.js +77 -19
  145. package/src/materials/nodes/VolumeNodeMaterial.js +80 -4
  146. package/src/materials/nodes/manager/NodeMaterialObserver.js +87 -0
  147. package/src/nodes/Nodes.js +1 -6
  148. package/src/nodes/TSL.js +2 -3
  149. package/src/nodes/accessors/AccessorsUtils.js +27 -0
  150. package/src/nodes/accessors/Arrays.js +24 -5
  151. package/src/nodes/accessors/BatchNode.js +39 -3
  152. package/src/nodes/accessors/Bitangent.js +37 -0
  153. package/src/nodes/accessors/BufferAttributeNode.js +178 -5
  154. package/src/nodes/accessors/BufferNode.js +63 -0
  155. package/src/nodes/accessors/BuiltinNode.js +38 -0
  156. package/src/nodes/accessors/Camera.js +49 -0
  157. package/src/nodes/accessors/ClippingNode.js +71 -2
  158. package/src/nodes/accessors/CubeTextureNode.js +64 -0
  159. package/src/nodes/accessors/InstanceNode.js +85 -2
  160. package/src/nodes/accessors/InstancedMeshNode.js +28 -3
  161. package/src/nodes/accessors/InstancedPointsMaterialNode.js +13 -0
  162. package/src/nodes/accessors/Lights.js +50 -1
  163. package/src/nodes/accessors/MaterialNode.js +302 -8
  164. package/src/nodes/accessors/MaterialProperties.js +7 -0
  165. package/src/nodes/accessors/MaterialReferenceNode.js +53 -13
  166. package/src/nodes/accessors/ModelNode.js +100 -5
  167. package/src/nodes/accessors/ModelViewProjectionNode.js +10 -38
  168. package/src/nodes/accessors/MorphNode.js +48 -4
  169. package/src/nodes/accessors/Normal.js +59 -3
  170. package/src/nodes/accessors/Object3DNode.js +102 -1
  171. package/src/nodes/accessors/PointUVNode.js +26 -0
  172. package/src/nodes/accessors/Position.js +53 -4
  173. package/src/nodes/accessors/ReferenceBaseNode.js +188 -0
  174. package/src/nodes/accessors/ReferenceNode.js +202 -2
  175. package/src/nodes/accessors/ReflectVector.js +24 -0
  176. package/src/nodes/accessors/RendererReferenceNode.js +46 -1
  177. package/src/nodes/accessors/SceneNode.js +54 -0
  178. package/src/nodes/accessors/SkinningNode.js +127 -1
  179. package/src/nodes/accessors/StorageBufferNode.js +168 -4
  180. package/src/nodes/accessors/StorageTextureNode.js +118 -0
  181. package/src/nodes/accessors/Tangent.js +36 -0
  182. package/src/nodes/accessors/Texture3DNode.js +89 -5
  183. package/src/nodes/accessors/TextureBicubic.js +12 -2
  184. package/src/nodes/accessors/TextureNode.js +309 -10
  185. package/src/nodes/accessors/TextureSizeNode.js +42 -0
  186. package/src/nodes/accessors/UV.js +10 -1
  187. package/src/nodes/accessors/UniformArrayNode.js +223 -23
  188. package/src/nodes/accessors/UserDataNode.js +46 -0
  189. package/src/nodes/accessors/VelocityNode.js +82 -0
  190. package/src/nodes/accessors/VertexColorNode.js +39 -2
  191. package/src/nodes/code/CodeNode.js +95 -1
  192. package/src/nodes/code/ExpressionNode.js +28 -0
  193. package/src/nodes/code/FunctionCallNode.js +37 -0
  194. package/src/nodes/code/FunctionNode.js +45 -0
  195. package/src/nodes/code/ScriptableNode.js +223 -1
  196. package/src/nodes/code/ScriptableValueNode.js +85 -1
  197. package/src/nodes/core/AssignNode.js +48 -2
  198. package/src/nodes/core/AttributeNode.js +43 -0
  199. package/src/nodes/core/BypassNode.js +47 -2
  200. package/src/nodes/core/CacheNode.js +53 -2
  201. package/src/nodes/core/ConstNode.js +24 -0
  202. package/src/nodes/core/ContextNode.js +65 -0
  203. package/src/nodes/core/IndexNode.js +68 -7
  204. package/src/nodes/core/InputNode.js +48 -0
  205. package/src/nodes/core/LightingModel.js +60 -0
  206. package/src/nodes/core/MRTNode.js +66 -0
  207. package/src/nodes/core/Node.js +337 -12
  208. package/src/nodes/core/NodeAttribute.js +38 -0
  209. package/src/nodes/core/NodeBuilder.js +945 -15
  210. package/src/nodes/core/NodeCache.js +41 -2
  211. package/src/nodes/core/NodeCode.js +31 -0
  212. package/src/nodes/core/NodeFrame.js +123 -2
  213. package/src/nodes/core/NodeFunction.js +46 -0
  214. package/src/nodes/core/NodeFunctionInput.js +44 -0
  215. package/src/nodes/core/NodeParser.js +11 -0
  216. package/src/nodes/core/NodeUniform.js +52 -0
  217. package/src/nodes/core/NodeUtils.js +141 -0
  218. package/src/nodes/core/NodeVar.js +30 -0
  219. package/src/nodes/core/NodeVarying.js +28 -0
  220. package/src/nodes/core/OutputStructNode.js +33 -2
  221. package/src/nodes/core/ParameterNode.js +28 -0
  222. package/src/nodes/core/PropertyNode.js +232 -0
  223. package/src/nodes/core/StackNode.js +78 -0
  224. package/src/nodes/core/StructTypeNode.js +39 -1
  225. package/src/nodes/core/TempNode.js +30 -4
  226. package/src/nodes/core/UniformGroupNode.js +82 -7
  227. package/src/nodes/core/UniformNode.js +66 -0
  228. package/src/nodes/core/VarNode.js +52 -0
  229. package/src/nodes/core/VaryingNode.js +83 -2
  230. package/src/nodes/core/constants.js +36 -0
  231. package/src/nodes/display/BumpMapNode.js +37 -0
  232. package/src/nodes/display/ColorAdjustment.js +53 -11
  233. package/src/nodes/display/ColorSpaceFunctions.js +16 -0
  234. package/src/nodes/display/ColorSpaceNode.js +82 -0
  235. package/src/nodes/display/FrontFacingNode.js +29 -0
  236. package/src/nodes/display/NormalMapNode.js +43 -0
  237. package/src/nodes/display/PassNode.js +298 -7
  238. package/src/nodes/display/PosterizeNode.js +33 -0
  239. package/src/nodes/display/RenderOutputNode.js +66 -1
  240. package/src/nodes/display/ScreenNode.js +87 -0
  241. package/src/nodes/display/ToneMappingFunctions.js +58 -10
  242. package/src/nodes/display/ToneMappingNode.js +55 -2
  243. package/src/nodes/display/ToonOutlinePassNode.js +73 -0
  244. package/src/nodes/display/ViewportDepthNode.js +122 -8
  245. package/src/nodes/display/ViewportDepthTextureNode.js +23 -0
  246. package/src/nodes/display/ViewportSharedTextureNode.js +23 -0
  247. package/src/nodes/display/ViewportTextureNode.js +57 -0
  248. package/src/nodes/fog/Fog.js +93 -0
  249. package/src/nodes/functions/BasicLightingModel.js +24 -0
  250. package/src/nodes/functions/PhongLightingModel.js +34 -2
  251. package/src/nodes/functions/PhysicalLightingModel.js +167 -8
  252. package/src/nodes/functions/ShadowMaskModel.js +23 -0
  253. package/src/nodes/functions/ToonLightingModel.js +20 -0
  254. package/src/nodes/functions/material/getAlphaHashThreshold.js +1 -3
  255. package/src/nodes/functions/material/getParallaxCorrectNormal.js +16 -1
  256. package/src/nodes/geometry/RangeNode.js +54 -2
  257. package/src/nodes/gpgpu/AtomicFunctionNode.js +157 -1
  258. package/src/nodes/gpgpu/BarrierNode.js +47 -0
  259. package/src/nodes/gpgpu/ComputeBuiltinNode.js +126 -0
  260. package/src/nodes/gpgpu/ComputeNode.js +106 -2
  261. package/src/nodes/gpgpu/WorkgroupInfoNode.js +115 -6
  262. package/src/nodes/lighting/AONode.js +18 -0
  263. package/src/nodes/lighting/AmbientLightNode.js +10 -0
  264. package/src/nodes/lighting/AnalyticLightNode.js +97 -2
  265. package/src/nodes/lighting/BasicEnvironmentNode.js +19 -0
  266. package/src/nodes/lighting/BasicLightMapNode.js +17 -0
  267. package/src/nodes/lighting/DirectionalLightNode.js +10 -0
  268. package/src/nodes/lighting/EnvironmentNode.js +18 -0
  269. package/src/nodes/lighting/HemisphereLightNode.js +31 -0
  270. package/src/nodes/lighting/IESSpotLightNode.js +11 -0
  271. package/src/nodes/lighting/IrradianceNode.js +17 -0
  272. package/src/nodes/lighting/LightProbeNode.js +20 -0
  273. package/src/nodes/lighting/LightUtils.js +12 -0
  274. package/src/nodes/lighting/LightingContextNode.js +48 -0
  275. package/src/nodes/lighting/LightingNode.js +15 -6
  276. package/src/nodes/lighting/LightsNode.js +132 -1
  277. package/src/nodes/lighting/PointLightNode.js +32 -1
  278. package/src/nodes/lighting/PointShadowNode.js +54 -1
  279. package/src/nodes/lighting/RectAreaLightNode.js +44 -6
  280. package/src/nodes/lighting/ShadowBaseNode.js +93 -0
  281. package/src/nodes/lighting/ShadowNode.js +240 -34
  282. package/src/nodes/lighting/SpotLightNode.js +43 -0
  283. package/src/nodes/math/ConditionalNode.js +70 -3
  284. package/src/nodes/math/Hash.js +9 -0
  285. package/src/nodes/math/MathNode.js +614 -11
  286. package/src/nodes/math/MathUtils.js +45 -1
  287. package/src/nodes/math/OperatorNode.js +233 -0
  288. package/src/nodes/math/TriNoise3D.js +18 -7
  289. package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
  290. package/src/nodes/parsers/GLSLNodeParser.js +11 -0
  291. package/src/nodes/pmrem/PMREMNode.js +133 -0
  292. package/src/nodes/pmrem/PMREMUtils.js +1 -1
  293. package/src/nodes/procedural/Checker.js +9 -0
  294. package/src/nodes/tsl/TSLBase.js +2 -2
  295. package/src/nodes/utils/ArrayElementNode.js +38 -2
  296. package/src/nodes/utils/ConvertNode.js +31 -0
  297. package/src/nodes/utils/CubeMapNode.js +78 -0
  298. package/src/nodes/utils/Discard.js +16 -0
  299. package/src/nodes/utils/EquirectUVNode.js +31 -1
  300. package/src/nodes/utils/FlipNode.js +38 -0
  301. package/src/nodes/utils/FunctionOverloadingNode.js +53 -1
  302. package/src/nodes/utils/JoinNode.js +25 -0
  303. package/src/nodes/utils/LoopNode.js +74 -1
  304. package/src/nodes/utils/MatcapUVNode.js +17 -0
  305. package/src/nodes/utils/MaxMipLevelNode.js +49 -0
  306. package/src/nodes/utils/Oscillators.js +33 -0
  307. package/src/nodes/utils/Packing.js +17 -0
  308. package/src/nodes/utils/PostProcessingUtils.js +28 -23
  309. package/src/nodes/utils/RTTNode.js +123 -2
  310. package/src/nodes/utils/ReflectorNode.js +174 -4
  311. package/src/nodes/utils/RemapNode.js +79 -0
  312. package/src/nodes/utils/RotateNode.js +41 -0
  313. package/src/nodes/utils/SetNode.js +44 -1
  314. package/src/nodes/utils/SplitNode.js +55 -3
  315. package/src/nodes/utils/SpriteSheetUVNode.js +46 -0
  316. package/src/nodes/utils/SpriteUtils.js +17 -0
  317. package/src/nodes/utils/StorageArrayElementNode.js +40 -0
  318. package/src/nodes/utils/Timer.js +19 -0
  319. package/src/nodes/utils/TriplanarTexturesNode.js +84 -0
  320. package/src/nodes/utils/UVUtils.js +20 -0
  321. package/src/nodes/utils/ViewportUtils.js +13 -0
  322. package/src/objects/BatchedMesh.js +1 -2
  323. package/src/objects/ClippingGroup.js +49 -0
  324. package/src/renderers/WebGLRenderer.js +23 -4
  325. package/src/renderers/common/Animation.js +63 -0
  326. package/src/renderers/common/Attributes.js +36 -0
  327. package/src/renderers/common/Backend.js +467 -52
  328. package/src/renderers/common/Background.js +34 -1
  329. package/src/renderers/common/BindGroup.js +43 -0
  330. package/src/renderers/common/Binding.js +35 -0
  331. package/src/renderers/common/Bindings.js +93 -1
  332. package/src/renderers/common/Buffer.js +49 -0
  333. package/src/renderers/common/BufferUtils.js +27 -0
  334. package/src/renderers/common/BundleGroup.js +57 -0
  335. package/src/renderers/common/ChainMap.js +38 -1
  336. package/src/renderers/common/ClippingContext.js +107 -14
  337. package/src/renderers/common/Color4.js +36 -0
  338. package/src/renderers/common/ComputePipeline.js +24 -0
  339. package/src/renderers/common/CubeRenderTarget.js +13 -0
  340. package/src/renderers/common/DataMap.js +37 -1
  341. package/src/renderers/common/Geometries.js +98 -0
  342. package/src/renderers/common/IndirectStorageBufferAttribute.js +25 -2
  343. package/src/renderers/common/Info.js +87 -0
  344. package/src/renderers/common/Lighting.js +26 -0
  345. package/src/renderers/common/Pipeline.js +22 -0
  346. package/src/renderers/common/Pipelines.js +148 -5
  347. package/src/renderers/common/PostProcessing.js +75 -3
  348. package/src/renderers/common/ProgrammableStage.js +60 -2
  349. package/src/renderers/common/QuadMesh.js +54 -5
  350. package/src/renderers/common/RenderBundle.js +14 -8
  351. package/src/renderers/common/RenderBundles.js +33 -10
  352. package/src/renderers/common/RenderContext.js +169 -4
  353. package/src/renderers/common/RenderContexts.js +42 -2
  354. package/src/renderers/common/RenderList.js +178 -0
  355. package/src/renderers/common/RenderLists.js +31 -0
  356. package/src/renderers/common/RenderObject.js +328 -4
  357. package/src/renderers/common/RenderObjects.js +101 -7
  358. package/src/renderers/common/RenderPipeline.js +24 -0
  359. package/src/renderers/common/Renderer.js +1096 -31
  360. package/src/renderers/common/RendererUtils.js +193 -0
  361. package/src/renderers/common/SampledTexture.js +121 -0
  362. package/src/renderers/common/Sampler.js +30 -0
  363. package/src/renderers/common/StorageBuffer.js +24 -0
  364. package/src/renderers/common/StorageBufferAttribute.js +31 -2
  365. package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
  366. package/src/renderers/common/StorageTexture.js +38 -0
  367. package/src/renderers/common/Textures.js +83 -0
  368. package/src/renderers/common/Uniform.js +188 -2
  369. package/src/renderers/common/UniformBuffer.js +19 -0
  370. package/src/renderers/common/UniformsGroup.js +139 -2
  371. package/src/renderers/common/extras/PMREMGenerator.js +24 -3
  372. package/src/renderers/common/nodes/NodeBuilderState.js +95 -1
  373. package/src/renderers/common/nodes/NodeLibrary.js +89 -0
  374. package/src/renderers/common/nodes/NodeSampledTexture.js +91 -2
  375. package/src/renderers/common/nodes/NodeSampler.js +28 -0
  376. package/src/renderers/common/nodes/NodeStorageBuffer.js +35 -0
  377. package/src/renderers/common/nodes/NodeUniform.js +189 -0
  378. package/src/renderers/common/nodes/NodeUniformBuffer.js +29 -0
  379. package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
  380. package/src/renderers/common/nodes/Nodes.js +327 -60
  381. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
  382. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
  383. package/src/renderers/webgl-fallback/WebGLBackend.js +547 -29
  384. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +0 -1
  385. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +1 -1
  386. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +1 -1
  387. package/src/renderers/webgpu/WebGPUBackend.js +480 -49
  388. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +34 -0
  389. package/src/renderers/webgpu/WebGPURenderer.js +35 -0
  390. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +20 -8
  391. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +21 -8
  392. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +59 -11
  393. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +17 -0
  394. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
  395. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +10 -8
  396. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +9 -1
  397. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +5 -9
  398. package/src/renderers/webgpu/utils/WebGPUUtils.js +30 -0
  399. package/src/renderers/webxr/WebXRDepthSensing.js +1 -1
  400. package/src/renderers/webxr/WebXRManager.js +7 -1
  401. package/src/textures/Data3DTexture.js +2 -2
  402. package/src/textures/Texture.js +4 -0
  403. package/examples/jsm/animation/MMDAnimationHelper.js +0 -1209
  404. package/examples/jsm/animation/MMDPhysics.js +0 -1408
  405. package/examples/jsm/exporters/MMDExporter.js +0 -223
  406. package/examples/jsm/libs/mmdparser.module.js +0 -11530
  407. package/examples/jsm/loaders/MMDLoader.js +0 -2298
  408. package/examples/jsm/shaders/MMDToonShader.js +0 -134
  409. package/src/nodes/core/UniformGroup.js +0 -13
  410. package/src/nodes/fog/FogExp2Node.js +0 -35
  411. package/src/nodes/fog/FogNode.js +0 -50
  412. package/src/nodes/fog/FogRangeNode.js +0 -36
  413. 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 StructTypeNode from './StructTypeNode.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';
@@ -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 = [];
166
+
167
+ /**
168
+ * A dictionary that assigns each node to a unique hash.
169
+ *
170
+ * @type {Object<Number,Node>}
171
+ */
82
172
  this.hashNodes = {};
83
173
 
174
+ /**
175
+ * A reference to a node material observer.
176
+ *
177
+ * @type {NodeMaterialObserver?}
178
+ * @default null
179
+ */
84
180
  this.monitor = null;
85
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,26 @@ 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 a bind group for the given group name and binding.
502
+ *
503
+ * @private
504
+ * @param {String} groupName - The group name.
505
+ * @param {Array<NodeUniformsGroup>} bindings - List of bindings.
506
+ * @return {BindGroup} The bind group
507
+ */
174
508
  _getBindGroup( groupName, bindings ) {
175
509
 
176
510
  const bindGroupsCache = this.getBindGroupsCache();
@@ -215,6 +549,13 @@ class NodeBuilder {
215
549
 
216
550
  }
217
551
 
552
+ /**
553
+ * Returns an array of node uniform groups for the given group name and shader stage.
554
+ *
555
+ * @param {String} groupName - The group name.
556
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
557
+ * @return {Array<NodeUniformsGroup>} The array of node uniform groups.
558
+ */
218
559
  getBindGroupArray( groupName, shaderStage ) {
219
560
 
220
561
  const bindings = this.bindings[ shaderStage ];
@@ -237,6 +578,11 @@ class NodeBuilder {
237
578
 
238
579
  }
239
580
 
581
+ /**
582
+ * Returns a list bindings of all shader stages separated by groups.
583
+ *
584
+ * @return {Array<BindGroup>} The list of bindings.
585
+ */
240
586
  getBindings() {
241
587
 
242
588
  let bindingsGroups = this.bindGroups;
@@ -279,6 +625,9 @@ class NodeBuilder {
279
625
 
280
626
  }
281
627
 
628
+ /**
629
+ * Sorts the bind groups and updates {@link NodeBuilder#bindingsIndexes}.
630
+ */
282
631
  sortBindingGroups() {
283
632
 
284
633
  const bindingsGroups = this.getBindings();
@@ -296,12 +645,24 @@ class NodeBuilder {
296
645
 
297
646
  }
298
647
 
648
+ /**
649
+ * The builder maintains each node in a hash-based dictionary.
650
+ * This method sets the given node (value) with the given hash (key) into this dictionary.
651
+ *
652
+ * @param {Node} node - The node to add.
653
+ * @param {Number} hash - The hash of the node.
654
+ */
299
655
  setHashNode( node, hash ) {
300
656
 
301
657
  this.hashNodes[ hash ] = node;
302
658
 
303
659
  }
304
660
 
661
+ /**
662
+ * Adds a node to this builder.
663
+ *
664
+ * @param {Node} node - The node to add.
665
+ */
305
666
  addNode( node ) {
306
667
 
307
668
  if ( this.nodes.includes( node ) === false ) {
@@ -314,6 +675,13 @@ class NodeBuilder {
314
675
 
315
676
  }
316
677
 
678
+ /**
679
+ * It is used to add Nodes that will be used as FRAME and RENDER events,
680
+ * and need to follow a certain sequence in the calls to work correctly.
681
+ * This function should be called after 'setup()' in the 'build()' process to ensure that the child nodes are processed first.
682
+ *
683
+ * @param {Node} node - The node to add.
684
+ */
317
685
  addSequentialNode( node ) {
318
686
 
319
687
  if ( this.sequentialNodes.includes( node ) === false ) {
@@ -324,6 +692,9 @@ class NodeBuilder {
324
692
 
325
693
  }
326
694
 
695
+ /**
696
+ * Checks the update types of nodes
697
+ */
327
698
  buildUpdateNodes() {
328
699
 
329
700
  for ( const node of this.nodes ) {
@@ -359,12 +730,24 @@ class NodeBuilder {
359
730
 
360
731
  }
361
732
 
733
+ /**
734
+ * A reference the current node which is the
735
+ * last node in the chain of nodes.
736
+ *
737
+ * @type {Node}
738
+ */
362
739
  get currentNode() {
363
740
 
364
741
  return this.chaining[ this.chaining.length - 1 ];
365
742
 
366
743
  }
367
744
 
745
+ /**
746
+ * Whether the given texture is filtered or not.
747
+ *
748
+ * @param {Texture} texture - The texture to check.
749
+ * @return {Boolean} Whether the given texture is filtered or not.
750
+ */
368
751
  isFilteredTexture( texture ) {
369
752
 
370
753
  return ( texture.magFilter === LinearFilter || texture.magFilter === LinearMipmapNearestFilter || texture.magFilter === NearestMipmapLinearFilter || texture.magFilter === LinearMipmapLinearFilter ||
@@ -372,6 +755,12 @@ class NodeBuilder {
372
755
 
373
756
  }
374
757
 
758
+ /**
759
+ * Adds the given node to the internal node chain.
760
+ * This is used to check recursive calls in node-graph.
761
+ *
762
+ * @param {Node} node - The node to add.
763
+ */
375
764
  addChain( node ) {
376
765
 
377
766
  /*
@@ -386,6 +775,11 @@ class NodeBuilder {
386
775
 
387
776
  }
388
777
 
778
+ /**
779
+ * Removes the given node from the internal node chain.
780
+ *
781
+ * @param {Node} node - The node to remove.
782
+ */
389
783
  removeChain( node ) {
390
784
 
391
785
  const lastChain = this.chaining.pop();
@@ -398,18 +792,40 @@ class NodeBuilder {
398
792
 
399
793
  }
400
794
 
795
+ /**
796
+ * Returns the native shader method name for a given generic name. E.g.
797
+ * the method name `textureDimensions` matches the WGSL name but must be
798
+ * resolved to `textureSize` in GLSL.
799
+ *
800
+ * @abstract
801
+ * @param {String} method - The method name to resolve.
802
+ * @return {String} The resolved method name.
803
+ */
401
804
  getMethod( method ) {
402
805
 
403
806
  return method;
404
807
 
405
808
  }
406
809
 
810
+ /**
811
+ * Returns a node for the given hash, see {@link NodeBuilder#setHashNode}.
812
+ *
813
+ * @param {Number} hash - The hash of the node.
814
+ * @return {Node} The found node.
815
+ */
407
816
  getNodeFromHash( hash ) {
408
817
 
409
818
  return this.hashNodes[ hash ];
410
819
 
411
820
  }
412
821
 
822
+ /**
823
+ * Adds the Node to a target flow so that it can generate code in the 'generate' process.
824
+ *
825
+ * @param {('vertex'|'fragment'|'compute')} shaderStage - The shader stage.
826
+ * @param {Node} node - The node to add.
827
+ * @return {Node} The node.
828
+ */
413
829
  addFlow( shaderStage, node ) {
414
830
 
415
831
  this.flowNodes[ shaderStage ].push( node );
@@ -418,18 +834,34 @@ class NodeBuilder {
418
834
 
419
835
  }
420
836
 
837
+ /**
838
+ * Sets builder's context.
839
+ *
840
+ * @param {Object} context - The context to set.
841
+ */
421
842
  setContext( context ) {
422
843
 
423
844
  this.context = context;
424
845
 
425
846
  }
426
847
 
848
+ /**
849
+ * Returns the builder's current context.
850
+ *
851
+ * @return {Object} The builder's current context.
852
+ */
427
853
  getContext() {
428
854
 
429
855
  return this.context;
430
856
 
431
857
  }
432
858
 
859
+ /**
860
+ * Gets a context used in shader construction that can be shared across different materials.
861
+ * This is necessary since the renderer cache can reuse shaders generated in one material and use them in another.
862
+ *
863
+ * @return {Object} The builder's current context without material.
864
+ */
433
865
  getSharedContext() {
434
866
 
435
867
  const context = { ...this.context };
@@ -440,18 +872,35 @@ class NodeBuilder {
440
872
 
441
873
  }
442
874
 
875
+ /**
876
+ * Sets builder's cache.
877
+ *
878
+ * @param {NodeCache} cache - The cache to set.
879
+ */
443
880
  setCache( cache ) {
444
881
 
445
882
  this.cache = cache;
446
883
 
447
884
  }
448
885
 
886
+ /**
887
+ * Returns the builder's current cache.
888
+ *
889
+ * @return {NodeCache} The builder's current cache.
890
+ */
449
891
  getCache() {
450
892
 
451
893
  return this.cache;
452
894
 
453
895
  }
454
896
 
897
+ /**
898
+ * Returns a cache for the given node.
899
+ *
900
+ * @param {Node} node - The node.
901
+ * @param {Boolean} [parent=true] - Whether this node refers to a shared parent cache or not.
902
+ * @return {NodeCache} The cache.
903
+ */
455
904
  getCacheFromNode( node, parent = true ) {
456
905
 
457
906
  const data = this.getDataFromNode( node );
@@ -461,48 +910,99 @@ class NodeBuilder {
461
910
 
462
911
  }
463
912
 
913
+ /**
914
+ * Whether the requested feature is available or not.
915
+ *
916
+ * @abstract
917
+ * @param {String} name - The requested feature.
918
+ * @return {Boolean} Whether the requested feature is supported or not.
919
+ */
464
920
  isAvailable( /*name*/ ) {
465
921
 
466
922
  return false;
467
923
 
468
924
  }
469
925
 
926
+ /**
927
+ * Returns the vertexIndex input variable as a native shader string.
928
+ *
929
+ * @abstract
930
+ * @return {String} The instanceIndex shader string.
931
+ */
470
932
  getVertexIndex() {
471
933
 
472
934
  console.warn( 'Abstract function.' );
473
935
 
474
936
  }
475
937
 
938
+ /**
939
+ * Returns the instanceIndex input variable as a native shader string.
940
+ *
941
+ * @abstract
942
+ * @return {String} The instanceIndex shader string.
943
+ */
476
944
  getInstanceIndex() {
477
945
 
478
946
  console.warn( 'Abstract function.' );
479
947
 
480
948
  }
481
949
 
950
+ /**
951
+ * Returns the drawIndex input variable as a native shader string.
952
+ * Only relevant for WebGL and its `WEBGL_multi_draw` extension.
953
+ *
954
+ * @abstract
955
+ * @return {String} The drawIndex shader string.
956
+ */
482
957
  getDrawIndex() {
483
958
 
484
959
  console.warn( 'Abstract function.' );
485
960
 
486
961
  }
487
962
 
963
+ /**
964
+ * Returns the frontFacing input variable as a native shader string.
965
+ *
966
+ * @abstract
967
+ * @return {String} The frontFacing shader string.
968
+ */
488
969
  getFrontFacing() {
489
970
 
490
971
  console.warn( 'Abstract function.' );
491
972
 
492
973
  }
493
974
 
975
+ /**
976
+ * Returns the fragCoord input variable as a native shader string.
977
+ *
978
+ * @abstract
979
+ * @return {String} The fragCoord shader string.
980
+ */
494
981
  getFragCoord() {
495
982
 
496
983
  console.warn( 'Abstract function.' );
497
984
 
498
985
  }
499
986
 
987
+ /**
988
+ * Whether to flip texture data along its vertical axis or not. WebGL needs
989
+ * this method evaluate to `true`, WebGPU to `false`.
990
+ *
991
+ * @abstract
992
+ * @return {Boolean} Whether to flip texture data along its vertical axis or not.
993
+ */
500
994
  isFlipY() {
501
995
 
502
996
  return false;
503
997
 
504
998
  }
505
999
 
1000
+ /**
1001
+ * Calling this method increases the usage count for the given node by one.
1002
+ *
1003
+ * @param {Node} node - The node to increase the usage count for.
1004
+ * @return {Number} The updated usage count.
1005
+ */
506
1006
  increaseUsage( node ) {
507
1007
 
508
1008
  const nodeData = this.getDataFromNode( node );
@@ -512,18 +1012,44 @@ class NodeBuilder {
512
1012
 
513
1013
  }
514
1014
 
1015
+ /**
1016
+ * Generates a texture sample shader string for the given texture data.
1017
+ *
1018
+ * @abstract
1019
+ * @param {Texture} texture - The texture.
1020
+ * @param {String} textureProperty - The texture property name.
1021
+ * @param {String} uvSnippet - Snippet defining the texture coordinates.
1022
+ * @return {String} The generated shader string.
1023
+ */
515
1024
  generateTexture( /* texture, textureProperty, uvSnippet */ ) {
516
1025
 
517
1026
  console.warn( 'Abstract function.' );
518
1027
 
519
1028
  }
520
1029
 
1030
+ /**
1031
+ * Generates a texture LOD shader string for the given texture data.
1032
+ *
1033
+ * @abstract
1034
+ * @param {Texture} texture - The texture.
1035
+ * @param {String} textureProperty - The texture property name.
1036
+ * @param {String} uvSnippet - Snippet defining the texture coordinates.
1037
+ * @param {String} levelSnippet - Snippet defining the mip level.
1038
+ * @return {String} The generated shader string.
1039
+ */
521
1040
  generateTextureLod( /* texture, textureProperty, uvSnippet, levelSnippet */ ) {
522
1041
 
523
1042
  console.warn( 'Abstract function.' );
524
1043
 
525
1044
  }
526
1045
 
1046
+ /**
1047
+ * Generates the shader string for the given type and value.
1048
+ *
1049
+ * @param {String} type - The type.
1050
+ * @param {Any?} [value=null] - The value.
1051
+ * @return {String} The generated value as a shader string.
1052
+ */
527
1053
  generateConst( type, value = null ) {
528
1054
 
529
1055
  if ( value === null ) {
@@ -575,6 +1101,13 @@ class NodeBuilder {
575
1101
 
576
1102
  }
577
1103
 
1104
+ /**
1105
+ * It might be necessary to convert certain data types to different ones
1106
+ * so this method can be used to hide the conversion.
1107
+ *
1108
+ * @param {String} type - The type.
1109
+ * @return {String} The updated type.
1110
+ */
578
1111
  getType( type ) {
579
1112
 
580
1113
  if ( type === 'color' ) return 'vec3';
@@ -583,12 +1116,25 @@ class NodeBuilder {
583
1116
 
584
1117
  }
585
1118
 
1119
+ /**
1120
+ * Whether the given attribute name is defined in the geometry or not.
1121
+ *
1122
+ * @param {String} name - The attribute name.
1123
+ * @return {Boolean} Whether the given attribute name is defined in the geometry.
1124
+ */
586
1125
  hasGeometryAttribute( name ) {
587
1126
 
588
1127
  return this.geometry && this.geometry.getAttribute( name ) !== undefined;
589
1128
 
590
1129
  }
591
1130
 
1131
+ /**
1132
+ * Returns a node attribute for the given name and type.
1133
+ *
1134
+ * @param {String} name - The attribute's name.
1135
+ * @param {String} type - The attribute's type.
1136
+ * @return {NodeAttribute} The node attribute.
1137
+ */
592
1138
  getAttribute( name, type ) {
593
1139
 
594
1140
  const attributes = this.attributes;
@@ -615,36 +1161,74 @@ class NodeBuilder {
615
1161
 
616
1162
  }
617
1163
 
1164
+ /**
1165
+ * Returns for the given node and shader stage the property name for the shader.
1166
+ *
1167
+ * @param {Node} node - The node.
1168
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
1169
+ * @return {String} The property name.
1170
+ */
618
1171
  getPropertyName( node/*, shaderStage*/ ) {
619
1172
 
620
1173
  return node.name;
621
1174
 
622
1175
  }
623
1176
 
1177
+ /**
1178
+ * Whether the given type is a vector type or not.
1179
+ *
1180
+ * @param {String} type - The type to check.
1181
+ * @return {Boolean} Whether the given type is a vector type or not.
1182
+ */
624
1183
  isVector( type ) {
625
1184
 
626
1185
  return /vec\d/.test( type );
627
1186
 
628
1187
  }
629
1188
 
1189
+ /**
1190
+ * Whether the given type is a matrix type or not.
1191
+ *
1192
+ * @param {String} type - The type to check.
1193
+ * @return {Boolean} Whether the given type is a matrix type or not.
1194
+ */
630
1195
  isMatrix( type ) {
631
1196
 
632
1197
  return /mat\d/.test( type );
633
1198
 
634
1199
  }
635
1200
 
1201
+ /**
1202
+ * Whether the given type is a reference type or not.
1203
+ *
1204
+ * @param {String} type - The type to check.
1205
+ * @return {Boolean} Whether the given type is a reference type or not.
1206
+ */
636
1207
  isReference( type ) {
637
1208
 
638
1209
  return type === 'void' || type === 'property' || type === 'sampler' || type === 'texture' || type === 'cubeTexture' || type === 'storageTexture' || type === 'depthTexture' || type === 'texture3D';
639
1210
 
640
1211
  }
641
1212
 
1213
+ /**
1214
+ * Whether the given texture needs a conversion to working color space.
1215
+ *
1216
+ * @abstract
1217
+ * @param {Texture} texture - The texture to check.
1218
+ * @return {Boolean} Whether a color space conversion is required or not.
1219
+ */
642
1220
  needsToWorkingColorSpace( /*texture*/ ) {
643
1221
 
644
1222
  return false;
645
1223
 
646
1224
  }
647
1225
 
1226
+ /**
1227
+ * Returns the component type of a given texture.
1228
+ *
1229
+ * @param {Texture} texture - The texture.
1230
+ * @return {String} The component type.
1231
+ */
648
1232
  getComponentTypeFromTexture( texture ) {
649
1233
 
650
1234
  const type = texture.type;
@@ -660,6 +1244,12 @@ class NodeBuilder {
660
1244
 
661
1245
  }
662
1246
 
1247
+ /**
1248
+ * Returns the element type for a given type.
1249
+ *
1250
+ * @param {String} type - The type.
1251
+ * @return {String} The element type.
1252
+ */
663
1253
  getElementType( type ) {
664
1254
 
665
1255
  if ( type === 'mat2' ) return 'vec2';
@@ -670,6 +1260,12 @@ class NodeBuilder {
670
1260
 
671
1261
  }
672
1262
 
1263
+ /**
1264
+ * Returns the component type for a given type.
1265
+ *
1266
+ * @param {String} type - The type.
1267
+ * @return {String} The component type.
1268
+ */
673
1269
  getComponentType( type ) {
674
1270
 
675
1271
  type = this.getVectorType( type );
@@ -688,6 +1284,12 @@ class NodeBuilder {
688
1284
 
689
1285
  }
690
1286
 
1287
+ /**
1288
+ * Returns the vector type for a given type.
1289
+ *
1290
+ * @param {String} type - The type.
1291
+ * @return {String} The vector type.
1292
+ */
691
1293
  getVectorType( type ) {
692
1294
 
693
1295
  if ( type === 'color' ) return 'vec3';
@@ -697,6 +1299,13 @@ class NodeBuilder {
697
1299
 
698
1300
  }
699
1301
 
1302
+ /**
1303
+ * Returns the data type for the given the length and component type.
1304
+ *
1305
+ * @param {Number} length - The length.
1306
+ * @param {String} [componentType='float'] - The component type.
1307
+ * @return {String} The type.
1308
+ */
700
1309
  getTypeFromLength( length, componentType = 'float' ) {
701
1310
 
702
1311
  if ( length === 1 ) return componentType;
@@ -708,12 +1317,24 @@ class NodeBuilder {
708
1317
 
709
1318
  }
710
1319
 
1320
+ /**
1321
+ * Returns the type for a given typed array.
1322
+ *
1323
+ * @param {TypedArray} array - The typed array.
1324
+ * @return {String} The type.
1325
+ */
711
1326
  getTypeFromArray( array ) {
712
1327
 
713
1328
  return typeFromArray.get( array.constructor );
714
1329
 
715
1330
  }
716
1331
 
1332
+ /**
1333
+ * Returns the type for a given buffer attribute.
1334
+ *
1335
+ * @param {BufferAttribute} attribute - The buffer attribute.
1336
+ * @return {String} The type.
1337
+ */
717
1338
  getTypeFromAttribute( attribute ) {
718
1339
 
719
1340
  let dataAttribute = attribute;
@@ -736,6 +1357,12 @@ class NodeBuilder {
736
1357
 
737
1358
  }
738
1359
 
1360
+ /**
1361
+ * Returns the length for the given data type.
1362
+ *
1363
+ * @param {String} type - The data type.
1364
+ * @return {Number} The length.
1365
+ */
739
1366
  getTypeLength( type ) {
740
1367
 
741
1368
  const vecType = this.getVectorType( type );
@@ -751,18 +1378,39 @@ class NodeBuilder {
751
1378
 
752
1379
  }
753
1380
 
1381
+ /**
1382
+ * Returns the vector type for a given matrix type.
1383
+ *
1384
+ * @param {String} type - The matrix type.
1385
+ * @return {String} The vector type.
1386
+ */
754
1387
  getVectorFromMatrix( type ) {
755
1388
 
756
1389
  return type.replace( 'mat', 'vec' );
757
1390
 
758
1391
  }
759
1392
 
1393
+ /**
1394
+ * For a given type this method changes the component type to the
1395
+ * given value. E.g. `vec4` should be changed to the new component type
1396
+ * `uint` which results in `uvec4`.
1397
+ *
1398
+ * @param {String} type - The type.
1399
+ * @param {String} newComponentType - The new component type.
1400
+ * @return {String} The new type.
1401
+ */
760
1402
  changeComponentType( type, newComponentType ) {
761
1403
 
762
1404
  return this.getTypeFromLength( this.getTypeLength( type ), newComponentType );
763
1405
 
764
1406
  }
765
1407
 
1408
+ /**
1409
+ * Returns the integer type pendant for the given type.
1410
+ *
1411
+ * @param {String} type - The type.
1412
+ * @return {String} The integer type.
1413
+ */
766
1414
  getIntegerType( type ) {
767
1415
 
768
1416
  const componentType = this.getComponentType( type );
@@ -773,6 +1421,11 @@ class NodeBuilder {
773
1421
 
774
1422
  }
775
1423
 
1424
+ /**
1425
+ * Adds a stack node to the internal stack.
1426
+ *
1427
+ * @return {StackNode} The added stack node.
1428
+ */
776
1429
  addStack() {
777
1430
 
778
1431
  this.stack = stack( this.stack );
@@ -784,6 +1437,11 @@ class NodeBuilder {
784
1437
 
785
1438
  }
786
1439
 
1440
+ /**
1441
+ * Removes the last stack node from the internal stack.
1442
+ *
1443
+ * @return {StackNode} The removed stack node.
1444
+ */
787
1445
  removeStack() {
788
1446
 
789
1447
  const lastStack = this.stack;
@@ -795,6 +1453,15 @@ class NodeBuilder {
795
1453
 
796
1454
  }
797
1455
 
1456
+ /**
1457
+ * The builder maintains (cached) data for each node during the building process. This method
1458
+ * can be used to get these data for a specific shader stage and cache.
1459
+ *
1460
+ * @param {Node} node - The node to get the data for.
1461
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
1462
+ * @param {NodeCache?} cache - An optional cache.
1463
+ * @return {Object} The node data.
1464
+ */
798
1465
  getDataFromNode( node, shaderStage = this.shaderStage, cache = null ) {
799
1466
 
800
1467
  cache = cache === null ? ( node.isGlobal( this ) ? this.globalCache : this.cache ) : cache;
@@ -815,6 +1482,13 @@ class NodeBuilder {
815
1482
 
816
1483
  }
817
1484
 
1485
+ /**
1486
+ * Returns the properties for the given node and shader stage.
1487
+ *
1488
+ * @param {Node} node - The node to get the properties for.
1489
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage='any'] - The shader stage.
1490
+ * @return {Object} The node properties.
1491
+ */
818
1492
  getNodeProperties( node, shaderStage = 'any' ) {
819
1493
 
820
1494
  const nodeData = this.getDataFromNode( node, shaderStage );
@@ -823,6 +1497,13 @@ class NodeBuilder {
823
1497
 
824
1498
  }
825
1499
 
1500
+ /**
1501
+ * Returns an instance of {@link NodeAttribute} for the given buffer attribute node.
1502
+ *
1503
+ * @param {BufferAttributeNode} node - The buffer attribute node.
1504
+ * @param {String} type - The node type.
1505
+ * @return {NodeAttribute} The node attribute.
1506
+ */
826
1507
  getBufferAttributeFromNode( node, type ) {
827
1508
 
828
1509
  const nodeData = this.getDataFromNode( node );
@@ -845,25 +1526,45 @@ class NodeBuilder {
845
1526
 
846
1527
  }
847
1528
 
848
- getStructTypeFromNode( node, shaderStage = this.shaderStage ) {
1529
+ /**
1530
+ * Returns an instance of {@link StructTypeNode} for the given output struct node.
1531
+ *
1532
+ * @param {OutputStructNode} node - The output struct node.
1533
+ * @param {Array<String>} types - The output struct types.
1534
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
1535
+ * @return {StructTypeNode} The struct type attribute.
1536
+ */
1537
+ getStructTypeFromNode( node, types, shaderStage = this.shaderStage ) {
849
1538
 
850
1539
  const nodeData = this.getDataFromNode( node, shaderStage );
851
1540
 
852
- if ( nodeData.structType === undefined ) {
1541
+ let structType = nodeData.structType;
1542
+
1543
+ if ( structType === undefined ) {
853
1544
 
854
1545
  const index = this.structs.index ++;
855
1546
 
856
- node.name = `StructType${ index }`;
857
- this.structs[ shaderStage ].push( node );
1547
+ structType = new StructTypeNode( 'StructType' + index, types );
1548
+
1549
+ this.structs[ shaderStage ].push( structType );
858
1550
 
859
- nodeData.structType = node;
1551
+ nodeData.structType = structType;
860
1552
 
861
1553
  }
862
1554
 
863
- return node;
1555
+ return structType;
864
1556
 
865
1557
  }
866
1558
 
1559
+ /**
1560
+ * Returns an instance of {@link NodeUniform} for the given uniform node.
1561
+ *
1562
+ * @param {UniformNode} node - The uniform node.
1563
+ * @param {String} type - The uniform type.
1564
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
1565
+ * @param {String?} name - The name of the uniform.
1566
+ * @return {NodeUniform} The node uniform.
1567
+ */
867
1568
  getUniformFromNode( node, type, shaderStage = this.shaderStage, name = null ) {
868
1569
 
869
1570
  const nodeData = this.getDataFromNode( node, shaderStage, this.globalCache );
@@ -886,6 +1587,15 @@ class NodeBuilder {
886
1587
 
887
1588
  }
888
1589
 
1590
+ /**
1591
+ * Returns an instance of {@link NodeVar} for the given variable node.
1592
+ *
1593
+ * @param {VarNode} node - The variable node.
1594
+ * @param {String?} name - The variable's name.
1595
+ * @param {String} [type=node.getNodeType( this )] - The variable's type.
1596
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
1597
+ * @return {NodeVar} The node variable.
1598
+ */
889
1599
  getVarFromNode( node, name = null, type = node.getNodeType( this ), shaderStage = this.shaderStage ) {
890
1600
 
891
1601
  const nodeData = this.getDataFromNode( node, shaderStage );
@@ -910,6 +1620,14 @@ class NodeBuilder {
910
1620
 
911
1621
  }
912
1622
 
1623
+ /**
1624
+ * Returns an instance of {@link NodeVarying} for the given varying node.
1625
+ *
1626
+ * @param {(VaryingNode|PropertyNode)} node - The varying node.
1627
+ * @param {String?} name - The varying's name.
1628
+ * @param {String} [type=node.getNodeType( this )] - The varying's type.
1629
+ * @return {NodeVar} The node varying.
1630
+ */
913
1631
  getVaryingFromNode( node, name = null, type = node.getNodeType( this ) ) {
914
1632
 
915
1633
  const nodeData = this.getDataFromNode( node, 'any' );
@@ -935,6 +1653,14 @@ class NodeBuilder {
935
1653
 
936
1654
  }
937
1655
 
1656
+ /**
1657
+ * Returns an instance of {@link NodeCode} for the given code node.
1658
+ *
1659
+ * @param {CodeNode} node - The code node.
1660
+ * @param {String} type - The node type.
1661
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
1662
+ * @return {NodeCode} The node code.
1663
+ */
938
1664
  getCodeFromNode( node, type, shaderStage = this.shaderStage ) {
939
1665
 
940
1666
  const nodeData = this.getDataFromNode( node );
@@ -958,6 +1684,15 @@ class NodeBuilder {
958
1684
 
959
1685
  }
960
1686
 
1687
+ /**
1688
+ * Adds a code flow based on the code-block hierarchy.
1689
+
1690
+ * This is used so that code-blocks like If,Else create their variables locally if the Node
1691
+ * is only used inside one of these conditionals in the current shader stage.
1692
+ *
1693
+ * @param {Node} node - The node to add.
1694
+ * @param {Node} nodeBlock - Node-based code-block. Usually 'ConditionalNode'.
1695
+ */
961
1696
  addFlowCodeHierarchy( node, nodeBlock ) {
962
1697
 
963
1698
  const { flowCodes, flowCodeBlock } = this.getDataFromNode( node );
@@ -990,6 +1725,13 @@ class NodeBuilder {
990
1725
 
991
1726
  }
992
1727
 
1728
+ /**
1729
+ * Add a inline-code to the current flow code-block.
1730
+ *
1731
+ * @param {Node} node - The node to add.
1732
+ * @param {String} code - The code to add.
1733
+ * @param {Node} nodeBlock - Current ConditionalNode
1734
+ */
993
1735
  addLineFlowCodeBlock( node, code, nodeBlock ) {
994
1736
 
995
1737
  const nodeData = this.getDataFromNode( node );
@@ -1001,6 +1743,13 @@ class NodeBuilder {
1001
1743
 
1002
1744
  }
1003
1745
 
1746
+ /**
1747
+ * Add a inline-code to the current flow.
1748
+ *
1749
+ * @param {String} code - The code to add.
1750
+ * @param {Node?} [node= null] - Optional Node, can help the system understand if the Node is part of a code-block.
1751
+ * @return {NodeBuilder} A reference to this node builder.
1752
+ */
1004
1753
  addLineFlowCode( code, node = null ) {
1005
1754
 
1006
1755
  if ( code === '' ) return this;
@@ -1025,6 +1774,12 @@ class NodeBuilder {
1025
1774
 
1026
1775
  }
1027
1776
 
1777
+ /**
1778
+ * Adds a code to the current code flow.
1779
+ *
1780
+ * @param {String} code - Shader code.
1781
+ * @return {NodeBuilder} A reference to this node builder.
1782
+ */
1028
1783
  addFlowCode( code ) {
1029
1784
 
1030
1785
  this.flow.code += code;
@@ -1033,6 +1788,12 @@ class NodeBuilder {
1033
1788
 
1034
1789
  }
1035
1790
 
1791
+ /**
1792
+ * Add tab in the code that will be generated so that other snippets respect the current tabulation.
1793
+ * Typically used in codes with If,Else.
1794
+ *
1795
+ * @return {NodeBuilder} A reference to this node builder.
1796
+ */
1036
1797
  addFlowTab() {
1037
1798
 
1038
1799
  this.tab += '\t';
@@ -1041,6 +1802,11 @@ class NodeBuilder {
1041
1802
 
1042
1803
  }
1043
1804
 
1805
+ /**
1806
+ * Removes a tab.
1807
+ *
1808
+ * @return {NodeBuilder} A reference to this node builder.
1809
+ */
1044
1810
  removeFlowTab() {
1045
1811
 
1046
1812
  this.tab = this.tab.slice( 0, - 1 );
@@ -1049,12 +1815,25 @@ class NodeBuilder {
1049
1815
 
1050
1816
  }
1051
1817
 
1818
+ /**
1819
+ * Gets the current flow data based on a Node.
1820
+ *
1821
+ * @param {Node} node - Node that the flow was started.
1822
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
1823
+ * @return {Object} The flow data.
1824
+ */
1052
1825
  getFlowData( node/*, shaderStage*/ ) {
1053
1826
 
1054
1827
  return this.flowsData.get( node );
1055
1828
 
1056
1829
  }
1057
1830
 
1831
+ /**
1832
+ * Executes the node flow based on a root node to generate the final shader code.
1833
+ *
1834
+ * @param {Node} node - The node to execute.
1835
+ * @return {Object} The code flow.
1836
+ */
1058
1837
  flowNode( node ) {
1059
1838
 
1060
1839
  const output = node.getNodeType( this );
@@ -1067,6 +1846,13 @@ class NodeBuilder {
1067
1846
 
1068
1847
  }
1069
1848
 
1849
+ /**
1850
+ * Returns the native shader operator name for a given generic name.
1851
+ * It is a similar type of method like {@link NodeBuilder#getMethod}.
1852
+ *
1853
+ * @param {ShaderNodeInternal} shaderNode - The shader node to build the function node with.
1854
+ * @return {FunctionNode} The build function node.
1855
+ */
1070
1856
  buildFunctionNode( shaderNode ) {
1071
1857
 
1072
1858
  const fn = new FunctionNode();
@@ -1083,6 +1869,12 @@ class NodeBuilder {
1083
1869
 
1084
1870
  }
1085
1871
 
1872
+ /**
1873
+ * Generates a code flow based on a TSL function: Fn().
1874
+ *
1875
+ * @param {ShaderNodeInternal} shaderNode - A function code will be generated based on the input.
1876
+ * @return {Object}
1877
+ */
1086
1878
  flowShaderNode( shaderNode ) {
1087
1879
 
1088
1880
  const layout = shaderNode.layout;
@@ -1121,6 +1913,13 @@ class NodeBuilder {
1121
1913
 
1122
1914
  }
1123
1915
 
1916
+ /**
1917
+ * Runs the node flow through all the steps of creation, 'setup', 'analyze', 'generate'.
1918
+ *
1919
+ * @param {Node} node - The node to execute.
1920
+ * @param {String?} output - Expected output type. For example 'vec3'.
1921
+ * @return {Object}
1922
+ */
1124
1923
  flowStagesNode( node, output = null ) {
1125
1924
 
1126
1925
  const previousFlow = this.flow;
@@ -1159,12 +1958,27 @@ class NodeBuilder {
1159
1958
 
1160
1959
  }
1161
1960
 
1162
- getFunctionOperator() {
1961
+ /**
1962
+ * Returns the native shader operator name for a given generic name.
1963
+ * It is a similar type of method like {@link NodeBuilder#getMethod}.
1964
+ *
1965
+ * @abstract
1966
+ * @param {String} op - The operator name to resolve.
1967
+ * @return {String} The resolved operator name.
1968
+ */
1969
+ getFunctionOperator( /* op */ ) {
1163
1970
 
1164
1971
  return null;
1165
1972
 
1166
1973
  }
1167
1974
 
1975
+ /**
1976
+ * Generates a code flow based on a child Node.
1977
+ *
1978
+ * @param {Node} node - The node to execute.
1979
+ * @param {String?} output - Expected output type. For example 'vec3'.
1980
+ * @return {Object} The code flow.
1981
+ */
1168
1982
  flowChildNode( node, output = null ) {
1169
1983
 
1170
1984
  const previousFlow = this.flow;
@@ -1183,6 +1997,18 @@ class NodeBuilder {
1183
1997
 
1184
1998
  }
1185
1999
 
2000
+ /**
2001
+ * Executes a flow of code in a different stage.
2002
+ *
2003
+ * Some nodes like `varying()` have the ability to compute code in vertex-stage and
2004
+ * return the value in fragment-stage even if it is being executed in an input fragment.
2005
+ *
2006
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2007
+ * @param {Node} node - The node to execute.
2008
+ * @param {String?} output - Expected output type. For example 'vec3'.
2009
+ * @param {String?} propertyName - The property name to assign the result.
2010
+ * @return {Object}
2011
+ */
1186
2012
  flowNodeFromShaderStage( shaderStage, node, output = null, propertyName = null ) {
1187
2013
 
1188
2014
  const previousShaderStage = this.shaderStage;
@@ -1205,30 +2031,62 @@ class NodeBuilder {
1205
2031
 
1206
2032
  }
1207
2033
 
2034
+ /**
2035
+ * Returns an array holding all node attributes of this node builder.
2036
+ *
2037
+ * @return {Array<NodeAttribute>} The node attributes of this builder.
2038
+ */
1208
2039
  getAttributesArray() {
1209
2040
 
1210
2041
  return this.attributes.concat( this.bufferAttributes );
1211
2042
 
1212
2043
  }
1213
2044
 
2045
+ /**
2046
+ * Returns the attribute definitions as a shader string for the given shader stage.
2047
+ *
2048
+ * @abstract
2049
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2050
+ * @return {String} The attribute code section.
2051
+ */
1214
2052
  getAttributes( /*shaderStage*/ ) {
1215
2053
 
1216
2054
  console.warn( 'Abstract function.' );
1217
2055
 
1218
2056
  }
1219
2057
 
2058
+ /**
2059
+ * Returns the varying definitions as a shader string for the given shader stage.
2060
+ *
2061
+ * @abstract
2062
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2063
+ * @return {String} The varying code section.
2064
+ */
1220
2065
  getVaryings( /*shaderStage*/ ) {
1221
2066
 
1222
2067
  console.warn( 'Abstract function.' );
1223
2068
 
1224
2069
  }
1225
2070
 
2071
+ /**
2072
+ * Returns a single variable definition as a shader string for the given variable type and name.
2073
+ *
2074
+ * @param {String} type - The variable's type.
2075
+ * @param {String} name - The variable's name.
2076
+ * @return {String} The shader string.
2077
+ */
1226
2078
  getVar( type, name ) {
1227
2079
 
1228
2080
  return `${ this.getType( type ) } ${ name }`;
1229
2081
 
1230
2082
  }
1231
2083
 
2084
+ /**
2085
+ * Returns the variable definitions as a shader string for the given shader stage.
2086
+ *
2087
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2088
+ * @return {String} The variable code section.
2089
+ */
1232
2090
  getVars( shaderStage ) {
1233
2091
 
1234
2092
  let snippet = '';
@@ -1249,12 +2107,25 @@ class NodeBuilder {
1249
2107
 
1250
2108
  }
1251
2109
 
2110
+ /**
2111
+ * Returns the uniform definitions as a shader string for the given shader stage.
2112
+ *
2113
+ * @abstract
2114
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2115
+ * @return {String} The uniform code section.
2116
+ */
1252
2117
  getUniforms( /*shaderStage*/ ) {
1253
2118
 
1254
2119
  console.warn( 'Abstract function.' );
1255
2120
 
1256
2121
  }
1257
2122
 
2123
+ /**
2124
+ * Returns the native code definitions as a shader string for the given shader stage.
2125
+ *
2126
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2127
+ * @return {String} The native code section.
2128
+ */
1258
2129
  getCodes( shaderStage ) {
1259
2130
 
1260
2131
  const codes = this.codes[ shaderStage ];
@@ -1275,42 +2146,77 @@ class NodeBuilder {
1275
2146
 
1276
2147
  }
1277
2148
 
2149
+ /**
2150
+ * Returns the hash of this node builder.
2151
+ *
2152
+ * @return {String} The hash.
2153
+ */
1278
2154
  getHash() {
1279
2155
 
1280
2156
  return this.vertexShader + this.fragmentShader + this.computeShader;
1281
2157
 
1282
2158
  }
1283
2159
 
2160
+ /**
2161
+ * Sets the current shader stage.
2162
+ *
2163
+ * @param {('vertex'|'fragment'|'compute'|'any')?} shaderStage - The shader stage to set.
2164
+ */
1284
2165
  setShaderStage( shaderStage ) {
1285
2166
 
1286
2167
  this.shaderStage = shaderStage;
1287
2168
 
1288
2169
  }
1289
2170
 
2171
+ /**
2172
+ * Returns the current shader stage.
2173
+ *
2174
+ * @return {('vertex'|'fragment'|'compute'|'any')?} The current shader stage.
2175
+ */
1290
2176
  getShaderStage() {
1291
2177
 
1292
2178
  return this.shaderStage;
1293
2179
 
1294
2180
  }
1295
2181
 
2182
+ /**
2183
+ * Sets the current build stage.
2184
+ *
2185
+ * @param {('setup'|'analyze'|'generate')?} buildStage - The build stage to set.
2186
+ */
1296
2187
  setBuildStage( buildStage ) {
1297
2188
 
1298
2189
  this.buildStage = buildStage;
1299
2190
 
1300
2191
  }
1301
2192
 
2193
+ /**
2194
+ * Returns the current build stage.
2195
+ *
2196
+ * @return {('setup'|'analyze'|'generate')?} The current build stage.
2197
+ */
1302
2198
  getBuildStage() {
1303
2199
 
1304
2200
  return this.buildStage;
1305
2201
 
1306
2202
  }
1307
2203
 
2204
+ /**
2205
+ * Controls the code build of the shader stages.
2206
+ *
2207
+ * @abstract
2208
+ */
1308
2209
  buildCode() {
1309
2210
 
1310
2211
  console.warn( 'Abstract function.' );
1311
2212
 
1312
2213
  }
1313
2214
 
2215
+ /**
2216
+ * Central build method which controls the build for the given object.
2217
+ *
2218
+ * @return {NodeBuilder} A reference to this node builder.
2219
+ */
1314
2220
  build() {
1315
2221
 
1316
2222
  const { object, material, renderer } = this;
@@ -1385,6 +2291,13 @@ class NodeBuilder {
1385
2291
 
1386
2292
  }
1387
2293
 
2294
+ /**
2295
+ * Returns a uniform representation which is later used for UBO generation and rendering.
2296
+ *
2297
+ * @param {NodeUniform} uniformNode - The uniform node.
2298
+ * @param {String} type - The requested type.
2299
+ * @return {Uniform} The uniform.
2300
+ */
1388
2301
  getNodeUniform( uniformNode, type ) {
1389
2302
 
1390
2303
  if ( type === 'float' || type === 'int' || type === 'uint' ) return new NumberNodeUniform( uniformNode );
@@ -1399,12 +2312,16 @@ class NodeBuilder {
1399
2312
 
1400
2313
  }
1401
2314
 
1402
- createNodeMaterial( type = 'NodeMaterial' ) { // @deprecated, r168
1403
-
1404
- throw new Error( `THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${ type }() instead.` );
1405
-
1406
- }
1407
-
2315
+ /**
2316
+ * Formats the given shader snippet from a given type into another one. E.g.
2317
+ * this method might be used to convert a simple float string `"1.0"` into a
2318
+ * `vec3` representation: `"vec3<f32>( 1.0 )"`.
2319
+ *
2320
+ * @param {String} snippet - The shader snippet.
2321
+ * @param {String} fromType - The source type.
2322
+ * @param {String} toType - The target type.
2323
+ * @return {String} The updated shader string.
2324
+ */
1408
2325
  format( snippet, fromType, toType ) {
1409
2326
 
1410
2327
  fromType = this.getVectorType( fromType );
@@ -1485,12 +2402,25 @@ class NodeBuilder {
1485
2402
 
1486
2403
  }
1487
2404
 
2405
+ /**
2406
+ * Returns a signature with the engine's current revision.
2407
+ *
2408
+ * @return {String} The signature.
2409
+ */
1488
2410
  getSignature() {
1489
2411
 
1490
2412
  return `// Three.js r${ REVISION } - Node System\n`;
1491
2413
 
1492
2414
  }
1493
2415
 
2416
+ // deprecated
2417
+
2418
+ createNodeMaterial( type = 'NodeMaterial' ) { // @deprecated, r168
2419
+
2420
+ throw new Error( `THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${ type }() instead.` );
2421
+
2422
+ }
2423
+
1494
2424
  }
1495
2425
 
1496
2426
  export default NodeBuilder;