@babylonjs/smart-filters 0.7.12-alpha → 0.7.13-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 (36) hide show
  1. package/dist/serialization/importCustomBlockDefinition.js +1 -25
  2. package/dist/serialization/importCustomBlockDefinition.js.map +1 -1
  3. package/dist/utils/buildTools/buildShaders.js +1 -1
  4. package/dist/utils/buildTools/buildShaders.js.map +1 -1
  5. package/dist/utils/buildTools/convertGlslIntoBlock.d.ts +7 -0
  6. package/dist/utils/buildTools/convertGlslIntoBlock.d.ts.map +1 -0
  7. package/dist/utils/buildTools/convertGlslIntoBlock.js +217 -0
  8. package/dist/utils/buildTools/convertGlslIntoBlock.js.map +1 -0
  9. package/dist/utils/buildTools/convertGlslIntoShaderProgram.d.ts +26 -0
  10. package/dist/utils/buildTools/convertGlslIntoShaderProgram.d.ts.map +1 -0
  11. package/dist/utils/buildTools/{convertShaderForHardcodedBlock.js → convertGlslIntoShaderProgram.js} +43 -30
  12. package/dist/utils/buildTools/convertGlslIntoShaderProgram.js.map +1 -0
  13. package/dist/utils/buildTools/convertShaders.d.ts +13 -0
  14. package/dist/utils/buildTools/convertShaders.d.ts.map +1 -0
  15. package/dist/utils/buildTools/convertShaders.js +37 -0
  16. package/dist/utils/buildTools/convertShaders.js.map +1 -0
  17. package/dist/utils/buildTools/shaderConverter.d.ts +2 -1
  18. package/dist/utils/buildTools/shaderConverter.d.ts.map +1 -1
  19. package/dist/utils/buildTools/shaderConverter.js +26 -1
  20. package/dist/utils/buildTools/shaderConverter.js.map +1 -1
  21. package/dist/utils/buildTools/watchShaders.js +2 -2
  22. package/dist/utils/buildTools/watchShaders.js.map +1 -1
  23. package/dist/version.d.ts +1 -1
  24. package/dist/version.js +1 -1
  25. package/package.json +1 -1
  26. package/src/serialization/importCustomBlockDefinition.ts +1 -26
  27. package/src/utils/buildTools/buildShaders.ts +1 -1
  28. package/src/utils/buildTools/convertGlslIntoBlock.ts +251 -0
  29. package/src/utils/buildTools/{convertShaderForHardcodedBlock.ts → convertGlslIntoShaderProgram.ts} +56 -35
  30. package/src/utils/buildTools/convertShaders.ts +42 -0
  31. package/src/utils/buildTools/shaderConverter.ts +28 -2
  32. package/src/utils/buildTools/watchShaders.ts +2 -2
  33. package/src/version.ts +1 -1
  34. package/dist/utils/buildTools/convertShaderForHardcodedBlock.d.ts +0 -13
  35. package/dist/utils/buildTools/convertShaderForHardcodedBlock.d.ts.map +0 -1
  36. package/dist/utils/buildTools/convertShaderForHardcodedBlock.js.map +0 -1
