@inweb/viewer-three 25.9.8 → 25.10.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/README.md +26 -18
- package/dist/viewer-three.js +10315 -6179
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +3 -2
- package/dist/viewer-three.module.js +1881 -322
- package/dist/viewer-three.module.js.map +1 -1
- package/lib/Viewer/IDisposable.d.ts +6 -0
- package/lib/Viewer/Viewer.d.ts +113 -14
- package/lib/Viewer/commands/ApplyModelTransform.d.ts +1 -0
- package/lib/Viewer/commands/ClearMarkup.d.ts +1 -0
- package/lib/Viewer/commands/ClearSlices.d.ts +1 -0
- package/lib/Viewer/commands/CreatePreview.d.ts +1 -0
- package/lib/Viewer/commands/Explode.d.ts +1 -0
- package/lib/Viewer/commands/GetDefaultViewPositions.d.ts +1 -0
- package/lib/Viewer/commands/GetModels.d.ts +1 -0
- package/lib/Viewer/commands/GetSelected.d.ts +1 -0
- package/lib/Viewer/commands/HideSelected.d.ts +1 -0
- package/lib/Viewer/commands/IsolateSelected.d.ts +1 -0
- package/lib/Viewer/commands/RegenerateAll.d.ts +1 -0
- package/lib/Viewer/commands/ResetView.d.ts +1 -0
- package/lib/Viewer/commands/SelectModel.d.ts +1 -0
- package/lib/Viewer/commands/SetActiveDragger.d.ts +1 -0
- package/lib/Viewer/commands/SetDefaultViewPosition.d.ts +13 -0
- package/lib/Viewer/commands/SetMarkupColor.d.ts +1 -0
- package/lib/Viewer/commands/SetSelected.d.ts +1 -0
- package/lib/Viewer/commands/ShowAll.d.ts +1 -0
- package/lib/Viewer/commands/Unselect.d.ts +1 -0
- package/lib/Viewer/commands/ZoomToExtents.d.ts +1 -0
- package/lib/Viewer/commands/ZoomToObjects.d.ts +1 -0
- package/lib/Viewer/commands/ZoomToSelected.d.ts +1 -0
- package/lib/Viewer/commands/index.d.ts +22 -0
- package/lib/Viewer/components/AxesHelperComponent.d.ts +10 -0
- package/lib/Viewer/components/BackgroundComponent.d.ts +4 -4
- package/lib/Viewer/components/{DefaultCameraPositionComponent.d.ts → DefaultPositionComponent.d.ts} +3 -2
- package/lib/Viewer/components/ExtentsComponent.d.ts +8 -0
- package/lib/Viewer/components/ExtentsHelperComponent.d.ts +9 -0
- package/lib/Viewer/components/LightComponent.d.ts +5 -5
- package/lib/Viewer/components/RenderLoopComponent.d.ts +3 -3
- package/lib/Viewer/components/ResizeCanvasComponent.d.ts +2 -2
- package/lib/Viewer/components/SelectionComponent.d.ts +19 -0
- package/lib/Viewer/components/ViewPositionComponent.d.ts +31 -0
- package/lib/Viewer/components/WCSHelperComponent.d.ts +9 -0
- package/lib/Viewer/controls/WalkControls.d.ts +26 -0
- package/lib/Viewer/draggers/CuttingPlaneDragger.d.ts +17 -0
- package/lib/Viewer/draggers/CuttingPlaneXAxis.d.ts +5 -0
- package/lib/Viewer/draggers/CuttingPlaneYAxis.d.ts +5 -0
- package/lib/Viewer/draggers/CuttingPlaneZAxis.d.ts +5 -0
- package/lib/Viewer/draggers/OrbitDragger.d.ts +9 -5
- package/lib/Viewer/draggers/WalkDragger.d.ts +7 -33
- package/lib/Viewer/helpers/PlaneHelper.d.ts +11 -0
- package/lib/Viewer/helpers/WCSHelper.d.ts +10 -0
- package/lib/Viewer/loaders/GLTFLoadingManager.d.ts +3 -3
- package/lib/index.d.ts +1 -0
- package/package.json +7 -6
- package/src/Viewer/IDisposable.ts +29 -0
- package/src/Viewer/Viewer.ts +218 -49
- package/src/Viewer/commands/ApplyModelTransform.ts +33 -0
- package/src/Viewer/commands/ClearMarkup.ts +29 -0
- package/src/Viewer/commands/ClearSlices.ts +32 -0
- package/src/Viewer/commands/CreatePreview.ts +32 -0
- package/src/Viewer/commands/Explode.ts +83 -0
- package/src/Viewer/commands/GetDefaultViewPositions.ts +31 -0
- package/src/Viewer/commands/GetModels.ts +32 -0
- package/src/Viewer/commands/GetSelected.ts +31 -0
- package/src/Viewer/commands/HideSelected.ts +40 -0
- package/src/Viewer/commands/IsolateSelected.ts +50 -0
- package/src/Viewer/commands/RegenerateAll.ts +32 -0
- package/src/Viewer/commands/ResetView.ts +41 -0
- package/src/Viewer/commands/SelectModel.ts +32 -0
- package/src/Viewer/commands/SetActiveDragger.ts +29 -0
- package/src/Viewer/commands/SetDefaultViewPosition.ts +83 -0
- package/src/Viewer/commands/SetMarkupColor.ts +30 -0
- package/src/Viewer/commands/SetSelected.ts +44 -0
- package/src/Viewer/commands/ShowAll.ts +34 -0
- package/src/Viewer/commands/Unselect.ts +37 -0
- package/src/Viewer/commands/ZoomToExtents.ts +47 -0
- package/src/Viewer/commands/ZoomToObjects.ts +55 -0
- package/src/Viewer/commands/ZoomToSelected.ts +51 -0
- package/src/Viewer/commands/index.ts +45 -0
- package/src/Viewer/components/AxesHelperComponent.ts +70 -0
- package/src/Viewer/components/BackgroundComponent.ts +9 -7
- package/src/Viewer/components/{DefaultCameraPositionComponent.ts → DefaultPositionComponent.ts} +11 -22
- package/src/Viewer/components/ExtentsComponent.ts +54 -0
- package/src/Viewer/components/ExtentsHelperComponent.ts +58 -0
- package/src/Viewer/components/LightComponent.ts +14 -10
- package/src/Viewer/components/RenderLoopComponent.ts +6 -6
- package/src/Viewer/components/ResizeCanvasComponent.ts +2 -2
- package/src/Viewer/components/SelectionComponent.ts +132 -0
- package/src/Viewer/components/ViewPositionComponent.ts +165 -0
- package/src/Viewer/components/WCSHelperComponent.ts +46 -0
- package/src/Viewer/controls/WalkControls.ts +221 -0
- package/src/Viewer/draggers/CuttingPlaneDragger.ts +110 -0
- package/src/Viewer/draggers/CuttingPlaneXAxis.ts +33 -0
- package/src/Viewer/draggers/CuttingPlaneYAxis.ts +33 -0
- package/src/Viewer/draggers/CuttingPlaneZAxis.ts +33 -0
- package/src/Viewer/draggers/OrbitDragger.ts +47 -22
- package/src/Viewer/draggers/PanDragger.ts +4 -3
- package/src/Viewer/draggers/WalkDragger.ts +27 -216
- package/src/Viewer/draggers/ZoomDragger.ts +4 -3
- package/src/Viewer/helpers/PlaneHelper.ts +99 -0
- package/src/Viewer/helpers/WCSHelper.ts +119 -0
- package/src/Viewer/loaders/GLTFLoadingManager.ts +6 -6
- package/src/index.ts +2 -0
- package/lib/Viewer/IComponent.d.ts +0 -3
- package/lib/Viewer/components/ObjectSelectionComponent.d.ts +0 -16
- package/lib/Viewer/draggers/ClippingPlaneDragger.d.ts +0 -17
- package/src/Viewer/IComponent.ts +0 -3
- package/src/Viewer/components/ObjectSelectionComponent.ts +0 -105
- package/src/Viewer/draggers/ClippingPlaneDragger.ts +0 -120
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
// This software and its documentation and related materials are owned by
|
|
6
|
+
// the Alliance. The software may only be incorporated into application
|
|
7
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
+
// protected by copyright law and international treaty provisions. Application
|
|
12
|
+
// programs incorporating this software must include the following statement
|
|
13
|
+
// with their copyright notices:
|
|
14
|
+
//
|
|
15
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
+
// license agreement with Open Design Alliance.
|
|
17
|
+
// Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
|
|
18
|
+
// All rights reserved.
|
|
19
|
+
//
|
|
20
|
+
// By use of this software, its documentation or related materials, you
|
|
21
|
+
// acknowledge and accept the above terms.
|
|
22
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
import { Object3D, Plane, Vector3 } from "three";
|
|
25
|
+
import { TransformControls } from "three/examples/jsm/controls/TransformControls.js";
|
|
26
|
+
|
|
27
|
+
import type { Viewer } from "../Viewer";
|
|
28
|
+
import { PlaneHelper } from "../helpers/PlaneHelper";
|
|
29
|
+
import { OrbitDragger } from "./OrbitDragger";
|
|
30
|
+
|
|
31
|
+
export class CuttingPlaneDragger extends OrbitDragger {
|
|
32
|
+
protected plane: Plane;
|
|
33
|
+
protected planeCenter: Object3D;
|
|
34
|
+
protected planeHelper: PlaneHelper;
|
|
35
|
+
protected transform: TransformControls;
|
|
36
|
+
|
|
37
|
+
constructor(viewer: Viewer, normal: Vector3, color: number) {
|
|
38
|
+
super(viewer);
|
|
39
|
+
|
|
40
|
+
const size = viewer.extents.getSize(new Vector3()).length();
|
|
41
|
+
const center = viewer.extents.getCenter(new Vector3());
|
|
42
|
+
const constant = -center.dot(normal);
|
|
43
|
+
|
|
44
|
+
this.plane = new Plane(normal, constant);
|
|
45
|
+
|
|
46
|
+
if (!viewer.renderer.clippingPlanes) viewer.renderer.clippingPlanes = [];
|
|
47
|
+
viewer.renderer.clippingPlanes.push(this.plane);
|
|
48
|
+
|
|
49
|
+
this.planeHelper = new PlaneHelper(this.plane, size, color, center);
|
|
50
|
+
this.viewer.helpers.add(this.planeHelper);
|
|
51
|
+
|
|
52
|
+
this.planeCenter = new Object3D();
|
|
53
|
+
this.planeCenter.position.copy(viewer.extents.getCenter(new Vector3()));
|
|
54
|
+
this.viewer.helpers.add(this.planeCenter);
|
|
55
|
+
|
|
56
|
+
this.transform = new TransformControls(viewer.camera, viewer.canvas);
|
|
57
|
+
this.transform.showX = !!normal.x;
|
|
58
|
+
this.transform.showY = !!normal.y;
|
|
59
|
+
this.transform.showZ = !!normal.z;
|
|
60
|
+
this.transform.attach(this.planeCenter);
|
|
61
|
+
this.transform.addEventListener("change", this.transformChange);
|
|
62
|
+
this.transform.addEventListener("dragging-changed", this.transformDrag);
|
|
63
|
+
this.viewer.helpers.add(this.transform);
|
|
64
|
+
|
|
65
|
+
this.viewer.on("explode", this.viewerExplode);
|
|
66
|
+
this.viewer.canvas.addEventListener("dblclick", this.onDoubleClick, true);
|
|
67
|
+
this.viewer.update();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
override dispose() {
|
|
71
|
+
this.viewer.off("explode", this.viewerExplode);
|
|
72
|
+
this.viewer.canvas.removeEventListener("dblclick", this.onDoubleClick, true);
|
|
73
|
+
|
|
74
|
+
this.transform.removeEventListener("change", this.transformChange);
|
|
75
|
+
this.transform.removeEventListener("dragging-changed", this.transformDrag);
|
|
76
|
+
this.transform.removeFromParent();
|
|
77
|
+
this.transform.dispose();
|
|
78
|
+
|
|
79
|
+
this.planeHelper.removeFromParent();
|
|
80
|
+
this.planeHelper.dispose();
|
|
81
|
+
|
|
82
|
+
this.planeCenter.removeFromParent();
|
|
83
|
+
|
|
84
|
+
// this.viewer.renderer.clippingPlanes = this.viewer.renderer.clippingPlanes.filter((plane) => plane !== this.plane);
|
|
85
|
+
// this.viewer.update();
|
|
86
|
+
|
|
87
|
+
super.dispose();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
transformChange = () => {
|
|
91
|
+
this.plane.constant = -this.planeCenter.position.dot(this.plane.normal);
|
|
92
|
+
this.viewer.update();
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
transformDrag = (event) => {
|
|
96
|
+
this.orbit.enabled = !event.value;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
viewerExplode = () => {
|
|
100
|
+
this.planeHelper.size = this.viewer.extents.getSize(new Vector3()).length();
|
|
101
|
+
this.viewer.update();
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
onDoubleClick = (event: PointerEvent) => {
|
|
105
|
+
event.stopPropagation();
|
|
106
|
+
|
|
107
|
+
this.plane.negate();
|
|
108
|
+
this.viewer.update();
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
// This software and its documentation and related materials are owned by
|
|
6
|
+
// the Alliance. The software may only be incorporated into application
|
|
7
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
+
// protected by copyright law and international treaty provisions. Application
|
|
12
|
+
// programs incorporating this software must include the following statement
|
|
13
|
+
// with their copyright notices:
|
|
14
|
+
//
|
|
15
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
+
// license agreement with Open Design Alliance.
|
|
17
|
+
// Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
|
|
18
|
+
// All rights reserved.
|
|
19
|
+
//
|
|
20
|
+
// By use of this software, its documentation or related materials, you
|
|
21
|
+
// acknowledge and accept the above terms.
|
|
22
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
import { Vector3 } from "three";
|
|
25
|
+
|
|
26
|
+
import type { Viewer } from "../Viewer";
|
|
27
|
+
import { CuttingPlaneDragger } from "./CuttingPlaneDragger";
|
|
28
|
+
|
|
29
|
+
export class CuttingPlaneXAxisDragger extends CuttingPlaneDragger {
|
|
30
|
+
constructor(viewer: Viewer) {
|
|
31
|
+
super(viewer, new Vector3(1, 0, 0), 0xff0000);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
// This software and its documentation and related materials are owned by
|
|
6
|
+
// the Alliance. The software may only be incorporated into application
|
|
7
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
+
// protected by copyright law and international treaty provisions. Application
|
|
12
|
+
// programs incorporating this software must include the following statement
|
|
13
|
+
// with their copyright notices:
|
|
14
|
+
//
|
|
15
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
+
// license agreement with Open Design Alliance.
|
|
17
|
+
// Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
|
|
18
|
+
// All rights reserved.
|
|
19
|
+
//
|
|
20
|
+
// By use of this software, its documentation or related materials, you
|
|
21
|
+
// acknowledge and accept the above terms.
|
|
22
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
import { Vector3 } from "three";
|
|
25
|
+
|
|
26
|
+
import type { Viewer } from "../Viewer";
|
|
27
|
+
import { CuttingPlaneDragger } from "./CuttingPlaneDragger";
|
|
28
|
+
|
|
29
|
+
export class CuttingPlaneYAxisDragger extends CuttingPlaneDragger {
|
|
30
|
+
constructor(viewer: Viewer) {
|
|
31
|
+
super(viewer, new Vector3(0, 1, 0), 0x00ff00);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
// This software and its documentation and related materials are owned by
|
|
6
|
+
// the Alliance. The software may only be incorporated into application
|
|
7
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
+
// protected by copyright law and international treaty provisions. Application
|
|
12
|
+
// programs incorporating this software must include the following statement
|
|
13
|
+
// with their copyright notices:
|
|
14
|
+
//
|
|
15
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
+
// license agreement with Open Design Alliance.
|
|
17
|
+
// Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
|
|
18
|
+
// All rights reserved.
|
|
19
|
+
//
|
|
20
|
+
// By use of this software, its documentation or related materials, you
|
|
21
|
+
// acknowledge and accept the above terms.
|
|
22
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
import { Vector3 } from "three";
|
|
25
|
+
|
|
26
|
+
import type { Viewer } from "../Viewer";
|
|
27
|
+
import { CuttingPlaneDragger } from "./CuttingPlaneDragger";
|
|
28
|
+
|
|
29
|
+
export class CuttingPlaneZAxisDragger extends CuttingPlaneDragger {
|
|
30
|
+
constructor(viewer: Viewer) {
|
|
31
|
+
super(viewer, new Vector3(0, 0, 1), 0x0000ff);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -21,41 +21,66 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import {
|
|
25
|
-
import * as THREE from "three";
|
|
24
|
+
import { MOUSE, TOUCH } from "three";
|
|
26
25
|
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
|
26
|
+
|
|
27
|
+
import type { IDisposable } from "../IDisposable";
|
|
27
28
|
import type { Viewer } from "../Viewer";
|
|
28
29
|
|
|
29
|
-
export class OrbitDragger
|
|
30
|
-
|
|
30
|
+
export class OrbitDragger implements IDisposable {
|
|
31
|
+
protected viewer: Viewer;
|
|
32
|
+
protected orbit: OrbitControls;
|
|
33
|
+
protected changed: boolean;
|
|
31
34
|
|
|
32
35
|
constructor(viewer: Viewer) {
|
|
33
|
-
|
|
34
|
-
this.mouseButtons = { LEFT:
|
|
35
|
-
this.touches = { ONE:
|
|
36
|
-
this.screenSpacePanning = true;
|
|
37
|
-
this.rotateSpeed = 0.33;
|
|
36
|
+
this.orbit = new OrbitControls(viewer.camera, viewer.canvas);
|
|
37
|
+
this.orbit.mouseButtons = { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.PAN, RIGHT: MOUSE.PAN };
|
|
38
|
+
this.orbit.touches = { ONE: TOUCH.ROTATE, TWO: TOUCH.DOLLY_PAN };
|
|
39
|
+
this.orbit.screenSpacePanning = true;
|
|
40
|
+
this.orbit.rotateSpeed = 0.33;
|
|
41
|
+
this.orbit.addEventListener("start", this.controlsStart);
|
|
42
|
+
this.orbit.addEventListener("change", this.controlsChange);
|
|
43
|
+
this.changed = false;
|
|
38
44
|
this.viewer = viewer;
|
|
39
|
-
this.viewer.
|
|
40
|
-
this.
|
|
45
|
+
this.viewer.on("geometryend", this.updateControls);
|
|
46
|
+
this.viewer.on("viewposition", this.updateControls);
|
|
47
|
+
this.viewer.on("zoom", this.updateControls);
|
|
48
|
+
this.viewer.on("contextmenu", this.stopContextMenu);
|
|
49
|
+
this.updateControls();
|
|
41
50
|
}
|
|
42
51
|
|
|
43
|
-
|
|
44
|
-
this.
|
|
45
|
-
this.viewer.
|
|
46
|
-
|
|
52
|
+
dispose(): void {
|
|
53
|
+
this.viewer.off("contextmenu", this.stopContextMenu);
|
|
54
|
+
this.viewer.off("zoom", this.updateControls);
|
|
55
|
+
this.viewer.off("viewposition", this.updateControls);
|
|
56
|
+
this.viewer.off("geometryend", this.updateControls);
|
|
57
|
+
|
|
58
|
+
this.orbit.removeEventListener("change", this.controlsChange);
|
|
59
|
+
this.orbit.dispose();
|
|
47
60
|
}
|
|
48
61
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
62
|
+
updateControls = () => {
|
|
63
|
+
this.orbit.maxDistance = this.viewer.camera.far;
|
|
64
|
+
this.orbit.minDistance = this.viewer.camera.near;
|
|
65
|
+
this.orbit.target.copy(this.viewer.target);
|
|
66
|
+
this.orbit.update();
|
|
67
|
+
};
|
|
53
68
|
|
|
54
|
-
|
|
55
|
-
this.
|
|
69
|
+
controlsStart = () => {
|
|
70
|
+
this.changed = false;
|
|
56
71
|
};
|
|
57
72
|
|
|
58
|
-
|
|
73
|
+
controlsChange = () => {
|
|
74
|
+
this.viewer.target.copy(this.orbit.target);
|
|
59
75
|
this.viewer.update();
|
|
76
|
+
|
|
77
|
+
this.changed = true;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
stopContextMenu = (event: PointerEvent) => {
|
|
81
|
+
if (this.changed) {
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
event.stopPropagation();
|
|
84
|
+
}
|
|
60
85
|
};
|
|
61
86
|
}
|
|
@@ -21,14 +21,15 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import
|
|
24
|
+
import { MOUSE } from "three";
|
|
25
|
+
|
|
25
26
|
import { OrbitDragger } from "./OrbitDragger";
|
|
26
27
|
import type { Viewer } from "../Viewer";
|
|
27
28
|
|
|
28
29
|
export class PanDragger extends OrbitDragger {
|
|
29
30
|
constructor(viewer: Viewer) {
|
|
30
31
|
super(viewer);
|
|
31
|
-
this.mouseButtons = { LEFT:
|
|
32
|
-
this.touches = { ONE:
|
|
32
|
+
this.orbit.mouseButtons = { LEFT: MOUSE.PAN, MIDDLE: MOUSE.PAN, RIGHT: MOUSE.PAN };
|
|
33
|
+
// this.controls.touches = { ONE: TOUCH.PAN, TWO: TOUCH.DOLLY_ROTATE };
|
|
33
34
|
}
|
|
34
35
|
}
|
|
@@ -21,240 +21,51 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import {
|
|
25
|
-
|
|
24
|
+
import { Vector3 } from "three";
|
|
25
|
+
|
|
26
26
|
import type { Viewer } from "../Viewer";
|
|
27
|
+
import { WalkControls } from "../controls/WalkControls";
|
|
27
28
|
|
|
28
29
|
export class WalkDragger {
|
|
29
30
|
protected viewer: Viewer;
|
|
30
|
-
|
|
31
|
-
protected canvas: HTMLCanvasElement;
|
|
32
|
-
protected _target: THREE.Vector3;
|
|
33
|
-
protected quaternion: THREE.Quaternion;
|
|
34
|
-
protected mouseStart: THREE.Vector2;
|
|
35
|
-
protected mouseDelta: THREE.Vector2;
|
|
36
|
-
protected xAxis: THREE.Vector3;
|
|
37
|
-
protected yAxis: THREE.Vector3;
|
|
38
|
-
protected zAxis: THREE.Vector3;
|
|
39
|
-
protected speed: THREE.Vector3;
|
|
40
|
-
protected _maxDistance: number;
|
|
41
|
-
protected xRotation: THREE.Quaternion;
|
|
42
|
-
protected yRotation: THREE.Quaternion;
|
|
43
|
-
protected yRotationAxis: THREE.Vector3;
|
|
44
|
-
protected touchStartDistance: number;
|
|
45
|
-
|
|
46
|
-
public walkSpeed: number;
|
|
47
|
-
public boostSpeed: number;
|
|
31
|
+
public controls: WalkControls;
|
|
48
32
|
|
|
49
33
|
constructor(viewer: Viewer) {
|
|
34
|
+
this.controls = new WalkControls(viewer.camera, viewer.canvas);
|
|
35
|
+
this.controls.addEventListener("change", this.controlsChange);
|
|
36
|
+
this.controls.addEventListener("walkspeedchange", this.walkspeedChange);
|
|
50
37
|
this.viewer = viewer;
|
|
51
|
-
|
|
52
|
-
this.
|
|
53
|
-
|
|
54
|
-
this.quaternion = this.viewer.camera.quaternion.clone();
|
|
55
|
-
this.xRotation = new THREE.Quaternion();
|
|
56
|
-
this.yRotation = new THREE.Quaternion();
|
|
57
|
-
|
|
58
|
-
this.mouseStart = new THREE.Vector2();
|
|
59
|
-
this.mouseDelta = new THREE.Vector2();
|
|
60
|
-
|
|
61
|
-
this.xAxis = new THREE.Vector3();
|
|
62
|
-
this.yAxis = new THREE.Vector3();
|
|
63
|
-
this.zAxis = new THREE.Vector3();
|
|
64
|
-
this.yRotationAxis = new THREE.Vector3(1, 0, 0);
|
|
65
|
-
this.walkSpeed = 1;
|
|
66
|
-
this.boostSpeed = 5;
|
|
67
|
-
this.speed = new THREE.Vector3();
|
|
68
|
-
this._maxDistance = 1;
|
|
69
|
-
|
|
70
|
-
this.touchStartDistance = 0;
|
|
71
|
-
|
|
72
|
-
this.viewer.addEventListener("render", this.onRender);
|
|
73
|
-
|
|
74
|
-
this.viewer.addEventListener("contextmenu", this.onContextMenu);
|
|
75
|
-
|
|
76
|
-
this.viewer.addEventListener("mousedown", this.onMouseDown);
|
|
77
|
-
this.viewer.addEventListener("mouseup", this.onMouseUp);
|
|
78
|
-
|
|
79
|
-
this.viewer.addEventListener("touchstart", this.onTouchStart);
|
|
80
|
-
this.viewer.addEventListener("touchmove", this.onTouchMove);
|
|
81
|
-
this.viewer.addEventListener("touchend", this.onTouchEnd);
|
|
82
|
-
|
|
83
|
-
this.viewer.addEventListener("wheel", this.onMouseWheel);
|
|
84
|
-
|
|
85
|
-
document.addEventListener("keydown", this.onKeyDown);
|
|
86
|
-
document.addEventListener("keyup", this.onKeyUp);
|
|
38
|
+
this.viewer.on("render", this.viewerRender);
|
|
39
|
+
this.viewer.on("zoom", this.viewerZoom);
|
|
40
|
+
this.updateControls();
|
|
87
41
|
}
|
|
88
42
|
|
|
89
|
-
dispose()
|
|
90
|
-
this.viewer.
|
|
91
|
-
|
|
92
|
-
this.
|
|
93
|
-
|
|
94
|
-
this.
|
|
95
|
-
this.viewer.removeEventListener("mouseup", this.onMouseUp);
|
|
96
|
-
this.viewer.removeEventListener("mousemove", this.onMouseMove);
|
|
97
|
-
|
|
98
|
-
this.viewer.removeEventListener("touchstart", this.onTouchStart);
|
|
99
|
-
this.viewer.removeEventListener("touchmove", this.onTouchMove);
|
|
100
|
-
this.viewer.removeEventListener("touchend", this.onTouchEnd);
|
|
101
|
-
|
|
102
|
-
this.viewer.removeEventListener("wheel", this.onMouseWheel);
|
|
103
|
-
|
|
104
|
-
document.removeEventListener("keydown", this.onKeyDown);
|
|
105
|
-
document.removeEventListener("keyup", this.onKeyUp);
|
|
43
|
+
dispose() {
|
|
44
|
+
this.viewer.off("render", this.viewerRender);
|
|
45
|
+
this.viewer.off("zoom", this.viewerZoom);
|
|
46
|
+
this.controls.removeEventListener("walkspeedchange", this.walkspeedChange);
|
|
47
|
+
this.controls.removeEventListener("change", this.controlsChange);
|
|
48
|
+
this.controls.dispose();
|
|
106
49
|
}
|
|
107
50
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (event.shiftKey) {
|
|
112
|
-
this.speed.z = this.walkSpeed * this.boostSpeed;
|
|
113
|
-
} else {
|
|
114
|
-
this.speed.z = this.walkSpeed;
|
|
115
|
-
}
|
|
116
|
-
break;
|
|
117
|
-
case "KeyS": // Backward
|
|
118
|
-
if (event.shiftKey) {
|
|
119
|
-
this.speed.z = -this.walkSpeed * this.boostSpeed;
|
|
120
|
-
} else {
|
|
121
|
-
this.speed.z = -this.walkSpeed;
|
|
122
|
-
}
|
|
123
|
-
break;
|
|
124
|
-
case "KeyA": // Left
|
|
125
|
-
if (event.shiftKey) {
|
|
126
|
-
this.speed.x = this.walkSpeed * this.boostSpeed;
|
|
127
|
-
} else {
|
|
128
|
-
this.speed.x = this.walkSpeed;
|
|
129
|
-
}
|
|
130
|
-
break;
|
|
131
|
-
case "KeyD": // Right
|
|
132
|
-
if (event.shiftKey) {
|
|
133
|
-
this.speed.x = -this.walkSpeed * this.boostSpeed;
|
|
134
|
-
} else {
|
|
135
|
-
this.speed.x = -this.walkSpeed;
|
|
136
|
-
}
|
|
137
|
-
break;
|
|
138
|
-
default:
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
onKeyUp = (event: KeyboardEvent) => {
|
|
144
|
-
switch (event.code) {
|
|
145
|
-
case "KeyW":
|
|
146
|
-
this.speed.z = 0;
|
|
147
|
-
break;
|
|
148
|
-
case "KeyS":
|
|
149
|
-
this.speed.z = 0;
|
|
150
|
-
break;
|
|
151
|
-
case "KeyA":
|
|
152
|
-
this.speed.x = 0;
|
|
153
|
-
break;
|
|
154
|
-
case "KeyD":
|
|
155
|
-
this.speed.x = 0;
|
|
156
|
-
break;
|
|
157
|
-
default:
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
onMouseDown = (event: PointerEvent) => {
|
|
163
|
-
const { clientX, clientY } = event;
|
|
164
|
-
this.mouseStart.set(clientX, clientY);
|
|
165
|
-
this.mouseDelta.set(0, 0);
|
|
166
|
-
this.quaternion.copy(this.viewer.camera.quaternion);
|
|
167
|
-
this.viewer.addEventListener("mousemove", this.onMouseMove);
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
onMouseMove = (event: MouseEvent) => {
|
|
171
|
-
const { clientX, clientY } = event;
|
|
172
|
-
this.mouseDelta.set(this.mouseStart.x - clientX, this.mouseStart.y - clientY);
|
|
173
|
-
this.rotateCamera(this.mouseDelta);
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
onMouseUp = (event: PointerEvent) => {
|
|
177
|
-
this.speed.set(0, 0, 0);
|
|
178
|
-
this.mouseStart.set(0, 0);
|
|
179
|
-
this.mouseDelta.set(0, 0);
|
|
180
|
-
this.quaternion.copy(this.viewer.camera.quaternion);
|
|
181
|
-
this.viewer.removeEventListener("mousemove", this.onMouseMove);
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
onMouseWheel = (event: WheelEvent) => {
|
|
185
|
-
event.preventDefault();
|
|
186
|
-
|
|
187
|
-
if (-event.deltaY < 0) {
|
|
188
|
-
this.walkSpeed = Math.max(0.001, this.walkSpeed - 1);
|
|
189
|
-
} else if (-event.deltaY > 0) {
|
|
190
|
-
this.walkSpeed++;
|
|
191
|
-
}
|
|
51
|
+
updateControls = () => {
|
|
52
|
+
const size = this.viewer.extents.getSize(new Vector3());
|
|
53
|
+
this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2;
|
|
192
54
|
};
|
|
193
55
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
event.preventDefault();
|
|
197
|
-
event.stopImmediatePropagation();
|
|
56
|
+
controlsChange = () => {
|
|
57
|
+
this.viewer.update();
|
|
198
58
|
};
|
|
199
59
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
this.touchStartDistance = this.getTouchsDistance(event.touches);
|
|
203
|
-
} else {
|
|
204
|
-
const { clientX, clientY } = event.touches[0];
|
|
205
|
-
this.mouseStart.set(clientX, clientY);
|
|
206
|
-
this.mouseDelta.set(0, 0);
|
|
207
|
-
this.quaternion.copy(this.viewer.camera.quaternion);
|
|
208
|
-
}
|
|
60
|
+
walkspeedChange = (event: any) => {
|
|
61
|
+
this.viewer.emitEvent(event);
|
|
209
62
|
};
|
|
210
63
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
this.touchStartDistance = 0;
|
|
214
|
-
}
|
|
215
|
-
this.speed.set(0, 0, 0);
|
|
216
|
-
this.mouseStart.set(0, 0);
|
|
217
|
-
this.mouseDelta.set(0, 0);
|
|
218
|
-
this.quaternion.copy(this.viewer.camera.quaternion);
|
|
64
|
+
viewerRender = () => {
|
|
65
|
+
this.controls.update();
|
|
219
66
|
};
|
|
220
67
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const { clientX, clientY } = event.touches[0];
|
|
224
|
-
this.mouseDelta.set(this.mouseStart.x - clientX, this.mouseStart.y - clientY);
|
|
225
|
-
this.rotateCamera(this.mouseDelta);
|
|
226
|
-
}
|
|
227
|
-
if (event.touches.length === 2) {
|
|
228
|
-
const distance = this.getTouchsDistance(event.touches);
|
|
229
|
-
this.speed.z = (distance - this.touchStartDistance) / 2;
|
|
230
|
-
}
|
|
68
|
+
viewerZoom = () => {
|
|
69
|
+
this.controls.rotateDelta.set(0, 0);
|
|
231
70
|
};
|
|
232
|
-
|
|
233
|
-
getTouchsDistance(touches) {
|
|
234
|
-
const [start, end] = touches;
|
|
235
|
-
const dx = start.clientX - end.clientX;
|
|
236
|
-
const dy = start.clientY - end.clientY;
|
|
237
|
-
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
238
|
-
return distance;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
onRender = (event: RenderEvent) => {
|
|
242
|
-
this.viewer.camera.matrix.extractBasis(this.xAxis, this.yAxis, this.zAxis);
|
|
243
|
-
this.viewer.camera.position.add(this.zAxis.multiplyScalar(-event.deltaTime * this.speed.z));
|
|
244
|
-
this.viewer.camera.position.add(this.xAxis.multiplyScalar(-event.deltaTime * this.speed.x));
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
update() {}
|
|
248
|
-
|
|
249
|
-
rotateCamera(delta: THREE.Vector2) {
|
|
250
|
-
const rotateX = (Math.PI * delta.x) / this.viewer.canvas.clientWidth;
|
|
251
|
-
const rotateY = (Math.PI * delta.y) / this.viewer.canvas.clientHeight;
|
|
252
|
-
|
|
253
|
-
const quaternion = this.quaternion.clone();
|
|
254
|
-
this.xRotation.setFromAxisAngle(this.viewer.camera.up, rotateX);
|
|
255
|
-
this.yRotation.setFromAxisAngle(this.yRotationAxis, rotateY);
|
|
256
|
-
quaternion.premultiply(this.xRotation).multiply(this.yRotation).normalize();
|
|
257
|
-
|
|
258
|
-
this.viewer.camera.setRotationFromQuaternion(quaternion);
|
|
259
|
-
}
|
|
260
71
|
}
|
|
@@ -21,14 +21,15 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import
|
|
24
|
+
import { MOUSE } from "three";
|
|
25
|
+
|
|
25
26
|
import { OrbitDragger } from "./OrbitDragger";
|
|
26
27
|
import type { Viewer } from "../Viewer";
|
|
27
28
|
|
|
28
29
|
export class ZoomDragger extends OrbitDragger {
|
|
29
30
|
constructor(viewer: Viewer) {
|
|
30
31
|
super(viewer);
|
|
31
|
-
this.mouseButtons = { LEFT:
|
|
32
|
-
this.touches = { ONE:
|
|
32
|
+
this.orbit.mouseButtons = { LEFT: MOUSE.DOLLY, MIDDLE: MOUSE.PAN, RIGHT: MOUSE.PAN };
|
|
33
|
+
// this.controls.touches = { ONE: TOUCH.DOLLY_PAN, TWO: TOUCH.DOLLY_PAN };
|
|
33
34
|
}
|
|
34
35
|
}
|