@babylonjs/smart-filters 1.0.12 → 8.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/dist/blockFoundation/aggregateBlock.d.ts +3 -3
  2. package/dist/blockFoundation/aggregateBlock.d.ts.map +1 -1
  3. package/dist/blockFoundation/aggregateBlock.js +1 -2
  4. package/dist/blockFoundation/aggregateBlock.js.map +1 -1
  5. package/dist/blockFoundation/baseBlock.d.ts +2 -2
  6. package/dist/blockFoundation/baseBlock.d.ts.map +1 -1
  7. package/dist/blockFoundation/baseBlock.js +5 -6
  8. package/dist/blockFoundation/baseBlock.js.map +1 -1
  9. package/dist/blockFoundation/customAggregateBlock.d.ts.map +1 -1
  10. package/dist/blockFoundation/customAggregateBlock.js +2 -2
  11. package/dist/blockFoundation/customAggregateBlock.js.map +1 -1
  12. package/dist/blockFoundation/customShaderBlock.d.ts.map +1 -1
  13. package/dist/blockFoundation/customShaderBlock.js +4 -6
  14. package/dist/blockFoundation/customShaderBlock.js.map +1 -1
  15. package/dist/blockFoundation/disableableShaderBlock.d.ts.map +1 -1
  16. package/dist/blockFoundation/disableableShaderBlock.js +4 -4
  17. package/dist/blockFoundation/disableableShaderBlock.js.map +1 -1
  18. package/dist/blockFoundation/index.js +0 -2
  19. package/dist/blockFoundation/index.js.map +1 -1
  20. package/dist/blockFoundation/inputBlock.d.ts +8 -8
  21. package/dist/blockFoundation/inputBlock.d.ts.map +1 -1
  22. package/dist/blockFoundation/inputBlock.deserializer.d.ts +1 -1
  23. package/dist/blockFoundation/inputBlock.deserializer.d.ts.map +1 -1
  24. package/dist/blockFoundation/inputBlock.deserializer.js +1 -1
  25. package/dist/blockFoundation/inputBlock.deserializer.js.map +1 -1
  26. package/dist/blockFoundation/inputBlock.js +7 -7
  27. package/dist/blockFoundation/inputBlock.js.map +1 -1
  28. package/dist/blockFoundation/inputBlock.serialization.types.d.ts.map +1 -1
  29. package/dist/blockFoundation/inputBlock.serializer.d.ts +1 -1
  30. package/dist/blockFoundation/inputBlock.serializer.js +26 -28
  31. package/dist/blockFoundation/inputBlock.serializer.js.map +1 -1
  32. package/dist/blockFoundation/outputBlock.d.ts +4 -9
  33. package/dist/blockFoundation/outputBlock.d.ts.map +1 -1
  34. package/dist/blockFoundation/outputBlock.js +13 -14
  35. package/dist/blockFoundation/outputBlock.js.map +1 -1
  36. package/dist/blockFoundation/shaderBlock.d.ts +4 -4
  37. package/dist/blockFoundation/shaderBlock.d.ts.map +1 -1
  38. package/dist/blockFoundation/shaderBlock.js +13 -19
  39. package/dist/blockFoundation/shaderBlock.js.map +1 -1
  40. package/dist/blockFoundation/textureOptions.d.ts +1 -1
  41. package/dist/blockFoundation/textureOptions.js +1 -1
  42. package/dist/command/command.d.ts +1 -1
  43. package/dist/command/command.js +1 -1
  44. package/dist/command/commandBuffer.d.ts +1 -1
  45. package/dist/command/commandBuffer.d.ts.map +1 -1
  46. package/dist/command/commandBuffer.js +2 -2
  47. package/dist/command/commandBufferDebugger.d.ts +2 -2
  48. package/dist/command/commandBufferDebugger.d.ts.map +1 -1
  49. package/dist/command/commandBufferDebugger.js +1 -1
  50. package/dist/command/commandBufferDebugger.js.map +1 -1
  51. package/dist/command/index.d.ts +3 -1
  52. package/dist/command/index.d.ts.map +1 -1
  53. package/dist/command/index.js +5 -1
  54. package/dist/command/index.js.map +1 -1
  55. package/dist/connection/connectionPoint.d.ts +3 -3
  56. package/dist/connection/connectionPoint.d.ts.map +1 -1
  57. package/dist/connection/connectionPoint.js +2 -2
  58. package/dist/connection/connectionPoint.js.map +1 -1
  59. package/dist/connection/connectionPointCompatibilityState.d.ts +1 -1
  60. package/dist/connection/connectionPointCompatibilityState.js +1 -1
  61. package/dist/connection/connectionPointType.d.ts +3 -3
  62. package/dist/connection/connectionPointType.d.ts.map +1 -1
  63. package/dist/connection/connectionPointWithDefault.d.ts +3 -3
  64. package/dist/connection/connectionPointWithDefault.d.ts.map +1 -1
  65. package/dist/connection/connectionPointWithDefault.js.map +1 -1
  66. package/dist/connection/index.d.ts +2 -1
  67. package/dist/connection/index.d.ts.map +1 -1
  68. package/dist/connection/index.js +3 -3
  69. package/dist/connection/index.js.map +1 -1
  70. package/dist/editorUtils/editableInPropertyPage.d.ts +2 -2
  71. package/dist/editorUtils/editableInPropertyPage.d.ts.map +1 -1
  72. package/dist/editorUtils/editableInPropertyPage.js +2 -2
  73. package/dist/editorUtils/editableInPropertyPage.js.map +1 -1
  74. package/dist/editorUtils/index.d.ts +1 -0
  75. package/dist/editorUtils/index.d.ts.map +1 -1
  76. package/dist/editorUtils/index.js +2 -0
  77. package/dist/editorUtils/index.js.map +1 -1
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +1 -1
  80. package/dist/index.js.map +1 -1
  81. package/dist/optimization/dependencyGraph.js.map +1 -1
  82. package/dist/optimization/optimizedShaderBlock.d.ts +4 -4
  83. package/dist/optimization/optimizedShaderBlock.d.ts.map +1 -1
  84. package/dist/optimization/optimizedShaderBlock.js.map +1 -1
  85. package/dist/optimization/smartFilterOptimizer.d.ts +2 -2
  86. package/dist/optimization/smartFilterOptimizer.d.ts.map +1 -1
  87. package/dist/optimization/smartFilterOptimizer.js +34 -57
  88. package/dist/optimization/smartFilterOptimizer.js.map +1 -1
  89. package/dist/runtime/index.d.ts +2 -1
  90. package/dist/runtime/index.d.ts.map +1 -1
  91. package/dist/runtime/index.js +3 -3
  92. package/dist/runtime/index.js.map +1 -1
  93. package/dist/runtime/renderTargetGenerator.d.ts +1 -1
  94. package/dist/runtime/renderTargetGenerator.d.ts.map +1 -1
  95. package/dist/runtime/renderTargetGenerator.js +5 -7
  96. package/dist/runtime/renderTargetGenerator.js.map +1 -1
  97. package/dist/runtime/shaderRuntime.d.ts +7 -7
  98. package/dist/runtime/shaderRuntime.d.ts.map +1 -1
  99. package/dist/runtime/shaderRuntime.js +7 -8
  100. package/dist/runtime/shaderRuntime.js.map +1 -1
  101. package/dist/runtime/smartFilterRuntime.d.ts +3 -3
  102. package/dist/runtime/smartFilterRuntime.d.ts.map +1 -1
  103. package/dist/runtime/smartFilterRuntime.js.map +1 -1
  104. package/dist/runtime/strongRef.d.ts +1 -1
  105. package/dist/runtime/strongRef.js +1 -1
  106. package/dist/serialization/importCustomBlockDefinition.d.ts +1 -1
  107. package/dist/serialization/importCustomBlockDefinition.js +8 -9
  108. package/dist/serialization/importCustomBlockDefinition.js.map +1 -1
  109. package/dist/serialization/index.d.ts +1 -0
  110. package/dist/serialization/index.d.ts.map +1 -1
  111. package/dist/serialization/index.js +3 -0
  112. package/dist/serialization/index.js.map +1 -1
  113. package/dist/serialization/serializedBlockDefinition.d.ts +2 -2
  114. package/dist/serialization/serializedBlockDefinition.d.ts.map +1 -1
  115. package/dist/serialization/serializedShaderBlockDefinition.d.ts +1 -1
  116. package/dist/serialization/serializedShaderBlockDefinition.d.ts.map +1 -1
  117. package/dist/serialization/serializedSmartFilter.d.ts +1 -1
  118. package/dist/serialization/serializedSmartFilter.d.ts.map +1 -1
  119. package/dist/serialization/smartFilterDeserializer.d.ts +6 -6
  120. package/dist/serialization/smartFilterDeserializer.d.ts.map +1 -1
  121. package/dist/serialization/smartFilterDeserializer.js +14 -12
  122. package/dist/serialization/smartFilterDeserializer.js.map +1 -1
  123. package/dist/serialization/smartFilterSerializer.d.ts +2 -2
  124. package/dist/serialization/smartFilterSerializer.d.ts.map +1 -1
  125. package/dist/serialization/smartFilterSerializer.js +10 -13
  126. package/dist/serialization/smartFilterSerializer.js.map +1 -1
  127. package/dist/serialization/v1/defaultBlockSerializer.d.ts +2 -2
  128. package/dist/serialization/v1/defaultBlockSerializer.d.ts.map +1 -1
  129. package/dist/serialization/v1/defaultBlockSerializer.js +3 -1
  130. package/dist/serialization/v1/defaultBlockSerializer.js.map +1 -1
  131. package/dist/serialization/v1/index.d.ts +1 -0
  132. package/dist/serialization/v1/index.d.ts.map +1 -1
  133. package/dist/serialization/v1/index.js +2 -0
  134. package/dist/serialization/v1/index.js.map +1 -1
  135. package/dist/serialization/v1/shaderBlockSerialization.types.d.ts +3 -3
  136. package/dist/serialization/v1/shaderBlockSerialization.types.d.ts.map +1 -1
  137. package/dist/serialization/v1/smartFilterSerialization.types.d.ts +5 -2
  138. package/dist/serialization/v1/smartFilterSerialization.types.d.ts.map +1 -1
  139. package/dist/smartFilter.d.ts +8 -8
  140. package/dist/smartFilter.d.ts.map +1 -1
  141. package/dist/smartFilter.js +6 -7
  142. package/dist/smartFilter.js.map +1 -1
  143. package/dist/utils/buildTools/buildShaders.d.ts +3 -2
  144. package/dist/utils/buildTools/buildShaders.d.ts.map +1 -1
  145. package/dist/utils/buildTools/buildShaders.js +7 -6
  146. package/dist/utils/buildTools/buildShaders.js.map +1 -1
  147. package/dist/utils/buildTools/convertGlslIntoBlock.d.ts +4 -2
  148. package/dist/utils/buildTools/convertGlslIntoBlock.d.ts.map +1 -1
  149. package/dist/utils/buildTools/convertGlslIntoBlock.js +136 -141
  150. package/dist/utils/buildTools/convertGlslIntoBlock.js.map +1 -1
  151. package/dist/utils/buildTools/convertGlslIntoShaderProgram.d.ts +4 -4
  152. package/dist/utils/buildTools/convertGlslIntoShaderProgram.d.ts.map +1 -1
  153. package/dist/utils/buildTools/convertGlslIntoShaderProgram.js +55 -48
  154. package/dist/utils/buildTools/convertGlslIntoShaderProgram.js.map +1 -1
  155. package/dist/utils/buildTools/convertShaders.d.ts +8 -5
  156. package/dist/utils/buildTools/convertShaders.d.ts.map +1 -1
  157. package/dist/utils/buildTools/convertShaders.js +38 -14
  158. package/dist/utils/buildTools/convertShaders.js.map +1 -1
  159. package/dist/utils/buildTools/shaderConverter.d.ts +4 -4
  160. package/dist/utils/buildTools/shaderConverter.d.ts.map +1 -1
  161. package/dist/utils/buildTools/shaderConverter.js +17 -21
  162. package/dist/utils/buildTools/shaderConverter.js.map +1 -1
  163. package/dist/utils/buildTools/watchShaders.d.ts +3 -2
  164. package/dist/utils/buildTools/watchShaders.d.ts.map +1 -1
  165. package/dist/utils/buildTools/watchShaders.js +10 -8
  166. package/dist/utils/buildTools/watchShaders.js.map +1 -1
  167. package/dist/utils/index.d.ts +1 -0
  168. package/dist/utils/index.d.ts.map +1 -1
  169. package/dist/utils/index.js +2 -1
  170. package/dist/utils/index.js.map +1 -1
  171. package/dist/utils/renderTargetUtils.d.ts +3 -3
  172. package/dist/utils/renderTargetUtils.d.ts.map +1 -1
  173. package/dist/utils/renderTargetUtils.js +4 -4
  174. package/dist/utils/renderTargetUtils.js.map +1 -1
  175. package/dist/utils/shaderCodeUtils.d.ts +8 -8
  176. package/dist/utils/shaderCodeUtils.d.ts.map +1 -1
  177. package/dist/utils/shaderCodeUtils.js +16 -28
  178. package/dist/utils/shaderCodeUtils.js.map +1 -1
  179. package/dist/utils/textureLoaders.d.ts +2 -2
  180. package/dist/utils/textureLoaders.d.ts.map +1 -1
  181. package/dist/utils/textureLoaders.js +2 -3
  182. package/dist/utils/textureLoaders.js.map +1 -1
  183. package/dist/utils/textureUtils.d.ts +5 -5
  184. package/dist/utils/textureUtils.d.ts.map +1 -1
  185. package/dist/utils/textureUtils.js +1 -1
  186. package/dist/utils/textureUtils.js.map +1 -1
  187. package/dist/version.d.ts +2 -2
  188. package/dist/version.js +2 -2
  189. package/license.md +21 -21
  190. package/package.json +14 -9
  191. package/src/blockFoundation/aggregateBlock.ts +148 -151
  192. package/src/blockFoundation/baseBlock.ts +339 -364
  193. package/src/blockFoundation/customAggregateBlock.ts +88 -104
  194. package/src/blockFoundation/customShaderBlock.ts +312 -326
  195. package/src/blockFoundation/disableableShaderBlock.ts +91 -100
  196. package/src/blockFoundation/index.ts +9 -9
  197. package/src/blockFoundation/inputBlock.deserializer.ts +72 -97
  198. package/src/blockFoundation/inputBlock.serialization.types.ts +126 -132
  199. package/src/blockFoundation/inputBlock.serializer.ts +150 -150
  200. package/src/blockFoundation/inputBlock.ts +181 -192
  201. package/src/blockFoundation/outputBlock.ts +144 -151
  202. package/src/blockFoundation/shaderBlock.ts +156 -163
  203. package/src/blockFoundation/textureOptions.ts +57 -57
  204. package/src/command/command.ts +59 -59
  205. package/src/command/commandBuffer.ts +71 -71
  206. package/src/command/commandBufferDebugger.ts +14 -14
  207. package/src/command/index.ts +7 -3
  208. package/src/connection/connectionPoint.ts +205 -214
  209. package/src/connection/connectionPointCompatibilityState.ts +31 -31
  210. package/src/connection/connectionPointType.ts +45 -45
  211. package/src/connection/connectionPointWithDefault.ts +27 -35
  212. package/src/connection/index.ts +8 -9
  213. package/src/editorUtils/editableInPropertyPage.ts +106 -106
  214. package/src/editorUtils/index.ts +3 -1
  215. package/src/index.ts +16 -15
  216. package/src/optimization/dependencyGraph.ts +96 -96
  217. package/src/optimization/index.ts +1 -1
  218. package/src/optimization/optimizedShaderBlock.ts +131 -134
  219. package/src/optimization/smartFilterOptimizer.ts +757 -825
  220. package/src/runtime/index.ts +8 -6
  221. package/src/runtime/renderTargetGenerator.ts +222 -248
  222. package/src/runtime/shaderRuntime.ts +174 -173
  223. package/src/runtime/smartFilterRuntime.ts +112 -112
  224. package/src/runtime/strongRef.ts +18 -18
  225. package/src/serialization/importCustomBlockDefinition.ts +86 -86
  226. package/src/serialization/index.ts +10 -7
  227. package/src/serialization/serializedBlockDefinition.ts +12 -12
  228. package/src/serialization/serializedShaderBlockDefinition.ts +7 -7
  229. package/src/serialization/serializedSmartFilter.ts +6 -6
  230. package/src/serialization/smartFilterDeserializer.ts +190 -214
  231. package/src/serialization/smartFilterSerializer.ts +110 -121
  232. package/src/serialization/v1/defaultBlockSerializer.ts +21 -19
  233. package/src/serialization/v1/index.ts +4 -2
  234. package/src/serialization/v1/shaderBlockSerialization.types.ts +85 -85
  235. package/src/serialization/v1/smartFilterSerialization.types.ts +129 -129
  236. package/src/smartFilter.ts +255 -260
  237. package/src/utils/buildTools/buildShaders.ts +14 -13
  238. package/src/utils/buildTools/convertGlslIntoBlock.ts +370 -385
  239. package/src/utils/buildTools/convertGlslIntoShaderProgram.ts +173 -172
  240. package/src/utils/buildTools/convertShaders.ts +65 -43
  241. package/src/utils/buildTools/recordVersionNumber.js +17 -0
  242. package/src/utils/buildTools/shaderConverter.ts +466 -478
  243. package/src/utils/buildTools/watchShaders.ts +44 -42
  244. package/src/utils/index.ts +4 -2
  245. package/src/utils/renderTargetUtils.ts +30 -35
  246. package/src/utils/shaderCodeUtils.ts +192 -207
  247. package/src/utils/textureLoaders.ts +31 -43
  248. package/src/utils/textureUtils.ts +28 -32
  249. package/src/version.ts +2 -2
  250. package/dist/utils/buildTools/determineVersion.d.ts +0 -36
  251. package/dist/utils/buildTools/determineVersion.d.ts.map +0 -1
  252. package/dist/utils/buildTools/determineVersion.js +0 -109
  253. package/dist/utils/buildTools/determineVersion.js.map +0 -1
  254. package/dist/utils/buildTools/versionUp.d.ts +0 -2
  255. package/dist/utils/buildTools/versionUp.d.ts.map +0 -1
  256. package/dist/utils/buildTools/versionUp.js +0 -53
  257. package/dist/utils/buildTools/versionUp.js.map +0 -1
  258. package/src/utils/buildTools/determineVersion.ts +0 -128
  259. package/src/utils/buildTools/versionUp.ts +0 -61
