UNPKG

xgpu

Version:

XGPU is an extendable library for WebGPU that provides a higher-level, easy-to-use interface for building rendering engines or processing numeric data. It handles automatic data binding, buffer alignment, variable declarations in shaders, and more. XGPU i

1,508 lines (1,502 loc) 233 kB
var ke = Object.defineProperty; var je = (v, t, e) => t in v ? ke(v, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : v[t] = e; var u = (v, t, e) => je(v, typeof t != "symbol" ? t + "" : t, e); import { mat4 as ee, vec3 as ae } from "gl-matrix"; class b { static __initDebug() { let t; for (let e in this.vertexDebug) t = this.vertexDebug[e](), this.vertexDebug[e].isArray = !!t.isArray, this.vertexDebug[e].len = t.len, this.vertexDebug[e].primitiveType = t.primitiveType, this.vertexDebug[e].type = t.type, this.vertexDebug[e].__debug = !0; } } u(b, "vertexInputs", { vertexIndex: { builtin: "@builtin(vertex_index)", type: "u32" }, instanceIndex: { builtin: "@builtin(instance_index)", type: "u32" } }), u(b, "vertexOutputs", { position: { builtin: "@builtin(position)", type: "vec4<f32>" }, Float: { type: "f32", vsOut: !0 }, Vec2: { type: "vec2<f32>", vsOut: !0 }, Vec3: { type: "vec3<f32>", vsOut: !0 }, Vec4: { type: "vec4<f32>", vsOut: !0 } }), u(b, "vertexDebug", { Float: (t = 0, e = 0) => ({ vertexId: e, instanceId: t, type: "f32", __debug: !0 }), Vec2: (t = 0, e = 0) => ({ vertexId: e, instanceId: t, type: "vec2<f32>", __debug: !0 }), Vec3: (t = 0, e = 0) => ({ vertexId: e, instanceId: t, type: "vec3<f32>", __debug: !0 }), Vec4: (t = 0, e = 0) => ({ vertexId: e, instanceId: t, type: "vec4<f32>", __debug: !0 }), Int: (t = 0, e = 0) => ({ vertexId: e, instanceId: t, type: "i32", __debug: !0 }), IVec2: (t = 0, e = 0) => ({ vertexId: e, instanceId: t, type: "vec2<i32>", __debug: !0 }), IVec3: (t = 0, e = 0) => ({ vertexId: e, instanceId: t, type: "vec3<i32>", __debug: !0 }), IVec4: (t = 0, e = 0) => ({ vertexId: e, instanceId: t, type: "vec4<i32>", __debug: !0 }), Uint: (t = 0, e = 0) => ({ vertexId: e, instanceId: t, type: "uint", __debug: !0 }), UVec2: (t = 0, e = 0) => ({ vertexId: e, instanceId: t, type: "vec2<u32>", __debug: !0 }), UVec3: (t = 0, e = 0) => ({ vertexId: e, instanceId: t, type: "vec3<u32>", __debug: !0 }), UVec4: (t = 0, e = 0) => ({ vertexId: e, instanceId: t, type: "vec4<uf32>", __debug: !0 }), Matrix3x3: (t = 0, e = 0) => ({ vertexId: e, instanceId: t, type: "mat3x3<f32>", __debug: !0 }), Matrix4x4: (t = 0, e = 0) => ({ vertexId: e, instanceId: t, type: "mat4x4<f32>", __debug: !0 }), Vec4Array: (t = 1, e = 0, s = 0) => ({ vertexId: s, instanceId: e, type: "array<vec4<f32>," + t + ">", __debug: !0, len: t, isArray: !0, primitiveType: "f32" }), IVec4Array: (t = 1, e = 0, s = 0) => ({ vertexId: s, instanceId: e, type: "array<vec4<i32>," + t + ">", __debug: !0, len: t, isArray: !0, primitiveType: "i32" }), UVec4Array: (t = 1, e = 0, s = 0) => ({ vertexId: s, instanceId: e, type: "array<vec4<u32>," + t + ">", __debug: !0, len: t, isArray: !0, primitiveType: "u32" }), Matrix4x4Array: (t = 1, e = 0, s = 0) => ({ vertexId: s, instanceId: e, type: "array<mat4x4<f32>," + t + ">", __debug: !0, len: t, isArray: !0, primitiveType: "mat4" }) }), //---- u(b, "fragmentInputs", { frontFacing: { builtin: "@builtin(front_facing)", type: "bool" }, fragDepth: { builtin: "@builtin(frag_depth)", type: "f32" }, sampleIndex: { builtin: "@builtin(sample_index)", type: "u32" }, sampleMask: { builtin: "@builtin(sample_mask)", type: "u32" } }), u(b, "fragmentOutputs", { color: { builtin: "@location(0)", type: "vec4<f32>" } }), //---- u(b, "computeInputs", { localInvocationId: { builtin: "@builtin(local_invocation_id)", type: "vec3<u32>" }, localInvocationIndex: { builtin: "@builtin(local_invocation_index)", type: "u32" }, globalInvocationId: { builtin: "@builtin(global_invocation_id)", type: "vec3<u32>" }, workgroupId: { builtin: "@builtin(workgroup_id)", type: "vec3<u32>" }, numWorkgroup: { builtin: "@builtin(num_workgroup)", type: "vec3<u32>" } }), u(b, "computeOutputs", { result: { builtin: "@location(0)", type: "???" } }); class ie { //https://www.w3.org/TR/WGSL/#alignment-and-size constructor(t) { u(this, "_isVector", !1); u(this, "_isMatrix", !1); u(this, "_isArray", !1); u(this, "_vecType", 1); u(this, "_arrayLen"); u(this, "_primitive"); u(this, "_matrixColumns", 1); u(this, "_matrixRows", 1); u(this, "_alignOf"); u(this, "_sizeOf"); u(this, "_dataType"); u(this, "_rawType"); u(this, "getPrimitiveDataType", (t, e) => { switch (t.substring(e, e + 1)) { case "u": this._primitive = "u32", this._alignOf = 4, this._sizeOf = 4; break; case "i": this._primitive = "i32", this._alignOf = 4, this._sizeOf = 4; break; case "f": const i = t.substring(e, e + 3); if (i === "f32" || i == "flo") this._primitive = "f32", this._alignOf = 4, this._sizeOf = 4; else if (i === "f16") this._primitive = i, this._alignOf = 2, this._sizeOf = 2; else throw new Error("invalid primitive type"); break; case "v": if (t.substring(e, e + 3) === "vec") { this._isVector = !0; const n = Number(t.substring(e + 3, e + 4)); if (n >= 2 && n <= 4) this._vecType = n, this.getPrimitiveDataType(t, e + 5), this._primitive === "f16" ? (this._sizeOf = 2 * n, n === 2 ? this._alignOf = 4 : n === 3 ? this._alignOf = 8 : n === 4 && (this._alignOf = 8)) : (this._sizeOf = 4 * n, n === 2 ? this._alignOf = 8 : n === 3 ? this._alignOf = 16 : n === 4 && (this._alignOf = 16)); else throw new Error("invalid vec type"); } else throw new Error("invalid primitive type"); break; case "a": if (t.substring(e, e + 5) === "array") { this._isArray = !0; let n = 15; if (t.substring(6, 7) === "m" ? n = 17 : (t.substring(6, 7) === "f" || t.substring(6, 7) === "i" || t.substring(6, 7) === "u") && (n = 9), t.substring(e + n, e + n + 1) === ",") { let r; n++; for (let a = 1; a < 16; a++) { let o = t.substring(n, n + a); if (isNaN(Number(o))) break; r = o; } this._arrayLen = Number(r); } this.getPrimitiveDataType(t, e + 6), this.arrayLength && (this._sizeOf *= this._arrayLen); } else throw new Error("invalid primitive type"); break; case "m": if (t.substring(e, e + 3) === "mat") { this._isMatrix = !0; const n = Number(t.substring(e + 3, e + 4)), r = Number(t.substring(e + 5, e + 6)); if (!isNaN(n) && !isNaN(r)) if (this._matrixColumns = n, this._matrixRows = r, this.getPrimitiveDataType(t, e + 7), this._primitive === "f16" || this._primitive === "f32") this.getMatrixBytesStructure(n, r, this._primitive); else throw new Error("Matrix values must be f32 or f16"); else throw new Error("invalid matrix type"); } else throw new Error("invalid primitive type"); break; } }); this._rawType = t, t = this.renameDataType(t), this._dataType = t, this.getPrimitiveDataType(t, 0); } renameDataType(t) { switch (t) { case "float": return "f32"; case "vec2": return "vec2<f32>"; case "vec3": return "vec3<f32>"; case "vec4": return "vec4<f32>"; case "int": return "i32"; case "ivec2": return "vec2<i32>"; case "ivec3": return "vec3<i32>"; case "ivec4": return "vec4<i32>"; case "uint": return "u32"; case "uvec2": return "vec2<u32>"; case "uvec3": return "vec3<u32>"; case "uvec4": return "vec4<u32>"; case "mat4": return "mat4x4<f32>"; case "mat3": return "mat3x3<f32>"; case "mat2": return "mat2x2<f32>"; case "mat2d": return "mat2w3<f32>"; } return t; } get isPrimitive() { return !this._isVector && !this._isArray && !this._isMatrix; } get isVector() { return this._isVector && !this._isArray && !this._isMatrix; } get isMatrix() { return this._isMatrix && !this._isArray; } get isArray() { return this._isArray; } get isMatrixOfVectors() { return this._isMatrix && this._isVector; } get isArrayOfVectors() { return this._isArray && this._isVector; } get isArrayOfMatrixs() { return this._isArray && this._isMatrix; } get vectorType() { return this._vecType; } get arrayLength() { return this._arrayLen; } get matrixColumns() { return this._matrixColumns; } get matrixRows() { return this._matrixRows; } get primitive() { return this._primitive; } get nbValues() { return this._matrixColumns * this._matrixRows * this._vecType * (this._arrayLen ? this._arrayLen : 1); } get byteSize() { return this._sizeOf; } get byteAlign() { return this._alignOf; } set byteAlign(t) { this._alignOf = t; } get dataType() { return this._dataType; } get rawType() { return this._rawType; } get byteValue() { return this._primitive === "f16" ? 2 : 4; } getMatrixBytesStructure(t, e, s) { const i = "mat" + t + "x" + e + "<" + s + ">", r = { "mat2x2<f32>": [8, 16], "mat2x2<f16>": [4, 8], "mat3x2<f32>": [8, 24], "mat3x2<f16>": [4, 12], "mat4x2<f32>": [8, 32], "mat4x2<f16>": [4, 16], "mat2x3<f32>": [16, 32], "mat2x3<f16>": [8, 16], "mat3x3<f32>": [16, 48], "mat3x3<f16>": [8, 24], "mat4x3<f32>": [16, 64], "mat4x3<f16>": [8, 32], "mat2x4<f32>": [16, 32], "mat2x4<f16>": [8, 16], "mat3x4<f32>": [16, 48], "mat3x4<f16>": [8, 24], "mat4x4<f32>": [16, 64], "mat4x4<f16>": [8, 32] }[i]; this._alignOf = r[0], this._sizeOf = r[1]; } } const $ = class $ extends Float32Array { constructor(e, s, i = !1) { super(s); //public uniform: Uniform; u(this, "name"); u(this, "type"); u(this, "startId", 0); u(this, "globalStartId", 0); u(this, "onChange"); u(this, "_mustBeTransfered", !0); //public mustBeTransfered:boolean = true; u(this, "uniformBuffer"); u(this, "propertyNames"); u(this, "createVariableInsideMain", !1); u(this, "className"); //--------- EVENT DISPATCHER CLASS (that I can't extends because we already extends Float32Array)---- u(this, "eventListeners", {}); this.type = new ie(e), this.createVariableInsideMain = i, this.className = this.constructor.name; } get mustBeTransfered() { return this._mustBeTransfered; } set mustBeTransfered(e) { e != this._mustBeTransfered && (e ? this.dispatchEvent($.ON_CHANGE) : this.dispatchEvent($.ON_CHANGED), this._mustBeTransfered = e); } clone() { const e = new $(this.type.rawType, this, this.createVariableInsideMain); return e.propertyNames = this.propertyNames, e.className = this.className, e.name = this.name, e.startId = this.startId, e; } initStruct(e, s = !1) { if (this.type.isArray || this.type.isMatrix) throw new Error("initStruct doesn't accept array or matrix"); this.propertyNames = e, this.createVariableInsideMain = s; } createStruct() { let e = "struct " + this.className + ` { `; for (let s = 0; s < this.propertyNames.length; s++) e += " " + this.propertyNames[s] + `:f32, `; return e += `} `, e; } set(e, s) { super.set(e, s), this.mustBeTransfered = !0; } createVariable(e, s) { if (!this.createVariableInsideMain) return ""; s || (s = this.name); let i = this.className; return i === "Float" && (i = "f32"), i === "Vec2" && (i = "vec2<f32>"), i === "Vec3" && (i = "vec3<f32>"), i === "Vec4" && (i = "vec4<f32>"), " var " + s + ":" + i + " = " + e + "." + s + `; `; } update() { } updateStartIdFromParentToChildren() { } addEventListener(e, s) { this.eventListeners[e] || (this.eventListeners[e] = []), this.eventListeners[e].push(s); } removeEventListener(e, s) { if (this.eventListeners[e]) { const i = this.eventListeners[e].indexOf(s); i != -1 && this.eventListeners[e].splice(i, 1); } } dispatchEvent(e, s) { this.eventListeners[e] && this.eventListeners[e].forEach((i) => { i(this, s); }); } //--------------------------------------------------------------------------------------------- get definition() { return { type: this.constructor.name, values: this, name: this.name }; } }; u($, "ON_CHANGE", "ON_CHANGE"), u($, "ON_CHANGED", "ON_CHANGED"); let O = $; const q = class q extends Int32Array { constructor(e, s, i = !1) { super(s); u(this, "name"); u(this, "type"); u(this, "startId", 0); u(this, "globalStartId", 0); u(this, "onChange"); u(this, "_mustBeTransfered", !0); u(this, "uniformBuffer"); u(this, "propertyNames"); u(this, "createVariableInsideMain", !1); u(this, "className"); //--------- EVENT DISPATCHER CLASS (that I can't extends because we already extends Int32Array)---- u(this, "eventListeners", {}); this.type = new ie(e), this.createVariableInsideMain = i, this.className = this.constructor.name; } get mustBeTransfered() { return this._mustBeTransfered; } set mustBeTransfered(e) { e != this._mustBeTransfered && (e ? this.dispatchEvent(q.ON_CHANGE) : this.dispatchEvent(q.ON_CHANGED), this._mustBeTransfered = e); } clone() { return new q(this.type.rawType, this, this.createVariableInsideMain); } initStruct(e, s = !1) { if (this.type.isArray || this.type.isMatrix) throw new Error("initStruct doesn't accept array or matrix"); this.propertyNames = e, this.createVariableInsideMain = s; } createStruct() { let e = "struct " + this.constructor.name + ` { `; for (let s = 0; s < this.propertyNames.length; s++) e += " " + this.propertyNames[s] + `:i32, `; return e += `} `, e; } updateStartIdFromParentToChildren() { } createVariable(e) { if (!this.createVariableInsideMain) return ""; let s = this.className; return s === "Int" && (s = "i32"), s === "IVec2" && (s = "vec2<i32>"), s === "IVec3" && (s = "vec3<i32>"), s === "IVec4" && (s = "vec4<i32>"), " var " + this.name + ":" + s + " = " + e + "." + this.name + `; `; } /* public feedbackVertexId: number = 0; public feedbackInstanceId: number = 0; public setFeedback(vertexId: number, instanceId: number): PrimitiveIntUniform { this.feedbackVertexId = vertexId; this.feedbackInstanceId = instanceId; return this; }*/ update() { } addEventListener(e, s) { this.eventListeners[e] || (this.eventListeners[e] = []), this.eventListeners[e].push(s); } removeEventListener(e, s) { if (this.eventListeners[e]) { const i = this.eventListeners[e].indexOf(s); i != -1 && this.eventListeners[e].splice(i, 1); } } dispatchEvent(e, s) { this.eventListeners[e] && this.eventListeners[e].forEach((i) => { i(this, s); }); } //--------------------------------------------------------------------------------------------- get definition() { return { type: this.constructor.name, values: this, name: this.name }; } }; u(q, "ON_CHANGE", "ON_CHANGE"), u(q, "ON_CHANGED", "ON_CHANGED"); let P = q; const X = class X extends Uint32Array { constructor(e, s, i = !1) { super(s); u(this, "name"); u(this, "type"); u(this, "startId", 0); u(this, "globalStartId", 0); u(this, "uniformBuffer"); u(this, "onChange"); u(this, "_mustBeTransfered", !0); u(this, "propertyNames"); u(this, "createVariableInsideMain", !1); u(this, "className"); //--------- EVENT DISPATCHER CLASS (that I can't extends because we already extends Uint32Array)---- u(this, "eventListeners", {}); this.type = new ie(e), this.createVariableInsideMain = i, this.className = this.constructor.name; } get mustBeTransfered() { return this._mustBeTransfered; } set mustBeTransfered(e) { e != this._mustBeTransfered && (e ? this.dispatchEvent(X.ON_CHANGE) : this.dispatchEvent(X.ON_CHANGED), this._mustBeTransfered = e); } clone() { return new X(this.type.rawType, this, this.createVariableInsideMain); } initStruct(e, s = !1) { if (this.type.isArray || this.type.isMatrix) throw new Error("initStruct doesn't accept array or matrix"); this.propertyNames = e, this.createVariableInsideMain = s; } createStruct() { let e = "struct " + this.constructor.name + ` { `; for (let s = 0; s < this.propertyNames.length; s++) e += " " + this.propertyNames[s] + `:u32, `; return e += `} `, e; } updateStartIdFromParentToChildren() { } createVariable(e) { if (!this.createVariableInsideMain) return ""; let s = this.className; return s === "Uint" && (s = "u32"), s === "UVec2" && (s = "vec2<u32>"), s === "UVec3" && (s = "vec3<u32>"), s === "UVec4" && (s = "vec4<u32>"), " var " + this.name + ":" + s + " = " + e + "." + this.name + `; `; } /* public feedbackVertexId: number = 0; public feedbackInstanceId: number = 0; public setFeedback(vertexId: number, instanceId: number): PrimitiveUintUniform { this.feedbackVertexId = vertexId; this.feedbackInstanceId = instanceId; return this; } */ update() { } addEventListener(e, s) { this.eventListeners[e] || (this.eventListeners[e] = []), this.eventListeners[e].push(s); } removeEventListener(e, s) { if (this.eventListeners[e]) { const i = this.eventListeners[e].indexOf(s); i != -1 && this.eventListeners[e].splice(i, 1); } } dispatchEvent(e, s) { this.eventListeners[e] && this.eventListeners[e].forEach((i) => { i(this, s); }); } //--------------------------------------------------------------------------------------------- get definition() { return { type: this.constructor.name, values: this, name: this.name }; } }; u(X, "ON_CHANGE", "ON_CHANGE"), u(X, "ON_CHANGED", "ON_CHANGED"); let D = X; class Ve extends O { constructor(t = 0, e = !1) { super("f32", [t], e); } set x(t) { this[0] = t, this.mustBeTransfered = !0; } get x() { return this[0]; } } class He extends O { constructor(t = 0, e = 0, s = !1) { super("vec2<f32>", [t, e], s); } set x(t) { this[0] = t, this.mustBeTransfered = !0; } set y(t) { this[1] = t, this.mustBeTransfered = !0; } get x() { return this[0]; } get y() { return this[1]; } } class Ye extends O { constructor(t = 0, e = 0, s = 0, i = !1) { super("vec3<f32>", [t, e, s], i); } set x(t) { this[0] = t, this.mustBeTransfered = !0; } set y(t) { this[1] = t, this.mustBeTransfered = !0; } set z(t) { this[2] = t, this.mustBeTransfered = !0; } get x() { return this[0]; } get y() { return this[1]; } get z() { return this[2]; } } class Ce extends O { constructor(t = 0, e = 0, s = 0, i = 0, n = !1) { super("vec4<f32>", [t, e, s, i], n); } set x(t) { this[0] = t, this.mustBeTransfered = !0; } set y(t) { this[1] = t, this.mustBeTransfered = !0; } set z(t) { this[2] = t, this.mustBeTransfered = !0; } set w(t) { this[3] = t, this.mustBeTransfered = !0; } get x() { return this[0]; } get y() { return this[1]; } get z() { return this[2]; } get w() { return this[3]; } } class We extends P { constructor(t = 0, e = !1) { super("i32", [t], e); } set x(t) { this[0] = t, this.mustBeTransfered = !0; } get x() { return this[0]; } } class $e extends P { constructor(t = 0, e = 0, s = !1) { super("vec2<i32>", [t, e], s); } set x(t) { this[0] = t, this.mustBeTransfered = !0; } set y(t) { this[1] = t, this.mustBeTransfered = !0; } get x() { return this[0]; } get y() { return this[1]; } } class qe extends P { constructor(t = 0, e = 0, s = 0, i = !1) { super("vec3<i32>", [t, e, s], i); } set x(t) { this[0] = t, this.mustBeTransfered = !0; } set y(t) { this[1] = t, this.mustBeTransfered = !0; } set z(t) { this[2] = t, this.mustBeTransfered = !0; } get x() { return this[0]; } get y() { return this[1]; } get z() { return this[2]; } } class Me extends P { constructor(t = 0, e = 0, s = 0, i = 0, n = !1) { super("vec4<i32>", [t, e, s, i], n); } set x(t) { this[0] = t, this.mustBeTransfered = !0; } set y(t) { this[1] = t, this.mustBeTransfered = !0; } set z(t) { this[2] = t, this.mustBeTransfered = !0; } set w(t) { this[3] = t, this.mustBeTransfered = !0; } get x() { return this[0]; } get y() { return this[1]; } get z() { return this[2]; } get w() { return this[3]; } } class Xe extends D { constructor(t = 0, e = !1) { super("u32", [t], e); } set x(t) { this[0] = t, this.mustBeTransfered = !0; } get x() { return this[0]; } } class Qe extends D { constructor(t = 0, e = 0, s = !1) { super("vec2<u32>", [t, e], s); } set x(t) { this[0] = t, this.mustBeTransfered = !0; } set y(t) { this[1] = t, this.mustBeTransfered = !0; } get x() { return this[0]; } get y() { return this[1]; } } class Ze extends D { constructor(t = 0, e = 0, s = 0, i = !1) { super("vec3<u32>", [t, e, s], i); } set x(t) { this[0] = t, this.mustBeTransfered = !0; } set y(t) { this[1] = t, this.mustBeTransfered = !0; } set z(t) { this[2] = t, this.mustBeTransfered = !0; } get x() { return this[0]; } get y() { return this[1]; } get z() { return this[2]; } } class Le extends D { constructor(t = 0, e = 0, s = 0, i = 0, n = !1) { super("vec4<u32>", [t, e, s, i], n); } set x(t) { this[0] = t, this.mustBeTransfered = !0; } set y(t) { this[1] = t, this.mustBeTransfered = !0; } set z(t) { this[2] = t, this.mustBeTransfered = !0; } set w(t) { this[3] = t, this.mustBeTransfered = !0; } get x() { return this[0]; } get y() { return this[1]; } get z() { return this[2]; } get w() { return this[3]; } } class Fe extends O { constructor(e) { let s; if (typeof e != "number") s = e; else { s = []; for (let a = 0; a < e; a++) s[a] = new Ce(); } const i = s.length; let n = new Float32Array(i * 4); for (let a = 0; a < i; a++) n.set(s[a], a * 4); let r = "array<vec4<f32>," + s.length + ">"; super("array<vec4<f32>," + s.length + ">", n); u(this, "vec4Array"); this.className = r, this.vec4Array = s; for (let a = 0; a < this.vec4Array.length; a++) this.vec4Array[a].addEventListener("ON_CHANGE", () => { this.mustBeTransfered = !0, this.set(this.vec4Array[a], a * 4), this.dispatchEvent("ON_CHANGE"); }); } updateStartIdFromParentToChildren() { for (let e = 0; e < this.vec4Array.length; e++) this.vec4Array[e].globalStartId = this.globalStartId + this.vec4Array[e].startId; } update() { let e = !1, s; for (let i = 0; i < this.vec4Array.length; i++) s = this.vec4Array[i], s.name || (s.name = this.name + "#" + i), s.update(), s.mustBeTransfered && (e = !0, this.set(s, i * 4), s.mustBeTransfered = !1); this.mustBeTransfered != e && (this.mustBeTransfered = e); } } class Je extends P { constructor(e) { let s; if (typeof e != "number") s = e; else { s = []; for (let a = 0; a < e; a++) s[a] = new Me(); } const i = s.length; let n = new Int32Array(i * 4); for (let a = 0; a < i; a++) n.set(s[a], a * 4); let r = "array<vec4<i32>," + s.length + ">"; super(r, n); u(this, "ivec4Array"); this.className = r, this.ivec4Array = s; for (let a = 0; a < this.ivec4Array.length; a++) this.ivec4Array[a].addEventListener("ON_CHANGE", () => { this.mustBeTransfered = !0, this.set(this.ivec4Array[a], a * 4), this.dispatchEvent("ON_CHANGE"); }); } updateStartIdFromParentToChildren() { for (let e = 0; e < this.ivec4Array.length; e++) this.ivec4Array[e].globalStartId = this.globalStartId + this.ivec4Array[e].startId; } update() { let e = !1, s; for (let i = 0; i < this.ivec4Array.length; i++) s = this.ivec4Array[i], s.update(), s.mustBeTransfered && (e = !0, this.set(s, i * 4), s.mustBeTransfered = !1); this.mustBeTransfered = e; } } class Ke extends D { constructor(e) { let s; if (typeof e != "number") s = e; else { s = []; for (let a = 0; a < e; a++) s[a] = new Le(); } const i = s.length; let n = new Uint32Array(i * 4); for (let a = 0; a < i; a++) n.set(s[a], a * 4); let r = "array<vec4<u32>," + s.length + ">"; super(r, n); u(this, "uvec4Array"); this.className = r, this.uvec4Array = s; for (let a = 0; a < this.uvec4Array.length; a++) this.uvec4Array[a].addEventListener("ON_CHANGE", () => { this.mustBeTransfered = !0, this.set(this.uvec4Array[a], a * 4), this.dispatchEvent("ON_CHANGE"); }); } updateStartIdFromParentToChildren() { for (let e = 0; e < this.uvec4Array.length; e++) this.uvec4Array[e].globalStartId = this.globalStartId + this.uvec4Array[e].startId; } update() { let e = !1, s; for (let i = 0; i < this.uvec4Array.length; i++) s = this.uvec4Array[i], s.update(), s.mustBeTransfered && (e = !0, this.set(s, i * 4), s.mustBeTransfered = !1); this.mustBeTransfered = e; } } class et extends O { constructor(e = null) { const s = !!e; e || (e = new Float32Array([ 1, 0, 0, 0, 1, 0, 0, 0, 1 ])); super("mat3x3<f32>", e); u(this, "disableUpdate"); this.className = "mat3x3<f32>", this.disableUpdate = s; } } class ye extends O { constructor(e = null) { const s = !!e; e || (e = new Float32Array([ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ])); super("mat4x4<f32>", e); u(this, "_x", 0); u(this, "_y", 0); u(this, "_z", 0); u(this, "_sx", 1); u(this, "_sy", 1); u(this, "_sz", 1); u(this, "_rx", 0); u(this, "_ry", 0); u(this, "_rz", 0); u(this, "disableUpdate"); this.className = "mat4x4<f32>", this.disableUpdate = s; } clone() { const e = new ye(this); return e.x = this.x, e.y = this.y, e.z = this.z, e.rotationX = this.rotationX, e.rotationY = this.rotationY, e.rotationZ = this.rotationZ, e.scaleX = this.scaleX, e.scaleY = this.scaleY, e.scaleZ = this.scaleZ, e.disableUpdate = this.disableUpdate, e; } get x() { return this._x; } get y() { return this._y; } get z() { return this._z; } get rotationX() { return this._rx; } get rotationY() { return this._ry; } get rotationZ() { return this._rz; } get scaleX() { return this._sx; } get scaleY() { return this._sy; } get scaleZ() { return this._sz; } set x(e) { e !== this._x && (this.mustBeTransfered = !0, this._x = e); } set y(e) { e !== this._y && (this.mustBeTransfered = !0, this._y = e); } set z(e) { e !== this._z && (this.mustBeTransfered = !0, this._z = e); } set rotationX(e) { e !== this._rx && (this.mustBeTransfered = !0, this._rx = e); } set rotationY(e) { e !== this._ry && (this.mustBeTransfered = !0, this._ry = e); } set rotationZ(e) { e !== this._rz && (this.mustBeTransfered = !0, this._rz = e); } set scaleX(e) { e !== this._sx && (this.mustBeTransfered = !0, this._sx = e); } set scaleY(e) { e !== this._sy && (this.mustBeTransfered = !0, this._sy = e); } set scaleZ(e) { e !== this._sz && (this.mustBeTransfered = !0, this._sz = e); } set scaleXYZ(e) { this.scaleX = this.scaleY = this.scaleZ = e, this.mustBeTransfered = !0; } setMatrix(e) { this.set(e), this.mustBeTransfered = !0; } update() { this.disableUpdate || this.mustBeTransfered && (ee.identity(this), ee.rotate(this, this, this._rx, ae.fromValues(1, 0, 0)), ee.rotate(this, this, this._ry, ae.fromValues(0, 1, 0)), ee.rotate(this, this, this._rz, ae.fromValues(0, 0, 1)), ee.translate(this, this, ae.fromValues(this._x, this._y, this._z)), ee.scale(this, this, ae.fromValues(this._sx, this._sy, this._sz))); } } class tt extends O { constructor(e) { let s; if (typeof e != "number") s = e; else { s = []; for (let r = 0; r < e; r++) s[r] = new ye(); } const i = s.length; let n = new Float32Array(i * 16); for (let r = 0; r < i; r++) n.set(s[r], r * 16); super("array<mat4x4<f32>," + i + ">", n); u(this, "matrixs"); this.matrixs = s, this.mustBeTransfered = !0, this.className = "array<mat4x4<f32>," + i + ">"; for (let r = 0; r < this.matrixs.length; r++) this.matrixs[r].addEventListener("ON_CHANGE", () => { this.mustBeTransfered = !0, this.set(this.matrixs[r], r * 16), this.dispatchEvent("ON_CHANGE"); }); } updateStartIdFromParentToChildren() { for (let e = 0; e < this.matrixs.length; e++) this.matrixs[e].globalStartId = this.globalStartId + this.matrixs[e].startId; } update() { let e = !1, s; for (let i = 0; i < this.matrixs.length; i++) s = this.matrixs[i], s.update(), s.mustBeTransfered && (e = !0, this.set(s, i * 16), s.mustBeTransfered = !1); this.mustBeTransfered = e; } } class Z { constructor() { u(this, "eventListeners", {}); } addEventListener(t, e, s = !1) { this.eventListeners[t] || (this.eventListeners[t] = []), s && (e.removeAfter = !0), this.eventListeners[t].push(e); } removeEventListener(t, e) { if (this.eventListeners[t]) { const s = this.eventListeners[t].indexOf(e); s != -1 && this.eventListeners[t].splice(s, 1); } } clearEvents(t) { this.addEventListener[t] = []; } hasEventListener(t) { return !!this.eventListeners[t]; } dispatchEvent(t, e) { this.eventListeners[t] && [...this.eventListeners[t]].forEach((i) => { i(e), i.removeAfter && this.removeEventListener(t, i); }); } } const se = class se extends Z { constructor(e, s = !1) { super(); u(this, "groups"); u(this, "startId", 0); u(this, "globalStartId", 0); u(this, "createVariableInsideMain", !1); u(this, "name"); u(this, "mustBeTransfered", !0); u(this, "mustDispatchChangeEvent", !1); u(this, "buffer", null); this.groups = e; let i = 0; e.forEach((n) => { n.startId = i, n.startId = i, i += n.arrayStride, n.addEventListener(re.ON_CHANGE, () => { this.mustBeTransfered = !0, this.dispatchEvent(se.ON_CHANGE); }); }), this.createVariableInsideMain = s; } get uniformBuffer() { return this.buffer; } set uniformBuffer(e) { this.buffer = e, e && (e.mustBeTransfered = !0); for (let s = 0; s < this.groups.length; s++) this.groups[s].uniformBuffer = e; } updateStartIdFromParentToChildren() { for (let e = 0; e < this.groups.length; e++) this.groups[e].globalStartId = this.globalStartId + this.groups[e].startId, this.groups[e].updateStartIdFromParentToChildren(); } clone() { const e = [...this.groups]; for (let i = 0; i < e.length; i++) e[i] = e[i].clone(); const s = new se(e, this.createVariableInsideMain); return s.startId = this.startId, s.name = this.name, s; } get type() { return { nbComponent: this.arrayStride, isUniformGroup: !0, isArray: !0 }; } copyIntoDataView(e, s) { let i; for (let n = 0; n < this.groups.length; n++) i = this.groups[n], i.mustBeTransfered && (i.copyIntoDataView(e, s), i.mustBeTransfered = !1), s += i.arrayStride; this.mustBeTransfered = !1; } getStructName(e) { return e ? e[0].toUpperCase() + e.slice(1) : null; } getVarName(e) { return e ? e[0].toLowerCase() + e.slice(1) : null; } createVariable(e) { if (!this.createVariableInsideMain) return ""; const s = this.getVarName(this.name); return " var " + s + ":array<" + this.getStructName(this.name) + "," + this.length + "> = " + this.getVarName(e) + "." + s + `; `; } update(e) { for (let s = 0; s < this.groups.length; s++) this.groups[s].update(e); } forceUpdate() { for (let e = 0; e < this.groups.length; e++) this.groups[e].forceUpdate(); } getElementById(e) { return this.groups[e]; } get length() { return this.groups.length; } get arrayStride() { return this.groups[0].arrayStride * this.groups.length; } get isArray() { return !0; } get isUniformGroup() { return !0; } get definition() { const e = []; for (let s = 0; s < this.groups.length; s++) e[s] = this.groups[s].definition; return { type: "UniformGroupArray", groups: e, name: this.name }; } }; u(se, "ON_CHANGE", "ON_CHANGE"), u(se, "ON_CHANGED", "ON_CHANGED"); let U = se; const N = class N extends Z { constructor(e, s, i = !1) { super(); u(this, "unstackedItems", {}); u(this, "items"); u(this, "itemNames", []); u(this, "arrayStride", 0); u(this, "startId", 0); u(this, "globalStartId", 0); u(this, "createVariableInsideMain", !1); u(this, "mustBeTransfered", !0); u(this, "mustDispatchChangeEvent", !1); /* protected _mustBeTransfered: boolean = true; public get mustBeTransfered():boolean{return this._mustBeTransfered}; public set mustBeTransfered(b:boolean){ if(b != this._mustBeTransfered){ console.warn(b) if(b) this.dispatchEvent(UniformGroup.ON_CHANGE); else this.dispatchEvent(UniformGroup.ON_CHANGED); this._mustBeTransfered = b; } }*/ u(this, "_name"); u(this, "wgsl"); u(this, "wgslStructNames", []); /*an uniformGroup can be used multiple times, not necessarily in an array so we must so we must store the name we use when we build the 'struct' in order to write a 'struct' for every properties while being sure we don't have two sames structs*/ u(this, "datas"); u(this, "dataView"); u(this, "buffer", null); u(this, "usedAsUniformBuffer"); u(this, "transfertWholeBuffer", !1); u(this, "existingStrucName"); this.usedAsUniformBuffer = i, this.createVariableInsideMain = !!s; let n; for (let r in e) { if (n = e[r], !(n instanceof O || n instanceof P || n instanceof D || n instanceof N || n instanceof U)) throw new Error("UniformGroup accept only PrimitiveFloatUniform, PrimitiveIntUniform, PrimitiveUintUniform, UniformGroup and UniformGroupArray"); this.add(r, n, this.createVariableInsideMain, !1); } this.items = this.stackItems(e); } //private debug:boolean = false; set(e) { this.datas = e, this.dataView = new DataView(e, 0, e.byteLength), this.updateItemFromDataView(this.dataView, 0), this.mustBeTransfered = !0; } get uniformBuffer() { return this.buffer; } set uniformBuffer(e) { this.buffer = e, e && (e.mustBeTransfered = !0); for (let s = 0; s < this.items.length; s++) this.items[s].uniformBuffer = e; } destroy() { console.warn("uniformGroup.destroy"), this.unstackedItems = {}, this.items = [], this.itemNames = [], this.arrayStride = 0, this.startId = 0, this.mustBeTransfered = !0, this.datas = null, this.buffer = null, this.wgsl = null, this._name = null, this.uniformBuffer = null; } get name() { return this._name; } set name(e) { this._name = this.getStructName(e); } clone(e) { const s = { ...this.unstackedItems }; if (e) for (let n = 0; n < e.length; n++) s[e[n]] = s[e[n]].clone(); else for (let n in s) s[n] = s[n].clone(); const i = new N(s); return i.name = this.name, i; } remove(e) { for (let s = 0; s < this.items.length; s++) if (this.items[s].name === e) { const i = this.items.splice(s, 1)[0]; return this.itemNames.splice(this.itemNames.indexOf(e), 1), i; } return null; } add(e, s, i = !1, n = !0) { s.uniformBuffer = this.uniformBuffer, s.name = e, s.mustBeTransfered = !0, (this.uniformBuffer && this.uniformBuffer.descriptor.useLocalVariable || i) && (s.createVariableInsideMain = !0), (this.usedAsUniformBuffer == !1 || s instanceof N || s instanceof U || s instanceof Fe) && s.addEventListener("ON_CHANGE", () => { this.mustBeTransfered = !0, this.dispatchEvent("ON_CHANGE"); }); const r = !!this.unstackedItems[e]; if (this.unstackedItems[e] = s, r) { for (let a = 0; a < this.items.length; a++) if (this.items[a].name === e) { this.items[a] = s; break; } } else this.itemNames.push(e); return n && (this.items = this.stackItems(this.unstackedItems)), this.wgsl && (this.wgsl = this.getStruct(this.name)), this.uniformBuffer && (this.uniformBuffer.mustBeTransfered = !0), s; } getElementByName(e) { for (let s = 0; s < this.items.length; s++) if (this.items[s].name === e) return this.items[s]; return null; } getStructName(e) { return e ? e[0].toUpperCase() + e.slice(1) : null; } getVarName(e) { return e ? e[0].toLowerCase() + e.slice(1) : null; } createVariable(e) { if (!this.createVariableInsideMain) return ""; const s = this.getVarName(this.name); return " var " + s + ":" + this.getStructName(this.name) + " = " + this.getVarName(e) + "." + s + `; `; } updateStack() { this.items = this.stackItems(this.items); } forceUpdate() { for (let e = 0; e < this.items.length; e++) (this.items[e] instanceof N || this.items[e] instanceof U) && this.items[e].forceUpdate(), this.items[e].mustBeTransfered = !0; } get type() { return { nbComponent: this.arrayStride, isUniformGroup: !0, isArray: !1 }; } setDatas(e, s = null, i = 0) { s || (s = this.dataView); const n = e.startId + i, r = e.type; switch (r.primitive) { case "f32": for (let o = 0; o < r.nbValues; o++) s.setFloat32((n + o) * 4, e[o], !0); break; case "i32": for (let o = 0; o < r.nbValues; o++) s.setInt32((n + o) * 4, e[o], !0); break; case "u32": for (let o = 0; o < r.nbValues; o++) s.setUint32((n + o) * 4, e[o], !0); break; } this.usedAsUniformBuffer == !1 && e.type.isArray == !1 && (e.mustBeTransfered = !1); } updateItemFromDataView(e, s) { let i; for (let n = 0; n < this.items.length; n++) if (i = this.items[n], i instanceof N || i instanceof U) i.updateItemFromDataView(e, s + i.startId); else { const r = i.startId + s, a = i.type, o = a.primitive, f = a.nbValues; if (o == "f32") for (let l = 0; l < f; l++) i[l] = e.getFloat32((r + l) * 4, !0); else if (o == "i32") for (let l = 0; l < f; l++) i[l] = e.getInt32((r + l) * 4, !0); else if (o == "u32") for (let l = 0; l < f; l++) i[l] = e.getUint32((r + l) * 4, !0); i.mustBeTransfered = !0; } } copyIntoDataView(e, s) { let i, n = !1; for (let r = 0; r < this.items.length; r++) i = this.items[r], i.mustBeTransfered && (n = !0, i instanceof N || i instanceof U ? i.copyIntoDataView(e, s + i.startId) : this.setDatas(i, e, s), this.usedAsUniformBuffer == !1 && (i.mustBeTransfered = !1)); this.mustBeTransfered = n, n && this.dispatchEvent(N.ON_CHANGE); } async update(e) { let s = !1, i; for (let n = 0; n < this.items.length; n++) i = this.items[n], i.type.isUniformGroup ? i.update(e) : i.update(), i.mustBeTransfered && (s = !0, i instanceof N || i instanceof U ? i.copyIntoDataView(this.dataView, i.startId) : (this.setDatas(i), i.mustBeTransfered = !1, (this.transfertWholeBuffer == !1 || i.type.isArray) && this.transfertWholeBuffer == !1 && g.device.queue.writeBuffer( e, i.globalStartId * Float32Array.BYTES_PER_ELEMENT, //item.startId * Float32Array.BYTES_PER_ELEMENT, i.buffer, i.byteOffset, i.byteLength ))); /*this.usedAsUniformBuffer &&*/ this.transfertWholeBuffer && s && g.device.queue.writeBuffer( e, 0, this.datas, 0, this.arrayStride * 4 ); } getStruct(e) { this.name = e; let s = "struct " + this.name + ` { `, i, n = "", r = "", a = "", o; for (let f = 0; f < this.items.length; f++) if (i = this.items[f], i instanceof N || i instanceof U) i instanceof N ? (i.wgsl || (o = i.getStruct(i.name), n += o.localVariables + ` `, i.wgslStructNames.push(i.name)), r.indexOf(i.wgsl.struct) === -1 && (r = i.wgsl.struct + r), s += " " + this.getVarName(i.name) + ":" + i.name + `, `, n += i.createVariable(this.name)) : (e = i.name, i.groups[0].wgsl || (o = i.groups[0].getStruct(i.name), n += o.localVariables), r.indexOf(i.groups[0].wgsl.struct) === -1 && (r = i.groups[0].wgsl.struct + r), s += "@size(" + i.length * i.groups[0].arrayStride * 4 + ") " + e + ":array<" + this.getStructName(e) + "," + i.length + `>, `, n += i.createVariable(this.name)); else { let l = i; if (l.propertyNames) { let h = l.createStruct(); a.indexOf(h) === -1 && r.indexOf(h) === -1 && s.indexOf(h) === -1 && (a += h + ` `), s += " @size(16) " + l.name + ":" + l.className + `, `; } else if (l.type.isArray) if (l.type.isArrayOfMatrixs) { let h = l.type.matrixColumns, c = 4; l.type.matrixRows === 2 && (c = 2), s += " @size(" + l.type.arrayLength * h * c * 4 + ") " + l.name + ":" + l.type.dataType + `, `; } else s += " @size(" + l.type.arrayLength * 16 + ") " + l.name + ":" + l.type.dataType + `, `; else s += " " + l.name + ":" + l.type.dataType + `, `; l.createVariableInsideMain && (n += l.createVariable(this.getVarName(this.name))); } return s += `} `, s = a + r + s, this.wgsl = { struct: s, localVariables: n }, this.wgsl; } stackItems(e) { const s = []; let i = 1; var n = [], r = [], a = []; let o, f, l, h = 0; for (let d in e) if (o = e[d], o.name = d, f = o.type, o instanceof U) o.startId = h, h += o.arrayStride, s.push(o); else if (f.isArray) o.startId = h, f.isArrayOfMatrixs ? h += f.matrixRows * 4 * f.arrayLength : h += 4 * f.arrayLength, i = 4, s.push(o); else if (f.isMatrix) { o.startId = h; let p = f.matrixColumns, y = 4; f.matrixRows === 2 && (y = 2), h += p * y, i = y, s.push(o); } else f.isUniformGroup ? f.nbComponent >= 4 && (i = 4, o.startId = h, h += Math.ceil(f.nbComponent / 4) * 4, s.push(o)) : o.propertyNames ? (i = 4, o.startId = h, h += 4, s.push(o)) : (l = f.nbValues, l === 1 ? n.push(o) : l === 2 ? (i < 2 && (i = 2), r.push(o)) : l === 3 ? (i = 4, a.push(o)) : l >= 4 && (i = 4, o.startId = h, h += l, s.push(o))); const c = () => { if (o = a.shift(), o.startId = h, h += 3, s.push(o), n.length) { const d = n.shift(); d.startId = h, s.push(d); } h++; }; let m = a.length; for (let d = 0; d < m; d++) c(); m = r.length; for (let d = 0; d < m; d++) o = r.shift(), o.startId = h, h += 2, s.push(o); m = n.length; for (let d = 0; d < m; d++) o = n.shift(), o.startId = h, h++, s.push(o); if (h % i !== 0 && (h += i - h % i), h % 4 != 0) { const d = 4 - h % 4; if (!this.usedAsUniformBuffer) for (let p = 0; p < d; p++) { const y = new Ve(0); y.startId = h, y.name = "padding_" + p, s.push(y), this.itemNames.push(y.name); } h += d; } return this.arrayStride = h, this.datas = new ArrayBuffer(h * 4), this.dataView = new DataView(this.datas, 0, this.datas.byteLength), this.items = s, this.copyIntoDataView(this.dataView, 0), s; } updateStartIdFromParentToChildren() { let e; for (let s = 0; s < this.items.length; s++) e = this.items[s], e.globalStartId = this.globalStartId + e.startId, (e instanceof N || e instanceof U || e.type.isArray) && e.updateStartIdFromParentToChildren(); } get definition() { const e = {}; for (let s = 0; s < this.items.length; s++) e[this.itemNames[s]] = this.items[s].definition; return { type: "UniformGroup", values: this.datas, items: e, name: this.name }; } /* protected createTypedArrayBuffer(result: any) { let datas: Float32Array | Int32Array | Uint32Array; if (this.primitiveType === "f32") datas = new Float32Array(this.arrayStride); else if (this.primitiveType === "i32") datas = new Int32Array(this.arrayStride); else if (this.primitiveType === "u32") datas = new Uint32Array(this.arrayStride); //console.log("uniform type = ", this._primitiveType) let o: any; for (let i = 0; i < result.length; i++) { o = result[i]; if (o instanceof UniformGroup || o instanceof UniformGroupArray) { if (o instanceof UniformGroup) { datas.set(o.datas as Float32Array | Int32Array | Uint32Array, o.startId); } else { let start = o.startId; for (let j = 0; j < o.length; j++) { datas.set(o.groups[j].datas as Float32Array | Int32Array | Uint32Array, start); start += o.groups[j].arrayStride; } } } else { datas.set(o, o.startId) } } this.datas = datas; } */ }; u(N, "ON_CHANGE", "ON_CHANGE"), u(N, "ON_CHANGED", "ON_CHANGED"); let re = N; const M = class M { static build(t, e, s) { let i = {}, n = /* @__PURE__ */ new Set(), r = [{ id: e, names: s }]; for (; r.length > 0; ) { let a = r.pop(), o = a.id, f = a.names; if (!n.has(o)) { for (let l in t) { let h = t[l], c = o | h, m = [...new Set(f.concat(l))]; c in i ? i[c] = [...new Set(i[c].concat(m))] : (i[c] = m, r.push({ id: c, names: m })); } n.add(o); } } return i; } static resolve(t, e) { return e in t ? t[e].join("|") : "undefined"; } static async getResult(t) { return new Promise((e) => { const s = this.build(t, 0, []); setTimeout(() => { e(s); }, 1); }); } static async init() { return this._instance || new M(), new Promise(async (t) => { this.ready || (this.bufferUsage = await this.getResult(GPUBufferUsage), this.shaderStage = await this.getResult(GPUShaderStage), this.textureUsage = await this.getResult(GPUTextureUsage), this.ready = !0), t(); }); } constructor() { if (M._instance) throw new Error("WebGPUProperties is not instanciable"); M._instance = this; } static getTextureUsageById(t) { return this.resolve(this.textureUsage, t); } static getBufferUsageById(t) { return this.resolve(this.bufferUsage, t); } static getShaderStageById(t) { return this.resolve(this.shaderStage, t); } }; u(M, "ready", !1), u(M, "textureUsage"), u(M, "bufferUsage"), u(M, "shaderStage"), u(M, "_instance"); let te = M; const A = class A { static get ready() { return this._ready; } static debugUsage(t) { return te.getBufferUsageById(t); } static debugTextureUsage(t) { return te.getTextureUsageById(t); } static debugShaderStage(t) { return te.getShaderStageById(t); } constructor() { throw new Error("GPU is static and can't be instanciated"); } static loseDevice() { this.losingDevice = !0, this.gpuDevice.destroy(); } static clear() { this.gpuDevice.destroy(); } static get loseDeviceRecently() { return (/* @__PURE__ */ new Date()).getTime() - this.deviceLostTime <= 3e3; } static getTransferableUniforms(t) { let e, s; const i = [], n = {}; for (let r in t) if (s = t[r], s.name = r, e = s.definition, n[r] = e, e.type == "UniformGroup") i.includes(e.values) == !1 && i.push(e.values); else if (e.type == "UniformGroupArray") { let a = e.groups; for (let o = 0; o < a.length; o++) i.includes(a[o].values) == !1 && i.push(a[o].values); } else e.values.buffer && i.includes(e.values.buffer) == !1 && i.push(e.values.buffer); return { items: n, transferables: i }; } /* export type TransferableUniforms = { items:{name:string,type:string,values:any,groups?:any,items?:any}; transferables:ArrayBuffer[] } */ static parseTransferableUniform(t) { const e = (r) => { if (r.type == "Float") return new Ve(r.values[0]); if (r.type == "Vec2") return new He(r.values[0], r.values[1]); if (r.type == "Vec3") return new Ye(r.values[0], r.values[1], r.values[2]); if (r.type == "Vec4") return new Ce(r.values[0], r.values[1], r.values[2], r.values[3]); if (r.type == "Int") return new We(r.values[0]); if (r.type == "IVec2") return new $e(r.values[0], r.values[1]); if (r.type == "IVec3") return new qe(r.values[0], r.values[1], r.values[2]); if (r.type == "IVec4") return new Me(r.values[0], r.values[1], r.values[2], r.values[3]); if (r.type == "Uint") return new Xe(r.values[0]); if (r.type == "UVec2") return new Qe(r.values[0], r.values[1]); if (r.type == "UVec3") return new Ze(r.values[0], r.values[1], r.values[2]); if (r.type == "UVec4") return new Le(r.values[0], r.values[1], r.values[2]