@margoengine/inspector 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +623 -3
  4. package/dist/animation.d.ts +53 -0
  5. package/dist/animation.js +234 -0
  6. package/dist/color-D6qetPCJ.js +10 -0
  7. package/dist/color.d.ts +4 -0
  8. package/dist/debug-geometry-D61TEkP9.js +61 -0
  9. package/dist/debug-geometry.d.ts +15 -0
  10. package/dist/edit-state-Dm3G17js.js +4 -0
  11. package/dist/edit-state.d.ts +3 -0
  12. package/dist/edit.d.ts +105 -0
  13. package/dist/edit.js +379 -0
  14. package/dist/errors-D8rc8kzg.js +7 -0
  15. package/dist/frame-panel.d.ts +16 -0
  16. package/dist/frame.d.ts +264 -0
  17. package/dist/frame.js +881 -0
  18. package/dist/gizmo.d.ts +49 -0
  19. package/dist/gizmo.js +131 -0
  20. package/dist/gl.d.ts +89 -0
  21. package/dist/gl.js +284 -0
  22. package/dist/history.d.ts +65 -0
  23. package/dist/history.js +66 -0
  24. package/dist/index.d.ts +122 -0
  25. package/dist/index.js +490 -0
  26. package/dist/mesh-debug.d.ts +115 -0
  27. package/dist/mesh-debug.js +501 -0
  28. package/dist/mesh-source-BSQA_1GQ.js +31 -0
  29. package/dist/packages.d.ts +98 -0
  30. package/dist/packages.js +337 -0
  31. package/dist/remote-relay.d.ts +25 -0
  32. package/dist/remote-relay.js +64 -0
  33. package/dist/remote.d.ts +175 -0
  34. package/dist/remote.js +349 -0
  35. package/dist/resources.d.ts +30 -0
  36. package/dist/resources.js +42 -0
  37. package/dist/shaders.d.ts +122 -0
  38. package/dist/shaders.js +285 -0
  39. package/dist/snapshot.d.ts +47 -0
  40. package/dist/snapshot.js +90 -0
  41. package/dist/textures.d.ts +127 -0
  42. package/dist/textures.js +380 -0
  43. package/dist/tools.d.ts +101 -0
  44. package/dist/tools.js +220 -0
  45. package/dist/tweak.d.ts +86 -0
  46. package/dist/tweak.js +291 -0
  47. package/dist/view-rect-CTC0iGjf.js +23 -0
  48. package/dist/visibility-7_j5J9Nv.js +7 -0
  49. package/package.json +149 -6
