@nebula-spatial/viewer 0.6.0 → 0.6.1

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/dist/index.d.ts CHANGED
@@ -22,7 +22,7 @@ export { USD_RESOURCE_AUTH, USD_RESOURCE_EXTERNAL_DENIED, USD_RESOURCE_FETCH, US
22
22
  export type { Disposable, ToolbarItem, ViewerState, ViewerInteractionHooks, ViewerContributionPoint, ViewerPlugin, ViewerPluginContext, ViewerPluginRegistry, } from './plugins';
23
23
  export { configureViewerText } from './cad/text';
24
24
  export type { ViewerTextBuilderOptions } from './cad/text';
25
- export type { CadBlockModel, CadDocumentHandle, CadDocumentUnits, CadFontResolver, CadFontRequest, CadResolvedFont, CadResolvedTextFont, CadTextWarmupOptions, CadHudModel, CadHudSnapshot, CadInspectorModel, CadInspectorSnapshot, CadLayerModel, CadLayerRow, CadBlockUsageRow, CadSessionPhase, CadWorldBounds, CadScaleRulerState, CadInsertDetails, CadInsertSelection, CadInsertSelectionId, CadTextDetails, CadTextSelection, CadTextSelectionId, CadSelection, CadHit, CadViewerSnapshot, CadLoadProgress, CadViewerErrorCode, CadViewerErrorEvent, CadLoadSource, CadOpenOptions, CadSessionLoadTiming, RenderDebugBreakdownEntry, SplitBlockLayerDetail, CadViewerCapability, ResolveTextFont, CadViewerEventMap, CameraStateStore, Viewer, ViewerEventMap, ViewerEnvironment, ViewerEnvironmentState, ViewerEnvironmentTexture, ViewerFitViewOptions, ViewerHighlightOptions, ViewerOptions, ViewerPickOptions, ViewerPickResult, ViewerPointerEvent, ViewerObjectOptions, ViewerPreviewDragPreset, ViewerCameraSnapshot, ViewerOrthographicSnapshot, ViewerOrbitSnapshot, ViewerRenderStats, ViewerDocumentRect, ViewerCadUiKeyboardOptions, ViewerUiOptions, ViewerCadUiParts, ViewerCadUiOptions, ViewerUiPreset, ViewerCadUiStateStore, ViewerUiTheme, ViewerViewMode, CadInteractionMode, CameraChangeReason, ViewerUiTokens, } from './types';
25
+ export type { CadBlockModel, CadDocumentHandle, CadDocumentUnits, CadFontResolver, CadFontRequest, CadResolvedFont, CadResolvedTextFont, CadTextWarmupOptions, CadHudModel, CadHudSnapshot, CadInspectorModel, CadInspectorSnapshot, CadLayerModel, CadLayerRow, CadBlockUsageRow, CadSessionPhase, CadWorldBounds, CadScaleRulerState, CadInsertDetails, CadInsertSelection, CadInsertSelectionId, CadTextDetails, CadTextSelection, CadTextSelectionId, CadSelection, CadHit, CadViewerSnapshot, CadLoadProgress, CadViewerErrorCode, CadViewerErrorEvent, CadLoadSource, CadOpenOptions, CadSessionLoadTiming, RenderDebugBreakdownEntry, SplitBlockLayerDetail, CadViewerCapability, ResolveTextFont, CadViewerEventMap, CameraStateStore, Viewer, ViewerEventMap, ViewerEnvironment, ViewerEnvironmentState, ViewerEnvironmentTexture, ViewerFitViewOptions, ViewerHighlightOptions, ViewerOptions, ViewerPickOptions, ViewerPickResult, ViewerPointerEvent, ViewerObjectOptions, ViewerPreviewDragPreset, ViewerCameraSnapshot, ViewerOrthographicSnapshot, ViewerOrbitSnapshot, ViewerRenderStats, ViewerRenderEffect, ViewerRenderEffectContext, ViewerDocumentRect, ViewerCadUiKeyboardOptions, ViewerUiOptions, ViewerCadUiParts, ViewerCadUiOptions, ViewerUiPreset, ViewerCadUiStateStore, ViewerUiTheme, ViewerViewMode, CadInteractionMode, CameraChangeReason, ViewerUiTokens, } from './types';
26
26
  export type { JointInspection, JointInspectionJoint, JointInspectionSnapshot, AssetInspection, UrdfEntityKind, UrdfInspection, UrdfInspectionEntity, UrdfInspectionIssue, UrdfInspectionJoint, UrdfInspectionLink, UrdfInspectionMode, UrdfInspectionNode, UrdfInspectionOverlays, UrdfInspectionRobot, UrdfInspectionSnapshot, UrdfSourceRange } from './inspection/types';
27
27
  /**
28
28
  * Multi-asset scene authoring. A scene owns one stage and several placed
@@ -34,7 +34,7 @@ export { createSceneSession, findInstanceId } from './scene/session';
34
34
  export type { SceneSessionDeps } from './scene/session';
35
35
  export { clampJointValue, createSceneInstanceJoints, isSceneScalarJoint, jointBlockReason, toSceneJointDescriptor, } from './scene/joints';
36
36
  export type { JointInspectionSource, SceneInstanceJoints, SceneJointBlockReason, SceneJointDescriptor, SceneJointPose, SceneJointSnapshot, SceneJointState, } from './scene/joints';
37
- export type { SceneControl, SceneDeterministicCheckOptions, SceneDeterministicCheckResult, SceneEntry, SceneInspectionOverlay, SceneInstanceBounds, SceneInstancePhysics, SceneInstanceRuntime, SceneInstanceSnapshot, SceneInstancePhase, SceneOptions, ScenePhysicsConfiguration, ScenePhysicsState, ScenePlacement, SceneSnapshot, Vec3Like, } from './scene/types';
37
+ export type { SceneControl, SceneDeterministicCheckOptions, SceneDeterministicCheckResult, SceneEntry, SceneInspectionOverlay, SceneInstanceBounds, SceneInstancePhysics, SceneInstanceRuntime, SceneInstanceSnapshot, SceneInstancePhase, SceneOptions, ScenePhysicsConfiguration, ScenePhysicsState, ScenePlacement, ScenePlacementCommitOptions, SceneSnapshot, Vec3Like, } from './scene/types';
38
38
  export type { PhysicsBodyMotionType, PhysicsRuntimeBodyState, PhysicsRuntimeCaptureOptions, PhysicsRuntimeContactState, PhysicsRuntimeGrabState, PhysicsRuntimeJointState, PhysicsRuntimeSnapshot, } from './simulation/physics-runtime-state';
39
39
  export type { UsdInspectionJoint, UsdInspectionMaterial, UsdInspectionMesh, UsdInspectionPrim, UsdInspectionSnapshot, UsdInspectionStage, UsdInspectionVariantSet, } from './simulation/usd-inspection';
40
40
  export type { ViewerCaptureOptions, ViewerCaptureResult } from './types';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { D as s, I as o, V as r, J as n, U as t, H as i, W as c, X as U, Y as d, Z as S, _ as E, $ as _, a0 as D, a1 as l, a2 as R, L as m, a3 as p, a4 as u, m as C, a5 as O, a6 as I, a7 as V, a8 as G, a9 as T, aa as f, ab as N } from "./index-DoxM1Msk.js";
1
+ import { D as s, I as o, V as r, J as n, U as t, H as i, W as c, X as U, Y as d, Z as S, _ as E, $ as _, a0 as D, a1 as l, a2 as R, L as m, a3 as p, a4 as u, m as C, a5 as O, a6 as I, a7 as V, a8 as G, a9 as T, aa as f, ab as N } from "./index-CHf9y9eX.js";
2
2
  import { configureCadTextBuilder as x } from "@nebula-spatial/cad-loader";
3
3
  export {
4
4
  s as DEFAULT_GROUND_GRID_SCALE,
@@ -1,4 +1,4 @@
1
- import { O as v, T as E, d as z } from "./index-DoxM1Msk.js";
1
+ import { O as v, T as E, d as z } from "./index-CHf9y9eX.js";
2
2
  import { Group as q, Euler as G, BoxGeometry as N, SphereGeometry as P, CylinderGeometry as $, CapsuleGeometry as I, PlaneGeometry as X, Mesh as j } from "three";
3
3
  function D(f) {
4
4
  const y = f.extension.documents, l = new q();
@@ -3,7 +3,7 @@ var B = (p, t, e) => t in p ? P(p, t, { enumerable: !0, configurable: !0, writab
3
3
  var j = (p, t, e) => B(p, typeof t != "symbol" ? t + "" : t, e);
4
4
  import L from "@mujoco/mujoco";
5
5
  import { Quaternion as D, Vector3 as w } from "three";
6
- import { e as C, y as R } from "./index-DoxM1Msk.js";
6
+ import { e as C, y as R } from "./index-CHf9y9eX.js";
7
7
  let V = 0;
8
8
  function z(p, t) {
9
9
  const e = `/viewer-simulation-${++V}`;
@@ -28,6 +28,14 @@ export interface ScenePlacement {
28
28
  readonly pivot?: Vec3Like;
29
29
  readonly visible?: boolean;
30
30
  }
31
+ export interface ScenePlacementCommitOptions {
32
+ /**
33
+ * Updates the rendered pose immediately and rebuilds physics in the
34
+ * background. Authoring gestures use this so pointer release is not blocked
35
+ * by MuJoCo compilation.
36
+ */
37
+ readonly deferPhysics?: boolean;
38
+ }
31
39
  /** One asset instance placed in the scene. */
