@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,268 @@
|
|
|
1
|
+
import { addListener, FLAG_TYPE, IViewportApi } from '@shapediver/viewer';
|
|
2
|
+
import { DeletionInteractionHandler } from './handlers/DeletionInteractionHandler';
|
|
3
|
+
import { DrawingToolsEventResponseMapping } from '../../../interfaces/events/EventResponseMapping';
|
|
4
|
+
import { DrawingToolsManager } from '../../DrawingToolsManager';
|
|
5
|
+
import { EVENTTYPE_DRAWING_TOOLS, IEvent } from '@shapediver/viewer.shared.services';
|
|
6
|
+
import { GeometryMathManager } from '../geometry/GeometryMathManager';
|
|
7
|
+
import { IManager } from '../../../interfaces/IManager';
|
|
8
|
+
import { InsertionInteractionHandler } from './handlers/InsertionInteractionHandler';
|
|
9
|
+
import { InteractionManagerHelper } from './helpers/InteractionManagerHelper';
|
|
10
|
+
import { IRay } from '@shapediver/viewer.features.interaction';
|
|
11
|
+
import { MidPointInteractionHandler } from './handlers/MidPointInteractionHandler';
|
|
12
|
+
import { RestrictionManager } from './RestrictionManager';
|
|
13
|
+
|
|
14
|
+
export class InteractionManager implements IManager {
|
|
15
|
+
// #region Properties (11)
|
|
16
|
+
|
|
17
|
+
readonly #deletionInteractionHandler: DeletionInteractionHandler;
|
|
18
|
+
readonly #drawingToolsManager: DrawingToolsManager;
|
|
19
|
+
readonly #geometryMathManager: GeometryMathManager;
|
|
20
|
+
readonly #insertionInteractionHandler: InsertionInteractionHandler;
|
|
21
|
+
readonly #interactionManagerHelper: InteractionManagerHelper;
|
|
22
|
+
readonly #midPointInteractionHandler: MidPointInteractionHandler;
|
|
23
|
+
readonly #restrictionManager: RestrictionManager;
|
|
24
|
+
readonly #viewport: IViewportApi;
|
|
25
|
+
|
|
26
|
+
#cameraFreezeFlag: string = '';
|
|
27
|
+
#lastEvent?: PointerEvent;
|
|
28
|
+
#onDownPointer?: PointerEvent;
|
|
29
|
+
|
|
30
|
+
// #endregion Properties (11)
|
|
31
|
+
|
|
32
|
+
// #region Constructors (1)
|
|
33
|
+
|
|
34
|
+
constructor(drawingToolsManager: DrawingToolsManager) {
|
|
35
|
+
this.#drawingToolsManager = drawingToolsManager;
|
|
36
|
+
this.#viewport = drawingToolsManager.viewport;
|
|
37
|
+
this.#geometryMathManager = this.#drawingToolsManager.geometryMathManager;
|
|
38
|
+
|
|
39
|
+
this.#restrictionManager = new RestrictionManager(this.#drawingToolsManager);
|
|
40
|
+
|
|
41
|
+
this.#deletionInteractionHandler = new DeletionInteractionHandler(this.#drawingToolsManager, this);
|
|
42
|
+
this.#insertionInteractionHandler = new InsertionInteractionHandler(this.#drawingToolsManager, this);
|
|
43
|
+
this.#midPointInteractionHandler = new MidPointInteractionHandler(this.#drawingToolsManager, this);
|
|
44
|
+
|
|
45
|
+
this.#interactionManagerHelper = new InteractionManagerHelper(this.#drawingToolsManager, this);
|
|
46
|
+
|
|
47
|
+
addListener(EVENTTYPE_DRAWING_TOOLS.ADDED, (e: IEvent) => {
|
|
48
|
+
const event = e as DrawingToolsEventResponseMapping[EVENTTYPE_DRAWING_TOOLS.ADDED];
|
|
49
|
+
this.addPoint(event.index!);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
addListener(EVENTTYPE_DRAWING_TOOLS.REMOVED, (e: IEvent) => {
|
|
53
|
+
const event = e as DrawingToolsEventResponseMapping[EVENTTYPE_DRAWING_TOOLS.REMOVED];
|
|
54
|
+
this.removePoint(event.index!);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// #endregion Constructors (1)
|
|
59
|
+
|
|
60
|
+
// #region Public Getters And Setters (4)
|
|
61
|
+
|
|
62
|
+
public get deletionInteractionHandler(): DeletionInteractionHandler {
|
|
63
|
+
return this.#deletionInteractionHandler;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public get insertionInteractionHandler(): InsertionInteractionHandler {
|
|
67
|
+
return this.#insertionInteractionHandler;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public get midPointInteractionHandler(): MidPointInteractionHandler {
|
|
71
|
+
return this.#midPointInteractionHandler;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public get restrictionManager(): RestrictionManager {
|
|
75
|
+
return this.#restrictionManager;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// #endregion Public Getters And Setters (4)
|
|
79
|
+
|
|
80
|
+
// #region Public Methods (10)
|
|
81
|
+
|
|
82
|
+
public addPoint(insertionIndex: number): void {
|
|
83
|
+
this.#interactionManagerHelper.addPoint(insertionIndex);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public close(): void {
|
|
87
|
+
this.#interactionManagerHelper.close();
|
|
88
|
+
this.#restrictionManager.close();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public deleteSelection(): void {
|
|
92
|
+
this.#deletionInteractionHandler.deleteSelection(this.#interactionManagerHelper.selectedPointIndices);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public onDown(event: PointerEvent, ray: IRay): void {
|
|
96
|
+
if (this.#drawingToolsManager.closed) return;
|
|
97
|
+
|
|
98
|
+
if(event.button === 0) {
|
|
99
|
+
this.#onDownPointer = event;
|
|
100
|
+
this.#interactionManagerHelper.moving = false;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* IF INSERT KEY IS PRESSED
|
|
104
|
+
* FINALIZE INSERTION AND START A NEW ONE
|
|
105
|
+
*/
|
|
106
|
+
if (this.#insertionInteractionHandler.insertionActive === true) {
|
|
107
|
+
const result = this.#insertionInteractionHandler.finalizeInsertion();
|
|
108
|
+
const distances = this.#geometryMathManager.checkPointDistances(ray);
|
|
109
|
+
this.#interactionManagerHelper.checkHover(distances, ray);
|
|
110
|
+
if(result) {
|
|
111
|
+
this.#drawingToolsManager.update();
|
|
112
|
+
return;
|
|
113
|
+
} else {
|
|
114
|
+
this.#insertionInteractionHandler.startInsertion(event);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const distances = this.#geometryMathManager.checkPointDistances(ray);
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* IF MID POINT INSERTION IS ACTIVE
|
|
122
|
+
* FINISH MID POINT INSERTION IF THE CURRENT INDEX IS THE MID POINT INSERTION INDEX
|
|
123
|
+
*/
|
|
124
|
+
if (this.#midPointInteractionHandler.midPointInsertionActive === true) {
|
|
125
|
+
this.#midPointInteractionHandler.finishMidPointInsertion(distances);
|
|
126
|
+
this.#interactionManagerHelper.midPointInserted = true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* CHECK HOVERED POINT
|
|
131
|
+
*/
|
|
132
|
+
this.#interactionManagerHelper.checkHover(distances, ray);
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* IF THERE IS A POINT CLOSE TO THE RAY
|
|
136
|
+
*/
|
|
137
|
+
this.#interactionManagerHelper.selectPoint(distances);
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* IF THE CURRENTLY HOVERED POINT IS SELECTED
|
|
141
|
+
* START DRAGGING
|
|
142
|
+
*/
|
|
143
|
+
const draggingStarted = this.#interactionManagerHelper.startDragging(ray);
|
|
144
|
+
if (draggingStarted && !this.#cameraFreezeFlag)
|
|
145
|
+
this.#cameraFreezeFlag = this.#viewport.addFlag(FLAG_TYPE.CAMERA_FREEZE);
|
|
146
|
+
} else if(event.button === 2) {
|
|
147
|
+
/**
|
|
148
|
+
* WHEN RIGHT MOUSE BUTTON IS PRESSED
|
|
149
|
+
*/
|
|
150
|
+
this.onOut();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* On mouse move, move the selected point if there is one
|
|
156
|
+
*
|
|
157
|
+
* @param event
|
|
158
|
+
* @param ray
|
|
159
|
+
*/
|
|
160
|
+
public onMove(event: PointerEvent, ray: IRay): void {
|
|
161
|
+
if (this.#drawingToolsManager.closed) return;
|
|
162
|
+
|
|
163
|
+
// if there are no points, start with the insertion right away
|
|
164
|
+
if (this.#drawingToolsManager.settings.general.autoStart && this.#insertionInteractionHandler.insertionActive === false && this.#drawingToolsManager.getPointsData().length === 0) {
|
|
165
|
+
this.#lastEvent = event;
|
|
166
|
+
this.startInsertion();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const distanceSquared = this.#onDownPointer ? Math.pow(event.clientX - this.#onDownPointer.clientX, 2) + Math.pow(event.clientY - this.#onDownPointer.clientY, 2) : Infinity;
|
|
170
|
+
const clickThresholdSquared = 25;
|
|
171
|
+
const pointerMoved = distanceSquared > clickThresholdSquared;
|
|
172
|
+
|
|
173
|
+
this.#interactionManagerHelper.moving = pointerMoved;
|
|
174
|
+
|
|
175
|
+
if (pointerMoved) {
|
|
176
|
+
this.#lastEvent = event;
|
|
177
|
+
/**
|
|
178
|
+
* IF WE ARE DRAGGING A POINT
|
|
179
|
+
* MOVE THE SELECTED POINTS
|
|
180
|
+
*/
|
|
181
|
+
this.#interactionManagerHelper.moveSelectedPoints(ray);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const distances = this.#geometryMathManager.checkPointDistances(ray);
|
|
185
|
+
this.#interactionManagerHelper.checkHover(distances, ray);
|
|
186
|
+
|
|
187
|
+
if (pointerMoved) {
|
|
188
|
+
/**
|
|
189
|
+
* IF INSERT KEY IS PRESSED
|
|
190
|
+
* ADD POINT AT RAY INTERSECTION IF THERE IS NONE WAS ADDED
|
|
191
|
+
* MOVE LAST ADDED POINT IF THERE IS ONE
|
|
192
|
+
*/
|
|
193
|
+
this.#insertionInteractionHandler.onMove(ray);
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* IF INSERT KEY IS NOT PRESSED AND DRAGGING IS NOT ACTIVE
|
|
197
|
+
* CHECK IF THERE IS A LINE CLOSE TO THE RAY AND ADD A MID POINT TO IT
|
|
198
|
+
*/
|
|
199
|
+
if (this.#insertionInteractionHandler.insertionActive === false && this.#interactionManagerHelper.dragging === false && this.#interactionManagerHelper.selectedPointIndices.length === 0) {
|
|
200
|
+
this.#midPointInteractionHandler.onMove(ray, this.#interactionManagerHelper.hoveredPoint);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (this.#interactionManagerHelper.dragging) {
|
|
205
|
+
document.body.style.cursor = 'grabbing';
|
|
206
|
+
} else if(this.#interactionManagerHelper.hoveredPoint !== undefined) {
|
|
207
|
+
document.body.style.cursor = 'pointer';
|
|
208
|
+
} else {
|
|
209
|
+
document.body.style.cursor = 'default';
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* On mouse out, deselect the hovered point and remove the stop dragging
|
|
215
|
+
*/
|
|
216
|
+
public onOut(): void {
|
|
217
|
+
this.#restrictionManager.showRestrictionVisualization = false;
|
|
218
|
+
this.#insertionInteractionHandler.stopInsertion();
|
|
219
|
+
this.#interactionManagerHelper.onOut();
|
|
220
|
+
this.reset();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* On mouse up, check if a point is close to the ray and deselect it
|
|
225
|
+
*/
|
|
226
|
+
public onUp(): void {
|
|
227
|
+
if (this.#drawingToolsManager.closed) return;
|
|
228
|
+
this.#interactionManagerHelper.onUp();
|
|
229
|
+
this.reset();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
public removePoint(index: number): void {
|
|
233
|
+
this.#interactionManagerHelper.removePoint(index);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public startInsertion(): void {
|
|
237
|
+
this.#restrictionManager.showRestrictionVisualization = true;
|
|
238
|
+
|
|
239
|
+
this.#midPointInteractionHandler.stopMidPointInsertion();
|
|
240
|
+
|
|
241
|
+
if (!this.#cameraFreezeFlag)
|
|
242
|
+
this.#cameraFreezeFlag = this.#viewport.addFlag(FLAG_TYPE.CAMERA_FREEZE);
|
|
243
|
+
|
|
244
|
+
this.#insertionInteractionHandler.startInsertion(this.#lastEvent!);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
public stopInsertion(): void {
|
|
248
|
+
this.#restrictionManager.showRestrictionVisualization = false;
|
|
249
|
+
this.#insertionInteractionHandler.stopInsertion();
|
|
250
|
+
this.#viewport.removeFlag(this.#cameraFreezeFlag);
|
|
251
|
+
this.#cameraFreezeFlag = '';
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// #endregion Public Methods (10)
|
|
255
|
+
|
|
256
|
+
// #region Private Methods (1)
|
|
257
|
+
|
|
258
|
+
private reset(): void {
|
|
259
|
+
if (this.#insertionInteractionHandler.insertionActive === false) {
|
|
260
|
+
this.#restrictionManager.showRestrictionVisualization = false;
|
|
261
|
+
this.#viewport.removeFlag(this.#cameraFreezeFlag);
|
|
262
|
+
this.#cameraFreezeFlag = '';
|
|
263
|
+
}
|
|
264
|
+
this.#interactionManagerHelper.reset();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// #endregion Private Methods (1)
|
|
268
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { AxisRestriction, AxisRestrictionProperties } from './restrictions/axis/AxisRestriction';
|
|
2
|
+
import { DrawingToolsManager } from '../../DrawingToolsManager';
|
|
3
|
+
import { GeometryRestriction, GeometryRestrictionProperties } from './restrictions/geometry/GeometryRestriction';
|
|
4
|
+
import { IManager } from '../../../interfaces/IManager';
|
|
5
|
+
import { IRay } from '@shapediver/viewer.features.interaction';
|
|
6
|
+
import {
|
|
7
|
+
IRestriction,
|
|
8
|
+
RESTRICTION_TYPE,
|
|
9
|
+
RestrictionMetaData,
|
|
10
|
+
RestrictionProperties
|
|
11
|
+
} from '../../../interfaces/IRestriction';
|
|
12
|
+
import { PlaneRestriction, PlaneRestrictionProperties } from './restrictions/plane/PlaneRestriction';
|
|
13
|
+
import { Settings } from '../../../interfaces/IDrawingToolsManager';
|
|
14
|
+
import { UuidGenerator } from '@shapediver/viewer.shared.services';
|
|
15
|
+
import { vec3 } from 'gl-matrix';
|
|
16
|
+
|
|
17
|
+
export class RestrictionManager implements IManager {
|
|
18
|
+
// #region Properties (5)
|
|
19
|
+
|
|
20
|
+
readonly #drawingToolsManager: DrawingToolsManager;
|
|
21
|
+
readonly #restrictions: { [token: string]: IRestriction } = {};
|
|
22
|
+
readonly #settings: Settings;
|
|
23
|
+
readonly #uuidGenerator = UuidGenerator.instance;
|
|
24
|
+
|
|
25
|
+
#showRestrictionVisualization: boolean = false;
|
|
26
|
+
|
|
27
|
+
// #endregion Properties (5)
|
|
28
|
+
|
|
29
|
+
// #region Constructors (1)
|
|
30
|
+
|
|
31
|
+
constructor(drawingToolsManager: DrawingToolsManager) {
|
|
32
|
+
this.#drawingToolsManager = drawingToolsManager;
|
|
33
|
+
this.#settings = drawingToolsManager.settings;
|
|
34
|
+
|
|
35
|
+
for (const restrictionToken in this.#settings.restrictions) {
|
|
36
|
+
this.addRestriction(this.#settings.restrictions[restrictionToken], restrictionToken);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// #endregion Constructors (1)
|
|
41
|
+
|
|
42
|
+
// #region Public Getters And Setters (3)
|
|
43
|
+
|
|
44
|
+
public get restrictions(): { [token: string]: IRestriction } {
|
|
45
|
+
return this.#restrictions;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public get showRestrictionVisualization(): boolean {
|
|
49
|
+
return this.#showRestrictionVisualization;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public set showRestrictionVisualization(value: boolean) {
|
|
53
|
+
this.#showRestrictionVisualization = value;
|
|
54
|
+
for (const restriction of Object.values(this.#restrictions)) {
|
|
55
|
+
restriction.showVisualization = value;
|
|
56
|
+
for (const snapRestriction of Object.values(restriction.snapRestrictions)) {
|
|
57
|
+
snapRestriction.showVisualization = value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// #endregion Public Getters And Setters (3)
|
|
63
|
+
|
|
64
|
+
// #region Public Methods (4)
|
|
65
|
+
|
|
66
|
+
public addRestriction(properties: RestrictionProperties, token?: string): string | undefined {
|
|
67
|
+
token = token || this.#uuidGenerator.create();
|
|
68
|
+
|
|
69
|
+
let restriction: IRestriction | undefined;
|
|
70
|
+
if (properties.type === RESTRICTION_TYPE.PLANE) {
|
|
71
|
+
restriction = new PlaneRestriction(this.#drawingToolsManager, token, properties as PlaneRestrictionProperties);
|
|
72
|
+
} else if (properties.type === RESTRICTION_TYPE.GEOMETRY) {
|
|
73
|
+
restriction = new GeometryRestriction(this.#drawingToolsManager, token, properties as GeometryRestrictionProperties);
|
|
74
|
+
} else if (properties.type === RESTRICTION_TYPE.AXIS) {
|
|
75
|
+
restriction = new AxisRestriction(this.#drawingToolsManager, token, properties as AxisRestrictionProperties);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (restriction) {
|
|
79
|
+
this.#restrictions[token] = restriction;
|
|
80
|
+
return token;
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public close(): void {
|
|
86
|
+
Object.keys(this.#restrictions).forEach(key => this.removeRestriction(key));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public rayTrace(ray: IRay, metaData?: RestrictionMetaData): vec3 | undefined {
|
|
90
|
+
let rayTracingResult: {
|
|
91
|
+
result: vec3 | undefined;
|
|
92
|
+
distance: number;
|
|
93
|
+
restriction: IRestriction;
|
|
94
|
+
} | undefined = undefined;
|
|
95
|
+
|
|
96
|
+
// create an array of arrays with the restrictions sorted by priority
|
|
97
|
+
const restrictionsSorted = Object.values(this.#restrictions).sort((a, b) => (b.priority || 0) - (a.priority || 0));
|
|
98
|
+
|
|
99
|
+
for (const restriction of restrictionsSorted) {
|
|
100
|
+
if (rayTracingResult && rayTracingResult.restriction.priority > restriction.priority) break;
|
|
101
|
+
|
|
102
|
+
const hit = restriction.rayTrace(ray, metaData);
|
|
103
|
+
|
|
104
|
+
if (!hit) continue;
|
|
105
|
+
const distance = vec3.squaredDistance(ray.origin, hit);
|
|
106
|
+
if (distance < (rayTracingResult ? rayTracingResult.distance : Infinity)) {
|
|
107
|
+
rayTracingResult = {
|
|
108
|
+
result: hit,
|
|
109
|
+
distance: distance,
|
|
110
|
+
restriction: restriction
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// deactivate the visualization of all restrictions that are not hit
|
|
116
|
+
for (const restriction of Object.values(this.#restrictions)) {
|
|
117
|
+
if (rayTracingResult && restriction !== rayTracingResult.restriction) {
|
|
118
|
+
for (const snapRestriction of Object.values(restriction.snapRestrictions)) {
|
|
119
|
+
snapRestriction.active = false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return rayTracingResult?.result;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public removeRestriction(token: string): void {
|
|
127
|
+
if (this.#restrictions[token]) {
|
|
128
|
+
Object.values(this.#restrictions[token].snapRestrictions).forEach(r => r.removeVisualization());
|
|
129
|
+
this.#restrictions[token].removeVisualization();
|
|
130
|
+
delete this.#restrictions[token];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// #endregion Public Methods (4)
|
|
135
|
+
}
|
package/src/business/implementation/managers/interaction/handlers/DeletionInteractionHandler.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { DrawingToolsManager } from '../../../DrawingToolsManager';
|
|
2
|
+
import { EventEngine, EVENTTYPE_DRAWING_TOOLS } from '@shapediver/viewer.shared.services';
|
|
3
|
+
import { GeometryMathManager } from '../../geometry/GeometryMathManager';
|
|
4
|
+
import { InteractionManager } from '../InteractionManager';
|
|
5
|
+
import { IRay, IViewportApi } from '@shapediver/viewer.features.interaction';
|
|
6
|
+
|
|
7
|
+
export class DeletionInteractionHandler {
|
|
8
|
+
// #region Properties (4)
|
|
9
|
+
|
|
10
|
+
readonly #drawingToolsManager: DrawingToolsManager;
|
|
11
|
+
readonly #eventEngine = EventEngine.instance;
|
|
12
|
+
readonly #geometryMathManager: GeometryMathManager;
|
|
13
|
+
readonly #viewport: IViewportApi;
|
|
14
|
+
|
|
15
|
+
// #endregion Properties (4)
|
|
16
|
+
|
|
17
|
+
// #region Constructors (1)
|
|
18
|
+
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
20
|
+
constructor(drawingToolsManager: DrawingToolsManager, interactionManager: InteractionManager) {
|
|
21
|
+
this.#drawingToolsManager = drawingToolsManager;
|
|
22
|
+
this.#viewport = drawingToolsManager.viewport;
|
|
23
|
+
this.#geometryMathManager = drawingToolsManager.geometryMathManager;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// #endregion Constructors (1)
|
|
27
|
+
|
|
28
|
+
// #region Public Methods (2)
|
|
29
|
+
|
|
30
|
+
public deletePoint(ray: IRay): void {
|
|
31
|
+
// check if there is a point close to the ray
|
|
32
|
+
const distances = this.#geometryMathManager.checkPointDistances(ray);
|
|
33
|
+
if (distances) {
|
|
34
|
+
// add the id if it is not already in the array
|
|
35
|
+
// remove it if it is in the array
|
|
36
|
+
this.#drawingToolsManager.removePoint(distances[0].index);
|
|
37
|
+
this.#eventEngine.emitEvent(EVENTTYPE_DRAWING_TOOLS.REMOVED, { viewportId: this.#viewport.id, drawingToolsId: this.#drawingToolsManager.uuid });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public deleteSelection(indices: number[]): void {
|
|
42
|
+
if(indices.length === 0) return;
|
|
43
|
+
this.#drawingToolsManager.removePoints(indices);
|
|
44
|
+
this.#eventEngine.emitEvent(EVENTTYPE_DRAWING_TOOLS.REMOVED, { viewportId: this.#viewport.id, drawingToolsId: this.#drawingToolsManager.uuid });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// #endregion Public Methods (2)
|
|
48
|
+
}
|
package/src/business/implementation/managers/interaction/handlers/InsertionInteractionHandler.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { DrawingToolsManager } from '../../../DrawingToolsManager';
|
|
2
|
+
import { GeometryMathManager } from '../../geometry/GeometryMathManager';
|
|
3
|
+
import { GeometryState } from '../../geometry/GeometryState';
|
|
4
|
+
import { InteractionManager } from '../InteractionManager';
|
|
5
|
+
import { IRay, IViewportApi } from '@shapediver/viewer.features.interaction';
|
|
6
|
+
import { MATERIAL_INDEX, Settings } from '../../../../interfaces/IDrawingToolsManager';
|
|
7
|
+
import { RestrictionManager } from '../RestrictionManager';
|
|
8
|
+
|
|
9
|
+
export class InsertionInteractionHandler {
|
|
10
|
+
// #region Properties (11)
|
|
11
|
+
|
|
12
|
+
readonly #drawingToolsManager: DrawingToolsManager;
|
|
13
|
+
readonly #geometryMathManager: GeometryMathManager;
|
|
14
|
+
readonly #geometryState: GeometryState;
|
|
15
|
+
readonly #restrictionManager: RestrictionManager;
|
|
16
|
+
readonly #settings: Settings;
|
|
17
|
+
readonly #viewport: IViewportApi;
|
|
18
|
+
|
|
19
|
+
#alreadyInserted: boolean = false;
|
|
20
|
+
#insertionActive: boolean = false;
|
|
21
|
+
#insertionActiveIndex: number = -1;
|
|
22
|
+
|
|
23
|
+
// #endregion Properties (11)
|
|
24
|
+
|
|
25
|
+
// #region Constructors (1)
|
|
26
|
+
|
|
27
|
+
constructor(drawingToolsManager: DrawingToolsManager, interactionManager: InteractionManager) {
|
|
28
|
+
this.#drawingToolsManager = drawingToolsManager;
|
|
29
|
+
|
|
30
|
+
this.#settings = drawingToolsManager.settings;
|
|
31
|
+
this.#viewport = drawingToolsManager.viewport;
|
|
32
|
+
this.#geometryMathManager = drawingToolsManager.geometryMathManager;
|
|
33
|
+
this.#restrictionManager = interactionManager.restrictionManager;
|
|
34
|
+
this.#geometryState = drawingToolsManager.geometryState;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// #endregion Constructors (1)
|
|
38
|
+
|
|
39
|
+
// #region Public Getters And Setters (2)
|
|
40
|
+
|
|
41
|
+
public get alreadyInserted(): boolean {
|
|
42
|
+
return this.#alreadyInserted;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public get insertionActive(): boolean {
|
|
46
|
+
return this.#insertionActive;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// #endregion Public Getters And Setters (2)
|
|
50
|
+
|
|
51
|
+
// #region Public Methods (4)
|
|
52
|
+
|
|
53
|
+
public finalizeInsertion(): boolean {
|
|
54
|
+
let result = false;
|
|
55
|
+
|
|
56
|
+
if (this.#insertionActive === true && this.#alreadyInserted === true) {
|
|
57
|
+
this.#geometryState.makePointPersistent(this.#insertionActiveIndex);
|
|
58
|
+
|
|
59
|
+
const canBeClosed = this.#geometryState.getPointCount() > 3 && this.#geometryState.checkNumberOfPoints(this.#geometryState.getPointCount() - 1);
|
|
60
|
+
const shouldBeClosed = this.#settings.geometry.close === true && this.#geometryState.closeLoop === false && this.#settings.geometry.autoClose === false;
|
|
61
|
+
|
|
62
|
+
// if there are more than 2 points and the geometry can be closed, check if the last point is close to the first point
|
|
63
|
+
if (canBeClosed && shouldBeClosed) {
|
|
64
|
+
// if restricted point is close to the first point, remove the current insertion point and draw a line to the first point
|
|
65
|
+
const firstPoint = this.#geometryState.getPosition(0);
|
|
66
|
+
const lastPoint = this.#geometryState.getPosition(this.#insertionActiveIndex);
|
|
67
|
+
|
|
68
|
+
if (this.#geometryMathManager.screenSpaceDistanceCheck(firstPoint, lastPoint, this.#settings.visualization.points.size_0! * this.#settings.visualization.distanceMultiplicationFactor).check === true) {
|
|
69
|
+
this.#geometryState.closeLoop = true;
|
|
70
|
+
this.#drawingToolsManager.removePoint(this.#insertionActiveIndex);
|
|
71
|
+
result = true;
|
|
72
|
+
} else {
|
|
73
|
+
this.#drawingToolsManager.updateMaterialIndex(this.#insertionActiveIndex, MATERIAL_INDEX.DEFAULT);
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
this.#drawingToolsManager.updateMaterialIndex(this.#insertionActiveIndex, MATERIAL_INDEX.DEFAULT);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
this.#insertionActive = false;
|
|
81
|
+
this.#alreadyInserted = false;
|
|
82
|
+
this.#insertionActiveIndex = -1;
|
|
83
|
+
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public onMove(ray: IRay): void {
|
|
88
|
+
if (this.#insertionActive === false) return;
|
|
89
|
+
|
|
90
|
+
if (this.#geometryState.getPointCount() > 0 && this.#insertionActive === true) {
|
|
91
|
+
const restrictedPoint = this.#restrictionManager.rayTrace(ray, { index: this.#insertionActiveIndex });
|
|
92
|
+
|
|
93
|
+
if (restrictedPoint) {
|
|
94
|
+
const canBeClosed = this.#geometryState.getPointCount() > 3 && this.#geometryState.checkNumberOfPoints(this.#geometryState.getPointCount() - 1);
|
|
95
|
+
const shouldBeClosed = this.#settings.geometry.close === true && this.#geometryState.closeLoop === false && this.#settings.geometry.autoClose === false;
|
|
96
|
+
|
|
97
|
+
// if there are more than 2 points and the geometry can be closed, check if the last point is close to the first point
|
|
98
|
+
if (canBeClosed && shouldBeClosed) {
|
|
99
|
+
// if restricted point is close to the first point, remove the current insertion point and draw a line to the first point
|
|
100
|
+
const firstPoint = this.#geometryState.getPosition(0);
|
|
101
|
+
const lastPoint = restrictedPoint;
|
|
102
|
+
|
|
103
|
+
if (lastPoint && this.#geometryMathManager.screenSpaceDistanceCheck(firstPoint, lastPoint, this.#settings.visualization.points.size_0! * this.#settings.visualization.distanceMultiplicationFactor).check === true) {
|
|
104
|
+
// close the geometry
|
|
105
|
+
this.#drawingToolsManager.updateMaterialIndex(this.#insertionActiveIndex, MATERIAL_INDEX.SELECTED_HOVERED);
|
|
106
|
+
this.#drawingToolsManager.movePointTemporary(this.#insertionActiveIndex, firstPoint);
|
|
107
|
+
} else {
|
|
108
|
+
// not close enough to close the geometry
|
|
109
|
+
this.#drawingToolsManager.updateMaterialIndex(this.#insertionActiveIndex, MATERIAL_INDEX.INSERTION_HOVERED);
|
|
110
|
+
this.#drawingToolsManager.movePointTemporary(this.#insertionActiveIndex, restrictedPoint);
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
// not enough points to close the geometry or auto close is enabled
|
|
114
|
+
this.#drawingToolsManager.updateMaterialIndex(this.#insertionActiveIndex, MATERIAL_INDEX.INSERTION_HOVERED);
|
|
115
|
+
this.#drawingToolsManager.movePointTemporary(this.#insertionActiveIndex, restrictedPoint);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public startInsertion(event: PointerEvent): void {
|
|
122
|
+
if (this.#insertionActive === false) {
|
|
123
|
+
// get current ray
|
|
124
|
+
const ray = this.#viewport.pointerEventToRay(event);
|
|
125
|
+
|
|
126
|
+
// add a point at the ray intersection
|
|
127
|
+
const restrictedPoint = this.#restrictionManager.rayTrace(ray);
|
|
128
|
+
// add at last position
|
|
129
|
+
this.#insertionActiveIndex = this.#geometryState.getPointCount();
|
|
130
|
+
this.#drawingToolsManager.addPointTemporary(this.#insertionActiveIndex, restrictedPoint);
|
|
131
|
+
this.#drawingToolsManager.updateMaterialIndex(this.#insertionActiveIndex, MATERIAL_INDEX.INSERTION_HOVERED);
|
|
132
|
+
|
|
133
|
+
this.#insertionActive = true;
|
|
134
|
+
this.#alreadyInserted = true;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public stopInsertion(): void {
|
|
139
|
+
if (this.#insertionActive === true) {
|
|
140
|
+
// remove last added point
|
|
141
|
+
this.#drawingToolsManager.removePointTemporary(this.#insertionActiveIndex);
|
|
142
|
+
this.#insertionActive = false;
|
|
143
|
+
this.#alreadyInserted = false;
|
|
144
|
+
this.#insertionActiveIndex = -1;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// #endregion Public Methods (4)
|
|
149
|
+
}
|