@vertexvis/viewer 0.17.2-canary.0 → 0.17.2

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 (44) hide show
  1. package/dist/cjs/controller-b93c925e.js +126 -0
  2. package/dist/cjs/controller-b93c925e.js.map +1 -0
  3. package/dist/cjs/index.cjs.js +79 -7
  4. package/dist/cjs/index.cjs.js.map +1 -1
  5. package/dist/cjs/vertex-viewer-transform-widget.cjs.entry.js +18 -121
  6. package/dist/cjs/vertex-viewer-transform-widget.cjs.entry.js.map +1 -1
  7. package/dist/collection/components/viewer-transform-widget/util.js +9 -2
  8. package/dist/collection/components/viewer-transform-widget/util.js.map +1 -1
  9. package/dist/collection/components/viewer-transform-widget/viewer-transform-widget.js +7 -2
  10. package/dist/collection/components/viewer-transform-widget/viewer-transform-widget.js.map +1 -1
  11. package/dist/collection/index.js +1 -0
  12. package/dist/collection/index.js.map +1 -1
  13. package/dist/collection/lib/transforms/index.js +7 -0
  14. package/dist/collection/lib/transforms/index.js.map +1 -0
  15. package/dist/collection/lib/transforms/transformation-delta.js +67 -0
  16. package/dist/collection/lib/transforms/transformation-delta.js.map +1 -0
  17. package/dist/collection/testing/random.js +12 -0
  18. package/dist/collection/testing/random.js.map +1 -1
  19. package/dist/custom-elements/index.js +204 -121
  20. package/dist/custom-elements/index.js.map +1 -1
  21. package/dist/esm/controller-bf3848bf.js +124 -0
  22. package/dist/esm/controller-bf3848bf.js.map +1 -0
  23. package/dist/esm/index.js +75 -1
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/index.mjs +75 -1
  26. package/dist/esm/vertex-viewer-transform-widget.entry.js +18 -121
  27. package/dist/esm/vertex-viewer-transform-widget.entry.js.map +1 -1
  28. package/dist/types/components/viewer-transform-widget/util.d.ts +8 -1
  29. package/dist/types/components/viewer-transform-widget/viewer-transform-widget.d.ts +1 -1
  30. package/dist/types/index.d.ts +1 -0
  31. package/dist/types/lib/transforms/index.d.ts +3 -0
  32. package/dist/types/lib/transforms/transformation-delta.d.ts +34 -0
  33. package/dist/types/testing/random.d.ts +1 -0
  34. package/dist/viewer/index.esm.js +1 -1
  35. package/dist/viewer/index.esm.js.map +1 -1
  36. package/dist/viewer/p-4025ad8d.js +5 -0
  37. package/dist/viewer/p-4025ad8d.js.map +1 -0
  38. package/dist/viewer/p-839064b7.entry.js +5 -0
  39. package/dist/viewer/p-839064b7.entry.js.map +1 -0
  40. package/dist/viewer/viewer.esm.js +1 -1
  41. package/package.json +7 -7
  42. package/readme.md +4 -4
  43. package/dist/viewer/p-844f80b3.entry.js +0 -5
  44. package/dist/viewer/p-844f80b3.entry.js.map +0 -1
@@ -105381,6 +105381,193 @@ class Scene {
105381
105381
  }
105382
105382
  }
105383
105383
 
