hilbert-chart-3d 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- // Version 0.4.0 hilbert-chart-3d - https://github.com/vasturiano/hilbert-chart-3d
1
+ // Version 0.4.1 hilbert-chart-3d - https://github.com/vasturiano/hilbert-chart-3d
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -16475,13 +16475,13 @@
16475
16475
  }
16476
16476
 
16477
16477
  // compute box center and extents
16478
- this.getCenter( _center );
16479
- _extents.subVectors( this.max, _center );
16478
+ this.getCenter( _center$1 );
16479
+ _extents.subVectors( this.max, _center$1 );
16480
16480
 
16481
16481
  // translate triangle to aabb origin
16482
- _v0$1.subVectors( triangle.a, _center );
16483
- _v1$4.subVectors( triangle.b, _center );
16484
- _v2$3.subVectors( triangle.c, _center );
16482
+ _v0$1.subVectors( triangle.a, _center$1 );
16483
+ _v1$4.subVectors( triangle.b, _center$1 );
16484
+ _v2$3.subVectors( triangle.c, _center$1 );
16485
16485
 
16486
16486
  // compute edge vectors for triangle
16487
16487
  _f0.subVectors( _v1$4, _v0$1 );
@@ -16719,7 +16719,7 @@
16719
16719
  const _f1 = /*@__PURE__*/ new Vector3();
16720
16720
  const _f2 = /*@__PURE__*/ new Vector3();
16721
16721
 
16722
- const _center = /*@__PURE__*/ new Vector3();
16722
+ const _center$1 = /*@__PURE__*/ new Vector3();
16723
16723
  const _extents = /*@__PURE__*/ new Vector3();
16724
16724
  const _triangleNormal = /*@__PURE__*/ new Vector3();
16725
16725
  const _testAxis = /*@__PURE__*/ new Vector3();
@@ -18301,7 +18301,7 @@
18301
18301
 
18302
18302
  const _m1$3 = /*@__PURE__*/ new Matrix4();
18303
18303
  const _obj = /*@__PURE__*/ new Object3D();
18304
- const _offset = /*@__PURE__*/ new Vector3();
18304
+ const _offset$1 = /*@__PURE__*/ new Vector3();
18305
18305
  const _box$2 = /*@__PURE__*/ new Box3();
18306
18306
  const _boxMorphTargets = /*@__PURE__*/ new Box3();
18307
18307
  const _vector$9 = /*@__PURE__*/ new Vector3();
@@ -18861,9 +18861,9 @@
18861
18861
 
18862
18862
  this.computeBoundingBox();
18863
18863
 
18864
- this.boundingBox.getCenter( _offset ).negate();
18864
+ this.boundingBox.getCenter( _offset$1 ).negate();
18865
18865
 
18866
- this.translate( _offset.x, _offset.y, _offset.z );
18866
+ this.translate( _offset$1.x, _offset$1.y, _offset$1.z );
18867
18867
 
18868
18868
  return this;
18869
18869
 
@@ -19089,8 +19089,8 @@
19089
19089
 
19090
19090
  if ( morphTargetsRelative ) {
19091
19091
 
19092
- _offset.fromBufferAttribute( position, j );
19093
- _vector$9.add( _offset );
19092
+ _offset$1.fromBufferAttribute( position, j );
19093
+ _vector$9.add( _offset$1 );
19094
19094
 
19095
19095
  }
19096
19096
 
@@ -25085,6 +25085,424 @@
25085
25085
 
25086
25086
  }
25087
25087
 
