@shapediver/viewer.rendering-engine.intersection-restriction-engine 3.16.8 → 3.16.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 (95) hide show
  1. package/dist/api/implementation/AbstractRestrictionApi.d.ts +12 -12
  2. package/dist/api/implementation/AbstractRestrictionApi.js +46 -46
  3. package/dist/api/implementation/AbstractRestrictionApi.js.map +1 -1
  4. package/dist/api/implementation/AbstractSnapRestrictionApi.d.ts +12 -12
  5. package/dist/api/implementation/AbstractSnapRestrictionApi.js +46 -46
  6. package/dist/api/implementation/AbstractSnapRestrictionApi.js.map +1 -1
  7. package/dist/api/implementation/camera_plane/CameraPlaneRestrictionApi.d.ts +6 -6
  8. package/dist/api/implementation/camera_plane/CameraPlaneRestrictionApi.js +23 -23
  9. package/dist/api/implementation/camera_plane/CameraPlaneRestrictionApi.js.map +1 -1
  10. package/dist/api/implementation/geometry/GeometryRestrictionApi.d.ts +14 -14
  11. package/dist/api/implementation/geometry/GeometryRestrictionApi.js +53 -53
  12. package/dist/api/implementation/geometry/GeometryRestrictionApi.js.map +1 -1
  13. package/dist/api/implementation/line/LineRestrictionApi.d.ts +10 -10
  14. package/dist/api/implementation/line/LineRestrictionApi.js +39 -39
  15. package/dist/api/implementation/line/LineRestrictionApi.js.map +1 -1
  16. package/dist/api/implementation/plane/PlaneRestrictionApi.d.ts +19 -19
  17. package/dist/api/implementation/plane/PlaneRestrictionApi.js +66 -66
  18. package/dist/api/implementation/plane/PlaneRestrictionApi.js.map +1 -1
  19. package/dist/api/implementation/plane/snap/AngularRestrictionApi.d.ts +9 -9
  20. package/dist/api/implementation/plane/snap/AngularRestrictionApi.js +39 -39
  21. package/dist/api/implementation/plane/snap/AngularRestrictionApi.js.map +1 -1
  22. package/dist/api/implementation/plane/snap/AxisRestrictionApi.d.ts +6 -6
  23. package/dist/api/implementation/plane/snap/AxisRestrictionApi.js +23 -23
  24. package/dist/api/implementation/plane/snap/AxisRestrictionApi.js.map +1 -1
  25. package/dist/api/implementation/plane/snap/GridRestrictionApi.d.ts +9 -9
  26. package/dist/api/implementation/plane/snap/GridRestrictionApi.js +39 -39
  27. package/dist/api/implementation/plane/snap/GridRestrictionApi.js.map +1 -1
  28. package/dist/api/implementation/point/PointRestrictionApi.d.ts +9 -9
  29. package/dist/api/implementation/point/PointRestrictionApi.js +36 -36
  30. package/dist/api/implementation/point/PointRestrictionApi.js.map +1 -1
  31. package/dist/api/interfaces/IRestrictionApi.d.ts +10 -10
  32. package/dist/api/interfaces/IRestrictionApi.js +2 -2
  33. package/dist/api/interfaces/ISnapRestrictionApi.d.ts +12 -12
  34. package/dist/api/interfaces/ISnapRestrictionApi.js +2 -2
  35. package/dist/implementation/EventManager.d.ts +25 -25
  36. package/dist/implementation/EventManager.d.ts.map +1 -1
  37. package/dist/implementation/EventManager.js +62 -62
  38. package/dist/implementation/EventManager.js.map +1 -1
  39. package/dist/implementation/GeometryMathManager.d.ts +87 -87
  40. package/dist/implementation/GeometryMathManager.js +260 -260
  41. package/dist/implementation/GeometryMathManager.js.map +1 -1
  42. package/dist/implementation/RestrictionManager.d.ts +28 -28
  43. package/dist/implementation/RestrictionManager.js +323 -323
  44. package/dist/implementation/RestrictionManager.js.map +1 -1
  45. package/dist/implementation/restrictions/AbstractRestriction.d.ts +42 -42
  46. package/dist/implementation/restrictions/AbstractRestriction.js +164 -154
  47. package/dist/implementation/restrictions/AbstractRestriction.js.map +1 -1
  48. package/dist/implementation/restrictions/AbstractSnapRestriction.d.ts +35 -35
  49. package/dist/implementation/restrictions/AbstractSnapRestriction.js +150 -140
  50. package/dist/implementation/restrictions/AbstractSnapRestriction.js.map +1 -1
  51. package/dist/implementation/restrictions/RestrictionsHelper.d.ts +10 -10
  52. package/dist/implementation/restrictions/RestrictionsHelper.d.ts.map +1 -1
  53. package/dist/implementation/restrictions/RestrictionsHelper.js +50 -50
  54. package/dist/implementation/restrictions/RestrictionsHelper.js.map +1 -1
  55. package/dist/implementation/restrictions/camera_plane/CameraPlaneRestriction.d.ts +17 -17
  56. package/dist/implementation/restrictions/camera_plane/CameraPlaneRestriction.js +62 -62
  57. package/dist/implementation/restrictions/camera_plane/CameraPlaneRestriction.js.map +1 -1
  58. package/dist/implementation/restrictions/geometry/GeometryRestriction.d.ts +92 -92
  59. package/dist/implementation/restrictions/geometry/GeometryRestriction.js +410 -400
  60. package/dist/implementation/restrictions/geometry/GeometryRestriction.js.map +1 -1
  61. package/dist/implementation/restrictions/line/LineRestriction.d.ts +58 -58
  62. package/dist/implementation/restrictions/line/LineRestriction.js +291 -281
  63. package/dist/implementation/restrictions/line/LineRestriction.js.map +1 -1
  64. package/dist/implementation/restrictions/plane/PlaneRestriction.d.ts +65 -65
  65. package/dist/implementation/restrictions/plane/PlaneRestriction.js +306 -306
  66. package/dist/implementation/restrictions/plane/PlaneRestriction.js.map +1 -1
  67. package/dist/implementation/restrictions/plane/snap/AngularRestriction.d.ts +39 -39
  68. package/dist/implementation/restrictions/plane/snap/AngularRestriction.d.ts.map +1 -1
  69. package/dist/implementation/restrictions/plane/snap/AngularRestriction.js +346 -346
  70. package/dist/implementation/restrictions/plane/snap/AngularRestriction.js.map +1 -1
  71. package/dist/implementation/restrictions/plane/snap/AxisRestriction.d.ts +27 -27
  72. package/dist/implementation/restrictions/plane/snap/AxisRestriction.d.ts.map +1 -1
  73. package/dist/implementation/restrictions/plane/snap/AxisRestriction.js +239 -229
  74. package/dist/implementation/restrictions/plane/snap/AxisRestriction.js.map +1 -1
  75. package/dist/implementation/restrictions/plane/snap/GridRestriction.d.ts +39 -39
  76. package/dist/implementation/restrictions/plane/snap/GridRestriction.d.ts.map +1 -1
  77. package/dist/implementation/restrictions/plane/snap/GridRestriction.js +318 -308
  78. package/dist/implementation/restrictions/plane/snap/GridRestriction.js.map +1 -1
  79. package/dist/implementation/restrictions/point/PointRestriction.d.ts +45 -45
  80. package/dist/implementation/restrictions/point/PointRestriction.js +166 -156
  81. package/dist/implementation/restrictions/point/PointRestriction.js.map +1 -1
  82. package/dist/index.d.ts +29 -29
  83. package/dist/index.js +37 -37
  84. package/dist/interfaces/IDragAnchor.d.ts +8 -8
  85. package/dist/interfaces/IDragAnchor.js +2 -2
  86. package/dist/interfaces/IRestriction.d.ts +117 -117
  87. package/dist/interfaces/IRestriction.d.ts.map +1 -1
  88. package/dist/interfaces/IRestriction.js +23 -23
  89. package/dist/interfaces/IRestriction.js.map +1 -1
  90. package/dist/interfaces/IRestrictionManager.d.ts +13 -13
  91. package/dist/interfaces/IRestrictionManager.js +2 -2
  92. package/dist/interfaces/ISnapRestriction.d.ts +81 -81
  93. package/dist/interfaces/ISnapRestriction.d.ts.map +1 -1
  94. package/dist/interfaces/ISnapRestriction.js +3 -3
  95. package/package.json +10 -10
