@margoengine/inspector 0.0.0-stage → 1.0.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.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +622 -2
- package/dist/animation.d.ts +53 -0
- package/dist/animation.js +234 -0
- package/dist/color-D6qetPCJ.js +10 -0
- package/dist/color.d.ts +4 -0
- package/dist/debug-geometry-D61TEkP9.js +61 -0
- package/dist/debug-geometry.d.ts +15 -0
- package/dist/edit-state-Dm3G17js.js +4 -0
- package/dist/edit-state.d.ts +3 -0
- package/dist/edit.d.ts +105 -0
- package/dist/edit.js +379 -0
- package/dist/errors-D8rc8kzg.js +7 -0
- package/dist/frame-panel.d.ts +16 -0
- package/dist/frame.d.ts +264 -0
- package/dist/frame.js +881 -0
- package/dist/gizmo.d.ts +49 -0
- package/dist/gizmo.js +131 -0
- package/dist/gl.d.ts +89 -0
- package/dist/gl.js +284 -0
- package/dist/history.d.ts +65 -0
- package/dist/history.js +66 -0
- package/dist/index.d.ts +122 -0
- package/dist/index.js +490 -0
- package/dist/mesh-debug.d.ts +115 -0
- package/dist/mesh-debug.js +501 -0
- package/dist/mesh-source-BSQA_1GQ.js +31 -0
- package/dist/packages.d.ts +98 -0
- package/dist/packages.js +337 -0
- package/dist/remote-relay.d.ts +25 -0
- package/dist/remote-relay.js +64 -0
- package/dist/remote.d.ts +175 -0
- package/dist/remote.js +349 -0
- package/dist/resources.d.ts +30 -0
- package/dist/resources.js +42 -0
- package/dist/shaders.d.ts +122 -0
- package/dist/shaders.js +285 -0
- package/dist/snapshot.d.ts +47 -0
- package/dist/snapshot.js +90 -0
- package/dist/textures.d.ts +127 -0
- package/dist/textures.js +380 -0
- package/dist/tools.d.ts +101 -0
- package/dist/tools.js +220 -0
- package/dist/tweak.d.ts +86 -0
- package/dist/tweak.js +291 -0
- package/dist/view-rect-CTC0iGjf.js +23 -0
- package/dist/visibility-7_j5J9Nv.js +7 -0
- package/package.json +147 -4
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
// @ts-ignore optional peer: its types apply when it is installed
|
|
3
|
+
import type { Animation } from '@margoengine/animation';
|
|
4
|
+
import type { EngineKernel } from '@margoengine/core';
|
|
5
|
+
import { type EnginePlugin, type FrameGraph } from '@margoengine/core/extension';
|
|
6
|
+
/** A clip's independent playback controls. Times are seconds, weights are nonnegative and normalized per model. */
|
|
7
|
+
export interface InspectorClipState {
|
|
8
|
+
time: number;
|
|
9
|
+
weight: number;
|
|
10
|
+
playing: boolean;
|
|
11
|
+
loop: boolean;
|
|
12
|
+
speed: number;
|
|
13
|
+
}
|
|
14
|
+
/** Animation panel placement and cancellation. */
|
|
15
|
+
export interface AnimationPanelOptions {
|
|
16
|
+
/** Default document.body; null keeps the controls detached. */
|
|
17
|
+
parent?: HTMLElement | ShadowRoot | null;
|
|
18
|
+
/** Default none. Aborting disposes the panel and restores each player's playback state. */
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}
|
|
21
|
+
/** Per-model play, pause, scrub and weighted clips, plus an on-top skeleton on either rendering backend. */
|
|
22
|
+
export declare class AnimationPanel implements EnginePlugin {
|
|
23
|
+
readonly engine: EngineKernel;
|
|
24
|
+
private readonly options;
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly element: HTMLElement;
|
|
27
|
+
readonly overlay: SVGSVGElement;
|
|
28
|
+
private readonly models;
|
|
29
|
+
private readonly runtime;
|
|
30
|
+
private disposed;
|
|
31
|
+
private readonly abort;
|
|
32
|
+
/** Attaches the panel. Omitted players are discovered from the engine's Animation plugins. */
|
|
33
|
+
static attach(engine: EngineKernel, players?: readonly Animation[], options?: AnimationPanelOptions): AnimationPanel;
|
|
34
|
+
constructor(engine: EngineKernel, options?: AnimationPanelOptions);
|
|
35
|
+
setup(): void;
|
|
36
|
+
/** Adds a live player from this engine. The panel owns its clock until remove or dispose. */
|
|
37
|
+
add(animation: Animation): this;
|
|
38
|
+
/** Returns a copy of one clip's state; clip indices disambiguate duplicate names. */
|
|
39
|
+
state(animation: Animation, clip: number): Readonly<InspectorClipState>;
|
|
40
|
+
private control;
|
|
41
|
+
/** Changes playback, immediately posing scrubs and weight edits. Scrubbing through the UI pauses that clip. */
|
|
42
|
+
set(animation: Animation, clip: number, patch: Partial<InspectorClipState>): this;
|
|
43
|
+
private pose;
|
|
44
|
+
private syncInputs;
|
|
45
|
+
onPreUpdate(delta: number): void;
|
|
46
|
+
registerPasses(graph: FrameGraph): void;
|
|
47
|
+
/** Refreshes projected joint segments after world matrices change; also used by the registered render pass. */
|
|
48
|
+
drawSkeletons(): void;
|
|
49
|
+
/** Removes a model and restores the original player state. A disposed model is left alone. */
|
|
50
|
+
remove(animation: Animation): void;
|
|
51
|
+
dispose(): void;
|
|
52
|
+
[Symbol.dispose](): void;
|
|
53
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
const n=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
|
+
import { r as e, t } from "./errors-D8rc8kzg.js";
|
|
5
|
+
import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
6
|
+
import { SkeletonHelper as r } from "@margoengine/lines";
|
|
7
|
+
import { interpolateQuaternions as i } from "@margoengine/math/quat";
|
|
8
|
+
//#region src/animation.ts
|
|
9
|
+
var a = [
|
|
10
|
+
"x",
|
|
11
|
+
"y",
|
|
12
|
+
"z",
|
|
13
|
+
"qx",
|
|
14
|
+
"qy",
|
|
15
|
+
"qz",
|
|
16
|
+
"qw",
|
|
17
|
+
"sx",
|
|
18
|
+
"sy",
|
|
19
|
+
"sz"
|
|
20
|
+
];
|
|
21
|
+
function o(e) {
|
|
22
|
+
let t = e.model.root.engine.store.transforms;
|
|
23
|
+
return {
|
|
24
|
+
nodes: e.model.nodes.map((e) => a.map((n) => t[n][e.id])),
|
|
25
|
+
morphs: e.model.primitives.map((e) => e.weights.slice())
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function s(e, t) {
|
|
29
|
+
e.model.nodes.forEach((e, n) => {
|
|
30
|
+
let r = t.nodes[n];
|
|
31
|
+
e.setPosition([
|
|
32
|
+
r[0],
|
|
33
|
+
r[1],
|
|
34
|
+
r[2]
|
|
35
|
+
]).setQuaternion([
|
|
36
|
+
r[3],
|
|
37
|
+
r[4],
|
|
38
|
+
r[5],
|
|
39
|
+
r[6]
|
|
40
|
+
]).setScale([
|
|
41
|
+
r[7],
|
|
42
|
+
r[8],
|
|
43
|
+
r[9]
|
|
44
|
+
]);
|
|
45
|
+
}), e.model.primitives.forEach((e, n) => e.weights.set(t.morphs[n]));
|
|
46
|
+
}
|
|
47
|
+
function c(e, t, n) {
|
|
48
|
+
e.nodes.forEach((e, r) => {
|
|
49
|
+
let a = t.nodes[r], o = i(e.slice(3, 7), a.slice(3, 7), n, .9995);
|
|
50
|
+
for (let t = 0; t < e.length; t++) e[t] = t >= 3 && t < 7 ? o[t - 3] : e[t] + (a[t] - e[t]) * n;
|
|
51
|
+
}), e.morphs.forEach((e, r) => {
|
|
52
|
+
for (let i = 0; i < e.length; i++) e[i] += (t.morphs[r][i] - e[i]) * n;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
var l = 0, u = class i {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
|
|
56
|
+
static attach(e, t, n = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
57
|
+
let r = new i(e, n);
|
|
58
|
+
try {
|
|
59
|
+
e.use(r);
|
|
60
|
+
for (let e of t ?? [...r.runtime.plugins.values()].filter((e) => "clips" in e && "model" in e && "seek" in e)) r.add(e);
|
|
61
|
+
return r;
|
|
62
|
+
} catch (e) {
|
|
63
|
+
throw r.dispose(), e;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
constructor(e, t = {}) {
|
|
67
|
+
this.engine = e, this.options = t, this.name = `inspector:animation:${++l}`, this.models = /* @__PURE__ */ new Map(), this.disposed = !1, this.abort = () => this.dispose(), t.signal?.throwIfAborted(), this.runtime = n(e);
|
|
68
|
+
let r = e.canvas.ownerDocument;
|
|
69
|
+
this.element = r.createElement("section"), this.element.setAttribute("aria-label", "Animations"), this.overlay = r.createElementNS("http://www.w3.org/2000/svg", "svg"), this.overlay.setAttribute("aria-label", "Skeleton overlay"), this.overlay.style.cssText = "position:fixed;pointer-events:none;z-index:10000;overflow:hidden", r.body.append(this.overlay), (t.parent === void 0 ? r.body : t.parent)?.append(this.element), t.signal?.addEventListener("abort", this.abort, { once: !0 });
|
|
70
|
+
}
|
|
71
|
+
setup() {}
|
|
72
|
+
add(e) {
|
|
73
|
+
if (this.disposed || e.model.disposed || e.model.root.engine !== this.runtime) throw t("state", "Use a live Animation from this panel engine");
|
|
74
|
+
if (this.models.has(e)) return this;
|
|
75
|
+
let n = e.captureState(), i = o(e), a = this.element.ownerDocument, s = a.createElement("fieldset"), c = a.createElement("legend");
|
|
76
|
+
c.textContent = e.model.name || "Model", s.append(c);
|
|
77
|
+
let l = (e.model.asset.doc.skins ?? []).map((t, n) => r.fromGLTF(e.model, n)), u = {
|
|
78
|
+
animation: e,
|
|
79
|
+
initial: n,
|
|
80
|
+
rest: i,
|
|
81
|
+
helpers: l,
|
|
82
|
+
skeleton: !1,
|
|
83
|
+
element: s,
|
|
84
|
+
inputs: [],
|
|
85
|
+
states: e.clips.map((e, t) => ({
|
|
86
|
+
time: t === n.clip ? n.time : 0,
|
|
87
|
+
weight: +(t === n.clip),
|
|
88
|
+
playing: n.playing,
|
|
89
|
+
loop: n.loop,
|
|
90
|
+
speed: n.speed
|
|
91
|
+
})),
|
|
92
|
+
off: () => {}
|
|
93
|
+
}, d = a.createElement("input");
|
|
94
|
+
d.type = "checkbox";
|
|
95
|
+
let f = a.createElement("label");
|
|
96
|
+
return f.textContent = "Skeleton", f.append(d), s.append(f), d.disabled = l.length === 0, d.addEventListener("change", () => {
|
|
97
|
+
u.skeleton = d.checked, this.drawSkeletons();
|
|
98
|
+
}), e.clips.forEach((t, n) => {
|
|
99
|
+
let r = a.createElement("fieldset"), i = a.createElement("legend");
|
|
100
|
+
i.textContent = t.name || `Clip ${n}`, r.append(i);
|
|
101
|
+
for (let [t, i] of [["Play", !0], ["Pause", !1]]) {
|
|
102
|
+
let o = a.createElement("button");
|
|
103
|
+
o.textContent = t, o.type = "button", o.addEventListener("click", () => this.set(e, n, { playing: i })), r.append(o);
|
|
104
|
+
}
|
|
105
|
+
let o = [];
|
|
106
|
+
for (let [i, s, c, l, u] of [
|
|
107
|
+
[
|
|
108
|
+
"Time",
|
|
109
|
+
"time",
|
|
110
|
+
0,
|
|
111
|
+
t.duration,
|
|
112
|
+
.001
|
|
113
|
+
],
|
|
114
|
+
[
|
|
115
|
+
"Weight",
|
|
116
|
+
"weight",
|
|
117
|
+
0,
|
|
118
|
+
1,
|
|
119
|
+
.01
|
|
120
|
+
],
|
|
121
|
+
[
|
|
122
|
+
"Speed",
|
|
123
|
+
"speed",
|
|
124
|
+
0,
|
|
125
|
+
10,
|
|
126
|
+
.1
|
|
127
|
+
]
|
|
128
|
+
]) {
|
|
129
|
+
let d = a.createElement("input"), f = a.createElement("label");
|
|
130
|
+
f.textContent = i, d.type = s === "time" ? "range" : "number", d.min = String(c), d.max = String(l), d.step = String(u), d.setAttribute("aria-label", `${t.name || n} ${i}`), f.append(d), r.append(f), o.push(d), d.addEventListener("input", () => this.set(e, n, {
|
|
131
|
+
[s]: d.valueAsNumber,
|
|
132
|
+
...s === "time" ? { playing: !1 } : {}
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
let c = a.createElement("input"), l = a.createElement("label");
|
|
136
|
+
c.type = "checkbox", l.textContent = "Loop", l.append(c), r.append(l), o.push(c), c.addEventListener("change", () => this.set(e, n, { loop: c.checked })), u.inputs.push(o), s.append(r);
|
|
137
|
+
}), u.off = e.model.onDispose(() => this.remove(e)), this.models.set(e, u), e.playing = !1, this.element.append(s), this.syncInputs(u), this;
|
|
138
|
+
}
|
|
139
|
+
state(e, t) {
|
|
140
|
+
return { ...this.control(e, t).states[t] };
|
|
141
|
+
}
|
|
142
|
+
control(t, n) {
|
|
143
|
+
let r = this.models.get(t);
|
|
144
|
+
if (!r || !Number.isInteger(n) || !r.states[n]) throw e("Use a clip index from a player added to this panel", "state");
|
|
145
|
+
return r;
|
|
146
|
+
}
|
|
147
|
+
set(t, n, r) {
|
|
148
|
+
let i = this.control(t, n), a = {
|
|
149
|
+
...i.states[n],
|
|
150
|
+
...r
|
|
151
|
+
};
|
|
152
|
+
if (![
|
|
153
|
+
a.time,
|
|
154
|
+
a.weight,
|
|
155
|
+
a.speed
|
|
156
|
+
].every((e) => Number.isFinite(e) && e >= 0) || typeof a.playing != "boolean" || typeof a.loop != "boolean") throw e("Use finite nonnegative time, weight and speed, and boolean playing and loop", "state");
|
|
157
|
+
return a.time = Math.min(a.time, t.clips[n].duration), i.states[n] = a, this.pose(i), this.syncInputs(i), this;
|
|
158
|
+
}
|
|
159
|
+
pose(e) {
|
|
160
|
+
let { animation: t, rest: n } = e, r, i = 0;
|
|
161
|
+
for (let [a, l] of e.states.entries()) if (l.weight > 0) {
|
|
162
|
+
s(t, n), t.clip = a, t.options.loop = !1, t.seek(l.time);
|
|
163
|
+
let e = o(t);
|
|
164
|
+
i += l.weight, r ? c(r, e, l.weight / i) : r = e;
|
|
165
|
+
}
|
|
166
|
+
s(t, r ?? n), t.playing = !1;
|
|
167
|
+
}
|
|
168
|
+
syncInputs(e) {
|
|
169
|
+
e.states.forEach((t, n) => {
|
|
170
|
+
let r = e.inputs[n];
|
|
171
|
+
[
|
|
172
|
+
t.time,
|
|
173
|
+
t.weight,
|
|
174
|
+
t.speed
|
|
175
|
+
].forEach((e, t) => {
|
|
176
|
+
r[t].value = String(e);
|
|
177
|
+
}), r[3].checked = t.loop;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
onPreUpdate(e) {
|
|
181
|
+
for (let t of this.models.values()) {
|
|
182
|
+
for (let [n, r] of t.states.entries()) if (r.playing) {
|
|
183
|
+
let i = t.animation.clips[n].duration;
|
|
184
|
+
r.time += e * r.speed, r.loop && i > 0 ? r.time %= i : r.time >= i && (r.time = i, r.playing = !1);
|
|
185
|
+
}
|
|
186
|
+
this.pose(t), this.syncInputs(t);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
registerPasses(e) {
|
|
190
|
+
e.add({
|
|
191
|
+
name: this.name,
|
|
192
|
+
order: 21,
|
|
193
|
+
execute: () => this.drawSkeletons()
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
drawSkeletons() {
|
|
197
|
+
let e = this.engine.canvas.getBoundingClientRect(), t = this.overlay, n = this.runtime.camera.matrix;
|
|
198
|
+
Object.assign(t.style, {
|
|
199
|
+
left: `${e.left}px`,
|
|
200
|
+
top: `${e.top}px`,
|
|
201
|
+
width: `${e.width}px`,
|
|
202
|
+
height: `${e.height}px`
|
|
203
|
+
}), t.setAttribute("viewBox", `0 0 ${this.engine.canvas.width} ${this.engine.canvas.height}`);
|
|
204
|
+
let r = [];
|
|
205
|
+
for (let e of this.models.values()) if (e.skeleton) {
|
|
206
|
+
for (let t of e.helpers) if (t.update(this.engine)) for (let e = 0; e + 1 < t.count; e += 2) {
|
|
207
|
+
let i = (e) => {
|
|
208
|
+
let r = t.points, i = r[e * 4], a = r[e * 4 + 1], o = r[e * 4 + 2], s = n[3] * i + n[7] * a + n[11] * o + n[15];
|
|
209
|
+
return s <= 0 ? null : [(n[0] * i + n[4] * a + n[8] * o + n[12]) / s, (n[1] * i + n[5] * a + n[9] * o + n[13]) / s];
|
|
210
|
+
}, a = i(e), o = i(e + 1);
|
|
211
|
+
a && o && r.push(`M${(a[0] + 1) * this.engine.canvas.width / 2},${(1 - a[1]) * this.engine.canvas.height / 2}L${(o[0] + 1) * this.engine.canvas.width / 2},${(1 - o[1]) * this.engine.canvas.height / 2}`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
t.replaceChildren();
|
|
215
|
+
let i = t.ownerDocument.createElementNS(t.namespaceURI, "path");
|
|
216
|
+
i.setAttribute("d", r.join("")), i.setAttribute("stroke", "#ff7a2e"), i.setAttribute("stroke-width", "2"), i.setAttribute("fill", "none"), t.append(i);
|
|
217
|
+
}
|
|
218
|
+
remove(e) {
|
|
219
|
+
let t = this.models.get(e);
|
|
220
|
+
t && (this.models.delete(e), t.off(), t.element.remove(), t.helpers.forEach((e) => e.dispose()), e.model.disposed || (s(e, t.rest), e.restoreState(t.initial)), this.drawSkeletons());
|
|
221
|
+
}
|
|
222
|
+
dispose() {
|
|
223
|
+
if (!this.disposed) {
|
|
224
|
+
this.disposed = !0;
|
|
225
|
+
for (let e of this.models.keys()) this.remove(e);
|
|
226
|
+
this.options.signal?.removeEventListener("abort", this.abort), this.overlay.remove(), this.element.remove(), this.runtime.sceneOf(this)?.removePlugin(this.name);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
[Symbol.dispose]() {
|
|
230
|
+
this.dispose();
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
//#endregion
|
|
234
|
+
export { u as AnimationPanel };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LinearToSRGB as e, parseColor as t } from "@margoengine/math/color";
|
|
2
|
+
//#region src/color.ts
|
|
3
|
+
function n(t) {
|
|
4
|
+
let n = "#";
|
|
5
|
+
for (let r = 0; r < 3; r++) n += Math.round(e(Math.max(0, Math.min(1, t[r]))) * 255).toString(16).padStart(2, "0");
|
|
6
|
+
return n;
|
|
7
|
+
}
|
|
8
|
+
var r = (e) => Array.from(t(e));
|
|
9
|
+
//#endregion
|
|
10
|
+
export { r as n, n as t };
|
package/dist/color.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** `#rrggbb` (sRGB) of a linear colour's first three channels, each clamped to 0..1, for a colour input. */
|
|
2
|
+
export declare function hexOf(data: ArrayLike<number>): string;
|
|
3
|
+
/** Linear rgb of a colour input's `#rrggbb` (sRGB) value. */
|
|
4
|
+
export declare const linearOf: (hex: string) => number[];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { r as e } from "./mesh-source-BSQA_1GQ.js";
|
|
2
|
+
import { Line as t } from "@margoengine/lines";
|
|
3
|
+
//#region src/debug-geometry.ts
|
|
4
|
+
var n = /* @__PURE__ */ new WeakMap(), r = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
function i(t) {
|
|
6
|
+
let n = e(t);
|
|
7
|
+
if (!n) return null;
|
|
8
|
+
let i = n.kind === "core" ? n.geometry : n.source, a = r.get(i);
|
|
9
|
+
if (!a) {
|
|
10
|
+
if (n.kind === "core") a = {
|
|
11
|
+
identity: i,
|
|
12
|
+
pbr: !1,
|
|
13
|
+
parts: [{
|
|
14
|
+
vertices: n.geometry.vertices,
|
|
15
|
+
indices: n.geometry.indices,
|
|
16
|
+
stride: 6
|
|
17
|
+
}],
|
|
18
|
+
radius: n.geometry.bounds[3]
|
|
19
|
+
};
|
|
20
|
+
else {
|
|
21
|
+
let e = n.source.bounds;
|
|
22
|
+
a = {
|
|
23
|
+
identity: i,
|
|
24
|
+
pbr: !0,
|
|
25
|
+
parts: n.source.primitives.map((e) => ({
|
|
26
|
+
vertices: e.vertices,
|
|
27
|
+
indices: e.indices,
|
|
28
|
+
stride: 20
|
|
29
|
+
})),
|
|
30
|
+
radius: Math.hypot(e[3] - e[0], e[4] - e[1], e[5] - e[2]) / 2
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
r.set(i, a);
|
|
34
|
+
}
|
|
35
|
+
return a;
|
|
36
|
+
}
|
|
37
|
+
function a(e) {
|
|
38
|
+
let r = i(e), a = n.get(r.identity);
|
|
39
|
+
if (!a) {
|
|
40
|
+
let e = [];
|
|
41
|
+
for (let { indices: t, vertices: n, stride: i } of r.parts) {
|
|
42
|
+
let r = n.length / i, a = /* @__PURE__ */ new Set();
|
|
43
|
+
for (let o = 0; o < t.length; o += 3) for (let s = 0; s < 3; s++) {
|
|
44
|
+
let c = t[o + s], l = t[o + (s + 1) % 3], u = Math.min(c, l) * r + Math.max(c, l);
|
|
45
|
+
a.has(u) || (a.add(u), e.push(n[c * i], n[c * i + 1], n[c * i + 2], n[l * i], n[l * i + 1], n[l * i + 2]));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
a = new Float32Array(e), n.set(r.identity, a);
|
|
49
|
+
}
|
|
50
|
+
return new t({
|
|
51
|
+
mesh: e,
|
|
52
|
+
positions: a,
|
|
53
|
+
mode: "segments",
|
|
54
|
+
color: "#72e8cc",
|
|
55
|
+
onTop: !0,
|
|
56
|
+
cap: "butt",
|
|
57
|
+
join: "miter"
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { a as n, i as t };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Mesh } from '@margoengine/core/extension';
|
|
2
|
+
import { Line } from '@margoengine/lines';
|
|
3
|
+
interface MeshData {
|
|
4
|
+
identity: object;
|
|
5
|
+
pbr: boolean;
|
|
6
|
+
parts: {
|
|
7
|
+
vertices: Float32Array;
|
|
8
|
+
indices: Uint32Array;
|
|
9
|
+
stride: number;
|
|
10
|
+
}[];
|
|
11
|
+
radius: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function meshData(mesh: Mesh): MeshData | null;
|
|
14
|
+
export declare function wireframe(mesh: Mesh): Line;
|
|
15
|
+
export {};
|
package/dist/edit.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { EngineKernel, Mesh as MeshHandle } from '@margoengine/core';
|
|
3
|
+
import { boxGeometry, sphereGeometry, planeGeometry, cylinderGeometry, coneGeometry, capsuleGeometry, torusGeometry, circleGeometry, ringGeometry, torusKnotGeometry } from '@margoengine/geometry/primitives';
|
|
4
|
+
import { Clustered } from '@margoengine/clustered';
|
|
5
|
+
import { DirectionalLights } from '@margoengine/clustered/directional';
|
|
6
|
+
import type { Inspector } from './index.js';
|
|
7
|
+
declare const primitives: {
|
|
8
|
+
box: typeof boxGeometry;
|
|
9
|
+
sphere: typeof sphereGeometry;
|
|
10
|
+
plane: typeof planeGeometry;
|
|
11
|
+
cylinder: typeof cylinderGeometry;
|
|
12
|
+
cone: typeof coneGeometry;
|
|
13
|
+
capsule: typeof capsuleGeometry;
|
|
14
|
+
torus: typeof torusGeometry;
|
|
15
|
+
circle: typeof circleGeometry;
|
|
16
|
+
ring: typeof ringGeometry;
|
|
17
|
+
torusKnot: typeof torusKnotGeometry;
|
|
18
|
+
};
|
|
19
|
+
/** Primitives built by the existing geometry package, with its default dimensions. */
|
|
20
|
+
export type EditorPrimitive = keyof typeof primitives;
|
|
21
|
+
/** Light kinds supported by the engine's existing lighting packages. */
|
|
22
|
+
export type EditorLightKind = 'point' | 'spot' | 'directional' | 'ambient';
|
|
23
|
+
/** Editable light values. Position and direction follow the anchor's full parent transform. */
|
|
24
|
+
export interface EditorLight {
|
|
25
|
+
kind: EditorLightKind;
|
|
26
|
+
color: [number, number, number];
|
|
27
|
+
intensity: number;
|
|
28
|
+
range: number;
|
|
29
|
+
angle: number;
|
|
30
|
+
penumbra: number;
|
|
31
|
+
}
|
|
32
|
+
/** Settings for an editor attached to an inspector's own scene. */
|
|
33
|
+
export interface SceneEditorOptions {
|
|
34
|
+
/** Toolbar parent; default inspector shadow root. Null hides it. */
|
|
35
|
+
parent?: HTMLElement | ShadowRoot | null;
|
|
36
|
+
/** Existing lights, otherwise the scene's Clustered or a lazily attached one. WebGPU only. */
|
|
37
|
+
lights?: Clustered;
|
|
38
|
+
/** Existing directional lights, otherwise the scene's or a lazily attached one. */
|
|
39
|
+
directional?: DirectionalLights;
|
|
40
|
+
/** Delete and Ctrl/Cmd+D in the inspector tree. Default true. */
|
|
41
|
+
keyboard?: boolean;
|
|
42
|
+
signal?: AbortSignal;
|
|
43
|
+
}
|
|
44
|
+
/** Undoable primitive/light creation, subtree deletion/duplication and tree drag reparenting. */
|
|
45
|
+
export declare class SceneEditor {
|
|
46
|
+
readonly engine: EngineKernel;
|
|
47
|
+
readonly inspector: Inspector;
|
|
48
|
+
private readonly options;
|
|
49
|
+
readonly element: HTMLFieldSetElement;
|
|
50
|
+
private readonly runtime;
|
|
51
|
+
private readonly scene;
|
|
52
|
+
private readonly pluginName;
|
|
53
|
+
private readonly tree;
|
|
54
|
+
private readonly observer?;
|
|
55
|
+
private readonly lightData;
|
|
56
|
+
private readonly outputs;
|
|
57
|
+
private lights?;
|
|
58
|
+
private directional?;
|
|
59
|
+
private readonly ambient;
|
|
60
|
+
private readonly owned;
|
|
61
|
+
private ambientActive;
|
|
62
|
+
private dragging?;
|
|
63
|
+
private disposed;
|
|
64
|
+
private wasConnected;
|
|
65
|
+
/** The inspector's parent at attach time; leaving it is a removal even while that parent is detached. */
|
|
66
|
+
private readonly host;
|
|
67
|
+
private readonly stopHistory;
|
|
68
|
+
private readonly abort;
|
|
69
|
+
static attach(engine: EngineKernel, inspector: Inspector, options?: SceneEditorOptions): SceneEditor;
|
|
70
|
+
constructor(engine: EngineKernel, inspector: Inspector, options?: SceneEditorOptions);
|
|
71
|
+
private alive;
|
|
72
|
+
private selected;
|
|
73
|
+
private check;
|
|
74
|
+
private subtree;
|
|
75
|
+
private presence;
|
|
76
|
+
/** Creates one primitive at the origin, parent-relative, and selects it. Default box, root parent. */
|
|
77
|
+
createPrimitive(kind?: EditorPrimitive, parent?: MeshHandle | null): MeshHandle;
|
|
78
|
+
/** Creates a selectable transform anchor and a real light. Default point, white, intensity 1, range 10, angle PI/4, penumbra 0. */
|
|
79
|
+
createLight(kind?: EditorLightKind, values?: Partial<Omit<EditorLight, 'kind'>>, parent?: MeshHandle | null): MeshHandle;
|
|
80
|
+
/** A copy of an editor light's local settings, or undefined for a primitive. */
|
|
81
|
+
light(handle: MeshHandle): EditorLight | undefined;
|
|
82
|
+
/** Updates light settings as one undoable operation. Transform edits use inspector properties or its gizmo. */
|
|
83
|
+
setLight(handle: MeshHandle, values: Partial<Omit<EditorLight, 'kind'>>): void;
|
|
84
|
+
private validateLight;
|
|
85
|
+
private ensureLights;
|
|
86
|
+
private syncLights;
|
|
87
|
+
/** Deletes the selected subtree (default) as one step. Original mesh handles survive until history eviction. */
|
|
88
|
+
delete(handle?: MeshHandle): void;
|
|
89
|
+
/** Deep-copies a subtree, shares immutable geometries and copies each distinct material once. */
|
|
90
|
+
duplicate(handle?: MeshHandle): MeshHandle;
|
|
91
|
+
/** Reparents with local transform preserved, as one undo step. Null moves to the root. Cycles reject before editing. */
|
|
92
|
+
reparent(handle: MeshHandle, parent: MeshHandle | null): void;
|
|
93
|
+
private item;
|
|
94
|
+
private readonly dragStart;
|
|
95
|
+
private readonly dragOver;
|
|
96
|
+
private readonly dragEnd;
|
|
97
|
+
private readonly drop;
|
|
98
|
+
private readonly keyDown;
|
|
99
|
+
/** Marks regenerated tree rows draggable. Called automatically on tree changes. */
|
|
100
|
+
refresh(): void;
|
|
101
|
+
/** Removes editor UI/input and its owned lights. Scene meshes and shared undo history remain usable. */
|
|
102
|
+
dispose(): void;
|
|
103
|
+
[Symbol.dispose](): void;
|
|
104
|
+
}
|
|
105
|
+
export {};
|