@vertexvis/viewer 0.13.1 → 0.13.2-canary.10

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 (177) hide show
  1. package/dist/cjs/{browser.esm-31b03292.js → browser.esm-075810bf.js} +1 -1
  2. package/dist/cjs/{bundle.esm-dc0a8361.js → bundle.esm-618a5fe9.js} +80 -28
  3. package/dist/cjs/{config-90ee43d5.js → config-fb124bac.js} +2 -2
  4. package/dist/cjs/{cursors-ad2fd395.js → cursors-d71f6a74.js} +1 -1
  5. package/dist/cjs/{dom-dd265f48.js → dom-57ef84e9.js} +1 -1
  6. package/dist/cjs/{entities-aa59890e.js → entities-90f1347a.js} +3 -3
  7. package/dist/cjs/index.cjs.js +14 -12
  8. package/dist/cjs/loader.cjs.js +1 -1
  9. package/dist/cjs/{mapper-f6e6cafe.js → mapper-80ee2957.js} +2 -2
  10. package/dist/cjs/{markup-fb1553b1.js → markup-7f7de5f2.js} +2 -2
  11. package/dist/cjs/{measurement-aba1e0e8.js → measurement-f1ae9248.js} +2 -2
  12. package/dist/cjs/{model-4ec0c36e.js → model-55abd9ab.js} +1 -1
  13. package/dist/cjs/{overlays-40c6cbc7.js → overlays-68e8eff2.js} +2 -2
  14. package/dist/cjs/{png-decoder-27d25eed.js → png-decoder-076131d8.js} +1 -1
  15. package/dist/cjs/{results-bc325974.js → results-e9496869.js} +1 -1
  16. package/dist/cjs/{scene-d420fd26.js → scene-92728420.js} +188 -90
  17. package/dist/cjs/{streamAttributes-d6236448.js → streamAttributes-81eb52f2.js} +1508 -43
  18. package/dist/cjs/{utils-545b1865.js → utils-463cd52e.js} +1 -1
  19. package/dist/cjs/{utils-f80be307.js → utils-6397efca.js} +1 -1
  20. package/dist/cjs/vertex-scene-tree-search_3.cjs.entry.js +1 -1
  21. package/dist/cjs/vertex-scene-tree-table-cell.cjs.entry.js +1 -1
  22. package/dist/cjs/vertex-scene-tree.cjs.entry.js +4 -4
  23. package/dist/cjs/vertex-viewer-dom-element_3.cjs.entry.js +8 -7
  24. package/dist/cjs/vertex-viewer-markup-arrow_3.cjs.entry.js +3 -3
  25. package/dist/cjs/vertex-viewer-markup-tool.cjs.entry.js +4 -4
  26. package/dist/cjs/vertex-viewer-markup.cjs.entry.js +4 -4
  27. package/dist/cjs/vertex-viewer-measurement-details.cjs.entry.js +3 -3
  28. package/dist/cjs/vertex-viewer-measurement-distance.cjs.entry.js +20 -15
  29. package/dist/cjs/vertex-viewer-measurement-line_2.cjs.entry.js +6 -6
  30. package/dist/cjs/vertex-viewer-measurement-precise.cjs.entry.js +10 -10
  31. package/dist/cjs/vertex-viewer-measurement-tool.cjs.entry.js +5 -5
  32. package/dist/cjs/vertex-viewer-measurements.cjs.entry.js +8 -8
  33. package/dist/cjs/vertex-viewer-view-cube.cjs.entry.js +3 -3
  34. package/dist/cjs/vertex-viewer.cjs.entry.js +287 -80
  35. package/dist/cjs/viewer.cjs.js +1 -1
  36. package/dist/cjs/{viewport-8c39089f.js → viewport-54b1389d.js} +34 -2
  37. package/dist/collection/components/scene-tree-table-cell/scene-tree-table-cell.css +1 -1
  38. package/dist/collection/components/viewer/viewer.js +68 -4
  39. package/dist/collection/components/viewer-dom-renderer/renderer2d.js +1 -1
  40. package/dist/collection/components/viewer-dom-renderer/renderer3d.js +4 -2
  41. package/dist/collection/components/viewer-dom-renderer/viewer-dom-renderer.js +5 -6
  42. package/dist/collection/components/viewer-measurement-distance/hitTest.js +9 -4
  43. package/dist/collection/components/viewer-measurement-distance/viewer-measurement-distance.js +5 -5
  44. package/dist/collection/components/viewer-measurement-overlays/viewer-measurement-overlays.js +3 -3
  45. package/dist/collection/index.js +2 -2
  46. package/dist/collection/lib/errors.js +8 -1
  47. package/dist/collection/lib/interactions/index.js +3 -1
  48. package/dist/collection/lib/interactions/interactionApi.js +4 -25
  49. package/dist/collection/lib/interactions/interactionApiOrthographic.js +136 -0
  50. package/dist/collection/lib/interactions/interactionApiPerspective.js +51 -0
  51. package/dist/collection/lib/interactions/multiTouchInteractionHandler.js +3 -2
  52. package/dist/collection/lib/mappers/frameStreaming.js +27 -5
  53. package/dist/collection/lib/rendering/matrices.js +13 -4
  54. package/dist/collection/lib/rendering/vectors.js +7 -0
  55. package/dist/collection/lib/scenes/__mocks__/mocks.js +2 -2
  56. package/dist/collection/lib/scenes/camera.js +163 -83
  57. package/dist/collection/lib/scenes/mapper.js +3 -2
  58. package/dist/collection/lib/scenes/scene.js +22 -9
  59. package/dist/collection/lib/types/clippingPlanes.js +48 -20
  60. package/dist/collection/lib/types/depthBuffer.js +32 -3
  61. package/dist/collection/lib/types/frame.js +133 -24
  62. package/dist/collection/lib/types/frameCamera.js +87 -6
  63. package/dist/collection/lib/types/viewport.js +34 -2
  64. package/dist/collection/testing/fixtures.js +28 -15
  65. package/dist/collection/testing/viewer.js +5 -3
  66. package/dist/custom-elements/index.js +2135 -283
  67. package/dist/esm/{browser.esm-59e914f6.js → browser.esm-e72d80ad.js} +1 -1
  68. package/dist/esm/{bundle.esm-d899b2d5.js → bundle.esm-8ceccb91.js} +80 -29
  69. package/dist/esm/{config-604c644e.js → config-fb7cd8ff.js} +2 -2
  70. package/dist/esm/{cursors-a7ec4adb.js → cursors-fc2deed7.js} +1 -1
  71. package/dist/esm/{dom-780d25be.js → dom-2cd18856.js} +1 -1
  72. package/dist/esm/{entities-759d97cd.js → entities-78557270.js} +3 -3
  73. package/dist/esm/index.js +12 -12
  74. package/dist/esm/index.mjs +12 -12
  75. package/dist/esm/loader.js +1 -1
  76. package/dist/esm/loader.mjs +1 -1
  77. package/dist/esm/{mapper-4b815e31.js → mapper-da36de17.js} +2 -2
  78. package/dist/esm/{markup-1d177b4a.js → markup-c313d99c.js} +2 -2
  79. package/dist/esm/{measurement-12cdbf5c.js → measurement-544b69d5.js} +2 -2
  80. package/dist/esm/{model-e5a4f00f.js → model-2a34b443.js} +1 -1
  81. package/dist/esm/{overlays-1919b192.js → overlays-354e275c.js} +2 -2
  82. package/dist/esm/{png-decoder-3f1fa486.js → png-decoder-07de80d1.js} +1 -1
  83. package/dist/esm/{results-994bdb50.js → results-4d0c3568.js} +1 -1
  84. package/dist/esm/{scene-2c2460d5.js → scene-2bfcce74.js} +188 -90
  85. package/dist/esm/{streamAttributes-d623bb60.js → streamAttributes-d0b384b3.js} +1502 -44
  86. package/dist/esm/{utils-83a19677.js → utils-3ea0acdd.js} +1 -1
  87. package/dist/esm/{utils-5e57bf24.js → utils-e0941c61.js} +1 -1
  88. package/dist/esm/vertex-scene-tree-search_3.entry.js +1 -1
  89. package/dist/esm/vertex-scene-tree-table-cell.entry.js +1 -1
  90. package/dist/esm/vertex-scene-tree.entry.js +4 -4
  91. package/dist/esm/vertex-viewer-dom-element_3.entry.js +8 -7
  92. package/dist/esm/vertex-viewer-markup-arrow_3.entry.js +3 -3
  93. package/dist/esm/vertex-viewer-markup-tool.entry.js +4 -4
  94. package/dist/esm/vertex-viewer-markup.entry.js +4 -4
  95. package/dist/esm/vertex-viewer-measurement-details.entry.js +3 -3
  96. package/dist/esm/vertex-viewer-measurement-distance.entry.js +20 -15
  97. package/dist/esm/vertex-viewer-measurement-line_2.entry.js +6 -6
  98. package/dist/esm/vertex-viewer-measurement-precise.entry.js +10 -10
  99. package/dist/esm/vertex-viewer-measurement-tool.entry.js +5 -5
  100. package/dist/esm/vertex-viewer-measurements.entry.js +8 -8
  101. package/dist/esm/vertex-viewer-view-cube.entry.js +3 -3
  102. package/dist/esm/vertex-viewer.entry.js +287 -80
  103. package/dist/esm/viewer.js +1 -1
  104. package/dist/esm/{viewport-01c886ea.js → viewport-5cc7b128.js} +34 -2
  105. package/dist/types/components/scene-tree-table-cell/scene-tree-table-cell.d.ts +1 -1
  106. package/dist/types/components/viewer/viewer.d.ts +8 -0
  107. package/dist/types/components/viewer-dom-renderer/renderer2d.d.ts +2 -2
  108. package/dist/types/components/viewer-dom-renderer/renderer3d.d.ts +3 -3
  109. package/dist/types/components/viewer-dom-renderer/viewer-dom-renderer.d.ts +2 -2
  110. package/dist/types/components/viewer-measurement-distance/hitTest.d.ts +3 -2
  111. package/dist/types/components/viewer-measurement-distance/utils.d.ts +2 -2
  112. package/dist/types/components/viewer-measurement-distance/viewer-measurement-distance.d.ts +2 -2
  113. package/dist/types/components/viewer-measurement-overlays/viewer-measurement-overlays-components.d.ts +2 -2
  114. package/dist/types/components/viewer-measurement-overlays/viewer-measurement-overlays.d.ts +2 -2
  115. package/dist/types/components.d.ts +15 -7
  116. package/dist/types/index.d.ts +1 -1
  117. package/dist/types/lib/errors.d.ts +3 -0
  118. package/dist/types/lib/interactions/index.d.ts +2 -0
  119. package/dist/types/lib/interactions/interactionApi.d.ts +34 -26
  120. package/dist/types/lib/interactions/interactionApiOrthographic.d.ts +35 -0
  121. package/dist/types/lib/interactions/interactionApiPerspective.d.ts +21 -0
  122. package/dist/types/lib/mappers/frameStreaming.d.ts +2 -0
  123. package/dist/types/lib/rendering/vectors.d.ts +2 -0
  124. package/dist/types/lib/scenes/__mocks__/mocks.d.ts +2 -2
  125. package/dist/types/lib/scenes/camera.d.ts +101 -38
  126. package/dist/types/lib/scenes/scene.d.ts +1 -1
  127. package/dist/types/lib/types/clippingPlanes.d.ts +3 -1
  128. package/dist/types/lib/types/depthBuffer.d.ts +28 -6
  129. package/dist/types/lib/types/frame.d.ts +80 -11
  130. package/dist/types/lib/types/frameCamera.d.ts +22 -3
  131. package/dist/types/lib/types/viewport.d.ts +24 -4
  132. package/dist/types/testing/fixtures.d.ts +8 -5
  133. package/dist/viewer/index.esm.js +1 -1
  134. package/dist/viewer/{p-f8d01b8a.entry.js → p-0a189e62.entry.js} +1 -1
  135. package/dist/viewer/{p-e07377fa.entry.js → p-1ca95f9a.entry.js} +1 -1
  136. package/dist/viewer/{p-d00e9203.js → p-3561d910.js} +1 -1
  137. package/dist/viewer/p-388a43f7.js +4 -0
  138. package/dist/viewer/{p-3810c24d.js → p-3f0f83ad.js} +1 -1
  139. package/dist/viewer/{p-8decee06.entry.js → p-41028d3b.entry.js} +1 -1
  140. package/dist/viewer/{p-439220c6.js → p-487e054a.js} +1 -1
  141. package/dist/viewer/p-49d36e94.entry.js +4 -0
  142. package/dist/viewer/{p-da2f4a56.js → p-5b342e97.js} +1 -1
  143. package/dist/viewer/p-661f0612.js +18 -0
  144. package/dist/viewer/{p-364ce21c.js → p-69058178.js} +1 -1
  145. package/dist/viewer/{p-353cfc7a.entry.js → p-73a5eacc.entry.js} +1 -1
  146. package/dist/viewer/p-77be081a.js +4 -0
  147. package/dist/viewer/{p-a0df0e0c.js → p-809d09d9.js} +1 -1
  148. package/dist/viewer/{p-d90f2f6d.entry.js → p-858bd2c7.entry.js} +1 -1
  149. package/dist/viewer/{p-25eaab00.entry.js → p-89b66838.entry.js} +1 -1
  150. package/dist/viewer/p-a93a63a9.js +4 -0
  151. package/dist/viewer/{p-df292b56.entry.js → p-b043b076.entry.js} +1 -1
  152. package/dist/viewer/{p-915d95ad.entry.js → p-b0ac6b3c.entry.js} +1 -1
  153. package/dist/viewer/{p-fec1a8d0.entry.js → p-b7624ff2.entry.js} +1 -1
  154. package/dist/viewer/{p-f7cb7e59.js → p-b8774c9c.js} +1 -1
  155. package/dist/viewer/{p-67446e35.js → p-bcb66f97.js} +1 -1
  156. package/dist/viewer/p-bcde5521.entry.js +4 -0
  157. package/dist/viewer/{p-7cad9bf4.js → p-d1584404.js} +1 -1
  158. package/dist/viewer/p-d32b54cb.js +4 -0
  159. package/dist/viewer/{p-f755af5a.entry.js → p-d3a20af4.entry.js} +1 -1
  160. package/dist/viewer/{p-c62cb926.entry.js → p-d9f99f4d.entry.js} +1 -1
  161. package/dist/viewer/p-e38458da.js +4 -0
  162. package/dist/viewer/{p-301660cf.js → p-e75bba97.js} +2 -2
  163. package/dist/viewer/{p-6e80f8b0.entry.js → p-ebd55df7.entry.js} +1 -1
  164. package/dist/viewer/{p-671c113c.entry.js → p-f0411993.entry.js} +1 -1
  165. package/dist/viewer/{p-2cefb1b0.js → p-fa9a0bed.js} +1 -1
  166. package/dist/viewer/p-ffdeb08c.js +4 -0
  167. package/dist/viewer/viewer.esm.js +1 -1
  168. package/package.json +8 -8
  169. package/dist/viewer/p-081e6873.js +0 -4
  170. package/dist/viewer/p-085e908a.js +0 -4
  171. package/dist/viewer/p-0aba71fd.js +0 -18
  172. package/dist/viewer/p-3f6ac74f.js +0 -4
  173. package/dist/viewer/p-423410be.js +0 -4
  174. package/dist/viewer/p-432267bc.entry.js +0 -4
  175. package/dist/viewer/p-4985fad5.js +0 -4
  176. package/dist/viewer/p-e2297df2.entry.js +0 -4
  177. package/dist/viewer/p-fe11d694.js +0 -4
