@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
@@ -0,0 +1,124 @@
1
+ /*!
2
+ * Copyright (c) 2023 Vertex Software LLC. All rights reserved.
3
+ */
4
+ import { m as matrix4 } from './bundle.esm-92fd4246.js';
5
+
6
+ class TransformController {
7
+ constructor(stream) {
8
+ this.stream = stream;
9
+ this.isTransforming = false;
10
+ this.currentDelta = matrix4.makeIdentity();
11
+ }
12
+ async dispose() {
13
+ if (this.isTransforming) {
14
+ this.endTransform();
15
+ }
16
+ }
17
+ async beginTransform(delta = matrix4.makeIdentity()) {
18
+ if (!this.isTransforming) {
19
+ this.currentDelta = delta;
20
+ this.isTransforming = true;
21
+ console.debug('Beginning transform interaction');
22
+ await this.stream.beginInteraction({
23
+ transform: {
24
+ delta: this.toDeltaTransform(delta),
25
+ },
26
+ });
27
+ }
28
+ }
29
+ async updateTransform(delta) {
30
+ this.currentDelta = delta;
31
+ await this.stream.updateInteraction({
32
+ transform: {
33
+ delta: this.toDeltaTransform(this.currentDelta, true),
34
+ },
35
+ });
36
+ }
37
+ async updateTranslation(delta) {
38
+ this.currentDelta = matrix4.makeTranslation(delta);
39
+ await this.stream.updateInteraction({
40
+ transform: {
41
+ delta: this.toDeltaTransform(this.currentDelta),
42
+ },
43
+ });
44
+ }
45
+ getCurrentDelta() {
46
+ return this.currentDelta;
47
+ }
48
+ async endTransform() {
49
+ if (this.isTransforming) {
50
+ console.debug(`Ending transform interaction [delta=${this.currentDelta}]`);
51
+ await this.stream.endInteraction({
52
+ transform: {
53
+ delta: this.toDeltaTransform(this.currentDelta),
54
+ },
55
+ });
56
+ this.isTransforming = false;
57
+ this.currentDelta = matrix4.makeIdentity();
58
+ }
59
+ }
60
+ async endInteraction() {
61
+ if (this.isTransforming) {
62
+ await this.stream.endInteraction();
63
+ this.isTransforming = false;
64
+ this.currentDelta = matrix4.makeIdentity();
65
+ }
66
+ }
67
+ clearTransform() {
68
+ this.currentDelta = matrix4.makeIdentity();
69
+ this.endTransform();
70
+ }
71
+ toDeltaTransform(delta, columnMajor = false) {
72
+ const asObject = matrix4.toObject(delta);
73
+ // TODO: update this to pass a single order for the
74
+ // transform matrix after work in https://vertexvis.atlassian.net/browse/PLAT-1582
75
+ const basisX = columnMajor
76
+ ? {
77
+ x: asObject.m11,
78
+ y: asObject.m21,
79
+ z: asObject.m31,
80
+ }
81
+ : {
82
+ x: asObject.m11,
83
+ y: asObject.m12,
84
+ z: asObject.m13,
85
+ };
86
+ const basisY = columnMajor
87
+ ? {
88
+ x: asObject.m12,
89
+ y: asObject.m22,
90
+ z: asObject.m32,
91
+ }
92
+ : {
93
+ x: asObject.m21,
94
+ y: asObject.m22,
95
+ z: asObject.m23,
96
+ };
97
+ const basisZ = columnMajor
98
+ ? {
99
+ x: asObject.m13,
100
+ y: asObject.m23,
101
+ z: asObject.m33,
102
+ }
103
+ : {
104
+ x: asObject.m31,
105
+ y: asObject.m32,
106
+ z: asObject.m33,
107
+ };
108
+ return {
109
+ basisX,
110
+ basisY,
111
+ basisZ,
112
+ xlate: {
113
+ x: asObject.m14,
114
+ y: asObject.m24,
115
+ z: asObject.m34,
116
+ },
117
+ scale: asObject.m44,
118
+ };
119
+ }
120
+ }
121
+
122
+ export { TransformController as T };
123
+
124
+ //# sourceMappingURL=controller-bf3848bf.js.map
@@ -0,0 +1 @@
1
+ {"file":"controller-bf3848bf.js","mappings":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AAC,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}
package/dist/esm/index.js CHANGED
@@ -13,13 +13,87 @@ export { A as AngleUnits, f as AreaUnits, D as DistanceUnits, F as FrameCameraBa
13
13
  export { E as EntityType } from './entities-47cdb654.js';
14
14
  export { A as ArrowMarkup, C as CircleMarkup, F as FreeformMarkup } from './markup-9930df20.js';
15
15
  export { V as Viewport } from './viewport-24c16dd5.js';
16
+ import { v as vector3, q as quaternion, m as matrix4 } from './bundle.esm-92fd4246.js';
17
+ export { T as TransformController } from './controller-bf3848bf.js';
16
18
  export { V as VolumeIntersectionQueryController } from './controller-2515cce4.js';
17
19
  import './browser.esm-595bfe2f.js';
18
- import './bundle.esm-92fd4246.js';
19
20
  import './errors-3cb95a06.js';
20
21
  import './bundle.esm-d4f38aab.js';
21
22
  import './wrappers_pb-975c7885.js';
22
23
  import './_commonjsHelpers-bb341e2b.js';
23
24
  import './mapper-b2222d19.js';
24
25
 
26
+ const ALMOST_ONE = 0.9999;
27
+ /**
28
+ * For any single vector, there are an infinite number of potential orthogonal vectors. This function will determine
29
+ * one orthogonal vector by crossing the provided vector with a unit vector in the positive X, Y, or Z directions.
30
+ * @param normal
31
+ * @returns
32
+ */
33
+ function chooseOrthogonalVector(normal) {
34
+ const absNorm = vector3.create(Math.abs(normal.x), Math.abs(normal.y), Math.abs(normal.z));
35
+ const x = absNorm.x < absNorm.y && absNorm.x < absNorm.z ? 1.0 : 0.0;
36
+ const y = absNorm.y <= absNorm.x && absNorm.y < absNorm.z ? 1.0 : 0.0;
37
+ const z = absNorm.z <= absNorm.x && absNorm.z <= absNorm.y ? 1.0 : 0.0;
38
+ const vector = vector3.create(x, y, z);
39
+ return vector3.normalize(vector3.cross(normal, vector));
40
+ }
41
+ /**
42
+ * Computes the rotation matrix for two normals. If both normals are neither parallel or anti-parallel,
43
+ * this will compute the rotation matrix delta based on the angle from both normals.
44
+ * If the normals are anti-parallel, the identity matrix will be returned, as no rotation is necessary in this case.
45
+ * If the normals are parallel, an axis direction based on a chosen orthogonal vector will be used
46
+ * to compute the rotation matrix to rotate the plane 180 degrees.
47
+ * @param normal1
48
+ * @param normal2
49
+ * @returns an anti-parallel rotation Matrix4 betwen the given normals
50
+ */
51
+ function computeRotationMatrix(normal1, normal2) {
52
+ const dot = vector3.dot(normal1, normal2);
53
+ // the angle is almost 0 in this case.
54
+ if (dot > ALMOST_ONE) {
55
+ const axisDirection = chooseOrthogonalVector(normal1);
56
+ const quaternion$1 = quaternion.fromAxisAngle(axisDirection, Math.PI);
57
+ return matrix4.makeRotation(quaternion$1);
58
+ }
59
+ // the angle is almost 180 in this case.
60
+ else if (dot <= -ALMOST_ONE) {
61
+ return matrix4.makeIdentity();
62
+ }
63
+ // the angle is between 0 & 180
64
+ else {
65
+ const angle = vector3.angleTo(normal2, normal1);
66
+ const axisDirection = vector3.normalize(vector3.cross(normal1, normal2));
67
+ return matrix4.makeRotation(quaternion.fromAxisAngle(axisDirection, angle + Math.PI));
68
+ }
69
+ }
70
+ /**
71
+ * Computes the translation & rotation matrix delta between two world positions and two normals.
72
+ * such that the computed translation matrix will be the delta between position 1 and position 2,
73
+ * and the rotation will be rotated to be anti-parallel.
74
+ *
75
+ * @param normal1
76
+ * @param position1
77
+ * @param normal2
78
+ * @param position2
79
+ *
80
+ * @returns Matrix4 translation matrix delta from position1 to
81
+ * position2 & an anti-parallel rotation delta.
82
+ */
83
+ function computeTransformationDelta(normal1, position1, normal2, position2) {
84
+ const rotationMatrix = computeRotationMatrix(normal1, normal2);
85
+ const translationDeltaMatrix = matrix4.makeTranslation(position2);
86
+ return matrix4.multiply(matrix4.multiply(translationDeltaMatrix, rotationMatrix), matrix4.makeTranslation(vector3.negate(position1)));
87
+ }
88
+
89
+ const transformationDelta = /*#__PURE__*/Object.freeze({
90
+ __proto__: null,
91
+ ALMOST_ONE: ALMOST_ONE,
92
+ chooseOrthogonalVector: chooseOrthogonalVector,
93
+ computeRotationMatrix: computeRotationMatrix,
94
+ computeTransformationDelta: computeTransformationDelta
95
+ });
96
+
97
+ export { transformationDelta as TransformationDelta };
98
+
25
99
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"file":"index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":[],"sourcesContent":[],"version":3}
1
+ {"file":"index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAEO,MAAM,UAAU,GAAG,MAAM,CAAC;AACjC;;;;;;SAMgB,sBAAsB,CACpC,MAAuB;EAEvB,MAAM,OAAO,GAAGA,OAAO,CAAC,MAAM,CAC5B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAClB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAClB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CACnB,CAAC;EACF,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC;EACrE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC;EACtE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC;EAEvE,MAAM,MAAM,GAAGA,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;EACvC,OAAOA,OAAO,CAAC,SAAS,CAACA,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;;;;;;SAUgB,qBAAqB,CACnC,OAAwB,EACxB,OAAwB;EAExB,MAA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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}
@@ -13,13 +13,87 @@ export { A as AngleUnits, f as AreaUnits, D as DistanceUnits, F as FrameCameraBa
13
13
  export { E as EntityType } from './entities-47cdb654.js';
14
14
  export { A as ArrowMarkup, C as CircleMarkup, F as FreeformMarkup } from './markup-9930df20.js';
15
15
  export { V as Viewport } from './viewport-24c16dd5.js';
16
+ import { v as vector3, q as quaternion, m as matrix4 } from './bundle.esm-92fd4246.js';
17
+ export { T as TransformController } from './controller-bf3848bf.js';
16
18
  export { V as VolumeIntersectionQueryController } from './controller-2515cce4.js';
17
19
  import './browser.esm-595bfe2f.js';
18
- import './bundle.esm-92fd4246.js';
19
20
  import './errors-3cb95a06.js';
20
21
  import './bundle.esm-d4f38aab.js';
21
22
  import './wrappers_pb-975c7885.js';
22
23
  import './_commonjsHelpers-bb341e2b.js';
23
24
  import './mapper-b2222d19.js';
24
25
 
26
+ const ALMOST_ONE = 0.9999;
27
+ /**
28
+ * For any single vector, there are an infinite number of potential orthogonal vectors. This function will determine
29
+ * one orthogonal vector by crossing the provided vector with a unit vector in the positive X, Y, or Z directions.
30
+ * @param normal
31
+ * @returns
32
+ */
33
+ function chooseOrthogonalVector(normal) {
34
+ const absNorm = vector3.create(Math.abs(normal.x), Math.abs(normal.y), Math.abs(normal.z));
35
+ const x = absNorm.x < absNorm.y && absNorm.x < absNorm.z ? 1.0 : 0.0;
36
+ const y = absNorm.y <= absNorm.x && absNorm.y < absNorm.z ? 1.0 : 0.0;
37
+ const z = absNorm.z <= absNorm.x && absNorm.z <= absNorm.y ? 1.0 : 0.0;
38
+ const vector = vector3.create(x, y, z);
39
+ return vector3.normalize(vector3.cross(normal, vector));
40
+ }
41
+ /**
42
+ * Computes the rotation matrix for two normals. If both normals are neither parallel or anti-parallel,
43
+ * this will compute the rotation matrix delta based on the angle from both normals.
44
+ * If the normals are anti-parallel, the identity matrix will be returned, as no rotation is necessary in this case.
45
+ * If the normals are parallel, an axis direction based on a chosen orthogonal vector will be used
46
+ * to compute the rotation matrix to rotate the plane 180 degrees.
47
+ * @param normal1
48
+ * @param normal2
49
+ * @returns an anti-parallel rotation Matrix4 betwen the given normals
50
+ */
51
+ function computeRotationMatrix(normal1, normal2) {
52
+ const dot = vector3.dot(normal1, normal2);
53
+ // the angle is almost 0 in this case.
54
+ if (dot > ALMOST_ONE) {
55
+ const axisDirection = chooseOrthogonalVector(normal1);
56
+ const quaternion$1 = quaternion.fromAxisAngle(axisDirection, Math.PI);
57
+ return matrix4.makeRotation(quaternion$1);
58
+ }
59
+ // the angle is almost 180 in this case.
60
+ else if (dot <= -ALMOST_ONE) {
61
+ return matrix4.makeIdentity();
62
+ }
63
+ // the angle is between 0 & 180
64
+ else {
65
+ const angle = vector3.angleTo(normal2, normal1);
66
+ const axisDirection = vector3.normalize(vector3.cross(normal1, normal2));
67
+ return matrix4.makeRotation(quaternion.fromAxisAngle(axisDirection, angle + Math.PI));
68
+ }
69
+ }
70
+ /**
71
+ * Computes the translation & rotation matrix delta between two world positions and two normals.
72
+ * such that the computed translation matrix will be the delta between position 1 and position 2,
73
+ * and the rotation will be rotated to be anti-parallel.
74
+ *
75
+ * @param normal1
76
+ * @param position1
77
+ * @param normal2
78
+ * @param position2
79
+ *
80
+ * @returns Matrix4 translation matrix delta from position1 to
81
+ * position2 & an anti-parallel rotation delta.
82
+ */
83
+ function computeTransformationDelta(normal1, position1, normal2, position2) {
84
+ const rotationMatrix = computeRotationMatrix(normal1, normal2);
85
+ const translationDeltaMatrix = matrix4.makeTranslation(position2);
86
+ return matrix4.multiply(matrix4.multiply(translationDeltaMatrix, rotationMatrix), matrix4.makeTranslation(vector3.negate(position1)));
87
+ }
88
+
89
+ const transformationDelta = /*#__PURE__*/Object.freeze({
90
+ __proto__: null,
91
+ ALMOST_ONE: ALMOST_ONE,
92
+ chooseOrthogonalVector: chooseOrthogonalVector,
93
+ computeRotationMatrix: computeRotationMatrix,
94
+ computeTransformationDelta: computeTransformationDelta
95
+ });
96
+
97
+ export { transformationDelta as TransformationDelta };
98
+
25
99
  //# sourceMappingURL=index.js.map
@@ -2,9 +2,10 @@
2
2
  * Copyright (c) 2023 Vertex Software LLC. All rights reserved.
3
3
  */
4
4
  import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-fd7d7b68.js';
5
- import { m as matrix4, p as point, v as vector3, r as ray, f as plane, q as quaternion, c as angle, b as boundingBox, e as rectangle } from './bundle.esm-92fd4246.js';
5
+ import { p as point, v as vector3, r as ray, f as plane, q as quaternion, m as matrix4, c as angle, b as boundingBox, e as rectangle } from './bundle.esm-92fd4246.js';
6
6
  import { c as classnames } from './index-ab0ec8dc.js';
7
7
  import { w as writeDOM, r as readDOM } from './stencil-b4965fdb.js';
8
+ import { T as TransformController } from './controller-bf3848bf.js';
8
9
  import { E as EventDispatcher } from './browser.esm-595bfe2f.js';
9
10
  import { d as TriangleMeshPoints, T as TriangleMesh, R as ReglComponent, e as computeDrawable2dBounds, r as regl, s as shapeBuilder, x as xAxisArrowPositions, A as AxisLine, b as axisPositions, y as yAxisArrowPositions, z as zAxisArrowPositions, f as rotationAxisPositions, g as RotationLine } from './regl-component-b58a74d8.js';
10
11
  import './_commonjsHelpers-bb341e2b.js';
@@ -13,122 +14,6 @@ import './bundle.esm-d4f38aab.js';
13
14
  import './entities-47cdb654.js';
14
15
  import './viewport-24c16dd5.js';
15
16
 
16
- class TransformController {
17
- constructor(stream) {
18
- this.stream = stream;
19
- this.isTransforming = false;
20
- this.currentDelta = matrix4.makeIdentity();
21
- }
22
- async dispose() {
23
- if (this.isTransforming) {
24
- this.endTransform();
25
- }
26
- }
27
- async beginTransform(delta = matrix4.makeIdentity()) {
28
- if (!this.isTransforming) {
29
- this.currentDelta = delta;
30
- this.isTransforming = true;
31
- console.debug('Beginning transform interaction');
32
- await this.stream.beginInteraction({
33
- transform: {
34
- delta: this.toDeltaTransform(delta),
35
- },
36
- });
37
- }
38
- }
39
- async updateTransform(delta) {
40
- this.currentDelta = delta;
41
- await this.stream.updateInteraction({
42
- transform: {
43
- delta: this.toDeltaTransform(this.currentDelta, true),
44
- },
45
- });
46
- }
47
- async updateTranslation(delta) {
48
- this.currentDelta = matrix4.makeTranslation(delta);
49
- await this.stream.updateInteraction({
50
- transform: {
51
- delta: this.toDeltaTransform(this.currentDelta),
52
- },
53
- });
54
- }
55
- getCurrentDelta() {
56
- return this.currentDelta;
57
- }
58
- async endTransform() {
59
- if (this.isTransforming) {
60
- console.debug(`Ending transform interaction [delta=${this.currentDelta}]`);
61
- await this.stream.endInteraction({
62
- transform: {
63
- delta: this.toDeltaTransform(this.currentDelta),
64
- },
65
- });
66
- this.isTransforming = false;
67
- this.currentDelta = matrix4.makeIdentity();
68
- }
69
- }
70
- async endInteraction() {
71
- if (this.isTransforming) {
72
- await this.stream.endInteraction();
73
- this.isTransforming = false;
74
- this.currentDelta = matrix4.makeIdentity();
75
- }
76
- }
77
- clearTransform() {
78
- this.currentDelta = matrix4.makeIdentity();
79
- this.endTransform();
80
- }
81
- toDeltaTransform(delta, columnMajor = false) {
82
- const asObject = matrix4.toObject(delta);
83
- // TODO: update this to pass a single order for the
84
- // transform matrix after work in https://vertexvis.atlassian.net/browse/PLAT-1582
85
- const basisX = columnMajor
86
- ? {
87
- x: asObject.m11,
88
- y: asObject.m21,
89
- z: asObject.m31,
90
- }
91
- : {
92
- x: asObject.m11,
93
- y: asObject.m12,
94
- z: asObject.m13,
95
- };
96
- const basisY = columnMajor
97
- ? {
98
- x: asObject.m12,
99
- y: asObject.m22,
100
- z: asObject.m32,
101
- }
102
- : {
103
- x: asObject.m21,
104
- y: asObject.m22,
105
- z: asObject.m23,
106
- };
107
- const basisZ = columnMajor
108
- ? {
109
- x: asObject.m13,
110
- y: asObject.m23,
111
- z: asObject.m33,
112
- }
113
- : {
114
- x: asObject.m31,
115
- y: asObject.m32,
116
- z: asObject.m33,
117
- };
118
- return {
119
- basisX,
120
- basisY,
121
- basisZ,
122
- xlate: {
123
- x: asObject.m14,
124
- y: asObject.m24,
125
- z: asObject.m34,
126
- },
127
- scale: asObject.m44,
128
- };
129
- }
130
- }
131
-
132
17
  function convertPointToCanvas(point$1, bounds) {
133
18
  return bounds != null
134
19
  ? point.create(point$1.x - bounds.left, point$1.y - bounds.top)
@@ -202,8 +87,15 @@ function computeTranslation(current, previous, next, direction) {
202
87
  const rotatedDelta = vector3.multiply(rotatedTranslationAxis, vector3.subtract(next, previous));
203
88
  return rotatedDelta.x + rotatedDelta.y + rotatedDelta.z;
204
89
  }
205
- function computeRotation(rotationAxis, current) {
206
- return matrix4.multiply(matrix4.multiply(matrix4.multiply(matrix4.makeTranslation(vector3.fromMatrixPosition(current)), matrix4.makeRotation(rotationAxis)), matrix4.makeTranslation(vector3.negate(vector3.fromMatrixPosition(current)))), current);
90
+ /**
91
+ * Computes a rotation Matrix4 by applying the rotation at the given position,
92
+ * then translating it back to convert it to a world delta.
93
+ * @param rotation
94
+ * @param current
95
+ * @returns
96
+ */
97
+ function computeRotation(rotation, current) {
98
+ return matrix4.multiply(matrix4.multiply(matrix4.multiply(matrix4.makeTranslation(vector3.fromMatrixPosition(current)), matrix4.makeRotation(rotation)), matrix4.makeTranslation(vector3.negate(vector3.fromMatrixPosition(current)))), current);
207
99
  }
208
100
 
209
101
  function xAxisRotationPositions(widgetTransform, camera, triangleSize = 3) {
@@ -725,6 +617,11 @@ const ViewerTransformWidget = class {
725
617
  hovered: this.hoveredColor,
726
618
  disabledColor: this.disabledColor,
727
619
  });
620
+ if (this.rotation != null) {
621
+ this.currentTransform = this.getTransformForNewRotation(this.rotation);
622
+ this.startingTransform = this.currentTransform;
623
+ this.widget.updateTransform(this.currentTransform);
624
+ }
728
625
  if (this.position != null) {
729
626
  this.currentTransform = matrix4.makeTranslation(this.position);
730
627
  this.startingTransform = this.currentTransform;
@@ -756,7 +653,7 @@ const ViewerTransformWidget = class {
756
653
  return matrix4.makeTranslation(newPosition);
757
654
  }
758
655
  };
759
- this.getTransformForHewRotation = (newRotationEuler) => {
656
+ this.getTransformForNewRotation = (newRotationEuler) => {
760
657
  const c = this.currentTransform != null
761
658
  ? this.currentTransform
762
659
  : matrix4.makeIdentity();
@@ -852,7 +749,7 @@ const ViewerTransformWidget = class {
852
749
  */
853
750
  handleRotationChanged(newRotation, oldRotation) {
854
751
  var _a;
855
- this.currentTransform = this.getTransformForHewRotation(newRotation);
752
+ this.currentTransform = this.getTransformForNewRotation(newRotation);
856
753
  this.startingTransform = this.currentTransform;
857
754
  (_a = this.widget) === null || _a === void 0 ? void 0 : _a.updateTransform(this.currentTransform);
858
755
  console.debug(`Updating widget rotation [previous=${JSON.stringify(oldRotation)}, current=${JSON.stringify(newRotation)}]`);