three-stdlib 2.8.9 → 2.8.12

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 (480) hide show
  1. package/Nodes-607e9ed8.js +471 -0
  2. package/Nodes-627a8bdf.js +1 -0
  3. package/index.cjs.js +1 -1
  4. package/index.d.ts +1 -127
  5. package/index.js +122 -128
  6. package/lines/LineMaterial.d.ts +7 -6
  7. package/loaders/NodeMaterialLoader.cjs.js +1 -1
  8. package/loaders/NodeMaterialLoader.js +2 -136
  9. package/modifiers/CurveModifier.cjs.js +1 -1
  10. package/modifiers/CurveModifier.d.ts +13 -9
  11. package/modifiers/CurveModifier.js +27 -30
  12. package/nodes/Nodes.cjs.js +1 -1
  13. package/nodes/Nodes.js +203 -76
  14. package/nodes/ShaderNode.cjs.js +1 -0
  15. package/nodes/ShaderNode.js +308 -0
  16. package/nodes/accessors/BufferNode.cjs.js +1 -0
  17. package/nodes/accessors/BufferNode.js +18 -0
  18. package/nodes/accessors/CameraNode.cjs.js +1 -1
  19. package/nodes/accessors/CameraNode.js +32 -138
  20. package/nodes/accessors/CubeTextureNode.cjs.js +1 -0
  21. package/nodes/accessors/CubeTextureNode.js +53 -0
  22. package/nodes/accessors/MaterialNode.cjs.js +1 -0
  23. package/nodes/accessors/MaterialNode.js +80 -0
  24. package/nodes/accessors/MaterialReferenceNode.cjs.js +1 -0
  25. package/nodes/accessors/MaterialReferenceNode.js +16 -0
  26. package/nodes/accessors/ModelNode.cjs.js +1 -0
  27. package/nodes/accessors/ModelNode.js +10 -0
  28. package/nodes/accessors/ModelViewProjectionNode.cjs.js +1 -0
  29. package/nodes/accessors/ModelViewProjectionNode.js +22 -0
  30. package/nodes/accessors/NormalNode.cjs.js +1 -1
  31. package/nodes/accessors/NormalNode.js +48 -78
  32. package/nodes/accessors/Object3DNode.cjs.js +1 -0
  33. package/nodes/accessors/Object3DNode.js +85 -0
  34. package/nodes/accessors/PointUVNode.cjs.js +1 -0
  35. package/nodes/accessors/PointUVNode.js +16 -0
  36. package/nodes/accessors/PositionNode.cjs.js +1 -1
  37. package/nodes/accessors/PositionNode.js +49 -87
  38. package/nodes/accessors/ReferenceNode.cjs.js +1 -0
  39. package/nodes/accessors/ReferenceNode.js +43 -0
  40. package/nodes/accessors/ReflectNode.cjs.js +1 -1
  41. package/nodes/accessors/ReflectNode.js +35 -98
  42. package/nodes/accessors/SkinningNode.cjs.js +1 -0
  43. package/nodes/accessors/SkinningNode.js +59 -0
  44. package/nodes/accessors/TextureNode.cjs.js +1 -0
  45. package/nodes/accessors/TextureNode.js +68 -0
  46. package/nodes/accessors/UVNode.cjs.js +1 -1
  47. package/nodes/accessors/UVNode.js +20 -38
  48. package/nodes/core/ArrayUniformNode.cjs.js +1 -0
  49. package/nodes/core/ArrayUniformNode.js +17 -0
  50. package/nodes/core/AttributeNode.cjs.js +1 -1
  51. package/nodes/core/AttributeNode.js +31 -40
  52. package/nodes/core/BypassNode.cjs.js +1 -0
  53. package/nodes/core/BypassNode.js +28 -0
  54. package/nodes/core/CodeNode.cjs.js +1 -0
  55. package/nodes/core/CodeNode.js +35 -0
  56. package/nodes/core/ConstNode.cjs.js +1 -1
  57. package/nodes/core/ConstNode.js +10 -78
  58. package/nodes/core/ContextNode.cjs.js +1 -0
  59. package/nodes/core/ContextNode.js +26 -0
  60. package/nodes/core/ExpressionNode.cjs.js +1 -1
  61. package/nodes/core/ExpressionNode.js +19 -8
  62. package/nodes/core/FunctionCallNode.cjs.js +1 -1
  63. package/nodes/core/FunctionCallNode.js +31 -60
  64. package/nodes/core/FunctionNode.cjs.js +1 -1
  65. package/nodes/core/FunctionNode.js +45 -166
  66. package/nodes/core/InputNode.cjs.js +1 -1
  67. package/nodes/core/InputNode.js +43 -57
  68. package/nodes/core/Node.cjs.js +1 -1
  69. package/nodes/core/Node.js +155 -113
  70. package/nodes/core/NodeAttribute.cjs.js +1 -0
  71. package/nodes/core/NodeAttribute.js +11 -0
  72. package/nodes/core/NodeBuilder.cjs.js +1 -1
  73. package/nodes/core/NodeBuilder.js +422 -548
  74. package/nodes/core/NodeCode.cjs.js +1 -0
  75. package/nodes/core/NodeCode.js +13 -0
  76. package/nodes/core/NodeFrame.cjs.js +1 -1
  77. package/nodes/core/NodeFrame.js +34 -27
  78. package/nodes/core/NodeFunction.cjs.js +1 -0
  79. package/nodes/core/NodeFunction.js +17 -0
  80. package/nodes/core/NodeFunctionInput.cjs.js +1 -0
  81. package/nodes/core/NodeFunctionInput.js +14 -0
  82. package/nodes/core/NodeKeywords.cjs.js +1 -0
  83. package/nodes/core/NodeKeywords.js +54 -0
  84. package/nodes/core/NodeParser.cjs.js +1 -0
  85. package/nodes/core/NodeParser.js +8 -0
  86. package/nodes/core/NodeUniform.cjs.js +1 -1
  87. package/nodes/core/NodeUniform.js +18 -17
  88. package/nodes/core/NodeUtils.cjs.js +1 -1
  89. package/nodes/core/NodeUtils.js +55 -35
  90. package/nodes/core/NodeVar.cjs.js +1 -0
  91. package/nodes/core/NodeVar.js +11 -0
  92. package/nodes/core/NodeVary.cjs.js +1 -0
  93. package/nodes/core/NodeVary.js +11 -0
  94. package/nodes/core/PropertyNode.cjs.js +1 -0
  95. package/nodes/core/PropertyNode.js +26 -0
  96. package/nodes/core/TempNode.cjs.js +1 -1
  97. package/nodes/core/TempNode.js +21 -88
  98. package/nodes/core/UniformNode.cjs.js +1 -0
  99. package/nodes/core/UniformNode.js +28 -0
  100. package/nodes/core/VarNode.cjs.js +1 -1
  101. package/nodes/core/VarNode.js +28 -35
  102. package/nodes/core/VaryNode.cjs.js +1 -0
  103. package/nodes/core/VaryNode.js +38 -0
  104. package/nodes/core/constants.cjs.js +1 -0
  105. package/nodes/core/constants.js +11 -0
  106. package/nodes/display/ColorSpaceNode.cjs.js +1 -0
  107. package/nodes/display/ColorSpaceNode.js +67 -0
  108. package/nodes/display/NormalMapNode.cjs.js +1 -0
  109. package/nodes/display/NormalMapNode.js +71 -0
  110. package/nodes/fog/FogNode.cjs.js +1 -0
  111. package/nodes/fog/FogNode.js +18 -0
  112. package/nodes/fog/FogRangeNode.cjs.js +1 -0
  113. package/nodes/fog/FogRangeNode.js +20 -0
  114. package/nodes/functions/BSDFs.cjs.js +1 -0
  115. package/nodes/functions/BSDFs.js +121 -0
  116. package/nodes/functions/PhysicalMaterialFunctions.cjs.js +1 -0
  117. package/nodes/functions/PhysicalMaterialFunctions.js +57 -0
  118. package/nodes/lights/LightContextNode.cjs.js +1 -0
  119. package/nodes/lights/LightContextNode.js +43 -0
  120. package/nodes/lights/LightNode.cjs.js +1 -0
  121. package/nodes/lights/LightNode.js +61 -0
  122. package/nodes/lights/LightsNode.cjs.js +1 -0
  123. package/nodes/lights/LightsNode.js +77 -0
  124. package/nodes/loaders/NodeLoader.cjs.js +1 -0
  125. package/nodes/loaders/NodeLoader.js +80 -0
  126. package/nodes/loaders/NodeMaterialLoader.cjs.js +1 -0
  127. package/nodes/loaders/NodeMaterialLoader.js +29 -0
  128. package/nodes/loaders/NodeObjectLoader.cjs.js +1 -0
  129. package/nodes/loaders/NodeObjectLoader.js +49 -0
  130. package/nodes/materials/LineBasicNodeMaterial.cjs.js +1 -0
  131. package/nodes/materials/LineBasicNodeMaterial.js +31 -0
  132. package/nodes/materials/Materials.cjs.js +1 -0
  133. package/nodes/materials/Materials.js +27 -0
  134. package/nodes/materials/MeshBasicNodeMaterial.cjs.js +1 -0
  135. package/nodes/materials/MeshBasicNodeMaterial.js +32 -0
  136. package/nodes/materials/MeshStandardNodeMaterial.cjs.js +1 -1
  137. package/nodes/materials/MeshStandardNodeMaterial.js +41 -13
  138. package/nodes/materials/NodeMaterial.cjs.js +1 -1
  139. package/nodes/materials/NodeMaterial.js +67 -140
  140. package/nodes/materials/PointsNodeMaterial.cjs.js +1 -0
  141. package/nodes/materials/PointsNodeMaterial.js +34 -0
  142. package/nodes/math/CondNode.cjs.js +1 -1
  143. package/nodes/math/CondNode.js +33 -74
  144. package/nodes/math/MathNode.cjs.js +1 -1
  145. package/nodes/math/MathNode.js +193 -193
  146. package/nodes/math/OperatorNode.cjs.js +1 -1
  147. package/nodes/math/OperatorNode.js +116 -52
  148. package/nodes/parsers/GLSLNodeFunction.cjs.js +1 -0
  149. package/nodes/parsers/GLSLNodeFunction.js +101 -0
  150. package/nodes/parsers/GLSLNodeParser.cjs.js +1 -0
  151. package/nodes/parsers/GLSLNodeParser.js +13 -0
  152. package/nodes/parsers/WGSLNodeFunction.cjs.js +1 -0
  153. package/nodes/parsers/WGSLNodeFunction.js +71 -0
  154. package/nodes/parsers/WGSLNodeParser.cjs.js +1 -0
  155. package/nodes/parsers/WGSLNodeParser.js +13 -0
  156. package/nodes/procedural/CheckerNode.cjs.js +1 -1
  157. package/nodes/procedural/CheckerNode.js +22 -40
  158. package/nodes/utils/ArrayElementNode.cjs.js +1 -0
  159. package/nodes/utils/ArrayElementNode.js +22 -0
  160. package/nodes/utils/ConvertNode.cjs.js +1 -0
  161. package/nodes/utils/ConvertNode.js +29 -0
  162. package/nodes/utils/JoinNode.cjs.js +1 -1
  163. package/nodes/utils/JoinNode.js +19 -69
  164. package/nodes/utils/MatcapUVNode.cjs.js +1 -0
  165. package/nodes/utils/MatcapUVNode.js +18 -0
  166. package/nodes/utils/OscNode.cjs.js +1 -0
  167. package/nodes/utils/OscNode.js +55 -0
  168. package/nodes/utils/SplitNode.cjs.js +1 -0
  169. package/nodes/utils/SplitNode.js +58 -0
  170. package/nodes/utils/SpriteSheetUVNode.cjs.js +1 -0
  171. package/nodes/utils/SpriteSheetUVNode.js +39 -0
  172. package/nodes/utils/TimerNode.cjs.js +1 -1
  173. package/nodes/utils/TimerNode.js +38 -56
  174. package/objects/Lensflare.cjs.js +1 -1
  175. package/objects/Lensflare.js +11 -3
  176. package/package.json +3 -3
  177. package/postprocessing/AfterimagePass.d.ts +2 -30
  178. package/shaders/ACESFilmicToneMappingShader.cjs.js +1 -1
  179. package/shaders/ACESFilmicToneMappingShader.d.ts +9 -0
  180. package/shaders/ACESFilmicToneMappingShader.js +1 -1
  181. package/shaders/AfterimageShader.d.ts +9 -15
  182. package/shaders/BasicShader.cjs.js +1 -1
  183. package/shaders/BasicShader.d.ts +5 -5
  184. package/shaders/BasicShader.js +1 -1
  185. package/shaders/BleachBypassShader.cjs.js +1 -1
  186. package/shaders/BleachBypassShader.d.ts +8 -9
  187. package/shaders/BleachBypassShader.js +1 -1
  188. package/shaders/BlendShader.cjs.js +1 -1
  189. package/shaders/BlendShader.d.ts +13 -7
  190. package/shaders/BlendShader.js +1 -1
  191. package/shaders/BokehShader.cjs.js +1 -1
  192. package/shaders/BokehShader.d.ts +18 -19
  193. package/shaders/BokehShader.js +1 -1
  194. package/shaders/BokehShader2.cjs.js +1 -1
  195. package/shaders/BokehShader2.d.ts +80 -34
  196. package/shaders/BokehShader2.js +2 -2
  197. package/shaders/BrightnessContrastShader.cjs.js +1 -1
  198. package/shaders/BrightnessContrastShader.d.ts +10 -6
  199. package/shaders/BrightnessContrastShader.js +1 -1
  200. package/shaders/ColorCorrectionShader.cjs.js +1 -1
  201. package/shaders/ColorCorrectionShader.d.ts +14 -7
  202. package/shaders/ColorCorrectionShader.js +1 -1
  203. package/shaders/ColorifyShader.cjs.js +1 -1
  204. package/shaders/ColorifyShader.d.ts +8 -5
  205. package/shaders/ColorifyShader.js +1 -1
  206. package/shaders/ConvolutionShader.cjs.js +1 -1
  207. package/shaders/ConvolutionShader.d.ts +15 -16
  208. package/shaders/ConvolutionShader.js +9 -14
  209. package/shaders/CopyShader.d.ts +8 -12
  210. package/shaders/DOFMipMapShader.cjs.js +1 -1
  211. package/shaders/DOFMipMapShader.d.ts +13 -7
  212. package/shaders/DOFMipMapShader.js +1 -1
  213. package/shaders/DepthLimitedBlurShader.cjs.js +1 -1
  214. package/shaders/DepthLimitedBlurShader.d.ts +26 -25
  215. package/shaders/DepthLimitedBlurShader.js +12 -16
  216. package/shaders/DigitalGlitch.cjs.js +1 -1
  217. package/shaders/DigitalGlitch.d.ts +34 -14
  218. package/shaders/DigitalGlitch.js +1 -10
  219. package/shaders/DotScreenShader.cjs.js +1 -1
  220. package/shaders/DotScreenShader.d.ts +17 -8
  221. package/shaders/DotScreenShader.js +1 -1
  222. package/shaders/FXAAShader.cjs.js +1 -1
  223. package/shaders/FXAAShader.d.ts +8 -5
  224. package/shaders/FXAAShader.js +1 -1
  225. package/shaders/FilmShader.cjs.js +1 -1
  226. package/shaders/FilmShader.d.ts +19 -9
  227. package/shaders/FilmShader.js +1 -1
  228. package/shaders/FocusShader.cjs.js +1 -1
  229. package/shaders/FocusShader.d.ts +16 -8
  230. package/shaders/FocusShader.js +1 -1
  231. package/shaders/FreiChenShader.cjs.js +1 -1
  232. package/shaders/FreiChenShader.d.ts +8 -5
  233. package/shaders/FreiChenShader.js +1 -1
  234. package/shaders/FresnelShader.cjs.js +1 -1
  235. package/shaders/FresnelShader.d.ts +21 -0
  236. package/shaders/FresnelShader.js +1 -1
  237. package/shaders/GammaCorrectionShader.d.ts +7 -7
  238. package/shaders/GodRaysShader.cjs.js +1 -1
  239. package/shaders/GodRaysShader.d.ts +38 -20
  240. package/shaders/GodRaysShader.js +4 -4
  241. package/shaders/HalftoneShader.cjs.js +1 -1
  242. package/shaders/HalftoneShader.d.ts +40 -16
  243. package/shaders/HalftoneShader.js +1 -1
  244. package/shaders/HorizontalBlurShader.d.ts +8 -8
  245. package/shaders/HorizontalTiltShiftShader.cjs.js +1 -1
  246. package/shaders/HorizontalTiltShiftShader.d.ts +10 -6
  247. package/shaders/HorizontalTiltShiftShader.js +1 -1
  248. package/shaders/HueSaturationShader.cjs.js +1 -1
  249. package/shaders/HueSaturationShader.d.ts +10 -6
  250. package/shaders/HueSaturationShader.js +1 -1
  251. package/shaders/KaleidoShader.cjs.js +1 -1
  252. package/shaders/KaleidoShader.d.ts +10 -6
  253. package/shaders/KaleidoShader.js +1 -1
  254. package/shaders/LuminosityHighPassShader.cjs.js +1 -1
  255. package/shaders/LuminosityHighPassShader.d.ts +17 -8
  256. package/shaders/LuminosityHighPassShader.js +1 -1
  257. package/shaders/LuminosityShader.cjs.js +1 -1
  258. package/shaders/LuminosityShader.d.ts +4 -4
  259. package/shaders/LuminosityShader.js +1 -1
  260. package/shaders/MirrorShader.cjs.js +1 -1
  261. package/shaders/MirrorShader.d.ts +7 -5
  262. package/shaders/MirrorShader.js +1 -1
  263. package/shaders/NormalMapShader.cjs.js +1 -1
  264. package/shaders/NormalMapShader.d.ts +14 -7
  265. package/shaders/NormalMapShader.js +1 -1
  266. package/shaders/ParallaxShader.cjs.js +1 -1
  267. package/shaders/ParallaxShader.d.ts +28 -0
  268. package/shaders/ParallaxShader.js +1 -1
  269. package/shaders/PixelShader.cjs.js +1 -1
  270. package/shaders/PixelShader.d.ts +10 -6
  271. package/shaders/PixelShader.js +1 -1
  272. package/shaders/RGBShiftShader.cjs.js +1 -1
  273. package/shaders/RGBShiftShader.d.ts +10 -6
  274. package/shaders/RGBShiftShader.js +1 -1
  275. package/shaders/SAOShader.cjs.js +1 -1
  276. package/shaders/SAOShader.d.ts +24 -29
  277. package/shaders/SAOShader.js +1 -5
  278. package/shaders/SMAAShader.cjs.js +1 -1
  279. package/shaders/SMAAShader.d.ts +31 -16
  280. package/shaders/SMAAShader.js +3 -3
  281. package/shaders/SSAOShader.cjs.js +1 -1
  282. package/shaders/SSAOShader.d.ts +58 -25
  283. package/shaders/SSAOShader.js +3 -3
  284. package/shaders/SSRShader.cjs.js +1 -1
  285. package/shaders/SSRShader.d.ts +67 -36
  286. package/shaders/SSRShader.js +3 -3
  287. package/shaders/SepiaShader.cjs.js +1 -1
  288. package/shaders/SepiaShader.d.ts +7 -5
  289. package/shaders/SepiaShader.js +1 -1
  290. package/shaders/SobelOperatorShader.cjs.js +1 -1
  291. package/shaders/SobelOperatorShader.d.ts +8 -5
  292. package/shaders/SobelOperatorShader.js +1 -1
  293. package/shaders/SubsurfaceScatteringShader.cjs.js +1 -1
  294. package/shaders/SubsurfaceScatteringShader.d.ts +2 -34
  295. package/shaders/SubsurfaceScatteringShader.js +3 -3
  296. package/shaders/TechnicolorShader.cjs.js +1 -1
  297. package/shaders/TechnicolorShader.d.ts +4 -4
  298. package/shaders/TechnicolorShader.js +1 -1
  299. package/shaders/ToneMapShader.cjs.js +1 -1
  300. package/shaders/ToneMapShader.d.ts +19 -9
  301. package/shaders/ToneMapShader.js +1 -1
  302. package/shaders/ToonShader.cjs.js +1 -1
  303. package/shaders/ToonShader.d.ts +80 -34
  304. package/shaders/ToonShader.js +4 -4
  305. package/shaders/TriangleBlurShader.cjs.js +1 -1
  306. package/shaders/TriangleBlurShader.d.ts +8 -5
  307. package/shaders/TriangleBlurShader.js +1 -1
  308. package/shaders/UnpackDepthRGBAShader.cjs.js +1 -1
  309. package/shaders/UnpackDepthRGBAShader.d.ts +7 -5
  310. package/shaders/UnpackDepthRGBAShader.js +1 -1
  311. package/shaders/VerticalBlurShader.cjs.js +1 -1
  312. package/shaders/VerticalBlurShader.d.ts +8 -8
  313. package/shaders/VerticalBlurShader.js +1 -1
  314. package/shaders/VerticalTiltShiftShader.cjs.js +1 -1
  315. package/shaders/VerticalTiltShiftShader.d.ts +10 -6
  316. package/shaders/VerticalTiltShiftShader.js +1 -1
  317. package/shaders/VignetteShader.cjs.js +1 -1
  318. package/shaders/VignetteShader.d.ts +10 -6
  319. package/shaders/VignetteShader.js +1 -1
  320. package/shaders/VolumeShader.cjs.js +1 -1
  321. package/shaders/VolumeShader.d.ts +20 -9
  322. package/shaders/VolumeShader.js +1 -1
  323. package/shaders/WaterRefractionShader.cjs.js +1 -1
  324. package/shaders/WaterRefractionShader.d.ts +16 -8
  325. package/shaders/WaterRefractionShader.js +1 -1
  326. package/shaders/index.cjs.js +1 -0
  327. package/shaders/index.d.ts +53 -0
  328. package/shaders/index.js +53 -0
  329. package/shaders/types.cjs.js +1 -0
  330. package/shaders/types.d.ts +14 -0
  331. package/shaders/types.js +1 -0
  332. package/types/shared.d.ts +0 -20
  333. package/Nodes-894ac9dc.js +0 -1
  334. package/Nodes-af575af7.js +0 -157
  335. package/nodes/accessors/ColorsNode.cjs.js +0 -1
  336. package/nodes/accessors/ColorsNode.d.ts +0 -10
  337. package/nodes/accessors/ColorsNode.js +0 -40
  338. package/nodes/accessors/LightNode.cjs.js +0 -1
  339. package/nodes/accessors/LightNode.d.ts +0 -12
  340. package/nodes/accessors/LightNode.js +0 -41
  341. package/nodes/accessors/ResolutionNode.cjs.js +0 -1
  342. package/nodes/accessors/ResolutionNode.d.ts +0 -14
  343. package/nodes/accessors/ResolutionNode.js +0 -41
  344. package/nodes/accessors/ScreenUVNode.cjs.js +0 -1
  345. package/nodes/accessors/ScreenUVNode.d.ts +0 -11
  346. package/nodes/accessors/ScreenUVNode.js +0 -43
  347. package/nodes/core/NodeLib.cjs.js +0 -1
  348. package/nodes/core/NodeLib.d.ts +0 -22
  349. package/nodes/core/NodeLib.js +0 -37
  350. package/nodes/core/StructNode.cjs.js +0 -1
  351. package/nodes/core/StructNode.d.ts +0 -19
  352. package/nodes/core/StructNode.js +0 -72
  353. package/nodes/effects/BlurNode.cjs.js +0 -1
  354. package/nodes/effects/BlurNode.d.ts +0 -31
  355. package/nodes/effects/BlurNode.js +0 -100
  356. package/nodes/effects/ColorAdjustmentNode.cjs.js +0 -1
  357. package/nodes/effects/ColorAdjustmentNode.d.ts +0 -27
  358. package/nodes/effects/ColorAdjustmentNode.js +0 -73
  359. package/nodes/effects/LuminanceNode.cjs.js +0 -1
  360. package/nodes/effects/LuminanceNode.d.ts +0 -18
  361. package/nodes/effects/LuminanceNode.js +0 -46
  362. package/nodes/inputs/BoolNode.cjs.js +0 -1
  363. package/nodes/inputs/BoolNode.d.ts +0 -19
  364. package/nodes/inputs/BoolNode.js +0 -36
  365. package/nodes/inputs/ColorNode.cjs.js +0 -1
  366. package/nodes/inputs/ColorNode.d.ts +0 -21
  367. package/nodes/inputs/ColorNode.js +0 -41
  368. package/nodes/inputs/CubeTextureNode.cjs.js +0 -1
  369. package/nodes/inputs/CubeTextureNode.d.ts +0 -17
  370. package/nodes/inputs/CubeTextureNode.js +0 -79
  371. package/nodes/inputs/FloatNode.cjs.js +0 -1
  372. package/nodes/inputs/FloatNode.d.ts +0 -19
  373. package/nodes/inputs/FloatNode.js +0 -36
  374. package/nodes/inputs/IntNode.cjs.js +0 -1
  375. package/nodes/inputs/IntNode.d.ts +0 -19
  376. package/nodes/inputs/IntNode.js +0 -36
  377. package/nodes/inputs/Matrix3Node.cjs.js +0 -1
  378. package/nodes/inputs/Matrix3Node.d.ts +0 -22
  379. package/nodes/inputs/Matrix3Node.js +0 -46
  380. package/nodes/inputs/Matrix4Node.cjs.js +0 -1
  381. package/nodes/inputs/Matrix4Node.d.ts +0 -22
  382. package/nodes/inputs/Matrix4Node.js +0 -46
  383. package/nodes/inputs/PropertyNode.cjs.js +0 -1
  384. package/nodes/inputs/PropertyNode.d.ts +0 -10
  385. package/nodes/inputs/PropertyNode.js +0 -35
  386. package/nodes/inputs/RTTNode.cjs.js +0 -1
  387. package/nodes/inputs/RTTNode.d.ts +0 -27
  388. package/nodes/inputs/RTTNode.js +0 -103
  389. package/nodes/inputs/ReflectorNode.cjs.js +0 -1
  390. package/nodes/inputs/ReflectorNode.d.ts +0 -21
  391. package/nodes/inputs/ReflectorNode.js +0 -60
  392. package/nodes/inputs/ScreenNode.cjs.js +0 -1
  393. package/nodes/inputs/ScreenNode.d.ts +0 -11
  394. package/nodes/inputs/ScreenNode.js +0 -20
  395. package/nodes/inputs/TextureNode.cjs.js +0 -1
  396. package/nodes/inputs/TextureNode.d.ts +0 -20
  397. package/nodes/inputs/TextureNode.js +0 -83
  398. package/nodes/inputs/Vector2Node.cjs.js +0 -1
  399. package/nodes/inputs/Vector2Node.d.ts +0 -21
  400. package/nodes/inputs/Vector2Node.js +0 -40
  401. package/nodes/inputs/Vector3Node.cjs.js +0 -1
  402. package/nodes/inputs/Vector3Node.d.ts +0 -21
  403. package/nodes/inputs/Vector3Node.js +0 -41
  404. package/nodes/inputs/Vector4Node.cjs.js +0 -1
  405. package/nodes/inputs/Vector4Node.d.ts +0 -21
  406. package/nodes/inputs/Vector4Node.js +0 -42
  407. package/nodes/materials/BasicNodeMaterial.cjs.js +0 -1
  408. package/nodes/materials/BasicNodeMaterial.d.ts +0 -11
  409. package/nodes/materials/BasicNodeMaterial.js +0 -15
  410. package/nodes/materials/PhongNodeMaterial.cjs.js +0 -1
  411. package/nodes/materials/PhongNodeMaterial.d.ts +0 -21
  412. package/nodes/materials/PhongNodeMaterial.js +0 -15
  413. package/nodes/materials/SpriteNodeMaterial.cjs.js +0 -1
  414. package/nodes/materials/SpriteNodeMaterial.d.ts +0 -12
  415. package/nodes/materials/SpriteNodeMaterial.js +0 -15
  416. package/nodes/materials/StandardNodeMaterial.cjs.js +0 -1
  417. package/nodes/materials/StandardNodeMaterial.d.ts +0 -25
  418. package/nodes/materials/StandardNodeMaterial.js +0 -15
  419. package/nodes/materials/nodes/BasicNode.cjs.js +0 -1
  420. package/nodes/materials/nodes/BasicNode.d.ts +0 -15
  421. package/nodes/materials/nodes/BasicNode.js +0 -91
  422. package/nodes/materials/nodes/MeshStandardNode.cjs.js +0 -1
  423. package/nodes/materials/nodes/MeshStandardNode.d.ts +0 -25
  424. package/nodes/materials/nodes/MeshStandardNode.js +0 -81
  425. package/nodes/materials/nodes/PhongNode.cjs.js +0 -1
  426. package/nodes/materials/nodes/PhongNode.d.ts +0 -14
  427. package/nodes/materials/nodes/PhongNode.js +0 -212
  428. package/nodes/materials/nodes/RawNode.cjs.js +0 -1
  429. package/nodes/materials/nodes/RawNode.d.ts +0 -10
  430. package/nodes/materials/nodes/RawNode.js +0 -42
  431. package/nodes/materials/nodes/SpriteNode.cjs.js +0 -1
  432. package/nodes/materials/nodes/SpriteNode.d.ts +0 -13
  433. package/nodes/materials/nodes/SpriteNode.js +0 -113
  434. package/nodes/materials/nodes/StandardNode.cjs.js +0 -1
  435. package/nodes/materials/nodes/StandardNode.d.ts +0 -15
  436. package/nodes/materials/nodes/StandardNode.js +0 -336
  437. package/nodes/misc/BumpMapNode.cjs.js +0 -1
  438. package/nodes/misc/BumpMapNode.d.ts +0 -21
  439. package/nodes/misc/BumpMapNode.js +0 -80
  440. package/nodes/misc/NormalMapNode.cjs.js +0 -1
  441. package/nodes/misc/NormalMapNode.d.ts +0 -19
  442. package/nodes/misc/NormalMapNode.js +0 -102
  443. package/nodes/misc/TextureCubeNode.cjs.js +0 -1
  444. package/nodes/misc/TextureCubeNode.d.ts +0 -21
  445. package/nodes/misc/TextureCubeNode.js +0 -52
  446. package/nodes/misc/TextureCubeUVNode.cjs.js +0 -1
  447. package/nodes/misc/TextureCubeUVNode.d.ts +0 -18
  448. package/nodes/misc/TextureCubeUVNode.js +0 -229
  449. package/nodes/postprocessing/NodePass.cjs.js +0 -1
  450. package/nodes/postprocessing/NodePass.d.ts +0 -15
  451. package/nodes/postprocessing/NodePass.js +0 -61
  452. package/nodes/postprocessing/NodePostProcessing.cjs.js +0 -1
  453. package/nodes/postprocessing/NodePostProcessing.d.ts +0 -26
  454. package/nodes/postprocessing/NodePostProcessing.js +0 -91
  455. package/nodes/procedural/NoiseNode.cjs.js +0 -1
  456. package/nodes/procedural/NoiseNode.d.ts +0 -17
  457. package/nodes/procedural/NoiseNode.js +0 -43
  458. package/nodes/utils/BypassNode.cjs.js +0 -1
  459. package/nodes/utils/BypassNode.d.ts +0 -11
  460. package/nodes/utils/BypassNode.js +0 -55
  461. package/nodes/utils/ColorSpaceNode.cjs.js +0 -1
  462. package/nodes/utils/ColorSpaceNode.d.ts +0 -55
  463. package/nodes/utils/ColorSpaceNode.js +0 -106
  464. package/nodes/utils/MaxMIPLevelNode.cjs.js +0 -1
  465. package/nodes/utils/MaxMIPLevelNode.d.ts +0 -11
  466. package/nodes/utils/MaxMIPLevelNode.js +0 -38
  467. package/nodes/utils/SpecularMIPLevelNode.cjs.js +0 -1
  468. package/nodes/utils/SpecularMIPLevelNode.d.ts +0 -17
  469. package/nodes/utils/SpecularMIPLevelNode.js +0 -61
  470. package/nodes/utils/SubSlotNode.cjs.js +0 -1
  471. package/nodes/utils/SubSlotNode.js +0 -53
  472. package/nodes/utils/SwitchNode.cjs.js +0 -1
  473. package/nodes/utils/SwitchNode.d.ts +0 -11
  474. package/nodes/utils/SwitchNode.js +0 -69
  475. package/nodes/utils/UVTransformNode.cjs.js +0 -1
  476. package/nodes/utils/UVTransformNode.d.ts +0 -15
  477. package/nodes/utils/UVTransformNode.js +0 -46
  478. package/nodes/utils/VelocityNode.cjs.js +0 -1
  479. package/nodes/utils/VelocityNode.d.ts +0 -28
  480. package/nodes/utils/VelocityNode.js +0 -115