25088
+ const _vStart = /*@__PURE__*/ new Vector3();
25089
+ const _vEnd = /*@__PURE__*/ new Vector3();
25090
+
25091
+ const _inverseMatrix$1 = /*@__PURE__*/ new Matrix4();
25092
+ const _ray$1 = /*@__PURE__*/ new Ray();
25093
+ const _sphere$1 = /*@__PURE__*/ new Sphere();
25094
+
25095
+ const _intersectPointOnRay = /*@__PURE__*/ new Vector3();
25096
+ const _intersectPointOnSegment = /*@__PURE__*/ new Vector3();
25097
+
25098
+ /**
25099
+ * A continuous line. The line are rendered by connecting consecutive
25100
+ * vertices with straight lines.
25101
+ *
25102
+ * ```js
25103
+ * const material = new THREE.LineBasicMaterial( { color: 0x0000ff } );
25104
+ *
25105
+ * const points = [];
25106
+ * points.push( new THREE.Vector3( - 10, 0, 0 ) );
25107
+ * points.push( new THREE.Vector3( 0, 10, 0 ) );
25108
+ * points.push( new THREE.Vector3( 10, 0, 0 ) );
25109
+ *
25110
+ * const geometry = new THREE.BufferGeometry().setFromPoints( points );
25111
+ *
25112
+ * const line = new THREE.Line( geometry, material );
25113
+ * scene.add( line );
25114
+ * ```
25115
+ *
25116
+ * @augments Object3D
25117
+ */
25118
+ class Line extends Object3D {
25119
+
25120
+ /**
25121
+ * Constructs a new line.
25122
+ *
25123
+ * @param {BufferGeometry} [geometry] - The line geometry.
25124
+ * @param {Material|Array<Material>} [material] - The line material.
25125
+ */
25126
+ constructor( geometry = new BufferGeometry(), material = new LineBasicMaterial() ) {
25127
+
25128
+ super();
25129
+
25130
+ /**
25131
+ * This flag can be used for type testing.
25132
+ *
25133
+ * @type {boolean}
25134
+ * @readonly
25135
+ * @default true
25136
+ */
25137
+ this.isLine = true;
25138
+
25139
+ this.type = 'Line';
25140
+
25141
+ /**
25142
+ * The line geometry.
25143
+ *
25144
+ * @type {BufferGeometry}
25145
+ */
25146
+ this.geometry = geometry;
25147
+
25148
+ /**
25149
+ * The line material.
25150
+ *
25151
+ * @type {Material|Array<Material>}
25152
+ * @default LineBasicMaterial
25153
+ */
25154
+ this.material = material;
25155
+
25156
+ /**
25157
+ * A dictionary representing the morph targets in the geometry. The key is the
25158
+ * morph targets name, the value its attribute index. This member is `undefined`
25159
+ * by default and only set when morph targets are detected in the geometry.
25160
+ *
25161
+ * @type {Object<string,number>|undefined}
25162
+ * @default undefined
25163
+ */
25164
+ this.morphTargetDictionary = undefined;
25165
+
25166
+ /**
25167
+ * An array of weights typically in the range `[0,1]` that specify how much of the morph
25168
+ * is applied. This member is `undefined` by default and only set when morph targets are
25169
+ * detected in the geometry.
25170
+ *
25171
+ * @type {Array<number>|undefined}
25172
+ * @default undefined
25173
+ */
25174
+ this.morphTargetInfluences = undefined;
25175
+
25176
+ this.updateMorphTargets();
25177
+
25178
+ }
25179
+
25180
+ copy( source, recursive ) {
25181
+
25182
+ super.copy( source, recursive );
25183
+
25184
+ if ( source.morphTargetInfluences !== undefined ) {
25185
+
25186
+ this.morphTargetInfluences = source.morphTargetInfluences.slice();
25187
+
25188
+ } else {
25189
+
25190
+ this.morphTargetInfluences = undefined;
25191
+
25192
+ }
25193
+
25194
+ if ( source.morphTargetDictionary !== undefined ) {
25195
+
25196
+ this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
25197
+
25198
+ } else {
25199
+
25200
+ this.morphTargetDictionary = undefined;
25201
+
25202
+ }
25203
+
25204
+ this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
25205
+ this.geometry = source.geometry;
25206
+
25207
+ return this;
25208
+
25209
+ }
25210
+
25211
+ /**
25212
+ * Computes an array of distance values which are necessary for rendering dashed lines.
25213
+ * For each vertex in the geometry, the method calculates the cumulative length from the
25214
+ * current point to the very beginning of the line.
25215
+ *
25216
+ * @return {Line} A reference to this line.
25217
+ */
25218
+ computeLineDistances() {
25219
+
25220
+ const geometry = this.geometry;
25221
+
25222
+ // we assume non-indexed geometry
25223
+
25224
+ if ( geometry.index === null ) {
25225
+
25226
+ const positionAttribute = geometry.attributes.position;
25227
+ const lineDistances = [ 0 ];
25228
+
25229
+ for ( let i = 1, l = positionAttribute.count; i < l; i ++ ) {
25230
+
25231
+ _vStart.fromBufferAttribute( positionAttribute, i - 1 );
25232
+ _vEnd.fromBufferAttribute( positionAttribute, i );
25233
+
25234
+ lineDistances[ i ] = lineDistances[ i - 1 ];
25235
+ lineDistances[ i ] += _vStart.distanceTo( _vEnd );
25236
+
25237
+ }
25238
+
25239
+ geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
25240
+
25241
+ } else {
25242
+
25243
+ warn( 'Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
25244
+
25245
+ }
25246
+
25247
+ return this;
25248
+
25249
+ }
25250
+
25251
+ /**
25252
+ * Returns `true` if this line intersects the given frustum.
25253
+ *
25254
+ * @param {Frustum|FrustumArray} frustum - The frustum to test.
25255
+ * @return {boolean} Whether this line intersects the given frustum or not.
25256
+ */
25257
+ intersectsFrustum( frustum ) {
25258
+
25259
+ return frustum.intersectsObject( this );
25260
+
25261
+ }
25262
+
25263
+ /**
25264
+ * Computes intersection points between a casted ray and this line.
25265
+ *
25266
+ * @param {Raycaster} raycaster - The raycaster.
25267
+ * @param {Array<Object>} intersects - The target array that holds the intersection points.
25268
+ */
25269
+ raycast( raycaster, intersects ) {
25270
+
25271
+ const geometry = this.geometry;
25272
+ const matrixWorld = this.matrixWorld;
25273
+ const threshold = raycaster.params.Line.threshold;
25274
+ const drawRange = geometry.drawRange;
25275
+
25276
+ // Checking boundingSphere distance to ray
25277
+
25278
+ if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
25279
+
25280
+ _sphere$1.copy( geometry.boundingSphere );
25281
+ _sphere$1.applyMatrix4( matrixWorld );
25282
+ _sphere$1.radius += threshold;
25283
+
25284
+ if ( raycaster.ray.intersectsSphere( _sphere$1 ) === false ) return;
25285
+
25286
+ //
25287
+
25288
+ _inverseMatrix$1.copy( matrixWorld ).invert();
25289
+ _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 );
25290
+
25291
+ const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
25292
+ const localThresholdSq = localThreshold * localThreshold;
25293
+
25294
+ const step = this.isLineSegments ? 2 : 1;
25295
+
25296
+ const index = geometry.index;
25297
+ const attributes = geometry.attributes;
25298
+ const positionAttribute = attributes.position;
25299
+
25300
+ if ( index !== null ) {
25301
+
25302
+ const start = Math.max( 0, drawRange.start );
25303
+ const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
25304
+
25305
+ for ( let i = start, l = end - 1; i < l; i += step ) {
25306
+
25307
+ const a = index.getX( i );
25308
+ const b = index.getX( i + 1 );
25309
+
25310
+ const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, a, b, i );
25311
+
25312
+ if ( intersect ) {
25313
+
25314
+ intersects.push( intersect );
25315
+
25316
+ }
25317
+
25318
+ }
25319
+
25320
+ if ( this.isLineLoop ) {
25321
+
25322
+ const a = index.getX( end - 1 );
25323
+ const b = index.getX( start );
25324
+
25325
+ const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, a, b, end - 1 );
25326
+
25327
+ if ( intersect ) {
25328
+
25329
+ intersects.push( intersect );
25330
+
25331
+ }
25332
+
25333
+ }
25334
+
25335
+ } else {
25336
+
25337
+ const start = Math.max( 0, drawRange.start );
25338
+ const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) );
25339
+
25340
+ for ( let i = start, l = end - 1; i < l; i += step ) {
25341
+
25342
+ const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, i, i + 1, i );
25343
+
25344
+ if ( intersect ) {
25345
+
25346
+ intersects.push( intersect );
25347
+
25348
+ }
25349
+
25350
+ }
25351
+
25352
+ if ( this.isLineLoop ) {
25353
+
25354
+ const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, end - 1, start, end - 1 );
25355
+
25356
+ if ( intersect ) {
25357
+
25358
+ intersects.push( intersect );
25359
+
25360
+ }
25361
+
25362
+ }
25363
+
25364
+ }
25365
+
25366
+ }
25367
+
25368
+ /**
25369
+ * Sets the values of {@link Line#morphTargetDictionary} and {@link Line#morphTargetInfluences}
25370
+ * to make sure existing morph targets can influence this 3D object.
25371
+ */
25372
+ updateMorphTargets() {
25373
+
25374
+ const geometry = this.geometry;
25375
+
25376
+ const morphAttributes = geometry.morphAttributes;
25377
+ const keys = Object.keys( morphAttributes );
25378
+
25379
+ if ( keys.length > 0 ) {
25380
+
25381
+ const morphAttribute = morphAttributes[ keys[ 0 ] ];
25382
+
25383
+ if ( morphAttribute !== undefined ) {
25384
+
25385
+ this.morphTargetInfluences = [];
25386
+ this.morphTargetDictionary = {};
25387
+
25388
+ for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
25389
+
25390
+ const name = morphAttribute[ m ].name || String( m );
25391
+
25392
+ this.morphTargetInfluences.push( 0 );
25393
+ this.morphTargetDictionary[ name ] = m;
25394
+
25395
+ }
25396
+
25397
+ }
25398
+
25399
+ }
25400
+
25401
+ }
25402
+
25403
+ }
25404
+
25405
+ function checkIntersection( object, raycaster, ray, thresholdSq, a, b, i ) {
25406
+
25407
+ const positionAttribute = object.geometry.attributes.position;
25408
+
25409
+ _vStart.fromBufferAttribute( positionAttribute, a );
25410
+ _vEnd.fromBufferAttribute( positionAttribute, b );
25411
+
25412
+ const distSq = ray.distanceSqToSegment( _vStart, _vEnd, _intersectPointOnRay, _intersectPointOnSegment );
25413
+
25414
+ if ( distSq > thresholdSq ) return;
25415
+
25416
+ _intersectPointOnRay.applyMatrix4( object.matrixWorld ); // Move back to world space for distance calculation
25417
+
25418
+ const distance = raycaster.ray.origin.distanceTo( _intersectPointOnRay );
25419
+
25420
+ if ( distance < raycaster.near || distance > raycaster.far ) return;
25421
+
25422
+ return {
25423
+
25424
+ distance: distance,
25425
+ // What do we want? intersection point on the ray or on the segment??
25426
+ // point: raycaster.ray.at( distance ),
25427
+ point: _intersectPointOnSegment.clone().applyMatrix4( object.matrixWorld ),
25428
+ index: i,
25429
+ face: null,
25430
+ faceIndex: null,
25431
+ barycoord: null,
25432
+ object: object
25433
+
25434
+ };
25435
+
25436
+ }
25437
+
25438
+ const _start = /*@__PURE__*/ new Vector3();
25439
+ const _end = /*@__PURE__*/ new Vector3();
25440
+
25441
+ /**
25442
+ * A series of lines drawn between pairs of vertices.
25443
+ *
25444
+ * @augments Line
25445
+ */
25446
+ class LineSegments extends Line {
25447
+
25448
+ /**
25449
+ * Constructs a new line segments.
25450
+ *
25451
+ * @param {BufferGeometry} [geometry] - The line geometry.
25452
+ * @param {Material|Array<Material>} [material] - The line material.
25453
+ */
25454
+ constructor( geometry, material ) {
25455
+
25456
+ super( geometry, material );
25457
+
25458
+ /**
25459
+ * This flag can be used for type testing.
25460
+ *
25461
+ * @type {boolean}
25462
+ * @readonly
25463
+ * @default true
25464
+ */
25465
+ this.isLineSegments = true;
25466
+
25467
+ this.type = 'LineSegments';
25468
+
25469
+ }
25470
+
25471
+ computeLineDistances() {
25472
+
25473
+ const geometry = this.geometry;
25474
+
25475
+ // we assume non-indexed geometry
25476
+
25477
+ if ( geometry.index === null ) {
25478
+
25479
+ const positionAttribute = geometry.attributes.position;
25480
+ const lineDistances = [];
25481
+
25482
+ for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) {
25483
+
25484
+ _start.fromBufferAttribute( positionAttribute, i );
25485
+ _end.fromBufferAttribute( positionAttribute, i + 1 );
25486
+
25487
+ lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
25488
+ lineDistances[ i + 1 ] = lineDistances[ i ] + _start.distanceTo( _end );
25489
+
25490
+ }
25491
+
25492
+ geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
25493
+
25494
+ } else {
25495
+
25496
+ warn( 'LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
25497
+
25498
+ }
25499
+
25500
+ return this;
25501
+
25502
+ }
25503
+
25504
+ }
25505
+
25088
25506
  /**
25089
25507
  * A material for rendering point primitives.
25090
25508
  *
@@ -26198,6 +26616,773 @@
26198
26616
 
26199
26617
  }
26200
26618
 
26619
+ /**
26620
+ * An abstract base class for creating an analytic curve object that contains methods
26621
+ * for interpolation.
26622
+ *
26623
+ * @abstract
26624
+ */
26625
+ class Curve {
26626
+
26627
+ /**
26628
+ * Constructs a new curve.
26629
+ */
26630
+ constructor() {
26631
+
26632
+ /**
26633
+ * The type property is used for detecting the object type
26634
+ * in context of serialization/deserialization.
26635
+ *
26636
+ * @type {string}
26637
+ * @readonly
26638
+ */
26639
+ this.type = 'Curve';
26640
+
26641
+ /**
26642
+ * This value determines the amount of divisions when calculating the
26643
+ * cumulative segment lengths of a curve via {@link Curve#getLengths}. To ensure
26644
+ * precision when using methods like {@link Curve#getSpacedPoints}, it is
26645
+ * recommended to increase the value of this property if the curve is very large.
26646
+ *
26647
+ * @type {number}
26648
+ * @default 200
26649
+ */
26650
+ this.arcLengthDivisions = 200;
26651
+
26652
+ /**
26653
+ * Must be set to `true` if the curve parameters have changed.
26654
+ *
26655
+ * @type {boolean}
26656
+ * @default false
26657
+ */
26658
+ this.needsUpdate = false;
26659
+
26660
+ /**
26661
+ * An internal cache that holds precomputed curve length values.
26662
+ *
26663
+ * @private
26664
+ * @type {?Array<number>}
26665
+ * @default null
26666
+ */
26667
+ this.cacheArcLengths = null;
26668
+
26669
+ }
26670
+
26671
+ /**
26672
+ * This method returns a vector in 2D or 3D space (depending on the curve definition)
26673
+ * for the given interpolation factor.
26674
+ *
26675
+ * @abstract
26676
+ * @param {number} t - A interpolation factor representing a position on the curve. Must be in the range `[0,1]`.
26677
+ * @param {(Vector2|Vector3)} [optionalTarget] - The optional target vector the result is written to.
26678
+ * @return {(Vector2|Vector3)} The position on the curve. It can be a 2D or 3D vector depending on the curve definition.
26679
+ */
26680
+ getPoint( /* t, optionalTarget */ ) {
26681
+
26682
+ warn( 'Curve: .getPoint() not implemented.' );
26683
+
26684
+ }
26685
+
26686
+ /**
26687
+ * This method returns a vector in 2D or 3D space (depending on the curve definition)
26688
+ * for the given interpolation factor. Unlike {@link Curve#getPoint}, this method honors the length
26689
+ * of the curve which equidistant samples.
26690
+ *
26691
+ * @param {number} u - A interpolation factor representing a position on the curve. Must be in the range `[0,1]`.
26692
+ * @param {(Vector2|Vector3)} [optionalTarget] - The optional target vector the result is written to.
26693
+ * @return {(Vector2|Vector3)} The position on the curve. It can be a 2D or 3D vector depending on the curve definition.
26694
+ */
26695
+ getPointAt( u, optionalTarget ) {
26696
+
26697
+ const t = this.getUtoTmapping( u );
26698
+ return this.getPoint( t, optionalTarget );
26699
+
26700
+ }
26701
+
26702
+ /**
26703
+ * This method samples the curve via {@link Curve#getPoint} and returns an array of points representing
26704
+ * the curve shape.
26705
+ *
26706
+ * @param {number} [divisions=5] - The number of divisions.
26707
+ * @return {Array<(Vector2|Vector3)>} An array holding the sampled curve values. The number of points is `divisions + 1`.
26708
+ */
26709
+ getPoints( divisions = 5 ) {
26710
+
26711
+ const points = [];
26712
+
26713
+ for ( let d = 0; d <= divisions; d ++ ) {
26714
+
26715
+ points.push( this.getPoint( d / divisions ) );
26716
+
26717
+ }
26718
+
26719
+ return points;
26720
+
26721
+ }
26722
+
26723
+ // Get sequence of points using getPointAt( u )
26724
+
26725
+ /**
26726
+ * This method samples the curve via {@link Curve#getPointAt} and returns an array of points representing
26727
+ * the curve shape. Unlike {@link Curve#getPoints}, this method returns equi-spaced points across the entire
26728
+ * curve.
26729
+ *
26730
+ * @param {number} [divisions=5] - The number of divisions.
26731
+ * @return {Array<(Vector2|Vector3)>} An array holding the sampled curve values. The number of points is `divisions + 1`.
26732
+ */
26733
+ getSpacedPoints( divisions = 5 ) {
26734
+
26735
+ const points = [];
26736
+
26737
+ for ( let d = 0; d <= divisions; d ++ ) {
26738
+
26739
+ points.push( this.getPointAt( d / divisions ) );
26740
+
26741
+ }
26742
+
26743
+ return points;
26744
+
26745
+ }
26746
+
26747
+ /**
26748
+ * Returns the total arc length of the curve.
26749
+ *
26750
+ * @return {number} The length of the curve.
26751
+ */
26752
+ getLength() {
26753
+
26754
+ const lengths = this.getLengths();
26755
+ return lengths[ lengths.length - 1 ];
26756
+
26757
+ }
26758
+
26759
+ /**
26760
+ * Returns an array of cumulative segment lengths of the curve.
26761
+ *
26762
+ * @param {number} [divisions=this.arcLengthDivisions] - The number of divisions.
26763
+ * @return {Array<number>} An array holding the cumulative segment lengths.
26764
+ */
26765
+ getLengths( divisions = this.arcLengthDivisions ) {
26766
+
26767
+ if ( this.cacheArcLengths &&
26768
+ ( this.cacheArcLengths.length === divisions + 1 ) &&
26769
+ ! this.needsUpdate ) {
26770
+
26771
+ return this.cacheArcLengths;
26772
+
26773
+ }
26774
+
26775
+ this.needsUpdate = false;
26776
+
26777
+ const cache = [];
26778
+ let current, last = this.getPoint( 0 );
26779
+ let sum = 0;
26780
+
26781
+ cache.push( 0 );
26782
+
26783
+ for ( let p = 1; p <= divisions; p ++ ) {
26784
+
26785
+ current = this.getPoint( p / divisions );
26786
+ sum += current.distanceTo( last );
26787
+ cache.push( sum );
26788
+ last = current;
26789
+
26790
+ }
26791
+
26792
+ this.cacheArcLengths = cache;
26793
+
26794
+ return cache; // { sums: cache, sum: sum }; Sum is in the last element.
26795
+
26796
+ }
26797
+
26798
+ /**
26799
+ * Update the cumulative segment distance cache. The method must be called
26800
+ * every time curve parameters are changed. If an updated curve is part of a
26801
+ * composed curve like {@link CurvePath}, this method must be called on the
26802
+ * composed curve, too.
26803
+ */
26804
+ updateArcLengths() {
26805
+
26806
+ this.needsUpdate = true;
26807
+ this.getLengths();
26808
+
26809
+ }
26810
+
26811
+ /**
26812
+ * Given an interpolation factor in the range `[0,1]`, this method returns an updated
26813
+ * interpolation factor in the same range that can be ued to sample equidistant points
26814
+ * from a curve.
26815
+ *
26816
+ * @param {number} u - The interpolation factor.
26817
+ * @param {?number} distance - An optional distance on the curve.
26818
+ * @return {number} The updated interpolation factor.
26819
+ */
26820
+ getUtoTmapping( u, distance = null ) {
26821
+
26822
+ const arcLengths = this.getLengths();
26823
+
26824
+ let i = 0;
26825
+ const il = arcLengths.length;
26826
+
26827
+ let targetArcLength; // The targeted u distance value to get
26828
+
26829
+ if ( distance ) {
26830
+
26831
+ targetArcLength = distance;
26832
+
26833
+ } else {
26834
+
26835
+ targetArcLength = u * arcLengths[ il - 1 ];
26836
+
26837
+ }
26838
+
26839
+ // binary search for the index with largest value smaller than target u distance
26840
+
26841
+ let low = 0, high = il - 1, comparison;
26842
+
26843
+ while ( low <= high ) {
26844
+
26845
+ i = Math.floor( low + ( high - low ) / 2 ); // less likely to overflow, though probably not issue here, JS doesn't really have integers, all numbers are floats
26846
+
26847
+ comparison = arcLengths[ i ] - targetArcLength;
26848
+
26849
+ if ( comparison < 0 ) {
26850
+
26851
+ low = i + 1;
26852
+
26853
+ } else if ( comparison > 0 ) {
26854
+
26855
+ high = i - 1;
26856
+
26857
+ } else {
26858
+
26859
+ high = i;
26860
+ break;
26861
+
26862
+ // DONE
26863
+
26864
+ }
26865
+
26866
+ }
26867
+
26868
+ i = high;
26869
+
26870
+ if ( arcLengths[ i ] === targetArcLength ) {
26871
+
26872
+ return i / ( il - 1 );
26873
+
26874
+ }
26875
+
26876
+ // we could get finer grain at lengths, or use simple interpolation between two points
26877
+
26878
+ const lengthBefore = arcLengths[ i ];
26879
+ const lengthAfter = arcLengths[ i + 1 ];
26880
+
26881
+ const segmentLength = lengthAfter - lengthBefore;
26882
+
26883
+ // determine where we are between the 'before' and 'after' points
26884
+
26885
+ const segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
26886
+
26887
+ // add that fractional amount to t
26888
+
26889
+ const t = ( i + segmentFraction ) / ( il - 1 );
26890
+
26891
+ return t;
26892
+
26893
+ }
26894
+
26895
+ /**
26896
+ * Returns a unit vector tangent for the given interpolation factor.
26897
+ * If the derived curve does not implement its tangent derivation,
26898
+ * two points a small delta apart will be used to find its gradient
26899
+ * which seems to give a reasonable approximation.
26900
+ *
26901
+ * @param {number} t - The interpolation factor.
26902
+ * @param {(Vector2|Vector3)} [optionalTarget] - The optional target vector the result is written to.
26903
+ * @return {(Vector2|Vector3)} The tangent vector.
26904
+ */
26905
+ getTangent( t, optionalTarget ) {
26906
+
26907
+ const delta = 0.0001;
26908
+ let t1 = t - delta;
26909
+ let t2 = t + delta;
26910
+
26911
+ // Capping in case of danger
26912
+
26913
+ if ( t1 < 0 ) t1 = 0;
26914
+ if ( t2 > 1 ) t2 = 1;
26915
+
26916
+ const pt1 = this.getPoint( t1 );
26917
+ const pt2 = this.getPoint( t2 );
26918
+
26919
+ const tangent = optionalTarget || ( ( pt1.isVector2 ) ? new Vector2() : new Vector3() );
26920
+
26921
+ tangent.copy( pt2 ).sub( pt1 ).normalize();
26922
+
26923
+ return tangent;
26924
+
26925
+ }
26926
+
26927
+ /**
26928
+ * Same as {@link Curve#getTangent} but with equidistant samples.
26929
+ *
26930
+ * @param {number} u - The interpolation factor.
26931
+ * @param {(Vector2|Vector3)} [optionalTarget] - The optional target vector the result is written to.
26932
+ * @return {(Vector2|Vector3)} The tangent vector.
26933
+ * @see {@link Curve#getPointAt}
26934
+ */
26935
+ getTangentAt( u, optionalTarget ) {
26936
+
26937
+ const t = this.getUtoTmapping( u );
26938
+ return this.getTangent( t, optionalTarget );
26939
+
26940
+ }
26941
+
26942
+ /**
26943
+ * Generates the Frenet Frames. Requires a curve definition in 3D space. Used
26944
+ * in geometries like {@link TubeGeometry} or {@link ExtrudeGeometry}.
26945
+ *
26946
+ * @param {number} segments - The number of segments.
26947
+ * @param {boolean} [closed=false] - Whether the curve is closed or not.
26948
+ * @return {{tangents: Array<Vector3>, normals: Array<Vector3>, binormals: Array<Vector3>}} The Frenet Frames.
26949
+ */
26950
+ computeFrenetFrames( segments, closed = false ) {
26951
+
26952
+ // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
26953
+
26954
+ const normal = new Vector3();
26955
+
26956
+ const tangents = [];
26957
+ const normals = [];
26958
+ const binormals = [];
26959
+
26960
+ const vec = new Vector3();
26961
+ const mat = new Matrix4();
26962
+
26963
+ // compute the tangent vectors for each segment on the curve
26964
+
26965
+ for ( let i = 0; i <= segments; i ++ ) {
26966
+
26967
+ const u = i / segments;
26968
+
26969
+ tangents[ i ] = this.getTangentAt( u, new Vector3() );
26970
+
26971
+ }
26972
+
26973
+ // select an initial normal vector perpendicular to the first tangent vector,
26974
+ // and in the direction of the minimum tangent xyz component
26975
+
26976
+ normals[ 0 ] = new Vector3();
26977
+ binormals[ 0 ] = new Vector3();
26978
+ let min = Number.MAX_VALUE;
26979
+ const tx = Math.abs( tangents[ 0 ].x );
26980
+ const ty = Math.abs( tangents[ 0 ].y );
26981
+ const tz = Math.abs( tangents[ 0 ].z );
26982
+
26983
+ if ( tx <= min ) {
26984
+
26985
+ min = tx;
26986
+ normal.set( 1, 0, 0 );
26987
+
26988
+ }
26989
+
26990
+ if ( ty <= min ) {
26991
+
26992
+ min = ty;
26993
+ normal.set( 0, 1, 0 );
26994
+
26995
+ }
26996
+
26997
+ if ( tz <= min ) {
26998
+
26999
+ normal.set( 0, 0, 1 );
27000
+
27001
+ }
27002
+
27003
+ vec.crossVectors( tangents[ 0 ], normal ).normalize();
27004
+
27005
+ normals[ 0 ].crossVectors( tangents[ 0 ], vec );
27006
+ binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
27007
+
27008
+
27009
+ // compute the slowly-varying normal and binormal vectors for each segment on the curve
27010
+
27011
+ for ( let i = 1; i <= segments; i ++ ) {
27012
+
27013
+ normals[ i ] = normals[ i - 1 ].clone();
27014
+
27015
+ binormals[ i ] = binormals[ i - 1 ].clone();
27016
+
27017
+ vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
27018
+
27019
+ if ( vec.length() > Number.EPSILON ) {
27020
+
27021
+ vec.normalize();
27022
+
27023
+ const theta = Math.acos( clamp$1( tangents[ i - 1 ].dot( tangents[ i ] ), -1, 1 ) ); // clamp for floating pt errors
27024
+
27025
+ normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
27026
+
27027
+ }
27028
+
27029
+ binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
27030
+
27031
+ }
27032
+
27033
+ // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
27034
+
27035
+ if ( closed === true ) {
27036
+
27037
+ let theta = Math.acos( clamp$1( normals[ 0 ].dot( normals[ segments ] ), -1, 1 ) );
27038
+ theta /= segments;
27039
+
27040
+ if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
27041
+
27042
+ theta = - theta;
27043
+
27044
+ }
27045
+
27046
+ for ( let i = 1; i <= segments; i ++ ) {
27047
+
27048
+ // twist a little...
27049
+ normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
27050
+ binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
27051
+
27052
+ }
27053
+
27054
+ }
27055
+
27056
+ return {
27057
+ tangents: tangents,
27058
+ normals: normals,
27059
+ binormals: binormals
27060
+ };
27061
+
27062
+ }
27063
+
27064
+ /**
27065
+ * Returns a new curve with copied values from this instance.
27066
+ *
27067
+ * @return {Curve} A clone of this instance.
27068
+ */
27069
+ clone() {
27070
+
27071
+ return new this.constructor().copy( this );
27072
+
27073
+ }
27074
+
27075
+ /**
27076
+ * Copies the values of the given curve to this instance.
27077
+ *
27078
+ * @param {Curve} source - The curve to copy.
27079
+ * @return {Curve} A reference to this curve.
27080
+ */
27081
+ copy( source ) {
27082
+
27083
+ this.arcLengthDivisions = source.arcLengthDivisions;
27084
+
27085
+ this.cacheArcLengths = null;
27086
+
27087
+ return this;
27088
+
27089
+ }
27090
+
27091
+ /**
27092
+ * Serializes the curve into JSON.
27093
+ *
27094
+ * @return {Object} A JSON object representing the serialized curve.
27095
+ * @see {@link ObjectLoader#parse}
27096
+ */
27097
+ toJSON() {
27098
+
27099
+ const data = {
27100
+ metadata: {
27101
+ version: 4.7,
27102
+ type: 'Curve',
27103
+ generator: 'Curve.toJSON'
27104
+ }
27105
+ };
27106
+
27107
+ data.arcLengthDivisions = this.arcLengthDivisions;
27108
+ data.type = this.type;
27109
+
27110
+ return data;
27111
+
27112
+ }
27113
+
27114
+ /**
27115
+ * Deserializes the curve from the given JSON.
27116
+ *
27117
+ * @param {Object} json - The JSON holding the serialized curve.
27118
+ * @return {Curve} A reference to this curve.
27119
+ */
27120
+ fromJSON( json ) {
27121
+
27122
+ this.arcLengthDivisions = json.arcLengthDivisions;
27123
+
27124
+ this.cacheArcLengths = null;
27125
+
27126
+ return this;
27127
+
27128
+ }
27129
+
27130
+ }
27131
+
27132
+ /**
27133
+ * A curve representing an ellipse.
27134
+ *
27135
+ * ```js
27136
+ * const curve = new THREE.EllipseCurve(
27137
+ * 0, 0,
27138
+ * 10, 10,
27139
+ * 0, 2 * Math.PI,
27140
+ * false,
27141
+ * 0
27142
+ * );
27143
+ *
27144
+ * const points = curve.getPoints( 50 );
27145
+ * const geometry = new THREE.BufferGeometry().setFromPoints( points );
27146
+ *
27147
+ * const material = new THREE.LineBasicMaterial( { color: 0xff0000 } );
27148
+ *
27149
+ * // Create the final object to add to the scene
27150
+ * const ellipse = new THREE.Line( geometry, material );
27151
+ * ```
27152
+ *
27153
+ * @augments Curve
27154
+ */
27155
+ class EllipseCurve extends Curve {
27156
+
27157
+ /**
27158
+ * Constructs a new ellipse curve.
27159
+ *
27160
+ * @param {number} [aX=0] - The X center of the ellipse.
27161
+ * @param {number} [aY=0] - The Y center of the ellipse.
27162
+ * @param {number} [xRadius=1] - The radius of the ellipse in the x direction.
27163
+ * @param {number} [yRadius=1] - The radius of the ellipse in the y direction.
27164
+ * @param {number} [aStartAngle=0] - The start angle of the curve in radians starting from the positive X axis.
27165
+ * @param {number} [aEndAngle=Math.PI*2] - The end angle of the curve in radians starting from the positive X axis.
27166
+ * @param {boolean} [aClockwise=false] - Whether the ellipse is drawn clockwise or not.
27167
+ * @param {number} [aRotation=0] - The rotation angle of the ellipse in radians, counterclockwise from the positive X axis.
27168
+ */
27169
+ constructor( aX = 0, aY = 0, xRadius = 1, yRadius = 1, aStartAngle = 0, aEndAngle = Math.PI * 2, aClockwise = false, aRotation = 0 ) {
27170
+
27171
+ super();
27172
+
27173
+ /**
27174
+ * This flag can be used for type testing.
27175
+ *
27176
+ * @type {boolean}
27177
+ * @readonly
27178
+ * @default true
27179
+ */
27180
+ this.isEllipseCurve = true;
27181
+
27182
+ this.type = 'EllipseCurve';
27183
+
27184
+ /**
27185
+ * The X center of the ellipse.
27186
+ *
27187
+ * @type {number}
27188
+ * @default 0
27189
+ */
27190
+ this.aX = aX;
27191
+
27192
+ /**
27193
+ * The Y center of the ellipse.
27194
+ *
27195
+ * @type {number}
27196
+ * @default 0
27197
+ */
27198
+ this.aY = aY;
27199
+
27200
+ /**
27201
+ * The radius of the ellipse in the x direction.
27202
+ * Setting the this value equal to the {@link EllipseCurve#yRadius} will result in a circle.
27203
+ *
27204
+ * @type {number}
27205
+ * @default 1
27206
+ */
27207
+ this.xRadius = xRadius;
27208
+
27209
+ /**
27210
+ * The radius of the ellipse in the y direction.
27211
+ * Setting the this value equal to the {@link EllipseCurve#xRadius} will result in a circle.
27212
+ *
27213
+ * @type {number}
27214
+ * @default 1
27215
+ */
27216
+ this.yRadius = yRadius;
27217
+
27218
+ /**
27219
+ * The start angle of the curve in radians starting from the positive X axis.
27220
+ *
27221
+ * @type {number}
27222
+ * @default 0
27223
+ */
27224
+ this.aStartAngle = aStartAngle;
27225
+
27226
+ /**
27227
+ * The end angle of the curve in radians starting from the positive X axis.
27228
+ *
27229
+ * @type {number}
27230
+ * @default Math.PI*2
27231
+ */
27232
+ this.aEndAngle = aEndAngle;
27233
+
27234
+ /**
27235
+ * Whether the ellipse is drawn clockwise or not.
27236
+ *
27237
+ * @type {boolean}
27238
+ * @default false
27239
+ */
27240
+ this.aClockwise = aClockwise;
27241
+
27242
+ /**
27243
+ * The rotation angle of the ellipse in radians, counterclockwise from the positive X axis.
27244
+ *
27245
+ * @type {number}
27246
+ * @default 0
27247
+ */
27248
+ this.aRotation = aRotation;
27249
+
27250
+ }
27251
+
27252
+ /**
27253
+ * Returns a point on the curve.
27254
+ *
27255
+ * @param {number} t - A interpolation factor representing a position on the curve. Must be in the range `[0,1]`.
27256
+ * @param {Vector2} [optionalTarget] - The optional target vector the result is written to.
27257
+ * @return {Vector2} The position on the curve.
27258
+ */
27259
+ getPoint( t, optionalTarget = new Vector2() ) {
27260
+
27261
+ const point = optionalTarget;
27262
+
27263
+ const twoPi = Math.PI * 2;
27264
+ let deltaAngle = this.aEndAngle - this.aStartAngle;
27265
+ const samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
27266
+
27267
+ // ensures that deltaAngle is 0 .. 2 PI
27268
+ while ( deltaAngle < 0 ) deltaAngle += twoPi;
27269
+ while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
27270
+
27271
+ if ( deltaAngle < Number.EPSILON ) {
27272
+
27273
+ if ( samePoints ) {
27274
+
27275
+ deltaAngle = 0;
27276
+
27277
+ } else {
27278
+
27279
+ deltaAngle = twoPi;
27280
+
27281
+ }
27282
+
27283
+ }
27284
+
27285
+ if ( this.aClockwise === true && ! samePoints ) {
27286
+
27287
+ if ( deltaAngle === twoPi ) {
27288
+
27289
+ deltaAngle = - twoPi;
27290
+
27291
+ } else {
27292
+
27293
+ deltaAngle = deltaAngle - twoPi;
27294
+
27295
+ }
27296
+
27297
+ }
27298
+
27299
+ const angle = this.aStartAngle + t * deltaAngle;
27300
+ let x = this.aX + this.xRadius * Math.cos( angle );
27301
+ let y = this.aY + this.yRadius * Math.sin( angle );
27302
+
27303
+ if ( this.aRotation !== 0 ) {
27304
+
27305
+ const cos = Math.cos( this.aRotation );
27306
+ const sin = Math.sin( this.aRotation );
27307
+
27308
+ const tx = x - this.aX;
27309
+ const ty = y - this.aY;
27310
+
27311
+ // Rotate the point about the center of the ellipse.
27312
+ x = tx * cos - ty * sin + this.aX;
27313
+ y = tx * sin + ty * cos + this.aY;
27314
+
27315
+ }
27316
+
27317
+ return point.set( x, y );
27318
+
27319
+ }
27320
+
27321
+ copy( source ) {
27322
+
27323
+ super.copy( source );
27324
+
27325
+ this.aX = source.aX;
27326
+ this.aY = source.aY;
27327
+
27328
+ this.xRadius = source.xRadius;
27329
+ this.yRadius = source.yRadius;
27330
+
27331
+ this.aStartAngle = source.aStartAngle;
27332
+ this.aEndAngle = source.aEndAngle;
27333
+
27334
+ this.aClockwise = source.aClockwise;
27335
+
27336
+ this.aRotation = source.aRotation;
27337
+
27338
+ return this;
27339
+
27340
+ }
27341
+
27342
+ toJSON() {
27343
+
27344
+ const data = super.toJSON();
27345
+
27346
+ data.aX = this.aX;
27347
+ data.aY = this.aY;
27348
+
27349
+ data.xRadius = this.xRadius;
27350
+ data.yRadius = this.yRadius;
27351
+
27352
+ data.aStartAngle = this.aStartAngle;
27353
+ data.aEndAngle = this.aEndAngle;
27354
+
27355
+ data.aClockwise = this.aClockwise;
27356
+
27357
+ data.aRotation = this.aRotation;
27358
+
27359
+ return data;
27360
+
27361
+ }
27362
+
27363
+ fromJSON( json ) {
27364
+
27365
+ super.fromJSON( json );
27366
+
27367
+ this.aX = json.aX;
27368
+ this.aY = json.aY;
27369
+
27370
+ this.xRadius = json.xRadius;
27371
+ this.yRadius = json.yRadius;
27372
+
27373
+ this.aStartAngle = json.aStartAngle;
27374
+ this.aEndAngle = json.aEndAngle;
27375
+
27376
+ this.aClockwise = json.aClockwise;
27377
+
27378
+ this.aRotation = json.aRotation;
27379
+
27380
+ return this;
27381
+
27382
+ }
27383
+
27384
+ }
27385
+
26201
27386
  /**
26202
27387
  * A geometry class for representing a plane.
26203
27388
  *
@@ -34868,6 +36053,82 @@
34868
36053
 
34869
36054
  }
34870
36055
 
36056
+ /**
36057
+ * The helper is an object to define grids. Grids are two-dimensional
36058
+ * arrays of lines.
36059
+ *
36060
+ * ```js
36061
+ * const size = 10;
36062
+ * const divisions = 10;
36063
+ *
36064
+ * const gridHelper = new THREE.GridHelper( size, divisions );
36065
+ * scene.add( gridHelper );
36066
+ * ```
36067
+ *
36068
+ * @augments LineSegments
36069
+ */
36070
+ class GridHelper extends LineSegments {
36071
+
36072
+ /**
36073
+ * Constructs a new grid helper.
36074
+ *
36075
+ * @param {number} [size=10] - The size of the grid.
36076
+ * @param {number} [divisions=10] - The number of divisions across the grid.
36077
+ * @param {number|Color|string} [color1=0x444444] - The color of the center line.
36078
+ * @param {number|Color|string} [color2=0x888888] - The color of the lines of the grid.
36079
+ */
36080
+ constructor( size = 10, divisions = 10, color1 = 0x444444, color2 = 0x888888 ) {
36081
+
36082
+ color1 = new Color$1( color1 );
36083
+ color2 = new Color$1( color2 );
36084
+
36085
+ const center = divisions / 2;
36086
+ const step = size / divisions;
36087
+ const halfSize = size / 2;
36088
+
36089
+ const vertices = [], colors = [];
36090
+
36091
+ for ( let i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
36092
+
36093
+ vertices.push( - halfSize, 0, k, halfSize, 0, k );
36094
+ vertices.push( k, 0, - halfSize, k, 0, halfSize );
36095
+
36096
+ const color = i === center ? color1 : color2;
36097
+
36098
+ color.toArray( colors, j ); j += 3;
36099
+ color.toArray( colors, j ); j += 3;
36100
+ color.toArray( colors, j ); j += 3;
36101
+ color.toArray( colors, j ); j += 3;
36102
+
36103
+ }
36104
+
36105
+ const geometry = new BufferGeometry();
36106
+ geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
36107
+ geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
36108
+
36109
+ const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
36110
+
36111
+ super( geometry, material );
36112
+
36113
+ this.type = 'GridHelper';
36114
+
36115
+ }
36116
+
36117
+ /**
36118
+ * Frees the GPU-related resources allocated by this instance. Call this
36119
+ * method whenever this instance is no longer used in your app.
36120
+ */
36121
+ dispose() {
36122
+
36123
+ super.dispose();
36124
+
36125
+ this.geometry.dispose();
36126
+ this.material.dispose();
36127
+
36128
+ }
36129
+
36130
+ }
36131
+
34871
36132
  /**
34872
36133
  * Abstract base class for controls.
34873
36134
  *
@@ -135878,7 +137139,7 @@ var<${access}> ${ name } : ${ structName };`;
135878
137139
  * @event TrackballControls#change
135879
137140
  * @type {Object}
135880
137141
  */
135881
- const _changeEvent$2 = { type: 'change' };
137142
+ const _changeEvent$3 = { type: 'change' };
135882
137143
 
135883
137144
  /**
135884
137145
  * Fires when an interaction was initiated.
@@ -135886,7 +137147,7 @@ var<${access}> ${ name } : ${ structName };`;
135886
137147
  * @event TrackballControls#start
135887
137148
  * @type {Object}
135888
137149
  */
