@realsee/dnalogel 2.0.0-alpha.12 → 2.0.0-alpha.13
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/dist/CSS3DRenderPlugin/index.js +17 -14
- package/dist/CameraMovementPlugin/index.js +40 -15
- package/dist/ModelChassisCompassPlugin/index.js +32 -6
- package/dist/ModelEntryDoorGuidePlugin/index.js +48 -18
- package/dist/ModelItemLabelPlugin/index.js +18 -17
- package/dist/ModelRoomLabelPlugin/index.js +67 -26
- package/dist/PanoCompassPlugin/index.js +311 -164
- package/dist/PanoCursorRaycasterPlugin/index.js +5 -3
- package/dist/PanoMeasurePlugin/index.js +1337 -583
- package/dist/PanoRulerPlugin/index.js +32 -5
- package/dist/PanoSpatialTagPlugin/index.js +64 -29
- package/dist/floorplan/ModelFloorplanPlugin/index.js +586 -362
- package/dist/floorplan/PanoFloorplanRadarPlugin/index.js +164 -72
- package/dist/floorplan/TopviewFloorplanPlugin/index.js +311 -153
- package/dist/index.es.js +2663 -1341
- package/dist/index.js +2667 -1345
- package/dist/index.umd.js +2667 -1345
- package/docs/assets/main.js +1 -1
- package/docs/classes/ModelRoomLabelController.html +6 -6
- package/docs/enums/FLOOR_PLAN_ATTACHED_TO.html +1 -1
- package/docs/enums/ModelFloorplanErrorType.html +1 -1
- package/docs/interfaces/LineJson.html +1 -1
- package/docs/interfaces/ModelChassisCompassPluginData.html +1 -1
- package/docs/interfaces/ModelChassisCompassPluginExportType.html +1 -1
- package/docs/interfaces/ModelChassisCompassPluginParameterType.html +1 -1
- package/docs/interfaces/ModelEntryDoorGuidePluginData.html +1 -1
- package/docs/interfaces/ModelEntryDoorGuidePluginExportType.html +1 -1
- package/docs/interfaces/ModelFloorplanParameterType.html +1 -1
- package/docs/interfaces/ModelFloorplanViewEvent.html +2 -2
- package/docs/interfaces/ModelRoomLabelPluginData.html +1 -1
- package/docs/interfaces/PanoCompassPluginData.html +1 -1
- package/docs/interfaces/PanoCompassPluginParameterType.html +1 -1
- package/docs/interfaces/PanoCursorRaycasterPluginExportType.html +6 -6
- package/docs/interfaces/PanoRulerPluginExportType.html +1 -1
- package/docs/interfaces/PanoRulerPluginOptions.html +1 -1
- package/docs/interfaces/PanoRulerPluginParameterType.html +1 -1
- package/docs/interfaces/PanoSpatialTagPluginData.html +1 -1
- package/docs/interfaces/PanoSpatialTagPluginExportType.html +1 -1
- package/docs/interfaces/PanoSpatialTagPluginParameterType.html +1 -1
- package/docs/interfaces/PointJson.html +1 -1
- package/docs/interfaces/RoomLabel.html +7 -7
- package/docs/interfaces/TopviewFloorplanPluginParameterType.html +1 -1
- package/docs/modules.html +12 -12
- package/libs/CSS3DRenderPlugin/index.js +16 -13
- package/libs/CameraMovementPlugin/index.js +24 -15
- package/libs/ModelChassisCompassPlugin/index.js +14 -5
- package/libs/ModelEntryDoorGuidePlugin/index.js +24 -12
- package/libs/ModelItemLabelPlugin/ItemLabelComponent.js +12 -10
- package/libs/ModelItemLabelPlugin/index.js +5 -3
- package/libs/ModelItemLabelPlugin/utils/parseData.js +1 -4
- package/libs/ModelRoomLabelPlugin/Controller.js +64 -23
- package/libs/ModelRoomLabelPlugin/RoomLabelItems.js +3 -3
- package/libs/PanoCompassPlugin/index.js +225 -128
- package/libs/PanoCursorRaycasterPlugin/index.js +5 -3
- package/libs/PanoMeasurePlugin/Controller/BaseController.js +68 -13
- package/libs/PanoMeasurePlugin/Controller/EditController.js +267 -154
- package/libs/PanoMeasurePlugin/Controller/ShortcutKeyController.js +40 -20
- package/libs/PanoMeasurePlugin/Controller/WatchController.js +234 -152
- package/libs/PanoMeasurePlugin/Controller/index.js +131 -47
- package/libs/PanoMeasurePlugin/Model/index.js +30 -5
- package/libs/PanoMeasurePlugin/Model/line.js +60 -10
- package/libs/PanoMeasurePlugin/Model/point.js +24 -4
- package/libs/PanoMeasurePlugin/Model/polyline.js +20 -3
- package/libs/PanoMeasurePlugin/Modules/DeleteDom/index.js +59 -14
- package/libs/PanoMeasurePlugin/Modules/FiveHelper.js +23 -8
- package/libs/PanoMeasurePlugin/Modules/GuideController.js +61 -26
- package/libs/PanoMeasurePlugin/Modules/Magnifier.js +60 -10
- package/libs/PanoMeasurePlugin/Modules/UIController/MainBtnController.js +83 -37
- package/libs/PanoMeasurePlugin/Modules/UIController/Revoke/index.js +52 -17
- package/libs/PanoMeasurePlugin/Modules/UIController/index.js +61 -30
- package/libs/PanoMeasurePlugin/utils/distanceDom.js +3 -2
- package/libs/PanoMeasurePlugin/utils/line.js +8 -7
- package/libs/PanoRulerPlugin/index.js +16 -5
- package/libs/PanoSpatialTagPlugin/index.js +11 -9
- package/libs/floorplan/Components/BaseImage.js +10 -5
- package/libs/floorplan/Components/RoomHighlight/RoomHighlight.js +3 -1
- package/libs/floorplan/Components/RoomMaterials/RoomMaterial.js +5 -6
- package/libs/floorplan/ModelFloorplanPlugin/Components/Compass.js +7 -2
- package/libs/floorplan/ModelFloorplanPlugin/Components/RoomLabels/RoomLabel.js +3 -1
- package/libs/floorplan/ModelFloorplanPlugin/Controller.js +456 -273
- package/libs/floorplan/ModelFloorplanPlugin/utils/correctFiveState.js +33 -22
- package/libs/floorplan/PanoFloorplanRadarPlugin/Components/CurrentFloor/CurrentFloor.js +3 -1
- package/libs/floorplan/PanoFloorplanRadarPlugin/Controller.js +97 -36
- package/libs/floorplan/TopviewFloorplanPlugin/Controller.js +231 -108
- package/libs/floorplan/utils/formatData.js +43 -28
- package/libs/floorplan/utils/formatPosition.js +1 -1
- package/libs/shared-utils/Subscribe.js +8 -1
- package/libs/shared-utils/animationFrame/BetterTween.js +47 -18
- package/libs/shared-utils/createCanvasTextTexture.js +6 -5
- package/libs/shared-utils/five/changeMode.js +23 -12
- package/libs/shared-utils/getPxmm.js +1 -1
- package/libs/shared-utils/math/evenNumber.js +1 -1
- package/libs/shared-utils/three/loadFbxObj.js +20 -9
- package/libs/shared-utils/three/loadTexture.js +17 -6
- package/libs/shared-utils/three/transfromToMeshBasicMaterial.js +2 -1
- package/libs/shared-utils/tinyEJSrender.js +36 -6
- package/libs/shared-utils/to.js +21 -10
- package/libs/shared-utils/useDebounce.js +1 -1
- package/libs/shared-utils/useThrottle.js +2 -1
- package/package.json +1 -1
- package/CHANGELOG.md +0 -41
|
@@ -8,14 +8,240 @@ import { findClosestPoint } from '../utils/findClosestPoint';
|
|
|
8
8
|
import { findAssociatedLines } from '../utils/findAssociatedLines';
|
|
9
9
|
import { getPointFromHammerEvent } from '../utils/getPointFromHammerEvent';
|
|
10
10
|
export default class WatchController extends BaseController {
|
|
11
|
-
type = 'watch';
|
|
12
|
-
deleteDom;
|
|
13
|
-
highlightedLines = [];
|
|
14
|
-
fiveElement;
|
|
15
|
-
editPointState;
|
|
16
|
-
hammer;
|
|
17
11
|
constructor(params) {
|
|
18
12
|
super(params);
|
|
13
|
+
Object.defineProperty(this, "type", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: 'watch'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(this, "deleteDom", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: void 0
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(this, "highlightedLines", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: []
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(this, "fiveElement", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: void 0
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(this, "editPointState", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: void 0
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(this, "hammer", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
writable: true,
|
|
47
|
+
value: void 0
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(this, "onPanStart", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
value: (e) => {
|
|
54
|
+
var _a;
|
|
55
|
+
if (this.model.points.length === 0 || !this.fiveElement)
|
|
56
|
+
return;
|
|
57
|
+
const mouse = getPointFromHammerEvent(e).point;
|
|
58
|
+
const closestPoint = (_a = findClosestPoint(this.five, this.model.points, mouse, 20)) === null || _a === void 0 ? void 0 : _a.point;
|
|
59
|
+
if (!closestPoint) {
|
|
60
|
+
this.editPointState = undefined;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const editPointState = {
|
|
64
|
+
point: closestPoint,
|
|
65
|
+
associatedLines: findAssociatedLines(closestPoint.lines[0]),
|
|
66
|
+
};
|
|
67
|
+
const cancelDragLine = this.hook.emit('wantsDragLine', {
|
|
68
|
+
point: closestPoint.id,
|
|
69
|
+
lines: editPointState.associatedLines.map(({ id }) => id),
|
|
70
|
+
});
|
|
71
|
+
if (cancelDragLine)
|
|
72
|
+
return;
|
|
73
|
+
this.editPointState = editPointState;
|
|
74
|
+
this.magnifier.appendTo(this.container);
|
|
75
|
+
this.group.add(this.mouseGroup);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(this, "onPanEnd", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
configurable: true,
|
|
81
|
+
writable: true,
|
|
82
|
+
value: () => {
|
|
83
|
+
if (!this.editPointState)
|
|
84
|
+
return;
|
|
85
|
+
// 把拖动的线从虚线转换为实线
|
|
86
|
+
this.editPointState.point.lines.forEach((line) => line.mesh.setMaterial({ dashed: false }));
|
|
87
|
+
// 还原选中态
|
|
88
|
+
this.highlightLines(this.editPointState.associatedLines);
|
|
89
|
+
this.editPointState = undefined;
|
|
90
|
+
this.magnifier.dispose();
|
|
91
|
+
this.group.remove(this.mouseGroup);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(this, "onPan", {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
configurable: true,
|
|
97
|
+
writable: true,
|
|
98
|
+
value: (e) => {
|
|
99
|
+
if (!this.editPointState || !this.fiveElement)
|
|
100
|
+
return;
|
|
101
|
+
const mouse = getPointFromHammerEvent(e).ndcPoint;
|
|
102
|
+
const raycaster = new Raycaster();
|
|
103
|
+
raycaster.setFromCamera(mouse, this.five.camera);
|
|
104
|
+
const [intersection] = this.five.model.intersectRaycaster(raycaster);
|
|
105
|
+
if (!intersection)
|
|
106
|
+
return;
|
|
107
|
+
this.onIntersectionUpdate(intersection);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
Object.defineProperty(this, "onIntersectionUpdate", {
|
|
111
|
+
enumerable: true,
|
|
112
|
+
configurable: true,
|
|
113
|
+
writable: true,
|
|
114
|
+
value: (intersection, mesh) => {
|
|
115
|
+
if (!this.editPointState)
|
|
116
|
+
return;
|
|
117
|
+
// 拖动过程中清除选中态
|
|
118
|
+
this.clearHighlightLines();
|
|
119
|
+
// 把拖动点相关的线变成虚线 & 改变相关线的位置
|
|
120
|
+
this.editPointState.point.position.copy(intersection.point);
|
|
121
|
+
this.editPointState.point.lines.forEach((line) => {
|
|
122
|
+
line.mesh.setPoints(line.points[0].position.clone(), line.points[1].position.clone());
|
|
123
|
+
line.lightMesh.setPoints(line.points[0].position.clone(), line.points[1].position.clone());
|
|
124
|
+
line.mesh.setMaterial({ dashed: true });
|
|
125
|
+
});
|
|
126
|
+
this.updateDistanceUI();
|
|
127
|
+
this.magnifier.updateWithPoint(intersection.point);
|
|
128
|
+
this.mouseGroup.position.copy(intersection.point);
|
|
129
|
+
if (mesh) {
|
|
130
|
+
this.mouseGroup.quaternion.copy(mesh.quaternion);
|
|
131
|
+
}
|
|
132
|
+
else if (intersection.face) {
|
|
133
|
+
const face = intersection.face.normal;
|
|
134
|
+
const positionVector = face.clone().multiplyScalar(0.05);
|
|
135
|
+
const position = intersection.point.clone().add(positionVector);
|
|
136
|
+
const lookAtVector = position.clone().add(positionVector);
|
|
137
|
+
this.mouseGroup.lookAt(lookAtVector);
|
|
138
|
+
}
|
|
139
|
+
this.five.needsRender = true;
|
|
140
|
+
this.hook.emit('selectedChange', this.editPointState.associatedLines.map((line) => line.toCompletelyJson()));
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperty(this, "wantsPanGesture", {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
configurable: true,
|
|
146
|
+
writable: true,
|
|
147
|
+
value: () => {
|
|
148
|
+
if (this.editPointState)
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
Object.defineProperty(this, "wantsTapGesture", {
|
|
153
|
+
enumerable: true,
|
|
154
|
+
configurable: true,
|
|
155
|
+
writable: true,
|
|
156
|
+
value: (raycaster) => {
|
|
157
|
+
const [target] = this.five.model.intersectRaycaster(raycaster);
|
|
158
|
+
if (!target)
|
|
159
|
+
return;
|
|
160
|
+
const camera = this.five.camera;
|
|
161
|
+
const ndcTarget = target.point.clone().project(camera);
|
|
162
|
+
const screenWidth = this.container.clientWidth;
|
|
163
|
+
const screenHeight = this.container.clientHeight;
|
|
164
|
+
const targetScreenPosition = new Vector2(ndcTarget.x * screenWidth, ndcTarget.y * screenHeight);
|
|
165
|
+
// 把线的端点全部映射到屏幕上,过滤掉不在视野内的线,同时乘以屏幕宽 & 高
|
|
166
|
+
const screenLines = this.model.lines
|
|
167
|
+
.map((line) => {
|
|
168
|
+
const [startPoint, endPoint] = line.points;
|
|
169
|
+
const ndcStartPoint = startPoint.position.clone().project(camera);
|
|
170
|
+
const ndcEndPoint = endPoint.position.clone().project(camera);
|
|
171
|
+
if (!isNDCPointInScreen(ndcStartPoint) && !isNDCPointInScreen(ndcEndPoint))
|
|
172
|
+
return null;
|
|
173
|
+
const startScreenPosition = new Vector2(ndcStartPoint.x * screenWidth, ndcStartPoint.y * screenHeight);
|
|
174
|
+
const endScreenPosition = new Vector2(ndcEndPoint.x * screenWidth, ndcEndPoint.y * screenHeight);
|
|
175
|
+
return { id: line.id, points: [startScreenPosition, endScreenPosition] };
|
|
176
|
+
})
|
|
177
|
+
.filter((line) => !!line);
|
|
178
|
+
if (screenLines.length === 0)
|
|
179
|
+
return;
|
|
180
|
+
// 找这些线距离鼠标点击位置最近的线
|
|
181
|
+
const distanceLines = screenLines
|
|
182
|
+
.map((line) => {
|
|
183
|
+
const closestPoint = closestPointOnLine(targetScreenPosition, line.points);
|
|
184
|
+
return { id: line.id, distance: closestPoint.distanceTo(targetScreenPosition) };
|
|
185
|
+
})
|
|
186
|
+
.sort((a, b) => a.distance - b.distance);
|
|
187
|
+
const closestScreenLine = distanceLines[0];
|
|
188
|
+
if (closestScreenLine.distance > 20)
|
|
189
|
+
return;
|
|
190
|
+
const closestLine = this.model.lines.find(({ id }) => id === closestScreenLine.id);
|
|
191
|
+
if (!closestLine)
|
|
192
|
+
return;
|
|
193
|
+
this.chooseLine(closestLine);
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
Object.defineProperty(this, "chooseLine", {
|
|
198
|
+
enumerable: true,
|
|
199
|
+
configurable: true,
|
|
200
|
+
writable: true,
|
|
201
|
+
value: (line) => {
|
|
202
|
+
const highlightLines = findAssociatedLines(line);
|
|
203
|
+
this.highlightLines(highlightLines);
|
|
204
|
+
this.five.needsRender = true;
|
|
205
|
+
this.hook.emit('selectedChange', highlightLines.map((line) => line.toCompletelyJson()));
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
Object.defineProperty(this, "lineRemoved", {
|
|
209
|
+
enumerable: true,
|
|
210
|
+
configurable: true,
|
|
211
|
+
writable: true,
|
|
212
|
+
value: (line) => {
|
|
213
|
+
this.removeLine(line);
|
|
214
|
+
// TODO: 这个逻辑不太好,改进一下
|
|
215
|
+
this.hook.emit('selectedChange', this.model.lines.filter((line) => line.selected).map((line) => line.toCompletelyJson()));
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
Object.defineProperty(this, "onCameraUpdate", {
|
|
219
|
+
enumerable: true,
|
|
220
|
+
configurable: true,
|
|
221
|
+
writable: true,
|
|
222
|
+
value: () => {
|
|
223
|
+
this.updateDistanceUI();
|
|
224
|
+
this.highlightedLines.length > 0 && this.deleteDom.updatePosition();
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
Object.defineProperty(this, "deleteDomClickCallback", {
|
|
228
|
+
enumerable: true,
|
|
229
|
+
configurable: true,
|
|
230
|
+
writable: true,
|
|
231
|
+
value: () => {
|
|
232
|
+
const firstLine = this.highlightedLines[0];
|
|
233
|
+
// TODO: 优化折线的删除逻辑
|
|
234
|
+
firstLine
|
|
235
|
+
.getPolyline()
|
|
236
|
+
.lines.slice()
|
|
237
|
+
.reverse()
|
|
238
|
+
.forEach((line) => this.model.removeLine(line));
|
|
239
|
+
this.highlightedLines = [];
|
|
240
|
+
// this.clearHighlightLines()
|
|
241
|
+
// this.highlightedLines.forEach((line) => this.model.removeLine(line))
|
|
242
|
+
this.deleteDom.setLines([]).hide();
|
|
243
|
+
}
|
|
244
|
+
});
|
|
19
245
|
this.deleteDom = new DeleteDom(this.five, { onClick: this.deleteDomClickCallback }).appendTo(this.container);
|
|
20
246
|
this.model.lines.forEach((line) => {
|
|
21
247
|
line.distanceItem.appendTo(this.container);
|
|
@@ -39,6 +265,7 @@ export default class WatchController extends BaseController {
|
|
|
39
265
|
this.five.needsRender = true;
|
|
40
266
|
}
|
|
41
267
|
dispose() {
|
|
268
|
+
var _a;
|
|
42
269
|
super.dispose();
|
|
43
270
|
this.deleteDom.dispose();
|
|
44
271
|
this.model.hook.off('lineRemoved', this.lineRemoved);
|
|
@@ -47,7 +274,7 @@ export default class WatchController extends BaseController {
|
|
|
47
274
|
this.five.off('wantsTapGesture', this.wantsTapGesture);
|
|
48
275
|
this.five.needsRender = true;
|
|
49
276
|
this.hook.emit('selectedChange', []);
|
|
50
|
-
this.hammer
|
|
277
|
+
(_a = this.hammer) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
51
278
|
}
|
|
52
279
|
highlightLine(line) {
|
|
53
280
|
if (line.selected)
|
|
@@ -69,155 +296,10 @@ export default class WatchController extends BaseController {
|
|
|
69
296
|
this.highlightedLines = [];
|
|
70
297
|
this.five.needsRender = true;
|
|
71
298
|
}
|
|
72
|
-
onPanStart = (e) => {
|
|
73
|
-
if (this.model.points.length === 0 || !this.fiveElement)
|
|
74
|
-
return;
|
|
75
|
-
const mouse = getPointFromHammerEvent(e).point;
|
|
76
|
-
const closestPoint = findClosestPoint(this.five, this.model.points, mouse, 20)?.point;
|
|
77
|
-
if (!closestPoint) {
|
|
78
|
-
this.editPointState = undefined;
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const editPointState = {
|
|
82
|
-
point: closestPoint,
|
|
83
|
-
associatedLines: findAssociatedLines(closestPoint.lines[0]),
|
|
84
|
-
};
|
|
85
|
-
const cancelDragLine = this.hook.emit('wantsDragLine', {
|
|
86
|
-
point: closestPoint.id,
|
|
87
|
-
lines: editPointState.associatedLines.map(({ id }) => id),
|
|
88
|
-
});
|
|
89
|
-
if (cancelDragLine)
|
|
90
|
-
return;
|
|
91
|
-
this.editPointState = editPointState;
|
|
92
|
-
this.magnifier.appendTo(this.container);
|
|
93
|
-
this.group.add(this.mouseGroup);
|
|
94
|
-
};
|
|
95
|
-
onPanEnd = () => {
|
|
96
|
-
if (!this.editPointState)
|
|
97
|
-
return;
|
|
98
|
-
// 把拖动的线从虚线转换为实线
|
|
99
|
-
this.editPointState.point.lines.forEach((line) => line.mesh.setMaterial({ dashed: false }));
|
|
100
|
-
// 还原选中态
|
|
101
|
-
this.highlightLines(this.editPointState.associatedLines);
|
|
102
|
-
this.editPointState = undefined;
|
|
103
|
-
this.magnifier.dispose();
|
|
104
|
-
this.group.remove(this.mouseGroup);
|
|
105
|
-
};
|
|
106
|
-
onPan = (e) => {
|
|
107
|
-
if (!this.editPointState || !this.fiveElement)
|
|
108
|
-
return;
|
|
109
|
-
const mouse = getPointFromHammerEvent(e).ndcPoint;
|
|
110
|
-
const raycaster = new Raycaster();
|
|
111
|
-
raycaster.setFromCamera(mouse, this.five.camera);
|
|
112
|
-
const [intersection] = this.five.model.intersectRaycaster(raycaster);
|
|
113
|
-
if (!intersection)
|
|
114
|
-
return;
|
|
115
|
-
this.onIntersectionUpdate(intersection);
|
|
116
|
-
};
|
|
117
|
-
onIntersectionUpdate = (intersection, mesh) => {
|
|
118
|
-
if (!this.editPointState)
|
|
119
|
-
return;
|
|
120
|
-
// 拖动过程中清除选中态
|
|
121
|
-
this.clearHighlightLines();
|
|
122
|
-
// 把拖动点相关的线变成虚线 & 改变相关线的位置
|
|
123
|
-
this.editPointState.point.position.copy(intersection.point);
|
|
124
|
-
this.editPointState.point.lines.forEach((line) => {
|
|
125
|
-
line.mesh.setPoints(line.points[0].position.clone(), line.points[1].position.clone());
|
|
126
|
-
line.lightMesh.setPoints(line.points[0].position.clone(), line.points[1].position.clone());
|
|
127
|
-
line.mesh.setMaterial({ dashed: true });
|
|
128
|
-
});
|
|
129
|
-
this.updateDistanceUI();
|
|
130
|
-
this.magnifier.updateWithPoint(intersection.point);
|
|
131
|
-
this.mouseGroup.position.copy(intersection.point);
|
|
132
|
-
if (mesh) {
|
|
133
|
-
this.mouseGroup.quaternion.copy(mesh.quaternion);
|
|
134
|
-
}
|
|
135
|
-
else if (intersection.face) {
|
|
136
|
-
const face = intersection.face.normal;
|
|
137
|
-
const positionVector = face.clone().multiplyScalar(0.05);
|
|
138
|
-
const position = intersection.point.clone().add(positionVector);
|
|
139
|
-
const lookAtVector = position.clone().add(positionVector);
|
|
140
|
-
this.mouseGroup.lookAt(lookAtVector);
|
|
141
|
-
}
|
|
142
|
-
this.five.needsRender = true;
|
|
143
|
-
this.hook.emit('selectedChange', this.editPointState.associatedLines.map((line) => line.toCompletelyJson()));
|
|
144
|
-
};
|
|
145
|
-
wantsPanGesture = () => {
|
|
146
|
-
if (this.editPointState)
|
|
147
|
-
return false;
|
|
148
|
-
};
|
|
149
|
-
wantsTapGesture = (raycaster) => {
|
|
150
|
-
const [target] = this.five.model.intersectRaycaster(raycaster);
|
|
151
|
-
if (!target)
|
|
152
|
-
return;
|
|
153
|
-
const camera = this.five.camera;
|
|
154
|
-
const ndcTarget = target.point.clone().project(camera);
|
|
155
|
-
const screenWidth = this.container.clientWidth;
|
|
156
|
-
const screenHeight = this.container.clientHeight;
|
|
157
|
-
const targetScreenPosition = new Vector2(ndcTarget.x * screenWidth, ndcTarget.y * screenHeight);
|
|
158
|
-
// 把线的端点全部映射到屏幕上,过滤掉不在视野内的线,同时乘以屏幕宽 & 高
|
|
159
|
-
const screenLines = this.model.lines
|
|
160
|
-
.map((line) => {
|
|
161
|
-
const [startPoint, endPoint] = line.points;
|
|
162
|
-
const ndcStartPoint = startPoint.position.clone().project(camera);
|
|
163
|
-
const ndcEndPoint = endPoint.position.clone().project(camera);
|
|
164
|
-
if (!isNDCPointInScreen(ndcStartPoint) && !isNDCPointInScreen(ndcEndPoint))
|
|
165
|
-
return null;
|
|
166
|
-
const startScreenPosition = new Vector2(ndcStartPoint.x * screenWidth, ndcStartPoint.y * screenHeight);
|
|
167
|
-
const endScreenPosition = new Vector2(ndcEndPoint.x * screenWidth, ndcEndPoint.y * screenHeight);
|
|
168
|
-
return { id: line.id, points: [startScreenPosition, endScreenPosition] };
|
|
169
|
-
})
|
|
170
|
-
.filter((line) => !!line);
|
|
171
|
-
if (screenLines.length === 0)
|
|
172
|
-
return;
|
|
173
|
-
// 找这些线距离鼠标点击位置最近的线
|
|
174
|
-
const distanceLines = screenLines
|
|
175
|
-
.map((line) => {
|
|
176
|
-
const closestPoint = closestPointOnLine(targetScreenPosition, line.points);
|
|
177
|
-
return { id: line.id, distance: closestPoint.distanceTo(targetScreenPosition) };
|
|
178
|
-
})
|
|
179
|
-
.sort((a, b) => a.distance - b.distance);
|
|
180
|
-
const closestScreenLine = distanceLines[0];
|
|
181
|
-
if (closestScreenLine.distance > 20)
|
|
182
|
-
return;
|
|
183
|
-
const closestLine = this.model.lines.find(({ id }) => id === closestScreenLine.id);
|
|
184
|
-
if (!closestLine)
|
|
185
|
-
return;
|
|
186
|
-
this.chooseLine(closestLine);
|
|
187
|
-
return false;
|
|
188
|
-
};
|
|
189
|
-
chooseLine = (line) => {
|
|
190
|
-
const highlightLines = findAssociatedLines(line);
|
|
191
|
-
this.highlightLines(highlightLines);
|
|
192
|
-
this.five.needsRender = true;
|
|
193
|
-
this.hook.emit('selectedChange', highlightLines.map((line) => line.toCompletelyJson()));
|
|
194
|
-
};
|
|
195
299
|
highlightLines(lines) {
|
|
196
300
|
this.clearHighlightLines();
|
|
197
301
|
this.highlightedLines = lines;
|
|
198
302
|
this.deleteDom.setLines(lines).updatePosition().show();
|
|
199
303
|
lines.forEach((line) => this.highlightLine(line));
|
|
200
304
|
}
|
|
201
|
-
lineRemoved = (line) => {
|
|
202
|
-
this.removeLine(line);
|
|
203
|
-
// TODO: 这个逻辑不太好,改进一下
|
|
204
|
-
this.hook.emit('selectedChange', this.model.lines.filter((line) => line.selected).map((line) => line.toCompletelyJson()));
|
|
205
|
-
};
|
|
206
|
-
onCameraUpdate = () => {
|
|
207
|
-
this.updateDistanceUI();
|
|
208
|
-
this.highlightedLines.length > 0 && this.deleteDom.updatePosition();
|
|
209
|
-
};
|
|
210
|
-
deleteDomClickCallback = () => {
|
|
211
|
-
const firstLine = this.highlightedLines[0];
|
|
212
|
-
// TODO: 优化折线的删除逻辑
|
|
213
|
-
firstLine
|
|
214
|
-
.getPolyline()
|
|
215
|
-
.lines.slice()
|
|
216
|
-
.reverse()
|
|
217
|
-
.forEach((line) => this.model.removeLine(line));
|
|
218
|
-
this.highlightedLines = [];
|
|
219
|
-
// this.clearHighlightLines()
|
|
220
|
-
// this.highlightedLines.forEach((line) => this.model.removeLine(line))
|
|
221
|
-
this.deleteDom.setLines([]).hide();
|
|
222
|
-
};
|
|
223
305
|
}
|
|
@@ -10,21 +10,127 @@ import { UIController } from '../Modules/UIController';
|
|
|
10
10
|
import { GuideController } from '../Modules/GuideController';
|
|
11
11
|
import { ShortcutKeyController } from './ShortcutKeyController';
|
|
12
12
|
export default class MeasureController {
|
|
13
|
-
hasOpen = false;
|
|
14
|
-
hook = new Subscribe();
|
|
15
|
-
five;
|
|
16
|
-
model;
|
|
17
|
-
group;
|
|
18
|
-
magnifier;
|
|
19
|
-
fiveHelper;
|
|
20
|
-
useUIController;
|
|
21
|
-
params;
|
|
22
|
-
useGuideController;
|
|
23
|
-
container = document.createElement('div');
|
|
24
|
-
shortcutKeyController;
|
|
25
|
-
controller = null;
|
|
26
|
-
controllerParams;
|
|
27
13
|
constructor(five, params) {
|
|
14
|
+
Object.defineProperty(this, "hasOpen", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: false
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(this, "hook", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: new Subscribe()
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(this, "five", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: void 0
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(this, "model", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true,
|
|
36
|
+
value: void 0
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(this, "group", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
writable: true,
|
|
42
|
+
value: void 0
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(this, "magnifier", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
configurable: true,
|
|
47
|
+
writable: true,
|
|
48
|
+
value: void 0
|
|
49
|
+
});
|
|
50
|
+
Object.defineProperty(this, "fiveHelper", {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
configurable: true,
|
|
53
|
+
writable: true,
|
|
54
|
+
value: void 0
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(this, "useUIController", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
value: void 0
|
|
61
|
+
});
|
|
62
|
+
Object.defineProperty(this, "params", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true,
|
|
66
|
+
value: void 0
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(this, "useGuideController", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
configurable: true,
|
|
71
|
+
writable: true,
|
|
72
|
+
value: void 0
|
|
73
|
+
});
|
|
74
|
+
Object.defineProperty(this, "container", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
configurable: true,
|
|
77
|
+
writable: true,
|
|
78
|
+
value: document.createElement('div')
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(this, "shortcutKeyController", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
configurable: true,
|
|
83
|
+
writable: true,
|
|
84
|
+
value: void 0
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(this, "controller", {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
configurable: true,
|
|
89
|
+
writable: true,
|
|
90
|
+
value: null
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(this, "controllerParams", {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
configurable: true,
|
|
95
|
+
writable: true,
|
|
96
|
+
value: void 0
|
|
97
|
+
});
|
|
98
|
+
Object.defineProperty(this, "getCurrentMode", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
configurable: true,
|
|
101
|
+
writable: true,
|
|
102
|
+
value: () => {
|
|
103
|
+
if (this.controller instanceof EditController)
|
|
104
|
+
return 'Edit';
|
|
105
|
+
if (this.controller instanceof WatchController)
|
|
106
|
+
return 'Watch';
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
/** 变更场景
|
|
111
|
+
* @description 如果从编辑场景改变到观看场景,不会自动保存,默认丢弃所有改动
|
|
112
|
+
*/
|
|
113
|
+
Object.defineProperty(this, "changeMode", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true,
|
|
116
|
+
writable: true,
|
|
117
|
+
value: (mode) => {
|
|
118
|
+
var _a;
|
|
119
|
+
if (!this.hasOpen)
|
|
120
|
+
return;
|
|
121
|
+
if (this.getCurrentMode() === mode)
|
|
122
|
+
return;
|
|
123
|
+
(_a = this.controller) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
124
|
+
const controllerMap = {
|
|
125
|
+
Watch: WatchController,
|
|
126
|
+
Edit: EditController,
|
|
127
|
+
};
|
|
128
|
+
if (!controllerMap[mode])
|
|
129
|
+
throw new Error('不存在的 Mode');
|
|
130
|
+
this.controller = new controllerMap[mode](this.controllerParams);
|
|
131
|
+
this.hook.emit('modeChange', mode);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
28
134
|
this.five = five;
|
|
29
135
|
this.params = params;
|
|
30
136
|
this.model = new Model({ userDistanceItemCreator: this.params.userDistanceItemCreator });
|
|
@@ -62,9 +168,10 @@ export default class MeasureController {
|
|
|
62
168
|
parent.append(this.container);
|
|
63
169
|
}
|
|
64
170
|
dispose() {
|
|
171
|
+
var _a, _b;
|
|
65
172
|
this.disable();
|
|
66
|
-
this.useUIController
|
|
67
|
-
this.magnifier
|
|
173
|
+
(_a = this.useUIController) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
174
|
+
(_b = this.magnifier) === null || _b === void 0 ? void 0 : _b.dispose();
|
|
68
175
|
this.five.needsRender = true;
|
|
69
176
|
}
|
|
70
177
|
/** 加载数据
|
|
@@ -80,6 +187,7 @@ export default class MeasureController {
|
|
|
80
187
|
* @description 会隐藏当前 VR 内的点位展示
|
|
81
188
|
*/
|
|
82
189
|
enable() {
|
|
190
|
+
var _a, _b;
|
|
83
191
|
if (this.hasOpen)
|
|
84
192
|
return;
|
|
85
193
|
this.hasOpen = true;
|
|
@@ -87,8 +195,8 @@ export default class MeasureController {
|
|
|
87
195
|
// 隐藏点位和鼠标聚焦环
|
|
88
196
|
this.five.helperVisible = false;
|
|
89
197
|
this.controller = new WatchController(this.controllerParams);
|
|
90
|
-
this.useUIController
|
|
91
|
-
this.useGuideController
|
|
198
|
+
(_a = this.useUIController) === null || _a === void 0 ? void 0 : _a.show();
|
|
199
|
+
(_b = this.useGuideController) === null || _b === void 0 ? void 0 : _b.show();
|
|
92
200
|
this.shortcutKeyController = new ShortcutKeyController(this, this.five);
|
|
93
201
|
this.hook.emit('enable', true);
|
|
94
202
|
}
|
|
@@ -97,43 +205,19 @@ export default class MeasureController {
|
|
|
97
205
|
* @description 还原点位展示和默认鼠标 UI
|
|
98
206
|
*/
|
|
99
207
|
disable() {
|
|
208
|
+
var _a, _b, _c, _d;
|
|
100
209
|
this.hasOpen = false;
|
|
101
210
|
// 展示点位和鼠标聚焦环
|
|
102
|
-
this.controller
|
|
103
|
-
this.useUIController
|
|
104
|
-
this.useGuideController
|
|
105
|
-
this.shortcutKeyController
|
|
211
|
+
(_a = this.controller) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
212
|
+
(_b = this.useUIController) === null || _b === void 0 ? void 0 : _b.hide();
|
|
213
|
+
(_c = this.useGuideController) === null || _c === void 0 ? void 0 : _c.hide();
|
|
214
|
+
(_d = this.shortcutKeyController) === null || _d === void 0 ? void 0 : _d.dispose();
|
|
106
215
|
this.controller = null;
|
|
107
216
|
this.five.helperVisible = true;
|
|
108
217
|
this.five.scene.remove(this.group);
|
|
109
218
|
this.five.needsRender = true;
|
|
110
219
|
this.hook.emit('disable', true);
|
|
111
220
|
}
|
|
112
|
-
getCurrentMode = () => {
|
|
113
|
-
if (this.controller instanceof EditController)
|
|
114
|
-
return 'Edit';
|
|
115
|
-
if (this.controller instanceof WatchController)
|
|
116
|
-
return 'Watch';
|
|
117
|
-
return null;
|
|
118
|
-
};
|
|
119
|
-
/** 变更场景
|
|
120
|
-
* @description 如果从编辑场景改变到观看场景,不会自动保存,默认丢弃所有改动
|
|
121
|
-
*/
|
|
122
|
-
changeMode = (mode) => {
|
|
123
|
-
if (!this.hasOpen)
|
|
124
|
-
return;
|
|
125
|
-
if (this.getCurrentMode() === mode)
|
|
126
|
-
return;
|
|
127
|
-
this.controller?.dispose();
|
|
128
|
-
const controllerMap = {
|
|
129
|
-
Watch: WatchController,
|
|
130
|
-
Edit: EditController,
|
|
131
|
-
};
|
|
132
|
-
if (!controllerMap[mode])
|
|
133
|
-
throw new Error('不存在的 Mode');
|
|
134
|
-
this.controller = new controllerMap[mode](this.controllerParams);
|
|
135
|
-
this.hook.emit('modeChange', mode);
|
|
136
|
-
};
|
|
137
221
|
/** 撤销编辑 */
|
|
138
222
|
revoke() {
|
|
139
223
|
if (!(this.controller instanceof EditController))
|
|
@@ -4,12 +4,37 @@ import { Subscribe } from '@realsee/five';
|
|
|
4
4
|
import removeArrayItem from '../../shared-utils/removeArrayItem';
|
|
5
5
|
import { Polyline } from './polyline';
|
|
6
6
|
export class Model {
|
|
7
|
-
lines = [];
|
|
8
|
-
points = [];
|
|
9
|
-
params;
|
|
10
|
-
polylines = [];
|
|
11
|
-
hook = new Subscribe();
|
|
12
7
|
constructor(params) {
|
|
8
|
+
Object.defineProperty(this, "lines", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: []
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(this, "points", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: []
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(this, "params", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: void 0
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(this, "polylines", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: []
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(this, "hook", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true,
|
|
36
|
+
value: new Subscribe()
|
|
37
|
+
});
|
|
13
38
|
this.params = params;
|
|
14
39
|
}
|
|
15
40
|
addLine(line) {
|