three-gamepad-controls 0.10.6 → 0.11.0

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.
@@ -203,6 +203,11 @@ var GamepadTransformControls = class extends GamepadControls {
203
203
  this.#pressedButtons.clear();
204
204
  super.onGamepadDisconnected(gamepad);
205
205
  }
206
+ /**
207
+ * Applies mode, space, and axis button transitions from the current frame.
208
+ *
209
+ * @param startedButtons - Button indices that transitioned to pressed.
210
+ */
206
211
  #handleModeAndAxisButtons(startedButtons) {
207
212
  const { buttonTranslate, buttonRotate, buttonScale, buttonToggleSpace, buttonAxisX, buttonAxisY, buttonAxisZ, buttonAxisComposite, buttonAxisPrevious, buttonAxisNext } = this.#options;
208
213
  if (startedButtons.has(buttonTranslate)) this.#setMode("translate");
@@ -216,30 +221,57 @@ var GamepadTransformControls = class extends GamepadControls {
216
221
  if (startedButtons.has(buttonAxisPrevious)) this.#cycleAxis(-1);
217
222
  if (startedButtons.has(buttonAxisNext)) this.#cycleAxis(1);
218
223
  }
224
+ /**
225
+ * Switches TransformControls mode and refreshes the active axis.
226
+ *
227
+ * @param mode - TransformControls mode to activate.
228
+ */
219
229
  #setMode(mode) {
220
230
  if (this.#controls.mode === mode) return;
221
231
  this.#endTransform(false);
222
232
  this.#controls.setMode(mode);
223
233
  this.#ensureValidAxis();
224
234
  }
235
+ /**
236
+ * Toggles TransformControls between local and world transform space.
237
+ */
225
238
  #toggleSpace() {
226
239
  const nextSpace = this.#controls.space === "world" ? "local" : "world";
227
240
  this.#endTransform(false);
228
241
  this.#controls.setSpace(nextSpace);
229
242
  }
243
+ /**
244
+ * Selects an explicit axis when it is valid for the current mode.
245
+ *
246
+ * @param axis - Axis requested by the gamepad button mapping.
247
+ */
230
248
  #selectAxis(axis) {
231
249
  if (!this.#isAxisAllowed(this.#controls.mode, axis)) return;
232
250
  this.#endTransform(false);
233
251
  this.#activeAxisByMode[this.#controls.mode] = axis;
234
252
  this.#ensureValidAxis();
235
253
  }
254
+ /**
255
+ * Cycles through composite axes available in the current mode.
256
+ */
236
257
  #cycleCompositeAxis() {
237
- const validAxes = COMPOSITE_AXES[this.#controls.mode].filter((axis) => this.#isAxisVisible(axis));
258
+ const validAxes = this.#getVisibleAxes(COMPOSITE_AXES[this.#controls.mode]);
238
259
  this.#cycleThroughAxes(validAxes, 1);
239
260
  }
261
+ /**
262
+ * Cycles through all valid axes for the current mode.
263
+ *
264
+ * @param direction - `1` for next axis, `-1` for previous axis.
265
+ */
240
266
  #cycleAxis(direction) {
241
267
  this.#cycleThroughAxes(this.#getValidAxes(this.#controls.mode), direction);
242
268
  }
269
+ /**
270
+ * Moves the active axis through a candidate axis list.
271
+ *
272
+ * @param axes - Candidate axes to cycle through.
273
+ * @param direction - `1` for next axis, `-1` for previous axis.
274
+ */
243
275
  #cycleThroughAxes(axes, direction) {
