three-gamepad-controls 0.16.0 → 0.18.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.
- package/dist/gamepad-input.d.ts +40 -6
- package/dist/gamepad-input.js +18 -5
- package/dist/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/gamepad-input.d.ts
CHANGED
|
@@ -23,6 +23,10 @@ type GamepadInputEventMap = {
|
|
|
23
23
|
gamepad: Gamepad;
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Dead zone processing mode for two-dimensional stick reads.
|
|
28
|
+
*/
|
|
29
|
+
type GamepadDeadzoneMode = "axial" | "radial";
|
|
26
30
|
/**
|
|
27
31
|
* Configuration for {@link GamepadInput}.
|
|
28
32
|
*/
|
|
@@ -32,6 +36,26 @@ type GamepadInputOptions = {
|
|
|
32
36
|
* @default 0.1
|
|
33
37
|
*/
|
|
34
38
|
deadzone: number;
|
|
39
|
+
/**
|
|
40
|
+
* Default dead zone mode for stick reads.
|
|
41
|
+
* @default "axial"
|
|
42
|
+
*/
|
|
43
|
+
deadzoneMode: GamepadDeadzoneMode;
|
|
44
|
+
/**
|
|
45
|
+
* Whether stick reads rescale values outside the dead zone by default.
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
rescale: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the horizontal component of stick reads is inverted by default.
|
|
51
|
+
* @default false
|
|
52
|
+
*/
|
|
53
|
+
invertX: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Whether the vertical component of stick reads is inverted by default.
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
invertY: boolean;
|
|
35
59
|
/**
|
|
36
60
|
* Browser-assigned gamepad slot to use.
|
|
37
61
|
*
|
|
@@ -63,23 +87,33 @@ type GamepadStickOptions = GamepadAxisOptions & {
|
|
|
63
87
|
* the stick magnitude.
|
|
64
88
|
* @default "axial"
|
|
65
89
|
*/
|
|
66
|
-
deadzoneMode?:
|
|
90
|
+
deadzoneMode?: GamepadDeadzoneMode;
|
|
67
91
|
/**
|
|
68
92
|
* Whether to remap values outside the dead zone to the full output range.
|
|
69
93
|
* @default false
|
|
70
94
|
*/
|
|
71
95
|
rescale?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Whether to invert the processed component from `xAxis`.
|
|
98
|
+
* @default false
|
|
99
|
+
*/
|
|
100
|
+
invertX?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Whether to invert the processed component from `yAxis`.
|
|
103
|
+
* @default false
|
|
104
|
+
*/
|
|
105
|
+
invertY?: boolean;
|
|
72
106
|
};
|
|
73
107
|
/**
|
|
74
|
-
* Two-dimensional stick input after
|
|
108
|
+
* Two-dimensional stick input after configured stick processing.
|
|
75
109
|
*/
|
|
76
110
|
type GamepadStick = {
|
|
77
111
|
/**
|
|
78
|
-
*
|
|
112
|
+
* Processed horizontal stick value.
|
|
79
113
|
*/
|
|
80
114
|
x: number;
|
|
81
115
|
/**
|
|
82
|
-
*
|
|
116
|
+
* Processed vertical stick value.
|
|
83
117
|
*/
|
|
84
118
|
y: number;
|
|
85
119
|
};
|
|
@@ -180,7 +214,7 @@ declare class GamepadInput extends EventDispatcher<GamepadInputEventMap> {
|
|
|
180
214
|
*/
|
|
181
215
|
axis(axis: number, options?: GamepadAxisOptions): number;
|
|
182
216
|
/**
|
|
183
|
-
* Returns a two-axis stick after dead zone processing.
|
|
217
|
+
* Returns a two-axis stick after dead zone, rescale, and inversion processing.
|
|
184
218
|
*
|
|
185
219
|
* @param xAxis - Horizontal axis index.
|
|
186
220
|
* @param yAxis - Vertical axis index.
|
|
@@ -211,4 +245,4 @@ declare class GamepadInput extends EventDispatcher<GamepadInputEventMap> {
|
|
|
211
245
|
resetVibration(): Promise<GamepadHapticsResult | null>;
|
|
212
246
|
}
|
|
213
247
|
//#endregion
|
|
214
|
-
export { GamepadAxisOptions, GamepadInput, GamepadInputEventMap, GamepadInputOptions, GamepadStick, GamepadStickOptions };
|
|
248
|
+
export { GamepadAxisOptions, GamepadDeadzoneMode, GamepadInput, GamepadInputEventMap, GamepadInputOptions, GamepadStick, GamepadStickOptions };
|
package/dist/gamepad-input.js
CHANGED
|
@@ -2,7 +2,13 @@ import { isGamepadVibrationSupported, playGamepadVibrationEffect, resetGamepadVi
|
|
|
2
2
|
import { GamepadManager } from "./gamepad-manager.js";
|
|
3
3
|
import { EventDispatcher } from "three";
|
|
4
4
|
//#region src/gamepad-input.ts
|
|
5
|
-
const DEFAULT_GAMEPAD_INPUT_OPTIONS = {
|
|
5
|
+
const DEFAULT_GAMEPAD_INPUT_OPTIONS = {
|
|
6
|
+
deadzone: .1,
|
|
7
|
+
deadzoneMode: "axial",
|
|
8
|
+
rescale: false,
|
|
9
|
+
invertX: false,
|
|
10
|
+
invertY: false
|
|
11
|
+
};
|
|
6
12
|
/**
|
|
7
13
|
* Applies a dead zone and remaps the remaining magnitude to `[0, 1]`.
|
|
8
14
|
*
|
|
@@ -273,7 +279,7 @@ var GamepadInput = class extends EventDispatcher {
|
|
|
273
279
|
return applyGamepadAxialDeadzone(value, this.#getDeadzone(options), false);
|
|
274
280
|
}
|
|
275
281
|
/**
|
|
276
|
-
* Returns a two-axis stick after dead zone processing.
|
|
282
|
+
* Returns a two-axis stick after dead zone, rescale, and inversion processing.
|
|
277
283
|
*
|
|
278
284
|
* @param xAxis - Horizontal axis index.
|
|
279
285
|
* @param yAxis - Vertical axis index.
|
|
@@ -281,15 +287,22 @@ var GamepadInput = class extends EventDispatcher {
|
|
|
281
287
|
* @returns Object containing processed `x` and `y` values.
|
|
282
288
|
*/
|
|
283
289
|
stick(xAxis, yAxis, options) {
|
|
284
|
-
const
|
|
290
|
+
const deadzoneMode = options?.deadzoneMode ?? this.#options.deadzoneMode;
|
|
291
|
+
const rescale = options?.rescale ?? this.#options.rescale;
|
|
292
|
+
const invertX = options?.invertX ?? this.#options.invertX;
|
|
293
|
+
const invertY = options?.invertY ?? this.#options.invertY;
|
|
285
294
|
const threshold = this.#getDeadzone(options);
|
|
286
295
|
const x = this.#gamepad?.axes[xAxis] ?? 0;
|
|
287
296
|
const y = this.#gamepad?.axes[yAxis] ?? 0;
|
|
288
|
-
|
|
289
|
-
return {
|
|
297
|
+
const processed = deadzoneMode === "radial" ? applyGamepadRadialDeadzone(x, y, threshold, rescale) : {
|
|
290
298
|
x: applyGamepadAxialDeadzone(x, threshold, rescale),
|
|
291
299
|
y: applyGamepadAxialDeadzone(y, threshold, rescale)
|
|
292
300
|
};
|
|
301
|
+
if (!invertX && !invertY) return processed;
|
|
302
|
+
return {
|
|
303
|
+
x: processed.x === 0 ? 0 : invertX ? -processed.x : processed.x,
|
|
304
|
+
y: processed.y === 0 ? 0 : invertY ? -processed.y : processed.y
|
|
305
|
+
};
|
|
293
306
|
}
|
|
294
307
|
/**
|
|
295
308
|
* Plays an effect through the active gamepad's primary vibration actuator.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GAMEPAD_AXIS, GAMEPAD_BUTTON, GamepadAxisKey, GamepadAxisValue, GamepadButtonKey, GamepadButtonValue, MAX_GAMEPAD_INDEX, MIN_GAMEPAD_INDEX } from "./core.js";
|
|
2
|
-
import { GamepadAxisOptions, GamepadInput, GamepadInputEventMap, GamepadInputOptions, GamepadStick, GamepadStickOptions } from "./gamepad-input.js";
|
|
2
|
+
import { GamepadAxisOptions, GamepadDeadzoneMode, GamepadInput, GamepadInputEventMap, GamepadInputOptions, GamepadStick, GamepadStickOptions } from "./gamepad-input.js";
|
|
3
3
|
import { GamepadControls, GamepadControlsEventMap, GamepadControlsOptions } from "./gamepad-controls.js";
|
|
4
4
|
import { GamepadArcballControls, GamepadArcballControlsOptions } from "./gamepad-arcball-controls.js";
|
|
5
5
|
import { GamepadDragControls, GamepadDragControlsOptions } from "./gamepad-drag-controls.js";
|
|
@@ -10,4 +10,4 @@ import { GamepadMapControls } from "./gamepad-map-controls.js";
|
|
|
10
10
|
import { GamepadPointerLockControls, GamepadPointerLockControlsOptions } from "./gamepad-pointer-lock-controls.js";
|
|
11
11
|
import { GamepadTrackballControls, GamepadTrackballControlsOptions } from "./gamepad-trackball-controls.js";
|
|
12
12
|
import { GamepadTransformControls, GamepadTransformControlsOptions } from "./gamepad-transform-controls.js";
|
|
13
|
-
export { GAMEPAD_AXIS, GAMEPAD_BUTTON, GamepadArcballControls, GamepadArcballControlsOptions, GamepadAxisKey, GamepadAxisOptions, GamepadAxisValue, GamepadButtonKey, GamepadButtonValue, GamepadControls, GamepadControlsEventMap, GamepadControlsOptions, GamepadDragControls, GamepadDragControlsOptions, GamepadFirstPersonControls, GamepadFirstPersonControlsOptions, GamepadFlyControls, GamepadFlyControlsOptions, GamepadInput, GamepadInputEventMap, GamepadInputOptions, GamepadMapControls, GamepadOrbitControls, GamepadOrbitControlsOptions, GamepadPointerLockControls, GamepadPointerLockControlsOptions, GamepadStick, GamepadStickOptions, GamepadTrackballControls, GamepadTrackballControlsOptions, GamepadTransformControls, GamepadTransformControlsOptions, MAX_GAMEPAD_INDEX, MIN_GAMEPAD_INDEX };
|
|
13
|
+
export { GAMEPAD_AXIS, GAMEPAD_BUTTON, GamepadArcballControls, GamepadArcballControlsOptions, GamepadAxisKey, GamepadAxisOptions, GamepadAxisValue, GamepadButtonKey, GamepadButtonValue, GamepadControls, GamepadControlsEventMap, GamepadControlsOptions, GamepadDeadzoneMode, GamepadDragControls, GamepadDragControlsOptions, GamepadFirstPersonControls, GamepadFirstPersonControlsOptions, GamepadFlyControls, GamepadFlyControlsOptions, GamepadInput, GamepadInputEventMap, GamepadInputOptions, GamepadMapControls, GamepadOrbitControls, GamepadOrbitControlsOptions, GamepadPointerLockControls, GamepadPointerLockControlsOptions, GamepadStick, GamepadStickOptions, GamepadTrackballControls, GamepadTrackballControlsOptions, GamepadTransformControls, GamepadTransformControlsOptions, MAX_GAMEPAD_INDEX, MIN_GAMEPAD_INDEX };
|
package/package.json
CHANGED