135889
- const _startEvent$1 = { type: 'start' };
137150
+ const _startEvent$2 = { type: 'start' };
135890
137151
 
135891
137152
  /**
135892
137153
  * Fires when an interaction has finished.
@@ -135894,9 +137155,9 @@ var<${access}> ${ name } : ${ structName };`;
135894
137155
  * @event TrackballControls#end
135895
137156
  * @type {Object}
135896
137157
  */
135897
- const _endEvent$1 = { type: 'end' };
137158
+ const _endEvent$2 = { type: 'end' };
135898
137159
 
135899
- const _EPS$2 = 0.000001;
137160
+ const _EPS$3 = 0.000001;
135900
137161
  const _STATE$1 = { NONE: -1, ROTATE: 0, ZOOM: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM_PAN: 4 };
135901
137162
 
135902
137163
  const _v2 = new Vector2();
@@ -136118,11 +137379,11 @@ var<${access}> ${ name } : ${ structName };`;
136118
137379
 
136119
137380
  // event listeners
136120
137381
 
136121
- this._onPointerMove = onPointerMove$2.bind( this );
136122
- this._onPointerDown = onPointerDown$2.bind( this );
136123
- this._onPointerUp = onPointerUp$2.bind( this );
136124
- this._onPointerCancel = onPointerCancel$1.bind( this );
136125
- this._onContextMenu = onContextMenu$2.bind( this );
137382
+ this._onPointerMove = onPointerMove$3.bind( this );
137383
+ this._onPointerDown = onPointerDown$3.bind( this );
137384
+ this._onPointerUp = onPointerUp$3.bind( this );
137385
+ this._onPointerCancel = onPointerCancel$2.bind( this );
137386
+ this._onContextMenu = onContextMenu$3.bind( this );
136126
137387
  this._onMouseWheel = onMouseWheel$1.bind( this );
136127
137388
  this._onKeyDown = onKeyDown$2.bind( this );
136128
137389
  this._onKeyUp = onKeyUp$1.bind( this );
@@ -136245,12 +137506,12 @@ var<${access}> ${ name } : ${ structName };`;
136245
137506
 
136246
137507
  this.object.lookAt( this.target );
136247
137508
 
136248
- const positionChanged = this._lastPosition.distanceToSquared( this.object.position ) > _EPS$2;
136249
- const rollChanged = this._lastUp.distanceToSquared( this.object.up ) > _EPS$2;
137509
+ const positionChanged = this._lastPosition.distanceToSquared( this.object.position ) > _EPS$3;
137510
+ const rollChanged = this._lastUp.distanceToSquared( this.object.up ) > _EPS$3;
136250
137511
 
136251
137512
  if ( positionChanged || rollChanged ) {
136252
137513
 
136253
- this.dispatchEvent( _changeEvent$2 );
137514
+ this.dispatchEvent( _changeEvent$3 );
136254
137515
 
136255
137516
  this._lastPosition.copy( this.object.position );
136256
137517
  this._lastUp.copy( this.object.up );
@@ -136261,13 +137522,13 @@ var<${access}> ${ name } : ${ structName };`;
136261
137522
 
136262
137523
  this.object.lookAt( this.target );
136263
137524
 
136264
- const positionChanged = this._lastPosition.distanceToSquared( this.object.position ) > _EPS$2;
136265
- const rollChanged = this._lastUp.distanceToSquared( this.object.up ) > _EPS$2;
137525
+ const positionChanged = this._lastPosition.distanceToSquared( this.object.position ) > _EPS$3;
137526
+ const rollChanged = this._lastUp.distanceToSquared( this.object.up ) > _EPS$3;
136266
137527
  const zoomChanged = this._lastZoom !== this.object.zoom;
136267
137528
 
136268
137529
  if ( positionChanged || rollChanged || zoomChanged ) {
136269
137530
 
136270
- this.dispatchEvent( _changeEvent$2 );
137531
+ this.dispatchEvent( _changeEvent$3 );
136271
137532
 
136272
137533
  this._lastPosition.copy( this.object.position );
136273
137534
  this._lastUp.copy( this.object.up );
@@ -136302,7 +137563,7 @@ var<${access}> ${ name } : ${ structName };`;
136302
137563
 
136303
137564
  this.object.lookAt( this.target );
136304
137565
 
136305
- this.dispatchEvent( _changeEvent$2 );
137566
+ this.dispatchEvent( _changeEvent$3 );
136306
137567
 
136307
137568
  this._lastPosition.copy( this.object.position );
136308
137569
  this._lastUp.copy( this.object.up );
@@ -136624,7 +137885,7 @@ var<${access}> ${ name } : ${ structName };`;
136624
137885
 
136625
137886
  }
136626
137887
 
136627
- function onPointerDown$2( event ) {
137888
+ function onPointerDown$3( event ) {
136628
137889
 
136629
137890
  if ( this.enabled === false ) return;
136630
137891
 
@@ -136653,7 +137914,7 @@ var<${access}> ${ name } : ${ structName };`;
136653
137914
 
136654
137915
  }
136655
137916
 
136656
- function onPointerMove$2( event ) {
137917
+ function onPointerMove$3( event ) {
136657
137918
 
136658
137919
  if ( this.enabled === false ) return;
136659
137920
 
@@ -136669,7 +137930,7 @@ var<${access}> ${ name } : ${ structName };`;
136669
137930
 
136670
137931
  }
136671
137932
 
136672
- function onPointerUp$2( event ) {
137933
+ function onPointerUp$3( event ) {
136673
137934
 
136674
137935
  if ( this.enabled === false ) return;
136675
137936
 
@@ -136698,7 +137959,7 @@ var<${access}> ${ name } : ${ structName };`;
136698
137959
 
136699
137960
  }
136700
137961
 
136701
- function onPointerCancel$1( event ) {
137962
+ function onPointerCancel$2( event ) {
136702
137963
 
136703
137964
  this._removePointer( event );
136704
137965
 
@@ -136801,7 +138062,7 @@ var<${access}> ${ name } : ${ structName };`;
136801
138062
 
136802
138063
  }
136803
138064
 
136804
- this.dispatchEvent( _startEvent$1 );
138065
+ this.dispatchEvent( _startEvent$2 );
136805
138066
 
136806
138067
  }
136807
138068
 
@@ -136829,7 +138090,7 @@ var<${access}> ${ name } : ${ structName };`;
136829
138090
 
136830
138091
  this.state = _STATE$1.NONE;
136831
138092
 
136832
- this.dispatchEvent( _endEvent$1 );
138093
+ this.dispatchEvent( _endEvent$2 );
136833
138094
 
136834
138095
  }
136835
138096
 
@@ -136860,12 +138121,12 @@ var<${access}> ${ name } : ${ structName };`;
136860
138121
 
136861
138122
  }
136862
138123
 
136863
- this.dispatchEvent( _startEvent$1 );
136864
- this.dispatchEvent( _endEvent$1 );
138124
+ this.dispatchEvent( _startEvent$2 );
138125
+ this.dispatchEvent( _endEvent$2 );
136865
138126
 
136866
138127
  }
136867
138128
 
136868
- function onContextMenu$2( event ) {
138129
+ function onContextMenu$3( event ) {
136869
138130
 
136870
138131
  if ( this.enabled === false ) return;
136871
138132
 
@@ -136899,7 +138160,7 @@ var<${access}> ${ name } : ${ structName };`;
136899
138160
 
136900
138161
  }
136901
138162
 
136902
- this.dispatchEvent( _startEvent$1 );
138163
+ this.dispatchEvent( _startEvent$2 );
136903
138164
 
136904
138165
  }
136905
138166
 
