@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,436 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import {
|
|
3
|
+
addListener,
|
|
4
|
+
EVENTTYPE_DRAWING_TOOLS,
|
|
5
|
+
ITreeNode,
|
|
6
|
+
IViewportApi
|
|
7
|
+
} from '@shapediver/viewer';
|
|
8
|
+
import {
|
|
9
|
+
AttributeData,
|
|
10
|
+
GeometryData,
|
|
11
|
+
IGeometryData,
|
|
12
|
+
IMapData,
|
|
13
|
+
MapData,
|
|
14
|
+
MATERIAL_ALPHA,
|
|
15
|
+
MaterialBasicLineData,
|
|
16
|
+
MaterialMultiPointData,
|
|
17
|
+
PRIMITIVE_MODE,
|
|
18
|
+
PrimitiveData
|
|
19
|
+
} from '@shapediver/viewer.shared.types';
|
|
20
|
+
import { DefaultTextures, PointsData, Settings } from '../../../interfaces/IDrawingToolsManager';
|
|
21
|
+
import { DrawingToolsEventResponseMapping } from '../../../interfaces/events/EventResponseMapping';
|
|
22
|
+
import { DrawingToolsManager } from '../../DrawingToolsManager';
|
|
23
|
+
import { EventEngine, IEvent } from '@shapediver/viewer.shared.services';
|
|
24
|
+
import { GeometryManager } from './GeometryManager';
|
|
25
|
+
import { MultiPointsMaterial } from '@shapediver/viewer.rendering-engine.rendering-engine-threejs';
|
|
26
|
+
import { vec3 } from 'gl-matrix';
|
|
27
|
+
export class GeometryState {
|
|
28
|
+
// #region Properties (15)
|
|
29
|
+
|
|
30
|
+
readonly #eventEngine: EventEngine = EventEngine.instance;
|
|
31
|
+
readonly #geometryManager: GeometryManager;
|
|
32
|
+
readonly #parentNode: ITreeNode;
|
|
33
|
+
readonly #settings: Settings;
|
|
34
|
+
readonly #viewport: IViewportApi;
|
|
35
|
+
|
|
36
|
+
#closeLoop: boolean = false;
|
|
37
|
+
#defaultTextures: DefaultTextures;
|
|
38
|
+
#geometryDataLines?: IGeometryData;
|
|
39
|
+
#geometryDataPoints!: IGeometryData;
|
|
40
|
+
#indicesArrayLines?: Uint8Array | null;
|
|
41
|
+
#materialIndexArray: number[] = [];
|
|
42
|
+
#positionArray!: Float32Array;
|
|
43
|
+
#positionIndexArray!: Float32Array;
|
|
44
|
+
#temporaryIndices: number[] = [];
|
|
45
|
+
#wasWithinMinimumMaximumPointsRange: boolean = false;
|
|
46
|
+
|
|
47
|
+
// #endregion Properties (15)
|
|
48
|
+
|
|
49
|
+
// #region Constructors (1)
|
|
50
|
+
|
|
51
|
+
constructor(drawingToolsManager: DrawingToolsManager, geometryManager: GeometryManager) {
|
|
52
|
+
this.#geometryManager = geometryManager;
|
|
53
|
+
|
|
54
|
+
this.#settings = drawingToolsManager.settings;
|
|
55
|
+
this.#viewport = drawingToolsManager.viewport;
|
|
56
|
+
this.#parentNode = geometryManager.parentNode;
|
|
57
|
+
|
|
58
|
+
this.#defaultTextures = drawingToolsManager.defaultTextures;
|
|
59
|
+
|
|
60
|
+
addListener(EVENTTYPE_DRAWING_TOOLS.ADDED, (e: IEvent) => {
|
|
61
|
+
const event = e as DrawingToolsEventResponseMapping[EVENTTYPE_DRAWING_TOOLS.ADDED];
|
|
62
|
+
if (event.temporary === false && event.index !== undefined) {
|
|
63
|
+
// shift the temporary indices
|
|
64
|
+
this.#temporaryIndices = this.#temporaryIndices.map(i => i > event.index! ? i + 1 : i);
|
|
65
|
+
} else if (event.temporary === true && event.index !== undefined) {
|
|
66
|
+
this.#temporaryIndices.push(event.index!);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
addListener(EVENTTYPE_DRAWING_TOOLS.REMOVED, (e: IEvent) => {
|
|
71
|
+
const event = e as DrawingToolsEventResponseMapping[EVENTTYPE_DRAWING_TOOLS.REMOVED];
|
|
72
|
+
if (event.temporary === false && event.index !== undefined) {
|
|
73
|
+
// shift the temporary indices
|
|
74
|
+
this.#temporaryIndices = this.#temporaryIndices.map(i => i > event.index! ? i - 1 : i);
|
|
75
|
+
} else if (event.temporary === true && event.index !== undefined) {
|
|
76
|
+
this.#temporaryIndices = this.#temporaryIndices.filter(i => i !== event.index);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// #endregion Constructors (1)
|
|
82
|
+
|
|
83
|
+
// #region Public Getters And Setters (12)
|
|
84
|
+
|
|
85
|
+
public get closeLoop(): boolean {
|
|
86
|
+
return this.#closeLoop;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public set closeLoop(value: boolean) {
|
|
90
|
+
this.#closeLoop = value;
|
|
91
|
+
this.updateData(this.#positionArray, true);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public get geometryData(): IGeometryData {
|
|
95
|
+
return this.#geometryDataPoints;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public get geometryDataLines(): IGeometryData | undefined {
|
|
99
|
+
return this.#geometryDataLines;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public get geometryDataPoints(): IGeometryData {
|
|
103
|
+
return this.#geometryDataPoints;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public get indicesArrayLines(): Uint8Array | null | undefined {
|
|
107
|
+
return this.#indicesArrayLines;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public get materialIndexArray(): number[] {
|
|
111
|
+
return this.#materialIndexArray;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public get pointsLength(): number {
|
|
115
|
+
return this.#positionArray.length / 3;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public get positionArray(): Float32Array {
|
|
119
|
+
return this.#positionArray;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public get positionIndexArray(): Float32Array {
|
|
123
|
+
return this.#positionIndexArray;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public get wasWithinMinimumMaximumPointsRange(): boolean {
|
|
127
|
+
return this.#wasWithinMinimumMaximumPointsRange;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public set wasWithinMinimumMaximumPointsRange(value: boolean) {
|
|
131
|
+
this.#wasWithinMinimumMaximumPointsRange = value;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// #endregion Public Getters And Setters (12)
|
|
135
|
+
|
|
136
|
+
// #region Public Methods (17)
|
|
137
|
+
|
|
138
|
+
public canAddPoint(number: number = 1): boolean {
|
|
139
|
+
if(this.wasWithinMinimumMaximumPointsRange === true && this.#settings.geometry.strictMinMaxPoints === true) {
|
|
140
|
+
return this.#settings.geometry.maxPoints !== undefined && this.pointsLength + number <= this.#settings.geometry.maxPoints;
|
|
141
|
+
}
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public canRemovePoint(number: number = 1): boolean {
|
|
146
|
+
if(this.wasWithinMinimumMaximumPointsRange === true && this.#settings.geometry.strictMinMaxPoints === true) {
|
|
147
|
+
return this.#settings.geometry.minPoints !== undefined && this.pointsLength - number >= this.#settings.geometry.minPoints;
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public checkMaximumNumberOfPoints(number?: number): boolean {
|
|
153
|
+
if (number === undefined) number = this.#positionArray.length / 3;
|
|
154
|
+
if (this.#settings.geometry.maxPoints === undefined) return true;
|
|
155
|
+
return number <= this.#settings.geometry.maxPoints;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
public checkMinimumNumberOfPoints(number?: number): boolean {
|
|
159
|
+
if (number === undefined) number = this.#positionArray.length / 3;
|
|
160
|
+
if (this.#settings.geometry.minPoints === undefined) return true;
|
|
161
|
+
return number >= this.#settings.geometry.minPoints;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
public checkNumberOfPoints(number?: number): boolean {
|
|
165
|
+
return this.checkMinimumNumberOfPoints(number) && this.checkMaximumNumberOfPoints(number);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
public close() {
|
|
169
|
+
this.#parentNode.removeData(this.#geometryDataPoints);
|
|
170
|
+
|
|
171
|
+
if (this.#geometryDataLines)
|
|
172
|
+
this.#parentNode.removeData(this.#geometryDataLines);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
public convertToFloat32Array(points: PointsData): Float32Array {
|
|
176
|
+
const positionArray = new Float32Array(points.length * 3);
|
|
177
|
+
for (let i = 0; i < points.length; i++) {
|
|
178
|
+
positionArray.set(points[i], i * 3);
|
|
179
|
+
}
|
|
180
|
+
return positionArray;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Creates the indices array for the lines
|
|
185
|
+
* Each line segment consists of two indices, start and end point
|
|
186
|
+
*
|
|
187
|
+
* optionally connect the last point with the first point
|
|
188
|
+
*/
|
|
189
|
+
public createLineIndices(loop: boolean): Uint8Array | undefined {
|
|
190
|
+
if (!this.#geometryDataLines) return;
|
|
191
|
+
|
|
192
|
+
const positionArrayLength = this.#positionArray.length / 3;
|
|
193
|
+
|
|
194
|
+
if (positionArrayLength < 1) return;
|
|
195
|
+
|
|
196
|
+
let indicesArrayLines = new Uint8Array((positionArrayLength - 1) * 2);
|
|
197
|
+
|
|
198
|
+
// create indices array
|
|
199
|
+
for (let i = 0; i < positionArrayLength - 1; i++) {
|
|
200
|
+
indicesArrayLines.set([i, i + 1], i * 2);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (loop) {
|
|
204
|
+
// connect the last point with the first point
|
|
205
|
+
const tempIndicesArray = new Uint8Array(indicesArrayLines.length + 2);
|
|
206
|
+
tempIndicesArray.set([...indicesArrayLines, positionArrayLength - 1, 0]);
|
|
207
|
+
indicesArrayLines = tempIndicesArray;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return indicesArrayLines;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
public getPointCount(): number {
|
|
214
|
+
return this.pointsLength;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
public getPointsData(): PointsData {
|
|
218
|
+
const points = [];
|
|
219
|
+
for (let i = 0; i < this.#positionArray.length; i += 3) {
|
|
220
|
+
points.push([this.#positionArray[i], this.#positionArray[i + 1], this.#positionArray[i + 2]]);
|
|
221
|
+
}
|
|
222
|
+
return points;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
public getPosition(index: number): vec3 {
|
|
226
|
+
return vec3.fromValues(
|
|
227
|
+
this.#positionArray[(index * 3)]!,
|
|
228
|
+
this.#positionArray[(index * 3) + 1]!,
|
|
229
|
+
this.#positionArray[(index * 3) + 2]!
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
public init() {
|
|
234
|
+
const geometryProperties = this.#settings.geometry!;
|
|
235
|
+
if (geometryProperties.points.length > 0) {
|
|
236
|
+
this.#positionArray = new Float32Array(geometryProperties.points.length * 3);
|
|
237
|
+
this.#positionArray.set(([] as number[]).concat(...geometryProperties.points));
|
|
238
|
+
} else {
|
|
239
|
+
this.#positionArray = new Float32Array();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
this.#geometryDataPoints = new GeometryData(
|
|
243
|
+
new PrimitiveData({
|
|
244
|
+
'POSITION': new AttributeData(this.#positionArray, 3, 12, 0, 4, false, this.#positionArray.length)
|
|
245
|
+
}),
|
|
246
|
+
PRIMITIVE_MODE.POINTS
|
|
247
|
+
);
|
|
248
|
+
this.#geometryDataPoints.renderOrder = 1000;
|
|
249
|
+
this.#parentNode.addData(this.#geometryDataPoints);
|
|
250
|
+
|
|
251
|
+
if (geometryProperties.mode !== 'points') {
|
|
252
|
+
this.#indicesArrayLines = new Uint8Array();
|
|
253
|
+
this.#geometryDataLines = new GeometryData(
|
|
254
|
+
new PrimitiveData({
|
|
255
|
+
'POSITION': new AttributeData(this.#positionArray, 3, 12, 0, 4, false, this.#positionArray.length)
|
|
256
|
+
},
|
|
257
|
+
new AttributeData(this.#indicesArrayLines, 1, 2, 0, 2, false, 0)),
|
|
258
|
+
PRIMITIVE_MODE.LINES
|
|
259
|
+
);
|
|
260
|
+
this.#geometryDataLines.renderOrder = 999;
|
|
261
|
+
this.#parentNode.addData(this.#geometryDataLines);
|
|
262
|
+
this.#indicesArrayLines = this.createLineIndices(this.#settings.geometry.close && this.#settings.geometry.autoClose);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// create material index array
|
|
266
|
+
this.#materialIndexArray = new Array(1024).fill(0);
|
|
267
|
+
|
|
268
|
+
this.#geometryDataPoints.material = new MaterialMultiPointData(
|
|
269
|
+
Object.assign(
|
|
270
|
+
{
|
|
271
|
+
materialIndexDataMap: new MapData(new Image(), { asData: true, data: this.#materialIndexArray }),
|
|
272
|
+
materialIndexDataMapSize: 1024,
|
|
273
|
+
alphaMode: MATERIAL_ALPHA.BLEND,
|
|
274
|
+
depthTest: false,
|
|
275
|
+
depthWrite: false,
|
|
276
|
+
transparent: true
|
|
277
|
+
},
|
|
278
|
+
this.#settings.visualization.points
|
|
279
|
+
)
|
|
280
|
+
);
|
|
281
|
+
const updateMaterialVariation = (variations: string[], map: IMapData) => {
|
|
282
|
+
for (const v of variations) {
|
|
283
|
+
(this.#geometryDataPoints.material as unknown as { [key: string]: unknown })[v as keyof MaterialMultiPointData] = map;
|
|
284
|
+
}
|
|
285
|
+
(this.#geometryDataPoints.material as MaterialMultiPointData).updateVersion();
|
|
286
|
+
this.#geometryDataPoints.updateVersion();
|
|
287
|
+
this.updateParentNode();
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const variation_0 = ['map_0', 'map_1', 'map_2', 'map_3', 'map_4', 'map_5', 'map_6', 'map_7'];
|
|
291
|
+
|
|
292
|
+
if (this.#defaultTextures.variation_0 instanceof MapData) {
|
|
293
|
+
updateMaterialVariation(variation_0, this.#defaultTextures.variation_0);
|
|
294
|
+
} else {
|
|
295
|
+
(this.#defaultTextures.variation_0 as Promise<IMapData>).then((map) => {
|
|
296
|
+
updateMaterialVariation(variation_0, map);
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (this.#geometryDataLines) {
|
|
301
|
+
this.#geometryDataLines.material = new MaterialBasicLineData(
|
|
302
|
+
Object.assign(
|
|
303
|
+
{
|
|
304
|
+
alphaMode: MATERIAL_ALPHA.BLEND,
|
|
305
|
+
depthTest: false,
|
|
306
|
+
depthWrite: false,
|
|
307
|
+
transparent: true
|
|
308
|
+
},
|
|
309
|
+
this.#settings.visualization.lines
|
|
310
|
+
)
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
this.updateData(this.#positionArray);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
public makePointPersistent(index: number, recordHistory = true): void {
|
|
318
|
+
// check if the number of points is within the minimum and maximum range
|
|
319
|
+
this.wasWithinMinimumMaximumPointsRange = this.checkNumberOfPoints();
|
|
320
|
+
|
|
321
|
+
// remove from the temporary indices
|
|
322
|
+
this.#temporaryIndices = this.#temporaryIndices.filter(i => i !== index);
|
|
323
|
+
|
|
324
|
+
this.#eventEngine.emitEvent(EVENTTYPE_DRAWING_TOOLS.GEOMETRY_CHANGED, {
|
|
325
|
+
points: this.getPointsData(),
|
|
326
|
+
temporary: false,
|
|
327
|
+
recordHistory
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
public updateData(
|
|
332
|
+
positionArray: Float32Array,
|
|
333
|
+
temporary: boolean = false,
|
|
334
|
+
fromHistory: boolean = false
|
|
335
|
+
): void {
|
|
336
|
+
this.#positionArray = positionArray;
|
|
337
|
+
this.#positionIndexArray = this.createAndSetPositionIndexArray();
|
|
338
|
+
|
|
339
|
+
this.geometryDataPoints.primitive.attributes['POSITION'] =
|
|
340
|
+
new AttributeData(
|
|
341
|
+
this.#positionArray,
|
|
342
|
+
this.geometryDataPoints.primitive.attributes['POSITION'].itemSize,
|
|
343
|
+
this.geometryDataPoints.primitive.attributes['POSITION'].itemBytes,
|
|
344
|
+
this.geometryDataPoints.primitive.attributes['POSITION'].byteOffset,
|
|
345
|
+
this.geometryDataPoints.primitive.attributes['POSITION'].elementBytes,
|
|
346
|
+
this.geometryDataPoints.primitive.attributes['POSITION'].normalized,
|
|
347
|
+
this.geometryDataPoints.primitive.attributes['POSITION'].count - 1
|
|
348
|
+
);
|
|
349
|
+
this.#geometryDataPoints.primitive.attributes['POSITION_INDEX'] = new AttributeData(this.#positionIndexArray, 1, 1, 0, 1, true, this.#positionIndexArray.length, [0], [this.#positionIndexArray.length]);
|
|
350
|
+
this.geometryDataPoints.updateVersion();
|
|
351
|
+
this.geometryDataPoints.primitive.updateVersion();
|
|
352
|
+
|
|
353
|
+
if (this.geometryDataLines) {
|
|
354
|
+
this.#indicesArrayLines = this.createLineIndices(this.#closeLoop || (this.#settings.geometry.close && this.#settings.geometry.autoClose));
|
|
355
|
+
if (this.#indicesArrayLines) {
|
|
356
|
+
this.geometryDataLines.primitive.indices =
|
|
357
|
+
new AttributeData(
|
|
358
|
+
this.#indicesArrayLines,
|
|
359
|
+
this.geometryDataLines.primitive.indices!.itemSize,
|
|
360
|
+
this.geometryDataLines.primitive.indices!.itemBytes,
|
|
361
|
+
this.geometryDataLines.primitive.indices!.byteOffset,
|
|
362
|
+
this.geometryDataLines.primitive.indices!.elementBytes,
|
|
363
|
+
this.geometryDataLines.primitive.indices!.normalized,
|
|
364
|
+
this.#indicesArrayLines.length
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
this.geometryDataLines.primitive.attributes['POSITION'] =
|
|
368
|
+
new AttributeData(
|
|
369
|
+
this.#positionArray,
|
|
370
|
+
this.geometryDataLines.primitive.attributes['POSITION'].itemSize,
|
|
371
|
+
this.geometryDataLines.primitive.attributes['POSITION'].itemBytes,
|
|
372
|
+
this.geometryDataLines.primitive.attributes['POSITION'].byteOffset,
|
|
373
|
+
this.geometryDataLines.primitive.attributes['POSITION'].elementBytes,
|
|
374
|
+
this.geometryDataLines.primitive.attributes['POSITION'].normalized,
|
|
375
|
+
this.geometryDataLines.primitive.attributes['POSITION'].count - 1
|
|
376
|
+
);
|
|
377
|
+
this.geometryDataLines.primitive.attributes['POSITION_INDEX'] = new AttributeData(this.#positionIndexArray, 1, 1, 0, 1, true, this.#positionIndexArray.length, [0], [this.#positionIndexArray.length]);
|
|
378
|
+
this.geometryDataLines.updateVersion();
|
|
379
|
+
this.geometryDataLines.primitive.updateVersion();
|
|
380
|
+
}
|
|
381
|
+
this.updateParentNode();
|
|
382
|
+
|
|
383
|
+
if (temporary === false) {
|
|
384
|
+
// check if the number of points is within the minimum and maximum range
|
|
385
|
+
this.wasWithinMinimumMaximumPointsRange = this.checkNumberOfPoints();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
this.#eventEngine.emitEvent(EVENTTYPE_DRAWING_TOOLS.GEOMETRY_CHANGED, {
|
|
389
|
+
points: this.getPointsData(),
|
|
390
|
+
temporary,
|
|
391
|
+
fromHistory
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
public updateDataFromHistory(points: PointsData): void {
|
|
396
|
+
const positionArray = this.convertToFloat32Array(points);
|
|
397
|
+
this.updateData(positionArray, false, true);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
public updateMaterialIndexArray(materialIndexArray: number[]): void {
|
|
401
|
+
this.#materialIndexArray = materialIndexArray;
|
|
402
|
+
|
|
403
|
+
const threeJsPointsGeometry: THREE.Points = this.#geometryDataPoints.convertedObject[this.#viewport.id] as THREE.Points;
|
|
404
|
+
for (let i = 0; i < this.#materialIndexArray.length; i++)
|
|
405
|
+
(threeJsPointsGeometry.material as MultiPointsMaterial).materialIndexDataTexture!.image.data[i] = this.#materialIndexArray[i];
|
|
406
|
+
(threeJsPointsGeometry.material as MultiPointsMaterial).materialIndexDataTexture!.needsUpdate = true;
|
|
407
|
+
(threeJsPointsGeometry.material as MultiPointsMaterial).needsUpdate = true;
|
|
408
|
+
|
|
409
|
+
(this.#geometryDataPoints.material as MaterialMultiPointData).materialIndexDataMap = new MapData(new Image(), { asData: true, data: this.#materialIndexArray }),
|
|
410
|
+
this.#geometryDataPoints.material!.updateVersion();
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
public updateParentNode(): void {
|
|
414
|
+
this.#parentNode.updateVersion(false, true);
|
|
415
|
+
this.#viewport.updateNode(this.#parentNode);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// #endregion Public Methods (17)
|
|
419
|
+
|
|
420
|
+
// #region Private Methods (1)
|
|
421
|
+
|
|
422
|
+
private createAndSetPositionIndexArray(): Float32Array {
|
|
423
|
+
const positionIndexArray = new Float32Array((this.#positionArray.length / 3));
|
|
424
|
+
// fill position index array with indices
|
|
425
|
+
for (let i = 0; i < positionIndexArray.length; i++) {
|
|
426
|
+
positionIndexArray.set([i], i);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
this.#positionIndexArray = positionIndexArray;
|
|
430
|
+
this.#geometryDataPoints.primitive.attributes['POSITION_INDEX'] = new AttributeData(this.#positionIndexArray, 1, 1, 0, 1, true, this.#positionIndexArray.length, [0], [this.#positionIndexArray.length]);
|
|
431
|
+
if (this.#geometryDataLines) this.#geometryDataLines.primitive.attributes['POSITION_INDEX'] = new AttributeData(this.#positionIndexArray, 1, 1, 0, 1, true, this.#positionIndexArray.length, [0], [this.#positionIndexArray.length]);
|
|
432
|
+
return positionIndexArray;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// #endregion Private Methods (1)
|
|
436
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { DrawingToolsManager } from '../../../DrawingToolsManager';
|
|
3
|
+
import { EventEngine, EVENTTYPE_DRAWING_TOOLS, ShapeDiverViewerDrawingToolsError } from '@shapediver/viewer.shared.services';
|
|
4
|
+
import { GeometryManager } from '../GeometryManager';
|
|
5
|
+
import { GeometryState } from '../GeometryState';
|
|
6
|
+
import { IViewportApi } from '@shapediver/viewer';
|
|
7
|
+
import { MATERIAL_INDEX } from '../../../../interfaces/IDrawingToolsManager';
|
|
8
|
+
import { vec3 } from 'gl-matrix';
|
|
9
|
+
|
|
10
|
+
export class GeometryManagerHelper {
|
|
11
|
+
// #region Properties (4)
|
|
12
|
+
|
|
13
|
+
readonly #eventEngine = EventEngine.instance;
|
|
14
|
+
readonly #geometryManager: GeometryManager;
|
|
15
|
+
readonly #geometryState: GeometryState;
|
|
16
|
+
readonly #viewport: IViewportApi;
|
|
17
|
+
|
|
18
|
+
// #endregion Properties (4)
|
|
19
|
+
|
|
20
|
+
// #region Constructors (1)
|
|
21
|
+
|
|
22
|
+
constructor(drawingToolsManager: DrawingToolsManager, geometryManager: GeometryManager, geometryState: GeometryState) {
|
|
23
|
+
this.#geometryManager = geometryManager;
|
|
24
|
+
this.#geometryState = geometryState;
|
|
25
|
+
this.#viewport = drawingToolsManager.viewport;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// #endregion Constructors (1)
|
|
29
|
+
|
|
30
|
+
// #region Public Methods (6)
|
|
31
|
+
|
|
32
|
+
public addPoint(insertionIndex: number, position?: vec3 | undefined, temporary = false): void {
|
|
33
|
+
const positionArrayLength = this.#geometryState.positionArray.length / 3;
|
|
34
|
+
const scaledIndex = insertionIndex * 3;
|
|
35
|
+
if (insertionIndex < 0 || insertionIndex > positionArrayLength) {
|
|
36
|
+
throw new ShapeDiverViewerDrawingToolsError('The insertion index is out of range. Please provide a valid index.');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const newPositionArray = new Float32Array(this.#geometryState.positionArray.length + 3);
|
|
40
|
+
|
|
41
|
+
let p: vec3;
|
|
42
|
+
if (position) {
|
|
43
|
+
p = position;
|
|
44
|
+
} else if (insertionIndex === 0) {
|
|
45
|
+
p = [this.#geometryState.positionArray.at(scaledIndex + 0)!, this.#geometryState.positionArray.at(scaledIndex + 1)!, this.#geometryState.positionArray.at(scaledIndex + 2)!];
|
|
46
|
+
} else if (insertionIndex === positionArrayLength) {
|
|
47
|
+
p = [this.#geometryState.positionArray.at(scaledIndex - 3)!, this.#geometryState.positionArray.at(scaledIndex - 2)!, this.#geometryState.positionArray.at(scaledIndex - 1)!];
|
|
48
|
+
} else {
|
|
49
|
+
const p1 = vec3.fromValues(this.#geometryState.positionArray.at(scaledIndex + 0)!, this.#geometryState.positionArray.at(scaledIndex + 1)!, this.#geometryState.positionArray.at(scaledIndex + 2)!);
|
|
50
|
+
const p2 = vec3.fromValues(this.#geometryState.positionArray.at(scaledIndex + 3)!, this.#geometryState.positionArray.at(scaledIndex + 4)!, this.#geometryState.positionArray.at(scaledIndex + 5)!);
|
|
51
|
+
p = vec3.div(vec3.create(), vec3.add(vec3.create(), p2, p1), vec3.fromValues(2, 2, 2));
|
|
52
|
+
// get neighboring point and calculate center
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
newPositionArray.set([...this.#geometryState.positionArray.slice(0, scaledIndex), ...p, ...this.#geometryState.positionArray.slice(scaledIndex, this.#geometryState.positionArray.length)]);
|
|
56
|
+
|
|
57
|
+
// set the material index at that point to 0 and move the other indices back
|
|
58
|
+
const materialIndexArray = this.#geometryState.materialIndexArray.slice(0, insertionIndex).concat([0], this.#geometryState.materialIndexArray.slice(insertionIndex, this.#geometryState.materialIndexArray.length - 1));
|
|
59
|
+
this.#geometryState.updateMaterialIndexArray(materialIndexArray);
|
|
60
|
+
this.#geometryState.updateData(newPositionArray, temporary);
|
|
61
|
+
|
|
62
|
+
this.#eventEngine.emitEvent(EVENTTYPE_DRAWING_TOOLS.ADDED, { viewportId: this.#viewport.id, drawingToolsId: this.#geometryManager.parentNode.id, temporary, index: insertionIndex });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public movePoint(index: number, point: vec3, temporary = false): void {
|
|
66
|
+
const threeJsPointsGeometry: THREE.Points = this.#geometryState.geometryDataPoints.convertedObject[this.#viewport.id] as THREE.Points;
|
|
67
|
+
threeJsPointsGeometry.geometry.attributes['position'].setXYZ(index, point[0], point[1], point[2]);
|
|
68
|
+
threeJsPointsGeometry.geometry.attributes['position'].needsUpdate = true;
|
|
69
|
+
|
|
70
|
+
if (this.#geometryState.geometryDataLines) {
|
|
71
|
+
const threeJsLinesGeometry: THREE.LineSegments = this.#geometryState.geometryDataLines.convertedObject[this.#viewport.id] as THREE.LineSegments;
|
|
72
|
+
threeJsLinesGeometry.geometry.attributes['position'].setXYZ(index, point[0], point[1], point[2]);
|
|
73
|
+
threeJsLinesGeometry.geometry.attributes['position'].needsUpdate = true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (temporary === false) {
|
|
77
|
+
// adjust position array
|
|
78
|
+
const positionArray = new Float32Array(this.#geometryState.positionArray);
|
|
79
|
+
positionArray.set([...positionArray.slice(0, index * 3), ...point, ...positionArray.slice(index * 3 + 3, positionArray.length)]);
|
|
80
|
+
this.#geometryState.updateData(positionArray, temporary);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this.#eventEngine.emitEvent(EVENTTYPE_DRAWING_TOOLS.MOVED, { viewportId: this.#viewport.id, drawingToolsId: this.#geometryManager.parentNode.id, temporary, index });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public removePoint(removalIndex: number, temporary = false): void {
|
|
87
|
+
const positionArrayLength = this.#geometryState.positionArray.length / 3;
|
|
88
|
+
if (removalIndex < 0 || removalIndex >= positionArrayLength) {
|
|
89
|
+
throw new ShapeDiverViewerDrawingToolsError('The removal index is out of range. Please provide a valid index.');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Adjust the position attribute
|
|
94
|
+
*
|
|
95
|
+
* Logic:
|
|
96
|
+
* - remove :D
|
|
97
|
+
*/
|
|
98
|
+
const newPositionArray = new Float32Array(this.#geometryState.positionArray.length - 3);
|
|
99
|
+
if (removalIndex > 0 && removalIndex < positionArrayLength) {
|
|
100
|
+
newPositionArray.set([...this.#geometryState.positionArray.slice(0, Math.max(removalIndex, 0) * 3), ...this.#geometryState.positionArray.slice(Math.min(removalIndex + 1, this.#geometryState.positionArray.length) * 3, this.#geometryState.positionArray.length)]);
|
|
101
|
+
} else if (removalIndex === 0) {
|
|
102
|
+
newPositionArray.set(this.#geometryState.positionArray.slice(3, this.#geometryState.positionArray.length));
|
|
103
|
+
} else {
|
|
104
|
+
newPositionArray.set(this.#geometryState.positionArray.slice(0, this.#geometryState.positionArray.length - 3));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// remove the material index at that point and move the other indices one forward
|
|
108
|
+
const materialIndexArray = this.#geometryState.materialIndexArray.slice(0, removalIndex).concat(this.#geometryState.materialIndexArray.slice(removalIndex + 1, this.#geometryState.materialIndexArray.length));
|
|
109
|
+
// add a 0 at the end
|
|
110
|
+
materialIndexArray.push(0);
|
|
111
|
+
this.#geometryState.updateMaterialIndexArray(materialIndexArray);
|
|
112
|
+
this.#geometryState.updateData(newPositionArray, temporary);
|
|
113
|
+
|
|
114
|
+
this.#eventEngine.emitEvent(EVENTTYPE_DRAWING_TOOLS.REMOVED, { viewportId: this.#viewport.id, drawingToolsId: this.#geometryManager.parentNode.id, temporary, index: removalIndex });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public removePoints(indices: number[]): void {
|
|
118
|
+
// sort indices so that highest is first
|
|
119
|
+
indices.sort((a, b) => b - a);
|
|
120
|
+
|
|
121
|
+
let positionArray = new Float32Array(this.#geometryState.positionArray);
|
|
122
|
+
let materialIndexArray = this.#geometryState.materialIndexArray;
|
|
123
|
+
|
|
124
|
+
for (const removalIndex of indices) {
|
|
125
|
+
const positionArrayLength = positionArray.length / 3;
|
|
126
|
+
if (removalIndex < 0 || removalIndex >= positionArrayLength) {
|
|
127
|
+
throw new ShapeDiverViewerDrawingToolsError('The removal index is out of range. Please provide a valid index.');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Adjust the position attribute
|
|
132
|
+
*
|
|
133
|
+
* Logic:
|
|
134
|
+
* - remove :D
|
|
135
|
+
*/
|
|
136
|
+
const newPositionArray = new Float32Array(positionArray.length - 3);
|
|
137
|
+
if (removalIndex > 0 && removalIndex < positionArrayLength) {
|
|
138
|
+
newPositionArray.set([...positionArray.slice(0, Math.max(removalIndex, 0) * 3), ...positionArray.slice(Math.min(removalIndex + 1, positionArray.length) * 3, positionArray.length)]);
|
|
139
|
+
} else if (removalIndex === 0) {
|
|
140
|
+
newPositionArray.set(positionArray.slice(3, positionArray.length));
|
|
141
|
+
} else {
|
|
142
|
+
newPositionArray.set(positionArray.slice(0, positionArray.length - 3));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
positionArray = newPositionArray;
|
|
146
|
+
|
|
147
|
+
materialIndexArray = materialIndexArray.slice(0, removalIndex).concat(materialIndexArray.slice(removalIndex + 1, materialIndexArray.length));
|
|
148
|
+
// add a 0 at the end
|
|
149
|
+
materialIndexArray.push(0);
|
|
150
|
+
}
|
|
151
|
+
this.#geometryState.updateMaterialIndexArray(materialIndexArray);
|
|
152
|
+
this.#geometryState.updateData(positionArray);
|
|
153
|
+
|
|
154
|
+
this.#eventEngine.emitEvent(EVENTTYPE_DRAWING_TOOLS.REMOVED, { viewportId: this.#viewport.id, drawingToolsId: this.#geometryManager.parentNode.id, temporary: false, index: indices });
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public resetMaterialIndices(): void {
|
|
158
|
+
this.#geometryState.updateMaterialIndexArray(new Array(1024).fill(0));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public updateMaterialIndex(index: number, materialIndex: MATERIAL_INDEX): void {
|
|
162
|
+
// change material index
|
|
163
|
+
if(this.#geometryState.materialIndexArray[index] !== materialIndex) {
|
|
164
|
+
this.#geometryState.materialIndexArray[index] = materialIndex;
|
|
165
|
+
this.#geometryState.updateMaterialIndexArray(this.#geometryState.materialIndexArray);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// #endregion Public Methods (6)
|
|
170
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { IDomEventListener } from '@shapediver/viewer.shared.services';
|
|
2
|
+
import { IManager } from '../../../interfaces/IManager';
|
|
3
|
+
import { IRay, IViewportApi } from '@shapediver/viewer.features.interaction';
|
|
4
|
+
|
|
5
|
+
// #region Type aliases (1)
|
|
6
|
+
|
|
7
|
+
type Callbacks = {
|
|
8
|
+
onDown: (event: PointerEvent, ray: IRay) => void,
|
|
9
|
+
onMove: (event: PointerEvent, ray: IRay) => void,
|
|
10
|
+
onUp: (event: PointerEvent, ray: IRay) => void,
|
|
11
|
+
onOut: (event: PointerEvent, ray: IRay) => void,
|
|
12
|
+
onKeyDown: (event: KeyboardEvent) => void,
|
|
13
|
+
onKeyUp: (event: KeyboardEvent) => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// #endregion Type aliases (1)
|
|
17
|
+
|
|
18
|
+
// #region Classes (1)
|
|
19
|
+
|
|
20
|
+
export class EventManager implements IDomEventListener, IManager {
|
|
21
|
+
// #region Properties (3)
|
|
22
|
+
|
|
23
|
+
readonly #callbacks: Callbacks;
|
|
24
|
+
readonly #canvasEventListenerToken: string;
|
|
25
|
+
readonly #viewport: IViewportApi;
|
|
26
|
+
|
|
27
|
+
// #endregion Properties (3)
|
|
28
|
+
|
|
29
|
+
// #region Constructors (1)
|
|
30
|
+
|
|
31
|
+
constructor(viewport: IViewportApi, callbacks: Callbacks) {
|
|
32
|
+
this.#viewport = viewport;
|
|
33
|
+
this.#callbacks = callbacks;
|
|
34
|
+
this.#canvasEventListenerToken = this.#viewport.addCanvasEventListener(this);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// #endregion Constructors (1)
|
|
38
|
+
|
|
39
|
+
// #region Public Methods (9)
|
|
40
|
+
|
|
41
|
+
public close(): void {
|
|
42
|
+
this.#viewport.removeCanvasEventListener(this.#canvasEventListenerToken);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public onKeyDown(event: KeyboardEvent): void {
|
|
46
|
+
this.#callbacks.onKeyDown(event);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public onKeyUp(event: KeyboardEvent): void {
|
|
50
|
+
this.#callbacks.onKeyUp(event);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public onMouseWheel(): void { }
|
|
54
|
+
|
|
55
|
+
public onPointerDown(event: PointerEvent): void {
|
|
56
|
+
const ray = this.#viewport.pointerEventToRay(event);
|
|
57
|
+
this.#callbacks.onDown(event, ray);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public onPointerEnd(): void { }
|
|
61
|
+
|
|
62
|
+
public onPointerMove(event: PointerEvent): void {
|
|
63
|
+
const ray = this.#viewport.pointerEventToRay(event);
|
|
64
|
+
this.#callbacks.onMove(event, ray);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public onPointerOut(event: PointerEvent): void {
|
|
68
|
+
const ray = this.#viewport.pointerEventToRay(event);
|
|
69
|
+
this.#callbacks.onOut(event, ray);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public onPointerUp(event: PointerEvent): void {
|
|
73
|
+
const ray = this.#viewport.pointerEventToRay(event);
|
|
74
|
+
this.#callbacks.onUp(event, ray);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// #endregion Public Methods (9)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// #endregion Classes (1)
|