105384
+ const ALMOST_ONE = 0.9999;
105385
+ /**
105386
+ * For any single vector, there are an infinite number of potential orthogonal vectors. This function will determine
105387
+ * one orthogonal vector by crossing the provided vector with a unit vector in the positive X, Y, or Z directions.
105388
+ * @param normal
105389
+ * @returns
105390
+ */
105391
+ function chooseOrthogonalVector(normal) {
105392
+ const absNorm = vector3.create(Math.abs(normal.x), Math.abs(normal.y), Math.abs(normal.z));
105393
+ const x = absNorm.x < absNorm.y && absNorm.x < absNorm.z ? 1.0 : 0.0;
105394
+ const y = absNorm.y <= absNorm.x && absNorm.y < absNorm.z ? 1.0 : 0.0;
105395
+ const z = absNorm.z <= absNorm.x && absNorm.z <= absNorm.y ? 1.0 : 0.0;
105396
+ const vector = vector3.create(x, y, z);
105397
+ return vector3.normalize(vector3.cross(normal, vector));
105398
+ }
105399
+ /**
105400
+ * Computes the rotation matrix for two normals. If both normals are neither parallel or anti-parallel,
105401
+ * this will compute the rotation matrix delta based on the angle from both normals.
105402
+ * If the normals are anti-parallel, the identity matrix will be returned, as no rotation is necessary in this case.
105403
+ * If the normals are parallel, an axis direction based on a chosen orthogonal vector will be used
105404
+ * to compute the rotation matrix to rotate the plane 180 degrees.
105405
+ * @param normal1
105406
+ * @param normal2
105407
+ * @returns an anti-parallel rotation Matrix4 betwen the given normals
105408
+ */
105409
+ function computeRotationMatrix(normal1, normal2) {
105410
+ const dot = vector3.dot(normal1, normal2);
105411
+ // the angle is almost 0 in this case.
105412
+ if (dot > ALMOST_ONE) {
105413
+ const axisDirection = chooseOrthogonalVector(normal1);
105414
+ const quaternion$1 = quaternion.fromAxisAngle(axisDirection, Math.PI);
105415
+ return matrix4.makeRotation(quaternion$1);
105416
+ }
105417
+ // the angle is almost 180 in this case.
105418
+ else if (dot <= -ALMOST_ONE) {
105419
+ return matrix4.makeIdentity();
105420
+ }
105421
+ // the angle is between 0 & 180
105422
+ else {
105423
+ const angle = vector3.angleTo(normal2, normal1);
105424
+ const axisDirection = vector3.normalize(vector3.cross(normal1, normal2));
105425
+ return matrix4.makeRotation(quaternion.fromAxisAngle(axisDirection, angle + Math.PI));
105426
+ }
105427
+ }
105428
+ /**
105429
+ * Computes the translation & rotation matrix delta between two world positions and two normals.
105430
+ * such that the computed translation matrix will be the delta between position 1 and position 2,
105431
+ * and the rotation will be rotated to be anti-parallel.
105432
+ *
105433
+ * @param normal1
105434
+ * @param position1
105435
+ * @param normal2
105436
+ * @param position2
105437
+ *
105438
+ * @returns Matrix4 translation matrix delta from position1 to
105439
+ * position2 & an anti-parallel rotation delta.
105440
+ */
105441
+ function computeTransformationDelta(normal1, position1, normal2, position2) {
105442
+ const rotationMatrix = computeRotationMatrix(normal1, normal2);
105443
+ const translationDeltaMatrix = matrix4.makeTranslation(position2);
105444
+ return matrix4.multiply(matrix4.multiply(translationDeltaMatrix, rotationMatrix), matrix4.makeTranslation(vector3.negate(position1)));
105445
+ }
105446
+
105447
+ const transformationDelta = /*#__PURE__*/Object.freeze({
105448
+ __proto__: null,
105449
+ ALMOST_ONE: ALMOST_ONE,
105450
+ chooseOrthogonalVector: chooseOrthogonalVector,
105451
+ computeRotationMatrix: computeRotationMatrix,
105452
+ computeTransformationDelta: computeTransformationDelta
105453
+ });
105454
+
105455
+ class TransformController {
105456
+ constructor(stream) {
105457
+ this.stream = stream;
105458
+ this.isTransforming = false;
105459
+ this.currentDelta = matrix4.makeIdentity();
105460
+ }
105461
+ async dispose() {
105462
+ if (this.isTransforming) {
105463
+ this.endTransform();
105464
+ }
105465
+ }
105466
+ async beginTransform(delta = matrix4.makeIdentity()) {
105467
+ if (!this.isTransforming) {
105468
+ this.currentDelta = delta;
105469
+ this.isTransforming = true;
105470
+ console.debug('Beginning transform interaction');
105471
+ await this.stream.beginInteraction({
105472
+ transform: {
105473
+ delta: this.toDeltaTransform(delta),
105474
+ },
105475
+ });
105476
+ }
105477
+ }
105478
+ async updateTransform(delta) {
105479
+ this.currentDelta = delta;
105480
+ await this.stream.updateInteraction({
105481
+ transform: {
105482
+ delta: this.toDeltaTransform(this.currentDelta, true),
105483
+ },
105484
+ });
105485
+ }
105486
+ async updateTranslation(delta) {
105487
+ this.currentDelta = matrix4.makeTranslation(delta);
105488
+ await this.stream.updateInteraction({
105489
+ transform: {
105490
+ delta: this.toDeltaTransform(this.currentDelta),
105491
+ },
105492
+ });
105493
+ }
105494
+ getCurrentDelta() {
105495
+ return this.currentDelta;
105496
+ }
105497
+ async endTransform() {
105498
+ if (this.isTransforming) {
105499
+ console.debug(`Ending transform interaction [delta=${this.currentDelta}]`);
105500
+ await this.stream.endInteraction({
105501
+ transform: {
105502
+ delta: this.toDeltaTransform(this.currentDelta),
105503
+ },
105504
+ });
105505
+ this.isTransforming = false;
105506
+ this.currentDelta = matrix4.makeIdentity();
105507
+ }
105508
+ }
105509
+ async endInteraction() {
105510
+ if (this.isTransforming) {
105511
+ await this.stream.endInteraction();
105512
+ this.isTransforming = false;
105513
+ this.currentDelta = matrix4.makeIdentity();
105514
+ }
105515
+ }
105516
+ clearTransform() {
105517
+ this.currentDelta = matrix4.makeIdentity();
105518
+ this.endTransform();
105519
+ }
105520
+ toDeltaTransform(delta, columnMajor = false) {
105521
+ const asObject = matrix4.toObject(delta);
105522
+ // TODO: update this to pass a single order for the
105523
+ // transform matrix after work in https://vertexvis.atlassian.net/browse/PLAT-1582
105524
+ const basisX = columnMajor
105525
+ ? {
105526
+ x: asObject.m11,
105527
+ y: asObject.m21,
105528
+ z: asObject.m31,
105529
+ }
105530
+ : {
105531
+ x: asObject.m11,
105532
+ y: asObject.m12,
105533
+ z: asObject.m13,
105534
+ };
105535
+ const basisY = columnMajor
105536
+ ? {
105537
+ x: asObject.m12,
105538
+ y: asObject.m22,
105539
+ z: asObject.m32,
105540
+ }
105541
+ : {
105542
+ x: asObject.m21,
105543
+ y: asObject.m22,
105544
+ z: asObject.m23,
105545
+ };
105546
+ const basisZ = columnMajor
105547
+ ? {
105548
+ x: asObject.m13,
105549
+ y: asObject.m23,
105550
+ z: asObject.m33,
105551
+ }
105552
+ : {
105553
+ x: asObject.m31,
105554
+ y: asObject.m32,
105555
+ z: asObject.m33,
105556
+ };
105557
+ return {
105558
+ basisX,
105559
+ basisY,
105560
+ basisZ,
105561
+ xlate: {
105562
+ x: asObject.m14,
105563
+ y: asObject.m24,
105564
+ z: asObject.m34,
105565
+ },
105566
+ scale: asObject.m44,
105567
+ };
105568
+ }
105569
+ }
105570
+
105384
105571
  class VolumeIntersectionQueryController {
105385
105572
  constructor(model, viewer) {
105386
105573
  this.model = model;
@@ -129221,122 +129408,6 @@ const ViewerToolbarGroup = class extends HTMLElement$1 {
129221
129408
  static get style() { return viewerToolbarGroupCss; }
129222
129409
  };
129223
129410
 
129224
- class TransformController {
129225
- constructor(stream) {
129226
- this.stream = stream;
129227
- this.isTransforming = false;
129228
- this.currentDelta = matrix4.makeIdentity();
129229
- }
129230
- async dispose() {
129231
- if (this.isTransforming) {
129232
- this.endTransform();
129233
- }
129234
- }
129235
- async beginTransform(delta = matrix4.makeIdentity()) {
129236
- if (!this.isTransforming) {
129237
- this.currentDelta = delta;
129238
- this.isTransforming = true;
129239
- console.debug('Beginning transform interaction');
129240
- await this.stream.beginInteraction({
129241
- transform: {
129242
- delta: this.toDeltaTransform(delta),
129243
- },
129244
- });
129245
- }
129246
- }
129247
- async updateTransform(delta) {
129248
- this.currentDelta = delta;
129249
- await this.stream.updateInteraction({
129250
- transform: {
129251
- delta: this.toDeltaTransform(this.currentDelta, true),
129252
- },
129253
- });
129254
- }
129255
- async updateTranslation(delta) {
129256
- this.currentDelta = matrix4.makeTranslation(delta);
129257
- await this.stream.updateInteraction({
129258
- transform: {
129259
- delta: this.toDeltaTransform(this.currentDelta),
129260
- },
129261
- });
129262
- }
129263
- getCurrentDelta() {
129264
- return this.currentDelta;
129265
- }
129266
- async endTransform() {
129267
- if (this.isTransforming) {
129268
- console.debug(`Ending transform interaction [delta=${this.currentDelta}]`);
129269
- await this.stream.endInteraction({
129270
- transform: {
129271
- delta: this.toDeltaTransform(this.currentDelta),
129272
- },
129273
- });
129274
- this.isTransforming = false;
129275
- this.currentDelta = matrix4.makeIdentity();
129276
- }
129277
- }
129278
- async endInteraction() {
129279
- if (this.isTransforming) {
129280
- await this.stream.endInteraction();
129281
- this.isTransforming = false;
129282
- this.currentDelta = matrix4.makeIdentity();
129283
- }
129284
- }
129285
- clearTransform() {
129286
- this.currentDelta = matrix4.makeIdentity();
129287
- this.endTransform();
129288
- }
129289
- toDeltaTransform(delta, columnMajor = false) {
129290
- const asObject = matrix4.toObject(delta);
129291
- // TODO: update this to pass a single order for the
129292
- // transform matrix after work in https://vertexvis.atlassian.net/browse/PLAT-1582
129293
- const basisX = columnMajor
129294
- ? {
129295
- x: asObject.m11,
129296
- y: asObject.m21,
129297
- z: asObject.m31,
129298
- }
129299
- : {
129300
- x: asObject.m11,
129301
- y: asObject.m12,
129302
- z: asObject.m13,
129303
- };
129304
- const basisY = columnMajor
129305
- ? {
129306
- x: asObject.m12,
129307
- y: asObject.m22,
129308
- z: asObject.m32,
129309
- }
129310
- : {
129311
- x: asObject.m21,
129312
- y: asObject.m22,
129313
- z: asObject.m23,
129314
- };
129315
- const basisZ = columnMajor
129316
- ? {
129317
- x: asObject.m13,
129318
- y: asObject.m23,
129319
- z: asObject.m33,
129320
- }
129321
- : {
129322
- x: asObject.m31,
129323
- y: asObject.m32,
129324
- z: asObject.m33,
129325
- };
129326
- return {
129327
- basisX,
129328
- basisY,
129329
- basisZ,
129330
- xlate: {
129331
- x: asObject.m14,
129332
- y: asObject.m24,
129333
- z: asObject.m34,
129334
- },
129335
- scale: asObject.m44,
129336
- };
129337
- }
129338
- }
129339
-
129340
129411
  function convertPointToCanvas(point$1, bounds) {
129341
129412
  return bounds != null
129342
129413
  ? point.create(point$1.x - bounds.left, point$1.y - bounds.top)
@@ -129410,8 +129481,15 @@ function computeTranslation(current, previous, next, direction) {
129410
129481
  const rotatedDelta = vector3.multiply(rotatedTranslationAxis, vector3.subtract(next, previous));
129411
129482
  return rotatedDelta.x + rotatedDelta.y + rotatedDelta.z;
129412
129483
  }
129413
- function computeRotation(rotationAxis, current) {
129414
- return matrix4.multiply(matrix4.multiply(matrix4.multiply(matrix4.makeTranslation(vector3.fromMatrixPosition(current)), matrix4.makeRotation(rotationAxis)), matrix4.makeTranslation(vector3.negate(vector3.fromMatrixPosition(current)))), current);
129484
+ /**
129485
+ * Computes a rotation Matrix4 by applying the rotation at the given position,
129486
+ * then translating it back to convert it to a world delta.
129487
+ * @param rotation
129488
+ * @param current
129489
+ * @returns
129490
+ */
129491
+ function computeRotation(rotation, current) {
129492
+ return matrix4.multiply(matrix4.multiply(matrix4.multiply(matrix4.makeTranslation(vector3.fromMatrixPosition(current)), matrix4.makeRotation(rotation)), matrix4.makeTranslation(vector3.negate(vector3.fromMatrixPosition(current)))), current);
129415
129493
  }
129416
129494
 
129417
129495
  function xAxisRotationPositions(widgetTransform, camera, triangleSize = 3) {
@@ -129935,6 +130013,11 @@ const ViewerTransformWidget = class extends HTMLElement$1 {
129935
130013
  hovered: this.hoveredColor,
129936
130014
  disabledColor: this.disabledColor,
129937
130015
  });
130016
+ if (this.rotation != null) {
130017
+ this.currentTransform = this.getTransformForNewRotation(this.rotation);
130018
+ this.startingTransform = this.currentTransform;
130019
+ this.widget.updateTransform(this.currentTransform);
130020
+ }
129938
130021
  if (this.position != null) {
129939
130022
  this.currentTransform = matrix4.makeTranslation(this.position);
129940
130023
  this.startingTransform = this.currentTransform;
@@ -129966,7 +130049,7 @@ const ViewerTransformWidget = class extends HTMLElement$1 {
129966
130049
  return matrix4.makeTranslation(newPosition);
129967
130050
  }
129968
130051
  };
129969
- this.getTransformForHewRotation = (newRotationEuler) => {
130052
+ this.getTransformForNewRotation = (newRotationEuler) => {
129970
130053
  const c = this.currentTransform != null
129971
130054
  ? this.currentTransform
129972
130055
  : matrix4.makeIdentity();
@@ -130062,7 +130145,7 @@ const ViewerTransformWidget = class extends HTMLElement$1 {
130062
130145
  */
130063
130146
  handleRotationChanged(newRotation, oldRotation) {
130064
130147
  var _a;
130065
- this.currentTransform = this.getTransformForHewRotation(newRotation);
130148
+ this.currentTransform = this.getTransformForNewRotation(newRotation);
130066
130149
  this.startingTransform = this.currentTransform;
130067
130150
  (_a = this.widget) === null || _a === void 0 ? void 0 : _a.updateTransform(this.currentTransform);
130068
130151
  console.debug(`Updating widget rotation [previous=${JSON.stringify(oldRotation)}, current=${JSON.stringify(newRotation)}]`);
@@ -130430,6 +130513,6 @@ const defineCustomElements = (opts) => {
130430
130513
  }
130431
130514
  };
130432
130515
 
130433
- export { AngleUnits, AreaUnits, ArrowMarkup, CircleMarkup, colorMaterial as ColorMaterial, CursorManager, DistanceUnits, EntityType, FrameCameraBase, FreeformMarkup, loadableResource as LoadableResource, MeasurementController, MeasurementEntity, MeasurementModel, MeasurementOverlayManager, Frame as ReceivedFrame, FrameImage as ReceivedFrameImage, FrameScene as ReceivedFrameScene, FrameOrthographicCamera as ReceivedOrthographicCamera, FramePerspectiveCamera as ReceivedPerspectiveCamera, Scene, SceneTreeController, SynchronizedClock, VertexSceneTree, VertexSceneTreeSearch, VertexSceneTreeTableCell, VertexSceneTreeTableColumn, VertexSceneTreeTableHeader, VertexSceneTreeTableLayout, VertexSceneTreeTableResizeDivider, VertexSceneTreeToolbar, VertexSceneTreeToolbarGroup, VertexViewer, VertexViewerBoxQueryTool, VertexViewerButton, VertexViewerDefaultToolbar, VertexViewerDomElement, VertexViewerDomGroup, VertexViewerDomRenderer, VertexViewerHitResultIndicator, VertexViewerIcon, VertexViewerLayer, VertexViewerMarkup, VertexViewerMarkupArrow, VertexViewerMarkupCircle, VertexViewerMarkupFreeform, VertexViewerMarkupTool, VertexViewerMeasurementDetails, VertexViewerMeasurementDistance, VertexViewerMeasurementLine, VertexViewerMeasurementOverlays, VertexViewerMeasurementPrecise, VertexViewerPinGroup, VertexViewerPinLabel, VertexViewerPinLabelLine, VertexViewerPinTool, VertexViewerSpinner, VertexViewerToolbar, VertexViewerToolbarGroup, VertexViewerTransformWidget, VertexViewerViewCube, Viewport, VolumeIntersectionQueryController, __awaiter as _, __generator as a, __spreadArray as b, boxQueryCursor, createCommonjsModule as c, defineCustomElements, fromNodeProto, isLoadedRow, labelPinCursor, makeMinimumDistanceResult, measurementCursor, measurementWithArrowCursor, pinCursor };
130516
+ export { AngleUnits, AreaUnits, ArrowMarkup, CircleMarkup, colorMaterial as ColorMaterial, CursorManager, DistanceUnits, EntityType, FrameCameraBase, FreeformMarkup, loadableResource as LoadableResource, MeasurementController, MeasurementEntity, MeasurementModel, MeasurementOverlayManager, Frame as ReceivedFrame, FrameImage as ReceivedFrameImage, FrameScene as ReceivedFrameScene, FrameOrthographicCamera as ReceivedOrthographicCamera, FramePerspectiveCamera as ReceivedPerspectiveCamera, Scene, SceneTreeController, SynchronizedClock, TransformController, transformationDelta as TransformationDelta, VertexSceneTree, VertexSceneTreeSearch, VertexSceneTreeTableCell, VertexSceneTreeTableColumn, VertexSceneTreeTableHeader, VertexSceneTreeTableLayout, VertexSceneTreeTableResizeDivider, VertexSceneTreeToolbar, VertexSceneTreeToolbarGroup, VertexViewer, VertexViewerBoxQueryTool, VertexViewerButton, VertexViewerDefaultToolbar, VertexViewerDomElement, VertexViewerDomGroup, VertexViewerDomRenderer, VertexViewerHitResultIndicator, VertexViewerIcon, VertexViewerLayer, VertexViewerMarkup, VertexViewerMarkupArrow, VertexViewerMarkupCircle, VertexViewerMarkupFreeform, VertexViewerMarkupTool, VertexViewerMeasurementDetails, VertexViewerMeasurementDistance, VertexViewerMeasurementLine, VertexViewerMeasurementOverlays, VertexViewerMeasurementPrecise, VertexViewerPinGroup, VertexViewerPinLabel, VertexViewerPinLabelLine, VertexViewerPinTool, VertexViewerSpinner, VertexViewerToolbar, VertexViewerToolbarGroup, VertexViewerTransformWidget, VertexViewerViewCube, Viewport, VolumeIntersectionQueryController, __awaiter as _, __generator as a, __spreadArray as b, boxQueryCursor, createCommonjsModule as c, defineCustomElements, fromNodeProto, isLoadedRow, labelPinCursor, makeMinimumDistanceResult, measurementCursor, measurementWithArrowCursor, pinCursor };
130434
130517
 
130435
130518
  //# sourceMappingURL=index.js.map