@@ -3,9 +3,9 @@
3
3
  */
4
4
  'use strict';
5
5
 
6
- const browser_esm = require('./browser.esm-31b03292.js');
7
- const bundle_esm = require('./bundle.esm-dc0a8361.js');
8
- const streamAttributes = require('./streamAttributes-d6236448.js');
6
+ const browser_esm = require('./browser.esm-075810bf.js');
7
+ const bundle_esm = require('./bundle.esm-618a5fe9.js');
8
+ const streamAttributes = require('./streamAttributes-81eb52f2.js');
9
9
 
10
10
  const defaultColor = {
11
11
  opacity: 100,
@@ -169,6 +169,13 @@ class InvalidArgumentError extends CustomError {
169
169
  Object.setPrototypeOf(this, InvalidArgumentError.prototype);
170
170
  }
171
171
  }
172
+ class InvalidCameraError extends CustomError {
173
+ constructor(message, e) {
174
+ super(message, e);
175
+ // Allows for `instanceof` checks.
176
+ Object.setPrototypeOf(this, InvalidCameraError.prototype);
177
+ }
178
+ }
172
179
 
173
180
  function fromUrn(urn) {
174
181
  const uri = browser_esm.uri.parse(urn);
@@ -459,7 +466,7 @@ function buildFlyToOperation(frameCorrelationId, options, animation) {
459
466
  }) });
