@plastic-software/three 0.167.4 → 0.174.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 (747) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/build/three.cjs +36217 -23964
  4. package/build/three.core.js +48830 -0
  5. package/build/three.core.min.js +6 -0
  6. package/build/three.module.js +10175 -46744
  7. package/build/three.module.min.js +2 -3
  8. package/build/three.tsl.js +550 -0
  9. package/build/three.tsl.min.js +6 -0
  10. package/build/three.webgpu.js +44348 -50671
  11. package/build/three.webgpu.min.js +2 -3
  12. package/build/three.webgpu.nodes.js +70301 -0
  13. package/build/three.webgpu.nodes.min.js +6 -0
  14. package/examples/jsm/Addons.js +3 -15
  15. package/examples/jsm/animation/AnimationClipCreator.js +1 -1
  16. package/examples/jsm/animation/CCDIKSolver.js +61 -11
  17. package/examples/jsm/capabilities/WebGL.js +27 -21
  18. package/examples/jsm/capabilities/WebGPU.js +1 -10
  19. package/examples/jsm/controls/ArcballControls.js +262 -231
  20. package/examples/jsm/controls/DragControls.js +1 -1
  21. package/examples/jsm/controls/FirstPersonControls.js +175 -163
  22. package/examples/jsm/controls/FlyControls.js +194 -188
  23. package/examples/jsm/controls/OrbitControls.js +801 -777
  24. package/examples/jsm/controls/PointerLockControls.js +26 -20
  25. package/examples/jsm/controls/TrackballControls.js +469 -448
  26. package/examples/jsm/controls/TransformControls.js +119 -68
  27. package/examples/jsm/csm/CSM.js +2 -2
  28. package/examples/jsm/csm/CSMFrustum.js +7 -4
  29. package/examples/jsm/csm/CSMHelper.js +2 -0
  30. package/examples/jsm/csm/CSMShadowNode.js +442 -0
  31. package/examples/jsm/curves/NURBSCurve.js +33 -2
  32. package/examples/jsm/curves/NURBSUtils.js +3 -0
  33. package/examples/jsm/effects/AnaglyphEffect.js +6 -13
  34. package/examples/jsm/effects/OutlineEffect.js +1 -1
  35. package/examples/jsm/effects/ParallaxBarrierEffect.js +17 -11
  36. package/examples/jsm/effects/StereoEffect.js +6 -1
  37. package/examples/jsm/exporters/DRACOExporter.js +4 -2
  38. package/examples/jsm/exporters/EXRExporter.js +19 -11
  39. package/examples/jsm/exporters/GLTFExporter.js +181 -109
  40. package/examples/jsm/exporters/KTX2Exporter.js +54 -23
  41. package/examples/jsm/exporters/OBJExporter.js +5 -1
  42. package/examples/jsm/exporters/PLYExporter.js +11 -9
  43. package/examples/jsm/exporters/USDZExporter.js +50 -11
  44. package/examples/jsm/geometries/DecalGeometry.js +73 -21
  45. package/examples/jsm/geometries/TextGeometry.js +1 -12
  46. package/examples/jsm/helpers/LightProbeHelper.js +43 -44
  47. package/examples/jsm/helpers/LightProbeHelperGPU.js +65 -0
  48. package/examples/jsm/helpers/TextureHelperGPU.js +185 -0
  49. package/examples/jsm/helpers/VertexNormalsHelper.js +2 -0
  50. package/examples/jsm/interactive/HTMLMesh.js +1 -0
  51. package/examples/jsm/interactive/InteractiveGroup.js +108 -51
  52. package/examples/jsm/interactive/SelectionHelper.js +3 -1
  53. package/examples/jsm/libs/basis/basis_transcoder.js +8 -10
  54. package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
  55. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  56. package/examples/jsm/libs/ktx-parse.module.js +1 -1
  57. package/examples/jsm/lighting/TiledLighting.js +18 -0
  58. package/examples/jsm/lights/LightProbeGenerator.js +26 -12
  59. package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
  60. package/examples/jsm/lines/LineGeometry.js +25 -0
  61. package/examples/jsm/lines/LineMaterial.js +0 -1
  62. package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
  63. package/examples/jsm/lines/webgpu/Line2.js +2 -1
  64. package/examples/jsm/lines/webgpu/LineSegments2.js +16 -21
  65. package/examples/jsm/lines/webgpu/Wireframe.js +57 -0
  66. package/examples/jsm/loaders/3DMLoader.js +1 -0
  67. package/examples/jsm/loaders/3MFLoader.js +104 -2
  68. package/examples/jsm/loaders/BVHLoader.js +1 -1
  69. package/examples/jsm/loaders/ColladaLoader.js +15 -12
  70. package/examples/jsm/loaders/DDSLoader.js +42 -0
  71. package/examples/jsm/loaders/DRACOLoader.js +3 -1
  72. package/examples/jsm/loaders/FBXLoader.js +71 -22
  73. package/examples/jsm/loaders/GCodeLoader.js +4 -2
  74. package/examples/jsm/loaders/GLTFLoader.js +29 -14
  75. package/examples/jsm/loaders/KTX2Loader.js +160 -58
  76. package/examples/jsm/loaders/KTXLoader.js +4 -4
  77. package/examples/jsm/loaders/LDrawLoader.js +22 -136
  78. package/examples/jsm/loaders/LottieLoader.js +2 -1
  79. package/examples/jsm/loaders/MTLLoader.js +27 -7
  80. package/examples/jsm/loaders/MaterialXLoader.js +40 -14
  81. package/examples/jsm/loaders/NRRDLoader.js +1 -1
  82. package/examples/jsm/loaders/OBJLoader.js +5 -3
  83. package/examples/jsm/loaders/PCDLoader.js +14 -13
  84. package/examples/jsm/loaders/PDBLoader.js +3 -2
  85. package/examples/jsm/loaders/PLYLoader.js +15 -12
  86. package/examples/jsm/loaders/PVRLoader.js +1 -1
  87. package/examples/jsm/loaders/STLLoader.js +3 -2
  88. package/examples/jsm/loaders/SVGLoader.js +2 -2
  89. package/examples/jsm/loaders/TDSLoader.js +17 -18
  90. package/examples/jsm/loaders/VRMLLoader.js +17 -17
  91. package/examples/jsm/loaders/VTKLoader.js +4 -3
  92. package/examples/jsm/loaders/XYZLoader.js +3 -2
  93. package/examples/jsm/loaders/lwo/IFFParser.js +4 -4
  94. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
  95. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
  96. package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
  97. package/examples/jsm/math/ColorSpaces.js +76 -0
  98. package/examples/jsm/math/ConvexHull.js +1 -1
  99. package/examples/jsm/math/OBB.js +17 -0
  100. package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
  101. package/examples/jsm/misc/ProgressiveLightMap.js +54 -41
  102. package/examples/jsm/misc/ProgressiveLightMapGPU.js +294 -0
  103. package/examples/jsm/misc/Timer.js +27 -12
  104. package/examples/jsm/misc/Volume.js +28 -18
  105. package/examples/jsm/misc/VolumeSlice.js +19 -16
  106. package/examples/jsm/modifiers/CurveModifier.js +10 -8
  107. package/examples/jsm/modifiers/CurveModifierGPU.js +235 -0
  108. package/examples/jsm/modifiers/SimplifyModifier.js +2 -2
  109. package/examples/jsm/objects/GroundedSkybox.js +4 -4
  110. package/examples/jsm/objects/LensflareMesh.js +324 -0
  111. package/examples/jsm/objects/Reflector.js +5 -2
  112. package/examples/jsm/objects/Sky.js +2 -2
  113. package/examples/jsm/objects/SkyMesh.js +14 -14
  114. package/examples/jsm/objects/Water2.js +1 -1
  115. package/examples/jsm/objects/Water2Mesh.js +11 -9
  116. package/examples/jsm/objects/WaterMesh.js +38 -33
  117. package/examples/jsm/physics/JoltPhysics.js +8 -8
  118. package/examples/jsm/physics/RapierPhysics.js +5 -5
  119. package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
  120. package/examples/jsm/postprocessing/BloomPass.js +2 -2
  121. package/examples/jsm/postprocessing/EffectComposer.js +1 -2
  122. package/examples/jsm/postprocessing/OutlinePass.js +37 -51
  123. package/examples/jsm/postprocessing/OutputPass.js +2 -0
  124. package/examples/jsm/postprocessing/SAOPass.js +1 -2
  125. package/examples/jsm/postprocessing/SMAAPass.js +1 -3
  126. package/examples/jsm/postprocessing/SSAARenderPass.js +3 -1
  127. package/examples/jsm/postprocessing/SSAOPass.js +2 -4
  128. package/examples/jsm/postprocessing/SSRPass.js +8 -4
  129. package/examples/jsm/postprocessing/UnrealBloomPass.js +2 -2
  130. package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
  131. package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
  132. package/examples/jsm/renderers/SVGRenderer.js +6 -4
  133. package/examples/jsm/shaders/BokehShader2.js +1 -1
  134. package/examples/jsm/shaders/FXAAShader.js +225 -224
  135. package/examples/jsm/shaders/GodRaysShader.js +3 -3
  136. package/examples/jsm/shaders/OutputShader.js +6 -2
  137. package/examples/jsm/shaders/SobelOperatorShader.js +1 -1
  138. package/examples/jsm/transpiler/AST.js +12 -2
  139. package/examples/jsm/transpiler/GLSLDecoder.js +77 -31
  140. package/examples/jsm/transpiler/ShaderToyDecoder.js +3 -3
  141. package/examples/jsm/transpiler/TSLEncoder.js +96 -21
  142. package/examples/jsm/tsl/display/AfterImageNode.js +243 -0
  143. package/examples/jsm/tsl/display/AnaglyphPassNode.js +106 -0
  144. package/examples/jsm/tsl/display/AnamorphicNode.js +257 -0
  145. package/{src/nodes/display/BleachBypassNode.js → examples/jsm/tsl/display/BleachBypass.js} +11 -6
  146. package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +252 -67
  147. package/examples/jsm/tsl/display/DenoiseNode.js +332 -0
  148. package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +92 -14
  149. package/examples/jsm/tsl/display/DotScreenNode.js +103 -0
  150. package/examples/jsm/tsl/display/FXAANode.js +364 -0
  151. package/examples/jsm/tsl/display/FilmNode.js +100 -0
  152. package/examples/jsm/tsl/display/GTAONode.js +521 -0
  153. package/examples/jsm/tsl/display/GaussianBlurNode.js +393 -0
  154. package/examples/jsm/tsl/display/LensflareNode.js +278 -0
  155. package/examples/jsm/tsl/display/Lut3DNode.js +108 -0
  156. package/examples/jsm/tsl/display/MotionBlur.js +33 -0
  157. package/examples/jsm/tsl/display/OutlineNode.js +750 -0
  158. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +88 -0
  159. package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +160 -28
  160. package/examples/jsm/tsl/display/RGBShiftNode.js +95 -0
  161. package/examples/jsm/tsl/display/SMAANode.js +767 -0
  162. package/examples/jsm/tsl/display/SSAAPassNode.js +357 -0
  163. package/examples/jsm/tsl/display/SSRNode.js +538 -0
  164. package/examples/jsm/tsl/display/Sepia.js +24 -0
  165. package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +66 -20
  166. package/examples/jsm/tsl/display/StereoCompositePassNode.js +184 -0
  167. package/examples/jsm/tsl/display/StereoPassNode.js +119 -0
  168. package/examples/jsm/tsl/display/TRAAPassNode.js +451 -0
  169. package/examples/jsm/tsl/display/TransitionNode.js +140 -0
  170. package/examples/jsm/tsl/display/hashBlur.js +34 -0
  171. package/examples/jsm/tsl/lighting/TiledLightsNode.js +395 -0
  172. package/examples/jsm/tsl/math/Bayer.js +18 -0
  173. package/examples/jsm/tsl/utils/Raymarching.js +65 -0
  174. package/examples/jsm/utils/BufferGeometryUtils.js +2 -2
  175. package/examples/jsm/utils/CameraUtils.js +4 -1
  176. package/examples/jsm/utils/GeometryCompressionUtils.js +38 -123
  177. package/examples/jsm/utils/GeometryUtils.js +22 -19
  178. package/examples/jsm/utils/SceneOptimizer.js +410 -0
  179. package/examples/jsm/utils/SceneUtils.js +2 -2
  180. package/examples/jsm/utils/ShadowMapViewer.js +3 -8
  181. package/examples/jsm/utils/ShadowMapViewerGPU.js +201 -0
  182. package/examples/jsm/utils/SkeletonUtils.js +84 -66
  183. package/examples/jsm/utils/UVsDebug.js +1 -1
  184. package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +1 -0
  185. package/examples/jsm/utils/WebGPUTextureUtils.js +64 -0
  186. package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
  187. package/examples/jsm/webxr/Text2D.js +6 -6
  188. package/examples/jsm/webxr/XRControllerModelFactory.js +7 -2
  189. package/examples/jsm/webxr/XREstimatedLight.js +1 -1
  190. package/package.json +14 -9
  191. package/src/Three.Core.js +182 -0
  192. package/src/Three.Legacy.js +0 -21
  193. package/src/Three.TSL.js +543 -0
  194. package/src/Three.WebGPU.Nodes.js +23 -0
  195. package/src/Three.WebGPU.js +13 -184
  196. package/src/Three.js +1 -176
  197. package/src/animation/AnimationClip.js +2 -2
  198. package/src/animation/AnimationObjectGroup.js +2 -2
  199. package/src/animation/AnimationUtils.js +1 -1
  200. package/src/animation/PropertyBinding.js +2 -2
  201. package/src/audio/Audio.js +379 -2
  202. package/src/audio/AudioAnalyser.js +58 -1
  203. package/src/audio/AudioContext.js +15 -0
  204. package/src/audio/AudioListener.js +76 -0
  205. package/src/audio/PositionalAudio.js +107 -0
  206. package/src/cameras/ArrayCamera.js +29 -0
  207. package/src/cameras/Camera.js +47 -0
  208. package/src/cameras/CubeCamera.js +66 -0
  209. package/src/cameras/OrthographicCamera.js +109 -0
  210. package/src/cameras/PerspectiveCamera.js +173 -34
  211. package/src/cameras/StereoCamera.js +48 -2
  212. package/src/constants.js +6 -6
  213. package/src/core/BufferAttribute.js +4 -9
  214. package/src/core/BufferGeometry.js +48 -8
  215. package/src/core/Clock.js +1 -1
  216. package/src/core/EventDispatcher.js +52 -8
  217. package/src/core/InterleavedBuffer.js +4 -13
  218. package/src/core/Object3D.js +573 -3
  219. package/src/core/RenderTarget.js +22 -4
  220. package/src/core/RenderTarget3D.js +22 -0
  221. package/src/core/RenderTargetArray.js +22 -0
  222. package/src/extras/Controls.js +104 -0
  223. package/src/extras/DataUtils.js +48 -8
  224. package/src/extras/Earcut.js +18 -7
  225. package/src/extras/ImageUtils.js +18 -11
  226. package/src/extras/PMREMGenerator.js +40 -9
  227. package/src/extras/ShapeUtils.js +24 -2
  228. package/src/extras/TextureUtils.js +96 -10
  229. package/src/extras/core/Curve.js +153 -53
  230. package/src/extras/core/CurvePath.js +63 -22
  231. package/src/extras/core/Interpolations.js +29 -3
  232. package/src/extras/core/Path.js +134 -1
  233. package/src/extras/core/Shape.js +66 -3
  234. package/src/extras/core/ShapePath.js +76 -0
  235. package/src/extras/curves/ArcCurve.js +22 -0
  236. package/src/extras/curves/CatmullRomCurve3.js +89 -18
  237. package/src/extras/curves/CubicBezierCurve.js +67 -0
  238. package/src/extras/curves/CubicBezierCurve3.js +50 -0
  239. package/src/extras/curves/EllipseCurve.js +102 -0
  240. package/src/extras/curves/LineCurve.js +36 -0
  241. package/src/extras/curves/LineCurve3.js +36 -0
  242. package/src/extras/curves/QuadraticBezierCurve.js +59 -0
  243. package/src/extras/curves/QuadraticBezierCurve3.js +43 -0
  244. package/src/extras/curves/SplineCurve.js +48 -0
  245. package/src/geometries/BoxGeometry.js +38 -0
  246. package/src/geometries/CapsuleGeometry.js +34 -0
  247. package/src/geometries/CircleGeometry.js +40 -0
  248. package/src/geometries/ConeGeometry.js +38 -0
  249. package/src/geometries/CylinderGeometry.js +50 -4
  250. package/src/geometries/DodecahedronGeometry.js +32 -0
  251. package/src/geometries/EdgesGeometry.js +30 -2
  252. package/src/geometries/ExtrudeGeometry.js +52 -0
  253. package/src/geometries/IcosahedronGeometry.js +32 -0
  254. package/src/geometries/LatheGeometry.js +43 -3
  255. package/src/geometries/OctahedronGeometry.js +32 -0
  256. package/src/geometries/PlaneGeometry.js +34 -0
  257. package/src/geometries/PolyhedronGeometry.js +29 -0
  258. package/src/geometries/RingGeometry.js +36 -0
  259. package/src/geometries/ShapeGeometry.js +37 -0
  260. package/src/geometries/SphereGeometry.js +37 -0
  261. package/src/geometries/TetrahedronGeometry.js +32 -0
  262. package/src/geometries/TorusGeometry.js +35 -0
  263. package/src/geometries/TorusKnotGeometry.js +38 -0
  264. package/src/geometries/TubeGeometry.js +49 -0
  265. package/src/geometries/WireframeGeometry.js +32 -0
  266. package/src/helpers/ArrowHelper.js +60 -3
  267. package/src/helpers/AxesHelper.js +28 -0
  268. package/src/helpers/Box3Helper.js +28 -0
  269. package/src/helpers/BoxHelper.js +43 -7
  270. package/src/helpers/CameraHelper.js +61 -18
  271. package/src/helpers/DirectionalLightHelper.js +52 -0
  272. package/src/helpers/GridHelper.js +26 -0
  273. package/src/helpers/HemisphereLightHelper.js +39 -0
  274. package/src/helpers/PlaneHelper.js +33 -0
  275. package/src/helpers/PointLightHelper.js +43 -0
  276. package/src/helpers/PolarGridHelper.js +30 -0
  277. package/src/helpers/SkeletonHelper.js +39 -2
  278. package/src/helpers/SpotLightHelper.js +40 -0
  279. package/src/lights/AmbientLight.js +25 -0
  280. package/src/lights/DirectionalLight.js +57 -0
  281. package/src/lights/DirectionalLightShadow.js +15 -0
  282. package/src/lights/HemisphereLight.js +32 -0
  283. package/src/lights/Light.js +36 -0
  284. package/src/lights/LightProbe.js +43 -0
  285. package/src/lights/LightShadow.js +159 -0
  286. package/src/lights/PointLight.js +59 -0
  287. package/src/lights/PointLightShadow.js +21 -0
  288. package/src/lights/RectAreaLight.js +59 -0
  289. package/src/lights/SpotLight.js +102 -0
  290. package/src/lights/SpotLightShadow.js +24 -2
  291. package/src/lights/webgpu/IESSpotLight.js +21 -0
  292. package/src/loaders/Loader.js +132 -0
  293. package/src/loaders/MaterialLoader.js +7 -1
  294. package/src/loaders/nodes/NodeLoader.js +189 -0
  295. package/src/loaders/nodes/NodeMaterialLoader.js +108 -0
  296. package/src/loaders/nodes/NodeObjectLoader.js +151 -0
  297. package/src/materials/LineDashedMaterial.js +0 -1
  298. package/src/materials/Material.js +469 -7
  299. package/src/materials/MeshPhongMaterial.js +1 -1
  300. package/src/materials/MeshPhysicalMaterial.js +2 -2
  301. package/src/materials/MeshStandardMaterial.js +2 -2
  302. package/src/{nodes/materials → materials/nodes}/Line2NodeMaterial.js +192 -82
  303. package/src/materials/nodes/LineBasicNodeMaterial.js +46 -0
  304. package/src/materials/nodes/LineDashedNodeMaterial.js +132 -0
  305. package/src/materials/nodes/MeshBasicNodeMaterial.js +133 -0
  306. package/src/materials/nodes/MeshLambertNodeMaterial.js +82 -0
  307. package/src/materials/nodes/MeshMatcapNodeMaterial.js +77 -0
  308. package/src/materials/nodes/MeshNormalNodeMaterial.js +67 -0
  309. package/src/materials/nodes/MeshPhongNodeMaterial.js +141 -0
  310. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +517 -0
  311. package/src/materials/nodes/MeshSSSNodeMaterial.js +175 -0
  312. package/src/materials/nodes/MeshStandardNodeMaterial.js +186 -0
  313. package/src/materials/nodes/MeshToonNodeMaterial.js +66 -0
  314. package/src/materials/nodes/NodeMaterial.js +1180 -0
  315. package/src/{nodes/materials/Materials.js → materials/nodes/NodeMaterials.js} +3 -2
  316. package/src/materials/nodes/PointsNodeMaterial.js +153 -0
  317. package/src/materials/nodes/ShadowNodeMaterial.js +67 -0
  318. package/src/materials/nodes/SpriteNodeMaterial.js +198 -0
  319. package/src/materials/nodes/VolumeNodeMaterial.js +72 -0
  320. package/src/materials/nodes/manager/NodeMaterialObserver.js +509 -0
  321. package/src/math/Box2.js +177 -0
  322. package/src/math/Box3.js +243 -0
  323. package/src/math/Color.js +343 -0
  324. package/src/math/ColorManagement.js +143 -102
  325. package/src/math/Cylindrical.js +65 -6
  326. package/src/math/Euler.js +137 -4
  327. package/src/math/Frustum.js +83 -0
  328. package/src/math/Interpolant.js +87 -8
  329. package/src/math/Line3.js +96 -2
  330. package/src/math/MathUtils.js +182 -19
  331. package/src/math/Matrix2.js +70 -0
  332. package/src/math/Matrix3.js +229 -4
  333. package/src/math/Matrix4.js +368 -3
  334. package/src/math/Plane.js +164 -2
  335. package/src/math/Quaternion.js +265 -9
  336. package/src/math/Ray.js +160 -0
  337. package/src/math/Sphere.js +147 -0
  338. package/src/math/Spherical.js +73 -11
  339. package/src/math/SphericalHarmonics3.js +112 -14
  340. package/src/math/Triangle.js +230 -2
  341. package/src/math/Vector2.js +396 -10
  342. package/src/math/Vector3.js +550 -13
  343. package/src/math/Vector4.js +415 -9
  344. package/src/math/interpolants/CubicInterpolant.js +10 -1
  345. package/src/math/interpolants/DiscreteInterpolant.js +10 -2
  346. package/src/math/interpolants/LinearInterpolant.js +13 -0
  347. package/src/math/interpolants/QuaternionLinearInterpolant.js +10 -1
  348. package/src/nodes/Nodes.js +84 -166
  349. package/src/nodes/TSL.js +167 -0
  350. package/src/nodes/accessors/AccessorsUtils.js +39 -10
  351. package/src/nodes/accessors/Arrays.js +68 -0
  352. package/src/nodes/accessors/BatchNode.js +93 -26
  353. package/src/nodes/accessors/Bitangent.js +54 -0
  354. package/src/nodes/accessors/BufferAttributeNode.js +189 -11
  355. package/src/nodes/accessors/BufferNode.js +70 -5
  356. package/src/nodes/accessors/BuiltinNode.js +63 -0
  357. package/src/nodes/accessors/Camera.js +129 -0
  358. package/src/nodes/accessors/ClippingNode.js +152 -43
  359. package/src/nodes/accessors/CubeTextureNode.js +76 -13
  360. package/src/nodes/accessors/InstanceNode.js +118 -35
  361. package/src/nodes/accessors/InstancedMeshNode.js +50 -0
  362. package/src/nodes/accessors/Lights.js +129 -0
  363. package/src/nodes/accessors/MaterialNode.js +394 -58
  364. package/src/nodes/accessors/MaterialProperties.js +57 -1
  365. package/src/nodes/accessors/MaterialReferenceNode.js +60 -18
  366. package/src/nodes/accessors/ModelNode.js +159 -12
  367. package/src/nodes/accessors/ModelViewProjectionNode.js +10 -36
  368. package/src/nodes/accessors/MorphNode.js +60 -13
  369. package/src/nodes/accessors/Normal.js +156 -0
  370. package/src/nodes/accessors/Object3DNode.js +154 -35
  371. package/src/nodes/accessors/PointUVNode.js +35 -6
  372. package/src/nodes/accessors/Position.js +64 -0
  373. package/src/nodes/accessors/ReferenceBaseNode.js +357 -0
  374. package/src/nodes/accessors/ReferenceNode.js +243 -6
  375. package/src/nodes/accessors/ReflectVector.js +36 -0
  376. package/src/nodes/accessors/RendererReferenceNode.js +57 -7
  377. package/src/nodes/accessors/SceneNode.js +98 -6
  378. package/src/nodes/accessors/SkinningNode.js +214 -21
  379. package/src/nodes/accessors/StorageBufferNode.js +288 -28
  380. package/src/nodes/accessors/StorageTextureNode.js +139 -12
  381. package/src/nodes/accessors/Tangent.js +62 -0
  382. package/src/nodes/accessors/Texture3DNode.js +98 -12
  383. package/src/nodes/accessors/{TextureBicubicNode.js → TextureBicubic.js} +14 -34
  384. package/src/nodes/accessors/TextureNode.js +347 -34
  385. package/src/nodes/accessors/TextureSizeNode.js +51 -9
  386. package/src/nodes/accessors/UV.js +11 -0
  387. package/src/nodes/accessors/UniformArrayNode.js +241 -32
  388. package/src/nodes/accessors/UserDataNode.js +55 -7
  389. package/src/nodes/accessors/VelocityNode.js +223 -0
  390. package/src/nodes/accessors/VertexColorNode.js +45 -6
  391. package/src/nodes/code/CodeNode.js +108 -8
  392. package/src/nodes/code/ExpressionNode.js +38 -7
  393. package/src/nodes/code/FunctionCallNode.js +62 -11
  394. package/src/nodes/code/FunctionNode.js +54 -24
  395. package/src/nodes/code/ScriptableNode.js +241 -17
  396. package/src/nodes/code/ScriptableValueNode.js +93 -8
  397. package/src/nodes/core/ArrayNode.js +142 -0
  398. package/src/nodes/core/AssignNode.js +60 -12
  399. package/src/nodes/core/AttributeNode.js +55 -22
  400. package/src/nodes/core/BypassNode.js +59 -11
  401. package/src/nodes/core/CacheNode.js +64 -10
  402. package/src/nodes/core/ConstNode.js +38 -3
  403. package/src/nodes/core/ContextNode.js +87 -12
  404. package/src/nodes/core/IndexNode.js +102 -10
  405. package/src/nodes/core/InputNode.js +55 -3
  406. package/src/nodes/core/LightingModel.js +65 -5
  407. package/src/nodes/core/MRTNode.js +81 -7
  408. package/src/nodes/core/Node.js +368 -50
  409. package/src/nodes/core/NodeAttribute.js +38 -0
  410. package/src/nodes/core/NodeBuilder.js +1317 -83
  411. package/src/nodes/core/NodeCache.js +41 -2
  412. package/src/nodes/core/NodeCode.js +31 -0
  413. package/src/nodes/core/NodeFrame.js +123 -2
  414. package/src/nodes/core/NodeFunction.js +46 -0
  415. package/src/nodes/core/NodeFunctionInput.js +44 -0
  416. package/src/nodes/core/NodeParser.js +11 -0
  417. package/src/nodes/core/NodeUniform.js +52 -0
  418. package/src/nodes/core/NodeUtils.js +226 -6
  419. package/src/nodes/core/NodeVar.js +47 -1
  420. package/src/nodes/core/NodeVarying.js +28 -0
  421. package/src/nodes/core/OutputStructNode.js +61 -17
  422. package/src/nodes/core/ParameterNode.js +34 -4
  423. package/src/nodes/core/PropertyNode.js +296 -32
  424. package/src/nodes/core/StackNode.js +108 -8
  425. package/src/nodes/core/StructNode.js +120 -0
  426. package/src/nodes/core/StructType.js +13 -0
  427. package/src/nodes/core/StructTypeNode.js +116 -9
  428. package/src/nodes/core/TempNode.js +37 -7
  429. package/src/nodes/core/UniformGroupNode.js +98 -17
  430. package/src/nodes/core/UniformNode.js +72 -4
  431. package/src/nodes/core/VarNode.js +170 -13
  432. package/src/nodes/core/VaryingNode.js +109 -8
  433. package/src/nodes/core/constants.js +40 -0
  434. package/src/nodes/display/BlendModes.js +193 -0
  435. package/src/nodes/display/BumpMapNode.js +47 -10
  436. package/src/nodes/display/ColorAdjustment.js +141 -0
  437. package/src/nodes/display/ColorSpaceFunctions.js +54 -0
  438. package/src/nodes/display/ColorSpaceNode.js +147 -68
  439. package/src/nodes/display/FrontFacingNode.js +39 -6
  440. package/src/nodes/display/NormalMapNode.js +55 -13
  441. package/src/nodes/display/PassNode.js +420 -19
  442. package/src/nodes/display/PosterizeNode.js +40 -7
  443. package/src/nodes/display/RenderOutputNode.js +81 -13
  444. package/src/nodes/display/ScreenNode.js +286 -0
  445. package/src/nodes/display/ToneMappingFunctions.js +242 -0
  446. package/src/nodes/display/ToneMappingNode.js +68 -175
  447. package/src/nodes/display/ToonOutlinePassNode.js +183 -0
  448. package/src/nodes/display/ViewportDepthNode.js +210 -36
  449. package/src/nodes/display/ViewportDepthTextureNode.js +32 -9
  450. package/src/nodes/display/ViewportSharedTextureNode.js +32 -9
  451. package/src/nodes/display/ViewportTextureNode.js +68 -11
  452. package/src/nodes/fog/Fog.js +113 -0
  453. package/src/nodes/functions/BSDF/BRDF_GGX.js +4 -4
  454. package/src/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
  455. package/src/nodes/functions/BSDF/BRDF_Sheen.js +6 -6
  456. package/src/nodes/functions/BSDF/DFGApprox.js +2 -2
  457. package/src/nodes/functions/BSDF/D_GGX.js +2 -2
  458. package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +3 -3
  459. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
  460. package/src/nodes/functions/BSDF/F_Schlick.js +2 -2
  461. package/src/nodes/functions/BSDF/LTC.js +50 -6
  462. package/src/nodes/functions/BSDF/Schlick_to_F0.js +2 -2
  463. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +2 -2
  464. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
  465. package/src/nodes/functions/BasicLightingModel.js +27 -6
  466. package/src/nodes/functions/PhongLightingModel.js +38 -8
  467. package/src/nodes/functions/PhysicalLightingModel.js +215 -51
  468. package/src/nodes/functions/ShadowMaskModel.js +24 -1
  469. package/src/nodes/functions/ToonLightingModel.js +24 -5
  470. package/src/nodes/functions/VolumetricLightingModel.js +183 -0
  471. package/src/nodes/functions/material/getAlphaHashThreshold.js +68 -0
  472. package/src/nodes/functions/material/getGeometryRoughness.js +10 -4
  473. package/src/nodes/functions/material/getParallaxCorrectNormal.js +37 -0
  474. package/src/nodes/functions/material/getRoughness.js +2 -2
  475. package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
  476. package/src/nodes/geometry/RangeNode.js +62 -7
  477. package/src/nodes/gpgpu/AtomicFunctionNode.js +280 -0
  478. package/src/nodes/gpgpu/BarrierNode.js +89 -0
  479. package/src/nodes/gpgpu/ComputeBuiltinNode.js +227 -0
  480. package/src/nodes/gpgpu/ComputeNode.js +124 -9
  481. package/src/nodes/gpgpu/WorkgroupInfoNode.js +208 -0
  482. package/src/nodes/lighting/AONode.js +24 -3
  483. package/src/nodes/lighting/AmbientLightNode.js +16 -8
  484. package/src/nodes/lighting/AnalyticLightNode.js +151 -231
  485. package/src/nodes/lighting/BasicEnvironmentNode.js +25 -3
  486. package/src/nodes/lighting/BasicLightMapNode.js +25 -5
  487. package/src/nodes/lighting/DirectionalLightNode.js +19 -20
  488. package/src/nodes/lighting/EnvironmentNode.js +34 -17
  489. package/src/nodes/lighting/HemisphereLightNode.js +42 -11
  490. package/src/nodes/lighting/IESSpotLightNode.js +18 -9
  491. package/src/nodes/lighting/IrradianceNode.js +23 -3
  492. package/src/nodes/lighting/LightProbeNode.js +29 -36
  493. package/src/nodes/lighting/LightUtils.js +12 -4
  494. package/src/nodes/lighting/LightingContextNode.js +70 -21
  495. package/src/nodes/lighting/LightingNode.js +22 -9
  496. package/src/nodes/lighting/LightsNode.js +309 -86
  497. package/src/nodes/lighting/PointLightNode.js +66 -32
  498. package/src/nodes/lighting/PointShadowNode.js +306 -0
  499. package/src/nodes/lighting/RectAreaLightNode.js +61 -25
  500. package/src/nodes/lighting/ShadowBaseNode.js +92 -0
  501. package/src/nodes/lighting/ShadowNode.js +812 -0
  502. package/src/nodes/lighting/SpotLightNode.js +73 -31
  503. package/src/nodes/materialx/MaterialXNodes.js +2 -2
  504. package/src/nodes/materialx/lib/mx_hsv.js +27 -22
  505. package/src/nodes/materialx/lib/mx_noise.js +70 -70
  506. package/src/nodes/materialx/lib/mx_transform_color.js +2 -2
  507. package/src/nodes/math/ConditionalNode.js +230 -0
  508. package/src/nodes/math/Hash.js +21 -0
  509. package/src/nodes/math/MathNode.js +812 -131
  510. package/src/nodes/math/MathUtils.js +47 -8
  511. package/src/nodes/math/OperatorNode.js +410 -66
  512. package/src/nodes/math/TriNoise3D.js +32 -32
  513. package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
  514. package/src/nodes/parsers/GLSLNodeParser.js +11 -0
  515. package/src/nodes/pmrem/PMREMNode.js +188 -28
  516. package/src/nodes/pmrem/PMREMUtils.js +24 -24
  517. package/src/nodes/procedural/Checker.js +22 -0
  518. package/src/nodes/shapes/Shapes.js +32 -0
  519. package/src/nodes/tsl/TSLBase.js +31 -0
  520. package/src/nodes/{shadernode/ShaderNode.js → tsl/TSLCore.js} +114 -98
  521. package/src/nodes/utils/ArrayElementNode.js +45 -5
  522. package/src/nodes/utils/ConvertNode.js +39 -4
  523. package/src/nodes/utils/CubeMapNode.js +88 -8
  524. package/src/nodes/utils/Discard.js +24 -0
  525. package/src/nodes/utils/EquirectUVNode.js +39 -7
  526. package/src/nodes/utils/FlipNode.js +106 -0
  527. package/src/nodes/utils/FunctionOverloadingNode.js +61 -6
  528. package/src/nodes/utils/JoinNode.js +31 -3
  529. package/src/nodes/utils/LoopNode.js +95 -9
  530. package/src/nodes/utils/MatcapUVNode.js +27 -8
  531. package/src/nodes/utils/MaxMipLevelNode.js +57 -6
  532. package/src/nodes/utils/MemberNode.js +68 -0
  533. package/src/nodes/utils/Oscillators.js +41 -0
  534. package/src/nodes/utils/Packing.js +21 -0
  535. package/src/nodes/utils/PostProcessingUtils.js +95 -0
  536. package/src/nodes/utils/RTTNode.js +141 -9
  537. package/src/nodes/utils/ReflectorNode.js +295 -21
  538. package/src/nodes/utils/RemapNode.js +93 -10
  539. package/src/nodes/utils/RotateNode.js +48 -13
  540. package/src/nodes/utils/SetNode.js +50 -4
  541. package/src/nodes/utils/SplitNode.js +62 -6
  542. package/src/nodes/utils/SpriteSheetUVNode.js +56 -7
  543. package/src/nodes/utils/SpriteUtils.js +21 -5
  544. package/src/nodes/utils/StorageArrayElementNode.js +64 -12
  545. package/src/nodes/utils/Timer.js +73 -0
  546. package/src/nodes/utils/TriplanarTexturesNode.js +96 -10
  547. package/src/nodes/utils/UVUtils.js +27 -9
  548. package/src/nodes/utils/ViewportUtils.js +16 -4
  549. package/src/objects/BatchedMesh.js +808 -281
  550. package/src/objects/Bone.js +24 -0
  551. package/src/objects/ClippingGroup.js +68 -0
  552. package/src/objects/Group.js +24 -0
  553. package/src/objects/InstancedMesh.js +120 -2
  554. package/src/objects/LOD.js +120 -5
  555. package/src/objects/Line.js +89 -6
  556. package/src/objects/LineLoop.js +20 -0
  557. package/src/objects/LineSegments.js +18 -0
  558. package/src/objects/Mesh.js +82 -23
  559. package/src/objects/Points.js +62 -0
  560. package/src/objects/Skeleton.js +107 -2
  561. package/src/objects/SkinnedMesh.js +99 -5
  562. package/src/objects/Sprite.js +54 -0
  563. package/src/renderers/WebGLRenderer.js +274 -157
  564. package/src/renderers/common/Animation.js +109 -12
  565. package/src/renderers/common/Attributes.js +40 -0
  566. package/src/renderers/common/Backend.js +504 -44
  567. package/src/renderers/common/Background.js +67 -9
  568. package/src/renderers/common/BindGroup.js +45 -1
  569. package/src/renderers/common/Binding.js +35 -0
  570. package/src/renderers/common/Bindings.js +136 -19
  571. package/src/renderers/common/Buffer.js +49 -0
  572. package/src/renderers/common/BufferUtils.js +25 -0
  573. package/src/renderers/common/BundleGroup.js +83 -0
  574. package/src/renderers/common/ChainMap.js +45 -6
  575. package/src/renderers/common/ClippingContext.js +175 -80
  576. package/src/renderers/common/Color4.js +40 -0
  577. package/src/renderers/common/ComputePipeline.js +24 -0
  578. package/src/renderers/common/Constants.js +2 -1
  579. package/src/renderers/common/CubeRenderTarget.js +22 -3
  580. package/src/renderers/common/DataMap.js +37 -1
  581. package/src/renderers/common/Geometries.js +111 -14
  582. package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
  583. package/src/renderers/common/Info.js +78 -35
  584. package/src/renderers/common/Lighting.js +73 -0
  585. package/src/renderers/common/Pipeline.js +22 -0
  586. package/src/renderers/common/Pipelines.js +148 -5
  587. package/src/renderers/common/PostProcessing.js +112 -11
  588. package/src/renderers/common/ProgrammableStage.js +60 -2
  589. package/src/renderers/common/QuadMesh.js +56 -5
  590. package/src/renderers/common/RenderBundle.js +14 -8
  591. package/src/renderers/common/RenderBundles.js +39 -10
  592. package/src/renderers/common/RenderContext.js +205 -7
  593. package/src/renderers/common/RenderContexts.js +59 -6
  594. package/src/renderers/common/RenderList.js +230 -21
  595. package/src/renderers/common/RenderLists.js +45 -6
  596. package/src/renderers/common/RenderObject.js +552 -41
  597. package/src/renderers/common/RenderObjects.js +118 -9
  598. package/src/renderers/common/RenderPipeline.js +24 -0
  599. package/src/renderers/common/Renderer.js +1537 -239
  600. package/src/renderers/common/RendererUtils.js +191 -0
  601. package/src/renderers/common/SampledTexture.js +132 -3
  602. package/src/renderers/common/Sampler.js +30 -0
  603. package/src/renderers/common/StorageBuffer.js +24 -0
  604. package/src/renderers/common/StorageBufferAttribute.js +31 -2
  605. package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
  606. package/src/renderers/common/StorageTexture.js +38 -0
  607. package/src/renderers/common/Textures.js +142 -32
  608. package/src/renderers/common/TimestampQueryPool.js +98 -0
  609. package/src/renderers/common/Uniform.js +225 -3
  610. package/src/renderers/common/UniformBuffer.js +19 -0
  611. package/src/renderers/common/UniformsGroup.js +157 -6
  612. package/src/renderers/common/XRManager.js +1185 -0
  613. package/src/renderers/common/XRRenderTarget.js +74 -0
  614. package/src/renderers/common/extras/PMREMGenerator.js +211 -53
  615. package/src/renderers/common/nodes/NodeBuilderState.js +100 -6
  616. package/src/renderers/common/nodes/NodeLibrary.js +194 -0
  617. package/src/renderers/common/nodes/NodeSampledTexture.js +92 -4
  618. package/src/renderers/common/nodes/NodeSampler.js +28 -0
  619. package/src/renderers/common/nodes/NodeStorageBuffer.js +37 -3
  620. package/src/renderers/common/nodes/NodeUniform.js +285 -2
  621. package/src/renderers/common/nodes/NodeUniformBuffer.js +29 -0
  622. package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
  623. package/src/renderers/common/nodes/Nodes.js +390 -70
  624. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
  625. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
  626. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
  627. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
  628. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +2 -2
  629. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
  630. package/src/renderers/shaders/ShaderLib/sprite.glsl.js +2 -4
  631. package/src/renderers/webgl/WebGLAttributes.js +45 -14
  632. package/src/renderers/webgl/WebGLBackground.js +24 -1
  633. package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
  634. package/src/renderers/webgl/WebGLCapabilities.js +2 -0
  635. package/src/renderers/webgl/WebGLGeometries.js +0 -28
  636. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
  637. package/src/renderers/webgl/WebGLProgram.js +27 -29
  638. package/src/renderers/webgl/WebGLPrograms.js +24 -16
  639. package/src/renderers/webgl/WebGLState.js +68 -11
  640. package/src/renderers/webgl/WebGLTextures.js +49 -10
  641. package/src/renderers/webgl-fallback/WebGLBackend.js +1055 -238
  642. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +5 -10
  643. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +425 -48
  644. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +64 -1
  645. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
  646. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
  647. package/src/renderers/webgl-fallback/utils/WebGLState.js +419 -14
  648. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +281 -59
  649. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +367 -0
  650. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
  651. package/src/renderers/webgpu/WebGPUBackend.js +816 -236
  652. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +78 -0
  653. package/src/renderers/webgpu/WebGPURenderer.js +45 -6
  654. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +63 -0
  655. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +97 -0
  656. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +954 -147
  657. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +29 -4
  658. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
  659. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +147 -31
  660. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +213 -31
  661. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +146 -28
  662. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +161 -7
  663. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +333 -50
  664. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +287 -0
  665. package/src/renderers/webgpu/utils/WebGPUUtils.js +131 -3
  666. package/src/renderers/webxr/WebXRDepthSensing.js +1 -1
  667. package/src/renderers/webxr/WebXRManager.js +54 -32
  668. package/src/scenes/Fog.js +60 -0
  669. package/src/scenes/FogExp2.js +51 -0
  670. package/src/scenes/Scene.js +87 -0
  671. package/src/textures/Data3DTexture.js +2 -2
  672. package/src/textures/DepthTexture.js +2 -0
  673. package/src/textures/Source.js +2 -2
  674. package/src/textures/Texture.js +368 -5
  675. package/src/textures/VideoFrameTexture.js +35 -0
  676. package/src/utils.js +33 -1
  677. package/examples/jsm/animation/MMDAnimationHelper.js +0 -1207
  678. package/examples/jsm/animation/MMDPhysics.js +0 -1406
  679. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  680. package/examples/jsm/controls/Controls.js +0 -32
  681. package/examples/jsm/exporters/MMDExporter.js +0 -217
  682. package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -174
  683. package/examples/jsm/geometries/SDFGeometryGenerator.js +0 -144
  684. package/examples/jsm/libs/mmdparser.module.js +0 -11530
  685. package/examples/jsm/loaders/LogLuvLoader.js +0 -606
  686. package/examples/jsm/loaders/MMDLoader.js +0 -2295
  687. package/examples/jsm/loaders/TiltLoader.js +0 -520
  688. package/examples/jsm/objects/InstancedPoints.js +0 -21
  689. package/examples/jsm/shaders/MMDToonShader.js +0 -134
  690. package/examples/jsm/utils/GPUStatsPanel.js +0 -95
  691. package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
  692. package/src/nodes/accessors/BitangentNode.js +0 -13
  693. package/src/nodes/accessors/CameraNode.js +0 -19
  694. package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -21
  695. package/src/nodes/accessors/NormalNode.js +0 -14
  696. package/src/nodes/accessors/PositionNode.js +0 -10
  697. package/src/nodes/accessors/ReflectVectorNode.js +0 -10
  698. package/src/nodes/accessors/TangentNode.js +0 -23
  699. package/src/nodes/accessors/UVNode.js +0 -3
  700. package/src/nodes/core/NodeKeywords.js +0 -80
  701. package/src/nodes/core/UniformGroup.js +0 -13
  702. package/src/nodes/display/AfterImageNode.js +0 -152
  703. package/src/nodes/display/AnamorphicNode.js +0 -145
  704. package/src/nodes/display/BlendModeNode.js +0 -128
  705. package/src/nodes/display/ColorAdjustmentNode.js +0 -104
  706. package/src/nodes/display/DenoiseNode.js +0 -198
  707. package/src/nodes/display/DotScreenNode.js +0 -75
  708. package/src/nodes/display/FXAANode.js +0 -327
  709. package/src/nodes/display/FilmNode.js +0 -52
  710. package/src/nodes/display/GTAONode.js +0 -324
  711. package/src/nodes/display/GaussianBlurNode.js +0 -207
  712. package/src/nodes/display/Lut3DNode.js +0 -53
  713. package/src/nodes/display/RGBShiftNode.js +0 -49
  714. package/src/nodes/display/SepiaNode.js +0 -18
  715. package/src/nodes/display/TransitionNode.js +0 -76
  716. package/src/nodes/display/ViewportNode.js +0 -137
  717. package/src/nodes/fog/FogExp2Node.js +0 -34
  718. package/src/nodes/fog/FogNode.js +0 -48
  719. package/src/nodes/fog/FogRangeNode.js +0 -35
  720. package/src/nodes/lighting/LightNode.js +0 -57
  721. package/src/nodes/loaders/NodeLoader.js +0 -110
  722. package/src/nodes/loaders/NodeMaterialLoader.js +0 -60
  723. package/src/nodes/loaders/NodeObjectLoader.js +0 -71
  724. package/src/nodes/materials/InstancedPointsNodeMaterial.js +0 -162
  725. package/src/nodes/materials/LineBasicNodeMaterial.js +0 -28
  726. package/src/nodes/materials/LineDashedNodeMaterial.js +0 -55
  727. package/src/nodes/materials/MeshBasicNodeMaterial.js +0 -73
  728. package/src/nodes/materials/MeshLambertNodeMaterial.js +0 -43
  729. package/src/nodes/materials/MeshMatcapNodeMaterial.js +0 -53
  730. package/src/nodes/materials/MeshNormalNodeMaterial.js +0 -40
  731. package/src/nodes/materials/MeshPhongNodeMaterial.js +0 -74
  732. package/src/nodes/materials/MeshPhysicalNodeMaterial.js +0 -244
  733. package/src/nodes/materials/MeshSSSNodeMaterial.js +0 -84
  734. package/src/nodes/materials/MeshStandardNodeMaterial.js +0 -104
  735. package/src/nodes/materials/MeshToonNodeMaterial.js +0 -34
  736. package/src/nodes/materials/NodeMaterial.js +0 -680
  737. package/src/nodes/materials/PointsNodeMaterial.js +0 -39
  738. package/src/nodes/materials/ShadowNodeMaterial.js +0 -34
  739. package/src/nodes/materials/SpriteNodeMaterial.js +0 -90
  740. package/src/nodes/materials/VolumeNodeMaterial.js +0 -106
  741. package/src/nodes/math/CondNode.js +0 -139
  742. package/src/nodes/math/HashNode.js +0 -34
  743. package/src/nodes/procedural/CheckerNode.js +0 -42
  744. package/src/nodes/utils/DiscardNode.js +0 -28
  745. package/src/nodes/utils/OscNode.js +0 -81
  746. package/src/nodes/utils/PackingNode.js +0 -55
  747. package/src/nodes/utils/TimerNode.js +0 -94
