@babylonjs/smart-filters 0.2.0-alpha → 0.3.0-alpha

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 (98) hide show
  1. package/dist/blocks/baseBlock.d.ts +1 -1
  2. package/dist/blocks/baseBlock.d.ts.map +1 -1
  3. package/dist/blocks/baseBlock.js +1 -1
  4. package/dist/blocks/baseBlock.js.map +1 -1
  5. package/dist/blocks/copyBlock.d.ts +2 -3
  6. package/dist/blocks/copyBlock.d.ts.map +1 -1
  7. package/dist/blocks/copyBlock.js +4 -24
  8. package/dist/blocks/copyBlock.js.map +1 -1
  9. package/dist/blocks/copyBlock.shader.d.ts +13 -0
  10. package/dist/blocks/copyBlock.shader.d.ts.map +1 -0
  11. package/dist/blocks/copyBlock.shader.js +31 -0
  12. package/dist/blocks/copyBlock.shader.js.map +1 -0
  13. package/dist/blocks/inputBlock.d.ts +15 -5
  14. package/dist/blocks/inputBlock.d.ts.map +1 -1
  15. package/dist/blocks/inputBlock.deserializer.d.ts +14 -0
  16. package/dist/blocks/inputBlock.deserializer.d.ts.map +1 -0
  17. package/dist/blocks/inputBlock.deserializer.js +23 -0
  18. package/dist/blocks/inputBlock.deserializer.js.map +1 -0
  19. package/dist/blocks/inputBlock.js +12 -6
  20. package/dist/blocks/inputBlock.js.map +1 -1
  21. package/dist/blocks/inputBlock.serialization.types.d.ts +62 -0
  22. package/dist/blocks/inputBlock.serialization.types.d.ts.map +1 -0
  23. package/dist/blocks/inputBlock.serialization.types.js +2 -0
  24. package/dist/blocks/inputBlock.serialization.types.js.map +1 -0
  25. package/dist/blocks/inputBlock.serializer.d.ts +6 -0
  26. package/dist/blocks/inputBlock.serializer.d.ts.map +1 -0
  27. package/dist/blocks/inputBlock.serializer.js +110 -0
  28. package/dist/blocks/inputBlock.serializer.js.map +1 -0
  29. package/dist/index.d.ts +1 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +1 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/serialization/index.d.ts +5 -0
  34. package/dist/serialization/index.d.ts.map +1 -0
  35. package/dist/serialization/index.js +5 -0
  36. package/dist/serialization/index.js.map +1 -0
  37. package/dist/serialization/serializedSmartFilter.d.ts +6 -0
  38. package/dist/serialization/serializedSmartFilter.d.ts.map +1 -0
  39. package/dist/serialization/serializedSmartFilter.js +2 -0
  40. package/dist/serialization/serializedSmartFilter.js.map +1 -0
  41. package/dist/serialization/smartFilterDeserializer.d.ts +25 -0
  42. package/dist/serialization/smartFilterDeserializer.d.ts.map +1 -0
  43. package/dist/serialization/smartFilterDeserializer.js +94 -0
  44. package/dist/serialization/smartFilterDeserializer.js.map +1 -0
  45. package/dist/serialization/smartFilterSerializer.d.ts +23 -0
  46. package/dist/serialization/smartFilterSerializer.d.ts.map +1 -0
  47. package/dist/serialization/smartFilterSerializer.js +91 -0
  48. package/dist/serialization/smartFilterSerializer.js.map +1 -0
  49. package/dist/serialization/v1/defaultBlockSerializer.d.ts +9 -0
  50. package/dist/serialization/v1/defaultBlockSerializer.d.ts.map +1 -0
  51. package/dist/serialization/v1/defaultBlockSerializer.js +16 -0
  52. package/dist/serialization/v1/defaultBlockSerializer.js.map +1 -0
  53. package/dist/serialization/v1/index.d.ts +3 -0
  54. package/dist/serialization/v1/index.d.ts.map +1 -0
  55. package/dist/serialization/v1/index.js +3 -0
  56. package/dist/serialization/v1/index.js.map +1 -0
  57. package/dist/serialization/v1/serialization.types.d.ts +83 -0
  58. package/dist/serialization/v1/serialization.types.d.ts.map +1 -0
  59. package/dist/serialization/v1/serialization.types.js +2 -0
  60. package/dist/serialization/v1/serialization.types.js.map +1 -0
  61. package/dist/smartFilter.d.ts +2 -2
  62. package/dist/smartFilter.d.ts.map +1 -1
  63. package/dist/smartFilter.js +0 -1
  64. package/dist/smartFilter.js.map +1 -1
  65. package/dist/utils/buildTools/shaderConverter.d.ts +2 -0
  66. package/dist/utils/buildTools/shaderConverter.d.ts.map +1 -0
  67. package/dist/utils/buildTools/shaderConverter.js +271 -0
  68. package/dist/utils/buildTools/shaderConverter.js.map +1 -0
  69. package/dist/utils/textureLoaders.d.ts +2 -1
  70. package/dist/utils/textureLoaders.d.ts.map +1 -1
  71. package/dist/utils/textureLoaders.js +3 -2
  72. package/dist/utils/textureLoaders.js.map +1 -1
  73. package/dist/utils/uniqueIdGenerator.d.ts +19 -0
  74. package/dist/utils/uniqueIdGenerator.d.ts.map +1 -0
  75. package/dist/utils/uniqueIdGenerator.js +27 -0
  76. package/dist/utils/uniqueIdGenerator.js.map +1 -0
  77. package/package.json +10 -5
  78. package/readme.md +12 -0
  79. package/src/blocks/baseBlock.ts +2 -3
  80. package/src/blocks/copyBlock.fragment.glsl +5 -0
  81. package/src/blocks/copyBlock.shader.ts +33 -0
  82. package/src/blocks/copyBlock.ts +4 -29
  83. package/src/blocks/inputBlock.deserializer.ts +38 -0
  84. package/src/blocks/inputBlock.serialization.types.ts +80 -0
  85. package/src/blocks/inputBlock.serializer.ts +127 -0
  86. package/src/blocks/inputBlock.ts +18 -7
  87. package/src/index.ts +1 -0
  88. package/src/serialization/index.ts +4 -0
  89. package/src/serialization/serializedSmartFilter.ts +6 -0
  90. package/src/serialization/smartFilterDeserializer.ts +127 -0
  91. package/src/serialization/smartFilterSerializer.ts +113 -0
  92. package/src/serialization/v1/defaultBlockSerializer.ts +18 -0
  93. package/src/serialization/v1/index.ts +2 -0
  94. package/src/serialization/v1/serialization.types.ts +108 -0
  95. package/src/smartFilter.ts +2 -2
  96. package/src/utils/buildTools/shaderConverter.ts +388 -0
  97. package/src/utils/textureLoaders.ts +16 -2
  98. package/src/utils/uniqueIdGenerator.ts +28 -0
