three-stdlib 2.6.3 → 2.7.2
Sign up to get free protection for your applications and to get access to all the features.
- package/{Nodes-ec4e1143.js → Nodes-894ac9dc.js} +0 -0
- package/{Nodes-427f68b0.js → Nodes-af575af7.js} +0 -0
- package/controls/ArcballControls.cjs.js +1 -1
- package/controls/ArcballControls.d.ts +161 -0
- package/controls/ArcballControls.js +554 -285
- 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 -2
- package/loaders/NodeMaterialLoader.cjs.js +1 -1
- package/loaders/RGBELoader.cjs.js +1 -1
- package/loaders/RGBELoader.js +10 -9
- package/loaders/RGBMLoader.cjs.js +1 -1
- package/loaders/RGBMLoader.js +181 -257
- 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/TempNode.js +6 -6
- package/nodes/effects/BlurNode.js +3 -3
- package/nodes/math/MathNode.js +3 -3
- 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/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
|
}
|
@@ -433,28 +628,16 @@ class ArcballControls extends EventDispatcher {
|
|
433
628
|
}
|
434
629
|
});
|
435
630
|
|
436
|
-
_defineProperty(this, "onKeyDown", event => {
|
437
|
-
if (event.key == 'c') {
|
438
|
-
if (event.ctrlKey || event.metaKey) {
|
439
|
-
this.copyState();
|
440
|
-
}
|
441
|
-
} else if (event.key == 'v') {
|
442
|
-
if (event.ctrlKey || event.metaKey) {
|
443
|
-
this.pasteState();
|
444
|
-
}
|
445
|
-
}
|
446
|
-
});
|
447
|
-
|
448
631
|
_defineProperty(this, "onSinglePanStart", (event, operation) => {
|
449
|
-
|
632
|
+
var _this$camera4;
|
633
|
+
|
634
|
+
if (this.enabled && this.domElement) {
|
450
635
|
this.dispatchEvent(_startEvent);
|
451
636
|
this.setCenter(event.clientX, event.clientY);
|
452
637
|
|
453
638
|
switch (operation) {
|
454
639
|
case 'PAN':
|
455
|
-
if (!this.enablePan)
|
456
|
-
return;
|
457
|
-
}
|
640
|
+
if (!this.enablePan) return;
|
458
641
|
|
459
642
|
if (this._animationId != -1) {
|
460
643
|
cancelAnimationFrame(this._animationId);
|
@@ -464,21 +647,24 @@ class ArcballControls extends EventDispatcher {
|
|
464
647
|
this.dispatchEvent(_changeEvent);
|
465
648
|
}
|
466
649
|
|
467
|
-
this.
|
650
|
+
if (this.camera) {
|
651
|
+
this.updateTbState(STATE.PAN, true);
|
652
|
+
const rayDir = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement);
|
468
653
|
|
469
|
-
|
654
|
+
if (rayDir !== undefined) {
|
655
|
+
this._startCursorPosition.copy(rayDir);
|
656
|
+
}
|
470
657
|
|
471
|
-
|
472
|
-
|
473
|
-
|
658
|
+
if (this.enableGrid) {
|
659
|
+
this.drawGrid();
|
660
|
+
this.dispatchEvent(_changeEvent);
|
661
|
+
}
|
474
662
|
}
|
475
663
|
|
476
664
|
break;
|
477
665
|
|
478
666
|
case 'ROTATE':
|
479
|
-
if (!this.enableRotate)
|
480
|
-
return;
|
481
|
-
}
|
667
|
+
if (!this.enableRotate) return;
|
482
668
|
|
483
669
|
if (this._animationId != -1) {
|
484
670
|
cancelAnimationFrame(this._animationId);
|
@@ -486,52 +672,55 @@ class ArcballControls extends EventDispatcher {
|
|
486
672
|
this._timeStart = -1;
|
487
673
|
}
|
488
674
|
|
489
|
-
this.
|
675
|
+
if (this.camera) {
|
676
|
+
this.updateTbState(STATE.ROTATE, true);
|
677
|
+
const rayDir = this.unprojectOnTbSurface(this.camera, _center.x, _center.y, this.domElement, this._tbRadius);
|
490
678
|
|
491
|
-
|
679
|
+
if (rayDir !== undefined) {
|
680
|
+
this._startCursorPosition.copy(rayDir);
|
681
|
+
}
|
492
682
|
|
493
|
-
|
683
|
+
this.activateGizmos(true);
|
494
684
|
|
495
|
-
|
496
|
-
|
497
|
-
|
685
|
+
if (this.enableAnimations) {
|
686
|
+
this._timePrev = this._timeCurrent = performance.now();
|
687
|
+
this._angleCurrent = this._anglePrev = 0;
|
498
688
|
|
499
|
-
|
689
|
+
this._cursorPosPrev.copy(this._startCursorPosition);
|
500
690
|
|
501
|
-
|
691
|
+
this._cursorPosCurr.copy(this._cursorPosPrev);
|
502
692
|
|
503
|
-
|
504
|
-
|
693
|
+
this._wCurr = 0;
|
694
|
+
this._wPrev = this._wCurr;
|
695
|
+
}
|
505
696
|
}
|
506
697
|
|
507
698
|
this.dispatchEvent(_changeEvent);
|
508
699
|
break;
|
509
700
|
|
510
701
|
case 'FOV':
|
511
|
-
if (!this.
|
512
|
-
return;
|
513
|
-
}
|
702
|
+
if (!this.enableZoom) return;
|
514
703
|
|
515
|
-
if (this.
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
704
|
+
if (((_this$camera4 = this.camera) === null || _this$camera4 === void 0 ? void 0 : _this$camera4.type) === 'PerspectiveCamera') {
|
705
|
+
if (this._animationId != -1) {
|
706
|
+
cancelAnimationFrame(this._animationId);
|
707
|
+
this._animationId = -1;
|
708
|
+
this._timeStart = -1;
|
709
|
+
this.activateGizmos(false);
|
710
|
+
this.dispatchEvent(_changeEvent);
|
711
|
+
}
|
522
712
|
|
523
|
-
|
713
|
+
this.updateTbState(STATE.FOV, true);
|
524
714
|
|
525
|
-
|
715
|
+
this._startCursorPosition.setY(this.getCursorNDC(_center.x, _center.y, this.domElement).y * 0.5);
|
526
716
|
|
527
|
-
|
717
|
+
this._currentCursorPosition.copy(this._startCursorPosition);
|
718
|
+
}
|
528
719
|
|
529
720
|
break;
|
530
721
|
|
531
722
|
case 'ZOOM':
|
532
|
-
if (!this.enableZoom)
|
533
|
-
return;
|
534
|
-
}
|
723
|
+
if (!this.enableZoom) return;
|
535
724
|
|
536
725
|
if (this._animationId != -1) {
|
537
726
|
cancelAnimationFrame(this._animationId);
|
@@ -553,20 +742,25 @@ class ArcballControls extends EventDispatcher {
|
|
553
742
|
});
|
554
743
|
|
555
744
|
_defineProperty(this, "onSinglePanMove", (event, opState) => {
|
556
|
-
|
745
|
+
var _this$camera5;
|
746
|
+
|
747
|
+
if (this.enabled && this.domElement) {
|
557
748
|
const restart = opState != this._state;
|
558
749
|
this.setCenter(event.clientX, event.clientY);
|
559
750
|
|
560
751
|
switch (opState) {
|
561
752
|
case STATE.PAN:
|
562
|
-
if (this.enablePan) {
|
753
|
+
if (this.enablePan && this.camera) {
|
563
754
|
if (restart) {
|
564
755
|
//switch to pan operation
|
565
756
|
this.dispatchEvent(_endEvent);
|
566
757
|
this.dispatchEvent(_startEvent);
|
567
758
|
this.updateTbState(opState, true);
|
759
|
+
const rayDir = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement);
|
568
760
|
|
569
|
-
|
761
|
+
if (rayDir !== undefined) {
|
762
|
+
this._startCursorPosition.copy(rayDir);
|
763
|
+
}
|
570
764
|
|
571
765
|
if (this.enableGrid) {
|
572
766
|
this.drawGrid();
|
@@ -575,7 +769,11 @@ class ArcballControls extends EventDispatcher {
|
|
575
769
|
this.activateGizmos(false);
|
576
770
|
} else {
|
577
771
|
//continue with pan operation
|
578
|
-
this.
|
772
|
+
const rayDir = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement);
|
773
|
+
|
774
|
+
if (rayDir !== undefined) {
|
775
|
+
this._currentCursorPosition.copy(rayDir);
|
776
|
+
}
|
579
777
|
|
580
778
|
this.applyTransformMatrix(this.pan(this._startCursorPosition, this._currentCursorPosition));
|
581
779
|
}
|
@@ -584,14 +782,17 @@ class ArcballControls extends EventDispatcher {
|
|
584
782
|
break;
|
585
783
|
|
586
784
|
case STATE.ROTATE:
|
587
|
-
if (this.enableRotate) {
|
785
|
+
if (this.enableRotate && this.camera) {
|
588
786
|
if (restart) {
|
589
787
|
//switch to rotate operation
|
590
788
|
this.dispatchEvent(_endEvent);
|
591
789
|
this.dispatchEvent(_startEvent);
|
592
790
|
this.updateTbState(opState, true);
|
791
|
+
const rayDir = this.unprojectOnTbSurface(this.camera, _center.x, _center.y, this.domElement, this._tbRadius);
|
593
792
|
|
594
|
-
|
793
|
+
if (rayDir !== undefined) {
|
794
|
+
this._startCursorPosition.copy(rayDir);
|
795
|
+
}
|
595
796
|
|
596
797
|
if (this.enableGrid) {
|
597
798
|
this.disposeGrid();
|
@@ -600,7 +801,11 @@ class ArcballControls extends EventDispatcher {
|
|
600
801
|
this.activateGizmos(true);
|
601
802
|
} else {
|
602
803
|
//continue with rotate operation
|
603
|
-
this.
|
804
|
+
const rayDir = this.unprojectOnTbSurface(this.camera, _center.x, _center.y, this.domElement, this._tbRadius);
|
805
|
+
|
806
|
+
if (rayDir !== undefined) {
|
807
|
+
this._currentCursorPosition.copy(rayDir);
|
808
|
+
}
|
604
809
|
|
605
810
|
const distance = this._startCursorPosition.distanceTo(this._currentCursorPosition);
|
606
811
|
|
@@ -667,7 +872,7 @@ class ArcballControls extends EventDispatcher {
|
|
667
872
|
break;
|
668
873
|
|
669
874
|
case STATE.FOV:
|
670
|
-
if (this.enableZoom && this.camera.
|
875
|
+
if (this.enableZoom && ((_this$camera5 = this.camera) === null || _this$camera5 === void 0 ? void 0 : _this$camera5.type) === 'PerspectiveCamera') {
|
671
876
|
if (restart) {
|
672
877
|
//switch to fov operation
|
673
878
|
this.dispatchEvent(_endEvent);
|
@@ -776,12 +981,12 @@ class ArcballControls extends EventDispatcher {
|
|
776
981
|
});
|
777
982
|
|
778
983
|
_defineProperty(this, "onDoubleTap", event => {
|
779
|
-
if (this.enabled && this.enablePan && this.scene
|
984
|
+
if (this.enabled && this.enablePan && this.scene && this.camera && this.domElement) {
|
780
985
|
this.dispatchEvent(_startEvent);
|
781
986
|
this.setCenter(event.clientX, event.clientY);
|
782
987
|
const hitP = this.unprojectOnObj(this.getCursorNDC(_center.x, _center.y, this.domElement), this.camera);
|
783
988
|
|
784
|
-
if (hitP
|
989
|
+
if (hitP && this.enableAnimations) {
|
785
990
|
const self = this;
|
786
991
|
|
787
992
|
if (this._animationId != -1) {
|
@@ -793,7 +998,7 @@ class ArcballControls extends EventDispatcher {
|
|
793
998
|
self.updateTbState(STATE.ANIMATION_FOCUS, true);
|
794
999
|
self.onFocusAnim(t, hitP, self._cameraMatrixState, self._gizmoMatrixState);
|
795
1000
|
});
|
796
|
-
} else if (hitP
|
1001
|
+
} else if (hitP && !this.enableAnimations) {
|
797
1002
|
this.updateTbState(STATE.FOCUS, true);
|
798
1003
|
this.focus(hitP, this.scaleFactor);
|
799
1004
|
this.updateTbState(STATE.IDLE, false);
|
@@ -805,12 +1010,15 @@ class ArcballControls extends EventDispatcher {
|
|
805
1010
|
});
|
806
1011
|
|
807
1012
|
_defineProperty(this, "onDoublePanStart", () => {
|
808
|
-
if (this.enabled && this.enablePan) {
|
1013
|
+
if (this.enabled && this.enablePan && this.camera && this.domElement) {
|
809
1014
|
this.dispatchEvent(_startEvent);
|
810
1015
|
this.updateTbState(STATE.PAN, true);
|
811
1016
|
this.setCenter((this._touchCurrent[0].clientX + this._touchCurrent[1].clientX) / 2, (this._touchCurrent[0].clientY + this._touchCurrent[1].clientY) / 2);
|
1017
|
+
const rayDir = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement, true);
|
812
1018
|
|
813
|
-
|
1019
|
+
if (rayDir !== undefined) {
|
1020
|
+
this._startCursorPosition.copy(rayDir);
|
1021
|
+
}
|
814
1022
|
|
815
1023
|
this._currentCursorPosition.copy(this._startCursorPosition);
|
816
1024
|
|
@@ -819,7 +1027,7 @@ class ArcballControls extends EventDispatcher {
|
|
819
1027
|
});
|
820
1028
|
|
821
1029
|
_defineProperty(this, "onDoublePanMove", () => {
|
822
|
-
if (this.enabled && this.enablePan) {
|
1030
|
+
if (this.enabled && this.enablePan && this.camera && this.domElement) {
|
823
1031
|
this.setCenter((this._touchCurrent[0].clientX + this._touchCurrent[1].clientX) / 2, (this._touchCurrent[0].clientY + this._touchCurrent[1].clientY) / 2);
|
824
1032
|
|
825
1033
|
if (this._state != STATE.PAN) {
|
@@ -828,8 +1036,8 @@ class ArcballControls extends EventDispatcher {
|
|
828
1036
|
this._startCursorPosition.copy(this._currentCursorPosition);
|
829
1037
|
}
|
830
1038
|
|
831
|
-
this.
|
832
|
-
|
1039
|
+
const rayDir = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement, true);
|
1040
|
+
if (rayDir !== undefined) this._currentCursorPosition.copy(rayDir);
|
833
1041
|
this.applyTransformMatrix(this.pan(this._startCursorPosition, this._currentCursorPosition, true));
|
834
1042
|
this.dispatchEvent(_changeEvent);
|
835
1043
|
}
|
@@ -842,12 +1050,14 @@ class ArcballControls extends EventDispatcher {
|
|
842
1050
|
|
843
1051
|
_defineProperty(this, "onRotateStart", () => {
|
844
1052
|
if (this.enabled && this.enableRotate) {
|
1053
|
+
var _this$camera6;
|
1054
|
+
|
845
1055
|
this.dispatchEvent(_startEvent);
|
846
1056
|
this.updateTbState(STATE.ZROTATE, true); //this._startFingerRotation = event.rotation;
|
847
1057
|
|
848
1058
|
this._startFingerRotation = this.getAngle(this._touchCurrent[1], this._touchCurrent[0]) + this.getAngle(this._touchStart[1], this._touchStart[0]);
|
849
1059
|
this._currentFingerRotation = this._startFingerRotation;
|
850
|
-
this.camera.getWorldDirection(this._rotationAxis); //rotation axis
|
1060
|
+
(_this$camera6 = this.camera) === null || _this$camera6 === void 0 ? void 0 : _this$camera6.getWorldDirection(this._rotationAxis); //rotation axis
|
851
1061
|
|
852
1062
|
if (!this.enablePan && !this.enableZoom) {
|
853
1063
|
this.activateGizmos(true);
|
@@ -856,7 +1066,7 @@ class ArcballControls extends EventDispatcher {
|
|
856
1066
|
});
|
857
1067
|
|
858
1068
|
_defineProperty(this, "onRotateMove", () => {
|
859
|
-
if (this.enabled && this.enableRotate) {
|
1069
|
+
if (this.enabled && this.enableRotate && this.camera && this.domElement) {
|
860
1070
|
this.setCenter((this._touchCurrent[0].clientX + this._touchCurrent[1].clientX) / 2, (this._touchCurrent[0].clientY + this._touchCurrent[1].clientY) / 2);
|
861
1071
|
let rotationPoint;
|
862
1072
|
|
@@ -870,14 +1080,20 @@ class ArcballControls extends EventDispatcher {
|
|
870
1080
|
|
871
1081
|
if (!this.enablePan) {
|
872
1082
|
rotationPoint = new Vector3().setFromMatrixPosition(this._gizmoMatrixState);
|
873
|
-
} else {
|
1083
|
+
} else if (this.camera) {
|
1084
|
+
var _this$unprojectOnTbPl3;
|
1085
|
+
|
874
1086
|
this._v3_2.setFromMatrixPosition(this._gizmoMatrixState);
|
875
1087
|
|
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);
|
1088
|
+
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
1089
|
}
|
878
1090
|
|
879
1091
|
const amount = MathUtils.DEG2RAD * (this._startFingerRotation - this._currentFingerRotation);
|
880
|
-
|
1092
|
+
|
1093
|
+
if (rotationPoint !== undefined) {
|
1094
|
+
this.applyTransformMatrix(this.zRotate(rotationPoint, amount));
|
1095
|
+
}
|
1096
|
+
|
881
1097
|
this.dispatchEvent(_changeEvent);
|
882
1098
|
}
|
883
1099
|
});
|
@@ -899,7 +1115,7 @@ class ArcballControls extends EventDispatcher {
|
|
899
1115
|
});
|
900
1116
|
|
901
1117
|
_defineProperty(this, "onPinchMove", () => {
|
902
|
-
if (this.enabled && this.enableZoom) {
|
1118
|
+
if (this.enabled && this.enableZoom && this.domElement) {
|
903
1119
|
this.setCenter((this._touchCurrent[0].clientX + this._touchCurrent[1].clientX) / 2, (this._touchCurrent[0].clientY + this._touchCurrent[1].clientY) / 2);
|
904
1120
|
const minDistance = 12; //minimum distance between fingers (in css pixels)
|
905
1121
|
|
@@ -915,14 +1131,23 @@ class ArcballControls extends EventDispatcher {
|
|
915
1131
|
if (!this.enablePan) {
|
916
1132
|
scalePoint = this._gizmos.position;
|
917
1133
|
} else {
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
1134
|
+
var _this$camera7, _this$camera8;
|
1135
|
+
|
1136
|
+
if (((_this$camera7 = this.camera) === null || _this$camera7 === void 0 ? void 0 : _this$camera7.type) === 'OrthographicCamera') {
|
1137
|
+
var _this$unprojectOnTbPl4;
|
1138
|
+
|
1139
|
+
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);
|
1140
|
+
} else if (((_this$camera8 = this.camera) === null || _this$camera8 === void 0 ? void 0 : _this$camera8.type) === 'PerspectiveCamera') {
|
1141
|
+
var _this$unprojectOnTbPl5;
|
1142
|
+
|
1143
|
+
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
1144
|
}
|
923
1145
|
}
|
924
1146
|
|
925
|
-
|
1147
|
+
if (scalePoint !== undefined) {
|
1148
|
+
this.applyTransformMatrix(this.applyScale(amount, scalePoint));
|
1149
|
+
}
|
1150
|
+
|
926
1151
|
this.dispatchEvent(_changeEvent);
|
927
1152
|
}
|
928
1153
|
});
|
@@ -933,7 +1158,7 @@ class ArcballControls extends EventDispatcher {
|
|
933
1158
|
});
|
934
1159
|
|
935
1160
|
_defineProperty(this, "onTriplePanStart", () => {
|
936
|
-
if (this.enabled && this.enableZoom) {
|
1161
|
+
if (this.enabled && this.enableZoom && this.domElement) {
|
937
1162
|
this.dispatchEvent(_startEvent);
|
938
1163
|
this.updateTbState(STATE.SCALE, true); //const center = event.center;
|
939
1164
|
|
@@ -955,7 +1180,7 @@ class ArcballControls extends EventDispatcher {
|
|
955
1180
|
});
|
956
1181
|
|
957
1182
|
_defineProperty(this, "onTriplePanMove", () => {
|
958
|
-
if (this.enabled && this.enableZoom) {
|
1183
|
+
if (this.enabled && this.enableZoom && this.camera && this.domElement) {
|
959
1184
|
// fov / 2
|
960
1185
|
// |\
|
961
1186
|
// | \
|
@@ -1038,18 +1263,6 @@ class ArcballControls extends EventDispatcher {
|
|
1038
1263
|
this.setMouseAction('FOV', 1, 'SHIFT');
|
1039
1264
|
});
|
1040
1265
|
|
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
1266
|
_defineProperty(this, "setMouseAction", (operation, mouse, key = null) => {
|
1054
1267
|
const operationInput = ['PAN', 'ROTATE', 'ZOOM', 'FOV'];
|
1055
1268
|
const mouseInput = [0, 1, 2, 'WHEEL'];
|
@@ -1104,17 +1317,6 @@ class ArcballControls extends EventDispatcher {
|
|
1104
1317
|
return true;
|
1105
1318
|
});
|
1106
1319
|
|
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
1320
|
_defineProperty(this, "getOpFromAction", (mouse, key) => {
|
1119
1321
|
let action;
|
1120
1322
|
|
@@ -1126,7 +1328,7 @@ class ArcballControls extends EventDispatcher {
|
|
1126
1328
|
}
|
1127
1329
|
}
|
1128
1330
|
|
1129
|
-
if (key
|
1331
|
+
if (key) {
|
1130
1332
|
for (let i = 0; i < this.mouseActions.length; i++) {
|
1131
1333
|
action = this.mouseActions[i];
|
1132
1334
|
|
@@ -1150,7 +1352,7 @@ class ArcballControls extends EventDispatcher {
|
|
1150
1352
|
}
|
1151
1353
|
}
|
1152
1354
|
|
1153
|
-
if (key
|
1355
|
+
if (key) {
|
1154
1356
|
for (let i = 0; i < this.mouseActions.length; i++) {
|
1155
1357
|
action = this.mouseActions[i];
|
1156
1358
|
|
@@ -1218,48 +1420,52 @@ class ArcballControls extends EventDispatcher {
|
|
1218
1420
|
});
|
1219
1421
|
|
1220
1422
|
_defineProperty(this, "focus", (point, size, amount = 1) => {
|
1221
|
-
|
1423
|
+
if (this.camera) {
|
1424
|
+
const focusPoint = point.clone(); //move center of camera (along with gizmos) towards point of interest
|
1222
1425
|
|
1223
|
-
|
1426
|
+
focusPoint.sub(this._gizmos.position).multiplyScalar(amount);
|
1224
1427
|
|
1225
|
-
|
1428
|
+
this._translationMatrix.makeTranslation(focusPoint.x, focusPoint.y, focusPoint.z);
|
1226
1429
|
|
1227
|
-
|
1430
|
+
const gizmoStateTemp = this._gizmoMatrixState.clone();
|
1228
1431
|
|
1229
|
-
|
1432
|
+
this._gizmoMatrixState.premultiply(this._translationMatrix);
|
1230
1433
|
|
1231
|
-
|
1434
|
+
this._gizmoMatrixState.decompose(this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale);
|
1232
1435
|
|
1233
|
-
|
1436
|
+
const cameraStateTemp = this._cameraMatrixState.clone();
|
1234
1437
|
|
1235
|
-
|
1438
|
+
this._cameraMatrixState.premultiply(this._translationMatrix);
|
1236
1439
|
|
1237
|
-
|
1440
|
+
this._cameraMatrixState.decompose(this.camera.position, this.camera.quaternion, this.camera.scale); //apply zoom
|
1238
1441
|
|
1239
1442
|
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1443
|
+
if (this.enableZoom) {
|
1444
|
+
this.applyTransformMatrix(this.applyScale(size, this._gizmos.position));
|
1445
|
+
}
|
1243
1446
|
|
1244
|
-
|
1447
|
+
this._gizmoMatrixState.copy(gizmoStateTemp);
|
1245
1448
|
|
1246
|
-
|
1449
|
+
this._cameraMatrixState.copy(cameraStateTemp);
|
1450
|
+
}
|
1247
1451
|
});
|
1248
1452
|
|
1249
1453
|
_defineProperty(this, "drawGrid", () => {
|
1250
|
-
if (this.scene
|
1454
|
+
if (this.scene) {
|
1455
|
+
var _this$camera9, _this$camera10;
|
1456
|
+
|
1251
1457
|
const color = 0x888888;
|
1252
1458
|
const multiplier = 3;
|
1253
1459
|
let size, divisions, maxLength, tick;
|
1254
1460
|
|
1255
|
-
if (this.camera.
|
1461
|
+
if (((_this$camera9 = this.camera) === null || _this$camera9 === void 0 ? void 0 : _this$camera9.type) === 'OrthographicCamera') {
|
1256
1462
|
const width = this.camera.right - this.camera.left;
|
1257
1463
|
const height = this.camera.bottom - this.camera.top;
|
1258
1464
|
maxLength = Math.max(width, height);
|
1259
1465
|
tick = maxLength / 20;
|
1260
1466
|
size = maxLength / this.camera.zoom * multiplier;
|
1261
1467
|
divisions = size / tick * this.camera.zoom;
|
1262
|
-
} else if (this.camera.
|
1468
|
+
} else if (((_this$camera10 = this.camera) === null || _this$camera10 === void 0 ? void 0 : _this$camera10.type) === 'PerspectiveCamera') {
|
1263
1469
|
const distance = this.camera.position.distanceTo(this._gizmos.position);
|
1264
1470
|
const halfFovV = MathUtils.DEG2RAD * this.camera.fov * 0.5;
|
1265
1471
|
const halfFovH = Math.atan(this.camera.aspect * Math.tan(halfFovV));
|
@@ -1269,7 +1475,7 @@ class ArcballControls extends EventDispatcher {
|
|
1269
1475
|
divisions = size / tick;
|
1270
1476
|
}
|
1271
1477
|
|
1272
|
-
if (this._grid == null) {
|
1478
|
+
if (this._grid == null && this.camera) {
|
1273
1479
|
this._grid = new GridHelper(size, divisions, color, color);
|
1274
1480
|
|
1275
1481
|
this._grid.position.copy(this._gizmos.position);
|
@@ -1286,35 +1492,42 @@ class ArcballControls extends EventDispatcher {
|
|
1286
1492
|
});
|
1287
1493
|
|
1288
1494
|
_defineProperty(this, "connect", domElement => {
|
1289
|
-
|
1495
|
+
// https://github.com/mrdoob/three.js/issues/20575
|
1496
|
+
if (domElement === document) {
|
1497
|
+
console.error('THREE.ArcballControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.');
|
1498
|
+
}
|
1499
|
+
|
1500
|
+
this.domElement = domElement; // disables touch scroll
|
1501
|
+
// touch-action needs to be defined for pointer events to work on mobile
|
1502
|
+
// https://stackoverflow.com/a/48254578
|
1503
|
+
|
1290
1504
|
this.domElement.style.touchAction = 'none';
|
1291
1505
|
this.domElement.addEventListener('contextmenu', this.onContextMenu);
|
1292
|
-
this.domElement.addEventListener('wheel', this.onWheel);
|
1293
1506
|
this.domElement.addEventListener('pointerdown', this.onPointerDown);
|
1294
1507
|
this.domElement.addEventListener('pointercancel', this.onPointerCancel);
|
1295
|
-
|
1296
|
-
window.addEventListener('resize', this.onWindowResize);
|
1508
|
+
this.domElement.addEventListener('wheel', this.onWheel);
|
1297
1509
|
});
|
1298
1510
|
|
1299
1511
|
_defineProperty(this, "dispose", () => {
|
1512
|
+
var _this$domElement, _this$domElement2, _this$domElement3, _this$domElement4, _this$scene;
|
1513
|
+
|
1300
1514
|
if (this._animationId != -1) {
|
1301
1515
|
window.cancelAnimationFrame(this._animationId);
|
1302
1516
|
}
|
1303
1517
|
|
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);
|
1518
|
+
(_this$domElement = this.domElement) === null || _this$domElement === void 0 ? void 0 : _this$domElement.removeEventListener('pointerdown', this.onPointerDown);
|
1519
|
+
(_this$domElement2 = this.domElement) === null || _this$domElement2 === void 0 ? void 0 : _this$domElement2.removeEventListener('pointercancel', this.onPointerCancel);
|
1520
|
+
(_this$domElement3 = this.domElement) === null || _this$domElement3 === void 0 ? void 0 : _this$domElement3.removeEventListener('wheel', this.onWheel);
|
1521
|
+
(_this$domElement4 = this.domElement) === null || _this$domElement4 === void 0 ? void 0 : _this$domElement4.removeEventListener('contextmenu', this.onContextMenu);
|
1308
1522
|
window.removeEventListener('pointermove', this.onPointerMove);
|
1309
1523
|
window.removeEventListener('pointerup', this.onPointerUp);
|
1310
1524
|
window.removeEventListener('resize', this.onWindowResize);
|
1311
|
-
|
1312
|
-
if (this.scene) this.scene.remove(this._gizmos);
|
1525
|
+
(_this$scene = this.scene) === null || _this$scene === void 0 ? void 0 : _this$scene.remove(this._gizmos);
|
1313
1526
|
this.disposeGrid();
|
1314
1527
|
});
|
1315
1528
|
|
1316
1529
|
_defineProperty(this, "disposeGrid", () => {
|
1317
|
-
if (this._grid
|
1530
|
+
if (this._grid && this.scene) {
|
1318
1531
|
this.scene.remove(this._grid);
|
1319
1532
|
this._grid = null;
|
1320
1533
|
}
|
@@ -1325,29 +1538,9 @@ class ArcballControls extends EventDispatcher {
|
|
1325
1538
|
});
|
1326
1539
|
|
1327
1540
|
_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
|
1541
|
+
for (const gizmo of this._gizmos.children) {
|
1542
|
+
gizmo.material.setValues({
|
1543
|
+
opacity: isActive ? 1 : 0.6
|
1351
1544
|
});
|
1352
1545
|
}
|
1353
1546
|
});
|
@@ -1363,49 +1556,62 @@ class ArcballControls extends EventDispatcher {
|
|
1363
1556
|
});
|
1364
1557
|
|
1365
1558
|
_defineProperty(this, "getCursorPosition", (cursorX, cursorY, canvas) => {
|
1559
|
+
var _this$camera11;
|
1560
|
+
|
1366
1561
|
this._v2_1.copy(this.getCursorNDC(cursorX, cursorY, canvas));
|
1367
1562
|
|
1368
|
-
|
1369
|
-
|
1563
|
+
if (((_this$camera11 = this.camera) === null || _this$camera11 === void 0 ? void 0 : _this$camera11.type) === 'OrthographicCamera') {
|
1564
|
+
this._v2_1.x *= (this.camera.right - this.camera.left) * 0.5;
|
1565
|
+
this._v2_1.y *= (this.camera.top - this.camera.bottom) * 0.5;
|
1566
|
+
}
|
1567
|
+
|
1370
1568
|
return this._v2_1.clone();
|
1371
1569
|
});
|
1372
1570
|
|
1373
1571
|
_defineProperty(this, "setCamera", camera => {
|
1374
|
-
camera
|
1375
|
-
|
1572
|
+
if (camera) {
|
1573
|
+
camera.lookAt(this.target);
|
1574
|
+
camera.updateMatrix(); //setting state
|
1376
1575
|
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1576
|
+
if ((camera === null || camera === void 0 ? void 0 : camera.type) == 'PerspectiveCamera') {
|
1577
|
+
this._fov0 = camera.fov;
|
1578
|
+
this._fovState = camera.fov;
|
1579
|
+
}
|
1580
|
+
|
1581
|
+
this._cameraMatrixState0.copy(camera.matrix);
|
1582
|
+
|
1583
|
+
this._cameraMatrixState.copy(this._cameraMatrixState0);
|
1381
1584
|
|
1382
|
-
|
1585
|
+
this._cameraProjectionState.copy(camera.projectionMatrix);
|
1383
1586
|
|
1384
|
-
|
1587
|
+
this._zoom0 = camera.zoom;
|
1588
|
+
this._zoomState = this._zoom0;
|
1589
|
+
this._initialNear = camera.near;
|
1590
|
+
this._nearPos0 = camera.position.distanceTo(this.target) - camera.near;
|
1591
|
+
this._nearPos = this._initialNear;
|
1592
|
+
this._initialFar = camera.far;
|
1593
|
+
this._farPos0 = camera.position.distanceTo(this.target) - camera.far;
|
1594
|
+
this._farPos = this._initialFar;
|
1385
1595
|
|
1386
|
-
|
1596
|
+
this._up0.copy(camera.up);
|
1387
1597
|
|
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;
|
1598
|
+
this._upState.copy(camera.up);
|
1396
1599
|
|
1397
|
-
|
1600
|
+
this.camera = camera;
|
1601
|
+
this.camera.updateProjectionMatrix(); //making gizmos
|
1398
1602
|
|
1399
|
-
|
1603
|
+
const tbRadius = this.calculateTbRadius(camera);
|
1400
1604
|
|
1401
|
-
|
1402
|
-
|
1605
|
+
if (tbRadius !== undefined) {
|
1606
|
+
this._tbRadius = tbRadius;
|
1607
|
+
}
|
1403
1608
|
|
1404
|
-
|
1405
|
-
|
1609
|
+
this.makeGizmos(this.target, this._tbRadius);
|
1610
|
+
}
|
1406
1611
|
});
|
1407
1612
|
|
1408
1613
|
_defineProperty(this, "makeGizmos", (tbCenter, tbRadius) => {
|
1614
|
+
// @ts-expect-error
|
1409
1615
|
const curve = new EllipseCurve(0, 0, tbRadius, tbRadius);
|
1410
1616
|
const points = curve.getPoints(this._curvePts); //geometry
|
1411
1617
|
|
@@ -1441,7 +1647,7 @@ class ArcballControls extends EventDispatcher {
|
|
1441
1647
|
|
1442
1648
|
this._gizmoMatrixState.copy(this._gizmoMatrixState0);
|
1443
1649
|
|
1444
|
-
if (this.camera.zoom != 1) {
|
1650
|
+
if (this.camera && this.camera.zoom != 1) {
|
1445
1651
|
//adapt gizmos size to camera zoom
|
1446
1652
|
const size = 1 / this.camera.zoom;
|
1447
1653
|
|
@@ -1550,60 +1756,72 @@ class ArcballControls extends EventDispatcher {
|
|
1550
1756
|
});
|
1551
1757
|
|
1552
1758
|
_defineProperty(this, "pan", (p0, p1, adjust = false) => {
|
1553
|
-
|
1759
|
+
if (this.camera) {
|
1760
|
+
const movement = p0.clone().sub(p1);
|
1554
1761
|
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
|
1559
|
-
//adjust movement amount
|
1560
|
-
this._v3_1.setFromMatrixPosition(this._cameraMatrixState0); //camera's initial position
|
1762
|
+
if (this.camera.type === 'OrthographicCamera') {
|
1763
|
+
//adjust movement amount
|
1764
|
+
movement.multiplyScalar(1 / this.camera.zoom);
|
1765
|
+
}
|
1561
1766
|
|
1767
|
+
if (this.camera.type === 'PerspectiveCamera' && adjust) {
|
1768
|
+
//adjust movement amount
|
1769
|
+
this._v3_1.setFromMatrixPosition(this._cameraMatrixState0); //camera's initial position
|
1562
1770
|
|
1563
|
-
this._v3_2.setFromMatrixPosition(this._gizmoMatrixState0); //gizmo's initial position
|
1564
1771
|
|
1772
|
+
this._v3_2.setFromMatrixPosition(this._gizmoMatrixState0); //gizmo's initial position
|
1565
1773
|
|
1566
|
-
const distanceFactor = this._v3_1.distanceTo(this._v3_2) / this.camera.position.distanceTo(this._gizmos.position);
|
1567
|
-
movement.multiplyScalar(1 / distanceFactor);
|
1568
|
-
}
|
1569
1774
|
|
1570
|
-
|
1775
|
+
const distanceFactor = this._v3_1.distanceTo(this._v3_2) / this.camera.position.distanceTo(this._gizmos.position);
|
1776
|
+
movement.multiplyScalar(1 / distanceFactor);
|
1777
|
+
}
|
1778
|
+
|
1779
|
+
this._v3_1.set(movement.x, movement.y, 0).applyQuaternion(this.camera.quaternion);
|
1571
1780
|
|
1572
|
-
|
1781
|
+
this._m4_1.makeTranslation(this._v3_1.x, this._v3_1.y, this._v3_1.z);
|
1782
|
+
|
1783
|
+
this.setTransformationMatrices(this._m4_1, this._m4_1);
|
1784
|
+
}
|
1573
1785
|
|
1574
|
-
this.setTransformationMatrices(this._m4_1, this._m4_1);
|
1575
1786
|
return _transformation;
|
1576
1787
|
});
|
1577
1788
|
|
1578
1789
|
_defineProperty(this, "reset", () => {
|
1579
|
-
this.camera
|
1790
|
+
if (this.camera) {
|
1791
|
+
this.camera.zoom = this._zoom0;
|
1580
1792
|
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1793
|
+
if (this.camera.type === 'PerspectiveCamera') {
|
1794
|
+
this.camera.fov = this._fov0;
|
1795
|
+
}
|
1584
1796
|
|
1585
|
-
|
1586
|
-
|
1797
|
+
this.camera.near = this._nearPos;
|
1798
|
+
this.camera.far = this._farPos;
|
1587
1799
|
|
1588
|
-
|
1800
|
+
this._cameraMatrixState.copy(this._cameraMatrixState0);
|
1589
1801
|
|
1590
|
-
|
1802
|
+
this._cameraMatrixState.decompose(this.camera.position, this.camera.quaternion, this.camera.scale);
|
1591
1803
|
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1804
|
+
this.camera.up.copy(this._up0);
|
1805
|
+
this.camera.updateMatrix();
|
1806
|
+
this.camera.updateProjectionMatrix();
|
1595
1807
|
|
1596
|
-
|
1808
|
+
this._gizmoMatrixState.copy(this._gizmoMatrixState0);
|
1597
1809
|
|
1598
|
-
|
1810
|
+
this._gizmoMatrixState0.decompose(this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale);
|
1599
1811
|
|
1600
|
-
|
1812
|
+
this._gizmos.updateMatrix();
|
1601
1813
|
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1814
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
1815
|
+
|
1816
|
+
if (tbRadius !== undefined) {
|
1817
|
+
this._tbRadius = tbRadius;
|
1818
|
+
}
|
1819
|
+
|
1820
|
+
this.makeGizmos(this._gizmos.position, this._tbRadius);
|
1821
|
+
this.camera.lookAt(this._gizmos.position);
|
1822
|
+
this.updateTbState(STATE.IDLE, false);
|
1823
|
+
this.dispatchEvent(_changeEvent);
|
1824
|
+
}
|
1607
1825
|
});
|
1608
1826
|
|
1609
1827
|
_defineProperty(this, "rotate", (axis, angle) => {
|
@@ -1625,10 +1843,10 @@ class ArcballControls extends EventDispatcher {
|
|
1625
1843
|
});
|
1626
1844
|
|
1627
1845
|
_defineProperty(this, "copyState", () => {
|
1628
|
-
|
1846
|
+
if (this.camera) {
|
1847
|
+
var _this$camera12;
|
1629
1848
|
|
1630
|
-
|
1631
|
-
state = JSON.stringify({
|
1849
|
+
const state = JSON.stringify(((_this$camera12 = this.camera) === null || _this$camera12 === void 0 ? void 0 : _this$camera12.type) === 'OrthographicCamera' ? {
|
1632
1850
|
arcballState: {
|
1633
1851
|
cameraFar: this.camera.far,
|
1634
1852
|
cameraMatrix: this.camera.matrix,
|
@@ -1637,9 +1855,7 @@ class ArcballControls extends EventDispatcher {
|
|
1637
1855
|
cameraZoom: this.camera.zoom,
|
1638
1856
|
gizmoMatrix: this._gizmos.matrix
|
1639
1857
|
}
|
1640
|
-
}
|
1641
|
-
} else if (this.camera.isPerspectiveCamera) {
|
1642
|
-
state = JSON.stringify({
|
1858
|
+
} : {
|
1643
1859
|
arcballState: {
|
1644
1860
|
cameraFar: this.camera.far,
|
1645
1861
|
cameraFov: this.camera.fov,
|
@@ -1650,9 +1866,8 @@ class ArcballControls extends EventDispatcher {
|
|
1650
1866
|
gizmoMatrix: this._gizmos.matrix
|
1651
1867
|
}
|
1652
1868
|
});
|
1869
|
+
navigator.clipboard.writeText(state);
|
1653
1870
|
}
|
1654
|
-
|
1655
|
-
navigator.clipboard.writeText(state);
|
1656
1871
|
});
|
1657
1872
|
|
1658
1873
|
_defineProperty(this, "pasteState", () => {
|
@@ -1663,6 +1878,8 @@ class ArcballControls extends EventDispatcher {
|
|
1663
1878
|
});
|
1664
1879
|
|
1665
1880
|
_defineProperty(this, "saveState", () => {
|
1881
|
+
if (!this.camera) return;
|
1882
|
+
|
1666
1883
|
this._cameraMatrixState0.copy(this.camera.matrix);
|
1667
1884
|
|
1668
1885
|
this._gizmoMatrixState0.copy(this._gizmos.matrix);
|
@@ -1673,16 +1890,17 @@ class ArcballControls extends EventDispatcher {
|
|
1673
1890
|
|
1674
1891
|
this._up0.copy(this.camera.up);
|
1675
1892
|
|
1676
|
-
if (this.camera.
|
1893
|
+
if (this.camera.type === 'PerspectiveCamera') {
|
1677
1894
|
this._fov0 = this.camera.fov;
|
1678
1895
|
}
|
1679
1896
|
});
|
1680
1897
|
|
1681
1898
|
_defineProperty(this, "applyScale", (size, point, scaleGizmos = true) => {
|
1899
|
+
if (!this.camera) return;
|
1682
1900
|
const scalePoint = point.clone();
|
1683
1901
|
let sizeInverse = 1 / size;
|
1684
1902
|
|
1685
|
-
if (this.camera.
|
1903
|
+
if (this.camera.type === 'OrthographicCamera') {
|
1686
1904
|
//camera zoom
|
1687
1905
|
this.camera.zoom = this._zoomState;
|
1688
1906
|
this.camera.zoom *= size; //check min and max zoom
|
@@ -1720,7 +1938,9 @@ class ArcballControls extends EventDispatcher {
|
|
1720
1938
|
|
1721
1939
|
this.setTransformationMatrices(this._m4_1, this._m4_2);
|
1722
1940
|
return _transformation;
|
1723
|
-
}
|
1941
|
+
}
|
1942
|
+
|
1943
|
+
if (this.camera.type === 'PerspectiveCamera') {
|
1724
1944
|
this._v3_1.setFromMatrixPosition(this._cameraMatrixState);
|
1725
1945
|
|
1726
1946
|
this._v3_2.setFromMatrixPosition(this._gizmoMatrixState); //move camera
|
@@ -1773,12 +1993,32 @@ class ArcballControls extends EventDispatcher {
|
|
1773
1993
|
});
|
1774
1994
|
|
1775
1995
|
_defineProperty(this, "setFov", value => {
|
1776
|
-
|
1996
|
+
var _this$camera13;
|
1997
|
+
|
1998
|
+
if (((_this$camera13 = this.camera) === null || _this$camera13 === void 0 ? void 0 : _this$camera13.type) === 'PerspectiveCamera') {
|
1777
1999
|
this.camera.fov = MathUtils.clamp(value, this.minFov, this.maxFov);
|
1778
2000
|
this.camera.updateProjectionMatrix();
|
1779
2001
|
}
|
1780
2002
|
});
|
1781
2003
|
|
2004
|
+
_defineProperty(this, "setTarget", (x, y, z) => {
|
2005
|
+
if (this.camera) {
|
2006
|
+
this.target.set(x, y, z);
|
2007
|
+
|
2008
|
+
this._gizmos.position.set(x, y, z); //for correct radius calculation
|
2009
|
+
|
2010
|
+
|
2011
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
2012
|
+
|
2013
|
+
if (tbRadius !== undefined) {
|
2014
|
+
this._tbRadius = tbRadius;
|
2015
|
+
}
|
2016
|
+
|
2017
|
+
this.makeGizmos(this.target, this._tbRadius);
|
2018
|
+
this.camera.lookAt(this.target);
|
2019
|
+
}
|
2020
|
+
});
|
2021
|
+
|
1782
2022
|
_defineProperty(this, "zRotate", (point, angle) => {
|
1783
2023
|
this._rotationMatrix.makeRotationAxis(this._rotationAxis, angle);
|
1784
2024
|
|
@@ -1805,6 +2045,7 @@ class ArcballControls extends EventDispatcher {
|
|
1805
2045
|
});
|
1806
2046
|
|
1807
2047
|
_defineProperty(this, "unprojectOnObj", (cursor, camera) => {
|
2048
|
+
if (!this.scene) return null;
|
1808
2049
|
const raycaster = new Raycaster();
|
1809
2050
|
raycaster.near = camera.near;
|
1810
2051
|
raycaster.far = camera.far;
|
@@ -1812,7 +2053,7 @@ class ArcballControls extends EventDispatcher {
|
|
1812
2053
|
const intersect = raycaster.intersectObjects(this.scene.children, true);
|
1813
2054
|
|
1814
2055
|
for (let i = 0; i < intersect.length; i++) {
|
1815
|
-
if (intersect[i].object.uuid != this._gizmos.uuid && intersect[i].face
|
2056
|
+
if (intersect[i].object.uuid != this._gizmos.uuid && intersect[i].face) {
|
1816
2057
|
return intersect[i].point.clone();
|
1817
2058
|
}
|
1818
2059
|
}
|
@@ -1839,7 +2080,9 @@ class ArcballControls extends EventDispatcher {
|
|
1839
2080
|
}
|
1840
2081
|
|
1841
2082
|
return this._v3_1;
|
1842
|
-
}
|
2083
|
+
}
|
2084
|
+
|
2085
|
+
if (camera.type == 'PerspectiveCamera') {
|
1843
2086
|
//unproject cursor on the near plane
|
1844
2087
|
this._v2_1.copy(this.getCursorNDC(cursorX, cursorY, canvas));
|
1845
2088
|
|
@@ -1934,7 +2177,9 @@ class ArcballControls extends EventDispatcher {
|
|
1934
2177
|
this._v3_1.set(this._v2_1.x, this._v2_1.y, 0);
|
1935
2178
|
|
1936
2179
|
return this._v3_1.clone();
|
1937
|
-
}
|
2180
|
+
}
|
2181
|
+
|
2182
|
+
if (camera.type == 'PerspectiveCamera') {
|
1938
2183
|
this._v2_1.copy(this.getCursorNDC(cursorX, cursorY, canvas)); //unproject cursor on the near plane
|
1939
2184
|
|
1940
2185
|
|
@@ -1989,17 +2234,20 @@ class ArcballControls extends EventDispatcher {
|
|
1989
2234
|
});
|
1990
2235
|
|
1991
2236
|
_defineProperty(this, "updateMatrixState", () => {
|
1992
|
-
//update camera and gizmos state
|
2237
|
+
if (!this.camera) return; //update camera and gizmos state
|
2238
|
+
|
1993
2239
|
this._cameraMatrixState.copy(this.camera.matrix);
|
1994
2240
|
|
1995
2241
|
this._gizmoMatrixState.copy(this._gizmos.matrix);
|
1996
2242
|
|
1997
|
-
if (this.camera.
|
2243
|
+
if (this.camera.type === 'OrthographicCamera') {
|
1998
2244
|
this._cameraProjectionState.copy(this.camera.projectionMatrix);
|
1999
2245
|
|
2000
2246
|
this.camera.updateProjectionMatrix();
|
2001
2247
|
this._zoomState = this.camera.zoom;
|
2002
|
-
}
|
2248
|
+
}
|
2249
|
+
|
2250
|
+
if (this.camera.type === 'PerspectiveCamera') {
|
2003
2251
|
this._fovState = this.camera.fov;
|
2004
2252
|
}
|
2005
2253
|
});
|
@@ -2015,24 +2263,32 @@ class ArcballControls extends EventDispatcher {
|
|
2015
2263
|
_defineProperty(this, "update", () => {
|
2016
2264
|
const EPS = 0.000001; // Update target and gizmos state
|
2017
2265
|
|
2018
|
-
if (!this.target.equals(this._currentTarget)) {
|
2266
|
+
if (!this.target.equals(this._currentTarget) && this.camera) {
|
2019
2267
|
this._gizmos.position.set(this.target.x, this.target.y, this.target.z); //for correct radius calculation
|
2020
2268
|
|
2021
2269
|
|
2022
|
-
|
2270
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
2271
|
+
|
2272
|
+
if (tbRadius !== undefined) {
|
2273
|
+
this._tbRadius = tbRadius;
|
2274
|
+
}
|
2275
|
+
|
2023
2276
|
this.makeGizmos(this.target, this._tbRadius);
|
2024
2277
|
|
2025
2278
|
this._currentTarget.copy(this.target);
|
2026
|
-
}
|
2279
|
+
}
|
2027
2280
|
|
2281
|
+
if (!this.camera) return; //check min/max parameters
|
2028
2282
|
|
2029
|
-
if (this.camera.
|
2283
|
+
if (this.camera.type === 'OrthographicCamera') {
|
2030
2284
|
//check zoom
|
2031
2285
|
if (this.camera.zoom > this.maxZoom || this.camera.zoom < this.minZoom) {
|
2032
2286
|
const newZoom = MathUtils.clamp(this.camera.zoom, this.minZoom, this.maxZoom);
|
2033
2287
|
this.applyTransformMatrix(this.applyScale(newZoom / this.camera.zoom, this._gizmos.position, true));
|
2034
2288
|
}
|
2035
|
-
}
|
2289
|
+
}
|
2290
|
+
|
2291
|
+
if (this.camera.type === 'PerspectiveCamera') {
|
2036
2292
|
//check distance
|
2037
2293
|
const distance = this.camera.position.distanceTo(this._gizmos.position);
|
2038
2294
|
|
@@ -2049,17 +2305,23 @@ class ArcballControls extends EventDispatcher {
|
|
2049
2305
|
}
|
2050
2306
|
|
2051
2307
|
const oldRadius = this._tbRadius;
|
2052
|
-
|
2308
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
2309
|
+
|
2310
|
+
if (tbRadius !== undefined) {
|
2311
|
+
this._tbRadius = tbRadius;
|
2312
|
+
}
|
2053
2313
|
|
2054
2314
|
if (oldRadius < this._tbRadius - EPS || oldRadius > this._tbRadius + EPS) {
|
2055
2315
|
const scale = (this._gizmos.scale.x + this._gizmos.scale.y + this._gizmos.scale.z) / 3;
|
2056
|
-
const newRadius = this._tbRadius / scale;
|
2316
|
+
const newRadius = this._tbRadius / scale; // @ts-expect-error
|
2317
|
+
|
2057
2318
|
const curve = new EllipseCurve(0, 0, newRadius, newRadius);
|
2058
2319
|
const points = curve.getPoints(this._curvePts);
|
2059
2320
|
const curveGeometry = new BufferGeometry().setFromPoints(points);
|
2060
2321
|
|
2061
2322
|
for (const gizmo in this._gizmos.children) {
|
2062
|
-
this._gizmos.children[gizmo]
|
2323
|
+
const child = this._gizmos.children[gizmo];
|
2324
|
+
child.geometry = curveGeometry;
|
2063
2325
|
}
|
2064
2326
|
}
|
2065
2327
|
}
|
@@ -2070,7 +2332,7 @@ class ArcballControls extends EventDispatcher {
|
|
2070
2332
|
_defineProperty(this, "setStateFromJSON", json => {
|
2071
2333
|
const state = JSON.parse(json);
|
2072
2334
|
|
2073
|
-
if (state.arcballState
|
2335
|
+
if (state.arcballState && this.camera) {
|
2074
2336
|
this._cameraMatrixState.fromArray(state.arcballState.cameraMatrix.elements);
|
2075
2337
|
|
2076
2338
|
this._cameraMatrixState.decompose(this.camera.position, this.camera.quaternion, this.camera.scale);
|
@@ -2080,7 +2342,7 @@ class ArcballControls extends EventDispatcher {
|
|
2080
2342
|
this.camera.far = state.arcballState.cameraFar;
|
2081
2343
|
this.camera.zoom = state.arcballState.cameraZoom;
|
2082
2344
|
|
2083
|
-
if (this.camera.
|
2345
|
+
if (this.camera.type === 'PerspectiveCamera') {
|
2084
2346
|
this.camera.fov = state.arcballState.cameraFov;
|
2085
2347
|
}
|
2086
2348
|
|
@@ -2093,7 +2355,12 @@ class ArcballControls extends EventDispatcher {
|
|
2093
2355
|
|
2094
2356
|
this._gizmos.updateMatrix();
|
2095
2357
|
|
2096
|
-
|
2358
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
2359
|
+
|
2360
|
+
if (tbRadius !== undefined) {
|
2361
|
+
this._tbRadius = tbRadius;
|
2362
|
+
}
|
2363
|
+
|
2097
2364
|
const gizmoTmp = new Matrix4().copy(this._gizmoMatrixState0);
|
2098
2365
|
this.makeGizmos(this._gizmos.position, this._tbRadius);
|
2099
2366
|
|
@@ -2106,6 +2373,7 @@ class ArcballControls extends EventDispatcher {
|
|
2106
2373
|
});
|
2107
2374
|
|
2108
2375
|
this.camera = null;
|
2376
|
+
this.domElement = _domElement;
|
2109
2377
|
this.scene = scene;
|
2110
2378
|
this.mouseActions = [];
|
2111
2379
|
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 +2431,6 @@ class ArcballControls extends EventDispatcher {
|
|
2163
2431
|
this._downValid = true;
|
2164
2432
|
this._nclicks = 0;
|
2165
2433
|
this._downEvents = [];
|
2166
|
-
this._downStart = 0; //pointerDown time
|
2167
|
-
|
2168
2434
|
this._clickStart = 0; //first click time
|
2169
2435
|
|
2170
2436
|
this._maxDownTime = 250;
|
@@ -2224,7 +2490,6 @@ class ArcballControls extends EventDispatcher {
|
|
2224
2490
|
this.enablePan = true;
|
2225
2491
|
this.enableRotate = true;
|
2226
2492
|
this.enableZoom = true;
|
2227
|
-
this.enableGizmos = true;
|
2228
2493
|
this.minDistance = 0;
|
2229
2494
|
this.maxDistance = Infinity;
|
2230
2495
|
this.minZoom = 0;
|
@@ -2237,14 +2502,14 @@ class ArcballControls extends EventDispatcher {
|
|
2237
2502
|
this._state = STATE.IDLE;
|
2238
2503
|
this.setCamera(_camera);
|
2239
2504
|
|
2240
|
-
if (this.scene
|
2505
|
+
if (this.scene) {
|
2241
2506
|
this.scene.add(this._gizmos);
|
2242
|
-
}
|
2243
|
-
|
2507
|
+
}
|
2244
2508
|
|
2245
|
-
if (_domElement !== undefined) this.connect(_domElement);
|
2246
2509
|
this._devPxRatio = window.devicePixelRatio;
|
2247
2510
|
this.initializeMouseActions();
|
2511
|
+
if (this.domElement) this.connect(this.domElement);
|
2512
|
+
window.addEventListener('resize', this.onWindowResize);
|
2248
2513
|
} //listeners
|
2249
2514
|
|
2250
2515
|
|
@@ -2253,7 +2518,7 @@ class ArcballControls extends EventDispatcher {
|
|
2253
2518
|
* @param {Object} transformation Object containing matrices to apply to camera and gizmos
|
2254
2519
|
*/
|
2255
2520
|
applyTransformMatrix(transformation) {
|
2256
|
-
if (transformation.camera
|
2521
|
+
if (transformation !== null && transformation !== void 0 && transformation.camera && this.camera) {
|
2257
2522
|
this._m4_1.copy(this._cameraMatrixState).premultiply(transformation.camera);
|
2258
2523
|
|
2259
2524
|
this._m4_1.decompose(this.camera.position, this.camera.quaternion, this.camera.scale);
|
@@ -2265,7 +2530,7 @@ class ArcballControls extends EventDispatcher {
|
|
2265
2530
|
}
|
2266
2531
|
}
|
2267
2532
|
|
2268
|
-
if (transformation
|
2533
|
+
if (transformation !== null && transformation !== void 0 && transformation.gizmos) {
|
2269
2534
|
this._m4_1.copy(this._gizmoMatrixState).premultiply(transformation.gizmos);
|
2270
2535
|
|
2271
2536
|
this._m4_1.decompose(this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale);
|
@@ -2273,8 +2538,12 @@ class ArcballControls extends EventDispatcher {
|
|
2273
2538
|
this._gizmos.updateMatrix();
|
2274
2539
|
}
|
2275
2540
|
|
2276
|
-
if (this._state == STATE.SCALE || this._state == STATE.FOCUS || this._state == STATE.ANIMATION_FOCUS) {
|
2277
|
-
|
2541
|
+
if ((this._state == STATE.SCALE || this._state == STATE.FOCUS || this._state == STATE.ANIMATION_FOCUS) && this.camera) {
|
2542
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
2543
|
+
|
2544
|
+
if (tbRadius !== undefined) {
|
2545
|
+
this._tbRadius = tbRadius;
|
2546
|
+
}
|
2278
2547
|
|
2279
2548
|
if (this.adjustNearFar) {
|
2280
2549
|
const cameraDistance = this.camera.position.distanceTo(this._gizmos.position);
|
@@ -2340,8 +2609,8 @@ class ArcballControls extends EventDispatcher {
|
|
2340
2609
|
* @param {Matrix4} gizmos Transformation to be applied to gizmos
|
2341
2610
|
*/
|
2342
2611
|
setTransformationMatrices(camera = null, gizmos = null) {
|
2343
|
-
if (camera
|
2344
|
-
if (_transformation.camera
|
2612
|
+
if (camera) {
|
2613
|
+
if (_transformation.camera) {
|
2345
2614
|
_transformation.camera.copy(camera);
|
2346
2615
|
} else {
|
2347
2616
|
_transformation.camera = camera.clone();
|
@@ -2350,8 +2619,8 @@ class ArcballControls extends EventDispatcher {
|
|
2350
2619
|
_transformation.camera = null;
|
2351
2620
|
}
|
2352
2621
|
|
2353
|
-
if (gizmos
|
2354
|
-
if (_transformation.gizmos
|
2622
|
+
if (gizmos) {
|
2623
|
+
if (_transformation.gizmos) {
|
2355
2624
|
_transformation.gizmos.copy(gizmos);
|
2356
2625
|
} else {
|
2357
2626
|
_transformation.gizmos = gizmos.clone();
|