@@ -3,47 +3,37 @@ import NodeAttribute from './NodeAttribute.js';
3
3
  import NodeVarying from './NodeVarying.js';
4
4
  import NodeVar from './NodeVar.js';
5
5
  import NodeCode from './NodeCode.js';
6
- import NodeKeywords from './NodeKeywords.js';
7
6
  import NodeCache from './NodeCache.js';
8
7
  import ParameterNode from './ParameterNode.js';
8
+ import StructType from './StructType.js';
9
9
  import FunctionNode from '../code/FunctionNode.js';
10
- import { createNodeMaterialFromType, default as NodeMaterial } from '../materials/NodeMaterial.js';
10
+ import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
11
+ import { getTypeFromLength } from './NodeUtils.js';
11
12
  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';
19
- import { getCurrentStack, setCurrentStack } from '../shadernode/ShaderNode.js';
20
+ import { getCurrentStack, setCurrentStack } from '../tsl/TSLBase.js';
20
21
 
21
22
  import CubeRenderTarget from '../../renderers/common/CubeRenderTarget.js';
22
23
  import ChainMap from '../../renderers/common/ChainMap.js';
23
24
 
24
- import PMREMGenerator from '../../renderers/common/extras/PMREMGenerator.js';
25
-
26
25
  import BindGroup from '../../renderers/common/BindGroup.js';
