three-stdlib 2.6.2 → 2.7.1
Sign up to get free protection for your applications and to get access to all the features.
- package/{Nodes-244507d0.js → Nodes-894ac9dc.js} +0 -0
- package/{Nodes-acab3ca5.js → Nodes-af575af7.js} +0 -0
- package/controls/ArcballControls.cjs.js +1 -1
- package/controls/ArcballControls.d.ts +162 -0
- package/controls/ArcballControls.js +556 -273
- package/controls/OrbitControls.cjs.js +1 -1
- package/controls/OrbitControls.d.ts +1 -0
- package/controls/OrbitControls.js +13 -2
- package/controls/TransformControls.cjs.js +1 -1
- package/controls/TransformControls.d.ts +2 -1
- package/controls/TransformControls.js +25 -26
- package/geometries/TeapotGeometry.js +2 -2
- package/geometries/TextGeometry.cjs.js +1 -0
- package/geometries/TextGeometry.d.ts +16 -0
- package/geometries/TextGeometry.js +26 -0
- package/index.cjs.js +1 -1
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/loaders/AMFLoader.js +1 -3
- package/loaders/ColladaLoader.cjs.js +1 -1
- package/loaders/ColladaLoader.js +58 -35
- package/loaders/EXRLoader.cjs.js +1 -1
- package/loaders/EXRLoader.js +197 -262
- package/loaders/FBXLoader.cjs.js +1 -1
- package/loaders/FBXLoader.js +41 -90
- package/loaders/FontLoader.cjs.js +1 -0
- package/loaders/FontLoader.d.ts +32 -0
- package/loaders/FontLoader.js +139 -0
- package/loaders/GLTFLoader.cjs.js +1 -1
- package/loaders/GLTFLoader.js +161 -75
- package/loaders/HDRCubeTextureLoader.cjs.js +1 -1
- package/loaders/HDRCubeTextureLoader.js +2 -10
- package/loaders/NodeMaterialLoader.cjs.js +1 -1
- package/loaders/RGBELoader.cjs.js +1 -1
- package/loaders/RGBELoader.js +11 -25
- package/loaders/RGBMLoader.cjs.js +1 -1
- package/loaders/RGBMLoader.js +225 -263
- package/loaders/STLLoader.js +7 -7
- package/loaders/SVGLoader.cjs.js +1 -1
- package/loaders/SVGLoader.js +46 -30
- package/loaders/VRMLLoader.cjs.js +1 -1
- package/loaders/VRMLLoader.js +2 -1
- package/nodes/accessors/CameraNode.js +12 -12
- package/nodes/accessors/PositionNode.js +3 -3
- package/nodes/accessors/ReflectNode.js +3 -3
- package/nodes/core/FunctionNode.js +3 -3
- package/nodes/core/InputNode.js +3 -3
- package/nodes/core/Node.js +6 -6
- package/nodes/core/NodeBuilder.cjs.js +1 -1
- package/nodes/core/NodeBuilder.js +2 -2
- package/nodes/core/TempNode.js +6 -6
- package/nodes/effects/BlurNode.js +3 -3
- package/nodes/inputs/CubeTextureNode.cjs.js +1 -1
- package/nodes/inputs/RTTNode.cjs.js +1 -1
- package/nodes/inputs/ReflectorNode.cjs.js +1 -1
- package/nodes/inputs/ScreenNode.cjs.js +1 -1
- package/nodes/inputs/TextureNode.cjs.js +1 -1
- package/nodes/materials/BasicNodeMaterial.cjs.js +1 -1
- package/nodes/materials/NodeMaterial.cjs.js +1 -1
- package/nodes/materials/SpriteNodeMaterial.cjs.js +1 -1
- package/nodes/math/MathNode.js +3 -3
- package/nodes/postprocessing/NodePass.cjs.js +1 -1
- package/nodes/postprocessing/NodePostProcessing.cjs.js +1 -1
- package/nodes/utils/ColorSpaceNode.cjs.js +1 -1
- package/nodes/utils/ColorSpaceNode.js +2 -45
- package/nodes/utils/VelocityNode.js +6 -6
- package/package.json +2 -2
- package/renderers/nodes/accessors/UVNode.js +1 -3
- package/renderers/nodes/core/AttributeNode.js +1 -3
- package/renderers/nodes/core/Node.js +4 -12
- package/renderers/nodes/core/NodeBuilder.js +6 -18
- package/shaders/GammaCorrectionShader.js +1 -2
- package/webxr/ARButton.js +6 -6
- package/webxr/VRButton.js +6 -6
@@ -1,6 +1,7 @@
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
2
2
|
import { Matrix4, EventDispatcher, EllipseCurve, BufferGeometry, MathUtils, Vector3, GridHelper, LineBasicMaterial, Line, Raycaster, Vector2, Quaternion, Group, Box3, Sphere } from 'three';
|
3
3
|
|
4
|
+
//trackball state
|
4
5
|
const STATE = {
|
5
6
|
IDLE: Symbol(),
|
6
7
|
ROTATE: Symbol(),
|
@@ -43,25 +44,211 @@ const _endEvent = {
|
|
43
44
|
};
|
44
45
|
/**
|
45
46
|
*
|
46
|
-
* @param {
|
47
|
-
* @param {HTMLElement} domElement Renderer's dom element
|
48
|
-
* @param {Scene} scene The scene to be rendered
|
47
|
+
* @param {CamOrthographicCamera | PerspectiveCameraera} camera Virtual camera used in the scene
|
48
|
+
* @param {HTMLElement=null} domElement Renderer's dom element
|
49
|
+
* @param {Scene=null} scene The scene to be rendered
|
49
50
|
*/
|
50
51
|
|
51
52
|
class ArcballControls extends EventDispatcher {
|
52
|
-
constructor(_camera, _domElement, scene = null) {
|
53
|
+
constructor(_camera, _domElement = null, scene = null) {
|
53
54
|
super();
|
54
55
|
|
56
|
+
_defineProperty(this, "camera", void 0);
|
57
|
+
|
58
|
+
_defineProperty(this, "domElement", void 0);
|
59
|
+
|
60
|
+
_defineProperty(this, "scene", void 0);
|
61
|
+
|
62
|
+
_defineProperty(this, "mouseActions", void 0);
|
63
|
+
|
64
|
+
_defineProperty(this, "_mouseOp", void 0);
|
65
|
+
|
66
|
+
_defineProperty(this, "_v2_1", void 0);
|
67
|
+
|
68
|
+
_defineProperty(this, "_v3_1", void 0);
|
69
|
+
|
70
|
+
_defineProperty(this, "_v3_2", void 0);
|
71
|
+
|
72
|
+
_defineProperty(this, "_m4_1", void 0);
|
73
|
+
|
74
|
+
_defineProperty(this, "_m4_2", void 0);
|
75
|
+
|
76
|
+
_defineProperty(this, "_quat", void 0);
|
77
|
+
|
78
|
+
_defineProperty(this, "_translationMatrix", void 0);
|
79
|
+
|
80
|
+
_defineProperty(this, "_rotationMatrix", void 0);
|
81
|
+
|
82
|
+
_defineProperty(this, "_scaleMatrix", void 0);
|
83
|
+
|
84
|
+
_defineProperty(this, "_rotationAxis", void 0);
|
85
|
+
|
86
|
+
_defineProperty(this, "_cameraMatrixState", void 0);
|
87
|
+
|
88
|
+
_defineProperty(this, "_cameraProjectionState", void 0);
|
89
|
+
|
90
|
+
_defineProperty(this, "_fovState", void 0);
|
91
|
+
|
92
|
+
_defineProperty(this, "_upState", void 0);
|
93
|
+
|
94
|
+
_defineProperty(this, "_zoomState", void 0);
|
95
|
+
|
96
|
+
_defineProperty(this, "_nearPos", void 0);
|
97
|
+
|
98
|
+
_defineProperty(this, "_farPos", void 0);
|
99
|
+
|
100
|
+
_defineProperty(this, "_gizmoMatrixState", void 0);
|
101
|
+
|
102
|
+
_defineProperty(this, "_up0", void 0);
|
103
|
+
|
104
|
+
_defineProperty(this, "_zoom0", void 0);
|
105
|
+
|
106
|
+
_defineProperty(this, "_fov0", void 0);
|
107
|
+
|
108
|
+
_defineProperty(this, "_initialNear", void 0);
|
109
|
+
|
110
|
+
_defineProperty(this, "_nearPos0", void 0);
|
111
|
+
|
112
|
+
_defineProperty(this, "_initialFar", void 0);
|
113
|
+
|
114
|
+
_defineProperty(this, "_farPos0", void 0);
|
115
|
+
|
116
|
+
_defineProperty(this, "_cameraMatrixState0", void 0);
|
117
|
+
|
118
|
+
_defineProperty(this, "_gizmoMatrixState0", void 0);
|
119
|
+
|
120
|
+
_defineProperty(this, "_button", void 0);
|
121
|
+
|
122
|
+
_defineProperty(this, "_touchStart", void 0);
|
123
|
+
|
124
|
+
_defineProperty(this, "_touchCurrent", void 0);
|
125
|
+
|
126
|
+
_defineProperty(this, "_input", void 0);
|
127
|
+
|
128
|
+
_defineProperty(this, "_switchSensibility", void 0);
|
129
|
+
|
130
|
+
_defineProperty(this, "_startFingerDistance", void 0);
|
131
|
+
|
132
|
+
_defineProperty(this, "_currentFingerDistance", void 0);
|
133
|
+
|
134
|
+
_defineProperty(this, "_startFingerRotation", void 0);
|
135
|
+
|
136
|
+
_defineProperty(this, "_currentFingerRotation", void 0);
|
137
|
+
|
138
|
+
_defineProperty(this, "_devPxRatio", void 0);
|
139
|
+
|
140
|
+
_defineProperty(this, "_downValid", void 0);
|
141
|
+
|
142
|
+
_defineProperty(this, "_nclicks", void 0);
|
143
|
+
|
144
|
+
_defineProperty(this, "_downEvents", void 0);
|
145
|
+
|
146
|
+
_defineProperty(this, "_clickStart", void 0);
|
147
|
+
|
148
|
+
_defineProperty(this, "_maxDownTime", void 0);
|
149
|
+
|
150
|
+
_defineProperty(this, "_maxInterval", void 0);
|
151
|
+
|
152
|
+
_defineProperty(this, "_posThreshold", void 0);
|
153
|
+
|
154
|
+
_defineProperty(this, "_movementThreshold", void 0);
|
155
|
+
|
156
|
+
_defineProperty(this, "_currentCursorPosition", void 0);
|
157
|
+
|
158
|
+
_defineProperty(this, "_startCursorPosition", void 0);
|
159
|
+
|
160
|
+
_defineProperty(this, "_grid", void 0);
|
161
|
+
|
162
|
+
_defineProperty(this, "_gridPosition", void 0);
|
163
|
+
|
164
|
+
_defineProperty(this, "_gizmos", void 0);
|
165
|
+
|
166
|
+
_defineProperty(this, "_curvePts", void 0);
|
167
|
+
|
168
|
+
_defineProperty(this, "_timeStart", void 0);
|
169
|
+
|
170
|
+
_defineProperty(this, "_animationId", void 0);
|
171
|
+
|
172
|
+
_defineProperty(this, "focusAnimationTime", void 0);
|
173
|
+
|
174
|
+
_defineProperty(this, "_timePrev", void 0);
|
175
|
+
|
176
|
+
_defineProperty(this, "_timeCurrent", void 0);
|
177
|
+
|
178
|
+
_defineProperty(this, "_anglePrev", void 0);
|
179
|
+
|
180
|
+
_defineProperty(this, "_angleCurrent", void 0);
|
181
|
+
|
182
|
+
_defineProperty(this, "_cursorPosPrev", void 0);
|
183
|
+
|
184
|
+
_defineProperty(this, "_cursorPosCurr", void 0);
|
185
|
+
|
186
|
+
_defineProperty(this, "_wPrev", void 0);
|
187
|
+
|
188
|
+
_defineProperty(this, "_wCurr", void 0);
|
189
|
+
|
190
|
+
_defineProperty(this, "adjustNearFar", void 0);
|
191
|
+
|
192
|
+
_defineProperty(this, "scaleFactor", void 0);
|
193
|
+
|
194
|
+
_defineProperty(this, "dampingFactor", void 0);
|
195
|
+
|
196
|
+
_defineProperty(this, "wMax", void 0);
|
197
|
+
|
198
|
+
_defineProperty(this, "enableAnimations", void 0);
|
199
|
+
|
200
|
+
_defineProperty(this, "enableGrid", void 0);
|
201
|
+
|
202
|
+
_defineProperty(this, "cursorZoom", void 0);
|
203
|
+
|
204
|
+
_defineProperty(this, "minFov", void 0);
|
205
|
+
|
206
|
+
_defineProperty(this, "maxFov", void 0);
|
207
|
+
|
208
|
+
_defineProperty(this, "enabled", void 0);
|
209
|
+
|
210
|
+
_defineProperty(this, "enablePan", void 0);
|
211
|
+
|
212
|
+
_defineProperty(this, "enableRotate", void 0);
|
213
|
+
|
214
|
+
_defineProperty(this, "enableZoom", void 0);
|
215
|
+
|
216
|
+
_defineProperty(this, "minDistance", void 0);
|
217
|
+
|
218
|
+
_defineProperty(this, "maxDistance", void 0);
|
219
|
+
|
220
|
+
_defineProperty(this, "minZoom", void 0);
|
221
|
+
|
222
|
+
_defineProperty(this, "maxZoom", void 0);
|
223
|
+
|
224
|
+
_defineProperty(this, "target", void 0);
|
225
|
+
|
226
|
+
_defineProperty(this, "_currentTarget", void 0);
|
227
|
+
|
228
|
+
_defineProperty(this, "_tbRadius", void 0);
|
229
|
+
|
230
|
+
_defineProperty(this, "_state", void 0);
|
231
|
+
|
55
232
|
_defineProperty(this, "onWindowResize", () => {
|
56
233
|
const scale = (this._gizmos.scale.x + this._gizmos.scale.y + this._gizmos.scale.z) / 3;
|
57
|
-
|
58
|
-
|
234
|
+
|
235
|
+
if (this.camera) {
|
236
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
237
|
+
|
238
|
+
if (tbRadius !== undefined) {
|
239
|
+
this._tbRadius = tbRadius;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
|
243
|
+
const newRadius = this._tbRadius / scale; // @ts-expect-error
|
244
|
+
|
59
245
|
const curve = new EllipseCurve(0, 0, newRadius, newRadius);
|
60
246
|
const points = curve.getPoints(this._curvePts);
|
61
247
|
const curveGeometry = new BufferGeometry().setFromPoints(points);
|
62
248
|
|
63
249
|
for (const gizmo in this._gizmos.children) {
|
64
|
-
this._gizmos.children[gizmo]
|
250
|
+
const child = this._gizmos.children[gizmo];
|
251
|
+
child.geometry = curveGeometry;
|
65
252
|
}
|
66
253
|
|
67
254
|
this.dispatchEvent(_changeEvent);
|
@@ -94,8 +281,6 @@ class ArcballControls extends EventDispatcher {
|
|
94
281
|
this._downValid = true;
|
95
282
|
|
96
283
|
this._downEvents.push(event);
|
97
|
-
|
98
|
-
this._downStart = performance.now();
|
99
284
|
} else {
|
100
285
|
this._downValid = false;
|
101
286
|
}
|
@@ -126,7 +311,7 @@ class ArcballControls extends EventDispatcher {
|
|
126
311
|
case INPUT.TWO_FINGER:
|
127
312
|
//multipleStart
|
128
313
|
this._input = INPUT.MULT_FINGER;
|
129
|
-
this.onTriplePanStart(
|
314
|
+
this.onTriplePanStart();
|
130
315
|
break;
|
131
316
|
}
|
132
317
|
} else if (event.pointerType != 'touch' && this._input == INPUT.NONE) {
|
@@ -140,7 +325,7 @@ class ArcballControls extends EventDispatcher {
|
|
140
325
|
|
141
326
|
this._mouseOp = this.getOpFromAction(event.button, modifier);
|
142
327
|
|
143
|
-
if (this._mouseOp
|
328
|
+
if (this._mouseOp) {
|
144
329
|
window.addEventListener('pointermove', this.onPointerMove);
|
145
330
|
window.addEventListener('pointerup', this.onPointerUp); //singleStart
|
146
331
|
|
@@ -184,7 +369,7 @@ class ArcballControls extends EventDispatcher {
|
|
184
369
|
case INPUT.MULT_FINGER:
|
185
370
|
//multMove
|
186
371
|
this.updateTouchEvent(event);
|
187
|
-
this.onTriplePanMove(
|
372
|
+
this.onTriplePanMove();
|
188
373
|
break;
|
189
374
|
}
|
190
375
|
} else if (event.pointerType != 'touch' && this._input == INPUT.CURSOR) {
|
@@ -198,7 +383,7 @@ class ArcballControls extends EventDispatcher {
|
|
198
383
|
|
199
384
|
const mouseOpState = this.getOpStateFromAction(this._button, modifier);
|
200
385
|
|
201
|
-
if (mouseOpState
|
386
|
+
if (mouseOpState) {
|
202
387
|
this.onSinglePanMove(event, mouseOpState);
|
203
388
|
}
|
204
389
|
} //checkDistance
|
@@ -239,9 +424,9 @@ class ArcballControls extends EventDispatcher {
|
|
239
424
|
|
240
425
|
case INPUT.TWO_FINGER:
|
241
426
|
//doubleEnd
|
242
|
-
this.onDoublePanEnd(
|
243
|
-
this.onPinchEnd(
|
244
|
-
this.onRotateEnd(
|
427
|
+
this.onDoublePanEnd();
|
428
|
+
this.onPinchEnd();
|
429
|
+
this.onRotateEnd(); //switching to singleStart
|
245
430
|
|
246
431
|
this._input = INPUT.ONE_FINGER_SWITCHED;
|
247
432
|
break;
|
@@ -311,7 +496,9 @@ class ArcballControls extends EventDispatcher {
|
|
311
496
|
});
|
312
497
|
|
313
498
|
_defineProperty(this, "onWheel", event => {
|
314
|
-
|
499
|
+
var _this$camera3;
|
500
|
+
|
501
|
+
if (this.enabled && this.enableZoom && this.domElement) {
|
315
502
|
let modifier = null;
|
316
503
|
|
317
504
|
if (event.ctrlKey || event.metaKey) {
|
@@ -322,7 +509,7 @@ class ArcballControls extends EventDispatcher {
|
|
322
509
|
|
323
510
|
const mouseOp = this.getOpFromAction('WHEEL', modifier);
|
324
511
|
|
325
|
-
if (mouseOp
|
512
|
+
if (mouseOp) {
|
326
513
|
event.preventDefault();
|
327
514
|
this.dispatchEvent(_startEvent);
|
328
515
|
const notchDeltaY = 125; //distance of one notch of mouse wheel
|
@@ -347,20 +534,28 @@ class ArcballControls extends EventDispatcher {
|
|
347
534
|
}
|
348
535
|
|
349
536
|
if (this.cursorZoom && this.enablePan) {
|
537
|
+
var _this$camera, _this$camera2;
|
538
|
+
|
350
539
|
let scalePoint;
|
351
540
|
|
352
|
-
if (this.camera.
|
353
|
-
|
354
|
-
|
355
|
-
scalePoint = this.unprojectOnTbPlane(this.camera, event.clientX, event.clientY, this.domElement).applyQuaternion(this.camera.quaternion).add(this._gizmos.position);
|
541
|
+
if (((_this$camera = this.camera) === null || _this$camera === void 0 ? void 0 : _this$camera.type) === 'OrthographicCamera') {
|
542
|
+
var _this$unprojectOnTbPl;
|
543
|
+
|
544
|
+
scalePoint = (_this$unprojectOnTbPl = this.unprojectOnTbPlane(this.camera, event.clientX, event.clientY, this.domElement)) === null || _this$unprojectOnTbPl === void 0 ? void 0 : _this$unprojectOnTbPl.applyQuaternion(this.camera.quaternion).multiplyScalar(1 / this.camera.zoom).add(this._gizmos.position);
|
545
|
+
}
|
546
|
+
|
547
|
+
if (((_this$camera2 = this.camera) === null || _this$camera2 === void 0 ? void 0 : _this$camera2.type) === 'PerspectiveCamera') {
|
548
|
+
var _this$unprojectOnTbPl2;
|
549
|
+
|
550
|
+
scalePoint = (_this$unprojectOnTbPl2 = this.unprojectOnTbPlane(this.camera, event.clientX, event.clientY, this.domElement)) === null || _this$unprojectOnTbPl2 === void 0 ? void 0 : _this$unprojectOnTbPl2.applyQuaternion(this.camera.quaternion).add(this._gizmos.position);
|
356
551
|
}
|
357
552
|
|
358
|
-
this.applyTransformMatrix(this.applyScale(size, scalePoint));
|
553
|
+
if (scalePoint !== undefined) this.applyTransformMatrix(this.applyScale(size, scalePoint));
|
359
554
|
} else {
|
360
555
|
this.applyTransformMatrix(this.applyScale(size, this._gizmos.position));
|
361
556
|
}
|
362
557
|
|
363
|
-
if (this._grid
|
558
|
+
if (this._grid) {
|
364
559
|
this.disposeGrid();
|
365
560
|
this.drawGrid();
|
366
561
|
}
|
@@ -371,7 +566,7 @@ class ArcballControls extends EventDispatcher {
|
|
371
566
|
break;
|
372
567
|
|
373
568
|
case 'FOV':
|
374
|
-
if (this.camera.
|
569
|
+
if (((_this$camera3 = this.camera) === null || _this$camera3 === void 0 ? void 0 : _this$camera3.type) === 'PerspectiveCamera') {
|
375
570
|
this.updateTbState(STATE.FOV, true); //Vertigo effect
|
376
571
|
// fov / 2
|
377
572
|
// |\
|
@@ -419,7 +614,7 @@ class ArcballControls extends EventDispatcher {
|
|
419
614
|
this.applyTransformMatrix(this.applyScale(size, this._gizmos.position, false));
|
420
615
|
}
|
421
616
|
|
422
|
-
if (this._grid
|
617
|
+
if (this._grid) {
|
423
618
|
this.disposeGrid();
|
424
619
|
this.drawGrid();
|
425
620
|
}
|
@@ -446,15 +641,15 @@ class ArcballControls extends EventDispatcher {
|
|
446
641
|
});
|
447
642
|
|
448
643
|
_defineProperty(this, "onSinglePanStart", (event, operation) => {
|
449
|
-
|
644
|
+
var _this$camera4;
|
645
|
+
|
646
|
+
if (this.enabled && this.domElement) {
|
450
647
|
this.dispatchEvent(_startEvent);
|
451
648
|
this.setCenter(event.clientX, event.clientY);
|
452
649
|
|
453
650
|
switch (operation) {
|
454
651
|
case 'PAN':
|
455
|
-
if (!this.enablePan)
|
456
|
-
return;
|
457
|
-
}
|
652
|
+
if (!this.enablePan) return;
|
458
653
|
|
459
654
|
if (this._animationId != -1) {
|
460
655
|
cancelAnimationFrame(this._animationId);
|
@@ -464,21 +659,24 @@ class ArcballControls extends EventDispatcher {
|
|
464
659
|
this.dispatchEvent(_changeEvent);
|
465
660
|
}
|
466
661
|
|
467
|
-
this.
|
662
|
+
if (this.camera) {
|
663
|
+
this.updateTbState(STATE.PAN, true);
|
664
|
+
const rayDir = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement);
|
468
665
|
|
469
|
-
|
666
|
+
if (rayDir !== undefined) {
|
667
|
+
this._startCursorPosition.copy(rayDir);
|
668
|
+
}
|
470
669
|
|
471
|
-
|
472
|
-
|
473
|
-
|
670
|
+
if (this.enableGrid) {
|
671
|
+
this.drawGrid();
|
672
|
+
this.dispatchEvent(_changeEvent);
|
673
|
+
}
|
474
674
|
}
|
475
675
|
|
476
676
|
break;
|
477
677
|
|
478
678
|
case 'ROTATE':
|
479
|
-
if (!this.enableRotate)
|
480
|
-
return;
|
481
|
-
}
|
679
|
+
if (!this.enableRotate) return;
|
482
680
|
|
483
681
|
if (this._animationId != -1) {
|
484
682
|
cancelAnimationFrame(this._animationId);
|
@@ -486,52 +684,55 @@ class ArcballControls extends EventDispatcher {
|
|
486
684
|
this._timeStart = -1;
|
487
685
|
}
|
488
686
|
|
489
|
-
this.
|
687
|
+
if (this.camera) {
|
688
|
+
this.updateTbState(STATE.ROTATE, true);
|
689
|
+
const rayDir = this.unprojectOnTbSurface(this.camera, _center.x, _center.y, this.domElement, this._tbRadius);
|
490
690
|
|
491
|
-
|
691
|
+
if (rayDir !== undefined) {
|
692
|
+
this._startCursorPosition.copy(rayDir);
|
693
|
+
}
|
492
694
|
|
493
|
-
|
695
|
+
this.activateGizmos(true);
|
494
696
|
|
495
|
-
|
496
|
-
|
497
|
-
|
697
|
+
if (this.enableAnimations) {
|
698
|
+
this._timePrev = this._timeCurrent = performance.now();
|
699
|
+
this._angleCurrent = this._anglePrev = 0;
|
498
700
|
|
499
|
-
|
701
|
+
this._cursorPosPrev.copy(this._startCursorPosition);
|
500
702
|
|
501
|
-
|
703
|
+
this._cursorPosCurr.copy(this._cursorPosPrev);
|
502
704
|
|
503
|
-
|
504
|
-
|
705
|
+
this._wCurr = 0;
|
706
|
+
this._wPrev = this._wCurr;
|
707
|
+
}
|
505
708
|
}
|
506
709
|
|
507
710
|
this.dispatchEvent(_changeEvent);
|
508
711
|
break;
|
509
712
|
|
510
713
|
case 'FOV':
|
511
|
-
if (!this.
|
512
|
-
return;
|
513
|
-
}
|
714
|
+
if (!this.enableZoom) return;
|
514
715
|
|
515
|
-
if (this.
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
716
|
+
if (((_this$camera4 = this.camera) === null || _this$camera4 === void 0 ? void 0 : _this$camera4.type) === 'PerspectiveCamera') {
|
717
|
+
if (this._animationId != -1) {
|
718
|
+
cancelAnimationFrame(this._animationId);
|
719
|
+
this._animationId = -1;
|
720
|
+
this._timeStart = -1;
|
721
|
+
this.activateGizmos(false);
|
722
|
+
this.dispatchEvent(_changeEvent);
|
723
|
+
}
|
522
724
|
|
523
|
-
|
725
|
+
this.updateTbState(STATE.FOV, true);
|
524
726
|
|
525
|
-
|
727
|
+
this._startCursorPosition.setY(this.getCursorNDC(_center.x, _center.y, this.domElement).y * 0.5);
|
526
728
|
|
527
|
-
|
729
|
+
this._currentCursorPosition.copy(this._startCursorPosition);
|
730
|
+
}
|
528
731
|
|
529
732
|
break;
|
530
733
|
|
531
734
|
case 'ZOOM':
|
532
|
-
if (!this.enableZoom)
|
533
|
-
return;
|
534
|
-
}
|
735
|
+
if (!this.enableZoom) return;
|
535
736
|
|
536
737
|
if (this._animationId != -1) {
|
537
738
|
cancelAnimationFrame(this._animationId);
|
@@ -553,20 +754,25 @@ class ArcballControls extends EventDispatcher {
|
|
553
754
|
});
|
554
755
|
|
555
756
|
_defineProperty(this, "onSinglePanMove", (event, opState) => {
|
556
|
-
|
757
|
+
var _this$camera5;
|
758
|
+
|
759
|
+
if (this.enabled && this.domElement) {
|
557
760
|
const restart = opState != this._state;
|
558
761
|
this.setCenter(event.clientX, event.clientY);
|
559
762
|
|
560
763
|
switch (opState) {
|
561
764
|
case STATE.PAN:
|
562
|
-
if (this.enablePan) {
|
765
|
+
if (this.enablePan && this.camera) {
|
563
766
|
if (restart) {
|
564
767
|
//switch to pan operation
|
565
768
|
this.dispatchEvent(_endEvent);
|
566
769
|
this.dispatchEvent(_startEvent);
|
567
770
|
this.updateTbState(opState, true);
|
771
|
+
const rayDir = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement);
|
568
772
|
|
569
|
-
|
773
|
+
if (rayDir !== undefined) {
|
774
|
+
this._startCursorPosition.copy(rayDir);
|
775
|
+
}
|
570
776
|
|
571
777
|
if (this.enableGrid) {
|
572
778
|
this.drawGrid();
|
@@ -575,7 +781,11 @@ class ArcballControls extends EventDispatcher {
|
|
575
781
|
this.activateGizmos(false);
|
576
782
|
} else {
|
577
783
|
//continue with pan operation
|
578
|
-
this.
|
784
|
+
const rayDir = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement);
|
785
|
+
|
786
|
+
if (rayDir !== undefined) {
|
787
|
+
this._currentCursorPosition.copy(rayDir);
|
788
|
+
}
|
579
789
|
|
580
790
|
this.applyTransformMatrix(this.pan(this._startCursorPosition, this._currentCursorPosition));
|
581
791
|
}
|
@@ -584,14 +794,17 @@ class ArcballControls extends EventDispatcher {
|
|
584
794
|
break;
|
585
795
|
|
586
796
|
case STATE.ROTATE:
|
587
|
-
if (this.enableRotate) {
|
797
|
+
if (this.enableRotate && this.camera) {
|
588
798
|
if (restart) {
|
589
799
|
//switch to rotate operation
|
590
800
|
this.dispatchEvent(_endEvent);
|
591
801
|
this.dispatchEvent(_startEvent);
|
592
802
|
this.updateTbState(opState, true);
|
803
|
+
const rayDir = this.unprojectOnTbSurface(this.camera, _center.x, _center.y, this.domElement, this._tbRadius);
|
593
804
|
|
594
|
-
|
805
|
+
if (rayDir !== undefined) {
|
806
|
+
this._startCursorPosition.copy(rayDir);
|
807
|
+
}
|
595
808
|
|
596
809
|
if (this.enableGrid) {
|
597
810
|
this.disposeGrid();
|
@@ -600,7 +813,11 @@ class ArcballControls extends EventDispatcher {
|
|
600
813
|
this.activateGizmos(true);
|
601
814
|
} else {
|
602
815
|
//continue with rotate operation
|
603
|
-
this.
|
816
|
+
const rayDir = this.unprojectOnTbSurface(this.camera, _center.x, _center.y, this.domElement, this._tbRadius);
|
817
|
+
|
818
|
+
if (rayDir !== undefined) {
|
819
|
+
this._currentCursorPosition.copy(rayDir);
|
820
|
+
}
|
604
821
|
|
605
822
|
const distance = this._startCursorPosition.distanceTo(this._currentCursorPosition);
|
606
823
|
|
@@ -667,7 +884,7 @@ class ArcballControls extends EventDispatcher {
|
|
667
884
|
break;
|
668
885
|
|
669
886
|
case STATE.FOV:
|
670
|
-
if (this.enableZoom && this.camera.
|
887
|
+
if (this.enableZoom && ((_this$camera5 = this.camera) === null || _this$camera5 === void 0 ? void 0 : _this$camera5.type) === 'PerspectiveCamera') {
|
671
888
|
if (restart) {
|
672
889
|
//switch to fov operation
|
673
890
|
this.dispatchEvent(_endEvent);
|
@@ -776,12 +993,12 @@ class ArcballControls extends EventDispatcher {
|
|
776
993
|
});
|
777
994
|
|
778
995
|
_defineProperty(this, "onDoubleTap", event => {
|
779
|
-
if (this.enabled && this.enablePan && this.scene
|
996
|
+
if (this.enabled && this.enablePan && this.scene && this.camera && this.domElement) {
|
780
997
|
this.dispatchEvent(_startEvent);
|
781
998
|
this.setCenter(event.clientX, event.clientY);
|
782
999
|
const hitP = this.unprojectOnObj(this.getCursorNDC(_center.x, _center.y, this.domElement), this.camera);
|
783
1000
|
|
784
|
-
if (hitP
|
1001
|
+
if (hitP && this.enableAnimations) {
|
785
1002
|
const self = this;
|
786
1003
|
|
787
1004
|
if (this._animationId != -1) {
|
@@ -793,7 +1010,7 @@ class ArcballControls extends EventDispatcher {
|
|
793
1010
|
self.updateTbState(STATE.ANIMATION_FOCUS, true);
|
794
1011
|
self.onFocusAnim(t, hitP, self._cameraMatrixState, self._gizmoMatrixState);
|
795
1012
|
});
|
796
|
-
} else if (hitP
|
1013
|
+
} else if (hitP && !this.enableAnimations) {
|
797
1014
|
this.updateTbState(STATE.FOCUS, true);
|
798
1015
|
this.focus(hitP, this.scaleFactor);
|
799
1016
|
this.updateTbState(STATE.IDLE, false);
|
@@ -805,12 +1022,15 @@ class ArcballControls extends EventDispatcher {
|
|
805
1022
|
});
|
806
1023
|
|
807
1024
|
_defineProperty(this, "onDoublePanStart", () => {
|
808
|
-
if (this.enabled && this.enablePan) {
|
1025
|
+
if (this.enabled && this.enablePan && this.camera && this.domElement) {
|
809
1026
|
this.dispatchEvent(_startEvent);
|
810
1027
|
this.updateTbState(STATE.PAN, true);
|
811
1028
|
this.setCenter((this._touchCurrent[0].clientX + this._touchCurrent[1].clientX) / 2, (this._touchCurrent[0].clientY + this._touchCurrent[1].clientY) / 2);
|
1029
|
+
const rayDir = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement, true);
|
812
1030
|
|
813
|
-
|
1031
|
+
if (rayDir !== undefined) {
|
1032
|
+
this._startCursorPosition.copy(rayDir);
|
1033
|
+
}
|
814
1034
|
|
815
1035
|
this._currentCursorPosition.copy(this._startCursorPosition);
|
816
1036
|
|
@@ -819,7 +1039,7 @@ class ArcballControls extends EventDispatcher {
|
|
819
1039
|
});
|
820
1040
|
|
821
1041
|
_defineProperty(this, "onDoublePanMove", () => {
|
822
|
-
if (this.enabled && this.enablePan) {
|
1042
|
+
if (this.enabled && this.enablePan && this.camera && this.domElement) {
|
823
1043
|
this.setCenter((this._touchCurrent[0].clientX + this._touchCurrent[1].clientX) / 2, (this._touchCurrent[0].clientY + this._touchCurrent[1].clientY) / 2);
|
824
1044
|
|
825
1045
|
if (this._state != STATE.PAN) {
|
@@ -828,8 +1048,8 @@ class ArcballControls extends EventDispatcher {
|
|
828
1048
|
this._startCursorPosition.copy(this._currentCursorPosition);
|
829
1049
|
}
|
830
1050
|
|
831
|
-
this.
|
832
|
-
|
1051
|
+
const rayDir = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement, true);
|
1052
|
+
if (rayDir !== undefined) this._currentCursorPosition.copy(rayDir);
|
833
1053
|
this.applyTransformMatrix(this.pan(this._startCursorPosition, this._currentCursorPosition, true));
|
834
1054
|
this.dispatchEvent(_changeEvent);
|
835
1055
|
}
|
@@ -842,12 +1062,14 @@ class ArcballControls extends EventDispatcher {
|
|
842
1062
|
|
843
1063
|
_defineProperty(this, "onRotateStart", () => {
|
844
1064
|
if (this.enabled && this.enableRotate) {
|
1065
|
+
var _this$camera6;
|
1066
|
+
|
845
1067
|
this.dispatchEvent(_startEvent);
|
846
1068
|
this.updateTbState(STATE.ZROTATE, true); //this._startFingerRotation = event.rotation;
|
847
1069
|
|
848
1070
|
this._startFingerRotation = this.getAngle(this._touchCurrent[1], this._touchCurrent[0]) + this.getAngle(this._touchStart[1], this._touchStart[0]);
|
849
1071
|
this._currentFingerRotation = this._startFingerRotation;
|
850
|
-
this.camera.getWorldDirection(this._rotationAxis); //rotation axis
|
1072
|
+
(_this$camera6 = this.camera) === null || _this$camera6 === void 0 ? void 0 : _this$camera6.getWorldDirection(this._rotationAxis); //rotation axis
|
851
1073
|
|
852
1074
|
if (!this.enablePan && !this.enableZoom) {
|
853
1075
|
this.activateGizmos(true);
|
@@ -856,7 +1078,7 @@ class ArcballControls extends EventDispatcher {
|
|
856
1078
|
});
|
857
1079
|
|
858
1080
|
_defineProperty(this, "onRotateMove", () => {
|
859
|
-
if (this.enabled && this.enableRotate) {
|
1081
|
+
if (this.enabled && this.enableRotate && this.camera && this.domElement) {
|
860
1082
|
this.setCenter((this._touchCurrent[0].clientX + this._touchCurrent[1].clientX) / 2, (this._touchCurrent[0].clientY + this._touchCurrent[1].clientY) / 2);
|
861
1083
|
let rotationPoint;
|
862
1084
|
|
@@ -870,14 +1092,20 @@ class ArcballControls extends EventDispatcher {
|
|
870
1092
|
|
871
1093
|
if (!this.enablePan) {
|
872
1094
|
rotationPoint = new Vector3().setFromMatrixPosition(this._gizmoMatrixState);
|
873
|
-
} else {
|
1095
|
+
} else if (this.camera) {
|
1096
|
+
var _this$unprojectOnTbPl3;
|
1097
|
+
|
874
1098
|
this._v3_2.setFromMatrixPosition(this._gizmoMatrixState);
|
875
1099
|
|
876
|
-
rotationPoint = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement).applyQuaternion(this.camera.quaternion).multiplyScalar(1 / this.camera.zoom).add(this._v3_2);
|
1100
|
+
rotationPoint = (_this$unprojectOnTbPl3 = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement)) === null || _this$unprojectOnTbPl3 === void 0 ? void 0 : _this$unprojectOnTbPl3.applyQuaternion(this.camera.quaternion).multiplyScalar(1 / this.camera.zoom).add(this._v3_2);
|
877
1101
|
}
|
878
1102
|
|
879
1103
|
const amount = MathUtils.DEG2RAD * (this._startFingerRotation - this._currentFingerRotation);
|
880
|
-
|
1104
|
+
|
1105
|
+
if (rotationPoint !== undefined) {
|
1106
|
+
this.applyTransformMatrix(this.zRotate(rotationPoint, amount));
|
1107
|
+
}
|
1108
|
+
|
881
1109
|
this.dispatchEvent(_changeEvent);
|
882
1110
|
}
|
883
1111
|
});
|
@@ -899,7 +1127,7 @@ class ArcballControls extends EventDispatcher {
|
|
899
1127
|
});
|
900
1128
|
|
901
1129
|
_defineProperty(this, "onPinchMove", () => {
|
902
|
-
if (this.enabled && this.enableZoom) {
|
1130
|
+
if (this.enabled && this.enableZoom && this.domElement) {
|
903
1131
|
this.setCenter((this._touchCurrent[0].clientX + this._touchCurrent[1].clientX) / 2, (this._touchCurrent[0].clientY + this._touchCurrent[1].clientY) / 2);
|
904
1132
|
const minDistance = 12; //minimum distance between fingers (in css pixels)
|
905
1133
|
|
@@ -915,14 +1143,23 @@ class ArcballControls extends EventDispatcher {
|
|
915
1143
|
if (!this.enablePan) {
|
916
1144
|
scalePoint = this._gizmos.position;
|
917
1145
|
} else {
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
1146
|
+
var _this$camera7, _this$camera8;
|
1147
|
+
|
1148
|
+
if (((_this$camera7 = this.camera) === null || _this$camera7 === void 0 ? void 0 : _this$camera7.type) === 'OrthographicCamera') {
|
1149
|
+
var _this$unprojectOnTbPl4;
|
1150
|
+
|
1151
|
+
scalePoint = (_this$unprojectOnTbPl4 = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement)) === null || _this$unprojectOnTbPl4 === void 0 ? void 0 : _this$unprojectOnTbPl4.applyQuaternion(this.camera.quaternion).multiplyScalar(1 / this.camera.zoom).add(this._gizmos.position);
|
1152
|
+
} else if (((_this$camera8 = this.camera) === null || _this$camera8 === void 0 ? void 0 : _this$camera8.type) === 'PerspectiveCamera') {
|
1153
|
+
var _this$unprojectOnTbPl5;
|
1154
|
+
|
1155
|
+
scalePoint = (_this$unprojectOnTbPl5 = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement)) === null || _this$unprojectOnTbPl5 === void 0 ? void 0 : _this$unprojectOnTbPl5.applyQuaternion(this.camera.quaternion).add(this._gizmos.position);
|
922
1156
|
}
|
923
1157
|
}
|
924
1158
|
|
925
|
-
|
1159
|
+
if (scalePoint !== undefined) {
|
1160
|
+
this.applyTransformMatrix(this.applyScale(amount, scalePoint));
|
1161
|
+
}
|
1162
|
+
|
926
1163
|
this.dispatchEvent(_changeEvent);
|
927
1164
|
}
|
928
1165
|
});
|
@@ -933,7 +1170,7 @@ class ArcballControls extends EventDispatcher {
|
|
933
1170
|
});
|
934
1171
|
|
935
1172
|
_defineProperty(this, "onTriplePanStart", () => {
|
936
|
-
if (this.enabled && this.enableZoom) {
|
1173
|
+
if (this.enabled && this.enableZoom && this.domElement) {
|
937
1174
|
this.dispatchEvent(_startEvent);
|
938
1175
|
this.updateTbState(STATE.SCALE, true); //const center = event.center;
|
939
1176
|
|
@@ -955,7 +1192,7 @@ class ArcballControls extends EventDispatcher {
|
|
955
1192
|
});
|
956
1193
|
|
957
1194
|
_defineProperty(this, "onTriplePanMove", () => {
|
958
|
-
if (this.enabled && this.enableZoom) {
|
1195
|
+
if (this.enabled && this.enableZoom && this.camera && this.domElement) {
|
959
1196
|
// fov / 2
|
960
1197
|
// |\
|
961
1198
|
// | \
|
@@ -1038,18 +1275,6 @@ class ArcballControls extends EventDispatcher {
|
|
1038
1275
|
this.setMouseAction('FOV', 1, 'SHIFT');
|
1039
1276
|
});
|
1040
1277
|
|
1041
|
-
_defineProperty(this, "compareMouseAction", (action1, action2) => {
|
1042
|
-
if (action1.operation == action2.operation) {
|
1043
|
-
if (action1.mouse == action2.mouse && action1.key == action2.key) {
|
1044
|
-
return true;
|
1045
|
-
} else {
|
1046
|
-
return false;
|
1047
|
-
}
|
1048
|
-
} else {
|
1049
|
-
return false;
|
1050
|
-
}
|
1051
|
-
});
|
1052
|
-
|
1053
1278
|
_defineProperty(this, "setMouseAction", (operation, mouse, key = null) => {
|
1054
1279
|
const operationInput = ['PAN', 'ROTATE', 'ZOOM', 'FOV'];
|
1055
1280
|
const mouseInput = [0, 1, 2, 'WHEEL'];
|
@@ -1104,17 +1329,6 @@ class ArcballControls extends EventDispatcher {
|
|
1104
1329
|
return true;
|
1105
1330
|
});
|
1106
1331
|
|
1107
|
-
_defineProperty(this, "unsetMouseAction", (mouse, key = null) => {
|
1108
|
-
for (let i = 0; i < this.mouseActions.length; i++) {
|
1109
|
-
if (this.mouseActions[i].mouse == mouse && this.mouseActions[i].key == key) {
|
1110
|
-
this.mouseActions.splice(i, 1);
|
1111
|
-
return true;
|
1112
|
-
}
|
1113
|
-
}
|
1114
|
-
|
1115
|
-
return false;
|
1116
|
-
});
|
1117
|
-
|
1118
1332
|
_defineProperty(this, "getOpFromAction", (mouse, key) => {
|
1119
1333
|
let action;
|
1120
1334
|
|
@@ -1126,7 +1340,7 @@ class ArcballControls extends EventDispatcher {
|
|
1126
1340
|
}
|
1127
1341
|
}
|
1128
1342
|
|
1129
|
-
if (key
|
1343
|
+
if (key) {
|
1130
1344
|
for (let i = 0; i < this.mouseActions.length; i++) {
|
1131
1345
|
action = this.mouseActions[i];
|
1132
1346
|
|
@@ -1150,7 +1364,7 @@ class ArcballControls extends EventDispatcher {
|
|
1150
1364
|
}
|
1151
1365
|
}
|
1152
1366
|
|
1153
|
-
if (key
|
1367
|
+
if (key) {
|
1154
1368
|
for (let i = 0; i < this.mouseActions.length; i++) {
|
1155
1369
|
action = this.mouseActions[i];
|
1156
1370
|
|
@@ -1218,48 +1432,52 @@ class ArcballControls extends EventDispatcher {
|
|
1218
1432
|
});
|
1219
1433
|
|
1220
1434
|
_defineProperty(this, "focus", (point, size, amount = 1) => {
|
1221
|
-
|
1435
|
+
if (this.camera) {
|
1436
|
+
const focusPoint = point.clone(); //move center of camera (along with gizmos) towards point of interest
|
1222
1437
|
|
1223
|
-
|
1438
|
+
focusPoint.sub(this._gizmos.position).multiplyScalar(amount);
|
1224
1439
|
|
1225
|
-
|
1440
|
+
this._translationMatrix.makeTranslation(focusPoint.x, focusPoint.y, focusPoint.z);
|
1226
1441
|
|
1227
|
-
|
1442
|
+
const gizmoStateTemp = this._gizmoMatrixState.clone();
|
1228
1443
|
|
1229
|
-
|
1444
|
+
this._gizmoMatrixState.premultiply(this._translationMatrix);
|
1230
1445
|
|
1231
|
-
|
1446
|
+
this._gizmoMatrixState.decompose(this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale);
|
1232
1447
|
|
1233
|
-
|
1448
|
+
const cameraStateTemp = this._cameraMatrixState.clone();
|
1234
1449
|
|
1235
|
-
|
1450
|
+
this._cameraMatrixState.premultiply(this._translationMatrix);
|
1236
1451
|
|
1237
|
-
|
1452
|
+
this._cameraMatrixState.decompose(this.camera.position, this.camera.quaternion, this.camera.scale); //apply zoom
|
1238
1453
|
|
1239
1454
|
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1455
|
+
if (this.enableZoom) {
|
1456
|
+
this.applyTransformMatrix(this.applyScale(size, this._gizmos.position));
|
1457
|
+
}
|
1243
1458
|
|
1244
|
-
|
1459
|
+
this._gizmoMatrixState.copy(gizmoStateTemp);
|
1245
1460
|
|
1246
|
-
|
1461
|
+
this._cameraMatrixState.copy(cameraStateTemp);
|
1462
|
+
}
|
1247
1463
|
});
|
1248
1464
|
|
1249
1465
|
_defineProperty(this, "drawGrid", () => {
|
1250
|
-
if (this.scene
|
1466
|
+
if (this.scene) {
|
1467
|
+
var _this$camera9, _this$camera10;
|
1468
|
+
|
1251
1469
|
const color = 0x888888;
|
1252
1470
|
const multiplier = 3;
|
1253
1471
|
let size, divisions, maxLength, tick;
|
1254
1472
|
|
1255
|
-
if (this.camera.
|
1473
|
+
if (((_this$camera9 = this.camera) === null || _this$camera9 === void 0 ? void 0 : _this$camera9.type) === 'OrthographicCamera') {
|
1256
1474
|
const width = this.camera.right - this.camera.left;
|
1257
1475
|
const height = this.camera.bottom - this.camera.top;
|
1258
1476
|
maxLength = Math.max(width, height);
|
1259
1477
|
tick = maxLength / 20;
|
1260
1478
|
size = maxLength / this.camera.zoom * multiplier;
|
1261
1479
|
divisions = size / tick * this.camera.zoom;
|
1262
|
-
} else if (this.camera.
|
1480
|
+
} else if (((_this$camera10 = this.camera) === null || _this$camera10 === void 0 ? void 0 : _this$camera10.type) === 'PerspectiveCamera') {
|
1263
1481
|
const distance = this.camera.position.distanceTo(this._gizmos.position);
|
1264
1482
|
const halfFovV = MathUtils.DEG2RAD * this.camera.fov * 0.5;
|
1265
1483
|
const halfFovH = Math.atan(this.camera.aspect * Math.tan(halfFovV));
|
@@ -1269,7 +1487,7 @@ class ArcballControls extends EventDispatcher {
|
|
1269
1487
|
divisions = size / tick;
|
1270
1488
|
}
|
1271
1489
|
|
1272
|
-
if (this._grid == null) {
|
1490
|
+
if (this._grid == null && this.camera) {
|
1273
1491
|
this._grid = new GridHelper(size, divisions, color, color);
|
1274
1492
|
|
1275
1493
|
this._grid.position.copy(this._gizmos.position);
|
@@ -1286,35 +1504,43 @@ class ArcballControls extends EventDispatcher {
|
|
1286
1504
|
});
|
1287
1505
|
|
1288
1506
|
_defineProperty(this, "connect", domElement => {
|
1289
|
-
|
1507
|
+
// https://github.com/mrdoob/three.js/issues/20575
|
1508
|
+
if (domElement === document) {
|
1509
|
+
console.error('THREE.ArcballControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.');
|
1510
|
+
}
|
1511
|
+
|
1512
|
+
this.domElement = domElement; // disables touch scroll
|
1513
|
+
// touch-action needs to be defined for pointer events to work on mobile
|
1514
|
+
// https://stackoverflow.com/a/48254578
|
1515
|
+
|
1290
1516
|
this.domElement.style.touchAction = 'none';
|
1291
1517
|
this.domElement.addEventListener('contextmenu', this.onContextMenu);
|
1292
|
-
this.domElement.addEventListener('wheel', this.onWheel);
|
1293
1518
|
this.domElement.addEventListener('pointerdown', this.onPointerDown);
|
1294
1519
|
this.domElement.addEventListener('pointercancel', this.onPointerCancel);
|
1295
|
-
|
1296
|
-
window.addEventListener('resize', this.onWindowResize);
|
1520
|
+
this.domElement.addEventListener('wheel', this.onWheel);
|
1297
1521
|
});
|
1298
1522
|
|
1299
1523
|
_defineProperty(this, "dispose", () => {
|
1524
|
+
var _this$domElement, _this$domElement2, _this$domElement3, _this$domElement4, _this$scene;
|
1525
|
+
|
1300
1526
|
if (this._animationId != -1) {
|
1301
1527
|
window.cancelAnimationFrame(this._animationId);
|
1302
1528
|
}
|
1303
1529
|
|
1304
|
-
this.domElement.removeEventListener('pointerdown', this.onPointerDown);
|
1305
|
-
this.domElement.removeEventListener('pointercancel', this.onPointerCancel);
|
1306
|
-
this.domElement.removeEventListener('wheel', this.onWheel);
|
1307
|
-
this.domElement.removeEventListener('contextmenu', this.onContextMenu);
|
1530
|
+
(_this$domElement = this.domElement) === null || _this$domElement === void 0 ? void 0 : _this$domElement.removeEventListener('pointerdown', this.onPointerDown);
|
1531
|
+
(_this$domElement2 = this.domElement) === null || _this$domElement2 === void 0 ? void 0 : _this$domElement2.removeEventListener('pointercancel', this.onPointerCancel);
|
1532
|
+
(_this$domElement3 = this.domElement) === null || _this$domElement3 === void 0 ? void 0 : _this$domElement3.removeEventListener('wheel', this.onWheel);
|
1533
|
+
(_this$domElement4 = this.domElement) === null || _this$domElement4 === void 0 ? void 0 : _this$domElement4.removeEventListener('contextmenu', this.onContextMenu);
|
1308
1534
|
window.removeEventListener('pointermove', this.onPointerMove);
|
1309
1535
|
window.removeEventListener('pointerup', this.onPointerUp);
|
1310
1536
|
window.removeEventListener('resize', this.onWindowResize);
|
1311
|
-
window.
|
1312
|
-
|
1537
|
+
window.addEventListener('keydown', this.onKeyDown);
|
1538
|
+
(_this$scene = this.scene) === null || _this$scene === void 0 ? void 0 : _this$scene.remove(this._gizmos);
|
1313
1539
|
this.disposeGrid();
|
1314
1540
|
});
|
1315
1541
|
|
1316
1542
|
_defineProperty(this, "disposeGrid", () => {
|
1317
|
-
if (this._grid
|
1543
|
+
if (this._grid && this.scene) {
|
1318
1544
|
this.scene.remove(this._grid);
|
1319
1545
|
this._grid = null;
|
1320
1546
|
}
|
@@ -1325,29 +1551,9 @@ class ArcballControls extends EventDispatcher {
|
|
1325
1551
|
});
|
1326
1552
|
|
1327
1553
|
_defineProperty(this, "activateGizmos", isActive => {
|
1328
|
-
const
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
if (isActive) {
|
1333
|
-
gizmoX.material.setValues({
|
1334
|
-
opacity: 1
|
1335
|
-
});
|
1336
|
-
gizmoY.material.setValues({
|
1337
|
-
opacity: 1
|
1338
|
-
});
|
1339
|
-
gizmoZ.material.setValues({
|
1340
|
-
opacity: 1
|
1341
|
-
});
|
1342
|
-
} else {
|
1343
|
-
gizmoX.material.setValues({
|
1344
|
-
opacity: 0.6
|
1345
|
-
});
|
1346
|
-
gizmoY.material.setValues({
|
1347
|
-
opacity: 0.6
|
1348
|
-
});
|
1349
|
-
gizmoZ.material.setValues({
|
1350
|
-
opacity: 0.6
|
1554
|
+
for (const gizmo of this._gizmos.children) {
|
1555
|
+
gizmo.material.setValues({
|
1556
|
+
opacity: isActive ? 1 : 0.6
|
1351
1557
|
});
|
1352
1558
|
}
|
1353
1559
|
});
|
@@ -1363,49 +1569,62 @@ class ArcballControls extends EventDispatcher {
|
|
1363
1569
|
});
|
1364
1570
|
|
1365
1571
|
_defineProperty(this, "getCursorPosition", (cursorX, cursorY, canvas) => {
|
1572
|
+
var _this$camera11;
|
1573
|
+
|
1366
1574
|
this._v2_1.copy(this.getCursorNDC(cursorX, cursorY, canvas));
|
1367
1575
|
|
1368
|
-
|
1369
|
-
|
1576
|
+
if (((_this$camera11 = this.camera) === null || _this$camera11 === void 0 ? void 0 : _this$camera11.type) === 'OrthographicCamera') {
|
1577
|
+
this._v2_1.x *= (this.camera.right - this.camera.left) * 0.5;
|
1578
|
+
this._v2_1.y *= (this.camera.top - this.camera.bottom) * 0.5;
|
1579
|
+
}
|
1580
|
+
|
1370
1581
|
return this._v2_1.clone();
|
1371
1582
|
});
|
1372
1583
|
|
1373
1584
|
_defineProperty(this, "setCamera", camera => {
|
1374
|
-
camera
|
1375
|
-
|
1585
|
+
if (camera) {
|
1586
|
+
camera.lookAt(this.target);
|
1587
|
+
camera.updateMatrix(); //setting state
|
1376
1588
|
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1589
|
+
if ((camera === null || camera === void 0 ? void 0 : camera.type) == 'PerspectiveCamera') {
|
1590
|
+
this._fov0 = camera.fov;
|
1591
|
+
this._fovState = camera.fov;
|
1592
|
+
}
|
1593
|
+
|
1594
|
+
this._cameraMatrixState0.copy(camera.matrix);
|
1381
1595
|
|
1382
|
-
|
1596
|
+
this._cameraMatrixState.copy(this._cameraMatrixState0);
|
1383
1597
|
|
1384
|
-
|
1598
|
+
this._cameraProjectionState.copy(camera.projectionMatrix);
|
1385
1599
|
|
1386
|
-
|
1600
|
+
this._zoom0 = camera.zoom;
|
1601
|
+
this._zoomState = this._zoom0;
|
1602
|
+
this._initialNear = camera.near;
|
1603
|
+
this._nearPos0 = camera.position.distanceTo(this.target) - camera.near;
|
1604
|
+
this._nearPos = this._initialNear;
|
1605
|
+
this._initialFar = camera.far;
|
1606
|
+
this._farPos0 = camera.position.distanceTo(this.target) - camera.far;
|
1607
|
+
this._farPos = this._initialFar;
|
1387
1608
|
|
1388
|
-
|
1389
|
-
this._zoomState = this._zoom0;
|
1390
|
-
this._initialNear = camera.near;
|
1391
|
-
this._nearPos0 = camera.position.distanceTo(this.target) - camera.near;
|
1392
|
-
this._nearPos = this._initialNear;
|
1393
|
-
this._initialFar = camera.far;
|
1394
|
-
this._farPos0 = camera.position.distanceTo(this.target) - camera.far;
|
1395
|
-
this._farPos = this._initialFar;
|
1609
|
+
this._up0.copy(camera.up);
|
1396
1610
|
|
1397
|
-
|
1611
|
+
this._upState.copy(camera.up);
|
1398
1612
|
|
1399
|
-
|
1613
|
+
this.camera = camera;
|
1614
|
+
this.camera.updateProjectionMatrix(); //making gizmos
|
1400
1615
|
|
1401
|
-
|
1402
|
-
|
1616
|
+
const tbRadius = this.calculateTbRadius(camera);
|
1617
|
+
|
1618
|
+
if (tbRadius !== undefined) {
|
1619
|
+
this._tbRadius = tbRadius;
|
1620
|
+
}
|
1403
1621
|
|
1404
|
-
|
1405
|
-
|
1622
|
+
this.makeGizmos(this.target, this._tbRadius);
|
1623
|
+
}
|
1406
1624
|
});
|
1407
1625
|
|
1408
1626
|
_defineProperty(this, "makeGizmos", (tbCenter, tbRadius) => {
|
1627
|
+
// @ts-expect-error
|
1409
1628
|
const curve = new EllipseCurve(0, 0, tbRadius, tbRadius);
|
1410
1629
|
const points = curve.getPoints(this._curvePts); //geometry
|
1411
1630
|
|
@@ -1441,7 +1660,7 @@ class ArcballControls extends EventDispatcher {
|
|
1441
1660
|
|
1442
1661
|
this._gizmoMatrixState.copy(this._gizmoMatrixState0);
|
1443
1662
|
|
1444
|
-
if (this.camera.zoom != 1) {
|
1663
|
+
if (this.camera && this.camera.zoom != 1) {
|
1445
1664
|
//adapt gizmos size to camera zoom
|
1446
1665
|
const size = 1 / this.camera.zoom;
|
1447
1666
|
|
@@ -1550,60 +1769,72 @@ class ArcballControls extends EventDispatcher {
|
|
1550
1769
|
});
|
1551
1770
|
|
1552
1771
|
_defineProperty(this, "pan", (p0, p1, adjust = false) => {
|
1553
|
-
|
1772
|
+
if (this.camera) {
|
1773
|
+
const movement = p0.clone().sub(p1);
|
1554
1774
|
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
|
1559
|
-
//adjust movement amount
|
1560
|
-
this._v3_1.setFromMatrixPosition(this._cameraMatrixState0); //camera's initial position
|
1775
|
+
if (this.camera.type === 'OrthographicCamera') {
|
1776
|
+
//adjust movement amount
|
1777
|
+
movement.multiplyScalar(1 / this.camera.zoom);
|
1778
|
+
}
|
1561
1779
|
|
1780
|
+
if (this.camera.type === 'PerspectiveCamera' && adjust) {
|
1781
|
+
//adjust movement amount
|
1782
|
+
this._v3_1.setFromMatrixPosition(this._cameraMatrixState0); //camera's initial position
|
1562
1783
|
|
1563
|
-
this._v3_2.setFromMatrixPosition(this._gizmoMatrixState0); //gizmo's initial position
|
1564
1784
|
|
1785
|
+
this._v3_2.setFromMatrixPosition(this._gizmoMatrixState0); //gizmo's initial position
|
1565
1786
|
|
1566
|
-
const distanceFactor = this._v3_1.distanceTo(this._v3_2) / this.camera.position.distanceTo(this._gizmos.position);
|
1567
|
-
movement.multiplyScalar(1 / distanceFactor);
|
1568
|
-
}
|
1569
1787
|
|
1570
|
-
|
1788
|
+
const distanceFactor = this._v3_1.distanceTo(this._v3_2) / this.camera.position.distanceTo(this._gizmos.position);
|
1789
|
+
movement.multiplyScalar(1 / distanceFactor);
|
1790
|
+
}
|
1791
|
+
|
1792
|
+
this._v3_1.set(movement.x, movement.y, 0).applyQuaternion(this.camera.quaternion);
|
1571
1793
|
|
1572
|
-
|
1794
|
+
this._m4_1.makeTranslation(this._v3_1.x, this._v3_1.y, this._v3_1.z);
|
1795
|
+
|
1796
|
+
this.setTransformationMatrices(this._m4_1, this._m4_1);
|
1797
|
+
}
|
1573
1798
|
|
1574
|
-
this.setTransformationMatrices(this._m4_1, this._m4_1);
|
1575
1799
|
return _transformation;
|
1576
1800
|
});
|
1577
1801
|
|
1578
1802
|
_defineProperty(this, "reset", () => {
|
1579
|
-
this.camera
|
1803
|
+
if (this.camera) {
|
1804
|
+
this.camera.zoom = this._zoom0;
|
1580
1805
|
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1806
|
+
if (this.camera.type === 'PerspectiveCamera') {
|
1807
|
+
this.camera.fov = this._fov0;
|
1808
|
+
}
|
1584
1809
|
|
1585
|
-
|
1586
|
-
|
1810
|
+
this.camera.near = this._nearPos;
|
1811
|
+
this.camera.far = this._farPos;
|
1587
1812
|
|
1588
|
-
|
1813
|
+
this._cameraMatrixState.copy(this._cameraMatrixState0);
|
1589
1814
|
|
1590
|
-
|
1815
|
+
this._cameraMatrixState.decompose(this.camera.position, this.camera.quaternion, this.camera.scale);
|
1591
1816
|
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1817
|
+
this.camera.up.copy(this._up0);
|
1818
|
+
this.camera.updateMatrix();
|
1819
|
+
this.camera.updateProjectionMatrix();
|
1595
1820
|
|
1596
|
-
|
1821
|
+
this._gizmoMatrixState.copy(this._gizmoMatrixState0);
|
1597
1822
|
|
1598
|
-
|
1823
|
+
this._gizmoMatrixState0.decompose(this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale);
|
1599
1824
|
|
1600
|
-
|
1825
|
+
this._gizmos.updateMatrix();
|
1601
1826
|
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1827
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
1828
|
+
|
1829
|
+
if (tbRadius !== undefined) {
|
1830
|
+
this._tbRadius = tbRadius;
|
1831
|
+
}
|
1832
|
+
|
1833
|
+
this.makeGizmos(this._gizmos.position, this._tbRadius);
|
1834
|
+
this.camera.lookAt(this._gizmos.position);
|
1835
|
+
this.updateTbState(STATE.IDLE, false);
|
1836
|
+
this.dispatchEvent(_changeEvent);
|
1837
|
+
}
|
1607
1838
|
});
|
1608
1839
|
|
1609
1840
|
_defineProperty(this, "rotate", (axis, angle) => {
|
@@ -1625,10 +1856,10 @@ class ArcballControls extends EventDispatcher {
|
|
1625
1856
|
});
|
1626
1857
|
|
1627
1858
|
_defineProperty(this, "copyState", () => {
|
1628
|
-
|
1859
|
+
if (this.camera) {
|
1860
|
+
var _this$camera12;
|
1629
1861
|
|
1630
|
-
|
1631
|
-
state = JSON.stringify({
|
1862
|
+
const state = JSON.stringify(((_this$camera12 = this.camera) === null || _this$camera12 === void 0 ? void 0 : _this$camera12.type) === 'OrthographicCamera' ? {
|
1632
1863
|
arcballState: {
|
1633
1864
|
cameraFar: this.camera.far,
|
1634
1865
|
cameraMatrix: this.camera.matrix,
|
@@ -1637,9 +1868,7 @@ class ArcballControls extends EventDispatcher {
|
|
1637
1868
|
cameraZoom: this.camera.zoom,
|
1638
1869
|
gizmoMatrix: this._gizmos.matrix
|
1639
1870
|
}
|
1640
|
-
}
|
1641
|
-
} else if (this.camera.isPerspectiveCamera) {
|
1642
|
-
state = JSON.stringify({
|
1871
|
+
} : {
|
1643
1872
|
arcballState: {
|
1644
1873
|
cameraFar: this.camera.far,
|
1645
1874
|
cameraFov: this.camera.fov,
|
@@ -1650,9 +1879,8 @@ class ArcballControls extends EventDispatcher {
|
|
1650
1879
|
gizmoMatrix: this._gizmos.matrix
|
1651
1880
|
}
|
1652
1881
|
});
|
1882
|
+
navigator.clipboard.writeText(state);
|
1653
1883
|
}
|
1654
|
-
|
1655
|
-
navigator.clipboard.writeText(state);
|
1656
1884
|
});
|
1657
1885
|
|
1658
1886
|
_defineProperty(this, "pasteState", () => {
|
@@ -1663,6 +1891,8 @@ class ArcballControls extends EventDispatcher {
|
|
1663
1891
|
});
|
1664
1892
|
|
1665
1893
|
_defineProperty(this, "saveState", () => {
|
1894
|
+
if (!this.camera) return;
|
1895
|
+
|
1666
1896
|
this._cameraMatrixState0.copy(this.camera.matrix);
|
1667
1897
|
|
1668
1898
|
this._gizmoMatrixState0.copy(this._gizmos.matrix);
|
@@ -1673,16 +1903,17 @@ class ArcballControls extends EventDispatcher {
|
|
1673
1903
|
|
1674
1904
|
this._up0.copy(this.camera.up);
|
1675
1905
|
|
1676
|
-
if (this.camera.
|
1906
|
+
if (this.camera.type === 'PerspectiveCamera') {
|
1677
1907
|
this._fov0 = this.camera.fov;
|
1678
1908
|
}
|
1679
1909
|
});
|
1680
1910
|
|
1681
1911
|
_defineProperty(this, "applyScale", (size, point, scaleGizmos = true) => {
|
1912
|
+
if (!this.camera) return;
|
1682
1913
|
const scalePoint = point.clone();
|
1683
1914
|
let sizeInverse = 1 / size;
|
1684
1915
|
|
1685
|
-
if (this.camera.
|
1916
|
+
if (this.camera.type === 'OrthographicCamera') {
|
1686
1917
|
//camera zoom
|
1687
1918
|
this.camera.zoom = this._zoomState;
|
1688
1919
|
this.camera.zoom *= size; //check min and max zoom
|
@@ -1720,7 +1951,9 @@ class ArcballControls extends EventDispatcher {
|
|
1720
1951
|
|
1721
1952
|
this.setTransformationMatrices(this._m4_1, this._m4_2);
|
1722
1953
|
return _transformation;
|
1723
|
-
}
|
1954
|
+
}
|
1955
|
+
|
1956
|
+
if (this.camera.type === 'PerspectiveCamera') {
|
1724
1957
|
this._v3_1.setFromMatrixPosition(this._cameraMatrixState);
|
1725
1958
|
|
1726
1959
|
this._v3_2.setFromMatrixPosition(this._gizmoMatrixState); //move camera
|
@@ -1773,12 +2006,32 @@ class ArcballControls extends EventDispatcher {
|
|
1773
2006
|
});
|
1774
2007
|
|
1775
2008
|
_defineProperty(this, "setFov", value => {
|
1776
|
-
|
2009
|
+
var _this$camera13;
|
2010
|
+
|
2011
|
+
if (((_this$camera13 = this.camera) === null || _this$camera13 === void 0 ? void 0 : _this$camera13.type) === 'PerspectiveCamera') {
|
1777
2012
|
this.camera.fov = MathUtils.clamp(value, this.minFov, this.maxFov);
|
1778
2013
|
this.camera.updateProjectionMatrix();
|
1779
2014
|
}
|
1780
2015
|
});
|
1781
2016
|
|
2017
|
+
_defineProperty(this, "setTarget", (x, y, z) => {
|
2018
|
+
if (this.camera) {
|
2019
|
+
this.target.set(x, y, z);
|
2020
|
+
|
2021
|
+
this._gizmos.position.set(x, y, z); //for correct radius calculation
|
2022
|
+
|
2023
|
+
|
2024
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
2025
|
+
|
2026
|
+
if (tbRadius !== undefined) {
|
2027
|
+
this._tbRadius = tbRadius;
|
2028
|
+
}
|
2029
|
+
|
2030
|
+
this.makeGizmos(this.target, this._tbRadius);
|
2031
|
+
this.camera.lookAt(this.target);
|
2032
|
+
}
|
2033
|
+
});
|
2034
|
+
|
1782
2035
|
_defineProperty(this, "zRotate", (point, angle) => {
|
1783
2036
|
this._rotationMatrix.makeRotationAxis(this._rotationAxis, angle);
|
1784
2037
|
|
@@ -1805,6 +2058,7 @@ class ArcballControls extends EventDispatcher {
|
|
1805
2058
|
});
|
1806
2059
|
|
1807
2060
|
_defineProperty(this, "unprojectOnObj", (cursor, camera) => {
|
2061
|
+
if (!this.scene) return null;
|
1808
2062
|
const raycaster = new Raycaster();
|
1809
2063
|
raycaster.near = camera.near;
|
1810
2064
|
raycaster.far = camera.far;
|
@@ -1812,7 +2066,7 @@ class ArcballControls extends EventDispatcher {
|
|
1812
2066
|
const intersect = raycaster.intersectObjects(this.scene.children, true);
|
1813
2067
|
|
1814
2068
|
for (let i = 0; i < intersect.length; i++) {
|
1815
|
-
if (intersect[i].object.uuid != this._gizmos.uuid && intersect[i].face
|
2069
|
+
if (intersect[i].object.uuid != this._gizmos.uuid && intersect[i].face) {
|
1816
2070
|
return intersect[i].point.clone();
|
1817
2071
|
}
|
1818
2072
|
}
|
@@ -1839,7 +2093,9 @@ class ArcballControls extends EventDispatcher {
|
|
1839
2093
|
}
|
1840
2094
|
|
1841
2095
|
return this._v3_1;
|
1842
|
-
}
|
2096
|
+
}
|
2097
|
+
|
2098
|
+
if (camera.type == 'PerspectiveCamera') {
|
1843
2099
|
//unproject cursor on the near plane
|
1844
2100
|
this._v2_1.copy(this.getCursorNDC(cursorX, cursorY, canvas));
|
1845
2101
|
|
@@ -1934,7 +2190,9 @@ class ArcballControls extends EventDispatcher {
|
|
1934
2190
|
this._v3_1.set(this._v2_1.x, this._v2_1.y, 0);
|
1935
2191
|
|
1936
2192
|
return this._v3_1.clone();
|
1937
|
-
}
|
2193
|
+
}
|
2194
|
+
|
2195
|
+
if (camera.type == 'PerspectiveCamera') {
|
1938
2196
|
this._v2_1.copy(this.getCursorNDC(cursorX, cursorY, canvas)); //unproject cursor on the near plane
|
1939
2197
|
|
1940
2198
|
|
@@ -1989,17 +2247,20 @@ class ArcballControls extends EventDispatcher {
|
|
1989
2247
|
});
|
1990
2248
|
|
1991
2249
|
_defineProperty(this, "updateMatrixState", () => {
|
1992
|
-
//update camera and gizmos state
|
2250
|
+
if (!this.camera) return; //update camera and gizmos state
|
2251
|
+
|
1993
2252
|
this._cameraMatrixState.copy(this.camera.matrix);
|
1994
2253
|
|
1995
2254
|
this._gizmoMatrixState.copy(this._gizmos.matrix);
|
1996
2255
|
|
1997
|
-
if (this.camera.
|
2256
|
+
if (this.camera.type === 'OrthographicCamera') {
|
1998
2257
|
this._cameraProjectionState.copy(this.camera.projectionMatrix);
|
1999
2258
|
|
2000
2259
|
this.camera.updateProjectionMatrix();
|
2001
2260
|
this._zoomState = this.camera.zoom;
|
2002
|
-
}
|
2261
|
+
}
|
2262
|
+
|
2263
|
+
if (this.camera.type === 'PerspectiveCamera') {
|
2003
2264
|
this._fovState = this.camera.fov;
|
2004
2265
|
}
|
2005
2266
|
});
|
@@ -2015,24 +2276,32 @@ class ArcballControls extends EventDispatcher {
|
|
2015
2276
|
_defineProperty(this, "update", () => {
|
2016
2277
|
const EPS = 0.000001; // Update target and gizmos state
|
2017
2278
|
|
2018
|
-
if (!this.target.equals(this._currentTarget)) {
|
2279
|
+
if (!this.target.equals(this._currentTarget) && this.camera) {
|
2019
2280
|
this._gizmos.position.set(this.target.x, this.target.y, this.target.z); //for correct radius calculation
|
2020
2281
|
|
2021
2282
|
|
2022
|
-
|
2283
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
2284
|
+
|
2285
|
+
if (tbRadius !== undefined) {
|
2286
|
+
this._tbRadius = tbRadius;
|
2287
|
+
}
|
2288
|
+
|
2023
2289
|
this.makeGizmos(this.target, this._tbRadius);
|
2024
2290
|
|
2025
2291
|
this._currentTarget.copy(this.target);
|
2026
|
-
}
|
2292
|
+
}
|
2027
2293
|
|
2294
|
+
if (!this.camera) return; //check min/max parameters
|
2028
2295
|
|
2029
|
-
if (this.camera.
|
2296
|
+
if (this.camera.type === 'OrthographicCamera') {
|
2030
2297
|
//check zoom
|
2031
2298
|
if (this.camera.zoom > this.maxZoom || this.camera.zoom < this.minZoom) {
|
2032
2299
|
const newZoom = MathUtils.clamp(this.camera.zoom, this.minZoom, this.maxZoom);
|
2033
2300
|
this.applyTransformMatrix(this.applyScale(newZoom / this.camera.zoom, this._gizmos.position, true));
|
2034
2301
|
}
|
2035
|
-
}
|
2302
|
+
}
|
2303
|
+
|
2304
|
+
if (this.camera.type === 'PerspectiveCamera') {
|
2036
2305
|
//check distance
|
2037
2306
|
const distance = this.camera.position.distanceTo(this._gizmos.position);
|
2038
2307
|
|
@@ -2049,17 +2318,23 @@ class ArcballControls extends EventDispatcher {
|
|
2049
2318
|
}
|
2050
2319
|
|
2051
2320
|
const oldRadius = this._tbRadius;
|
2052
|
-
|
2321
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
2322
|
+
|
2323
|
+
if (tbRadius !== undefined) {
|
2324
|
+
this._tbRadius = tbRadius;
|
2325
|
+
}
|
2053
2326
|
|
2054
2327
|
if (oldRadius < this._tbRadius - EPS || oldRadius > this._tbRadius + EPS) {
|
2055
2328
|
const scale = (this._gizmos.scale.x + this._gizmos.scale.y + this._gizmos.scale.z) / 3;
|
2056
|
-
const newRadius = this._tbRadius / scale;
|
2329
|
+
const newRadius = this._tbRadius / scale; // @ts-expect-error
|
2330
|
+
|
2057
2331
|
const curve = new EllipseCurve(0, 0, newRadius, newRadius);
|
2058
2332
|
const points = curve.getPoints(this._curvePts);
|
2059
2333
|
const curveGeometry = new BufferGeometry().setFromPoints(points);
|
2060
2334
|
|
2061
2335
|
for (const gizmo in this._gizmos.children) {
|
2062
|
-
this._gizmos.children[gizmo]
|
2336
|
+
const child = this._gizmos.children[gizmo];
|
2337
|
+
child.geometry = curveGeometry;
|
2063
2338
|
}
|
2064
2339
|
}
|
2065
2340
|
}
|
@@ -2070,7 +2345,7 @@ class ArcballControls extends EventDispatcher {
|
|
2070
2345
|
_defineProperty(this, "setStateFromJSON", json => {
|
2071
2346
|
const state = JSON.parse(json);
|
2072
2347
|
|
2073
|
-
if (state.arcballState
|
2348
|
+
if (state.arcballState && this.camera) {
|
2074
2349
|
this._cameraMatrixState.fromArray(state.arcballState.cameraMatrix.elements);
|
2075
2350
|
|
2076
2351
|
this._cameraMatrixState.decompose(this.camera.position, this.camera.quaternion, this.camera.scale);
|
@@ -2080,7 +2355,7 @@ class ArcballControls extends EventDispatcher {
|
|
2080
2355
|
this.camera.far = state.arcballState.cameraFar;
|
2081
2356
|
this.camera.zoom = state.arcballState.cameraZoom;
|
2082
2357
|
|
2083
|
-
if (this.camera.
|
2358
|
+
if (this.camera.type === 'PerspectiveCamera') {
|
2084
2359
|
this.camera.fov = state.arcballState.cameraFov;
|
2085
2360
|
}
|
2086
2361
|
|
@@ -2093,7 +2368,12 @@ class ArcballControls extends EventDispatcher {
|
|
2093
2368
|
|
2094
2369
|
this._gizmos.updateMatrix();
|
2095
2370
|
|
2096
|
-
|
2371
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
2372
|
+
|
2373
|
+
if (tbRadius !== undefined) {
|
2374
|
+
this._tbRadius = tbRadius;
|
2375
|
+
}
|
2376
|
+
|
2097
2377
|
const gizmoTmp = new Matrix4().copy(this._gizmoMatrixState0);
|
2098
2378
|
this.makeGizmos(this._gizmos.position, this._tbRadius);
|
2099
2379
|
|
@@ -2106,6 +2386,7 @@ class ArcballControls extends EventDispatcher {
|
|
2106
2386
|
});
|
2107
2387
|
|
2108
2388
|
this.camera = null;
|
2389
|
+
this.domElement = _domElement;
|
2109
2390
|
this.scene = scene;
|
2110
2391
|
this.mouseActions = [];
|
2111
2392
|
this._mouseOp = null; //global vectors and matrices that are used in some operations to avoid creating new objects every time (e.g. every time cursor moves)
|
@@ -2163,8 +2444,6 @@ class ArcballControls extends EventDispatcher {
|
|
2163
2444
|
this._downValid = true;
|
2164
2445
|
this._nclicks = 0;
|
2165
2446
|
this._downEvents = [];
|
2166
|
-
this._downStart = 0; //pointerDown time
|
2167
|
-
|
2168
2447
|
this._clickStart = 0; //first click time
|
2169
2448
|
|
2170
2449
|
this._maxDownTime = 250;
|
@@ -2224,7 +2503,6 @@ class ArcballControls extends EventDispatcher {
|
|
2224
2503
|
this.enablePan = true;
|
2225
2504
|
this.enableRotate = true;
|
2226
2505
|
this.enableZoom = true;
|
2227
|
-
this.enableGizmos = true;
|
2228
2506
|
this.minDistance = 0;
|
2229
2507
|
this.maxDistance = Infinity;
|
2230
2508
|
this.minZoom = 0;
|
@@ -2237,14 +2515,15 @@ class ArcballControls extends EventDispatcher {
|
|
2237
2515
|
this._state = STATE.IDLE;
|
2238
2516
|
this.setCamera(_camera);
|
2239
2517
|
|
2240
|
-
if (this.scene
|
2518
|
+
if (this.scene) {
|
2241
2519
|
this.scene.add(this._gizmos);
|
2242
|
-
}
|
2243
|
-
|
2520
|
+
}
|
2244
2521
|
|
2245
|
-
if (_domElement !== undefined) this.connect(_domElement);
|
2246
2522
|
this._devPxRatio = window.devicePixelRatio;
|
2247
2523
|
this.initializeMouseActions();
|
2524
|
+
if (this.domElement) this.connect(this.domElement);
|
2525
|
+
window.addEventListener('keydown', this.onKeyDown);
|
2526
|
+
window.addEventListener('resize', this.onWindowResize);
|
2248
2527
|
} //listeners
|
2249
2528
|
|
2250
2529
|
|
@@ -2253,7 +2532,7 @@ class ArcballControls extends EventDispatcher {
|
|
2253
2532
|
* @param {Object} transformation Object containing matrices to apply to camera and gizmos
|
2254
2533
|
*/
|
2255
2534
|
applyTransformMatrix(transformation) {
|
2256
|
-
if (transformation.camera
|
2535
|
+
if (transformation !== null && transformation !== void 0 && transformation.camera && this.camera) {
|
2257
2536
|
this._m4_1.copy(this._cameraMatrixState).premultiply(transformation.camera);
|
2258
2537
|
|
2259
2538
|
this._m4_1.decompose(this.camera.position, this.camera.quaternion, this.camera.scale);
|
@@ -2265,7 +2544,7 @@ class ArcballControls extends EventDispatcher {
|
|
2265
2544
|
}
|
2266
2545
|
}
|
2267
2546
|
|
2268
|
-
if (transformation
|
2547
|
+
if (transformation !== null && transformation !== void 0 && transformation.gizmos) {
|
2269
2548
|
this._m4_1.copy(this._gizmoMatrixState).premultiply(transformation.gizmos);
|
2270
2549
|
|
2271
2550
|
this._m4_1.decompose(this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale);
|
@@ -2273,8 +2552,12 @@ class ArcballControls extends EventDispatcher {
|
|
2273
2552
|
this._gizmos.updateMatrix();
|
2274
2553
|
}
|
2275
2554
|
|
2276
|
-
if (this._state == STATE.SCALE || this._state == STATE.FOCUS || this._state == STATE.ANIMATION_FOCUS) {
|
2277
|
-
|
2555
|
+
if ((this._state == STATE.SCALE || this._state == STATE.FOCUS || this._state == STATE.ANIMATION_FOCUS) && this.camera) {
|
2556
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
2557
|
+
|
2558
|
+
if (tbRadius !== undefined) {
|
2559
|
+
this._tbRadius = tbRadius;
|
2560
|
+
}
|
2278
2561
|
|
2279
2562
|
if (this.adjustNearFar) {
|
2280
2563
|
const cameraDistance = this.camera.position.distanceTo(this._gizmos.position);
|
@@ -2340,8 +2623,8 @@ class ArcballControls extends EventDispatcher {
|
|
2340
2623
|
* @param {Matrix4} gizmos Transformation to be applied to gizmos
|
2341
2624
|
*/
|
2342
2625
|
setTransformationMatrices(camera = null, gizmos = null) {
|
2343
|
-
if (camera
|
2344
|
-
if (_transformation.camera
|
2626
|
+
if (camera) {
|
2627
|
+
if (_transformation.camera) {
|
2345
2628
|
_transformation.camera.copy(camera);
|
2346
2629
|
} else {
|
2347
2630
|
_transformation.camera = camera.clone();
|
@@ -2350,8 +2633,8 @@ class ArcballControls extends EventDispatcher {
|
|
2350
2633
|
_transformation.camera = null;
|
2351
2634
|
}
|
2352
2635
|
|
2353
|
-
if (gizmos
|
2354
|
-
if (_transformation.gizmos
|
2636
|
+
if (gizmos) {
|
2637
|
+
if (_transformation.gizmos) {
|
2355
2638
|
_transformation.gizmos.copy(gizmos);
|
2356
2639
|
} else {
|
2357
2640
|
_transformation.gizmos = gizmos.clone();
|