@@ -136964,7 +138225,3530 @@ var<${access}> ${ name } : ${ structName };`;
136964
138225
 
136965
138226
  }
136966
138227
 
136967
- this.dispatchEvent( _endEvent$1 );
138228
+ this.dispatchEvent( _endEvent$2 );
138229
+
138230
+ }
138231
+
138232
+ //trackball state
138233
+ const STATE = {
138234
+
138235
+ IDLE: Symbol(),
138236
+ ROTATE: Symbol(),
138237
+ PAN: Symbol(),
138238
+ SCALE: Symbol(),
138239
+ FOV: Symbol(),
138240
+ FOCUS: Symbol(),
138241
+ ZROTATE: Symbol(),
138242
+ ANIMATION_FOCUS: Symbol(),
138243
+ ANIMATION_ROTATE: Symbol()
138244
+
138245
+ };
138246
+
138247
+ const INPUT = {
138248
+
138249
+ NONE: Symbol(),
138250
+ ONE_FINGER: Symbol(),
138251
+ ONE_FINGER_SWITCHED: Symbol(),
138252
+ TWO_FINGER: Symbol(),
138253
+ MULT_FINGER: Symbol(),
138254
+ CURSOR: Symbol()
138255
+
138256
+ };
138257
+
138258
+ //cursor center coordinates
138259
+ const _center = {
138260
+
138261
+ x: 0,
138262
+ y: 0
138263
+
138264
+ };
138265
+
138266
+ //transformation matrices for gizmos and camera
138267
+ const _transformation = {
138268
+
138269
+ camera: new Matrix4(),
138270
+ gizmos: new Matrix4()
138271
+
138272
+ };
138273
+
138274
+ /**
138275
+ * Fires when the camera has been transformed by the controls.
138276
+ *
138277
+ * @event ArcballControls#change
138278
+ * @type {Object}
138279
+ */
138280
+ const _changeEvent$2 = { type: 'change' };
138281
+
138282
+ /**
138283
+ * Fires when an interaction was initiated.
138284
+ *
138285
+ * @event ArcballControls#start
138286
+ * @type {Object}
138287
+ */
138288
+ const _startEvent$1 = { type: 'start' };
138289
+
138290
+ /**
138291
+ * Fires when an interaction has finished.
138292
+ *
138293
+ * @event ArcballControls#end
138294
+ * @type {Object}
138295
+ */
138296
+ const _endEvent$1 = { type: 'end' };
138297
+
138298
+ const _raycaster = new Raycaster();
138299
+ const _offset = new Vector3();
138300
+
138301
+ const _gizmoMatrixStateTemp = new Matrix4();
138302
+ const _cameraMatrixStateTemp = new Matrix4();
138303
+ const _scalePointTemp = new Vector3();
138304
+
138305
+ const _EPS$2 = 0.000001;
138306
+
138307
+ /**
138308
+ * Arcball controls allow the camera to be controlled by a virtual trackball with full touch support and advanced navigation functionality.
138309
+ * Cursor/finger positions and movements are mapped over a virtual trackball surface represented by a gizmo and mapped in intuitive and
138310
+ * consistent camera movements. Dragging cursor/fingers will cause camera to orbit around the center of the trackball in a conservative
138311
+ * way (returning to the starting point will make the camera return to its starting orientation).
138312
+ *
138313
+ * In addition to supporting pan, zoom and pinch gestures, double clicking/tapping focuses on a point, intuitively moving the object's
138314
+ * point of interest to the center of the virtual trackball. Focus allows a much better inspection and navigation in complex environment.
138315
+ * Moreover Arcball controls allow FOV manipulation (in a vertigo-style method) and z-rotation. Saving and restoring of Camera State
138316
+ * is supported also through clipboard (use ctrl+c and ctrl+v shortcuts for copy and paste the state).
138317
+ *
138318
+ * Unlike {@link OrbitControls} and {@link TrackballControls}, `ArcballControls` doesn't require `update()` to be called externally in an
138319
+ * animation loop when animations are on.
138320
+ *
138321
+ * @augments Controls
138322
+ * @three_import import { ArcballControls } from 'three/addons/controls/ArcballControls.js';
138323
+ */
138324
+ class ArcballControls extends Controls {
138325
+
138326
+ /**
138327
+ * Constructs a new controls instance.
138328
+ *
138329
+ * @param {Camera} camera - The camera to be controlled. The camera must not be a child of another object, unless that object is the scene itself.
138330
+ * @param {?HTMLElement} [domElement=null] - The HTML element used for event listeners.
138331
+ * @param {?Scene} [scene=null] The scene rendered by the camera. If not given, gizmos cannot be shown.
138332
+ */
138333
+ constructor( camera, domElement = null, scene = null ) {
138334
+
138335
+ super( camera, domElement );
138336
+
138337
+ /**
138338
+ * The scene rendered by the camera. If not given, gizmos cannot be shown.
138339
+ *
138340
+ * @type {?Scene}
138341
+ * @default null
138342
+ */
138343
+ this.scene = scene;
138344
+
138345
+ /**
138346
+ * The control's focus point.
138347
+ *
138348
+ * @type {Vector3}
138349
+ */
138350
+ this.target = new Vector3();
138351
+ this._currentTarget = new Vector3();
138352
+
138353
+ /**
138354
+ * The size of the gizmo relative to the screen width and height.
138355
+ *
138356
+ * @type {number}
138357
+ * @default 0.67
138358
+ */
138359
+ this.radiusFactor = 0.67;
138360
+
138361
+ /**
138362
+ * Holds the mouse actions of this controls. This property is maintained by the methods
138363
+ * `setMouseAction()` and `unsetMouseAction()`.
138364
+ *
138365
+ * @type {Array<Object>}
138366
+ */
138367
+ this.mouseActions = [];
138368
+ this._mouseOp = null;
138369
+
138370
+
138371
+ //global vectors and matrices that are used in some operations to avoid creating new objects every time (e.g. every time cursor moves)
138372
+ this._v2_1 = new Vector2();
138373
+ this._v3_1 = new Vector3();
138374
+ this._v3_2 = new Vector3();
138375
+
138376
+ this._m4_1 = new Matrix4();
138377
+ this._m4_2 = new Matrix4();
138378
+
138379
+ this._quat = new Quaternion();
138380
+
138381
+ //transformation matrices
138382
+ this._translationMatrix = new Matrix4(); //matrix for translation operation
138383
+ this._rotationMatrix = new Matrix4(); //matrix for rotation operation
138384
+ this._scaleMatrix = new Matrix4(); //matrix for scaling operation
138385
+
138386
+ this._rotationAxis = new Vector3(); //axis for rotate operation
138387
+
138388
+
138389
+ //camera state
138390
+ this._cameraMatrixState = new Matrix4();
138391
+ this._cameraProjectionState = new Matrix4();
138392
+
138393
+ this._fovState = 1;
138394
+ this._upState = new Vector3();
138395
+ this._zoomState = 1;
138396
+ this._nearPos = 0;
138397
+ this._farPos = 0;
138398
+
138399
+ this._gizmoMatrixState = new Matrix4();
138400
+
138401
+ //initial values
138402
+ this._up0 = new Vector3();
138403
+ this._zoom0 = 1;
138404
+ this._fov0 = 0;
138405
+ this._initialNear = 0;
138406
+ this._nearPos0 = 0;
138407
+ this._initialFar = 0;
138408
+ this._farPos0 = 0;
138409
+ this._cameraMatrixState0 = new Matrix4();
138410
+ this._gizmoMatrixState0 = new Matrix4();
138411
+ this._target0 = new Vector3();
138412
+
138413
+ //pointers array
138414
+ this._button = -1;
138415
+ this._touchStart = [];
138416
+ this._touchCurrent = [];
138417
+ this._input = INPUT.NONE;
138418
+
138419
+ //two fingers touch interaction
138420
+ this._switchSensibility = 32; //minimum movement to be performed to fire single pan start after the second finger has been released
138421
+ this._startFingerDistance = 0; //distance between two fingers
138422
+ this._currentFingerDistance = 0;
138423
+ this._startFingerRotation = 0; //amount of rotation performed with two fingers
138424
+ this._currentFingerRotation = 0;
138425
+
138426
+ //double tap
138427
+ this._devPxRatio = 0;
138428
+ this._downValid = true;
138429
+ this._nclicks = 0;
138430
+ this._downEvents = [];
138431
+ this._downStart = 0; //pointerDown time
138432
+ this._clickStart = 0; //first click time
138433
+ this._maxDownTime = 250;
138434
+ this._maxInterval = 300;
138435
+ this._posThreshold = 24;
138436
+ this._movementThreshold = 24;
138437
+
138438
+ //cursor positions
138439
+ this._currentCursorPosition = new Vector3();
138440
+ this._startCursorPosition = new Vector3();
138441
+
138442
+ //grid
138443
+ this._grid = null; //grid to be visualized during pan operation
138444
+ this._gridPosition = new Vector3();
138445
+
138446
+ //gizmos
138447
+ this._gizmos = new Group$1();
138448
+ this._curvePts = 128;
138449
+
138450
+
138451
+ //animations
138452
+ this._timeStart = -1; //initial time
138453
+ this._animationId = -1;
138454
+
138455
+ /**
138456
+ * Duration of focus animations in ms.
138457
+ *
138458
+ * @type {number}
138459
+ * @default 500
138460
+ */
138461
+ this.focusAnimationTime = 500;
138462
+
138463
+ //rotate animation
138464
+ this._timePrev = 0; //time at which previous rotate operation has been detected
138465
+ this._timeCurrent = 0; //time at which current rotate operation has been detected
138466
+ this._anglePrev = 0; //angle of previous rotation
138467
+ this._angleCurrent = 0; //angle of current rotation
138468
+ this._cursorPosPrev = new Vector3(); //cursor position when previous rotate operation has been detected
138469
+ this._cursorPosCurr = new Vector3();//cursor position when current rotate operation has been detected
138470
+ this._wPrev = 0; //angular velocity of the previous rotate operation
138471
+ this._wCurr = 0; //angular velocity of the current rotate operation
138472
+
138473
+ //parameters
138474
+
138475
+ /**
138476
+ * If set to `true`, the camera's near and far values will be adjusted every time zoom is
138477
+ * performed trying to maintain the same visible portion given by initial near and far
138478
+ * values. Only works with perspective cameras.
138479
+ *
138480
+ * This feature only works as expected if the camera's initial state (position, near and far values)
138481
+ * is correctly configured before creating the controls. Otherwise {@link ArcballControls#setCamera}
138482
+ * must be called by the application.
138483
+ *
138484
+ * @type {boolean}
138485
+ * @default false
138486
+ */
138487
+ this.adjustNearFar = false;
138488
+
138489
+ /**
138490
+ * The scaling factor used when performing zoom operation.
138491
+ *
138492
+ * @type {number}
138493
+ * @default 1.1
138494
+ */
138495
+ this.scaleFactor = 1.1;
138496
+
138497
+ /**
138498
+ * The damping inertia used if 'enableAnimations` is set to `true`.
138499
+ *
138500
+ * @type {number}
138501
+ * @default 25
138502
+ */
138503
+ this.dampingFactor = 25;
138504
+
138505
+ /**
138506
+ * Maximum angular velocity allowed on rotation animation start.
138507
+ *
138508
+ * @type {number}
138509
+ * @default 20
138510
+ */
138511
+ this.wMax = 20;
138512
+
138513
+ /**
138514
+ * Set to `true` to enable animations for rotation (damping) and focus operation.
138515
+ *
138516
+ * @type {boolean}
138517
+ * @default true
138518
+ */
138519
+ this.enableAnimations = true;
138520
+
138521
+ /**
138522
+ * If set to `true`, a grid will appear when panning operation is being performed
138523
+ * (desktop interaction only).
138524
+ *
138525
+ * @type {boolean}
138526
+ * @default false
138527
+ */
138528
+ this.enableGrid = false;
138529
+
138530
+ /**
138531
+ * Set to `true` to make zoom become cursor centered.
138532
+ *
138533
+ * @type {boolean}
138534
+ * @default false
138535
+ */
138536
+ this.cursorZoom = false;
138537
+
138538
+ /**
138539
+ * The minimum FOV in degrees.
138540
+ *
138541
+ * @type {number}
138542
+ * @default 5
138543
+ */
138544
+ this.minFov = 5;
138545
+
138546
+ /**
138547
+ * The maximum FOV in degrees.
138548
+ *
138549
+ * @type {number}
138550
+ * @default 90
138551
+ */
138552
+ this.maxFov = 90;
138553
+
138554
+ /**
138555
+ * Speed of rotation.
138556
+ *
138557
+ * @type {number}
138558
+ * @default 1
138559
+ */
138560
+ this.rotateSpeed = 1;
138561
+
138562
+ /**
138563
+ * Enable or disable camera panning.
138564
+ *
138565
+ * @type {boolean}
138566
+ * @default true
138567
+ */
138568
+ this.enablePan = true;
138569
+
138570
+ /**
138571
+ * Enable or disable camera rotation.
138572
+ *
138573
+ * @type {boolean}
138574
+ * @default true
138575
+ */
138576
+ this.enableRotate = true;
138577
+
138578
+ /**
138579
+ * Enable or disable camera zoom.
138580
+ *
138581
+ * @type {boolean}
138582
+ * @default true
138583
+ */
138584
+ this.enableZoom = true;
138585
+
138586
+ /**
138587
+ * Enable or disable gizmos.
138588
+ *
138589
+ * @type {boolean}
138590
+ * @default true
138591
+ */
138592
+ this.enableGizmos = true;
138593
+
138594
+ /**
138595
+ * Enable or disable camera focusing on double-tap (or click) operations.
138596
+ *
138597
+ * @type {boolean}
138598
+ * @default true
138599
+ */
138600
+ this.enableFocus = true;
138601
+
138602
+ /**
138603
+ * How far you can dolly in. For perspective cameras only.
138604
+ *
138605
+ * @type {number}
138606
+ * @default 0
138607
+ */
138608
+ this.minDistance = 0;
138609
+
138610
+ /**
138611
+ * How far you can dolly out. For perspective cameras only.
138612
+ *
138613
+ * @type {number}
138614
+ * @default Infinity
138615
+ */
138616
+ this.maxDistance = Infinity;
138617
+
138618
+ /**
138619
+ * How far you can zoom in. For orthographic cameras only.
138620
+ *
138621
+ * @type {number}
138622
+ * @default 0
138623
+ */
138624
+ this.minZoom = 0;
138625
+
138626
+ /**
138627
+ * How far you can zoom out. For orthographic cameras only.
138628
+ *
138629
+ * @type {number}
138630
+ * @default Infinity
138631
+ */
138632
+ this.maxZoom = Infinity;
138633
+
138634
+ //trackball parameters
138635
+ this._tbRadius = 1;
138636
+
138637
+ //FSA
138638
+ this._state = STATE.IDLE;
138639
+
138640
+ this.setCamera( camera );
138641
+
138642
+ if ( this.scene != null ) {
138643
+
138644
+ this.scene.add( this._gizmos );
138645
+
138646
+ }
138647
+
138648
+ this.initializeMouseActions();
138649
+
138650
+ // event listeners
138651
+
138652
+ this._onContextMenu = onContextMenu$2.bind( this );
138653
+ this._onWheel = onWheel.bind( this );
138654
+ this._onPointerUp = onPointerUp$2.bind( this );
138655
+ this._onPointerMove = onPointerMove$2.bind( this );
138656
+ this._onPointerDown = onPointerDown$2.bind( this );
138657
+ this._onPointerCancel = onPointerCancel$1.bind( this );
138658
+ this._onWindowResize = onWindowResize.bind( this );
138659
+
138660
+ if ( domElement !== null ) {
138661
+
138662
+ this.connect( domElement );
138663
+
138664
+ }
138665
+
138666
+ }
138667
+
138668
+ connect( element ) {
138669
+
138670
+ super.connect( element );
138671
+
138672
+ this._devPxRatio = window.devicePixelRatio;
138673
+
138674
+ this.domElement.addEventListener( 'contextmenu', this._onContextMenu );
138675
+ this.domElement.addEventListener( 'wheel', this._onWheel, { passive: false } );
138676
+ this.domElement.addEventListener( 'pointerdown', this._onPointerDown );
138677
+ this.domElement.addEventListener( 'pointercancel', this._onPointerCancel );
138678
+
138679
+ window.addEventListener( 'resize', this._onWindowResize );
138680
+
138681
+ this.domElement.style.touchAction = 'none'; // Disable touch scroll
138682
+
138683
+ }
138684
+
138685
+ disconnect() {
138686
+
138687
+ this.domElement.removeEventListener( 'pointerdown', this._onPointerDown );
138688
+ this.domElement.removeEventListener( 'pointercancel', this._onPointerCancel );
138689
+ this.domElement.removeEventListener( 'wheel', this._onWheel );
138690
+ this.domElement.removeEventListener( 'contextmenu', this._onContextMenu );
138691
+
138692
+ window.removeEventListener( 'pointermove', this._onPointerMove );
138693
+ window.removeEventListener( 'pointerup', this._onPointerUp );
138694
+
138695
+ window.removeEventListener( 'resize', this._onWindowResize );
138696
+
138697
+ this.domElement.style.touchAction = ''; // Restore touch scroll
138698
+
138699
+ }
138700
+
138701
+ onSinglePanStart( event, operation ) {
138702
+
138703
+ if ( this.enabled ) {
138704
+
138705
+ this.dispatchEvent( _startEvent$1 );
138706
+
138707
+ this.setCenter( event.clientX, event.clientY );
138708
+
138709
+ switch ( operation ) {
138710
+
138711
+ case 'PAN':
138712
+
138713
+ if ( ! this.enablePan ) {
138714
+
138715
+ return;
138716
+
138717
+ }
138718
+
138719
+ if ( this._animationId != -1 ) {
138720
+
138721
+ cancelAnimationFrame( this._animationId );
138722
+ this._animationId = -1;
138723
+ this._timeStart = -1;
138724
+
138725
+ this.activateGizmos( false );
138726
+ this.dispatchEvent( _changeEvent$2 );
138727
+
138728
+ }
138729
+
138730
+ this.updateTbState( STATE.PAN, true );
138731
+ this._startCursorPosition.copy( this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement ) );
138732
+ if ( this.enableGrid ) {
138733
+
138734
+ this.drawGrid();
138735
+ this.dispatchEvent( _changeEvent$2 );
138736
+
138737
+ }
138738
+
138739
+ break;
138740
+
138741
+ case 'ROTATE':
138742
+
138743
+ if ( ! this.enableRotate ) {
138744
+
138745
+ return;
138746
+
138747
+ }
138748
+
138749
+ if ( this._animationId != -1 ) {
138750
+
138751
+ cancelAnimationFrame( this._animationId );
138752
+ this._animationId = -1;
138753
+ this._timeStart = -1;
138754
+
138755
+ }
138756
+
138757
+ this.updateTbState( STATE.ROTATE, true );
138758
+ this._startCursorPosition.copy( this.unprojectOnTbSurface( this.object, _center.x, _center.y, this.domElement, this._tbRadius ) );
138759
+ this.activateGizmos( true );
138760
+ if ( this.enableAnimations ) {
138761
+
138762
+ this._timePrev = this._timeCurrent = performance.now();
138763
+ this._angleCurrent = this._anglePrev = 0;
138764
+ this._cursorPosPrev.copy( this._startCursorPosition );
138765
+ this._cursorPosCurr.copy( this._cursorPosPrev );
138766
+ this._wCurr = 0;
138767
+ this._wPrev = this._wCurr;
138768
+
138769
+ }
138770
+
138771
+ this.dispatchEvent( _changeEvent$2 );
138772
+ break;
138773
+
138774
+ case 'FOV':
138775
+
138776
+ if ( ! this.object.isPerspectiveCamera || ! this.enableZoom ) {
138777
+
138778
+ return;
138779
+
138780
+ }
138781
+
138782
+ if ( this._animationId != -1 ) {
138783
+
138784
+ cancelAnimationFrame( this._animationId );
138785
+ this._animationId = -1;
138786
+ this._timeStart = -1;
138787
+
138788
+ this.activateGizmos( false );
138789
+ this.dispatchEvent( _changeEvent$2 );
138790
+
138791
+ }
138792
+
138793
+ this.updateTbState( STATE.FOV, true );
138794
+ this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
138795
+ this._currentCursorPosition.copy( this._startCursorPosition );
138796
+ break;
138797
+
138798
+ case 'ZOOM':
138799
+
138800
+ if ( ! this.enableZoom ) {
138801
+
138802
+ return;
138803
+
138804
+ }
138805
+
138806
+ if ( this._animationId != -1 ) {
138807
+
138808
+ cancelAnimationFrame( this._animationId );
138809
+ this._animationId = -1;
138810
+ this._timeStart = -1;
138811
+
138812
+ this.activateGizmos( false );
138813
+ this.dispatchEvent( _changeEvent$2 );
138814
+
138815
+ }
138816
+
138817
+ this.updateTbState( STATE.SCALE, true );
138818
+ this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
138819
+ this._currentCursorPosition.copy( this._startCursorPosition );
138820
+ break;
138821
+
138822
+ }
138823
+
138824
+ }
138825
+
138826
+ }
138827
+
138828
+ onSinglePanMove( event, opState ) {
138829
+
138830
+ if ( this.enabled ) {
138831
+
138832
+ const restart = opState != this._state;
138833
+ this.setCenter( event.clientX, event.clientY );
138834
+
138835
+ switch ( opState ) {
138836
+
138837
+ case STATE.PAN:
138838
+
138839
+ if ( this.enablePan ) {
138840
+
138841
+ if ( restart ) {
138842
+
138843
+ //switch to pan operation
138844
+
138845
+ this.dispatchEvent( _endEvent$1 );
138846
+ this.dispatchEvent( _startEvent$1 );
138847
+
138848
+ this.updateTbState( opState, true );
138849
+ this._startCursorPosition.copy( this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement ) );
138850
+ if ( this.enableGrid ) {
138851
+
138852
+ this.drawGrid();
138853
+
138854
+ }
138855
+
138856
+ this.activateGizmos( false );
138857
+
138858
+ } else {
138859
+
138860
+ //continue with pan operation
138861
+ this._currentCursorPosition.copy( this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement ) );
138862
+ this.applyTransformMatrix( this.pan( this._startCursorPosition, this._currentCursorPosition ) );
138863
+
138864
+ }
138865
+
138866
+ }
138867
+
138868
+ break;
138869
+
138870
+ case STATE.ROTATE:
138871
+
138872
+ if ( this.enableRotate ) {
138873
+
138874
+ if ( restart ) {
138875
+
138876
+ //switch to rotate operation
138877
+
138878
+ this.dispatchEvent( _endEvent$1 );
138879
+ this.dispatchEvent( _startEvent$1 );
138880
+
138881
+ this.updateTbState( opState, true );
138882
+ this._startCursorPosition.copy( this.unprojectOnTbSurface( this.object, _center.x, _center.y, this.domElement, this._tbRadius ) );
138883
+
138884
+ if ( this.enableGrid ) {
138885
+
138886
+ this.disposeGrid();
138887
+
138888
+ }
138889
+
138890
+ this.activateGizmos( true );
138891
+
138892
+ } else {
138893
+
138894
+ //continue with rotate operation
138895
+ this._currentCursorPosition.copy( this.unprojectOnTbSurface( this.object, _center.x, _center.y, this.domElement, this._tbRadius ) );
138896
+
138897
+ const distance = this._startCursorPosition.distanceTo( this._currentCursorPosition );
138898
+ const angle = this._startCursorPosition.angleTo( this._currentCursorPosition );
138899
+ const amount = Math.max( distance / this._tbRadius, angle ) * this.rotateSpeed; //effective rotation angle
138900
+
138901
+ this.applyTransformMatrix( this.rotate( this.calculateRotationAxis( this._startCursorPosition, this._currentCursorPosition ), amount ) );
138902
+
138903
+ if ( this.enableAnimations ) {
138904
+
138905
+ this._timePrev = this._timeCurrent;
138906
+ this._timeCurrent = performance.now();
138907
+ this._anglePrev = this._angleCurrent;
138908
+ this._angleCurrent = amount;
138909
+ this._cursorPosPrev.copy( this._cursorPosCurr );
138910
+ this._cursorPosCurr.copy( this._currentCursorPosition );
138911
+ this._wPrev = this._wCurr;
138912
+ this._wCurr = this.calculateAngularSpeed( this._anglePrev, this._angleCurrent, this._timePrev, this._timeCurrent );
138913
+
138914
+ }
138915
+
138916
+ }
138917
+
138918
+ }
138919
+
138920
+ break;
138921
+
138922
+ case STATE.SCALE:
138923
+
138924
+ if ( this.enableZoom ) {
138925
+
138926
+ if ( restart ) {
138927
+
138928
+ //switch to zoom operation
138929
+
138930
+ this.dispatchEvent( _endEvent$1 );
138931
+ this.dispatchEvent( _startEvent$1 );
138932
+
138933
+ this.updateTbState( opState, true );
138934
+ this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
138935
+ this._currentCursorPosition.copy( this._startCursorPosition );
138936
+
138937
+ if ( this.enableGrid ) {
138938
+
138939
+ this.disposeGrid();
138940
+
138941
+ }
138942
+
138943
+ this.activateGizmos( false );
138944
+
138945
+ } else {
138946
+
138947
+ //continue with zoom operation
138948
+ const screenNotches = 8; //how many wheel notches corresponds to a full screen pan
138949
+ this._currentCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
138950
+
138951
+ const movement = this._currentCursorPosition.y - this._startCursorPosition.y;
138952
+
138953
+ let size = 1;
138954
+
138955
+ if ( movement < 0 ) {
138956
+
138957
+ size = 1 / ( Math.pow( this.scaleFactor, - movement * screenNotches ) );
138958
+
138959
+ } else if ( movement > 0 ) {
138960
+
138961
+ size = Math.pow( this.scaleFactor, movement * screenNotches );
138962
+
138963
+ }
138964
+
138965
+ this._v3_1.setFromMatrixPosition( this._gizmoMatrixState );
138966
+
138967
+ this.applyTransformMatrix( this.scale( size, this._v3_1 ) );
138968
+
138969
+ }
138970
+
138971
+ }
138972
+
138973
+ break;
138974
+
138975
+ case STATE.FOV:
138976
+
138977
+ if ( this.enableZoom && this.object.isPerspectiveCamera ) {
138978
+
138979
+ if ( restart ) {
138980
+
138981
+ //switch to fov operation
138982
+
138983
+ this.dispatchEvent( _endEvent$1 );
138984
+ this.dispatchEvent( _startEvent$1 );
138985
+
138986
+ this.updateTbState( opState, true );
138987
+ this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
138988
+ this._currentCursorPosition.copy( this._startCursorPosition );
138989
+
138990
+ if ( this.enableGrid ) {
138991
+
138992
+ this.disposeGrid();
138993
+
138994
+ }
138995
+
138996
+ this.activateGizmos( false );
138997
+
138998
+ } else {
138999
+
139000
+ //continue with fov operation
139001
+ const screenNotches = 8; //how many wheel notches corresponds to a full screen pan
139002
+ this._currentCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
139003
+
139004
+ const movement = this._currentCursorPosition.y - this._startCursorPosition.y;
139005
+
139006
+ let size = 1;
139007
+
139008
+ if ( movement < 0 ) {
139009
+
139010
+ size = 1 / ( Math.pow( this.scaleFactor, - movement * screenNotches ) );
139011
+
139012
+ } else if ( movement > 0 ) {
139013
+
139014
+ size = Math.pow( this.scaleFactor, movement * screenNotches );
139015
+
139016
+ }
139017
+
139018
+ this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
139019
+ const x = this._v3_1.distanceTo( this._gizmos.position );
139020
+ let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
139021
+
139022
+ //check min and max distance
139023
+ xNew = MathUtils.clamp( xNew, this.minDistance, this.maxDistance );
139024
+
139025
+ const y = x * Math.tan( MathUtils.DEG2RAD * this._fovState * 0.5 );
139026
+
139027
+ //calculate new fov
139028
+ let newFov = MathUtils.RAD2DEG * ( Math.atan( y / xNew ) * 2 );
139029
+
139030
+ //check min and max fov
139031
+ newFov = MathUtils.clamp( newFov, this.minFov, this.maxFov );
139032
+
139033
+ const newDistance = y / Math.tan( MathUtils.DEG2RAD * ( newFov / 2 ) );
139034
+ size = x / newDistance;
139035
+ this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
139036
+
139037
+ this.setFov( newFov );
139038
+ this.applyTransformMatrix( this.scale( size, this._v3_2, false ) );
139039
+
139040
+ //adjusting distance
139041
+ _offset.copy( this._gizmos.position ).sub( this.object.position ).normalize().multiplyScalar( newDistance / x );
139042
+ this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
139043
+
139044
+ }
139045
+
139046
+ }
139047
+
139048
+ break;
139049
+
139050
+ }
139051
+
139052
+ this.dispatchEvent( _changeEvent$2 );
139053
+
139054
+ }
139055
+
139056
+ }
139057
+
139058
+ onSinglePanEnd() {
139059
+
139060
+ if ( this._state == STATE.ROTATE ) {
139061
+
139062
+
139063
+ if ( ! this.enableRotate ) {
139064
+
139065
+ return;
139066
+
139067
+ }
139068
+
139069
+ if ( this.enableAnimations ) {
139070
+
139071
+ //perform rotation animation
139072
+ const deltaTime = ( performance.now() - this._timeCurrent );
139073
+ if ( deltaTime < 120 ) {
139074
+
139075
+ const w = Math.abs( ( this._wPrev + this._wCurr ) / 2 );
139076
+
139077
+ const self = this;
139078
+ this._animationId = window.requestAnimationFrame( function ( t ) {
139079
+
139080
+ self.updateTbState( STATE.ANIMATION_ROTATE, true );
139081
+ const rotationAxis = self.calculateRotationAxis( self._cursorPosPrev, self._cursorPosCurr );
139082
+
139083
+ self.onRotationAnim( t, rotationAxis, Math.min( w, self.wMax ) );
139084
+
139085
+ } );
139086
+
139087
+ } else {
139088
+
139089
+ //cursor has been standing still for over 120 ms since last movement
139090
+ this.updateTbState( STATE.IDLE, false );
139091
+ this.activateGizmos( false );
139092
+ this.dispatchEvent( _changeEvent$2 );
139093
+
139094
+ }
139095
+
139096
+ } else {
139097
+
139098
+ this.updateTbState( STATE.IDLE, false );
139099
+ this.activateGizmos( false );
139100
+ this.dispatchEvent( _changeEvent$2 );
139101
+
139102
+ }
139103
+
139104
+ } else if ( this._state == STATE.PAN || this._state == STATE.IDLE ) {
139105
+
139106
+ this.updateTbState( STATE.IDLE, false );
139107
+
139108
+ if ( this.enableGrid ) {
139109
+
139110
+ this.disposeGrid();
139111
+
139112
+ }
139113
+
139114
+ this.activateGizmos( false );
139115
+ this.dispatchEvent( _changeEvent$2 );
139116
+
139117
+
139118
+ }
139119
+
139120
+ this.dispatchEvent( _endEvent$1 );
139121
+
139122
+ }
139123
+
139124
+ onDoubleTap( event ) {
139125
+
139126
+ if ( this.enabled && this.enablePan && this.enableFocus && this.scene != null ) {
139127
+
139128
+ this.dispatchEvent( _startEvent$1 );
139129
+
139130
+ this.setCenter( event.clientX, event.clientY );
139131
+ const hitP = this.unprojectOnObj( this.getCursorNDC( _center.x, _center.y, this.domElement ), this.object );
139132
+
139133
+ if ( hitP != null && this.enableAnimations ) {
139134
+
139135
+ const self = this;
139136
+ if ( this._animationId != -1 ) {
139137
+
139138
+ window.cancelAnimationFrame( this._animationId );
139139
+
139140
+ }
139141
+
139142
+ this._timeStart = -1;
139143
+ this._animationId = window.requestAnimationFrame( function ( t ) {
139144
+
139145
+ self.updateTbState( STATE.ANIMATION_FOCUS, true );
139146
+ self.onFocusAnim( t, hitP, self._cameraMatrixState, self._gizmoMatrixState );
139147
+
139148
+ } );
139149
+
139150
+ } else if ( hitP != null && ! this.enableAnimations ) {
139151
+
139152
+ this.updateTbState( STATE.FOCUS, true );
139153
+ this.focus( hitP, this.scaleFactor );
139154
+ this.updateTbState( STATE.IDLE, false );
139155
+ this.dispatchEvent( _changeEvent$2 );
139156
+
139157
+ }
139158
+
139159
+ }
139160
+
139161
+ this.dispatchEvent( _endEvent$1 );
139162
+
139163
+ }
139164
+
139165
+ onDoublePanStart() {
139166
+
139167
+ if ( this.enabled && this.enablePan ) {
139168
+
139169
+ this.dispatchEvent( _startEvent$1 );
139170
+
139171
+ this.updateTbState( STATE.PAN, true );
139172
+
139173
+ this.setCenter( ( this._touchCurrent[ 0 ].clientX + this._touchCurrent[ 1 ].clientX ) / 2, ( this._touchCurrent[ 0 ].clientY + this._touchCurrent[ 1 ].clientY ) / 2 );
139174
+ this._startCursorPosition.copy( this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement, true ) );
139175
+ this._currentCursorPosition.copy( this._startCursorPosition );
139176
+
139177
+ this.activateGizmos( false );
139178
+
139179
+ }
139180
+
139181
+ }
139182
+
139183
+ onDoublePanMove() {
139184
+
139185
+ if ( this.enabled && this.enablePan ) {
139186
+
139187
+ this.setCenter( ( this._touchCurrent[ 0 ].clientX + this._touchCurrent[ 1 ].clientX ) / 2, ( this._touchCurrent[ 0 ].clientY + this._touchCurrent[ 1 ].clientY ) / 2 );
139188
+
139189
+ if ( this._state != STATE.PAN ) {
139190
+
139191
+ this.updateTbState( STATE.PAN, true );
139192
+ this._startCursorPosition.copy( this._currentCursorPosition );
139193
+
139194
+ }
139195
+
139196
+ this._currentCursorPosition.copy( this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement, true ) );
139197
+ this.applyTransformMatrix( this.pan( this._startCursorPosition, this._currentCursorPosition, true ) );
139198
+ this.dispatchEvent( _changeEvent$2 );
139199
+
139200
+ }
139201
+
139202
+ }
139203
+
139204
+ onDoublePanEnd() {
139205
+
139206
+ this.updateTbState( STATE.IDLE, false );
139207
+ this.dispatchEvent( _endEvent$1 );
139208
+
139209
+ }
139210
+
139211
+ onRotateStart() {
139212
+
139213
+ if ( this.enabled && this.enableRotate ) {
139214
+
139215
+ this.dispatchEvent( _startEvent$1 );
139216
+
139217
+ this.updateTbState( STATE.ZROTATE, true );
139218
+
139219
+ //this._startFingerRotation = event.rotation;
139220
+
139221
+ this._startFingerRotation = this.getAngle( this._touchCurrent[ 1 ], this._touchCurrent[ 0 ] ) + this.getAngle( this._touchStart[ 1 ], this._touchStart[ 0 ] );
139222
+ this._currentFingerRotation = this._startFingerRotation;
139223
+
139224
+ this.object.getWorldDirection( this._rotationAxis ); //rotation axis
139225
+
139226
+ if ( ! this.enablePan && ! this.enableZoom ) {
139227
+
139228
+ this.activateGizmos( true );
139229
+
139230
+ }
139231
+
139232
+ }
139233
+
139234
+ }
139235
+
139236
+ onRotateMove() {
139237
+
139238
+ if ( this.enabled && this.enableRotate ) {
139239
+
139240
+ this.setCenter( ( this._touchCurrent[ 0 ].clientX + this._touchCurrent[ 1 ].clientX ) / 2, ( this._touchCurrent[ 0 ].clientY + this._touchCurrent[ 1 ].clientY ) / 2 );
139241
+ let rotationPoint;
139242
+
139243
+ if ( this._state != STATE.ZROTATE ) {
139244
+
139245
+ this.updateTbState( STATE.ZROTATE, true );
139246
+ this._startFingerRotation = this._currentFingerRotation;
139247
+
139248
+ }
139249
+
139250
+ //this._currentFingerRotation = event.rotation;
139251
+ this._currentFingerRotation = this.getAngle( this._touchCurrent[ 1 ], this._touchCurrent[ 0 ] ) + this.getAngle( this._touchStart[ 1 ], this._touchStart[ 0 ] );
139252
+
139253
+ if ( ! this.enablePan ) {
139254
+
139255
+ rotationPoint = new Vector3().setFromMatrixPosition( this._gizmoMatrixState );
139256
+
139257
+ } else {
139258
+
139259
+ this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
139260
+ rotationPoint = this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement ).applyQuaternion( this.object.quaternion ).multiplyScalar( 1 / this.object.zoom ).add( this._v3_2 );
139261
+
139262
+ }
139263
+
139264
+ const amount = MathUtils.DEG2RAD * ( this._startFingerRotation - this._currentFingerRotation );
139265
+
139266
+ this.applyTransformMatrix( this.zRotate( rotationPoint, amount ) );
139267
+ this.dispatchEvent( _changeEvent$2 );
139268
+
139269
+ }
139270
+
139271
+ }
139272
+
139273
+ onRotateEnd() {
139274
+
139275
+ this.updateTbState( STATE.IDLE, false );
139276
+ this.activateGizmos( false );
139277
+ this.dispatchEvent( _endEvent$1 );
139278
+
139279
+ }
139280
+
139281
+ onPinchStart() {
139282
+
139283
+ if ( this.enabled && this.enableZoom ) {
139284
+
139285
+ this.dispatchEvent( _startEvent$1 );
139286
+ this.updateTbState( STATE.SCALE, true );
139287
+
139288
+ this._startFingerDistance = this.calculatePointersDistance( this._touchCurrent[ 0 ], this._touchCurrent[ 1 ] );
139289
+ this._currentFingerDistance = this._startFingerDistance;
139290
+
139291
+ this.activateGizmos( false );
139292
+
139293
+ }
139294
+
139295
+ }
139296
+
139297
+ onPinchMove() {
139298
+
139299
+ if ( this.enabled && this.enableZoom ) {
139300
+
139301
+ this.setCenter( ( this._touchCurrent[ 0 ].clientX + this._touchCurrent[ 1 ].clientX ) / 2, ( this._touchCurrent[ 0 ].clientY + this._touchCurrent[ 1 ].clientY ) / 2 );
139302
+ const minDistance = 12; //minimum distance between fingers (in css pixels)
139303
+
139304
+ if ( this._state != STATE.SCALE ) {
139305
+
139306
+ this._startFingerDistance = this._currentFingerDistance;
139307
+ this.updateTbState( STATE.SCALE, true );
139308
+
139309
+ }
139310
+
139311
+ this._currentFingerDistance = Math.max( this.calculatePointersDistance( this._touchCurrent[ 0 ], this._touchCurrent[ 1 ] ), minDistance * this._devPxRatio );
139312
+ const amount = this._currentFingerDistance / this._startFingerDistance;
139313
+
139314
+ let scalePoint;
139315
+
139316
+ if ( ! this.enablePan ) {
139317
+
139318
+ scalePoint = this._gizmos.position;
139319
+
139320
+ } else {
139321
+
139322
+ if ( this.object.isOrthographicCamera ) {
139323
+
139324
+ scalePoint = this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement )
139325
+ .applyQuaternion( this.object.quaternion )
139326
+ .multiplyScalar( 1 / this.object.zoom )
139327
+ .add( this._gizmos.position );
139328
+
139329
+ } else if ( this.object.isPerspectiveCamera ) {
139330
+
139331
+ scalePoint = this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement )
139332
+ .applyQuaternion( this.object.quaternion )
139333
+ .add( this._gizmos.position );
139334
+
139335
+ }
139336
+
139337
+ }
139338
+
139339
+ this.applyTransformMatrix( this.scale( amount, scalePoint ) );
139340
+ this.dispatchEvent( _changeEvent$2 );
139341
+
139342
+ }
139343
+
139344
+ }
139345
+
139346
+ onPinchEnd() {
139347
+
139348
+ this.updateTbState( STATE.IDLE, false );
139349
+ this.dispatchEvent( _endEvent$1 );
139350
+
139351
+ }
139352
+
139353
+ onTriplePanStart() {
139354
+
139355
+ if ( this.enabled && this.enableZoom ) {
139356
+
139357
+ this.dispatchEvent( _startEvent$1 );
139358
+
139359
+ this.updateTbState( STATE.SCALE, true );
139360
+
139361
+ //const center = event.center;
139362
+ let clientX = 0;
139363
+ let clientY = 0;
139364
+ const nFingers = this._touchCurrent.length;
139365
+
139366
+ for ( let i = 0; i < nFingers; i ++ ) {
139367
+
139368
+ clientX += this._touchCurrent[ i ].clientX;
139369
+ clientY += this._touchCurrent[ i ].clientY;
139370
+
139371
+ }
139372
+
139373
+ this.setCenter( clientX / nFingers, clientY / nFingers );
139374
+
139375
+ this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
139376
+ this._currentCursorPosition.copy( this._startCursorPosition );
139377
+
139378
+ }
139379
+
139380
+ }
139381
+
139382
+ onTriplePanMove() {
139383
+
139384
+ if ( this.enabled && this.enableZoom ) {
139385
+
139386
+ // fov / 2
139387
+ // |\
139388
+ // | \
139389
+ // | \
139390
+ // x | \
139391
+ // | \
139392
+ // | \
139393
+ // | _ _ _\
139394
+ // y
139395
+
139396
+ //const center = event.center;
139397
+ let clientX = 0;
139398
+ let clientY = 0;
139399
+ const nFingers = this._touchCurrent.length;
139400
+
139401
+ for ( let i = 0; i < nFingers; i ++ ) {
139402
+
139403
+ clientX += this._touchCurrent[ i ].clientX;
139404
+ clientY += this._touchCurrent[ i ].clientY;
139405
+
139406
+ }
139407
+
139408
+ this.setCenter( clientX / nFingers, clientY / nFingers );
139409
+
139410
+ const screenNotches = 8; //how many wheel notches corresponds to a full screen pan
139411
+ this._currentCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
139412
+
139413
+ const movement = this._currentCursorPosition.y - this._startCursorPosition.y;
139414
+
139415
+ let size = 1;
139416
+
139417
+ if ( movement < 0 ) {
139418
+
139419
+ size = 1 / ( Math.pow( this.scaleFactor, - movement * screenNotches ) );
139420
+
139421
+ } else if ( movement > 0 ) {
139422
+
139423
+ size = Math.pow( this.scaleFactor, movement * screenNotches );
139424
+
139425
+ }
139426
+
139427
+ this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
139428
+ const x = this._v3_1.distanceTo( this._gizmos.position );
139429
+ let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
139430
+
139431
+ //check min and max distance
139432
+ xNew = MathUtils.clamp( xNew, this.minDistance, this.maxDistance );
139433
+
139434
+ const y = x * Math.tan( MathUtils.DEG2RAD * this._fovState * 0.5 );
139435
+
139436
+ //calculate new fov
139437
+ let newFov = MathUtils.RAD2DEG * ( Math.atan( y / xNew ) * 2 );
139438
+
139439
+ //check min and max fov
139440
+ newFov = MathUtils.clamp( newFov, this.minFov, this.maxFov );
139441
+
139442
+ const newDistance = y / Math.tan( MathUtils.DEG2RAD * ( newFov / 2 ) );
139443
+ size = x / newDistance;
139444
+ this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
139445
+
139446
+ this.setFov( newFov );
139447
+ this.applyTransformMatrix( this.scale( size, this._v3_2, false ) );
139448
+
139449
+ //adjusting distance
139450
+ _offset.copy( this._gizmos.position ).sub( this.object.position ).normalize().multiplyScalar( newDistance / x );
139451
+ this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
139452
+
139453
+ this.dispatchEvent( _changeEvent$2 );
139454
+
139455
+ }
139456
+
139457
+ }
139458
+
139459
+ onTriplePanEnd() {
139460
+
139461
+ this.updateTbState( STATE.IDLE, false );
139462
+ this.dispatchEvent( _endEvent$1 );
139463
+ //this.dispatchEvent( _changeEvent );
139464
+
139465
+ }
139466
+
139467
+ /**
139468
+ * Set _center's x/y coordinates.
139469
+ *
139470
+ * @private
139471
+ * @param {number} clientX - The x coordinate.
139472
+ * @param {number} clientY - The y coordinate.
139473
+ */
139474
+ setCenter( clientX, clientY ) {
139475
+
139476
+ _center.x = clientX;
139477
+ _center.y = clientY;
139478
+
139479
+ }
139480
+
139481
+ /**
139482
+ * Set default mouse actions.
139483
+ *
139484
+ * @private
139485
+ */
139486
+ initializeMouseActions() {
139487
+
139488
+ this.setMouseAction( 'PAN', 0, 'CTRL' );
139489
+ this.setMouseAction( 'PAN', 2 );
139490
+
139491
+ this.setMouseAction( 'ROTATE', 0 );
139492
+
139493
+ this.setMouseAction( 'ZOOM', 'WHEEL' );
139494
+ this.setMouseAction( 'ZOOM', 1 );
139495
+
139496
+ this.setMouseAction( 'FOV', 'WHEEL', 'SHIFT' );
139497
+ this.setMouseAction( 'FOV', 1, 'SHIFT' );
139498
+
139499
+
139500
+ }
139501
+
139502
+ /**
139503
+ * Compare two mouse actions.
139504
+ *
139505
+ * @private
139506
+ * @param {Object} action1 - The first mouse action.
139507
+ * @param {Object} action2 - The second mouse action.
139508
+ * @returns {boolean} `true` if action1 and action 2 are the same mouse action, `false` otherwise.
139509
+ */
139510
+ compareMouseAction( action1, action2 ) {
139511
+
139512
+ if ( action1.operation == action2.operation ) {
139513
+
139514
+ if ( action1.mouse == action2.mouse && action1.key == action2.key ) {
139515
+
139516
+ return true;
139517
+
139518
+ } else {
139519
+
139520
+ return false;
139521
+
139522
+ }
139523
+
139524
+ } else {
139525
+
139526
+ return false;
139527
+
139528
+ }
139529
+
139530
+ }
139531
+
139532
+ /**
139533
+ * Set a new mouse action by specifying the operation to be performed and a mouse/key combination. In case of conflict, replaces the existing one.
139534
+ *
139535
+ * @param {'PAN'|'ROTATE'|'ZOOM'|'FOV'} operation - The operation to be performed ('PAN', 'ROTATE', 'ZOOM', 'FOV').
139536
+ * @param {0|1|2|'WHEEL'} mouse - A mouse button (0, 1, 2) or 'WHEEL' for wheel notches.
139537
+ * @param {?('CTRL'|'SHIFT')} [key=null] - The keyboard modifier ('CTRL', 'SHIFT') or null if key is not needed.
139538
+ * @returns {boolean} `true` if the mouse action has been successfully added, `false` otherwise.
139539
+ */
139540
+ setMouseAction( operation, mouse, key = null ) {
139541
+
139542
+ const operationInput = [ 'PAN', 'ROTATE', 'ZOOM', 'FOV' ];
139543
+ const mouseInput = [ 0, 1, 2, 'WHEEL' ];
139544
+ const keyInput = [ 'CTRL', 'SHIFT', null ];
139545
+ let state;
139546
+
139547
+ if ( ! operationInput.includes( operation ) || ! mouseInput.includes( mouse ) || ! keyInput.includes( key ) ) {
139548
+
139549
+ //invalid parameters
139550
+ return false;
139551
+
139552
+ }
139553
+
139554
+ if ( mouse == 'WHEEL' ) {
139555
+
139556
+ if ( operation != 'ZOOM' && operation != 'FOV' ) {
139557
+
139558
+ //cannot associate 2D operation to 1D input
139559
+ return false;
139560
+
139561
+ }
139562
+
139563
+ }
139564
+
139565
+ switch ( operation ) {
139566
+
139567
+ case 'PAN':
139568
+
139569
+ state = STATE.PAN;
139570
+ break;
139571
+
139572
+ case 'ROTATE':
139573
+
139574
+ state = STATE.ROTATE;
139575
+ break;
139576
+
139577
+ case 'ZOOM':
139578
+
139579
+ state = STATE.SCALE;
139580
+ break;
139581
+
139582
+ case 'FOV':
139583
+
139584
+ state = STATE.FOV;
139585
+ break;
139586
+
139587
+ }
139588
+
139589
+ const action = {
139590
+
139591
+ operation: operation,
139592
+ mouse: mouse,
139593
+ key: key,
139594
+ state: state
139595
+
139596
+ };
139597
+
139598
+ for ( let i = 0; i < this.mouseActions.length; i ++ ) {
139599
+
139600
+ if ( this.mouseActions[ i ].mouse == action.mouse && this.mouseActions[ i ].key == action.key ) {
139601
+
139602
+ this.mouseActions.splice( i, 1, action );
139603
+ return true;
139604
+
139605
+ }
139606
+
139607
+ }
139608
+
139609
+ this.mouseActions.push( action );
139610
+ return true;
139611
+
139612
+ }
139613
+
139614
+ /**
139615
+ * Remove a mouse action by specifying its mouse/key combination.
139616
+ *
139617
+ * @param {0|1|2|'WHEEL'} mouse - A mouse button (0, 1, 2) or 'WHEEL' for wheel notches.
139618
+ * @param {?('CTRL'|'SHIFT')} key - The keyboard modifier ('CTRL', 'SHIFT') or null if key is not needed.
139619
+ * @returns {boolean} `true` if the operation has been successfully removed, `false` otherwise.
139620
+ */
139621
+ unsetMouseAction( mouse, key = null ) {
139622
+
139623
+ for ( let i = 0; i < this.mouseActions.length; i ++ ) {
139624
+
139625
+ if ( this.mouseActions[ i ].mouse == mouse && this.mouseActions[ i ].key == key ) {
139626
+
139627
+ this.mouseActions.splice( i, 1 );
139628
+ return true;
139629
+
139630
+ }
139631
+
139632
+ }
139633
+
139634
+ return false;
139635
+
139636
+ }
139637
+
139638
+ /**
139639
+ * Return the operation associated to a mouse/keyboard combination.
139640
+ *
139641
+ * @private
139642
+ * @param {0|1|2|'WHEEL'} mouse - Mouse button index (0, 1, 2) or 'WHEEL' for wheel notches.
139643
+ * @param {?('CTRL'|'SHIFT')} key - Keyboard modifier.
139644
+ * @returns {?('PAN'|'ROTATE'|'ZOOM'|'FOV')} The operation if it has been found, `null` otherwise.
139645
+ */
139646
+ getOpFromAction( mouse, key ) {
139647
+
139648
+ let action;
139649
+
139650
+ for ( let i = 0; i < this.mouseActions.length; i ++ ) {
139651
+
139652
+ action = this.mouseActions[ i ];
139653
+ if ( action.mouse == mouse && action.key == key ) {
139654
+
139655
+ return action.operation;
139656
+
139657
+ }
139658
+
139659
+ }
139660
+
139661
+ if ( key != null ) {
139662
+
139663
+ for ( let i = 0; i < this.mouseActions.length; i ++ ) {
139664
+
139665
+ action = this.mouseActions[ i ];
139666
+ if ( action.mouse == mouse && action.key == null ) {
139667
+
139668
+ return action.operation;
139669
+
139670
+ }
139671
+
139672
+ }
139673
+
139674
+ }
139675
+
139676
+ return null;
139677
+
139678
+ }
139679
+
139680
+ /**
139681
+ * Get the operation associated to mouse and key combination and returns the corresponding FSA state.
139682
+ *
139683
+ * @private
139684
+ * @param {0|1|2} mouse - Mouse button index (0, 1, 2)
139685
+ * @param {?('CTRL'|'SHIFT')} key - Keyboard modifier
139686
+ * @returns {?STATE} The FSA state obtained from the operation associated to mouse/keyboard combination.
139687
+ */
139688
+ getOpStateFromAction( mouse, key ) {
139689
+
139690
+ let action;
139691
+
139692
+ for ( let i = 0; i < this.mouseActions.length; i ++ ) {
139693
+
139694
+ action = this.mouseActions[ i ];
139695
+ if ( action.mouse == mouse && action.key == key ) {
139696
+
139697
+ return action.state;
139698
+
139699
+ }
139700
+
139701
+ }
139702
+
139703
+ if ( key != null ) {
139704
+
139705
+ for ( let i = 0; i < this.mouseActions.length; i ++ ) {
139706
+
139707
+ action = this.mouseActions[ i ];
139708
+ if ( action.mouse == mouse && action.key == null ) {
139709
+
139710
+ return action.state;
139711
+
139712
+ }
139713
+
139714
+ }
139715
+
139716
+ }
139717
+
139718
+ return null;
139719
+
139720
+ }
139721
+
139722
+ /**
139723
+ * Calculate the angle between two pointers.
139724
+ *
139725
+ * @private
139726
+ * @param {PointerEvent} p1 - The first pointer event.
139727
+ * @param {PointerEvent} p2 - The second pointer event.
139728
+ * @returns {number} The angle between two pointers in degrees.
139729
+ */
139730
+ getAngle( p1, p2 ) {
139731
+
139732
+ return Math.atan2( p2.clientY - p1.clientY, p2.clientX - p1.clientX ) * 180 / Math.PI;
139733
+
139734
+ }
139735
+
139736
+ /**
139737
+ * Updates a PointerEvent inside current pointerevents array.
139738
+ *
139739
+ * @private
139740
+ * @param {PointerEvent} event - The pointer event.
139741
+ */
139742
+ updateTouchEvent( event ) {
139743
+
139744
+ for ( let i = 0; i < this._touchCurrent.length; i ++ ) {
139745
+
139746
+ if ( this._touchCurrent[ i ].pointerId == event.pointerId ) {
139747
+
139748
+ this._touchCurrent.splice( i, 1, event );
139749
+ break;
139750
+
139751
+ }
139752
+
139753
+ }
139754
+
139755
+ }
139756
+
139757
+ /**
139758
+ * Applies a transformation matrix, to the camera and gizmos.
139759
+ *
139760
+ * @private
139761
+ * @param {Object} transformation - Object containing matrices to apply to camera and gizmos.
139762
+ */
139763
+ applyTransformMatrix( transformation ) {
139764
+
139765
+ if ( transformation.camera != null ) {
139766
+
139767
+ this._m4_1.copy( this._cameraMatrixState ).premultiply( transformation.camera );
139768
+ this._m4_1.decompose( this.object.position, this.object.quaternion, this.object.scale );
139769
+ this.object.updateMatrix();
139770
+
139771
+ //update camera up vector
139772
+ if ( this._state == STATE.ROTATE || this._state == STATE.ZROTATE || this._state == STATE.ANIMATION_ROTATE ) {
139773
+
139774
+ this.object.up.copy( this._upState ).applyQuaternion( this.object.quaternion );
139775
+
139776
+ }
139777
+
139778
+ }
139779
+
139780
+ if ( transformation.gizmos != null ) {
139781
+
139782
+ this._m4_1.copy( this._gizmoMatrixState ).premultiply( transformation.gizmos );
139783
+ this._m4_1.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
139784
+ this._gizmos.updateMatrix();
139785
+
139786
+ }
139787
+
139788
+ if ( this._state == STATE.SCALE || this._state == STATE.FOCUS || this._state == STATE.ANIMATION_FOCUS ) {
139789
+
139790
+ this._tbRadius = this.calculateTbRadius( this.object );
139791
+
139792
+ if ( this.adjustNearFar ) {
139793
+
139794
+ const cameraDistance = this.object.position.distanceTo( this._gizmos.position );
139795
+
139796
+ const bb = new Box3();
139797
+ bb.setFromObject( this._gizmos );
139798
+ const sphere = new Sphere();
139799
+ bb.getBoundingSphere( sphere );
139800
+
139801
+ const adjustedNearPosition = Math.max( this._nearPos0, sphere.radius + sphere.center.length() );
139802
+ const regularNearPosition = cameraDistance - this._initialNear;
139803
+
139804
+ const minNearPos = Math.min( adjustedNearPosition, regularNearPosition );
139805
+ this.object.near = cameraDistance - minNearPos;
139806
+
139807
+
139808
+ const adjustedFarPosition = Math.min( this._farPos0, - sphere.radius + sphere.center.length() );
139809
+ const regularFarPosition = cameraDistance - this._initialFar;
139810
+
139811
+ const minFarPos = Math.min( adjustedFarPosition, regularFarPosition );
139812
+ this.object.far = cameraDistance - minFarPos;
139813
+
139814
+ this.object.updateProjectionMatrix();
139815
+
139816
+ } else {
139817
+
139818
+ let update = false;
139819
+
139820
+ if ( this.object.near != this._initialNear ) {
139821
+
139822
+ this.object.near = this._initialNear;
139823
+ update = true;
139824
+
139825
+ }
139826
+
139827
+ if ( this.object.far != this._initialFar ) {
139828
+
139829
+ this.object.far = this._initialFar;
139830
+ update = true;
139831
+
139832
+ }
139833
+
139834
+ if ( update ) {
139835
+
139836
+ this.object.updateProjectionMatrix();
139837
+
139838
+ }
139839
+
139840
+ }
139841
+
139842
+ }
139843
+
139844
+ }
139845
+
139846
+ /**
139847
+ * Calculates the angular speed.
139848
+ *
139849
+ * @private
139850
+ * @param {number} p0 - Position at t0.
139851
+ * @param {number} p1 - Position at t1.
139852
+ * @param {number} t0 - Initial time in milliseconds.
139853
+ * @param {number} t1 - Ending time in milliseconds.
139854
+ * @returns {number} The angular speed.
139855
+ */
139856
+ calculateAngularSpeed( p0, p1, t0, t1 ) {
139857
+
139858
+ const s = p1 - p0;
139859
+ const t = ( t1 - t0 ) / 1000;
139860
+ if ( t == 0 ) {
139861
+
139862
+ return 0;
139863
+
139864
+ }
139865
+
139866
+ return s / t;
139867
+
139868
+ }
139869
+
139870
+ /**
139871
+ * Calculates the distance between two pointers.
139872
+ *
139873
+ * @private
139874
+ * @param {PointerEvent} p0 - The first pointer.
139875
+ * @param {PointerEvent} p1 - The second pointer.
139876
+ * @returns {number} The distance between the two pointers.
139877
+ */
139878
+ calculatePointersDistance( p0, p1 ) {
139879
+
139880
+ return Math.sqrt( Math.pow( p1.clientX - p0.clientX, 2 ) + Math.pow( p1.clientY - p0.clientY, 2 ) );
139881
+
139882
+ }
139883
+
139884
+ /**
139885
+ * Calculates the rotation axis as the vector perpendicular between two vectors.
139886
+ *
139887
+ * @private
139888
+ * @param {Vector3} vec1 - The first vector.
139889
+ * @param {Vector3} vec2 - The second vector.
139890
+ * @returns {Vector3} The normalized rotation axis.
139891
+ */
139892
+ calculateRotationAxis( vec1, vec2 ) {
139893
+
139894
+ this._rotationMatrix.extractRotation( this._cameraMatrixState );
139895
+ this._quat.setFromRotationMatrix( this._rotationMatrix );
139896
+
139897
+ this._rotationAxis.crossVectors( vec1, vec2 ).applyQuaternion( this._quat );
139898
+ return this._rotationAxis.normalize().clone();
139899
+
139900
+ }
139901
+
139902
+ /**
139903
+ * Calculates the trackball radius so that gizmo's diameter will be 2/3 of the minimum side of the camera frustum.
139904
+ *
139905
+ * @private
139906
+ * @param {Camera} camera - The camera.
139907
+ * @returns {number} The trackball radius.
139908
+ */
139909
+ calculateTbRadius( camera ) {
139910
+
139911
+ const distance = camera.position.distanceTo( this._gizmos.position );
139912
+
139913
+ if ( camera.type == 'PerspectiveCamera' ) {
139914
+
139915
+ const halfFovV = MathUtils.DEG2RAD * camera.fov * 0.5; //vertical fov/2 in radians
139916
+ const halfFovH = Math.atan( ( camera.aspect ) * Math.tan( halfFovV ) ); //horizontal fov/2 in radians
139917
+ return Math.tan( Math.min( halfFovV, halfFovH ) ) * distance * this.radiusFactor;
139918
+
139919
+ } else if ( camera.type == 'OrthographicCamera' ) {
139920
+
139921
+ return Math.min( camera.top, camera.right ) * this.radiusFactor;
139922
+
139923
+ }
139924
+
139925
+ }
139926
+
139927
+ /**
139928
+ * Focus operation consist of positioning the point of interest in front of the camera and a slightly zoom in.
139929
+ *
139930
+ * @private
139931
+ * @param {Vector3} point - The point of interest.
139932
+ * @param {number} size - Scale factor.
139933
+ * @param {number} [amount=1] - Amount of operation to be completed (used for focus animations, default is complete full operation).
139934
+ */
139935
+ focus( point, size, amount = 1 ) {
139936
+
139937
+ //move center of camera (along with gizmos) towards point of interest
139938
+ _offset.copy( point ).sub( this._gizmos.position ).multiplyScalar( amount );
139939
+ this._translationMatrix.makeTranslation( _offset.x, _offset.y, _offset.z );
139940
+
139941
+ _gizmoMatrixStateTemp.copy( this._gizmoMatrixState );
139942
+ this._gizmoMatrixState.premultiply( this._translationMatrix );
139943
+ this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
139944
+
139945
+ _cameraMatrixStateTemp.copy( this._cameraMatrixState );
139946
+ this._cameraMatrixState.premultiply( this._translationMatrix );
139947
+ this._cameraMatrixState.decompose( this.object.position, this.object.quaternion, this.object.scale );
139948
+
139949
+ //apply zoom
139950
+ if ( this.enableZoom ) {
139951
+
139952
+ this.applyTransformMatrix( this.scale( size, this._gizmos.position ) );
139953
+
139954
+ }
139955
+
139956
+ this._gizmoMatrixState.copy( _gizmoMatrixStateTemp );
139957
+ this._cameraMatrixState.copy( _cameraMatrixStateTemp );
139958
+
139959
+ }
139960
+
139961
+ /**
139962
+ * Creates a grid if necessary and adds it to the scene.
139963
+ *
139964
+ * @private
139965
+ */
139966
+ drawGrid() {
139967
+
139968
+ if ( this.scene != null ) {
139969
+
139970
+ const color = 0x888888;
139971
+ const multiplier = 3;
139972
+ let size, divisions, maxLength, tick;
139973
+
139974
+ if ( this.object.isOrthographicCamera ) {
139975
+
139976
+ const width = this.object.right - this.object.left;
139977
+ const height = this.object.bottom - this.object.top;
139978
+
139979
+ maxLength = Math.max( width, height );
139980
+ tick = maxLength / 20;
139981
+
139982
+ size = maxLength / this.object.zoom * multiplier;
139983
+ divisions = size / tick * this.object.zoom;
139984
+
139985
+ } else if ( this.object.isPerspectiveCamera ) {
139986
+
139987
+ const distance = this.object.position.distanceTo( this._gizmos.position );
139988
+ const halfFovV = MathUtils.DEG2RAD * this.object.fov * 0.5;
139989
+ const halfFovH = Math.atan( ( this.object.aspect ) * Math.tan( halfFovV ) );
139990
+
139991
+ maxLength = Math.tan( Math.max( halfFovV, halfFovH ) ) * distance * 2;
139992
+ tick = maxLength / 20;
139993
+
139994
+ size = maxLength * multiplier;
139995
+ divisions = size / tick;
139996
+
139997
+ }
139998
+
139999
+ if ( this._grid == null ) {
140000
+
140001
+ this._grid = new GridHelper( size, divisions, color, color );
140002
+ this._grid.position.copy( this._gizmos.position );
140003
+ this._gridPosition.copy( this._grid.position );
140004
+ this._grid.quaternion.copy( this.object.quaternion );
140005
+ this._grid.rotateX( Math.PI * 0.5 );
140006
+
140007
+ this.scene.add( this._grid );
140008
+
140009
+ }
140010
+
140011
+ }
140012
+
140013
+ }
140014
+
140015
+ dispose() {
140016
+
140017
+ if ( this._animationId != -1 ) {
140018
+
140019
+ window.cancelAnimationFrame( this._animationId );
140020
+
140021
+ }
140022
+
140023
+ this.disconnect();
140024
+
140025
+ if ( this.scene !== null ) this.scene.remove( this._gizmos );
140026
+ this.disposeGrid();
140027
+
140028
+ }
140029
+
140030
+ /**
140031
+ * Removes the grid from the scene.
140032
+ */
140033
+ disposeGrid() {
140034
+
140035
+ if ( this._grid != null && this.scene != null ) {
140036
+
140037
+ this.scene.remove( this._grid );
140038
+ this._grid = null;
140039
+
140040
+ }
140041
+
140042
+ }
140043
+
140044
+ /**
140045
+ * Computes the easing out cubic function for ease out effect in animation.
140046
+ *
140047
+ * @private
140048
+ * @param {number} t - The absolute progress of the animation in the bound of `0` (beginning of the) and `1` (ending of animation).
140049
+ * @returns {number} Result of easing out cubic at time `t`.
140050
+ */
140051
+ easeOutCubic( t ) {
140052
+
140053
+ return 1 - Math.pow( 1 - t, 3 );
140054
+
140055
+ }
140056
+
140057
+ /**
140058
+ * Makes rotation gizmos more or less visible.
140059
+ *
140060
+ * @param {boolean} isActive - If set to `true`, gizmos are more visible.
140061
+ */
140062
+ activateGizmos( isActive ) {
140063
+
140064
+ const gizmoX = this._gizmos.children[ 0 ];
140065
+ const gizmoY = this._gizmos.children[ 1 ];
140066
+ const gizmoZ = this._gizmos.children[ 2 ];
140067
+
140068
+ if ( isActive ) {
140069
+
140070
+ gizmoX.material.setValues( { opacity: 1 } );
140071
+ gizmoY.material.setValues( { opacity: 1 } );
140072
+ gizmoZ.material.setValues( { opacity: 1 } );
140073
+
140074
+ } else {
140075
+
140076
+ gizmoX.material.setValues( { opacity: 0.6 } );
140077
+ gizmoY.material.setValues( { opacity: 0.6 } );
140078
+ gizmoZ.material.setValues( { opacity: 0.6 } );
140079
+
140080
+ }
140081
+
140082
+ }
140083
+
140084
+ /**
140085
+ * Calculates the cursor position in NDC.
140086
+ *
140087
+ * @private
140088
+ * @param {number} cursorX - Cursor horizontal coordinate within the canvas.
140089
+ * @param {number} cursorY - Cursor vertical coordinate within the canvas.
140090
+ * @param {HTMLElement} canvas - The canvas where the renderer draws its output.
140091
+ * @returns {Vector2} Cursor normalized position inside the canvas.
140092
+ */
140093
+ getCursorNDC( cursorX, cursorY, canvas ) {
140094
+
140095
+ const canvasRect = canvas.getBoundingClientRect();
140096
+ this._v2_1.setX( ( ( cursorX - canvasRect.left ) / canvasRect.width ) * 2 - 1 );
140097
+ this._v2_1.setY( ( ( canvasRect.bottom - cursorY ) / canvasRect.height ) * 2 - 1 );
140098
+ return this._v2_1.clone();
140099
+
140100
+ }
140101
+
140102
+ /**
140103
+ * Calculates the cursor position inside the canvas x/y coordinates with the origin being in the center of the canvas.
140104
+ *
140105
+ * @private
140106
+ * @param {number} cursorX - Cursor horizontal coordinate within the canvas.
140107
+ * @param {number} cursorY - Cursor vertical coordinate within the canvas.
140108
+ * @param {HTMLElement} canvas - The canvas where the renderer draws its output.
140109
+ * @returns {Vector2} Cursor position inside the canvas.
140110
+ */
140111
+ getCursorPosition( cursorX, cursorY, canvas ) {
140112
+
140113
+ this._v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) );
140114
+ this._v2_1.x *= ( this.object.right - this.object.left ) * 0.5;
140115
+ this._v2_1.y *= ( this.object.top - this.object.bottom ) * 0.5;
140116
+ return this._v2_1.clone();
140117
+
140118
+ }
140119
+
140120
+ /**
140121
+ * Sets the camera to be controlled. Must be called in order to set a new camera to be controlled.
140122
+ *
140123
+ * @param {Camera} camera - The camera to be controlled.
140124
+ */
140125
+ setCamera( camera ) {
140126
+
140127
+ camera.lookAt( this.target );
140128
+ camera.updateMatrix();
140129
+
140130
+ //setting state
140131
+ if ( camera.type == 'PerspectiveCamera' ) {
140132
+
140133
+ this._fov0 = camera.fov;
140134
+ this._fovState = camera.fov;
140135
+
140136
+ }
140137
+
140138
+ this._cameraMatrixState0.copy( camera.matrix );
140139
+ this._cameraMatrixState.copy( this._cameraMatrixState0 );
140140
+ this._cameraProjectionState.copy( camera.projectionMatrix );
140141
+ this._zoom0 = camera.zoom;
140142
+ this._zoomState = this._zoom0;
140143
+
140144
+ this._initialNear = camera.near;
140145
+ this._nearPos0 = camera.position.distanceTo( this.target ) - camera.near;
140146
+ this._nearPos = this._initialNear;
140147
+
140148
+ this._initialFar = camera.far;
140149
+ this._farPos0 = camera.position.distanceTo( this.target ) - camera.far;
140150
+ this._farPos = this._initialFar;
140151
+
140152
+ this._up0.copy( camera.up );
140153
+ this._upState.copy( camera.up );
140154
+
140155
+ this.object = camera;
140156
+ this.object.updateProjectionMatrix();
140157
+
140158
+ //making gizmos
140159
+ this._tbRadius = this.calculateTbRadius( camera );
140160
+ this.makeGizmos( this.target, this._tbRadius );
140161
+
140162
+ }
140163
+
140164
+ /**
140165
+ * Sets gizmos visibility.
140166
+ *
140167
+ * @param {boolean} value - Value of gizmos visibility.
140168
+ */
140169
+ setGizmosVisible( value ) {
140170
+
140171
+ this._gizmos.visible = value;
140172
+ this.dispatchEvent( _changeEvent$2 );
140173
+
140174
+ }
140175
+
140176
+ /**
140177
+ * Sets gizmos radius factor and redraws gizmos.
140178
+ *
140179
+ * @param {number} value - Value of radius factor.
140180
+ */
140181
+ setTbRadius( value ) {
140182
+
140183
+ this.radiusFactor = value;
140184
+ this._tbRadius = this.calculateTbRadius( this.object );
140185
+
140186
+ const curve = new EllipseCurve( 0, 0, this._tbRadius, this._tbRadius );
140187
+ const points = curve.getPoints( this._curvePts );
140188
+ const curveGeometry = new BufferGeometry().setFromPoints( points );
140189
+
140190
+
140191
+ for ( const gizmo in this._gizmos.children ) {
140192
+
140193
+ this._gizmos.children[ gizmo ].geometry = curveGeometry;
140194
+
140195
+ }
140196
+
140197
+ this.dispatchEvent( _changeEvent$2 );
140198
+
140199
+ }
140200
+
140201
+ /**
140202
+ * Creates the rotation gizmos matching trackball center and radius.
140203
+ *
140204
+ * @private
140205
+ * @param {Vector3} tbCenter - The trackball center.
140206
+ * @param {number} tbRadius - The trackball radius.
140207
+ */
140208
+ makeGizmos( tbCenter, tbRadius ) {
140209
+
140210
+ const curve = new EllipseCurve( 0, 0, tbRadius, tbRadius );
140211
+ const points = curve.getPoints( this._curvePts );
140212
+
140213
+ //geometry
140214
+ const curveGeometry = new BufferGeometry().setFromPoints( points );
140215
+
140216
+ //material
140217
+ const curveMaterialX = new LineBasicMaterial( { color: 0xff8080, fog: false, transparent: true, opacity: 0.6 } );
140218
+ const curveMaterialY = new LineBasicMaterial( { color: 0x80ff80, fog: false, transparent: true, opacity: 0.6 } );
140219
+ const curveMaterialZ = new LineBasicMaterial( { color: 0x8080ff, fog: false, transparent: true, opacity: 0.6 } );
140220
+
140221
+ //line
140222
+ const gizmoX = new Line( curveGeometry, curveMaterialX );
140223
+ const gizmoY = new Line( curveGeometry, curveMaterialY );
140224
+ const gizmoZ = new Line( curveGeometry, curveMaterialZ );
140225
+
140226
+ const rotation = Math.PI * 0.5;
140227
+ gizmoX.rotation.y = rotation;
140228
+ gizmoY.rotation.x = rotation;
140229
+
140230
+
140231
+ //setting state
140232
+ this._gizmoMatrixState0.identity().setPosition( tbCenter );
140233
+ this._gizmoMatrixState.copy( this._gizmoMatrixState0 );
140234
+
140235
+ if ( this.object.zoom !== 1 ) {
140236
+
140237
+ //adapt gizmos size to camera zoom
140238
+ const size = 1 / this.object.zoom;
140239
+ this._scaleMatrix.makeScale( size, size, size );
140240
+ this._translationMatrix.makeTranslation( - tbCenter.x, - tbCenter.y, - tbCenter.z );
140241
+
140242
+ this._gizmoMatrixState.premultiply( this._translationMatrix ).premultiply( this._scaleMatrix );
140243
+ this._translationMatrix.makeTranslation( tbCenter.x, tbCenter.y, tbCenter.z );
140244
+ this._gizmoMatrixState.premultiply( this._translationMatrix );
140245
+
140246
+ }
140247
+
140248
+ this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
140249
+
140250
+ //
140251
+
140252
+ this._gizmos.traverse( function ( object ) {
140253
+
140254
+ if ( object.isLine ) {
140255
+
140256
+ object.geometry.dispose();
140257
+ object.material.dispose();
140258
+
140259
+ }
140260
+
140261
+ } );
140262
+
140263
+ this._gizmos.clear();
140264
+
140265
+ //
140266
+
140267
+ this._gizmos.add( gizmoX );
140268
+ this._gizmos.add( gizmoY );
140269
+ this._gizmos.add( gizmoZ );
140270
+
140271
+ }
140272
+
140273
+ /**
140274
+ * Performs animation for focus operation.
140275
+ *
140276
+ * @private
140277
+ * @param {number} time - Instant in which this function is called as performance.now().
140278
+ * @param {Vector3} point - Point of interest for focus operation.
140279
+ * @param {Matrix4} cameraMatrix - Camera matrix.
140280
+ * @param {Matrix4} gizmoMatrix - Gizmos matrix.
140281
+ */
140282
+ onFocusAnim( time, point, cameraMatrix, gizmoMatrix ) {
140283
+
140284
+ if ( this._timeStart == -1 ) {
140285
+
140286
+ //animation start
140287
+ this._timeStart = time;
140288
+
140289
+ }
140290
+
140291
+ if ( this._state == STATE.ANIMATION_FOCUS ) {
140292
+
140293
+ const deltaTime = time - this._timeStart;
140294
+ const animTime = deltaTime / this.focusAnimationTime;
140295
+
140296
+ this._gizmoMatrixState.copy( gizmoMatrix );
140297
+
140298
+ if ( animTime >= 1 ) {
140299
+
140300
+ //animation end
140301
+
140302
+ this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
140303
+
140304
+ this.focus( point, this.scaleFactor );
140305
+
140306
+ this._timeStart = -1;
140307
+ this.updateTbState( STATE.IDLE, false );
140308
+ this.activateGizmos( false );
140309
+
140310
+ this.dispatchEvent( _changeEvent$2 );
140311
+
140312
+ } else {
140313
+
140314
+ const amount = this.easeOutCubic( animTime );
140315
+ const size = ( ( 1 - amount ) + ( this.scaleFactor * amount ) );
140316
+
140317
+ this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
140318
+ this.focus( point, size, amount );
140319
+
140320
+ this.dispatchEvent( _changeEvent$2 );
140321
+ const self = this;
140322
+ this._animationId = window.requestAnimationFrame( function ( t ) {
140323
+
140324
+ self.onFocusAnim( t, point, cameraMatrix, gizmoMatrix.clone() );
140325
+
140326
+ } );
140327
+
140328
+ }
140329
+
140330
+ } else {
140331
+
140332
+ //interrupt animation
140333
+
140334
+ this._animationId = -1;
140335
+ this._timeStart = -1;
140336
+
140337
+ }
140338
+
140339
+ }
140340
+
140341
+ /**
140342
+ * Performs animation for rotation operation.
140343
+ *
140344
+ * @private
140345
+ * @param {number} time - Instant in which this function is called as performance.now().
140346
+ * @param {Vector3} rotationAxis - Rotation axis.
140347
+ * @param {number} w0 - Initial angular velocity.
140348
+ */
140349
+ onRotationAnim( time, rotationAxis, w0 ) {
140350
+
140351
+ if ( this._timeStart == -1 ) {
140352
+
140353
+ //animation start
140354
+ this._anglePrev = 0;
140355
+ this._angleCurrent = 0;
140356
+ this._timeStart = time;
140357
+
140358
+ }
140359
+
140360
+ if ( this._state == STATE.ANIMATION_ROTATE ) {
140361
+
140362
+ //w = w0 + alpha * t
140363
+ const deltaTime = ( time - this._timeStart ) / 1000;
140364
+ const w = w0 + ( ( - this.dampingFactor ) * deltaTime );
140365
+
140366
+ if ( w > 0 ) {
140367
+
140368
+ //tetha = 0.5 * alpha * t^2 + w0 * t + tetha0
140369
+ this._angleCurrent = 0.5 * ( - this.dampingFactor ) * Math.pow( deltaTime, 2 ) + w0 * deltaTime + 0;
140370
+ this.applyTransformMatrix( this.rotate( rotationAxis, this._angleCurrent ) );
140371
+ this.dispatchEvent( _changeEvent$2 );
140372
+ const self = this;
140373
+ this._animationId = window.requestAnimationFrame( function ( t ) {
140374
+
140375
+ self.onRotationAnim( t, rotationAxis, w0 );
140376
+
140377
+ } );
140378
+
140379
+ } else {
140380
+
140381
+ this._animationId = -1;
140382
+ this._timeStart = -1;
140383
+
140384
+ this.updateTbState( STATE.IDLE, false );
140385
+ this.activateGizmos( false );
140386
+
140387
+ this.dispatchEvent( _changeEvent$2 );
140388
+
140389
+ }
140390
+
140391
+ } else {
140392
+
140393
+ //interrupt animation
140394
+
140395
+ this._animationId = -1;
140396
+ this._timeStart = -1;
140397
+
140398
+ if ( this._state != STATE.ROTATE ) {
140399
+
140400
+ this.activateGizmos( false );
140401
+ this.dispatchEvent( _changeEvent$2 );
140402
+
140403
+ }
140404
+
140405
+ }
140406
+
140407
+ }
140408
+
140409
+
140410
+ /**
140411
+ * Performs pan operation moving camera between two points.
140412
+ *
140413
+ * @private
140414
+ * @param {Vector3} p0 - Initial point.
140415
+ * @param {Vector3} p1 - Ending point.
140416
+ * @param {boolean} [adjust=false] - If movement should be adjusted considering camera distance (Perspective only).
140417
+ * @returns {Object}
140418
+ */
140419
+ pan( p0, p1, adjust = false ) {
140420
+
140421
+ const movement = p0.clone().sub( p1 );
140422
+
140423
+ if ( this.object.isOrthographicCamera ) {
140424
+
140425
+ //adjust movement amount
140426
+ movement.multiplyScalar( 1 / this.object.zoom );
140427
+
140428
+ } else if ( this.object.isPerspectiveCamera && adjust ) {
140429
+
140430
+ //adjust movement amount
140431
+ this._v3_1.setFromMatrixPosition( this._cameraMatrixState0 ); //camera's initial position
140432
+ this._v3_2.setFromMatrixPosition( this._gizmoMatrixState0 ); //gizmo's initial position
140433
+ const distanceFactor = this._v3_1.distanceTo( this._v3_2 ) / this.object.position.distanceTo( this._gizmos.position );
140434
+ movement.multiplyScalar( 1 / distanceFactor );
140435
+
140436
+ }
140437
+
140438
+ this._v3_1.set( movement.x, movement.y, 0 ).applyQuaternion( this.object.quaternion );
140439
+
140440
+ this._m4_1.makeTranslation( this._v3_1.x, this._v3_1.y, this._v3_1.z );
140441
+
140442
+ this.setTransformationMatrices( this._m4_1, this._m4_1 );
140443
+ return _transformation;
140444
+
140445
+ }
140446
+
140447
+ /**
140448
+ * Resets the controls.
140449
+ */
140450
+ reset() {
140451
+
140452
+ this.target.copy( this._target0 );
140453
+ this.object.zoom = this._zoom0;
140454
+
140455
+ if ( this.object.isPerspectiveCamera ) {
140456
+
140457
+ this.object.fov = this._fov0;
140458
+
140459
+ }
140460
+
140461
+ this.object.near = this._nearPos;
140462
+ this.object.far = this._farPos;
140463
+ this._cameraMatrixState.copy( this._cameraMatrixState0 );
140464
+ this._cameraMatrixState.decompose( this.object.position, this.object.quaternion, this.object.scale );
140465
+ this.object.up.copy( this._up0 );
140466
+
140467
+ this.object.updateMatrix();
140468
+ this.object.updateProjectionMatrix();
140469
+
140470
+ this._gizmoMatrixState.copy( this._gizmoMatrixState0 );
140471
+ this._gizmoMatrixState0.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
140472
+ this._gizmos.updateMatrix();
140473
+
140474
+ this._tbRadius = this.calculateTbRadius( this.object );
140475
+ this.makeGizmos( this._gizmos.position, this._tbRadius );
140476
+
140477
+ this.object.lookAt( this._gizmos.position );
140478
+
140479
+ this.updateTbState( STATE.IDLE, false );
140480
+
140481
+ this.dispatchEvent( _changeEvent$2 );
140482
+
140483
+ }
140484
+
140485
+ /**
140486
+ * Rotates the camera around an axis passing by trackball's center.
140487
+ *
140488
+ * @private
140489
+ * @param {Vector3} axis - Rotation axis.
140490
+ * @param {number} angle - Angle in radians.
140491
+ * @returns {Object} Object with 'camera' field containing transformation matrix resulting from the operation to be applied to the camera.
140492
+ */
140493
+ rotate( axis, angle ) {
140494
+
140495
+ const point = this._gizmos.position; //rotation center
140496
+ this._translationMatrix.makeTranslation( - point.x, - point.y, - point.z );
140497
+ this._rotationMatrix.makeRotationAxis( axis, - angle );
140498
+
140499
+ //rotate camera
140500
+ this._m4_1.makeTranslation( point.x, point.y, point.z );
140501
+ this._m4_1.multiply( this._rotationMatrix );
140502
+ this._m4_1.multiply( this._translationMatrix );
140503
+
140504
+ this.setTransformationMatrices( this._m4_1 );
140505
+
140506
+ return _transformation;
140507
+
140508
+ }
140509
+
140510
+ /**
140511
+ * Copy the current state to clipboard (as a readable JSON text).
140512
+ */
140513
+ copyState() {
140514
+
140515
+ let state;
140516
+ if ( this.object.isOrthographicCamera ) {
140517
+
140518
+ state = JSON.stringify( {
140519
+ arcballState: {
140520
+ cameraFar: this.object.far,
140521
+ cameraMatrix: this.object.matrix,
140522
+ cameraNear: this.object.near,
140523
+ cameraUp: this.object.up,
140524
+ cameraZoom: this.object.zoom,
140525
+ gizmoMatrix: this._gizmos.matrix,
140526
+ target: this.target
140527
+
140528
+ }
140529
+ } );
140530
+
140531
+ } else if ( this.object.isPerspectiveCamera ) {
140532
+
140533
+ state = JSON.stringify( {
140534
+ arcballState: {
140535
+ cameraFar: this.object.far,
140536
+ cameraFov: this.object.fov,
140537
+ cameraMatrix: this.object.matrix,
140538
+ cameraNear: this.object.near,
140539
+ cameraUp: this.object.up,
140540
+ cameraZoom: this.object.zoom,
140541
+ gizmoMatrix: this._gizmos.matrix,
140542
+ target: this.target
140543
+
140544
+ }
140545
+ } );
140546
+
140547
+ }
140548
+
140549
+ navigator.clipboard.writeText( state );
140550
+
140551
+ }
140552
+
140553
+ /**
140554
+ * Set the controls state from the clipboard, assumes that the clipboard stores a JSON
140555
+ * text as saved from `copyState()`.
140556
+ */
140557
+ pasteState() {
140558
+
140559
+ const self = this;
140560
+ navigator.clipboard.readText().then( function resolved( value ) {
140561
+
140562
+ self.setStateFromJSON( value );
140563
+
140564
+ } );
140565
+
140566
+ }
140567
+
140568
+ /**
140569
+ * Saves the current state of the control. This can later be recover with `reset()`.
140570
+ */
140571
+ saveState() {
140572
+
140573
+ this.object.updateMatrix();
140574
+ this._gizmos.updateMatrix();
140575
+
140576
+ this._target0.copy( this.target );
140577
+ this._cameraMatrixState0.copy( this.object.matrix );
140578
+ this._gizmoMatrixState0.copy( this._gizmos.matrix );
140579
+ this._nearPos = this.object.near;
140580
+ this._farPos = this.object.far;
140581
+ this._zoom0 = this.object.zoom;
140582
+ this._up0.copy( this.object.up );
140583
+
140584
+ if ( this.object.isPerspectiveCamera ) {
140585
+
140586
+ this._fov0 = this.object.fov;
140587
+
140588
+ }
140589
+
140590
+ }
140591
+
140592
+ /**
140593
+ * Performs uniform scale operation around a given point.
140594
+ *
140595
+ * @private
140596
+ * @param {number} size - Scale factor.
140597
+ * @param {Vector3} point - Point around which scale.
140598
+ * @param {boolean} scaleGizmos - If gizmos should be scaled (Perspective only).
140599
+ * @returns {Object} Object with 'camera' and 'gizmo' fields containing transformation matrices resulting from the operation to be applied to the camera and gizmos.
140600
+ */
140601
+ scale( size, point, scaleGizmos = true ) {
140602
+
140603
+ _scalePointTemp.copy( point );
140604
+ let sizeInverse = 1 / size;
140605
+
140606
+ if ( this.object.isOrthographicCamera ) {
140607
+
140608
+ //camera zoom
140609
+ this.object.zoom = this._zoomState;
140610
+ this.object.zoom *= size;
140611
+
140612
+ //check min and max zoom
140613
+ if ( this.object.zoom > this.maxZoom ) {
140614
+
140615
+ this.object.zoom = this.maxZoom;
140616
+ sizeInverse = this._zoomState / this.maxZoom;
140617
+
140618
+ } else if ( this.object.zoom < this.minZoom ) {
140619
+
140620
+ this.object.zoom = this.minZoom;
140621
+ sizeInverse = this._zoomState / this.minZoom;
140622
+
140623
+ }
140624
+
140625
+ this.object.updateProjectionMatrix();
140626
+
140627
+ this._v3_1.setFromMatrixPosition( this._gizmoMatrixState ); //gizmos position
140628
+
140629
+ //scale gizmos so they appear in the same spot having the same dimension
140630
+ this._scaleMatrix.makeScale( sizeInverse, sizeInverse, sizeInverse );
140631
+ this._translationMatrix.makeTranslation( - this._v3_1.x, - this._v3_1.y, - this._v3_1.z );
140632
+
140633
+ this._m4_2.makeTranslation( this._v3_1.x, this._v3_1.y, this._v3_1.z ).multiply( this._scaleMatrix );
140634
+ this._m4_2.multiply( this._translationMatrix );
140635
+
140636
+
140637
+ //move camera and gizmos to obtain pinch effect
140638
+ _scalePointTemp.sub( this._v3_1 );
140639
+
140640
+ const amount = _scalePointTemp.clone().multiplyScalar( sizeInverse );
140641
+ _scalePointTemp.sub( amount );
140642
+
140643
+ this._m4_1.makeTranslation( _scalePointTemp.x, _scalePointTemp.y, _scalePointTemp.z );
140644
+ this._m4_2.premultiply( this._m4_1 );
140645
+
140646
+ this.setTransformationMatrices( this._m4_1, this._m4_2 );
140647
+ return _transformation;
140648
+
140649
+ } else if ( this.object.isPerspectiveCamera ) {
140650
+
140651
+ this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
140652
+ this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
140653
+
140654
+ //move camera
140655
+ let distance = this._v3_1.distanceTo( _scalePointTemp );
140656
+ let amount = distance - ( distance * sizeInverse );
140657
+
140658
+ //check min and max distance
140659
+ const newDistance = distance - amount;
140660
+ if ( newDistance < this.minDistance ) {
140661
+
140662
+ sizeInverse = this.minDistance / distance;
140663
+ amount = distance - ( distance * sizeInverse );
140664
+
140665
+ } else if ( newDistance > this.maxDistance ) {
140666
+
140667
+ sizeInverse = this.maxDistance / distance;
140668
+ amount = distance - ( distance * sizeInverse );
140669
+
140670
+ }
140671
+
140672
+ _offset.copy( _scalePointTemp ).sub( this._v3_1 ).normalize().multiplyScalar( amount );
140673
+
140674
+ this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
140675
+
140676
+
140677
+ if ( scaleGizmos ) {
140678
+
140679
+ //scale gizmos so they appear in the same spot having the same dimension
140680
+ const pos = this._v3_2;
140681
+
140682
+ distance = pos.distanceTo( _scalePointTemp );
140683
+ amount = distance - ( distance * sizeInverse );
140684
+ _offset.copy( _scalePointTemp ).sub( this._v3_2 ).normalize().multiplyScalar( amount );
140685
+
140686
+ this._translationMatrix.makeTranslation( pos.x, pos.y, pos.z );
140687
+ this._scaleMatrix.makeScale( sizeInverse, sizeInverse, sizeInverse );
140688
+
140689
+ this._m4_2.makeTranslation( _offset.x, _offset.y, _offset.z ).multiply( this._translationMatrix );
140690
+ this._m4_2.multiply( this._scaleMatrix );
140691
+
140692
+ this._translationMatrix.makeTranslation( - pos.x, - pos.y, - pos.z );
140693
+
140694
+ this._m4_2.multiply( this._translationMatrix );
140695
+ this.setTransformationMatrices( this._m4_1, this._m4_2 );
140696
+
140697
+
140698
+ } else {
140699
+
140700
+ this.setTransformationMatrices( this._m4_1 );
140701
+
140702
+ }
140703
+
140704
+ return _transformation;
140705
+
140706
+ }
140707
+
140708
+ }
140709
+
140710
+ /**
140711
+ * Sets camera fov.
140712
+ *
140713
+ * @private
140714
+ * @param {number} value - The FOV to be set.
140715
+ */
140716
+ setFov( value ) {
140717
+
140718
+ if ( this.object.isPerspectiveCamera ) {
140719
+
140720
+ this.object.fov = MathUtils.clamp( value, this.minFov, this.maxFov );
140721
+ this.object.updateProjectionMatrix();
140722
+
140723
+ }
140724
+
140725
+ }
140726
+
140727
+ /**
140728
+ * Sets values in transformation object.
140729
+ *
140730
+ * @private
140731
+ * @param {?Matrix4} [camera=null] - Transformation to be applied to the camera.
140732
+ * @param {?Matrix4} [gizmos=null] - Transformation to be applied to gizmos.
140733
+ */
140734
+ setTransformationMatrices( camera = null, gizmos = null ) {
140735
+
140736
+ if ( camera != null ) {
140737
+
140738
+ if ( _transformation.camera != null ) {
140739
+
140740
+ _transformation.camera.copy( camera );
140741
+
140742
+ } else {
140743
+
140744
+ _transformation.camera = camera.clone();
140745
+
140746
+ }
140747
+
140748
+ } else {
140749
+
140750
+ _transformation.camera = null;
140751
+
140752
+ }
140753
+
140754
+ if ( gizmos != null ) {
140755
+
140756
+ if ( _transformation.gizmos != null ) {
140757
+
140758
+ _transformation.gizmos.copy( gizmos );
140759
+
140760
+ } else {
140761
+
140762
+ _transformation.gizmos = gizmos.clone();
140763
+
140764
+ }
140765
+
140766
+ } else {
140767
+
140768
+ _transformation.gizmos = null;
140769
+
140770
+ }
140771
+
140772
+ }
140773
+
140774
+ /**
140775
+ * Rotates camera around its direction axis passing by a given point by a given angle.
140776
+ *
140777
+ * @private
140778
+ * @param {Vector3} point - The point where the rotation axis is passing through.
140779
+ * @param {number} angle - Angle in radians.
140780
+ * @returns {Object} The computed transformation matrix.
140781
+ */
140782
+ zRotate( point, angle ) {
140783
+
140784
+ this._rotationMatrix.makeRotationAxis( this._rotationAxis, angle );
140785
+ this._translationMatrix.makeTranslation( - point.x, - point.y, - point.z );
140786
+
140787
+ this._m4_1.makeTranslation( point.x, point.y, point.z );
140788
+ this._m4_1.multiply( this._rotationMatrix );
140789
+ this._m4_1.multiply( this._translationMatrix );
140790
+
140791
+ this._v3_1.setFromMatrixPosition( this._gizmoMatrixState ).sub( point ); //vector from rotation center to gizmos position
140792
+ this._v3_2.copy( this._v3_1 ).applyAxisAngle( this._rotationAxis, angle ); //apply rotation
140793
+ this._v3_2.sub( this._v3_1 );
140794
+
140795
+ this._m4_2.makeTranslation( this._v3_2.x, this._v3_2.y, this._v3_2.z );
140796
+
140797
+ this.setTransformationMatrices( this._m4_1, this._m4_2 );
140798
+ return _transformation;
140799
+
140800
+ }
140801
+
140802
+ /**
140803
+ * Returns the raycaster that is used for user interaction. This object is shared between all
140804
+ * instances of `ArcballControls`.
140805
+ *
140806
+ * @returns {Raycaster} The internal raycaster.
140807
+ */
140808
+ getRaycaster() {
140809
+
140810
+ return _raycaster;
140811
+
140812
+ }
140813
+
140814
+
140815
+ /**
140816
+ * Unprojects the cursor on the 3D object surface.
140817
+ *
140818
+ * @private
140819
+ * @param {Vector2} cursor - Cursor coordinates in NDC.
140820
+ * @param {Camera} camera - Virtual camera.
140821
+ * @returns {?Vector3} The point of intersection with the model, if exist, null otherwise.
140822
+ */
140823
+ unprojectOnObj( cursor, camera ) {
140824
+
140825
+ const raycaster = this.getRaycaster();
140826
+ raycaster.near = camera.near;
140827
+ raycaster.far = camera.far;
140828
+ raycaster.setFromCamera( cursor, camera );
140829
+
140830
+ const intersect = raycaster.intersectObjects( this.scene.children, true );
140831
+
140832
+ for ( let i = 0; i < intersect.length; i ++ ) {
140833
+
140834
+ if ( intersect[ i ].object.uuid != this._gizmos.uuid && intersect[ i ].face != null ) {
140835
+
140836
+ return intersect[ i ].point.clone();
140837
+
140838
+ }
140839
+
140840
+ }
140841
+
140842
+ return null;
140843
+
140844
+ }
140845
+
140846
+ /**
140847
+ * Unproject the cursor on the trackball surface.
140848
+ *
140849
+ * @private
140850
+ * @param {Camera} camera - The virtual camera.
140851
+ * @param {number} cursorX - Cursor horizontal coordinate on screen.
140852
+ * @param {number} cursorY - Cursor vertical coordinate on screen.
140853
+ * @param {HTMLElement} canvas - The canvas where the renderer draws its output.
140854
+ * @param {number} tbRadius - The trackball radius.
140855
+ * @returns {Vector3} The unprojected point on the trackball surface.
140856
+ */
140857
+ unprojectOnTbSurface( camera, cursorX, cursorY, canvas, tbRadius ) {
140858
+
140859
+ if ( camera.type == 'OrthographicCamera' ) {
140860
+
140861
+ this._v2_1.copy( this.getCursorPosition( cursorX, cursorY, canvas ) );
140862
+ this._v3_1.set( this._v2_1.x, this._v2_1.y, 0 );
140863
+
140864
+ const x2 = Math.pow( this._v2_1.x, 2 );
140865
+ const y2 = Math.pow( this._v2_1.y, 2 );
140866
+ const r2 = Math.pow( this._tbRadius, 2 );
140867
+
140868
+ if ( x2 + y2 <= r2 * 0.5 ) {
140869
+
140870
+ //intersection with sphere
140871
+ this._v3_1.setZ( Math.sqrt( r2 - ( x2 + y2 ) ) );
140872
+
140873
+ } else {
140874
+
140875
+ //intersection with hyperboloid
140876
+ this._v3_1.setZ( ( r2 * 0.5 ) / ( Math.sqrt( x2 + y2 ) ) );
140877
+
140878
+ }
140879
+
140880
+ return this._v3_1;
140881
+
140882
+ } else if ( camera.type == 'PerspectiveCamera' ) {
140883
+
140884
+ //unproject cursor on the near plane
140885
+ this._v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) );
140886
+
140887
+ this._v3_1.set( this._v2_1.x, this._v2_1.y, -1 );
140888
+ this._v3_1.applyMatrix4( camera.projectionMatrixInverse );
140889
+
140890
+ const rayDir = this._v3_1.clone().normalize(); //unprojected ray direction
140891
+ const cameraGizmoDistance = camera.position.distanceTo( this._gizmos.position );
140892
+ const radius2 = Math.pow( tbRadius, 2 );
140893
+
140894
+ // camera
140895
+ // |\
140896
+ // | \
140897
+ // | \
140898
+ // h | \
140899
+ // | \
140900
+ // | \
140901
+ // _ _ | _ _ _\ _ _ near plane
140902
+ // l
140903
+
140904
+ const h = this._v3_1.z;
140905
+ const l = Math.sqrt( Math.pow( this._v3_1.x, 2 ) + Math.pow( this._v3_1.y, 2 ) );
140906
+
140907
+ if ( l == 0 ) {
140908
+
140909
+ //ray aligned with camera
140910
+ rayDir.set( this._v3_1.x, this._v3_1.y, tbRadius );
140911
+ return rayDir;
140912
+
140913
+ }
140914
+
140915
+ const m = h / l;
140916
+ const q = cameraGizmoDistance;
140917
+
140918
+ /*
140919
+ * calculate intersection point between unprojected ray and trackball surface
140920
+ *|y = m * x + q
140921
+ *|x^2 + y^2 = r^2
140922
+ *
140923
+ * (m^2 + 1) * x^2 + (2 * m * q) * x + q^2 - r^2 = 0
140924
+ */
140925
+ let a = Math.pow( m, 2 ) + 1;
140926
+ let b = 2 * m * q;
140927
+ let c = Math.pow( q, 2 ) - radius2;
140928
+ let delta = Math.pow( b, 2 ) - ( 4 * a * c );
140929
+
140930
+ if ( delta >= 0 ) {
140931
+
140932
+ //intersection with sphere
140933
+ this._v2_1.setX( ( - b - Math.sqrt( delta ) ) / ( 2 * a ) );
140934
+ this._v2_1.setY( m * this._v2_1.x + q );
140935
+
140936
+ const angle = MathUtils.RAD2DEG * this._v2_1.angle();
140937
+
140938
+ if ( angle >= 45 ) {
140939
+
140940
+ //if angle between intersection point and X' axis is >= 45°, return that point
140941
+ //otherwise, calculate intersection point with hyperboloid
140942
+
140943
+ const rayLength = Math.sqrt( Math.pow( this._v2_1.x, 2 ) + Math.pow( ( cameraGizmoDistance - this._v2_1.y ), 2 ) );
140944
+ rayDir.multiplyScalar( rayLength );
140945
+ rayDir.z += cameraGizmoDistance;
140946
+ return rayDir;
140947
+
140948
+ }
140949
+
140950
+ }
140951
+
140952
+ //intersection with hyperboloid
140953
+ /*
140954
+ *|y = m * x + q
140955
+ *|y = (1 / x) * (r^2 / 2)
140956
+ *
140957
+ * m * x^2 + q * x - r^2 / 2 = 0
140958
+ */
140959
+
140960
+ a = m;
140961
+ b = q;
140962
+ c = - radius2 * 0.5;
140963
+ delta = Math.pow( b, 2 ) - ( 4 * a * c );
140964
+ this._v2_1.setX( ( - b - Math.sqrt( delta ) ) / ( 2 * a ) );
140965
+ this._v2_1.setY( m * this._v2_1.x + q );
140966
+
140967
+ const rayLength = Math.sqrt( Math.pow( this._v2_1.x, 2 ) + Math.pow( ( cameraGizmoDistance - this._v2_1.y ), 2 ) );
140968
+
140969
+ rayDir.multiplyScalar( rayLength );
140970
+ rayDir.z += cameraGizmoDistance;
140971
+ return rayDir;
140972
+
140973
+ }
140974
+
140975
+ }
140976
+
140977
+
140978
+ /**
140979
+ * Unprojects the cursor on the plane passing through the center of the trackball orthogonal to the camera.
140980
+ *
140981
+ * @private
140982
+ * @param {Camera} camera - The virtual camera.
140983
+ * @param {number} cursorX - Cursor horizontal coordinate on screen.
140984
+ * @param {number} cursorY - Cursor vertical coordinate on screen.
140985
+ * @param {HTMLElement} canvas - The canvas where the renderer draws its output.
140986
+ * @param {boolean} [initialDistance=false] - If initial distance between camera and gizmos should be used for calculations instead of current (Perspective only).
140987
+ * @returns {Vector3} The unprojected point on the trackball plane.
140988
+ */
140989
+ unprojectOnTbPlane( camera, cursorX, cursorY, canvas, initialDistance = false ) {
140990
+
140991
+ if ( camera.type == 'OrthographicCamera' ) {
140992
+
140993
+ this._v2_1.copy( this.getCursorPosition( cursorX, cursorY, canvas ) );
140994
+ this._v3_1.set( this._v2_1.x, this._v2_1.y, 0 );
140995
+
140996
+ return this._v3_1.clone();
140997
+
140998
+ } else if ( camera.type == 'PerspectiveCamera' ) {
140999
+
141000
+ this._v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) );
141001
+
141002
+ //unproject cursor on the near plane
141003
+ this._v3_1.set( this._v2_1.x, this._v2_1.y, -1 );
141004
+ this._v3_1.applyMatrix4( camera.projectionMatrixInverse );
141005
+
141006
+ const rayDir = this._v3_1.clone().normalize(); //unprojected ray direction
141007
+
141008
+ // camera
141009
+ // |\
141010
+ // | \
141011
+ // | \
141012
+ // h | \
141013
+ // | \
141014
+ // | \
141015
+ // _ _ | _ _ _\ _ _ near plane
141016
+ // l
141017
+
141018
+ const h = this._v3_1.z;
141019
+ const l = Math.sqrt( Math.pow( this._v3_1.x, 2 ) + Math.pow( this._v3_1.y, 2 ) );
141020
+ let cameraGizmoDistance;
141021
+
141022
+ if ( initialDistance ) {
141023
+
141024
+ cameraGizmoDistance = this._v3_1.setFromMatrixPosition( this._cameraMatrixState0 ).distanceTo( this._v3_2.setFromMatrixPosition( this._gizmoMatrixState0 ) );
141025
+
141026
+ } else {
141027
+
141028
+ cameraGizmoDistance = camera.position.distanceTo( this._gizmos.position );
141029
+
141030
+ }
141031
+
141032
+ /*
141033
+ * calculate intersection point between unprojected ray and the plane
141034
+ *|y = mx + q
141035
+ *|y = 0
141036
+ *
141037
+ * x = -q/m
141038
+ */
141039
+ if ( l == 0 ) {
141040
+
141041
+ //ray aligned with camera
141042
+ rayDir.set( 0, 0, 0 );
141043
+ return rayDir;
141044
+
141045
+ }
141046
+
141047
+ const m = h / l;
141048
+ const q = cameraGizmoDistance;
141049
+ const x = - q / m;
141050
+
141051
+ const rayLength = Math.sqrt( Math.pow( q, 2 ) + Math.pow( x, 2 ) );
141052
+ rayDir.multiplyScalar( rayLength );
141053
+ rayDir.z = 0;
141054
+ return rayDir;
141055
+
141056
+ }
141057
+
141058
+ }
141059
+
141060
+ /**
141061
+ * Updates camera and gizmos state.
141062
+ *
141063
+ * @private
141064
+ */
141065
+ updateMatrixState() {
141066
+
141067
+ //update camera and gizmos state
141068
+ this._cameraMatrixState.copy( this.object.matrix );
141069
+ this._gizmoMatrixState.copy( this._gizmos.matrix );
141070
+
141071
+ if ( this.object.isOrthographicCamera ) {
141072
+
141073
+ this._cameraProjectionState.copy( this.object.projectionMatrix );
141074
+ this.object.updateProjectionMatrix();
141075
+ this._zoomState = this.object.zoom;
141076
+
141077
+ } else if ( this.object.isPerspectiveCamera ) {
141078
+
141079
+ this._fovState = this.object.fov;
141080
+
141081
+ }
141082
+
141083
+ }
141084
+
141085
+ /**
141086
+ * Updates the trackball FSA.
141087
+ *
141088
+ * @private
141089
+ * @param {STATE} newState - New state of the FSA.
141090
+ * @param {boolean} updateMatrices - If matrices state should be updated.
141091
+ */
141092
+ updateTbState( newState, updateMatrices ) {
141093
+
141094
+ this._state = newState;
141095
+ if ( updateMatrices ) {
141096
+
141097
+ this.updateMatrixState();
141098
+
141099
+ }
141100
+
141101
+ }
141102
+
141103
+ update() {
141104
+
141105
+ if ( this.target.equals( this._currentTarget ) === false ) {
141106
+
141107
+ this._gizmos.position.copy( this.target ); //for correct radius calculation
141108
+ this._tbRadius = this.calculateTbRadius( this.object );
141109
+ this.makeGizmos( this.target, this._tbRadius );
141110
+ this._currentTarget.copy( this.target );
141111
+
141112
+ }
141113
+
141114
+ //check min/max parameters
141115
+ if ( this.object.isOrthographicCamera ) {
141116
+
141117
+ //check zoom
141118
+ if ( this.object.zoom > this.maxZoom || this.object.zoom < this.minZoom ) {
141119
+
141120
+ const newZoom = MathUtils.clamp( this.object.zoom, this.minZoom, this.maxZoom );
141121
+ this.applyTransformMatrix( this.scale( newZoom / this.object.zoom, this._gizmos.position, true ) );
141122
+
141123
+ }
141124
+
141125
+ } else if ( this.object.isPerspectiveCamera ) {
141126
+
141127
+ //check distance
141128
+ const distance = this.object.position.distanceTo( this._gizmos.position );
141129
+
141130
+ if ( distance > this.maxDistance + _EPS$2 || distance < this.minDistance - _EPS$2 ) {
141131
+
141132
+ const newDistance = MathUtils.clamp( distance, this.minDistance, this.maxDistance );
141133
+ this.applyTransformMatrix( this.scale( newDistance / distance, this._gizmos.position ) );
141134
+ this.updateMatrixState();
141135
+
141136
+ }
141137
+
141138
+ //check fov
141139
+ if ( this.object.fov < this.minFov || this.object.fov > this.maxFov ) {
141140
+
141141
+ this.object.fov = MathUtils.clamp( this.object.fov, this.minFov, this.maxFov );
141142
+ this.object.updateProjectionMatrix();
141143
+
141144
+ }
141145
+
141146
+ const oldRadius = this._tbRadius;
141147
+ this._tbRadius = this.calculateTbRadius( this.object );
141148
+
141149
+ if ( oldRadius < this._tbRadius - _EPS$2 || oldRadius > this._tbRadius + _EPS$2 ) {
141150
+
141151
+ const scale = ( this._gizmos.scale.x + this._gizmos.scale.y + this._gizmos.scale.z ) / 3;
141152
+ const newRadius = this._tbRadius / scale;
141153
+ const curve = new EllipseCurve( 0, 0, newRadius, newRadius );
141154
+ const points = curve.getPoints( this._curvePts );
141155
+ const curveGeometry = new BufferGeometry().setFromPoints( points );
141156
+
141157
+ for ( const gizmo in this._gizmos.children ) {
141158
+
141159
+ this._gizmos.children[ gizmo ].geometry = curveGeometry;
141160
+
141161
+ }
141162
+
141163
+ }
141164
+
141165
+ }
141166
+
141167
+ this.object.lookAt( this._gizmos.position );
141168
+
141169
+ }
141170
+
141171
+ setStateFromJSON( json ) {
141172
+
141173
+ const state = JSON.parse( json );
141174
+
141175
+ if ( state.arcballState != undefined ) {
141176
+
141177
+ this.target.fromArray( state.arcballState.target );
141178
+
141179
+ this._cameraMatrixState.fromArray( state.arcballState.cameraMatrix.elements );
141180
+ this._cameraMatrixState.decompose( this.object.position, this.object.quaternion, this.object.scale );
141181
+
141182
+ this.object.up.copy( state.arcballState.cameraUp );
141183
+ this.object.near = state.arcballState.cameraNear;
141184
+ this.object.far = state.arcballState.cameraFar;
141185
+
141186
+ this.object.zoom = state.arcballState.cameraZoom;
141187
+
141188
+ if ( this.object.isPerspectiveCamera ) {
141189
+
141190
+ this.object.fov = state.arcballState.cameraFov;
141191
+
141192
+ }
141193
+
141194
+ this._gizmoMatrixState.fromArray( state.arcballState.gizmoMatrix.elements );
141195
+ this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
141196
+
141197
+ this.object.updateMatrix();
141198
+ this.object.updateProjectionMatrix();
141199
+
141200
+ this._gizmos.updateMatrix();
141201
+
141202
+ this._tbRadius = this.calculateTbRadius( this.object );
141203
+ const gizmoTmp = new Matrix4().copy( this._gizmoMatrixState0 );
141204
+ this.makeGizmos( this._gizmos.position, this._tbRadius );
141205
+ this._gizmoMatrixState0.copy( gizmoTmp );
141206
+
141207
+ this.object.lookAt( this._gizmos.position );
141208
+ this.updateTbState( STATE.IDLE, false );
141209
+
141210
+ this.dispatchEvent( _changeEvent$2 );
141211
+
141212
+ }
141213
+
141214
+ }
141215
+
141216
+ }
141217
+
141218
+ //listeners
141219
+
141220
+ function onWindowResize() {
141221
+
141222
+ const scale = ( this._gizmos.scale.x + this._gizmos.scale.y + this._gizmos.scale.z ) / 3;
141223
+ this._tbRadius = this.calculateTbRadius( this.object );
141224
+
141225
+ const newRadius = this._tbRadius / scale;
141226
+ const curve = new EllipseCurve( 0, 0, newRadius, newRadius );
141227
+ const points = curve.getPoints( this._curvePts );
141228
+ const curveGeometry = new BufferGeometry().setFromPoints( points );
141229
+
141230
+
141231
+ for ( const gizmo in this._gizmos.children ) {
141232
+
141233
+ this._gizmos.children[ gizmo ].geometry = curveGeometry;
141234
+
141235
+ }
141236
+
141237
+ this.dispatchEvent( _changeEvent$2 );
141238
+
141239
+ }
141240
+
141241
+ function onContextMenu$2( event ) {
141242
+
141243
+ if ( ! this.enabled ) {
141244
+
141245
+ return;
141246
+
141247
+ }
141248
+
141249
+ for ( let i = 0; i < this.mouseActions.length; i ++ ) {
141250
+
141251
+ if ( this.mouseActions[ i ].mouse == 2 ) {
141252
+
141253
+ //prevent only if button 2 is actually used
141254
+ event.preventDefault();
141255
+ break;
141256
+
141257
+ }
141258
+
141259
+ }
141260
+
141261
+ }
141262
+
141263
+ function onPointerCancel$1() {
141264
+
141265
+ this._touchStart.splice( 0, this._touchStart.length );
141266
+ this._touchCurrent.splice( 0, this._touchCurrent.length );
141267
+ this._input = INPUT.NONE;
141268
+
141269
+ }
141270
+
141271
+ function onPointerDown$2( event ) {
141272
+
141273
+ if ( event.button == 0 && event.isPrimary ) {
141274
+
141275
+ this._downValid = true;
141276
+ this._downEvents.push( event );
141277
+ this._downStart = performance.now();
141278
+
141279
+ } else {
141280
+
141281
+ this._downValid = false;
141282
+
141283
+ }
141284
+
141285
+ if ( event.pointerType == 'touch' && this._input != INPUT.CURSOR ) {
141286
+
141287
+ this._touchStart.push( event );
141288
+ this._touchCurrent.push( event );
141289
+
141290
+ switch ( this._input ) {
141291
+
141292
+ case INPUT.NONE:
141293
+
141294
+ //singleStart
141295
+ this._input = INPUT.ONE_FINGER;
141296
+ this.onSinglePanStart( event, 'ROTATE' );
141297
+
141298
+ window.addEventListener( 'pointermove', this._onPointerMove );
141299
+ window.addEventListener( 'pointerup', this._onPointerUp );
141300
+
141301
+ break;
141302
+
141303
+ case INPUT.ONE_FINGER:
141304
+ case INPUT.ONE_FINGER_SWITCHED:
141305
+
141306
+ //doubleStart
141307
+ this._input = INPUT.TWO_FINGER;
141308
+
141309
+ this.onRotateStart();
141310
+ this.onPinchStart();
141311
+ this.onDoublePanStart();
141312
+
141313
+ break;
141314
+
141315
+ case INPUT.TWO_FINGER:
141316
+
141317
+ //multipleStart
141318
+ this._input = INPUT.MULT_FINGER;
141319
+ this.onTriplePanStart( event );
141320
+ break;
141321
+
141322
+ }
141323
+
141324
+ } else if ( event.pointerType != 'touch' && this._input == INPUT.NONE ) {
141325
+
141326
+ let modifier = null;
141327
+
141328
+ if ( event.ctrlKey || event.metaKey ) {
141329
+
141330
+ modifier = 'CTRL';
141331
+
141332
+ } else if ( event.shiftKey ) {
141333
+
141334
+ modifier = 'SHIFT';
141335
+
141336
+ }
141337
+
141338
+ this._mouseOp = this.getOpFromAction( event.button, modifier );
141339
+ if ( this._mouseOp != null ) {
141340
+
141341
+ window.addEventListener( 'pointermove', this._onPointerMove );
141342
+ window.addEventListener( 'pointerup', this._onPointerUp );
141343
+
141344
+ //singleStart
141345
+ this._input = INPUT.CURSOR;
141346
+ this._button = event.button;
141347
+ this.onSinglePanStart( event, this._mouseOp );
141348
+
141349
+ }
141350
+
141351
+ }
141352
+
141353
+ }
141354
+
141355
+ function onPointerMove$2( event ) {
141356
+
141357
+ if ( event.pointerType == 'touch' && this._input != INPUT.CURSOR ) {
141358
+
141359
+ switch ( this._input ) {
141360
+
141361
+ case INPUT.ONE_FINGER:
141362
+
141363
+ //singleMove
141364
+ this.updateTouchEvent( event );
141365
+
141366
+ this.onSinglePanMove( event, STATE.ROTATE );
141367
+ break;
141368
+
141369
+ case INPUT.ONE_FINGER_SWITCHED:
141370
+
141371
+ const movement = this.calculatePointersDistance( this._touchCurrent[ 0 ], event ) * this._devPxRatio;
141372
+
141373
+ if ( movement >= this._switchSensibility ) {
141374
+
141375
+ //singleMove
141376
+ this._input = INPUT.ONE_FINGER;
141377
+ this.updateTouchEvent( event );
141378
+
141379
+ this.onSinglePanStart( event, 'ROTATE' );
141380
+ break;
141381
+
141382
+ }
141383
+
141384
+ break;
141385
+
141386
+ case INPUT.TWO_FINGER:
141387
+
141388
+ //rotate/pan/pinchMove
141389
+ this.updateTouchEvent( event );
141390
+
141391
+ this.onRotateMove();
141392
+ this.onPinchMove();
141393
+ this.onDoublePanMove();
141394
+
141395
+ break;
141396
+
141397
+ case INPUT.MULT_FINGER:
141398
+
141399
+ //multMove
141400
+ this.updateTouchEvent( event );
141401
+
141402
+ this.onTriplePanMove( event );
141403
+ break;
141404
+
141405
+ }
141406
+
141407
+ } else if ( event.pointerType != 'touch' && this._input == INPUT.CURSOR ) {
141408
+
141409
+ let modifier = null;
141410
+
141411
+ if ( event.ctrlKey || event.metaKey ) {
141412
+
141413
+ modifier = 'CTRL';
141414
+
141415
+ } else if ( event.shiftKey ) {
141416
+
141417
+ modifier = 'SHIFT';
141418
+
141419
+ }
141420
+
141421
+ const mouseOpState = this.getOpStateFromAction( this._button, modifier );
141422
+
141423
+ if ( mouseOpState != null ) {
141424
+
141425
+ this.onSinglePanMove( event, mouseOpState );
141426
+
141427
+ }
141428
+
141429
+ }
141430
+
141431
+ //checkDistance
141432
+ if ( this._downValid ) {
141433
+
141434
+ const movement = this.calculatePointersDistance( this._downEvents[ this._downEvents.length - 1 ], event ) * this._devPxRatio;
141435
+ if ( movement > this._movementThreshold ) {
141436
+
141437
+ this._downValid = false;
141438
+
141439
+ }
141440
+
141441
+ }
141442
+
141443
+ }
141444
+
141445
+ function onPointerUp$2( event ) {
141446
+
141447
+ if ( event.pointerType == 'touch' && this._input != INPUT.CURSOR ) {
141448
+
141449
+ const nTouch = this._touchCurrent.length;
141450
+
141451
+ for ( let i = 0; i < nTouch; i ++ ) {
141452
+
141453
+ if ( this._touchCurrent[ i ].pointerId == event.pointerId ) {
141454
+
141455
+ this._touchCurrent.splice( i, 1 );
141456
+ this._touchStart.splice( i, 1 );
141457
+ break;
141458
+
141459
+ }
141460
+
141461
+ }
141462
+
141463
+ switch ( this._input ) {
141464
+
141465
+ case INPUT.ONE_FINGER:
141466
+ case INPUT.ONE_FINGER_SWITCHED:
141467
+
141468
+ //singleEnd
141469
+ window.removeEventListener( 'pointermove', this._onPointerMove );
141470
+ window.removeEventListener( 'pointerup', this._onPointerUp );
141471
+
141472
+ this._input = INPUT.NONE;
141473
+ this.onSinglePanEnd();
141474
+
141475
+ break;
141476
+
141477
+ case INPUT.TWO_FINGER:
141478
+
141479
+ //doubleEnd
141480
+ this.onDoublePanEnd( event );
141481
+ this.onPinchEnd( event );
141482
+ this.onRotateEnd( event );
141483
+
141484
+ //switching to singleStart
141485
+ this._input = INPUT.ONE_FINGER_SWITCHED;
141486
+
141487
+ break;
141488
+
141489
+ case INPUT.MULT_FINGER:
141490
+
141491
+ if ( this._touchCurrent.length == 0 ) {
141492
+
141493
+ window.removeEventListener( 'pointermove', this._onPointerMove );
141494
+ window.removeEventListener( 'pointerup', this._onPointerUp );
141495
+
141496
+ //multCancel
141497
+ this._input = INPUT.NONE;
141498
+ this.onTriplePanEnd();
141499
+
141500
+ }
141501
+
141502
+ break;
141503
+
141504
+ }
141505
+
141506
+ } else if ( event.pointerType != 'touch' && this._input == INPUT.CURSOR ) {
141507
+
141508
+ window.removeEventListener( 'pointermove', this._onPointerMove );
141509
+ window.removeEventListener( 'pointerup', this._onPointerUp );
141510
+
141511
+ this._input = INPUT.NONE;
141512
+ this.onSinglePanEnd();
141513
+ this._button = -1;
141514
+
141515
+ }
141516
+
141517
+ if ( event.isPrimary ) {
141518
+
141519
+ if ( this._downValid ) {
141520
+
141521
+ const downTime = event.timeStamp - this._downEvents[ this._downEvents.length - 1 ].timeStamp;
141522
+
141523
+ if ( downTime <= this._maxDownTime ) {
141524
+
141525
+ if ( this._nclicks == 0 ) {
141526
+
141527
+ //first valid click detected
141528
+ this._nclicks = 1;
141529
+ this._clickStart = performance.now();
141530
+
141531
+ } else {
141532
+
141533
+ const clickInterval = event.timeStamp - this._clickStart;
141534
+ const movement = this.calculatePointersDistance( this._downEvents[ 1 ], this._downEvents[ 0 ] ) * this._devPxRatio;
141535
+
141536
+ if ( clickInterval <= this._maxInterval && movement <= this._posThreshold ) {
141537
+
141538
+ //second valid click detected
141539
+ //fire double tap and reset values
141540
+ this._nclicks = 0;
141541
+ this._downEvents.splice( 0, this._downEvents.length );
141542
+ this.onDoubleTap( event );
141543
+
141544
+ } else {
141545
+
141546
+ //new 'first click'
141547
+ this._nclicks = 1;
141548
+ this._downEvents.shift();
141549
+ this._clickStart = performance.now();
141550
+
141551
+ }
141552
+
141553
+ }
141554
+
141555
+ } else {
141556
+
141557
+ this._downValid = false;
141558
+ this._nclicks = 0;
141559
+ this._downEvents.splice( 0, this._downEvents.length );
141560
+
141561
+ }
141562
+
141563
+ } else {
141564
+
141565
+ this._nclicks = 0;
141566
+ this._downEvents.splice( 0, this._downEvents.length );
141567
+
141568
+ }
141569
+
141570
+ }
141571
+
141572
+ }
141573
+
141574
+ function onWheel( event ) {
141575
+
141576
+ if ( this.enabled && this.enableZoom ) {
141577
+
141578
+ let modifier = null;
141579
+
141580
+ if ( event.ctrlKey || event.metaKey ) {
141581
+
141582
+ modifier = 'CTRL';
141583
+
141584
+ } else if ( event.shiftKey ) {
141585
+
141586
+ modifier = 'SHIFT';
141587
+
141588
+ }
141589
+
141590
+ const mouseOp = this.getOpFromAction( 'WHEEL', modifier );
141591
+
141592
+ if ( mouseOp != null ) {
141593
+
141594
+ event.preventDefault();
141595
+ this.dispatchEvent( _startEvent$1 );
141596
+
141597
+ const notchDeltaY = 125; //distance of one notch of mouse wheel
141598
+ let sgn = event.deltaY / notchDeltaY;
141599
+
141600
+ let size = 1;
141601
+
141602
+ if ( sgn > 0 ) {
141603
+
141604
+ size = 1 / this.scaleFactor;
141605
+
141606
+ } else if ( sgn < 0 ) {
141607
+
141608
+ size = this.scaleFactor;
141609
+
141610
+ }
141611
+
141612
+ switch ( mouseOp ) {
141613
+
141614
+ case 'ZOOM':
141615
+
141616
+ this.updateTbState( STATE.SCALE, true );
141617
+
141618
+ if ( sgn > 0 ) {
141619
+
141620
+ size = 1 / ( Math.pow( this.scaleFactor, sgn ) );
141621
+
141622
+ } else if ( sgn < 0 ) {
141623
+
141624
+ size = Math.pow( this.scaleFactor, - sgn );
141625
+
141626
+ }
141627
+
141628
+ if ( this.cursorZoom && this.enablePan ) {
141629
+
141630
+ let scalePoint;
141631
+
141632
+ if ( this.object.isOrthographicCamera ) {
141633
+
141634
+ scalePoint = this.unprojectOnTbPlane( this.object, event.clientX, event.clientY, this.domElement ).applyQuaternion( this.object.quaternion ).multiplyScalar( 1 / this.object.zoom ).add( this._gizmos.position );
141635
+
141636
+ } else if ( this.object.isPerspectiveCamera ) {
141637
+
141638
+ scalePoint = this.unprojectOnTbPlane( this.object, event.clientX, event.clientY, this.domElement ).applyQuaternion( this.object.quaternion ).add( this._gizmos.position );
141639
+
141640
+ }
141641
+
141642
+ this.applyTransformMatrix( this.scale( size, scalePoint ) );
141643
+
141644
+ } else {
141645
+
141646
+ this.applyTransformMatrix( this.scale( size, this._gizmos.position ) );
141647
+
141648
+ }
141649
+
141650
+ if ( this._grid != null ) {
141651
+
141652
+ this.disposeGrid();
141653
+ this.drawGrid();
141654
+
141655
+ }
141656
+
141657
+ this.updateTbState( STATE.IDLE, false );
141658
+
141659
+ this.dispatchEvent( _changeEvent$2 );
141660
+ this.dispatchEvent( _endEvent$1 );
141661
+
141662
+ break;
141663
+
141664
+ case 'FOV':
141665
+
141666
+ if ( this.object.isPerspectiveCamera ) {
141667
+
141668
+ this.updateTbState( STATE.FOV, true );
141669
+
141670
+
141671
+ //Vertigo effect
141672
+
141673
+ // fov / 2
141674
+ // |\
141675
+ // | \
141676
+ // | \
141677
+ // x | \
141678
+ // | \
141679
+ // | \
141680
+ // | _ _ _\
141681
+ // y
141682
+
141683
+ //check for iOs shift shortcut
141684
+ if ( event.deltaX != 0 ) {
141685
+
141686
+ sgn = event.deltaX / notchDeltaY;
141687
+
141688
+ size = 1;
141689
+
141690
+ if ( sgn > 0 ) {
141691
+
141692
+ size = 1 / ( Math.pow( this.scaleFactor, sgn ) );
141693
+
141694
+ } else if ( sgn < 0 ) {
141695
+
141696
+ size = Math.pow( this.scaleFactor, - sgn );
141697
+
141698
+ }
141699
+
141700
+ }
141701
+
141702
+ this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
141703
+ const x = this._v3_1.distanceTo( this._gizmos.position );
141704
+ let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
141705
+
141706
+ //check min and max distance
141707
+ xNew = MathUtils.clamp( xNew, this.minDistance, this.maxDistance );
141708
+
141709
+ const y = x * Math.tan( MathUtils.DEG2RAD * this.object.fov * 0.5 );
141710
+
141711
+ //calculate new fov
141712
+ let newFov = MathUtils.RAD2DEG * ( Math.atan( y / xNew ) * 2 );
141713
+
141714
+ //check min and max fov
141715
+ if ( newFov > this.maxFov ) {
141716
+
141717
+ newFov = this.maxFov;
141718
+
141719
+ } else if ( newFov < this.minFov ) {
141720
+
141721
+ newFov = this.minFov;
141722
+
141723
+ }
141724
+
141725
+ const newDistance = y / Math.tan( MathUtils.DEG2RAD * ( newFov / 2 ) );
141726
+ size = x / newDistance;
141727
+
141728
+ this.setFov( newFov );
141729
+ this.applyTransformMatrix( this.scale( size, this._gizmos.position, false ) );
141730
+
141731
+ }
141732
+
141733
+ if ( this._grid != null ) {
141734
+
141735
+ this.disposeGrid();
141736
+ this.drawGrid();
141737
+
141738
+ }
141739
+
141740
+ this.updateTbState( STATE.IDLE, false );
141741
+
141742
+ this.dispatchEvent( _changeEvent$2 );
141743
+ this.dispatchEvent( _endEvent$1 );
141744
+
141745
+ break;
141746
+
141747
+ }
141748
+
141749
+ }
141750
+
141751
+ }
136968
141752
 
136969
141753
  }