244
276
  if (axes.length === 0) {
245
277
  this.#setActiveAxis(null);
@@ -252,6 +284,11 @@ var GamepadTransformControls = class extends GamepadControls {
252
284
  this.#activeAxisByMode[this.#controls.mode] = axes[nextIndex] ?? null;
253
285
  this.#ensureValidAxis();
254
286
  }
287
+ /**
288
+ * Ensures the highlighted TransformControls axis is valid and visible.
289
+ *
290
+ * @returns The active valid axis, or `null` when no axis is available.
291
+ */
255
292
  #ensureValidAxis() {
256
293
  const mode = this.#controls.mode;
257
294
  const current = this.#activeAxisByMode[mode];
@@ -261,16 +298,51 @@ var GamepadTransformControls = class extends GamepadControls {
261
298
  if (this.#controls.axis !== nextAxis) this.#controls.axis = nextAxis;
262
299
  return nextAxis;
263
300
  }
301
+ /**
302
+ * Updates both the remembered axis for the current mode and the control axis.
303
+ *
304
+ * @param axis - Axis to activate, or `null` to clear selection.
305
+ */
264
306
  #setActiveAxis(axis) {
265
307
  this.#activeAxisByMode[this.#controls.mode] = axis;
266
308
  if (this.#controls.axis !== axis) this.#controls.axis = axis;
267
309
  }
310
+ /**
311
+ * Returns all visible axes supported by a TransformControls mode.
312
+ *
313
+ * @param mode - Mode whose axes should be inspected.
314
+ * @returns Visible axes for the mode.
315
+ */
268
316
  #getValidAxes(mode) {
269
- return MODE_AXES[mode].filter((axis) => this.#isAxisVisible(axis));
317
+ return this.#getVisibleAxes(MODE_AXES[mode]);
318
+ }
319
+ /**
320
+ * Filters a list of axes to those enabled by TransformControls visibility flags.
321
+ *
322
+ * @param axes - Axes to inspect.
323
+ * @returns Axes whose component visibility flags are enabled.
324
+ */
325
+ #getVisibleAxes(axes) {
326
+ const visibleAxes = [];
327
+ for (const axis of axes) if (this.#isAxisVisible(axis)) visibleAxes.push(axis);
328
+ return visibleAxes;
270
329
  }
330
+ /**
331
+ * Checks whether an axis can be used in a mode and is currently visible.
332
+ *
333
+ * @param mode - TransformControls mode to validate against.
334
+ * @param axis - Axis to validate.
335
+ * @returns `true` when the axis is supported and visible.
336
+ */
271
337
  #isAxisAllowed(mode, axis) {
272
338
  return MODE_AXES[mode].includes(axis) && this.#isAxisVisible(axis);
273
339
  }
340
+ /**
341
+ * Reads TransformControls visibility flags for an axis or plane.
342
+ *
343
+ * @param axis - Axis whose visibility should be checked.
344
+ * @returns `true` when all components required by the axis are visible.
345
+ */
274
346
  #isAxisVisible(axis) {
275
347
  const controls = this.#controls;
276
348
  switch (axis) {
@@ -285,6 +357,11 @@ var GamepadTransformControls = class extends GamepadControls {
285
357
  case "E": return true;
286
358
  }
287
359
  }
360
+ /**
361
+ * Starts a TransformControls drag interaction for the active object and axis.
362
+ *
363
+ * @returns `true` when a transform interaction was started.
364
+ */
288
365
  #startTransform() {
289
366
  const controls = this.#controls;
290
367
  const object = controls.object;
@@ -298,6 +375,11 @@ var GamepadTransformControls = class extends GamepadControls {
298
375
  });
299
376
  return true;
300
377
  }
378
+ /**
379
+ * Ends an active TransformControls drag interaction.
380
+ *
381
+ * @param clearAxis - Whether to clear the highlighted axis after ending.
382
+ */
301
383
  #endTransform(clearAxis) {
302
384
  const controls = this.#controls;
303
385
  if (this.#isTransforming) {
@@ -310,6 +392,9 @@ var GamepadTransformControls = class extends GamepadControls {
310
392
  }
311
393
  if (clearAxis) this.#setActiveAxis(null);
312
394
  }
395
+ /**
396
+ * Resets the active object to TransformControls' captured drag start state.
397
+ */
313
398
  #resetActiveTransform() {
314
399
  const object = this.#controls.object;
