@nebula-spatial/viewer 0.5.7 → 0.5.9

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.
@@ -2,8 +2,8 @@ var R = Object.defineProperty;
2
2
  var S = (a, t, e) => t in a ? R(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
3
3
  var s = (a, t, e) => S(a, typeof t != "symbol" ? t + "" : t, e);
4
4
  import * as i from "three";
5
- import { Quaternion as C, Vector3 as V } from "three";
6
- import { V as b, D as A, w as W } from "./index-BTAC6njT.js";
5
+ import { Quaternion as P, Vector3 as V } from "three";
6
+ import { V as b, D as A, w as W } from "./index-BQn4yVNd.js";
7
7
  import { disposeModelResources as T } from "./resources-CHhCm2f7.js";
8
8
  const v = 1, B = (
9
9
  /* glsl */
@@ -201,7 +201,7 @@ const G = {
201
201
  }, E = {
202
202
  simulation: 1.2,
203
203
  model: 1.2
204
- }, I = new C().setFromAxisAngle(new V(1, 0, 0), Math.PI / 2), D = new C();
204
+ }, I = new P().setFromAxisAngle(new V(1, 0, 0), Math.PI / 2), D = new P();
205
205
  function tt(a) {
206
206
  return a === "glb" || a === "gltf" || a === "fbx" ? "y" : "z";
207
207
  }
@@ -212,7 +212,7 @@ function et(a, t) {
212
212
  const e = F(t);
213
213
  return e.equals(a.quaternion) ? !1 : (a.quaternion.copy(e), a.updateMatrixWorld(!0), !0);
214
214
  }
215
- const m = 2213822, _ = 6000111, z = 6, x = 2e-3, U = 1e-4, N = 1e-4, H = 0.18, k = 0.35, q = 0.18, j = 0.75, Y = Math.PI / 3, y = new i.Vector3(), M = new i.Matrix4(), w = new i.Matrix4();
215
+ const m = 2213822, _ = 6000111, z = 6, x = 2e-3, U = 1e-4, N = 1e-4, k = 0.18, H = 0.35, q = 0.18, j = 0.75, Y = Math.PI / 3, y = new i.Vector3(), M = new i.Matrix4(), C = new i.Matrix4();
216
216
  function Q(a, t, e) {
217
217
  t.updateMatrixWorld();
218
218
  const r = new i.Vector3();
@@ -239,12 +239,12 @@ function X(a, t) {
239
239
  }
240
240
  if (t instanceof i.InstancedMesh) {
241
241
  for (let r = 0; r < t.count; r += 1)
242
- t.getMatrixAt(r, M), w.multiplyMatrices(t.matrixWorld, M), P(a, t, e.count, w);
242
+ t.getMatrixAt(r, M), C.multiplyMatrices(t.matrixWorld, M), w(a, t, e.count, C);
243
243
  return;
244
244
  }
245
- P(a, t, e.count, t.matrixWorld);
245
+ w(a, t, e.count, t.matrixWorld);
246
246
  }
247
- function P(a, t, e, r) {
247
+ function w(a, t, e, r) {
248
248
  for (let o = 0; o < e; o += 1)
249
249
  t.getVertexPosition(o, y), y.applyMatrix4(r), a.expandByPoint(y);
250
250
  }
@@ -298,12 +298,13 @@ class rt {
298
298
  s(this, "groundGrabBlend", 0);
299
299
  s(this, "groundCameraPoseValid", !1);
300
300
  s(this, "disposed", !1);
301
+ s(this, "invalidationCallback");
301
302
  this.model = t, this.runtime = r, this.presentation = o, this.groundPlacement = n ?? (o === "model" ? "visual" : "physics"), this.values = G[e];
302
303
  const l = this.values, u = p(t), d = Math.max(...u.getSize(new i.Vector3()).toArray());
303
304
  if (!Number.isFinite(d) || d <= 0) throw new Error("Empty simulation geometry.");
304
305
  this.modelWrapper.name = "simulation-model-wrapper", this.root.add(this.modelWrapper), this.modelWrapper.add(t), this.forceLine = this.createForceLine(), this.root.add(this.forceLine), t.traverse((g) => {
305
306
  g instanceof i.Mesh && g.layers.enable(v);
306
- }), this.root.add(this.reflector);
307
+ }), this.reflector.userData.hdrTransparentBackdrop = !1, this.root.add(this.reflector);
307
308
  const c = Math.max(u.getSize(new i.Vector3()).length() * 0.5, 0.02), h = this.reflector.material.uniforms;
308
309
  h.fineGridColor.value.setHex(l.fineGrid), h.coarseGridColor.value.setHex(l.coarseGrid), h.gridOpacity.value = l.gridOpacity, h.reflectionMix.value = l.reflectionMix, this.layoutGround(u, c), this.groundVisible = !0, this.setGroundVisible(this.groundVisible);
309
310
  const f = c / Math.sin(i.MathUtils.degToRad(38) / 2) * 1.25;
@@ -312,10 +313,14 @@ class rt {
312
313
  setRuntime(t) {
313
314
  this.disposed || this.runtime === t || (this.endGrab(), this.runtime = t, t && (this.groundPlacement = "physics"), this.bodyGroups.clear(), this.groundGrabFocusValid = !1, this.groundGrabBlend = 0, this.groundFollowDirty = !0, this.applyUpAxis());
314
315
  }
316
+ setCacheInvalidationCallback(t) {
317
+ this.invalidationCallback = t;
318
+ }
315
319
  replaceModel(t, e = !0) {
316
- this.disposed || t === this.model || (this.endGrab(), this.bodyGroups.clear(), this.model.removeFromParent(), this.model = t, this.modelWrapper.add(t), t.traverse((r) => {
317
- r instanceof i.Mesh && r.layers.enable(v);
318
- }), e && this.reseatGround());
320
+ var r;
321
+ this.disposed || t === this.model || (this.endGrab(), this.bodyGroups.clear(), this.model.removeFromParent(), this.model = t, this.modelWrapper.add(t), t.traverse((o) => {
322
+ o instanceof i.Mesh && o.layers.enable(v);
323
+ }), e && this.reseatGround(), (r = this.invalidationCallback) == null || r.call(this));
319
324
  }
320
325
  /**
321
326
  * Re-orients the scene to the given authored up axis. The rotation is a real
@@ -397,7 +402,7 @@ class rt {
397
402
  if (r)
398
403
  this.groundCenter.set(u, d);
399
404
  else {
400
- const g = this.groundInteractionActive ? k : H;
405
+ const g = this.groundInteractionActive ? H : k;
401
406
  this.groundCenter.x += c * g, this.groundCenter.y += h * g;
402
407
  }
403
408
  this.reflector.setRadius(e, this.groundGridScale, this.groundCenter), this.reflector.updateMatrixWorld(!0);
@@ -475,7 +480,7 @@ class rt {
475
480
  }
476
481
  beginGrab(t, e, r) {
477
482
  if (!this.runtime || this.disposed) return !1;
478
- this.pointerRay(t, e, r);
483
+ this.pointerRay(t, e, r), this.raycaster.firstHitOnly = !0;
479
484
  const o = this.raycaster.intersectObject(this.model, !0).find((d) => d.object.isMesh);
480
485
  if (!o) return !1;
481
486
  const n = this.findBodyGroup(o.object);
@@ -557,10 +562,12 @@ class rt {
557
562
  * anything the physics runtime drives is rotated inside the compiled model.
558
563
  */
559
564
  attachAuxiliary(t) {
560
- this.auxiliaries.add(t), this.modelWrapper.add(t);
565
+ var e;
566
+ this.auxiliaries.add(t), this.modelWrapper.add(t), (e = this.invalidationCallback) == null || e.call(this);
561
567
  }
562
568
  detachAuxiliary(t) {
563
- this.auxiliaries.delete(t) && t.removeFromParent();
569
+ var e;
570
+ this.auxiliaries.delete(t) && (t.removeFromParent(), (e = this.invalidationCallback) == null || e.call(this));
564
571
  }
565
572
  getModelBounds() {
566
573
  this.root.updateMatrixWorld(!0);
package/dist/types.d.ts CHANGED
@@ -20,10 +20,26 @@ export type ViewerNavigationPolicy = 'legacy' | 'viewer' | 'preview';
20
20
  export type ViewerPreviewDragPreset = 'left-rotate' | 'left-pan';
21
21
  export type CameraChangeReason = 'pointer' | 'wheel' | 'fit' | 'restore' | 'api' | 'view-mode';
22
22
  export type ViewerEnvironment = 'room' | {
23
- /** Load an external equirectangular HDR texture for image-based lighting. */
24
- readonly type: 'hdr';
23
+ /** Load an external equirectangular texture for image-based lighting. */
24
+ readonly type: 'hdr' | 'image';
25
25
  readonly url: string;
26
26
  };
27
+ export interface ViewerEnvironmentTexture {
28
+ readonly type: 'hdr' | 'image';
29
+ readonly url: string;
30
+ readonly name: string;
31
+ }
32
+ export interface ViewerEnvironmentState {
33
+ readonly available: boolean;
34
+ readonly active: 'default' | 'custom';
35
+ readonly backgroundVisible: boolean;
36
+ /** Shared environment/background yaw in degrees around Three.js' Y-up axis. */
37
+ readonly rotation: number;
38
+ readonly rotationAvailable: boolean;
39
+ readonly loading: boolean;
40
+ readonly defaultEnvironment: ViewerEnvironmentTexture | null;
41
+ readonly customEnvironment: ViewerEnvironmentTexture | null;
42
+ }
27
43
  export interface ViewerDocumentRect {
28
44
  readonly minX: number;
29
45
  readonly minY: number;
@@ -63,8 +79,24 @@ export interface ViewerOptions {
63
79
  alpha?: boolean;
64
80
  powerPreference?: WebGLPowerPreference;
65
81
  initialViewMode?: ViewerViewMode;
66
- /** Image-based lighting environment. Defaults to the built-in room environment. */
82
+ /** Equirectangular HDR/image lighting environment. Defaults to the built-in room environment. */
67
83
  environment?: ViewerEnvironment;
84
+ /** Shared environment/background yaw in degrees around Three.js' Y-up axis. */
85
+ environmentRotation?: number;
86
+ /**
87
+ * Opt into the HDR backdrop used by transparent surfaces and Three.js
88
+ * transmission. The native Three.js path remains unchanged when disabled.
89
+ * Defaults to false.
90
+ */
91
+ transparentHdrBackdrop?: boolean;
92
+ /** Blur applied while an HDR backdrop is enabled. Range 0..1, defaults to 0. */
93
+ transparentHdrBackdropBlurriness?: number;
94
+ /**
95
+ * `three` keeps the native Three.js transmission pipeline. Enabling
96
+ * `transparentHdrBackdrop` additionally injects the HDR behind transmission.
97
+ * `eevee-sphere-probe` always samples the scene environment through PMREM.
98
+ */
99
+ transmissionMode?: 'three' | 'eevee-sphere-probe';
68
100
  /** Pointer mapping for model/simulation previews. Defaults to `left-rotate`. */
69
101
  previewDragPreset?: ViewerPreviewDragPreset;
70
102
  autoSelectOnPick?: boolean;
@@ -183,6 +215,7 @@ export interface ViewerEventMap {
183
215
  'asset-change': AssetChangeEvent;
184
216
  'asset-error': AssetErrorEvent;
185
217
  'asset-control-change': AssetControlChangeEvent;
218
+ 'environment-change': ViewerEnvironmentState;
186
219
  }
187
220
  export interface Viewer {
188
221
  readonly viewport: HTMLElement;
@@ -211,6 +244,14 @@ export interface Viewer {
211
244
  execute(id: string, args?: unknown): boolean;
212
245
  has(id: string): boolean;
213
246
  };
247
+ readonly environment: {
248
+ getState(): ViewerEnvironmentState;
249
+ setBackgroundVisible(visible: boolean): boolean;
250
+ setRotation(degrees: number): boolean;
251
+ useDefault(): Promise<boolean>;
252
+ useCustom(): Promise<boolean>;
253
+ load(file: File): Promise<boolean>;
254
+ };
214
255
  openAsset(source: AssetSource, options?: OpenAssetOptions): AssetPreview;
215
256
  closeAsset(): Promise<void>;
216
257
  addObject(object: Object3D, options?: ViewerObjectOptions): void;
@@ -232,6 +273,8 @@ export interface Viewer {
232
273
  requestRender(): void;
233
274
  getActiveCamera(): import('three').Camera;
234
275
  setNavigationEnabled(enabled: boolean): void;
276
+ /** Changes HDR backdrop blur without rebuilding the scene. Values are clamped to 0..1. */
277
+ setTransparentHdrBackdropBlurriness(value: number): boolean;
235
278
  /** Switches the model/simulation preview pointer mapping at runtime. */
236
279
  setPreviewDragPreset(preset: ViewerPreviewDragPreset): void;
237
280
  dispose(): void;
@@ -16,6 +16,8 @@ export interface ViewerSceneUiParts {
16
16
  scaleRuler?: boolean;
17
17
  ground?: boolean;
18
18
  collision?: boolean;
19
+ environment?: boolean;
20
+ background?: boolean;
19
21
  theme?: boolean;
20
22
  }
21
23
  /** Shared UI configuration; asset-specific controls live in their named groups. */