@shapediver/viewer.features.drawing-tools 3.3.4 → 3.3.7

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 (46) hide show
  1. package/dist/business/implementation/managers/geometry/GeometryState.d.ts.map +1 -1
  2. package/dist/business/implementation/managers/geometry/GeometryState.js +4 -1
  3. package/dist/business/implementation/managers/geometry/GeometryState.js.map +1 -1
  4. package/package.json +12 -13
  5. package/src/api/implementation/DrawingToolsApi.ts +0 -130
  6. package/src/api/implementation/restrictions/AbstractRestrictionApi.ts +0 -34
  7. package/src/api/implementation/restrictions/AbstractSnapRestrictionApi.ts +0 -36
  8. package/src/api/implementation/restrictions/geometry/GeometryRestrictionApi.ts +0 -56
  9. package/src/api/implementation/restrictions/plane/PlaneRestrictionApi.ts +0 -70
  10. package/src/api/implementation/restrictions/plane/snap/AngularRestrictionApi.ts +0 -35
  11. package/src/api/implementation/restrictions/plane/snap/AxisRestrictionApi.ts +0 -19
  12. package/src/api/implementation/restrictions/plane/snap/GridRestrictionApi.ts +0 -35
  13. package/src/api/interfaces/IDrawingToolsApi.ts +0 -98
  14. package/src/api/interfaces/IRestrictionApi.ts +0 -15
  15. package/src/api/interfaces/ISnapRestrictionApi.ts +0 -18
  16. package/src/business/implementation/DrawingToolsManager.ts +0 -618
  17. package/src/business/implementation/managers/HistoryManager.ts +0 -101
  18. package/src/business/implementation/managers/TextVisualizationManager.ts +0 -269
  19. package/src/business/implementation/managers/geometry/GeometryManager.ts +0 -95
  20. package/src/business/implementation/managers/geometry/GeometryMathManager.ts +0 -289
  21. package/src/business/implementation/managers/geometry/GeometryState.ts +0 -436
  22. package/src/business/implementation/managers/geometry/helpers/GeometryManagerHelper.ts +0 -170
  23. package/src/business/implementation/managers/interaction/EventManager.ts +0 -80
  24. package/src/business/implementation/managers/interaction/InteractionManager.ts +0 -268
  25. package/src/business/implementation/managers/interaction/RestrictionManager.ts +0 -132
  26. package/src/business/implementation/managers/interaction/handlers/DeletionInteractionHandler.ts +0 -48
  27. package/src/business/implementation/managers/interaction/handlers/InsertionInteractionHandler.ts +0 -149
  28. package/src/business/implementation/managers/interaction/handlers/MidPointInteractionHandler.ts +0 -127
  29. package/src/business/implementation/managers/interaction/helpers/InteractionManagerHelper.ts +0 -411
  30. package/src/business/implementation/managers/interaction/restrictions/AbstractRestriction.ts +0 -99
  31. package/src/business/implementation/managers/interaction/restrictions/geometry/GeometryRestriction.ts +0 -237
  32. package/src/business/implementation/managers/interaction/restrictions/plane/PlaneRestriction.ts +0 -337
  33. package/src/business/implementation/managers/interaction/restrictions/plane/snap/AngularRestriction.ts +0 -394
  34. package/src/business/implementation/managers/interaction/restrictions/plane/snap/AxisRestriction.ts +0 -116
  35. package/src/business/implementation/managers/interaction/restrictions/plane/snap/GridRestriction.ts +0 -246
  36. package/src/business/implementation/utils/numberCleaner.ts +0 -5
  37. package/src/business/interfaces/IDrawingToolsManager.ts +0 -312
  38. package/src/business/interfaces/IManager.ts +0 -7
  39. package/src/business/interfaces/IRestriction.ts +0 -63
  40. package/src/business/interfaces/IRestrictionBase.ts +0 -33
  41. package/src/business/interfaces/ISnapRestriction.ts +0 -70
  42. package/src/business/interfaces/events/EventResponseMapping.ts +0 -19
  43. package/src/business/interfaces/events/IDrawingToolsEvent.ts +0 -16
  44. package/src/index.ts +0 -72
  45. package/src/three/CSS2DRenderer.ts +0 -212
  46. package/tsconfig.json +0 -17
