three-stdlib 2.6.4 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- package/controls/ArcballControls.cjs.js +1 -1
- package/controls/ArcballControls.d.ts +164 -0
- package/controls/ArcballControls.js +512 -197
- package/controls/OrbitControls.cjs.js +1 -1
- package/controls/OrbitControls.d.ts +1 -0
- package/controls/OrbitControls.js +13 -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/FontLoader.cjs.js +1 -0
- package/loaders/FontLoader.d.ts +32 -0
- package/loaders/FontLoader.js +139 -0
- package/package.json +1 -1
@@ -1,6 +1,7 @@
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
2
|
-
import { Matrix4, EventDispatcher, EllipseCurve, BufferGeometry, MathUtils, Vector3, GridHelper, LineBasicMaterial, Line, Raycaster, Vector2, Quaternion, Group, Box3, Sphere } from 'three';
|
2
|
+
import { Matrix4, EventDispatcher, EllipseCurve, BufferGeometry, Mesh, PerspectiveCamera, MathUtils, OrthographicCamera, 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(),
|
@@ -49,19 +50,212 @@ const _endEvent = {
|
|
49
50
|
*/
|
50
51
|
|
51
52
|
class ArcballControls extends EventDispatcher {
|
52
|
-
constructor(_camera,
|
53
|
+
constructor(_camera, domElement, 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, "_downStart", void 0);
|
147
|
+
|
148
|
+
_defineProperty(this, "_clickStart", void 0);
|
149
|
+
|
150
|
+
_defineProperty(this, "_maxDownTime", void 0);
|
151
|
+
|
152
|
+
_defineProperty(this, "_maxInterval", void 0);
|
153
|
+
|
154
|
+
_defineProperty(this, "_posThreshold", void 0);
|
155
|
+
|
156
|
+
_defineProperty(this, "_movementThreshold", void 0);
|
157
|
+
|
158
|
+
_defineProperty(this, "_currentCursorPosition", void 0);
|
159
|
+
|
160
|
+
_defineProperty(this, "_startCursorPosition", void 0);
|
161
|
+
|
162
|
+
_defineProperty(this, "_grid", void 0);
|
163
|
+
|
164
|
+
_defineProperty(this, "_gridPosition", void 0);
|
165
|
+
|
166
|
+
_defineProperty(this, "_gizmos", void 0);
|
167
|
+
|
168
|
+
_defineProperty(this, "_curvePts", void 0);
|
169
|
+
|
170
|
+
_defineProperty(this, "_timeStart", void 0);
|
171
|
+
|
172
|
+
_defineProperty(this, "_animationId", void 0);
|
173
|
+
|
174
|
+
_defineProperty(this, "focusAnimationTime", void 0);
|
175
|
+
|
176
|
+
_defineProperty(this, "_timePrev", void 0);
|
177
|
+
|
178
|
+
_defineProperty(this, "_timeCurrent", void 0);
|
179
|
+
|
180
|
+
_defineProperty(this, "_anglePrev", void 0);
|
181
|
+
|
182
|
+
_defineProperty(this, "_angleCurrent", void 0);
|
183
|
+
|
184
|
+
_defineProperty(this, "_cursorPosPrev", void 0);
|
185
|
+
|
186
|
+
_defineProperty(this, "_cursorPosCurr", void 0);
|
187
|
+
|
188
|
+
_defineProperty(this, "_wPrev", void 0);
|
189
|
+
|
190
|
+
_defineProperty(this, "_wCurr", void 0);
|
191
|
+
|
192
|
+
_defineProperty(this, "adjustNearFar", void 0);
|
193
|
+
|
194
|
+
_defineProperty(this, "scaleFactor", void 0);
|
195
|
+
|
196
|
+
_defineProperty(this, "dampingFactor", void 0);
|
197
|
+
|
198
|
+
_defineProperty(this, "wMax", void 0);
|
199
|
+
|
200
|
+
_defineProperty(this, "enableAnimations", void 0);
|
201
|
+
|
202
|
+
_defineProperty(this, "enableGrid", void 0);
|
203
|
+
|
204
|
+
_defineProperty(this, "cursorZoom", void 0);
|
205
|
+
|
206
|
+
_defineProperty(this, "minFov", void 0);
|
207
|
+
|
208
|
+
_defineProperty(this, "maxFov", void 0);
|
209
|
+
|
210
|
+
_defineProperty(this, "enabled", void 0);
|
211
|
+
|
212
|
+
_defineProperty(this, "enablePan", void 0);
|
213
|
+
|
214
|
+
_defineProperty(this, "enableRotate", void 0);
|
215
|
+
|
216
|
+
_defineProperty(this, "enableZoom", void 0);
|
217
|
+
|
218
|
+
_defineProperty(this, "enableGizmos", void 0);
|
219
|
+
|
220
|
+
_defineProperty(this, "minDistance", void 0);
|
221
|
+
|
222
|
+
_defineProperty(this, "maxDistance", void 0);
|
223
|
+
|
224
|
+
_defineProperty(this, "minZoom", void 0);
|
225
|
+
|
226
|
+
_defineProperty(this, "maxZoom", void 0);
|
227
|
+
|
228
|
+
_defineProperty(this, "target", void 0);
|
229
|
+
|
230
|
+
_defineProperty(this, "_currentTarget", void 0);
|
231
|
+
|
232
|
+
_defineProperty(this, "_tbRadius", void 0);
|
233
|
+
|
234
|
+
_defineProperty(this, "_state", void 0);
|
235
|
+
|
55
236
|
_defineProperty(this, "onWindowResize", () => {
|
56
237
|
const scale = (this._gizmos.scale.x + this._gizmos.scale.y + this._gizmos.scale.z) / 3;
|
57
|
-
|
58
|
-
|
238
|
+
|
239
|
+
if (this.camera !== null) {
|
240
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
241
|
+
|
242
|
+
if (tbRadius !== undefined) {
|
243
|
+
this._tbRadius = tbRadius;
|
244
|
+
}
|
245
|
+
}
|
246
|
+
|
247
|
+
const newRadius = this._tbRadius / scale; // @ts-expect-error
|
248
|
+
|
59
249
|
const curve = new EllipseCurve(0, 0, newRadius, newRadius);
|
60
250
|
const points = curve.getPoints(this._curvePts);
|
61
251
|
const curveGeometry = new BufferGeometry().setFromPoints(points);
|
62
252
|
|
63
253
|
for (const gizmo in this._gizmos.children) {
|
64
|
-
this._gizmos.children[gizmo]
|
254
|
+
const child = this._gizmos.children[gizmo];
|
255
|
+
|
256
|
+
if (child instanceof Mesh) {
|
257
|
+
child.geometry = curveGeometry;
|
258
|
+
}
|
65
259
|
}
|
66
260
|
|
67
261
|
this.dispatchEvent(_changeEvent);
|
@@ -126,7 +320,7 @@ class ArcballControls extends EventDispatcher {
|
|
126
320
|
case INPUT.TWO_FINGER:
|
127
321
|
//multipleStart
|
128
322
|
this._input = INPUT.MULT_FINGER;
|
129
|
-
this.onTriplePanStart(
|
323
|
+
this.onTriplePanStart();
|
130
324
|
break;
|
131
325
|
}
|
132
326
|
} else if (event.pointerType != 'touch' && this._input == INPUT.NONE) {
|
@@ -184,7 +378,7 @@ class ArcballControls extends EventDispatcher {
|
|
184
378
|
case INPUT.MULT_FINGER:
|
185
379
|
//multMove
|
186
380
|
this.updateTouchEvent(event);
|
187
|
-
this.onTriplePanMove(
|
381
|
+
this.onTriplePanMove();
|
188
382
|
break;
|
189
383
|
}
|
190
384
|
} else if (event.pointerType != 'touch' && this._input == INPUT.CURSOR) {
|
@@ -239,9 +433,9 @@ class ArcballControls extends EventDispatcher {
|
|
239
433
|
|
240
434
|
case INPUT.TWO_FINGER:
|
241
435
|
//doubleEnd
|
242
|
-
this.onDoublePanEnd(
|
243
|
-
this.onPinchEnd(
|
244
|
-
this.onRotateEnd(
|
436
|
+
this.onDoublePanEnd();
|
437
|
+
this.onPinchEnd();
|
438
|
+
this.onRotateEnd(); //switching to singleStart
|
245
439
|
|
246
440
|
this._input = INPUT.ONE_FINGER_SWITCHED;
|
247
441
|
break;
|
@@ -349,13 +543,17 @@ class ArcballControls extends EventDispatcher {
|
|
349
543
|
if (this.cursorZoom && this.enablePan) {
|
350
544
|
let scalePoint;
|
351
545
|
|
352
|
-
if (this.camera.isOrthographicCamera) {
|
353
|
-
|
354
|
-
|
355
|
-
scalePoint = this.unprojectOnTbPlane(this.camera, event.clientX, event.clientY, this.domElement).applyQuaternion(this.camera.quaternion).add(this._gizmos.position);
|
546
|
+
if (this.camera instanceof OrthographicCamera && this.camera.isOrthographicCamera) {
|
547
|
+
var _this$unprojectOnTbPl;
|
548
|
+
|
549
|
+
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);
|
550
|
+
} else if (this.camera instanceof PerspectiveCamera && this.camera.isPerspectiveCamera) {
|
551
|
+
var _this$unprojectOnTbPl2;
|
552
|
+
|
553
|
+
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
554
|
}
|
357
555
|
|
358
|
-
this.applyTransformMatrix(this.applyScale(size, scalePoint));
|
556
|
+
if (scalePoint !== undefined) this.applyTransformMatrix(this.applyScale(size, scalePoint));
|
359
557
|
} else {
|
360
558
|
this.applyTransformMatrix(this.applyScale(size, this._gizmos.position));
|
361
559
|
}
|
@@ -371,7 +569,7 @@ class ArcballControls extends EventDispatcher {
|
|
371
569
|
break;
|
372
570
|
|
373
571
|
case 'FOV':
|
374
|
-
if (this.camera.isPerspectiveCamera) {
|
572
|
+
if (this.camera instanceof PerspectiveCamera && this.camera.isPerspectiveCamera) {
|
375
573
|
this.updateTbState(STATE.FOV, true); //Vertigo effect
|
376
574
|
// fov / 2
|
377
575
|
// |\
|
@@ -464,13 +662,18 @@ class ArcballControls extends EventDispatcher {
|
|
464
662
|
this.dispatchEvent(_changeEvent);
|
465
663
|
}
|
466
664
|
|
467
|
-
this.
|
665
|
+
if (this.camera !== null) {
|
666
|
+
this.updateTbState(STATE.PAN, true);
|
667
|
+
const rayDir = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement);
|
468
668
|
|
469
|
-
|
669
|
+
if (rayDir !== undefined) {
|
670
|
+
this._startCursorPosition.copy(rayDir);
|
671
|
+
}
|
470
672
|
|
471
|
-
|
472
|
-
|
473
|
-
|
673
|
+
if (this.enableGrid) {
|
674
|
+
this.drawGrid();
|
675
|
+
this.dispatchEvent(_changeEvent);
|
676
|
+
}
|
474
677
|
}
|
475
678
|
|
476
679
|
break;
|
@@ -486,29 +689,34 @@ class ArcballControls extends EventDispatcher {
|
|
486
689
|
this._timeStart = -1;
|
487
690
|
}
|
488
691
|
|
489
|
-
this.
|
692
|
+
if (this.camera !== null) {
|
693
|
+
this.updateTbState(STATE.ROTATE, true);
|
694
|
+
const rayDir = this.unprojectOnTbSurface(this.camera, _center.x, _center.y, this.domElement, this._tbRadius);
|
490
695
|
|
491
|
-
|
696
|
+
if (rayDir !== undefined) {
|
697
|
+
this._startCursorPosition.copy(rayDir);
|
698
|
+
}
|
492
699
|
|
493
|
-
|
700
|
+
this.activateGizmos(true);
|
494
701
|
|
495
|
-
|
496
|
-
|
497
|
-
|
702
|
+
if (this.enableAnimations) {
|
703
|
+
this._timePrev = this._timeCurrent = performance.now();
|
704
|
+
this._angleCurrent = this._anglePrev = 0;
|
498
705
|
|
499
|
-
|
706
|
+
this._cursorPosPrev.copy(this._startCursorPosition);
|
500
707
|
|
501
|
-
|
708
|
+
this._cursorPosCurr.copy(this._cursorPosPrev);
|
502
709
|
|
503
|
-
|
504
|
-
|
710
|
+
this._wCurr = 0;
|
711
|
+
this._wPrev = this._wCurr;
|
712
|
+
}
|
505
713
|
}
|
506
714
|
|
507
715
|
this.dispatchEvent(_changeEvent);
|
508
716
|
break;
|
509
717
|
|
510
718
|
case 'FOV':
|
511
|
-
if (!this.camera.isPerspectiveCamera || !this.enableZoom) {
|
719
|
+
if (!(this.camera instanceof PerspectiveCamera && this.camera.isPerspectiveCamera) || !this.enableZoom) {
|
512
720
|
return;
|
513
721
|
}
|
514
722
|
|
@@ -559,14 +767,17 @@ class ArcballControls extends EventDispatcher {
|
|
559
767
|
|
560
768
|
switch (opState) {
|
561
769
|
case STATE.PAN:
|
562
|
-
if (this.enablePan) {
|
770
|
+
if (this.enablePan && this.camera !== null) {
|
563
771
|
if (restart) {
|
564
772
|
//switch to pan operation
|
565
773
|
this.dispatchEvent(_endEvent);
|
566
774
|
this.dispatchEvent(_startEvent);
|
567
775
|
this.updateTbState(opState, true);
|
776
|
+
const rayDir = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement);
|
568
777
|
|
569
|
-
|
778
|
+
if (rayDir !== undefined) {
|
779
|
+
this._startCursorPosition.copy(rayDir);
|
780
|
+
}
|
570
781
|
|
571
782
|
if (this.enableGrid) {
|
572
783
|
this.drawGrid();
|
@@ -575,7 +786,11 @@ class ArcballControls extends EventDispatcher {
|
|
575
786
|
this.activateGizmos(false);
|
576
787
|
} else {
|
577
788
|
//continue with pan operation
|
578
|
-
this.
|
789
|
+
const rayDir = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement);
|
790
|
+
|
791
|
+
if (rayDir !== undefined) {
|
792
|
+
this._currentCursorPosition.copy(rayDir);
|
793
|
+
}
|
579
794
|
|
580
795
|
this.applyTransformMatrix(this.pan(this._startCursorPosition, this._currentCursorPosition));
|
581
796
|
}
|
@@ -584,14 +799,17 @@ class ArcballControls extends EventDispatcher {
|
|
584
799
|
break;
|
585
800
|
|
586
801
|
case STATE.ROTATE:
|
587
|
-
if (this.enableRotate) {
|
802
|
+
if (this.enableRotate && this.camera !== null) {
|
588
803
|
if (restart) {
|
589
804
|
//switch to rotate operation
|
590
805
|
this.dispatchEvent(_endEvent);
|
591
806
|
this.dispatchEvent(_startEvent);
|
592
807
|
this.updateTbState(opState, true);
|
808
|
+
const rayDir = this.unprojectOnTbSurface(this.camera, _center.x, _center.y, this.domElement, this._tbRadius);
|
593
809
|
|
594
|
-
|
810
|
+
if (rayDir !== undefined) {
|
811
|
+
this._startCursorPosition.copy(rayDir);
|
812
|
+
}
|
595
813
|
|
596
814
|
if (this.enableGrid) {
|
597
815
|
this.disposeGrid();
|
@@ -600,7 +818,11 @@ class ArcballControls extends EventDispatcher {
|
|
600
818
|
this.activateGizmos(true);
|
601
819
|
} else {
|
602
820
|
//continue with rotate operation
|
603
|
-
this.
|
821
|
+
const rayDir = this.unprojectOnTbSurface(this.camera, _center.x, _center.y, this.domElement, this._tbRadius);
|
822
|
+
|
823
|
+
if (rayDir !== undefined) {
|
824
|
+
this._currentCursorPosition.copy(rayDir);
|
825
|
+
}
|
604
826
|
|
605
827
|
const distance = this._startCursorPosition.distanceTo(this._currentCursorPosition);
|
606
828
|
|
@@ -667,7 +889,7 @@ class ArcballControls extends EventDispatcher {
|
|
667
889
|
break;
|
668
890
|
|
669
891
|
case STATE.FOV:
|
670
|
-
if (this.enableZoom && this.camera.isPerspectiveCamera) {
|
892
|
+
if (this.enableZoom && this.camera instanceof PerspectiveCamera && this.camera.isPerspectiveCamera) {
|
671
893
|
if (restart) {
|
672
894
|
//switch to fov operation
|
673
895
|
this.dispatchEvent(_endEvent);
|
@@ -776,7 +998,7 @@ class ArcballControls extends EventDispatcher {
|
|
776
998
|
});
|
777
999
|
|
778
1000
|
_defineProperty(this, "onDoubleTap", event => {
|
779
|
-
if (this.enabled && this.enablePan && this.scene != null) {
|
1001
|
+
if (this.enabled && this.enablePan && this.scene != null && this.camera !== null) {
|
780
1002
|
this.dispatchEvent(_startEvent);
|
781
1003
|
this.setCenter(event.clientX, event.clientY);
|
782
1004
|
const hitP = this.unprojectOnObj(this.getCursorNDC(_center.x, _center.y, this.domElement), this.camera);
|
@@ -805,12 +1027,15 @@ class ArcballControls extends EventDispatcher {
|
|
805
1027
|
});
|
806
1028
|
|
807
1029
|
_defineProperty(this, "onDoublePanStart", () => {
|
808
|
-
if (this.enabled && this.enablePan) {
|
1030
|
+
if (this.enabled && this.enablePan && this.camera !== null) {
|
809
1031
|
this.dispatchEvent(_startEvent);
|
810
1032
|
this.updateTbState(STATE.PAN, true);
|
811
1033
|
this.setCenter((this._touchCurrent[0].clientX + this._touchCurrent[1].clientX) / 2, (this._touchCurrent[0].clientY + this._touchCurrent[1].clientY) / 2);
|
1034
|
+
const rayDir = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement, true);
|
812
1035
|
|
813
|
-
|
1036
|
+
if (rayDir !== undefined) {
|
1037
|
+
this._startCursorPosition.copy(rayDir);
|
1038
|
+
}
|
814
1039
|
|
815
1040
|
this._currentCursorPosition.copy(this._startCursorPosition);
|
816
1041
|
|
@@ -819,7 +1044,7 @@ class ArcballControls extends EventDispatcher {
|
|
819
1044
|
});
|
820
1045
|
|
821
1046
|
_defineProperty(this, "onDoublePanMove", () => {
|
822
|
-
if (this.enabled && this.enablePan) {
|
1047
|
+
if (this.enabled && this.enablePan && this.camera !== null) {
|
823
1048
|
this.setCenter((this._touchCurrent[0].clientX + this._touchCurrent[1].clientX) / 2, (this._touchCurrent[0].clientY + this._touchCurrent[1].clientY) / 2);
|
824
1049
|
|
825
1050
|
if (this._state != STATE.PAN) {
|
@@ -828,8 +1053,8 @@ class ArcballControls extends EventDispatcher {
|
|
828
1053
|
this._startCursorPosition.copy(this._currentCursorPosition);
|
829
1054
|
}
|
830
1055
|
|
831
|
-
this.
|
832
|
-
|
1056
|
+
const rayDir = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement, true);
|
1057
|
+
if (rayDir !== undefined) this._currentCursorPosition.copy(rayDir);
|
833
1058
|
this.applyTransformMatrix(this.pan(this._startCursorPosition, this._currentCursorPosition, true));
|
834
1059
|
this.dispatchEvent(_changeEvent);
|
835
1060
|
}
|
@@ -842,12 +1067,14 @@ class ArcballControls extends EventDispatcher {
|
|
842
1067
|
|
843
1068
|
_defineProperty(this, "onRotateStart", () => {
|
844
1069
|
if (this.enabled && this.enableRotate) {
|
1070
|
+
var _this$camera;
|
1071
|
+
|
845
1072
|
this.dispatchEvent(_startEvent);
|
846
1073
|
this.updateTbState(STATE.ZROTATE, true); //this._startFingerRotation = event.rotation;
|
847
1074
|
|
848
1075
|
this._startFingerRotation = this.getAngle(this._touchCurrent[1], this._touchCurrent[0]) + this.getAngle(this._touchStart[1], this._touchStart[0]);
|
849
1076
|
this._currentFingerRotation = this._startFingerRotation;
|
850
|
-
this.camera.getWorldDirection(this._rotationAxis); //rotation axis
|
1077
|
+
(_this$camera = this.camera) === null || _this$camera === void 0 ? void 0 : _this$camera.getWorldDirection(this._rotationAxis); //rotation axis
|
851
1078
|
|
852
1079
|
if (!this.enablePan && !this.enableZoom) {
|
853
1080
|
this.activateGizmos(true);
|
@@ -856,7 +1083,7 @@ class ArcballControls extends EventDispatcher {
|
|
856
1083
|
});
|
857
1084
|
|
858
1085
|
_defineProperty(this, "onRotateMove", () => {
|
859
|
-
if (this.enabled && this.enableRotate) {
|
1086
|
+
if (this.enabled && this.enableRotate && this.camera !== null) {
|
860
1087
|
this.setCenter((this._touchCurrent[0].clientX + this._touchCurrent[1].clientX) / 2, (this._touchCurrent[0].clientY + this._touchCurrent[1].clientY) / 2);
|
861
1088
|
let rotationPoint;
|
862
1089
|
|
@@ -870,14 +1097,20 @@ class ArcballControls extends EventDispatcher {
|
|
870
1097
|
|
871
1098
|
if (!this.enablePan) {
|
872
1099
|
rotationPoint = new Vector3().setFromMatrixPosition(this._gizmoMatrixState);
|
873
|
-
} else {
|
1100
|
+
} else if (this.camera instanceof PerspectiveCamera || this.camera instanceof OrthographicCamera) {
|
1101
|
+
var _this$unprojectOnTbPl3;
|
1102
|
+
|
874
1103
|
this._v3_2.setFromMatrixPosition(this._gizmoMatrixState);
|
875
1104
|
|
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);
|
1105
|
+
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
1106
|
}
|
878
1107
|
|
879
1108
|
const amount = MathUtils.DEG2RAD * (this._startFingerRotation - this._currentFingerRotation);
|
880
|
-
|
1109
|
+
|
1110
|
+
if (rotationPoint !== undefined) {
|
1111
|
+
this.applyTransformMatrix(this.zRotate(rotationPoint, amount));
|
1112
|
+
}
|
1113
|
+
|
881
1114
|
this.dispatchEvent(_changeEvent);
|
882
1115
|
}
|
883
1116
|
});
|
@@ -915,14 +1148,21 @@ class ArcballControls extends EventDispatcher {
|
|
915
1148
|
if (!this.enablePan) {
|
916
1149
|
scalePoint = this._gizmos.position;
|
917
1150
|
} else {
|
918
|
-
if (this.camera.isOrthographicCamera) {
|
919
|
-
|
920
|
-
|
921
|
-
scalePoint = this.unprojectOnTbPlane(this.camera, _center.x, _center.y, this.domElement).applyQuaternion(this.camera.quaternion).add(this._gizmos.position);
|
1151
|
+
if (this.camera instanceof OrthographicCamera && this.camera.isOrthographicCamera) {
|
1152
|
+
var _this$unprojectOnTbPl4;
|
1153
|
+
|
1154
|
+
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);
|
1155
|
+
} else if (this.camera instanceof PerspectiveCamera && this.camera.isPerspectiveCamera) {
|
1156
|
+
var _this$unprojectOnTbPl5;
|
1157
|
+
|
1158
|
+
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
1159
|
}
|
923
1160
|
}
|
924
1161
|
|
925
|
-
|
1162
|
+
if (scalePoint !== undefined) {
|
1163
|
+
this.applyTransformMatrix(this.applyScale(amount, scalePoint));
|
1164
|
+
}
|
1165
|
+
|
926
1166
|
this.dispatchEvent(_changeEvent);
|
927
1167
|
}
|
928
1168
|
});
|
@@ -955,7 +1195,7 @@ class ArcballControls extends EventDispatcher {
|
|
955
1195
|
});
|
956
1196
|
|
957
1197
|
_defineProperty(this, "onTriplePanMove", () => {
|
958
|
-
if (this.enabled && this.enableZoom) {
|
1198
|
+
if (this.enabled && this.enableZoom && this.camera !== null) {
|
959
1199
|
// fov / 2
|
960
1200
|
// |\
|
961
1201
|
// | \
|
@@ -1206,44 +1446,46 @@ class ArcballControls extends EventDispatcher {
|
|
1206
1446
|
const factor = 0.67;
|
1207
1447
|
const distance = camera.position.distanceTo(this._gizmos.position);
|
1208
1448
|
|
1209
|
-
if (camera.type == 'PerspectiveCamera') {
|
1449
|
+
if (camera.type == 'PerspectiveCamera' && camera instanceof PerspectiveCamera) {
|
1210
1450
|
const halfFovV = MathUtils.DEG2RAD * camera.fov * 0.5; //vertical fov/2 in radians
|
1211
1451
|
|
1212
1452
|
const halfFovH = Math.atan(camera.aspect * Math.tan(halfFovV)); //horizontal fov/2 in radians
|
1213
1453
|
|
1214
1454
|
return Math.tan(Math.min(halfFovV, halfFovH)) * distance * factor;
|
1215
|
-
} else if (camera.type == 'OrthographicCamera') {
|
1455
|
+
} else if (camera.type == 'OrthographicCamera' && camera instanceof OrthographicCamera) {
|
1216
1456
|
return Math.min(camera.top, camera.right) * factor;
|
1217
1457
|
}
|
1218
1458
|
});
|
1219
1459
|
|
1220
1460
|
_defineProperty(this, "focus", (point, size, amount = 1) => {
|
1221
|
-
|
1461
|
+
if (this.camera !== null) {
|
1462
|
+
const focusPoint = point.clone(); //move center of camera (along with gizmos) towards point of interest
|
1222
1463
|
|
1223
|
-
|
1464
|
+
focusPoint.sub(this._gizmos.position).multiplyScalar(amount);
|
1224
1465
|
|
1225
|
-
|
1466
|
+
this._translationMatrix.makeTranslation(focusPoint.x, focusPoint.y, focusPoint.z);
|
1226
1467
|
|
1227
|
-
|
1468
|
+
const gizmoStateTemp = this._gizmoMatrixState.clone();
|
1228
1469
|
|
1229
|
-
|
1470
|
+
this._gizmoMatrixState.premultiply(this._translationMatrix);
|
1230
1471
|
|
1231
|
-
|
1472
|
+
this._gizmoMatrixState.decompose(this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale);
|
1232
1473
|
|
1233
|
-
|
1474
|
+
const cameraStateTemp = this._cameraMatrixState.clone();
|
1234
1475
|
|
1235
|
-
|
1476
|
+
this._cameraMatrixState.premultiply(this._translationMatrix);
|
1236
1477
|
|
1237
|
-
|
1478
|
+
this._cameraMatrixState.decompose(this.camera.position, this.camera.quaternion, this.camera.scale); //apply zoom
|
1238
1479
|
|
1239
1480
|
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1481
|
+
if (this.enableZoom) {
|
1482
|
+
this.applyTransformMatrix(this.applyScale(size, this._gizmos.position));
|
1483
|
+
}
|
1243
1484
|
|
1244
|
-
|
1485
|
+
this._gizmoMatrixState.copy(gizmoStateTemp);
|
1245
1486
|
|
1246
|
-
|
1487
|
+
this._cameraMatrixState.copy(cameraStateTemp);
|
1488
|
+
}
|
1247
1489
|
});
|
1248
1490
|
|
1249
1491
|
_defineProperty(this, "drawGrid", () => {
|
@@ -1252,14 +1494,14 @@ class ArcballControls extends EventDispatcher {
|
|
1252
1494
|
const multiplier = 3;
|
1253
1495
|
let size, divisions, maxLength, tick;
|
1254
1496
|
|
1255
|
-
if (this.camera.isOrthographicCamera) {
|
1497
|
+
if (this.camera instanceof OrthographicCamera && this.camera.isOrthographicCamera) {
|
1256
1498
|
const width = this.camera.right - this.camera.left;
|
1257
1499
|
const height = this.camera.bottom - this.camera.top;
|
1258
1500
|
maxLength = Math.max(width, height);
|
1259
1501
|
tick = maxLength / 20;
|
1260
1502
|
size = maxLength / this.camera.zoom * multiplier;
|
1261
1503
|
divisions = size / tick * this.camera.zoom;
|
1262
|
-
} else if (this.camera.isPerspectiveCamera) {
|
1504
|
+
} else if (this.camera instanceof PerspectiveCamera && this.camera.isPerspectiveCamera) {
|
1263
1505
|
const distance = this.camera.position.distanceTo(this._gizmos.position);
|
1264
1506
|
const halfFovV = MathUtils.DEG2RAD * this.camera.fov * 0.5;
|
1265
1507
|
const halfFovH = Math.atan(this.camera.aspect * Math.tan(halfFovV));
|
@@ -1269,7 +1511,7 @@ class ArcballControls extends EventDispatcher {
|
|
1269
1511
|
divisions = size / tick;
|
1270
1512
|
}
|
1271
1513
|
|
1272
|
-
if (this._grid == null) {
|
1514
|
+
if (this._grid == null && this.camera !== null) {
|
1273
1515
|
this._grid = new GridHelper(size, divisions, color, color);
|
1274
1516
|
|
1275
1517
|
this._grid.position.copy(this._gizmos.position);
|
@@ -1285,18 +1527,9 @@ class ArcballControls extends EventDispatcher {
|
|
1285
1527
|
}
|
1286
1528
|
});
|
1287
1529
|
|
1288
|
-
_defineProperty(this, "connect", domElement => {
|
1289
|
-
this.domElement = domElement;
|
1290
|
-
this.domElement.style.touchAction = 'none';
|
1291
|
-
this.domElement.addEventListener('contextmenu', this.onContextMenu);
|
1292
|
-
this.domElement.addEventListener('wheel', this.onWheel);
|
1293
|
-
this.domElement.addEventListener('pointerdown', this.onPointerDown);
|
1294
|
-
this.domElement.addEventListener('pointercancel', this.onPointerCancel);
|
1295
|
-
window.addEventListener('keydown', this.onKeyDown);
|
1296
|
-
window.addEventListener('resize', this.onWindowResize);
|
1297
|
-
});
|
1298
|
-
|
1299
1530
|
_defineProperty(this, "dispose", () => {
|
1531
|
+
var _this$scene;
|
1532
|
+
|
1300
1533
|
if (this._animationId != -1) {
|
1301
1534
|
window.cancelAnimationFrame(this._animationId);
|
1302
1535
|
}
|
@@ -1308,8 +1541,8 @@ class ArcballControls extends EventDispatcher {
|
|
1308
1541
|
window.removeEventListener('pointermove', this.onPointerMove);
|
1309
1542
|
window.removeEventListener('pointerup', this.onPointerUp);
|
1310
1543
|
window.removeEventListener('resize', this.onWindowResize);
|
1311
|
-
window.
|
1312
|
-
|
1544
|
+
window.addEventListener('keydown', this.onKeyDown);
|
1545
|
+
(_this$scene = this.scene) === null || _this$scene === void 0 ? void 0 : _this$scene.remove(this._gizmos);
|
1313
1546
|
this.disposeGrid();
|
1314
1547
|
});
|
1315
1548
|
|
@@ -1365,47 +1598,62 @@ class ArcballControls extends EventDispatcher {
|
|
1365
1598
|
_defineProperty(this, "getCursorPosition", (cursorX, cursorY, canvas) => {
|
1366
1599
|
this._v2_1.copy(this.getCursorNDC(cursorX, cursorY, canvas));
|
1367
1600
|
|
1368
|
-
|
1369
|
-
|
1601
|
+
if (this.camera instanceof OrthographicCamera) {
|
1602
|
+
this._v2_1.x *= (this.camera.right - this.camera.left) * 0.5;
|
1603
|
+
this._v2_1.y *= (this.camera.top - this.camera.bottom) * 0.5;
|
1604
|
+
}
|
1605
|
+
|
1370
1606
|
return this._v2_1.clone();
|
1371
1607
|
});
|
1372
1608
|
|
1373
1609
|
_defineProperty(this, "setCamera", camera => {
|
1374
|
-
camera
|
1375
|
-
|
1610
|
+
if (camera instanceof PerspectiveCamera || camera instanceof OrthographicCamera) {
|
1611
|
+
camera.lookAt(this.target);
|
1612
|
+
camera.updateMatrix(); //setting state
|
1376
1613
|
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1614
|
+
if ((camera === null || camera === void 0 ? void 0 : camera.type) == 'PerspectiveCamera' && camera instanceof PerspectiveCamera) {
|
1615
|
+
this._fov0 = camera.fov;
|
1616
|
+
this._fovState = camera.fov;
|
1617
|
+
}
|
1381
1618
|
|
1382
|
-
|
1619
|
+
this._cameraMatrixState0.copy(camera.matrix);
|
1383
1620
|
|
1384
|
-
|
1621
|
+
this._cameraMatrixState.copy(this._cameraMatrixState0);
|
1385
1622
|
|
1386
|
-
|
1623
|
+
this._cameraProjectionState.copy(camera.projectionMatrix);
|
1387
1624
|
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1625
|
+
this._zoom0 = camera.zoom;
|
1626
|
+
this._zoomState = this._zoom0;
|
1627
|
+
this._initialNear = camera.near;
|
1628
|
+
this._nearPos0 = camera.position.distanceTo(this.target) - camera.near;
|
1629
|
+
this._nearPos = this._initialNear;
|
1630
|
+
this._initialFar = camera.far;
|
1631
|
+
this._farPos0 = camera.position.distanceTo(this.target) - camera.far;
|
1632
|
+
this._farPos = this._initialFar;
|
1396
1633
|
|
1397
|
-
|
1634
|
+
this._up0.copy(camera.up);
|
1398
1635
|
|
1399
|
-
|
1636
|
+
this._upState.copy(camera.up);
|
1400
1637
|
|
1401
|
-
|
1402
|
-
this.camera.updateProjectionMatrix(); //making gizmos
|
1638
|
+
this.camera = camera;
|
1403
1639
|
|
1404
|
-
|
1405
|
-
|
1640
|
+
if (this.camera instanceof PerspectiveCamera || this.camera instanceof OrthographicCamera) {
|
1641
|
+
this.camera.updateProjectionMatrix();
|
1642
|
+
} //making gizmos
|
1643
|
+
|
1644
|
+
|
1645
|
+
const tbRadius = this.calculateTbRadius(camera);
|
1646
|
+
|
1647
|
+
if (tbRadius !== undefined) {
|
1648
|
+
this._tbRadius = tbRadius;
|
1649
|
+
}
|
1650
|
+
|
1651
|
+
this.makeGizmos(this.target, this._tbRadius);
|
1652
|
+
}
|
1406
1653
|
});
|
1407
1654
|
|
1408
1655
|
_defineProperty(this, "makeGizmos", (tbCenter, tbRadius) => {
|
1656
|
+
// @ts-expect-error
|
1409
1657
|
const curve = new EllipseCurve(0, 0, tbRadius, tbRadius);
|
1410
1658
|
const points = curve.getPoints(this._curvePts); //geometry
|
1411
1659
|
|
@@ -1441,7 +1689,7 @@ class ArcballControls extends EventDispatcher {
|
|
1441
1689
|
|
1442
1690
|
this._gizmoMatrixState.copy(this._gizmoMatrixState0);
|
1443
1691
|
|
1444
|
-
if (this.camera.zoom != 1) {
|
1692
|
+
if ((this.camera instanceof PerspectiveCamera || this.camera instanceof OrthographicCamera) && this.camera.zoom != 1) {
|
1445
1693
|
//adapt gizmos size to camera zoom
|
1446
1694
|
const size = 1 / this.camera.zoom;
|
1447
1695
|
|
@@ -1550,60 +1798,70 @@ class ArcballControls extends EventDispatcher {
|
|
1550
1798
|
});
|
1551
1799
|
|
1552
1800
|
_defineProperty(this, "pan", (p0, p1, adjust = false) => {
|
1553
|
-
|
1801
|
+
if (this.camera !== null) {
|
1802
|
+
const movement = p0.clone().sub(p1);
|
1554
1803
|
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1804
|
+
if (this.camera instanceof OrthographicCamera && this.camera.isOrthographicCamera) {
|
1805
|
+
//adjust movement amount
|
1806
|
+
movement.multiplyScalar(1 / this.camera.zoom);
|
1807
|
+
} else if (this.camera instanceof PerspectiveCamera && this.camera.isPerspectiveCamera && adjust) {
|
1808
|
+
//adjust movement amount
|
1809
|
+
this._v3_1.setFromMatrixPosition(this._cameraMatrixState0); //camera's initial position
|
1561
1810
|
|
1562
1811
|
|
1563
|
-
|
1812
|
+
this._v3_2.setFromMatrixPosition(this._gizmoMatrixState0); //gizmo's initial position
|
1564
1813
|
|
1565
1814
|
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1815
|
+
const distanceFactor = this._v3_1.distanceTo(this._v3_2) / this.camera.position.distanceTo(this._gizmos.position);
|
1816
|
+
movement.multiplyScalar(1 / distanceFactor);
|
1817
|
+
}
|
1818
|
+
|
1819
|
+
this._v3_1.set(movement.x, movement.y, 0).applyQuaternion(this.camera.quaternion);
|
1569
1820
|
|
1570
|
-
|
1821
|
+
this._m4_1.makeTranslation(this._v3_1.x, this._v3_1.y, this._v3_1.z);
|
1571
1822
|
|
1572
|
-
|
1823
|
+
this.setTransformationMatrices(this._m4_1, this._m4_1);
|
1824
|
+
}
|
1573
1825
|
|
1574
|
-
this.setTransformationMatrices(this._m4_1, this._m4_1);
|
1575
1826
|
return _transformation;
|
1576
1827
|
});
|
1577
1828
|
|
1578
1829
|
_defineProperty(this, "reset", () => {
|
1579
|
-
this.camera
|
1830
|
+
if (this.camera instanceof PerspectiveCamera || this.camera instanceof OrthographicCamera) {
|
1831
|
+
this.camera.zoom = this._zoom0;
|
1580
1832
|
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1833
|
+
if (this.camera instanceof PerspectiveCamera && this.camera.isPerspectiveCamera) {
|
1834
|
+
this.camera.fov = this._fov0;
|
1835
|
+
}
|
1584
1836
|
|
1585
|
-
|
1586
|
-
|
1837
|
+
this.camera.near = this._nearPos;
|
1838
|
+
this.camera.far = this._farPos;
|
1587
1839
|
|
1588
|
-
|
1840
|
+
this._cameraMatrixState.copy(this._cameraMatrixState0);
|
1589
1841
|
|
1590
|
-
|
1842
|
+
this._cameraMatrixState.decompose(this.camera.position, this.camera.quaternion, this.camera.scale);
|
1591
1843
|
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1844
|
+
this.camera.up.copy(this._up0);
|
1845
|
+
this.camera.updateMatrix();
|
1846
|
+
this.camera.updateProjectionMatrix();
|
1595
1847
|
|
1596
|
-
|
1848
|
+
this._gizmoMatrixState.copy(this._gizmoMatrixState0);
|
1597
1849
|
|
1598
|
-
|
1850
|
+
this._gizmoMatrixState0.decompose(this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale);
|
1599
1851
|
|
1600
|
-
|
1852
|
+
this._gizmos.updateMatrix();
|
1601
1853
|
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1854
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
1855
|
+
|
1856
|
+
if (tbRadius !== undefined) {
|
1857
|
+
this._tbRadius = tbRadius;
|
1858
|
+
}
|
1859
|
+
|
1860
|
+
this.makeGizmos(this._gizmos.position, this._tbRadius);
|
1861
|
+
this.camera.lookAt(this._gizmos.position);
|
1862
|
+
this.updateTbState(STATE.IDLE, false);
|
1863
|
+
this.dispatchEvent(_changeEvent);
|
1864
|
+
}
|
1607
1865
|
});
|
1608
1866
|
|
1609
1867
|
_defineProperty(this, "rotate", (axis, angle) => {
|
@@ -1627,7 +1885,7 @@ class ArcballControls extends EventDispatcher {
|
|
1627
1885
|
_defineProperty(this, "copyState", () => {
|
1628
1886
|
let state;
|
1629
1887
|
|
1630
|
-
if (this.camera.isOrthographicCamera) {
|
1888
|
+
if (this.camera instanceof OrthographicCamera && this.camera.isOrthographicCamera) {
|
1631
1889
|
state = JSON.stringify({
|
1632
1890
|
arcballState: {
|
1633
1891
|
cameraFar: this.camera.far,
|
@@ -1638,7 +1896,7 @@ class ArcballControls extends EventDispatcher {
|
|
1638
1896
|
gizmoMatrix: this._gizmos.matrix
|
1639
1897
|
}
|
1640
1898
|
});
|
1641
|
-
} else if (this.camera.isPerspectiveCamera) {
|
1899
|
+
} else if (this.camera instanceof PerspectiveCamera && this.camera.isPerspectiveCamera) {
|
1642
1900
|
state = JSON.stringify({
|
1643
1901
|
arcballState: {
|
1644
1902
|
cameraFar: this.camera.far,
|
@@ -1652,7 +1910,9 @@ class ArcballControls extends EventDispatcher {
|
|
1652
1910
|
});
|
1653
1911
|
}
|
1654
1912
|
|
1655
|
-
|
1913
|
+
if (state !== undefined) {
|
1914
|
+
navigator.clipboard.writeText(state);
|
1915
|
+
}
|
1656
1916
|
});
|
1657
1917
|
|
1658
1918
|
_defineProperty(this, "pasteState", () => {
|
@@ -1663,18 +1923,20 @@ class ArcballControls extends EventDispatcher {
|
|
1663
1923
|
});
|
1664
1924
|
|
1665
1925
|
_defineProperty(this, "saveState", () => {
|
1666
|
-
this.
|
1926
|
+
if (this.camera instanceof PerspectiveCamera || this.camera instanceof OrthographicCamera) {
|
1927
|
+
this._cameraMatrixState0.copy(this.camera.matrix);
|
1667
1928
|
|
1668
|
-
|
1929
|
+
this._gizmoMatrixState0.copy(this._gizmos.matrix);
|
1669
1930
|
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1931
|
+
this._nearPos = this.camera.near;
|
1932
|
+
this._farPos = this.camera.far;
|
1933
|
+
this._zoom0 = this.camera.zoom;
|
1673
1934
|
|
1674
|
-
|
1935
|
+
this._up0.copy(this.camera.up);
|
1675
1936
|
|
1676
|
-
|
1677
|
-
|
1937
|
+
if (this.camera instanceof PerspectiveCamera && this.camera.isPerspectiveCamera) {
|
1938
|
+
this._fov0 = this.camera.fov;
|
1939
|
+
}
|
1678
1940
|
}
|
1679
1941
|
});
|
1680
1942
|
|
@@ -1682,7 +1944,7 @@ class ArcballControls extends EventDispatcher {
|
|
1682
1944
|
const scalePoint = point.clone();
|
1683
1945
|
let sizeInverse = 1 / size;
|
1684
1946
|
|
1685
|
-
if (this.camera.isOrthographicCamera) {
|
1947
|
+
if (this.camera instanceof OrthographicCamera && this.camera.isOrthographicCamera) {
|
1686
1948
|
//camera zoom
|
1687
1949
|
this.camera.zoom = this._zoomState;
|
1688
1950
|
this.camera.zoom *= size; //check min and max zoom
|
@@ -1720,7 +1982,7 @@ class ArcballControls extends EventDispatcher {
|
|
1720
1982
|
|
1721
1983
|
this.setTransformationMatrices(this._m4_1, this._m4_2);
|
1722
1984
|
return _transformation;
|
1723
|
-
} else if (this.camera.isPerspectiveCamera) {
|
1985
|
+
} else if (this.camera instanceof PerspectiveCamera && this.camera.isPerspectiveCamera) {
|
1724
1986
|
this._v3_1.setFromMatrixPosition(this._cameraMatrixState);
|
1725
1987
|
|
1726
1988
|
this._v3_2.setFromMatrixPosition(this._gizmoMatrixState); //move camera
|
@@ -1773,12 +2035,30 @@ class ArcballControls extends EventDispatcher {
|
|
1773
2035
|
});
|
1774
2036
|
|
1775
2037
|
_defineProperty(this, "setFov", value => {
|
1776
|
-
if (this.camera.isPerspectiveCamera) {
|
2038
|
+
if (this.camera instanceof PerspectiveCamera && this.camera.isPerspectiveCamera) {
|
1777
2039
|
this.camera.fov = MathUtils.clamp(value, this.minFov, this.maxFov);
|
1778
2040
|
this.camera.updateProjectionMatrix();
|
1779
2041
|
}
|
1780
2042
|
});
|
1781
2043
|
|
2044
|
+
_defineProperty(this, "setTarget", (x, y, z) => {
|
2045
|
+
if (this.camera !== null) {
|
2046
|
+
this.target.set(x, y, z);
|
2047
|
+
|
2048
|
+
this._gizmos.position.set(x, y, z); //for correct radius calculation
|
2049
|
+
|
2050
|
+
|
2051
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
2052
|
+
|
2053
|
+
if (tbRadius !== undefined) {
|
2054
|
+
this._tbRadius = tbRadius;
|
2055
|
+
}
|
2056
|
+
|
2057
|
+
this.makeGizmos(this.target, this._tbRadius);
|
2058
|
+
this.camera.lookAt(this.target);
|
2059
|
+
}
|
2060
|
+
});
|
2061
|
+
|
1782
2062
|
_defineProperty(this, "zRotate", (point, angle) => {
|
1783
2063
|
this._rotationMatrix.makeRotationAxis(this._rotationAxis, angle);
|
1784
2064
|
|
@@ -1805,15 +2085,17 @@ class ArcballControls extends EventDispatcher {
|
|
1805
2085
|
});
|
1806
2086
|
|
1807
2087
|
_defineProperty(this, "unprojectOnObj", (cursor, camera) => {
|
1808
|
-
|
1809
|
-
|
1810
|
-
|
1811
|
-
|
1812
|
-
|
1813
|
-
|
1814
|
-
|
1815
|
-
|
1816
|
-
|
2088
|
+
if ((camera instanceof PerspectiveCamera || camera instanceof OrthographicCamera) && this.scene != null) {
|
2089
|
+
const raycaster = new Raycaster();
|
2090
|
+
raycaster.near = camera.near;
|
2091
|
+
raycaster.far = camera.far;
|
2092
|
+
raycaster.setFromCamera(cursor, camera);
|
2093
|
+
const intersect = raycaster.intersectObjects(this.scene.children, true);
|
2094
|
+
|
2095
|
+
for (let i = 0; i < intersect.length; i++) {
|
2096
|
+
if (intersect[i].object.uuid != this._gizmos.uuid && intersect[i].face != null) {
|
2097
|
+
return intersect[i].point.clone();
|
2098
|
+
}
|
1817
2099
|
}
|
1818
2100
|
}
|
1819
2101
|
|
@@ -1989,18 +2271,20 @@ class ArcballControls extends EventDispatcher {
|
|
1989
2271
|
});
|
1990
2272
|
|
1991
2273
|
_defineProperty(this, "updateMatrixState", () => {
|
1992
|
-
|
1993
|
-
|
2274
|
+
if (this.camera !== null) {
|
2275
|
+
//update camera and gizmos state
|
2276
|
+
this._cameraMatrixState.copy(this.camera.matrix);
|
1994
2277
|
|
1995
|
-
|
2278
|
+
this._gizmoMatrixState.copy(this._gizmos.matrix);
|
1996
2279
|
|
1997
|
-
|
1998
|
-
|
2280
|
+
if (this.camera instanceof OrthographicCamera && this.camera.isOrthographicCamera) {
|
2281
|
+
this._cameraProjectionState.copy(this.camera.projectionMatrix);
|
1999
2282
|
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2283
|
+
this.camera.updateProjectionMatrix();
|
2284
|
+
this._zoomState = this.camera.zoom;
|
2285
|
+
} else if (this.camera instanceof PerspectiveCamera && this.camera.isPerspectiveCamera) {
|
2286
|
+
this._fovState = this.camera.fov;
|
2287
|
+
}
|
2004
2288
|
}
|
2005
2289
|
});
|
2006
2290
|
|
@@ -2013,26 +2297,33 @@ class ArcballControls extends EventDispatcher {
|
|
2013
2297
|
});
|
2014
2298
|
|
2015
2299
|
_defineProperty(this, "update", () => {
|
2300
|
+
var _this$camera2;
|
2301
|
+
|
2016
2302
|
const EPS = 0.000001; // Update target and gizmos state
|
2017
2303
|
|
2018
|
-
if (!this.target.equals(this._currentTarget)) {
|
2304
|
+
if (!this.target.equals(this._currentTarget) && this.camera !== null) {
|
2019
2305
|
this._gizmos.position.set(this.target.x, this.target.y, this.target.z); //for correct radius calculation
|
2020
2306
|
|
2021
2307
|
|
2022
|
-
|
2308
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
2309
|
+
|
2310
|
+
if (tbRadius !== undefined) {
|
2311
|
+
this._tbRadius = tbRadius;
|
2312
|
+
}
|
2313
|
+
|
2023
2314
|
this.makeGizmos(this.target, this._tbRadius);
|
2024
2315
|
|
2025
2316
|
this._currentTarget.copy(this.target);
|
2026
2317
|
} //check min/max parameters
|
2027
2318
|
|
2028
2319
|
|
2029
|
-
if (this.camera.isOrthographicCamera) {
|
2320
|
+
if (this.camera instanceof OrthographicCamera && this.camera.isOrthographicCamera) {
|
2030
2321
|
//check zoom
|
2031
2322
|
if (this.camera.zoom > this.maxZoom || this.camera.zoom < this.minZoom) {
|
2032
2323
|
const newZoom = MathUtils.clamp(this.camera.zoom, this.minZoom, this.maxZoom);
|
2033
2324
|
this.applyTransformMatrix(this.applyScale(newZoom / this.camera.zoom, this._gizmos.position, true));
|
2034
2325
|
}
|
2035
|
-
} else if (this.camera.isPerspectiveCamera) {
|
2326
|
+
} else if (this.camera instanceof PerspectiveCamera && this.camera.isPerspectiveCamera) {
|
2036
2327
|
//check distance
|
2037
2328
|
const distance = this.camera.position.distanceTo(this._gizmos.position);
|
2038
2329
|
|
@@ -2049,28 +2340,37 @@ class ArcballControls extends EventDispatcher {
|
|
2049
2340
|
}
|
2050
2341
|
|
2051
2342
|
const oldRadius = this._tbRadius;
|
2052
|
-
|
2343
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
2344
|
+
|
2345
|
+
if (tbRadius !== undefined) {
|
2346
|
+
this._tbRadius = tbRadius;
|
2347
|
+
}
|
2053
2348
|
|
2054
2349
|
if (oldRadius < this._tbRadius - EPS || oldRadius > this._tbRadius + EPS) {
|
2055
2350
|
const scale = (this._gizmos.scale.x + this._gizmos.scale.y + this._gizmos.scale.z) / 3;
|
2056
|
-
const newRadius = this._tbRadius / scale;
|
2351
|
+
const newRadius = this._tbRadius / scale; // @ts-expect-error
|
2352
|
+
|
2057
2353
|
const curve = new EllipseCurve(0, 0, newRadius, newRadius);
|
2058
2354
|
const points = curve.getPoints(this._curvePts);
|
2059
2355
|
const curveGeometry = new BufferGeometry().setFromPoints(points);
|
2060
2356
|
|
2061
2357
|
for (const gizmo in this._gizmos.children) {
|
2062
|
-
this._gizmos.children[gizmo]
|
2358
|
+
const child = this._gizmos.children[gizmo];
|
2359
|
+
|
2360
|
+
if (child instanceof Mesh) {
|
2361
|
+
child.geometry = curveGeometry;
|
2362
|
+
}
|
2063
2363
|
}
|
2064
2364
|
}
|
2065
2365
|
}
|
2066
2366
|
|
2067
|
-
this.camera.lookAt(this._gizmos.position);
|
2367
|
+
(_this$camera2 = this.camera) === null || _this$camera2 === void 0 ? void 0 : _this$camera2.lookAt(this._gizmos.position);
|
2068
2368
|
});
|
2069
2369
|
|
2070
2370
|
_defineProperty(this, "setStateFromJSON", json => {
|
2071
2371
|
const state = JSON.parse(json);
|
2072
2372
|
|
2073
|
-
if (state.arcballState != undefined) {
|
2373
|
+
if (state.arcballState != undefined && (this.camera instanceof PerspectiveCamera || this.camera instanceof OrthographicCamera)) {
|
2074
2374
|
this._cameraMatrixState.fromArray(state.arcballState.cameraMatrix.elements);
|
2075
2375
|
|
2076
2376
|
this._cameraMatrixState.decompose(this.camera.position, this.camera.quaternion, this.camera.scale);
|
@@ -2080,7 +2380,7 @@ class ArcballControls extends EventDispatcher {
|
|
2080
2380
|
this.camera.far = state.arcballState.cameraFar;
|
2081
2381
|
this.camera.zoom = state.arcballState.cameraZoom;
|
2082
2382
|
|
2083
|
-
if (this.camera.isPerspectiveCamera) {
|
2383
|
+
if (this.camera instanceof PerspectiveCamera && this.camera.isPerspectiveCamera) {
|
2084
2384
|
this.camera.fov = state.arcballState.cameraFov;
|
2085
2385
|
}
|
2086
2386
|
|
@@ -2093,7 +2393,12 @@ class ArcballControls extends EventDispatcher {
|
|
2093
2393
|
|
2094
2394
|
this._gizmos.updateMatrix();
|
2095
2395
|
|
2096
|
-
|
2396
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
2397
|
+
|
2398
|
+
if (tbRadius !== undefined) {
|
2399
|
+
this._tbRadius = tbRadius;
|
2400
|
+
}
|
2401
|
+
|
2097
2402
|
const gizmoTmp = new Matrix4().copy(this._gizmoMatrixState0);
|
2098
2403
|
this.makeGizmos(this._gizmos.position, this._tbRadius);
|
2099
2404
|
|
@@ -2106,6 +2411,7 @@ class ArcballControls extends EventDispatcher {
|
|
2106
2411
|
});
|
2107
2412
|
|
2108
2413
|
this.camera = null;
|
2414
|
+
this.domElement = domElement;
|
2109
2415
|
this.scene = scene;
|
2110
2416
|
this.mouseActions = [];
|
2111
2417
|
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)
|
@@ -2239,12 +2545,17 @@ class ArcballControls extends EventDispatcher {
|
|
2239
2545
|
|
2240
2546
|
if (this.scene != null) {
|
2241
2547
|
this.scene.add(this._gizmos);
|
2242
|
-
}
|
2243
|
-
|
2548
|
+
}
|
2244
2549
|
|
2245
|
-
|
2550
|
+
this.domElement.style.touchAction = 'none';
|
2246
2551
|
this._devPxRatio = window.devicePixelRatio;
|
2247
2552
|
this.initializeMouseActions();
|
2553
|
+
this.domElement.addEventListener('contextmenu', this.onContextMenu);
|
2554
|
+
this.domElement.addEventListener('wheel', this.onWheel);
|
2555
|
+
this.domElement.addEventListener('pointerdown', this.onPointerDown);
|
2556
|
+
this.domElement.addEventListener('pointercancel', this.onPointerCancel);
|
2557
|
+
window.addEventListener('keydown', this.onKeyDown);
|
2558
|
+
window.addEventListener('resize', this.onWindowResize);
|
2248
2559
|
} //listeners
|
2249
2560
|
|
2250
2561
|
|
@@ -2253,7 +2564,7 @@ class ArcballControls extends EventDispatcher {
|
|
2253
2564
|
* @param {Object} transformation Object containing matrices to apply to camera and gizmos
|
2254
2565
|
*/
|
2255
2566
|
applyTransformMatrix(transformation) {
|
2256
|
-
if (transformation.camera != null) {
|
2567
|
+
if ((transformation === null || transformation === void 0 ? void 0 : transformation.camera) != null && this.camera !== null) {
|
2257
2568
|
this._m4_1.copy(this._cameraMatrixState).premultiply(transformation.camera);
|
2258
2569
|
|
2259
2570
|
this._m4_1.decompose(this.camera.position, this.camera.quaternion, this.camera.scale);
|
@@ -2265,7 +2576,7 @@ class ArcballControls extends EventDispatcher {
|
|
2265
2576
|
}
|
2266
2577
|
}
|
2267
2578
|
|
2268
|
-
if (transformation.gizmos != null) {
|
2579
|
+
if ((transformation === null || transformation === void 0 ? void 0 : transformation.gizmos) != null) {
|
2269
2580
|
this._m4_1.copy(this._gizmoMatrixState).premultiply(transformation.gizmos);
|
2270
2581
|
|
2271
2582
|
this._m4_1.decompose(this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale);
|
@@ -2273,8 +2584,12 @@ class ArcballControls extends EventDispatcher {
|
|
2273
2584
|
this._gizmos.updateMatrix();
|
2274
2585
|
}
|
2275
2586
|
|
2276
|
-
if (this._state == STATE.SCALE || this._state == STATE.FOCUS || this._state == STATE.ANIMATION_FOCUS) {
|
2277
|
-
|
2587
|
+
if ((this._state == STATE.SCALE || this._state == STATE.FOCUS || this._state == STATE.ANIMATION_FOCUS) && (this.camera instanceof PerspectiveCamera || this.camera instanceof OrthographicCamera)) {
|
2588
|
+
const tbRadius = this.calculateTbRadius(this.camera);
|
2589
|
+
|
2590
|
+
if (tbRadius !== undefined) {
|
2591
|
+
this._tbRadius = tbRadius;
|
2592
|
+
}
|
2278
2593
|
|
2279
2594
|
if (this.adjustNearFar) {
|
2280
2595
|
const cameraDistance = this.camera.position.distanceTo(this._gizmos.position);
|