460
467
  }
461
468
  case 'camera': {
462
- return Object.assign(Object.assign({}, payload), { camera: options.flyTo.data });
469
+ return Object.assign(Object.assign({}, payload), { camera: streamAttributes.toProtobuf(options.flyTo.data) });
463
470
  }
464
471
  case 'bounding-box': {
465
472
  return Object.assign(Object.assign({}, payload), { boundingBox: {
@@ -593,32 +600,19 @@ class FlyToExecutor {
593
600
  * a new instance of the class with the updated properties.
594
601
  */
595
602
  class Camera {
596
- constructor(stream, aspect, data, boundingBox, decodeFrame) {
603
+ constructor(stream, aspect, data, boundingBox, decodeFrame, flyToOptions) {
597
604
  this.stream = stream;
598
605
  this.aspect = aspect;
599
606
  this.data = data;
600
607
  this.boundingBox = boundingBox;
601
608
  this.decodeFrame = decodeFrame;
609
+ this.flyToOptions = flyToOptions;
602
610
  }
603
- /**
604
- * Updates the position of the camera such that the given bounding box will
605
- * be contained within the camera's view.
606
- *
607
- * @param boundingBox The bounding box to position to.
608
- */
609
- fitToBoundingBox(boundingBox) {
610
- const radius = 1.1 *
611
- bundle_esm.vector3.magnitude(bundle_esm.vector3.subtract(boundingBox.max, bundle_esm.boundingBox.center(boundingBox)));
612
- // ratio of the height of the frustum to the distance along the view vector
613
- let hOverD = Math.tan(this.fovY * PI_OVER_360);
614
- if (this.aspectRatio < 1.0) {
615
- hOverD *= this.aspectRatio;
616
- }
617
- const distance = Math.abs(radius / hOverD);
618
- const vvec = bundle_esm.vector3.scale(distance, bundle_esm.vector3.normalize(this.viewVector()));
611
+ fitCameraToBoundingBox(boundingBox, distance, viewVector) {
612
+ const vvec = bundle_esm.vector3.scale(distance, bundle_esm.vector3.normalize(viewVector));
619
613
  const lookAt = bundle_esm.boundingBox.center(boundingBox);
620
614
  const position = bundle_esm.vector3.subtract(lookAt, vvec);
621
- return this.update({ lookAt, position });
615
+ return this.update({ lookAt, position, viewVector: vvec });
622
616
  }
623
617
  /**
624
618
  * Returns the distance from the camera's position to the center
@@ -626,12 +620,11 @@ class Camera {
626
620
  *
627
621
  * @param boundingBox - The bounding box to determine distance from.
628
622
  */
629
- distanceToBoundingBoxCenter(boundingBox) {
630
- const box = boundingBox || this.boundingBox;
631
- const boundingBoxCenter = bundle_esm.boundingBox.center(box);
632
- const cameraToCenter = bundle_esm.vector3.subtract(this.position, boundingBoxCenter);
633
- const distanceToCenterAlongViewVec = Math.abs(bundle_esm.vector3.dot(bundle_esm.vector3.subtract(this.lookAt, this.position), cameraToCenter)) / bundle_esm.vector3.magnitude(bundle_esm.vector3.subtract(this.lookAt, this.position));
634
- return distanceToCenterAlongViewVec;
623
+ signedDistanceToBoundingBoxCenter(boundingBox) {
624
+ const { position, viewVector } = streamAttributes.withPositionAndViewVector(this.data);
625
+ const boundingBoxCenter = bundle_esm.boundingBox.center(boundingBox !== null && boundingBox !== void 0 ? boundingBox : this.boundingBox);
626
+ const cameraToCenter = bundle_esm.vector3.subtract(boundingBoxCenter, position);
627
+ return (bundle_esm.vector3.dot(viewVector, cameraToCenter) / bundle_esm.vector3.magnitude(viewVector));
635
628
  }
636
629
  /**
637
630
  * Specifies that the next render of the camera will be repositioned to one of
@@ -642,26 +635,14 @@ class Camera {
642
635
  */
643
636
  flyTo(paramsOrQuery) {
644
637
  if (typeof paramsOrQuery !== 'function') {
645
- this.flyToOptions = { flyTo: this.buildFlyToType(paramsOrQuery) };
646
- return this;
638
+ return this.updateFlyToOptions({
639
+ flyTo: this.buildFlyToType(paramsOrQuery),
640
+ });
647
641
  }
648
642
  else {
649
- this.flyToOptions = paramsOrQuery(new FlyToExecutor()).build();
650
- return this;
643
+ return this.updateFlyToOptions(paramsOrQuery(new FlyToExecutor()).build());
651
644
  }
652
645
  }
653
- /**
654
- * Shifts the position of the camera by the given delta.
655
- *
656
- * @param delta The number of units to shift the camera on the X, Y, and Z
657
- * axis.
658
- */
659
- moveBy(delta) {
660
- return this.update({
661
- position: bundle_esm.vector3.add(this.position, delta),
662
- lookAt: bundle_esm.vector3.add(this.lookAt, delta),
663
- });
664
- }
665
646
  viewAll() {
666
647
  return this.fitToBoundingBox(this.boundingBox);
667
648
  }
@@ -693,7 +674,7 @@ class Camera {
693
674
  }
694
675
  else {
695
676
  this.stream.replaceCamera({
696
- camera: this.data,
677
+ camera: streamAttributes.toProtobuf(this.data),
697
678
  frameCorrelationId: { value: corrId },
698
679
  });
699
680
  return new CameraRenderResult(this.stream, this.decodeFrame, {
@@ -713,22 +694,7 @@ class Camera {
713
694
  * @param axis A normalized vector to rotate around.
714
695
  */
715
696
  rotateAroundAxis(angleInRadians, axis) {
716
- return this.rotateAroundAxisAtPoint(angleInRadians, this.lookAt, axis);
717
- }
718
- /**
719
- * Repositions the camera by rotating its current position around an axis
720
- * defined at a specific world point.
721
- *
722
- * @param angleInRadians The angle, in radians, to rotate.
723
- * @param point The point in world space to place the axis at.
724
- * @param axis A normalized vector to rotate around.
725
- */
726
- rotateAroundAxisAtPoint(angleInRadians, point, axis) {
727
- return this.update({
728
- position: bundle_esm.vector3.rotateAboutAxis(angleInRadians, this.position, axis, point),
729
- lookAt: bundle_esm.vector3.rotateAboutAxis(angleInRadians, this.lookAt, axis, point),
730
- up: bundle_esm.vector3.rotateAboutAxis(angleInRadians, this.up, axis, bundle_esm.vector3.origin()),
731
- });
697
+ return this.rotateAroundAxisAtPoint(angleInRadians, this.data.lookAt, axis);
732
698
  }
733
699
  /**
734
700
  * Updates the `position` and `up` vectors of the camera to the given standard
@@ -740,24 +706,11 @@ class Camera {
740
706
  standardView(standardView) {
741
707
  return this.update({
742
708
  position: standardView.position,
709
+ viewVector: bundle_esm.vector3.subtract(bundle_esm.vector3.origin(), standardView.position),
743
710
  lookAt: bundle_esm.vector3.origin(),
744
711
  up: standardView.up,
745
712
  });
746
713
  }
747
- /**
748
- * Updates the `position`, `lookAt` and/or `up` vectors of the camera.
749
- *
750
- * @param camera The values to update the camera to.
751
- */
752
- update(camera) {
753
- return new Camera(this.stream, this.aspectRatio, Object.assign(Object.assign({}, this.data), camera), this.boundingBox, this.decodeFrame);
754
- }
755
- /**
756
- * Returns a `FramePerspectiveCamera` representation.
757
- */
758
- toFrameCamera() {
759
- return new streamAttributes.FramePerspectiveCamera(this.position, this.lookAt, this.up, this.near, this.far, this.aspectRatio, this.fovY);
760
- }
761
714
  buildFlyToType(options) {
762
715
  if (options.boundingBox != null) {
763
716
  return { type: 'bounding-box', data: options.boundingBox };
@@ -778,36 +731,76 @@ class Camera {
778
731
  computeClippingPlanes(camera) {
779
732
  return streamAttributes.fromBoundingBoxAndLookAtCamera(this.boundingBox, camera);
780
733
  }
734
+ }
735
+ class PerspectiveCamera extends Camera {
736
+ constructor(stream, aspect, perspectiveData, boundingBox, decodeFrame, flyToOptions) {
737
+ super(stream, aspect, perspectiveData, boundingBox, decodeFrame, flyToOptions);
738
+ this.perspectiveData = perspectiveData;
739
+ }
781
740
  /**
782
- * Returns the view vector for the camera, which is the direction between the
783
- * `position` and `lookAt` vectors.
741
+ * Shifts the position of the camera by the given delta.
742
+ *
743
+ * @param delta The number of units to shift the camera on the X, Y, and Z
744
+ * axis.
784
745
  */
785
- viewVector() {
746
+ moveBy(delta) {
747
+ return this.update({
748
+ position: bundle_esm.vector3.add(this.position, delta),
749
+ lookAt: bundle_esm.vector3.add(this.lookAt, delta),
750
+ });
751
+ }
752
+ rotateAroundAxisAtPoint(angleInRadians, point, axis) {
753
+ return this.update({
754
+ position: bundle_esm.vector3.rotateAboutAxis(angleInRadians, this.position, axis, point),
755
+ lookAt: bundle_esm.vector3.rotateAboutAxis(angleInRadians, this.lookAt, axis, point),
756
+ up: bundle_esm.vector3.rotateAboutAxis(angleInRadians, this.up, axis, bundle_esm.vector3.origin()),
757
+ });
758
+ }
759
+ fitToBoundingBox(boundingBox) {
760
+ var _a;
761
+ const radius = 1.1 *
762
+ bundle_esm.vector3.magnitude(bundle_esm.vector3.subtract(boundingBox.max, bundle_esm.boundingBox.center(boundingBox)));
763
+ // ratio of the height of the frustum to the distance along the view vector
764
+ let hOverD = Math.tan(((_a = this.fovY) !== null && _a !== void 0 ? _a : 45) * PI_OVER_360);
765
+ if (this.aspect < 1.0) {
766
+ hOverD *= this.aspect;
767
+ }
768
+ const distance = Math.abs(radius / hOverD);
769
+ return super.fitCameraToBoundingBox(boundingBox, distance, this.viewVector);
770
+ }
771
+ update(camera) {
772
+ return new PerspectiveCamera(this.stream, this.aspect, Object.assign(Object.assign({}, this.perspectiveData), camera), this.boundingBox, this.decodeFrame, this.flyToOptions);
773
+ }
774
+ toFrameCamera() {
775
+ var _a;
776
+ return new streamAttributes.FramePerspectiveCamera(this.position, this.lookAt, this.up, this.near, this.far, this.aspectRatio, (_a = this.fovY) !== null && _a !== void 0 ? _a : 45);
777
+ }
778
+ get viewVector() {
786
779
  return bundle_esm.vector3.subtract(this.lookAt, this.position);
787
780
  }
788
781
  /**
789
782
  * The position vector for the camera, in world space coordinates.
790
783
  */
791
784
  get position() {
792
- return Object.assign({}, this.data.position);
785
+ return Object.assign({}, this.perspectiveData.position);
793
786
  }
794
787
  /**
795
788
  * A normalized vector representing the up direction.
796
789
  */
797
790
  get up() {
798
- return Object.assign({}, this.data.up);
791
+ return Object.assign({}, this.perspectiveData.up);
799
792
  }
800
793
  /**
801
794
  * A vector, in world space coordinates, of where the camera is pointed at.
802
795
  */
803
796
  get lookAt() {
804
- return Object.assign({}, this.data.lookAt);
797
+ return Object.assign({}, this.perspectiveData.lookAt);
805
798
  }
806
799
  /**
807
800
  * The camera's field of view.
808
801
  */
809
802
  get fovY() {
810
- return 45;
803
+ return this.perspectiveData.fovY;
811
804
  }
812
805
  /**
813
806
  * The aspect ratio of the camera.
@@ -819,16 +812,108 @@ class Camera {
819
812
  * The camera's near clipping plane.
820
813
  */
821
814
  get near() {
822
- const { near } = this.computeClippingPlanes(this.data);
815
+ const { near } = this.computeClippingPlanes(this.perspectiveData);
823
816
  return near;
824
817
  }
825
818
  /**
826
819
  * The camera's far clipping plane.
827
820
  */
828
821
  get far() {
829
- const { far } = this.computeClippingPlanes(this.data);
822
+ const { far } = this.computeClippingPlanes(this.perspectiveData);
830
823
  return far;
831
824
  }
825
+ updateFlyToOptions(flyToOptions) {
826
+ return new PerspectiveCamera(this.stream, this.aspect, this.perspectiveData, this.boundingBox, this.decodeFrame, flyToOptions);
827
+ }
828
+ }
829
+ class OrthographicCamera extends Camera {
830
+ constructor(stream, aspect, orthographicData, boundingBox, decodeFrame, flyToOptions) {
831
+ super(stream, aspect, orthographicData, boundingBox, decodeFrame, flyToOptions);
832
+ this.orthographicData = orthographicData;
833
+ }
834
+ /**
835
+ * Shifts the position of the camera by the given delta.
836
+ *
837
+ * @param delta The number of units to shift the camera on the X, Y, and Z
838
+ * axis.
839
+ */
840
+ moveBy(delta) {
841
+ return this.update({
842
+ lookAt: bundle_esm.vector3.add(this.lookAt, delta),
843
+ });
844
+ }
845
+ rotateAroundAxisAtPoint(angleInRadians, point, axis) {
846
+ const updatedLookAt = bundle_esm.vector3.rotateAboutAxis(angleInRadians, this.lookAt, axis, point);
847
+ const updatedPosition = bundle_esm.vector3.rotateAboutAxis(angleInRadians, this.position, axis, point);
848
+ const viewVector = streamAttributes.constrainViewVector(bundle_esm.vector3.subtract(updatedLookAt, updatedPosition), bundle_esm.boundingSphere.create(this.boundingBox));
849
+ return this.update({
850
+ viewVector: viewVector,
851
+ lookAt: updatedLookAt,
852
+ up: bundle_esm.vector3.rotateAboutAxis(angleInRadians, this.up, axis, bundle_esm.vector3.origin()),
853
+ });
854
+ }
855
+ fitToBoundingBox(boundingBox) {
856
+ const boundingSphere = bundle_esm.boundingSphere.create(boundingBox);
857
+ const fitAll = super.fitCameraToBoundingBox(boundingBox, boundingSphere.radius, this.viewVector);
858
+ return this.update({
859
+ lookAt: fitAll.lookAt,
860
+ viewVector: fitAll.viewVector,
861
+ fovHeight: boundingSphere.radius * 2,
862
+ });
863
+ }
864
+ update(camera) {
865
+ return new OrthographicCamera(this.stream, this.aspect, Object.assign(Object.assign({}, this.orthographicData), camera), this.boundingBox, this.decodeFrame, this.flyToOptions);
866
+ }
867
+ toFrameCamera() {
868
+ return new streamAttributes.FrameOrthographicCamera(streamAttributes.constrainViewVector(this.viewVector, bundle_esm.boundingSphere.create(this.boundingBox)), this.lookAt, this.up, this.near, this.far, this.aspectRatio, this.fovHeight);
869
+ }
870
+ get viewVector() {
871
+ return Object.assign({}, this.orthographicData.viewVector);
872
+ }
873
+ get position() {
874
+ return bundle_esm.vector3.add(this.lookAt, bundle_esm.vector3.negate(this.viewVector));
875
+ }
876
+ /**
877
+ * A normalized vector representing the up direction.
878
+ */
879
+ get up() {
880
+ return Object.assign({}, this.orthographicData.up);
881
+ }
882
+ /**
883
+ * A vector, in world space coordinates, of where the camera is pointed at.
884
+ */
885
+ get lookAt() {
886
+ return Object.assign({}, this.orthographicData.lookAt);
887
+ }
888
+ /**
889
+ * The camera's field of view.
890
+ */
891
+ get fovHeight() {
892
+ return this.orthographicData.fovHeight;
893
+ }
894
+ /**
895
+ * The aspect ratio of the camera.
896
+ */
897
+ get aspectRatio() {
898
+ return this.aspect;
899
+ }
900
+ /**
901
+ * The camera's near clipping plane.
902
+ */
903
+ get near() {
904
+ const { near } = this.computeClippingPlanes(this.orthographicData);
905
+ return near;
906
+ }
907
+ /**
908
+ * The camera's far clipping plane.
909
+ */
910
+ get far() {
911
+ const { far } = this.computeClippingPlanes(this.orthographicData);
912
+ return far;
913
+ }
914
+ updateFlyToOptions(flyToOptions) {
915
+ return new OrthographicCamera(this.stream, this.aspect, this.orthographicData, this.boundingBox, this.decodeFrame, flyToOptions);
916
+ }
832
917
  }
833
918
 
834
919
  /**
@@ -1235,12 +1320,25 @@ class Scene {
1235
1320
  */
1236
1321
  camera() {
1237
1322
  const { scene } = this.frame;
1238
- const data = {
1239
- position: scene.camera.position,
1240
- lookAt: scene.camera.lookAt,
1241
- up: scene.camera.up,
1242
- };
1243
- return new Camera(this.stream, bundle_esm.dimensions.aspectRatio(this.viewport()), data, this.frame.scene.boundingBox, this.decodeFrame);
1323
+ if (scene.camera.isOrthographic()) {
1324
+ return new OrthographicCamera(this.stream, bundle_esm.dimensions.aspectRatio(this.viewport()), {
1325
+ viewVector: scene.camera.viewVector,
1326
+ lookAt: scene.camera.lookAt,
1327
+ up: scene.camera.up,
1328
+ fovHeight: scene.camera.fovHeight,
1329
+ }, this.frame.scene.boundingBox, this.decodeFrame);
1330
+ }
1331
+ else if (scene.camera.isPerspective()) {
1332
+ return new PerspectiveCamera(this.stream, bundle_esm.dimensions.aspectRatio(this.viewport()), {
1333
+ position: scene.camera.position,
1334
+ lookAt: scene.camera.lookAt,
1335
+ up: scene.camera.up,
1336
+ fovY: scene.camera.fovY,
1337
+ }, this.frame.scene.boundingBox, this.decodeFrame);
1338
+ }
1339
+ else {
1340
+ throw new InvalidCameraError('Cannot retrieve camera. Scene has an unknown or invalid camera type.');
1341
+ }
1244
1342
  }
1245
1343
  boundingBox() {
1246
1344
  return this.frame.scene.boundingBox;