@shapediver/viewer.features.drawing-tools 3.1.0
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.
- package/LICENSE +73 -0
- package/README.md +161 -0
- package/dist/api/implementation/DrawingToolsApi.d.ts +31 -0
- package/dist/api/implementation/DrawingToolsApi.d.ts.map +1 -0
- package/dist/api/implementation/DrawingToolsApi.js +111 -0
- package/dist/api/implementation/DrawingToolsApi.js.map +1 -0
- package/dist/api/implementation/restrictions/AbstractRestrictionApi.d.ts +10 -0
- package/dist/api/implementation/restrictions/AbstractRestrictionApi.d.ts.map +1 -0
- package/dist/api/implementation/restrictions/AbstractRestrictionApi.js +38 -0
- package/dist/api/implementation/restrictions/AbstractRestrictionApi.js.map +1 -0
- package/dist/api/implementation/restrictions/AbstractSnapRestrictionApi.d.ts +11 -0
- package/dist/api/implementation/restrictions/AbstractSnapRestrictionApi.d.ts.map +1 -0
- package/dist/api/implementation/restrictions/AbstractSnapRestrictionApi.js +40 -0
- package/dist/api/implementation/restrictions/AbstractSnapRestrictionApi.js.map +1 -0
- package/dist/api/implementation/restrictions/axis/AxisRestrictionApi.d.ts +7 -0
- package/dist/api/implementation/restrictions/axis/AxisRestrictionApi.d.ts.map +1 -0
- package/dist/api/implementation/restrictions/axis/AxisRestrictionApi.js +24 -0
- package/dist/api/implementation/restrictions/axis/AxisRestrictionApi.js.map +1 -0
- package/dist/api/implementation/restrictions/geometry/GeometryRestrictionApi.d.ts +15 -0
- package/dist/api/implementation/restrictions/geometry/GeometryRestrictionApi.d.ts.map +1 -0
- package/dist/api/implementation/restrictions/geometry/GeometryRestrictionApi.js +54 -0
- package/dist/api/implementation/restrictions/geometry/GeometryRestrictionApi.js.map +1 -0
- package/dist/api/implementation/restrictions/plane/PlaneRestrictionApi.d.ts +18 -0
- package/dist/api/implementation/restrictions/plane/PlaneRestrictionApi.d.ts.map +1 -0
- package/dist/api/implementation/restrictions/plane/PlaneRestrictionApi.js +61 -0
- package/dist/api/implementation/restrictions/plane/PlaneRestrictionApi.js.map +1 -0
- package/dist/api/implementation/restrictions/plane/snap/AngularRestrictionApi.d.ts +10 -0
- package/dist/api/implementation/restrictions/plane/snap/AngularRestrictionApi.d.ts.map +1 -0
- package/dist/api/implementation/restrictions/plane/snap/AngularRestrictionApi.js +40 -0
- package/dist/api/implementation/restrictions/plane/snap/AngularRestrictionApi.js.map +1 -0
- package/dist/api/implementation/restrictions/plane/snap/GridRestrictionApi.d.ts +10 -0
- package/dist/api/implementation/restrictions/plane/snap/GridRestrictionApi.d.ts.map +1 -0
- package/dist/api/implementation/restrictions/plane/snap/GridRestrictionApi.js +40 -0
- package/dist/api/implementation/restrictions/plane/snap/GridRestrictionApi.js.map +1 -0
- package/dist/api/interfaces/IDrawingToolsApi.d.ts +89 -0
- package/dist/api/interfaces/IDrawingToolsApi.d.ts.map +1 -0
- package/dist/api/interfaces/IDrawingToolsApi.js +3 -0
- package/dist/api/interfaces/IDrawingToolsApi.js.map +1 -0
- package/dist/api/interfaces/IRestrictionApi.d.ts +11 -0
- package/dist/api/interfaces/IRestrictionApi.d.ts.map +1 -0
- package/dist/api/interfaces/IRestrictionApi.js +3 -0
- package/dist/api/interfaces/IRestrictionApi.js.map +1 -0
- package/dist/api/interfaces/ISnapRestrictionApi.d.ts +13 -0
- package/dist/api/interfaces/ISnapRestrictionApi.d.ts.map +1 -0
- package/dist/api/interfaces/ISnapRestrictionApi.js +3 -0
- package/dist/api/interfaces/ISnapRestrictionApi.js.map +1 -0
- package/dist/business/implementation/DrawingToolsManager.d.ts +95 -0
- package/dist/business/implementation/DrawingToolsManager.d.ts.map +1 -0
- package/dist/business/implementation/DrawingToolsManager.js +544 -0
- package/dist/business/implementation/DrawingToolsManager.js.map +1 -0
- package/dist/business/implementation/managers/HistoryManager.d.ts +19 -0
- package/dist/business/implementation/managers/HistoryManager.d.ts.map +1 -0
- package/dist/business/implementation/managers/HistoryManager.js +89 -0
- package/dist/business/implementation/managers/HistoryManager.js.map +1 -0
- package/dist/business/implementation/managers/TextVisualizationManager.d.ts +14 -0
- package/dist/business/implementation/managers/TextVisualizationManager.d.ts.map +1 -0
- package/dist/business/implementation/managers/TextVisualizationManager.js +228 -0
- package/dist/business/implementation/managers/TextVisualizationManager.js.map +1 -0
- package/dist/business/implementation/managers/geometry/GeometryManager.d.ts +23 -0
- package/dist/business/implementation/managers/geometry/GeometryManager.d.ts.map +1 -0
- package/dist/business/implementation/managers/geometry/GeometryManager.js +82 -0
- package/dist/business/implementation/managers/geometry/GeometryManager.js.map +1 -0
- package/dist/business/implementation/managers/geometry/GeometryMathManager.d.ts +73 -0
- package/dist/business/implementation/managers/geometry/GeometryMathManager.d.ts.map +1 -0
- package/dist/business/implementation/managers/geometry/GeometryMathManager.js +230 -0
- package/dist/business/implementation/managers/geometry/GeometryMathManager.js.map +1 -0
- package/dist/business/implementation/managers/geometry/GeometryState.d.ts +46 -0
- package/dist/business/implementation/managers/geometry/GeometryState.d.ts.map +1 -0
- package/dist/business/implementation/managers/geometry/GeometryState.js +323 -0
- package/dist/business/implementation/managers/geometry/GeometryState.js.map +1 -0
- package/dist/business/implementation/managers/geometry/helpers/GeometryManagerHelper.d.ts +16 -0
- package/dist/business/implementation/managers/geometry/helpers/GeometryManagerHelper.d.ts.map +1 -0
- package/dist/business/implementation/managers/geometry/helpers/GeometryManagerHelper.js +157 -0
- package/dist/business/implementation/managers/geometry/helpers/GeometryManagerHelper.js.map +1 -0
- package/dist/business/implementation/managers/interaction/EventManager.d.ts +26 -0
- package/dist/business/implementation/managers/interaction/EventManager.d.ts.map +1 -0
- package/dist/business/implementation/managers/interaction/EventManager.js +63 -0
- package/dist/business/implementation/managers/interaction/EventManager.js.map +1 -0
- package/dist/business/implementation/managers/interaction/InteractionManager.d.ts +39 -0
- package/dist/business/implementation/managers/interaction/InteractionManager.d.ts.map +1 -0
- package/dist/business/implementation/managers/interaction/InteractionManager.js +237 -0
- package/dist/business/implementation/managers/interaction/InteractionManager.js.map +1 -0
- package/dist/business/implementation/managers/interaction/RestrictionManager.d.ts +19 -0
- package/dist/business/implementation/managers/interaction/RestrictionManager.d.ts.map +1 -0
- package/dist/business/implementation/managers/interaction/RestrictionManager.js +117 -0
- package/dist/business/implementation/managers/interaction/RestrictionManager.js.map +1 -0
- package/dist/business/implementation/managers/interaction/handlers/DeletionInteractionHandler.d.ts +10 -0
- package/dist/business/implementation/managers/interaction/handlers/DeletionInteractionHandler.d.ts.map +1 -0
- package/dist/business/implementation/managers/interaction/handlers/DeletionInteractionHandler.js +52 -0
- package/dist/business/implementation/managers/interaction/handlers/DeletionInteractionHandler.js.map +1 -0
- package/dist/business/implementation/managers/interaction/handlers/InsertionInteractionHandler.d.ts +14 -0
- package/dist/business/implementation/managers/interaction/handlers/InsertionInteractionHandler.d.ts.map +1 -0
- package/dist/business/implementation/managers/interaction/handlers/InsertionInteractionHandler.js +135 -0
- package/dist/business/implementation/managers/interaction/handlers/InsertionInteractionHandler.js.map +1 -0
- package/dist/business/implementation/managers/interaction/handlers/MidPointInteractionHandler.d.ts +16 -0
- package/dist/business/implementation/managers/interaction/handlers/MidPointInteractionHandler.d.ts.map +1 -0
- package/dist/business/implementation/managers/interaction/handlers/MidPointInteractionHandler.js +113 -0
- package/dist/business/implementation/managers/interaction/handlers/MidPointInteractionHandler.js.map +1 -0
- package/dist/business/implementation/managers/interaction/helpers/InteractionManagerHelper.d.ts +58 -0
- package/dist/business/implementation/managers/interaction/helpers/InteractionManagerHelper.d.ts.map +1 -0
- package/dist/business/implementation/managers/interaction/helpers/InteractionManagerHelper.js +377 -0
- package/dist/business/implementation/managers/interaction/helpers/InteractionManagerHelper.js.map +1 -0
- package/dist/business/implementation/managers/interaction/restrictions/AbstractRestriction.d.ts +19 -0
- package/dist/business/implementation/managers/interaction/restrictions/AbstractRestriction.d.ts.map +1 -0
- package/dist/business/implementation/managers/interaction/restrictions/AbstractRestriction.js +105 -0
- package/dist/business/implementation/managers/interaction/restrictions/AbstractRestriction.js.map +1 -0
- package/dist/business/implementation/managers/interaction/restrictions/axis/AxisRestriction.d.ts +22 -0
- package/dist/business/implementation/managers/interaction/restrictions/axis/AxisRestriction.d.ts.map +1 -0
- package/dist/business/implementation/managers/interaction/restrictions/axis/AxisRestriction.js +96 -0
- package/dist/business/implementation/managers/interaction/restrictions/axis/AxisRestriction.js.map +1 -0
- package/dist/business/implementation/managers/interaction/restrictions/geometry/GeometryRestriction.d.ts +39 -0
- package/dist/business/implementation/managers/interaction/restrictions/geometry/GeometryRestriction.d.ts.map +1 -0
- package/dist/business/implementation/managers/interaction/restrictions/geometry/GeometryRestriction.js +215 -0
- package/dist/business/implementation/managers/interaction/restrictions/geometry/GeometryRestriction.js.map +1 -0
- package/dist/business/implementation/managers/interaction/restrictions/plane/PlaneRestriction.d.ts +58 -0
- package/dist/business/implementation/managers/interaction/restrictions/plane/PlaneRestriction.d.ts.map +1 -0
- package/dist/business/implementation/managers/interaction/restrictions/plane/PlaneRestriction.js +180 -0
- package/dist/business/implementation/managers/interaction/restrictions/plane/PlaneRestriction.js.map +1 -0
- package/dist/business/implementation/managers/interaction/restrictions/plane/snap/AngularRestriction.d.ts +38 -0
- package/dist/business/implementation/managers/interaction/restrictions/plane/snap/AngularRestriction.d.ts.map +1 -0
- package/dist/business/implementation/managers/interaction/restrictions/plane/snap/AngularRestriction.js +308 -0
- package/dist/business/implementation/managers/interaction/restrictions/plane/snap/AngularRestriction.js.map +1 -0
- package/dist/business/implementation/managers/interaction/restrictions/plane/snap/GridRestriction.d.ts +37 -0
- package/dist/business/implementation/managers/interaction/restrictions/plane/snap/GridRestriction.d.ts.map +1 -0
- package/dist/business/implementation/managers/interaction/restrictions/plane/snap/GridRestriction.js +228 -0
- package/dist/business/implementation/managers/interaction/restrictions/plane/snap/GridRestriction.js.map +1 -0
- package/dist/business/implementation/utils/numberCleaner.d.ts +2 -0
- package/dist/business/implementation/utils/numberCleaner.d.ts.map +1 -0
- package/dist/business/implementation/utils/numberCleaner.js +9 -0
- package/dist/business/implementation/utils/numberCleaner.js.map +1 -0
- package/dist/business/interfaces/IDrawingToolsManager.d.ts +270 -0
- package/dist/business/interfaces/IDrawingToolsManager.d.ts.map +1 -0
- package/dist/business/interfaces/IDrawingToolsManager.js +16 -0
- package/dist/business/interfaces/IDrawingToolsManager.js.map +1 -0
- package/dist/business/interfaces/IManager.d.ts +4 -0
- package/dist/business/interfaces/IManager.d.ts.map +1 -0
- package/dist/business/interfaces/IManager.js +3 -0
- package/dist/business/interfaces/IManager.js.map +1 -0
- package/dist/business/interfaces/IRestriction.d.ts +41 -0
- package/dist/business/interfaces/IRestriction.d.ts.map +1 -0
- package/dist/business/interfaces/IRestriction.js +13 -0
- package/dist/business/interfaces/IRestriction.js.map +1 -0
- package/dist/business/interfaces/IRestrictionBase.d.ts +19 -0
- package/dist/business/interfaces/IRestrictionBase.d.ts.map +1 -0
- package/dist/business/interfaces/IRestrictionBase.js +5 -0
- package/dist/business/interfaces/IRestrictionBase.js.map +1 -0
- package/dist/business/interfaces/ISnapRestriction.d.ts +50 -0
- package/dist/business/interfaces/ISnapRestriction.d.ts.map +1 -0
- package/dist/business/interfaces/ISnapRestriction.js +4 -0
- package/dist/business/interfaces/ISnapRestriction.js.map +1 -0
- package/dist/business/interfaces/events/EventResponseMapping.d.ts +19 -0
- package/dist/business/interfaces/events/EventResponseMapping.d.ts.map +1 -0
- package/dist/business/interfaces/events/EventResponseMapping.js +4 -0
- package/dist/business/interfaces/events/EventResponseMapping.js.map +1 -0
- package/dist/business/interfaces/events/IDrawingToolsEvent.d.ts +12 -0
- package/dist/business/interfaces/events/IDrawingToolsEvent.d.ts.map +1 -0
- package/dist/business/interfaces/events/IDrawingToolsEvent.js +3 -0
- package/dist/business/interfaces/events/IDrawingToolsEvent.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/three/CSS2DRenderer.d.ts +32 -0
- package/dist/three/CSS2DRenderer.d.ts.map +1 -0
- package/dist/three/CSS2DRenderer.js +137 -0
- package/dist/three/CSS2DRenderer.js.map +1 -0
- package/package.json +55 -0
- package/src/api/implementation/DrawingToolsApi.ts +135 -0
- package/src/api/implementation/restrictions/AbstractRestrictionApi.ts +34 -0
- package/src/api/implementation/restrictions/AbstractSnapRestrictionApi.ts +36 -0
- package/src/api/implementation/restrictions/axis/AxisRestrictionApi.ts +19 -0
- package/src/api/implementation/restrictions/geometry/GeometryRestrictionApi.ts +56 -0
- package/src/api/implementation/restrictions/plane/PlaneRestrictionApi.ts +63 -0
- package/src/api/implementation/restrictions/plane/snap/AngularRestrictionApi.ts +35 -0
- package/src/api/implementation/restrictions/plane/snap/GridRestrictionApi.ts +35 -0
- package/src/api/interfaces/IDrawingToolsApi.ts +99 -0
- package/src/api/interfaces/IRestrictionApi.ts +15 -0
- package/src/api/interfaces/ISnapRestrictionApi.ts +18 -0
- package/src/business/implementation/DrawingToolsManager.ts +619 -0
- package/src/business/implementation/managers/HistoryManager.ts +101 -0
- package/src/business/implementation/managers/TextVisualizationManager.ts +245 -0
- package/src/business/implementation/managers/geometry/GeometryManager.ts +95 -0
- package/src/business/implementation/managers/geometry/GeometryMathManager.ts +273 -0
- package/src/business/implementation/managers/geometry/GeometryState.ts +436 -0
- package/src/business/implementation/managers/geometry/helpers/GeometryManagerHelper.ts +170 -0
- package/src/business/implementation/managers/interaction/EventManager.ts +80 -0
- package/src/business/implementation/managers/interaction/InteractionManager.ts +268 -0
- package/src/business/implementation/managers/interaction/RestrictionManager.ts +135 -0
- package/src/business/implementation/managers/interaction/handlers/DeletionInteractionHandler.ts +48 -0
- package/src/business/implementation/managers/interaction/handlers/InsertionInteractionHandler.ts +149 -0
- package/src/business/implementation/managers/interaction/handlers/MidPointInteractionHandler.ts +127 -0
- package/src/business/implementation/managers/interaction/helpers/InteractionManagerHelper.ts +411 -0
- package/src/business/implementation/managers/interaction/restrictions/AbstractRestriction.ts +99 -0
- package/src/business/implementation/managers/interaction/restrictions/axis/AxisRestriction.ts +107 -0
- package/src/business/implementation/managers/interaction/restrictions/geometry/GeometryRestriction.ts +237 -0
- package/src/business/implementation/managers/interaction/restrictions/plane/PlaneRestriction.ts +257 -0
- package/src/business/implementation/managers/interaction/restrictions/plane/snap/AngularRestriction.ts +384 -0
- package/src/business/implementation/managers/interaction/restrictions/plane/snap/GridRestriction.ts +262 -0
- package/src/business/implementation/utils/numberCleaner.ts +5 -0
- package/src/business/interfaces/IDrawingToolsManager.ts +313 -0
- package/src/business/interfaces/IManager.ts +7 -0
- package/src/business/interfaces/IRestriction.ts +64 -0
- package/src/business/interfaces/IRestrictionBase.ts +33 -0
- package/src/business/interfaces/ISnapRestriction.ts +70 -0
- package/src/business/interfaces/events/EventResponseMapping.ts +19 -0
- package/src/business/interfaces/events/IDrawingToolsEvent.ts +16 -0
- package/src/index.ts +72 -0
- package/src/three/CSS2DRenderer.ts +212 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { AbstractRestriction } from '../AbstractRestriction';
|
|
2
|
+
import { DrawingToolsManager } from '../../../../DrawingToolsManager';
|
|
3
|
+
import { GeometryMathManager } from '../../../geometry/GeometryMathManager';
|
|
4
|
+
import { IRay } from '@shapediver/viewer.features.interaction';
|
|
5
|
+
import { IRestriction, RestrictionMetaData, RestrictionProperties } from '../../../../../interfaces/IRestriction';
|
|
6
|
+
import { ISnapRestriction } from '../../../../../interfaces/ISnapRestriction';
|
|
7
|
+
import { vec3 } from 'gl-matrix';
|
|
8
|
+
|
|
9
|
+
// #region Type aliases (1)
|
|
10
|
+
|
|
11
|
+
export type AxisRestrictionProperties = {
|
|
12
|
+
activationKeyX?: string;
|
|
13
|
+
activationKeyY?: string;
|
|
14
|
+
activationKeyZ?: string;
|
|
15
|
+
} & RestrictionProperties;
|
|
16
|
+
|
|
17
|
+
// #endregion Type aliases (1)
|
|
18
|
+
|
|
19
|
+
// #region Classes (1)
|
|
20
|
+
|
|
21
|
+
export class AxisRestriction extends AbstractRestriction implements IRestriction {
|
|
22
|
+
// #region Properties (7)
|
|
23
|
+
|
|
24
|
+
readonly #activationKeyX: string;
|
|
25
|
+
readonly #activationKeyY: string;
|
|
26
|
+
readonly #activationKeyZ: string;
|
|
27
|
+
readonly #drawingToolsManager: DrawingToolsManager;
|
|
28
|
+
|
|
29
|
+
#geometryMathManager: GeometryMathManager;
|
|
30
|
+
#snapRestrictions: { [key: string]: ISnapRestriction; } = {};
|
|
31
|
+
|
|
32
|
+
// #endregion Properties (7)
|
|
33
|
+
|
|
34
|
+
// #region Constructors (1)
|
|
35
|
+
|
|
36
|
+
constructor(drawingToolsManager: DrawingToolsManager, id: string, properties: AxisRestrictionProperties) {
|
|
37
|
+
super(drawingToolsManager, id);
|
|
38
|
+
this.#drawingToolsManager = drawingToolsManager;
|
|
39
|
+
this.#geometryMathManager = drawingToolsManager.geometryMathManager;
|
|
40
|
+
|
|
41
|
+
this.#activationKeyX = properties.activationKeyX || 'x';
|
|
42
|
+
this.#activationKeyY = properties.activationKeyY || 'y';
|
|
43
|
+
this.#activationKeyZ = properties.activationKeyZ || 'z';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// #endregion Constructors (1)
|
|
47
|
+
|
|
48
|
+
// #region Public Getters And Setters (2)
|
|
49
|
+
|
|
50
|
+
public get priority(): number {
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public get snapRestrictions(): { [key: string]: ISnapRestriction; } {
|
|
55
|
+
return this.#snapRestrictions;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// #endregion Public Getters And Setters (2)
|
|
59
|
+
|
|
60
|
+
// #region Public Methods (1)
|
|
61
|
+
|
|
62
|
+
public rayTrace(ray: IRay, metaData?: RestrictionMetaData): vec3 | undefined {
|
|
63
|
+
if (this.enabled === false) return;
|
|
64
|
+
if (!metaData || !metaData.referencePoint) return;
|
|
65
|
+
|
|
66
|
+
const xPressed = this.#drawingToolsManager.keyPressed(this.#activationKeyX);
|
|
67
|
+
const yPressed = this.#drawingToolsManager.keyPressed(this.#activationKeyY);
|
|
68
|
+
const zPressed = this.#drawingToolsManager.keyPressed(this.#activationKeyZ);
|
|
69
|
+
const xyPressed = this.#drawingToolsManager.keyPressed(`${this.#activationKeyX}+${this.#activationKeyY}`);
|
|
70
|
+
const xzPressed = this.#drawingToolsManager.keyPressed(`${this.#activationKeyX}+${this.#activationKeyZ}`);
|
|
71
|
+
const yzPressed = this.#drawingToolsManager.keyPressed(`${this.#activationKeyY}+${this.#activationKeyZ}`);
|
|
72
|
+
const xyzPressed = this.#drawingToolsManager.keyPressed(`${this.#activationKeyX}+${this.#activationKeyY}+${this.#activationKeyZ}`);
|
|
73
|
+
|
|
74
|
+
if (xPressed) {
|
|
75
|
+
const { closestPointOnRay2 } = this.#geometryMathManager.closestPointsRayRay(ray, { origin: metaData.referencePoint, direction: vec3.fromValues(1, 0, 0) });
|
|
76
|
+
return closestPointOnRay2;
|
|
77
|
+
} else if (yPressed) {
|
|
78
|
+
const { closestPointOnRay2 } = this.#geometryMathManager.closestPointsRayRay(ray, { origin: metaData.referencePoint, direction: vec3.fromValues(0, 1, 0) });
|
|
79
|
+
return closestPointOnRay2;
|
|
80
|
+
} else if (zPressed) {
|
|
81
|
+
const { closestPointOnRay2 } = this.#geometryMathManager.closestPointsRayRay(ray, { origin: metaData.referencePoint, direction: vec3.fromValues(0, 0, 1) });
|
|
82
|
+
return closestPointOnRay2;
|
|
83
|
+
} else if (xyPressed) {
|
|
84
|
+
const { closestPointOnRay2 } = this.#geometryMathManager.closestPointsRayRay(ray, { origin: metaData.referencePoint, direction: vec3.fromValues(1, 1, 0) });
|
|
85
|
+
return closestPointOnRay2;
|
|
86
|
+
} else if (xzPressed) {
|
|
87
|
+
const { closestPointOnRay2 } = this.#geometryMathManager.closestPointsRayRay(ray, { origin: metaData.referencePoint, direction: vec3.fromValues(1, 0, 1) });
|
|
88
|
+
return closestPointOnRay2;
|
|
89
|
+
} else if (yzPressed) {
|
|
90
|
+
const { closestPointOnRay2 } = this.#geometryMathManager.closestPointsRayRay(ray, { origin: metaData.referencePoint, direction: vec3.fromValues(0, 1, 1) });
|
|
91
|
+
return closestPointOnRay2;
|
|
92
|
+
} else if (xyzPressed) {
|
|
93
|
+
const { closestPointOnRay2 } = this.#geometryMathManager.closestPointsRayRay(ray, { origin: metaData.referencePoint, direction: vec3.fromValues(1, 1, 1) });
|
|
94
|
+
return closestPointOnRay2;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// #endregion Public Methods (1)
|
|
99
|
+
|
|
100
|
+
// #region Protected Methods (1)
|
|
101
|
+
|
|
102
|
+
protected visibilityChanged(): void { }
|
|
103
|
+
|
|
104
|
+
// #endregion Protected Methods (1)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// #endregion Classes (1)
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { AbstractRestriction } from '../AbstractRestriction';
|
|
3
|
+
import { DrawingToolsManager } from '../../../../DrawingToolsManager';
|
|
4
|
+
import { GeometryMathManager } from '../../../geometry/GeometryMathManager';
|
|
5
|
+
import { IRay, IViewportApi } from '@shapediver/viewer.features.interaction';
|
|
6
|
+
import { IRestriction, RestrictionMetaData, RestrictionProperties } from '../../../../../interfaces/IRestriction';
|
|
7
|
+
import { ISnapRestriction } from '../../../../../interfaces/ISnapRestriction';
|
|
8
|
+
import { ITreeNode } from '@shapediver/viewer.shared.node-tree';
|
|
9
|
+
import { Settings } from '../../../../../interfaces/IDrawingToolsManager';
|
|
10
|
+
import { vec3 } from 'gl-matrix';
|
|
11
|
+
|
|
12
|
+
// #region Type aliases (1)
|
|
13
|
+
|
|
14
|
+
export type GeometryRestrictionProperties = {
|
|
15
|
+
/**
|
|
16
|
+
* The nodes to restrict the interaction to.
|
|
17
|
+
*/
|
|
18
|
+
nodes: ITreeNode[];
|
|
19
|
+
/**
|
|
20
|
+
* If the geometry should be displayed as wireframe.
|
|
21
|
+
*/
|
|
22
|
+
wireframe?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The color of the wireframe.
|
|
25
|
+
*/
|
|
26
|
+
wireframeColor?: string;
|
|
27
|
+
} & RestrictionProperties;
|
|
28
|
+
|
|
29
|
+
// #endregion Type aliases (1)
|
|
30
|
+
|
|
31
|
+
// #region Classes (1)
|
|
32
|
+
|
|
33
|
+
export class GeometryRestriction extends AbstractRestriction implements IRestriction {
|
|
34
|
+
// #region Properties (10)
|
|
35
|
+
|
|
36
|
+
readonly #raycaster = new THREE.Raycaster();
|
|
37
|
+
readonly #viewport: IViewportApi;
|
|
38
|
+
|
|
39
|
+
#geometryMathManager: GeometryMathManager;
|
|
40
|
+
#nodes: ITreeNode[] = [];
|
|
41
|
+
#settings: Settings;
|
|
42
|
+
#snapRestrictions: { [key: string]: ISnapRestriction; } = {};
|
|
43
|
+
#snapToEdges: boolean = true;
|
|
44
|
+
#snapToFaces: boolean = true;
|
|
45
|
+
#snapToVertices: boolean = true;
|
|
46
|
+
#visualizationObject: THREE.Object3D = new THREE.Object3D();
|
|
47
|
+
#wireframe: boolean;
|
|
48
|
+
#wireframeColor: string;
|
|
49
|
+
|
|
50
|
+
// #endregion Properties (10)
|
|
51
|
+
|
|
52
|
+
// #region Constructors (1)
|
|
53
|
+
|
|
54
|
+
constructor(drawingToolsManager: DrawingToolsManager, id: string, properties: GeometryRestrictionProperties) {
|
|
55
|
+
super(drawingToolsManager, id);
|
|
56
|
+
this.#viewport = drawingToolsManager.viewport;
|
|
57
|
+
this.#settings = drawingToolsManager.settings;
|
|
58
|
+
this.#geometryMathManager = drawingToolsManager.geometryMathManager;
|
|
59
|
+
this.#wireframe = properties.wireframe ?? true;
|
|
60
|
+
this.#wireframeColor = properties.wireframeColor ?? this.#settings.visualization.points.color_1 as string;
|
|
61
|
+
|
|
62
|
+
this.updateNodes(properties.nodes);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// #endregion Constructors (1)
|
|
66
|
+
|
|
67
|
+
// #region Public Getters And Setters (8)
|
|
68
|
+
|
|
69
|
+
public get priority(): number {
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public get snapRestrictions(): { [key: string]: ISnapRestriction; } {
|
|
74
|
+
return this.#snapRestrictions;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public get snapToEdges(): boolean {
|
|
78
|
+
return this.#snapToEdges;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public set snapToEdges(value: boolean) {
|
|
82
|
+
this.#snapToEdges = value;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public get snapToFaces(): boolean {
|
|
86
|
+
return this.#snapToFaces;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public set snapToFaces(value: boolean) {
|
|
90
|
+
this.#snapToFaces = value;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public get snapToVertices(): boolean {
|
|
94
|
+
return this.#snapToVertices;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public set snapToVertices(value: boolean) {
|
|
98
|
+
this.#snapToVertices = value;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// #endregion Public Getters And Setters (8)
|
|
102
|
+
|
|
103
|
+
// #region Public Methods (2)
|
|
104
|
+
|
|
105
|
+
public rayTrace(ray: IRay, metaData?: RestrictionMetaData): vec3 | undefined {
|
|
106
|
+
if (this.enabled === false) return;
|
|
107
|
+
if (this.#snapToVertices === false && this.#snapToEdges === false && this.#snapToFaces === false) return;
|
|
108
|
+
|
|
109
|
+
this.#raycaster.ray.direction.set(ray.direction[0], ray.direction[1], ray.direction[2]);
|
|
110
|
+
this.#raycaster.ray.origin.set(ray.origin[0], ray.origin[1], ray.origin[2]);
|
|
111
|
+
|
|
112
|
+
// intersect all nodes
|
|
113
|
+
let intersections: THREE.Intersection[] = [];
|
|
114
|
+
this.#nodes.forEach(node => {
|
|
115
|
+
const threeJsObject = node.convertedObject[this.#viewport.id] as THREE.Object3D;
|
|
116
|
+
if (threeJsObject) {
|
|
117
|
+
const currentIntersections = this.#raycaster.intersectObject(threeJsObject);
|
|
118
|
+
intersections = intersections.concat(currentIntersections);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// sort
|
|
123
|
+
intersections.sort((a, b) => a.distance - b.distance);
|
|
124
|
+
|
|
125
|
+
// return first intersection
|
|
126
|
+
if (intersections.length > 0) {
|
|
127
|
+
const object = intersections[0].object as THREE.Mesh;
|
|
128
|
+
const geometry = object.geometry;
|
|
129
|
+
const positionAttribute = geometry.getAttribute('position');
|
|
130
|
+
const intersectionPoint = intersections[0].point;
|
|
131
|
+
const intersectionPointVec3 = vec3.fromValues(intersectionPoint.x, intersectionPoint.y, intersectionPoint.z);
|
|
132
|
+
|
|
133
|
+
if (!intersections[0].face) return vec3.fromValues(intersectionPoint.x, intersectionPoint.y, intersectionPoint.z);
|
|
134
|
+
|
|
135
|
+
if (this.#snapToVertices === true || this.#snapToEdges === true) {
|
|
136
|
+
const vertexA = new THREE.Vector3();
|
|
137
|
+
vertexA.fromBufferAttribute(positionAttribute, intersections[0].face!.a);
|
|
138
|
+
object.localToWorld(vertexA);
|
|
139
|
+
const vertexAVec3 = vec3.fromValues(vertexA.x, vertexA.y, vertexA.z);
|
|
140
|
+
|
|
141
|
+
const vertexB = new THREE.Vector3();
|
|
142
|
+
vertexB.fromBufferAttribute(positionAttribute, intersections[0].face!.b);
|
|
143
|
+
object.localToWorld(vertexB);
|
|
144
|
+
const vertexBVec3 = vec3.fromValues(vertexB.x, vertexB.y, vertexB.z);
|
|
145
|
+
|
|
146
|
+
const vertexC = new THREE.Vector3();
|
|
147
|
+
vertexC.fromBufferAttribute(positionAttribute, intersections[0].face!.c);
|
|
148
|
+
object.localToWorld(vertexC);
|
|
149
|
+
const vertexCVec3 = vec3.fromValues(vertexC.x, vertexC.y, vertexC.z);
|
|
150
|
+
|
|
151
|
+
if (this.#snapToVertices === true) {
|
|
152
|
+
const distanceA = this.#geometryMathManager.screenSpaceDistanceCheck(intersectionPointVec3, vertexAVec3, this.#settings.visualization.points.size_0! * this.#settings.visualization.distanceMultiplicationFactor);
|
|
153
|
+
const distanceB = this.#geometryMathManager.screenSpaceDistanceCheck(intersectionPointVec3, vertexBVec3, this.#settings.visualization.points.size_0! * this.#settings.visualization.distanceMultiplicationFactor);
|
|
154
|
+
const distanceC = this.#geometryMathManager.screenSpaceDistanceCheck(intersectionPointVec3, vertexCVec3, this.#settings.visualization.points.size_0! * this.#settings.visualization.distanceMultiplicationFactor);
|
|
155
|
+
|
|
156
|
+
// part 1 - check if the intersection point is close to a vertex
|
|
157
|
+
if (distanceA.check && distanceA.distanceSquared < distanceB.distanceSquared && distanceA.distanceSquared < distanceC.distanceSquared) {
|
|
158
|
+
return vec3.fromValues(vertexA.x, vertexA.y, vertexA.z);
|
|
159
|
+
} else if (distanceB.check && distanceB.distanceSquared < distanceA.distanceSquared && distanceB.distanceSquared < distanceC.distanceSquared) {
|
|
160
|
+
return vec3.fromValues(vertexB.x, vertexB.y, vertexB.z);
|
|
161
|
+
} else if (distanceC.check && distanceC.distanceSquared < distanceA.distanceSquared && distanceC.distanceSquared < distanceB.distanceSquared) {
|
|
162
|
+
return vec3.fromValues(vertexC.x, vertexC.y, vertexC.z);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (this.#snapToEdges === true) {
|
|
167
|
+
// part 2 - check if the intersection point is close to an edge
|
|
168
|
+
|
|
169
|
+
// create the closest points on the edges
|
|
170
|
+
const closestPointOnEdgeAB = this.#geometryMathManager.closestPointOnLine(vertexAVec3, vertexBVec3, intersectionPointVec3);
|
|
171
|
+
const closestPointOnEdgeBC = this.#geometryMathManager.closestPointOnLine(vertexBVec3, vertexCVec3, intersectionPointVec3);
|
|
172
|
+
const closestPointOnEdgeCA = this.#geometryMathManager.closestPointOnLine(vertexCVec3, vertexAVec3, intersectionPointVec3);
|
|
173
|
+
|
|
174
|
+
// create the distances
|
|
175
|
+
const distanceAB = this.#geometryMathManager.screenSpaceDistanceCheck(intersectionPointVec3, closestPointOnEdgeAB, this.#settings.visualization.points.size_0! * this.#settings.visualization.distanceMultiplicationFactor);
|
|
176
|
+
const distanceBC = this.#geometryMathManager.screenSpaceDistanceCheck(intersectionPointVec3, closestPointOnEdgeBC, this.#settings.visualization.points.size_0! * this.#settings.visualization.distanceMultiplicationFactor);
|
|
177
|
+
const distanceCA = this.#geometryMathManager.screenSpaceDistanceCheck(intersectionPointVec3, closestPointOnEdgeCA, this.#settings.visualization.points.size_0! * this.#settings.visualization.distanceMultiplicationFactor);
|
|
178
|
+
|
|
179
|
+
// check if the intersection point is close to an edge
|
|
180
|
+
if (distanceAB.check && distanceAB.distanceSquared < distanceBC.distanceSquared && distanceAB.distanceSquared < distanceCA.distanceSquared) {
|
|
181
|
+
return closestPointOnEdgeAB;
|
|
182
|
+
} else if (distanceBC.check && distanceBC.distanceSquared < distanceAB.distanceSquared && distanceBC.distanceSquared < distanceCA.distanceSquared) {
|
|
183
|
+
return closestPointOnEdgeBC;
|
|
184
|
+
} else if (distanceCA.check && distanceCA.distanceSquared < distanceAB.distanceSquared && distanceCA.distanceSquared < distanceBC.distanceSquared) {
|
|
185
|
+
return closestPointOnEdgeCA;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (this.#snapToFaces === true) {
|
|
191
|
+
// part 3 - face intersection
|
|
192
|
+
return vec3.fromValues(intersectionPoint.x, intersectionPoint.y, intersectionPoint.z);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
public updateNodes(nodes: ITreeNode[]) {
|
|
200
|
+
this.#nodes = nodes;
|
|
201
|
+
|
|
202
|
+
if (this.#wireframe) {
|
|
203
|
+
this.#visualizationObject.traverse((object) => {
|
|
204
|
+
if (object instanceof THREE.LineSegments) {
|
|
205
|
+
object.geometry.dispose();
|
|
206
|
+
object.material.dispose();
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
this._object3D.remove(this.#visualizationObject);
|
|
210
|
+
|
|
211
|
+
this.#visualizationObject = new THREE.Object3D();
|
|
212
|
+
this.#nodes.forEach(node => {
|
|
213
|
+
const threeJsObject = node.convertedObject[this.#viewport.id] as THREE.Object3D;
|
|
214
|
+
if (threeJsObject) {
|
|
215
|
+
threeJsObject.traverse((object) => {
|
|
216
|
+
if (object instanceof THREE.Mesh) {
|
|
217
|
+
const wireframe = new THREE.WireframeGeometry(object.geometry);
|
|
218
|
+
const line = new THREE.LineSegments(wireframe, new THREE.LineBasicMaterial({ color: new THREE.Color(this.#wireframeColor) }));
|
|
219
|
+
this.#visualizationObject.add(line);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
this._object3D.add(this.#visualizationObject);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// #endregion Public Methods (2)
|
|
229
|
+
|
|
230
|
+
// #region Protected Methods (1)
|
|
231
|
+
|
|
232
|
+
protected visibilityChanged(): void { }
|
|
233
|
+
|
|
234
|
+
// #endregion Protected Methods (1)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// #endregion Classes (1)
|
package/src/business/implementation/managers/interaction/restrictions/plane/PlaneRestriction.ts
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { AbstractRestriction } from '../AbstractRestriction';
|
|
2
|
+
import { AngularRestriction, AngularRestrictionProperties } from './snap/AngularRestriction';
|
|
3
|
+
import { DrawingToolsManager } from '../../../../DrawingToolsManager';
|
|
4
|
+
import { GridRestriction, GridRestrictionProperties } from './snap/GridRestriction';
|
|
5
|
+
import { IRay } from '@shapediver/viewer.features.interaction';
|
|
6
|
+
import { IRestriction, RestrictionMetaData, RestrictionProperties } from '../../../../../interfaces/IRestriction';
|
|
7
|
+
import { ISnapRestriction } from '../../../../../interfaces/ISnapRestriction';
|
|
8
|
+
import { mat4, vec3 } from 'gl-matrix';
|
|
9
|
+
import { UuidGenerator } from '@shapediver/viewer.shared.services';
|
|
10
|
+
|
|
11
|
+
// #region Type aliases (1)
|
|
12
|
+
|
|
13
|
+
export type PlaneRestrictionProperties = {
|
|
14
|
+
/**
|
|
15
|
+
* The origin of the plane.
|
|
16
|
+
*
|
|
17
|
+
* @default vec3.fromValues(0, 0, 0)
|
|
18
|
+
*/
|
|
19
|
+
origin?: vec3
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Vector U of the plane
|
|
23
|
+
* with the cross product of vector_u and vector_v the normal of the plane can be calculated
|
|
24
|
+
*/
|
|
25
|
+
vector_u?: vec3;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Vector V of the plane
|
|
29
|
+
* with the cross product of vector_u and vector_v the normal of the plane can be calculated
|
|
30
|
+
*/
|
|
31
|
+
vector_v?: vec3;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* grid snap restriction
|
|
35
|
+
*/
|
|
36
|
+
gridSnapRestriction?: GridRestrictionProperties;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* angular snap restriction
|
|
40
|
+
*/
|
|
41
|
+
angularSnapRestriction?: AngularRestrictionProperties;
|
|
42
|
+
} & RestrictionProperties;
|
|
43
|
+
|
|
44
|
+
// #endregion Type aliases (1)
|
|
45
|
+
|
|
46
|
+
// #region Classes (1)
|
|
47
|
+
|
|
48
|
+
export class PlaneRestriction extends AbstractRestriction implements IRestriction {
|
|
49
|
+
// #region Properties (10)
|
|
50
|
+
|
|
51
|
+
readonly #uuidGenerator = UuidGenerator.instance;
|
|
52
|
+
|
|
53
|
+
#angularRestriction: AngularRestriction;
|
|
54
|
+
#gridRestriction: GridRestriction;
|
|
55
|
+
#normal: vec3;
|
|
56
|
+
#origin: vec3;
|
|
57
|
+
#snapRestrictions: { [key: string]: ISnapRestriction };
|
|
58
|
+
#transformationFromXYPlaneMatrix: mat4 = mat4.create();
|
|
59
|
+
#transformationToXYPlaneMatrix: mat4 = mat4.create();
|
|
60
|
+
#vectorU: vec3;
|
|
61
|
+
#vectorV: vec3;
|
|
62
|
+
|
|
63
|
+
// #endregion Properties (10)
|
|
64
|
+
|
|
65
|
+
// #region Constructors (1)
|
|
66
|
+
|
|
67
|
+
constructor(drawingToolsManager: DrawingToolsManager, id: string, properties: PlaneRestrictionProperties) {
|
|
68
|
+
super(drawingToolsManager, id);
|
|
69
|
+
properties.vector_u = properties.vector_u ? vec3.normalize(vec3.create(), properties.vector_u) : vec3.fromValues(1, 0, 0);
|
|
70
|
+
properties.vector_v = properties.vector_v ? vec3.normalize(vec3.create(), properties.vector_v) : vec3.fromValues(0, 1, 0);
|
|
71
|
+
|
|
72
|
+
this.#normal = vec3.normalize(vec3.create(), vec3.cross(vec3.create(), properties.vector_u, properties.vector_v));
|
|
73
|
+
if (vec3.dot(properties.vector_u, properties.vector_v) !== 0)
|
|
74
|
+
properties.vector_v = vec3.normalize(vec3.create(), vec3.cross(vec3.create(), this.#normal, properties.vector_u));
|
|
75
|
+
|
|
76
|
+
this.#vectorU = properties.vector_u;
|
|
77
|
+
this.#vectorV = properties.vector_v;
|
|
78
|
+
this.#origin = properties.origin || vec3.create();
|
|
79
|
+
|
|
80
|
+
this.createTransformationMatrices();
|
|
81
|
+
|
|
82
|
+
this.#gridRestriction = new GridRestriction(drawingToolsManager, this, properties.gridSnapRestriction);
|
|
83
|
+
this.#angularRestriction = new AngularRestriction(drawingToolsManager, this, properties.angularSnapRestriction);
|
|
84
|
+
|
|
85
|
+
this.#snapRestrictions = {
|
|
86
|
+
grid: this.#gridRestriction,
|
|
87
|
+
angular: this.#angularRestriction
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// #endregion Constructors (1)
|
|
92
|
+
|
|
93
|
+
// #region Public Getters And Setters (13)
|
|
94
|
+
|
|
95
|
+
public get angularRestriction(): AngularRestriction {
|
|
96
|
+
return this.#angularRestriction;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public get gridRestriction(): GridRestriction {
|
|
100
|
+
return this.#gridRestriction;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public get normal(): vec3 {
|
|
104
|
+
return this.#normal;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public get origin(): vec3 {
|
|
108
|
+
return this.#origin;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public set origin(value: vec3) {
|
|
112
|
+
this.#origin = value;
|
|
113
|
+
this.#gridRestriction.updatePlaneDefinition(this.#origin, this.#vectorU, this.#vectorV, this.#normal);
|
|
114
|
+
this.createTransformationMatrices();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public get priority(): number {
|
|
118
|
+
return -1;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public get snapRestrictions(): { [key: string]: ISnapRestriction; } {
|
|
122
|
+
return this.#snapRestrictions;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public get transformationFromXYPlaneMatrix(): mat4 {
|
|
126
|
+
return this.#transformationFromXYPlaneMatrix;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
public get transformationToXYPlaneMatrix(): mat4 {
|
|
130
|
+
return this.#transformationToXYPlaneMatrix;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public get vectorU(): vec3 {
|
|
134
|
+
return this.#vectorU;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public set vectorU(value: vec3) {
|
|
138
|
+
this.#vectorU = value;
|
|
139
|
+
this.#normal = vec3.normalize(vec3.create(), vec3.cross(vec3.create(), this.#vectorU, this.#vectorV));
|
|
140
|
+
|
|
141
|
+
if (vec3.dot(this.#vectorU, this.#vectorV) !== 0)
|
|
142
|
+
this.#vectorV = vec3.normalize(vec3.create(), vec3.cross(vec3.create(), this.#normal, this.#vectorU));
|
|
143
|
+
|
|
144
|
+
this.createTransformationMatrices();
|
|
145
|
+
this.#gridRestriction.updatePlaneDefinition(this.#origin, this.#vectorU, this.#vectorV, this.#normal);
|
|
146
|
+
this.#angularRestriction.updatePlaneDefinition(this.#origin, this.#vectorU, this.#vectorV, this.#normal);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public get vectorV(): vec3 {
|
|
150
|
+
return this.#vectorV;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public set vectorV(value: vec3) {
|
|
154
|
+
this.#vectorV = value;
|
|
155
|
+
this.#normal = vec3.normalize(vec3.create(), vec3.cross(vec3.create(), this.#vectorU, this.#vectorV));
|
|
156
|
+
|
|
157
|
+
if (vec3.dot(this.#vectorU, this.#vectorV) !== 0)
|
|
158
|
+
this.#vectorV = vec3.normalize(vec3.create(), vec3.cross(vec3.create(), this.#normal, this.#vectorU));
|
|
159
|
+
|
|
160
|
+
this.createTransformationMatrices();
|
|
161
|
+
this.#gridRestriction.updatePlaneDefinition(this.#origin, this.#vectorU, this.#vectorV, this.#normal);
|
|
162
|
+
this.#angularRestriction.updatePlaneDefinition(this.#origin, this.#vectorU, this.#vectorV, this.#normal);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// #endregion Public Getters And Setters (13)
|
|
166
|
+
|
|
167
|
+
// #region Public Methods (1)
|
|
168
|
+
|
|
169
|
+
public rayTrace(ray: IRay, metaData?: RestrictionMetaData): vec3 | undefined {
|
|
170
|
+
if (this.enabled === false) return vec3.create();
|
|
171
|
+
|
|
172
|
+
let origin = this.#origin;
|
|
173
|
+
if (metaData?.referencePoint)
|
|
174
|
+
origin = vec3.sub(vec3.create(), this.#origin, vec3.scale(vec3.create(), this.#normal, vec3.dot(vec3.sub(vec3.create(), this.#origin, metaData.referencePoint), this.#normal)));
|
|
175
|
+
|
|
176
|
+
// find intersection of ray and plane
|
|
177
|
+
const t = (vec3.dot(origin, this.#normal) - vec3.dot(ray.origin, this.#normal)) / vec3.dot(ray.direction, this.#normal);
|
|
178
|
+
const intersection = vec3.add(vec3.create(), ray.origin, vec3.multiply(vec3.create(), ray.direction, vec3.fromValues(t, t, t)));
|
|
179
|
+
return this.snap(intersection, metaData);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// #endregion Public Methods (1)
|
|
183
|
+
|
|
184
|
+
// #region Protected Methods (1)
|
|
185
|
+
|
|
186
|
+
protected visibilityChanged(): void { }
|
|
187
|
+
|
|
188
|
+
// #endregion Protected Methods (1)
|
|
189
|
+
|
|
190
|
+
// #region Private Methods (2)
|
|
191
|
+
|
|
192
|
+
private createTransformationMatrices(): void {
|
|
193
|
+
// Calculate the transformation matrix for the rotation
|
|
194
|
+
const rotationMatrix = mat4.fromValues(
|
|
195
|
+
this.#vectorU[0], this.#vectorV[0], this.#normal[0], 0,
|
|
196
|
+
this.#vectorU[1], this.#vectorV[1], this.#normal[1], 0,
|
|
197
|
+
this.#vectorU[2], this.#vectorV[2], this.#normal[2], 0,
|
|
198
|
+
0, 0, 0, 1
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
const rotationMatrixInverse = mat4.invert(mat4.create(), rotationMatrix);
|
|
202
|
+
const pivotMatrix = mat4.fromTranslation(mat4.create(), vec3.fromValues(this.#origin[0], this.#origin[1], this.#origin[2]));
|
|
203
|
+
const pivotMatrixInverse = mat4.fromTranslation(mat4.create(), vec3.fromValues(-this.#origin[0], -this.#origin[1], -this.#origin[2]));
|
|
204
|
+
|
|
205
|
+
mat4.multiply(this.#transformationToXYPlaneMatrix, pivotMatrix, rotationMatrix);
|
|
206
|
+
mat4.multiply(this.#transformationToXYPlaneMatrix, this.#transformationToXYPlaneMatrix, pivotMatrixInverse);
|
|
207
|
+
|
|
208
|
+
mat4.multiply(this.#transformationFromXYPlaneMatrix, pivotMatrix, rotationMatrixInverse);
|
|
209
|
+
mat4.multiply(this.#transformationFromXYPlaneMatrix, this.#transformationFromXYPlaneMatrix, pivotMatrixInverse);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private snap(point: vec3, metaData?: RestrictionMetaData): vec3 | undefined {
|
|
213
|
+
if (this.enabled === false) return;
|
|
214
|
+
|
|
215
|
+
const sortedSnapRestrictions = Object.values(this.#snapRestrictions).sort((a, b) => b.priority - a.priority);
|
|
216
|
+
|
|
217
|
+
// group snap restrictions by priority
|
|
218
|
+
const groupedSnapRestrictions: { [key: number]: ISnapRestriction[] } = {};
|
|
219
|
+
for (const snapRestriction of sortedSnapRestrictions) {
|
|
220
|
+
if (!groupedSnapRestrictions[snapRestriction.priority]) groupedSnapRestrictions[snapRestriction.priority] = [];
|
|
221
|
+
groupedSnapRestrictions[snapRestriction.priority].push(snapRestriction);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// call snap method for each group
|
|
225
|
+
for (const snapRestrictions of Object.values(groupedSnapRestrictions)) {
|
|
226
|
+
const results = [];
|
|
227
|
+
for (const snapRestriction of snapRestrictions) {
|
|
228
|
+
results.push(snapRestriction.snap(point, metaData));
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const indexedResults = results.map((value, index) => ({ index, value }));
|
|
232
|
+
|
|
233
|
+
// find the result that is closest to the point and set the snap restriction to active
|
|
234
|
+
indexedResults.sort((a, b) => {
|
|
235
|
+
if (!a.value) return 1;
|
|
236
|
+
if (!b.value) return -1;
|
|
237
|
+
return vec3.squaredDistance(point, a.value) - vec3.squaredDistance(point, b.value);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
for (const snapRestriction of snapRestrictions) {
|
|
241
|
+
snapRestriction.active = false;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// if a snap restriction returned a result, return it
|
|
245
|
+
if (indexedResults[0].value !== undefined) {
|
|
246
|
+
snapRestrictions[indexedResults[0].index].active = true;
|
|
247
|
+
return indexedResults[0].value;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return point;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// #endregion Private Methods (2)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// #endregion Classes (1)
|