@inweb/viewer-three 25.9.8 → 25.11.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 +9963 -6031
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +3 -2
- package/dist/viewer-three.module.js +2648 -353
- package/dist/viewer-three.module.js.map +1 -1
- package/lib/Viewer/IDisposable.d.ts +6 -0
- package/lib/Viewer/Viewer.d.ts +119 -14
- package/lib/Viewer/commands/ApplyModelTransform.d.ts +1 -0
- package/lib/Viewer/commands/ClearMarkup.d.ts +1 -0
- package/lib/Viewer/commands/ClearSelected.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/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 +10 -6
- 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 +6 -5
- package/src/Viewer/IDisposable.ts +29 -0
- package/src/Viewer/Viewer.ts +240 -49
- package/src/Viewer/commands/ApplyModelTransform.ts +33 -0
- package/src/Viewer/commands/ClearMarkup.ts +29 -0
- package/src/Viewer/commands/ClearSelected.ts +38 -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/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/OrbitControls.js +1007 -0
- package/src/Viewer/controls/WalkControls.ts +222 -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 +70 -23
- 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,222 @@
|
|
|
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 { Clock, Camera, EventDispatcher, Quaternion, Vector2, Vector3 } from "three";
|
|
25
|
+
|
|
26
|
+
const _changeEvent = { type: "change" };
|
|
27
|
+
|
|
28
|
+
export class WalkControls extends EventDispatcher {
|
|
29
|
+
public camera: Camera;
|
|
30
|
+
public canvas: HTMLElement;
|
|
31
|
+
|
|
32
|
+
public movementSpeed = 0.2;
|
|
33
|
+
public lookSpeed = 5;
|
|
34
|
+
public multiplier = 5;
|
|
35
|
+
|
|
36
|
+
private moveKeys: Set<string>;
|
|
37
|
+
private moveWheel = 0;
|
|
38
|
+
private moveClock: Clock;
|
|
39
|
+
|
|
40
|
+
private quaternion: Quaternion;
|
|
41
|
+
private downPosition: Vector2;
|
|
42
|
+
private mouseDragOn = false;
|
|
43
|
+
public rotateDelta: Vector2;
|
|
44
|
+
|
|
45
|
+
constructor(camera: Camera, canvas: HTMLElement) {
|
|
46
|
+
super();
|
|
47
|
+
|
|
48
|
+
this.camera = camera;
|
|
49
|
+
this.canvas = canvas;
|
|
50
|
+
|
|
51
|
+
this.moveKeys = new Set();
|
|
52
|
+
this.moveClock = new Clock();
|
|
53
|
+
|
|
54
|
+
this.quaternion = camera.quaternion.clone();
|
|
55
|
+
this.downPosition = new Vector2(0, 0);
|
|
56
|
+
this.rotateDelta = new Vector2(0, 0);
|
|
57
|
+
|
|
58
|
+
this.canvas.addEventListener("pointerdown", this.onPointerDown);
|
|
59
|
+
this.canvas.addEventListener("pointermove", this.onPointerMove);
|
|
60
|
+
this.canvas.addEventListener("pointerup", this.onPointerUp);
|
|
61
|
+
this.canvas.addEventListener("pointercancel", this.onPointerCancel);
|
|
62
|
+
this.canvas.addEventListener("wheel", this.onWheel);
|
|
63
|
+
|
|
64
|
+
window.addEventListener("keydown", this.onKeyDown);
|
|
65
|
+
window.addEventListener("keyup", this.onKeyUp);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
dispose() {
|
|
69
|
+
this.canvas.removeEventListener("pointerdown", this.onPointerDown);
|
|
70
|
+
this.canvas.removeEventListener("pointermove", this.onPointerMove);
|
|
71
|
+
this.canvas.removeEventListener("pointerup", this.onPointerUp);
|
|
72
|
+
this.canvas.removeEventListener("pointercancel", this.onPointerCancel);
|
|
73
|
+
this.canvas.removeEventListener("wheel", this.onWheel);
|
|
74
|
+
|
|
75
|
+
window.removeEventListener("keydown", this.onKeyDown);
|
|
76
|
+
window.removeEventListener("keyup", this.onKeyUp);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
onPointerDown = (event: PointerEvent) => {
|
|
80
|
+
if (!event.isPrimary || event.button !== 0) return;
|
|
81
|
+
|
|
82
|
+
this.canvas.setPointerCapture(event.pointerId);
|
|
83
|
+
this.downPosition.set(event.clientX, event.clientY);
|
|
84
|
+
this.quaternion.copy(this.camera.quaternion);
|
|
85
|
+
this.mouseDragOn = true;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
onPointerMove = (event: PointerEvent) => {
|
|
89
|
+
if (!event.isPrimary || !this.mouseDragOn) return;
|
|
90
|
+
|
|
91
|
+
const movePosition = new Vector2(event.clientX, event.clientY);
|
|
92
|
+
if (this.downPosition.distanceTo(movePosition) === 0) return;
|
|
93
|
+
|
|
94
|
+
this.rotateDelta.copy(this.downPosition).sub(movePosition);
|
|
95
|
+
this.rotateCamera(this.rotateDelta);
|
|
96
|
+
this.dispatchEvent(_changeEvent);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
onPointerUp = (event: PointerEvent) => {
|
|
100
|
+
if (!event.isPrimary || event.button !== 0) return;
|
|
101
|
+
|
|
102
|
+
this.canvas.releasePointerCapture(event.pointerId);
|
|
103
|
+
this.mouseDragOn = false;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
onPointerCancel = (event: PointerEvent) => {
|
|
107
|
+
this.canvas.dispatchEvent(new PointerEvent("pointerup", event));
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
onWheel = (event: WheelEvent) => {
|
|
111
|
+
this.moveWheel = event.deltaY;
|
|
112
|
+
this.update();
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
onKeyDown = (event: KeyboardEvent) => {
|
|
116
|
+
switch (event.code) {
|
|
117
|
+
case "NumpadSubtract":
|
|
118
|
+
case "Minus":
|
|
119
|
+
if (this.multiplier > 1) {
|
|
120
|
+
this.multiplier = this.multiplier - 1;
|
|
121
|
+
this.dispatchEvent({ type: "walkspeedchange", data: this.multiplier });
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
|
|
125
|
+
case "NumpadAdd":
|
|
126
|
+
case "Equal":
|
|
127
|
+
if (this.multiplier < 10) {
|
|
128
|
+
this.multiplier = this.multiplier + 1;
|
|
129
|
+
this.dispatchEvent({ type: "walkspeedchange", data: this.multiplier });
|
|
130
|
+
}
|
|
131
|
+
break;
|
|
132
|
+
|
|
133
|
+
case "ArrowLeft":
|
|
134
|
+
case "ArrowRight":
|
|
135
|
+
case "ArrowUp":
|
|
136
|
+
case "ArrowDown":
|
|
137
|
+
case "KeyW":
|
|
138
|
+
case "KeyS":
|
|
139
|
+
case "KeyA":
|
|
140
|
+
case "KeyD":
|
|
141
|
+
case "KeyQ":
|
|
142
|
+
case "KeyE":
|
|
143
|
+
this.moveKeys.add(event.code);
|
|
144
|
+
this.update();
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
onKeyUp = (event: KeyboardEvent) => {
|
|
150
|
+
switch (event.code) {
|
|
151
|
+
case "ArrowLeft":
|
|
152
|
+
case "ArrowRight":
|
|
153
|
+
case "ArrowUp":
|
|
154
|
+
case "ArrowDown":
|
|
155
|
+
case "KeyW":
|
|
156
|
+
case "KeyS":
|
|
157
|
+
case "KeyA":
|
|
158
|
+
case "KeyD":
|
|
159
|
+
case "KeyQ":
|
|
160
|
+
case "KeyE":
|
|
161
|
+
this.moveKeys.delete(event.code);
|
|
162
|
+
this.update();
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
update() {
|
|
168
|
+
if (this.moveKeys.size > 0) {
|
|
169
|
+
const timeDelta = this.moveClock.getDelta();
|
|
170
|
+
const moveDelta = timeDelta * this.movementSpeed * this.multiplier;
|
|
171
|
+
|
|
172
|
+
if (this.moveKeys.has("KeyW")) this.camera.translateZ(-moveDelta);
|
|
173
|
+
if (this.moveKeys.has("KeyS")) this.camera.translateZ(moveDelta);
|
|
174
|
+
|
|
175
|
+
if (this.moveKeys.has("KeyA")) this.camera.translateX(-moveDelta);
|
|
176
|
+
if (this.moveKeys.has("KeyD")) this.camera.translateX(moveDelta);
|
|
177
|
+
|
|
178
|
+
if (this.moveKeys.has("KeyQ")) this.camera.translateY(moveDelta);
|
|
179
|
+
if (this.moveKeys.has("KeyE")) this.camera.translateY(-moveDelta);
|
|
180
|
+
|
|
181
|
+
const lookDelta = this.lookSpeed + (this.multiplier - 1);
|
|
182
|
+
|
|
183
|
+
if (this.moveKeys.has("ArrowUp")) this.rotateCamera(this.rotateDelta.add(new Vector2(0, -lookDelta / 2)));
|
|
184
|
+
if (this.moveKeys.has("ArrowDown")) this.rotateCamera(this.rotateDelta.add(new Vector2(0, lookDelta / 2)));
|
|
185
|
+
|
|
186
|
+
if (this.moveKeys.has("ArrowLeft")) this.rotateCamera(this.rotateDelta.add(new Vector2(lookDelta, 0)));
|
|
187
|
+
if (this.moveKeys.has("ArrowRight")) this.rotateCamera(this.rotateDelta.add(new Vector2(-lookDelta, 0)));
|
|
188
|
+
|
|
189
|
+
this.moveWheel = 0;
|
|
190
|
+
this.dispatchEvent(_changeEvent);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (this.moveWheel !== 0) {
|
|
194
|
+
const moveDelta = this.moveWheel * 0.0001 * this.movementSpeed * this.multiplier;
|
|
195
|
+
|
|
196
|
+
this.camera.translateZ(-moveDelta);
|
|
197
|
+
this.moveWheel += -1 * Math.sign(this.moveWheel);
|
|
198
|
+
this.dispatchEvent(_changeEvent);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (this.moveKeys.size === 0 && this.moveWheel === 0) {
|
|
202
|
+
this.moveClock.stop();
|
|
203
|
+
this.moveClock.autoStart = true;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
rotateCamera(delta: Vector2) {
|
|
208
|
+
const rotateX = (Math.PI * delta.x) / this.canvas.clientWidth;
|
|
209
|
+
const rotateY = (Math.PI * delta.y) / this.canvas.clientHeight;
|
|
210
|
+
|
|
211
|
+
const xRotation = new Quaternion();
|
|
212
|
+
xRotation.setFromAxisAngle(this.camera.up, rotateX);
|
|
213
|
+
|
|
214
|
+
const yRotation = new Quaternion();
|
|
215
|
+
yRotation.setFromAxisAngle(new Vector3(1, 0, 0), rotateY);
|
|
216
|
+
|
|
217
|
+
const quaternion = this.quaternion.clone();
|
|
218
|
+
quaternion.premultiply(xRotation).multiply(yRotation).normalize();
|
|
219
|
+
|
|
220
|
+
this.camera.setRotationFromQuaternion(quaternion);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -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,88 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
import {
|
|
24
|
+
import { MOUSE, TOUCH } from "three";
|
|
25
|
+
|
|
26
|
+
import type { IDisposable } from "../IDisposable";
|
|
27
27
|
import type { Viewer } from "../Viewer";
|
|
28
|
+
import { OrbitControls, STATE } from "../controls/OrbitControls.js";
|
|
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("geometryend", this.updateControls);
|
|
54
|
+
this.viewer.off("viewposition", this.updateControls);
|
|
55
|
+
this.viewer.off("zoom", this.updateControls);
|
|
56
|
+
this.viewer.off("contextmenu", this.stopContextMenu);
|
|
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
|
+
switch (this.orbit.state) {
|
|
78
|
+
case STATE.PAN:
|
|
79
|
+
case STATE.TOUCH_PAN:
|
|
80
|
+
this.viewer.emitEvent({
|
|
81
|
+
type: "pan",
|
|
82
|
+
x: this.orbit.panEnd.x,
|
|
83
|
+
y: this.orbit.panEnd.y,
|
|
84
|
+
dX: this.orbit.panDelta.x,
|
|
85
|
+
dY: this.orbit.panDelta.y,
|
|
86
|
+
});
|
|
87
|
+
break;
|
|
88
|
+
|
|
89
|
+
case STATE.DOLLY:
|
|
90
|
+
this.viewer.emitEvent({
|
|
91
|
+
type: "zoomat",
|
|
92
|
+
data: this.orbit.dollyScale,
|
|
93
|
+
x: this.orbit.dollyEnd.x,
|
|
94
|
+
y: this.orbit.dollyEnd.y,
|
|
95
|
+
});
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
this.changed = true;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
stopContextMenu = (event: PointerEvent) => {
|
|
103
|
+
if (this.changed) {
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
event.stopPropagation();
|
|
106
|
+
}
|
|
60
107
|
};
|
|
61
108
|
}
|
|
@@ -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
|
}
|