copper3d 1.15.5 → 1.15.7
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/Controls/Copper3dTrackballControls.js +77 -155
- package/dist/Controls/Copper3dTrackballControls.js.map +1 -1
- package/dist/Scene/copperScene.d.ts +2 -2
- package/dist/Scene/copperScene.js +2 -2
- package/dist/Scene/copperScene.js.map +1 -1
- package/dist/bundle.esm.js +101 -716
- package/dist/bundle.umd.js +101 -716
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/types/Scene/copperScene.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/Controls/Copper3dTrackballControls1.d.ts +0 -45
- package/dist/Controls/Copper3dTrackballControls1.js +0 -539
- package/dist/Controls/Copper3dTrackballControls1.js.map +0 -1
- package/dist/types/Controls/Copper3dTrackballControls1.d.ts +0 -45
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,6 @@ import { nrrd_tools } from "./Utils/nrrd_tool";
|
|
|
16
16
|
import { Copper3dTrackballControls } from "./Controls/Copper3dTrackballControls";
|
|
17
17
|
import { nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, paintImageType, exportPaintImageType, IOptVTKLoader } from "./types/types";
|
|
18
18
|
import "./css/style.css";
|
|
19
|
-
export declare const REVISION = "v1.15.
|
|
19
|
+
export declare const REVISION = "v1.15.7";
|
|
20
20
|
export { copperRenderer, copperRendererOnDemond, copperMSceneRenderer, setHDRFilePath, addLabelToScene, convert3DPostoScreenPos, convertScreenPosto3DPos, addBoxHelper, fullScreenListenner, configKiwriousHeart, copperScene, copperSceneOnDemond, copperMScene, CameraViewPoint, kiwrious, nrrd_tools, loading, Copper3dTrackballControls, createTexture2D_NRRD, };
|
|
21
21
|
export type { positionType, screenPosType, optsType, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, paintImageType, exportPaintImageType, IOptVTKLoader, };
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import kiwrious from "./Utils/kiwrious/configKiwrious";
|
|
|
16
16
|
import { nrrd_tools } from "./Utils/nrrd_tool";
|
|
17
17
|
import { Copper3dTrackballControls } from "./Controls/Copper3dTrackballControls";
|
|
18
18
|
import "./css/style.css";
|
|
19
|
-
export const REVISION = "v1.15.
|
|
20
|
-
console.log("%cCopper3D Visualisation %cBeta:v1.15.
|
|
19
|
+
export const REVISION = "v1.15.7";
|
|
20
|
+
console.log("%cCopper3D Visualisation %cBeta:v1.15.7", "padding: 3px;color:white; background:#023047", "padding: 3px;color:white; background:#f50a25");
|
|
21
21
|
export { copperRenderer, copperRendererOnDemond, copperMSceneRenderer, setHDRFilePath, addLabelToScene, convert3DPostoScreenPos, convertScreenPosto3DPos, addBoxHelper, fullScreenListenner, configKiwriousHeart, copperScene, copperSceneOnDemond, copperMScene, CameraViewPoint, kiwrious, nrrd_tools, loading, Copper3dTrackballControls, createTexture2D_NRRD, };
|
|
22
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as THREE from "three";
|
|
2
|
-
import {
|
|
2
|
+
import { Copper3dTrackballControls } from "../Controls/Copper3dTrackballControls";
|
|
3
3
|
import { CameraViewPoint } from "../Controls/copperControls";
|
|
4
4
|
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
|
|
5
5
|
import baseScene from "./baseScene";
|
|
@@ -7,7 +7,7 @@ import { vtkModels } from "../types/types";
|
|
|
7
7
|
import { TrackballControls } from "three/examples/jsm/controls/TrackballControls";
|
|
8
8
|
export default class copperScene extends baseScene {
|
|
9
9
|
clock: THREE.Clock;
|
|
10
|
-
controls:
|
|
10
|
+
controls: Copper3dTrackballControls | OrbitControls | TrackballControls;
|
|
11
11
|
private mixer;
|
|
12
12
|
private playRate;
|
|
13
13
|
private modelReady;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -16,6 +16,6 @@ import { nrrd_tools } from "./Utils/nrrd_tool";
|
|
|
16
16
|
import { Copper3dTrackballControls } from "./Controls/Copper3dTrackballControls";
|
|
17
17
|
import { nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, paintImageType, exportPaintImageType, IOptVTKLoader } from "./types/types";
|
|
18
18
|
import "./css/style.css";
|
|
19
|
-
export declare const REVISION = "v1.15.
|
|
19
|
+
export declare const REVISION = "v1.15.7";
|
|
20
20
|
export { copperRenderer, copperRendererOnDemond, copperMSceneRenderer, setHDRFilePath, addLabelToScene, convert3DPostoScreenPos, convertScreenPosto3DPos, addBoxHelper, fullScreenListenner, configKiwriousHeart, copperScene, copperSceneOnDemond, copperMScene, CameraViewPoint, kiwrious, nrrd_tools, loading, Copper3dTrackballControls, createTexture2D_NRRD, };
|
|
21
21
|
export type { positionType, screenPosType, optsType, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, paintImageType, exportPaintImageType, IOptVTKLoader, };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "copper3d",
|
|
3
3
|
"description": "A 3d visualisation package base on threejs provides multiple scenes and Nrrd image load funtion.",
|
|
4
|
-
"version": "1.15.
|
|
4
|
+
"version": "1.15.7",
|
|
5
5
|
"main": "dist/bundle.umd.js",
|
|
6
6
|
"moudle": "dist/bundle.esm.js",
|
|
7
7
|
"types": "dist/types/index.d.ts",
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { EventDispatcher, MOUSE, Vector3, PerspectiveCamera, OrthographicCamera } from "three";
|
|
2
|
-
declare class Copper3dTrackballControls1 extends EventDispatcher {
|
|
3
|
-
object: PerspectiveCamera | OrthographicCamera;
|
|
4
|
-
domElement: HTMLElement;
|
|
5
|
-
enabled: boolean;
|
|
6
|
-
screen: {
|
|
7
|
-
left: number;
|
|
8
|
-
top: number;
|
|
9
|
-
width: number;
|
|
10
|
-
height: number;
|
|
11
|
-
};
|
|
12
|
-
rotateSpeed: number;
|
|
13
|
-
zoomSpeed: number;
|
|
14
|
-
panSpeed: number;
|
|
15
|
-
noRotate: boolean;
|
|
16
|
-
noZoom: boolean;
|
|
17
|
-
noPan: boolean;
|
|
18
|
-
staticMoving: boolean;
|
|
19
|
-
dynamicDampingFactor: number;
|
|
20
|
-
minDistance: number;
|
|
21
|
-
maxDistance: number;
|
|
22
|
-
minZoom: number;
|
|
23
|
-
maxZoom: number;
|
|
24
|
-
keys: ["KeyA", "KeyS", "KeyD"];
|
|
25
|
-
mouseButtons: {
|
|
26
|
-
LEFT: MOUSE.ROTATE;
|
|
27
|
-
MIDDLE: MOUSE.DOLLY;
|
|
28
|
-
RIGHT: MOUSE.PAN;
|
|
29
|
-
};
|
|
30
|
-
target: Vector3;
|
|
31
|
-
target0: Vector3;
|
|
32
|
-
position0: Vector3;
|
|
33
|
-
up0: Vector3;
|
|
34
|
-
zoom0: number;
|
|
35
|
-
handleResize: () => void;
|
|
36
|
-
rotateCamera: () => void;
|
|
37
|
-
zoomCamera: () => void;
|
|
38
|
-
panCamera: () => void;
|
|
39
|
-
checkDistances: () => void;
|
|
40
|
-
update: () => void;
|
|
41
|
-
reset: () => void;
|
|
42
|
-
dispose: () => void;
|
|
43
|
-
constructor(object: PerspectiveCamera | OrthographicCamera, domElement: HTMLElement);
|
|
44
|
-
}
|
|
45
|
-
export { Copper3dTrackballControls1 };
|
|
@@ -1,539 +0,0 @@
|
|
|
1
|
-
import { EventDispatcher, MathUtils, MOUSE, Quaternion, Vector2, Vector3, } from "three";
|
|
2
|
-
const _changeEvent = { type: "change" };
|
|
3
|
-
const _startEvent = { type: "start" };
|
|
4
|
-
const _endEvent = { type: "end" };
|
|
5
|
-
class Copper3dTrackballControls1 extends EventDispatcher {
|
|
6
|
-
constructor(object, domElement) {
|
|
7
|
-
super();
|
|
8
|
-
const scope = this;
|
|
9
|
-
const STATE = {
|
|
10
|
-
NONE: -1,
|
|
11
|
-
ROTATE: 0,
|
|
12
|
-
ZOOM: 1,
|
|
13
|
-
PAN: 2,
|
|
14
|
-
TOUCH_ROTATE: 3,
|
|
15
|
-
TOUCH_ZOOM: 4,
|
|
16
|
-
TOUCH_PAN: 5,
|
|
17
|
-
TOUCH_ZOOM_PAN: 6,
|
|
18
|
-
};
|
|
19
|
-
this.object = object;
|
|
20
|
-
this.domElement = domElement;
|
|
21
|
-
this.domElement.style.touchAction = "none"; // disable touch scroll
|
|
22
|
-
// API
|
|
23
|
-
this.enabled = true;
|
|
24
|
-
this.screen = { left: 0, top: 0, width: 0, height: 0 };
|
|
25
|
-
this.rotateSpeed = 1.0;
|
|
26
|
-
this.zoomSpeed = 1.2;
|
|
27
|
-
this.panSpeed = 0.3;
|
|
28
|
-
this.noRotate = false;
|
|
29
|
-
this.noZoom = false;
|
|
30
|
-
this.noPan = false;
|
|
31
|
-
this.staticMoving = false;
|
|
32
|
-
this.dynamicDampingFactor = 0.2;
|
|
33
|
-
this.minDistance = 0;
|
|
34
|
-
this.maxDistance = Infinity;
|
|
35
|
-
this.minZoom = 0;
|
|
36
|
-
this.maxZoom = Infinity;
|
|
37
|
-
this.keys = ["KeyA" /*A*/, "KeyS" /*S*/, "KeyD" /*D*/];
|
|
38
|
-
this.mouseButtons = {
|
|
39
|
-
LEFT: MOUSE.ROTATE,
|
|
40
|
-
MIDDLE: MOUSE.DOLLY,
|
|
41
|
-
RIGHT: MOUSE.PAN,
|
|
42
|
-
};
|
|
43
|
-
// internals
|
|
44
|
-
this.target = new Vector3();
|
|
45
|
-
const EPS = 0.000001;
|
|
46
|
-
const lastPosition = new Vector3();
|
|
47
|
-
let lastZoom = 1;
|
|
48
|
-
let _state = STATE.NONE, _keyState = STATE.NONE, _touchZoomDistanceStart = 0, _touchZoomDistanceEnd = 0, _lastAngle = 0;
|
|
49
|
-
const _eye = new Vector3(), _movePrev = new Vector2(), _moveCurr = new Vector2(), _lastAxis = new Vector3(), _zoomStart = new Vector2(), _zoomEnd = new Vector2(), _panStart = new Vector2(), _panEnd = new Vector2(), _pointers = [], _pointerPositions = {};
|
|
50
|
-
// for reset
|
|
51
|
-
this.target0 = this.target.clone();
|
|
52
|
-
this.position0 = this.object.position.clone();
|
|
53
|
-
this.up0 = this.object.up.clone();
|
|
54
|
-
this.zoom0 = this.object.zoom;
|
|
55
|
-
// methods
|
|
56
|
-
this.handleResize = function () {
|
|
57
|
-
const box = scope.domElement.getBoundingClientRect();
|
|
58
|
-
// adjustments come from similar code in the jquery offset() function
|
|
59
|
-
const d = scope.domElement.ownerDocument.documentElement;
|
|
60
|
-
scope.screen.left = box.left + window.pageXOffset - d.clientLeft;
|
|
61
|
-
scope.screen.top = box.top + window.pageYOffset - d.clientTop;
|
|
62
|
-
scope.screen.width = box.width;
|
|
63
|
-
scope.screen.height = box.height;
|
|
64
|
-
};
|
|
65
|
-
const getMouseOnScreen = (function () {
|
|
66
|
-
const vector = new Vector2();
|
|
67
|
-
return function getMouseOnScreen(pageX, pageY) {
|
|
68
|
-
vector.set((pageX - scope.screen.left) / scope.screen.width, (pageY - scope.screen.top) / scope.screen.height);
|
|
69
|
-
return vector;
|
|
70
|
-
};
|
|
71
|
-
})();
|
|
72
|
-
const getMouseOnCircle = (function () {
|
|
73
|
-
const vector = new Vector2();
|
|
74
|
-
return function getMouseOnCircle(pageX, pageY) {
|
|
75
|
-
vector.set((pageX - scope.screen.width * 0.5 - scope.screen.left) /
|
|
76
|
-
(scope.screen.width * 0.5), (scope.screen.height + 2 * (scope.screen.top - pageY)) /
|
|
77
|
-
scope.screen.width // screen.width intentional
|
|
78
|
-
);
|
|
79
|
-
return vector;
|
|
80
|
-
};
|
|
81
|
-
})();
|
|
82
|
-
this.rotateCamera = (function () {
|
|
83
|
-
const axis = new Vector3(), quaternion = new Quaternion(), eyeDirection = new Vector3(), objectUpDirection = new Vector3(), objectSidewaysDirection = new Vector3(), moveDirection = new Vector3();
|
|
84
|
-
return function rotateCamera() {
|
|
85
|
-
moveDirection.set(_moveCurr.x - _movePrev.x, _moveCurr.y - _movePrev.y, 0);
|
|
86
|
-
let angle = moveDirection.length();
|
|
87
|
-
if (angle) {
|
|
88
|
-
_eye.copy(scope.object.position).sub(scope.target);
|
|
89
|
-
eyeDirection.copy(_eye).normalize();
|
|
90
|
-
objectUpDirection.copy(scope.object.up).normalize();
|
|
91
|
-
objectSidewaysDirection
|
|
92
|
-
.crossVectors(objectUpDirection, eyeDirection)
|
|
93
|
-
.normalize();
|
|
94
|
-
objectUpDirection.setLength(_moveCurr.y - _movePrev.y);
|
|
95
|
-
objectSidewaysDirection.setLength(_moveCurr.x - _movePrev.x);
|
|
96
|
-
moveDirection.copy(objectUpDirection.add(objectSidewaysDirection));
|
|
97
|
-
axis.crossVectors(moveDirection, _eye).normalize();
|
|
98
|
-
angle *= scope.rotateSpeed;
|
|
99
|
-
quaternion.setFromAxisAngle(axis, angle);
|
|
100
|
-
_eye.applyQuaternion(quaternion);
|
|
101
|
-
scope.object.up.applyQuaternion(quaternion);
|
|
102
|
-
_lastAxis.copy(axis);
|
|
103
|
-
_lastAngle = angle;
|
|
104
|
-
}
|
|
105
|
-
else if (!scope.staticMoving && _lastAngle) {
|
|
106
|
-
_lastAngle *= Math.sqrt(1.0 - scope.dynamicDampingFactor);
|
|
107
|
-
_eye.copy(scope.object.position).sub(scope.target);
|
|
108
|
-
quaternion.setFromAxisAngle(_lastAxis, _lastAngle);
|
|
109
|
-
_eye.applyQuaternion(quaternion);
|
|
110
|
-
scope.object.up.applyQuaternion(quaternion);
|
|
111
|
-
}
|
|
112
|
-
_movePrev.copy(_moveCurr);
|
|
113
|
-
};
|
|
114
|
-
})();
|
|
115
|
-
this.zoomCamera = function () {
|
|
116
|
-
let factor;
|
|
117
|
-
if (_state === STATE.TOUCH_ZOOM_PAN) {
|
|
118
|
-
factor = _touchZoomDistanceStart / _touchZoomDistanceEnd;
|
|
119
|
-
_touchZoomDistanceStart = _touchZoomDistanceEnd;
|
|
120
|
-
if (scope.object.isPerspectiveCamera) {
|
|
121
|
-
_eye.multiplyScalar(factor);
|
|
122
|
-
}
|
|
123
|
-
else if (scope.object.isOrthographicCamera) {
|
|
124
|
-
scope.object.zoom = MathUtils.clamp(scope.object.zoom / factor, scope.minZoom, scope.maxZoom);
|
|
125
|
-
if (lastZoom !== scope.object.zoom) {
|
|
126
|
-
scope.object.updateProjectionMatrix();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
console.warn("THREE.TrackballControls: Unsupported camera type");
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
factor = 1.0 + (_zoomEnd.y - _zoomStart.y) * scope.zoomSpeed;
|
|
135
|
-
if (factor !== 1.0 && factor > 0.0) {
|
|
136
|
-
if (scope.object.isPerspectiveCamera) {
|
|
137
|
-
_eye.multiplyScalar(factor);
|
|
138
|
-
}
|
|
139
|
-
else if (scope.object.isOrthographicCamera) {
|
|
140
|
-
scope.object.zoom = MathUtils.clamp(scope.object.zoom / factor, scope.minZoom, scope.maxZoom);
|
|
141
|
-
if (lastZoom !== scope.object.zoom) {
|
|
142
|
-
scope.object.updateProjectionMatrix();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
console.warn("THREE.TrackballControls: Unsupported camera type");
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (scope.staticMoving) {
|
|
150
|
-
_zoomStart.copy(_zoomEnd);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
_zoomStart.y +=
|
|
154
|
-
(_zoomEnd.y - _zoomStart.y) * this.dynamicDampingFactor;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
this.panCamera = (function () {
|
|
159
|
-
const mouseChange = new Vector2(), objectUp = new Vector3(), pan = new Vector3();
|
|
160
|
-
return function panCamera() {
|
|
161
|
-
mouseChange.copy(_panEnd).sub(_panStart);
|
|
162
|
-
if (mouseChange.lengthSq()) {
|
|
163
|
-
if (scope.object.isOrthographicCamera) {
|
|
164
|
-
const scale_x = (scope.object.right -
|
|
165
|
-
scope.object.left) /
|
|
166
|
-
scope.object.zoom /
|
|
167
|
-
scope.domElement.clientWidth;
|
|
168
|
-
const scale_y = (scope.object.top -
|
|
169
|
-
scope.object.bottom) /
|
|
170
|
-
scope.object.zoom /
|
|
171
|
-
scope.domElement.clientWidth;
|
|
172
|
-
mouseChange.x *= scale_x;
|
|
173
|
-
mouseChange.y *= scale_y;
|
|
174
|
-
}
|
|
175
|
-
mouseChange.multiplyScalar(_eye.length() * scope.panSpeed);
|
|
176
|
-
pan.copy(_eye).cross(scope.object.up).setLength(mouseChange.x);
|
|
177
|
-
pan.add(objectUp.copy(scope.object.up).setLength(mouseChange.y));
|
|
178
|
-
scope.object.position.add(pan);
|
|
179
|
-
scope.target.add(pan);
|
|
180
|
-
if (scope.staticMoving) {
|
|
181
|
-
_panStart.copy(_panEnd);
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
_panStart.add(mouseChange
|
|
185
|
-
.subVectors(_panEnd, _panStart)
|
|
186
|
-
.multiplyScalar(scope.dynamicDampingFactor));
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
})();
|
|
191
|
-
this.checkDistances = function () {
|
|
192
|
-
if (!scope.noZoom || !scope.noPan) {
|
|
193
|
-
if (_eye.lengthSq() > scope.maxDistance * scope.maxDistance) {
|
|
194
|
-
scope.object.position.addVectors(scope.target, _eye.setLength(scope.maxDistance));
|
|
195
|
-
_zoomStart.copy(_zoomEnd);
|
|
196
|
-
}
|
|
197
|
-
if (_eye.lengthSq() < scope.minDistance * scope.minDistance) {
|
|
198
|
-
scope.object.position.addVectors(scope.target, _eye.setLength(scope.minDistance));
|
|
199
|
-
_zoomStart.copy(_zoomEnd);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
this.update = function () {
|
|
204
|
-
_eye.subVectors(scope.object.position, scope.target);
|
|
205
|
-
if (!scope.noRotate) {
|
|
206
|
-
scope.rotateCamera();
|
|
207
|
-
}
|
|
208
|
-
if (!scope.noZoom) {
|
|
209
|
-
scope.zoomCamera();
|
|
210
|
-
}
|
|
211
|
-
if (!scope.noPan) {
|
|
212
|
-
scope.panCamera();
|
|
213
|
-
}
|
|
214
|
-
scope.object.position.addVectors(scope.target, _eye);
|
|
215
|
-
if (scope.object.isPerspectiveCamera) {
|
|
216
|
-
scope.checkDistances();
|
|
217
|
-
scope.object.lookAt(scope.target);
|
|
218
|
-
if (lastPosition.distanceToSquared(scope.object.position) > EPS) {
|
|
219
|
-
scope.dispatchEvent(_changeEvent);
|
|
220
|
-
lastPosition.copy(scope.object.position);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
else if (scope.object.isOrthographicCamera) {
|
|
224
|
-
scope.object.lookAt(scope.target);
|
|
225
|
-
if (lastPosition.distanceToSquared(scope.object.position) > EPS ||
|
|
226
|
-
lastZoom !== scope.object.zoom) {
|
|
227
|
-
scope.dispatchEvent(_changeEvent);
|
|
228
|
-
lastPosition.copy(scope.object.position);
|
|
229
|
-
lastZoom = scope.object.zoom;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
console.warn("THREE.TrackballControls: Unsupported camera type");
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
this.reset = function () {
|
|
237
|
-
_state = STATE.NONE;
|
|
238
|
-
_keyState = STATE.NONE;
|
|
239
|
-
scope.target.copy(scope.target0);
|
|
240
|
-
scope.object.position.copy(scope.position0);
|
|
241
|
-
scope.object.up.copy(scope.up0);
|
|
242
|
-
scope.object.zoom = scope.zoom0;
|
|
243
|
-
scope.object.updateProjectionMatrix();
|
|
244
|
-
_eye.subVectors(scope.object.position, scope.target);
|
|
245
|
-
scope.object.lookAt(scope.target);
|
|
246
|
-
scope.dispatchEvent(_changeEvent);
|
|
247
|
-
lastPosition.copy(scope.object.position);
|
|
248
|
-
lastZoom = scope.object.zoom;
|
|
249
|
-
};
|
|
250
|
-
// listeners
|
|
251
|
-
function onPointerDown(event) {
|
|
252
|
-
if (scope.enabled === false)
|
|
253
|
-
return;
|
|
254
|
-
if (_pointers.length === 0) {
|
|
255
|
-
scope.domElement.setPointerCapture(event.pointerId);
|
|
256
|
-
scope.domElement.addEventListener("pointermove", onPointerMove);
|
|
257
|
-
scope.domElement.addEventListener("pointerup", onPointerUp);
|
|
258
|
-
}
|
|
259
|
-
//
|
|
260
|
-
addPointer(event);
|
|
261
|
-
if (event.pointerType === "touch") {
|
|
262
|
-
onTouchStart(event);
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
onMouseDown(event);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
function onPointerMove(event) {
|
|
269
|
-
if (scope.enabled === false)
|
|
270
|
-
return;
|
|
271
|
-
if (event.pointerType === "touch") {
|
|
272
|
-
onTouchMove(event);
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
onMouseMove(event);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
function onPointerUp(event) {
|
|
279
|
-
if (scope.enabled === false)
|
|
280
|
-
return;
|
|
281
|
-
if (event.pointerType === "touch") {
|
|
282
|
-
onTouchEnd(event);
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
onMouseUp();
|
|
286
|
-
}
|
|
287
|
-
//
|
|
288
|
-
removePointer(event);
|
|
289
|
-
if (_pointers.length === 0) {
|
|
290
|
-
scope.domElement.releasePointerCapture(event.pointerId);
|
|
291
|
-
scope.domElement.removeEventListener("pointermove", onPointerMove);
|
|
292
|
-
scope.domElement.removeEventListener("pointerup", onPointerUp);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
function onPointerCancel(event) {
|
|
296
|
-
removePointer(event);
|
|
297
|
-
}
|
|
298
|
-
function keydown(event) {
|
|
299
|
-
if (scope.enabled === false)
|
|
300
|
-
return;
|
|
301
|
-
window.removeEventListener("keydown", keydown);
|
|
302
|
-
if (_keyState !== STATE.NONE) {
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
else if (event.code === scope.keys[STATE.ROTATE] && !scope.noRotate) {
|
|
306
|
-
_keyState = STATE.ROTATE;
|
|
307
|
-
}
|
|
308
|
-
else if (event.code === scope.keys[STATE.ZOOM] && !scope.noZoom) {
|
|
309
|
-
_keyState = STATE.ZOOM;
|
|
310
|
-
}
|
|
311
|
-
else if (event.code === scope.keys[STATE.PAN] && !scope.noPan) {
|
|
312
|
-
_keyState = STATE.PAN;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
function keyup() {
|
|
316
|
-
if (scope.enabled === false)
|
|
317
|
-
return;
|
|
318
|
-
_keyState = STATE.NONE;
|
|
319
|
-
window.addEventListener("keydown", keydown);
|
|
320
|
-
}
|
|
321
|
-
function onMouseDown(event) {
|
|
322
|
-
if (_state === STATE.NONE) {
|
|
323
|
-
switch (event.button) {
|
|
324
|
-
case scope.mouseButtons.LEFT:
|
|
325
|
-
_state = STATE.ROTATE;
|
|
326
|
-
break;
|
|
327
|
-
case scope.mouseButtons.MIDDLE:
|
|
328
|
-
_state = STATE.ZOOM;
|
|
329
|
-
break;
|
|
330
|
-
case scope.mouseButtons.RIGHT:
|
|
331
|
-
_state = STATE.PAN;
|
|
332
|
-
break;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
const state = _keyState !== STATE.NONE ? _keyState : _state;
|
|
336
|
-
if (state === STATE.ROTATE && !scope.noRotate) {
|
|
337
|
-
_moveCurr.copy(getMouseOnCircle(event.pageX, event.pageY));
|
|
338
|
-
_movePrev.copy(_moveCurr);
|
|
339
|
-
}
|
|
340
|
-
else if (state === STATE.ZOOM && !scope.noZoom) {
|
|
341
|
-
_zoomStart.copy(getMouseOnScreen(event.pageX, event.pageY));
|
|
342
|
-
_zoomEnd.copy(_zoomStart);
|
|
343
|
-
}
|
|
344
|
-
else if (state === STATE.PAN && !scope.noPan) {
|
|
345
|
-
_panStart.copy(getMouseOnScreen(event.pageX, event.pageY));
|
|
346
|
-
_panEnd.copy(_panStart);
|
|
347
|
-
}
|
|
348
|
-
scope.dispatchEvent(_startEvent);
|
|
349
|
-
}
|
|
350
|
-
function onMouseMove(event) {
|
|
351
|
-
const state = _keyState !== STATE.NONE ? _keyState : _state;
|
|
352
|
-
if (state === STATE.ROTATE && !scope.noRotate) {
|
|
353
|
-
_movePrev.copy(_moveCurr);
|
|
354
|
-
_moveCurr.copy(getMouseOnCircle(event.pageX, event.pageY));
|
|
355
|
-
}
|
|
356
|
-
else if (state === STATE.ZOOM && !scope.noZoom) {
|
|
357
|
-
_zoomEnd.copy(getMouseOnScreen(event.pageX, event.pageY));
|
|
358
|
-
}
|
|
359
|
-
else if (state === STATE.PAN && !scope.noPan) {
|
|
360
|
-
_panEnd.copy(getMouseOnScreen(event.pageX, event.pageY));
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
function onMouseUp() {
|
|
364
|
-
_state = STATE.NONE;
|
|
365
|
-
scope.dispatchEvent(_endEvent);
|
|
366
|
-
}
|
|
367
|
-
function onMouseWheel(event) {
|
|
368
|
-
if (scope.enabled === false)
|
|
369
|
-
return;
|
|
370
|
-
if (scope.noZoom === true)
|
|
371
|
-
return;
|
|
372
|
-
event.preventDefault();
|
|
373
|
-
switch (event.deltaMode) {
|
|
374
|
-
case 2:
|
|
375
|
-
// Zoom in pages
|
|
376
|
-
_zoomStart.y -= event.deltaY * 0.025;
|
|
377
|
-
break;
|
|
378
|
-
case 1:
|
|
379
|
-
// Zoom in lines
|
|
380
|
-
_zoomStart.y -= event.deltaY * 0.01;
|
|
381
|
-
break;
|
|
382
|
-
default:
|
|
383
|
-
// undefined, 0, assume pixels
|
|
384
|
-
_zoomStart.y -= event.deltaY * 0.00025;
|
|
385
|
-
break;
|
|
386
|
-
}
|
|
387
|
-
scope.dispatchEvent(_startEvent);
|
|
388
|
-
scope.dispatchEvent(_endEvent);
|
|
389
|
-
}
|
|
390
|
-
function onTouchStart(event) {
|
|
391
|
-
trackPointer(event);
|
|
392
|
-
switch (_pointers.length) {
|
|
393
|
-
case 1:
|
|
394
|
-
_state = STATE.TOUCH_ROTATE;
|
|
395
|
-
_moveCurr.copy(getMouseOnCircle(_pointers[0].pageX, _pointers[0].pageY));
|
|
396
|
-
_movePrev.copy(_moveCurr);
|
|
397
|
-
break;
|
|
398
|
-
case 2:
|
|
399
|
-
_state = STATE.TOUCH_ZOOM_PAN;
|
|
400
|
-
const dx = _pointers[0].pageX - _pointers[1].pageX;
|
|
401
|
-
const dy = _pointers[0].pageY - _pointers[1].pageY;
|
|
402
|
-
_touchZoomDistanceEnd = _touchZoomDistanceStart = Math.sqrt(dx * dx + dy * dy);
|
|
403
|
-
const x = (_pointers[0].pageX + _pointers[1].pageX) / 2;
|
|
404
|
-
const y = (_pointers[0].pageY + _pointers[1].pageY) / 2;
|
|
405
|
-
_panStart.copy(getMouseOnScreen(x, y));
|
|
406
|
-
_panEnd.copy(_panStart);
|
|
407
|
-
break;
|
|
408
|
-
case 3:
|
|
409
|
-
_state = STATE.TOUCH_PAN;
|
|
410
|
-
const centerX = (_pointers[0].pageX + _pointers[1].pageX + _pointers[2].pageX) / 3;
|
|
411
|
-
const centerY = (_pointers[0].pageY + _pointers[1].pageY + _pointers[2].pageY) / 3;
|
|
412
|
-
_panStart.copy(getMouseOnScreen(centerX, centerY));
|
|
413
|
-
_panEnd.copy(_panStart);
|
|
414
|
-
break;
|
|
415
|
-
}
|
|
416
|
-
scope.dispatchEvent(_startEvent);
|
|
417
|
-
}
|
|
418
|
-
function onTouchMove(event) {
|
|
419
|
-
trackPointer(event);
|
|
420
|
-
let position, x, y;
|
|
421
|
-
switch (_pointers.length) {
|
|
422
|
-
case 1:
|
|
423
|
-
if (_state != STATE.TOUCH_ROTATE)
|
|
424
|
-
return;
|
|
425
|
-
_movePrev.copy(_moveCurr);
|
|
426
|
-
_moveCurr.copy(getMouseOnCircle(event.pageX, event.pageY));
|
|
427
|
-
break;
|
|
428
|
-
case 2:
|
|
429
|
-
if (_state != STATE.TOUCH_ZOOM_PAN)
|
|
430
|
-
return;
|
|
431
|
-
position = getSecondPointerPosition(event);
|
|
432
|
-
const dx = event.pageX - position.x;
|
|
433
|
-
const dy = event.pageY - position.y;
|
|
434
|
-
_touchZoomDistanceEnd = Math.sqrt(dx * dx + dy * dy);
|
|
435
|
-
x = (event.pageX + position.x) / 2;
|
|
436
|
-
y = (event.pageY + position.y) / 2;
|
|
437
|
-
_panEnd.copy(getMouseOnScreen(x, y));
|
|
438
|
-
break;
|
|
439
|
-
case 3:
|
|
440
|
-
if (_state != STATE.TOUCH_PAN)
|
|
441
|
-
return;
|
|
442
|
-
const point_1 = _pointerPositions[_pointers[0].pointerId];
|
|
443
|
-
const point_2 = _pointerPositions[_pointers[1].pointerId];
|
|
444
|
-
const point_3 = _pointerPositions[_pointers[2].pointerId];
|
|
445
|
-
const centerX = (point_1.x + point_2.x + point_3.x) / 3;
|
|
446
|
-
const centerY = (point_1.y + point_2.y + point_3.y) / 3;
|
|
447
|
-
_panEnd.copy(getMouseOnScreen(centerX, centerY));
|
|
448
|
-
break;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
function onTouchEnd(event) {
|
|
452
|
-
switch (_pointers.length) {
|
|
453
|
-
case 0:
|
|
454
|
-
_state = STATE.NONE;
|
|
455
|
-
break;
|
|
456
|
-
case 1:
|
|
457
|
-
_state = STATE.TOUCH_ROTATE;
|
|
458
|
-
_moveCurr.copy(getMouseOnCircle(event.pageX, event.pageY));
|
|
459
|
-
_movePrev.copy(_moveCurr);
|
|
460
|
-
break;
|
|
461
|
-
case 2:
|
|
462
|
-
_state = STATE.TOUCH_ZOOM_PAN;
|
|
463
|
-
for (let i = 0; i < _pointers.length; i++) {
|
|
464
|
-
if (_pointers[i].pointerId !== event.pointerId) {
|
|
465
|
-
const position = _pointerPositions[_pointers[i].pointerId];
|
|
466
|
-
_moveCurr.copy(getMouseOnScreen(position.x, position.y));
|
|
467
|
-
_movePrev.copy(_moveCurr);
|
|
468
|
-
break;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
break;
|
|
472
|
-
case 3:
|
|
473
|
-
_state = STATE.TOUCH_PAN;
|
|
474
|
-
for (let i = 0; i < _pointers.length; i++) {
|
|
475
|
-
if (_pointers[i].pointerId !== event.pointerId) {
|
|
476
|
-
const position = _pointerPositions[_pointers[i].pointerId];
|
|
477
|
-
_moveCurr.copy(getMouseOnScreen(position.x, position.y));
|
|
478
|
-
_movePrev.copy(_moveCurr);
|
|
479
|
-
break;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
break;
|
|
483
|
-
}
|
|
484
|
-
scope.dispatchEvent(_endEvent);
|
|
485
|
-
}
|
|
486
|
-
function contextmenu(event) {
|
|
487
|
-
if (scope.enabled === false)
|
|
488
|
-
return;
|
|
489
|
-
event.preventDefault();
|
|
490
|
-
}
|
|
491
|
-
function addPointer(event) {
|
|
492
|
-
_pointers.push(event);
|
|
493
|
-
}
|
|
494
|
-
function removePointer(event) {
|
|
495
|
-
delete _pointerPositions[event.pointerId];
|
|
496
|
-
for (let i = 0; i < _pointers.length; i++) {
|
|
497
|
-
if (_pointers[i].pointerId == event.pointerId) {
|
|
498
|
-
_pointers.splice(i, 1);
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
function trackPointer(event) {
|
|
504
|
-
let position = _pointerPositions[event.pointerId];
|
|
505
|
-
if (position === undefined) {
|
|
506
|
-
position = new Vector2();
|
|
507
|
-
_pointerPositions[event.pointerId] = position;
|
|
508
|
-
}
|
|
509
|
-
position.set(event.pageX, event.pageY);
|
|
510
|
-
}
|
|
511
|
-
function getSecondPointerPosition(event) {
|
|
512
|
-
const pointer = event.pointerId === _pointers[0].pointerId
|
|
513
|
-
? _pointers[1]
|
|
514
|
-
: _pointers[0];
|
|
515
|
-
return _pointerPositions[pointer.pointerId];
|
|
516
|
-
}
|
|
517
|
-
this.dispose = function () {
|
|
518
|
-
scope.domElement.removeEventListener("contextmenu", contextmenu);
|
|
519
|
-
scope.domElement.removeEventListener("pointerdown", onPointerDown);
|
|
520
|
-
scope.domElement.removeEventListener("pointercancel", onPointerCancel);
|
|
521
|
-
scope.domElement.removeEventListener("wheel", onMouseWheel);
|
|
522
|
-
scope.domElement.removeEventListener("pointermove", onPointerMove);
|
|
523
|
-
scope.domElement.removeEventListener("pointerup", onPointerUp);
|
|
524
|
-
window.removeEventListener("keydown", keydown);
|
|
525
|
-
window.removeEventListener("keyup", keyup);
|
|
526
|
-
};
|
|
527
|
-
this.domElement.addEventListener("contextmenu", contextmenu);
|
|
528
|
-
this.domElement.addEventListener("pointerdown", onPointerDown);
|
|
529
|
-
this.domElement.addEventListener("pointercancel", onPointerCancel);
|
|
530
|
-
this.domElement.addEventListener("wheel", onMouseWheel, { passive: false });
|
|
531
|
-
window.addEventListener("keydown", keydown);
|
|
532
|
-
window.addEventListener("keyup", keyup);
|
|
533
|
-
this.handleResize();
|
|
534
|
-
// force an update at start
|
|
535
|
-
this.update();
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
export { Copper3dTrackballControls1 };
|
|
539
|
-
//# sourceMappingURL=Copper3dTrackballControls1.js.map
|