32
40
  export interface SceneEntry {
33
41
  /** Stable caller-chosen id echoed back by instance-level commands. */
@@ -176,10 +184,10 @@ export interface SceneControl {
176
184
  getSnapshot(): SceneSnapshot;
177
185
  subscribe(listener: (snapshot: SceneSnapshot) => void): () => void;
178
186
  /**
179
- * Replaces one loaded instance placement and resolves after the shared scene
180
- * physics world has been rebuilt for the committed pose.
187
+ * Replaces one loaded instance placement. By default it resolves after the
188
+ * shared scene physics world has been rebuilt for the committed pose.
181
189
  */
182
- setInstancePlacement(id: string, placement: ScenePlacement): Promise<boolean>;
190
+ setInstancePlacement(id: string, placement: ScenePlacement, options?: ScenePlacementCommitOptions): Promise<boolean>;
183
191
  /** Update the unified collision overlay for an uncommitted instance pose. */
184
192
  previewInstancePlacement(id: string, placement: ScenePlacement): boolean;
185
193
  /** Adds an instance at runtime; resolves once it is loaded or failed. */
@@ -0,0 +1,240 @@
1
+ import { Group as O, MeshStandardMaterial as Z, Mesh as z, PointsMaterial as H, Points as j, Color as J, Box3 as $, Vector3 as b, MeshBasicMaterial as Q, BoxGeometry as q } from "three";
2
+ import { PLYLoader as X } from "three/examples/jsm/loaders/PLYLoader.js";
3
+ import { S as ee, a as x } from "./spark.module-kM8pwA1o.js";
4
+ import { L as te, A as _, B as ne, D as ie } from "./index-CHf9y9eX.js";
5
+ import { a as re, r as ae } from "./spark-renderer-BGF_AaI9.js";
6
+ function xe(t, e) {
7
+ let u = !1, s = null, c = null, i = null, o = null, w = null, d = null, h = null, r = null, v = "unsupported", B = null, F = null, k = null, S = "y", G;
8
+ const V = P(), T = () => {
9
+ u = !0;
10
+ }, U = () => {
11
+ h && (ae(h), h = null);
12
+ }, Y = (n, f) => {
13
+ (h == null ? void 0 : h.scene) !== f && (U(), h = re(n, f, e.requestRender));
14
+ }, E = (async () => {
15
+ var C, N, R, D, L, W;
16
+ const n = await le(t);
17
+ if (u || e.signal.aborted) throw I();
18
+ const f = t.entryPath ?? t.filename, p = te(n, f, e.format);
19
+ if (p.kind === "unsupported")
20
+ throw new Error(`Unsupported visual asset: ${p.reason}`);
21
+ v = p.kind;
22
+ const A = new O();
23
+ A.name = "viewer-visual-root";
24
+ const m = new O();
25
+ if (m.name = "viewer-visual-content", p.kind === "glb" || p.kind === "gltf")
26
+ throw new Error("GLB/glTF is handled by the model loader.");
27
+ if (p.kind === "ply-mesh" || p.kind === "ply-point-cloud") {
28
+ const l = new X().parse(me(n));
29
+ if (l.computeBoundingBox(), !l.boundingBox || l.boundingBox.isEmpty())
30
+ throw l.dispose(), new Error("PLY does not contain displayable vertex data.");
31
+ if (p.kind === "ply-mesh") {
32
+ const a = l.hasAttribute("color"), y = new Z({
33
+ color: a ? 16777215 : 10135733,
34
+ vertexColors: a,
35
+ roughness: 0.82,
36
+ metalness: 0.04
37
+ }), g = new z(l, y);
38
+ g.name = "viewer-visual-ply-mesh", m.add(g);
39
+ } else {
40
+ const a = l.hasAttribute("color"), y = new H({
41
+ color: a ? 16777215 : 10934783,
42
+ vertexColors: a,
43
+ size: Math.max(4e-3, de(l.boundingBox) * 3e-3),
44
+ sizeAttenuation: !0
45
+ }), g = new j(l, y);
46
+ g.name = "viewer-visual-ply-points", m.add(g);
47
+ }
48
+ B = null;
49
+ } else {
50
+ const l = ue(p.kind), a = new ee({
51
+ fileBytes: n,
52
+ fileType: l,
53
+ fileName: f ?? `visual.${l}`,
54
+ raycastable: e.options.visualSelectionMode === "exact"
55
+ });
56
+ if (await a.initialized, u || e.signal.aborted)
57
+ throw a.dispose(), I();
58
+ if (a.name = "viewer-visual-splat", a.position.set(0, 0, 0), (C = e.options.visualAppearance) != null && C.color && (a.recolor = new J(...e.options.visualAppearance.color)), ((N = e.options.visualAppearance) == null ? void 0 : N.opacity) !== void 0 && (a.opacity = e.options.visualAppearance.opacity), m.add(a), o = a, B = ((R = a.packedSplats) == null ? void 0 : R.numSplats) ?? ((D = a.extSplats) == null ? void 0 : D.numSplats) ?? ((L = a.paged) == null ? void 0 : L.numSplats) ?? ((W = a.splats) == null ? void 0 : W.getNumSplats()) ?? null, w = pe(a), w.isEmpty()) throw new Error("Gaussian asset has empty bounds.");
59
+ }
60
+ if (S = e.options.upAxis ?? oe(p.kind), _(m, S), A.add(m), m.updateMatrixWorld(!0), r = new $().setFromObject(m), o && w && (o.updateWorldMatrix(!0, !1), r.union(w.clone().applyMatrix4(o.matrixWorld))), r.isEmpty()) throw new Error("Visual asset has no displayable bounds.");
61
+ if (o && e.options.visualSelectionMode !== "exact") {
62
+ const l = r.getSize(new b()), a = new Q({
63
+ transparent: !0,
64
+ // The scene picker filters fully transparent materials, while colorWrite
65
+ // keeps this raycastable proxy invisible in the rendered frame.
66
+ opacity: 1,
67
+ colorWrite: !1,
68
+ depthTest: !1,
69
+ depthWrite: !1
70
+ }), y = new z(new q(l.x, l.y, l.z), a), g = r.getCenter(new b());
71
+ y.position.copy(g), y.name = "viewer-visual-bounds-proxy", y.userData.viewerVisualBoundsProxy = !0, A.add(y), d = y;
72
+ }
73
+ se(A);
74
+ const M = new ne(
75
+ A,
76
+ e.options.simulationTheme,
77
+ void 0,
78
+ "model"
79
+ );
80
+ M.setCacheInvalidationCallback(e.invalidateTransmissionCaches), i = M, s = M.root, c = m, k = P() - V;
81
+ })();
82
+ return E.catch((n) => {
83
+ F = n instanceof Error ? n.message : String(n), k = P() - V;
84
+ }), {
85
+ id: `visual-${Math.random().toString(36).slice(2)}`,
86
+ opened: E,
87
+ get root() {
88
+ return s;
89
+ },
90
+ get fitTarget() {
91
+ return r;
92
+ },
93
+ getFitBounds() {
94
+ return r;
95
+ },
96
+ capabilities: {
97
+ canPlay: !1,
98
+ canPause: !1,
99
+ canReset: !1,
100
+ hasPhysics: !1,
101
+ canReorientUpAxis: !0,
102
+ canToggleGround: !0
103
+ },
104
+ presentation: {
105
+ preferredViewMode: "3d",
106
+ interactionMode: "object",
107
+ uiProfile: "model",
108
+ fitPolicy: "fit-on-ready"
109
+ },
110
+ getUpAxis() {
111
+ return c ? S : null;
112
+ },
113
+ setUpAxis(n) {
114
+ u || !c || _(c, n) && (S = n, c.updateMatrixWorld(!0), r = new $().setFromObject(c), o && w && (o.updateWorldMatrix(!0, !1), r.union(w.clone().applyMatrix4(o.matrixWorld))), K(), i == null || i.reseatGround(), e.requestRender());
115
+ },
116
+ setGroundVisible(n) {
117
+ i == null || i.setGroundVisible(n);
118
+ },
119
+ getGroundVisible() {
120
+ return (i == null ? void 0 : i.getGroundVisible()) ?? !1;
121
+ },
122
+ getGroundGridScale() {
123
+ return (i == null ? void 0 : i.getGroundGridScale()) ?? ie;
124
+ },
125
+ beforeRender(n, f, p) {
126
+ return !u && o && Y(n, f), i == null ? void 0 : i.beforeRender(n, f, p);
127
+ },
128
+ getVisualDiagnostics() {
129
+ const n = (r == null ? void 0 : r.getSize(new b())) ?? new b();
130
+ return {
131
+ schemaVersion: 1,
132
+ backend: o ? "spark-2.4.0" : v === "ply-point-cloud" ? "three-points" : "three-mesh",
133
+ kind: v,
134
+ splatCount: B,
135
+ bounds: r ? {
136
+ min: [r.min.x, r.min.y, r.min.z],
137
+ max: [r.max.x, r.max.y, r.max.z],
138
+ size: [n.x, n.y, n.z]
139
+ } : null,
140
+ upAxis: S,
141
+ loadMilliseconds: k,
142
+ error: F
143
+ };
144
+ },
145
+ beginDispose() {
146
+ T();
147
+ },
148
+ dispose() {
149
+ return T(), G ?? (G = E.catch(() => {
150
+ }).then(() => {
151
+ if (d == null || d.geometry.dispose(), d)
152
+ for (const n of Array.isArray(d.material) ? d.material : [d.material]) n.dispose();
153
+ d = null, o == null || o.dispose(), o = null, w = null, i ? i.dispose() : s && ce(s), i = null, s = null, c = null, U();
154
+ })), G;
155
+ }
156
+ };
157
+ function K() {
158
+ if (!d || !r) return;
159
+ const n = r.getSize(new b()), f = r.getCenter(new b());
160
+ d.geometry.dispose(), d.geometry = new q(n.x, n.y, n.z), d.position.copy(f);
161
+ }
162
+ }
163
+ function se(t) {
164
+ t.traverse((e) => {
165
+ e instanceof z && (e.userData.hdrTransparentBackdrop = !1);
166
+ });
167
+ }
168
+ function oe(t) {
169
+ return t.startsWith("gaussian-") ? "y-down" : "y";
170
+ }
171
+ async function le(t) {
172
+ if (t.entryBlob)
173
+ return new Uint8Array(await t.entryBlob.arrayBuffer());
174
+ const e = t.original;
175
+ if (typeof Blob < "u" && e instanceof Blob)
176
+ return new Uint8Array(await e.arrayBuffer());
177
+ if (e instanceof ArrayBuffer) return new Uint8Array(e);
178
+ if (typeof e == "object" && e !== null && "kind" in e) {
179
+ if (e.kind === "buffer") return new Uint8Array(e.buffer);
180
+ if (e.kind === "files") {
181
+ const c = t.entryPath ?? e.entry, i = e.files.find((o) => o.path === c) ?? (e.files.length === 1 ? e.files[0] : null);
182
+ if (i) return new Uint8Array(await i.file.arrayBuffer());
183
+ }
184
+ }
185
+ const u = t.url ?? await t.resolve(t.entryPath ?? ""), s = await fetch(u, { signal: t.signal });
186
+ if (!s.ok) throw new Error(`Visual asset request failed: ${s.status} ${s.statusText}`);
187
+ return new Uint8Array(await s.arrayBuffer());
188
+ }
189
+ function ue(t) {
190
+ switch (t) {
191
+ case "gaussian-ply":
192
+ return x.PLY;
193
+ case "gaussian-spz":
194
+ return x.SPZ;
195
+ case "gaussian-splat":
196
+ return x.SPLAT;
197
+ case "gaussian-ksplat":
198
+ return x.KSPLAT;
199
+ case "gaussian-sog":
200
+ return x.PCSOGSZIP;
201
+ case "gaussian-rad":
202
+ return x.RAD;
203
+ default:
204
+ throw new Error(`Not a Gaussian format: ${t}`);
205
+ }
206
+ }
207
+ function de(t) {
208
+ return t.getSize(new b()).length();
209
+ }
210
+ function pe(t) {
211
+ const e = t.getBoundingBox(!0);
212
+ return fe(e) || (e.makeEmpty(), t.forEachSplat((u, s) => {
213
+ Number.isFinite(s.x) && Number.isFinite(s.y) && Number.isFinite(s.z) && e.expandByPoint(s);
214
+ })), e;
215
+ }
216
+ function fe(t) {
217
+ return !t.isEmpty() && Number.isFinite(t.min.x) && Number.isFinite(t.min.y) && Number.isFinite(t.min.z) && Number.isFinite(t.max.x) && Number.isFinite(t.max.y) && Number.isFinite(t.max.z);
218
+ }
219
+ function ce(t) {
220
+ t.traverse((e) => {
221
+ "geometry" in e && e.geometry && typeof e.geometry.dispose == "function" && e.geometry.dispose();
222
+ const u = "material" in e ? e.material : null;
223
+ for (const s of Array.isArray(u) ? u : u ? [u] : []) s.dispose();
224
+ });
225
+ }
226
+ function me(t) {
227
+ const e = new Uint8Array(t.byteLength);
228
+ return e.set(t), e.buffer;
229
+ }
230
+ function I() {
231
+ return Object.assign(new Error("Visual asset load aborted."), { name: "AbortError", code: "E_ABORTED" });
232
+ }
233
+ function P() {
234
+ return typeof performance > "u" ? Date.now() : performance.now();
235
+ }
236
+ export {
237
+ xe as createVisualSession,
238
+ oe as defaultVisualAssetUpAxis,
239
+ se as excludeVisualSessionFromHdrBackdrop
240
+ };