three-gamepad-controls 0.25.3 → 0.25.4

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.
@@ -92,6 +92,8 @@ export type GamepadTransformControlsOptions = GamepadControlsOptions & {
92
92
  * Modes and axes are selected explicitly with buttons. Moving the transform
93
93
  * stick starts a native-style transform interaction, and releasing it ends
94
94
  * the interaction while keeping the active axis highlighted.
95
+ * Selection follows the native helper's explicit visibility flags, including
96
+ * combined axes and planes, independently of camera-alignment hiding.
95
97
  */
96
98
  export declare class GamepadTransformControls extends GamepadControls {
97
99
  #private;
@@ -66,6 +66,8 @@ const PROJECTED_AXIS_EPSILON = .001;
66
66
  * Modes and axes are selected explicitly with buttons. Moving the transform
67
67
  * stick starts a native-style transform interaction, and releasing it ends
68
68
  * the interaction while keeping the active axis highlighted.
69
+ * Selection follows the native helper's explicit visibility flags, including
70
+ * combined axes and planes, independently of camera-alignment hiding.
69
71
  */
70
72
  var GamepadTransformControls = class extends GamepadControls {
71
73
  #controls;
@@ -321,9 +323,10 @@ var GamepadTransformControls = class extends GamepadControls {
321
323
  * callbacks, interrupting this update if its context or segment was invalidated.
322
324
  *
323
325
  * @param context - Context expected after the operation that invoked callbacks.
326
+ * @param validateAxis - Also validate a newly selected axis before acquisition.
324
327
  * @returns `true` when this update may continue applying gamepad input.
325
328
  */
326
- #afterCallback(context) {
329
+ #afterCallback(context, validateAxis = false) {
327
330
  const segment = this.#segment;
328
331
  if (!this.#matchesContext(context)) {
329
332
  this.#interrupted = true;
@@ -331,6 +334,7 @@ var GamepadTransformControls = class extends GamepadControls {
331
334
  }
332
335
  this.#reconcileSegment();
333
336
  if (segment !== null && this.#segment !== segment) this.#interrupted = true;
337
+ if (validateAxis && context.axis !== null && !this.#isAxisAllowed(context.mode, context.axis)) this.#interrupted = true;
334
338
  return this.#canApplyInput();
335
339
  }
336
340
  /**
@@ -347,7 +351,7 @@ var GamepadTransformControls = class extends GamepadControls {
347
351
  };
348
352
  const controls = this.#controls;
349
353
  controls[key] = value;
350
- this.#afterCallback(context);
354
+ this.#afterCallback(context, key === "axis");
351
355
  }
352
356
  /**
353
357
  * Applies mode, space, and axis button transitions from the current frame.
@@ -404,7 +408,10 @@ var GamepadTransformControls = class extends GamepadControls {
404
408
  * @param axis - Axis requested by the gamepad button mapping.
405
409
  */
406
410
  #selectAxis(axis) {
407
- if (!this.#isAxisAllowed(this.#controls.mode, axis)) return;
411
+ if (!this.#isAxisAllowed(this.#controls.mode, axis)) {
412
+ if (this.#resolveAxis() === null) this.#setActiveAxis(null);
413
+ return;
414
+ }
408
415
  this.#endTransform(false);
409
416
  if (!this.#canApplyInput()) return;
410
417
  this.#setActiveAxis(axis);
@@ -413,8 +420,7 @@ var GamepadTransformControls = class extends GamepadControls {
413
420
  * Selects the next visible composite axis available in the current mode.
414
421
  */
415
422
  #cycleCompositeAxis() {
416
- const validAxes = this.#getVisibleAxes(COMPOSITE_AXES[this.#controls.mode]);
417
- this.#cycleThroughAxes(validAxes, 1);
423
+ this.#cycleThroughAxes(COMPOSITE_AXES[this.#controls.mode], 1);
418
424
  }
419
425
  /**
420
426
  * Cycles through all valid axes for the current mode.
@@ -422,17 +428,18 @@ var GamepadTransformControls = class extends GamepadControls {
422
428
  * @param direction - `1` for next axis, `-1` for previous axis.
423
429
  */
424
430
  #cycleAxis(direction) {
425
- this.#cycleThroughAxes(this.#getValidAxes(this.#controls.mode), direction);
431
+ this.#cycleThroughAxes(MODE_AXES[this.#controls.mode], direction);
426
432
  }
427
433
  /**
428
- * Moves the active axis through a candidate axis list.
434
+ * Moves the active axis through candidates permitted after end callbacks.
429
435
  *
430
- * @param axes - Candidate axes to cycle through.
436
+ * @param candidates - Unfiltered candidate axes to cycle through.
431
437
  * @param direction - `1` for next axis, `-1` for previous axis.
432
438
  */
433
- #cycleThroughAxes(axes, direction) {
439
+ #cycleThroughAxes(candidates, direction) {
434
440
  this.#endTransform(false);
435
441
  if (!this.#canApplyInput()) return;
442
+ const axes = this.#getVisibleAxes(candidates);
436
443
  if (axes.length === 0) {
437
444
  this.#setActiveAxis(null);
438
445
  return;
@@ -457,11 +464,16 @@ var GamepadTransformControls = class extends GamepadControls {
457
464
  return current !== null && validAxes.includes(current) ? current : validAxes[0] ?? null;
458
465
  }
459
466
  /**
460
- * Updates both the remembered axis for the current mode and the control axis.
467
+ * Revalidates a candidate after end callbacks before updating axis memory
468
+ * and the control. An invalidated candidate interrupts this update.
461
469
  *
462
470
  * @param axis - Axis to activate, or `null` to clear selection.
463
471
  */
464
472
  #setActiveAxis(axis) {
473
+ if (axis !== null && !this.#isAxisAllowed(this.#controls.mode, axis)) {
474
+ this.#interrupted = true;
475
+ return;
476
+ }
465
477
  this.#activeAxisByMode[this.#controls.mode] = axis;
466
478
  if (this.#controls.axis !== axis) this.#writeProperty("axis", axis);
467
479
  }
@@ -496,7 +508,8 @@ var GamepadTransformControls = class extends GamepadControls {
496
508
  return MODE_AXES[mode].includes(axis) && this.#isAxisVisible(axis);
497
509
  }
498
510
  /**
499
- * Reads TransformControls visibility flags for an axis or plane.
511
+ * Reads the native helper's explicit axis and plane visibility flags.
512
+ * Camera-alignment hiding does not prohibit gamepad selection.
500
513
  *
501
514
  * @param axis - Axis whose visibility should be checked.
502
515
  * @returns `true` when all components required by the axis are visible.
@@ -510,9 +523,9 @@ var GamepadTransformControls = class extends GamepadControls {
510
523
  case "XY": return controls.showX && controls.showY && controls.showXY;
511
524
  case "YZ": return controls.showY && controls.showZ && controls.showYZ;
512
525
  case "XZ": return controls.showX && controls.showZ && controls.showXZ;
513
- case "XYZ":
514
- case "XYZE": return controls.showX && controls.showY && controls.showZ;
515
- case "E": return true;
526
+ case "XYZ": return controls.showX && controls.showY && controls.showZ && controls.showXY && controls.showYZ;
527
+ case "XYZE": return controls.showX && controls.showY && controls.showZ && controls.showXY && controls.showYZ && controls.showXYZE;
528
+ case "E": return controls.showX && controls.showY && controls.showZ && controls.showE;
516
529
  }
517
530
  }
518
531
  /**
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.25.3",
4
+ "version": "0.25.4",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/luckasnix/three-gamepad-controls#readme",
7
7
  "author": {