@@ -1,307 +1,307 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _AngularRestriction_activationKey, _AngularRestriction_geometryMathManager, _AngularRestriction_planeRestriction, _AngularRestriction_active, _AngularRestriction_activePolarGrids, _AngularRestriction_angleStep, _AngularRestriction_angleStepEditable, _AngularRestriction_angles, _AngularRestriction_labelNext, _AngularRestriction_labelPrevious, _AngularRestriction_priority, _AngularRestriction_settings;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.AngularRestriction = void 0;
16
- const viewer_1 = require("@shapediver/viewer");
17
- const viewer_rendering_engine_rendering_engine_threejs_1 = require("@shapediver/viewer.rendering-engine.rendering-engine-threejs");
18
- const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
19
- const gl_matrix_1 = require("gl-matrix");
20
- const IRestriction_1 = require("../../../../interfaces/IRestriction");
21
- const AbstractSnapRestriction_1 = require("../../AbstractSnapRestriction");
22
- // #endregion Type aliases (1)
23
- // #region Classes (1)
24
- class AngularRestriction extends AbstractSnapRestriction_1.AbstractSnapRestriction {
25
- // #endregion Properties (12)
26
- // #region Constructors (1)
27
- constructor(viewport, geometryMathManager, parentNode, planeRestriction, settings, properties) {
28
- var _a, _b, _c;
29
- super(viewport, parentNode, "angular", properties);
30
- // #region Properties (12)
31
- _AngularRestriction_activationKey.set(this, void 0);
32
- _AngularRestriction_geometryMathManager.set(this, void 0);
33
- _AngularRestriction_planeRestriction.set(this, void 0);
34
- _AngularRestriction_active.set(this, false);
35
- _AngularRestriction_activePolarGrids.set(this, {
36
- next: false,
37
- previous: false,
38
- });
39
- _AngularRestriction_angleStep.set(this, void 0);
40
- _AngularRestriction_angleStepEditable.set(this, true);
41
- _AngularRestriction_angles.set(this, []);
42
- _AngularRestriction_labelNext.set(this, void 0);
43
- _AngularRestriction_labelPrevious.set(this, void 0);
44
- _AngularRestriction_priority.set(this, 0);
45
- _AngularRestriction_settings.set(this, void 0);
46
- __classPrivateFieldSet(this, _AngularRestriction_geometryMathManager, geometryMathManager, "f");
47
- __classPrivateFieldSet(this, _AngularRestriction_settings, settings, "f");
48
- __classPrivateFieldSet(this, _AngularRestriction_planeRestriction, planeRestriction, "f");
49
- __classPrivateFieldSet(this, _AngularRestriction_activationKey, (properties === null || properties === void 0 ? void 0 : properties.activationKey) || "a", "f");
50
- this.enabled = (_a = properties === null || properties === void 0 ? void 0 : properties.enabled) !== null && _a !== void 0 ? _a : false;
51
- this._enabledEditable = (_b = properties === null || properties === void 0 ? void 0 : properties.enabledEditable) !== null && _b !== void 0 ? _b : true;
52
- __classPrivateFieldSet(this, _AngularRestriction_angleStep, (properties === null || properties === void 0 ? void 0 : properties.angleStep) || Math.PI / 12, "f");
53
- __classPrivateFieldSet(this, _AngularRestriction_angleStepEditable, (_c = properties === null || properties === void 0 ? void 0 : properties.angleStepEditable) !== null && _c !== void 0 ? _c : true, "f");
54
- __classPrivateFieldSet(this, _AngularRestriction_priority, (properties === null || properties === void 0 ? void 0 : properties.priority) || 0, "f");
55
- // calculate the angles
56
- this.calculateAngles();
57
- }
58
- // #endregion Constructors (1)
59
- // #region Public Getters And Setters (8)
60
- get active() {
61
- return __classPrivateFieldGet(this, _AngularRestriction_active, "f");
62
- }
63
- set active(value) {
64
- __classPrivateFieldSet(this, _AngularRestriction_active, value, "f");
65
- if (value === false) {
66
- if (__classPrivateFieldGet(this, _AngularRestriction_labelNext, "f"))
67
- __classPrivateFieldGet(this, _AngularRestriction_labelNext, "f").visible = false;
68
- if (__classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f"))
69
- __classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f").visible = false;
70
- }
71
- else {
72
- if (__classPrivateFieldGet(this, _AngularRestriction_labelNext, "f") && __classPrivateFieldGet(this, _AngularRestriction_activePolarGrids, "f").next)
73
- __classPrivateFieldGet(this, _AngularRestriction_labelNext, "f").visible = true;
74
- if (__classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f") && __classPrivateFieldGet(this, _AngularRestriction_activePolarGrids, "f").previous)
75
- __classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f").visible = true;
76
- }
77
- }
78
- get angleStep() {
79
- return __classPrivateFieldGet(this, _AngularRestriction_angleStep, "f");
80
- }
81
- set angleStep(value) {
82
- if (__classPrivateFieldGet(this, _AngularRestriction_angleStepEditable, "f") === false)
83
- return;
84
- __classPrivateFieldSet(this, _AngularRestriction_angleStep, value, "f");
85
- this.calculateAngles();
86
- }
87
- get angleStepEditable() {
88
- return __classPrivateFieldGet(this, _AngularRestriction_angleStepEditable, "f");
89
- }
90
- get enabledEditable() {
91
- return this._enabledEditable;
92
- }
93
- get priority() {
94
- return __classPrivateFieldGet(this, _AngularRestriction_priority, "f");
95
- }
96
- set priority(value) {
97
- __classPrivateFieldSet(this, _AngularRestriction_priority, value, "f");
98
- }
99
- // #endregion Public Getters And Setters (8)
100
- // #region Public Methods (2)
101
- snap(ray, point, distance, metaData) {
102
- var _a;
103
- if (!(0, IRestriction_1.isDrawingRestriction)(metaData))
104
- return;
105
- // check if the activation key is pressed
106
- const isKeyToggled = ((_a = metaData === null || metaData === void 0 ? void 0 : metaData.toggledKeys) === null || _a === void 0 ? void 0 : _a.length) === 1 &&
107
- (metaData === null || metaData === void 0 ? void 0 : metaData.toggledKeys[0]) === __classPrivateFieldGet(this, _AngularRestriction_activationKey, "f");
108
- // if the restriction is not enabled OR the activation key is set and the key is not pressed, return
109
- if (this.enabled === false && !isKeyToggled)
110
- return;
111
- if (__classPrivateFieldGet(this, _AngularRestriction_labelNext, "f"))
112
- __classPrivateFieldGet(this, _AngularRestriction_labelNext, "f").visible = false;
113
- if (__classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f"))
114
- __classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f").visible = false;
115
- __classPrivateFieldSet(this, _AngularRestriction_activePolarGrids, {
116
- next: false,
117
- previous: false,
118
- }, "f");
119
- const positionArray = metaData === null || metaData === void 0 ? void 0 : metaData.positionArray;
120
- if (!positionArray)
121
- return;
122
- let previousIndex, nextIndex;
123
- if (metaData !== undefined && metaData.index !== undefined) {
124
- previousIndex = this.getPreviousIndex(metaData.index, positionArray);
125
- nextIndex = this.getNextIndex(metaData.index, positionArray);
126
- }
127
- else {
128
- // if no index was provided, it is a new point
129
- previousIndex = positionArray.length / 3 - 1;
130
- nextIndex = 0;
131
- }
132
- const previousPreviousIndex = this.getPreviousIndex(previousIndex, positionArray);
133
- const nextNextIndex = this.getNextIndex(nextIndex, positionArray);
134
- if (positionArray.length / 3 < 2)
135
- return;
136
- /**
137
- * Explanation of the algorithm:
138
- * 1. Project the point onto the XY-Plane
139
- * 2. Find the next point and the previous point
140
- * 3. Project the next and previous point onto the XY-Plane
141
- * 4. Calculate the angle between the point and the next and previous point
142
- * 5. Determine which if the angles are in the range to snap to
143
- * a. If both are in the range, snap to the intersection of the two lines
144
- * b. If only one is in the range, snap to the intersection of the line and the plane
145
- * c. If none is in the range, return
146
- * 6. Reverse the projection to the original coordinate system
147
- */
148
- // get the next and previous point from the position array
149
- const nextPointFromData = gl_matrix_1.vec3.fromValues(positionArray.at(nextIndex * 3), positionArray.at(nextIndex * 3 + 1), positionArray.at(nextIndex * 3 + 2));
150
- const nextNextPointFromData = gl_matrix_1.vec3.fromValues(positionArray.at(nextNextIndex * 3), positionArray.at(nextNextIndex * 3 + 1), positionArray.at(nextNextIndex * 3 + 2));
151
- const previousPointFromData = gl_matrix_1.vec3.fromValues(positionArray.at(previousIndex * 3), positionArray.at(previousIndex * 3 + 1), positionArray.at(previousIndex * 3 + 2));
152
- const previousPreviousPointFromData = gl_matrix_1.vec3.fromValues(positionArray.at(previousPreviousIndex * 3), positionArray.at(previousPreviousIndex * 3 + 1), positionArray.at(previousPreviousIndex * 3 + 2));
153
- // project them onto the same plane as the point
154
- const nextPointProjected = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), nextPointFromData, gl_matrix_1.vec3.scale(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").normal, gl_matrix_1.vec3.dot(gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), nextPointFromData, point), __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").normal)));
155
- const nextNextPointProjected = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), nextNextPointFromData, gl_matrix_1.vec3.scale(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").normal, gl_matrix_1.vec3.dot(gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), nextNextPointFromData, point), __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").normal)));
156
- const previousPointProjected = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), previousPointFromData, gl_matrix_1.vec3.scale(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").normal, gl_matrix_1.vec3.dot(gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), previousPointFromData, point), __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").normal)));
157
- const previousPreviousPointProjected = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), previousPreviousPointFromData, gl_matrix_1.vec3.scale(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").normal, gl_matrix_1.vec3.dot(gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), previousPreviousPointFromData, point), __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").normal)));
158
- // project the point onto the XY-Plane
159
- const pointProjected = gl_matrix_1.vec3.transformMat4(gl_matrix_1.vec3.create(), point, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationToXYPlaneMatrix);
160
- gl_matrix_1.vec3.transformMat4(nextPointProjected, nextPointProjected, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationToXYPlaneMatrix);
161
- gl_matrix_1.vec3.transformMat4(nextNextPointProjected, nextNextPointProjected, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationToXYPlaneMatrix);
162
- gl_matrix_1.vec3.transformMat4(previousPointProjected, previousPointProjected, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationToXYPlaneMatrix);
163
- gl_matrix_1.vec3.transformMat4(previousPreviousPointProjected, previousPreviousPointProjected, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationToXYPlaneMatrix);
164
- // calculate the angle between the next and previous point and the point to restrict on the axis
165
- const { angularDifference: angularDifferenceNext, crossProduct: crossProductNext, closestAngle: closestAngleNext, } = this.getAngularDifference({ start: nextPointProjected, end: nextNextPointProjected }, { start: nextPointProjected, end: pointProjected });
166
- const { angularDifference: angularDifferencePrevious, crossProduct: crossProductPrevious, closestAngle: closestAnglePrevious, } = this.getAngularDifference({
167
- start: previousPointProjected,
168
- end: previousPreviousPointProjected,
169
- }, { start: previousPointProjected, end: pointProjected });
170
- // calculate the distances in screen space so we can check how close it is
171
- const resultPointNextAngle = gl_matrix_1.vec3.rotateZ(gl_matrix_1.vec3.create(), pointProjected, nextPointProjected, crossProductNext[2] < 0
172
- ? -angularDifferenceNext
173
- : angularDifferenceNext);
174
- const screenSpaceDistanceCheckNextAngle = __classPrivateFieldGet(this, _AngularRestriction_geometryMathManager, "f").screenSpaceDistanceCheck(resultPointNextAngle, pointProjected, __classPrivateFieldGet(this, _AngularRestriction_settings, "f").points.size_0 *
175
- __classPrivateFieldGet(this, _AngularRestriction_settings, "f").distanceMultiplicationFactor);
176
- const resultPointPreviousAngle = gl_matrix_1.vec3.rotateZ(gl_matrix_1.vec3.create(), pointProjected, previousPointProjected, crossProductPrevious[2] < 0
177
- ? -angularDifferencePrevious
178
- : angularDifferencePrevious);
179
- const screenSpaceDistanceCheckPreviousAngle = __classPrivateFieldGet(this, _AngularRestriction_geometryMathManager, "f").screenSpaceDistanceCheck(resultPointPreviousAngle, pointProjected, __classPrivateFieldGet(this, _AngularRestriction_settings, "f").points.size_0 *
180
- __classPrivateFieldGet(this, _AngularRestriction_settings, "f").distanceMultiplicationFactor);
181
- if (screenSpaceDistanceCheckNextAngle.check === false &&
182
- screenSpaceDistanceCheckPreviousAngle.check === false)
183
- return;
184
- // snap to clear defined point if both distances are smaller than threshold
185
- if (positionArray.length > 6 &&
186
- screenSpaceDistanceCheckNextAngle.check === true &&
187
- screenSpaceDistanceCheckPreviousAngle.check === true) {
188
- const rayDirectionNext = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), resultPointNextAngle, nextPointProjected));
189
- const rayDirectionPrevious = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), resultPointPreviousAngle, previousPointProjected));
190
- const crossProduct = gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), rayDirectionNext, rayDirectionPrevious);
191
- const crossProductLength = gl_matrix_1.vec3.length(crossProduct);
192
- if (crossProductLength < 0.001) {
193
- gl_matrix_1.vec3.transformMat4(resultPointNextAngle, resultPointNextAngle, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationFromXYPlaneMatrix);
194
- return {
195
- targetPoint: resultPointNextAngle,
196
- distanceClosestPointToTargetPointSquared: gl_matrix_1.vec3.sqrDist(resultPointNextAngle, point),
197
- closestIntersectionPoint: point,
198
- distanceOriginToClosestIntersectionPointSquared: distance,
199
- restriction: __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f"),
200
- snapRestriction: this,
201
- };
202
- }
203
- const t = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), previousPointProjected, nextPointProjected);
204
- const u = gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), t, rayDirectionPrevious);
205
- const v = gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), t, rayDirectionNext);
206
- const tValue = gl_matrix_1.vec3.dot(u, crossProduct) / Math.pow(crossProductLength, 2);
207
- const uValue = gl_matrix_1.vec3.dot(v, crossProduct) / Math.pow(crossProductLength, 2);
208
- if (tValue < 0 || uValue < 0) {
209
- gl_matrix_1.vec3.transformMat4(resultPointNextAngle, resultPointNextAngle, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationFromXYPlaneMatrix);
210
- return {
211
- targetPoint: resultPointNextAngle,
212
- distanceClosestPointToTargetPointSquared: gl_matrix_1.vec3.sqrDist(resultPointNextAngle, point),
213
- closestIntersectionPoint: point,
214
- distanceOriginToClosestIntersectionPointSquared: distance,
215
- restriction: __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f"),
216
- snapRestriction: this,
217
- };
218
- }
219
- const intersection = gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), nextPointProjected, gl_matrix_1.vec3.scale(gl_matrix_1.vec3.create(), rayDirectionNext, tValue));
220
- __classPrivateFieldSet(this, _AngularRestriction_labelNext, this.createGrid(__classPrivateFieldGet(this, _AngularRestriction_labelNext, "f"), nextPointFromData, closestAngleNext), "f");
221
- __classPrivateFieldGet(this, _AngularRestriction_activePolarGrids, "f").next = true;
222
- __classPrivateFieldSet(this, _AngularRestriction_labelPrevious, this.createGrid(__classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f"), previousPointFromData, closestAnglePrevious), "f");
223
- __classPrivateFieldGet(this, _AngularRestriction_activePolarGrids, "f").previous = true;
224
- // reverse the projection to the original coordinate system
225
- gl_matrix_1.vec3.transformMat4(intersection, intersection, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationFromXYPlaneMatrix);
226
- return {
227
- targetPoint: intersection,
228
- distanceClosestPointToTargetPointSquared: gl_matrix_1.vec3.sqrDist(intersection, point),
229
- closestIntersectionPoint: point,
230
- distanceOriginToClosestIntersectionPointSquared: distance,
231
- restriction: __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f"),
232
- snapRestriction: this,
233
- };
234
- }
235
- // check which distance to the projection is smaller
236
- if (screenSpaceDistanceCheckNextAngle.distanceSquared <
237
- screenSpaceDistanceCheckPreviousAngle.distanceSquared) {
238
- __classPrivateFieldSet(this, _AngularRestriction_labelNext, this.createGrid(__classPrivateFieldGet(this, _AngularRestriction_labelNext, "f"), nextPointFromData, closestAngleNext), "f");
239
- __classPrivateFieldGet(this, _AngularRestriction_activePolarGrids, "f").next = true;
240
- // reverse the projection to the original coordinate system
241
- gl_matrix_1.vec3.transformMat4(resultPointNextAngle, resultPointNextAngle, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationFromXYPlaneMatrix);
242
- return {
243
- targetPoint: resultPointNextAngle,
244
- distanceClosestPointToTargetPointSquared: gl_matrix_1.vec3.sqrDist(resultPointNextAngle, point),
245
- closestIntersectionPoint: point,
246
- distanceOriginToClosestIntersectionPointSquared: distance,
247
- restriction: __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f"),
248
- snapRestriction: this,
249
- };
250
- }
251
- else {
252
- __classPrivateFieldSet(this, _AngularRestriction_labelPrevious, this.createGrid(__classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f"), previousPointFromData, closestAnglePrevious), "f");
253
- __classPrivateFieldGet(this, _AngularRestriction_activePolarGrids, "f").previous = true;
254
- // reverse the projection to the original coordinate system
255
- gl_matrix_1.vec3.transformMat4(resultPointPreviousAngle, resultPointPreviousAngle, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationFromXYPlaneMatrix);
256
- return {
257
- targetPoint: resultPointPreviousAngle,
258
- distanceClosestPointToTargetPointSquared: gl_matrix_1.vec3.sqrDist(resultPointPreviousAngle, point),
259
- closestIntersectionPoint: point,
260
- distanceOriginToClosestIntersectionPointSquared: distance,
261
- restriction: __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f"),
262
- snapRestriction: this,
263
- };
264
- }
265
- }
266
- updatePlaneDefinition() { }
267
- // #endregion Public Methods (2)
268
- // #region Protected Methods (1)
269
- visibilityChanged(visible) {
270
- if (visible === false) {
271
- if (__classPrivateFieldGet(this, _AngularRestriction_labelNext, "f"))
272
- __classPrivateFieldGet(this, _AngularRestriction_labelNext, "f").visible = false;
273
- if (__classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f"))
274
- __classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f").visible = false;
275
- }
276
- }
277
- // #endregion Protected Methods (1)
278
- // #region Private Methods (5)
279
- calculateAngles() {
280
- __classPrivateFieldSet(this, _AngularRestriction_angles, [], "f");
281
- for (let i = 0; i <= Math.PI + 0.0001; i += __classPrivateFieldGet(this, _AngularRestriction_angleStep, "f")) {
282
- __classPrivateFieldGet(this, _AngularRestriction_angles, "f").push(i);
283
- }
284
- }
285
- createGrid(label, position, angle) {
286
- if (label)
287
- this._object3D.remove(label);
288
- let radius = viewer_1.sceneTree.root.boundingBox.boundingSphere.radius / 100;
289
- if (radius === Infinity)
290
- radius = 1;
291
- const text = document.createElement("div");
292
- text.className = "label";
293
- label = new viewer_rendering_engine_rendering_engine_threejs_1.CSS2DObject(text);
294
- // remove the old style, if there is one
295
- document.head.querySelectorAll("style").forEach((style) => {
296
- var _a;
297
- if ((_a = style.textContent) === null || _a === void 0 ? void 0 : _a.includes(label.uuid))
298
- document.head.removeChild(style);
299
- });
300
- const parent = document.createElement("div");
301
- parent.className = `angular-label-parent-${label.uuid}`;
302
- const child = document.createElement("div");
303
- child.className = `angular-label-${label.uuid}`;
304
- const style = document.createElement("style");
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _AngularRestriction_activationKey, _AngularRestriction_geometryMathManager, _AngularRestriction_planeRestriction, _AngularRestriction_active, _AngularRestriction_activePolarGrids, _AngularRestriction_angleStep, _AngularRestriction_angleStepEditable, _AngularRestriction_angles, _AngularRestriction_labelNext, _AngularRestriction_labelPrevious, _AngularRestriction_priority, _AngularRestriction_settings;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AngularRestriction = void 0;
16
+ const viewer_1 = require("@shapediver/viewer");
17
+ const viewer_rendering_engine_rendering_engine_threejs_1 = require("@shapediver/viewer.rendering-engine.rendering-engine-threejs");
18
+ const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
19
+ const gl_matrix_1 = require("gl-matrix");
20
+ const IRestriction_1 = require("../../../../interfaces/IRestriction");
21
+ const AbstractSnapRestriction_1 = require("../../AbstractSnapRestriction");
22
+ // #endregion Type aliases (1)
23
+ // #region Classes (1)
24
+ class AngularRestriction extends AbstractSnapRestriction_1.AbstractSnapRestriction {
25
+ // #endregion Properties (12)
26
+ // #region Constructors (1)
27
+ constructor(viewport, geometryMathManager, parentNode, planeRestriction, settings, properties) {
28
+ var _a, _b, _c;
29
+ super(viewport, parentNode, "angular", properties);
30
+ // #region Properties (12)
31
+ _AngularRestriction_activationKey.set(this, void 0);
32
+ _AngularRestriction_geometryMathManager.set(this, void 0);
33
+ _AngularRestriction_planeRestriction.set(this, void 0);
34
+ _AngularRestriction_active.set(this, false);
35
+ _AngularRestriction_activePolarGrids.set(this, {
36
+ next: false,
37
+ previous: false,
38
+ });
39
+ _AngularRestriction_angleStep.set(this, void 0);
40
+ _AngularRestriction_angleStepEditable.set(this, true);
41
+ _AngularRestriction_angles.set(this, []);
42
+ _AngularRestriction_labelNext.set(this, void 0);
43
+ _AngularRestriction_labelPrevious.set(this, void 0);
44
+ _AngularRestriction_priority.set(this, 0);
45
+ _AngularRestriction_settings.set(this, void 0);
46
+ __classPrivateFieldSet(this, _AngularRestriction_geometryMathManager, geometryMathManager, "f");
47
+ __classPrivateFieldSet(this, _AngularRestriction_settings, settings, "f");
48
+ __classPrivateFieldSet(this, _AngularRestriction_planeRestriction, planeRestriction, "f");
49
+ __classPrivateFieldSet(this, _AngularRestriction_activationKey, (properties === null || properties === void 0 ? void 0 : properties.activationKey) || "a", "f");
50
+ this.enabled = (_a = properties === null || properties === void 0 ? void 0 : properties.enabled) !== null && _a !== void 0 ? _a : false;
51
+ this._enabledEditable = (_b = properties === null || properties === void 0 ? void 0 : properties.enabledEditable) !== null && _b !== void 0 ? _b : true;
52
+ __classPrivateFieldSet(this, _AngularRestriction_angleStep, (properties === null || properties === void 0 ? void 0 : properties.angleStep) || Math.PI / 12, "f");
53
+ __classPrivateFieldSet(this, _AngularRestriction_angleStepEditable, (_c = properties === null || properties === void 0 ? void 0 : properties.angleStepEditable) !== null && _c !== void 0 ? _c : true, "f");
54
+ __classPrivateFieldSet(this, _AngularRestriction_priority, (properties === null || properties === void 0 ? void 0 : properties.priority) || 0, "f");
55
+ // calculate the angles
56
+ this.calculateAngles();
57
+ }
58
+ // #endregion Constructors (1)
59
+ // #region Public Getters And Setters (8)
60
+ get active() {
61
+ return __classPrivateFieldGet(this, _AngularRestriction_active, "f");
62
+ }
63
+ set active(value) {
64
+ __classPrivateFieldSet(this, _AngularRestriction_active, value, "f");
65
+ if (value === false) {
66
+ if (__classPrivateFieldGet(this, _AngularRestriction_labelNext, "f"))
67
+ __classPrivateFieldGet(this, _AngularRestriction_labelNext, "f").visible = false;
68
+ if (__classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f"))
69
+ __classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f").visible = false;
70
+ }
71
+ else {
72
+ if (__classPrivateFieldGet(this, _AngularRestriction_labelNext, "f") && __classPrivateFieldGet(this, _AngularRestriction_activePolarGrids, "f").next)
73
+ __classPrivateFieldGet(this, _AngularRestriction_labelNext, "f").visible = true;
74
+ if (__classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f") && __classPrivateFieldGet(this, _AngularRestriction_activePolarGrids, "f").previous)
75
+ __classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f").visible = true;
76
+ }
77
+ }
78
+ get angleStep() {
79
+ return __classPrivateFieldGet(this, _AngularRestriction_angleStep, "f");
80
+ }
81
+ set angleStep(value) {
82
+ if (__classPrivateFieldGet(this, _AngularRestriction_angleStepEditable, "f") === false)
83
+ return;
84
+ __classPrivateFieldSet(this, _AngularRestriction_angleStep, value, "f");
85
+ this.calculateAngles();
86
+ }
87
+ get angleStepEditable() {
88
+ return __classPrivateFieldGet(this, _AngularRestriction_angleStepEditable, "f");
89
+ }
90
+ get enabledEditable() {
91
+ return this._enabledEditable;
92
+ }
93
+ get priority() {
94
+ return __classPrivateFieldGet(this, _AngularRestriction_priority, "f");
95
+ }
96
+ set priority(value) {
97
+ __classPrivateFieldSet(this, _AngularRestriction_priority, value, "f");
98
+ }
99
+ // #endregion Public Getters And Setters (8)
100
+ // #region Public Methods (2)
101
+ snap(ray, point, distance, metaData) {
102
+ var _a;
103
+ if (!(0, IRestriction_1.isDrawingRestriction)(metaData))
104
+ return;
105
+ // check if the activation key is pressed
106
+ const isKeyToggled = ((_a = metaData === null || metaData === void 0 ? void 0 : metaData.toggledKeys) === null || _a === void 0 ? void 0 : _a.length) === 1 &&
107
+ (metaData === null || metaData === void 0 ? void 0 : metaData.toggledKeys[0]) === __classPrivateFieldGet(this, _AngularRestriction_activationKey, "f");
108
+ // if the restriction is not enabled OR the activation key is set and the key is not pressed, return
109
+ if (this.enabled === false && !isKeyToggled)
110
+ return;
111
+ if (__classPrivateFieldGet(this, _AngularRestriction_labelNext, "f"))
112
+ __classPrivateFieldGet(this, _AngularRestriction_labelNext, "f").visible = false;
113
+ if (__classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f"))
114
+ __classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f").visible = false;
115
+ __classPrivateFieldSet(this, _AngularRestriction_activePolarGrids, {
116
+ next: false,
117
+ previous: false,
118
+ }, "f");
119
+ const positionArray = metaData === null || metaData === void 0 ? void 0 : metaData.positionArray;
120
+ if (!positionArray)
121
+ return;
122
+ let previousIndex, nextIndex;
123
+ if (metaData !== undefined && metaData.index !== undefined) {
124
+ previousIndex = this.getPreviousIndex(metaData.index, positionArray);
125
+ nextIndex = this.getNextIndex(metaData.index, positionArray);
126
+ }
127
+ else {
128
+ // if no index was provided, it is a new point
129
+ previousIndex = positionArray.length / 3 - 1;
130
+ nextIndex = 0;
131
+ }
132
+ const previousPreviousIndex = this.getPreviousIndex(previousIndex, positionArray);
133
+ const nextNextIndex = this.getNextIndex(nextIndex, positionArray);
134
+ if (positionArray.length / 3 < 2)
135
+ return;
136
+ /**
137
+ * Explanation of the algorithm:
138
+ * 1. Project the point onto the XY-Plane
139
+ * 2. Find the next point and the previous point
140
+ * 3. Project the next and previous point onto the XY-Plane
141
+ * 4. Calculate the angle between the point and the next and previous point
142
+ * 5. Determine which if the angles are in the range to snap to
143
+ * a. If both are in the range, snap to the intersection of the two lines
144
+ * b. If only one is in the range, snap to the intersection of the line and the plane
145
+ * c. If none is in the range, return
146
+ * 6. Reverse the projection to the original coordinate system
147
+ */
148
+ // get the next and previous point from the position array
149
+ const nextPointFromData = gl_matrix_1.vec3.fromValues(positionArray.at(nextIndex * 3), positionArray.at(nextIndex * 3 + 1), positionArray.at(nextIndex * 3 + 2));
150
+ const nextNextPointFromData = gl_matrix_1.vec3.fromValues(positionArray.at(nextNextIndex * 3), positionArray.at(nextNextIndex * 3 + 1), positionArray.at(nextNextIndex * 3 + 2));
151
+ const previousPointFromData = gl_matrix_1.vec3.fromValues(positionArray.at(previousIndex * 3), positionArray.at(previousIndex * 3 + 1), positionArray.at(previousIndex * 3 + 2));
152
+ const previousPreviousPointFromData = gl_matrix_1.vec3.fromValues(positionArray.at(previousPreviousIndex * 3), positionArray.at(previousPreviousIndex * 3 + 1), positionArray.at(previousPreviousIndex * 3 + 2));
153
+ // project them onto the same plane as the point
154
+ const nextPointProjected = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), nextPointFromData, gl_matrix_1.vec3.scale(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").normal, gl_matrix_1.vec3.dot(gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), nextPointFromData, point), __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").normal)));
155
+ const nextNextPointProjected = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), nextNextPointFromData, gl_matrix_1.vec3.scale(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").normal, gl_matrix_1.vec3.dot(gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), nextNextPointFromData, point), __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").normal)));
156
+ const previousPointProjected = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), previousPointFromData, gl_matrix_1.vec3.scale(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").normal, gl_matrix_1.vec3.dot(gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), previousPointFromData, point), __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").normal)));
157
+ const previousPreviousPointProjected = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), previousPreviousPointFromData, gl_matrix_1.vec3.scale(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").normal, gl_matrix_1.vec3.dot(gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), previousPreviousPointFromData, point), __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").normal)));
158
+ // project the point onto the XY-Plane
159
+ const pointProjected = gl_matrix_1.vec3.transformMat4(gl_matrix_1.vec3.create(), point, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationToXYPlaneMatrix);
160
+ gl_matrix_1.vec3.transformMat4(nextPointProjected, nextPointProjected, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationToXYPlaneMatrix);
161
+ gl_matrix_1.vec3.transformMat4(nextNextPointProjected, nextNextPointProjected, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationToXYPlaneMatrix);
162
+ gl_matrix_1.vec3.transformMat4(previousPointProjected, previousPointProjected, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationToXYPlaneMatrix);
163
+ gl_matrix_1.vec3.transformMat4(previousPreviousPointProjected, previousPreviousPointProjected, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationToXYPlaneMatrix);
164
+ // calculate the angle between the next and previous point and the point to restrict on the axis
165
+ const { angularDifference: angularDifferenceNext, crossProduct: crossProductNext, closestAngle: closestAngleNext, } = this.getAngularDifference({ start: nextPointProjected, end: nextNextPointProjected }, { start: nextPointProjected, end: pointProjected });
166
+ const { angularDifference: angularDifferencePrevious, crossProduct: crossProductPrevious, closestAngle: closestAnglePrevious, } = this.getAngularDifference({
167
+ start: previousPointProjected,
168
+ end: previousPreviousPointProjected,
169
+ }, { start: previousPointProjected, end: pointProjected });
170
+ // calculate the distances in screen space so we can check how close it is
171
+ const resultPointNextAngle = gl_matrix_1.vec3.rotateZ(gl_matrix_1.vec3.create(), pointProjected, nextPointProjected, crossProductNext[2] < 0
172
+ ? -angularDifferenceNext
173
+ : angularDifferenceNext);
174
+ const screenSpaceDistanceCheckNextAngle = __classPrivateFieldGet(this, _AngularRestriction_geometryMathManager, "f").screenSpaceDistanceCheck(resultPointNextAngle, pointProjected, __classPrivateFieldGet(this, _AngularRestriction_settings, "f").points.size_0 *
175
+ __classPrivateFieldGet(this, _AngularRestriction_settings, "f").distanceMultiplicationFactor);
176
+ const resultPointPreviousAngle = gl_matrix_1.vec3.rotateZ(gl_matrix_1.vec3.create(), pointProjected, previousPointProjected, crossProductPrevious[2] < 0
177
+ ? -angularDifferencePrevious
178
+ : angularDifferencePrevious);
179
+ const screenSpaceDistanceCheckPreviousAngle = __classPrivateFieldGet(this, _AngularRestriction_geometryMathManager, "f").screenSpaceDistanceCheck(resultPointPreviousAngle, pointProjected, __classPrivateFieldGet(this, _AngularRestriction_settings, "f").points.size_0 *
180
+ __classPrivateFieldGet(this, _AngularRestriction_settings, "f").distanceMultiplicationFactor);
181
+ if (screenSpaceDistanceCheckNextAngle.check === false &&
182
+ screenSpaceDistanceCheckPreviousAngle.check === false)
183
+ return;
184
+ // snap to clear defined point if both distances are smaller than threshold
185
+ if (positionArray.length > 6 &&
186
+ screenSpaceDistanceCheckNextAngle.check === true &&
187
+ screenSpaceDistanceCheckPreviousAngle.check === true) {
188
+ const rayDirectionNext = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), resultPointNextAngle, nextPointProjected));
189
+ const rayDirectionPrevious = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), resultPointPreviousAngle, previousPointProjected));
190
+ const crossProduct = gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), rayDirectionNext, rayDirectionPrevious);
191
+ const crossProductLength = gl_matrix_1.vec3.length(crossProduct);
192
+ if (crossProductLength < 0.001) {
193
+ gl_matrix_1.vec3.transformMat4(resultPointNextAngle, resultPointNextAngle, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationFromXYPlaneMatrix);
194
+ return {
195
+ targetPoint: resultPointNextAngle,
196
+ distanceClosestPointToTargetPointSquared: gl_matrix_1.vec3.sqrDist(resultPointNextAngle, point),
197
+ closestIntersectionPoint: point,
198
+ distanceOriginToClosestIntersectionPointSquared: distance,
199
+ restriction: __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f"),
200
+ snapRestriction: this,
201
+ };
202
+ }
203
+ const t = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), previousPointProjected, nextPointProjected);
204
+ const u = gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), t, rayDirectionPrevious);
205
+ const v = gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), t, rayDirectionNext);
206
+ const tValue = gl_matrix_1.vec3.dot(u, crossProduct) / Math.pow(crossProductLength, 2);
207
+ const uValue = gl_matrix_1.vec3.dot(v, crossProduct) / Math.pow(crossProductLength, 2);
208
+ if (tValue < 0 || uValue < 0) {
209
+ gl_matrix_1.vec3.transformMat4(resultPointNextAngle, resultPointNextAngle, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationFromXYPlaneMatrix);
210
+ return {
211
+ targetPoint: resultPointNextAngle,
212
+ distanceClosestPointToTargetPointSquared: gl_matrix_1.vec3.sqrDist(resultPointNextAngle, point),
213
+ closestIntersectionPoint: point,
214
+ distanceOriginToClosestIntersectionPointSquared: distance,
215
+ restriction: __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f"),
216
+ snapRestriction: this,
217
+ };
218
+ }
219
+ const intersection = gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), nextPointProjected, gl_matrix_1.vec3.scale(gl_matrix_1.vec3.create(), rayDirectionNext, tValue));
220
+ __classPrivateFieldSet(this, _AngularRestriction_labelNext, this.createGrid(__classPrivateFieldGet(this, _AngularRestriction_labelNext, "f"), nextPointFromData, closestAngleNext), "f");
221
+ __classPrivateFieldGet(this, _AngularRestriction_activePolarGrids, "f").next = true;
222
+ __classPrivateFieldSet(this, _AngularRestriction_labelPrevious, this.createGrid(__classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f"), previousPointFromData, closestAnglePrevious), "f");
223
+ __classPrivateFieldGet(this, _AngularRestriction_activePolarGrids, "f").previous = true;
224
+ // reverse the projection to the original coordinate system
225
+ gl_matrix_1.vec3.transformMat4(intersection, intersection, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationFromXYPlaneMatrix);
226
+ return {
227
+ targetPoint: intersection,
228
+ distanceClosestPointToTargetPointSquared: gl_matrix_1.vec3.sqrDist(intersection, point),
229
+ closestIntersectionPoint: point,
230
+ distanceOriginToClosestIntersectionPointSquared: distance,
231
+ restriction: __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f"),
232
+ snapRestriction: this,
233
+ };
234
+ }
235
+ // check which distance to the projection is smaller
236
+ if (screenSpaceDistanceCheckNextAngle.distanceSquared <
237
+ screenSpaceDistanceCheckPreviousAngle.distanceSquared) {
238
+ __classPrivateFieldSet(this, _AngularRestriction_labelNext, this.createGrid(__classPrivateFieldGet(this, _AngularRestriction_labelNext, "f"), nextPointFromData, closestAngleNext), "f");
239
+ __classPrivateFieldGet(this, _AngularRestriction_activePolarGrids, "f").next = true;
240
+ // reverse the projection to the original coordinate system
241
+ gl_matrix_1.vec3.transformMat4(resultPointNextAngle, resultPointNextAngle, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationFromXYPlaneMatrix);
242
+ return {
243
+ targetPoint: resultPointNextAngle,
244
+ distanceClosestPointToTargetPointSquared: gl_matrix_1.vec3.sqrDist(resultPointNextAngle, point),
245
+ closestIntersectionPoint: point,
246
+ distanceOriginToClosestIntersectionPointSquared: distance,
247
+ restriction: __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f"),
248
+ snapRestriction: this,
249
+ };
250
+ }
251
+ else {
252
+ __classPrivateFieldSet(this, _AngularRestriction_labelPrevious, this.createGrid(__classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f"), previousPointFromData, closestAnglePrevious), "f");
253
+ __classPrivateFieldGet(this, _AngularRestriction_activePolarGrids, "f").previous = true;
254
+ // reverse the projection to the original coordinate system
255
+ gl_matrix_1.vec3.transformMat4(resultPointPreviousAngle, resultPointPreviousAngle, __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f").transformationFromXYPlaneMatrix);
256
+ return {
257
+ targetPoint: resultPointPreviousAngle,
258
+ distanceClosestPointToTargetPointSquared: gl_matrix_1.vec3.sqrDist(resultPointPreviousAngle, point),
259
+ closestIntersectionPoint: point,
260
+ distanceOriginToClosestIntersectionPointSquared: distance,
261
+ restriction: __classPrivateFieldGet(this, _AngularRestriction_planeRestriction, "f"),
262
+ snapRestriction: this,
263
+ };
264
+ }
265
+ }
266
+ updatePlaneDefinition() { }
267
+ // #endregion Public Methods (2)
268
+ // #region Protected Methods (1)
269
+ visibilityChanged(visible) {
270
+ if (visible === false) {
271
+ if (__classPrivateFieldGet(this, _AngularRestriction_labelNext, "f"))
272
+ __classPrivateFieldGet(this, _AngularRestriction_labelNext, "f").visible = false;
273
+ if (__classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f"))
274
+ __classPrivateFieldGet(this, _AngularRestriction_labelPrevious, "f").visible = false;
275
+ }
276
+ }
277
+ // #endregion Protected Methods (1)
278
+ // #region Private Methods (5)
279
+ calculateAngles() {
280
+ __classPrivateFieldSet(this, _AngularRestriction_angles, [], "f");
281
+ for (let i = 0; i <= Math.PI + 0.0001; i += __classPrivateFieldGet(this, _AngularRestriction_angleStep, "f")) {
282
+ __classPrivateFieldGet(this, _AngularRestriction_angles, "f").push(i);
283
+ }
284
+ }
285
+ createGrid(label, position, angle) {
286
+ if (label)
287
+ this._object3D.remove(label);
288
+ let radius = viewer_1.sceneTree.root.boundingBox.boundingSphere.radius / 100;
289
+ if (radius === Infinity)
290
+ radius = 1;
291
+ const text = document.createElement("div");
292
+ text.className = "label";
293
+ label = new viewer_rendering_engine_rendering_engine_threejs_1.CSS2DObject(text);
294
+ // remove the old style, if there is one
295
+ document.head.querySelectorAll("style").forEach((style) => {
296
+ var _a;
297
+ if ((_a = style.textContent) === null || _a === void 0 ? void 0 : _a.includes(label.uuid))
298
+ document.head.removeChild(style);
299
+ });
300
+ const parent = document.createElement("div");
301
+ parent.className = `angular-label-parent-${label.uuid}`;
302
+ const child = document.createElement("div");
303
+ child.className = `angular-label-${label.uuid}`;
304
+ const style = document.createElement("style");
305
305
  style.textContent = `
306
306
  .angular-label-${label.uuid} {
307
307
  display: flex;
@@ -328,46 +328,46 @@ class AngularRestriction extends AbstractSnapRestriction_1.AbstractSnapRestricti
328
328
  ${__classPrivateFieldGet(this, _AngularRestriction_settings, "f").points.color_1} ${(angle / Math.PI) * 100}% 100%
329
329
  );
330
330
  }
331
- `;
332
- document.head.appendChild(style);
333
- parent.appendChild(child);
334
- child.textContent = `${(0, viewer_shared_services_1.numberCleaner)((angle / Math.PI) * 180)}°`;
335
- text.appendChild(parent);
336
- label.position.set(position[0], position[1], position[2]);
337
- label.visible = false;
338
- this._object3D.add(label);
339
- return label;
340
- }
341
- getAngularDifference(line, referenceLine) {
342
- const lineDirection = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), line.end, line.start));
343
- const referenceLineDirection = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), referenceLine.end, referenceLine.start));
344
- // calculate the angle between the lineDirection and the referenceLineDirection
345
- const angleReference = gl_matrix_1.vec3.angle(lineDirection, referenceLineDirection);
346
- const crossProduct = gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), lineDirection, referenceLineDirection);
347
- // find the angle that is closest to the angle of the previous point
348
- let closestAngle = __classPrivateFieldGet(this, _AngularRestriction_angles, "f")[0];
349
- for (let i = 0; i < __classPrivateFieldGet(this, _AngularRestriction_angles, "f").length; i++) {
350
- const angle = __classPrivateFieldGet(this, _AngularRestriction_angles, "f")[i];
351
- if (Math.abs(angleReference - angle) <
352
- Math.abs(angleReference - closestAngle))
353
- closestAngle = angle;
354
- }
355
- // move the point to the closest angle
356
- const angularDifference = closestAngle - angleReference;
357
- return {
358
- angularDifference,
359
- crossProduct,
360
- closestAngle,
361
- };
362
- }
363
- getNextIndex(index, positionArray) {
364
- return index + 1 > positionArray.length / 3 - 1 ? 0 : index + 1;
365
- }
366
- getPreviousIndex(index, positionArray) {
367
- return index - 1 < 0 ? positionArray.length / 3 - 1 : index - 1;
368
- }
369
- }
370
- exports.AngularRestriction = AngularRestriction;
371
- _AngularRestriction_activationKey = new WeakMap(), _AngularRestriction_geometryMathManager = new WeakMap(), _AngularRestriction_planeRestriction = new WeakMap(), _AngularRestriction_active = new WeakMap(), _AngularRestriction_activePolarGrids = new WeakMap(), _AngularRestriction_angleStep = new WeakMap(), _AngularRestriction_angleStepEditable = new WeakMap(), _AngularRestriction_angles = new WeakMap(), _AngularRestriction_labelNext = new WeakMap(), _AngularRestriction_labelPrevious = new WeakMap(), _AngularRestriction_priority = new WeakMap(), _AngularRestriction_settings = new WeakMap();
372
- // #endregion Classes (1)
331
+ `;
332
+ document.head.appendChild(style);
333
+ parent.appendChild(child);
334
+ child.textContent = `${(0, viewer_shared_services_1.numberCleaner)((angle / Math.PI) * 180)}°`;
335
+ text.appendChild(parent);
336
+ label.position.set(position[0], position[1], position[2]);
337
+ label.visible = false;
338
+ this._object3D.add(label);
339
+ return label;
340
+ }
341
+ getAngularDifference(line, referenceLine) {
342
+ const lineDirection = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), line.end, line.start));
343
+ const referenceLineDirection = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), referenceLine.end, referenceLine.start));
344
+ // calculate the angle between the lineDirection and the referenceLineDirection
345
+ const angleReference = gl_matrix_1.vec3.angle(lineDirection, referenceLineDirection);
346
+ const crossProduct = gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), lineDirection, referenceLineDirection);
347
+ // find the angle that is closest to the angle of the previous point
348
+ let closestAngle = __classPrivateFieldGet(this, _AngularRestriction_angles, "f")[0];
349
+ for (let i = 0; i < __classPrivateFieldGet(this, _AngularRestriction_angles, "f").length; i++) {
350
+ const angle = __classPrivateFieldGet(this, _AngularRestriction_angles, "f")[i];
351
+ if (Math.abs(angleReference - angle) <
352
+ Math.abs(angleReference - closestAngle))
353
+ closestAngle = angle;
354
+ }
355
+ // move the point to the closest angle
356
+ const angularDifference = closestAngle - angleReference;
357
+ return {
358
+ angularDifference,
359
+ crossProduct,
360
+ closestAngle,
361
+ };
362
+ }
363
+ getNextIndex(index, positionArray) {
364
+ return index + 1 > positionArray.length / 3 - 1 ? 0 : index + 1;
365
+ }
366
+ getPreviousIndex(index, positionArray) {
367
+ return index - 1 < 0 ? positionArray.length / 3 - 1 : index - 1;
368
+ }
369
+ }
370
+ exports.AngularRestriction = AngularRestriction;
371
+ _AngularRestriction_activationKey = new WeakMap(), _AngularRestriction_geometryMathManager = new WeakMap(), _AngularRestriction_planeRestriction = new WeakMap(), _AngularRestriction_active = new WeakMap(), _AngularRestriction_activePolarGrids = new WeakMap(), _AngularRestriction_angleStep = new WeakMap(), _AngularRestriction_angleStepEditable = new WeakMap(), _AngularRestriction_angles = new WeakMap(), _AngularRestriction_labelNext = new WeakMap(), _AngularRestriction_labelPrevious = new WeakMap(), _AngularRestriction_priority = new WeakMap(), _AngularRestriction_settings = new WeakMap();
372
+ // #endregion Classes (1)
373
373
  //# sourceMappingURL=AngularRestriction.js.map