@vertexvis/viewer 0.23.6-canary.8 → 0.23.6-testing.0

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.
Files changed (38) hide show
  1. package/dist/cjs/index-4ebe6acf.js +138 -1
  2. package/dist/cjs/{regl-component-b9b3e921.js → regl-component-32e37b41.js} +30 -2
  3. package/dist/cjs/{regl-component-b9b3e921.js.map → regl-component-32e37b41.js.map} +1 -1
  4. package/dist/cjs/vertex-viewer-hit-result-indicator.cjs.entry.js +1 -1
  5. package/dist/cjs/vertex-viewer-transform-widget.cjs.entry.js +1 -1
  6. package/dist/cjs/vertex-viewer.cjs.entry.js +89 -15
  7. package/dist/cjs/vertex-viewer.cjs.entry.js.map +1 -1
  8. package/dist/collection/lib/interactions/interactionApi.js +66 -8
  9. package/dist/collection/lib/interactions/interactionApi.js.map +1 -1
  10. package/dist/collection/lib/interactions/interactionApiOrthographic.js +23 -7
  11. package/dist/collection/lib/interactions/interactionApiOrthographic.js.map +1 -1
  12. package/dist/collection/lib/webgl/regl-component.js +29 -1
  13. package/dist/collection/lib/webgl/regl-component.js.map +1 -1
  14. package/dist/components/regl-component.js +29 -1
  15. package/dist/components/regl-component.js.map +1 -1
  16. package/dist/components/vertex-viewer.js +90 -16
  17. package/dist/components/vertex-viewer.js.map +1 -1
  18. package/dist/esm/index-fef00dee.js +138 -1
  19. package/dist/esm/{regl-component-3d0639a6.js → regl-component-76cd98b9.js} +30 -2
  20. package/dist/esm/{regl-component-3d0639a6.js.map → regl-component-76cd98b9.js.map} +1 -1
  21. package/dist/esm/vertex-viewer-hit-result-indicator.entry.js +1 -1
  22. package/dist/esm/vertex-viewer-transform-widget.entry.js +1 -1
  23. package/dist/esm/vertex-viewer.entry.js +90 -16
  24. package/dist/esm/vertex-viewer.entry.js.map +1 -1
  25. package/dist/types/lib/webgl/regl-component.d.ts +4 -0
  26. package/dist/viewer/{p-d7a621a2.entry.js → p-07d2b2fa.entry.js} +2 -2
  27. package/dist/viewer/{p-ed1460ad.js → p-75cad0f2.js} +2 -2
  28. package/dist/viewer/p-75cad0f2.js.map +1 -0
  29. package/dist/viewer/{p-96dd1ad5.entry.js → p-9c4fc8bd.entry.js} +2 -2
  30. package/dist/viewer/p-d2ddc770.entry.js +5 -0
  31. package/dist/viewer/p-d2ddc770.entry.js.map +1 -0
  32. package/dist/viewer/viewer.esm.js +1 -1
  33. package/package.json +7 -7
  34. package/dist/viewer/p-7e808b58.entry.js +0 -5
  35. package/dist/viewer/p-7e808b58.entry.js.map +0 -1
  36. package/dist/viewer/p-ed1460ad.js.map +0 -1
  37. /package/dist/viewer/{p-d7a621a2.entry.js.map → p-07d2b2fa.entry.js.map} +0 -0
  38. /package/dist/viewer/{p-96dd1ad5.entry.js.map → p-9c4fc8bd.entry.js.map} +0 -0