@@ -1,289 +0,0 @@
1
- import { DrawingToolsManager } from '../../DrawingToolsManager';
2
- import { IManager } from '../../../interfaces/IManager';
3
- import { IRay, IViewportApi } from '@shapediver/viewer.features.interaction';
4
- import { Settings } from '../../../interfaces/IDrawingToolsManager';
5
- import { vec3 } from 'gl-matrix';
6
-
7
- export class GeometryMathManager implements IManager {
8
- // #region Properties (3)
9
-
10
- readonly #drawingToolsManager: DrawingToolsManager;
11
- readonly #settings: Settings;
12
- readonly #viewport: IViewportApi;
13
-
14
- // #endregion Properties (3)
15
-
16
- // #region Constructors (1)
17
-
18
- constructor(drawingToolsManager: DrawingToolsManager) {
19
- this.#drawingToolsManager = drawingToolsManager;
20
- this.#viewport = drawingToolsManager.viewport;
21
- this.#settings = drawingToolsManager.settings;
22
- }
23
-
24
- // #endregion Constructors (1)
25
-
26
- // #region Public Methods (9)
27
-
28
- /**
29
- * Check which distances of lines to ray
30
- *
31
- * @param ray
32
- * @returns
33
- */
34
- public checkLineDistances(ray: IRay): { index: number[]; distance: number; }[] | undefined {
35
- const positionArray = this.#drawingToolsManager.positionArray;
36
- const indicesArrayLines = this.#drawingToolsManager.indicesArrayLines;
37
-
38
- // if there are no line array indices, return
39
- if (!indicesArrayLines) return;
40
-
41
- /**
42
- * Calculate line distances to ray
43
- */
44
- const distances: {
45
- index: number[];
46
- distance: number;
47
- }[] = [];
48
-
49
- for (let i = 0; i < indicesArrayLines.length; i += 2) {
50
- const firstIndex = indicesArrayLines.at(i)!;
51
- const secondIndex = indicesArrayLines.at(i + 1)!;
52
- const lineStart = vec3.fromValues(positionArray.at(firstIndex * 3)!, positionArray.at(firstIndex * 3 + 1)!, positionArray.at(firstIndex * 3 + 2)!);
53
- const lineEnd = vec3.fromValues(positionArray.at(secondIndex * 3)!, positionArray.at(secondIndex * 3 + 1)!, positionArray.at(secondIndex * 3 + 2)!);
54
-
55
- const { closestPointOnRay, closestPointOnLine } = this.closestPointsRayLine(ray, lineStart, lineEnd);
56
- if (this.screenSpaceDistanceCheck(closestPointOnRay, closestPointOnLine, this.#settings.visualization.points.size_0! * this.#settings.visualization.distanceMultiplicationFactor).check === false) continue;
57
-
58
- distances.push({ index: [firstIndex, secondIndex], distance: vec3.distance(closestPointOnRay, closestPointOnLine) });
59
- }
60
-
61
- // if there are no distances, return
62
- if (distances.length === 0) return;
63
-
64
- return distances.sort((a, b) => a.distance - b.distance);
65
- }
66
-
67
- /**
68
- * Check which distances of points to ray
69
- *
70
- * @param ray
71
- * @returns
72
- */
73
- public checkPointDistances(ray: IRay): {
74
- index: number;
75
- distance: number;
76
- }[] | undefined {
77
- const positionArray = this.#drawingToolsManager.positionArray;
78
-
79
- /**
80
- * Calculate point distances to ray
81
- */
82
- const distances: {
83
- index: number;
84
- distance: number;
85
- }[] = [];
86
- for (let i = 0; i < positionArray.length; i += 3) {
87
- const point = vec3.fromValues(positionArray.at(i)!, positionArray.at(i + 1)!, positionArray.at(i + 2)!);
88
-
89
- // distance from point to ray
90
- const closestPoint = this.closestPoint(ray, point);
91
- if (this.screenSpaceDistanceCheck(point, closestPoint, this.#settings.visualization.points.size_0! * this.#settings.visualization.distanceMultiplicationFactor).check === false) continue;
92
-
93
- distances.push({ index: i / 3, distance: vec3.distance(point, closestPoint) });
94
- }
95
-
96
- // if there are no distances, return
97
- if (distances.length === 0) return;
98
-
99
- // sort distances
100
- return distances.sort((a, b) => a.distance - b.distance);
101
- }
102
-
103
- public close(): void { }
104
-
105
- /**
106
- * Calculate the closest point on a ray to a point
107
- *
108
- * @param ray
109
- * @param point
110
- * @returns
111
- */
112
- public closestPoint(ray: IRay, point: vec3): vec3 {
113
- // distance from point to ray
114
- const dot = vec3.dot(ray.direction, vec3.sub(vec3.create(), point, ray.origin));
115
- // closest point on ray to point
116
- return vec3.add(vec3.create(), ray.origin, vec3.multiply(vec3.create(), ray.direction, vec3.fromValues(dot, dot, dot)));
117
- }
118
-
119
- /**
120
- * Calculate the closest point on a line to a point
121
- *
122
- * @param start
123
- * @param end
124
- * @param point
125
- */
126
- public closestPointOnLine(start: vec3, end: vec3, point: vec3): vec3 {
127
- const lineDir = vec3.sub(vec3.create(), end, start);
128
- // Vector from linePoint to point
129
- const v = vec3.sub(vec3.create(), point, start);
130
-
131
- // Line direction dot product with itself
132
- const dirDotDir = vec3.dot(lineDir, lineDir);
133
-
134
- // If the direction vector is a zero vector, return the line point as closest point
135
- if (dirDotDir === 0) return start;
136
-
137
- // Projection factor t
138
- const t = vec3.dot(v, lineDir) / dirDotDir;
139
-
140
- // Closest point on the line
141
- const closestPoint = vec3.add(vec3.create(), start, vec3.scale(vec3.create(), lineDir, t));
142
-
143
- return closestPoint;
144
- }
145
-
146
- /**
147
- * Calculate the closest point on a plane to a point
148
- *
149
- * @param point
150
- * @param planeNormal
151
- * @param planeOrigin
152
- * @returns
153
- */
154
- public closestPointOnPlane(planeOrigin: vec3, planeNormal: vec3, point: vec3): vec3 {
155
- // Calculate the vector from the plane origin to the point
156
- const toPoint = vec3.sub(vec3.create(), point, planeOrigin);
157
-
158
- // Project the vector onto the plane normal
159
- const projectionLength = vec3.dot(toPoint, planeNormal);
160
- const projectionVector = vec3.scale(vec3.create(), planeNormal, projectionLength);
161
-
162
- // Subtract the projection vector from the original point to get the projected point
163
- return vec3.sub(vec3.create(), point, projectionVector);
164
- }
165
-
166
- /**
167
- * Calculate the distance between a ray and a line segment
168
- *
169
- * @param ray
170
- * @param lineStart
171
- * @param lineEnd
172
- * @returns
173
- */
174
- public closestPointsRayLine(ray: IRay, lineStart: vec3, lineEnd: vec3): { closestPointOnRay: vec3, closestPointOnLine: vec3 } {
175
- // direction of line
176
- const lineDirection = vec3.normalize(vec3.create(), vec3.subtract(vec3.create(), lineEnd, lineStart));
177
-
178
- // cross product of ray direction and line direction
179
- const crossProduct = vec3.cross(vec3.create(), ray.direction, lineDirection);
180
-
181
- // length of cross product
182
- const crossProductLength = vec3.length(crossProduct);
183
-
184
- if (crossProductLength < 0.0001) {
185
- // ray and line are parallel, calculate the distance differently
186
- const closestPointOnRay = ray.origin;
187
- const closestPointOnLine = vec3.add(vec3.create(), lineStart, vec3.scale(vec3.create(), lineDirection, vec3.dot(vec3.subtract(vec3.create(), ray.origin, lineStart), lineDirection)));
188
- return {
189
- closestPointOnRay, closestPointOnLine
190
- };
191
- }
192
-
193
- const t = vec3.sub(vec3.create(), lineStart, ray.origin);
194
- const u = vec3.cross(vec3.create(), t, lineDirection);
195
- const v = vec3.cross(vec3.create(), t, ray.direction);
196
-
197
- const tValue = vec3.dot(u, crossProduct) / crossProductLength ** 2;
198
- const uValue = vec3.dot(v, crossProduct) / crossProductLength ** 2;
199
-
200
- const closestPointOnRay = vec3.add(vec3.create(), ray.origin, vec3.scale(vec3.create(), ray.direction, tValue));
201
-
202
- // restrict the closest point on line to the line segment
203
- let closestPointOnLine: vec3;
204
- if (uValue < 0) {
205
- closestPointOnLine = lineStart;
206
- } else if (uValue > vec3.distance(lineStart, lineEnd)) {
207
- closestPointOnLine = lineEnd;
208
- } else {
209
- closestPointOnLine = vec3.add(vec3.create(), lineStart, vec3.scale(vec3.create(), lineDirection, uValue));
210
- }
211
-
212
- return {
213
- closestPointOnRay, closestPointOnLine
214
- };
215
- }
216
-
217
- /**
218
- * Calculate the distance between two rays
219
- *
220
- * @param ray1
221
- * @param ray2
222
- * @returns
223
- */
224
- public closestPointsRayRay(ray1: IRay, ray2: IRay): { closestPointOnRay1: vec3, closestPointOnRay2: vec3 } {
225
- // cross product of ray1 direction and ray2 direction
226
- const crossProduct = vec3.cross(vec3.create(), ray1.direction, ray2.direction);
227
-
228
- // length of cross product
229
- const crossProductLength = vec3.length(crossProduct);
230
-
231
- if (crossProductLength < 0.0001) {
232
- // ray1 and ray2 are parallel, calculate the distance differently
233
- const closestPointOnRay1 = ray1.origin;
234
- const closestPointOnRay2 = vec3.add(vec3.create(), ray2.origin, vec3.scale(vec3.create(), ray2.direction, vec3.dot(vec3.subtract(vec3.create(), ray1.origin, ray2.origin), ray2.direction)));
235
- return {
236
- closestPointOnRay1, closestPointOnRay2
237
- };
238
- }
239
-
240
- const t = vec3.sub(vec3.create(), ray2.origin, ray1.origin);
241
- const u = vec3.cross(vec3.create(), t, ray2.direction);
242
- const v = vec3.cross(vec3.create(), t, ray1.direction);
243
-
244
- const tValue = vec3.dot(u, crossProduct) / crossProductLength ** 2;
245
- const uValue = vec3.dot(v, crossProduct) / crossProductLength ** 2;
246
-
247
- const closestPointOnRay1 = vec3.add(vec3.create(), ray1.origin, vec3.scale(vec3.create(), ray1.direction, tValue));
248
- const closestPointOnRay2 = vec3.add(vec3.create(), ray2.origin, vec3.scale(vec3.create(), ray2.direction, uValue));
249
-
250
- return {
251
- closestPointOnRay1, closestPointOnRay2
252
- };
253
- }
254
-
255
- public screenSpaceDistanceCheck(point1: vec3, point2: vec3, threshold: number) {
256
- const camera = this.#viewport.camera!;
257
-
258
- // Project points to NDC
259
- const screenPos1 = camera.project(vec3.clone(point1));
260
- const screenPos2 = camera.project(vec3.clone(point2));
261
-
262
- const width = this.#viewport.canvas.width;
263
- const height = this.#viewport.canvas.height;
264
-
265
- const x1 = ((screenPos1[0] * (width / 2)) + (width / 2));
266
- const y1 = - ((screenPos1[1] * (height / 2)) + (height / 2));
267
-
268
- const x2 = ((screenPos2[0] * (width / 2)) + (width / 2));
269
- const y2 = - ((screenPos2[1] * (height / 2)) + (height / 2));
270
-
271
- const distanceSquared = (x2 - x1) ** 2 + (y2 - y1) ** 2;
272
-
273
- /**
274
- * Logic: The actual calculation would be
275
- * distance * 2 < threshold
276
- * the multiplication by 2 is to account for the fact that the distance is from the center of the point
277
- *
278
- * However, we work with the squared distance to avoid the sqrt operation
279
- * Therefore we square all values:
280
- * distanceSquared * 4 < threshold ** 2
281
- */
282
- return {
283
- distanceSquared: distanceSquared,
284
- check: distanceSquared * 4 < threshold ** 2
285
- };
286
- }
287
-
288
- // #endregion Public Methods (9)
289
- }