@nebula-spatial/viewer 0.5.6 → 0.5.7

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.
@@ -1,479 +0,0 @@
1
- var y = Object.defineProperty;
2
- var T = (e, t, n) => t in e ? y(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var f = (e, t, n) => T(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { disposeModelResources as M } from "./resources-CHhCm2f7.js";
5
- import { q as U, s as j, t as v, u as k, U as P, p as x } from "./index-D6-ClMfm.js";
6
- import { LineBasicMaterial as B, MeshBasicMaterial as F, DoubleSide as $, WireframeGeometry as V, LineSegments as z, Mesh as G, EdgesGeometry as m, Vector3 as w } from "three";
7
- const W = /* @__PURE__ */ new Set([
8
- "E_MJCF_INCLUDE_CYCLE",
9
- "E_MJCF_PARSE",
10
- "E_URDF_COMPILE",
11
- "E_URDF_INERTIA",
12
- "E_USD_INVALID_COLLISION_GEOMETRY",
13
- "E_USD_INVALID_COLLISION_GROUP",
14
- "E_USD_INVALID_EQUALITY_CONNECT",
15
- "E_USD_INVALID_JOINT_REFERENCE",
16
- "E_USD_INVALID_MASS",
17
- "E_USD_INVALID_MIMIC",
18
- "E_USD_INVALID_UNITS",
19
- "E_USD_MISSING_COLLISION_GEOMETRY",
20
- "E_USD_MULTIPLE_PHYSICS_SCENES",
21
- "E_USD_PARTIAL_INERTIA",
22
- "E_USD_UNREACHABLE_BODIES"
23
- ]), H = /* @__PURE__ */ new Set(["step", "reset", "grab", "up-axis"]), q = Object.freeze({
24
- kind: "visual-adaptation",
25
- title: "视觉适配信息",
26
- summary: "部分材质细节采用近似表示,不影响资产结构与模型查看。",
27
- tone: "info"
28
- }), Y = Object.freeze({
29
- kind: "unsupported-by-viewer",
30
- title: "视觉预览模式",
31
- summary: "当前仿真链路未能建立物理模型,资产视觉内容仍可正常查看。",
32
- tone: "info"
33
- });
34
- function I(e, t) {
35
- return e === "E_URDF_INERTIA" ? {
36
- kind: "invalid-asset",
37
- title: "物理定义无效",
38
- summary: "该 URDF 未声明动力学仿真所需的有效惯性数据,动力学模型无法建立。",
39
- tone: "warning"
40
- } : {
41
- kind: "invalid-asset",
42
- title: "物理定义无效",
43
- summary: t === "usd-physics" ? "该 USD 资产的物理参数或关节定义无效,物理模型无法建立。" : "该资产的物理参数缺失或无效,物理模型无法建立。",
44
- tone: "warning"
45
- };
46
- }
47
- function J(e) {
48
- return e === "visual-material" ? {
49
- kind: "visual-adaptation",
50
- title: "视觉材质近似",
51
- summary: "部分材质信息未完整转换,当前显示使用近似材质。",
52
- tone: "info"
53
- } : q;
54
- }
55
- function A(e, t) {
56
- const n = t.split(":").at(-1);
57
- if (n && H.has(n))
58
- return {
59
- kind: "runtime-failure",
60
- title: "仿真运行异常",
61
- summary: "仿真初始化或运行过程中发生异常,物理仿真已停止;资产视觉内容仍可正常查看。",
62
- tone: "warning"
63
- };
64
- if (e === "E_MUJOCO_INITIALIZE") {
65
- if (t === "mjcf-physics")
66
- return {
67
- kind: "runtime-failure",
68
- title: "物理模型初始化失败",
69
- summary: "MuJoCo 物理模型初始化失败,资产仍可进行视觉预览。",
70
- tone: "warning"
71
- };
72
- if (t === "urdf-physics")
73
- return {
74
- kind: "runtime-failure",
75
- title: "动力学初始化失败",
76
- summary: "URDF 动力学初始化失败,当前保留运动学预览。",
77
- tone: "warning"
78
- };
79
- if (t === "usd-physics")
80
- return {
81
- kind: "runtime-failure",
82
- title: "物理模型初始化失败",
83
- summary: "当前 USD 物理模型未能完成 MuJoCo 初始化,资产视觉内容仍可正常查看。",
84
- tone: "warning"
85
- };
86
- }
87
- return W.has(e) ? I(e, t) : t === "usd-physics" || e.startsWith("E_USD_") ? {
88
- kind: "unsupported-by-viewer",
89
- title: "视觉预览模式",
90
- summary: "当前 Viewer 未覆盖该 USD 资产使用的部分物理语义,视觉与结构信息可正常查看,物理仿真未启动。",
91
- tone: "info"
92
- } : e.startsWith("E_MJCF_") || e.startsWith("E_URDF_") ? I(e, t) : Y;
93
- }
94
- function Et(e, t) {
95
- const n = e.notice ?? (t === "physics-validation" ? I(e.code, e.source) : t === "visual-adaptation" || t === "visual-material" ? J(t) : A(e.code, e.source ?? t));
96
- return { ...e, stage: t, notice: n };
97
- }
98
- function pt(e, t, n) {
99
- if (t.throwIfAborted(), e instanceof Error && (e.name === "AbortError" || ["E_ABORTED", "E_SUPERSEDED"].includes(String(e.code)))) throw e;
100
- const i = e && typeof e == "object" && "code" in e && typeof e.code == "string" ? e.code : "E_PHYSICS_INITIALIZE", s = e instanceof Error ? e.message : String(e);
101
- return { code: i, source: n, message: s, notice: A(i, n) };
102
- }
103
- class _t {
104
- constructor(t, n) {
105
- f(this, "root");
106
- f(this, "bodies", /* @__PURE__ */ new Map());
107
- f(this, "links", /* @__PURE__ */ new Map());
108
- f(this, "disposed", !1);
109
- this.runtime = t, this.root = n.root;
110
- const i = t.mujoco, s = t.model;
111
- for (const [o, r] of n.bindings) {
112
- const l = i.mj_name2id(s, i.mjtObj.mjOBJ_BODY.value, o);
113
- if (l < 0) throw D(`Physics body missing for visual link: ${o}`, "E_SIMULATION_BIND");
114
- this.links.set(o, r), r.userData.bodyId = l, this.bodies.set(l, r);
115
- }
116
- if (this.bodies.size !== n.expectedLinkCount) throw D("Visual body binding count mismatch.", "E_SIMULATION_BIND");
117
- this.sync();
118
- }
119
- objectForLink(t) {
120
- return this.links.get(t) ?? null;
121
- }
122
- bodyPoses() {
123
- return new Map([...this.bodies.values()].map((t) => [t.name, { position: t.position.clone(), quaternion: t.quaternion.clone() }]));
124
- }
125
- sync() {
126
- if (this.disposed || !this.runtime.data) return;
127
- const { xpos: t, xquat: n } = this.runtime.data;
128
- for (const [i, s] of this.bodies) {
129
- const o = i * 3, r = i * 4;
130
- s.position.set(t[o], t[o + 1], t[o + 2]), s.quaternion.set(n[r + 1], n[r + 2], n[r + 3], n[r]);
131
- }
132
- this.root.updateMatrixWorld(!0);
133
- }
134
- dispose() {
135
- this.disposed || (this.disposed = !0, this.bodies.clear(), this.links.clear(), M(this.root));
136
- }
137
- }
138
- function D(e, t) {
139
- return Object.assign(new Error(e), { code: t });
140
- }
141
- const K = /<UDIM>/i;
142
- function X(e, t) {
143
- const n = g(e).replaceAll("\\", "/");
144
- if (!K.test(n)) return null;
145
- const i = R(n), s = i.split("/").at(-1);
146
- if (!s) return { paths: [], tiles: [] };
147
- const o = Q(s);
148
- if (!o) return { paths: [], tiles: [] };
149
- const r = [];
150
- for (const a of new Set(t)) {
151
- const h = g(a).replaceAll("\\", "/"), S = R(h), b = S.split("/").at(-1);
152
- if (!b) continue;
153
- const O = o.exec(b);
154
- if (!O) continue;
155
- const E = Number(O[1]);
156
- !Number.isInteger(E) || E < 1001 || E > 9999 || r.push({
157
- path: a,
158
- tile: E,
159
- score: tt(i, S)
160
- });
161
- }
162
- if (!r.length) return { paths: [], tiles: [] };
163
- const l = Math.max(...r.map((a) => a.score)), c = r.filter((a) => a.score === l).sort((a, h) => a.tile - h.tile || a.path.localeCompare(h.path));
164
- return {
165
- paths: c.map((a) => a.path),
166
- tiles: c.map((a) => a.tile)
167
- };
168
- }
169
- function mt(e) {
170
- if (!e.tiles.length) return null;
171
- const t = e.tiles.map(Z), n = Math.min(...t.map(({ column: r }) => r)), i = Math.max(...t.map(({ column: r }) => r)), s = Math.min(...t.map(({ row: r }) => r)), o = Math.max(...t.map(({ row: r }) => r));
172
- return {
173
- minColumn: n,
174
- maxColumn: i,
175
- minRow: s,
176
- maxRow: o,
177
- columns: i - n + 1,
178
- rows: o - s + 1
179
- };
180
- }
181
- function Z(e) {
182
- const t = e - 1001;
183
- return {
184
- column: (t % 10 + 10) % 10,
185
- row: Math.floor(t / 10)
186
- };
187
- }
188
- function Q(e) {
189
- const t = e.split(/<UDIM>/i);
190
- return t.length !== 2 ? null : new RegExp(`^${L(t[0])}(\\d{4})${L(t[1])}$`, "i");
191
- }
192
- function tt(e, t) {
193
- const n = e.split("/").slice(0, -1).filter(Boolean), i = t.split("/").slice(0, -1).filter(Boolean);
194
- let s = 0;
195
- for (; s < n.length && s < i.length; ) {
196
- const o = n.at(-1 - s), r = i.at(-1 - s);
197
- if ((o == null ? void 0 : o.toLowerCase()) !== (r == null ? void 0 : r.toLowerCase())) break;
198
- s += 1;
199
- }
200
- return s;
201
- }
202
- function g(e) {
203
- const t = e.replace(/%3CUDIM%3E/gi, "<UDIM>");
204
- try {
205
- return decodeURIComponent(t);
206
- } catch {
207
- return t;
208
- }
209
- }
210
- function R(e) {
211
- const t = e.search(/[?#]/);
212
- return t < 0 ? e : e.slice(0, t);
213
- }
214
- function L(e) {
215
- return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
216
- }
217
- class It {
218
- constructor(t) {
219
- f(this, "entries", /* @__PURE__ */ new Map());
220
- f(this, "objectUrls", /* @__PURE__ */ new Map());
221
- f(this, "objectUrlPaths", /* @__PURE__ */ new Map());
222
- /**
223
- * Reads that already failed, so a missing resource is not requested again by
224
- * the visual adapter after the reference prefetch has recorded it.
225
- */
226
- f(this, "failures", /* @__PURE__ */ new Map());
227
- this.source = t;
228
- const n = t.original;
229
- if (et(n))
230
- for (const i of n.files) this.entries.set(u(i.path), i.file);
231
- else typeof Blob < "u" && n instanceof Blob ? this.entries.set(t.entryPath ?? t.filename ?? "asset", n) : n instanceof ArrayBuffer ? this.entries.set(t.entryPath ?? t.filename ?? "asset", new Blob([n])) : typeof n == "object" && n !== null && "kind" in n && n.kind === "buffer" && this.entries.set(t.entryPath ?? t.filename ?? "asset", new Blob([n.buffer]));
232
- }
233
- paths() {
234
- return [...this.entries.keys()];
235
- }
236
- hasLocalFiles() {
237
- return this.entries.size > 0;
238
- }
239
- put(t, n) {
240
- this.entries.set(u(t), n);
241
- }
242
- relativePaths(t = "", n = !1) {
243
- return [...this.relativeEntries(t, n)].map(([i]) => i);
244
- }
245
- asSourceRecord(t = "", n = !1) {
246
- return Object.fromEntries(this.relativeEntries(t, n));
247
- }
248
- *relativeEntries(t = "", n = !1) {
249
- const i = u(t), s = i ? `${i}/` : "";
250
- for (const [o, r] of this.entries)
251
- if (!s || o.startsWith(s)) yield [s ? o.slice(s.length) : o, r];
252
- else if (n) {
253
- const l = i.split("/"), c = o.split("/");
254
- let a = 0;
255
- for (; a < l.length && l[a] === c[a]; ) a++;
256
- yield [[...l.slice(a).map(() => ".."), ...c.slice(a)].join("/"), r];
257
- }
258
- }
259
- resolve(t, n = "") {
260
- const i = this.find(t, n);
261
- if (i) return i;
262
- const s = u(n).split("/").slice(0, -1).join("/");
263
- if (this.source.url) return u(`${s}/${t.replace(/^package:\/\//, "")}`);
264
- throw d(`Simulation resource not found: ${t}`, "E_ASSET_RESOURCE_NOT_FOUND");
265
- }
266
- find(t, n = "") {
267
- const i = u(t.replace(/^package:\/\//, ""));
268
- if (_(i)) return this.entries.has(i) ? i : null;
269
- const s = u(n).split("/").slice(0, -1).join("/");
270
- for (const r of [u(`${s}/${t.replace(/^package:\/\//, "")}`), i])
271
- if (this.entries.has(r)) return r;
272
- const o = this.paths().filter(
273
- (r) => !_(r) && (r === i || r.endsWith(`/${i}`) || i.endsWith(`/${r}`))
274
- );
275
- return o.length === 1 ? o[0] : null;
276
- }
277
- async text(t) {
278
- await this.ensure(t);
279
- const n = this.entries.get(this.resolve(t));
280
- if (!n) throw d(`Simulation resource not found: ${t}`, "E_ASSET_RESOURCE_NOT_FOUND");
281
- return n.text();
282
- }
283
- async bytes(t) {
284
- await this.ensure(t);
285
- const n = this.entries.get(this.resolve(t));
286
- if (!n) throw d(`Simulation resource not found: ${t}`, "E_ASSET_RESOURCE_NOT_FOUND");
287
- return new Uint8Array(await n.arrayBuffer());
288
- }
289
- getBlob(t) {
290
- const n = this.resolve(t), i = this.entries.get(n);
291
- if (!i) throw d(`Simulation resource not found: ${t}`, "E_ASSET_RESOURCE_NOT_FOUND");
292
- return i;
293
- }
294
- async ensure(t) {
295
- const n = u(t);
296
- if (this.entries.has(n)) return;
297
- const i = this.failures.get(n);
298
- if (i) throw i;
299
- try {
300
- const s = await this.source.resolve(n);
301
- if (!/^https?:\/\//i.test(s) && !/^blob:/i.test(s))
302
- throw d(`Simulation resource not found: ${t}. Upload the complete asset folder or provide a resourceResolver/baseUrl.`, U);
303
- const o = await fetch(s, { signal: this.source.signal });
304
- if (!o.ok) {
305
- const c = o.status === 401 || o.status === 403 ? j : o.status === 404 || o.status === 410 ? U : v;
306
- throw d(`Simulation resource request failed (${o.status}): ${s}`, c);
307
- }
308
- const r = await o.blob();
309
- this.source.signal.throwIfAborted();
310
- const l = await k(r);
311
- if (l) throw d(`Simulation resource is not usable (${l}): ${s}`, P);
312
- this.entries.set(n, r);
313
- } catch (s) {
314
- throw x(s) === "aborted" || this.failures.set(n, s instanceof Error ? s : new Error(String(s))), s;
315
- }
316
- }
317
- /** The recorded failure for a resource, if a previous read already failed. */
318
- failureOf(t) {
319
- return this.failures.get(u(t));
320
- }
321
- objectUrl(t) {
322
- const n = this.resolve(t);
323
- let i = this.objectUrls.get(n);
324
- return i || (i = URL.createObjectURL(this.getBlob(n)), this.objectUrls.set(n, i), this.objectUrlPaths.set(i, n)), i;
325
- }
326
- pathForObjectUrl(t) {
327
- return this.objectUrlPaths.get(t) ?? null;
328
- }
329
- /**
330
- * Resolve a texture relative to the directory containing the entry layer.
331
- * Pass the entry directory, not the entry file path.
332
- */
333
- findTexture(t, n = "") {
334
- const i = this.findPresent(t, n);
335
- if (i) return i;
336
- const s = this.udimTextureSet(t);
337
- return (s == null ? void 0 : s.paths.length) === 1 ? s.paths[0] : null;
338
- }
339
- udimTextureSet(t) {
340
- return X(t, this.paths());
341
- }
342
- objectUrlIfPresent(t, n = "") {
343
- const i = this.findTexture(t, n);
344
- return i ? this.objectUrl(i) : null;
345
- }
346
- findPresent(t, n = "") {
347
- if (_(t)) return this.entries.has(t) ? t : null;
348
- const i = u(n), s = i ? `${i}/` : "", o = u(t), r = s ? this.paths().filter((l) => {
349
- if (!l.startsWith(s)) return !1;
350
- const c = l.slice(s.length);
351
- return c === o || o.endsWith(`/${c}`);
352
- }) : [];
353
- return r.length === 1 ? r[0] : this.find(t);
354
- }
355
- dispose() {
356
- for (const t of this.objectUrls.values()) URL.revokeObjectURL(t);
357
- this.objectUrls.clear(), this.objectUrlPaths.clear(), this.entries.clear(), this.failures.clear();
358
- }
359
- }
360
- async function St(e, t) {
361
- if (t.hasLocalFiles()) return t.text(e.entryPath ?? e.filename ?? t.paths()[0]);
362
- const n = await fetch(e.url ?? await e.resolve(e.entryPath ?? ""), { signal: e.signal });
363
- if (!n.ok) throw d(`Simulation asset request failed: ${n.status}`, "E_ASSET_FETCH");
364
- return n.text();
365
- }
366
- function bt(e) {
367
- return u(e);
368
- }
369
- function u(e) {
370
- if (_(e)) return e;
371
- const t = [];
372
- for (const n of e.replaceAll("\\", "/").split("/"))
373
- !n || n === "." || (n === ".." && t.length && t.at(-1) !== ".." ? t.pop() : t.push(n));
374
- return t.join("/");
375
- }
376
- function _(e) {
377
- return /^[a-z][a-z\d+.-]*:/i.test(e) && !/^package:\/\//i.test(e);
378
- }
379
- function et(e) {
380
- return typeof e == "object" && e !== null && "kind" in e && e.kind === "files";
381
- }
382
- function d(e, t) {
383
- return Object.assign(new Error(e), { code: t });
384
- }
385
- function Ot() {
386
- return { errors: [], warnings: [], approximations: [], droppedFeatures: [] };
387
- }
388
- function Ut(e, t = {}) {
389
- const n = Object.freeze({ schemaVersion: 1, ...e });
390
- return nt(n, t), n;
391
- }
392
- function nt(e, t = {}) {
393
- if (!e.id.trim() || !e.name.trim()) throw p("Asset IR id and name are required.", "E_ASSET_IR_INVALID");
394
- if (e.source.format !== "usd" && e.links.length === 0) throw p("Asset IR requires at least one link.", "E_ASSET_IR_INVALID");
395
- const n = /* @__PURE__ */ new Set();
396
- for (const s of e.links) {
397
- if (!s.id || n.has(s.id)) throw p(`Invalid or duplicate link: ${s.id}`, "E_ASSET_IR_INVALID");
398
- n.add(s.id);
399
- }
400
- const i = /* @__PURE__ */ new Set();
401
- for (const s of e.joints) {
402
- if (!s.id || i.has(s.id) || !t.allowInvalidGraph && (!n.has(s.parent) || !n.has(s.child)))
403
- throw p(`Invalid joint: ${s.id}`, "E_ASSET_IR_INVALID");
404
- i.add(s.id);
405
- }
406
- }
407
- function p(e, t) {
408
- return Object.assign(new Error(e), { code: t });
409
- }
410
- const C = 3073715, wt = 16758861, it = 0.96, st = 0.1, rt = 20, ot = 1;
411
- function Dt(e = C) {
412
- return new B({
413
- color: e,
414
- transparent: !0,
415
- opacity: it,
416
- depthTest: !1,
417
- depthWrite: !1,
418
- linewidth: 2,
419
- toneMapped: !1,
420
- fog: !1
421
- });
422
- }
423
- function gt(e = C) {
424
- return new F({
425
- color: e,
426
- transparent: !0,
427
- opacity: st,
428
- depthTest: !0,
429
- depthWrite: !1,
430
- side: $,
431
- polygonOffset: !0,
432
- polygonOffsetFactor: -1,
433
- polygonOffsetUnits: -1,
434
- toneMapped: !1,
435
- fog: !1
436
- });
437
- }
438
- function Rt(e, t, n = "feature", i) {
439
- const s = n === "mesh" ? new V(e) : at(e), o = new z(s, t);
440
- if (o.renderOrder = 9, i) {
441
- const r = new G(e.clone(), i);
442
- r.name = "collision-volume", r.renderOrder = 8, r.userData.collisionDebugRole = "volume", o.add(r), o.userData.collisionDebugRole = "outline";
443
- }
444
- return o;
445
- }
446
- function at(e) {
447
- let t = new m(e, rt);
448
- return N(e, t) || (t.dispose(), t = new m(e, ot)), N(e, t) || (t.dispose(), t = new m(e, 0)), t;
449
- }
450
- const lt = 256, ct = 0.5;
451
- function N(e, t) {
452
- var l, c;
453
- const n = t.getAttribute("position");
454
- if (!n || n.count === 0) return !1;
455
- const i = e.getAttribute("position");
456
- if (!i || i.count < lt) return !0;
457
- e.computeBoundingBox(), t.computeBoundingBox();
458
- const s = (l = e.boundingBox) == null ? void 0 : l.getSize(new w()), o = (c = t.boundingBox) == null ? void 0 : c.getSize(new w());
459
- if (!s || !o) return !1;
460
- const r = s.length();
461
- return !Number.isFinite(r) || r <= 0 ? !0 : o.length() / r >= ct;
462
- }
463
- export {
464
- wt as C,
465
- _t as S,
466
- gt as a,
467
- Rt as b,
468
- Dt as c,
469
- Ut as d,
470
- Ot as e,
471
- It as f,
472
- St as g,
473
- I as h,
474
- bt as n,
475
- pt as p,
476
- X as r,
477
- mt as u,
478
- Et as w
479
- };