@@ -0,0 +1,271 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ const TYPE_IMPORT_PATH = "@TYPE_IMPORT_PATH@";
4
+ const VERTEX_SHADER = "@VERTEX_SHADER@";
5
+ const UNIFORMS = "@UNIFORMS@";
6
+ const CONSTS_VALUE = "@CONSTS@";
7
+ const CONSTS_PROPERTY = "@CONSTS_PROPERTY@";
8
+ const MAIN_INPUT_NAME = "@MAIN_INPUT_NAME@";
9
+ const MAIN_FUNCTION_NAME = "@MAIN_FUNCTION_NAME@";
10
+ const FUNCTIONS = "@FUNCTIONS@";
11
+ const FUNCTION_NAME = "@FUNCTION_NAME@";
12
+ const FUNCTION_CODE = "@FUNCTION_CODE@";
13
+ const UNIFORM_NAMES = "@UNIFORM_NAMES@";
14
+ const ConstsTemplate = `
15
+ const: \`${CONSTS_VALUE}\`,`;
16
+ const FunctionTemplate = `
17
+ {
18
+ name: "${FUNCTION_NAME}",
19
+ code: \`
20
+ ${FUNCTION_CODE}
21
+ \`,
22
+ },`;
23
+ const CodeLinePrefix = " ";
24
+ const UniformLinePrefix = " ";
25
+ const ConstLinePrefix = " ";
26
+ const ShaderTemplate = `import type { ShaderProgram } from "${TYPE_IMPORT_PATH}";
27
+
28
+ /**
29
+ * The shader program for the block.
30
+ */
31
+ export const shaderProgram: ShaderProgram = {
32
+ vertex: ${VERTEX_SHADER},
33
+ fragment: {
34
+ uniform: \`${UNIFORMS}\`,${CONSTS_PROPERTY}
35
+ mainInputTexture: "${MAIN_INPUT_NAME}",
36
+ mainFunctionName: "${MAIN_FUNCTION_NAME}",
37
+ functions: [${FUNCTIONS}
38
+ ],
39
+ },
40
+ };
41
+
42
+ /**
43
+ * The uniform names for this shader, to be used in the shader binding so
44
+ * that the names are always in sync.
45
+ */
46
+ export const uniforms = {
47
+ ${UNIFORM_NAMES}
48
+ };
49
+ `;
50
+ const UniformNameLinePrefix = " ";
51
+ const GetFunctionNamesRegEx = /\S*\w+\s+(\w+)\s*\(/g;
52
+ /**
53
+ * Converts a single shader
54
+ * @param fragmentShaderPath - The path to the fragment file for the shader
55
+ * @param importPath - The path to import the ShaderProgram type from
56
+ */
57
+ function convertShader(fragmentShaderPath, importPath) {
58
+ console.log(`Processing fragment shader: ${fragmentShaderPath}`);
59
+ // See if there is a corresponding vertex shader
60
+ let vertexShader = undefined;
61
+ const vertexShaderPath = fragmentShaderPath.replace(".fragment.glsl", ".vertex.glsl");
62
+ if (fs.existsSync(vertexShaderPath)) {
63
+ vertexShader = fs.readFileSync(vertexShaderPath, "utf8");
64
+ }
65
+ if (vertexShader) {
66
+ console.log("Found vertex shader");
67
+ }
68
+ // Read the fragment shader
69
+ const fragmentShader = fs.readFileSync(fragmentShaderPath, "utf8");
70
+ // Version check
71
+ const versionsFound = [...fragmentShader.matchAll(/\/\/\s+\[Smart Filter Shader Version\]\s*=\s*(\d+)/g)].map((match) => match[1]);
72
+ let version = 1;
73
+ if (versionsFound.length === 1 && versionsFound[0]) {
74
+ version = parseInt(versionsFound[0]);
75
+ }
76
+ console.log(`Shader version: ${version}`);
77
+ let fragmentShaderInfo;
78
+ switch (version) {
79
+ case 1:
80
+ {
81
+ fragmentShaderInfo = processFragmentShaderV1(fragmentShader);
82
+ }
83
+ break;
84
+ default: {
85
+ throw new Error(`Unsupported shader version: ${version}`);
86
+ }
87
+ }
88
+ // Write the shader TS file
89
+ const shaderFile = fragmentShaderPath.replace(".fragment.glsl", ".shader.ts");
90
+ const finalContents = ShaderTemplate.replace(VERTEX_SHADER, vertexShader ? `\`${vertexShader}\`` : "undefined")
91
+ .replace(TYPE_IMPORT_PATH, importPath)
92
+ .replace(UNIFORMS, "\n" + addLinePrefixes(fragmentShaderInfo.finalUniforms.join("\n"), UniformLinePrefix))
93
+ .replace(MAIN_FUNCTION_NAME, fragmentShaderInfo.mainFunctionName)
94
+ .replace(MAIN_INPUT_NAME, fragmentShaderInfo.mainInputName)
95
+ .replace(CONSTS_PROPERTY, fragmentShaderInfo.finalConsts.length > 0
96
+ ? ConstsTemplate.replace(CONSTS_VALUE, addLinePrefixes(fragmentShaderInfo.finalConsts.join("\n"), ConstLinePrefix))
97
+ : "")
98
+ .replace(FUNCTIONS, fragmentShaderInfo.extractedFunctions.join(""))
99
+ .replace(UNIFORM_NAMES, addLinePrefixes(fragmentShaderInfo.uniformNames.join("\n"), UniformNameLinePrefix));
100
+ fs.writeFileSync(shaderFile, finalContents);
101
+ }
102
+ /**
103
+ * Processes a fragment shader
104
+ * @param fragmentShader - The fragment shader to process
105
+ * @returns The processed fragment shader
106
+ */
107
+ function processFragmentShaderV1(fragmentShader) {
108
+ const fragmentShaderWithNoFunctionBodies = removeFunctionBodies(fragmentShader);
109
+ // Collect uniform, const, and function names which need to be decorated
110
+ // eslint-disable-next-line prettier/prettier
111
+ const uniforms = [...fragmentShader.matchAll(/\S*uniform.*\s(\w*);/g)].map((match) => match[1]);
112
+ console.log(`Uniforms found: ${JSON.stringify(uniforms)}`);
113
+ const consts = [...fragmentShader.matchAll(/\S*const\s+\w*\s+(\w*)\s*=.*;/g)].map((match) => match[1]);
114
+ console.log(`Consts found: ${JSON.stringify(consts)}`);
115
+ const functionNames = [...fragmentShaderWithNoFunctionBodies.matchAll(GetFunctionNamesRegEx)].map((match) => match[1]);
116
+ console.log(`Functions found: ${JSON.stringify(functionNames)}`);
117
+ // Decorate the uniforms, consts, and functions
118
+ const symbolsToDecorate = [...uniforms, ...consts, ...functionNames];
119
+ let fragmentShaderWithRenamedSymbols = fragmentShader;
120
+ for (const symbol of symbolsToDecorate) {
121
+ const regex = new RegExp(`(\\S*(?:\\s|;|,|\\)|\\()+)${symbol}((\\s|;|,|\\)|\\()+)`, "gs");
122
+ fragmentShaderWithRenamedSymbols = fragmentShaderWithRenamedSymbols.replace(regex, `$1_${symbol}_$2`);
123
+ }
124
+ console.log(`${symbolsToDecorate.length} symbol(s) renamed`);
125
+ const uniformNames = uniforms.map((uniform) => `${uniform}: "${uniform}",`);
126
+ // Extract all the uniforms
127
+ const finalUniforms = [...fragmentShaderWithRenamedSymbols.matchAll(/^\s*(uniform\s.*)/gm)].map((match) => match[1]);
128
+ // Extract all the consts
129
+ const finalConsts = [...fragmentShaderWithRenamedSymbols.matchAll(/^\s*(const\s.*)/gm)].map((match) => match[1]);
130
+ // Extract all the functions
131
+ const { extractedFunctions, mainFunctionName } = extractFunctions(fragmentShaderWithRenamedSymbols);
132
+ // Find the main input
133
+ const mainInputs = [...fragmentShaderWithRenamedSymbols.matchAll(/\S*uniform.*\s(\w*);\s*\/\/\s*main/gm)].map((match) => match[1]);
134
+ if (mainInputs.length !== 1 || !mainInputs[0]) {
135
+ throw new Error("Exactly one main input must be defined in the shader");
136
+ }
137
+ const mainInputName = mainInputs[0];
138
+ return {
139
+ finalUniforms,
140
+ mainFunctionName,
141
+ mainInputName,
142
+ finalConsts,
143
+ extractedFunctions,
144
+ uniformNames,
145
+ };
146
+ }
147
+ /**
148
+ * Prefixes each line in the input
149
+ * @param input - The input string
150
+ * @param prefix - The prefix to add to each line
151
+ * @returns The input with each line prefixed
152
+ */
153
+ function addLinePrefixes(input, prefix) {
154
+ return input
155
+ .split("\n")
156
+ .map((line) => prefix + line)
157
+ .join("\n");
158
+ }
159
+ /**
160
+ * Extracts all the functions from the shader
161
+ * @param fragment - The shader code to process
162
+ * @returns A list of functions
163
+ */
164
+ function extractFunctions(fragment) {
165
+ const lines = fragment.split("\n");
166
+ const extractedFunctions = [];
167
+ let mainFunctionName;
168
+ let inFunction = false;
169
+ let depth = 0;
170
+ let currentFunction = "";
171
+ for (const line of lines) {
172
+ if (!inFunction && line.includes("{")) {
173
+ inFunction = true;
174
+ }
175
+ if (inFunction) {
176
+ currentFunction += line + "\n";
177
+ }
178
+ for (let pos = 0; pos < line.length; pos++) {
179
+ if (line[pos] === "{") {
180
+ depth++;
181
+ }
182
+ else if (line[pos] === "}") {
183
+ depth--;
184
+ }
185
+ }
186
+ if (inFunction && depth === 0) {
187
+ inFunction = false;
188
+ const { functionBody, functionName, isMainFunction } = processFunctionBody(currentFunction);
189
+ extractedFunctions.push(FunctionTemplate.replace(FUNCTION_NAME, functionName).replace(FUNCTION_CODE, addLinePrefixes(functionBody, CodeLinePrefix)));
190
+ if (isMainFunction) {
191
+ if (mainFunctionName) {
192
+ throw new Error("Multiple main functions found in shader code");
193
+ }
194
+ mainFunctionName = functionName;
195
+ }
196
+ currentFunction = "";
197
+ }
198
+ }
199
+ if (!mainFunctionName) {
200
+ throw new Error("No main function found in shader code");
201
+ }
202
+ return { extractedFunctions, mainFunctionName };
203
+ }
204
+ /**
205
+ * Creates code for a ShaderFunction instance from the body of a function
206
+ * @param functionBody - The body of the function
207
+ * @returns The body, name, and whether the function is the main function
208
+ */
209
+ function processFunctionBody(functionBody) {
210
+ // Extract the function name
211
+ const functionNamesFound = [...functionBody.matchAll(GetFunctionNamesRegEx)].map((match) => match[1]);
212
+ const functionName = functionNamesFound[0];
213
+ if (!functionName) {
214
+ throw new Error("No function name found in shader code");
215
+ }
216
+ const isMainFunction = functionBody.includes("// main");
217
+ return { functionBody, functionName, isMainFunction };
218
+ }
219
+ /**
220
+ * Removes all function bodies from the shader code, leaving just curly braces behind at the top level
221
+ * @param input - The shader code to process
222
+ * @returns The shader code with all function bodies removed
223
+ */
224
+ function removeFunctionBodies(input) {
225
+ let output = "";
226
+ let depth = 0;
227
+ for (let pos = 0; pos < input.length; pos++) {
228
+ if (input[pos] === "{") {
229
+ depth++;
230
+ // Special case - if we just hit the first { then include it
231
+ if (depth === 1) {
232
+ output += "{";
233
+ }
234
+ }
235
+ else if (input[pos] === "}") {
236
+ depth--;
237
+ // Special case - if we just hit the last } then include it
238
+ if (depth === 0) {
239
+ output += "}";
240
+ }
241
+ }
242
+ else if (depth === 0) {
243
+ output += input[pos];
244
+ }
245
+ }
246
+ if (depth !== 0) {
247
+ console.error("Unbalanced curly braces in shader code");
248
+ }
249
+ return output;
250
+ }
251
+ /**
252
+ * Converts .fragment.glsl and vertex.glsl file pairs into .shader.ts files which export a ShaderProgram object.
253
+ * @param shaderPath - The path to the .glsl files to convert.
254
+ * @param importPath - The path to import the ShaderProgram type from.
255
+ */
256
+ function convertShaders(shaderPath, importPath) {
257
+ // Get all files in the path
258
+ const allFiles = fs.readdirSync(shaderPath, { withFileTypes: true, recursive: true });
259
+ // Find all fragment shaders (excluding the template)
260
+ const fragmentShaderFiles = allFiles.filter((file) => file.isFile() && file.name.endsWith(".fragment.glsl") && !file.name.endsWith("template.fragment.glsl"));
261
+ // Convert all shaders
262
+ for (const fragmentShaderFile of fragmentShaderFiles) {
263
+ convertShader(path.join(fragmentShaderFile.path, fragmentShaderFile.name), importPath);
264
+ }
265
+ }
266
+ const externalArguments = process.argv.slice(2);
267
+ if (externalArguments.length >= 2 && externalArguments[0] && externalArguments[1]) {
268
+ convertShaders(externalArguments[0], externalArguments[1]);
269
+ }
270
+ // TODO: simple copy from shader file to .ts, get it to build (including import trick)
271
+ //# sourceMappingURL=shaderConverter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shaderConverter.js","sourceRoot":"","sources":["../../../src/utils/buildTools/shaderConverter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAC9C,MAAM,aAAa,GAAG,iBAAiB,CAAC;AACxC,MAAM,QAAQ,GAAG,YAAY,CAAC;AAC9B,MAAM,YAAY,GAAG,UAAU,CAAC;AAChC,MAAM,eAAe,GAAG,mBAAmB,CAAC;AAC5C,MAAM,eAAe,GAAG,mBAAmB,CAAC;AAC5C,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AAClD,MAAM,SAAS,GAAG,aAAa,CAAC;AAChC,MAAM,aAAa,GAAG,iBAAiB,CAAC;AACxC,MAAM,aAAa,GAAG,iBAAiB,CAAC;AACxC,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAExC,MAAM,cAAc,GAAG;mBACJ,YAAY,KAAK,CAAC;AAErC,MAAM,gBAAgB,GAAG;;yBAEA,aAAa;;EAEpC,aAAa;;eAEA,CAAC;AAEhB,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAC9C,MAAM,iBAAiB,GAAG,cAAc,CAAC;AACzC,MAAM,eAAe,GAAG,cAAc,CA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AM,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CACnH,CAAC;IAEF,sBAAsB;IACtB,KAAK,MAAM,kBAAkB,IAAI,mBAAmB,EAAE,CAAC;QACnD,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,EAAE,kBAAkB,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC;IAC3F,CAAC;AACL,CAAC;AAED,MAAM,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAChD,IAAI,iBAAiB,CAAC,MAAM,IAAI,CAAC,IAAI,iBAAiB,CAAC,CAAC,CAAC,IAAI,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC;IAChF,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED,sFAAsF"}
@@ -8,7 +8,8 @@ import { type ThinEngine } from "@babylonjs/core/Engines/thinEngine.js";
8
8
  * * A base64 string of in-line texture data, e.g. 'data:image/jpg;base64,/...'
9
9
  * @param flipY - Indicates if the Y axis should be flipped
10
10
  * @param samplingMode - The sampling mode to use
11
+ * @param forcedExtension - defines the extension to use to pick the right loader
11
12
  * @returns A ThinTexture of the image
12
13
  */
13
- export declare function createImageTexture(engine: ThinEngine, url: string, flipY?: boolean, samplingMode?: number | undefined): ThinTexture;
14
+ export declare function createImageTexture(engine: ThinEngine, url: string, flipY?: boolean, samplingMode?: number | undefined, forcedExtension?: string | null): ThinTexture;
14
15
  //# sourceMappingURL=textureLoaders.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"textureLoaders.d.ts","sourceRoot":"","sources":["../../src/utils/textureLoaders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mDAAmD,CAAC;AAChF,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,uCAAuC,CAAC;AAExE;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAC9B,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,MAAM,EACX,KAAK,GAAE,OAAc,EACrB,YAAY,GAAE,MAAM,GAAG,SAAqB,GAC7C,WAAW,CAGb"}
1
+ {"version":3,"file":"textureLoaders.d.ts","sourceRoot":"","sources":["../../src/utils/textureLoaders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mDAAmD,CAAC;AAChF,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,uCAAuC,CAAC;AAExE;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAC9B,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,MAAM,EACX,KAAK,GAAE,OAAc,EACrB,YAAY,GAAE,MAAM,GAAG,SAAqB,EAC5C,eAAe,GAAE,MAAM,GAAG,IAAW,GACtC,WAAW,CAeb"}
@@ -8,10 +8,11 @@ import {} from "@babylonjs/core/Engines/thinEngine.js";
8
8
  * * A base64 string of in-line texture data, e.g. 'data:image/jpg;base64,/...'
9
9
  * @param flipY - Indicates if the Y axis should be flipped
10
10
  * @param samplingMode - The sampling mode to use
11
+ * @param forcedExtension - defines the extension to use to pick the right loader
11
12
  * @returns A ThinTexture of the image
12
13
  */
13
- export function createImageTexture(engine, url, flipY = true, samplingMode = undefined) {
14
- const internalTexture = engine.createTexture(url, true, flipY, null, samplingMode);
14
+ export function createImageTexture(engine, url, flipY = true, samplingMode = undefined, forcedExtension = null) {
15
+ const internalTexture = engine.createTexture(url, true, flipY, null, samplingMode, null, null, null, null, null, forcedExtension);
15
16
  return new ThinTexture(internalTexture);
16
17
  }
17
18
  /*
@@ -1 +1 @@
1
- {"version":3,"file":"textureLoaders.js","sourceRoot":"","sources":["../../src/utils/textureLoaders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mDAAmD,CAAC;AAChF,OAAO,EAAmB,MAAM,uCAAuC,CAAC;AAExE;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAC9B,MAAkB,EAClB,GAAW,EACX,QAAiB,IAAI,EACrB,eAAmC,SAAS;IAE5C,MAAM,eAAe,GAAG,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;IACnF,OAAO,IAAI,WAAW,CAAC,eAAe,CAAC,CAAC;AAC5C,CAAC;AAED;;;;EAIE"}
1
+ {"version":3,"file":"textureLoaders.js","sourceRoot":"","sources":["../../src/utils/textureLoaders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mDAAmD,CAAC;AAChF,OAAO,EAAmB,MAAM,uCAAuC,CAAC;AAExE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAC9B,MAAkB,EAClB,GAAW,EACX,QAAiB,IAAI,EACrB,eAAmC,SAAS,EAC5C,kBAAiC,IAAI;IAErC,MAAM,eAAe,GAAG,MAAM,CAAC,aAAa,CACxC,GAAG,EACH,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,YAAY,EACZ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,eAAe,CAClB,CAAC;IACF,OAAO,IAAI,WAAW,CAAC,eAAe,CAAC,CAAC;AAC5C,CAAC;AAED;;;;EAIE"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Helper class used to generate IDs unique to the current session
3
+ */
4
+ export declare class UniqueIdGenerator {
5
+ /**
6
+ * The next unique ID to be returned
7
+ */
8
+ static _NextUniqueId: number;
9
+ /**
10
+ * Gets a unique (relatively to the current session) Id
11
+ */
12
+ static get UniqueId(): number;
13
+ /**
14
+ * Ensures future generated IDs are greater than the specified value
15
+ * @param minimum - The minimum value that future generated IDs should be greater than
16
+ */
17
+ static EnsureIdsGreaterThan(minimum: number): void;
18
+ }
19
+ //# sourceMappingURL=uniqueIdGenerator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uniqueIdGenerator.d.ts","sourceRoot":"","sources":["../../src/utils/uniqueIdGenerator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,iBAAiB;IAC1B;;OAEG;IACH,OAAc,aAAa,SAAK;IAEhC;;OAEG;IACH,WAAkB,QAAQ,WAIzB;IAED;;;OAGG;WACW,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAK5D"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Helper class used to generate IDs unique to the current session
3
+ */
4
+ export class UniqueIdGenerator {
5
+ /**
6
+ * Gets a unique (relatively to the current session) Id
7
+ */
8
+ static get UniqueId() {
9
+ const result = this._NextUniqueId;
10
+ this._NextUniqueId++;
11
+ return result;
12
+ }
13
+ /**
14
+ * Ensures future generated IDs are greater than the specified value
15
+ * @param minimum - The minimum value that future generated IDs should be greater than
16
+ */
17
+ static EnsureIdsGreaterThan(minimum) {
18
+ if (this._NextUniqueId <= minimum) {
19
+ this._NextUniqueId = minimum + 1;
20
+ }
21
+ }
22
+ }
23
+ /**
24
+ * The next unique ID to be returned
25
+ */
26
+ UniqueIdGenerator._NextUniqueId = 1;
27
+ //# sourceMappingURL=uniqueIdGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uniqueIdGenerator.js","sourceRoot":"","sources":["../../src/utils/uniqueIdGenerator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAM1B;;OAEG;IACI,MAAM,KAAK,QAAQ;QACtB,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC;QAClC,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,oBAAoB,CAAC,OAAe;QAC9C,IAAI,IAAI,CAAC,aAAa,IAAI,OAAO,EAAE,CAAC;YAChC,IAAI,CAAC,aAAa,GAAG,OAAO,GAAG,CAAC,CAAC;QACrC,CAAC;IACL,CAAC;;AAtBD;;GAEG;AACW,+BAAa,GAAG,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@babylonjs/smart-filters",
3
- "version": "0.2.0-alpha",
4
- "description": "Babylon.js Smart Filter core and common block library",
3
+ "version": "0.3.0-alpha",
4
+ "description": "Babylon.js Smart Filter core",
5
5
  "author": {
6
6
  "name": "Sebastien VANDENBERGHE"
7
7
  },
@@ -24,7 +24,9 @@
24
24
  "esnext": "dist/index",
25
25
  "types": "dist/index",
26
26
  "type": "module",
27
- "sideEffects": false,
27
+ "sideEffects": [
28
+ "./dist/utils/buildTools/**"
29
+ ],
28
30
  "repository": {
29
31
  "type": "git",
30
32
  "url": "git+https://github.com/BabylonJS/SmartFilters.git"
@@ -37,8 +39,11 @@
37
39
  ],
38
40
  "scripts": {
39
41
  "clean": "rimraf dist && rimraf tsconfig.build.tsbuildinfo",
40
- "versionUp": "node tools/versionUp.js",
41
- "build": "tsc -p ./tsconfig.build.json",
42
+ "versionUp": "node buildTools/versionUp.js",
43
+ "build": "npm run build:buildTools && npm run build:runTools && npm run build:core",
44
+ "build:core": "tsc -p ./tsconfig.build.json",
45
+ "build:buildTools": "tsc -p ./tsconfig.buildTools.build.json",
46
+ "build:runTools": "node buildTools/dist/shaderConverter.js ./src/blocks ../utils/shaderCodeUtils",
42
47
  "watch": "tsc -p ./tsconfig.build.json --watch",
43
48
  "test": "echo \"Error: run test from the root of the monorepo\" && exit 1"
44
49
  },
package/readme.md CHANGED
@@ -163,3 +163,15 @@ The overall system is trying at best to follow 3 simple rules:
163
163
  - Be CPU efficient: for instance, we are trying to be branchless in most of our commands and we try to keep the number of commands as low as possible.
164
164
  - Be memory efficient: no commands should allocate memory as it could trigger some garbage collection at the expense of frame loss.
165
165
  - Be GPU efficient: the graph and texture optimizers minimize the number of "passes" required to render an image and the GPU resources used by the graph.
166
+
167
+ ## Requirements for GLSL code
168
+
169
+ To be imported into blocks, the following requirements must be met by .glsl files:
170
+
171
+ 1. There must be a sampler2D uniform designed as the main input texture (the one to be passed along) if this block is disabled. It must have a comment on its line like this:
172
+ `// main`
173
+ 1. There must be a single main function which takes in a vec2 named vUV and returns a vec4, and it must have a comment on its line like this:
174
+ `// main`
175
+ 1. Any uniforms which should have the same value across all instances of the same block should have a comment on its line like this:
176
+ `// single`
177
+ 1. Functions must be declared with the open { on the same line as the function name
@@ -1,12 +1,11 @@
1
1
  import type { Nullable } from "@babylonjs/core/types";
2
- import { UniqueIdGenerator } from "@babylonjs/core/Misc/uniqueIdGenerator.js";
3
-
4
2
  import { ConnectionPointType, type ConnectionPointValue } from "../connection/connectionPointType.js";
5
3
  import type { InitializationData, SmartFilter } from "../smartFilter";
6
4
  import type { ICommandOwner } from "../command/command";
7
5
  import { ConnectionPoint, type RuntimeData } from "../connection/connectionPoint.js";
8
6
  import { ConnectionPointWithDefault } from "../connection/connectionPointWithDefault.js";
9
7
  import { ConnectionPointDirection } from "../connection/connectionPointDirection.js";
8
+ import { UniqueIdGenerator } from "../utils/uniqueIdGenerator.js";
10
9
 
11
10
  /**
12
11
  * Defines a callback function that is triggered when visiting a block,
@@ -38,7 +37,7 @@ export abstract class BaseBlock implements ICommandOwner {
38
37
  /**
39
38
  * Global unique id of the block (This is unique for the current session).
40
39
  */
41
- public readonly uniqueId: number;
40
+ public uniqueId: number;
42
41
 
43
42
  /**
44
43
  * The name of the block. This is used to identify the block in the smart filter or in debug.
@@ -0,0 +1,5 @@
1
+ uniform sampler2D input; // main
2
+
3
+ vec4 copy(vec2 vUV) { // main
4
+ return texture2D(input, vUV);
5
+ }
@@ -0,0 +1,33 @@
1
+ import type { ShaderProgram } from "../utils/shaderCodeUtils";
2
+
3
+ /**
4
+ * The shader program for the block.
5
+ */
6
+ export const shaderProgram: ShaderProgram = {
7
+ vertex: undefined,
8
+ fragment: {
9
+ uniform: `
10
+ uniform sampler2D _input_; // main`,
11
+ mainInputTexture: "_input_",
12
+ mainFunctionName: "_copy_",
13
+ functions: [
14
+ {
15
+ name: "_copy_",
16
+ code: `
17
+ vec4 _copy_(vec2 vUV) { // main
18
+ return texture2D(_input_, vUV);
19
+ }
20
+
21
+ `,
22
+ },
23
+ ],
24
+ },
25
+ };
26
+
27
+ /**
28
+ * The uniform names for this shader, to be used in the shader binding so
29
+ * that the names are always in sync.
30
+ */
31
+ export const uniforms = {
32
+ input: "input",
33
+ };
@@ -1,32 +1,11 @@
1
1
  import type { Effect } from "@babylonjs/core/Materials/effect";
2
2
 
3
- import type { ShaderProgram } from "../utils/shaderCodeUtils";
4
3
  import type { SmartFilter } from "../smartFilter";
5
4
  import { ConnectionPointType } from "../connection/connectionPointType.js";
6
5
  import { ShaderBlock } from "./shaderBlock.js";
7
6
  import { ShaderBinding } from "../runtime/shaderRuntime.js";
8
7
  import type { RuntimeData } from "../connection/connectionPoint";
9
-
10
- const shaderProgram: ShaderProgram = {
11
- fragment: {
12
- uniform: `
13
- uniform sampler2D _input_;
14
- `,
15
-
16
- mainFunctionName: "_copy_",
17
-
18
- functions: [
19
- {
20
- name: "_copy_",
21
- code: `
22
- vec4 _copy_(vec2 vUV) {
23
- return texture2D(_input_, vUV);
24
- }
25
- `,
26
- },
27
- ],
28
- },
29
- };
8
+ import { shaderProgram, uniforms } from "./copyBlock.shader.js";
30
9
 
31
10
  /**
32
11
  * The shader bindings for the Copy block.
@@ -50,7 +29,7 @@ export class CopyShaderBinding extends ShaderBinding {
50
29
  * @internal
51
30
  */
52
31
  public override bind(effect: Effect): void {
53
- effect.setTexture(this.getRemappedName("input"), this._inputTexture.value);
32
+ effect.setTexture(this.getRemappedName(uniforms.input), this._inputTexture.value);
54
33
  }
55
34
  }
56
35
 
@@ -59,7 +38,7 @@ export class CopyShaderBinding extends ShaderBinding {
59
38
  *
60
39
  * This might be helpful to duplicate a texture if necessary.
61
40
  *
62
- * It simply takes a texture as input and outputs it to another texture or the main canvas.
41
+ * It simply takes a texture as input and outputs it to another texture or to the main canvas.
63
42
  */
64
43
  export class CopyBlock extends ShaderBlock {
65
44
  /**
@@ -91,11 +70,7 @@ export class CopyBlock extends ShaderBlock {
91
70
  * @returns The class instance that binds the data to the effect
92
71
  */
93
72
  public getShaderBinding(): ShaderBinding {
94
- const input = this.input.runtimeData;
95
-
96
- if (!input) {
97
- throw new Error(`The input texture is missing for the CopyBlock named ${this.name}`);
98
- }
73
+ const input = this._confirmRuntimeDataSupplied(this.input);
99
74
 
100
75
  return new CopyShaderBinding(this, input);
101
76
  }
@@ -0,0 +1,38 @@
1
+ import { InputBlock } from "./inputBlock.js";
2
+ import type { SerializedInputBlockData } from "./inputBlock.serialization.types.js";
3
+ import { ConnectionPointType } from "../connection/connectionPointType.js";
4
+ import type { SmartFilter } from "../smartFilter.js";
5
+ import type { ISerializedBlockV1 } from "../serialization/v1/serialization.types.js";
6
+ import { createImageTexture } from "../utils/textureLoaders.js";
7
+ import type { ThinEngine } from "@babylonjs/core/Engines/thinEngine.js";
8
+
9
+ /**
10
+ * V1 Input Block Deserializer
11
+ * @param smartFilter - The SmartFilter to deserialize the block into
12
+ * @param serializedBlock - The serialized block data
13
+ * @param engine - The ThinEngine to use for loading textures
14
+ * @returns A deserialized InputBlock
15
+ */
16
+ export function inputBlockDeserializer(
17
+ smartFilter: SmartFilter,
18
+ serializedBlock: ISerializedBlockV1,
19
+ engine: ThinEngine
20
+ ) {
21
+ const blockData = serializedBlock.data as SerializedInputBlockData;
22
+
23
+ switch (blockData.inputType) {
24
+ case ConnectionPointType.Boolean:
25
+ return new InputBlock(smartFilter, serializedBlock.name, ConnectionPointType.Boolean, blockData.value);
26
+ case ConnectionPointType.Float:
27
+ return new InputBlock(smartFilter, serializedBlock.name, ConnectionPointType.Float, blockData.value);
28
+ case ConnectionPointType.Texture:
29
+ return new InputBlock(
30
+ smartFilter,
31
+ serializedBlock.name,
32
+ ConnectionPointType.Texture,
33
+ blockData.url !== null ? createImageTexture(engine, blockData.url) : null
34
+ );
35
+ }
36
+
37
+ throw new Error("Could not deserialize input block, unknown input type");
38
+ }