@inweb/viewer-three 27.2.3 → 27.2.4
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/viewer-three.js +319 -652
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +3 -3
- package/dist/viewer-three.module.js +321 -654
- package/dist/viewer-three.module.js.map +1 -1
- package/lib/Viewer/controls/WalkControls.d.ts +0 -8
- package/lib/Viewer/draggers/CuttingPlaneDragger.d.ts +5 -23
- package/lib/Viewer/helpers/PlaneHelper2.d.ts +4 -8
- package/lib/Viewer/measurement/Snapper.d.ts +1 -1
- package/package.json +5 -5
- package/src/Viewer/components/SelectionComponent.ts +1 -1
- package/src/Viewer/controls/WalkControls.ts +4 -50
- package/src/Viewer/draggers/CuttingPlaneDragger.ts +31 -191
- package/src/Viewer/draggers/CuttingPlaneXAxis.ts +3 -2
- package/src/Viewer/draggers/CuttingPlaneYAxis.ts +3 -2
- package/src/Viewer/draggers/CuttingPlaneZAxis.ts +3 -2
- package/src/Viewer/draggers/index.ts +0 -2
- package/src/Viewer/helpers/PlaneHelper2.ts +17 -30
- package/src/Viewer/loaders/DynamicGltfLoader/DynamicGltfLoader.js +189 -413
- package/src/Viewer/measurement/Snapper.ts +5 -13
|
@@ -19,14 +19,8 @@ export declare class WalkControls extends Controls<WalkControlsEventMap> {
|
|
|
19
19
|
movementSpeed: number;
|
|
20
20
|
multiplier: number;
|
|
21
21
|
private groundFollowingSkippedFrames;
|
|
22
|
-
readonly GROUND_BOX_HALF_SIZE = 20;
|
|
23
|
-
readonly GROUND_BOX_REFRESH_THRESHOLD = 0.3;
|
|
24
22
|
private raycaster;
|
|
25
23
|
private groundObjects;
|
|
26
|
-
private _groundObjectBoxes;
|
|
27
|
-
private _activeGroundObjects;
|
|
28
|
-
private _groundBox;
|
|
29
|
-
private _groundBoxCenter;
|
|
30
24
|
private moveKeys;
|
|
31
25
|
private moveWheel;
|
|
32
26
|
private moveClock;
|
|
@@ -47,8 +41,6 @@ export declare class WalkControls extends Controls<WalkControlsEventMap> {
|
|
|
47
41
|
onWheel: (event: WheelEvent) => void;
|
|
48
42
|
onKeyDown: (event: KeyboardEvent) => void;
|
|
49
43
|
onKeyUp: (event: KeyboardEvent) => void;
|
|
50
|
-
private _rebuildGroundBox;
|
|
51
|
-
private _needsGroundBoxRebuild;
|
|
52
44
|
private updateGroundFollowing;
|
|
53
45
|
update(): void;
|
|
54
46
|
rotateCamera(delta: Vector2): void;
|
|
@@ -1,40 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Object3D, Plane, Vector3 } from "three";
|
|
2
2
|
import { TransformControls } from "three/examples/jsm/controls/TransformControls.js";
|
|
3
3
|
import type { Viewer } from "../Viewer";
|
|
4
4
|
import { PlaneHelper2 } from "../helpers/PlaneHelper2";
|
|
5
|
-
import { Snapper } from "../measurement/Snapper";
|
|
6
5
|
import { OrbitDragger } from "./OrbitDragger";
|
|
7
6
|
export declare class CuttingPlaneDragger extends OrbitDragger {
|
|
8
|
-
protected
|
|
9
|
-
protected
|
|
10
|
-
protected
|
|
11
|
-
protected snapper: Snapper;
|
|
12
|
-
protected downPosition: Vector2;
|
|
13
|
-
protected position0: Vector3;
|
|
14
|
-
protected quaternion0: Quaternion;
|
|
7
|
+
protected plane: Plane;
|
|
8
|
+
protected planeCenter: Object3D;
|
|
9
|
+
protected planeHelper: PlaneHelper2;
|
|
15
10
|
protected translate: TransformControls;
|
|
16
11
|
protected rotate: TransformControls;
|
|
17
|
-
constructor(viewer: Viewer);
|
|
12
|
+
constructor(viewer: Viewer, normal: Vector3);
|
|
18
13
|
dispose(): void;
|
|
19
14
|
transformChange: () => void;
|
|
20
15
|
translateDrag: (event: any) => void;
|
|
21
16
|
rotateDrag: (event: any) => void;
|
|
22
17
|
updatePlaneSize: () => void;
|
|
23
18
|
updateTransformCamera: () => void;
|
|
24
|
-
clearHelpers: () => void;
|
|
25
19
|
onKeyDown: (event: KeyboardEvent) => void;
|
|
26
20
|
onKeyUp: (event: KeyboardEvent) => void;
|
|
27
|
-
onPointerDown: (event: PointerEvent) => void;
|
|
28
|
-
onPointerUp: (event: PointerEvent) => void;
|
|
29
|
-
onPointerCancel: (event: PointerEvent) => void;
|
|
30
21
|
onDoubleClick: (event: PointerEvent) => void;
|
|
31
|
-
private addHelper;
|
|
32
|
-
private setActiveHelper;
|
|
33
|
-
private saveState;
|
|
34
|
-
private reset;
|
|
35
|
-
addPlane(normal: Vector3): void;
|
|
36
|
-
addPlaneX(): void;
|
|
37
|
-
addPlaneY(): void;
|
|
38
|
-
addPlaneZ(): void;
|
|
39
|
-
deleteActivePlane(): void;
|
|
40
22
|
}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { Line,
|
|
2
|
-
export declare class PlaneHelper2 extends
|
|
3
|
-
plane: Plane;
|
|
1
|
+
import { Line, Mesh } from "three";
|
|
2
|
+
export declare class PlaneHelper2 extends Line {
|
|
4
3
|
size: number;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
constructor(size?: number, color?: number, opacity?: number);
|
|
4
|
+
helper: Mesh;
|
|
5
|
+
constructor(size?: number, color?: number);
|
|
8
6
|
dispose(): void;
|
|
9
7
|
updateMatrixWorld(force: boolean): void;
|
|
10
|
-
getLineMaterial(): LineBasicMaterial;
|
|
11
|
-
getMeshMaterial(): MeshBasicMaterial;
|
|
12
8
|
}
|
|
@@ -10,7 +10,7 @@ export declare class Snapper {
|
|
|
10
10
|
constructor(camera: Camera, renderer: WebGLRenderer, canvas: HTMLCanvasElement);
|
|
11
11
|
isMobile(): boolean;
|
|
12
12
|
getMousePosition(event: MouseEvent, target: Vector2): Vector2;
|
|
13
|
-
getPointerIntersects(mouse: Vector2, objects: Object3D[]
|
|
13
|
+
getPointerIntersects(mouse: Vector2, objects: Object3D[]): Array<Intersection<Object3D>>;
|
|
14
14
|
getDetectRadius(point: Vector3): number;
|
|
15
15
|
getSnapPoint(mouse: Vector2, objects: Object3D[]): Vector3;
|
|
16
16
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inweb/viewer-three",
|
|
3
|
-
"version": "27.2.
|
|
3
|
+
"version": "27.2.4",
|
|
4
4
|
"description": "JavaScript library for rendering CAD and BIM files in a browser using Three.js",
|
|
5
5
|
"homepage": "https://cloud.opendesign.com/docs/index.html",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"docs": "typedoc"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@inweb/client": "~27.2.
|
|
39
|
-
"@inweb/eventemitter2": "~27.2.
|
|
40
|
-
"@inweb/markup": "~27.2.
|
|
41
|
-
"@inweb/viewer-core": "~27.2.
|
|
38
|
+
"@inweb/client": "~27.2.4",
|
|
39
|
+
"@inweb/eventemitter2": "~27.2.4",
|
|
40
|
+
"@inweb/markup": "~27.2.4",
|
|
41
|
+
"@inweb/viewer-core": "~27.2.4"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@streamparser/json": "^0.0.22",
|
|
@@ -58,7 +58,7 @@ export class SelectionComponent implements IComponent {
|
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
onPointerUp = (event: PointerEvent) => {
|
|
61
|
-
if (!event.isPrimary
|
|
61
|
+
if (!event.isPrimary) return;
|
|
62
62
|
|
|
63
63
|
const upPosition = this.getMousePosition(event, new Vector2());
|
|
64
64
|
if (upPosition.distanceTo(this.downPosition) !== 0) return;
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import {
|
|
24
|
+
import { Clock, Camera, Controls, Quaternion, Vector2, Vector3, Raycaster, Object3D, MathUtils } from "three";
|
|
25
25
|
|
|
26
26
|
interface WalkControlsEventMap {
|
|
27
27
|
change: { type: "change" };
|
|
@@ -41,15 +41,8 @@ export class WalkControls extends Controls<WalkControlsEventMap> {
|
|
|
41
41
|
public multiplier = 3;
|
|
42
42
|
private groundFollowingSkippedFrames = 0;
|
|
43
43
|
|
|
44
|
-
readonly GROUND_BOX_HALF_SIZE = 20;
|
|
45
|
-
readonly GROUND_BOX_REFRESH_THRESHOLD = 0.3;
|
|
46
|
-
|
|
47
44
|
private raycaster: Raycaster;
|
|
48
45
|
private groundObjects: Object3D[];
|
|
49
|
-
private _groundObjectBoxes = new Map<Object3D, Box3>();
|
|
50
|
-
private _activeGroundObjects: Object3D[] = [];
|
|
51
|
-
private _groundBox = new Box3();
|
|
52
|
-
private _groundBoxCenter = new Vector3();
|
|
53
46
|
|
|
54
47
|
private moveKeys: Set<string>;
|
|
55
48
|
private moveWheel = 0;
|
|
@@ -71,12 +64,6 @@ export class WalkControls extends Controls<WalkControlsEventMap> {
|
|
|
71
64
|
this.camera = camera;
|
|
72
65
|
|
|
73
66
|
this.groundObjects = groundObjects;
|
|
74
|
-
for (const obj of groundObjects) {
|
|
75
|
-
this._groundObjectBoxes.set(obj, new Box3().setFromObject(obj));
|
|
76
|
-
}
|
|
77
|
-
const pos = this.object.position;
|
|
78
|
-
this._rebuildGroundBox(pos);
|
|
79
|
-
|
|
80
67
|
this.raycaster = new Raycaster();
|
|
81
68
|
this.raycaster.near = 0;
|
|
82
69
|
this.raycaster.far = this.EYE_HEIGHT + this.FAILING_DISTANCE;
|
|
@@ -188,47 +175,14 @@ export class WalkControls extends Controls<WalkControlsEventMap> {
|
|
|
188
175
|
};
|
|
189
176
|
|
|
190
177
|
onKeyUp = (event: KeyboardEvent) => {
|
|
191
|
-
if (this.moveKeys.delete(event.code))
|
|
192
|
-
if (this.moveKeys.size === 0) {
|
|
193
|
-
this._rebuildGroundBox(this.object.position);
|
|
194
|
-
}
|
|
195
|
-
this.update();
|
|
196
|
-
}
|
|
178
|
+
if (this.moveKeys.delete(event.code)) this.update();
|
|
197
179
|
};
|
|
198
180
|
|
|
199
|
-
private _rebuildGroundBox(center: Vector3) {
|
|
200
|
-
const h = this.GROUND_BOX_HALF_SIZE;
|
|
201
|
-
this._groundBoxCenter.copy(center);
|
|
202
|
-
this._groundBox.set(
|
|
203
|
-
new Vector3(center.x - h, center.y - h * 4, center.z - h),
|
|
204
|
-
new Vector3(center.x + h, center.y + h * 4, center.z + h)
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
this._activeGroundObjects = this.groundObjects.filter((obj) => {
|
|
208
|
-
const objectBox = this._groundObjectBoxes.get(obj);
|
|
209
|
-
return objectBox !== undefined && this._groundBox.intersectsBox(objectBox);
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
private _needsGroundBoxRebuild(pos: Vector3): boolean {
|
|
214
|
-
if (this._activeGroundObjects.length === 0 && this.groundObjects.length > 0) return true;
|
|
215
|
-
const threshold = this.GROUND_BOX_HALF_SIZE * this.GROUND_BOX_REFRESH_THRESHOLD;
|
|
216
|
-
return (
|
|
217
|
-
Math.abs(pos.x - this._groundBoxCenter.x) > threshold || Math.abs(pos.z - this._groundBoxCenter.z) > threshold
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
181
|
private updateGroundFollowing() {
|
|
222
|
-
const pos = this.object.position;
|
|
223
|
-
|
|
224
|
-
if (this._needsGroundBoxRebuild(pos)) {
|
|
225
|
-
this._rebuildGroundBox(pos);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
182
|
this._up.copy(this.camera.up).negate();
|
|
229
|
-
this.raycaster.set(
|
|
183
|
+
this.raycaster.set(this.object.position, this._up);
|
|
230
184
|
|
|
231
|
-
const intersects = this.raycaster.intersectObjects(this.
|
|
185
|
+
const intersects = this.raycaster.intersectObjects(this.groundObjects, false);
|
|
232
186
|
if (intersects.length > 0) {
|
|
233
187
|
const groundY = intersects[0].point.y;
|
|
234
188
|
const targetY = groundY + this.EYE_HEIGHT;
|
|
@@ -21,49 +21,46 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import {
|
|
24
|
+
import { Object3D, Plane, Vector3 } from "three";
|
|
25
25
|
import { TransformControls } from "three/examples/jsm/controls/TransformControls.js";
|
|
26
26
|
|
|
27
27
|
import type { Viewer } from "../Viewer";
|
|
28
|
-
import { STATE } from "../controls/OrbitControls.js";
|
|
29
28
|
import { PlaneHelper2 } from "../helpers/PlaneHelper2";
|
|
30
|
-
import { Snapper } from "../measurement/Snapper";
|
|
31
29
|
import { OrbitDragger } from "./OrbitDragger";
|
|
32
30
|
|
|
33
31
|
export class CuttingPlaneDragger extends OrbitDragger {
|
|
34
|
-
protected
|
|
35
|
-
protected
|
|
36
|
-
protected
|
|
37
|
-
protected snapper: Snapper;
|
|
38
|
-
protected downPosition: Vector2;
|
|
39
|
-
protected position0: Vector3;
|
|
40
|
-
protected quaternion0: Quaternion;
|
|
32
|
+
protected plane: Plane;
|
|
33
|
+
protected planeCenter: Object3D;
|
|
34
|
+
protected planeHelper: PlaneHelper2;
|
|
41
35
|
protected translate: TransformControls;
|
|
42
36
|
protected rotate: TransformControls;
|
|
43
37
|
|
|
44
|
-
constructor(viewer: Viewer) {
|
|
38
|
+
constructor(viewer: Viewer, normal: Vector3) {
|
|
45
39
|
super(viewer);
|
|
46
40
|
|
|
47
|
-
|
|
41
|
+
const extentsSize = viewer.extents.getSize(new Vector3()).length() || 1;
|
|
42
|
+
const extentsCenter = viewer.extents.getCenter(new Vector3());
|
|
43
|
+
const constant = -extentsCenter.dot(normal);
|
|
48
44
|
|
|
49
|
-
this.
|
|
50
|
-
this.clippingPlanes.forEach((plane) => this.addHelper(plane));
|
|
45
|
+
this.plane = new Plane(normal, constant);
|
|
51
46
|
|
|
52
|
-
|
|
47
|
+
if (!viewer.renderer.clippingPlanes) viewer.renderer.clippingPlanes = [];
|
|
48
|
+
viewer.renderer.clippingPlanes.push(this.plane);
|
|
53
49
|
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
50
|
+
this.planeCenter = new Object3D();
|
|
51
|
+
this.planeCenter.position.copy(extentsCenter);
|
|
52
|
+
this.planeCenter.quaternion.setFromUnitVectors(new Vector3(0, 0, -1), normal);
|
|
53
|
+
this.viewer.helpers.add(this.planeCenter);
|
|
56
54
|
|
|
57
|
-
this.
|
|
58
|
-
this.
|
|
59
|
-
this.quaternion0 = new Quaternion();
|
|
55
|
+
this.planeHelper = new PlaneHelper2(extentsSize);
|
|
56
|
+
this.planeCenter.add(this.planeHelper);
|
|
60
57
|
|
|
61
58
|
this.translate = new TransformControls(viewer.camera, viewer.canvas);
|
|
62
|
-
this.translate.setMode("translate");
|
|
63
59
|
this.translate.setSpace("local");
|
|
64
60
|
this.translate.showX = false;
|
|
65
61
|
this.translate.showY = false;
|
|
66
62
|
this.translate.showZ = true;
|
|
63
|
+
this.translate.attach(this.planeCenter);
|
|
67
64
|
this.translate.addEventListener("change", this.transformChange);
|
|
68
65
|
this.translate.addEventListener("dragging-changed", this.translateDrag);
|
|
69
66
|
this.viewer.helpers.add(this.translate.getHelper());
|
|
@@ -74,20 +71,15 @@ export class CuttingPlaneDragger extends OrbitDragger {
|
|
|
74
71
|
this.rotate.showX = true;
|
|
75
72
|
this.rotate.showY = true;
|
|
76
73
|
this.rotate.showZ = false;
|
|
74
|
+
this.rotate.attach(this.planeCenter);
|
|
77
75
|
this.rotate.addEventListener("change", this.transformChange);
|
|
78
76
|
this.rotate.addEventListener("dragging-changed", this.rotateDrag);
|
|
79
77
|
this.viewer.helpers.add(this.rotate.getHelper());
|
|
80
78
|
|
|
81
|
-
this.setActiveHelper(this.helpers[this.helpers.length - 1]);
|
|
82
|
-
|
|
83
79
|
this.viewer.addEventListener("explode", this.updatePlaneSize);
|
|
84
80
|
this.viewer.addEventListener("show", this.updatePlaneSize);
|
|
85
81
|
this.viewer.addEventListener("showall", this.updatePlaneSize);
|
|
86
82
|
this.viewer.addEventListener("changecameramode", this.updateTransformCamera);
|
|
87
|
-
this.viewer.addEventListener("clearslices", this.clearHelpers);
|
|
88
|
-
this.viewer.canvas.addEventListener("pointerdown", this.onPointerDown, true);
|
|
89
|
-
this.viewer.canvas.addEventListener("pointerup", this.onPointerUp, true);
|
|
90
|
-
this.viewer.canvas.addEventListener("pointercancel", this.onPointerCancel, true);
|
|
91
83
|
this.viewer.canvas.addEventListener("dblclick", this.onDoubleClick, true);
|
|
92
84
|
window.addEventListener("keydown", this.onKeyDown);
|
|
93
85
|
window.addEventListener("keyup", this.onKeyUp);
|
|
@@ -100,10 +92,6 @@ export class CuttingPlaneDragger extends OrbitDragger {
|
|
|
100
92
|
this.viewer.removeEventListener("show", this.updatePlaneSize);
|
|
101
93
|
this.viewer.removeEventListener("showall", this.updatePlaneSize);
|
|
102
94
|
this.viewer.removeEventListener("changecameramode", this.updateTransformCamera);
|
|
103
|
-
this.viewer.removeEventListener("clearslices", this.clearHelpers);
|
|
104
|
-
this.viewer.canvas.removeEventListener("pointerdown", this.onPointerDown, true);
|
|
105
|
-
this.viewer.canvas.removeEventListener("pointerup", this.onPointerUp, true);
|
|
106
|
-
this.viewer.canvas.removeEventListener("pointercancel", this.onPointerCancel, true);
|
|
107
95
|
this.viewer.canvas.removeEventListener("dblclick", this.onDoubleClick, true);
|
|
108
96
|
window.removeEventListener("keydown", this.onKeyDown);
|
|
109
97
|
window.removeEventListener("keyup", this.onKeyUp);
|
|
@@ -120,26 +108,21 @@ export class CuttingPlaneDragger extends OrbitDragger {
|
|
|
120
108
|
this.rotate.detach();
|
|
121
109
|
this.rotate.dispose();
|
|
122
110
|
|
|
123
|
-
this.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
this.
|
|
111
|
+
this.planeHelper.removeFromParent();
|
|
112
|
+
this.planeHelper.dispose();
|
|
113
|
+
|
|
114
|
+
this.planeCenter.removeFromParent();
|
|
115
|
+
|
|
116
|
+
// this.viewer.renderer.clippingPlanes = this.viewer.renderer.clippingPlanes.filter((plane) => plane !== this.plane);
|
|
117
|
+
// this.viewer.update();
|
|
129
118
|
|
|
130
119
|
super.dispose();
|
|
131
120
|
}
|
|
132
121
|
|
|
133
122
|
transformChange = () => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const plane = this.activeHelper.plane;
|
|
137
|
-
plane.normal.copy(new Vector3(0, 0, -1)).applyQuaternion(this.activeHelper.quaternion);
|
|
138
|
-
plane.constant = -this.activeHelper.position.dot(plane.normal);
|
|
139
|
-
|
|
123
|
+
this.plane.normal.copy(new Vector3(0, 0, -1)).applyQuaternion(this.planeCenter.quaternion);
|
|
124
|
+
this.plane.constant = -this.planeCenter.position.dot(this.plane.normal);
|
|
140
125
|
this.viewer.update();
|
|
141
|
-
|
|
142
|
-
this.changed = true; // <- cancel context menu
|
|
143
126
|
};
|
|
144
127
|
|
|
145
128
|
translateDrag = (event) => {
|
|
@@ -153,170 +136,27 @@ export class CuttingPlaneDragger extends OrbitDragger {
|
|
|
153
136
|
};
|
|
154
137
|
|
|
155
138
|
updatePlaneSize = () => {
|
|
156
|
-
|
|
157
|
-
this.helpers.forEach((planeHelper) => (planeHelper.size = extentsSize));
|
|
139
|
+
this.planeHelper.size = this.viewer.extents.getSize(new Vector3()).length() || 1;
|
|
158
140
|
this.viewer.update();
|
|
159
141
|
};
|
|
160
142
|
|
|
161
143
|
updateTransformCamera = () => {
|
|
162
144
|
this.translate.camera = this.viewer.camera;
|
|
163
145
|
this.rotate.camera = this.viewer.camera;
|
|
164
|
-
this.snapper.camera = this.viewer.camera;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
clearHelpers = () => {
|
|
168
|
-
this.setActiveHelper();
|
|
169
|
-
|
|
170
|
-
this.helpers.forEach((helper) => {
|
|
171
|
-
helper.removeFromParent();
|
|
172
|
-
helper.dispose();
|
|
173
|
-
});
|
|
174
|
-
this.helpers = [];
|
|
175
|
-
|
|
176
|
-
this.viewer.update();
|
|
177
146
|
};
|
|
178
147
|
|
|
179
148
|
onKeyDown = (event: KeyboardEvent) => {
|
|
180
149
|
if (event.key === "Shift") this.rotate.setRotationSnap(Math.PI / 4);
|
|
181
|
-
if (event.key === "Delete" || event.key === "Backspace") this.deleteActivePlane();
|
|
182
|
-
if (event.key === "Escape" && (this.translate.dragging || this.rotate.dragging)) this.reset();
|
|
183
150
|
};
|
|
184
151
|
|
|
185
152
|
onKeyUp = (event: KeyboardEvent) => {
|
|
186
153
|
if (event.key === "Shift") this.rotate.setRotationSnap(null);
|
|
187
154
|
};
|
|
188
155
|
|
|
189
|
-
onPointerDown = (event: PointerEvent) => {
|
|
190
|
-
if (event.button !== 0 || !event.isPrimary) return;
|
|
191
|
-
|
|
192
|
-
this.snapper.getMousePosition(event, this.downPosition);
|
|
193
|
-
this.saveState();
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
onPointerUp = (event: PointerEvent) => {
|
|
197
|
-
if (event.button !== 0) return;
|
|
198
|
-
|
|
199
|
-
const upPosition = this.snapper.getMousePosition(event, new Vector2());
|
|
200
|
-
if (upPosition.distanceTo(this.downPosition) !== 0) return;
|
|
201
|
-
|
|
202
|
-
const intersects = this.snapper.getPointerIntersects(upPosition, this.helpers, true, false);
|
|
203
|
-
if (intersects.length === 0) return;
|
|
204
|
-
|
|
205
|
-
this.setActiveHelper(intersects[0].object.parent as PlaneHelper2);
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
onPointerCancel = (event: PointerEvent) => {
|
|
209
|
-
this.viewer.canvas.dispatchEvent(new PointerEvent("pointerup", event));
|
|
210
|
-
};
|
|
211
|
-
|
|
212
156
|
onDoubleClick = (event: PointerEvent) => {
|
|
213
|
-
if (!this.activeHelper) return;
|
|
214
|
-
|
|
215
|
-
const mousePosition = this.snapper.getMousePosition(event, new Vector2());
|
|
216
|
-
|
|
217
|
-
const intersects = this.snapper.getPointerIntersects(mousePosition, [this.activeHelper], true, false);
|
|
218
|
-
if (intersects.length === 0) return;
|
|
219
|
-
|
|
220
|
-
this.activeHelper.rotateOnAxis(new Vector3(0, 1, 0), Math.PI);
|
|
221
|
-
this.transformChange();
|
|
222
|
-
|
|
223
157
|
event.stopPropagation();
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
private addHelper(plane: Plane): PlaneHelper2 {
|
|
227
|
-
const extentsSize = this.viewer.extents.getSize(new Vector3()).length() || 1;
|
|
228
|
-
const extentsCenter = this.viewer.extents.getCenter(new Vector3());
|
|
229
|
-
|
|
230
|
-
const helper = new PlaneHelper2(extentsSize);
|
|
231
|
-
helper.plane = plane;
|
|
232
|
-
helper.position.copy(plane.projectPoint(extentsCenter, new Vector3()));
|
|
233
|
-
helper.quaternion.setFromUnitVectors(new Vector3(0, 0, -1), plane.normal);
|
|
234
|
-
|
|
235
|
-
this.helpers.push(helper);
|
|
236
|
-
this.viewer.helpers.add(helper);
|
|
237
|
-
|
|
238
|
-
return helper;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
private setActiveHelper(helper?: PlaneHelper2) {
|
|
242
|
-
if (helper === this.activeHelper) return;
|
|
243
|
-
|
|
244
|
-
if (this.activeHelper) {
|
|
245
|
-
this.activeHelper.getLineMaterial().color.setHex(0xf0f0f0);
|
|
246
|
-
this.activeHelper.getMeshMaterial().opacity = 0.15;
|
|
247
|
-
|
|
248
|
-
this.translate.detach();
|
|
249
|
-
this.rotate.detach();
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
this.activeHelper = helper;
|
|
253
|
-
|
|
254
|
-
if (this.activeHelper) {
|
|
255
|
-
this.activeHelper.getLineMaterial().color.setHex(0xd0d0d0);
|
|
256
|
-
this.activeHelper.getMeshMaterial().opacity = 0.3;
|
|
257
|
-
|
|
258
|
-
this.translate.attach(this.activeHelper);
|
|
259
|
-
this.rotate.attach(this.activeHelper);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
this.viewer.update();
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
private saveState() {
|
|
266
|
-
if (!this.activeHelper) return;
|
|
267
|
-
|
|
268
|
-
this.position0.copy(this.activeHelper.position);
|
|
269
|
-
this.quaternion0.copy(this.activeHelper.quaternion);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
private reset() {
|
|
273
|
-
if (!this.activeHelper) return;
|
|
274
|
-
|
|
275
|
-
this.translate.dragging = false;
|
|
276
|
-
this.rotate.dragging = false;
|
|
277
|
-
this.orbit.state = STATE.NONE;
|
|
278
|
-
|
|
279
|
-
this.activeHelper.position.copy(this.position0);
|
|
280
|
-
this.activeHelper.quaternion.copy(this.quaternion0);
|
|
281
158
|
|
|
159
|
+
this.planeCenter.rotateOnAxis(new Vector3(0, 1, 0), Math.PI);
|
|
282
160
|
this.transformChange();
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
addPlane(normal: Vector3) {
|
|
286
|
-
const extentsCenter = this.viewer.extents.getCenter(new Vector3());
|
|
287
|
-
const constant = -extentsCenter.dot(normal);
|
|
288
|
-
|
|
289
|
-
const plane = new Plane(normal, constant);
|
|
290
|
-
this.clippingPlanes.push(plane);
|
|
291
|
-
|
|
292
|
-
const helper = this.addHelper(plane);
|
|
293
|
-
this.setActiveHelper(helper);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
addPlaneX() {
|
|
297
|
-
this.addPlane(new Vector3(-1, 0, 0));
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
addPlaneY() {
|
|
301
|
-
this.addPlane(new Vector3(0, -1, 0));
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
addPlaneZ() {
|
|
305
|
-
this.addPlane(new Vector3(0, 0, -1));
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
deleteActivePlane() {
|
|
309
|
-
if (!this.activeHelper) return;
|
|
310
|
-
|
|
311
|
-
const helper = this.activeHelper;
|
|
312
|
-
|
|
313
|
-
const index = this.clippingPlanes.indexOf(helper.plane);
|
|
314
|
-
if (index !== -1) this.clippingPlanes.splice(index, 1);
|
|
315
|
-
|
|
316
|
-
this.helpers = this.helpers.filter((x) => x !== helper);
|
|
317
|
-
helper.removeFromParent();
|
|
318
|
-
helper.dispose();
|
|
319
|
-
|
|
320
|
-
this.setActiveHelper(this.helpers[this.helpers.length - 1]);
|
|
321
|
-
}
|
|
161
|
+
};
|
|
322
162
|
}
|
|
@@ -21,12 +21,13 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
+
import { Vector3 } from "three";
|
|
25
|
+
|
|
24
26
|
import type { Viewer } from "../Viewer";
|
|
25
27
|
import { CuttingPlaneDragger } from "./CuttingPlaneDragger";
|
|
26
28
|
|
|
27
29
|
export class CuttingPlaneXAxisDragger extends CuttingPlaneDragger {
|
|
28
30
|
constructor(viewer: Viewer) {
|
|
29
|
-
super(viewer);
|
|
30
|
-
this.addPlaneX();
|
|
31
|
+
super(viewer, new Vector3(-1, 0, 0));
|
|
31
32
|
}
|
|
32
33
|
}
|
|
@@ -21,12 +21,13 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
+
import { Vector3 } from "three";
|
|
25
|
+
|
|
24
26
|
import type { Viewer } from "../Viewer";
|
|
25
27
|
import { CuttingPlaneDragger } from "./CuttingPlaneDragger";
|
|
26
28
|
|
|
27
29
|
export class CuttingPlaneYAxisDragger extends CuttingPlaneDragger {
|
|
28
30
|
constructor(viewer: Viewer) {
|
|
29
|
-
super(viewer);
|
|
30
|
-
this.addPlaneY();
|
|
31
|
+
super(viewer, new Vector3(0, -1, 0));
|
|
31
32
|
}
|
|
32
33
|
}
|
|
@@ -21,12 +21,13 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
+
import { Vector3 } from "three";
|
|
25
|
+
|
|
24
26
|
import type { Viewer } from "../Viewer";
|
|
25
27
|
import { CuttingPlaneDragger } from "./CuttingPlaneDragger";
|
|
26
28
|
|
|
27
29
|
export class CuttingPlaneZAxisDragger extends CuttingPlaneDragger {
|
|
28
30
|
constructor(viewer: Viewer) {
|
|
29
|
-
super(viewer);
|
|
30
|
-
this.addPlaneZ();
|
|
31
|
+
super(viewer, new Vector3(0, 0, -1));
|
|
31
32
|
}
|
|
32
33
|
}
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
|
|
24
24
|
import { IDraggersRegistry, draggersRegistry } from "@inweb/viewer-core";
|
|
25
25
|
|
|
26
|
-
import { CuttingPlaneDragger } from "./CuttingPlaneDragger";
|
|
27
26
|
import { CuttingPlaneXAxisDragger } from "./CuttingPlaneXAxis";
|
|
28
27
|
import { CuttingPlaneYAxisDragger } from "./CuttingPlaneYAxis";
|
|
29
28
|
import { CuttingPlaneZAxisDragger } from "./CuttingPlaneZAxis";
|
|
@@ -85,7 +84,6 @@ draggers.registerDragger("Pan", (viewer) => new PanDragger(viewer));
|
|
|
85
84
|
draggers.registerDragger("Orbit", (viewer) => new OrbitDragger(viewer));
|
|
86
85
|
draggers.registerDragger("Zoom", (viewer) => new ZoomDragger(viewer));
|
|
87
86
|
draggers.registerDragger("MeasureLine", (viewer) => new MeasureLineDragger(viewer));
|
|
88
|
-
draggers.registerDragger("CuttingPlane", (viewer) => new CuttingPlaneDragger(viewer));
|
|
89
87
|
draggers.registerDragger("CuttingPlaneXAxis", (viewer) => new CuttingPlaneXAxisDragger(viewer));
|
|
90
88
|
draggers.registerDragger("CuttingPlaneYAxis", (viewer) => new CuttingPlaneYAxisDragger(viewer));
|
|
91
89
|
draggers.registerDragger("CuttingPlaneZAxis", (viewer) => new CuttingPlaneZAxisDragger(viewer));
|