@vertexvis/viewer 0.17.1 → 0.17.2-canary.1

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 (43) 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/dist/viewer/p-844f80b3.entry.js +0 -5
  43. package/dist/viewer/p-844f80b3.entry.js.map +0 -1
@@ -0,0 +1,126 @@
1
+ /*!
2
+ * Copyright (c) 2023 Vertex Software LLC. All rights reserved.
3
+ */
4
+ 'use strict';
5
+
6
+ const bundle_esm = require('./bundle.esm-5847ff0b.js');
7
+
8
+ class TransformController {
9
+ constructor(stream) {
10
+ this.stream = stream;
11
+ this.isTransforming = false;
12
+ this.currentDelta = bundle_esm.matrix4.makeIdentity();
13
+ }
14
+ async dispose() {
15
+ if (this.isTransforming) {
16
+ this.endTransform();
17
+ }
18
+ }
19
+ async beginTransform(delta = bundle_esm.matrix4.makeIdentity()) {
20
+ if (!this.isTransforming) {
21
+ this.currentDelta = delta;
22
+ this.isTransforming = true;
23
+ console.debug('Beginning transform interaction');
24
+ await this.stream.beginInteraction({
25
+ transform: {
26
+ delta: this.toDeltaTransform(delta),
27
+ },
28
+ });
29
+ }
30
+ }
31
+ async updateTransform(delta) {
32
+ this.currentDelta = delta;
33
+ await this.stream.updateInteraction({
34
+ transform: {
35
+ delta: this.toDeltaTransform(this.currentDelta, true),
36
+ },
37
+ });
38
+ }
39
+ async updateTranslation(delta) {
40
+ this.currentDelta = bundle_esm.matrix4.makeTranslation(delta);
41
+ await this.stream.updateInteraction({
42
+ transform: {
43
+ delta: this.toDeltaTransform(this.currentDelta),
44
+ },
45
+ });
46
+ }
47
+ getCurrentDelta() {
48
+ return this.currentDelta;
49
+ }
50
+ async endTransform() {
51
+ if (this.isTransforming) {
52
+ console.debug(`Ending transform interaction [delta=${this.currentDelta}]`);
53
+ await this.stream.endInteraction({
54
+ transform: {
55
+ delta: this.toDeltaTransform(this.currentDelta),
56
+ },
57
+ });
58
+ this.isTransforming = false;
59
+ this.currentDelta = bundle_esm.matrix4.makeIdentity();
60
+ }
61
+ }
62
+ async endInteraction() {
63
+ if (this.isTransforming) {
64
+ await this.stream.endInteraction();
65
+ this.isTransforming = false;
66
+ this.currentDelta = bundle_esm.matrix4.makeIdentity();
67
+ }
68
+ }
69
+ clearTransform() {
70
+ this.currentDelta = bundle_esm.matrix4.makeIdentity();
71
+ this.endTransform();
72
+ }
73
+ toDeltaTransform(delta, columnMajor = false) {
74
+ const asObject = bundle_esm.matrix4.toObject(delta);
75
+ // TODO: update this to pass a single order for the
76
+ // transform matrix after work in https://vertexvis.atlassian.net/browse/PLAT-1582
77
+ const basisX = columnMajor
78
+ ? {
79
+ x: asObject.m11,
80
+ y: asObject.m21,
81
+ z: asObject.m31,
82
+ }
83
+ : {
84
+ x: asObject.m11,
85
+ y: asObject.m12,
86
+ z: asObject.m13,
87
+ };
88
+ const basisY = columnMajor
89
+ ? {
90
+ x: asObject.m12,
91
+ y: asObject.m22,
92
+ z: asObject.m32,
93
+ }
94
+ : {
95
+ x: asObject.m21,
96
+ y: asObject.m22,
97
+ z: asObject.m23,
98
+ };
99
+ const basisZ = columnMajor
100
+ ? {
101
+ x: asObject.m13,
102
+ y: asObject.m23,
103
+ z: asObject.m33,
104
+ }
105
+ : {
106
+ x: asObject.m31,
107
+ y: asObject.m32,
108
+ z: asObject.m33,
109
+ };
110
+ return {
111
+ basisX,
112
+ basisY,
113
+ basisZ,
114
+ xlate: {
115
+ x: asObject.m14,
116
+ y: asObject.m24,
117
+ z: asObject.m34,
118
+ },
119
+ scale: asObject.m44,
120
+ };
121
+ }
122
+ }
123
+
124
+ exports.TransformController = TransformController;
125
+
126
+ //# sourceMappingURL=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MAAM,MAAM,GAAG,WAAW;QACtB;QACE,CAAC,EAAE,QAAQ,CAAC,GAAG;QACf,CAAC,EAAE,QAAQ,CAAC,GAAG;QACf,CAAC,EAAE,QAAQ,CAAC,GAAG;OAChB;QACD;QACE,CAAC,EAAE,QAAQ,CAAC,GAAG;QACf,CAAC,EAAE,QAAQ,CAAC,GAAG;QACf,CAAC,EAAE,QAAQ,CAAC,GAAG;OAChB,CAAC;IACN,MAAM,MAAM,GAAG,WAAW;QACtB;QACE,CAAC,EAAE,QAAQ,CAAC,GAAG;QACf,CAAC,EAAE,QAAQ,CAAC,GAAG;QACf,CAAC,EAAE,QAAQ,CAAC,GAAG;OAChB;QACD;QACE,CAAC,EAAE,QAAQ,CAAC,GAAG;QACf,CAAC,EAAE,QAAQ,CAAC,GAAG;QACf,CAAC,EAAE,QAAQ,CAAC,GAAG;OAChB,CAAC;IAEN,OAAO;MACL,MAAM;MACN,MAAM;MACN,MAAM;MACN,KAAK,EAAE;QACL,CAAC,EAAE,QAAQ,CAAC,GAAG;QACf,CAAC,EAAE,QAAQ,CAAC,GAAG;QACf,CAAC,EAAE,QAAQ,CAAC,GAAG;OAChB;MACD,KAAK,EAAE,QAAQ,CAAC,GAAG;KACpB,CAAC;GACH;;;;;","names":["Matrix4"],"sources":["./src/lib/transforms/controller.ts"],"sourcesContent":["import { vertexvis } from '@vertexvis/frame-streaming-protos';\nimport { Matrix4, Vector3 } from '@vertexvis/geometry';\nimport { StreamApi } from '@vertexvis/stream-api';\n\nexport class TransformController {\n private isTransforming = false;\n private currentDelta: Matrix4.Matrix4 = Matrix4.makeIdentity();\n\n public constructor(private stream: StreamApi) {}\n\n public async dispose(): Promise<void> {\n if (this.isTransforming) {\n this.endTransform();\n }\n }\n\n public async beginTransform(\n delta: Matrix4.Matrix4 = Matrix4.makeIdentity()\n ): Promise<void> {\n if (!this.isTransforming) {\n this.currentDelta = delta;\n this.isTransforming = true;\n\n console.debug('Beginning transform interaction');\n\n await this.stream.beginInteraction({\n transform: {\n delta: this.toDeltaTransform(delta),\n },\n });\n }\n }\n\n public async updateTransform(delta: Matrix4.Matrix4): Promise<void> {\n this.currentDelta = delta;\n\n await this.stream.updateInteraction({\n transform: {\n delta: this.toDeltaTransform(this.currentDelta, true),\n },\n });\n }\n\n public async updateTranslation(delta: Vector3.Vector3): Promise<void> {\n this.currentDelta = Matrix4.makeTranslation(delta);\n\n await this.stream.updateInteraction({\n transform: {\n delta: this.toDeltaTransform(this.currentDelta),\n },\n });\n }\n\n public getCurrentDelta(): Matrix4.Matrix4 | undefined {\n return this.currentDelta;\n }\n\n public async endTransform(): Promise<void> {\n if (this.isTransforming) {\n console.debug(\n `Ending transform interaction [delta=${this.currentDelta}]`\n );\n\n await this.stream.endInteraction({\n transform: {\n delta: this.toDeltaTransform(this.currentDelta),\n },\n });\n this.isTransforming = false;\n this.currentDelta = Matrix4.makeIdentity();\n }\n }\n\n public async endInteraction(): Promise<void> {\n if (this.isTransforming) {\n await this.stream.endInteraction();\n this.isTransforming = false;\n this.currentDelta = Matrix4.makeIdentity();\n }\n }\n\n public clearTransform(): void {\n this.currentDelta = Matrix4.makeIdentity();\n this.endTransform();\n }\n\n private toDeltaTransform(\n delta: Matrix4.Matrix4,\n columnMajor = false\n ): vertexvis.protobuf.core.IAffineMatrix4f {\n const asObject = Matrix4.toObject(delta);\n\n // TODO: update this to pass a single order for the\n // transform matrix after work in https://vertexvis.atlassian.net/browse/PLAT-1582\n const basisX = columnMajor\n ? {\n x: asObject.m11,\n y: asObject.m21,\n z: asObject.m31,\n }\n : {\n x: asObject.m11,\n y: asObject.m12,\n z: asObject.m13,\n };\n const basisY = columnMajor\n ? {\n x: asObject.m12,\n y: asObject.m22,\n z: asObject.m32,\n }\n : {\n x: asObject.m21,\n y: asObject.m22,\n z: asObject.m23,\n };\n const basisZ = columnMajor\n ? {\n x: asObject.m13,\n y: asObject.m23,\n z: asObject.m33,\n }\n : {\n x: asObject.m31,\n y: asObject.m32,\n z: asObject.m33,\n };\n\n return {\n basisX,\n basisY,\n basisZ,\n xlate: {\n x: asObject.m14,\n y: asObject.m24,\n z: asObject.m34,\n },\n scale: asObject.m44,\n };\n }\n}\n"],"version":3}
@@ -17,16 +17,86 @@ const streamAttributes = require('./streamAttributes-fc4f97e1.js');
17
17
  const entities = require('./entities-a2e154e7.js');