@@ -47,34 +47,10 @@ function importAnnotatedGlsl(fragmentShader) {
47
47
  // Calculate the input connection points
48
48
  const inputConnectionPoints = [];
49
49
  for (const uniform of fragmentShaderInfo.uniforms) {
50
- // Convert to ConnectionPointType
51
- let type;
52
- switch (uniform.type) {
53
- case "float":
54
- type = ConnectionPointType.Float;
55
- break;
56
- case "sampler2D":
57
- type = ConnectionPointType.Texture;
58
- break;
59
- case "vec3":
60
- type = ConnectionPointType.Color3;
61
- break;
62
- case "vec4":
63
- type = ConnectionPointType.Color4;
64
- break;
65
- case "bool":
66
- type = ConnectionPointType.Boolean;
67
- break;
68
- case "vec2":
69
- type = ConnectionPointType.Vector2;
70
- break;
71
- default:
72
- throw new Error(`Unsupported uniform type: '${uniform.type}'`);
73
- }
74
50
  // Add to input connection point list
75
51
  const inputConnectionPoint = {
76
52
  name: uniform.name,
77
- type,
53
+ type: uniform.type,
78
54
  autoBind: (_a = uniform.properties) === null || _a === void 0 ? void 0 : _a.autoBind,
79
55
  };
80
56
  if (inputConnectionPoint.type !== ConnectionPointType.Texture && ((_b = uniform.properties) === null || _b === void 0 ? void 0 : _b.default) !== undefined) {
@@ -1 +1 @@
1
- {"version":3,"file":"importCustomBlockDefinition.js","sourceRoot":"","sources":["../../src/serialization/importCustomBlockDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO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mBAAmB,CAAC,OAAO,CAAC;gBACnC,MAAM;YACV,KAAK,MAAM;gBACP,IAAI,GAAG,mBAAmB,CAAC,MAAM,CAAC;gBAClC,MAAM;YACV,KAAK,MAAM;gBACP,IAAI,GAAG,mBAAmB,CAAC,MAAM,CAAC;gBAClC,MAAM;YACV,KAAK,MAAM;gBACP,IAAI,GAAG,mBAAmB,CAAC,OAAO,CAAC;gBACnC,MAAM;YACV,KAAK,MAAM;gBACP,IAAI,GAAG,mBAAmB,CAAC,OAAO,CAAC;gBACnC,MAAM;YACV;gBACI,MAAM,IAAI,KAAK,CAAC,8BAA8B,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC;QACvE,CAAC;QAED,qCAAqC;QACrC,MAAM,oBAAoB,GAAqC;YAC3D,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,IAAI;YACJ,QAAQ,EAAE,MAAA,OAAO,CAAC,UAAU,0CAAE,QAA2B;SAC5D,CAAC;QACF,IAAI,oBAAoB,CAAC,IAAI,KAAK,mBAAmB,CAAC,OAAO,IAAI,CAAA,MAAA,OAAO,CAAC,UAAU,0CAAE,OAAO,MAAK,SAAS,EAAE,CAAC;YACzG,oBAAoB,CAAC,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC;QACnE,CAAC;QACD,qBAAqB,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACrD,CAAC;IAED,OAAO;QACH,MAAM,EAAE,uBAAuB;QAC/B,aAAa,EAAE,CAAC;QAChB,SAAS,EAAE,kBAAkB,CAAC,SAAS;QACvC,SAAS,EAAE,kBAAkB,CAAC,SAAS;QACvC,aAAa,EAAE;YACX,QAAQ,EAAE,kBAAkB,CAAC,UAAU;SAC1C;QACD,qBAAqB;QACrB,mBAAmB,EAAE,CAAC,CAAC,kBAAkB,CAAC,mBAAmB;KAChE,CAAC;AACN,CAAC"}
1
+ {"version":3,"file":"importCustomBlockDefinition.js","sourceRoot":"","sources":["../../src/serialization/importCustomBlockDef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IAAI;YAClB,QAAQ,EAAE,MAAA,OAAO,CAAC,UAAU,0CAAE,QAA2B;SAC5D,CAAC;QACF,IAAI,oBAAoB,CAAC,IAAI,KAAK,mBAAmB,CAAC,OAAO,IAAI,CAAA,MAAA,OAAO,CAAC,UAAU,0CAAE,OAAO,MAAK,SAAS,EAAE,CAAC;YACzG,oBAAoB,CAAC,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC;QACnE,CAAC;QACD,qBAAqB,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACrD,CAAC;IAED,OAAO;QACH,MAAM,EAAE,uBAAuB;QAC/B,aAAa,EAAE,CAAC;QAChB,SAAS,EAAE,kBAAkB,CAAC,SAAS;QACvC,SAAS,EAAE,kBAAkB,CAAC,SAAS;QACvC,aAAa,EAAE;YACX,QAAQ,EAAE,kBAAkB,CAAC,UAAU;SAC1C;QACD,qBAAqB;QACrB,mBAAmB,EAAE,CAAC,CAAC,kBAAkB,CAAC,mBAAmB;KAChE,CAAC;AACN,CAAC"}
@@ -4,7 +4,7 @@
4
4
  * @param importPath - The path to import the converted shaders
5
5
  * @example node buildShaders.js <shaderPath> <importPath>
6
6
  */
7
- import { convertShaders } from "./convertShaderForHardcodedBlock.js";
7
+ import { convertShaders } from "./convertShaders.js";
8
8
  const externalArguments = process.argv.slice(2);
9
9
  if (externalArguments.length >= 2 && externalArguments[0] && externalArguments[1]) {
10
10
  convertShaders(externalArguments[0], externalArguments[1]);
@@ -1 +1 @@
1
- {"version":3,"file":"buildShaders.js","sourceRoot":"","sources":["../../../src/utils/buildTools/buildShaders.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAErE,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"}
1
+ {"version":3,"file":"buildShaders.js","sourceRoot":"","sources":["../../../src/utils/buildTools/buildShaders.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,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"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Converts a single shader to a .ts file which exports a Smart Filter block
3
+ * @param fragmentShaderPath - The path to the fragment file for the shader
4
+ * @param importPath - The path to import the ShaderProgram type from
5
+ */
6
+ export declare function convertGlslIntoBlock(fragmentShaderPath: string, importPath: string): void;
7
+ //# sourceMappingURL=convertGlslIntoBlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertGlslIntoBlock.d.ts","sourceRoot":"","sources":["../../../src/utils/buildTools/convertGlslIntoBlock.ts"],"names":[],"mappings":"AAwHA;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,kBAAkB,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAiFzF"}
@@ -0,0 +1,217 @@
1
+ import * as fs from "fs";
2
+ import { extractShaderProgramFromGlsl } from "./convertGlslIntoShaderProgram.js";
3
+ import { ConnectionPointType } from "../../connection/connectionPointType.js";
4
+ const SHADER_PROGRAM = "@SHADER_PROGRAM@";
5
+ const BLOCK_NAME = "@BLOCK_NAME@";
6
+ const NAMESPACE = "@NAMESPACE@";
7
+ const SHADER_BINDING_PRIVATE_VARIABLES = "@SHADER_BINDING_PRIVATE_VARIABLES@";
8
+ const CAMEL_CASE_UNIFORM = "@CAMEL_CASE_UNIFORM@";
9
+ const CONNECTION_POINT_TYPE = "@CONNECTION_POINT_TYPE@";
10
+ const SHADER_BINDING_CTOR_DOCSTRING_PARAMS = "@SHADER_BINDING_CTOR_DOCSTRING_PARAMS@";
11
+ const SHADER_BINDING_CTOR_PARAMS = "@SHADER_CTOR_PARAMS@";
12
+ const SHADER_BINDING_CTOR = "@SHADER_BINDING_CTOR@";
13
+ const SHADER_BINDING_BIND = "@SHADER_BINDING_BIND@";
14
+ const BLOCK_INPUT_PROPERTIES = "@BLOCK_INPUT_PROPERTIES@";
15
+ const BLOCK_GET_SHADER_BINDING_VARS = "@BLOCK_SHADER_BINDING_BIND_VARS@";
16
+ const BLOCK_GET_SHADER_PARAM_LIST = "@BLOCK_GET_SHADER_PARAM_LIST@";
17
+ const EFFECT_SETTER = "@EFFECT_SETTER@";
18
+ const ShaderBindingPrivateVariablesTemplate = ` private readonly _${CAMEL_CASE_UNIFORM}: RuntimeData<ConnectionPointType.${CONNECTION_POINT_TYPE}>;`;
19
+ const ShaderBindingCtorDocstringParams = ` * @param ${CAMEL_CASE_UNIFORM} - The ${CAMEL_CASE_UNIFORM} runtime value`;
20
+ const ShaderBindingCtorParams = ` ${CAMEL_CASE_UNIFORM}: RuntimeData<ConnectionPointType.${CONNECTION_POINT_TYPE}>`;
21
+ const ShaderBindingCtor = ` this._${CAMEL_CASE_UNIFORM} = ${CAMEL_CASE_UNIFORM};`;
22
+ const ShaderBindingBind = ` effect.${EFFECT_SETTER}(this.getRemappedName(uniforms.${CAMEL_CASE_UNIFORM}), this._${CAMEL_CASE_UNIFORM}.value);`;
23
+ const BlockInputProperties = ` /**
24
+ * The ${CAMEL_CASE_UNIFORM} connection point.
25
+ */
26
+ public readonly ${CAMEL_CASE_UNIFORM} = this._registerInput(uniforms.${CAMEL_CASE_UNIFORM}, ConnectionPointType.${CONNECTION_POINT_TYPE});
27
+ `;
28
+ const BlockGetShaderBindingVars = ` const ${CAMEL_CASE_UNIFORM} = this._confirmRuntimeDataSupplied(this.${CAMEL_CASE_UNIFORM});`;
29
+ const FileTemplate = `/* eslint-disable prettier/prettier */
30
+ // ************************************************************
31
+ // Note: this file is auto-generated, do not modify it directly
32
+ // ************************************************************
33
+
34
+ // It was generated by convertGlslIntoBlock() from
35
+ // an annotated .glsl file. Modify the .glsl file to make changes
36
+ // to the block. This file will get overwritten when the build
37
+ // is run or during a watch when the .glsl file is updated.
38
+
39
+ import type { Effect } from "@babylonjs/core/Materials/effect";
40
+
41
+ import {
42
+ ShaderBinding,
43
+ type RuntimeData,
44
+ ConnectionPointType,
45
+ type SmartFilter,
46
+ ShaderBlock,
47
+ type ShaderProgram,
48
+ } from "@babylonjs/smart-filters";${SHADER_PROGRAM}
49
+ /**
50
+ * The shader binding for the ${BLOCK_NAME}, used by the runtime
51
+ */
52
+ class ${BLOCK_NAME}ShaderBinding extends ShaderBinding {
53
+ ${SHADER_BINDING_PRIVATE_VARIABLES}
54
+
55
+ /**
56
+ * Creates a new shader binding instance for the block.
57
+ ${SHADER_BINDING_CTOR_DOCSTRING_PARAMS}
58
+ */
59
+ constructor(
60
+ ${SHADER_BINDING_CTOR_PARAMS}
61
+ ) {
62
+ super();
63
+ ${SHADER_BINDING_CTOR}
64
+ }
65
+
66
+ /**
67
+ * Binds all the required data to the shader when rendering.
68
+ * @param effect - defines the effect to bind the data to
69
+ */
70
+ public override bind(effect: Effect): void {
71
+ ${SHADER_BINDING_BIND}
72
+ }
73
+ }
74
+
75
+ /**
76
+ * The implementation of the ${BLOCK_NAME}
77
+ */
78
+ export class ${BLOCK_NAME} extends ShaderBlock {
79
+ /**
80
+ * The class name of the block.
81
+ */
82
+ public static override ClassName = "${BLOCK_NAME}";
83
+
84
+ /**
85
+ * The namespace of the block.
86
+ */
87
+ public static override Namespace = "${NAMESPACE}";
88
+
89
+ ${BLOCK_INPUT_PROPERTIES}
90
+ /**
91
+ * The shader program (vertex and fragment code) to use to render the block
92
+ */
93
+ public static override ShaderCode = shaderProgram;
94
+
95
+ /**
96
+ * Instantiates a new ${BLOCK_NAME}.
97
+ * @param smartFilter - The smart filter this block belongs to
98
+ * @param name - The friendly name of the block
99
+ */
100
+ constructor(smartFilter: SmartFilter, name: string) {
101
+ super(smartFilter, name);
102
+ }
103
+
104
+ /**
105
+ * Get the class instance that binds all the required data to the shader (effect) when rendering.
106
+ * @returns The class instance that binds the data to the effect
107
+ */
108
+ public getShaderBinding(): ShaderBinding {
109
+ ${BLOCK_GET_SHADER_BINDING_VARS}
110
+
111
+ return new ${BLOCK_NAME}ShaderBinding(${BLOCK_GET_SHADER_PARAM_LIST});
112
+ }
113
+ }
114
+
115
+ `;
116
+ /**
117
+ * Converts a single shader to a .ts file which exports a Smart Filter block
118
+ * @param fragmentShaderPath - The path to the fragment file for the shader
119
+ * @param importPath - The path to import the ShaderProgram type from
120
+ */
121
+ export function convertGlslIntoBlock(fragmentShaderPath, importPath) {
122
+ const { shaderProgramCode, fragmentShaderInfo } = extractShaderProgramFromGlsl(fragmentShaderPath, importPath, false, false);
123
+ // Validation
124
+ if (!fragmentShaderInfo.blockType) {
125
+ throw new Error("The glsl file must contain a header comment with a smartFilterBlockType value");
126
+ }
127
+ // Generate shader binding private variables
128
+ const shaderBindingPrivateVariables = fragmentShaderInfo.uniforms.map((uniform) => {
129
+ return ShaderBindingPrivateVariablesTemplate.replace(CAMEL_CASE_UNIFORM, uniform.name).replace(CONNECTION_POINT_TYPE, getConnectionPointTypeString(uniform.type));
130
+ });
131
+ // Generate the shader binding constructor docstring params
132
+ const shaderBindingCtorDocstringParams = fragmentShaderInfo.uniforms.map((uniform) => {
133
+ return ShaderBindingCtorDocstringParams.replace(new RegExp(CAMEL_CASE_UNIFORM, "g"), uniform.name);
134
+ });
135
+ // Generate the shader binding constructor params
136
+ const shaderBindingCtorParams = fragmentShaderInfo.uniforms.map((uniform) => {
137
+ return ShaderBindingCtorParams.replace(CAMEL_CASE_UNIFORM, uniform.name).replace(CONNECTION_POINT_TYPE, getConnectionPointTypeString(uniform.type));
138
+ });
139
+ // Generate the shader binding constructor
140
+ const shaderBindingCtor = fragmentShaderInfo.uniforms.map((uniform) => {
141
+ return ShaderBindingCtor.replace(new RegExp(CAMEL_CASE_UNIFORM, "g"), uniform.name);
142
+ });
143
+ // Generate the shader binding bind
144
+ const shaderBindingBind = fragmentShaderInfo.uniforms.map((uniform) => {
145
+ return ShaderBindingBind.replace(new RegExp(CAMEL_CASE_UNIFORM, "g"), uniform.name).replace(EFFECT_SETTER, getEffectSetter(uniform.type));
146
+ });
147
+ // Generate the block input properties
148
+ const blockInputProperties = fragmentShaderInfo.uniforms.map((uniform) => {
149
+ return BlockInputProperties.replace(new RegExp(CAMEL_CASE_UNIFORM, "g"), uniform.name).replace(CONNECTION_POINT_TYPE, getConnectionPointTypeString(uniform.type));
150
+ });
151
+ // Generate the block get shader binding vars
152
+ const blockGetShaderBindingVars = fragmentShaderInfo.uniforms.map((uniform) => {
153
+ return BlockGetShaderBindingVars.replace(new RegExp(CAMEL_CASE_UNIFORM, "g"), uniform.name);
154
+ });
155
+ // Generate the block get shader param list
156
+ const blockGetShaderParamList = fragmentShaderInfo.uniforms.map((uniform) => {
157
+ return uniform.name;
158
+ });
159
+ // Generate final contents
160
+ const finalContents = FileTemplate.replace(SHADER_PROGRAM, shaderProgramCode)
161
+ .replace(new RegExp(BLOCK_NAME, "g"), fragmentShaderInfo.blockType)
162
+ .replace(NAMESPACE, fragmentShaderInfo.namespace || "Other")
163
+ .replace(SHADER_BINDING_PRIVATE_VARIABLES, shaderBindingPrivateVariables.join("\n"))
164
+ .replace(SHADER_BINDING_CTOR_DOCSTRING_PARAMS, shaderBindingCtorDocstringParams.join("\n"))
165
+ .replace(SHADER_BINDING_CTOR_PARAMS, shaderBindingCtorParams.join(",\n"))
166
+ .replace(SHADER_BINDING_CTOR, shaderBindingCtor.join("\n"))
167
+ .replace(SHADER_BINDING_BIND, shaderBindingBind.join("\n"))
168
+ .replace(BLOCK_INPUT_PROPERTIES, blockInputProperties.join("\n"))
169
+ .replace(BLOCK_GET_SHADER_BINDING_VARS, blockGetShaderBindingVars.join("\n"))
170
+ .replace(BLOCK_GET_SHADER_PARAM_LIST, blockGetShaderParamList.join(","));
171
+ // Write the block class TS file
172
+ const outputFullPathAndFileName = fragmentShaderPath.replace(".glsl", ".ts");
173
+ fs.writeFileSync(outputFullPathAndFileName, finalContents);
174
+ }
175
+ /**
176
+ * Get the string representation of a connection point type
177
+ * @param type - The connection point type
178
+ * @returns - The string representation of the connection point type
179
+ */
180
+ function getConnectionPointTypeString(type) {
181
+ switch (type) {
182
+ case ConnectionPointType.Float:
183
+ return "Float";
184
+ case ConnectionPointType.Texture:
185
+ return "Texture";
186
+ case ConnectionPointType.Color3:
187
+ return "Color3";
188
+ case ConnectionPointType.Color4:
189
+ return "Color4";
190
+ case ConnectionPointType.Vector2:
191
+ return "Vector2";
192
+ case ConnectionPointType.Boolean:
193
+ return "Boolean";
194
+ }
195
+ }
196
+ /**
197
+ * Get the effect setter for a connection point type
198
+ * @param type - The connection point type
199
+ * @returns - The effect setter for the connection point type
200
+ */
201
+ function getEffectSetter(type) {
202
+ switch (type) {
203
+ case ConnectionPointType.Float:
204
+ return "setFloat";
205
+ case ConnectionPointType.Texture:
206
+ return "setTexture";
207
+ case ConnectionPointType.Color3:
208
+ return "setColor3";
209
+ case ConnectionPointType.Color4:
210
+ return "setDirectColor4";
211
+ case ConnectionPointType.Vector2:
212
+ return "setVector2";
213
+ case ConnectionPointType.Boolean:
214
+ return "setBool";
215
+ }
216
+ }
217
+ //# sourceMappingURL=convertGlslIntoBlock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertGlslIntoBlock.js","sourceRoot":"","sources":["../../../src/utils/buildT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a ShaderProgram which can be imported by a hardcoded block
4
+ * @param fragmentShaderPath - The path to the fragment file for the shader
5
+ * @param importPath - The path to import the ShaderProgram type from
6
+ */
7
+ export declare function convertGlslIntoShaderProgram(fragmentShaderPath: string, importPath: string): void;
8
+ /**
9
+ * Extracts the shader program from a glsl file(s) and returns it as a string which can be written to a .ts file
10
+ * @param fragmentShaderPath - The path to the fragment file for the shader
11
+ * @param importPath - The path to import the ShaderProgram type from
12
+ * @param exportObjects - Whether to export the shaderProgram and uniforms objects
13
+ * @param includeImports - Whether to include the imports in the output
14
+ * @returns The string to write to the .ts file
15
+ */
16
+ export declare function extractShaderProgramFromGlsl(fragmentShaderPath: string, importPath: string, exportObjects: boolean, includeImports: boolean): {
17
+ /**
18
+ * The shader program code
19
+ */
20
+ shaderProgramCode: string;
21
+ /**
22
+ * The FragmentShaderInfo
23
+ */
24
+ fragmentShaderInfo: FragmentShaderInfo;
25
+ };
26
+ //# sourceMappingURL=convertGlslIntoShaderProgram.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertGlslIntoShaderProgram.d.ts","sourceRoot":"","sources":["../../../src/utils/buildTools/convertGlslIntoShaderProgram.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AA2DpF;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,kBAAkB,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAIjG;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CACxC,kBAAkB,EAAE,MAAM,EAC1B,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,OAAO,EACtB,cAAc,EAAE,OAAO,GACxB;IACC;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,kBAAkB,EAAE,kBAAkB,CAAC;CAC1C,CA8DA"}
@@ -1,5 +1,4 @@
1
1
  import * as fs from "fs";
2
- import * as path from "path";
3
2
  import { parseFragmentShader } from "./shaderConverter.js";
4
3
  const TYPE_IMPORT_PATH = "@TYPE_IMPORT_PATH@";
5
4
  const VERTEX_SHADER = "@VERTEX_SHADER@";
@@ -12,6 +11,8 @@ const FUNCTIONS = "@FUNCTIONS@";
12
11
  const FUNCTION_NAME = "@FUNCTION_NAME@";
13
12
  const FUNCTION_CODE = "@FUNCTION_CODE@";
14
13
  const UNIFORM_NAMES = "@UNIFORM_NAMES@";
14
+ const EXPORT = "@EXPORT_SHADER_PROGRAM@";
15
+ const IMPORTS = "@IMPORT@";
15
16
  const ConstsTemplate = `
16
17
  const: \`${CONSTS_VALUE}\`,`;
17
18
  const FunctionTemplate = `
@@ -24,12 +25,13 @@ ${FUNCTION_CODE}
24
25
  const CodeLinePrefix = " ";
25
26
  const UniformLinePrefix = " ";
26
27
  const ConstLinePrefix = " ";
27
- const ShaderTemplate = `import type { ShaderProgram } from "${TYPE_IMPORT_PATH}";
28
+ const ImportTemplate = `import type { ShaderProgram } from "${TYPE_IMPORT_PATH}";`;
29
+ const ShaderTemplate = `${IMPORTS}
28
30
 
29
31
  /**
30
32
  * The shader program for the block.
31
33
  */
32
- export const shaderProgram: ShaderProgram = {
34
+ ${EXPORT}const shaderProgram: ShaderProgram = {
33
35
  vertex: ${VERTEX_SHADER},
34
36
  fragment: {
35
37
  uniform: \`${UNIFORMS}\`,${CONSTS_PROPERTY}
@@ -44,21 +46,43 @@ export const shaderProgram: ShaderProgram = {
44
46
  * The uniform names for this shader, to be used in the shader binding so
45
47
  * that the names are always in sync.
46
48
  */
47
- export const uniforms = {
49
+ ${EXPORT}const uniforms = {
48
50
  ${UNIFORM_NAMES}
49
51
  };
50
52
  `;
51
53
  const UniformNameLinePrefix = " ";
52
54
  /**
53
- * Converts a single shader to a .ts file which can be imported by a hardcoded block
55
+ * Converts a single shader to a .ts file which exports a ShaderProgram which can be imported by a hardcoded block
54
56
  * @param fragmentShaderPath - The path to the fragment file for the shader
55
57
  * @param importPath - The path to import the ShaderProgram type from
56
58
  */
57
- export function convertShaderForHardcodedBlock(fragmentShaderPath, importPath) {
58
- console.log(`Processing fragment shader: ${fragmentShaderPath}`);
59
+ export function convertGlslIntoShaderProgram(fragmentShaderPath, importPath) {
60
+ const { shaderProgramCode } = extractShaderProgramFromGlsl(fragmentShaderPath, importPath, true, true);
61
+ const shaderFile = fragmentShaderPath.replace(".glsl", ".ts");
62
+ fs.writeFileSync(shaderFile, shaderProgramCode);
63
+ }
64
+ /**
65
+ * Extracts the shader program from a glsl file(s) and returns it as a string which can be written to a .ts file
66
+ * @param fragmentShaderPath - The path to the fragment file for the shader
67
+ * @param importPath - The path to import the ShaderProgram type from
68
+ * @param exportObjects - Whether to export the shaderProgram and uniforms objects
69
+ * @param includeImports - Whether to include the imports in the output
70
+ * @returns The string to write to the .ts file
71
+ */
72
+ export function extractShaderProgramFromGlsl(fragmentShaderPath, importPath, exportObjects, includeImports) {
59
73
  // See if there is a corresponding vertex shader
60
74
  let vertexShader = undefined;
61
- const vertexShaderPath = fragmentShaderPath.replace(".fragment.glsl", ".vertex.glsl");
75
+ let extensionToFind;
76
+ if (fragmentShaderPath.endsWith(".block.glsl")) {
77
+ extensionToFind = ".block.glsl";
78
+ }
79
+ else if (fragmentShaderPath.endsWith(".fragment.glsl")) {
80
+ extensionToFind = ".fragment.glsl";
81
+ }
82
+ else {
83
+ throw new Error("The shader file must end with .fragment.glsl or .block.glsl");
84
+ }
85
+ const vertexShaderPath = fragmentShaderPath.replace(extensionToFind, ".vertex.glsl");
62
86
  if (fs.existsSync(vertexShaderPath)) {
63
87
  vertexShader = fs.readFileSync(vertexShaderPath, "utf8");
64
88
  }
@@ -68,38 +92,27 @@ export function convertShaderForHardcodedBlock(fragmentShaderPath, importPath) {
68
92
  // Read the fragment shader
69
93
  const fragmentShader = fs.readFileSync(fragmentShaderPath, "utf8");
70
94
  const fragmentShaderInfo = parseFragmentShader(fragmentShader);
71
- // Write the shader TS file
72
- const shaderFile = fragmentShaderPath.replace(".fragment.glsl", ".shader.ts");
95
+ // Generate the shader program code
73
96
  const functionsSection = [];
74
97
  for (const shaderFunction of fragmentShaderInfo.shaderCode.functions) {
75
98
  functionsSection.push(FunctionTemplate.replace(FUNCTION_NAME, shaderFunction.name).replace(FUNCTION_CODE, addLinePrefixes(shaderFunction.code, CodeLinePrefix)));
76
99
  }
100
+ const imports = includeImports ? ImportTemplate.replace(TYPE_IMPORT_PATH, importPath) : "";
77
101
  const finalContents = ShaderTemplate.replace(VERTEX_SHADER, vertexShader ? `\`${vertexShader}\`` : "undefined")
78
- .replace(TYPE_IMPORT_PATH, importPath)
102
+ .replace(IMPORTS, imports)
79
103
  .replace(UNIFORMS, "\n" + addLinePrefixes(fragmentShaderInfo.shaderCode.uniform || "", UniformLinePrefix))
80
104
  .replace(MAIN_FUNCTION_NAME, fragmentShaderInfo.shaderCode.mainFunctionName)
81
- .replace(MAIN_INPUT_NAME, fragmentShaderInfo.shaderCode.mainInputTexture || '""')
105
+ .replace(MAIN_INPUT_NAME, fragmentShaderInfo.shaderCode.mainInputTexture || "")
82
106
  .replace(CONSTS_PROPERTY, fragmentShaderInfo.shaderCode.const
83
107
  ? ConstsTemplate.replace(CONSTS_VALUE, addLinePrefixes(fragmentShaderInfo.shaderCode.const, ConstLinePrefix))
84
108
  : "")
85
109
  .replace(FUNCTIONS, functionsSection.join(""))
86
- .replace(UNIFORM_NAMES, addLinePrefixes(fragmentShaderInfo.uniforms.map((u) => `${u.name}: "${u.name}",`).join("\n"), UniformNameLinePrefix));
87
- fs.writeFileSync(shaderFile, finalContents);
88
- }
89
- /**
90
- * Converts .fragment.glsl and vertex.glsl file pairs into .shader.ts files which export a ShaderProgram object.
91
- * @param shaderPath - The path to the .glsl files to convert.
92
- * @param importPath - The path to import the ShaderProgram type from.
93
- */
94
- export function convertShaders(shaderPath, importPath) {
95
- // Get all files in the path
96
- const allFiles = fs.readdirSync(shaderPath, { withFileTypes: true, recursive: true });
97
- // Find all fragment shaders (excluding the template)
98
- const fragmentShaderFiles = allFiles.filter((file) => file.isFile() && file.name.endsWith(".fragment.glsl") && !file.name.endsWith("template.fragment.glsl"));
99
- // Convert all shaders
100
- for (const fragmentShaderFile of fragmentShaderFiles) {
101
- convertShaderForHardcodedBlock(path.join(fragmentShaderFile.path, fragmentShaderFile.name), importPath);
102
- }
110
+ .replace(UNIFORM_NAMES, addLinePrefixes(fragmentShaderInfo.uniforms.map((u) => `${u.name}: "${u.name}",`).join("\n"), UniformNameLinePrefix))
111
+ .replace(new RegExp(EXPORT, "g"), exportObjects ? "export " : "");
112
+ return {
113
+ shaderProgramCode: finalContents,
114
+ fragmentShaderInfo,
115
+ };
103
116
  }
104
117
  /**
105
118
  * Prefixes each line in the input
@@ -113,4 +126,4 @@ function addLinePrefixes(input, prefix) {
113
126
  .map((line) => prefix + line)
114
127
  .join("\n");
115
128
  }
116
- //# sourceMappingURL=convertShaderForHardcodedBlock.js.map
129
+ //# sourceMappingURL=convertGlslIntoShaderProgram.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertGlslIntoShaderProgram.js","sourceRoot":"","sources":["../../../src/utils/buildTools/convertGlslIntoShaderProgram.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,mBAAmB,EAA2B,MAAM,sBAAsB,CAAC;AAEpF,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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AC5B,IAAI,CAAC,IAAI,CAAC,CAAC;AACpB,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Converts all GLSL files in a path into blocks for use in the build system.
3
+ * @param shaderPath - The path to the .glsl files to convert.
4
+ * @param importPath - The path to import the ShaderProgram type from.
5
+ */
6
+ export declare function convertShaders(shaderPath: string, importPath: string): void;
7
+ /**
8
+ * Converts a single GLSL file into a block class or a ShaderProgram for use in the build system.
9
+ * @param fullPathAndFileName - The full path and file name of the .glsl file to convert.
10
+ * @param importPath - The path to import the ShaderProgram type from.
11
+ */
12
+ export declare function convertShader(fullPathAndFileName: string, importPath: string): void;
13
+ //# sourceMappingURL=convertShaders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertShaders.d.ts","sourceRoot":"","sources":["../../../src/utils/buildTools/convertShaders.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,QAcpE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,mBAAmB,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAUnF"}
@@ -0,0 +1,37 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ import { convertGlslIntoShaderProgram } from "./convertGlslIntoShaderProgram.js";
4
+ import { convertGlslIntoBlock } from "./convertGlslIntoBlock.js";
5
+ /**
6
+ * Converts all GLSL files in a path into blocks for use in the build system.
7
+ * @param shaderPath - The path to the .glsl files to convert.
8
+ * @param importPath - The path to import the ShaderProgram type from.
9
+ */
10
+ export function convertShaders(shaderPath, importPath) {
11
+ // Get all files in the path
12
+ const allFiles = fs.readdirSync(shaderPath, { withFileTypes: true, recursive: true });
13
+ // Find all shaders (files with .fragment.glsl or .block.glsl extensions)
14
+ const shaderFiles = allFiles.filter((file) => file.isFile() && (file.name.endsWith(".fragment.glsl") || file.name.endsWith(".block.glsl")));
15
+ // Convert all shaders
16
+ for (const shaderFile of shaderFiles) {
17
+ const fullPathAndFileName = path.join(shaderFile.path, shaderFile.name);
18
+ convertShader(fullPathAndFileName, importPath);
19
+ }
20
+ }
21
+ /**
22
+ * Converts a single GLSL file into a block class or a ShaderProgram for use in the build system.
23
+ * @param fullPathAndFileName - The full path and file name of the .glsl file to convert.
24
+ * @param importPath - The path to import the ShaderProgram type from.
25
+ */
26
+ export function convertShader(fullPathAndFileName, importPath) {
27
+ console.log(`\nProcessing shader: ${fullPathAndFileName}`);
28
+ if (fullPathAndFileName.endsWith(".fragment.glsl")) {
29
+ console.log("Generating a .ts file that exports a ShaderProgram.");
30
+ convertGlslIntoShaderProgram(fullPathAndFileName, importPath);
31
+ }
32
+ else if (fullPathAndFileName.endsWith(".block.glsl")) {
33
+ console.log("Generating a .ts file that exports the block as a class.");
34
+ convertGlslIntoBlock(fullPathAndFileName, importPath);
35
+ }
36
+ }
37
+ //# sourceMappingURL=convertShaders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertShaders.js","sourceRoot":"","sources":["../../../src/utils/buildTools/convertShaders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,UAAkB,EAAE,UAAkB;IACjE,4BAA4B;IAC5B,MAAM,QAAQ,GAAG,EAAE,CAAC,WAAW,CAAC,UAAU,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAEtF,yEAAyE;IACzE,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAC/B,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CACzG,CAAC;IAEF,sBAAsB;IACtB,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACnC,MAAM,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;QACxE,aAAa,CAAC,mBAAmB,EAAE,UAAU,CAAC,CAAC;IACnD,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,mBAA2B,EAAE,UAAkB;IACzE,OAAO,CAAC,GAAG,CAAC,wBAAwB,mBAAmB,EAAE,CAAC,CAAC;IAE3D,IAAI,mBAAmB,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACjD,OAAO,CAAC,GAAG,CAAC,qDAAqD,CAAC,CAAC;QACnE,4BAA4B,CAAC,mBAAmB,EAAE,UAAU,CAAC,CAAC;IAClE,CAAC;SAAM,IAAI,mBAAmB,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;QACrD,OAAO,CAAC,GAAG,CAAC,0DAA0D,CAAC,CAAC;QACxE,oBAAoB,CAAC,mBAAmB,EAAE,UAAU,CAAC,CAAC;IAC1D,CAAC;AACL,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import type { Nullable } from "@babylonjs/core/types";
2
2
  import type { ShaderCode } from "./shaderCode.types";
3
+ import { ConnectionPointType } from "../../connection/connectionPointType.js";
3
4
  /**
4
5
  * Describes the supported metadata properties for a uniform
5
6
  */
@@ -25,7 +26,7 @@ export type UniformMetadata = {
25
26
  /**
26
27
  * The type string of the uniform
27
28
  */
28
- type: string;
29
+ type: ConnectionPointType;
29
30
  /**
30
31
  * Optional properties of the uniform
31
32
  */
@@ -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;AACtD,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,oBAAoB,CAAC;AAIrE;;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,MAAM,CAAC;IAEb;;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;IACH,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAE5B;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B;;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,CAwG9E;AAsMD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAE7D"}
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;AACtD,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAI9E;;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;IACH,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAE5B;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B;;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,CAiI9E;AAsMD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAE7D"}
@@ -1,3 +1,4 @@
1
+ import { ConnectionPointType } from "../../connection/connectionPointType.js";
1
2
  const GetFunctionNamesRegEx = /\S*\w+\s+(\w+)\s*\(/g;
2
3
  /**
3
4
  * Parses a fragment shader
@@ -31,9 +32,33 @@ export function parseFragmentShader(fragmentShader) {
31
32
  if (!uniformName) {
32
33
  throw new Error(`Uniforms must have a name: '${uniformLine}'`);
33
34
  }
35
+ // Convert to ConnectionPointType
36
+ let type;
37
+ switch (uniformTypeString) {
38
+ case "float":
39
+ type = ConnectionPointType.Float;
40
+ break;
41
+ case "sampler2D":
42
+ type = ConnectionPointType.Texture;
43
+ break;
44
+ case "vec3":
45
+ type = ConnectionPointType.Color3;
46
+ break;
47
+ case "vec4":
48
+ type = ConnectionPointType.Color4;
49
+ break;
50
+ case "bool":
51
+ type = ConnectionPointType.Boolean;
52
+ break;
53
+ case "vec2":
54
+ type = ConnectionPointType.Vector2;
55
+ break;
56
+ default:
57
+ throw new Error(`Unsupported uniform type: '${uniformTypeString}'`);
58
+ }
34
59
  uniforms.push({
35
60
  name: uniformName,
36
- type: uniformTypeString,
61
+ type,
37
62
  properties: annotationJSON ? JSON.parse(annotationJSON.replace("//", "").trim()) : undefined,
38
63
  });
39
64
  if (annotationJSON) {