@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,101 @@
|
|
|
1
|
+
import { addListener, EVENTTYPE_DRAWING_TOOLS, IEvent } from '@shapediver/viewer';
|
|
2
|
+
import { DrawingToolsEventResponseMapping } from '../../interfaces/events/EventResponseMapping';
|
|
3
|
+
import { DrawingToolsManager } from '../DrawingToolsManager';
|
|
4
|
+
import { IManager } from '../../interfaces/IManager';
|
|
5
|
+
import { PointsData } from '../../interfaces/IDrawingToolsManager';
|
|
6
|
+
|
|
7
|
+
// #region Type aliases (1)
|
|
8
|
+
|
|
9
|
+
export type HistoryState = {
|
|
10
|
+
points: PointsData;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// #endregion Type aliases (1)
|
|
14
|
+
|
|
15
|
+
// #region Classes (1)
|
|
16
|
+
|
|
17
|
+
export class HistoryManager implements IManager {
|
|
18
|
+
// #region Properties (3)
|
|
19
|
+
|
|
20
|
+
#currentStateIndex: number = -1;
|
|
21
|
+
#drawingToolsManager: DrawingToolsManager;
|
|
22
|
+
#history: HistoryState[] = [];
|
|
23
|
+
|
|
24
|
+
// #endregion Properties (3)
|
|
25
|
+
|
|
26
|
+
// #region Constructors (1)
|
|
27
|
+
|
|
28
|
+
constructor(drawingToolsManager: DrawingToolsManager) {
|
|
29
|
+
this.#drawingToolsManager = drawingToolsManager;
|
|
30
|
+
|
|
31
|
+
addListener(EVENTTYPE_DRAWING_TOOLS.GEOMETRY_CHANGED, (e: IEvent) => {
|
|
32
|
+
const event = e as DrawingToolsEventResponseMapping[EVENTTYPE_DRAWING_TOOLS.GEOMETRY_CHANGED];
|
|
33
|
+
if (event.temporary === false && event.points !== undefined && event.fromHistory !== true && event.recordHistory !== false) {
|
|
34
|
+
/**
|
|
35
|
+
* DO SOME CHECKS TO ENSURE THAT THE STATE IS CORRECT
|
|
36
|
+
*/
|
|
37
|
+
// 1. within number of points
|
|
38
|
+
if (this.#drawingToolsManager.geometryState.checkNumberOfPoints(event.points.length) === false) return;
|
|
39
|
+
// 2. closed loop if it should be closed
|
|
40
|
+
if (this.#drawingToolsManager.settings.geometry.close === true && this.#drawingToolsManager.geometryState.closeLoop === false && this.#drawingToolsManager.settings.geometry.autoClose === false) return;
|
|
41
|
+
|
|
42
|
+
this.recordState({
|
|
43
|
+
points: event.points
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// #endregion Constructors (1)
|
|
50
|
+
|
|
51
|
+
// #region Public Methods (8)
|
|
52
|
+
|
|
53
|
+
public applyState(state: HistoryState): void {
|
|
54
|
+
this.#drawingToolsManager.geometryState.updateDataFromHistory(state.points);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public canRedo(): boolean {
|
|
58
|
+
return this.#currentStateIndex < this.#history.length - 1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public canUndo(): boolean {
|
|
62
|
+
return this.#currentStateIndex > 0;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public close(): void {
|
|
66
|
+
this.#currentStateIndex = -1;
|
|
67
|
+
this.#history = [];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public getState(): HistoryState {
|
|
71
|
+
return this.#history[this.#currentStateIndex];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public recordState(state: HistoryState): void {
|
|
75
|
+
this.#history = this.#history.slice(0, this.#currentStateIndex + 1);
|
|
76
|
+
this.#history.push(state);
|
|
77
|
+
this.#currentStateIndex = this.#history.length - 1;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public redo(): void {
|
|
81
|
+
if (!this.canRedo()) return;
|
|
82
|
+
|
|
83
|
+
if (this.#currentStateIndex < this.#history.length - 1)
|
|
84
|
+
this.#currentStateIndex++;
|
|
85
|
+
|
|
86
|
+
this.applyState(this.#history[this.#currentStateIndex]);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public undo(): void {
|
|
90
|
+
if (!this.canUndo()) return;
|
|
91
|
+
|
|
92
|
+
if (this.#currentStateIndex > 0)
|
|
93
|
+
this.#currentStateIndex--;
|
|
94
|
+
|
|
95
|
+
this.applyState(this.#history[this.#currentStateIndex]);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// #endregion Public Methods (8)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// #endregion Classes (1)
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import {
|
|
3
|
+
addListener,
|
|
4
|
+
EVENTTYPE_DRAWING_TOOLS,
|
|
5
|
+
ITreeNode,
|
|
6
|
+
IViewportApi,
|
|
7
|
+
ThreejsData,
|
|
8
|
+
TreeNode
|
|
9
|
+
} from '@shapediver/viewer';
|
|
10
|
+
import { CSS2DObject, CSS2DRenderer } from '../../../three/CSS2DRenderer';
|
|
11
|
+
import { DrawingToolsManager } from '../DrawingToolsManager';
|
|
12
|
+
import { IManager } from '../../interfaces/IManager';
|
|
13
|
+
import { numberCleaner } from '../utils/numberCleaner';
|
|
14
|
+
import { Settings } from '../../interfaces/IDrawingToolsManager';
|
|
15
|
+
import { vec3 } from 'gl-matrix';
|
|
16
|
+
|
|
17
|
+
export class TextVisualizationManager implements IManager {
|
|
18
|
+
// #region Properties (11)
|
|
19
|
+
|
|
20
|
+
readonly #drawingToolsManager: DrawingToolsManager;
|
|
21
|
+
readonly #labelRenderer: CSS2DRenderer;
|
|
22
|
+
readonly #parentNode: ITreeNode;
|
|
23
|
+
readonly #settings: Settings;
|
|
24
|
+
readonly #viewport: IViewportApi;
|
|
25
|
+
readonly #visualizationNode: TreeNode = new TreeNode('TextVisualizationNode');
|
|
26
|
+
|
|
27
|
+
#distanceObject3D: THREE.Object3D;
|
|
28
|
+
#object3D: THREE.Object3D;
|
|
29
|
+
#positionObject3D: THREE.Object3D;
|
|
30
|
+
#showDistanceLabels: boolean = true;
|
|
31
|
+
#showPointLabels: boolean = true;
|
|
32
|
+
|
|
33
|
+
#prevWidth: number = 0;
|
|
34
|
+
#prevHeight: number = 0;
|
|
35
|
+
|
|
36
|
+
// #endregion Properties (11)
|
|
37
|
+
|
|
38
|
+
// #region Constructors (1)
|
|
39
|
+
|
|
40
|
+
constructor(drawingToolsManager: DrawingToolsManager) {
|
|
41
|
+
this.#drawingToolsManager = drawingToolsManager;
|
|
42
|
+
this.#viewport = drawingToolsManager.viewport;
|
|
43
|
+
this.#settings = drawingToolsManager.settings;
|
|
44
|
+
this.#parentNode = drawingToolsManager.parentNode;
|
|
45
|
+
|
|
46
|
+
this.#labelRenderer = new CSS2DRenderer();
|
|
47
|
+
this.#labelRenderer.setSize(this.#viewport.canvas.clientWidth, this.#viewport.canvas.clientHeight);
|
|
48
|
+
this.#labelRenderer.domElement.style.userSelect = 'none';
|
|
49
|
+
this.#labelRenderer.domElement.style.cursor = 'default';
|
|
50
|
+
this.#labelRenderer.domElement.style.pointerEvents = 'none';
|
|
51
|
+
this.#labelRenderer.domElement.style.overflow = 'hidden';
|
|
52
|
+
this.#labelRenderer.domElement.style.position = 'absolute';
|
|
53
|
+
this.#labelRenderer.domElement.style.width = '100%';
|
|
54
|
+
this.#labelRenderer.domElement.style.height = '100%';
|
|
55
|
+
this.#labelRenderer.domElement.style.left = '0%';
|
|
56
|
+
this.#labelRenderer.domElement.style.top = '0%';
|
|
57
|
+
this.#viewport.canvas.parentElement!.appendChild(this.#labelRenderer.domElement);
|
|
58
|
+
|
|
59
|
+
this.#viewport.postRenderingCallback = (renderer: THREE.WebGLRenderer, scene: THREE.Scene, camera: THREE.Camera) => {
|
|
60
|
+
if(this.#prevWidth !== renderer.domElement.clientWidth || this.#prevHeight !== renderer.domElement.clientHeight) {
|
|
61
|
+
this.#prevWidth = renderer.domElement.clientWidth;
|
|
62
|
+
this.#prevHeight = renderer.domElement.clientHeight;
|
|
63
|
+
this.#labelRenderer.setSize(renderer.domElement.clientWidth, renderer.domElement.clientHeight);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (this.#labelRenderer.domElement.clientWidth !== renderer.domElement.clientWidth || this.#labelRenderer.domElement.clientHeight !== renderer.domElement.clientHeight) {
|
|
67
|
+
this.#labelRenderer.setSize(renderer.domElement.clientWidth, renderer.domElement.clientHeight);
|
|
68
|
+
}
|
|
69
|
+
this.#labelRenderer.render(scene, camera);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
this.#object3D = new THREE.Object3D();
|
|
73
|
+
this.#positionObject3D = new THREE.Object3D();
|
|
74
|
+
this.#positionObject3D.visible = this.#settings.visualization.pointLabels;
|
|
75
|
+
this.#distanceObject3D = new THREE.Object3D();
|
|
76
|
+
this.#distanceObject3D.visible = this.#settings.visualization.distanceLabels;
|
|
77
|
+
|
|
78
|
+
this.#object3D.add(this.#positionObject3D);
|
|
79
|
+
this.#object3D.add(this.#distanceObject3D);
|
|
80
|
+
|
|
81
|
+
this.#showPointLabels = this.#settings.visualization.pointLabels;
|
|
82
|
+
this.#showDistanceLabels = this.#settings.visualization.distanceLabels;
|
|
83
|
+
|
|
84
|
+
const node = new TreeNode('ThreeJsDataNode');
|
|
85
|
+
|
|
86
|
+
const data = new ThreejsData(this.#object3D);
|
|
87
|
+
node.addData(data);
|
|
88
|
+
|
|
89
|
+
this.#visualizationNode.addChild(node);
|
|
90
|
+
this.#visualizationNode.updateVersion();
|
|
91
|
+
this.#parentNode.addChild(this.#visualizationNode);
|
|
92
|
+
this.#parentNode.updateVersion(false, false);
|
|
93
|
+
this.#viewport.updateNode(this.#parentNode);
|
|
94
|
+
|
|
95
|
+
this.createPointLabels();
|
|
96
|
+
this.createDistanceLabels();
|
|
97
|
+
|
|
98
|
+
addListener(EVENTTYPE_DRAWING_TOOLS.GEOMETRY_CHANGED, () => {
|
|
99
|
+
this.createPointLabels();
|
|
100
|
+
this.createDistanceLabels();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
addListener(EVENTTYPE_DRAWING_TOOLS.MOVED, () => {
|
|
104
|
+
this.createPointLabels();
|
|
105
|
+
this.createDistanceLabels();
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// #endregion Constructors (1)
|
|
110
|
+
|
|
111
|
+
// #region Public Getters And Setters (4)
|
|
112
|
+
|
|
113
|
+
public get showDistanceLabels(): boolean {
|
|
114
|
+
return this.#distanceObject3D.visible;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public set showDistanceLabels(value: boolean) {
|
|
118
|
+
this.#showDistanceLabels = value;
|
|
119
|
+
if (this.#showDistanceLabels) {
|
|
120
|
+
this.createDistanceLabels();
|
|
121
|
+
} else {
|
|
122
|
+
this.#distanceObject3D.remove(...this.#distanceObject3D.children);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public get showPointLabels(): boolean {
|
|
127
|
+
return this.#showPointLabels;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public set showPointLabels(value: boolean) {
|
|
131
|
+
this.#showPointLabels = value;
|
|
132
|
+
if (this.#showPointLabels) {
|
|
133
|
+
this.createPointLabels();
|
|
134
|
+
} else {
|
|
135
|
+
this.#positionObject3D.remove(...this.#positionObject3D.children);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// #endregion Public Getters And Setters (4)
|
|
140
|
+
|
|
141
|
+
// #region Public Methods (3)
|
|
142
|
+
|
|
143
|
+
public close(): void {
|
|
144
|
+
this.#positionObject3D.remove(...this.#positionObject3D.children);
|
|
145
|
+
this.#distanceObject3D.remove(...this.#distanceObject3D.children);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public createDistanceLabels(): void {
|
|
149
|
+
if (!this.#showDistanceLabels) return;
|
|
150
|
+
this.#distanceObject3D.remove(...this.#distanceObject3D.children);
|
|
151
|
+
|
|
152
|
+
const positionArray = this.#drawingToolsManager.positionArray;
|
|
153
|
+
const indicesArrayLines = this.#drawingToolsManager.indicesArrayLines;
|
|
154
|
+
|
|
155
|
+
if (!indicesArrayLines || positionArray.length <= 3) return;
|
|
156
|
+
|
|
157
|
+
for (let i = 0; i < indicesArrayLines.length; i += 2) {
|
|
158
|
+
// calculate the midpoint of the line
|
|
159
|
+
const firstIndex = indicesArrayLines[i];
|
|
160
|
+
const secondIndex = indicesArrayLines[i + 1];
|
|
161
|
+
const firstPoint = vec3.fromValues(
|
|
162
|
+
positionArray.at(firstIndex * 3)!,
|
|
163
|
+
positionArray.at(firstIndex * 3 + 1)!,
|
|
164
|
+
positionArray.at(firstIndex * 3 + 2)!
|
|
165
|
+
);
|
|
166
|
+
const secondPoint = vec3.fromValues(
|
|
167
|
+
positionArray.at(secondIndex * 3)!,
|
|
168
|
+
positionArray.at(secondIndex * 3 + 1)!,
|
|
169
|
+
positionArray.at(secondIndex * 3 + 2)!
|
|
170
|
+
);
|
|
171
|
+
const midPoint = vec3.add(vec3.create(), firstPoint, secondPoint);
|
|
172
|
+
vec3.scale(midPoint, midPoint, 0.5);
|
|
173
|
+
|
|
174
|
+
const text = document.createElement('div');
|
|
175
|
+
text.className = 'label';
|
|
176
|
+
text.style.marginTop = '1em';
|
|
177
|
+
|
|
178
|
+
const child = document.createElement('div');
|
|
179
|
+
child.className = 'distance-label';
|
|
180
|
+
|
|
181
|
+
const style = document.createElement('style');
|
|
182
|
+
style.textContent = `
|
|
183
|
+
.distance-label {
|
|
184
|
+
display: flex;
|
|
185
|
+
justify-content: center;
|
|
186
|
+
align-items: center;
|
|
187
|
+
color: white;
|
|
188
|
+
background-color: ${this.#settings.visualization.points.color_1}80;
|
|
189
|
+
border-radius: 5px;
|
|
190
|
+
font-size: 16px;
|
|
191
|
+
text-align: center;
|
|
192
|
+
padding: 0px 2px;
|
|
193
|
+
}
|
|
194
|
+
`;
|
|
195
|
+
document.head.appendChild(style);
|
|
196
|
+
|
|
197
|
+
child.textContent = `${numberCleaner(vec3.distance(firstPoint, secondPoint))}${this.#settings.general.displayUnit}`;
|
|
198
|
+
text.appendChild(child);
|
|
199
|
+
|
|
200
|
+
const label = new CSS2DObject(text);
|
|
201
|
+
label.position.set(midPoint[0], midPoint[1], midPoint[2]);
|
|
202
|
+
this.#distanceObject3D.add(label);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
public createPointLabels(): void {
|
|
207
|
+
if (!this.#showPointLabels) return;
|
|
208
|
+
this.#positionObject3D.remove(...this.#positionObject3D.children);
|
|
209
|
+
|
|
210
|
+
const positionArray = this.#drawingToolsManager.positionArray;
|
|
211
|
+
for (let i = 0; i < positionArray.length; i += 3) {
|
|
212
|
+
const text = document.createElement('div');
|
|
213
|
+
text.className = 'label';
|
|
214
|
+
text.style.marginTop = '1em';
|
|
215
|
+
|
|
216
|
+
const child = document.createElement('div');
|
|
217
|
+
child.className = 'point-label';
|
|
218
|
+
|
|
219
|
+
const style = document.createElement('style');
|
|
220
|
+
style.textContent = `
|
|
221
|
+
.point-label {
|
|
222
|
+
display: flex;
|
|
223
|
+
justify-content: center;
|
|
224
|
+
align-items: center;
|
|
225
|
+
color: white;
|
|
226
|
+
background-color: ${this.#settings.visualization.points.color_1}80;
|
|
227
|
+
border-radius: 5px;
|
|
228
|
+
font-size: 16px;
|
|
229
|
+
text-align: center;
|
|
230
|
+
padding: 0px 2px;
|
|
231
|
+
}
|
|
232
|
+
`;
|
|
233
|
+
document.head.appendChild(style);
|
|
234
|
+
|
|
235
|
+
child.textContent = `[${numberCleaner(positionArray[i])}${this.#settings.general.displayUnit}, ${numberCleaner(positionArray[i + 1])}${this.#settings.general.displayUnit}, ${numberCleaner(positionArray[i + 2])}${this.#settings.general.displayUnit}]`;
|
|
236
|
+
text.appendChild(child);
|
|
237
|
+
|
|
238
|
+
const label = new CSS2DObject(text);
|
|
239
|
+
label.position.set(positionArray[i], positionArray[i + 1], positionArray[i + 2]);
|
|
240
|
+
this.#positionObject3D.add(label);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// #endregion Public Methods (3)
|
|
245
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { DrawingToolsManager } from '../../DrawingToolsManager';
|
|
2
|
+
import { GeometryManagerHelper } from './helpers/GeometryManagerHelper';
|
|
3
|
+
import { GeometryState } from './GeometryState';
|
|
4
|
+
import { IManager } from '../../../interfaces/IManager';
|
|
5
|
+
import { ITreeNode, TreeNode } from '@shapediver/viewer.shared.node-tree';
|
|
6
|
+
import { MATERIAL_INDEX } from '../../../interfaces/IDrawingToolsManager';
|
|
7
|
+
import { vec3 } from 'gl-matrix';
|
|
8
|
+
|
|
9
|
+
export class GeometryManager implements IManager {
|
|
10
|
+
// #region Properties (4)
|
|
11
|
+
|
|
12
|
+
readonly #geometryState: GeometryState;
|
|
13
|
+
readonly #originalParentNode: ITreeNode;
|
|
14
|
+
readonly #parentNode: ITreeNode;
|
|
15
|
+
|
|
16
|
+
#geometryManagerHelper: GeometryManagerHelper;
|
|
17
|
+
|
|
18
|
+
// #endregion Properties (4)
|
|
19
|
+
|
|
20
|
+
// #region Constructors (1)
|
|
21
|
+
|
|
22
|
+
constructor(drawingToolsManager: DrawingToolsManager) {
|
|
23
|
+
this.#originalParentNode = drawingToolsManager.parentNode;
|
|
24
|
+
|
|
25
|
+
// create a new node with the geometry data
|
|
26
|
+
const parentNode = new TreeNode('DrawingToolsGeometry');
|
|
27
|
+
this.#originalParentNode.addChild(parentNode);
|
|
28
|
+
|
|
29
|
+
this.#parentNode = parentNode;
|
|
30
|
+
|
|
31
|
+
this.#geometryState = new GeometryState(drawingToolsManager, this);
|
|
32
|
+
this.#geometryManagerHelper = new GeometryManagerHelper(drawingToolsManager, this, this.#geometryState);
|
|
33
|
+
this.#geometryState.init();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// #endregion Constructors (1)
|
|
37
|
+
|
|
38
|
+
// #region Public Getters And Setters (2)
|
|
39
|
+
|
|
40
|
+
public get geometryState(): GeometryState {
|
|
41
|
+
return this.#geometryState;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public get parentNode(): ITreeNode {
|
|
45
|
+
return this.#parentNode;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// #endregion Public Getters And Setters (2)
|
|
49
|
+
|
|
50
|
+
// #region Public Methods (10)
|
|
51
|
+
|
|
52
|
+
public addPoint(index: number, position?: vec3, temporary = false): void {
|
|
53
|
+
this.#geometryManagerHelper.addPoint(index, position, temporary);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public canAddPoint(): boolean {
|
|
57
|
+
return this.#geometryState.canAddPoint();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public canRemovePoint(): boolean {
|
|
61
|
+
return this.#geometryState.canRemovePoint();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public close(): void {
|
|
65
|
+
this.#geometryState.close();
|
|
66
|
+
this.#originalParentNode.removeChild(this.#parentNode);
|
|
67
|
+
this.#originalParentNode.updateVersion();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public createLineIndices(loop: boolean): void {
|
|
71
|
+
this.#geometryState.createLineIndices(loop);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public movePoint(index: number, position: vec3, temporary = false): void {
|
|
75
|
+
this.#geometryManagerHelper.movePoint(index, position, temporary);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public removePoint(removalIndex: number, temporary = false): void {
|
|
79
|
+
this.#geometryManagerHelper.removePoint(removalIndex, temporary);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public removePoints(removalIndices: number[]): void {
|
|
83
|
+
this.#geometryManagerHelper.removePoints(removalIndices);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public resetMaterialIndices(): void {
|
|
87
|
+
this.#geometryManagerHelper.resetMaterialIndices();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public updateMaterialIndex(index: number, materialIndex: MATERIAL_INDEX): void {
|
|
91
|
+
this.#geometryManagerHelper.updateMaterialIndex(index, materialIndex);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// #endregion Public Methods (10)
|
|
95
|
+
}
|