18
18
  const markup = require('./markup-10958c12.js');
19
19
  const viewport = require('./viewport-1f918fe4.js');
20
- const controller$1 = require('./controller-1961ce2b.js');
20
+ const bundle_esm = require('./bundle.esm-5847ff0b.js');
21
+ const controller$1 = require('./controller-b93c925e.js');
22
+ const controller$2 = require('./controller-1961ce2b.js');
21
23
  require('./browser.esm-bf5e4488.js');
22
- require('./bundle.esm-5847ff0b.js');
23
24
  require('./errors-3842d8ec.js');
24
25
  require('./bundle.esm-d51532e3.js');
25
26
  require('./wrappers_pb-9ec12cf5.js');
26
27
  require('./_commonjsHelpers-77dbcc2e.js');
27
28
  require('./mapper-fb3499f2.js');
28
29
 
30
+ const ALMOST_ONE = 0.9999;
31
+ /**
32
+ * For any single vector, there are an infinite number of potential orthogonal vectors. This function will determine
33
+ * one orthogonal vector by crossing the provided vector with a unit vector in the positive X, Y, or Z directions.
34
+ * @param normal
35
+ * @returns
36
+ */
37
+ function chooseOrthogonalVector(normal) {
38
+ const absNorm = bundle_esm.vector3.create(Math.abs(normal.x), Math.abs(normal.y), Math.abs(normal.z));
39
+ const x = absNorm.x < absNorm.y && absNorm.x < absNorm.z ? 1.0 : 0.0;
40
+ const y = absNorm.y <= absNorm.x && absNorm.y < absNorm.z ? 1.0 : 0.0;
41
+ const z = absNorm.z <= absNorm.x && absNorm.z <= absNorm.y ? 1.0 : 0.0;
42
+ const vector = bundle_esm.vector3.create(x, y, z);
43
+ return bundle_esm.vector3.normalize(bundle_esm.vector3.cross(normal, vector));
44
+ }
45
+ /**
46
+ * Computes the rotation matrix for two normals. If both normals are neither parallel or anti-parallel,
47
+ * this will compute the rotation matrix delta based on the angle from both normals.
48
+ * If the normals are anti-parallel, the identity matrix will be returned, as no rotation is necessary in this case.
49
+ * If the normals are parallel, an axis direction based on a chosen orthogonal vector will be used
50
+ * to compute the rotation matrix to rotate the plane 180 degrees.
51
+ * @param normal1
52
+ * @param normal2
53
+ * @returns an anti-parallel rotation Matrix4 betwen the given normals
54
+ */
55
+ function computeRotationMatrix(normal1, normal2) {
56
+ const dot = bundle_esm.vector3.dot(normal1, normal2);
57
+ // the angle is almost 0 in this case.
58
+ if (dot > ALMOST_ONE) {
59
+ const axisDirection = chooseOrthogonalVector(normal1);
60
+ const quaternion = bundle_esm.quaternion.fromAxisAngle(axisDirection, Math.PI);
61
+ return bundle_esm.matrix4.makeRotation(quaternion);
62
+ }
63
+ // the angle is almost 180 in this case.
64
+ else if (dot <= -ALMOST_ONE) {
65
+ return bundle_esm.matrix4.makeIdentity();
66
+ }
67
+ // the angle is between 0 & 180
68
+ else {
69
+ const angle = bundle_esm.vector3.angleTo(normal2, normal1);
70
+ const axisDirection = bundle_esm.vector3.normalize(bundle_esm.vector3.cross(normal1, normal2));
71
+ return bundle_esm.matrix4.makeRotation(bundle_esm.quaternion.fromAxisAngle(axisDirection, angle + Math.PI));
72
+ }
73
+ }
74
+ /**
75
+ * Computes the translation & rotation matrix delta between two world positions and two normals.
76
+ * such that the computed translation matrix will be the delta between position 1 and position 2,
77
+ * and the rotation will be rotated to be anti-parallel.
78
+ *
79
+ * @param normal1
80
+ * @param position1
81
+ * @param normal2
82
+ * @param position2
83
+ *
84
+ * @returns Matrix4 translation matrix delta from position1 to
85
+ * position2 & an anti-parallel rotation delta.
86
+ */
87
+ function computeTransformationDelta(normal1, position1, normal2, position2) {
88
+ const rotationMatrix = computeRotationMatrix(normal1, normal2);
89
+ const translationDeltaMatrix = bundle_esm.matrix4.makeTranslation(position2);
90
+ return bundle_esm.matrix4.multiply(bundle_esm.matrix4.multiply(translationDeltaMatrix, rotationMatrix), bundle_esm.matrix4.makeTranslation(bundle_esm.vector3.negate(position1)));
91
+ }
29
92
 