@@ -1,631 +1,505 @@
1
- import { CubeUVRefractionMapping, CubeUVReflectionMapping, CubeRefractionMapping, CubeReflectionMapping, LinearEncoding, sRGBEncoding } from 'three';
2
- import { NodeUniform } from './NodeUniform.js';
3
- import { NodeUtils } from './NodeUtils.js';
4
- import { NodeLib } from './NodeLib.js';
5
- import { FunctionNode } from './FunctionNode.js';
6
- import { ConstNode } from './ConstNode.js';
7
- import { StructNode } from './StructNode.js';
8
- import { Vector2Node } from '../inputs/Vector2Node.js';
9
- import { Vector3Node } from '../inputs/Vector3Node.js';
10
- import { Vector4Node } from '../inputs/Vector4Node.js';
11
- import { TextureNode } from '../inputs/TextureNode.js';
12
- import { CubeTextureNode } from '../inputs/CubeTextureNode.js';
13
- import { TextureCubeNode } from '../misc/TextureCubeNode.js';
14
-
15
- var elements = NodeUtils.elements,
16
- constructors = ['float', 'vec2', 'vec3', 'vec4'],
17
- convertFormatToType = {
18
- float: 'f',
19
- vec2: 'v2',
20
- vec3: 'v3',
21
- vec4: 'v4',
22
- mat4: 'v4',
23
- int: 'i',
24
- bool: 'b'
25
- },
26
- convertTypeToFormat = {
27
- t: 'sampler2D',
28
- tc: 'samplerCube',
29
- b: 'bool',
30
- i: 'int',
31
- f: 'float',
32
- c: 'vec3',
33
- v2: 'vec2',
34
- v3: 'vec3',
35
- v4: 'vec4',
36
- m3: 'mat3',
37
- m4: 'mat4'
1
+ import NodeUniform from './NodeUniform.js';
2
+ import NodeAttribute from './NodeAttribute.js';
3
+ import NodeVary from './NodeVary.js';
4
+ import NodeVar from './NodeVar.js';
5
+ import NodeCode from './NodeCode.js';
6
+ import NodeKeywords from './NodeKeywords.js';
7
+ import { NodeUpdateType } from './constants.js';
8
+ import { REVISION, LinearEncoding } from 'three';
9
+
10
+ const shaderStages = ['fragment', 'vertex'];
11
+ const vector = ['x', 'y', 'z', 'w'];
12
+
13
+ const toFloat = value => {
14
+ value = Number(value);
15
+ return value + (value % 1 ? '' : '.0');
38
16
  };
39
17
 
40
- function NodeBuilder() {
41
- this.slots = [];
42
- this.caches = [];
43
- this.contexts = [];
44
- this.keywords = {};
45
- this.nodeData = {};
46
- this.requires = {
47
- uv: [],
48
- color: [],
49
- lights: false,
50
- fog: false,
51
- transparent: false,
52
- irradiance: false
53
- };
54
- this.includes = {
55
- consts: [],
56
- functions: [],
57
- structs: []
58
- };
59
- this.attributes = {};
60
- this.prefixCode = ['#ifdef TEXTURE_LOD_EXT', ' #define texCube(a, b) textureCube(a, b)', ' #define texCubeBias(a, b, c) textureCubeLodEXT(a, b, c)', ' #define tex2D(a, b) texture2D(a, b)', ' #define tex2DBias(a, b, c) texture2DLodEXT(a, b, c)', '#else', ' #define texCube(a, b) textureCube(a, b)', ' #define texCubeBias(a, b, c) textureCube(a, b, c)', ' #define tex2D(a, b) texture2D(a, b)', ' #define tex2DBias(a, b, c) texture2D(a, b, c)', '#endif', '#include <packing>', '#include <common>'].join('\n');
61
- this.parsCode = {
62
- vertex: '',
63
- fragment: ''
64
- };
65
- this.code = {
66
- vertex: '',
67
- fragment: ''
68
- };
69
- this.nodeCode = {
70
- vertex: '',
71
- fragment: ''
72
- };
73
- this.resultCode = {
74
- vertex: '',
75
- fragment: ''
76
- };
77
- this.finalCode = {
78
- vertex: '',
79
- fragment: ''
80
- };
81
- this.inputs = {
82
- uniforms: {
83
- list: [],
18
+ class NodeBuilder {
19
+ constructor(object, renderer, parser) {
20
+ this.object = object;
21
+ this.material = object.material;
22
+ this.renderer = renderer;
23
+ this.parser = parser;
24
+ this.nodes = [];
25
+ this.updateNodes = [];
26
+ this.hashNodes = {};
27
+ this.vertexShader = null;
28
+ this.fragmentShader = null;
29
+ this.flowNodes = {
30
+ vertex: [],
31
+ fragment: []
32
+ };
33
+ this.flowCode = {
34
+ vertex: '',
35
+ fragment: ''
36
+ };
37
+ this.uniforms = {
38
+ vertex: [],
39
+ fragment: [],
40
+ index: 0
41
+ };
42
+ this.codes = {
84
43
  vertex: [],
85
44
  fragment: []
86
- },
87
- vars: {
88
- varying: [],
45
+ };
46
+ this.attributes = [];
47
+ this.varys = [];
48
+ this.vars = {
89
49
  vertex: [],
90
50
  fragment: []
91
- }
92
- }; // send to material
51
+ };
52
+ this.flow = {
53
+ code: ''
54
+ };
55
+ this.stack = [];
56
+ this.context = {
57
+ keywords: new NodeKeywords(),
58
+ material: object.material
59
+ };
60
+ this.nodesData = new WeakMap();
61
+ this.flowsData = new WeakMap();
62
+ this.shaderStage = null;
63
+ this.node = null;
64
+ }
93
65
 
94
- this.defines = {};
95
- this.uniforms = {};
96
- this.extensions = {};
97
- this.updaters = [];
98
- this.nodes = []; // --
66
+ addStack(node) {
67
+ /*
68
+ if ( this.stack.indexOf( node ) !== - 1 ) {
69
+ console.warn( 'Recursive node: ', node );
70
+ }
71
+ */
72
+ this.stack.push(node);
73
+ }
99
74
 
100
- this.analyzing = false;
101
- }
75
+ removeStack(node) {
76
+ const lastStack = this.stack.pop();
102
77
 
103
- NodeBuilder.prototype = {
104
- constructor: NodeBuilder,
105
- build: function (vertex, fragment) {
106
- this.buildShader('vertex', vertex);
107
- this.buildShader('fragment', fragment);
78
+ if (lastStack !== node) {
79
+ throw new Error('NodeBuilder: Invalid node stack!');
80
+ }
81
+ }
108
82
 
109
- for (let i = 0; i < this.requires.uv.length; i++) {
110
- if (this.requires.uv[i]) {
111
- var uvIndex = i > 0 ? i + 1 : '';
112
- this.addVaryCode('varying vec2 vUv' + uvIndex + ';');
83
+ setHashNode(node, hash) {
84
+ this.hashNodes[hash] = node;
85
+ }
113
86
 
114
- if (i > 0) {
115
- this.addVertexParsCode('attribute vec2 uv' + uvIndex + ';');
116
- }
87
+ addNode(node) {
88
+ if (this.nodes.indexOf(node) === -1) {
89
+ const updateType = node.getUpdateType(this);
117
90
 
118
- this.addVertexFinalCode('vUv' + uvIndex + ' = uv' + uvIndex + ';');
91
+ if (updateType !== NodeUpdateType.None) {
92
+ this.updateNodes.push(node);
119
93
  }
120
- }
121
94
 
122
- if (this.requires.color[0]) {
123
- this.addVaryCode('varying vec4 vColor;');
124
- this.addVertexParsCode('attribute vec4 color;');
125
- this.addVertexFinalCode('vColor = color;');
95
+ this.nodes.push(node);
96
+ this.setHashNode(node, node.getHash(this));
126
97
  }
98
+ }
127
99
 
128
- if (this.requires.color[1]) {
129
- this.addVaryCode('varying vec4 vColor2;');
130
- this.addVertexParsCode('attribute vec4 color2;');
131
- this.addVertexFinalCode('vColor2 = color2;');
132
- }
100
+ getMethod(method) {
101
+ return method;
102
+ }
133
103
 
134
- if (this.requires.position) {
135
- this.addVaryCode('varying vec3 vPosition;');
136
- this.addVertexFinalCode('vPosition = transformed;');
137
- }
104
+ getNodeFromHash(hash) {
105
+ return this.hashNodes[hash];
106
+ }
138
107
 
139
- if (this.requires.worldPosition) {
140
- this.addVaryCode('varying vec3 vWPosition;');
141
- this.addVertexFinalCode('vWPosition = ( modelMatrix * vec4( transformed, 1.0 ) ).xyz;');
142
- }
108
+ addFlow(shaderStage, node) {
109
+ this.flowNodes[shaderStage].push(node);
110
+ return node;
111
+ }
143
112
 
144
- if (this.requires.normal) {
145
- this.addVaryCode('varying vec3 vObjectNormal;');
146
- this.addVertexFinalCode('vObjectNormal = normal;');
147
- }
113
+ setContext(context) {
114
+ this.context = context;
115
+ }
148
116
 
149
- if (this.requires.worldNormal) {
150
- this.addVaryCode('varying vec3 vWNormal;');
151
- this.addVertexFinalCode('vWNormal = inverseTransformDirection( transformedNormal, viewMatrix ).xyz;');
152
- }
117
+ getContext() {
118
+ return this.context;
119
+ }
153
120
 
154
- return this;
155
- },
156
- buildShader: function (shader, node) {
157
- this.resultCode[shader] = node.build(this.setShader(shader), 'v4');
158
- },
159
- setMaterial: function (material, renderer) {
160
- this.material = material;
161
- this.renderer = renderer;
162
- this.requires.lights = material.lights;
163
- this.requires.fog = material.fog;
164
- this.mergeDefines(material.defines);
165
- return this;
166
- },
167
- addFlow: function (slot, cache, context) {
168
- return this.addSlot(slot).addCache(cache).addContext(context);
169
- },
170
- removeFlow: function () {
171
- return this.removeSlot().removeCache().removeContext();
172
- },
173
- addCache: function (name) {
174
- this.cache = name || '';
175
- this.caches.push(this.cache);
176
- return this;
177
- },
178
- removeCache: function () {
179
- this.caches.pop();
180
- this.cache = this.caches[this.caches.length - 1] || '';
181
- return this;
182
- },
183
- addContext: function (context) {
184
- this.context = Object.assign({}, this.context, context);
185
- this.context.extra = this.context.extra || {};
186
- this.contexts.push(this.context);
187
- return this;
188
- },
189
- removeContext: function () {
190
- this.contexts.pop();
191
- this.context = this.contexts[this.contexts.length - 1] || {};
192
- return this;
193
- },
194
- addSlot: function (name) {
195
- this.slot = name || '';
196
- this.slots.push(this.slot);
197
- return this;
198
- },
199
- removeSlot: function () {
200
- this.slots.pop();
201
- this.slot = this.slots[this.slots.length - 1] || '';
202
- return this;
203
- },
204
- addVertexCode: function (code) {
205
- this.addCode(code, 'vertex');
206
- },
207
- addFragmentCode: function (code) {
208
- this.addCode(code, 'fragment');
209
- },
210
- addCode: function (code, shader) {
211
- this.code[shader || this.shader] += code + '\n';
212
- },
213
- addVertexNodeCode: function (code) {
214
- this.addNodeCode(code, 'vertex');
215
- },
216
- addFragmentNodeCode: function (code) {
217
- this.addNodeCode(code, 'fragment');
218
- },
219
- addNodeCode: function (code, shader) {
220
- this.nodeCode[shader || this.shader] += code + '\n';
221
- },
222
- clearNodeCode: function (shader) {
223
- shader = shader || this.shader;
224
- var code = this.nodeCode[shader];
225
- this.nodeCode[shader] = '';
226
- return code;
227
- },
228
- clearVertexNodeCode: function () {
229
- return this.clearNodeCode('vertex');
230
- },
231
- clearFragmentNodeCode: function () {
232
- return this.clearNodeCode('fragment');
233
- },
234
- addVertexFinalCode: function (code) {
235
- this.addFinalCode(code, 'vertex');
236
- },
237
- addFragmentFinalCode: function (code) {
238
- this.addFinalCode(code, 'fragment');
239
- },
240
- addFinalCode: function (code, shader) {
241
- this.finalCode[shader || this.shader] += code + '\n';
242
- },
243
- addVertexParsCode: function (code) {
244
- this.addParsCode(code, 'vertex');
245
- },
246
- addFragmentParsCode: function (code) {
247
- this.addParsCode(code, 'fragment');
248
- },
249
- addParsCode: function (code, shader) {
250
- this.parsCode[shader || this.shader] += code + '\n';
251
- },
252
- addVaryCode: function (code) {
253
- this.addVertexParsCode(code);
254
- this.addFragmentParsCode(code);
255
- },
256
- isCache: function (name) {
257
- return this.caches.indexOf(name) !== -1;
258
- },
259
- isSlot: function (name) {
260
- return this.slots.indexOf(name) !== -1;
261
- },
262
- define: function (name, value) {
263
- this.defines[name] = value === undefined ? 1 : value;
264
- },
265
- require: function (name) {
266
- this.requires[name] = true;
267
- },
268
- isDefined: function (name) {
269
- return this.defines[name] !== undefined;
270
- },
271
- getVar: function (uuid, type, ns, shader = 'varying', prefix = 'V', label = '') {
272
- var vars = this.getVars(shader),
273
- data = vars[uuid];
274
-
275
- if (!data) {
276
- var index = vars.length,
277
- name = ns ? ns : 'node' + prefix + index + (label ? '_' + label : '');
278
- data = {
279
- name: name,
280
- type: type
281
- };
282
- vars.push(data);
283
- vars[uuid] = data;
284
- }
121
+ getTexture() {
122
+ console.warn('Abstract function.');
123
+ }
285
124
 
286
- return data;
287
- },
288
- getTempVar: function (uuid, type, ns, label) {
289
- return this.getVar(uuid, type, ns, this.shader, 'T', label);
290
- },
291
- getAttribute: function (name, type) {
292
- if (!this.attributes[name]) {
293
- var varying = this.getVar(name, type);
294
- this.addVertexParsCode('attribute ' + type + ' ' + name + ';');
295
- this.addVertexFinalCode(varying.name + ' = ' + name + ';');
296
- this.attributes[name] = {
297
- varying: varying,
298
- name: name,
299
- type: type
300
- };
301
- }
125
+ getTextureBias() {
126
+ console.warn('Abstract function.');
127
+ }
302
128
 
303
- return this.attributes[name];
304
- },
305
- getCode: function (shader) {
306
- return [this.prefixCode, this.parsCode[shader], this.getVarListCode(this.getVars('varying'), 'varying'), this.getVarListCode(this.inputs.uniforms[shader], 'uniform'), this.getIncludesCode('consts', shader), this.getIncludesCode('structs', shader), this.getIncludesCode('functions', shader), 'void main() {', this.getVarListCode(this.getVars(shader)), this.code[shader], this.resultCode[shader], this.finalCode[shader], '}'].join('\n');
307
- },
308
- getVarListCode: function (vars, prefix) {
309
- prefix = prefix || '';
310
- var code = '';
311
-
312
- for (let i = 0, l = vars.length; i < l; ++i) {
313
- var nVar = vars[i],
314
- type = nVar.type,
315
- name = nVar.name;
316
- var formatType = this.getFormatByType(type);
317
-
318
- if (formatType === undefined) {
319
- throw new Error('Node pars ' + formatType + ' not found.');
320
- }
129
+ getCubeTexture() {
130
+ console.warn('Abstract function.');
131
+ }
321
132
 
322
- code += prefix + ' ' + formatType + ' ' + name + ';\n';
323
- }
133
+ getCubeTextureBias() {
134
+ console.warn('Abstract function.');
135
+ } // @TODO: rename to .generateConst()
324
136
 
325
- return code;
326
- },
327
- getVars: function (shader) {
328
- return this.inputs.vars[shader || this.shader];
329
- },
330
- getNodeData: function (node) {
331
- var uuid = node.isNode ? node.uuid : node;
332
- return this.nodeData[uuid] = this.nodeData[uuid] || {};
333
- },
334
- createUniform: function (shader, type, node, ns, needsUpdate, label) {
335
- var uniforms = this.inputs.uniforms,
336
- index = uniforms.list.length;
337
- var uniform = new NodeUniform({
338
- type: type,
339
- name: ns ? ns : 'nodeU' + index + (label ? '_' + label : ''),
340
- node: node,
341
- needsUpdate: needsUpdate
342
- });
343
- uniforms.list.push(uniform);
344
- uniforms[shader].push(uniform);
345
- uniforms[shader][uniform.name] = uniform;
346
- this.uniforms[uniform.name] = uniform;
347
- return uniform;
348
- },
349
- createVertexUniform: function (type, node, ns, needsUpdate, label) {
350
- return this.createUniform('vertex', type, node, ns, needsUpdate, label);
351
- },
352
- createFragmentUniform: function (type, node, ns, needsUpdate, label) {
353
- return this.createUniform('fragment', type, node, ns, needsUpdate, label);
354
- },
355
- include: function (node, parent, source) {
356
- var includesStruct;
357
- node = typeof node === 'string' ? NodeLib.get(node) : node;
358
-
359
- if (this.context.include === false) {
360
- return node.name;
361
- }
362
137
 
363
- if (node instanceof FunctionNode) {
364
- includesStruct = this.includes.functions;
365
- } else if (node instanceof ConstNode) {
366
- includesStruct = this.includes.consts;
367
- } else if (node instanceof StructNode) {
368
- includesStruct = this.includes.structs;
138
+ getConst(type, value) {
139
+ if (type === 'float') return toFloat(value);
140
+ if (type === 'int') return `${Math.round(value)}`;
141
+ if (type === 'uint') return value >= 0 ? `${Math.round(value)}u` : '0u';
142
+ if (type === 'bool') return value ? 'true' : 'false';
143
+ if (type === 'color') return `${this.getType('vec3')}( ${toFloat(value.r)}, ${toFloat(value.g)}, ${toFloat(value.b)} )`;
144
+ const typeLength = this.getTypeLength(type);
145
+ const componentType = this.getComponentType(type);
146
+
147
+ const getConst = value => this.getConst(componentType, value);
148
+
149
+ if (typeLength === 2) {
150
+ return `${this.getType(type)}( ${getConst(value.x)}, ${getConst(value.y)} )`;
151
+ } else if (typeLength === 3) {
152
+ return `${this.getType(type)}( ${getConst(value.x)}, ${getConst(value.y)}, ${getConst(value.z)} )`;
153
+ } else if (typeLength === 4) {
154
+ return `${this.getType(type)}( ${getConst(value.x)}, ${getConst(value.y)}, ${getConst(value.z)}, ${getConst(value.w)} )`;
369
155
  }
370
156
 
371
- var includes = includesStruct[this.shader] = includesStruct[this.shader] || [];
157
+ throw new Error(`NodeBuilder: Type '${type}' not found in generate constant attempt.`);
158
+ }
159
+
160
+ getType(type) {
161
+ return type;
162
+ }
163
+
164
+ generateMethod(method) {
165
+ return method;
166
+ }
372
167
 
373
- if (node) {
374
- var included = includes[node.name];
168
+ getAttribute(name, type) {
169
+ const attributes = this.attributes; // find attribute
375
170
 
376
- if (!included) {
377
- included = includes[node.name] = {
378
- node: node,
379
- deps: []
380
- };
381
- includes.push(included);
382
- included.src = node.build(this, 'source');
171
+ for (const attribute of attributes) {
172
+ if (attribute.name === name) {
173
+ return attribute;
383
174
  }
175
+ } // create a new if no exist
384
176
 
385
- if (node instanceof FunctionNode && parent && includes[parent.name] && includes[parent.name].deps.indexOf(node) == -1) {
386
- includes[parent.name].deps.push(node);
387
177
 
388
- if (node.includes && node.includes.length) {
389
- var i = 0;
178
+ const attribute = new NodeAttribute(name, type);
179
+ attributes.push(attribute);
180
+ return attribute;
181
+ }
390
182
 
391
- do {
392
- this.include(node.includes[i++], parent);
393
- } while (i < node.includes.length);
394
- }
395
- }
183
+ getPropertyName(node
184
+ /*, shaderStage*/
185
+ ) {
186
+ return node.name;
187
+ }
396
188
 
397
- if (source) {
398
- included.src = source;
399
- }
189
+ isVector(type) {
190
+ return /vec\d/.test(type);
191
+ }
192
+
193
+ isMatrix(type) {
194
+ return /mat\d/.test(type);
195
+ }
196
+
197
+ isReference(type) {
198
+ return type === 'void' || type === 'property' || type === 'sampler';
199
+ }
400
200
 
401
- return node.name;
201
+ isShaderStage(shaderStage) {
202
+ return this.shaderStage === shaderStage;
203
+ }
204
+
205
+ getTextureEncodingFromMap(map) {
206
+ let encoding;
207
+
208
+ if (map && map.isTexture) {
209
+ encoding = map.encoding;
210
+ } else if (map && map.isWebGLRenderTarget) {
211
+ encoding = map.texture.encoding;
402
212
  } else {
403
- throw new Error('Include not found.');
404
- }
405
- },
406
- colorToVectorProperties: function (color) {
407
- return color.replace('r', 'x').replace('g', 'y').replace('b', 'z').replace('a', 'w');
408
- },
409
- colorToVector: function (color) {
410
- return color.replace(/c/g, 'v3');
411
- },
412
- getIncludes: function (type, shader) {
413
- return this.includes[type][shader || this.shader];
414
- },
415
- getIncludesCode: function () {
416
- function sortByPosition(a, b) {
417
- return a.deps.length - b.deps.length;
213
+ encoding = LinearEncoding;
418
214
  }
419
215
 
420
- return function getIncludesCode(type, shader) {
421
- var includes = this.getIncludes(type, shader);
422
- if (!includes) return '';
423
- var code = '',
424
- includes = includes.sort(sortByPosition);
216
+ return encoding;
217
+ }
218
+
219
+ getComponentType(type) {
220
+ type = this.getVectorType(type);
221
+ const componentType = /(b|i|u|)(vec|mat)([2-4])/.exec(type);
222
+ if (componentType === null) return null;
223
+ if (componentType[1] === 'b') return 'bool';
224
+ if (componentType[1] === 'i') return 'int';
225
+ if (componentType[1] === 'u') return 'uint';
226
+ return 'float';
227
+ }
425
228
 
426
- for (let i = 0; i < includes.length; i++) {
427
- if (includes[i].src) code += includes[i].src + '\n';
428
- }
229
+ getVectorType(type) {
230
+ if (type === 'color') return 'vec3';
231
+ if (type === 'texture') return 'vec4';
232
+ return type;
233
+ }
429
234
 
430
- return code;
431
- };
432
- }(),
433
- getConstructorFromLength: function (len) {
434
- return constructors[len - 1];
435
- },
436
- isTypeMatrix: function (format) {
437
- return /^m/.test(format);
438
- },
439
- getTypeLength: function (type) {
440
- if (type === 'f') return 1;
441
- return parseInt(this.colorToVector(type).substr(1));
442
- },
443
- getTypeFromLength: function (len) {
444
- if (len === 1) return 'f';
445
- return 'v' + len;
446
- },
447
- findNode: function () {
448
- for (let i = 0; i < arguments.length; i++) {
449
- var nodeCandidate = arguments[i];
450
-
451
- if (nodeCandidate !== undefined && nodeCandidate.isNode) {
452
- return nodeCandidate;
453
- }
235
+ getTypeFromLength(type) {
236
+ if (type === 1) return 'float';
237
+ if (type === 2) return 'vec2';
238
+ if (type === 3) return 'vec3';
239
+ if (type === 4) return 'vec4';
240
+ return 0;
241
+ }
242
+
243
+ getTypeLength(type) {
244
+ const vecType = this.getVectorType(type);
245
+ const vecNum = /vec([2-4])/.exec(vecType);
246
+ if (vecNum !== null) return Number(vecNum[1]);
247
+ if (vecType === 'float' || vecType === 'bool' || vecType === 'int' || vecType === 'uint') return 1;
248
+ return 0;
249
+ }
250
+
251
+ getVectorFromMatrix(type) {
252
+ return type.replace('mat', 'vec');
253
+ }
254
+
255
+ getDataFromNode(node, shaderStage = this.shaderStage) {
256
+ let nodeData = this.nodesData.get(node);
257
+
258
+ if (nodeData === undefined) {
259
+ nodeData = {
260
+ vertex: {},
261
+ fragment: {}
262
+ };
263
+ this.nodesData.set(node, nodeData);
454
264
  }
455
- },
456
- resolve: function () {
457
- for (let i = 0; i < arguments.length; i++) {
458
- var nodeCandidate = arguments[i];
459
-
460
- if (nodeCandidate !== undefined) {
461
- if (nodeCandidate.isNode) {
462
- return nodeCandidate;
463
- } else if (nodeCandidate.isTexture) {
464
- switch (nodeCandidate.mapping) {
465
- case CubeReflectionMapping:
466
- case CubeRefractionMapping:
467
- return new CubeTextureNode(nodeCandidate);
468
-
469
- case CubeUVReflectionMapping:
470
- case CubeUVRefractionMapping:
471
- return new TextureCubeNode(new TextureNode(nodeCandidate));
472
-
473
- default:
474
- return new TextureNode(nodeCandidate);
475
- }
476
- } else if (nodeCandidate.isVector2) {
477
- return new Vector2Node(nodeCandidate);
478
- } else if (nodeCandidate.isVector3) {
479
- return new Vector3Node(nodeCandidate);
480
- } else if (nodeCandidate.isVector4) {
481
- return new Vector4Node(nodeCandidate);
482
- }
483
- }
265
+
266
+ return shaderStage !== null ? nodeData[shaderStage] : nodeData;
267
+ }
268
+
269
+ getUniformFromNode(node, shaderStage, type) {
270
+ const nodeData = this.getDataFromNode(node, shaderStage);
271
+ let nodeUniform = nodeData.uniform;
272
+
273
+ if (nodeUniform === undefined) {
274
+ const index = this.uniforms.index++;
275
+ nodeUniform = new NodeUniform('nodeUniform' + index, type, node);
276
+ this.uniforms[shaderStage].push(nodeUniform);
277
+ nodeData.uniform = nodeUniform;
484
278
  }
485
- },
486
- format: function (code, from, to) {
487
- var typeToType = this.colorToVector(to + ' <- ' + from);
488
279
 
489
- switch (typeToType) {
490
- case 'f <- v2':
491
- return code + '.x';
280
+ return nodeUniform;
281
+ }
492
282
 
493
- case 'f <- v3':
494
- return code + '.x';
283
+ getVarFromNode(node, type, shaderStage = this.shaderStage) {
284
+ const nodeData = this.getDataFromNode(node, shaderStage);
285
+ let nodeVar = nodeData.variable;
495
286
 
496
- case 'f <- v4':
497
- return code + '.x';
287
+ if (nodeVar === undefined) {
288
+ const vars = this.vars[shaderStage];
289
+ const index = vars.length;
290
+ nodeVar = new NodeVar('nodeVar' + index, type);
291
+ vars.push(nodeVar);
292
+ nodeData.variable = nodeVar;
293
+ }
498
294
 
499
- case 'f <- i':
500
- case 'f <- b':
501
- return 'float( ' + code + ' )';
295
+ return nodeVar;
296
+ }
502
297
 
503
- case 'v2 <- f':
504
- return 'vec2( ' + code + ' )';
298
+ getVaryFromNode(node, type) {
299
+ const nodeData = this.getDataFromNode(node, null);
300
+ let nodeVary = nodeData.vary;
505
301
 
506
- case 'v2 <- v3':
507
- return code + '.xy';
302
+ if (nodeVary === undefined) {
303
+ const varys = this.varys;
304
+ const index = varys.length;
305
+ nodeVary = new NodeVary('nodeVary' + index, type);
306
+ varys.push(nodeVary);
307
+ nodeData.vary = nodeVary;
308
+ }
508
309
 
509
- case 'v2 <- v4':
510
- return code + '.xy';
310
+ return nodeVary;
311
+ }
511
312
 
512
- case 'v2 <- i':
513
- case 'v2 <- b':
514
- return 'vec2( float( ' + code + ' ) )';
313
+ getCodeFromNode(node, type, shaderStage = this.shaderStage) {
314
+ const nodeData = this.getDataFromNode(node);
315
+ let nodeCode = nodeData.code;
515
316
 
516
- case 'v3 <- f':
517
- return 'vec3( ' + code + ' )';
317
+ if (nodeCode === undefined) {
318
+ const codes = this.codes[shaderStage];
319
+ const index = codes.length;
320
+ nodeCode = new NodeCode('nodeCode' + index, type);
321
+ codes.push(nodeCode);
322
+ nodeData.code = nodeCode;
323
+ }
518
324
 
519
- case 'v3 <- v2':
520
- return 'vec3( ' + code + ', 0.0 )';
325
+ return nodeCode;
326
+ }
521
327
 
522
- case 'v3 <- v4':
523
- return code + '.xyz';
328
+ addFlowCode(code) {
329
+ this.flow.code += code;
330
+ }
524
331
 
525
- case 'v3 <- i':
526
- case 'v3 <- b':
527
- return 'vec2( float( ' + code + ' ) )';
332
+ getFlowData(shaderStage, node) {
333
+ return this.flowsData.get(node);
334
+ }
528
335
 
529
- case 'v4 <- f':
530
- return 'vec4( ' + code + ' )';
336
+ flowNode(node) {
337
+ this.node = node;
338
+ const output = node.getNodeType(this);
339
+ const flowData = this.flowChildNode(node, output);
340
+ this.flowsData.set(node, flowData);
341
+ this.node = null;
342
+ return flowData;
343
+ }
531
344
 
532
- case 'v4 <- v2':
533
- return 'vec4( ' + code + ', 0.0, 1.0 )';
345
+ flowChildNode(node, output = null) {
346
+ const previousFlow = this.flow;
347
+ const flow = {
348
+ code: ''
349
+ };
350
+ this.flow = flow;
351
+ flow.result = node.build(this, output);
352
+ this.flow = previousFlow;
353
+ return flow;
354
+ }
534
355
 
535
- case 'v4 <- v3':
536
- return 'vec4( ' + code + ', 1.0 )';
356
+ flowNodeFromShaderStage(shaderStage, node, output = null, propertyName = null) {
357
+ const previousShaderStage = this.shaderStage;
358
+ this.setShaderStage(shaderStage);
359
+ const flowData = this.flowChildNode(node, output);
537
360
 
538
- case 'v4 <- i':
539
- case 'v4 <- b':
540
- return 'vec4( float( ' + code + ' ) )';
361
+ if (propertyName !== null) {
362
+ flowData.code += `${propertyName} = ${flowData.result};\n\t`;
363
+ }
541
364
 
542
- case 'i <- f':
543
- case 'i <- b':
544
- return 'int( ' + code + ' )';
365
+ this.flowCode[shaderStage] = this.flowCode[shaderStage] + flowData.code;
366
+ this.setShaderStage(previousShaderStage);
367
+ return flowData;
368
+ }
545
369
 
546
- case 'i <- v2':
547
- return 'int( ' + code + '.x )';
370
+ getAttributes() {
371
+ console.warn('Abstract function.');
372
+ }
548
373
 
549
- case 'i <- v3':
550
- return 'int( ' + code + '.x )';
374
+ getVarys() {
375
+ console.warn('Abstract function.');
376
+ }
551
377
 
552
- case 'i <- v4':
553
- return 'int( ' + code + '.x )';
378
+ getVars(shaderStage) {
379
+ let snippet = '';
380
+ const vars = this.vars[shaderStage];
554
381
 
555
- case 'b <- f':
556
- return '( ' + code + ' != 0.0 )';
382
+ for (let index = 0; index < vars.length; index++) {
383
+ const variable = vars[index];
384
+ snippet += `${variable.type} ${variable.name}; `;
385
+ }
557
386
 
558
- case 'b <- v2':
559
- return '( ' + code + ' != vec2( 0.0 ) )';
387
+ return snippet;
388
+ }
560
389
 
561
- case 'b <- v3':
562
- return '( ' + code + ' != vec3( 0.0 ) )';
390
+ getUniforms() {
391
+ console.warn('Abstract function.');
392
+ }
563
393
 
564
- case 'b <- v4':
565
- return '( ' + code + ' != vec4( 0.0 ) )';
394
+ getCodes(shaderStage) {
395
+ const codes = this.codes[shaderStage];
396
+ let code = '';
566
397
 
567
- case 'b <- i':
568
- return '( ' + code + ' != 0 )';
398
+ for (const nodeCode of codes) {
399
+ code += nodeCode.code + '\n';
569
400
  }
570
401
 
571
402
  return code;
572
- },
573
- getTypeByFormat: function (format) {
574
- return convertFormatToType[format] || format;
575
- },
576
- getFormatByType: function (type) {
577
- return convertTypeToFormat[type] || type;
578
- },
579
- getUuid: function (uuid, useCache) {
580
- useCache = useCache !== undefined ? useCache : true;
581
- if (useCache && this.cache) uuid = this.cache + '-' + uuid;
582
- return uuid;
583
- },
584
- getElementByIndex: function (index) {
585
- return elements[index];
586
- },
587
- getIndexByElement: function (elm) {
588
- return elements.indexOf(elm);
589
- },
590
- isShader: function (shader) {
591
- return this.shader === shader;
592
- },
593
- setShader: function (shader) {
594
- this.shader = shader;
403
+ }
404
+
405
+ getHash() {
406
+ return this.vertexShader + this.fragmentShader;
407
+ }
408
+
409
+ getShaderStage() {
410
+ return this.shaderStage;
411
+ }
412
+
413
+ setShaderStage(shaderStage) {
414
+ this.shaderStage = shaderStage;
415
+ }
416
+
417
+ buildCode() {
418
+ console.warn('Abstract function.');
419
+ }
420
+
421
+ build() {
422
+ // stage 1: analyze nodes to possible optimization and validation
423
+ for (const shaderStage of shaderStages) {
424
+ this.setShaderStage(shaderStage);
425
+ const flowNodes = this.flowNodes[shaderStage];
426
+
427
+ for (const node of flowNodes) {
428
+ node.analyze(this);
429
+ }
430
+ } // stage 2: pre-build vertex code used in fragment shader
431
+
432
+
433
+ if (this.context.vertex && this.context.vertex.isNode) {
434
+ this.flowNodeFromShaderStage('vertex', this.context.vertex);
435
+ } // stage 3: generate shader
436
+
437
+
438
+ for (const shaderStage of shaderStages) {
439
+ this.setShaderStage(shaderStage);
440
+ const flowNodes = this.flowNodes[shaderStage];
441
+
442
+ for (const node of flowNodes) {
443
+ this.flowNode(node, shaderStage);
444
+ }
445
+ }
446
+
447
+ this.setShaderStage(null); // stage 4: build code for a specific output
448
+
449
+ this.buildCode();
595
450
  return this;
596
- },
597
- mergeDefines: function (defines) {
598
- for (let name in defines) {
599
- this.defines[name] = defines[name];
451
+ }
452
+
453
+ format(snippet, fromType, toType) {
454
+ fromType = this.getVectorType(fromType);
455
+ toType = this.getVectorType(toType);
456
+
457
+ if (fromType === toType || toType === null || this.isReference(toType)) {
458
+ return snippet;
600
459
  }
601
460
 
602
- return this.defines;
603
- },
604
- mergeUniform: function (uniforms) {
605
- for (let name in uniforms) {
606
- this.uniforms[name] = uniforms[name];
461
+ const fromTypeLength = this.getTypeLength(fromType);
462
+ const toTypeLength = this.getTypeLength(toType);
463
+
464
+ if (fromTypeLength === 0) {
465
+ // fromType is matrix-like
466
+ const vectorType = this.getVectorFromMatrix(fromType);
467
+ return this.format(`( ${snippet} * ${this.getType(vectorType)}( 1.0 ) )`, vectorType, toType);
607
468
  }
608
469
 
609
- return this.uniforms;
610
- },
611
- getTextureEncodingFromMap: function (map) {
612
- var encoding;
470
+ if (toTypeLength === 0) {
471
+ // toType is matrix-like
472
+ // ignore for now
473
+ //return `${ this.getType( toType ) }( ${ snippet } )`;
474
+ return snippet;
475
+ }
613
476
 
614
- if (!map) {
615
- encoding = LinearEncoding;
616
- } else if (map.isTexture) {
617
- encoding = map.encoding;
618
- } else if (map.isWebGLRenderTarget) {
619
- console.warn("THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead.");
620
- encoding = map.texture.encoding;
477
+ if (fromTypeLength === toTypeLength) {
478
+ return `${this.getType(toType)}( ${snippet} )`;
621
479
  }
622
480
 
623
- if (encoding === LinearEncoding && this.context.gamma) {
624
- encoding = sRGBEncoding;
481
+ if (fromTypeLength > toTypeLength) {
482
+ return this.format(`${snippet}.${'xyz'.slice(0, toTypeLength)}`, this.getTypeFromLength(toTypeLength), toType);
625
483
  }
626
484
 
627
- return encoding;
485
+ if (toTypeLength === 4) {
486
+ // toType is vec4-like
487
+ return `${this.getType(toType)}( ${this.format(snippet, fromType, 'vec3')}, 1.0 )`;
488
+ }
489
+
490
+ if (fromTypeLength === 2) {
491
+ // fromType is vec2-like and toType is vec3-like
492
+ return `${this.getType(toType)}( ${this.format(snippet, fromType, 'vec2')}, 0.0 )`;
493
+ }
494
+
495
+ return `${this.getType(toType)}( ${snippet} )`; // fromType is float-like
628
496
  }
629
- };
630
497
 
631
- export { NodeBuilder };
498
+ getSignature() {
499
+ return `// Three.js r${REVISION} - NodeMaterial System\n`;
500
+ }
501
+
502
+ }
503
+
504
+ export default NodeBuilder;
505
+ export { shaderStages, vector };