@shapediver/viewer.rendering-engine.intersection-restriction-engine 3.16.8 → 3.16.9

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,309 +1,319 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
26
- if (kind === "m") throw new TypeError("Private method is not writable");
27
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
28
- 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");
29
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
30
- };
31
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
32
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
33
- 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");
34
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
35
- };
36
- var _GridRestriction_activationKey, _GridRestriction_eventEngine, _GridRestriction_planeRestriction, _GridRestriction_active, _GridRestriction_gridHelper, _GridRestriction_gridSize, _GridRestriction_gridUnit, _GridRestriction_gridUnitEditable, _GridRestriction_offsetFromUnit, _GridRestriction_toggleInversion, _GridRestriction_priority;
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.GridRestriction = void 0;
39
- const viewer_1 = require("@shapediver/viewer");
40
- const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
41
- const gl_matrix_1 = require("gl-matrix");
42
- const THREE = __importStar(require("three"));
43
- const AbstractSnapRestriction_1 = require("../../AbstractSnapRestriction");
44
- // #endregion Type aliases (1)
45
- // #region Classes (1)
46
- class GridRestriction extends AbstractSnapRestriction_1.AbstractSnapRestriction {
47
- // #endregion Properties (9)
48
- // #region Constructors (1)
49
- constructor(viewport, geometryMathManager, parentNode, planeRestriction, properties) {
50
- var _a, _b, _c, _d;
51
- super(viewport, parentNode, "grid", properties);
52
- // #region Properties (9)
53
- _GridRestriction_activationKey.set(this, void 0);
54
- _GridRestriction_eventEngine.set(this, viewer_shared_services_1.EventEngine.instance);
55
- _GridRestriction_planeRestriction.set(this, void 0);
56
- _GridRestriction_active.set(this, false);
57
- _GridRestriction_gridHelper.set(this, void 0);
58
- _GridRestriction_gridSize.set(this, 100);
59
- _GridRestriction_gridUnit.set(this, void 0);
60
- _GridRestriction_gridUnitEditable.set(this, true);
61
- _GridRestriction_offsetFromUnit.set(this, gl_matrix_1.vec3.create());
62
- _GridRestriction_toggleInversion.set(this, false);
63
- _GridRestriction_priority.set(this, 0);
64
- __classPrivateFieldSet(this, _GridRestriction_planeRestriction, planeRestriction, "f");
65
- __classPrivateFieldSet(this, _GridRestriction_activationKey, (properties === null || properties === void 0 ? void 0 : properties.activationKey) || "g", "f");
66
- this.enabled = (_a = properties === null || properties === void 0 ? void 0 : properties.enabled) !== null && _a !== void 0 ? _a : false;
67
- this._enabledEditable = (_b = properties === null || properties === void 0 ? void 0 : properties.enabledEditable) !== null && _b !== void 0 ? _b : true;
68
- this._enableVisualization = (_c = properties === null || properties === void 0 ? void 0 : properties.enableVisualization) !== null && _c !== void 0 ? _c : true;
69
- // if a grid unit is provided, we toggle it on by default
70
- if ((properties === null || properties === void 0 ? void 0 : properties.gridUnit) !== undefined && (properties === null || properties === void 0 ? void 0 : properties.gridUnit) !== 0) {
71
- __classPrivateFieldSet(this, _GridRestriction_toggleInversion, true, "f");
72
- __classPrivateFieldSet(this, _GridRestriction_gridUnit, properties.gridUnit, "f");
73
- }
74
- else {
75
- // we define our own grid unit
76
- __classPrivateFieldSet(this, _GridRestriction_gridUnit, 1, "f");
77
- /**
78
- * Depending on the scene radius, we calculate the grid unit.
79
- * The grid unit is calculated as follows:
80
- * - calculate 1% of the scene radius
81
- * - find the closest power of 10 that is smaller than the 1% of the scene radius
82
- * - find the closest power of 10 that is larger than the 1% of the scene radius
83
- * - the grid unit is whichever of the two is closer to the 1% of the scene radius
84
- *
85
- * @param sceneRadius
86
- * @returns
87
- */
88
- const calculateGridUnit = (sceneRadius) => {
89
- const percentage = 0.01;
90
- const percentageSceneRadius = sceneRadius * percentage;
91
- const log10 = Math.log10(percentageSceneRadius);
92
- const smaller = Math.pow(10, Math.floor(log10));
93
- const larger = Math.pow(10, Math.ceil(log10));
94
- const gridUnit = Math.abs(smaller - percentageSceneRadius) <
95
- Math.abs(larger - percentageSceneRadius)
96
- ? smaller
97
- : larger;
98
- return gridUnit;
99
- };
100
- if (viewer_1.sceneTree.root.boundingBox.isEmpty()) {
101
- // add an event listener to update the grid size
102
- const eventListenerToken = __classPrivateFieldGet(this, _GridRestriction_eventEngine, "f").addListener(viewer_shared_services_1.EVENTTYPE_SCENE.SCENE_BOUNDING_BOX_CHANGE, (e) => {
103
- const sceneEvent = e;
104
- if (sceneEvent.boundingBox) {
105
- const box = new viewer_1.Box(sceneEvent.boundingBox.min, sceneEvent.boundingBox.max);
106
- if (box.isEmpty())
107
- return;
108
- __classPrivateFieldSet(this, _GridRestriction_gridUnit, calculateGridUnit(box.boundingSphere.radius), "f");
109
- this.createOffsetFromUnit();
110
- this.createGridVisualization();
111
- __classPrivateFieldGet(this, _GridRestriction_eventEngine, "f").removeListener(eventListenerToken);
112
- }
113
- });
114
- }
115
- else {
116
- __classPrivateFieldSet(this, _GridRestriction_gridUnit, calculateGridUnit(viewer_1.sceneTree.root.boundingBox.boundingSphere.radius), "f");
117
- }
118
- }
119
- __classPrivateFieldSet(this, _GridRestriction_gridUnitEditable, (_d = properties === null || properties === void 0 ? void 0 : properties.gridUnitEditable) !== null && _d !== void 0 ? _d : true, "f");
120
- __classPrivateFieldSet(this, _GridRestriction_priority, (properties === null || properties === void 0 ? void 0 : properties.priority) || 0, "f");
121
- // create the offset of the grid size to origin
122
- this.createOffsetFromUnit();
123
- // calculate offset of grid size to origin
124
- this.createGridVisualization();
125
- }
126
- // #endregion Constructors (1)
127
- // #region Public Getters And Setters (8)
128
- get active() {
129
- return __classPrivateFieldGet(this, _GridRestriction_active, "f");
130
- }
131
- set active(value) {
132
- __classPrivateFieldSet(this, _GridRestriction_active, value, "f");
133
- if (__classPrivateFieldGet(this, _GridRestriction_gridHelper, "f"))
134
- __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").visible = value;
135
- }
136
- get enabledEditable() {
137
- return this._enabledEditable;
138
- }
139
- get gridUnit() {
140
- return __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f");
141
- }
142
- set gridUnit(value) {
143
- if (__classPrivateFieldGet(this, _GridRestriction_gridUnitEditable, "f") === false)
144
- return;
145
- __classPrivateFieldSet(this, _GridRestriction_gridUnit, value, "f");
146
- this.createOffsetFromUnit();
147
- this.createGridVisualization();
148
- }
149
- get gridUnitEditable() {
150
- return __classPrivateFieldGet(this, _GridRestriction_gridUnitEditable, "f");
151
- }
152
- get priority() {
153
- return __classPrivateFieldGet(this, _GridRestriction_priority, "f");
154
- }
155
- set priority(value) {
156
- __classPrivateFieldSet(this, _GridRestriction_priority, value, "f");
157
- }
158
- // #endregion Public Getters And Setters (8)
159
- // #region Public Methods (2)
160
- // public get
161
- snap(ray, point, distance, metaData) {
162
- var _a;
163
- // check if the activation key is pressed
164
- let isKeyToggled = ((_a = metaData === null || metaData === void 0 ? void 0 : metaData.toggledKeys) === null || _a === void 0 ? void 0 : _a.length) === 1 &&
165
- (metaData === null || metaData === void 0 ? void 0 : metaData.toggledKeys[0]) === __classPrivateFieldGet(this, _GridRestriction_activationKey, "f");
166
- // invert the result if toggleInversion is set
167
- if (__classPrivateFieldGet(this, _GridRestriction_toggleInversion, "f"))
168
- isKeyToggled = !isKeyToggled;
169
- // if the restriction is not enabled and the activation key is set and the key is not pressed, return
170
- if (this.enabled === false && !isKeyToggled)
171
- return;
172
- /**
173
- * Explanation of the following code:
174
- * 1. Calculate the projection of the origin onto the plane that is created by the point and the normal
175
- * 2. Move the grid helper to the projected origin
176
- */
177
- // vector from the point to the origin
178
- const v = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin, point);
179
- // dot product of the vector and the normal
180
- const dot = gl_matrix_1.vec3.dot(v, __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").normal);
181
- // projection of the origin onto the plane that is created by the point and the normal
182
- const projectedOrigin = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin, gl_matrix_1.vec3.scale(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").normal, dot));
183
- // we move the grid helper to the projected origin
184
- if (__classPrivateFieldGet(this, _GridRestriction_gridHelper, "f")) {
185
- __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").position.copy(new THREE.Vector3(projectedOrigin[0], projectedOrigin[1], projectedOrigin[2]));
186
- __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").visible = false;
187
- }
188
- /**
189
- * Explanation of the following code:
190
- * 1. Rotate the point so that the normal of the plane is aligned with the Z axis (with previously calculated transformation matrix)
191
- * 2. Snap the point to the grid
192
- * 3. Rotate the point back to the original coordinate system (with previously calculated transformation matrix)
193
- */
194
- // Apply the transformation to the point
195
- const rotatedPoint = gl_matrix_1.vec3.transformMat4(gl_matrix_1.vec3.create(), point, __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").transformationToXYPlaneMatrix);
196
- // Snap the offset to the grid
197
- const snappedOffset = gl_matrix_1.vec3.create();
198
- snappedOffset[0] =
199
- Math.round(rotatedPoint[0] / __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f")) * __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f") -
200
- __classPrivateFieldGet(this, _GridRestriction_offsetFromUnit, "f")[0];
201
- snappedOffset[1] =
202
- Math.round(rotatedPoint[1] / __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f")) * __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f") -
203
- __classPrivateFieldGet(this, _GridRestriction_offsetFromUnit, "f")[1];
204
- snappedOffset[2] = rotatedPoint[2];
205
- // Move the snapped point back to the original coordinate system
206
- const snappedPoint = gl_matrix_1.vec3.transformMat4(gl_matrix_1.vec3.create(), snappedOffset, __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").transformationFromXYPlaneMatrix);
207
- return {
208
- targetPoint: snappedPoint,
209
- closestIntersectionPoint: point,
210
- distanceOriginToClosestIntersectionPointSquared: distance,
211
- distanceClosestPointToTargetPointSquared: gl_matrix_1.vec3.sqrDist(snappedPoint, point),
212
- restriction: __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f"),
213
- snapRestriction: this,
214
- };
215
- }
216
- updatePlaneDefinition() {
217
- this.createOffsetFromUnit();
218
- this.createGridVisualization();
219
- }
220
- // #endregion Public Methods (2)
221
- // #region Protected Methods (1)
222
- visibilityChanged(visible) {
223
- if (visible === false) {
224
- if (__classPrivateFieldGet(this, _GridRestriction_gridHelper, "f")) {
225
- __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").visible = false;
226
- }
227
- }
228
- }
229
- // #endregion Protected Methods (1)
230
- // #region Private Methods (2)
231
- createGridVisualization() {
232
- if (!this._createHelperObjects)
233
- return;
234
- if (__classPrivateFieldGet(this, _GridRestriction_gridHelper, "f")) {
235
- this._object3D.remove(__classPrivateFieldGet(this, _GridRestriction_gridHelper, "f"));
236
- __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").dispose();
237
- }
238
- const bb = new viewer_1.Box();
239
- for (let i = 0; i < viewer_1.sceneTree.root.children.length; i++) {
240
- if (viewer_1.sceneTree.root.children[i].sessionNode === true) {
241
- bb.union(viewer_1.sceneTree.root.children[i].boundingBox);
242
- }
243
- }
244
- const radius = bb.boundingSphere.radius;
245
- __classPrivateFieldSet(this, _GridRestriction_gridSize, radius * 2, "f");
246
- if (__classPrivateFieldGet(this, _GridRestriction_gridSize, "f") === Infinity ||
247
- __classPrivateFieldGet(this, _GridRestriction_gridSize, "f") === -Infinity ||
248
- isNaN(__classPrivateFieldGet(this, _GridRestriction_gridSize, "f")) ||
249
- __classPrivateFieldGet(this, _GridRestriction_gridSize, "f") === 0)
250
- __classPrivateFieldSet(this, _GridRestriction_gridSize, 100, "f");
251
- // if the grid size is not divisible by the grid unit, we need to adjust the grid size
252
- let gridSize = __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f") * Math.ceil(__classPrivateFieldGet(this, _GridRestriction_gridSize, "f") / __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f"));
253
- // if the number of divisions is odd, we need to add one more division
254
- if ((gridSize / __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f")) % 2 === 1)
255
- gridSize += __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f");
256
- // todo adjust grid size so that is divisible by grid unit
257
- __classPrivateFieldSet(this, _GridRestriction_gridHelper, new THREE.GridHelper(gridSize, gridSize / __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f"), 0x666666, 0x222222), "f");
258
- const adjustedOrigin = gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin, __classPrivateFieldGet(this, _GridRestriction_offsetFromUnit, "f"));
259
- __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").position.copy(new THREE.Vector3(adjustedOrigin[0], adjustedOrigin[1], adjustedOrigin[2]));
260
- __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").visible = false;
261
- __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").renderOrder = 100;
262
- __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").material.depthTest =
263
- false;
264
- __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").material.transparent =
265
- true;
266
- // three.js uses a right-handed coordinate system, so we need to rotate the grid helper
267
- const rotationMatrix = new THREE.Matrix4().fromArray([
268
- __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").vectorU[0],
269
- __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").vectorU[1],
270
- __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").vectorU[2],
271
- 0,
272
- __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").vectorV[0],
273
- __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").vectorV[1],
274
- __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").vectorV[2],
275
- 0,
276
- __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").normal[0],
277
- __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").normal[1],
278
- __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").normal[2],
279
- 0,
280
- 0,
281
- 0,
282
- 0,
283
- 1,
284
- ]);
285
- __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").rotation.setFromRotationMatrix(rotationMatrix);
286
- // three.js grid helper is created in the XY plane, so we need to rotate it by 90 degrees around the X axis
287
- __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").rotateX(Math.PI / 2);
288
- this._object3D.add(__classPrivateFieldGet(this, _GridRestriction_gridHelper, "f"));
289
- }
290
- createOffsetFromUnit() {
291
- // Calculate the offset of the rotated point from the rotated origin
292
- __classPrivateFieldGet(this, _GridRestriction_offsetFromUnit, "f")[0] =
293
- __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f") *
294
- Math.round(__classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin[0] / __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f")) -
295
- __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin[0];
296
- __classPrivateFieldGet(this, _GridRestriction_offsetFromUnit, "f")[1] =
297
- __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f") *
298
- Math.round(__classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin[1] / __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f")) -
299
- __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin[1];
300
- __classPrivateFieldGet(this, _GridRestriction_offsetFromUnit, "f")[2] =
301
- __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f") *
302
- Math.round(__classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin[2] / __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f")) -
303
- __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin[2];
304
- }
305
- }
306
- exports.GridRestriction = GridRestriction;
307
- _GridRestriction_activationKey = new WeakMap(), _GridRestriction_eventEngine = new WeakMap(), _GridRestriction_planeRestriction = new WeakMap(), _GridRestriction_active = new WeakMap(), _GridRestriction_gridHelper = new WeakMap(), _GridRestriction_gridSize = new WeakMap(), _GridRestriction_gridUnit = new WeakMap(), _GridRestriction_gridUnitEditable = new WeakMap(), _GridRestriction_offsetFromUnit = new WeakMap(), _GridRestriction_toggleInversion = new WeakMap(), _GridRestriction_priority = new WeakMap();
308
- // #endregion Classes (1)
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
36
+ if (kind === "m") throw new TypeError("Private method is not writable");
37
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
38
+ 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");
39
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
40
+ };
41
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
42
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
43
+ 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");
44
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
45
+ };
46
+ var _GridRestriction_activationKey, _GridRestriction_eventEngine, _GridRestriction_planeRestriction, _GridRestriction_active, _GridRestriction_gridHelper, _GridRestriction_gridSize, _GridRestriction_gridUnit, _GridRestriction_gridUnitEditable, _GridRestriction_offsetFromUnit, _GridRestriction_toggleInversion, _GridRestriction_priority;
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.GridRestriction = void 0;
49
+ const viewer_1 = require("@shapediver/viewer");
50
+ const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
51
+ const gl_matrix_1 = require("gl-matrix");
52
+ const THREE = __importStar(require("three"));
53
+ const AbstractSnapRestriction_1 = require("../../AbstractSnapRestriction");
54
+ // #endregion Type aliases (1)
55
+ // #region Classes (1)
56
+ class GridRestriction extends AbstractSnapRestriction_1.AbstractSnapRestriction {
57
+ // #endregion Properties (9)
58
+ // #region Constructors (1)
59
+ constructor(viewport, geometryMathManager, parentNode, planeRestriction, properties) {
60
+ var _a, _b, _c, _d;
61
+ super(viewport, parentNode, "grid", properties);
62
+ // #region Properties (9)
63
+ _GridRestriction_activationKey.set(this, void 0);
64
+ _GridRestriction_eventEngine.set(this, viewer_shared_services_1.EventEngine.instance);
65
+ _GridRestriction_planeRestriction.set(this, void 0);
66
+ _GridRestriction_active.set(this, false);
67
+ _GridRestriction_gridHelper.set(this, void 0);
68
+ _GridRestriction_gridSize.set(this, 100);
69
+ _GridRestriction_gridUnit.set(this, void 0);
70
+ _GridRestriction_gridUnitEditable.set(this, true);
71
+ _GridRestriction_offsetFromUnit.set(this, gl_matrix_1.vec3.create());
72
+ _GridRestriction_toggleInversion.set(this, false);
73
+ _GridRestriction_priority.set(this, 0);
74
+ __classPrivateFieldSet(this, _GridRestriction_planeRestriction, planeRestriction, "f");
75
+ __classPrivateFieldSet(this, _GridRestriction_activationKey, (properties === null || properties === void 0 ? void 0 : properties.activationKey) || "g", "f");
76
+ this.enabled = (_a = properties === null || properties === void 0 ? void 0 : properties.enabled) !== null && _a !== void 0 ? _a : false;
77
+ this._enabledEditable = (_b = properties === null || properties === void 0 ? void 0 : properties.enabledEditable) !== null && _b !== void 0 ? _b : true;
78
+ this._enableVisualization = (_c = properties === null || properties === void 0 ? void 0 : properties.enableVisualization) !== null && _c !== void 0 ? _c : true;
79
+ // if a grid unit is provided, we toggle it on by default
80
+ if ((properties === null || properties === void 0 ? void 0 : properties.gridUnit) !== undefined && (properties === null || properties === void 0 ? void 0 : properties.gridUnit) !== 0) {
81
+ __classPrivateFieldSet(this, _GridRestriction_toggleInversion, true, "f");
82
+ __classPrivateFieldSet(this, _GridRestriction_gridUnit, properties.gridUnit, "f");
83
+ }
84
+ else {
85
+ // we define our own grid unit
86
+ __classPrivateFieldSet(this, _GridRestriction_gridUnit, 1, "f");
87
+ /**
88
+ * Depending on the scene radius, we calculate the grid unit.
89
+ * The grid unit is calculated as follows:
90
+ * - calculate 1% of the scene radius
91
+ * - find the closest power of 10 that is smaller than the 1% of the scene radius
92
+ * - find the closest power of 10 that is larger than the 1% of the scene radius
93
+ * - the grid unit is whichever of the two is closer to the 1% of the scene radius
94
+ *
95
+ * @param sceneRadius
96
+ * @returns
97
+ */
98
+ const calculateGridUnit = (sceneRadius) => {
99
+ const percentage = 0.01;
100
+ const percentageSceneRadius = sceneRadius * percentage;
101
+ const log10 = Math.log10(percentageSceneRadius);
102
+ const smaller = Math.pow(10, Math.floor(log10));
103
+ const larger = Math.pow(10, Math.ceil(log10));
104
+ const gridUnit = Math.abs(smaller - percentageSceneRadius) <
105
+ Math.abs(larger - percentageSceneRadius)
106
+ ? smaller
107
+ : larger;
108
+ return gridUnit;
109
+ };
110
+ if (viewer_1.sceneTree.root.boundingBox.isEmpty()) {
111
+ // add an event listener to update the grid size
112
+ const eventListenerToken = __classPrivateFieldGet(this, _GridRestriction_eventEngine, "f").addListener(viewer_shared_services_1.EVENTTYPE_SCENE.SCENE_BOUNDING_BOX_CHANGE, (e) => {
113
+ const sceneEvent = e;
114
+ if (sceneEvent.boundingBox) {
115
+ const box = new viewer_1.Box(sceneEvent.boundingBox.min, sceneEvent.boundingBox.max);
116
+ if (box.isEmpty())
117
+ return;
118
+ __classPrivateFieldSet(this, _GridRestriction_gridUnit, calculateGridUnit(box.boundingSphere.radius), "f");
119
+ this.createOffsetFromUnit();
120
+ this.createGridVisualization();
121
+ __classPrivateFieldGet(this, _GridRestriction_eventEngine, "f").removeListener(eventListenerToken);
122
+ }
123
+ });
124
+ }
125
+ else {
126
+ __classPrivateFieldSet(this, _GridRestriction_gridUnit, calculateGridUnit(viewer_1.sceneTree.root.boundingBox.boundingSphere.radius), "f");
127
+ }
128
+ }
129
+ __classPrivateFieldSet(this, _GridRestriction_gridUnitEditable, (_d = properties === null || properties === void 0 ? void 0 : properties.gridUnitEditable) !== null && _d !== void 0 ? _d : true, "f");
130
+ __classPrivateFieldSet(this, _GridRestriction_priority, (properties === null || properties === void 0 ? void 0 : properties.priority) || 0, "f");
131
+ // create the offset of the grid size to origin
132
+ this.createOffsetFromUnit();
133
+ // calculate offset of grid size to origin
134
+ this.createGridVisualization();
135
+ }
136
+ // #endregion Constructors (1)
137
+ // #region Public Getters And Setters (8)
138
+ get active() {
139
+ return __classPrivateFieldGet(this, _GridRestriction_active, "f");
140
+ }
141
+ set active(value) {
142
+ __classPrivateFieldSet(this, _GridRestriction_active, value, "f");
143
+ if (__classPrivateFieldGet(this, _GridRestriction_gridHelper, "f"))
144
+ __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").visible = value;
145
+ }
146
+ get enabledEditable() {
147
+ return this._enabledEditable;
148
+ }
149
+ get gridUnit() {
150
+ return __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f");
151
+ }
152
+ set gridUnit(value) {
153
+ if (__classPrivateFieldGet(this, _GridRestriction_gridUnitEditable, "f") === false)
154
+ return;
155
+ __classPrivateFieldSet(this, _GridRestriction_gridUnit, value, "f");
156
+ this.createOffsetFromUnit();
157
+ this.createGridVisualization();
158
+ }
159
+ get gridUnitEditable() {
160
+ return __classPrivateFieldGet(this, _GridRestriction_gridUnitEditable, "f");
161
+ }
162
+ get priority() {
163
+ return __classPrivateFieldGet(this, _GridRestriction_priority, "f");
164
+ }
165
+ set priority(value) {
166
+ __classPrivateFieldSet(this, _GridRestriction_priority, value, "f");
167
+ }
168
+ // #endregion Public Getters And Setters (8)
169
+ // #region Public Methods (2)
170
+ // public get
171
+ snap(ray, point, distance, metaData) {
172
+ var _a;
173
+ // check if the activation key is pressed
174
+ let isKeyToggled = ((_a = metaData === null || metaData === void 0 ? void 0 : metaData.toggledKeys) === null || _a === void 0 ? void 0 : _a.length) === 1 &&
175
+ (metaData === null || metaData === void 0 ? void 0 : metaData.toggledKeys[0]) === __classPrivateFieldGet(this, _GridRestriction_activationKey, "f");
176
+ // invert the result if toggleInversion is set
177
+ if (__classPrivateFieldGet(this, _GridRestriction_toggleInversion, "f"))
178
+ isKeyToggled = !isKeyToggled;
179
+ // if the restriction is not enabled and the activation key is set and the key is not pressed, return
180
+ if (this.enabled === false && !isKeyToggled)
181
+ return;
182
+ /**
183
+ * Explanation of the following code:
184
+ * 1. Calculate the projection of the origin onto the plane that is created by the point and the normal
185
+ * 2. Move the grid helper to the projected origin
186
+ */
187
+ // vector from the point to the origin
188
+ const v = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin, point);
189
+ // dot product of the vector and the normal
190
+ const dot = gl_matrix_1.vec3.dot(v, __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").normal);
191
+ // projection of the origin onto the plane that is created by the point and the normal
192
+ const projectedOrigin = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin, gl_matrix_1.vec3.scale(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").normal, dot));
193
+ // we move the grid helper to the projected origin
194
+ if (__classPrivateFieldGet(this, _GridRestriction_gridHelper, "f")) {
195
+ __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").position.copy(new THREE.Vector3(projectedOrigin[0], projectedOrigin[1], projectedOrigin[2]));
196
+ __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").visible = false;
197
+ }
198
+ /**
199
+ * Explanation of the following code:
200
+ * 1. Rotate the point so that the normal of the plane is aligned with the Z axis (with previously calculated transformation matrix)
201
+ * 2. Snap the point to the grid
202
+ * 3. Rotate the point back to the original coordinate system (with previously calculated transformation matrix)
203
+ */
204
+ // Apply the transformation to the point
205
+ const rotatedPoint = gl_matrix_1.vec3.transformMat4(gl_matrix_1.vec3.create(), point, __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").transformationToXYPlaneMatrix);
206
+ // Snap the offset to the grid
207
+ const snappedOffset = gl_matrix_1.vec3.create();
208
+ snappedOffset[0] =
209
+ Math.round(rotatedPoint[0] / __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f")) * __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f") -
210
+ __classPrivateFieldGet(this, _GridRestriction_offsetFromUnit, "f")[0];
211
+ snappedOffset[1] =
212
+ Math.round(rotatedPoint[1] / __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f")) * __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f") -
213
+ __classPrivateFieldGet(this, _GridRestriction_offsetFromUnit, "f")[1];
214
+ snappedOffset[2] = rotatedPoint[2];
215
+ // Move the snapped point back to the original coordinate system
216
+ const snappedPoint = gl_matrix_1.vec3.transformMat4(gl_matrix_1.vec3.create(), snappedOffset, __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").transformationFromXYPlaneMatrix);
217
+ return {
218
+ targetPoint: snappedPoint,
219
+ closestIntersectionPoint: point,
220
+ distanceOriginToClosestIntersectionPointSquared: distance,
221
+ distanceClosestPointToTargetPointSquared: gl_matrix_1.vec3.sqrDist(snappedPoint, point),
222
+ restriction: __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f"),
223
+ snapRestriction: this,
224
+ };
225
+ }
226
+ updatePlaneDefinition() {
227
+ this.createOffsetFromUnit();
228
+ this.createGridVisualization();
229
+ }
230
+ // #endregion Public Methods (2)
231
+ // #region Protected Methods (1)
232
+ visibilityChanged(visible) {
233
+ if (visible === false) {
234
+ if (__classPrivateFieldGet(this, _GridRestriction_gridHelper, "f")) {
235
+ __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").visible = false;
236
+ }
237
+ }
238
+ }
239
+ // #endregion Protected Methods (1)
240
+ // #region Private Methods (2)
241
+ createGridVisualization() {
242
+ if (!this._createHelperObjects)
243
+ return;
244
+ if (__classPrivateFieldGet(this, _GridRestriction_gridHelper, "f")) {
245
+ this._object3D.remove(__classPrivateFieldGet(this, _GridRestriction_gridHelper, "f"));
246
+ __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").dispose();
247
+ }
248
+ const bb = new viewer_1.Box();
249
+ for (let i = 0; i < viewer_1.sceneTree.root.children.length; i++) {
250
+ if (viewer_1.sceneTree.root.children[i].sessionNode === true) {
251
+ bb.union(viewer_1.sceneTree.root.children[i].boundingBox);
252
+ }
253
+ }
254
+ const radius = bb.boundingSphere.radius;
255
+ __classPrivateFieldSet(this, _GridRestriction_gridSize, radius * 2, "f");
256
+ if (__classPrivateFieldGet(this, _GridRestriction_gridSize, "f") === Infinity ||
257
+ __classPrivateFieldGet(this, _GridRestriction_gridSize, "f") === -Infinity ||
258
+ isNaN(__classPrivateFieldGet(this, _GridRestriction_gridSize, "f")) ||
259
+ __classPrivateFieldGet(this, _GridRestriction_gridSize, "f") === 0)
260
+ __classPrivateFieldSet(this, _GridRestriction_gridSize, 100, "f");
261
+ // if the grid size is not divisible by the grid unit, we need to adjust the grid size
262
+ let gridSize = __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f") * Math.ceil(__classPrivateFieldGet(this, _GridRestriction_gridSize, "f") / __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f"));
263
+ // if the number of divisions is odd, we need to add one more division
264
+ if ((gridSize / __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f")) % 2 === 1)
265
+ gridSize += __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f");
266
+ // todo adjust grid size so that is divisible by grid unit
267
+ __classPrivateFieldSet(this, _GridRestriction_gridHelper, new THREE.GridHelper(gridSize, gridSize / __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f"), 0x666666, 0x222222), "f");
268
+ const adjustedOrigin = gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin, __classPrivateFieldGet(this, _GridRestriction_offsetFromUnit, "f"));
269
+ __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").position.copy(new THREE.Vector3(adjustedOrigin[0], adjustedOrigin[1], adjustedOrigin[2]));
270
+ __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").visible = false;
271
+ __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").renderOrder = 100;
272
+ __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").material.depthTest =
273
+ false;
274
+ __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").material.transparent =
275
+ true;
276
+ // three.js uses a right-handed coordinate system, so we need to rotate the grid helper
277
+ const rotationMatrix = new THREE.Matrix4().fromArray([
278
+ __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").vectorU[0],
279
+ __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").vectorU[1],
280
+ __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").vectorU[2],
281
+ 0,
282
+ __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").vectorV[0],
283
+ __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").vectorV[1],
284
+ __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").vectorV[2],
285
+ 0,
286
+ __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").normal[0],
287
+ __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").normal[1],
288
+ __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").normal[2],
289
+ 0,
290
+ 0,
291
+ 0,
292
+ 0,
293
+ 1,
294
+ ]);
295
+ __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").rotation.setFromRotationMatrix(rotationMatrix);
296
+ // three.js grid helper is created in the XY plane, so we need to rotate it by 90 degrees around the X axis
297
+ __classPrivateFieldGet(this, _GridRestriction_gridHelper, "f").rotateX(Math.PI / 2);
298
+ this._object3D.add(__classPrivateFieldGet(this, _GridRestriction_gridHelper, "f"));
299
+ }
300
+ createOffsetFromUnit() {
301
+ // Calculate the offset of the rotated point from the rotated origin
302
+ __classPrivateFieldGet(this, _GridRestriction_offsetFromUnit, "f")[0] =
303
+ __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f") *
304
+ Math.round(__classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin[0] / __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f")) -
305
+ __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin[0];
306
+ __classPrivateFieldGet(this, _GridRestriction_offsetFromUnit, "f")[1] =
307
+ __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f") *
308
+ Math.round(__classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin[1] / __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f")) -
309
+ __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin[1];
310
+ __classPrivateFieldGet(this, _GridRestriction_offsetFromUnit, "f")[2] =
311
+ __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f") *
312
+ Math.round(__classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin[2] / __classPrivateFieldGet(this, _GridRestriction_gridUnit, "f")) -
313
+ __classPrivateFieldGet(this, _GridRestriction_planeRestriction, "f").origin[2];
314
+ }
315
+ }
316
+ exports.GridRestriction = GridRestriction;
317
+ _GridRestriction_activationKey = new WeakMap(), _GridRestriction_eventEngine = new WeakMap(), _GridRestriction_planeRestriction = new WeakMap(), _GridRestriction_active = new WeakMap(), _GridRestriction_gridHelper = new WeakMap(), _GridRestriction_gridSize = new WeakMap(), _GridRestriction_gridUnit = new WeakMap(), _GridRestriction_gridUnitEditable = new WeakMap(), _GridRestriction_offsetFromUnit = new WeakMap(), _GridRestriction_toggleInversion = new WeakMap(), _GridRestriction_priority = new WeakMap();
318
+ // #endregion Classes (1)
309
319
  //# sourceMappingURL=GridRestriction.js.map