vim-web 0.3.44-dev.17 → 0.3.44-dev.19

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/vim-web.js CHANGED
@@ -50648,7 +50648,7 @@ class CameraLerp extends CameraMovement {
50648
50648
  }
50649
50649
  init(duration) {
50650
50650
  this.cancel();
50651
- this._duration = duration;
50651
+ this._duration = Math.max(duration, 0.01);
50652
50652
  this._clock.start();
50653
50653
  }
50654
50654
  cancel() {
@@ -50969,6 +50969,7 @@ let Camera$1 = class Camera2 {
50969
50969
  * @returns {CameraMovement} The camera movement api.
50970
50970
  */
50971
50971
  lerp(duration = 1, force = false) {
50972
+ if (duration <= 0) return this.snap(force);
50972
50973
  this.stop();
50973
50974
  this._force = force;
50974
50975
  this._lerp.init(duration);
@@ -51870,10 +51871,10 @@ class MouseHandler extends InputHandler$1 {
51870
51871
  });
51871
51872
  __publicField(this, "onMouseUp", (event) => {
51872
51873
  event.stopImmediatePropagation();
51874
+ event.preventDefault();
51873
51875
  const btn = this.getButton(event);
51874
51876
  if (btn === this._buttonDown) return;
51875
51877
  this._viewer.gizmos.rectangle.visible = false;
51876
- event.preventDefault();
51877
51878
  if (!this._buttonDown) return;
51878
51879
  if (this.inputs.pointerActive === "rect" && this._hasMouseMoved && !this._hasCameraMoved) {
51879
51880
  this.onRectEnd();
@@ -51890,6 +51891,7 @@ class MouseHandler extends InputHandler$1 {
51890
51891
  this.inputs.pointerOverride = void 0;
51891
51892
  });
51892
51893
  __publicField(this, "onDoubleClick", (event) => {
51894
+ console.log("Double click");
51893
51895
  event.stopImmediatePropagation();
51894
51896
  this.onMouseClick(
51895
51897
  new Vector2(event.offsetX, event.offsetY),
@@ -55453,6 +55455,7 @@ class SectionBoxHandle extends Mesh {
55453
55455
  __publicField(this, "_color");
55454
55456
  __publicField(this, "_highlightColor");
55455
55457
  __publicField(this, "_materials");
55458
+ __publicField(this, "_camera");
55456
55459
  __publicField(this, "_camSub");
55457
55460
  this._materials = [matAlways, matBehind];
55458
55461
  this._forward = new Vector3();
@@ -55465,15 +55468,18 @@ class SectionBoxHandle extends Mesh {
55465
55468
  this.quaternion.setFromUnitVectors(new Vector3(0, -1, 0), this._forward);
55466
55469
  }
55467
55470
  trackCamera(camera2) {
55468
- const rescale = () => {
55469
- const size = camera2.frustrumSizeAt(this.position);
55470
- this.scale.set(size.x * 3e-3, size.x * 3e-3, size.x * 3e-3);
55471
- };
55472
- this._camSub = camera2.onMoved.subscribe(() => rescale());
55473
- rescale();
55471
+ this._camera = camera2;
55472
+ this.update();
55473
+ this._camSub = camera2.onMoved.subscribe(() => this.update());
55474
+ }
55475
+ update() {
55476
+ if (!this._camera) return;
55477
+ const size = this._camera.frustrumSizeAt(this.position);
55478
+ this.scale.set(size.x * 3e-3, size.x * 3e-3, size.x * 3e-3);
55474
55479
  }
55475
55480
  setPosition(position) {
55476
55481
  this.position.copy(position);
55482
+ this.update();
55477
55483
  }
55478
55484
  get forward() {
55479
55485
  return this._forward;
@@ -57611,6 +57617,36 @@ function clamp$1(value, min2, max2) {
57611
57617
  }
57612
57618
  return Math.min(Math.max(value, min2), max2);
57613
57619
  }
57620
+ class CaptureStateMachine {
57621
+ constructor(canvas) {
57622
+ __publicField(this, "_canvas");
57623
+ __publicField(this, "state");
57624
+ __publicField(this, "id");
57625
+ this._canvas = canvas;
57626
+ this.state = "none";
57627
+ this.id = -1;
57628
+ }
57629
+ onPointerDown(event) {
57630
+ if (this.state === "captured") {
57631
+ this._canvas.releasePointerCapture(this.id);
57632
+ }
57633
+ this.id = event.pointerId;
57634
+ this.state = "captured";
57635
+ }
57636
+ onPointerMove(event) {
57637
+ if (this.state === "capture") {
57638
+ this._canvas.setPointerCapture(this.id);
57639
+ this.state = "captured";
57640
+ }
57641
+ }
57642
+ onPointerUp(event) {
57643
+ if (this.state === "captured") {
57644
+ this._canvas.releasePointerCapture(this.id);
57645
+ this.state = "none";
57646
+ this.id = -1;
57647
+ }
57648
+ }
57649
+ }
57614
57650
  class InputMouse extends InputHandler2 {
57615
57651
  constructor(canvas, rpc, selection, camera2) {
57616
57652
  super();
@@ -57619,45 +57655,47 @@ class InputMouse extends InputHandler2 {
57619
57655
  __publicField(this, "_lastMouseDownPosition", new Vector2(0, 0));
57620
57656
  __publicField(this, "_selection");
57621
57657
  __publicField(this, "_camera");
57658
+ __publicField(this, "_capture");
57622
57659
  this._canvas = canvas;
57623
57660
  this._rpc = rpc;
57624
57661
  this._selection = selection;
57625
57662
  this._camera = camera2;
57663
+ this._capture = new CaptureStateMachine(canvas);
57626
57664
  }
57627
57665
  register() {
57628
57666
  this.reg(this._canvas, "pointerdown", (e) => {
57629
- this.handlePointerDown(e);
57667
+ this.onPointerDown(e);
57630
57668
  });
57631
57669
  this.reg(this._canvas, "pointerup", (e) => {
57632
- this.handlePointerUp(e);
57670
+ this.onPointerUp(e);
57633
57671
  });
57634
57672
  this.reg(this._canvas, "pointermove", (e) => {
57635
- this.handlePointerMove(e);
57673
+ this.onPointerMove(e);
57636
57674
  });
57637
57675
  this.reg(this._canvas, "wheel", (e) => {
57638
- this.handleMouseScroll(e);
57676
+ this.onMouseScroll(e);
57639
57677
  });
57640
57678
  this.reg(this._canvas, "dblclick", (e) => {
57641
- this.handleDoubleClick(e);
57679
+ this.onDoubleClick(e);
57642
57680
  });
57643
57681
  }
57644
57682
  dispose() {
57645
57683
  this.unregister();
57646
57684
  }
57647
- handlePointerDown(event) {
57685
+ onPointerDown(event) {
57648
57686
  if (event.pointerType !== "mouse") return;
57649
57687
  const pos = this.relativePosition(event);
57650
57688
  this._rpc.RPCMouseButtonEvent(pos, event.button, true);
57651
57689
  this._lastMouseDownPosition = pos;
57652
- this._canvas.setPointerCapture(event.pointerId);
57690
+ this._capture.onPointerDown(event);
57653
57691
  event.preventDefault();
57654
57692
  }
57655
- handlePointerUp(event) {
57693
+ onPointerUp(event) {
57656
57694
  if (event.pointerType !== "mouse") return;
57657
57695
  const pos = this.relativePosition(event);
57658
57696
  this._rpc.RPCMouseButtonEvent(pos, event.button, false);
57659
57697
  this.handleMouseClick(event);
57660
- this._canvas.releasePointerCapture(event.pointerId);
57698
+ this._capture.onPointerUp(event);
57661
57699
  event.preventDefault();
57662
57700
  }
57663
57701
  async handleMouseClick(event) {
@@ -57677,21 +57715,24 @@ class InputMouse extends InputHandler2 {
57677
57715
  this._selection.select(hit.vim, hit.nodeIndex);
57678
57716
  }
57679
57717
  }
57680
- handlePointerMove(event) {
57718
+ onPointerMove(event) {
57681
57719
  if (event.pointerType !== "mouse") return;
57682
57720
  this._canvas.focus();
57721
+ this._capture.onPointerMove(event);
57683
57722
  const pos = this.relativePosition(event);
57684
57723
  this._rpc.RPCMouseMoveEvent(pos);
57685
57724
  }
57686
- async handleDoubleClick(event) {
57725
+ async onDoubleClick(event) {
57687
57726
  const pos = this.relativePosition(event);
57688
57727
  const hit = await this._selection.hitTest(pos);
57689
57728
  if (hit) {
57690
57729
  this._camera.frameVim(hit.vim, [hit.nodeIndex], 1);
57730
+ } else {
57731
+ this._camera.frameAll(1);
57691
57732
  }
57692
57733
  event.preventDefault();
57693
57734
  }
57694
- handleMouseScroll(event) {
57735
+ onMouseScroll(event) {
57695
57736
  this._rpc.RPCMouseScrollEvent(Math.sign(event.deltaY));
57696
57737
  event.preventDefault();
57697
57738
  }
@@ -59671,15 +59712,19 @@ class InputKeyboard extends InputHandler2 {
59671
59712
  switch (event.key) {
59672
59713
  case "Escape":
59673
59714
  this._selection.clear();
59715
+ event.preventDefault();
59674
59716
  break;
59675
59717
  case "f":
59676
59718
  this.frameContext();
59719
+ event.preventDefault();
59677
59720
  break;
59678
59721
  case "Home":
59679
59722
  this._camera.restoreSavedPosition();
59723
+ event.preventDefault();
59680
59724
  break;
59681
59725
  case " ":
59682
59726
  this._inputs.mode = this._inputs.mode === InputMode.Orbit ? InputMode.Free : InputMode.Orbit;
59727
+ event.preventDefault();
59683
59728
  break;
59684
59729
  }
59685
59730
  }
@@ -61219,11 +61264,15 @@ class Camera3 {
61219
61264
  * Handles camera initialization when connection is established
61220
61265
  */
61221
61266
  onConnect() {
61267
+ this.set(new Vector3(-1e3, 1e3, 1e3), new Vector3(0, 0, 0), 0);
61222
61268
  this.restoreLastPosition();
61223
61269
  }
61224
61270
  onCameraPose(pose) {
61225
61271
  this._lastPosition = pose;
61226
61272
  }
61273
+ set(position, target, blendTime = this._defaultBlendTime) {
61274
+ this._rpc.RPCSetCameraPosition(new Segment(position, target), blendTime);
61275
+ }
61227
61276
  /**
61228
61277
  * Pauses or resumes rendering
61229
61278
  * @param value - True to pause rendering, false to resume
@@ -61237,6 +61286,7 @@ class Camera3 {
61237
61286
  * @returns Promise that resolves when the framing animation is complete
61238
61287
  */
61239
61288
  async frameAll(blendTime = this._defaultBlendTime) {
61289
+ console.log("Camera.frameAll");
61240
61290
  const segment = await this._rpc.RPCFrameAll(blendTime);
61241
61291
  this._savedPosition = this._savedPosition ?? segment;
61242
61292
  return segment;
@@ -61247,6 +61297,7 @@ class Camera3 {
61247
61297
  * @param blendTime - Duration of the camera animation in seconds (defaults to 0.5)
61248
61298
  */
61249
61299
  async frameBox(box, blendTime = this._defaultBlendTime) {
61300
+ console.log("Camera.frameAll");
61250
61301
  const segment = await this._rpc.RPCFrameBox(box, blendTime);
61251
61302
  this._savedPosition = this._savedPosition ?? segment;
61252
61303
  return segment;
@@ -66801,6 +66852,25 @@ function hidden({ height, width, fill: fill2, className = "" }) {
66801
66852
  }
66802
66853
  );
66803
66854
  }
66855
+ function autoCamera({ height, width, fill: fill2 = "", className }) {
66856
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("svg", { className, height, width, viewBox: "0 0 256 256", children: [
66857
+ /* @__PURE__ */ jsxRuntimeExports.jsx("path", { fill: "none", d: "M0 0h256v256H0z" }),
66858
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
66859
+ "path",
66860
+ {
66861
+ fill: fill2,
66862
+ d: "M 242.35934,69.720521 V 192.19034 c 0,9.46501 -7.97359,15.37204 -14.35248,10.67406 l -39.68884,-29.41993 v 8.38267 c 0,25.1595 -15.90243,45.64407 -35.51391,45.64407 H 48.520099 C 28.90861,227.51727 13.006195,206.98664 13.006195,181.80411 V 80.187338 c 0,-25.159506 15.902415,-45.644066 35.513904,-45.644066 H 152.55325 c 19.57566,0 35.51392,20.4385 35.51392,45.644066 v 8.382665 L 227.756,59.150074 c 6.33409,-4.801607 14.60334,1.162981 14.60334,10.570447 z"
66863
+ }
66864
+ ),
66865
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
66866
+ "path",
66867
+ {
66868
+ fill: "white",
66869
+ d: "m 134.24221,179.28573 -6.38,-16.771 H 73.539201 l -6.38,17.135 c -2.492,6.684 -4.618,11.211 -6.38,13.581 -1.763,2.309 -4.649,3.464 -8.659,3.464 -3.403,0 -6.411,-1.246 -9.024,-3.737 -2.613,-2.492 -3.919,-5.317 -3.919,-8.477 0,-1.823 0.304,-3.706 0.911,-5.651 0.608,-1.944 1.611,-4.648 3.008,-8.112 l 34.18,-86.771005 c 0.972,-2.491 2.127,-5.469 3.463,-8.932 1.398,-3.525 2.856,-6.441 4.375,-8.75 1.58,-2.309 3.616,-4.163 6.107,-5.56 2.552005,-1.458 5.682005,-2.188 9.388009,-2.188 3.768,0 6.897,0.73 9.388,2.188 2.552,1.397 4.588,3.22 6.107,5.469 1.58,2.248 2.886,4.678 3.919,7.291 1.094,2.552 2.461,5.986 4.102,10.3 l 34.909,86.224005 c 2.734,6.562 4.101,11.332 4.101,14.31 0,3.099 -1.306,5.955 -3.919,8.568 -2.552,2.552 -5.651,3.828 -9.297,3.828 -2.126,0 -3.949,-0.395 -5.468,-1.185 -1.52,-0.729 -2.796,-1.732 -3.829,-3.008 -1.033,-1.337 -2.157,-3.342 -3.372,-6.016 -1.155,-2.734 -2.157,-5.134 -3.008,-7.2 z m -53.594009,-37.097 h 39.922009 l -20.143,-55.143005 z"
66870
+ }
66871
+ )
66872
+ ] });
66873
+ }
66804
66874
  function orbit({ height, width, fill: fill2 = "", className }) {
66805
66875
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("svg", { className, height, width, viewBox: "0 0 256 256", children: [
66806
66876
  /* @__PURE__ */ jsxRuntimeExports.jsx("path", { fill: "none", d: "M0 0h256v256H0z" }),
@@ -67324,6 +67394,7 @@ function ghostDead({ height, width, fill: fill2, className }) {
67324
67394
  const icons = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
67325
67395
  __proto__: null,
67326
67396
  arrowLeft,
67397
+ autoCamera,
67327
67398
  camera,
67328
67399
  checkmark,
67329
67400
  close,
@@ -67470,7 +67541,7 @@ function AxesPanel(props) {
67470
67541
  );
67471
67542
  };
67472
67543
  const onHomeBtn = () => {
67473
- props.camera.reset();
67544
+ props.camera.reset.call();
67474
67545
  };
67475
67546
  const btnStyle2 = "vim-axes-button vc-flex vc-items-center vc-justify-center vc-text-gray-medium vc-transition-all hover:vc-text-primary-royal";
67476
67547
  const btnIsolation = /* @__PURE__ */ jsxRuntimeExports.jsx(
@@ -67564,12 +67635,14 @@ function createSection$1(section) {
67564
67635
  const ids = {
67565
67636
  // Sections
67566
67637
  sectionCamera: "controlBar.sectionCamera",
67638
+ sectionInputs: "controlBar.sectionInputs",
67567
67639
  sectionActions: "controlBar.sectionActions",
67568
67640
  sectionTools: "controlBar.sectionTools",
67569
67641
  sectionSettings: "controlBar.sectionSettings",
67570
67642
  sectionMeasure: "controlBar.sectionMeasure",
67571
67643
  sectionSectionBox: "controlBar.sectionSectionBox",
67572
67644
  // Camera buttons
67645
+ buttonCameraAuto: "controlBar.camera.auto",
67573
67646
  buttonCameraOrbit: "controlBar.camera.orbit",
67574
67647
  buttonCameraLook: "controlBarcamera.look",
67575
67648
  buttonCameraPan: "controlBar.camera.pan",
@@ -67591,7 +67664,7 @@ const ids = {
67591
67664
  buttonSectionBoxVisible: "controlBar.sectionBox.visible",
67592
67665
  buttonSectionBoxShrinkToSelection: "controlBar.sectionBox.shrinkToSelection",
67593
67666
  buttonSectionBoxAuto: "controlBar.sectionBox.auto",
67594
- buttonSectionBoxClip: "controlBar.sectionBox.clip",
67667
+ buttonSectionBoxReset: "controlBar.sectionBox.reset",
67595
67668
  buttonSectionBoxSettings: "controlBar.sectionBox.settings"
67596
67669
  };
67597
67670
  function ControlBar(props) {
@@ -67833,7 +67906,7 @@ function controlBarSectionBox(section, hasSelection) {
67833
67906
  icon: sectionBoxShrink
67834
67907
  },
67835
67908
  {
67836
- id: ids.buttonSectionBoxClip,
67909
+ id: ids.buttonSectionBoxReset,
67837
67910
  tip: "Reset Section",
67838
67911
  enabled: () => section.enable.get(),
67839
67912
  style: (on) => buttonDefaultStyle(on),
@@ -67873,7 +67946,7 @@ function controlBarSectionBox(section, hasSelection) {
67873
67946
  function controlBarPointer(viewer, camera2, settings2, section) {
67874
67947
  const pointer = getPointerState(viewer);
67875
67948
  return {
67876
- id: ids.sectionCamera,
67949
+ id: ids.sectionInputs,
67877
67950
  enable: () => anyUiCursorButton(settings2),
67878
67951
  style: sectionDefaultStyle,
67879
67952
  buttons: [
@@ -67937,7 +68010,7 @@ function controlBarActions(camera2, settings2, isolation, measure$1) {
67937
68010
  id: ids.buttonZoomToFit,
67938
68011
  enabled: () => isTrue(settings2.ui.zoomToFit),
67939
68012
  tip: "Zoom to Fit",
67940
- action: () => camera2.frameContext(),
68013
+ action: () => camera2.frameSelection.call(),
67941
68014
  icon: frameSelection,
67942
68015
  isOn: () => false,
67943
68016
  style: buttonDefaultStyle
@@ -68004,15 +68077,34 @@ function controlBarSettings(modal, side, settings$1) {
68004
68077
  ]
68005
68078
  };
68006
68079
  }
68080
+ function controlBarCamera(camera2) {
68081
+ return {
68082
+ id: ids.sectionCamera,
68083
+ enable: () => true,
68084
+ style: sectionDefaultStyle,
68085
+ buttons: [
68086
+ {
68087
+ id: ids.buttonCameraAuto,
68088
+ tip: "Auto Camera",
68089
+ isOn: () => camera2.autoCamera.get(),
68090
+ action: () => camera2.autoCamera.set(!camera2.autoCamera.get()),
68091
+ icon: autoCamera,
68092
+ style: buttonDefaultStyle
68093
+ }
68094
+ ]
68095
+ };
68096
+ }
68007
68097
  function useControlBar(viewer, camera2, modal, side, isolation, cursor, settings2, section, customization) {
68008
68098
  const measure2 = getMeasureState(viewer, cursor);
68009
68099
  const pointerSection = controlBarPointer(viewer, camera2, settings2);
68010
68100
  const actionSection = controlBarActions(camera2, settings2, isolation, measure2);
68011
68101
  const sectionBoxSection = controlBarSectionBox(section, viewer.selection.count > 0);
68012
68102
  const settingsSection = controlBarSettings(modal, side, settings2);
68103
+ const cameraSection = controlBarCamera(camera2);
68013
68104
  let controlBarSections = [
68014
68105
  pointerSection,
68015
68106
  actionSection,
68107
+ cameraSection,
68016
68108
  sectionBoxSection,
68017
68109
  // Optional section
68018
68110
  settingsSection
@@ -72038,11 +72130,11 @@ function VimContextMenu(props) {
72038
72130
  e.stopPropagation();
72039
72131
  };
72040
72132
  const onCameraResetBtn = (e) => {
72041
- camera2.reset();
72133
+ camera2.reset.call();
72042
72134
  e.stopPropagation();
72043
72135
  };
72044
72136
  const onCameraFrameBtn = (e) => {
72045
- camera2.frameContext();
72137
+ camera2.frameSelection.call();
72046
72138
  e.stopPropagation();
72047
72139
  };
72048
72140
  const onSelectionIsolateBtn = (e) => {
@@ -72374,7 +72466,7 @@ function BimTree(props) {
72374
72466
  createInteractiveElementProps: (item, treeId, actions, renderFlags) => ({
72375
72467
  onKeyUp: (e) => {
72376
72468
  if (e.key === "f") {
72377
- props.camera.frameContext();
72469
+ props.camera.frameSelection.call();
72378
72470
  }
72379
72471
  if (e.key === "Escape") {
72380
72472
  props.viewer.selection.clear();
@@ -72417,7 +72509,7 @@ function BimTree(props) {
72417
72509
  },
72418
72510
  onPrimaryAction: (item, _) => {
72419
72511
  if (doubleClick.isDoubleClick(item.index)) {
72420
- props.camera.frameSelection();
72512
+ props.camera.frameSelection.call();
72421
72513
  }
72422
72514
  },
72423
72515
  onFocusItem: (item) => {
@@ -74708,7 +74800,7 @@ class ComponentInputs {
74708
74800
  return true;
74709
74801
  }
74710
74802
  case KEYS.KEY_F: {
74711
- this._camera.frameContext();
74803
+ this._camera.frameSelection.call();
74712
74804
  return true;
74713
74805
  }
74714
74806
  case KEYS.KEY_I: {
@@ -74902,7 +74994,7 @@ class Isolation {
74902
74994
  if (!this._settings.isolation.enable) return;
74903
74995
  this._isolation = objects ?? [];
74904
74996
  this._apply(source);
74905
- this._camera.frameVisibleObjects();
74997
+ this._camera.frameScene.call();
74906
74998
  }
74907
74999
  /**
74908
75000
  * Toggles isolation by using the current selection.
@@ -74917,7 +75009,7 @@ class Isolation {
74917
75009
  if (!this._settings.isolation.enable) return;
74918
75010
  this._isolation = [...this._viewer.selection.objects].filter((o) => o.type === "Object3D");
74919
75011
  this._apply(source);
74920
- this._camera.frameVisibleObjects();
75012
+ this._camera.frameScene.call();
74921
75013
  this._viewer.selection.clear();
74922
75014
  }
74923
75015
  /**
@@ -75017,75 +75109,6 @@ class Isolation {
75017
75109
  return objects;
75018
75110
  }
75019
75111
  }
75020
- class ComponentCamera {
75021
- constructor(viewer) {
75022
- __publicField(this, "_viewer");
75023
- this._viewer = viewer;
75024
- }
75025
- /**
75026
- * Resets the camera to its initial position.
75027
- */
75028
- reset() {
75029
- this._viewer.camera.lerp(1).reset();
75030
- }
75031
- /**
75032
- * Frames selected elements if there is an active selection; otherwise, frames all visible objects.
75033
- * @param duration Optional duration of the camera movement animation (default: 1).
75034
- */
75035
- frameContext(duration = 1) {
75036
- if (this._viewer.selection.count > 0) {
75037
- this.frameSelection(duration);
75038
- } else {
75039
- this.frameVisibleObjects(void 0, duration);
75040
- }
75041
- }
75042
- /**
75043
- * Frames selected elements if there is an active selection; otherwise, does nothing.
75044
- * @param duration Optional duration of the camera movement animation (default: 1).
75045
- */
75046
- frameSelection(duration = 1) {
75047
- if (this._viewer.selection.count === 0) return;
75048
- const box = this._viewer.selection.getBoundingBox();
75049
- if (box && this._viewer.gizmos.sectionBox.box.intersectsBox(box)) {
75050
- const movement = duration === 0 ? this._viewer.camera.snap() : this._viewer.camera.lerp(duration);
75051
- movement.frame(box);
75052
- }
75053
- }
75054
- /**
75055
- * Frames all visible objects in the scene.
75056
- * @param source Optional VIM to specify the source of objects to frame.
75057
- * @param duration Duration of the camera movement animation (default: 1).
75058
- */
75059
- frameVisibleObjects(source, duration = 1) {
75060
- const movement = duration === 0 ? this._viewer.camera.snap() : this._viewer.camera.lerp(duration);
75061
- const box = this.getVisibleBoundingBox(source);
75062
- movement.frame(box);
75063
- }
75064
- /**
75065
- * Returns the bounding box of all visible objects.
75066
- * @param source Optional VIM to specify the source of visible objects.
75067
- * @returns The bounding box of all visible objects.
75068
- */
75069
- getVisibleBoundingBox(source) {
75070
- let box;
75071
- const vimBoxUnion = (vim) => {
75072
- for (const obj of vim.getObjects()) {
75073
- if (!obj.visible) continue;
75074
- const b = obj.getBoundingBox();
75075
- if (!b) continue;
75076
- box = box ? box.union(b) : b == null ? void 0 : b.clone();
75077
- }
75078
- };
75079
- if (source) {
75080
- vimBoxUnion(source);
75081
- } else {
75082
- for (const vim of this._viewer.vims) {
75083
- vimBoxUnion(vim);
75084
- }
75085
- }
75086
- return box;
75087
- }
75088
- }
75089
75112
  function createContainer(element) {
75090
75113
  let root = element;
75091
75114
  if (root === void 0) {
@@ -75839,6 +75862,17 @@ function useStateRef(initialValue) {
75839
75862
  }
75840
75863
  };
75841
75864
  }
75865
+ function useActionRef(action) {
75866
+ const ref = useRef(action);
75867
+ return {
75868
+ call() {
75869
+ ref == null ? void 0 : ref.current();
75870
+ },
75871
+ set(func) {
75872
+ ref.current = func;
75873
+ }
75874
+ };
75875
+ }
75842
75876
  function useArgActionRef(action) {
75843
75877
  const ref = useRef(action);
75844
75878
  return {
@@ -75861,6 +75895,17 @@ function useFuncRef(func) {
75861
75895
  }
75862
75896
  };
75863
75897
  }
75898
+ function useAsyncFuncRef(func) {
75899
+ const ref = useRef(func);
75900
+ return {
75901
+ async call() {
75902
+ return ref == null ? void 0 : ref.current();
75903
+ },
75904
+ set(func2) {
75905
+ ref.current = func2;
75906
+ }
75907
+ };
75908
+ }
75864
75909
  function useSectionBox(adapter) {
75865
75910
  const enable = useStateRef(false);
75866
75911
  const visible2 = useStateRef(false);
@@ -75892,6 +75937,7 @@ function useSectionBox(adapter) {
75892
75937
  });
75893
75938
  visible2.useOnChange((v) => adapter.setVisible(v));
75894
75939
  useEffect(() => {
75940
+ adapter.setVisible(false);
75895
75941
  return adapter.onSelectionChanged.sub(() => {
75896
75942
  if (auto.get() && enable.get()) sectionSelection.call();
75897
75943
  });
@@ -75956,12 +76002,61 @@ function useWebglSectionBox(viewer) {
75956
76002
  fitBox: (box) => viewer.gizmos.sectionBox.fitBox(box),
75957
76003
  getSelectionBox: () => Promise.resolve(viewer.selection.getBoundingBox()),
75958
76004
  getRendererBox: () => Promise.resolve(viewer.renderer.getBoundingBox()),
75959
- onSceneChanged: viewer.renderer.onBoxUpdated,
75960
76005
  onSelectionChanged: viewer.selection.onValueChanged
75961
76006
  };
75962
76007
  viewer.gizmos.sectionBox.clip = true;
75963
76008
  return useSectionBox(vimAdapter);
75964
76009
  }
76010
+ function useCamera(adapter) {
76011
+ const autoCamera2 = useStateRef(false);
76012
+ autoCamera2.useOnChange((v) => {
76013
+ if (v) {
76014
+ frameSelection2.call();
76015
+ }
76016
+ });
76017
+ useEffect(() => {
76018
+ adapter.onSelectionChanged.sub(() => {
76019
+ if (autoCamera2.get()) {
76020
+ frameSelection2.call();
76021
+ }
76022
+ });
76023
+ }, []);
76024
+ const reset = useActionRef(() => adapter.resetCamera(1));
76025
+ const frameSelection2 = useAsyncFuncRef(async () => {
76026
+ console.log("frameSelection");
76027
+ if (!adapter.hasSelection()) {
76028
+ frameScene.call();
76029
+ return;
76030
+ }
76031
+ const box = await adapter.getSelectionBox();
76032
+ if (!box) {
76033
+ return;
76034
+ }
76035
+ adapter.frameCamera(box, 1);
76036
+ });
76037
+ const frameScene = useAsyncFuncRef(async () => {
76038
+ adapter.frameAll(1);
76039
+ });
76040
+ return {
76041
+ autoCamera: autoCamera2,
76042
+ reset,
76043
+ frameSelection: frameSelection2,
76044
+ frameScene
76045
+ };
76046
+ }
76047
+ function useWebglCamera(viewer) {
76048
+ return useCamera({
76049
+ onSelectionChanged: viewer.selection.onValueChanged,
76050
+ frameCamera: (box, duration) => viewer.camera.lerp(duration).frame(box),
76051
+ resetCamera: (duration) => viewer.camera.lerp(duration).reset(),
76052
+ frameAll: (duration) => {
76053
+ const box = viewer.renderer.getBoundingBox();
76054
+ viewer.camera.lerp(duration).frame(box);
76055
+ },
76056
+ hasSelection: () => viewer.selection.count > 0,
76057
+ getSelectionBox: () => Promise.resolve(viewer.selection.getBoundingBox())
76058
+ });
76059
+ }
75965
76060
  function createWebglComponent(container, componentSettings = {}, viewerSettings = {}) {
75966
76061
  const promise2 = new DeferredPromise2();
75967
76062
  const cmpContainer = container instanceof HTMLElement ? createContainer(container) : container ?? createContainer();
@@ -75993,7 +76088,7 @@ function VimComponent(props) {
75993
76088
  var _a2;
75994
76089
  const settings2 = useSettings(props.viewer, props.settings ?? {});
75995
76090
  const modal = useModal(settings2.value.capacity.canFollowUrl);
75996
- const camera2 = useMemo(() => new ComponentCamera(props.viewer), []);
76091
+ const camera2 = useWebglCamera(props.viewer);
75997
76092
  const cursor = useMemo(() => new CursorManager(props.viewer), []);
75998
76093
  const loader = useRef(new ComponentLoader(props.viewer, modal));
75999
76094
  const [isolation] = useState(() => new Isolation(props.viewer, camera2, settings2.value));
@@ -76449,6 +76544,7 @@ async function updateProgress(request2, modal) {
76449
76544
  function useUltraSectionBox(viewer) {
76450
76545
  const ultraAdapter = {
76451
76546
  setVisible: (b) => {
76547
+ console.log("SetVisible!", b);
76452
76548
  viewer.sectionBox.visible = b;
76453
76549
  viewer.sectionBox.interactive = b;
76454
76550
  },
@@ -76456,15 +76552,26 @@ function useUltraSectionBox(viewer) {
76456
76552
  fitBox: (box) => viewer.sectionBox.fitBox(box),
76457
76553
  getSelectionBox: () => viewer.selection.getBoundingBox(),
76458
76554
  getRendererBox: () => viewer.renderer.getBoundingBox(),
76459
- onSelectionChanged: viewer.selection.onValueChanged,
76460
- onSceneChanged: viewer.vims.onChanged
76555
+ onSelectionChanged: viewer.selection.onValueChanged
76461
76556
  };
76462
76557
  return useSectionBox(ultraAdapter);
76463
76558
  }
76464
- function useUltraControlBar(viewer, section, customization) {
76465
- let controlBar2 = [controlBarSectionBox(section, viewer.selection.count > 0)];
76466
- controlBar2 = (customization == null ? void 0 : customization(controlBar2)) ?? controlBar2;
76467
- return controlBar2;
76559
+ function useUltraControlBar(viewer, section, camera2, customization) {
76560
+ const sectionSectionBox = controlBarSectionBox(section, viewer.selection.count > 0);
76561
+ const sectionCamera = controlBarCamera(camera2);
76562
+ let bar = [sectionCamera, sectionSectionBox];
76563
+ bar = (customization == null ? void 0 : customization(bar)) ?? bar;
76564
+ return bar;
76565
+ }
76566
+ function useUltraCamera(viewer) {
76567
+ return useCamera({
76568
+ onSelectionChanged: viewer.selection.onValueChanged,
76569
+ frameCamera: (box, duration) => void viewer.camera.frameBox(box, duration),
76570
+ frameAll: (duration) => viewer.camera.frameAll(duration),
76571
+ resetCamera: (duration) => viewer.camera.restoreSavedPosition(duration),
76572
+ hasSelection: () => viewer.selection.count > 0,
76573
+ getSelectionBox: () => viewer.selection.getBoundingBox()
76574
+ });
76468
76575
  }
76469
76576
  function createUltraComponent(container) {
76470
76577
  const promise2 = new DeferredPromise2();
@@ -76494,10 +76601,11 @@ function createUltraComponent(container) {
76494
76601
  function UltraComponent(props) {
76495
76602
  const modal = useModal(true);
76496
76603
  const sectionBox2 = useUltraSectionBox(props.viewer);
76604
+ const camera2 = useUltraCamera(props.viewer);
76497
76605
  const side = useSideState(true, 400);
76498
76606
  const [_, setSelectState] = useState(0);
76499
76607
  const [controlBarCustom, setControlBarCustom] = useState(() => (c) => c);
76500
- const controlBar2 = useUltraControlBar(props.viewer, sectionBox2, (_2) => _2);
76608
+ const controlBar2 = useUltraControlBar(props.viewer, sectionBox2, camera2, (_2) => _2);
76501
76609
  useEffect(() => {
76502
76610
  props.viewer.onStateChanged.subscribe((state) => updateModal(modal, state));
76503
76611
  props.viewer.selection.onValueChanged.subscribe(() => {