93
+ const transformationDelta = /*#__PURE__*/Object.freeze({
94
+ __proto__: null,
95
+ ALMOST_ONE: ALMOST_ONE,
96
+ chooseOrthogonalVector: chooseOrthogonalVector,
97
+ computeRotationMatrix: computeRotationMatrix,
98
+ computeTransformationDelta: computeTransformationDelta
99
+ });
30
100
 
31
101
  exports.ColorMaterial = scene.colorMaterial;
32
102
  exports.LoadableResource = scene.loadableResource;
@@ -56,15 +126,17 @@ exports.ReceivedFrameScene = streamAttributes.FrameScene;
56
126
  exports.ReceivedOrthographicCamera = streamAttributes.FrameOrthographicCamera;
57
127
  exports.ReceivedPerspectiveCamera = streamAttributes.FramePerspectiveCamera;
58
128
  Object.defineProperty(exports, 'EntityType', {
59
- enumerable: true,
60
- get: function () {
61
- return entities.EntityType;
62
- }
129
+ enumerable: true,
130
+ get: function () {
131
+ return entities.EntityType;
132
+ }
63
133
  });
64
134
  exports.ArrowMarkup = markup.ArrowMarkup;
65
135
  exports.CircleMarkup = markup.CircleMarkup;
66
136
  exports.FreeformMarkup = markup.FreeformMarkup;