136970
141754
 
@@ -144274,6 +149058,7 @@ var<${access}> ${ name } : ${ structName };`;
144274
149058
  state.navInfo.textContent = {
144275
149059
  orbit: 'Left-click: rotate, Mouse-wheel/middle-click: zoom, Right-click: pan',
144276
149060
  trackball: 'Left-click: rotate, Mouse-wheel/middle-click: zoom, Right-click: pan',
149061
+ arcball: 'Left-click: rotate, Mouse-wheel/middle-click: zoom, Right-click: pan',
144277
149062
  fly: 'WASD: move, R|F: up | down, Q|E: roll, up|down: pitch, left|right: yaw'
144278
149063
  }[controlType] || '';
144279
149064
  state.navInfo.style.display = state.showNavInfo ? null : 'none';
@@ -144366,6 +149151,7 @@ var<${access}> ${ name } : ${ structName };`;
144366
149151
  // configure controls
144367
149152
  state.controls = new (isClass(controlType) ? controlType : {
144368
149153
  trackball: TrackballControls,
149154
+ arcball: ArcballControls,
144369
149155
  orbit: OrbitControls,
144370
149156
  fly: FlyControls
144371
149157
  }[controlType])(state.camera, state.renderer.domElement);
@@ -144374,7 +149160,7 @@ var<${access}> ${ name } : ${ structName };`;
144374
149160
  state.controls.rollSpeed = Math.PI / 6;
144375
149161
  state.controls.dragToLook = true;
144376
149162
  }
144377
- if (controlType === 'trackball' || controlType === 'orbit') {
149163
+ if (controlType === 'trackball' || controlType === 'arcball' || controlType === 'orbit') {
144378
149164
  state.controls.minDistance = 0.1;
144379
149165
  state.controls.maxDistance = state.skyRadius;
144380
149166
  state.controls.addEventListener('start', () => {
@@ -148865,7 +153651,7 @@ var<${access}> ${ name } : ${ structName };`;
148865
153651
  d ? state.onClick?.(d, ev) : state.onBackgroundClick?.(ev);
148866
153652
  });
148867
153653
  state.renderObjs.camera().position.z = 500;
148868
- state.controlType === 'fly' && (state.renderObjs.controls().movementSpeed = 100);
153654
+ state.controlType === 'fly' && (state.renderObjs.controls().movementSpeed = 80);
148869
153655
 
148870
153656
  //
148871
153657