315
400
  if (!this.#isTransforming || object === void 0) return;
@@ -320,6 +405,11 @@ var GamepadTransformControls = class extends GamepadControls {
320
405
  this.#freeRotationX = 0;
321
406
  this.#freeRotationY = 0;
322
407
  }
408
+ /**
409
+ * Captures object and control state needed to apply gamepad transforms.
410
+ *
411
+ * @param object - Object attached to TransformControls.
412
+ */
323
413
  #captureTransformStart(object) {
324
414
  object.updateWorldMatrix(true, false);
325
415
  object.parent?.updateWorldMatrix(true, false);
@@ -339,6 +429,11 @@ var GamepadTransformControls = class extends GamepadControls {
339
429
  this.#freeRotationX = 0;
340
430
  this.#freeRotationY = 0;
341
431
  }
432
+ /**
433
+ * Captures the attached object's parent world transform for local conversions.
434
+ *
435
+ * @param object - Object attached to TransformControls.
436
+ */
342
437
  #captureParentTransform(object) {
343
438
  if (object.parent === null) {
344
439
  this.#parentPosition.set(0, 0, 0);
@@ -351,6 +446,14 @@ var GamepadTransformControls = class extends GamepadControls {
351
446
  object.parent.matrixWorld.decompose(this.#parentPosition, this.#parentQuaternion, this.#parentScale);
352
447
  this.#parentQuaternionInv.copy(this.#parentQuaternion).invert();
353
448
  }
449
+ /**
450
+ * Dispatches the current stick input to the active TransformControls mode.
451
+ *
452
+ * @param deltaTime - Seconds since the last frame.
453
+ * @param transformX - Horizontal transform input after dead zone processing.
454
+ * @param transformY - Vertical transform input after dead zone processing.
455
+ * @returns `true` when the attached object changed.
456
+ */
354
457
  #applyCurrentTransform(deltaTime, transformX, transformY) {
355
458
  switch (this.#controls.mode) {
356
459
  case "translate": return this.#applyTranslate(deltaTime, transformX, transformY);
@@ -358,6 +461,14 @@ var GamepadTransformControls = class extends GamepadControls {
358
461
  case "scale": return this.#applyScale(deltaTime, transformX, transformY);
359
462
  }
360
463
  }
464
+ /**
465
+ * Applies translation in the selected axis, plane, or screen-facing plane.
466
+ *
467
+ * @param deltaTime - Seconds since the last frame.
468
+ * @param transformX - Horizontal transform input after dead zone processing.
469
+ * @param transformY - Vertical transform input after dead zone processing.
470
+ * @returns `true` when the attached object moved.
471
+ */
361
472
  #applyTranslate(deltaTime, transformX, transformY) {
362
473
  const controls = this.#controls;
363
474
  const object = controls.object;
@@ -377,6 +488,15 @@ var GamepadTransformControls = class extends GamepadControls {
377
488
  this.#applyAccumulatedPosition(object, axis, scale);
378
489
  return true;
379
490
  }
491
+ /**
492
+ * Accumulates a world-space translation delta along selected axis letters.
493
+ *
494
+ * @param axis - Transform axis or plane currently selected.
495
+ * @param space - Transform space used to resolve axis directions.
496
+ * @param transformX - Horizontal transform input after dead zone processing.
497
+ * @param transformY - Vertical transform input after dead zone processing.
498
+ * @param distance - World-space distance scale for the frame.
499
+ */
380
500
  #addAxisTranslation(axis, space, transformX, transformY, distance) {
381
501
  for (const letter of [
382
502
  "X",
@@ -388,6 +508,13 @@ var GamepadTransformControls = class extends GamepadControls {
388
508
  this.#worldDelta.addScaledVector(this.#axisWorld, this.#getProjectedAxisInput(this.#axisWorld, transformX, transformY, this.#getDominantInput(transformX, -transformY)) * distance);
389
509
  }
390
510
  }
511
+ /**
512
+ * Applies accumulated translation with snapping and bounds.
513
+ *
514
+ * @param object - Object attached to TransformControls.
515
+ * @param axis - Transform axis or plane currently selected.
516
+ * @param space - Transform space used for snapping.
517
+ */
391
518
  #applyAccumulatedPosition(object, axis, space) {
392
519
  this.#snappedPosition.copy(this.#accumulatedPosition);
393
520
  if (this.#controls.translationSnap !== null) this.#snapPosition(object, axis, space, this.#controls.translationSnap);
@@ -397,6 +524,14 @@ var GamepadTransformControls = class extends GamepadControls {
397
524
  object.position.copy(this.#snappedPosition);
398
525
  object.updateMatrixWorld();
399
526
  }
527
+ /**
528
+ * Snaps the pending position in world or local transform space.
529
+ *
530
+ * @param object - Object attached to TransformControls.
531
+ * @param axis - Axis letters that should be snapped.
532
+ * @param space - Transform space used for snapping.
533
+ * @param snap - Snap interval.
534
+ */
400
535
  #snapPosition(object, axis, space, snap) {
401
536
  if (snap <= 0) return;
402
537
  if (space === "world") {
@@ -418,6 +553,14 @@ var GamepadTransformControls = class extends GamepadControls {
418
553
  ]) if (axis.includes(letter)) this.#setVectorComponent(this.#snappedPosition, letter, this.#snapValue(this.#getVectorComponent(this.#snappedPosition, letter), snap));
419
554
  this.#snappedPosition.applyQuaternion(this.#quaternionStart);
420
555
  }
556
+ /**
557
+ * Applies rotation for the selected axis or free-rotation mode.
558
+ *
559
+ * @param deltaTime - Seconds since the last frame.
560
+ * @param transformX - Horizontal transform input after dead zone processing.
561
+ * @param transformY - Vertical transform input after dead zone processing.
562
+ * @returns `true` when the attached object rotated.
563
+ */
421
564
  #applyRotate(deltaTime, transformX, transformY) {
422
565
  const controls = this.#controls;
423
566
  const object = controls.object;
@@ -450,11 +593,23 @@ var GamepadTransformControls = class extends GamepadControls {
450
593
  object.updateMatrixWorld();
451
594
  return true;
452
595
  }
596
+ /**
597
+ * Applies a rotation around a world-space axis while preserving local parent space.
598
+ *
599
+ * @param object - Object attached to TransformControls.
600
+ * @param worldAxis - World-space axis to rotate around.
601
+ * @param angle - Rotation amount in radians from the drag start.
602
+ */
453
603
  #applyWorldRotation(object, worldAxis, angle) {
454
604
  this.#axisLocal.copy(worldAxis).applyQuaternion(this.#parentQuaternionInv).normalize();
455
605
  this.#rotationQuaternion.setFromAxisAngle(this.#axisLocal, angle);
456
606
  object.quaternion.copy(this.#rotationQuaternion).multiply(this.#quaternionStart).normalize();
457
607
  }
608
+ /**
609
+ * Applies screen-relative free rotation from accumulated stick input.
610
+ *
611
+ * @param object - Object attached to TransformControls.
612
+ */
458
613
  #applyFreeRotation(object) {
459
614
  const angleX = this.#snapRotation(this.#freeRotationX);
460
615
  const angleY = this.#snapRotation(this.#freeRotationY);
@@ -467,6 +622,14 @@ var GamepadTransformControls = class extends GamepadControls {
467
622
  object.quaternion.copy(this.#rotationQuaternion2).multiply(this.#rotationQuaternion).multiply(this.#quaternionStart).normalize();
468
623
  object.updateMatrixWorld();
469
624
  }
625
+ /**
626
+ * Applies scale along the selected axis or uniformly across all axes.
627
+ *
628
+ * @param deltaTime - Seconds since the last frame.
629
+ * @param transformX - Horizontal transform input after dead zone processing.
630
+ * @param transformY - Vertical transform input after dead zone processing.
631
+ * @returns `true` when the attached object scaled.
632
+ */
470
633
  #applyScale(deltaTime, transformX, transformY) {
471
634
  const controls = this.#controls;
472
635
  const object = controls.object;
@@ -489,11 +652,24 @@ var GamepadTransformControls = class extends GamepadControls {
489
652
  object.updateMatrixWorld();
490
653
  return true;
491
654
  }
655
+ /**
656
+ * Projects stick input onto the selected scale axis.
657
+ *
658
+ * @param axis - Transform axis or plane currently selected.
659
+ * @param transformX - Horizontal transform input after dead zone processing.
660
+ * @param transformY - Vertical transform input after dead zone processing.
661
+ * @returns Signed scale input for the current frame.
662
+ */
492
663
  #getProjectedScaleInput(axis, transformX, transformY) {
493
664
  if (axis !== "X" && axis !== "Y" && axis !== "Z") return this.#getDominantInput(transformX, -transformY);
494
665
  this.#getTransformAxisWorld(axis, "local", this.#axisWorld);
495
666
  return this.#getProjectedAxisInput(this.#axisWorld, transformX, transformY, this.#getDominantInput(transformX, -transformY));
496
667
  }
668
+ /**
669
+ * Refreshes camera vectors, object world position, and viewport scale.
670
+ *
671
+ * @param object - Object attached to TransformControls.
672
+ */
497
673
  #updateCameraState(object) {
498
674
  const camera = this.#controls.camera;
499
675
  camera.updateMatrixWorld();
@@ -506,6 +682,11 @@ var GamepadTransformControls = class extends GamepadControls {
506
682
  this.#eye.copy(this.#cameraWorldPosition).sub(this.#worldPosition).normalize();
507
683
  this.#updateViewSizeAtObjectDepth(camera);
508
684
  }
685
+ /**
686
+ * Computes world-space viewport size at the attached object's depth.
687
+ *
688
+ * @param camera - TransformControls camera.
689
+ */
509
690
  #updateViewSizeAtObjectDepth(camera) {
510
691
  if (this.#isOrthographicCamera(camera)) {
511
692
  this.#viewSize.set(Math.abs(camera.right - camera.left) / camera.zoom, Math.abs(camera.top - camera.bottom) / camera.zoom);
@@ -519,16 +700,41 @@ var GamepadTransformControls = class extends GamepadControls {
519
700
  }
520
701
  this.#viewSize.set(1, 1);
521
702
  }
703
+ /**
704
+ * Resolves a transform axis letter to a normalized world-space direction.
705
+ *
706
+ * @param axis - Axis letter to resolve.
707
+ * @param space - Transform space used to orient the axis.
708
+ * @param target - Vector that receives the axis direction.
709
+ * @returns The normalized target vector.
710
+ */
522
711
  #getTransformAxisWorld(axis, space, target) {
523
712
  this.#setUnitAxis(axis, target);
524
713
  if (space === "local") target.applyQuaternion(this.#worldQuaternionStart);
525
714
  return target.normalize();
526
715
  }
716
+ /**
717
+ * Projects stick input onto the screen-space tangent of a rotation axis.
718
+ *
719
+ * @param axisWorld - Rotation axis in world space.
720
+ * @param transformX - Horizontal transform input after dead zone processing.
721
+ * @param transformY - Vertical transform input after dead zone processing.
722
+ * @returns Signed rotation input for the current frame.
723
+ */
527
724
  #getRotationAxisInput(axisWorld, transformX, transformY) {
528
725
  this.#axisWorld2.crossVectors(axisWorld, this.#eye);
529
726
  if (this.#axisWorld2.lengthSq() < PROJECTED_AXIS_EPSILON) return this.#getDominantInput(transformX, -transformY);
530
727
  return this.#getProjectedAxisInput(this.#axisWorld2.normalize(), transformX, transformY, this.#getDominantInput(transformX, -transformY));
531
728
  }
729
+ /**
730
+ * Projects two-axis stick input onto a world axis as seen by the camera.
731
+ *
732
+ * @param axisWorld - World-space axis to project onto the screen.
733
+ * @param transformX - Horizontal transform input after dead zone processing.
734
+ * @param transformY - Vertical transform input after dead zone processing.
735
+ * @param fallback - Value to use when the axis has no stable screen projection.
736
+ * @returns Signed input along the projected axis.
737
+ */
532
738
  #getProjectedAxisInput(axisWorld, transformX, transformY, fallback) {
533
739
  const screenX = axisWorld.dot(this.#cameraRight);
534
740
  const screenY = -axisWorld.dot(this.#cameraUp);
@@ -536,11 +742,24 @@ var GamepadTransformControls = class extends GamepadControls {
536
742
  if (length < PROJECTED_AXIS_EPSILON) return fallback;
537
743
  return (transformX * screenX + transformY * screenY) / length;
538
744
  }
745
+ /**
746
+ * Converts a world-space movement delta into the object's parent-local space.
747
+ *
748
+ * @param worldDelta - World-space delta to convert.
749
+ * @param target - Vector that receives the local delta.
750
+ * @returns The target vector containing the local delta.
751
+ */
539
752
  #worldDeltaToLocalDelta(worldDelta, target) {
540
753
  target.copy(worldDelta).applyQuaternion(this.#parentQuaternionInv);
541
754
  this.#divideByParentScale(target);
542
755
  return target;
543
756
  }
757
+ /**
758
+ * Converts a local position to world space into the reusable world position.
759
+ *
760
+ * @param object - Object whose parent space contains the local position.
761
+ * @param localPosition - Local position to convert.
762
+ */
544
763
  #localPositionToWorld(object, localPosition) {
545
764
  if (object.parent === null) {
546
765
  this.#worldPosition.copy(localPosition);
@@ -549,6 +768,12 @@ var GamepadTransformControls = class extends GamepadControls {
549
768
  object.parent.updateWorldMatrix(true, false);
550
769
  this.#worldPosition.copy(localPosition).applyMatrix4(object.parent.matrixWorld);
551
770
  }
771
+ /**
772
+ * Converts a world position to object parent-local space into snapped position.
773
+ *
774
+ * @param object - Object whose parent space should receive the result.
775
+ * @param worldPosition - World-space position to convert.
776
+ */
552
777
  #worldPositionToLocal(object, worldPosition) {
553
778
  if (object.parent === null) {
554
779
  this.#snappedPosition.copy(worldPosition);
@@ -558,11 +783,23 @@ var GamepadTransformControls = class extends GamepadControls {
558
783
  this.#parentInverse.copy(object.parent.matrixWorld).invert();
559
784
  this.#snappedPosition.copy(worldPosition).applyMatrix4(this.#parentInverse);
560
785
  }
786
+ /**
787
+ * Removes captured parent scale from a local-space delta.
788
+ *
789
+ * @param target - Vector to adjust in place.
790
+ */
561
791
  #divideByParentScale(target) {
562
792
  target.x = this.#parentScale.x === 0 ? 0 : target.x / this.#parentScale.x;
563
793
  target.y = this.#parentScale.y === 0 ? 0 : target.y / this.#parentScale.y;
564
794
  target.z = this.#parentScale.z === 0 ? 0 : target.z / this.#parentScale.z;
565
795
  }
796
+ /**
797
+ * Writes a unit axis vector into a target vector.
798
+ *
799
+ * @param axis - Axis letter to write.
800
+ * @param target - Vector that receives the unit axis.
801
+ * @returns The target vector.
802
+ */
566
803
  #setUnitAxis(axis, target) {
567
804
  switch (axis) {
568
805
  case "X": return target.set(1, 0, 0);
@@ -570,6 +807,13 @@ var GamepadTransformControls = class extends GamepadControls {
570
807
  case "Z": return target.set(0, 0, 1);
571
808
  }
572
809
  }
810
+ /**
811
+ * Reads one component from a vector by axis letter.
812
+ *
813
+ * @param vector - Vector to inspect.
814
+ * @param axis - Component axis to read.
815
+ * @returns The selected component value.
816
+ */
573
817
  #getVectorComponent(vector, axis) {
574
818
  switch (axis) {
575
819
  case "X": return vector.x;
@@ -577,6 +821,13 @@ var GamepadTransformControls = class extends GamepadControls {
577
821
  case "Z": return vector.z;
578
822
  }
579
823
  }
824
+ /**
825
+ * Writes one component on a vector by axis letter.
826
+ *
827
+ * @param vector - Vector to modify.
828
+ * @param axis - Component axis to write.
829
+ * @param value - Component value to assign.
830
+ */
580
831
  #setVectorComponent(vector, axis, value) {
581
832
  switch (axis) {
582
833
  case "X":
@@ -590,19 +841,52 @@ var GamepadTransformControls = class extends GamepadControls {
590
841
  return;
591
842
  }
592
843
  }
844
+ /**
845
+ * Applies TransformControls rotation snapping to an angle.
846
+ *
847
+ * @param value - Angle in radians.
848
+ * @returns Snapped angle, or the original angle when snapping is disabled.
849
+ */
593
850
  #snapRotation(value) {
594
851
  const snap = this.#controls.rotationSnap;
595
852
  return snap === null || snap <= 0 ? value : this.#snapValue(value, snap);
596
853
  }
854
+ /**
855
+ * Snaps a numeric value to the nearest interval.
856
+ *
857
+ * @param value - Value to snap.
858
+ * @param snap - Snap interval.
859
+ * @returns Value rounded to the nearest snap interval.
860
+ */
597
861
  #snapValue(value, snap) {
598
862
  return Math.round(value / snap) * snap;
599
863
  }
864
+ /**
865
+ * Snaps a scale component while avoiding zero scale.
866
+ *
867
+ * @param value - Scale component to snap.
868
+ * @param snap - Snap interval.
869
+ * @returns Snapped scale component.
870
+ */
600
871
  #snapScale(value, snap) {
601
872
  return this.#snapValue(value, snap) || snap;
602
873
  }
874
+ /**
875
+ * Chooses the larger-magnitude stick component for ambiguous transforms.
876
+ *
877
+ * @param inputX - Horizontal input component.
878
+ * @param inputY - Vertical input component.
879
+ * @returns The input component with the larger absolute magnitude.
880
+ */
603
881
  #getDominantInput(inputX, inputY) {
604
882
  return Math.abs(inputX) >= Math.abs(inputY) ? inputX : inputY;
605
883
  }
884
+ /**
885
+ * Tracks pressed buttons and returns those newly pressed this frame.
886
+ *
887
+ * @param gamepad - Fresh gamepad snapshot to read from.
888
+ * @returns Button indices that transitioned to pressed.
889
+ */
606
890
  #getStartedButtons(gamepad) {
607
891
  const startedButtons = /* @__PURE__ */ new Set();
608
892
  for (let index = 0; index < gamepad.buttons.length; index += 1) {
@@ -615,9 +899,21 @@ var GamepadTransformControls = class extends GamepadControls {
615
899
  }
616
900
  return startedButtons;
617
901
  }
902
+ /**
903
+ * Narrows a Three.js camera to `PerspectiveCamera`.
904
+ *
905
+ * @param camera - Camera to inspect.
906
+ * @returns `true` when the camera is perspective.
907
+ */
618
908
  #isPerspectiveCamera(camera) {
619
909
  return camera.isPerspectiveCamera === true;
620
910
  }
911
+ /**
912
+ * Narrows a Three.js camera to `OrthographicCamera`.
913
+ *
914
+ * @param camera - Camera to inspect.
915
+ * @returns `true` when the camera is orthographic.
916
+ */
621
917
  #isOrthographicCamera(camera) {
622
918
  return camera.isOrthographicCamera === true;
623
919
  }
package/dist/index.d.ts CHANGED
@@ -4,9 +4,10 @@ import { GamepadArcballControls, GamepadArcballControlsOptions } from "./gamepad
4
4
  import { GamepadDragControls, GamepadDragControlsOptions } from "./gamepad-drag-controls.js";
5
5
  import { GamepadFirstPersonControls, GamepadFirstPersonControlsOptions } from "./gamepad-first-person-controls.js";
6
6
  import { GamepadFlyControls, GamepadFlyControlsOptions } from "./gamepad-fly-controls.js";
7
+ import { GamepadAxisOptions, GamepadInput, GamepadInputEventMap, GamepadInputOptions, GamepadStick } from "./gamepad-input.js";
7
8
  import { GamepadOrbitControls, GamepadOrbitControlsOptions } from "./gamepad-orbit-controls.js";
8
9
  import { GamepadMapControls } from "./gamepad-map-controls.js";
9
10
  import { GamepadPointerLockControls, GamepadPointerLockControlsOptions } from "./gamepad-pointer-lock-controls.js";
10
11
  import { GamepadTrackballControls, GamepadTrackballControlsOptions } from "./gamepad-trackball-controls.js";
11
12
  import { GamepadTransformControls, GamepadTransformControlsOptions } from "./gamepad-transform-controls.js";
12
- export { GAMEPAD_AXIS, GAMEPAD_BUTTON, GamepadArcballControls, GamepadArcballControlsOptions, GamepadAxisKey, GamepadAxisValue, GamepadButtonKey, GamepadButtonValue, GamepadControls, GamepadControlsEventMap, GamepadDragControls, GamepadDragControlsOptions, GamepadFirstPersonControls, GamepadFirstPersonControlsOptions, GamepadFlyControls, GamepadFlyControlsOptions, GamepadMapControls, GamepadOrbitControls, GamepadOrbitControlsOptions, GamepadPointerLockControls, GamepadPointerLockControlsOptions, GamepadTrackballControls, GamepadTrackballControlsOptions, GamepadTransformControls, GamepadTransformControlsOptions };
13
+ export { GAMEPAD_AXIS, GAMEPAD_BUTTON, GamepadArcballControls, GamepadArcballControlsOptions, GamepadAxisKey, GamepadAxisOptions, GamepadAxisValue, GamepadButtonKey, GamepadButtonValue, GamepadControls, GamepadControlsEventMap, GamepadDragControls, GamepadDragControlsOptions, GamepadFirstPersonControls, GamepadFirstPersonControlsOptions, GamepadFlyControls, GamepadFlyControlsOptions, GamepadInput, GamepadInputEventMap, GamepadInputOptions, GamepadMapControls, GamepadOrbitControls, GamepadOrbitControlsOptions, GamepadPointerLockControls, GamepadPointerLockControlsOptions, GamepadStick, GamepadTrackballControls, GamepadTrackballControlsOptions, GamepadTransformControls, GamepadTransformControlsOptions };
package/dist/index.js CHANGED
@@ -4,9 +4,10 @@ import { GamepadArcballControls } from "./gamepad-arcball-controls.js";
4
4
  import { GamepadDragControls } from "./gamepad-drag-controls.js";
5
5
  import { GamepadFirstPersonControls } from "./gamepad-first-person-controls.js";
6
6
  import { GamepadFlyControls } from "./gamepad-fly-controls.js";
7
+ import { GamepadInput } from "./gamepad-input.js";
7
8
  import { GamepadOrbitControls } from "./gamepad-orbit-controls.js";
8
9
  import { GamepadMapControls } from "./gamepad-map-controls.js";
9
10
  import { GamepadPointerLockControls } from "./gamepad-pointer-lock-controls.js";
10
11
  import { GamepadTrackballControls } from "./gamepad-trackball-controls.js";
11
12
  import { GamepadTransformControls } from "./gamepad-transform-controls.js";
12
- export { GAMEPAD_AXIS, GAMEPAD_BUTTON, GamepadArcballControls, GamepadControls, GamepadDragControls, GamepadFirstPersonControls, GamepadFlyControls, GamepadMapControls, GamepadOrbitControls, GamepadPointerLockControls, GamepadTrackballControls, GamepadTransformControls };
13
+ export { GAMEPAD_AXIS, GAMEPAD_BUTTON, GamepadArcballControls, GamepadControls, GamepadDragControls, GamepadFirstPersonControls, GamepadFlyControls, GamepadInput, GamepadMapControls, GamepadOrbitControls, GamepadPointerLockControls, GamepadTrackballControls, GamepadTransformControls };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "three-gamepad-controls",
3
3
  "description": "Gamepad support for Three.js controls.",
4
- "version": "0.10.6",
4
+ "version": "0.11.0",
5
5
  "homepage": "https://github.com/luckasnix/three-gamepad-controls#readme",
6
6
  "author": {
7
7
  "name": "Kasnix",