67
137
  exports.Viewport = viewport.Viewport;
68
- exports.VolumeIntersectionQueryController = controller$1.VolumeIntersectionQueryController;
138
+ exports.TransformController = controller$1.TransformController;
139
+ exports.VolumeIntersectionQueryController = controller$2.VolumeIntersectionQueryController;
140
+ exports.TransformationDelta = transformationDelta;
69
141
 
70
142
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"file":"index.cjs.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":[],"sourcesContent":[],"version":3}
1
+ {"file":"index.cjs.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEO,MAAM,UAAU,GAAG,MAAM,CAAC;AACjC;;;;;;SAMgB,sBAAsB,CACpC,MAAuB;EAEvB,MAAM,OAAO,GAAGA,kBAAO,CAAC,MAAM,CAC5B,IAAI,CAAC,GAAG,C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OA,kBAAO,CAAC,YAAY,EAAE,CAAC;GAC/B;;OAEI;IACH,MAAM,KAAK,GAAGF,kBAAO,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAChD,MAAM,aAAa,GAAGA,kBAAO,CAAC,SAAS,CAACA,kBAAO,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IACzE,OAAOE,kBAAO,CAAC,YAAY,CACzBD,qBAAU,CAAC,aAAa,CAAC,aAAa,EAAE,KAAK,GAAG,IAAI,CAAC,EAAE,CAAC,CACzD,CAAC;GACH;AACH,CAAC;AAED;;;;;;;;;;;;;SAagB,0BAA0B,CACxC,OAAwB,EACxB,SAA0B,EAC1B,OAAwB,EACxB,SAA0B;EAE1B,MAAM,cAAc,GAAG,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;EAE/D,MAAM,sBAAsB,GAAGC,kBAAO,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;EAClE,OAAOA,kBAAO,CAAC,QAAQ,CACrBA,kBAAO,CAAC,QAAQ,CAAC,sBAAsB,EAAE,cAAc,CAAC,EACxDA,kBAAO,CAAC,eAAe,CAACF,kBAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CACnD,CAAC;AACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["Vector3","Quaternion","Matrix4"],"sources":["./src/lib/transforms/transformation-delta.ts"],"sourcesContent":["import { Matrix4, Quaternion, Vector3 } from '@vertexvis/geometry';\n\nexport const ALMOST_ONE = 0.9999;\n/**\n * For any single vector, there are an infinite number of potential orthogonal vectors. This function will determine\n * one orthogonal vector by crossing the provided vector with a unit vector in the positive X, Y, or Z directions.\n * @param normal\n * @returns\n */\nexport function chooseOrthogonalVector(\n normal: Vector3.Vector3\n): Vector3.Vector3 {\n const absNorm = Vector3.create(\n Math.abs(normal.x),\n Math.abs(normal.y),\n Math.abs(normal.z)\n );\n const x = absNorm.x < absNorm.y && absNorm.x < absNorm.z ? 1.0 : 0.0;\n const y = absNorm.y <= absNorm.x && absNorm.y < absNorm.z ? 1.0 : 0.0;\n const z = absNorm.z <= absNorm.x && absNorm.z <= absNorm.y ? 1.0 : 0.0;\n\n const vector = Vector3.create(x, y, z);\n return Vector3.normalize(Vector3.cross(normal, vector));\n}\n\n/**\n * Computes the rotation matrix for two normals. If both normals are neither parallel or anti-parallel,\n * this will compute the rotation matrix delta based on the angle from both normals.\n * If the normals are anti-parallel, the identity matrix will be returned, as no rotation is necessary in this case.\n * If the normals are parallel, an axis direction based on a chosen orthogonal vector will be used\n * to compute the rotation matrix to rotate the plane 180 degrees.\n * @param normal1\n * @param normal2\n * @returns an anti-parallel rotation Matrix4 betwen the given normals\n */\nexport function computeRotationMatrix(\n normal1: Vector3.Vector3,\n normal2: Vector3.Vector3\n): Matrix4.Matrix4 {\n const dot = Vector3.dot(normal1, normal2);\n // the angle is almost 0 in this case.\n if (dot > ALMOST_ONE) {\n const axisDirection = chooseOrthogonalVector(normal1);\n\n const quaternion = Quaternion.fromAxisAngle(axisDirection, Math.PI);\n return Matrix4.makeRotation(quaternion);\n }\n // the angle is almost 180 in this case.\n else if (dot <= -ALMOST_ONE) {\n return Matrix4.makeIdentity();\n }\n // the angle is between 0 & 180\n else {\n const angle = Vector3.angleTo(normal2, normal1);\n const axisDirection = Vector3.normalize(Vector3.cross(normal1, normal2));\n return Matrix4.makeRotation(\n Quaternion.fromAxisAngle(axisDirection, angle + Math.PI)\n );\n }\n}\n\n/**\n * Computes the translation & rotation matrix delta between two world positions and two normals.\n * such that the computed translation matrix will be the delta between position 1 and position 2,\n * and the rotation will be rotated to be anti-parallel.\n *\n * @param normal1\n * @param position1\n * @param normal2\n * @param position2\n *\n * @returns Matrix4 translation matrix delta from position1 to\n * position2 & an anti-parallel rotation delta.\n */\nexport function computeTransformationDelta(\n normal1: Vector3.Vector3,\n position1: Vector3.Vector3,\n normal2: Vector3.Vector3,\n position2: Vector3.Vector3\n): Matrix4.Matrix4 {\n const rotationMatrix = computeRotationMatrix(normal1, normal2);\n\n const translationDeltaMatrix = Matrix4.makeTranslation(position2);\n return Matrix4.multiply(\n Matrix4.multiply(translationDeltaMatrix, rotationMatrix),\n Matrix4.makeTranslation(Vector3.negate(position1))\n );\n}\n"],"version":3}
@@ -9,6 +9,7 @@ const index = require('./index-b99cd335.js');
9
9
  const bundle_esm = require('./bundle.esm-5847ff0b.js');
10
10
  const index$1 = require('./index-5e1feaea.js');
11
11
  const stencil = require('./stencil-507a4f26.js');
12
+ const controller = require('./controller-b93c925e.js');
12
13
  const browser_esm = require('./browser.esm-bf5e4488.js');
13
14
  const reglComponent = require('./regl-component-5b601d0c.js');
14
15
  require('./_commonjsHelpers-77dbcc2e.js');
@@ -17,122 +18,6 @@ require('./bundle.esm-d51532e3.js');
17
18
  require('./entities-a2e154e7.js');
18
19
  require('./viewport-1f918fe4.js');
19
20
 
20
- class TransformController {
21
- constructor(stream) {
22
- this.stream = stream;
23
- this.isTransforming = false;
24
- this.currentDelta = bundle_esm.matrix4.makeIdentity();
25
- }
26
- async dispose() {
27
- if (this.isTransforming) {
28
- this.endTransform();
29
- }
30
- }
31
- async beginTransform(delta = bundle_esm.matrix4.makeIdentity()) {
32
- if (!this.isTransforming) {
33
- this.currentDelta = delta;
34
- this.isTransforming = true;
35
- console.debug('Beginning transform interaction');
36
- await this.stream.beginInteraction({
37
- transform: {
38
- delta: this.toDeltaTransform(delta),
39
- },
40
- });
41
- }
42
- }
43
- async updateTransform(delta) {
44
- this.currentDelta = delta;
45
- await this.stream.updateInteraction({
46
- transform: {
47
- delta: this.toDeltaTransform(this.currentDelta, true),
48
- },
49
- });
50
- }
51
- async updateTranslation(delta) {
52
- this.currentDelta = bundle_esm.matrix4.makeTranslation(delta);
53
- await this.stream.updateInteraction({
54
- transform: {
55
- delta: this.toDeltaTransform(this.currentDelta),
56
- },
57
- });
58
- }
59
- getCurrentDelta() {
60
- return this.currentDelta;
61
- }
62
- async endTransform() {
63
- if (this.isTransforming) {
64
- console.debug(`Ending transform interaction [delta=${this.currentDelta}]`);
65
- await this.stream.endInteraction({
66
- transform: {
67
- delta: this.toDeltaTransform(this.currentDelta),
68
- },
69
- });
70
- this.isTransforming = false;
71
- this.currentDelta = bundle_esm.matrix4.makeIdentity();
72
- }
73
- }
74
- async endInteraction() {
75
- if (this.isTransforming) {
76
- await this.stream.endInteraction();
77
- this.isTransforming = false;
78
- this.currentDelta = bundle_esm.matrix4.makeIdentity();
79
- }
80
- }
81
- clearTransform() {
82
- this.currentDelta = bundle_esm.matrix4.makeIdentity();
83
- this.endTransform();
84
- }
85
- toDeltaTransform(delta, columnMajor = false) {
86
- const asObject = bundle_esm.matrix4.toObject(delta);
87
- // TODO: update this to pass a single order for the
88
- // transform matrix after work in https://vertexvis.atlassian.net/browse/PLAT-1582
89
- const basisX = columnMajor
90
- ? {
91
- x: asObject.m11,
92
- y: asObject.m21,
93
- z: asObject.m31,
94
- }
95
- : {
96
- x: asObject.m11,
97
- y: asObject.m12,
98
- z: asObject.m13,
99
- };
100
- const basisY = columnMajor
101
- ? {
102
- x: asObject.m12,
103
- y: asObject.m22,
104
- z: asObject.m32,
105
- }
106
- : {
107
- x: asObject.m21,
108
- y: asObject.m22,
109
- z: asObject.m23,
110
- };
111
- const basisZ = columnMajor
112
- ? {
113
- x: asObject.m13,
114
- y: asObject.m23,
115
- z: asObject.m33,
116
- }
117
- : {
118
- x: asObject.m31,
119
- y: asObject.m32,
120
- z: asObject.m33,
121
- };
122
- return {
123
- basisX,
124
- basisY,
125
- basisZ,
126
- xlate: {
127
- x: asObject.m14,
128
- y: asObject.m24,
129
- z: asObject.m34,
130
- },
131
- scale: asObject.m44,
132
- };
133
- }
134
- }
135
-
136
21
  function convertPointToCanvas(point, bounds) {
137
22
  return bounds != null
138
23
  ? bundle_esm.point.create(point.x - bounds.left, point.y - bounds.top)
@@ -206,8 +91,15 @@ function computeTranslation(current, previous, next, direction) {
206
91
  const rotatedDelta = bundle_esm.vector3.multiply(rotatedTranslationAxis, bundle_esm.vector3.subtract(next, previous));
207
92
  return rotatedDelta.x + rotatedDelta.y + rotatedDelta.z;
208
93
  }
209
- function computeRotation(rotationAxis, current) {
210
- return bundle_esm.matrix4.multiply(bundle_esm.matrix4.multiply(bundle_esm.matrix4.multiply(bundle_esm.matrix4.makeTranslation(bundle_esm.vector3.fromMatrixPosition(current)), bundle_esm.matrix4.makeRotation(rotationAxis)), bundle_esm.matrix4.makeTranslation(bundle_esm.vector3.negate(bundle_esm.vector3.fromMatrixPosition(current)))), current);
94
+ /**
95
+ * Computes a rotation Matrix4 by applying the rotation at the given position,
96
+ * then translating it back to convert it to a world delta.
97
+ * @param rotation
98
+ * @param current
99
+ * @returns
100
+ */
101
+ function computeRotation(rotation, current) {
102
+ return bundle_esm.matrix4.multiply(bundle_esm.matrix4.multiply(bundle_esm.matrix4.multiply(bundle_esm.matrix4.makeTranslation(bundle_esm.vector3.fromMatrixPosition(current)), bundle_esm.matrix4.makeRotation(rotation)), bundle_esm.matrix4.makeTranslation(bundle_esm.vector3.negate(bundle_esm.vector3.fromMatrixPosition(current)))), current);
211
103
  }
212
104
 
213
105
  function xAxisRotationPositions(widgetTransform, camera, triangleSize = 3) {
@@ -729,6 +621,11 @@ const ViewerTransformWidget = class {
729
621
  hovered: this.hoveredColor,
730
622
  disabledColor: this.disabledColor,
731
623
  });
624
+ if (this.rotation != null) {
625
+ this.currentTransform = this.getTransformForNewRotation(this.rotation);
626
+ this.startingTransform = this.currentTransform;
627
+ this.widget.updateTransform(this.currentTransform);
628
+ }
732
629
  if (this.position != null) {
733
630
  this.currentTransform = bundle_esm.matrix4.makeTranslation(this.position);
734
631
  this.startingTransform = this.currentTransform;
@@ -760,7 +657,7 @@ const ViewerTransformWidget = class {
760
657
  return bundle_esm.matrix4.makeTranslation(newPosition);
761
658
  }
762
659
  };
763
- this.getTransformForHewRotation = (newRotationEuler) => {
660
+ this.getTransformForNewRotation = (newRotationEuler) => {
764
661
  const c = this.currentTransform != null
765
662
  ? this.currentTransform
766
663
  : bundle_esm.matrix4.makeIdentity();
@@ -835,7 +732,7 @@ const ViewerTransformWidget = class {
835
732
  newViewer === null || newViewer === void 0 ? void 0 : newViewer.addEventListener('dimensionschange', this.handleViewerDimensionsChange);
836
733
  if ((newViewer === null || newViewer === void 0 ? void 0 : newViewer.stream) != null) {
837
734
  (_a = this.controller) === null || _a === void 0 ? void 0 : _a.dispose();
838
- this.controller = new TransformController(newViewer.stream);
735
+ this.controller = new controller.TransformController(newViewer.stream);
839
736
  }
840
737
  }
841
738
  /**
@@ -856,7 +753,7 @@ const ViewerTransformWidget = class {
856
753
  */
857
754
  handleRotationChanged(newRotation, oldRotation) {
858
755
  var _a;
859
- this.currentTransform = this.getTransformForHewRotation(newRotation);
756
+ this.currentTransform = this.getTransformForNewRotation(newRotation);
860
757
  this.startingTransform = this.currentTransform;
861
758
  (_a = this.widget) === null || _a === void 0 ? void 0 : _a.updateTransform(this.currentTransform);
862
759
  console.debug(`Updating widget rotation [previous=${JSON.stringify(oldRotation)}, current=${JSON.stringify(newRotation)}]`);