@selvajs/visualization 1.8.0-beta.5 → 1.8.0-beta.6

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/render.d.cts CHANGED
@@ -291,6 +291,17 @@ type EventConfig = {
291
291
  */
292
292
  type ViewPreset = 'top' | 'bottom' | 'front' | 'back' | 'left' | 'right' | 'iso';
293
293
  type CameraProjection = 'perspective' | 'orthographic';
294
+ /**
295
+ * A view a host saves and restores, as plain arrays so it serializes as is. Without `position`
296
+ * and `target` (or with either not three numbers) only `direction` counts: the camera looks along
297
+ * it and frames the content, so the view keeps its angle when the model changes size.
298
+ */
299
+ interface CameraView {
300
+ /** From the target towards the camera. */
301
+ direction: number[];
302
+ position?: number[];
303
+ target?: number[];
304
+ }
294
305
  interface CameraController {
295
306
  /** Swaps identity on {@link setProjection}. */
296
307
  getActiveCamera(): THREE.Camera;
@@ -303,6 +314,10 @@ interface CameraController {
303
314
  * named preset — used by the nav-cube, whose clicked axis is a world axis.
304
315
  */
305
316
  setViewDirection(direction: THREE.Vector3, animate?: boolean): void;
317
+ /** The current view: direction, exact position and target. */
318
+ getCameraView(): CameraView;
319
+ /** Restores a {@link CameraView}; one without a usable direction falls back to `iso`. */
320
+ setCameraView(view: CameraView, animate?: boolean): void;
306
321
  /** Frame a world-space box from the current view direction. No-op on an empty box. */
307
322
  frameBounds(box: THREE.Box3, animate?: boolean): void;
308
323
  setRotateEnabled(enabled: boolean): void;
@@ -636,5 +651,5 @@ export declare function isHostOwned(object: THREE.Object3D): boolean;
636
651
  export declare function isOwnedBy(object: THREE.Object3D, id?: string): boolean;
637
652
  /** Replaces scene content with `meshes`, rescales the camera frustum to fit, and (first call only) positions the camera/controls. */
638
653
  export declare function updateScene(scene: THREE.Scene, meshes: THREE.Object3D[], camera: THREE.PerspectiveCamera, controls: OrbitControls, initialPositionSet: boolean): void;
639
- export { type CameraConfig, type CameraController, type CameraProjection, type ControlsConfig, type EdgesConfig, type EnvironmentConfig, type ErrorCode, type EventConfig, type FloorConfig, type GizmoConfig, type Grid, type GridConfig, LOOKS, type LabelHandle, type LabelLayer, type LightingConfig, type Logger, type Look, type LookMaterialOverride, type LookPreset, type MaterialAppearanceOptions, type MeasureConfig, type MeasureTool, type PointerTool, type RenderConfig, type SetLookOptions, type ThreeInitializerOptions, type ThreeViewer, type ToolRegistration, type ToolRegistry, type ViewGizmo, type ViewPreset };
654
+ export { type CameraConfig, type CameraController, type CameraProjection, type CameraView, type ControlsConfig, type EdgesConfig, type EnvironmentConfig, type ErrorCode, type EventConfig, type FloorConfig, type GizmoConfig, type Grid, type GridConfig, LOOKS, type LabelHandle, type LabelLayer, type LightingConfig, type Logger, type Look, type LookMaterialOverride, type LookPreset, type MaterialAppearanceOptions, type MeasureConfig, type MeasureTool, type PointerTool, type RenderConfig, type SetLookOptions, type ThreeInitializerOptions, type ThreeViewer, type ToolRegistration, type ToolRegistry, type ViewGizmo, type ViewPreset };
640
655
  //# sourceMappingURL=render.d.cts.map
package/dist/render.d.ts CHANGED
@@ -291,6 +291,17 @@ type EventConfig = {
291
291
  */
292
292
  type ViewPreset = 'top' | 'bottom' | 'front' | 'back' | 'left' | 'right' | 'iso';
293
293
  type CameraProjection = 'perspective' | 'orthographic';
294
+ /**
295
+ * A view a host saves and restores, as plain arrays so it serializes as is. Without `position`
296
+ * and `target` (or with either not three numbers) only `direction` counts: the camera looks along
297
+ * it and frames the content, so the view keeps its angle when the model changes size.
298
+ */
299
+ interface CameraView {
300
+ /** From the target towards the camera. */
301
+ direction: number[];
302
+ position?: number[];
303
+ target?: number[];
304
+ }
294
305
  interface CameraController {
295
306
  /** Swaps identity on {@link setProjection}. */
296
307
  getActiveCamera(): THREE.Camera;
@@ -303,6 +314,10 @@ interface CameraController {
303
314
  * named preset — used by the nav-cube, whose clicked axis is a world axis.
304
315
  */
305
316
  setViewDirection(direction: THREE.Vector3, animate?: boolean): void;
317
+ /** The current view: direction, exact position and target. */
318
+ getCameraView(): CameraView;
319
+ /** Restores a {@link CameraView}; one without a usable direction falls back to `iso`. */
320
+ setCameraView(view: CameraView, animate?: boolean): void;
306
321
  /** Frame a world-space box from the current view direction. No-op on an empty box. */
307
322
  frameBounds(box: THREE.Box3, animate?: boolean): void;
308
323
  setRotateEnabled(enabled: boolean): void;
@@ -636,5 +651,5 @@ export declare function isHostOwned(object: THREE.Object3D): boolean;
636
651
  export declare function isOwnedBy(object: THREE.Object3D, id?: string): boolean;
637
652
  /** Replaces scene content with `meshes`, rescales the camera frustum to fit, and (first call only) positions the camera/controls. */
638
653
  export declare function updateScene(scene: THREE.Scene, meshes: THREE.Object3D[], camera: THREE.PerspectiveCamera, controls: OrbitControls, initialPositionSet: boolean): void;
639
- export { type CameraConfig, type CameraController, type CameraProjection, type ControlsConfig, type EdgesConfig, type EnvironmentConfig, type ErrorCode, type EventConfig, type FloorConfig, type GizmoConfig, type Grid, type GridConfig, LOOKS, type LabelHandle, type LabelLayer, type LightingConfig, type Logger, type Look, type LookMaterialOverride, type LookPreset, type MaterialAppearanceOptions, type MeasureConfig, type MeasureTool, type PointerTool, type RenderConfig, type SetLookOptions, type ThreeInitializerOptions, type ThreeViewer, type ToolRegistration, type ToolRegistry, type ViewGizmo, type ViewPreset };
654
+ export { type CameraConfig, type CameraController, type CameraProjection, type CameraView, type ControlsConfig, type EdgesConfig, type EnvironmentConfig, type ErrorCode, type EventConfig, type FloorConfig, type GizmoConfig, type Grid, type GridConfig, LOOKS, type LabelHandle, type LabelLayer, type LightingConfig, type Logger, type Look, type LookMaterialOverride, type LookPreset, type MaterialAppearanceOptions, type MeasureConfig, type MeasureTool, type PointerTool, type RenderConfig, type SetLookOptions, type ThreeInitializerOptions, type ThreeViewer, type ToolRegistration, type ToolRegistry, type ViewGizmo, type ViewPreset };
640
655
  //# sourceMappingURL=render.d.ts.map
package/dist/render.js CHANGED
@@ -852,6 +852,40 @@ function createCameraController(deps) {
852
852
  const setView = (preset, animate = true) => {
853
853
  setViewDirection(VIEW_DIRECTIONS[preset], animate);
854
854
  };
855
+ const getCameraView = () => {
856
+ const target = controls.target;
857
+ const offset = active().position.clone().sub(target);
858
+ if (offset.lengthSq() < 1e-12) offset.copy(VIEW_DIRECTIONS.iso);
859
+ if (projection === "orthographic") offset.divideScalar(ortho.zoom);
860
+ return {
861
+ direction: rounded(offset.clone().normalize()),
862
+ position: rounded(target.clone().add(offset)),
863
+ target: rounded(target)
864
+ };
865
+ };
866
+ const setCameraView = (view, animate = false) => {
867
+ const position = toVector(view.position);
868
+ const target = toVector(view.target);
869
+ if (position && target && position.distanceToSquared(target) > 1e-12) {
870
+ cancelTween();
871
+ const cam = active();
872
+ if (projection === "orthographic") ortho.zoom = 1;
873
+ if (animate) {
874
+ activeTween = animateMove(cam, controls, position, target, () => {
875
+ if (projection === "orthographic") syncOrthoFrustum();
876
+ });
877
+ return;
878
+ }
879
+ cam.position.copy(position);
880
+ controls.target.copy(target);
881
+ if (projection === "orthographic") syncOrthoFrustum();
882
+ controls.update();
883
+ return;
884
+ }
885
+ const direction = toVector(view.direction);
886
+ if (direction && direction.lengthSq() > 1e-12) setViewDirection(direction.normalize(), animate);
887
+ else setView("iso", animate);
888
+ };
855
889
  const setRotateEnabled = (enabled) => {
856
890
  controls.enableRotate = enabled;
857
891
  };
@@ -869,6 +903,8 @@ function createCameraController(deps) {
869
903
  },
870
904
  setView,
871
905
  setViewDirection,
906
+ getCameraView,
907
+ setCameraView,
872
908
  frameBounds,
873
909
  setRotateEnabled,
874
910
  isRotateEnabled: () => controls.enableRotate,
@@ -876,6 +912,12 @@ function createCameraController(deps) {
876
912
  dispose: cancelTween
877
913
  };
878
914
  }
915
+ const rounded = (v) => [
916
+ v.x,
917
+ v.y,
918
+ v.z
919
+ ].map((n) => Math.round(n * 1e6) / 1e6);
920
+ const toVector = (values) => values?.length === 3 && values.every(Number.isFinite) ? new THREE.Vector3(values[0], values[1], values[2]) : void 0;
879
921
  /**
880
922
  * Nudges a top/bottom view direction a ~0.5° tilt off the up axis; other presets pass through
881
923
  * unchanged. Looking exactly down `up` is an OrbitControls singularity: camera direction coincides