@@ -749,14 +749,72 @@ class InteractionApi {
749
749
  * values zoom out.
750
750
  */
751
751
  async zoomCamera(delta) {
752
- return this.transformCamera(({ camera, viewport }) => {
753
- const vv = camera.viewVector;
754
- const v = vector3.normalize(vv);
755
- const distance = vector3.magnitude(vv);
756
- const epsilon = (3 * distance * delta) / viewport.height;
757
- const position = vector3.add(camera.position, vector3.scale(epsilon, v));
758
- const newCamera = camera.update({ position });
759
- return newCamera;
752
+ return this.transformCamera(({ camera, viewport, frame, boundingBox: boundingBox$1 }) => {
753
+ if (viewport != null && frame != null) {
754
+ const isPerspective = camera === null || camera === void 0 ? void 0 : camera.toFrameCamera().isPerspective();
755
+ if (isPerspective) {
756
+ const vv = camera.viewVector;
757
+ // Calculate the unit-less scalar determining the amount to zoom. The delta parameter
758
+ // is scaled by the viewport height because if the viewport is larger, then the
759
+ // user should have to perform a bigger action to zoom the model the same amount.
760
+ // Note that delta and viewport.height both have units of pixels. Further, the
761
+ // 3 multiplier was chosen to match the desired zoom speed.
762
+ const distance = vector3.magnitude(vv);
763
+ const relativeDeltaToViewportHeight = 3 * distance * (delta / viewport.height);
764
+ // Scale the current viewVector by the scalar calculated above to determine how to adjust the camera position
765
+ const v = vector3.normalize(vv);
766
+ const positionChange = vector3.scale(relativeDeltaToViewportHeight, v);
767
+ // Calculate the new camera position
768
+ const position = vector3.add(camera.position, positionChange);
769
+ // Update the camera with the new position
770
+ const newCamera = camera.update({ position });
771
+ return newCamera;
772
+ }
773
+ else {
774
+ // Retrieve properties of the current camera
775
+ const orthographicCamera = camera;
776
+ const frameCam = camera.toFrameCamera();
777
+ const dir = frameCam.direction;
778
+ const ray$1 = viewport.transformPointToRay(viewport.center, frame.image, frameCam);
779
+ // Calculate the unit-less scalar determining the amount to zoom. The delta parameter
780
+ // is scaled by the viewport height because if the viewport is larger, then the
781
+ // user should have to perform a bigger action to zoom the model the same amount.
782
+ // Note that delta and viewport.height both have units of pixels. Further, the
783
+ // 4 multiplier was chosen to match the desired zoom speed.
784
+ const relativeDeltaToViewportHeight = 4 * (delta / viewport.height);
785
+ // Calculate the fovHeight after performing the zoom. zoomedFovHeight has the
786
+ // same units of camera.fovHeight (the world units). The new fovHeight
787
+ // has a minimum value, which is a function of the size of the bounding box,
788
+ // which ensures the new fovHeight is a positive, non-zero number.
789
+ const minimumFovHeight = vector3.magnitude(boundingBox.diagonal(boundingBox$1)) * 1e-5;
790
+ const zoomedFovHeight = Math.max(minimumFovHeight, orthographicCamera.fovHeight * (1 - relativeDeltaToViewportHeight));
791
+ // Calculate the plane and point to zoom relative to
792
+ const planeToZoomRelativeTo = plane.fromNormalAndCoplanarPoint(dir, frameCam.lookAt);
793
+ const pointToZoomRelativeTo = ray.intersectPlane(ray$1, planeToZoomRelativeTo);
794
+ if (pointToZoomRelativeTo != null) {
795
+ // Project the current look at point onto the zoom plane
796
+ const projectedLookAt = plane.projectPoint(planeToZoomRelativeTo, orthographicCamera.lookAt);
797
+ // Calculate the vector to determine how to adjust the camera's look at point.
798
+ // Ensure that the viewVector is scaled to the expected length in order to
799
+ // ensure other camera calculations are correct, for example, the occlusion
800
+ // calculations for pins.
801
+ const fovHeightRelativeChange = (orthographicCamera.fovHeight - zoomedFovHeight) /
802
+ orthographicCamera.fovHeight;
803
+ const lookAtChangeVector = vector3.scale(fovHeightRelativeChange, vector3.subtract(pointToZoomRelativeTo, projectedLookAt));
804
+ // Calculate the camera's new look at point
805
+ const updatedLookAt = vector3.add(orthographicCamera.lookAt, lookAtChangeVector);
806
+ // Update the orthographic camera
807
+ // Note rotationPoint should match lookAt after a zoom interaction
808
+ const newCamera = camera.update({
809
+ lookAt: updatedLookAt,
810
+ rotationPoint: updatedLookAt,
811
+ fovHeight: zoomedFovHeight,
812
+ });
813
+ return newCamera;
814
+ }
815
+ }
816
+ }
817
+ return camera;
760
818
  });
761
819
  }
762
820
  /**
@@ -946,7 +1004,7 @@ class InteractionApiOrthographic extends InteractionApi {
946
1004
  });
947
1005
  }
948
1006
  async zoomCameraToPoint(point$1, delta) {
949
- return this.transformCamera(({ camera, viewport, frame, depthBuffer, boundingBox }) => {
1007
+ return this.transformCamera(({ camera, viewport, frame, depthBuffer, boundingBox: boundingBox$1 }) => {
950
1008
  if (this.orthographicZoomData == null ||
951
1009
  point.distance(point$1, this.orthographicZoomData.startingScreenPt) > 2) {
952
1010
  const frameCam = camera.toFrameCamera();
@@ -970,17 +1028,33 @@ class InteractionApiOrthographic extends InteractionApi {
970
1028
  }
971
1029
  if (this.orthographicZoomData != null) {
972
1030
  const { hitPt, hitPlane } = this.orthographicZoomData;
973
- // The 4 multiplier was chosen to match the desired zoom speed
974
- const relativeDelta = 4 * (camera.fovHeight / viewport.height) * delta;
975
- const fovHeight = Math.max(1, camera.fovHeight - relativeDelta);
1031
+ // Calculate the unit-less scalar determining the amount to zoom. The delta parameter
1032
+ // is scaled by the viewport height because if the viewport is larger, then the
1033
+ // user should have to perform a bigger action to zoom the model the same amount.
1034
+ // Note that delta and viewport.height both have units of pixels. Further, the
1035
+ // 4 multiplier was chosen to match the desired zoom speed.
1036
+ const relativeDeltaToViewportHeight = 4 * (delta / viewport.height);
1037
+ // Calculate the fovHeight after performing the zoom. zoomedFovHeight has the
1038
+ // same units of camera.fovHeight (the world units). The new fovHeight
1039
+ // has a minimum value, which is a function of the size of the bounding box,
1040
+ // which ensures the new fovHeight is a positive, non-zero number.
1041
+ const minimumFovHeight = vector3.magnitude(boundingBox.diagonal(boundingBox$1)) * 1e-5;
1042
+ const zoomedFovHeight = Math.max(minimumFovHeight, camera.fovHeight * (1 - relativeDeltaToViewportHeight));
1043
+ // Calculate the vector to determine how to adjust the camera's look at point.
1044
+ // Ensure that the viewVector is scaled to the expected length in order to
1045
+ // ensure other camera calculations are correct, for example, the occlusion
1046
+ // calculations for pins.
976
1047
  const projectedLookAt = plane.projectPoint(hitPlane, camera.lookAt);
977
- const diff = vector3.scale((camera.fovHeight - fovHeight) / camera.fovHeight, vector3.subtract(hitPt, projectedLookAt));
978
- // rotationPoint should match lookAt after a zoom interaction
979
- const updatedLookAt = vector3.add(camera.lookAt, diff);
1048
+ const fovHeightRelativeChange = (camera.fovHeight - zoomedFovHeight) / camera.fovHeight;
1049
+ const lookAtChangeVector = vector3.scale(fovHeightRelativeChange, vector3.subtract(hitPt, projectedLookAt));
1050
+ // Calculate the camera's new look at point
1051
+ const updatedLookAt = vector3.add(camera.lookAt, lookAtChangeVector);
1052
+ // Return the updated camera
1053
+ // Note rotationPoint should match lookAt after a zoom interaction
980
1054
  return camera.update({
981
1055
  lookAt: updatedLookAt,
982
1056
  rotationPoint: updatedLookAt,
983
- fovHeight: Math.max(1, camera.fovHeight - relativeDelta),
1057
+ fovHeight: zoomedFovHeight,
984
1058
  });
985
1059
  }
986
1060
  return camera;