@babylonjs/smart-filters 1.0.1 → 1.0.3
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.
- package/dist/utils/buildTools/shaderConverter.d.ts.map +1 -1
- package/dist/utils/buildTools/shaderConverter.js +47 -51
- package/dist/utils/buildTools/shaderConverter.js.map +1 -1
- package/dist/utils/buildTools/watchShaders.js +2 -1
- package/dist/utils/buildTools/watchShaders.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/utils/buildTools/shaderConverter.ts +57 -79
- package/src/utils/buildTools/watchShaders.ts +4 -2
- package/src/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shaderConverter.d.ts","sourceRoot":"","sources":["../../../src/utils/buildTools/shaderConverter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iDAAiD,CAAC;AAKvF;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACpC;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC;IAEd;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,mBAAmB,CAAC;IAE1B;;OAEG;IACH,UAAU,CAAC,EAAE,yBAAyB,CAAC;CAC1C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC7B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IAC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H,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAE5C;;OAEG;IACH,UAAU,EAAE,UAAU,CAAC;IAEvB;;OAEG;IACH,QAAQ,EAAE,eAAe,EAAE,CAAC;CAC/B,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,MAAM,GAAG,kBAAkB,CAwI9E;AA+ND;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAE7D"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Logger } from "@babylonjs/core/Misc/logger.js";
|
|
2
2
|
import { ConnectionPointType } from "../../connection/connectionPointType.js";
|
|
3
3
|
import { BlockDisableStrategy } from "../../blockFoundation/disableableShaderBlock.js";
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const GetFunctionHeaderRegEx = /\S*\w+\s+(\w+)\s*\((.*?)\)\s*\{/g; // Matches a function's name and its parameters
|
|
5
|
+
const ReservedSymbols = ["main"];
|
|
6
6
|
/**
|
|
7
7
|
* Parses a fragment shader
|
|
8
8
|
* @param fragmentShader - The fragment shader to process
|
|
@@ -76,12 +76,18 @@ export function parseFragmentShader(fragmentShader) {
|
|
|
76
76
|
Logger.Log(`Uniforms found: ${JSON.stringify(uniforms)}`);
|
|
77
77
|
const consts = [...fragmentShader.matchAll(/\S*const\s+\w*\s+(\w*)\s*=.*;/g)].map((match) => match[1]);
|
|
78
78
|
Logger.Log(`Consts found: ${JSON.stringify(consts)}`);
|
|
79
|
-
const functionNames = [...fragmentShaderWithNoFunctionBodies.matchAll(
|
|
79
|
+
const functionNames = [...fragmentShaderWithNoFunctionBodies.matchAll(GetFunctionHeaderRegEx)].map((match) => match[1]);
|
|
80
80
|
Logger.Log(`Functions found: ${JSON.stringify(functionNames)}`);
|
|
81
81
|
// Decorate the uniforms, consts, and functions
|
|
82
82
|
const symbolsToDecorate = [...uniformNames, ...consts, ...functionNames];
|
|
83
83
|
let fragmentShaderWithRenamedSymbols = fragmentShader;
|
|
84
84
|
for (const symbol of symbolsToDecorate) {
|
|
85
|
+
if (!symbol) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (ReservedSymbols.indexOf(symbol) !== -1) {
|
|
89
|
+
throw new Error(`Symbol "${symbol}" is reserved and cannot be used`);
|
|
90
|
+
}
|
|
85
91
|
const regex = new RegExp(`(?<=\\W+)${symbol}(?=\\W+)`, "gs");
|
|
86
92
|
fragmentShaderWithRenamedSymbols = fragmentShaderWithRenamedSymbols.replace(regex, `_${symbol}_`);
|
|
87
93
|
}
|
|
@@ -117,75 +123,65 @@ export function parseFragmentShader(fragmentShader) {
|
|
|
117
123
|
};
|
|
118
124
|
}
|
|
119
125
|
/**
|
|
120
|
-
* Extracts all
|
|
126
|
+
* Extracts all functions from the shader
|
|
121
127
|
* @param fragment - The shader code to process
|
|
122
128
|
* @returns A list of functions
|
|
123
129
|
*/
|
|
124
130
|
function extractFunctions(fragment) {
|
|
125
|
-
const lines = fragment.split("\n");
|
|
126
131
|
const extractedFunctions = [];
|
|
127
132
|
let mainFunctionName;
|
|
128
|
-
let
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
let pos = 0;
|
|
134
|
+
while (pos < fragment.length) {
|
|
135
|
+
// Match the next available function header in the fragment code
|
|
136
|
+
GetFunctionHeaderRegEx.lastIndex = pos;
|
|
137
|
+
const match = GetFunctionHeaderRegEx.exec(fragment);
|
|
138
|
+
if (!match) {
|
|
139
|
+
break;
|
|
134
140
|
}
|
|
135
|
-
|
|
136
|
-
|
|
141
|
+
const functionName = match[1];
|
|
142
|
+
if (!functionName) {
|
|
143
|
+
throw new Error("No function name found in shader code");
|
|
137
144
|
}
|
|
138
|
-
|
|
139
|
-
|
|
145
|
+
const functionParams = match[2] || "";
|
|
146
|
+
// Store start index of the function definition
|
|
147
|
+
const startIndex = match.index;
|
|
148
|
+
// Balance braces to find end of function, starting just after the opening `{`
|
|
149
|
+
let endIndex = match.index + match[0].length;
|
|
150
|
+
let depth = 1;
|
|
151
|
+
while (depth > 0 && endIndex < fragment.length) {
|
|
152
|
+
if (fragment[endIndex] === "{") {
|
|
140
153
|
depth++;
|
|
141
154
|
}
|
|
142
|
-
else if (
|
|
155
|
+
else if (fragment[endIndex] === "}") {
|
|
143
156
|
depth--;
|
|
144
157
|
}
|
|
158
|
+
endIndex++;
|
|
145
159
|
}
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (mainFunctionName) {
|
|
156
|
-
throw new Error("Multiple main functions found in shader code");
|
|
157
|
-
}
|
|
158
|
-
mainFunctionName = functionName;
|
|
160
|
+
if (depth !== 0) {
|
|
161
|
+
throw new Error(`Mismatched curly braces found near: ${functionName}`);
|
|
162
|
+
}
|
|
163
|
+
// Finally, process the function code
|
|
164
|
+
let functionCode = fragment.substring(startIndex, endIndex).trim();
|
|
165
|
+
// Check if this function is the main function
|
|
166
|
+
if (functionCode.includes("// main")) {
|
|
167
|
+
if (mainFunctionName) {
|
|
168
|
+
throw new Error("Multiple main functions found in shader code");
|
|
159
169
|
}
|
|
160
|
-
|
|
170
|
+
mainFunctionName = functionName;
|
|
171
|
+
functionCode = functionCode.replace("// main", "");
|
|
161
172
|
}
|
|
173
|
+
extractedFunctions.push({
|
|
174
|
+
name: functionName,
|
|
175
|
+
code: functionCode,
|
|
176
|
+
params: functionParams.trim(),
|
|
177
|
+
});
|
|
178
|
+
pos = endIndex;
|
|
162
179
|
}
|
|
163
180
|
if (!mainFunctionName) {
|
|
164
181
|
throw new Error("No main function found in shader code");
|
|
165
182
|
}
|
|
166
183
|
return { extractedFunctions, mainFunctionName };
|
|
167
184
|
}
|
|
168
|
-
/**
|
|
169
|
-
* Creates code for a ShaderFunction instance from the body of a function
|
|
170
|
-
* @param functionBody - The body of the function
|
|
171
|
-
* @returns The body, name, parameter list, and whether the function is the main function
|
|
172
|
-
*/
|
|
173
|
-
function processFunctionBody(functionBody) {
|
|
174
|
-
// Extract the function name
|
|
175
|
-
const functionNamesFound = [...functionBody.matchAll(GetFunctionNamesRegEx)].map((match) => match[1]);
|
|
176
|
-
const functionName = functionNamesFound[0];
|
|
177
|
-
if (!functionName) {
|
|
178
|
-
throw new Error("No function name found in shader code");
|
|
179
|
-
}
|
|
180
|
-
// Extract the function params
|
|
181
|
-
const functionParamsFound = [...functionBody.matchAll(GetFunctionParamsRegEx)].map((match) => match[1]);
|
|
182
|
-
const functionParams = functionParamsFound[0] || "";
|
|
183
|
-
const isMainFunction = functionBody.includes("// main");
|
|
184
|
-
if (isMainFunction) {
|
|
185
|
-
functionBody = functionBody.replace("// main", "");
|
|
186
|
-
}
|
|
187
|
-
return { functionBody, functionName, functionParams, isMainFunction };
|
|
188
|
-
}
|
|
189
185
|
/**
|
|
190
186
|
* Removes all function bodies from the shader code, leaving just curly braces behind at the top level
|
|
191
187
|
* @param input - The shader code to process
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shaderConverter.js","sourceRoot":"","sources":["../../../src/utils/buildTools/shaderConverter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAExD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iDAAiD,CAAC;AAEvF,MAAM,
|
|
1
|
+
{"version":3,"file":"shaderConverter.js","sourceRoot":"","sources":["../../../src/utils/buildTools/shaderConverter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAExD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iDAAiD,CAAC;AAEvF,MAAM,sBAAsB,GAAG,kCAAkC,C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CAAC;IACL,CAAC;IAED,OAAO,UAAU,CAAC;AACtB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,cAAsB;IAChD,OAAO,cAAc,CAAC,OAAO,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -21,6 +21,7 @@ if (externalArguments.length >= 2 && externalArguments[0] && externalArguments[1
|
|
|
21
21
|
if (extname(file) !== ".glsl") {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
+
console.log(`Change detected. Starting conversion...`);
|
|
24
25
|
// Wrap in try-catch to prevent the watcher from crashing
|
|
25
26
|
// if the new shader changes are invalid
|
|
26
27
|
try {
|
|
@@ -30,7 +31,7 @@ if (externalArguments.length >= 2 && externalArguments[0] && externalArguments[1
|
|
|
30
31
|
catch (error) {
|
|
31
32
|
console.error(`Failed to convert shader ${file}: ${error}`);
|
|
32
33
|
}
|
|
34
|
+
console.log(`Watching for changes in ${shaderPath}...`);
|
|
33
35
|
});
|
|
34
|
-
console.log(`Watching for shader changes in ${shaderPath}`);
|
|
35
36
|
}
|
|
36
37
|
//# sourceMappingURL=watchShaders.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watchShaders.js","sourceRoot":"","sources":["../../../src/utils/buildTools/watchShaders.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,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,M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,UAAU,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAExC,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACxC,4CAA4C;QAC5C,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YACxC,OAAO;QACX,CAAC;QAED,2BAA2B;QAC3B,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,EAAE,CAAC;YAC5B,OAAO;QACX,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;QAEvD,yDAAyD;QACzD,wCAAwC;QACxC,IAAI,CAAC;YACD,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;YAChC,OAAO,CAAC,GAAG,CAAC,+BAA+B,IAAI,EAAE,CAAC,CAAC;QACvD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,4BAA4B,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC;QAChE,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,2BAA2B,UAAU,KAAK,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACP,CAAC"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The version of the SmartFilter core. During publish, this file is overwritten by versionUp.ts with the same version that is used for the NPM publish.
|
|
3
3
|
*/
|
|
4
|
-
export declare const SmartFilterCoreVersion = "1.0.
|
|
4
|
+
export declare const SmartFilterCoreVersion = "1.0.3";
|
|
5
5
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The version of the SmartFilter core. During publish, this file is overwritten by versionUp.ts with the same version that is used for the NPM publish.
|
|
3
3
|
*/
|
|
4
|
-
export const SmartFilterCoreVersion = "1.0.
|
|
4
|
+
export const SmartFilterCoreVersion = "1.0.3";
|
|
5
5
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@ import type { ShaderCode, ShaderFunction } from "./shaderCode.types";
|
|
|
4
4
|
import { ConnectionPointType } from "../../connection/connectionPointType.js";
|
|
5
5
|
import { BlockDisableStrategy } from "../../blockFoundation/disableableShaderBlock.js";
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const GetFunctionHeaderRegEx = /\S*\w+\s+(\w+)\s*\((.*?)\)\s*\{/g; // Matches a function's name and its parameters
|
|
8
|
+
const ReservedSymbols = ["main"];
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Describes the supported metadata properties for a uniform
|
|
@@ -160,7 +160,7 @@ export function parseFragmentShader(fragmentShader: string): FragmentShaderInfo
|
|
|
160
160
|
Logger.Log(`Uniforms found: ${JSON.stringify(uniforms)}`);
|
|
161
161
|
const consts = [...fragmentShader.matchAll(/\S*const\s+\w*\s+(\w*)\s*=.*;/g)].map((match) => match[1]);
|
|
162
162
|
Logger.Log(`Consts found: ${JSON.stringify(consts)}`);
|
|
163
|
-
const functionNames = [...fragmentShaderWithNoFunctionBodies.matchAll(
|
|
163
|
+
const functionNames = [...fragmentShaderWithNoFunctionBodies.matchAll(GetFunctionHeaderRegEx)].map(
|
|
164
164
|
(match) => match[1]
|
|
165
165
|
);
|
|
166
166
|
Logger.Log(`Functions found: ${JSON.stringify(functionNames)}`);
|
|
@@ -169,6 +169,12 @@ export function parseFragmentShader(fragmentShader: string): FragmentShaderInfo
|
|
|
169
169
|
const symbolsToDecorate = [...uniformNames, ...consts, ...functionNames];
|
|
170
170
|
let fragmentShaderWithRenamedSymbols = fragmentShader;
|
|
171
171
|
for (const symbol of symbolsToDecorate) {
|
|
172
|
+
if (!symbol) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (ReservedSymbols.indexOf(symbol) !== -1) {
|
|
176
|
+
throw new Error(`Symbol "${symbol}" is reserved and cannot be used`);
|
|
177
|
+
}
|
|
172
178
|
const regex = new RegExp(`(?<=\\W+)${symbol}(?=\\W+)`, "gs");
|
|
173
179
|
fragmentShaderWithRenamedSymbols = fragmentShaderWithRenamedSymbols.replace(regex, `_${symbol}_`);
|
|
174
180
|
}
|
|
@@ -216,7 +222,7 @@ export function parseFragmentShader(fragmentShader: string): FragmentShaderInfo
|
|
|
216
222
|
}
|
|
217
223
|
|
|
218
224
|
/**
|
|
219
|
-
* Extracts all
|
|
225
|
+
* Extracts all functions from the shader
|
|
220
226
|
* @param fragment - The shader code to process
|
|
221
227
|
* @returns A list of functions
|
|
222
228
|
*/
|
|
@@ -231,98 +237,70 @@ function extractFunctions(fragment: string): {
|
|
|
231
237
|
*/
|
|
232
238
|
mainFunctionName: string;
|
|
233
239
|
} {
|
|
234
|
-
const lines = fragment.split("\n");
|
|
235
240
|
const extractedFunctions: ShaderFunction[] = [];
|
|
236
241
|
let mainFunctionName: string | undefined;
|
|
237
|
-
let
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
let pos = 0;
|
|
243
|
+
|
|
244
|
+
while (pos < fragment.length) {
|
|
245
|
+
// Match the next available function header in the fragment code
|
|
246
|
+
GetFunctionHeaderRegEx.lastIndex = pos;
|
|
247
|
+
const match = GetFunctionHeaderRegEx.exec(fragment);
|
|
248
|
+
if (!match) {
|
|
249
|
+
break;
|
|
244
250
|
}
|
|
245
|
-
|
|
246
|
-
|
|
251
|
+
|
|
252
|
+
const functionName = match[1];
|
|
253
|
+
if (!functionName) {
|
|
254
|
+
throw new Error("No function name found in shader code");
|
|
247
255
|
}
|
|
248
|
-
|
|
249
|
-
|
|
256
|
+
|
|
257
|
+
const functionParams = match[2] || "";
|
|
258
|
+
|
|
259
|
+
// Store start index of the function definition
|
|
260
|
+
const startIndex = match.index;
|
|
261
|
+
|
|
262
|
+
// Balance braces to find end of function, starting just after the opening `{`
|
|
263
|
+
let endIndex = match.index + match[0].length;
|
|
264
|
+
let depth = 1;
|
|
265
|
+
while (depth > 0 && endIndex < fragment.length) {
|
|
266
|
+
if (fragment[endIndex] === "{") {
|
|
250
267
|
depth++;
|
|
251
|
-
} else if (
|
|
268
|
+
} else if (fragment[endIndex] === "}") {
|
|
252
269
|
depth--;
|
|
253
270
|
}
|
|
271
|
+
endIndex++;
|
|
254
272
|
}
|
|
255
|
-
if (inFunction && depth === 0) {
|
|
256
|
-
inFunction = false;
|
|
257
|
-
const { functionBody, functionName, functionParams, isMainFunction } = processFunctionBody(currentFunction);
|
|
258
|
-
|
|
259
|
-
extractedFunctions.push({
|
|
260
|
-
name: functionName,
|
|
261
|
-
params: functionParams,
|
|
262
|
-
code: functionBody,
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
if (isMainFunction) {
|
|
266
|
-
if (mainFunctionName) {
|
|
267
|
-
throw new Error("Multiple main functions found in shader code");
|
|
268
|
-
}
|
|
269
|
-
mainFunctionName = functionName;
|
|
270
|
-
}
|
|
271
|
-
currentFunction = "";
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
if (!mainFunctionName) {
|
|
276
|
-
throw new Error("No main function found in shader code");
|
|
277
|
-
}
|
|
278
273
|
|
|
279
|
-
|
|
280
|
-
}
|
|
274
|
+
if (depth !== 0) {
|
|
275
|
+
throw new Error(`Mismatched curly braces found near: ${functionName}`);
|
|
276
|
+
}
|
|
281
277
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
* @param functionBody - The body of the function
|
|
285
|
-
* @returns The body, name, parameter list, and whether the function is the main function
|
|
286
|
-
*/
|
|
287
|
-
function processFunctionBody(functionBody: string): {
|
|
288
|
-
/**
|
|
289
|
-
* The body of the function
|
|
290
|
-
*/
|
|
291
|
-
functionBody: string;
|
|
278
|
+
// Finally, process the function code
|
|
279
|
+
let functionCode = fragment.substring(startIndex, endIndex).trim();
|
|
292
280
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
281
|
+
// Check if this function is the main function
|
|
282
|
+
if (functionCode.includes("// main")) {
|
|
283
|
+
if (mainFunctionName) {
|
|
284
|
+
throw new Error("Multiple main functions found in shader code");
|
|
285
|
+
}
|
|
286
|
+
mainFunctionName = functionName;
|
|
287
|
+
functionCode = functionCode.replace("// main", "");
|
|
288
|
+
}
|
|
297
289
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
290
|
+
extractedFunctions.push({
|
|
291
|
+
name: functionName,
|
|
292
|
+
code: functionCode,
|
|
293
|
+
params: functionParams.trim(),
|
|
294
|
+
});
|
|
302
295
|
|
|
303
|
-
|
|
304
|
-
* Whether the function is the main function
|
|
305
|
-
*/
|
|
306
|
-
isMainFunction: boolean;
|
|
307
|
-
} {
|
|
308
|
-
// Extract the function name
|
|
309
|
-
const functionNamesFound = [...functionBody.matchAll(GetFunctionNamesRegEx)].map((match) => match[1]);
|
|
310
|
-
const functionName = functionNamesFound[0];
|
|
311
|
-
if (!functionName) {
|
|
312
|
-
throw new Error("No function name found in shader code");
|
|
296
|
+
pos = endIndex;
|
|
313
297
|
}
|
|
314
298
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
const functionParams = functionParamsFound[0] || "";
|
|
318
|
-
|
|
319
|
-
const isMainFunction = functionBody.includes("// main");
|
|
320
|
-
|
|
321
|
-
if (isMainFunction) {
|
|
322
|
-
functionBody = functionBody.replace("// main", "");
|
|
299
|
+
if (!mainFunctionName) {
|
|
300
|
+
throw new Error("No main function found in shader code");
|
|
323
301
|
}
|
|
324
302
|
|
|
325
|
-
return {
|
|
303
|
+
return { extractedFunctions, mainFunctionName };
|
|
326
304
|
}
|
|
327
305
|
|
|
328
306
|
/**
|
|
@@ -26,6 +26,8 @@ if (externalArguments.length >= 2 && externalArguments[0] && externalArguments[1
|
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
console.log(`Change detected. Starting conversion...`);
|
|
30
|
+
|
|
29
31
|
// Wrap in try-catch to prevent the watcher from crashing
|
|
30
32
|
// if the new shader changes are invalid
|
|
31
33
|
try {
|
|
@@ -34,7 +36,7 @@ if (externalArguments.length >= 2 && externalArguments[0] && externalArguments[1
|
|
|
34
36
|
} catch (error) {
|
|
35
37
|
console.error(`Failed to convert shader ${file}: ${error}`);
|
|
36
38
|
}
|
|
37
|
-
});
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
console.log(`Watching for changes in ${shaderPath}...`);
|
|
41
|
+
});
|
|
40
42
|
}
|
package/src/version.ts
CHANGED