27
26
 
28
- import { REVISION } from '../../constants.js';
27
+ import { REVISION, IntType, UnsignedIntType, LinearFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapLinearFilter } from '../../constants.js';
29
28
  import { RenderTarget } from '../../core/RenderTarget.js';
30
29
  import { Color } from '../../math/Color.js';
31
30
  import { Vector2 } from '../../math/Vector2.js';
32
31
  import { Vector3 } from '../../math/Vector3.js';
33
32
  import { Vector4 } from '../../math/Vector4.js';
34
33
  import { Float16BufferAttribute } from '../../core/BufferAttribute.js';
35
- import { IntType, UnsignedIntType, LinearFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapLinearFilter } from '../../constants.js';
36
34
 
37
35
  const rendererCache = new WeakMap();
38
36
 
39
- const typeFromLength = new Map( [
40
- [ 2, 'vec2' ],
41
- [ 3, 'vec3' ],
42
- [ 4, 'vec4' ],
43
- [ 9, 'mat3' ],
44
- [ 16, 'mat4' ]
45
- ] );
46
-
47
37
  const typeFromArray = new Map( [
48
38
  [ Int8Array, 'int' ],
49
39
  [ Int16Array, 'int' ],
@@ -56,79 +46,385 @@ const typeFromArray = new Map( [
56
46
 
57
47
  const toFloat = ( value ) => {
58
48
 
59
- value = Number( value );
49
+ if ( /e/g.test( value ) ) {
50
+
51
+ return String( value ).replace( /\+/g, '' );
60
52
 
61
- return value + ( value % 1 ? '' : '.0' );
53
+ } else {
54
+
55
+ value = Number( value );
56
+
57
+ return value + ( value % 1 ? '' : '.0' );
58
+
59
+ }
62
60
 
63
61
  };
64
62
 
63
+ /**
64
+ * Base class for builders which generate a shader program based
65
+ * on a 3D object and its node material definition.
66
+ */
65
67
  class NodeBuilder {
66
68
 
69
+ /**
70
+ * Constructs a new node builder.
71
+ *
72
+ * @param {Object3D} object - The 3D object.
73
+ * @param {Renderer} renderer - The current renderer.
74
+ * @param {NodeParser} parser - A reference to a node parser.
75
+ */
67
76
  constructor( object, renderer, parser ) {
68
77
 
78
+ /**
79
+ * The 3D object.
80
+ *
81
+ * @type {Object3D}
82
+ */
69
83
  this.object = object;
84
+
85
+ /**
86
+ * The material of the 3D object.
87
+ *
88
+ * @type {?Material}
89
+ */
70
90
  this.material = ( object && object.material ) || null;
91
+
92
+ /**
93
+ * The geometry of the 3D object.
94
+ *
95
+ * @type {?BufferGeometry}
96
+ */
71
97
  this.geometry = ( object && object.geometry ) || null;
98
+
99
+ /**
100
+ * The current renderer.
101
+ *
102
+ * @type {Renderer}
103
+ */
72
104
  this.renderer = renderer;
105
+
106
+ /**
107
+ * A reference to a node parser.
108
+ *
109
+ * @type {NodeParser}
110
+ */
73
111
  this.parser = parser;
112
+
113
+ /**
114
+ * The scene the 3D object belongs to.
115
+ *
116
+ * @type {?Scene}
117
+ * @default null
118
+ */
74
119
  this.scene = null;
120
+
121
+ /**
122
+ * The camera the 3D object is rendered with.
123
+ *
124
+ * @type {?Camera}
125
+ * @default null
126
+ */
75
127
  this.camera = null;
76
128
 
129
+ /**
130
+ * A list of all nodes the builder is processing
131
+ * for this 3D object.
132
+ *
133
+ * @type {Array<Node>}
134
+ */
77
135
  this.nodes = [];
136
+
137
+ /**
138
+ * A list of all sequential nodes.
139
+ *
140
+ * @type {Array<Node>}
141
+ */
142
+ this.sequentialNodes = [];
143
+
144
+ /**
145
+ * A list of all nodes which {@link Node#update} method should be executed.
146
+ *
147
+ * @type {Array<Node>}
148
+ */
78
149
  this.updateNodes = [];
150
+
151
+ /**
152
+ * A list of all nodes which {@link Node#updateBefore} method should be executed.
153
+ *
154
+ * @type {Array<Node>}
155
+ */
79
156
  this.updateBeforeNodes = [];
157
+
158
+ /**
159
+ * A list of all nodes which {@link Node#updateAfter} method should be executed.
160
+ *
161
+ * @type {Array<Node>}
162
+ */
80
163
  this.updateAfterNodes = [];
164
+
165
+ /**
166
+ * A dictionary that assigns each node to a unique hash.
167
+ *
168
+ * @type {Object<number,Node>}
169
+ */
81
170
  this.hashNodes = {};
82
171
 
172
+ /**
173
+ * A reference to a node material observer.
174
+ *
175
+ * @type {?NodeMaterialObserver}
176
+ * @default null
177
+ */
178
+ this.observer = null;
179
+
180
+ /**
181
+ * A reference to the current lights node.
182
+ *
183
+ * @type {?LightsNode}
184
+ * @default null
185
+ */
83
186
  this.lightsNode = null;
187
+
188
+ /**
189
+ * A reference to the current environment node.
190
+ *
191
+ * @type {?Node}
192
+ * @default null
193
+ */
84
194
  this.environmentNode = null;
195
+
196
+ /**
197
+ * A reference to the current fog node.
198
+ *
199
+ * @type {?FogNode}
200
+ * @default null
201
+ */
85
202
  this.fogNode = null;
86
203
 
204
+ /**
205
+ * The current clipping context.
206
+ *
207
+ * @type {?ClippingContext}
208
+ */
87
209
  this.clippingContext = null;
88
210
 
211
+ /**
212
+ * The generated vertex shader.
213
+ *
214
+ * @type {?string}
215
+ */
89
216
  this.vertexShader = null;
217
+
218
+ /**
219
+ * The generated fragment shader.
220
+ *
221
+ * @type {?string}
222
+ */
90
223
  this.fragmentShader = null;
224
+
225
+ /**
226
+ * The generated compute shader.
227
+ *
228
+ * @type {?string}
229
+ */
91
230
  this.computeShader = null;
92
231
 
232
+ /**
233
+ * Nodes used in the primary flow of code generation.
234
+ *
235
+ * @type {Object<string,Array<Node>>}
236
+ */
93
237
  this.flowNodes = { vertex: [], fragment: [], compute: [] };
238
+
239
+ /**
240
+ * Nodes code from `.flowNodes`.
241
+ *
242
+ * @type {Object<string,string>}
243
+ */
94
244
  this.flowCode = { vertex: '', fragment: '', compute: '' };
245
+
246
+ /**
247
+ * This dictionary holds the node uniforms of the builder.
248
+ * The uniforms are maintained in an array for each shader stage.
249
+ *
250
+ * @type {Object}
251
+ */
95
252
  this.uniforms = { vertex: [], fragment: [], compute: [], index: 0 };
253
+
254
+ /**
255
+ * This dictionary holds the output structs of the builder.
256
+ * The structs are maintained in an array for each shader stage.
257
+ *
258
+ * @type {Object}
259
+ */
96
260
  this.structs = { vertex: [], fragment: [], compute: [], index: 0 };
261
+
262
+ /**
263
+ * This dictionary holds the bindings for each shader stage.
264
+ *
265
+ * @type {Object}
266
+ */
97
267
  this.bindings = { vertex: {}, fragment: {}, compute: {} };
268
+
269
+ /**
270
+ * This dictionary maintains the binding indices per bind group.
271
+ *
272
+ * @type {Object}
273
+ */
98
274
  this.bindingsIndexes = {};
275
+
276
+ /**
277
+ * Reference to the array of bind groups.
278
+ *
279
+ * @type {?Array<BindGroup>}
280
+ */
99
281
  this.bindGroups = null;
282
+
283
+ /**
284
+ * This array holds the node attributes of this builder
285
+ * created via {@link AttributeNode}.
286
+ *
287
+ * @type {Array<NodeAttribute>}
288
+ */
100
289
  this.attributes = [];
290
+
291
+ /**
292
+ * This array holds the node attributes of this builder
293
+ * created via {@link BufferAttributeNode}.
294
+ *
295
+ * @type {Array<NodeAttribute>}
296
+ */
101
297
  this.bufferAttributes = [];
298
+
299
+ /**
300
+ * This array holds the node varyings of this builder.
301
+ *
302
+ * @type {Array<NodeVarying>}
303
+ */
102
304
  this.varyings = [];
305
+
306
+ /**
307
+ * This dictionary holds the (native) node codes of this builder.
308
+ * The codes are maintained in an array for each shader stage.
309
+ *
310
+ * @type {Object<string,Array<NodeCode>>}
311
+ */
103
312
  this.codes = {};
313
+
314
+ /**
315
+ * This dictionary holds the node variables of this builder.
316
+ * The variables are maintained in an array for each shader stage.
317
+ *
318
+ * @type {Object<string,Array<NodeVar>>}
319
+ */
104
320
  this.vars = {};
321
+
322
+ /**
323
+ * Current code flow.
324
+ * All code generated in this stack will be stored in `.flow`.
325
+ *
326
+ * @type {{code: string}}
327
+ */
105
328
  this.flow = { code: '' };
329
+
330
+ /**
331
+ * A chain of nodes.
332
+ * Used to check recursive calls in node-graph.
333
+ *
334
+ * @type {Array<Node>}
335
+ */
106
336
  this.chaining = [];
337
+
338
+ /**
339
+ * The current stack.
340
+ * This reflects the current process in the code block hierarchy,
341
+ * it is useful to know if the current process is inside a conditional for example.
342
+ *
343
+ * @type {StackNode}
344
+ */
107
345
  this.stack = stack();
346
+
347
+ /**
348
+ * List of stack nodes.
349
+ * The current stack hierarchy is stored in an array.
350
+ *
351
+ * @type {Array<StackNode>}
352
+ */
108
353
  this.stacks = [];
109
- this.tab = '\t';
110
354
 
111
- this.instanceBindGroups = true;
355
+ /**
356
+ * A tab value. Used for shader string generation.
357
+ *
358
+ * @type {string}
359
+ * @default '\t'
360
+ */
361
+ this.tab = '\t';
112
362
 
363
+ /**
364
+ * Reference to the current function node.
365
+ *
366
+ * @type {?FunctionNode}
367
+ * @default null
368
+ */
113
369
  this.currentFunctionNode = null;
114
370
 
371
+ /**
372
+ * The builder's context.
373
+ *
374
+ * @type {Object}
375
+ */
115
376
  this.context = {
116
- keywords: new NodeKeywords(),
117
377
  material: this.material
118
378
  };
119
379
 
380
+ /**
381
+ * The builder's cache.
382
+ *
383
+ * @type {NodeCache}
384
+ */
120
385
  this.cache = new NodeCache();
386
+
387
+ /**
388
+ * Since the {@link NodeBuilder#cache} might be temporarily
389
+ * overwritten by other caches, this member retains the reference
390
+ * to the builder's own cache.
391
+ *
392
+ * @type {NodeCache}
393
+ * @default this.cache
394
+ */
121
395
  this.globalCache = this.cache;
122
396
 
123
397
  this.flowsData = new WeakMap();
124
398
 
399
+ /**
400
+ * The current shader stage.
401
+ *
402
+ * @type {?('vertex'|'fragment'|'compute'|'any')}
403
+ */
125
404
  this.shaderStage = null;
405
+
406
+ /**
407
+ * The current build stage.
408
+ *
409
+ * @type {?('setup'|'analyze'|'generate')}
410
+ */
126
411
  this.buildStage = null;
127
412
 
413
+ /**
414
+ * Whether comparison in shader code are generated with methods or not.
415
+ *
416
+ * @type {boolean}
417
+ * @default false
418
+ */
128
419
  this.useComparisonMethod = false;
129
420
 
130
421
  }
131
422
 
423
+ /**
424
+ * Returns the bind groups of the current renderer.
425
+ *
426
+ * @return {ChainMap} The cache.
427
+ */
132
428
  getBindGroupsCache() {
133
429
 
134
430
  let bindGroupsCache = rendererCache.get( this.renderer );
@@ -145,32 +441,64 @@ class NodeBuilder {
145
441
 
146
442
  }
147
443
 
444
+ /**
445
+ * Factory method for creating an instance of {@link RenderTarget} with the given
446
+ * dimensions and options.
447
+ *
448
+ * @param {number} width - The width of the render target.
449
+ * @param {number} height - The height of the render target.
450
+ * @param {Object} options - The options of the render target.
451
+ * @return {RenderTarget} The render target.
452
+ */
148
453
  createRenderTarget( width, height, options ) {
149
454
 
150
455
  return new RenderTarget( width, height, options );
151
456
 
152
457
  }
153
458
 
459
+ /**
460
+ * Factory method for creating an instance of {@link CubeRenderTarget} with the given
461
+ * dimensions and options.
462
+ *
463
+ * @param {number} size - The size of the cube render target.
464
+ * @param {Object} options - The options of the cube render target.
465
+ * @return {CubeRenderTarget} The cube render target.
466
+ */
154
467
  createCubeRenderTarget( size, options ) {
155
468
 
156
469
  return new CubeRenderTarget( size, options );
157
470
 
158
471
  }
159
472
 
160
- createPMREMGenerator() {
161
-
162
- // TODO: Move Materials.js to outside of the Nodes.js in order to remove this function and improve tree-shaking support
163
-
164
- return new PMREMGenerator( this.renderer );
165
-
166
- }
167
-
473
+ /**
474
+ * Whether the given node is included in the internal array of nodes or not.
475
+ *
476
+ * @param {Node} node - The node to test.
477
+ * @return {boolean} Whether the given node is included in the internal array of nodes or not.
478
+ */
168
479
  includes( node ) {
169
480
 
170
481
  return this.nodes.includes( node );
171
482
 
172
483
  }
173
484
 
485
+ /**
486
+ * Returns the output struct name which is required by
487
+ * {@link OutputStructNode}.
488
+ *
489
+ * @abstract
490
+ * @return {string} The name of the output struct.
491
+ */
492
+ getOutputStructName() {}
493
+
494
+ /**
495
+ * Returns a bind group for the given group name and binding.
496
+ *
497
+ * @private
498
+ * @param {string} groupName - The group name.
499
+ * @param {Array<NodeUniformsGroup>} bindings - List of bindings.
500
+ * @return {BindGroup} The bind group
501
+ */
174
502
  _getBindGroup( groupName, bindings ) {
175
503
 
176
504
  const bindGroupsCache = this.getBindGroupsCache();
@@ -199,7 +527,7 @@ class NodeBuilder {
199
527
 
200
528
  if ( bindGroup === undefined ) {
201
529
 
202
- bindGroup = new BindGroup( groupName, bindingsArray, this.bindingsIndexes[ groupName ].group );
530
+ bindGroup = new BindGroup( groupName, bindingsArray, this.bindingsIndexes[ groupName ].group, bindingsArray );
203
531
 
204
532
  bindGroupsCache.set( bindingsArray, bindGroup );
205
533
 
@@ -207,7 +535,7 @@ class NodeBuilder {
207
535
 
208
536
  } else {
209
537
 
210
- bindGroup = new BindGroup( groupName, bindingsArray, this.bindingsIndexes[ groupName ].group );
538
+ bindGroup = new BindGroup( groupName, bindingsArray, this.bindingsIndexes[ groupName ].group, bindingsArray );
211
539
 
212
540
  }
213
541
 
@@ -215,6 +543,13 @@ class NodeBuilder {
215
543
 
216
544
  }
217
545
 
546
+ /**
547
+ * Returns an array of node uniform groups for the given group name and shader stage.
548
+ *
549
+ * @param {string} groupName - The group name.
550
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
551
+ * @return {Array<NodeUniformsGroup>} The array of node uniform groups.
552
+ */
218
553
  getBindGroupArray( groupName, shaderStage ) {
219
554
 
220
555
  const bindings = this.bindings[ shaderStage ];
@@ -237,6 +572,11 @@ class NodeBuilder {
237
572
 
238
573
  }
239
574
 
575
+ /**
576
+ * Returns a list bindings of all shader stages separated by groups.
577
+ *
578
+ * @return {Array<BindGroup>} The list of bindings.
579
+ */
240
580
  getBindings() {
241
581
 
242
582
  let bindingsGroups = this.bindGroups;
@@ -279,12 +619,44 @@ class NodeBuilder {
279
619
 
280
620
  }
281
621
 
622
+ /**
623
+ * Sorts the bind groups and updates {@link NodeBuilder#bindingsIndexes}.
624
+ */
625
+ sortBindingGroups() {
626
+
627
+ const bindingsGroups = this.getBindings();
628
+
629
+ bindingsGroups.sort( ( a, b ) => ( a.bindings[ 0 ].groupNode.order - b.bindings[ 0 ].groupNode.order ) );
630
+
631
+ for ( let i = 0; i < bindingsGroups.length; i ++ ) {
632
+
633
+ const bindingGroup = bindingsGroups[ i ];
634
+ this.bindingsIndexes[ bindingGroup.name ].group = i;
635
+
636
+ bindingGroup.index = i;
637
+
638
+ }
639
+
640
+ }
641
+
642
+ /**
643
+ * The builder maintains each node in a hash-based dictionary.
644
+ * This method sets the given node (value) with the given hash (key) into this dictionary.
645
+ *
646
+ * @param {Node} node - The node to add.
647
+ * @param {number} hash - The hash of the node.
648
+ */
282
649
  setHashNode( node, hash ) {
283
650
 
284
651
  this.hashNodes[ hash ] = node;
285
652
 
286
653
  }
287
654
 
655
+ /**
656
+ * Adds a node to this builder.
657
+ *
658
+ * @param {Node} node - The node to add.
659
+ */
288
660
  addNode( node ) {
289
661
 
290
662
  if ( this.nodes.includes( node ) === false ) {
@@ -297,13 +669,31 @@ class NodeBuilder {
297
669
 
298
670
  }
299
671
 
672
+ /**
673
+ * It is used to add Nodes that will be used as FRAME and RENDER events,
674
+ * and need to follow a certain sequence in the calls to work correctly.
675
+ * This function should be called after 'setup()' in the 'build()' process to ensure that the child nodes are processed first.
676
+ *
677
+ * @param {Node} node - The node to add.
678
+ */
679
+ addSequentialNode( node ) {
680
+
681
+ if ( this.sequentialNodes.includes( node ) === false ) {
682
+
683
+ this.sequentialNodes.push( node );
684
+
685
+ }
686
+
687
+ }
688
+
689
+ /**
690
+ * Checks the update types of nodes
691
+ */
300
692
  buildUpdateNodes() {
301
693
 
302
694
  for ( const node of this.nodes ) {
303
695
 
304
696
  const updateType = node.getUpdateType();
305
- const updateBeforeType = node.getUpdateBeforeType();
306
- const updateAfterType = node.getUpdateAfterType();
307
697
 
308
698
  if ( updateType !== NodeUpdateType.NONE ) {
309
699
 
@@ -311,15 +701,22 @@ class NodeBuilder {
311
701
 
312
702
  }
313
703
 
704
+ }
705
+
706
+ for ( const node of this.sequentialNodes ) {
707
+
708
+ const updateBeforeType = node.getUpdateBeforeType();
709
+ const updateAfterType = node.getUpdateAfterType();
710
+
314
711
  if ( updateBeforeType !== NodeUpdateType.NONE ) {
315
712
 
316
- this.updateBeforeNodes.push( node );
713
+ this.updateBeforeNodes.push( node.getSelf() );
317
714
 
318
715
  }
319
716
 
320
717
  if ( updateAfterType !== NodeUpdateType.NONE ) {
321
718
 
322
- this.updateAfterNodes.push( node );
719
+ this.updateAfterNodes.push( node.getSelf() );
323
720
 
324
721
  }
325
722
 
@@ -327,12 +724,24 @@ class NodeBuilder {
327
724
 
328
725
  }
329
726
 
727
+ /**
728
+ * A reference the current node which is the
729
+ * last node in the chain of nodes.
730
+ *
731
+ * @type {Node}
732
+ */
330
733
  get currentNode() {
331
734
 
332
735
  return this.chaining[ this.chaining.length - 1 ];
333
736
 
334
737
  }
335
738
 
739
+ /**
740
+ * Whether the given texture is filtered or not.
741
+ *
742
+ * @param {Texture} texture - The texture to check.
743
+ * @return {boolean} Whether the given texture is filtered or not.
744
+ */
336
745
  isFilteredTexture( texture ) {
337
746
 
338
747
  return ( texture.magFilter === LinearFilter || texture.magFilter === LinearMipmapNearestFilter || texture.magFilter === NearestMipmapLinearFilter || texture.magFilter === LinearMipmapLinearFilter ||
@@ -340,6 +749,12 @@ class NodeBuilder {
340
749
 
341
750
  }
342
751
 
752
+ /**
753
+ * Adds the given node to the internal node chain.
754
+ * This is used to check recursive calls in node-graph.
755
+ *
756
+ * @param {Node} node - The node to add.
757
+ */
343
758
  addChain( node ) {
344
759
 
345
760
  /*
@@ -354,6 +769,11 @@ class NodeBuilder {
354
769
 
355
770
  }
356
771
 
772
+ /**
773
+ * Removes the given node from the internal node chain.
774
+ *
775
+ * @param {Node} node - The node to remove.
776
+ */
357
777
  removeChain( node ) {
358
778
 
359
779
  const lastChain = this.chaining.pop();
@@ -366,18 +786,40 @@ class NodeBuilder {
366
786
 
367
787
  }
368
788
 
789
+ /**
790
+ * Returns the native shader method name for a given generic name. E.g.
791
+ * the method name `textureDimensions` matches the WGSL name but must be
792
+ * resolved to `textureSize` in GLSL.
793
+ *
794
+ * @abstract
795
+ * @param {string} method - The method name to resolve.
796
+ * @return {string} The resolved method name.
797
+ */
369
798
  getMethod( method ) {
370
799
 
371
800
  return method;
372
801
 
373
802
  }
374
803
 
804
+ /**
805
+ * Returns a node for the given hash, see {@link NodeBuilder#setHashNode}.
806
+ *
807
+ * @param {number} hash - The hash of the node.
808
+ * @return {Node} The found node.
809
+ */
375
810
  getNodeFromHash( hash ) {
376
811
 
377
812
  return this.hashNodes[ hash ];
378
813
 
379
814
  }
380
815
 
816
+ /**
817
+ * Adds the Node to a target flow so that it can generate code in the 'generate' process.
818
+ *
819
+ * @param {('vertex'|'fragment'|'compute')} shaderStage - The shader stage.
820
+ * @param {Node} node - The node to add.
821
+ * @return {Node} The node.
822
+ */
381
823
  addFlow( shaderStage, node ) {
382
824
 
383
825
  this.flowNodes[ shaderStage ].push( node );
@@ -386,41 +828,73 @@ class NodeBuilder {
386
828
 
387
829
  }
388
830
 
831
+ /**
832
+ * Sets builder's context.
833
+ *
834
+ * @param {Object} context - The context to set.
835
+ */
389
836
  setContext( context ) {
390
837
 
391
838
  this.context = context;
392
839
 
393
840
  }
394
841
 
842
+ /**
843
+ * Returns the builder's current context.
844
+ *
845
+ * @return {Object} The builder's current context.
846
+ */
395
847
  getContext() {
396
848
 
397
849
  return this.context;
398
850
 
399
851
  }
400
852
 
853
+ /**
854
+ * Gets a context used in shader construction that can be shared across different materials.
855
+ * This is necessary since the renderer cache can reuse shaders generated in one material and use them in another.
856
+ *
857
+ * @return {Object} The builder's current context without material.
858
+ */
401
859
  getSharedContext() {
402
860
 
403
861
  const context = { ...this.context };
404
862
 
405
- delete context.keywords;
406
863
  delete context.material;
407
864
 
408
865
  return this.context;
409
866
 
410
867
  }
411
868
 
869
+ /**
870
+ * Sets builder's cache.
871
+ *
872
+ * @param {NodeCache} cache - The cache to set.
873
+ */
412
874
  setCache( cache ) {
413
875
 
414
876
  this.cache = cache;
415
877
 
416
878
  }
417
879
 
880
+ /**
881
+ * Returns the builder's current cache.
882
+ *
883
+ * @return {NodeCache} The builder's current cache.
884
+ */
418
885
  getCache() {
419
886
 
420
887
  return this.cache;
421
888
 
422
889
  }
423
890
 
891
+ /**
892
+ * Returns a cache for the given node.
893
+ *
894
+ * @param {Node} node - The node.
895
+ * @param {boolean} [parent=true] - Whether this node refers to a shared parent cache or not.
896
+ * @return {NodeCache} The cache.
897
+ */
424
898
  getCacheFromNode( node, parent = true ) {
425
899
 
426
900
  const data = this.getDataFromNode( node );
@@ -430,60 +904,229 @@ class NodeBuilder {
430
904
 
431
905
  }
432
906
 
907
+ /**
908
+ * Whether the requested feature is available or not.
909
+ *
910
+ * @abstract
911
+ * @param {string} name - The requested feature.
912
+ * @return {boolean} Whether the requested feature is supported or not.
913
+ */
433
914
  isAvailable( /*name*/ ) {
434
915
 
435
916
  return false;
436
917
 
437
918
  }
438
919
 
920
+ /**
921
+ * Returns the vertexIndex input variable as a native shader string.
922
+ *
923
+ * @abstract
924
+ * @return {string} The instanceIndex shader string.
925
+ */
439
926
  getVertexIndex() {
440
927
 
441
928
  console.warn( 'Abstract function.' );
442
929
 
443
930
  }
444
931
 
932
+ /**
933
+ * Returns the instanceIndex input variable as a native shader string.
934
+ *
935
+ * @abstract
936
+ * @return {string} The instanceIndex shader string.
937
+ */
445
938
  getInstanceIndex() {
446
939
 
447
940
  console.warn( 'Abstract function.' );
448
941
 
449
942
  }
450
943
 
944
+ /**
945
+ * Returns the drawIndex input variable as a native shader string.
946
+ * Only relevant for WebGL and its `WEBGL_multi_draw` extension.
947
+ *
948
+ * @abstract
949
+ * @return {string} The drawIndex shader string.
950
+ */
451
951
  getDrawIndex() {
452
952
 
453
953
  console.warn( 'Abstract function.' );
454
954
 
455
955
  }
456
956
 
957
+ /**
958
+ * Returns the frontFacing input variable as a native shader string.
959
+ *
960
+ * @abstract
961
+ * @return {string} The frontFacing shader string.
962
+ */
457
963
  getFrontFacing() {
458
964
 
459
965
  console.warn( 'Abstract function.' );
460
966
 
461
967
  }
462
968
 
969
+ /**
970
+ * Returns the fragCoord input variable as a native shader string.
971
+ *
972
+ * @abstract
973
+ * @return {string} The fragCoord shader string.
974
+ */
463
975
  getFragCoord() {
464
976
 
465
977
  console.warn( 'Abstract function.' );
466
978
 
467
979
  }
468
980
 
981
+ /**
982
+ * Whether to flip texture data along its vertical axis or not. WebGL needs
983
+ * this method evaluate to `true`, WebGPU to `false`.
984
+ *
985
+ * @abstract
986
+ * @return {boolean} Whether to flip texture data along its vertical axis or not.
987
+ */
469
988
  isFlipY() {
470
989
 
471
990
  return false;
472
991
 
473
992
  }
474
993
 
994
+ /**
995
+ * Calling this method increases the usage count for the given node by one.
996
+ *
997
+ * @param {Node} node - The node to increase the usage count for.
998
+ * @return {number} The updated usage count.
999
+ */
1000
+ increaseUsage( node ) {
1001
+
1002
+ const nodeData = this.getDataFromNode( node );
1003
+ nodeData.usageCount = nodeData.usageCount === undefined ? 1 : nodeData.usageCount + 1;
1004
+
1005
+ return nodeData.usageCount;
1006
+
1007
+ }
1008
+
1009
+ /**
1010
+ * Generates a texture sample shader string for the given texture data.
1011
+ *
1012
+ * @abstract
1013
+ * @param {Texture} texture - The texture.
1014
+ * @param {string} textureProperty - The texture property name.
1015
+ * @param {string} uvSnippet - Snippet defining the texture coordinates.
1016
+ * @return {string} The generated shader string.
1017
+ */
475
1018
  generateTexture( /* texture, textureProperty, uvSnippet */ ) {
476
1019
 
477
1020
  console.warn( 'Abstract function.' );
478
1021
 
479
1022
  }
480
1023
 
481
- generateTextureLod( /* texture, textureProperty, uvSnippet, levelSnippet */ ) {
1024
+ /**
1025
+ * Generates a texture LOD 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
+ * @param {?string} depthSnippet - Snippet defining the 0-based texture array index to sample.
1032
+ * @param {string} levelSnippet - Snippet defining the mip level.
1033
+ * @return {string} The generated shader string.
1034
+ */
1035
+ generateTextureLod( /* texture, textureProperty, uvSnippet, depthSnippet, levelSnippet */ ) {
482
1036
 
483
1037
  console.warn( 'Abstract function.' );
484
1038
 
485
1039
  }
486
1040
 
1041
+ /**
1042
+ * Generates the array declaration string.
1043
+ *
1044
+ * @param {string} type - The type.
1045
+ * @param {?number} [count] - The count.
1046
+ * @return {string} The generated value as a shader string.
1047
+ */
1048
+ generateArrayDeclaration( type, count ) {
1049
+
1050
+ return this.getType( type ) + '[ ' + count + ' ]';
1051
+
1052
+ }
1053
+
1054
+ /**
1055
+ * Generates the array shader string for the given type and value.
1056
+ *
1057
+ * @param {string} type - The type.
1058
+ * @param {?number} [count] - The count.
1059
+ * @param {?Array<Node>} [values=null] - The default values.
1060
+ * @return {string} The generated value as a shader string.
1061
+ */
1062
+ generateArray( type, count, values = null ) {
1063
+
1064
+ let snippet = this.generateArrayDeclaration( type, count ) + '( ';
1065
+
1066
+ for ( let i = 0; i < count; i ++ ) {
1067
+
1068
+ const value = values ? values[ i ] : null;
1069
+
1070
+ if ( value !== null ) {
1071
+
1072
+ snippet += value.build( this, type );
1073
+
1074
+ } else {
1075
+
1076
+ snippet += this.generateConst( type );
1077
+
1078
+ }
1079
+
1080
+ if ( i < count - 1 ) snippet += ', ';
1081
+
1082
+ }
1083
+
1084
+ snippet += ' )';
1085
+
1086
+ return snippet;
1087
+
1088
+ }
1089
+
1090
+ /**
1091
+ * Generates the struct shader string.
1092
+ *
1093
+ * @param {string} type - The type.
1094
+ * @param {Array<Object>} [membersLayout] - The count.
1095
+ * @param {?Array<Node>} [values=null] - The default values.
1096
+ * @return {string} The generated value as a shader string.
1097
+ */
1098
+ generateStruct( type, membersLayout, values = null ) {
1099
+
1100
+ const snippets = [];
1101
+
1102
+ for ( const member of membersLayout ) {
1103
+
1104
+ const { name, type } = member;
1105
+
1106
+ if ( values && values[ name ] && values[ name ].isNode ) {
1107
+
1108
+ snippets.push( values[ name ].build( this, type ) );
1109
+
1110
+ } else {
1111
+
1112
+ snippets.push( this.generateConst( type ) );
1113
+
1114
+ }
1115
+
1116
+ }
1117
+
1118
+ return type + '( ' + snippets.join( ', ' ) + ' )';
1119
+
1120
+ }
1121
+
1122
+
1123
+ /**
1124
+ * Generates the shader string for the given type and value.
1125
+ *
1126
+ * @param {string} type - The type.
1127
+ * @param {?any} [value=null] - The value.
1128
+ * @return {string} The generated value as a shader string.
1129
+ */
487
1130
  generateConst( type, value = null ) {
488
1131
 
489
1132
  if ( value === null ) {
@@ -517,11 +1160,11 @@ class NodeBuilder {
517
1160
 
518
1161
  return `${ this.getType( type ) }( ${ generateConst( value.x ) }, ${ generateConst( value.y ) }, ${ generateConst( value.z ) } )`;
519
1162
 
520
- } else if ( typeLength === 4 ) {
1163
+ } else if ( typeLength === 4 && type !== 'mat2' ) {
521
1164
 
522
1165
  return `${ this.getType( type ) }( ${ generateConst( value.x ) }, ${ generateConst( value.y ) }, ${ generateConst( value.z ) }, ${ generateConst( value.w ) } )`;
523
1166
 
524
- } else if ( typeLength > 4 && value && ( value.isMatrix3 || value.isMatrix4 ) ) {
1167
+ } else if ( typeLength >= 4 && value && ( value.isMatrix2 || value.isMatrix3 || value.isMatrix4 ) ) {
525
1168
 
526
1169
  return `${ this.getType( type ) }( ${ value.elements.map( generateConst ).join( ', ' ) } )`;
527
1170
 
@@ -535,6 +1178,13 @@ class NodeBuilder {
535
1178
 
536
1179
  }
537
1180
 
1181
+ /**
1182
+ * It might be necessary to convert certain data types to different ones
1183
+ * so this method can be used to hide the conversion.
1184
+ *
1185
+ * @param {string} type - The type.
1186
+ * @return {string} The updated type.
1187
+ */
538
1188
  getType( type ) {
539
1189
 
540
1190
  if ( type === 'color' ) return 'vec3';
@@ -543,12 +1193,25 @@ class NodeBuilder {
543
1193
 
544
1194
  }
545
1195
 
1196
+ /**
1197
+ * Whether the given attribute name is defined in the geometry or not.
1198
+ *
1199
+ * @param {string} name - The attribute name.
1200
+ * @return {boolean} Whether the given attribute name is defined in the geometry.
1201
+ */
546
1202
  hasGeometryAttribute( name ) {
547
1203
 
548
1204
  return this.geometry && this.geometry.getAttribute( name ) !== undefined;
549
1205
 
550
1206
  }
551
1207
 
1208
+ /**
1209
+ * Returns a node attribute for the given name and type.
1210
+ *
1211
+ * @param {string} name - The attribute's name.
1212
+ * @param {string} type - The attribute's type.
1213
+ * @return {NodeAttribute} The node attribute.
1214
+ */
552
1215
  getAttribute( name, type ) {
553
1216
 
554
1217
  const attributes = this.attributes;
@@ -575,36 +1238,74 @@ class NodeBuilder {
575
1238
 
576
1239
  }
577
1240
 
1241
+ /**
1242
+ * Returns for the given node and shader stage the property name for the shader.
1243
+ *
1244
+ * @param {Node} node - The node.
1245
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
1246
+ * @return {string} The property name.
1247
+ */
578
1248
  getPropertyName( node/*, shaderStage*/ ) {
579
1249
 
580
1250
  return node.name;
581
1251
 
582
1252
  }
583
1253
 
1254
+ /**
1255
+ * Whether the given type is a vector type or not.
1256
+ *
1257
+ * @param {string} type - The type to check.
1258
+ * @return {boolean} Whether the given type is a vector type or not.
1259
+ */
584
1260
  isVector( type ) {
585
1261
 
586
1262
  return /vec\d/.test( type );
587
1263
 
588
1264
  }
589
1265
 
1266
+ /**
1267
+ * Whether the given type is a matrix type or not.
1268
+ *
1269
+ * @param {string} type - The type to check.
1270
+ * @return {boolean} Whether the given type is a matrix type or not.
1271
+ */
590
1272
  isMatrix( type ) {
591
1273
 
592
1274
  return /mat\d/.test( type );
593
1275
 
594
1276
  }
595
1277
 
1278
+ /**
1279
+ * Whether the given type is a reference type or not.
1280
+ *
1281
+ * @param {string} type - The type to check.
1282
+ * @return {boolean} Whether the given type is a reference type or not.
1283
+ */
596
1284
  isReference( type ) {
597
1285
 
598
1286
  return type === 'void' || type === 'property' || type === 'sampler' || type === 'texture' || type === 'cubeTexture' || type === 'storageTexture' || type === 'depthTexture' || type === 'texture3D';
599
1287
 
600
1288
  }
601
1289
 
602
- needsColorSpaceToLinear( /*texture*/ ) {
1290
+ /**
1291
+ * Checks if the given texture requires a manual conversion to the working color space.
1292
+ *
1293
+ * @abstract
1294
+ * @param {Texture} texture - The texture to check.
1295
+ * @return {boolean} Whether the given texture requires a conversion to working color space or not.
1296
+ */
1297
+ needsToWorkingColorSpace( /*texture*/ ) {
603
1298
 
604
1299
  return false;
605
1300
 
606
1301
  }
607
1302
 
1303
+ /**
1304
+ * Returns the component type of a given texture.
1305
+ *
1306
+ * @param {Texture} texture - The texture.
1307
+ * @return {string} The component type.
1308
+ */
608
1309
  getComponentTypeFromTexture( texture ) {
609
1310
 
610
1311
  const type = texture.type;
@@ -620,6 +1321,12 @@ class NodeBuilder {
620
1321
 
621
1322
  }
622
1323
 
1324
+ /**
1325
+ * Returns the element type for a given type.
1326
+ *
1327
+ * @param {string} type - The type.
1328
+ * @return {string} The element type.
1329
+ */
623
1330
  getElementType( type ) {
624
1331
 
625
1332
  if ( type === 'mat2' ) return 'vec2';
@@ -630,6 +1337,12 @@ class NodeBuilder {
630
1337
 
631
1338
  }
632
1339
 
1340
+ /**
1341
+ * Returns the component type for a given type.
1342
+ *
1343
+ * @param {string} type - The type.
1344
+ * @return {string} The component type.
1345
+ */
633
1346
  getComponentType( type ) {
634
1347
 
635
1348
  type = this.getVectorType( type );
@@ -648,6 +1361,12 @@ class NodeBuilder {
648
1361
 
649
1362
  }
650
1363
 
1364
+ /**
1365
+ * Returns the vector type for a given type.
1366
+ *
1367
+ * @param {string} type - The type.
1368
+ * @return {string} The vector type.
1369
+ */
651
1370
  getVectorType( type ) {
652
1371
 
653
1372
  if ( type === 'color' ) return 'vec3';
@@ -657,23 +1376,49 @@ class NodeBuilder {
657
1376
 
658
1377
  }
659
1378
 
1379
+ /**
1380
+ * Returns the data type for the given the length and component type.
1381
+ *
1382
+ * @param {number} length - The length.
1383
+ * @param {string} [componentType='float'] - The component type.
1384
+ * @return {string} The type.
1385
+ */
660
1386
  getTypeFromLength( length, componentType = 'float' ) {
661
1387
 
662
1388
  if ( length === 1 ) return componentType;
663
1389
 
664
- const baseType = typeFromLength.get( length );
1390
+ let baseType = getTypeFromLength( length );
665
1391
  const prefix = componentType === 'float' ? '' : componentType[ 0 ];
666
1392
 
1393
+ // fix edge case for mat2x2 being same size as vec4
1394
+ if ( /mat2/.test( componentType ) === true ) {
1395
+
1396
+ baseType = baseType.replace( 'vec', 'mat' );
1397
+
1398
+ }
1399
+
667
1400
  return prefix + baseType;
668
1401
 
669
1402
  }
670
1403
 
1404
+ /**
1405
+ * Returns the type for a given typed array.
1406
+ *
1407
+ * @param {TypedArray} array - The typed array.
1408
+ * @return {string} The type.
1409
+ */
671
1410
  getTypeFromArray( array ) {
672
1411
 
673
1412
  return typeFromArray.get( array.constructor );
674
1413
 
675
1414
  }
676
1415
 
1416
+ /**
1417
+ * Returns the type for a given buffer attribute.
1418
+ *
1419
+ * @param {BufferAttribute} attribute - The buffer attribute.
1420
+ * @return {string} The type.
1421
+ */
677
1422
  getTypeFromAttribute( attribute ) {
678
1423
 
679
1424
  let dataAttribute = attribute;
@@ -696,6 +1441,12 @@ class NodeBuilder {
696
1441
 
697
1442
  }
698
1443
 
1444
+ /**
1445
+ * Returns the length for the given data type.
1446
+ *
1447
+ * @param {string} type - The data type.
1448
+ * @return {number} The length.
1449
+ */
699
1450
  getTypeLength( type ) {
700
1451
 
701
1452
  const vecType = this.getVectorType( type );
@@ -711,18 +1462,39 @@ class NodeBuilder {
711
1462
 
712
1463
  }
713
1464
 
1465
+ /**
1466
+ * Returns the vector type for a given matrix type.
1467
+ *
1468
+ * @param {string} type - The matrix type.
1469
+ * @return {string} The vector type.
1470
+ */
714
1471
  getVectorFromMatrix( type ) {
715
1472
 
716
1473
  return type.replace( 'mat', 'vec' );
717
1474
 
718
1475
  }
719
1476
 
1477
+ /**
1478
+ * For a given type this method changes the component type to the
1479
+ * given value. E.g. `vec4` should be changed to the new component type
1480
+ * `uint` which results in `uvec4`.
1481
+ *
1482
+ * @param {string} type - The type.
1483
+ * @param {string} newComponentType - The new component type.
1484
+ * @return {string} The new type.
1485
+ */
720
1486
  changeComponentType( type, newComponentType ) {
721
1487
 
722
1488
  return this.getTypeFromLength( this.getTypeLength( type ), newComponentType );
723
1489
 
724
1490
  }
725
1491
 
1492
+ /**
1493
+ * Returns the integer type pendant for the given type.
1494
+ *
1495
+ * @param {string} type - The type.
1496
+ * @return {string} The integer type.
1497
+ */
726
1498
  getIntegerType( type ) {
727
1499
 
728
1500
  const componentType = this.getComponentType( type );
@@ -733,6 +1505,11 @@ class NodeBuilder {
733
1505
 
734
1506
  }
735
1507
 
1508
+ /**
1509
+ * Adds a stack node to the internal stack.
1510
+ *
1511
+ * @return {StackNode} The added stack node.
1512
+ */
736
1513
  addStack() {
737
1514
 
738
1515
  this.stack = stack( this.stack );
@@ -744,6 +1521,11 @@ class NodeBuilder {
744
1521
 
745
1522
  }
746
1523
 
1524
+ /**
1525
+ * Removes the last stack node from the internal stack.
1526
+ *
1527
+ * @return {StackNode} The removed stack node.
1528
+ */
747
1529
  removeStack() {
748
1530
 
749
1531
  const lastStack = this.stack;
@@ -755,6 +1537,15 @@ class NodeBuilder {
755
1537
 
756
1538
  }
757
1539
 
1540
+ /**
1541
+ * The builder maintains (cached) data for each node during the building process. This method
1542
+ * can be used to get these data for a specific shader stage and cache.
1543
+ *
1544
+ * @param {Node} node - The node to get the data for.
1545
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
1546
+ * @param {?NodeCache} cache - An optional cache.
1547
+ * @return {Object} The node data.
1548
+ */
758
1549
  getDataFromNode( node, shaderStage = this.shaderStage, cache = null ) {
759
1550
 
760
1551
  cache = cache === null ? ( node.isGlobal( this ) ? this.globalCache : this.cache ) : cache;
@@ -775,6 +1566,13 @@ class NodeBuilder {
775
1566
 
776
1567
  }
777
1568
 
1569
+ /**
1570
+ * Returns the properties for the given node and shader stage.
1571
+ *
1572
+ * @param {Node} node - The node to get the properties for.
1573
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage='any'] - The shader stage.
1574
+ * @return {Object} The node properties.
1575
+ */
778
1576
  getNodeProperties( node, shaderStage = 'any' ) {
779
1577
 
780
1578
  const nodeData = this.getDataFromNode( node, shaderStage );
@@ -783,6 +1581,13 @@ class NodeBuilder {
783
1581
 
784
1582
  }
785
1583
 
1584
+ /**
1585
+ * Returns an instance of {@link NodeAttribute} for the given buffer attribute node.
1586
+ *
1587
+ * @param {BufferAttributeNode} node - The buffer attribute node.
1588
+ * @param {string} type - The node type.
1589
+ * @return {NodeAttribute} The node attribute.
1590
+ */
786
1591
  getBufferAttributeFromNode( node, type ) {
787
1592
 
788
1593
  const nodeData = this.getDataFromNode( node );
@@ -805,25 +1610,64 @@ class NodeBuilder {
805
1610
 
806
1611
  }
807
1612
 
808
- getStructTypeFromNode( node, shaderStage = this.shaderStage ) {
1613
+ /**
1614
+ * Returns an instance of {@link StructType} for the given output struct node.
1615
+ *
1616
+ * @param {OutputStructNode} node - The output struct node.
1617
+ * @param {Array<Object>} membersLayout - The output struct types.
1618
+ * @param {?string} [name=null] - The name of the struct.
1619
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
1620
+ * @return {StructType} The struct type attribute.
1621
+ */
1622
+ getStructTypeFromNode( node, membersLayout, name = null, shaderStage = this.shaderStage ) {
809
1623
 
810
- const nodeData = this.getDataFromNode( node, shaderStage );
1624
+ const nodeData = this.getDataFromNode( node, shaderStage, this.globalCache );
1625
+
1626
+ let structType = nodeData.structType;
811
1627
 
812
- if ( nodeData.structType === undefined ) {
1628
+ if ( structType === undefined ) {
813
1629
 
814
1630
  const index = this.structs.index ++;
815
1631
 
816
- node.name = `StructType${ index }`;
817
- this.structs[ shaderStage ].push( node );
1632
+ if ( name === null ) name = 'StructType' + index;
818
1633
 
819
- nodeData.structType = node;
1634
+ structType = new StructType( name, membersLayout );
1635
+
1636
+ this.structs[ shaderStage ].push( structType );
1637
+
1638
+ nodeData.structType = structType;
820
1639
 
821
1640
  }
822
1641
 
823
- return node;
1642
+ return structType;
824
1643
 
825
1644
  }
826
1645
 
1646
+ /**
1647
+ * Returns an instance of {@link StructType} for the given output struct node.
1648
+ *
1649
+ * @param {OutputStructNode} node - The output struct node.
1650
+ * @param {Array<Object>} membersLayout - The output struct types.
1651
+ * @return {StructType} The struct type attribute.
1652
+ */
1653
+ getOutputStructTypeFromNode( node, membersLayout ) {
1654
+
1655
+ const structType = this.getStructTypeFromNode( node, membersLayout, 'OutputType', 'fragment' );
1656
+ structType.output = true;
1657
+
1658
+ return structType;
1659
+
1660
+ }
1661
+
1662
+ /**
1663
+ * Returns an instance of {@link NodeUniform} for the given uniform node.
1664
+ *
1665
+ * @param {UniformNode} node - The uniform node.
1666
+ * @param {string} type - The uniform type.
1667
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
1668
+ * @param {?string} name - The name of the uniform.
1669
+ * @return {NodeUniform} The node uniform.
1670
+ */
827
1671
  getUniformFromNode( node, type, shaderStage = this.shaderStage, name = null ) {
828
1672
 
829
1673
  const nodeData = this.getDataFromNode( node, shaderStage, this.globalCache );
@@ -846,7 +1690,35 @@ class NodeBuilder {
846
1690
 
847
1691
  }
848
1692
 
849
- getVarFromNode( node, name = null, type = node.getNodeType( this ), shaderStage = this.shaderStage ) {
1693
+ /**
1694
+ * Returns the array length.
1695
+ *
1696
+ * @param {Node} node - The node.
1697
+ * @return {?number} The array length.
1698
+ */
1699
+ getArrayCount( node ) {
1700
+
1701
+ let count = null;
1702
+
1703
+ if ( node.isArrayNode ) count = node.count;
1704
+ else if ( node.isVarNode && node.node.isArrayNode ) count = node.node.count;
1705
+
1706
+ return count;
1707
+
1708
+ }
1709
+
1710
+ /**
1711
+ * Returns an instance of {@link NodeVar} for the given variable node.
1712
+ *
1713
+ * @param {VarNode} node - The variable node.
1714
+ * @param {?string} name - The variable's name.
1715
+ * @param {string} [type=node.getNodeType( this )] - The variable's type.
1716
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
1717
+ * @param {boolean} [readOnly=false] - Whether the variable is read-only or not.
1718
+ *
1719
+ * @return {NodeVar} The node variable.
1720
+ */
1721
+ getVarFromNode( node, name = null, type = node.getNodeType( this ), shaderStage = this.shaderStage, readOnly = false ) {
850
1722
 
851
1723
  const nodeData = this.getDataFromNode( node, shaderStage );
852
1724
 
@@ -854,13 +1726,30 @@ class NodeBuilder {
854
1726
 
855
1727
  if ( nodeVar === undefined ) {
856
1728
 
1729
+ const idNS = readOnly ? '_const' : '_var';
1730
+
857
1731
  const vars = this.vars[ shaderStage ] || ( this.vars[ shaderStage ] = [] );
1732
+ const id = this.vars[ idNS ] || ( this.vars[ idNS ] = 0 );
858
1733
 
859
- if ( name === null ) name = 'nodeVar' + vars.length;
1734
+ if ( name === null ) {
1735
+
1736
+ name = ( readOnly ? 'nodeConst' : 'nodeVar' ) + id;
1737
+
1738
+ this.vars[ idNS ] ++;
1739
+
1740
+ }
860
1741
 
861
- nodeVar = new NodeVar( name, type );
1742
+ //
862
1743
 
863
- vars.push( nodeVar );
1744
+ const count = this.getArrayCount( node );
1745
+
1746
+ nodeVar = new NodeVar( name, type, readOnly, count );
1747
+
1748
+ if ( ! readOnly ) {
1749
+
1750
+ vars.push( nodeVar );
1751
+
1752
+ }
864
1753
 
865
1754
  nodeData.variable = nodeVar;
866
1755
 
@@ -870,6 +1759,61 @@ class NodeBuilder {
870
1759
 
871
1760
  }
872
1761
 
1762
+ /**
1763
+ * Returns whether a Node or its flow is deterministic, useful for use in `const`.
1764
+ *
1765
+ * @param {Node} node - The varying node.
1766
+ * @return {boolean} Returns true if deterministic.
1767
+ */
1768
+ isDeterministic( node ) {
1769
+
1770
+ if ( node.isMathNode ) {
1771
+
1772
+ return this.isDeterministic( node.aNode ) &&
1773
+ ( node.bNode ? this.isDeterministic( node.bNode ) : true ) &&
1774
+ ( node.cNode ? this.isDeterministic( node.cNode ) : true );
1775
+
1776
+ } else if ( node.isOperatorNode ) {
1777
+
1778
+ return this.isDeterministic( node.aNode ) &&
1779
+ ( node.bNode ? this.isDeterministic( node.bNode ) : true );
1780
+
1781
+ } else if ( node.isArrayNode ) {
1782
+
1783
+ if ( node.values !== null ) {
1784
+
1785
+ for ( const n of node.values ) {
1786
+
1787
+ if ( ! this.isDeterministic( n ) ) {
1788
+
1789
+ return false;
1790
+
1791
+ }
1792
+
1793
+ }
1794
+
1795
+ }
1796
+
1797
+ return true;
1798
+
1799
+ } else if ( node.isConstNode ) {
1800
+
1801
+ return true;
1802
+
1803
+ }
1804
+
1805
+ return false;
1806
+
1807
+ }
1808
+
1809
+ /**
1810
+ * Returns an instance of {@link NodeVarying} for the given varying node.
1811
+ *
1812
+ * @param {(VaryingNode|PropertyNode)} node - The varying node.
1813
+ * @param {?string} name - The varying's name.
1814
+ * @param {string} [type=node.getNodeType( this )] - The varying's type.
1815
+ * @return {NodeVar} The node varying.
1816
+ */
873
1817
  getVaryingFromNode( node, name = null, type = node.getNodeType( this ) ) {
874
1818
 
875
1819
  const nodeData = this.getDataFromNode( node, 'any' );
@@ -895,6 +1839,14 @@ class NodeBuilder {
895
1839
 
896
1840
  }
897
1841
 
1842
+ /**
1843
+ * Returns an instance of {@link NodeCode} for the given code node.
1844
+ *
1845
+ * @param {CodeNode} node - The code node.
1846
+ * @param {string} type - The node type.
1847
+ * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
1848
+ * @return {NodeCode} The node code.
1849
+ */
898
1850
  getCodeFromNode( node, type, shaderStage = this.shaderStage ) {
899
1851
 
900
1852
  const nodeData = this.getDataFromNode( node );
@@ -918,10 +1870,82 @@ class NodeBuilder {
918
1870
 
919
1871
  }
920
1872
 
921
- addLineFlowCode( code ) {
1873
+ /**
1874
+ * Adds a code flow based on the code-block hierarchy.
1875
+
1876
+ * This is used so that code-blocks like If,Else create their variables locally if the Node
1877
+ * is only used inside one of these conditionals in the current shader stage.
1878
+ *
1879
+ * @param {Node} node - The node to add.
1880
+ * @param {Node} nodeBlock - Node-based code-block. Usually 'ConditionalNode'.
1881
+ */
1882
+ addFlowCodeHierarchy( node, nodeBlock ) {
1883
+
1884
+ const { flowCodes, flowCodeBlock } = this.getDataFromNode( node );
1885
+
1886
+ let needsFlowCode = true;
1887
+ let nodeBlockHierarchy = nodeBlock;
1888
+
1889
+ while ( nodeBlockHierarchy ) {
1890
+
1891
+ if ( flowCodeBlock.get( nodeBlockHierarchy ) === true ) {
1892
+
1893
+ needsFlowCode = false;
1894
+ break;
1895
+
1896
+ }
1897
+
1898
+ nodeBlockHierarchy = this.getDataFromNode( nodeBlockHierarchy ).parentNodeBlock;
1899
+
1900
+ }
1901
+
1902
+ if ( needsFlowCode ) {
1903
+
1904
+ for ( const flowCode of flowCodes ) {
1905
+
1906
+ this.addLineFlowCode( flowCode );
1907
+
1908
+ }
1909
+
1910
+ }
1911
+
1912
+ }
1913
+
1914
+ /**
1915
+ * Add a inline-code to the current flow code-block.
1916
+ *
1917
+ * @param {Node} node - The node to add.
1918
+ * @param {string} code - The code to add.
1919
+ * @param {Node} nodeBlock - Current ConditionalNode
1920
+ */
1921
+ addLineFlowCodeBlock( node, code, nodeBlock ) {
1922
+
1923
+ const nodeData = this.getDataFromNode( node );
1924
+ const flowCodes = nodeData.flowCodes || ( nodeData.flowCodes = [] );
1925
+ const codeBlock = nodeData.flowCodeBlock || ( nodeData.flowCodeBlock = new WeakMap() );
1926
+
1927
+ flowCodes.push( code );
1928
+ codeBlock.set( nodeBlock, true );
1929
+
1930
+ }
1931
+
1932
+ /**
1933
+ * Add a inline-code to the current flow.
1934
+ *
1935
+ * @param {string} code - The code to add.
1936
+ * @param {?Node} [node= null] - Optional Node, can help the system understand if the Node is part of a code-block.
1937
+ * @return {NodeBuilder} A reference to this node builder.
1938
+ */
1939
+ addLineFlowCode( code, node = null ) {
922
1940
 
923
1941
  if ( code === '' ) return this;
924
1942
 
1943
+ if ( node !== null && this.context.nodeBlock ) {
1944
+
1945
+ this.addLineFlowCodeBlock( node, code, this.context.nodeBlock );
1946
+
1947
+ }
1948
+
925
1949
  code = this.tab + code;
926
1950
 
927
1951
  if ( ! /;\s*$/.test( code ) ) {
@@ -936,6 +1960,12 @@ class NodeBuilder {
936
1960
 
937
1961
  }
938
1962
 
1963
+ /**
1964
+ * Adds a code to the current code flow.
1965
+ *
1966
+ * @param {string} code - Shader code.
1967
+ * @return {NodeBuilder} A reference to this node builder.
1968
+ */
939
1969
  addFlowCode( code ) {
940
1970
 
941
1971
  this.flow.code += code;
@@ -944,6 +1974,12 @@ class NodeBuilder {
944
1974
 
945
1975
  }
946
1976
 
1977
+ /**
1978
+ * Add tab in the code that will be generated so that other snippets respect the current tabulation.
1979
+ * Typically used in codes with If,Else.
1980
+ *
1981
+ * @return {NodeBuilder} A reference to this node builder.
1982
+ */
947
1983
  addFlowTab() {
948
1984
 
949
1985
  this.tab += '\t';
@@ -952,6 +1988,11 @@ class NodeBuilder {
952
1988
 
953
1989
  }
954
1990
 
1991
+ /**
1992
+ * Removes a tab.
1993
+ *
1994
+ * @return {NodeBuilder} A reference to this node builder.
1995
+ */
955
1996
  removeFlowTab() {
956
1997
 
957
1998
  this.tab = this.tab.slice( 0, - 1 );
@@ -960,12 +2001,25 @@ class NodeBuilder {
960
2001
 
961
2002
  }
962
2003
 
2004
+ /**
2005
+ * Gets the current flow data based on a Node.
2006
+ *
2007
+ * @param {Node} node - Node that the flow was started.
2008
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2009
+ * @return {Object} The flow data.
2010
+ */
963
2011
  getFlowData( node/*, shaderStage*/ ) {
964
2012
 
965
2013
  return this.flowsData.get( node );
966
2014
 
967
2015
  }
968
2016
 
2017
+ /**
2018
+ * Executes the node flow based on a root node to generate the final shader code.
2019
+ *
2020
+ * @param {Node} node - The node to execute.
2021
+ * @return {Object} The code flow.
2022
+ */
969
2023
  flowNode( node ) {
970
2024
 
971
2025
  const output = node.getNodeType( this );
@@ -978,6 +2032,29 @@ class NodeBuilder {
978
2032
 
979
2033
  }
980
2034
 
2035
+ /**
2036
+ * Includes a node in the current function node.
2037
+ *
2038
+ * @param {Node} node - The node to include.
2039
+ * @returns {void}
2040
+ */
2041
+ addInclude( node ) {
2042
+
2043
+ if ( this.currentFunctionNode !== null ) {
2044
+
2045
+ this.currentFunctionNode.includes.push( node );
2046
+
2047
+ }
2048
+
2049
+ }
2050
+
2051
+ /**
2052
+ * Returns the native shader operator name for a given generic name.
2053
+ * It is a similar type of method like {@link NodeBuilder#getMethod}.
2054
+ *
2055
+ * @param {ShaderNodeInternal} shaderNode - The shader node to build the function node with.
2056
+ * @return {FunctionNode} The build function node.
2057
+ */
981
2058
  buildFunctionNode( shaderNode ) {
982
2059
 
983
2060
  const fn = new FunctionNode();
@@ -994,31 +2071,34 @@ class NodeBuilder {
994
2071
 
995
2072
  }
996
2073
 
2074
+ /**
2075
+ * Generates a code flow based on a TSL function: Fn().
2076
+ *
2077
+ * @param {ShaderNodeInternal} shaderNode - A function code will be generated based on the input.
2078
+ * @return {Object}
2079
+ */
997
2080
  flowShaderNode( shaderNode ) {
998
2081
 
999
2082
  const layout = shaderNode.layout;
1000
2083
 
1001
- let inputs;
1002
-
1003
- if ( shaderNode.isArrayInput ) {
2084
+ const inputs = {
2085
+ [ Symbol.iterator ]() {
1004
2086
 
1005
- inputs = [];
1006
-
1007
- for ( const input of layout.inputs ) {
1008
-
1009
- inputs.push( new ParameterNode( input.type, input.name ) );
2087
+ let index = 0;
2088
+ const values = Object.values( this );
2089
+ return {
2090
+ next: () => ( {
2091
+ value: values[ index ],
2092
+ done: index ++ >= values.length
2093
+ } )
2094
+ };
1010
2095
 
1011
2096
  }
2097
+ };
1012
2098
 
1013
- } else {
1014
-
1015
- inputs = {};
1016
-
1017
- for ( const input of layout.inputs ) {
1018
-
1019
- inputs[ input.name ] = new ParameterNode( input.type, input.name );
2099
+ for ( const input of layout.inputs ) {
1020
2100
 
1021
- }
2101
+ inputs[ input.name ] = new ParameterNode( input.type, input.name );
1022
2102
 
1023
2103
  }
1024
2104
 
@@ -1035,6 +2115,13 @@ class NodeBuilder {
1035
2115
 
1036
2116
  }
1037
2117
 
2118
+ /**
2119
+ * Runs the node flow through all the steps of creation, 'setup', 'analyze', 'generate'.
2120
+ *
2121
+ * @param {Node} node - The node to execute.
2122
+ * @param {?string} output - Expected output type. For example 'vec3'.
2123
+ * @return {Object}
2124
+ */
1038
2125
  flowStagesNode( node, output = null ) {
1039
2126
 
1040
2127
  const previousFlow = this.flow;
@@ -1073,12 +2160,27 @@ class NodeBuilder {
1073
2160
 
1074
2161
  }
1075
2162
 
1076
- getFunctionOperator() {
2163
+ /**
2164
+ * Returns the native shader operator name for a given generic name.
2165
+ * It is a similar type of method like {@link NodeBuilder#getMethod}.
2166
+ *
2167
+ * @abstract
2168
+ * @param {string} op - The operator name to resolve.
2169
+ * @return {string} The resolved operator name.
2170
+ */
2171
+ getFunctionOperator( /* op */ ) {
1077
2172
 
1078
2173
  return null;
1079
2174
 
1080
2175
  }
1081
2176
 
2177
+ /**
2178
+ * Generates a code flow based on a child Node.
2179
+ *
2180
+ * @param {Node} node - The node to execute.
2181
+ * @param {?string} output - Expected output type. For example 'vec3'.
2182
+ * @return {Object} The code flow.
2183
+ */
1082
2184
  flowChildNode( node, output = null ) {
1083
2185
 
1084
2186
  const previousFlow = this.flow;
@@ -1097,6 +2199,18 @@ class NodeBuilder {
1097
2199
 
1098
2200
  }
1099
2201
 
2202
+ /**
2203
+ * Executes a flow of code in a different stage.
2204
+ *
2205
+ * Some nodes like `varying()` have the ability to compute code in vertex-stage and
2206
+ * return the value in fragment-stage even if it is being executed in an input fragment.
2207
+ *
2208
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2209
+ * @param {Node} node - The node to execute.
2210
+ * @param {?string} output - Expected output type. For example 'vec3'.
2211
+ * @param {?string} propertyName - The property name to assign the result.
2212
+ * @return {Object}
2213
+ */
1100
2214
  flowNodeFromShaderStage( shaderStage, node, output = null, propertyName = null ) {
1101
2215
 
1102
2216
  const previousShaderStage = this.shaderStage;
@@ -1119,30 +2233,63 @@ class NodeBuilder {
1119
2233
 
1120
2234
  }
1121
2235
 
2236
+ /**
2237
+ * Returns an array holding all node attributes of this node builder.
2238
+ *
2239
+ * @return {Array<NodeAttribute>} The node attributes of this builder.
2240
+ */
1122
2241
  getAttributesArray() {
1123
2242
 
1124
2243
  return this.attributes.concat( this.bufferAttributes );
1125
2244
 
1126
2245
  }
1127
2246
 
2247
+ /**
2248
+ * Returns the attribute definitions as a shader string for the given shader stage.
2249
+ *
2250
+ * @abstract
2251
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2252
+ * @return {string} The attribute code section.
2253
+ */
1128
2254
  getAttributes( /*shaderStage*/ ) {
1129
2255
 
1130
2256
  console.warn( 'Abstract function.' );
1131
2257
 
1132
2258
  }
1133
2259
 
2260
+ /**
2261
+ * Returns the varying definitions as a shader string for the given shader stage.
2262
+ *
2263
+ * @abstract
2264
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2265
+ * @return {string} The varying code section.
2266
+ */
1134
2267
  getVaryings( /*shaderStage*/ ) {
1135
2268
 
1136
2269
  console.warn( 'Abstract function.' );
1137
2270
 
1138
2271
  }
1139
2272
 
1140
- getVar( type, name ) {
2273
+ /**
2274
+ * Returns a single variable definition as a shader string for the given variable type and name.
2275
+ *
2276
+ * @param {string} type - The variable's type.
2277
+ * @param {string} name - The variable's name.
2278
+ * @param {?number} [count=null] - The array length.
2279
+ * @return {string} The shader string.
2280
+ */
2281
+ getVar( type, name, count = null ) {
1141
2282
 
1142
- return `${ this.getType( type ) } ${ name }`;
2283
+ return `${ count !== null ? this.generateArrayDeclaration( type, count ) : this.getType( type ) } ${ name }`;
1143
2284
 
1144
2285
  }
1145
2286
 
2287
+ /**
2288
+ * Returns the variable definitions as a shader string for the given shader stage.
2289
+ *
2290
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2291
+ * @return {string} The variable code section.
2292
+ */
1146
2293
  getVars( shaderStage ) {
1147
2294
 
1148
2295
  let snippet = '';
@@ -1163,12 +2310,25 @@ class NodeBuilder {
1163
2310
 
1164
2311
  }
1165
2312
 
2313
+ /**
2314
+ * Returns the uniform definitions as a shader string for the given shader stage.
2315
+ *
2316
+ * @abstract
2317
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2318
+ * @return {string} The uniform code section.
2319
+ */
1166
2320
  getUniforms( /*shaderStage*/ ) {
1167
2321
 
1168
2322
  console.warn( 'Abstract function.' );
1169
2323
 
1170
2324
  }
1171
2325
 
2326
+ /**
2327
+ * Returns the native code definitions as a shader string for the given shader stage.
2328
+ *
2329
+ * @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
2330
+ * @return {string} The native code section.
2331
+ */
1172
2332
  getCodes( shaderStage ) {
1173
2333
 
1174
2334
  const codes = this.codes[ shaderStage ];
@@ -1189,50 +2349,94 @@ class NodeBuilder {
1189
2349
 
1190
2350
  }
1191
2351
 
2352
+ /**
2353
+ * Returns the hash of this node builder.
2354
+ *
2355
+ * @return {string} The hash.
2356
+ */
1192
2357
  getHash() {
1193
2358
 
1194
2359
  return this.vertexShader + this.fragmentShader + this.computeShader;
1195
2360
 
1196
2361
  }
1197
2362
 
2363
+ /**
2364
+ * Sets the current shader stage.
2365
+ *
2366
+ * @param {?('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage to set.
2367
+ */
1198
2368
  setShaderStage( shaderStage ) {
1199
2369
 
1200
2370
  this.shaderStage = shaderStage;
1201
2371
 
1202
2372
  }
1203
2373
 
2374
+ /**
2375
+ * Returns the current shader stage.
2376
+ *
2377
+ * @return {?('vertex'|'fragment'|'compute'|'any')} The current shader stage.
2378
+ */
1204
2379
  getShaderStage() {
1205
2380
 
1206
2381
  return this.shaderStage;
1207
2382
 
1208
2383
  }
1209
2384
 
2385
+ /**
2386
+ * Sets the current build stage.
2387
+ *
2388
+ * @param {?('setup'|'analyze'|'generate')} buildStage - The build stage to set.
2389
+ */
1210
2390
  setBuildStage( buildStage ) {
1211
2391
 
1212
2392
  this.buildStage = buildStage;
1213
2393
 
1214
2394
  }
1215
2395
 
2396
+ /**
2397
+ * Returns the current build stage.
2398
+ *
2399
+ * @return {?('setup'|'analyze'|'generate')} The current build stage.
2400
+ */
1216
2401
  getBuildStage() {
1217
2402
 
1218
2403
  return this.buildStage;
1219
2404
 
1220
2405
  }
1221
2406
 
2407
+ /**
2408
+ * Controls the code build of the shader stages.
2409
+ *
2410
+ * @abstract
2411
+ */
1222
2412
  buildCode() {
1223
2413
 
1224
2414
  console.warn( 'Abstract function.' );
1225
2415
 
1226
2416
  }
1227
2417
 
2418
+ /**
2419
+ * Central build method which controls the build for the given object.
2420
+ *
2421
+ * @return {NodeBuilder} A reference to this node builder.
2422
+ */
1228
2423
  build() {
1229
2424
 
1230
- const { object, material } = this;
1231
-
2425
+ const { object, material, renderer } = this;
1232
2426
 
1233
2427
  if ( material !== null ) {
1234
2428
 
1235
- NodeMaterial.fromMaterial( material ).build( this );
2429
+ let nodeMaterial = renderer.library.fromMaterial( material );
2430
+
2431
+ if ( nodeMaterial === null ) {
2432
+
2433
+ console.error( `NodeMaterial: Material "${ material.type }" is not compatible.` );
2434
+
2435
+ nodeMaterial = new NodeMaterial();
2436
+
2437
+ }
2438
+
2439
+ nodeMaterial.build( this );
1236
2440
 
1237
2441
  } else {
1238
2442
 
@@ -1290,6 +2494,13 @@ class NodeBuilder {
1290
2494
 
1291
2495
  }
1292
2496
 
2497
+ /**
2498
+ * Returns a uniform representation which is later used for UBO generation and rendering.
2499
+ *
2500
+ * @param {NodeUniform} uniformNode - The uniform node.
2501
+ * @param {string} type - The requested type.
2502
+ * @return {Uniform} The uniform.
2503
+ */
1293
2504
  getNodeUniform( uniformNode, type ) {
1294
2505
 
1295
2506
  if ( type === 'float' || type === 'int' || type === 'uint' ) return new NumberNodeUniform( uniformNode );
@@ -1297,6 +2508,7 @@ class NodeBuilder {
1297
2508
  if ( type === 'vec3' || type === 'ivec3' || type === 'uvec3' ) return new Vector3NodeUniform( uniformNode );
1298
2509
  if ( type === 'vec4' || type === 'ivec4' || type === 'uvec4' ) return new Vector4NodeUniform( uniformNode );
1299
2510
  if ( type === 'color' ) return new ColorNodeUniform( uniformNode );
2511
+ if ( type === 'mat2' ) return new Matrix2NodeUniform( uniformNode );
1300
2512
  if ( type === 'mat3' ) return new Matrix3NodeUniform( uniformNode );
1301
2513
  if ( type === 'mat4' ) return new Matrix4NodeUniform( uniformNode );
1302
2514
 
@@ -1304,14 +2516,16 @@ class NodeBuilder {
1304
2516
 
1305
2517
  }
1306
2518
 
1307
- createNodeMaterial( type = 'NodeMaterial' ) {
1308
-
1309
- // TODO: Move Materials.js to outside of the Nodes.js in order to remove this function and improve tree-shaking support
1310
-
1311
- return createNodeMaterialFromType( type );
1312
-
1313
- }
1314
-
2519
+ /**
2520
+ * Formats the given shader snippet from a given type into another one. E.g.
2521
+ * this method might be used to convert a simple float string `"1.0"` into a
2522
+ * `vec3` representation: `"vec3<f32>( 1.0 )"`.
2523
+ *
2524
+ * @param {string} snippet - The shader snippet.
2525
+ * @param {string} fromType - The source type.
2526
+ * @param {string} toType - The target type.
2527
+ * @return {string} The updated shader string.
2528
+ */
1315
2529
  format( snippet, fromType, toType ) {
1316
2530
 
1317
2531
  fromType = this.getVectorType( fromType );
@@ -1392,12 +2606,32 @@ class NodeBuilder {
1392
2606
 
1393
2607
  }
1394
2608
 
2609
+ /**
2610
+ * Returns a signature with the engine's current revision.
2611
+ *
2612
+ * @return {string} The signature.
2613
+ */
1395
2614
  getSignature() {
1396
2615
 
1397
2616
  return `// Three.js r${ REVISION } - Node System\n`;
1398
2617
 
1399
2618
  }
1400
2619
 
2620
+ // Deprecated
2621
+
2622
+ /**
2623
+ * @function
2624
+ * @deprecated since r168. Use `new NodeMaterial()` instead, with targeted node material name.
2625
+ *
2626
+ * @param {string} [type='NodeMaterial'] - The node material type.
2627
+ * @throws {Error}
2628
+ */
2629
+ createNodeMaterial( type = 'NodeMaterial' ) { // @deprecated, r168
2630
+
2631
+ throw new Error( `THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${ type }() instead.` );
2632
+
2633
+ }
2634
+
1401
2635
  }
1402
2636
 
1403
2637
  export default NodeBuilder;