three-stdlib 2.8.7 → 2.8.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (322) 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 +0 -75
  5. package/index.js +70 -76
  6. package/loaders/NodeMaterialLoader.cjs.js +1 -1
  7. package/loaders/NodeMaterialLoader.js +2 -136
  8. package/loaders/RGBELoader.cjs.js +1 -1
  9. package/loaders/RGBELoader.js +3 -3
  10. package/loaders/RGBMLoader.cjs.js +1 -1
  11. package/loaders/RGBMLoader.js +190 -268
  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/package.json +2 -2
  175. package/Nodes-894ac9dc.js +0 -1
  176. package/Nodes-af575af7.js +0 -157
  177. package/nodes/accessors/ColorsNode.cjs.js +0 -1
  178. package/nodes/accessors/ColorsNode.d.ts +0 -10
  179. package/nodes/accessors/ColorsNode.js +0 -40
  180. package/nodes/accessors/LightNode.cjs.js +0 -1
  181. package/nodes/accessors/LightNode.d.ts +0 -12
  182. package/nodes/accessors/LightNode.js +0 -41
  183. package/nodes/accessors/ResolutionNode.cjs.js +0 -1
  184. package/nodes/accessors/ResolutionNode.d.ts +0 -14
  185. package/nodes/accessors/ResolutionNode.js +0 -41
  186. package/nodes/accessors/ScreenUVNode.cjs.js +0 -1
  187. package/nodes/accessors/ScreenUVNode.d.ts +0 -11
  188. package/nodes/accessors/ScreenUVNode.js +0 -43
  189. package/nodes/core/NodeLib.cjs.js +0 -1
  190. package/nodes/core/NodeLib.d.ts +0 -22
  191. package/nodes/core/NodeLib.js +0 -37
  192. package/nodes/core/StructNode.cjs.js +0 -1
  193. package/nodes/core/StructNode.d.ts +0 -19
  194. package/nodes/core/StructNode.js +0 -72
  195. package/nodes/effects/BlurNode.cjs.js +0 -1
  196. package/nodes/effects/BlurNode.d.ts +0 -31
  197. package/nodes/effects/BlurNode.js +0 -100
  198. package/nodes/effects/ColorAdjustmentNode.cjs.js +0 -1
  199. package/nodes/effects/ColorAdjustmentNode.d.ts +0 -27
  200. package/nodes/effects/ColorAdjustmentNode.js +0 -73
  201. package/nodes/effects/LuminanceNode.cjs.js +0 -1
  202. package/nodes/effects/LuminanceNode.d.ts +0 -18
  203. package/nodes/effects/LuminanceNode.js +0 -46
  204. package/nodes/inputs/BoolNode.cjs.js +0 -1
  205. package/nodes/inputs/BoolNode.d.ts +0 -19
  206. package/nodes/inputs/BoolNode.js +0 -36
  207. package/nodes/inputs/ColorNode.cjs.js +0 -1
  208. package/nodes/inputs/ColorNode.d.ts +0 -21
  209. package/nodes/inputs/ColorNode.js +0 -41
  210. package/nodes/inputs/CubeTextureNode.cjs.js +0 -1
  211. package/nodes/inputs/CubeTextureNode.d.ts +0 -17
  212. package/nodes/inputs/CubeTextureNode.js +0 -79
  213. package/nodes/inputs/FloatNode.cjs.js +0 -1
  214. package/nodes/inputs/FloatNode.d.ts +0 -19
  215. package/nodes/inputs/FloatNode.js +0 -36
  216. package/nodes/inputs/IntNode.cjs.js +0 -1
  217. package/nodes/inputs/IntNode.d.ts +0 -19
  218. package/nodes/inputs/IntNode.js +0 -36
  219. package/nodes/inputs/Matrix3Node.cjs.js +0 -1
  220. package/nodes/inputs/Matrix3Node.d.ts +0 -22
  221. package/nodes/inputs/Matrix3Node.js +0 -46
  222. package/nodes/inputs/Matrix4Node.cjs.js +0 -1
  223. package/nodes/inputs/Matrix4Node.d.ts +0 -22
  224. package/nodes/inputs/Matrix4Node.js +0 -46
  225. package/nodes/inputs/PropertyNode.cjs.js +0 -1
  226. package/nodes/inputs/PropertyNode.d.ts +0 -10
  227. package/nodes/inputs/PropertyNode.js +0 -35
  228. package/nodes/inputs/RTTNode.cjs.js +0 -1
  229. package/nodes/inputs/RTTNode.d.ts +0 -27
  230. package/nodes/inputs/RTTNode.js +0 -103
  231. package/nodes/inputs/ReflectorNode.cjs.js +0 -1
  232. package/nodes/inputs/ReflectorNode.d.ts +0 -21
  233. package/nodes/inputs/ReflectorNode.js +0 -60
  234. package/nodes/inputs/ScreenNode.cjs.js +0 -1
  235. package/nodes/inputs/ScreenNode.d.ts +0 -11
  236. package/nodes/inputs/ScreenNode.js +0 -20
  237. package/nodes/inputs/TextureNode.cjs.js +0 -1
  238. package/nodes/inputs/TextureNode.d.ts +0 -20
  239. package/nodes/inputs/TextureNode.js +0 -83
  240. package/nodes/inputs/Vector2Node.cjs.js +0 -1
  241. package/nodes/inputs/Vector2Node.d.ts +0 -21
  242. package/nodes/inputs/Vector2Node.js +0 -40
  243. package/nodes/inputs/Vector3Node.cjs.js +0 -1
  244. package/nodes/inputs/Vector3Node.d.ts +0 -21
  245. package/nodes/inputs/Vector3Node.js +0 -41
  246. package/nodes/inputs/Vector4Node.cjs.js +0 -1
  247. package/nodes/inputs/Vector4Node.d.ts +0 -21
  248. package/nodes/inputs/Vector4Node.js +0 -42
  249. package/nodes/materials/BasicNodeMaterial.cjs.js +0 -1
  250. package/nodes/materials/BasicNodeMaterial.d.ts +0 -11
  251. package/nodes/materials/BasicNodeMaterial.js +0 -15
  252. package/nodes/materials/PhongNodeMaterial.cjs.js +0 -1
  253. package/nodes/materials/PhongNodeMaterial.d.ts +0 -21
  254. package/nodes/materials/PhongNodeMaterial.js +0 -15
  255. package/nodes/materials/SpriteNodeMaterial.cjs.js +0 -1
  256. package/nodes/materials/SpriteNodeMaterial.d.ts +0 -12
  257. package/nodes/materials/SpriteNodeMaterial.js +0 -15
  258. package/nodes/materials/StandardNodeMaterial.cjs.js +0 -1
  259. package/nodes/materials/StandardNodeMaterial.d.ts +0 -25
  260. package/nodes/materials/StandardNodeMaterial.js +0 -15
  261. package/nodes/materials/nodes/BasicNode.cjs.js +0 -1
  262. package/nodes/materials/nodes/BasicNode.d.ts +0 -15
  263. package/nodes/materials/nodes/BasicNode.js +0 -91
  264. package/nodes/materials/nodes/MeshStandardNode.cjs.js +0 -1
  265. package/nodes/materials/nodes/MeshStandardNode.d.ts +0 -25
  266. package/nodes/materials/nodes/MeshStandardNode.js +0 -81
  267. package/nodes/materials/nodes/PhongNode.cjs.js +0 -1
  268. package/nodes/materials/nodes/PhongNode.d.ts +0 -14
  269. package/nodes/materials/nodes/PhongNode.js +0 -212
  270. package/nodes/materials/nodes/RawNode.cjs.js +0 -1
  271. package/nodes/materials/nodes/RawNode.d.ts +0 -10
  272. package/nodes/materials/nodes/RawNode.js +0 -42
  273. package/nodes/materials/nodes/SpriteNode.cjs.js +0 -1
  274. package/nodes/materials/nodes/SpriteNode.d.ts +0 -13
  275. package/nodes/materials/nodes/SpriteNode.js +0 -113
  276. package/nodes/materials/nodes/StandardNode.cjs.js +0 -1
  277. package/nodes/materials/nodes/StandardNode.d.ts +0 -15
  278. package/nodes/materials/nodes/StandardNode.js +0 -336
  279. package/nodes/misc/BumpMapNode.cjs.js +0 -1
  280. package/nodes/misc/BumpMapNode.d.ts +0 -21
  281. package/nodes/misc/BumpMapNode.js +0 -80
  282. package/nodes/misc/NormalMapNode.cjs.js +0 -1
  283. package/nodes/misc/NormalMapNode.d.ts +0 -19
  284. package/nodes/misc/NormalMapNode.js +0 -102
  285. package/nodes/misc/TextureCubeNode.cjs.js +0 -1
  286. package/nodes/misc/TextureCubeNode.d.ts +0 -21
  287. package/nodes/misc/TextureCubeNode.js +0 -52
  288. package/nodes/misc/TextureCubeUVNode.cjs.js +0 -1
  289. package/nodes/misc/TextureCubeUVNode.d.ts +0 -18
  290. package/nodes/misc/TextureCubeUVNode.js +0 -229
  291. package/nodes/postprocessing/NodePass.cjs.js +0 -1
  292. package/nodes/postprocessing/NodePass.d.ts +0 -15
  293. package/nodes/postprocessing/NodePass.js +0 -61
  294. package/nodes/postprocessing/NodePostProcessing.cjs.js +0 -1
  295. package/nodes/postprocessing/NodePostProcessing.d.ts +0 -26
  296. package/nodes/postprocessing/NodePostProcessing.js +0 -91
  297. package/nodes/procedural/NoiseNode.cjs.js +0 -1
  298. package/nodes/procedural/NoiseNode.d.ts +0 -17
  299. package/nodes/procedural/NoiseNode.js +0 -43
  300. package/nodes/utils/BypassNode.cjs.js +0 -1
  301. package/nodes/utils/BypassNode.d.ts +0 -11
  302. package/nodes/utils/BypassNode.js +0 -55
  303. package/nodes/utils/ColorSpaceNode.cjs.js +0 -1
  304. package/nodes/utils/ColorSpaceNode.d.ts +0 -55
  305. package/nodes/utils/ColorSpaceNode.js +0 -106
  306. package/nodes/utils/MaxMIPLevelNode.cjs.js +0 -1
  307. package/nodes/utils/MaxMIPLevelNode.d.ts +0 -11
  308. package/nodes/utils/MaxMIPLevelNode.js +0 -38
  309. package/nodes/utils/SpecularMIPLevelNode.cjs.js +0 -1
  310. package/nodes/utils/SpecularMIPLevelNode.d.ts +0 -17
  311. package/nodes/utils/SpecularMIPLevelNode.js +0 -61
  312. package/nodes/utils/SubSlotNode.cjs.js +0 -1
  313. package/nodes/utils/SubSlotNode.js +0 -53
  314. package/nodes/utils/SwitchNode.cjs.js +0 -1
  315. package/nodes/utils/SwitchNode.d.ts +0 -11
  316. package/nodes/utils/SwitchNode.js +0 -69
  317. package/nodes/utils/UVTransformNode.cjs.js +0 -1
  318. package/nodes/utils/UVTransformNode.d.ts +0 -15
  319. package/nodes/utils/UVTransformNode.js +0 -46
  320. package/nodes/utils/VelocityNode.cjs.js +0 -1
  321. package/nodes/utils/VelocityNode.d.ts +0 -28
  322. 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 };