@@ -1,172 +1,173 @@
1
- import * as fs from "fs";
2
- import { Logger } from "@babylonjs/core/Misc/logger.js";
3
- import { parseFragmentShader, type FragmentShaderInfo } from "./shaderConverter.js";
4
-
5
- const TYPE_IMPORT_PATH = "@TYPE_IMPORT_PATH@";
6
- const VERTEX_SHADER = "@VERTEX_SHADER@";
7
- const UNIFORMS = "@UNIFORMS@";
8
- const CONSTS_VALUE = "@CONSTS@";
9
- const CONSTS_PROPERTY = "@CONSTS_PROPERTY@";
10
- const MAIN_INPUT_NAME = "@MAIN_INPUT_NAME@";
11
- const MAIN_FUNCTION_NAME = "@MAIN_FUNCTION_NAME@";
12
- const FUNCTIONS = "@FUNCTIONS@";
13
- const FUNCTION_NAME = "@FUNCTION_NAME@";
14
- const FUNCTION_PARAMS = "@FUNCTION_PARAMS@";
15
- const FUNCTION_CODE = "@FUNCTION_CODE@";
16
- const UNIFORM_NAMES = "@UNIFORM_NAMES@";
17
- const EXPORT = "@EXPORT_SHADER_PROGRAM@";
18
- const IMPORTS = "@IMPORT@";
19
-
20
- const ConstsTemplate = `
21
- const: \`${CONSTS_VALUE}\`,`;
22
-
23
- const FunctionTemplate = `
24
- {
25
- name: "${FUNCTION_NAME}",
26
- code: \`
27
- ${FUNCTION_CODE}
28
- \`,
29
- params: "${FUNCTION_PARAMS}",
30
- },`;
31
-
32
- const CodeLinePrefix = " ";
33
- const UniformLinePrefix = " ";
34
- const ConstLinePrefix = " ";
35
-
36
- const ImportTemplate = `import type { ShaderProgram } from "${TYPE_IMPORT_PATH}";`;
37
- const ShaderTemplate = `${IMPORTS}
38
-
39
- /**
40
- * The shader program for the block.
41
- */
42
- ${EXPORT}const shaderProgram: ShaderProgram = {
43
- vertex: ${VERTEX_SHADER},
44
- fragment: {
45
- uniform: \`${UNIFORMS}\`,${CONSTS_PROPERTY}
46
- mainInputTexture: "${MAIN_INPUT_NAME}",
47
- mainFunctionName: "${MAIN_FUNCTION_NAME}",
48
- functions: [${FUNCTIONS}
49
- ],
50
- },
51
- };
52
-
53
- /**
54
- * The uniform names for this shader, to be used in the shader binding so
55
- * that the names are always in sync.
56
- */
57
- ${EXPORT}const uniforms = {
58
- ${UNIFORM_NAMES}
59
- };
60
- `;
61
-
62
- const UniformNameLinePrefix = " ";
63
-
64
- /**
65
- * Converts a single shader to a .ts file which exports a ShaderProgram which can be imported by a hardcoded block
66
- * @param fragmentShaderPath - The path to the fragment file for the shader
67
- * @param importPath - The path to import the ShaderProgram type from
68
- */
69
- export function convertGlslIntoShaderProgram(fragmentShaderPath: string, importPath: string): void {
70
- const { shaderProgramCode } = extractShaderProgramFromGlsl(fragmentShaderPath, importPath, true, true);
71
- const shaderFile = fragmentShaderPath.replace(".glsl", ".ts");
72
- fs.writeFileSync(shaderFile, shaderProgramCode);
73
- }
74
-
75
- /**
76
- * Extracts the shader program from a glsl file(s) and returns it as a string which can be written to a .ts file
77
- * @param fragmentShaderPath - The path to the fragment file for the shader
78
- * @param importPath - The path to import the ShaderProgram type from
79
- * @param exportObjects - Whether to export the shaderProgram and uniforms objects
80
- * @param includeImports - Whether to include the imports in the output
81
- * @returns The string to write to the .ts file
82
- */
83
- export function extractShaderProgramFromGlsl(
84
- fragmentShaderPath: string,
85
- importPath: string,
86
- exportObjects: boolean,
87
- includeImports: boolean
88
- ): {
89
- /**
90
- * The shader program code
91
- */
92
- shaderProgramCode: string;
93
-
94
- /**
95
- * The FragmentShaderInfo
96
- */
97
- fragmentShaderInfo: FragmentShaderInfo;
98
- } {
99
- // See if there is a corresponding vertex shader
100
- let vertexShader: string | undefined = undefined;
101
- let extensionToFind: string;
102
- if (fragmentShaderPath.endsWith(".block.glsl")) {
103
- extensionToFind = ".block.glsl";
104
- } else if (fragmentShaderPath.endsWith(".fragment.glsl")) {
105
- extensionToFind = ".fragment.glsl";
106
- } else {
107
- throw new Error("The shader file must end with .fragment.glsl or .block.glsl");
108
- }
109
- const vertexShaderPath = fragmentShaderPath.replace(extensionToFind, ".vertex.glsl");
110
- if (fs.existsSync(vertexShaderPath)) {
111
- vertexShader = fs.readFileSync(vertexShaderPath, "utf8");
112
- }
113
- if (vertexShader) {
114
- Logger.Log("Found vertex shader");
115
- }
116
-
117
- // Read the fragment shader
118
- const fragmentShader = fs.readFileSync(fragmentShaderPath, "utf8");
119
- const fragmentShaderInfo = parseFragmentShader(fragmentShader);
120
-
121
- // Generate the shader program code
122
- const functionsSection: string[] = [];
123
- for (const shaderFunction of fragmentShaderInfo.shaderCode.functions) {
124
- functionsSection.push(
125
- FunctionTemplate.replace(FUNCTION_NAME, shaderFunction.name)
126
- .replace(FUNCTION_PARAMS, shaderFunction.params || "")
127
- .replace(FUNCTION_CODE, addLinePrefixes(shaderFunction.code, CodeLinePrefix))
128
- );
129
- }
130
- const imports = includeImports ? ImportTemplate.replace(TYPE_IMPORT_PATH, importPath) : "";
131
- const finalContents = ShaderTemplate.replace(VERTEX_SHADER, vertexShader ? `\`${vertexShader}\`` : "undefined")
132
- .replace(IMPORTS, imports)
133
- .replace(UNIFORMS, "\n" + addLinePrefixes(fragmentShaderInfo.shaderCode.uniform || "", UniformLinePrefix))
134
- .replace(MAIN_FUNCTION_NAME, fragmentShaderInfo.shaderCode.mainFunctionName)
135
- .replace(MAIN_INPUT_NAME, fragmentShaderInfo.shaderCode.mainInputTexture || "")
136
- .replace(
137
- CONSTS_PROPERTY,
138
- fragmentShaderInfo.shaderCode.const
139
- ? ConstsTemplate.replace(
140
- CONSTS_VALUE,
141
- addLinePrefixes(fragmentShaderInfo.shaderCode.const, ConstLinePrefix)
142
- )
143
- : ""
144
- )
145
- .replace(FUNCTIONS, functionsSection.join(""))
146
- .replace(
147
- UNIFORM_NAMES,
148
- addLinePrefixes(
149
- fragmentShaderInfo.uniforms.map((u) => `${u.name}: "${u.name}",`).join("\n"),
150
- UniformNameLinePrefix
151
- )
152
- )
153
- .replace(new RegExp(EXPORT, "g"), exportObjects ? "export " : "");
154
-
155
- return {
156
- shaderProgramCode: finalContents,
157
- fragmentShaderInfo,
158
- };
159
- }
160
-
161
- /**
162
- * Prefixes each line in the input
163
- * @param input - The input string
164
- * @param prefix - The prefix to add to each line
165
- * @returns The input with each line prefixed
166
- */
167
- function addLinePrefixes(input: string, prefix: string): string {
168
- return input
169
- .split("\n")
170
- .map((line) => prefix + line)
171
- .join("\n");
172
- }
1
+ import * as fs from "fs";
2
+ import { Logger } from "core/Misc/logger.js";
3
+ import { ParseFragmentShader, type FragmentShaderInfo } from "./shaderConverter.js";
4
+
5
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6
+ const TYPE_IMPORT_PATH = "@TYPE_IMPORT_PATH@";
7
+ // eslint-disable-next-line @typescript-eslint/naming-convention
8
+ const VERTEX_SHADER = "@VERTEX_SHADER@";
9
+ const UNIFORMS = "@UNIFORMS@";
10
+ const CONSTS_VALUE = "@CONSTS@";
11
+ // eslint-disable-next-line @typescript-eslint/naming-convention
12
+ const CONSTS_PROPERTY = "@CONSTS_PROPERTY@";
13
+ const MAIN_INPUT_NAME = "@MAIN_INPUT_NAME@";
14
+ const MAIN_FUNCTION_NAME = "@MAIN_FUNCTION_NAME@";
15
+ const FUNCTIONS = "@FUNCTIONS@";
16
+ const FUNCTION_NAME = "@FUNCTION_NAME@";
17
+ const FUNCTION_PARAMS = "@FUNCTION_PARAMS@";
18
+ const FUNCTION_CODE = "@FUNCTION_CODE@";
19
+ const UNIFORM_NAMES = "@UNIFORM_NAMES@";
20
+ const EXPORT = "@EXPORT_SHADER_PROGRAM@";
21
+ const IMPORTS = "@IMPORT@";
22
+
23
+ const ConstsTemplate = `
24
+ const: \`${CONSTS_VALUE}\`,`;
25
+
26
+ const FunctionTemplate = `
27
+ {
28
+ name: "${FUNCTION_NAME}",
29
+ code: \`
30
+ ${FUNCTION_CODE}
31
+ \`,
32
+ params: "${FUNCTION_PARAMS}",
33
+ },`;
34
+
35
+ const CodeLinePrefix = " ";
36
+ const UniformLinePrefix = " ";
37
+ const ConstLinePrefix = " ";
38
+
39
+ const ImportTemplate = `import type { ShaderProgram } from "${TYPE_IMPORT_PATH}";`;
40
+ const ShaderTemplate = `${IMPORTS}
41
+
42
+ /**
43
+ * The shader program for the block.
44
+ */
45
+ const BlockShaderProgram: ShaderProgram = {
46
+ vertex: ${VERTEX_SHADER},
47
+ fragment: {
48
+ uniform: \`${UNIFORMS}\`,${CONSTS_PROPERTY}
49
+ mainInputTexture: "${MAIN_INPUT_NAME}",
50
+ mainFunctionName: "${MAIN_FUNCTION_NAME}",
51
+ functions: [${FUNCTIONS}
52
+ ],
53
+ },
54
+ };
55
+
56
+ /**
57
+ * The uniform names for this shader, to be used in the shader binding so
58
+ * that the names are always in sync.
59
+ */
60
+ const Uniforms = {
61
+ ${UNIFORM_NAMES}
62
+ };
63
+
64
+ ${EXPORT}`;
65
+
66
+ const UniformNameLinePrefix = " ";
67
+
68
+ /**
69
+ * Converts a single shader to a .ts file which exports a ShaderProgram which can be imported by a hardcoded block
70
+ * @param fragmentShaderPath - The path to the fragment file for the shader
71
+ * @param importPath - The path to import the Smart Filters core from
72
+ */
73
+ export function ConvertGlslIntoShaderProgram(fragmentShaderPath: string, importPath: string): void {
74
+ const { shaderProgramCode } = ExtractShaderProgramFromGlsl(fragmentShaderPath, importPath, true, true);
75
+ const shaderFile = fragmentShaderPath.replace(".glsl", ".ts");
76
+ fs.writeFileSync(shaderFile, shaderProgramCode);
77
+ }
78
+
79
+ /**
80
+ * Extracts the shader program from a glsl file(s) and returns it as a string which can be written to a .ts file
81
+ * @param fragmentShaderPath - The path to the fragment file for the shader
82
+ * @param smartFiltersCorePath - The path to import the Smart Filters core from
83
+ * @param exportObjects - Whether to export the shaderProgram and uniforms objects
84
+ * @param includeImports - Whether to include the imports in the output
85
+ * @returns The string to write to the .ts file
86
+ */
87
+ export function ExtractShaderProgramFromGlsl(
88
+ fragmentShaderPath: string,
89
+ smartFiltersCorePath: string,
90
+ exportObjects: boolean,
91
+ includeImports: boolean
92
+ ): {
93
+ /**
94
+ * The shader program code
95
+ */
96
+ shaderProgramCode: string;
97
+
98
+ /**
99
+ * The FragmentShaderInfo
100
+ */
101
+ fragmentShaderInfo: FragmentShaderInfo;
102
+ } {
103
+ // See if there is a corresponding vertex shader
104
+ let vertexShader: string | undefined = undefined;
105
+ let extensionToFind: string;
106
+ if (fragmentShaderPath.endsWith(".block.glsl")) {
107
+ extensionToFind = ".block.glsl";
108
+ } else if (fragmentShaderPath.endsWith(".fragment.glsl")) {
109
+ extensionToFind = ".fragment.glsl";
110
+ } else {
111
+ throw new Error("The shader file must end with .fragment.glsl or .block.glsl");
112
+ }
113
+ const vertexShaderPath = fragmentShaderPath.replace(extensionToFind, ".vertex.glsl");
114
+ if (fs.existsSync(vertexShaderPath)) {
115
+ vertexShader = fs.readFileSync(vertexShaderPath, "utf8");
116
+ }
117
+ if (vertexShader) {
118
+ Logger.Log("Found vertex shader");
119
+ }
120
+
121
+ // Read the fragment shader
122
+ const fragmentShader = fs.readFileSync(fragmentShaderPath, "utf8");
123
+ const fragmentShaderInfo = ParseFragmentShader(fragmentShader);
124
+
125
+ // Generate the shader program code
126
+ const functionsSection: string[] = [];
127
+ for (const shaderFunction of fragmentShaderInfo.shaderCode.functions) {
128
+ functionsSection.push(
129
+ FunctionTemplate.replace(FUNCTION_NAME, shaderFunction.name)
130
+ .replace(FUNCTION_PARAMS, shaderFunction.params || "")
131
+ .replace(FUNCTION_CODE, AddLinePrefixes(shaderFunction.code, CodeLinePrefix))
132
+ );
133
+ }
134
+ const imports = includeImports ? ImportTemplate.replace(TYPE_IMPORT_PATH, smartFiltersCorePath) : "";
135
+ const finalContents = ShaderTemplate.replace(VERTEX_SHADER, vertexShader ? `\`${vertexShader}\`` : "undefined")
136
+ .replace(IMPORTS, imports)
137
+ .replace(UNIFORMS, "\n" + AddLinePrefixes(fragmentShaderInfo.shaderCode.uniform || "", UniformLinePrefix))
138
+ .replace(MAIN_FUNCTION_NAME, fragmentShaderInfo.shaderCode.mainFunctionName)
139
+ .replace(MAIN_INPUT_NAME, fragmentShaderInfo.shaderCode.mainInputTexture || "")
140
+ .replace(
141
+ CONSTS_PROPERTY,
142
+ fragmentShaderInfo.shaderCode.const ? ConstsTemplate.replace(CONSTS_VALUE, AddLinePrefixes(fragmentShaderInfo.shaderCode.const, ConstLinePrefix)) : ""
143
+ )
144
+ .replace(FUNCTIONS, functionsSection.join(""))
145
+ .replace(UNIFORM_NAMES, AddLinePrefixes(fragmentShaderInfo.uniforms.map((u) => `${u.name}: "${u.name}",`).join("\n"), UniformNameLinePrefix))
146
+ .replace(
147
+ new RegExp(EXPORT, "g"),
148
+ exportObjects
149
+ ? `export { BlockShaderProgram, Uniforms };
150
+ // Back compat for when camelCase was used
151
+ export { BlockShaderProgram as shaderProgram, Uniforms as uniforms };
152
+ `
153
+ : ""
154
+ );
155
+
156
+ return {
157
+ shaderProgramCode: finalContents,
158
+ fragmentShaderInfo,
159
+ };
160
+ }
161
+
162
+ /**
163
+ * Prefixes each line in the input
164
+ * @param input - The input string
165
+ * @param prefix - The prefix to add to each line
166
+ * @returns The input with each line prefixed
167
+ */
168
+ function AddLinePrefixes(input: string, prefix: string): string {
169
+ return input
170
+ .split("\n")
171
+ .map((line) => prefix + line)
172
+ .join("\n");
173
+ }
@@ -1,43 +1,65 @@
1
- import * as fs from "fs";
2
- import * as path from "path";
3
- import { Logger } from "@babylonjs/core/Misc/logger.js";
4
- import { convertGlslIntoShaderProgram } from "./convertGlslIntoShaderProgram.js";
5
- import { convertGlslIntoBlock } from "./convertGlslIntoBlock.js";
6
-
7
- /**
8
- * Converts all GLSL files in a path into blocks for use in the build system.
9
- * @param shaderPath - The path to the .glsl files to convert.
10
- * @param importPath - The path to import the ShaderProgram type from.
11
- */
12
- export function convertShaders(shaderPath: string, importPath: string) {
13
- // Get all files in the path
14
- const allFiles = fs.readdirSync(shaderPath, { withFileTypes: true, recursive: true });
15
-
16
- // Find all shaders (files with .fragment.glsl or .block.glsl extensions)
17
- const shaderFiles = allFiles.filter(
18
- (file) => file.isFile() && (file.name.endsWith(".fragment.glsl") || file.name.endsWith(".block.glsl"))
19
- );
20
-
21
- // Convert all shaders
22
- for (const shaderFile of shaderFiles) {
23
- const fullPathAndFileName = path.join(shaderFile.path, shaderFile.name);
24
- convertShader(fullPathAndFileName, importPath);
25
- }
26
- }
27
-
28
- /**
29
- * Converts a single GLSL file into a block class or a ShaderProgram for use in the build system.
30
- * @param fullPathAndFileName - The full path and file name of the .glsl file to convert.
31
- * @param importPath - The path to import the ShaderProgram type from.
32
- */
33
- export function convertShader(fullPathAndFileName: string, importPath: string): void {
34
- Logger.Log(`\nProcessing shader: ${fullPathAndFileName}`);
35
-
36
- if (fullPathAndFileName.endsWith(".fragment.glsl")) {
37
- Logger.Log("Generating a .ts file that exports a ShaderProgram.");
38
- convertGlslIntoShaderProgram(fullPathAndFileName, importPath);
39
- } else if (fullPathAndFileName.endsWith(".block.glsl")) {
40
- Logger.Log("Generating a .ts file that exports the block as a class.");
41
- convertGlslIntoBlock(fullPathAndFileName, importPath);
42
- }
43
- }
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ import { Logger } from "core/Misc/logger.js";
4
+ import { ConvertGlslIntoShaderProgram } from "./convertGlslIntoShaderProgram.js";
5
+ import { ConvertGlslIntoBlock } from "./convertGlslIntoBlock.js";
6
+
7
+ /**
8
+ * Converts all GLSL files in a path into blocks for use in the build system.
9
+ * @param shaderPath - The path to the .glsl files to convert, or a single .glsl file.
10
+ * @param smartFiltersCorePath - The path to import the Smart Filters core from.
11
+ * @param babylonCorePath - The path to import the Babylon core from (optional).
12
+
13
+ */
14
+ export function ConvertShaders(shaderPath: string, smartFiltersCorePath: string, babylonCorePath?: string) {
15
+ const stats = fs.statSync(shaderPath);
16
+
17
+ let shaderFiles: fs.Dirent[];
18
+
19
+ if (stats.isFile()) {
20
+ // If it's a file, create a Dirent-like object for consistency
21
+ const fileName = path.basename(shaderPath);
22
+ const dirPath = path.dirname(shaderPath);
23
+ shaderFiles = [
24
+ {
25
+ name: fileName,
26
+ path: dirPath,
27
+ isFile: () => true,
28
+ isDirectory: () => false,
29
+ } as fs.Dirent,
30
+ ];
31
+ } else if (stats.isDirectory()) {
32
+ // Get all files in the directory
33
+ const allFiles = fs.readdirSync(shaderPath, { withFileTypes: true, recursive: true });
34
+
35
+ // Find all shaders (files with .fragment.glsl or .block.glsl extensions)
36
+ shaderFiles = allFiles.filter((file) => file.isFile() && (file.name.endsWith(".fragment.glsl") || file.name.endsWith(".block.glsl")));
37
+ } else {
38
+ Logger.Log(`Error: ${shaderPath} is neither a file nor a directory.`);
39
+ return;
40
+ }
41
+
42
+ // Convert all shaders
43
+ for (const shaderFile of shaderFiles) {
44
+ const fullPathAndFileName = path.join(shaderFile.path, shaderFile.name);
45
+ ConvertShader(fullPathAndFileName, smartFiltersCorePath, babylonCorePath);
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Converts a single GLSL file into a block class or a ShaderProgram for use in the build system.
51
+ * @param fullPathAndFileName - The full path and file name of the .glsl file to convert.
52
+ * @param smartFiltersCorePath - The path to import the Smart Filters core from.
53
+ * @param babylonCorePath - The path to import the Babylon core from (optional).
54
+ */
55
+ export function ConvertShader(fullPathAndFileName: string, smartFiltersCorePath: string, babylonCorePath?: string): void {
56
+ Logger.Log(`\nProcessing shader: ${fullPathAndFileName}`);
57
+
58
+ if (fullPathAndFileName.endsWith(".fragment.glsl")) {
59
+ Logger.Log("Generating a .ts file that exports a ShaderProgram.");
60
+ ConvertGlslIntoShaderProgram(fullPathAndFileName, smartFiltersCorePath);
61
+ } else if (fullPathAndFileName.endsWith(".block.glsl")) {
62
+ Logger.Log("Generating a .ts file that exports the block as a class.");
63
+ ConvertGlslIntoBlock(fullPathAndFileName, smartFiltersCorePath, babylonCorePath);
64
+ }
65
+ }
@@ -0,0 +1,17 @@
1
+ /* eslint-disable no-console */
2
+ import * as fs from "fs";
3
+
4
+ const PackageText = fs.readFileSync("package.json");
5
+ const PackageJSON = JSON.parse(PackageText.toString());
6
+
7
+ const PackageName = PackageJSON.name;
8
+ console.log("Processing package:", PackageName);
9
+ console.log("Current package.json version:", PackageJSON.version);
10
+
11
+ // Write out to version.ts
12
+ const VersionTsText = `/**
13
+ * The version of the SmartFilter core. During publish, this file is overwritten by recordVersionNumber.ts with the same version that is used for the NPM publish.
14
+ */
15
+ export const SmartFilterCoreVersion = "${PackageJSON.version}";\n`;
16
+ fs.writeFileSync("src/version.ts", VersionTsText);
17
+ console.log("Wrote version.ts with version:", PackageJSON.version);