package/dist/edit.js ADDED
@@ -0,0 +1,379 @@
1
+ // @margo/core-built 0.1.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+ const s=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
+ import { t as e } from "./errors-D8rc8kzg.js";
5
+ import { r as t } from "./mesh-source-BSQA_1GQ.js";
6
+ import { n, t as r } from "./edit-state-Dm3G17js.js";
7
+ import { t as i } from "./visibility-7_j5J9Nv.js";
8
+ import { Geometry as a, PbrMaterial as o, engineRuntime as __margoRuntime, meshRuntime as c } from "@margoengine/core/extension";
9
+ import { boxGeometry as l, capsuleGeometry as u, circleGeometry as d, coneGeometry as f, cylinderGeometry as p, planeGeometry as m, ringGeometry as h, sphereGeometry as g, torusGeometry as _, torusKnotGeometry as v } from "@margoengine/geometry/primitives";
10
+ import { Clustered as y } from "@margoengine/clustered";
11
+ import { DirectionalLights as b } from "@margoengine/clustered/directional";
12
+ import { worldMatrix as x } from "@margoengine/scene";
13
+ //#region src/edit.ts
14
+ var S = {
15
+ box: l,
16
+ sphere: g,
17
+ plane: m,
18
+ cylinder: p,
19
+ cone: f,
20
+ capsule: u,
21
+ torus: _,
22
+ circle: d,
23
+ ring: h,
24
+ torusKnot: v
25
+ }, C = 0, w = class l {
26
+ static attach(e, t, n = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
27
+ return new l(e, t, n);
28
+ }
29
+ constructor(t, n, r = {}) {
30
+ this.engine = t, this.inspector = n, this.options = r, this.pluginName = `inspector:edit:${++C}`, this.lightData = /* @__PURE__ */ new Map(), this.outputs = /* @__PURE__ */ new Set(), this.owned = [], this.ambientActive = !1, this.disposed = !1, this.wasConnected = !1, this.abort = () => this.dispose(), this.dragStart = (e) => {
31
+ this.dragging = this.item(e), this.dragging && (e.dataTransfer?.setData("text/plain", String(this.dragging.id)), e.dataTransfer && (e.dataTransfer.effectAllowed = "move"), e.stopPropagation());
32
+ }, this.dragOver = (e) => {
33
+ this.dragging && (e.preventDefault(), e.dataTransfer && (e.dataTransfer.dropEffect = "move"));
34
+ }, this.dragEnd = () => {
35
+ this.dragging = void 0;
36
+ }, this.drop = (e) => {
37
+ let t = this.dragging;
38
+ if (this.dragging = void 0, t) {
39
+ e.preventDefault(), e.stopPropagation();
40
+ try {
41
+ this.reparent(t, this.item(e) ?? null);
42
+ } catch (e) {
43
+ this.element.querySelector("output").textContent = e instanceof Error ? e.message : String(e);
44
+ }
45
+ }
46
+ }, this.keyDown = (e) => {
47
+ if (e.key === "Delete" || (e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "d") {
48
+ e.preventDefault();
49
+ try {
50
+ e.key === "Delete" ? this.delete() : this.duplicate();
51
+ } catch (e) {
52
+ this.element.querySelector("output").textContent = e instanceof Error ? e.message : String(e);
53
+ }
54
+ }
55
+ }, r.signal?.throwIfAborted(), this.runtime = s(t);
56
+ let i = this.runtime.sceneOf(n);
57
+ if (!i) throw e("state", "Attach the inspector to this engine before its scene editor");
58
+ if (this.scene = i, [...i.plugins.keys()].some((e) => e.startsWith("inspector:edit:"))) throw e("attached", "Only one scene editor may own a scene; reuse its existing editor", "state");
59
+ this.lights = r.lights ?? i.plugins.get("clustered"), this.directional = r.directional ?? i.plugins.get("clustered:directional");
60
+ for (let t of [this.lights, this.directional]) if (t && this.runtime.sceneOf(t) !== i) throw e("state", "Editor lights must belong to the inspector scene");
61
+ this.ambient = [...i.lighting.ambient, i.lighting.radiance[3]];
62
+ let a = n.element.ownerDocument;
63
+ this.tree = n.root.querySelector("[role=tree]"), this.element = a.createElement("fieldset");
64
+ let o = a.createElement("legend");
65
+ o.textContent = "Scene editing", this.element.append(o);
66
+ let c = a.createElement("select");
67
+ c.setAttribute("aria-label", "Create entity");
68
+ for (let e of [
69
+ ...Object.keys(S),
70
+ "point light",
71
+ "spot light",
72
+ "directional light",
73
+ "ambient light"
74
+ ]) {
75
+ let t = a.createElement("option");
76
+ t.value = t.textContent = e, c.append(t);
77
+ }
78
+ this.element.append(c);
79
+ let l = a.createElement("output");
80
+ l.setAttribute("role", "status");
81
+ let u = (e) => {
82
+ try {
83
+ e(), l.textContent = "";
84
+ } catch (e) {
85
+ l.textContent = e instanceof Error ? e.message : String(e);
86
+ }
87
+ };
88
+ for (let [e, t] of [
89
+ ["Create", () => c.value.endsWith(" light") ? this.createLight(c.value.split(" ")[0]) : this.createPrimitive(c.value)],
90
+ ["Duplicate", () => this.duplicate()],
91
+ ["Delete", () => this.delete()],
92
+ ["Move to root", () => this.reparent(this.selected(), null)]
93
+ ]) {
94
+ let n = a.createElement("button");
95
+ n.textContent = e, n.addEventListener("click", () => u(t)), this.element.append(n);
96
+ }
97
+ this.element.append(l), (r.parent === void 0 ? n.root : r.parent)?.append(this.element), this.tree.addEventListener("dragstart", this.dragStart), this.tree.addEventListener("dragover", this.dragOver), this.tree.addEventListener("drop", this.drop), this.tree.addEventListener("dragend", this.dragEnd), r.keyboard !== !1 && this.tree.addEventListener("keydown", this.keyDown), this.stopHistory = n.history.onChange(() => this.refresh()), this.host = n.element.parentNode;
98
+ let d = a.defaultView?.MutationObserver;
99
+ d && (this.observer = new d(() => this.refresh()), this.observer.observe(this.tree, {
100
+ childList: !0,
101
+ subtree: !0
102
+ }), this.observer.observe(n.element.parentNode, { childList: !0 })), i.use({coreRequirement:/*@__PURE__*/__margoCoreRequirement("0.1.0",import.meta.url),
103
+ name: this.pluginName,
104
+ setup() {},
105
+ onPreUpdate: () => this.syncLights(),
106
+ dispose: () => this.dispose()
107
+ }), r.signal?.addEventListener("abort", this.abort, { once: !0 }), this.refresh();
108
+ }
109
+ alive() {
110
+ if (this.disposed || this.runtime.disposed) throw e("disposed", "Scene editor is disposed; attach a new editor");
111
+ }
112
+ selected() {
113
+ let t = this.inspector.selected;
114
+ if (!t) throw e("state", "Select an entity in the tree first");
115
+ return this.check(t);
116
+ }
117
+ check(t) {
118
+ this.alive();
119
+ let n = c(t);
120
+ if (n.check(), n.scene !== this.scene || r.has(n)) throw e("state", "Choose a live entity in the inspector scene");
121
+ return n;
122
+ }
123
+ subtree(n) {
124
+ let i = [], a = (n) => {
125
+ if (t(n)?.kind === "pbr") throw e("unsupported", "Package-owned models need their package editor; edit core primitive hierarchies here");
126
+ i.push(n);
127
+ for (let e of n.kids ?? []) {
128
+ let t = this.runtime.meshes.get(e);
129
+ r.has(t) || a(t);
130
+ }
131
+ };
132
+ return a(n), i;
133
+ }
134
+ presence(e, t, i) {
135
+ let a = [], o = () => {
136
+ a = e.map((e) => ({
137
+ mesh: e,
138
+ geometry: e.geometry,
139
+ visible: e.visible
140
+ }));
141
+ for (let { mesh: e } of a) e.setGeometry(null), e.visible = !1, r.add(e);
142
+ this.inspector.selected && e.includes(c(this.inspector.selected)) && this.inspector.select(null), this.syncLights(), this.inspector.refresh();
143
+ }, s = () => {
144
+ let t = [];
145
+ try {
146
+ for (let { mesh: e, geometry: n } of a) e.setGeometry(n), t.push(e);
147
+ } catch (e) {
148
+ for (let e of t) e.setGeometry(null);
149
+ throw e;
150
+ }
151
+ for (let { mesh: e, visible: t } of a) e.visible = t, r.delete(e);
152
+ this.syncLights(), this.inspector.select(e[0]);
153
+ };
154
+ i || o();
155
+ for (let t of e) n.set(t, (n.get(t) ?? 0) + 1);
156
+ this.inspector.history.record({
157
+ label: t,
158
+ undo: i ? o : s,
159
+ redo: i ? s : o,
160
+ discard: () => {
161
+ for (let t of [...e].reverse()) {
162
+ let e = n.get(t) - 1;
163
+ e ? n.set(t, e) : (n.delete(t), r.has(t) && (r.delete(t), this.lightData.delete(t), t.dispose()));
164
+ }
165
+ }
166
+ }), i && this.inspector.select(e[0]);
167
+ }
168
+ createPrimitive(e = "box", t = null) {
169
+ if (this.alive(), !Object.hasOwn(S, e)) throw TypeError("Unknown primitive; choose a documented primitive kind");
170
+ let n = t ? this.check(t) : null, r = S[e](), i = new a(r.positions, r.normals, r.indices), o = this.scene.createMesh(n);
171
+ try {
172
+ o.setGeometry(i);
173
+ } catch (e) {
174
+ throw o.dispose(), e;
175
+ }
176
+ return o.name = e, this.presence([o], `Create ${e}`, !0), o;
177
+ }
178
+ createLight(e = "point", t = {}, n = null) {
179
+ if (this.alive(), ![
180
+ "point",
181
+ "spot",
182
+ "directional",
183
+ "ambient"
184
+ ].includes(e)) throw TypeError("Unknown light kind; use point, spot, directional or ambient");
185
+ let r = this.validateLight({
186
+ kind: e,
187
+ color: [
188
+ 1,
189
+ 1,
190
+ 1
191
+ ],
192
+ intensity: 1,
193
+ range: 10,
194
+ angle: Math.PI / 4,
195
+ penumbra: 0,
196
+ ...t
197
+ }), i = n ? this.check(n) : null;
198
+ e !== "ambient" && this.ensureLights(e === "directional");
199
+ let a = this.scene.createMesh(i);
200
+ a.name = `${e} light`, this.lightData.set(a, r);
201
+ try {
202
+ this.syncLights();
203
+ } catch (e) {
204
+ throw this.lightData.delete(a), a.dispose(), this.syncLights(), e;
205
+ }
206
+ return this.presence([a], `Create ${a.name}`, !0), a;
207
+ }
208
+ light(e) {
209
+ let t = this.lightData.get(this.check(e));
210
+ return t ? {
211
+ ...t,
212
+ color: [...t.color]
213
+ } : void 0;
214
+ }
215
+ setLight(t, n) {
216
+ let r = this.check(t), i = this.light(r);
217
+ if (!i) throw e("state", "Choose a light created by this editor");
218
+ let a = this.validateLight({
219
+ ...i,
220
+ ...n
221
+ }), o = (e) => {
222
+ let t = this.lightData.get(r);
223
+ this.lightData.set(r, e);
224
+ try {
225
+ this.syncLights();
226
+ } catch (e) {
227
+ throw this.lightData.set(r, t), this.syncLights(), e;
228
+ }
229
+ };
230
+ o(a), this.inspector.history.record({
231
+ label: `Edit ${r.name}`,
232
+ undo: () => o(i),
233
+ redo: () => o(a)
234
+ });
235
+ }
236
+ validateLight(e) {
237
+ if (!Array.isArray(e.color) || e.color.length !== 3 || e.color.some((e) => !Number.isFinite(e) || e < 0) || ![
238
+ e.intensity,
239
+ e.range,
240
+ e.angle,
241
+ e.penumbra
242
+ ].every(Number.isFinite) || e.intensity < 0 || e.range < 0 || e.angle <= 0 || e.angle > Math.PI / 2 || e.penumbra < 0 || e.penumbra > 1) throw RangeError("Light needs nonnegative finite RGB, intensity/range, angle (0, PI/2] and penumbra [0,1]");
243
+ return {
244
+ ...e,
245
+ color: [...e.color]
246
+ };
247
+ }
248
+ ensureLights(t) {
249
+ if (this.engine.backend !== "webgpu") throw e("unsupported", "Local and additional directional lights require WebGPU or the WebGL2 compatibility device; preview supports ambient editing");
250
+ this.lights || (this.lights = new y(), this.scene.use(this.lights), this.owned.push(this.lights.name)), t && !this.directional && (this.directional = new b({ lights: this.lights }), this.scene.use(this.directional), this.owned.push(this.directional.name));
251
+ }
252
+ syncLights() {
253
+ if (this.runtime.disposed) return;
254
+ let e = [], t = [], n = this.ambient.slice(0, 3).map((e) => e * this.ambient[3]), a = !1;
255
+ for (let [o, s] of this.lightData) {
256
+ if (r.has(o) || this.runtime.meshes.get(o.id) !== o || i(this.runtime.store, o.id)) continue;
257
+ let c = x(o), l = [
258
+ c[12],
259
+ c[13],
260
+ c[14]
261
+ ], u = [
262
+ -c[8],
263
+ -c[9],
264
+ -c[10]
265
+ ], d = [...s.color];
266
+ if (s.kind === "ambient") {
267
+ a = !0;
268
+ for (let e = 0; e < 3; e++) n[e] += d[e] * s.intensity;
269
+ } else s.kind === "directional" ? t.push({
270
+ direction: u,
271
+ color: d,
272
+ intensity: s.intensity
273
+ }) : e.push({
274
+ position: l,
275
+ color: d,
276
+ intensity: s.intensity,
277
+ range: s.range,
278
+ ...s.kind === "spot" ? {
279
+ direction: u,
280
+ angle: s.angle,
281
+ penumbra: s.penumbra
282
+ } : {}
283
+ });
284
+ }
285
+ let o = this.lights?.list.filter((e) => !this.outputs.has(e)) ?? [], s = this.directional?.list.filter((e) => !this.outputs.has(e)) ?? [];
286
+ this.lights?.setLights([...o, ...e]), this.directional?.setLights([...s, ...t]), this.outputs.clear();
287
+ for (let n of [...e, ...t]) this.outputs.add(n);
288
+ (a || this.ambientActive) && (this.scene.lighting.ambient.set(a ? n : this.ambient.slice(0, 3)), this.scene.lighting.radiance[3] = a ? 1 : this.ambient[3]), this.ambientActive = a;
289
+ }
290
+ delete(e = this.selected()) {
291
+ let t = this.check(e);
292
+ this.presence(this.subtree(t), `Delete ${t.name || "entity"}`, !1);
293
+ }
294
+ duplicate(e = this.selected()) {
295
+ let t = this.subtree(this.check(e)), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
296
+ try {
297
+ for (let e of t) {
298
+ let i = this.runtime.meshes.get(this.runtime.store.parents[e.id]) ?? null, a = this.scene.createMesh(i ? n.get(i) ?? i : null);
299
+ n.set(e, a), a.name = e === t[0] ? `${e.name || "Entity"} copy` : e.name, a.setGeometry(e.geometry).setPosition([
300
+ e.position.x,
301
+ e.position.y,
302
+ e.position.z
303
+ ]).setScale([
304
+ e.scale.x,
305
+ e.scale.y,
306
+ e.scale.z
307
+ ]), a.setQuaternion([
308
+ "qx",
309
+ "qy",
310
+ "qz",
311
+ "qw"
312
+ ].map((t) => this.runtime.store.transforms[t][e.id])), a.visible = e.visible, a.receiveShadow = e.receiveShadow;
313
+ let s = r.get(e.material);
314
+ s || (s = new o(), s.data.set(e.material.data), r.set(e.material, s)), a.setMaterial(s);
315
+ let c = this.lightData.get(e);
316
+ c && this.lightData.set(a, {
317
+ ...c,
318
+ color: [...c.color]
319
+ });
320
+ }
321
+ this.syncLights();
322
+ } catch (e) {
323
+ for (let e of [...n.values()].reverse()) this.lightData.delete(e), e.dispose();
324
+ throw this.syncLights(), e;
325
+ }
326
+ let i = [...n.values()];
327
+ return this.presence(i, `Duplicate ${t[0].name || "entity"}`, !0), i[0];
328
+ }
329
+ reparent(t, n) {
330
+ let r = this.check(t), i = n ? this.check(n) : null, a = this.runtime.meshes.get(this.runtime.store.parents[r.id]) ?? null;
331
+ if (i === a) return;
332
+ let o = 0;
333
+ for (let t = i; t; t = this.runtime.meshes.get(this.runtime.store.parents[t.id]) ?? null) {
334
+ if (t === r) throw e("state", "Cannot parent an entity below itself; choose a different parent");
335
+ o++;
336
+ }
337
+ let s = this.subtree(r);
338
+ for (let e of s) {
339
+ let t = 0;
340
+ for (let n = e; n !== r; n = this.runtime.meshes.get(this.runtime.store.parents[n.id])) t++;
341
+ if (o + t >= 64) throw RangeError("Parent depth must remain below 64; choose a shallower parent");
342
+ }
343
+ let c = (e) => {
344
+ r.setParent(e), this.syncLights(), this.inspector.select(r);
345
+ };
346
+ c(i), this.inspector.history.record({
347
+ label: `Reparent ${r.name || "entity"}`,
348
+ undo: () => c(a),
349
+ redo: () => c(i)
350
+ });
351
+ }
352
+ item(e) {
353
+ let t = e.target.closest("[data-entity]");
354
+ return t ? this.scene.meshes.get(Number(t.dataset.entity)) : void 0;
355
+ }
356
+ refresh() {
357
+ if (this.disposed) return;
358
+ let e = this.inspector.element;
359
+ if (e.parentNode !== this.host || this.wasConnected && !e.isConnected) this.dispose();
360
+ else {
361
+ this.wasConnected ||= e.isConnected;
362
+ for (let e of this.tree.querySelectorAll("[data-entity]")) e.draggable = !0;
363
+ }
364
+ }
365
+ dispose() {
366
+ if (!this.disposed) {
367
+ this.disposed = !0, this.observer?.disconnect(), this.stopHistory?.(), this.options.signal?.removeEventListener("abort", this.abort), this.tree.removeEventListener("dragstart", this.dragStart), this.tree.removeEventListener("dragover", this.dragOver), this.tree.removeEventListener("drop", this.drop), this.tree.removeEventListener("dragend", this.dragEnd), this.tree.removeEventListener("keydown", this.keyDown);
368
+ for (let e of this.tree.querySelectorAll("[data-entity]")) e.draggable = !1;
369
+ this.lightData.clear(), this.syncLights();
370
+ for (let e of this.owned.reverse()) this.scene.removePlugin(e);
371
+ this.element.remove(), this.scene.removePlugin(this.pluginName);
372
+ }
373
+ }
374
+ [Symbol.dispose]() {
375
+ this.dispose();
376
+ }
377
+ };
378
+ //#endregion
379
+ export { w as SceneEditor };
@@ -0,0 +1,7 @@
1
+ //#region ../shared/errors.js
2
+ var e = (e, t) => Object.assign(Error(t), {
3
+ name: "MargoError",
4
+ code: e
5
+ }), t = (e, t) => `${e}; see https://margoengine.com/errors#${t}`, n = (n, r, i = n) => e(n, t(r, i)), r = (e, n) => TypeError(t(e, n)), i = (e, n) => RangeError(t(e, n));
6
+ //#endregion
7
+ export { r as i, e as n, i as r, n as t };
@@ -0,0 +1,16 @@
1
+ import type { FrameReport } from './frame.js';
2
+ /** DOM view of a FrameReport: frame graph tree, draw tables, pipelines and memory. Text only (no HTML injection). */
3
+ export declare class FramePanel {
4
+ private readonly onSelect;
5
+ readonly element: HTMLDivElement;
6
+ private readonly body;
7
+ private readonly doc;
8
+ constructor(parent: HTMLElement, onCapture: () => void, onSelect: (entity: number) => void);
9
+ show(report: FrameReport): void;
10
+ dispose(): void;
11
+ private pass;
12
+ private row;
13
+ private details;
14
+ private table;
15
+ private el;
16
+ }
@@ -0,0 +1,264 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import type { EngineKernel } from '@margoengine/core';
3
+ import { type Engine, type EnginePlugin } from '@margoengine/core/extension';
4
+ /** A texture used by the captured frame, read from the GPUTexture itself. */
5
+ export interface TextureReport {
6
+ label: string;
7
+ format: string;
8
+ width: number;
9
+ height: number;
10
+ depthOrArrayLayers: number;
11
+ sampleCount: number;
12
+ mipLevelCount: number;
13
+ }
14
+ /** One render target of a render pass. `view` is null when the view was created before the debugger attached. */
15
+ export interface AttachmentReport {
16
+ target: 'color' | 'depth';
17
+ index: number;
18
+ view: TextureReport | null;
19
+ resolveTarget?: TextureReport | null;
20
+ loadOp?: string;
21
+ storeOp?: string;
22
+ stencilLoadOp?: string;
23
+ stencilStoreOp?: string;
24
+ readOnly?: boolean;
25
+ }
26
+ /** What a bind group entry points at. */
27
+ export interface BindingReport {
28
+ binding: number;
29
+ kind: 'buffer' | 'texture' | 'sampler' | 'external-texture' | 'unknown';
30
+ resource: string;
31
+ }
32
+ /** A bind group used by the frame. `entries` is null when the group was created before the debugger attached. */
33
+ export interface BindGroupReport {
34
+ id: number;
35
+ label: string;
36
+ entries: BindingReport[] | null;
37
+ }
38
+ /**
39
+ * A pipeline used (or compiled) by the frame. Descriptor fields are absent when the pipeline was created before the
40
+ * debugger attached. `textures`/`samplers` are the most bound by any one command using it (all its bind groups
41
+ * summed), against the 16 of each per shader stage that WebGPU guarantees.
42
+ */
43
+ export interface PipelineReport {
44
+ id: number;
45
+ kind: 'render' | 'compute';
46
+ label: string;
47
+ createdThisFrame: boolean;
48
+ known: boolean;
49
+ /** Frame graph passes that used it (names most WebGPU code leaves unlabeled pipelines by). */
50
+ passes: string[];
51
+ topology?: string;
52
+ cullMode?: string;
53
+ /** Per color target: `none` or `operation(srcFactor, dstFactor)` of the color blend. */
54
+ blend?: string[];
55
+ formats?: string[];
56
+ depth?: {
57
+ format: string;
58
+ write: boolean;
59
+ compare: string;
60
+ } | null;
61
+ samples?: number;
62
+ textures: number;
63
+ samplers: number;
64
+ }
65
+ /** Kinds of recorded commands. */
66
+ export type CommandKind = 'draw' | 'drawIndexed' | 'drawIndirect' | 'drawIndexedIndirect' | 'dispatchWorkgroups' | 'dispatchWorkgroupsIndirect' | 'executeBundles';
67
+ /**
68
+ * One draw, dispatch or bundle execution. Indirect counts are read back after the frame when the arguments buffer has
69
+ * COPY_SRC usage, else null. `entities` are core or PBR mesh ids that own this draw's current vertex buffer.
70
+ */
71
+ export interface CommandReport {
72
+ kind: CommandKind;
73
+ pipeline: number | null;
74
+ bindGroups: Array<number | null>;
75
+ vertexCount?: number | null;
76
+ indexCount?: number | null;
77
+ instanceCount?: number | null;
78
+ workgroups?: [number, number, number] | null;
79
+ bundles?: number;
80
+ indirect?: {
81
+ buffer: string;
82
+ offset: number;
83
+ };
84
+ triangles: number | null;
85
+ entities: number[];
86
+ }
87
+ /** One GPU render or compute pass. `gpuMilliseconds` needs timestamp queries and a pass on the frame graph's encoder. */
88
+ export interface GPUPassReport {
89
+ kind: 'render' | 'compute';
90
+ label: string;
91
+ encoder: number;
92
+ gpuMilliseconds: number | null;
93
+ attachments: AttachmentReport[];
94
+ commands: CommandReport[];
95
+ }
96
+ /** One frame graph pass (core's `main`, or a plugin pass) and the GPU passes it encoded. */
97
+ export interface FramePassReport {
98
+ name: string;
99
+ /** Plugin that registered the pass; `core` for the main pass, `engine` for work outside the graph, `app` for unowned passes. */
100
+ owner: string;
101
+ order: number | null;
102
+ /**
103
+ * The engine view it ran for (`RenderView.id`, its rectangle in drawing-buffer pixels, its scene's name); absent for a
104
+ * plain full-canvas frame. A frame of several views lists every pass once per view. Passes of scenes created after
105
+ * the capture started are not listed; start a new capture to include them.
106
+ */
107
+ view?: {
108
+ id: string;
109
+ viewport: readonly [number, number, number, number];
110
+ scene: string;
111
+ };
112
+ cpuMilliseconds: number;
113
+ gpuMilliseconds: number | null;
114
+ passes: GPUPassReport[];
115
+ }
116
+ /** Live GPU memory created while the debugger was attached (earlier resources are not counted). */
117
+ export interface MemoryReport {
118
+ bytes: number;
119
+ buffers: {
120
+ count: number;
121
+ bytes: number;
122
+ };
123
+ textures: {
124
+ count: number;
125
+ bytes: number;
126
+ };
127
+ largest: Array<{
128
+ kind: 'buffer' | 'texture';
129
+ label: string;
130
+ bytes: number;
131
+ }>;
132
+ }
133
+ /** One plugin attached when the capture started, in attach order per scene. */
134
+ export interface PluginReport {
135
+ name: string;
136
+ /** Name of the scene it is attached to. */
137
+ scene: string;
138
+ /** Attach order within its scene, from 0. */
139
+ order: number;
140
+ /** Frame graph passes it registered (listed in `graph` with it as `owner`). */
141
+ passes: number;
142
+ /**
143
+ * Time spent in its `onPreUpdate` during the captured frame, summed over every call; null when it has none or the
144
+ * hook cannot be wrapped (a frozen plugin).
145
+ */
146
+ preUpdateMilliseconds: number | null;
147
+ }
148
+ /** Everything `FrameDebugger.capture()` recorded for one frame; plain JSON. */
149
+ export interface FrameReport {
150
+ /** `gpu` when pass times come from timestamp queries, else `cpu` (encode time). */
151
+ timing: 'gpu' | 'cpu';
152
+ note: string;
153
+ cpuMilliseconds: number;
154
+ gpuMilliseconds: number | null;
155
+ graph: FramePassReport[];
156
+ /** Plugins of every scene at the start of the capture (one attached during the frame is not listed). */
157
+ plugins: PluginReport[];
158
+ pipelines: PipelineReport[];
159
+ bindGroups: BindGroupReport[];
160
+ totals: {
161
+ draws: number;
162
+ indexedDraws: number;
163
+ indirectDraws: number;
164
+ dispatches: number;
165
+ triangles: number;
166
+ instances: number;
167
+ renderPasses: number;
168
+ computePasses: number;
169
+ encoders: number;
170
+ submits: number;
171
+ pipelinesCreated: number;
172
+ shaderModulesCreated: number;
173
+ bindGroupsCreated: number;
174
+ uploads: number;
175
+ uploadBytes: number;
176
+ };
177
+ /** Uploads per destination, largest first (at most 20). */
178
+ uploads: Array<{
179
+ target: string;
180
+ calls: number;
181
+ bytes: number;
182
+ }>;
183
+ memory: MemoryReport;
184
+ warnings: string[];
185
+ }
186
+ /** Options for `FrameDebugger.attach`. */
187
+ export interface FrameDebuggerOptions {
188
+ /** Element for the DOM panel; null for no panel (tests, CI). Default `document.body` when there is a document. */
189
+ parent?: HTMLElement | null;
190
+ }
191
+ /** Options for `FrameDebugger.capture`. */
192
+ export interface CaptureOptions {
193
+ /** Render the frame now instead of waiting for the engine's next frame (static scenes, tests). */
194
+ render?: boolean;
195
+ }
196
+ /** Bytes per texel of a WebGPU texture format (block-compressed formats averaged over the block). */
197
+ export declare function texelBytes(format: string): number;
198
+ /**
199
+ * Estimated bytes of a texture: every mip level, layer and sample. A compressed level is stored in whole blocks (the
200
+ * WebGPU specification's physical miplevel-specific texture extent rounds each level up to the block size), so a 2x2
201
+ * or 1x1 mip of a 4x4-block format still takes a whole block.
202
+ */
203
+ export declare function textureBytes(texture: GPUTexture): number;
204
+ /**
205
+ * Frame debugger: `capture()` records one frame (frame graph passes, GPU passes, draws, pipelines, bind groups,
206
+ * render targets, uploads, GPU memory) and resolves with a JSON report; an optional DOM panel shows it.
207
+ *
208
+ * While attached it wraps only the device's resource-creation calls (pipeline and bind group descriptions, GPU memory).
209
+ * The per-frame path (engine.render, the frame graph, command encoders, passes, queue writes) is wrapped only for the
210
+ * captured frame and restored right after. Not importing `@margoengine/inspector/frame` costs nothing.
211
+ */
212
+ export declare class FrameDebugger implements EnginePlugin {
213
+ readonly name = "frame-debugger";
214
+ /** The last completed report. */
215
+ report: FrameReport | null;
216
+ private engine?;
217
+ private device?;
218
+ private profiler?;
219
+ private disposed;
220
+ private paused;
221
+ private session?;
222
+ private pending?;
223
+ private readonly panel?;
224
+ private unpatchDevice;
225
+ private readonly tracked;
226
+ private readonly pipelines;
227
+ private readonly groups;
228
+ private readonly views;
229
+ constructor({ parent }?: FrameDebuggerOptions);
230
+ /** Creates the debugger and attaches it to the engine (`engine.use(new FrameDebugger(options))`). */
231
+ static attach(engine: EngineKernel, options?: FrameDebuggerOptions): FrameDebugger;
232
+ /** Engine plugin hook: starts resource bookkeeping on the engine's device. */
233
+ setup(engine: Engine): void;
234
+ /** Engine plugin hook: moves bookkeeping to the restored device (memory counts restart from zero). */
235
+ onDeviceRestored(engine: Engine): void;
236
+ /**
237
+ * Records the next frame the engine renders (or one rendered now with `{render: true}`) and resolves with its report
238
+ * once GPU timestamps and indirect arguments are read back. A call while one is pending returns the same promise.
239
+ */
240
+ capture(options?: CaptureOptions): Promise<FrameReport>;
241
+ /** GPU memory of the live buffers and textures created while attached. */
242
+ memory(): MemoryReport;
243
+ /** Removes the panel and every wrapper, rejects a pending capture and detaches from the engine. */
244
+ dispose(): void;
245
+ [Symbol.dispose]: () => void;
246
+ private captureFromPanel;
247
+ private select;
248
+ private track;
249
+ private pipelineCreated;
250
+ private trackResource;
251
+ private untrack;
252
+ private record;
253
+ private instrumentPlugins;
254
+ private instrument;
255
+ private wrapEncoder;
256
+ /** Copies indirect draw arguments (from buffers with COPY_SRC) into one readback buffer at the end of the frame graph's encoder. */
257
+ private copyIndirect;
258
+ private wrapPass;
259
+ private texture;
260
+ private attachments;
261
+ private binding;
262
+ private finish;
263
+ private build;
264
+ }