three-gamepad-controls 0.23.0 → 0.24.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.
- package/LICENSE.md +9 -0
- package/README.md +34 -5
- package/dist/core.d.ts +9 -10
- package/dist/gamepad-arcball-controls.d.ts +5 -4
- package/dist/gamepad-arcball-controls.js +28 -13
- package/dist/gamepad-controls.d.ts +18 -11
- package/dist/gamepad-controls.js +13 -6
- package/dist/gamepad-drag-controls.d.ts +4 -6
- package/dist/gamepad-drag-controls.js +24 -15
- package/dist/gamepad-first-person-controls.d.ts +3 -4
- package/dist/gamepad-first-person-controls.js +1 -0
- package/dist/gamepad-fly-controls.d.ts +3 -4
- package/dist/gamepad-fly-controls.js +1 -0
- package/dist/gamepad-input.d.ts +26 -14
- package/dist/gamepad-input.js +15 -6
- package/dist/gamepad-manager.js +4 -2
- package/dist/gamepad-map-controls.d.ts +2 -3
- package/dist/gamepad-orbit-controls.d.ts +3 -4
- package/dist/gamepad-orbit-controls.js +22 -5
- package/dist/gamepad-pointer-lock-controls.d.ts +3 -4
- package/dist/gamepad-pointer-lock-controls.js +1 -0
- package/dist/gamepad-stick-processing.d.ts +16 -17
- package/dist/gamepad-trackball-controls.d.ts +3 -4
- package/dist/gamepad-trackball-controls.js +4 -13
- package/dist/gamepad-transform-controls.d.ts +4 -5
- package/dist/gamepad-transform-controls.js +52 -28
- package/package.json +15 -14
- package/LICENSE +0 -21
package/dist/gamepad-input.js
CHANGED
|
@@ -52,7 +52,9 @@ const getGamepadButtonValue = (gamepad, button) => {
|
|
|
52
52
|
*/
|
|
53
53
|
var GamepadInput = class extends EventDispatcher {
|
|
54
54
|
/**
|
|
55
|
-
* When `false`,
|
|
55
|
+
* When `false`, polling through `update()` is paused and the last observed
|
|
56
|
+
* state, including button transitions, is retained. Browser listeners remain
|
|
57
|
+
* active and may adopt or disconnect a gamepad; connection events may poll.
|
|
56
58
|
* @default true
|
|
57
59
|
*/
|
|
58
60
|
enabled = true;
|
|
@@ -144,6 +146,9 @@ var GamepadInput = class extends EventDispatcher {
|
|
|
144
146
|
}
|
|
145
147
|
/**
|
|
146
148
|
* Polls the gamepad and refreshes current and previous button state.
|
|
149
|
+
*
|
|
150
|
+
* Resuming compares against the last observed state, without replaying clicks
|
|
151
|
+
* completed during the pause. Adoption seeds held buttons without transitions.
|
|
147
152
|
*/
|
|
148
153
|
update() {
|
|
149
154
|
if (!this.enabled) return;
|
|
@@ -170,7 +175,9 @@ var GamepadInput = class extends EventDispatcher {
|
|
|
170
175
|
this.#syncButtonState({ seedPrevious: false });
|
|
171
176
|
}
|
|
172
177
|
/**
|
|
173
|
-
* Removes
|
|
178
|
+
* Removes this reader's window listeners, clears its state, and disables it.
|
|
179
|
+
* Does not dispatch a synthetic disconnection or affect other input readers.
|
|
180
|
+
* Reusing a disposed reader is unsupported; create a new instance instead.
|
|
174
181
|
*/
|
|
175
182
|
dispose() {
|
|
176
183
|
window.removeEventListener("gamepadconnected", this.#onGamepadConnected);
|
|
@@ -190,19 +197,21 @@ var GamepadInput = class extends EventDispatcher {
|
|
|
190
197
|
return this.#pressedButtons.has(button);
|
|
191
198
|
}
|
|
192
199
|
/**
|
|
193
|
-
* Returns whether a button
|
|
200
|
+
* Returns whether a button changed to pressed in the latest observed state.
|
|
201
|
+
* Paused updates retain this result until the next observation or cleanup.
|
|
194
202
|
*
|
|
195
203
|
* @param button - Button index to inspect.
|
|
196
|
-
* @returns
|
|
204
|
+
* @returns Whether the latest observed button state transitioned to pressed.
|
|
197
205
|
*/
|
|
198
206
|
wasPressed(button) {
|
|
199
207
|
return this.#pressedButtons.has(button) && !this.#previousPressedButtons.has(button);
|
|
200
208
|
}
|
|
201
209
|
/**
|
|
202
|
-
* Returns whether a button
|
|
210
|
+
* Returns whether a button changed to released in the latest observed state.
|
|
211
|
+
* Paused updates retain this result until the next observation or cleanup.
|
|
203
212
|
*
|
|
204
213
|
* @param button - Button index to inspect.
|
|
205
|
-
* @returns
|
|
214
|
+
* @returns Whether the latest observed button state transitioned to released.
|
|
206
215
|
*/
|
|
207
216
|
wasReleased(button) {
|
|
208
217
|
return !this.#pressedButtons.has(button) && this.#previousPressedButtons.has(button);
|
package/dist/gamepad-manager.js
CHANGED
|
@@ -68,8 +68,10 @@ var GamepadManager = class {
|
|
|
68
68
|
/**
|
|
69
69
|
* Polls the Gamepad API and refreshes the active gamepad snapshot.
|
|
70
70
|
*
|
|
71
|
-
* Polling
|
|
72
|
-
*
|
|
71
|
+
* Polling refreshes the active slot without treating changes in object
|
|
72
|
+
* reference, `id`, or `timestamp` as reconnections. A missing or disconnected
|
|
73
|
+
* slot reports only a disconnection; adoption waits until the next update.
|
|
74
|
+
* Physical replacements without an observed loss cannot be distinguished.
|
|
73
75
|
*
|
|
74
76
|
* @returns The active gamepad and any connect/disconnect transition found.
|
|
75
77
|
*/
|
|
@@ -9,7 +9,7 @@ import { MapControls } from "three/addons/controls/MapControls.js";
|
|
|
9
9
|
*
|
|
10
10
|
* Call `update()` inside the render loop **before** `MapControls.update()`.
|
|
11
11
|
*/
|
|
12
|
-
declare class GamepadMapControls extends GamepadOrbitControls {
|
|
12
|
+
export declare class GamepadMapControls extends GamepadOrbitControls {
|
|
13
13
|
/**
|
|
14
14
|
* @param controls - A Three.js `MapControls` instance.
|
|
15
15
|
* @param options - Optional overrides for the default behavior.
|
|
@@ -17,5 +17,4 @@ declare class GamepadMapControls extends GamepadOrbitControls {
|
|
|
17
17
|
*/
|
|
18
18
|
constructor(controls: MapControls, options?: Partial<GamepadOrbitControlsOptions>);
|
|
19
19
|
}
|
|
20
|
-
//#endregion
|
|
21
|
-
export { GamepadMapControls };
|
|
20
|
+
//#endregion
|
|
@@ -7,7 +7,7 @@ import { OrbitControls } from "three/addons/controls/OrbitControls.js";
|
|
|
7
7
|
*
|
|
8
8
|
* Every property has a sensible default, so you only need to pass the properties you want to override.
|
|
9
9
|
*/
|
|
10
|
-
type GamepadOrbitControlsOptions = GamepadControlsOptions & {
|
|
10
|
+
export type GamepadOrbitControlsOptions = GamepadControlsOptions & {
|
|
11
11
|
/**
|
|
12
12
|
* Multiplier on orbit rotation speed.
|
|
13
13
|
* @default 1.0
|
|
@@ -55,7 +55,7 @@ type GamepadOrbitControlsOptions = GamepadControlsOptions & {
|
|
|
55
55
|
* Call `update()` inside the render loop **before** `OrbitControls.update()`.
|
|
56
56
|
* Bindings and speeds are configurable via {@link GamepadOrbitControlsOptions}.
|
|
57
57
|
*/
|
|
58
|
-
declare class GamepadOrbitControls extends GamepadControls {
|
|
58
|
+
export declare class GamepadOrbitControls extends GamepadControls {
|
|
59
59
|
#private;
|
|
60
60
|
/**
|
|
61
61
|
* @param controls - A Three.js `OrbitControls` instance.
|
|
@@ -70,5 +70,4 @@ declare class GamepadOrbitControls extends GamepadControls {
|
|
|
70
70
|
*/
|
|
71
71
|
protected onUpdate(deltaTime: number): void;
|
|
72
72
|
}
|
|
73
|
-
//#endregion
|
|
74
|
-
export { GamepadOrbitControls, GamepadOrbitControlsOptions };
|
|
73
|
+
//#endregion
|
|
@@ -50,17 +50,34 @@ var GamepadOrbitControls = class extends GamepadControls {
|
|
|
50
50
|
* @param deltaTime - Seconds since the last frame.
|
|
51
51
|
*/
|
|
52
52
|
onUpdate(deltaTime) {
|
|
53
|
+
if (!this.#canApplyInput()) return;
|
|
54
|
+
const controls = this.#controls;
|
|
53
55
|
const { rotateSpeed, panSpeed, zoomSpeed, rotateStick, panStick, buttonDeadzone, buttonDollyIn, buttonDollyOut } = this.#options;
|
|
54
56
|
const input = this.gamepadInput;
|
|
55
57
|
const rotate = input.stick(rotateStick.xAxis, rotateStick.yAxis, rotateStick.pipeline);
|
|
56
|
-
if (rotate.x !== 0)
|
|
57
|
-
|
|
58
|
+
if (controls.enableRotate && rotate.x !== 0) {
|
|
59
|
+
controls.rotateLeft(rotate.x * rotateSpeed * deltaTime * Math.PI);
|
|
60
|
+
if (!this.#canApplyInput()) return;
|
|
61
|
+
}
|
|
62
|
+
if (controls.enableRotate && rotate.y !== 0) {
|
|
63
|
+
controls.rotateUp(rotate.y * rotateSpeed * deltaTime * Math.PI);
|
|
64
|
+
if (!this.#canApplyInput()) return;
|
|
65
|
+
}
|
|
58
66
|
const pan = input.stick(panStick.xAxis, panStick.yAxis, panStick.pipeline);
|
|
59
|
-
if (pan.x !== 0 || pan.y !== 0)
|
|
67
|
+
if (controls.enablePan && (pan.x !== 0 || pan.y !== 0)) {
|
|
68
|
+
controls.pan(pan.x * panSpeed * deltaTime * 500, pan.y * panSpeed * deltaTime * 500);
|
|
69
|
+
if (!this.#canApplyInput()) return;
|
|
70
|
+
}
|
|
60
71
|
const triggerIn = input.buttonValue(buttonDollyIn);
|
|
61
72
|
const triggerOut = input.buttonValue(buttonDollyOut);
|
|
62
|
-
if (
|
|
63
|
-
|
|
73
|
+
if (controls.enableZoom && triggerIn > buttonDeadzone) {
|
|
74
|
+
controls.dollyIn(1 / (1 + zoomSpeed * triggerIn * deltaTime));
|
|
75
|
+
if (!this.#canApplyInput()) return;
|
|
76
|
+
}
|
|
77
|
+
if (controls.enableZoom && triggerOut > buttonDeadzone) controls.dollyOut(1 / (1 + zoomSpeed * triggerOut * deltaTime));
|
|
78
|
+
}
|
|
79
|
+
#canApplyInput() {
|
|
80
|
+
return this.enabled && this.#controls.enabled && this.gamepad !== null;
|
|
64
81
|
}
|
|
65
82
|
};
|
|
66
83
|
//#endregion
|
|
@@ -7,7 +7,7 @@ import { PointerLockControls } from "three/addons/controls/PointerLockControls.j
|
|
|
7
7
|
*
|
|
8
8
|
* Every property has a sensible default, so you only need to pass the properties you want to override.
|
|
9
9
|
*/
|
|
10
|
-
type GamepadPointerLockControlsOptions = GamepadControlsOptions & {
|
|
10
|
+
export type GamepadPointerLockControlsOptions = GamepadControlsOptions & {
|
|
11
11
|
/**
|
|
12
12
|
* Camera movement speed in world units per second at full stick deflection.
|
|
13
13
|
* @default 5.0
|
|
@@ -36,7 +36,7 @@ type GamepadPointerLockControlsOptions = GamepadControlsOptions & {
|
|
|
36
36
|
* IS locked, mouse and gamepad look inputs are additive.
|
|
37
37
|
* Bindings and speeds are configurable via {@link GamepadPointerLockControlsOptions}.
|
|
38
38
|
*/
|
|
39
|
-
declare class GamepadPointerLockControls extends GamepadControls {
|
|
39
|
+
export declare class GamepadPointerLockControls extends GamepadControls {
|
|
40
40
|
#private;
|
|
41
41
|
/**
|
|
42
42
|
* @param controls - A Three.js `PointerLockControls` instance.
|
|
@@ -51,5 +51,4 @@ declare class GamepadPointerLockControls extends GamepadControls {
|
|
|
51
51
|
*/
|
|
52
52
|
protected onUpdate(deltaTime: number): void;
|
|
53
53
|
}
|
|
54
|
-
//#endregion
|
|
55
|
-
export { GamepadPointerLockControls, GamepadPointerLockControlsOptions };
|
|
54
|
+
//#endregion
|
|
@@ -50,6 +50,7 @@ var GamepadPointerLockControls = class extends GamepadControls {
|
|
|
50
50
|
* @param deltaTime - Seconds since the last frame.
|
|
51
51
|
*/
|
|
52
52
|
onUpdate(deltaTime) {
|
|
53
|
+
if (!this.#controls.enabled) return;
|
|
53
54
|
const { moveSpeed, lookSpeed, moveStick, lookStick } = this.#options;
|
|
54
55
|
const input = this.gamepadInput;
|
|
55
56
|
const move = input.stick(moveStick.xAxis, moveStick.yAxis, moveStick.pipeline);
|
|
@@ -5,19 +5,19 @@
|
|
|
5
5
|
* Axial processing transforms each component independently. Radial processing
|
|
6
6
|
* transforms vector magnitude while preserving direction.
|
|
7
7
|
*/
|
|
8
|
-
type GamepadStickProcessingMode = "axial" | "radial";
|
|
8
|
+
export type GamepadStickProcessingMode = "axial" | "radial";
|
|
9
9
|
/**
|
|
10
10
|
* Built-in response curve applied to stick components or magnitude.
|
|
11
11
|
*/
|
|
12
|
-
type GamepadResponseCurve = "linear" | "quadratic" | "cubic";
|
|
12
|
+
export type GamepadResponseCurve = "linear" | "quadratic" | "cubic";
|
|
13
13
|
/**
|
|
14
14
|
* Stick component selection used by inversion processing.
|
|
15
15
|
*/
|
|
16
|
-
type GamepadStickInversionAxis = "x" | "y" | "both";
|
|
16
|
+
export type GamepadStickInversionAxis = "x" | "y" | "both";
|
|
17
17
|
/**
|
|
18
18
|
* Two-dimensional gamepad stick value.
|
|
19
19
|
*/
|
|
20
|
-
type GamepadStick = {
|
|
20
|
+
export type GamepadStick = {
|
|
21
21
|
/**
|
|
22
22
|
* Horizontal stick component.
|
|
23
23
|
*/
|
|
@@ -30,14 +30,14 @@ type GamepadStick = {
|
|
|
30
30
|
/**
|
|
31
31
|
* Pure custom transformation applied to a gamepad stick.
|
|
32
32
|
*/
|
|
33
|
-
type GamepadStickTransform = (value: Readonly<GamepadStick>) => GamepadStick;
|
|
33
|
+
export type GamepadStickTransform = (value: Readonly<GamepadStick>) => GamepadStick;
|
|
34
34
|
/**
|
|
35
35
|
* Pure, stateless transformation applied to a gamepad stick.
|
|
36
36
|
*
|
|
37
37
|
* Implementations must not mutate `value`. Stateful processing such as
|
|
38
38
|
* smoothing belongs in a separate lifecycle-aware abstraction.
|
|
39
39
|
*/
|
|
40
|
-
type GamepadStickProcessor = {
|
|
40
|
+
export type GamepadStickProcessor = {
|
|
41
41
|
/**
|
|
42
42
|
* Transforms one stick value.
|
|
43
43
|
*
|
|
@@ -49,7 +49,7 @@ type GamepadStickProcessor = {
|
|
|
49
49
|
/**
|
|
50
50
|
* Options for {@link gamepadStickPipeline}.
|
|
51
51
|
*/
|
|
52
|
-
type GamepadStickPipelineOptions = {
|
|
52
|
+
export type GamepadStickPipelineOptions = {
|
|
53
53
|
/**
|
|
54
54
|
* Default geometry for processing methods that support axial and radial modes.
|
|
55
55
|
* @default "axial"
|
|
@@ -59,7 +59,7 @@ type GamepadStickPipelineOptions = {
|
|
|
59
59
|
/**
|
|
60
60
|
* Options for {@link GamepadStickPipeline.deadzone}.
|
|
61
61
|
*/
|
|
62
|
-
type GamepadDeadzoneOptions = {
|
|
62
|
+
export type GamepadDeadzoneOptions = {
|
|
63
63
|
/**
|
|
64
64
|
* Geometry for this dead zone, overriding the pipeline default.
|
|
65
65
|
*/
|
|
@@ -73,7 +73,7 @@ type GamepadDeadzoneOptions = {
|
|
|
73
73
|
/**
|
|
74
74
|
* Options for {@link GamepadStickPipeline.responseCurve}.
|
|
75
75
|
*/
|
|
76
|
-
type GamepadResponseCurveOptions = {
|
|
76
|
+
export type GamepadResponseCurveOptions = {
|
|
77
77
|
/**
|
|
78
78
|
* Geometry for this response curve, overriding the pipeline default.
|
|
79
79
|
*/
|
|
@@ -85,7 +85,7 @@ type GamepadResponseCurveOptions = {
|
|
|
85
85
|
* Every configuration method returns a new frozen pipeline and leaves the
|
|
86
86
|
* current pipeline unchanged.
|
|
87
87
|
*/
|
|
88
|
-
type GamepadStickPipeline = GamepadStickProcessor & {
|
|
88
|
+
export type GamepadStickPipeline = GamepadStickProcessor & {
|
|
89
89
|
/**
|
|
90
90
|
* Appends an axial or radial dead zone.
|
|
91
91
|
*
|
|
@@ -129,7 +129,7 @@ type GamepadStickPipeline = GamepadStickProcessor & {
|
|
|
129
129
|
*
|
|
130
130
|
* Omitted fields inherit the action-specific defaults.
|
|
131
131
|
*/
|
|
132
|
-
type GamepadStickBindingOptions = {
|
|
132
|
+
export type GamepadStickBindingOptions = {
|
|
133
133
|
/**
|
|
134
134
|
* Axis index used as the horizontal component.
|
|
135
135
|
*/
|
|
@@ -146,7 +146,7 @@ type GamepadStickBindingOptions = {
|
|
|
146
146
|
/**
|
|
147
147
|
* Fully resolved binding used when reading a two-dimensional stick action.
|
|
148
148
|
*/
|
|
149
|
-
type GamepadStickBinding = Required<GamepadStickBindingOptions>;
|
|
149
|
+
export type GamepadStickBinding = Required<GamepadStickBindingOptions>;
|
|
150
150
|
/**
|
|
151
151
|
* Creates an immutable, fluent stick processing pipeline.
|
|
152
152
|
*
|
|
@@ -157,11 +157,11 @@ type GamepadStickBinding = Required<GamepadStickBindingOptions>;
|
|
|
157
157
|
* @param options - Optional pipeline defaults.
|
|
158
158
|
* @returns Frozen stick pipeline.
|
|
159
159
|
*/
|
|
160
|
-
declare const gamepadStickPipeline: (options?: GamepadStickPipelineOptions) => GamepadStickPipeline;
|
|
160
|
+
export declare const gamepadStickPipeline: (options?: GamepadStickPipelineOptions) => GamepadStickPipeline;
|
|
161
161
|
/**
|
|
162
162
|
* Historical stick processing used when no custom pipeline is supplied.
|
|
163
163
|
*/
|
|
164
|
-
declare const DEFAULT_GAMEPAD_STICK_PIPELINE: GamepadStickPipeline;
|
|
164
|
+
export declare const DEFAULT_GAMEPAD_STICK_PIPELINE: GamepadStickPipeline;
|
|
165
165
|
/**
|
|
166
166
|
* Resolves a partial stick binding over an action-specific default.
|
|
167
167
|
*
|
|
@@ -169,6 +169,5 @@ declare const DEFAULT_GAMEPAD_STICK_PIPELINE: GamepadStickPipeline;
|
|
|
169
169
|
* @param options - Optional binding overrides.
|
|
170
170
|
* @returns Complete resolved binding.
|
|
171
171
|
*/
|
|
172
|
-
declare const resolveGamepadStickBinding: (defaults: GamepadStickBinding, options?: GamepadStickBindingOptions) => GamepadStickBinding;
|
|
173
|
-
//#endregion
|
|
174
|
-
export { DEFAULT_GAMEPAD_STICK_PIPELINE, GamepadDeadzoneOptions, GamepadResponseCurve, GamepadResponseCurveOptions, GamepadStick, GamepadStickBinding, GamepadStickBindingOptions, GamepadStickInversionAxis, GamepadStickPipeline, GamepadStickPipelineOptions, GamepadStickProcessingMode, GamepadStickProcessor, GamepadStickTransform, gamepadStickPipeline, resolveGamepadStickBinding };
|
|
172
|
+
export declare const resolveGamepadStickBinding: (defaults: GamepadStickBinding, options?: GamepadStickBindingOptions) => GamepadStickBinding;
|
|
173
|
+
//#endregion
|
|
@@ -7,7 +7,7 @@ import { TrackballControls } from "three/addons/controls/TrackballControls.js";
|
|
|
7
7
|
*
|
|
8
8
|
* Every property has a sensible default, so you only need to pass the properties you want to override.
|
|
9
9
|
*/
|
|
10
|
-
type GamepadTrackballControlsOptions = GamepadControlsOptions & {
|
|
10
|
+
export type GamepadTrackballControlsOptions = GamepadControlsOptions & {
|
|
11
11
|
/**
|
|
12
12
|
* Multiplier on `TrackballControls.rotateSpeed` for rotation.
|
|
13
13
|
* @default 1.0
|
|
@@ -55,7 +55,7 @@ type GamepadTrackballControlsOptions = GamepadControlsOptions & {
|
|
|
55
55
|
* Call `update()` inside the render loop **before** `TrackballControls.update()`.
|
|
56
56
|
* Bindings and speed multipliers are configurable via {@link GamepadTrackballControlsOptions}.
|
|
57
57
|
*/
|
|
58
|
-
declare class GamepadTrackballControls extends GamepadControls {
|
|
58
|
+
export declare class GamepadTrackballControls extends GamepadControls {
|
|
59
59
|
#private;
|
|
60
60
|
/**
|
|
61
61
|
* @param controls - A Three.js `TrackballControls` instance.
|
|
@@ -70,5 +70,4 @@ declare class GamepadTrackballControls extends GamepadControls {
|
|
|
70
70
|
*/
|
|
71
71
|
protected onUpdate(deltaTime: number): void;
|
|
72
72
|
}
|
|
73
|
-
//#endregion
|
|
74
|
-
export { GamepadTrackballControls, GamepadTrackballControlsOptions };
|
|
73
|
+
//#endregion
|
|
@@ -50,6 +50,7 @@ var GamepadTrackballControls = class extends GamepadControls {
|
|
|
50
50
|
* @param deltaTime - Seconds since the last frame.
|
|
51
51
|
*/
|
|
52
52
|
onUpdate(deltaTime) {
|
|
53
|
+
if (!this.#controls.enabled) return;
|
|
53
54
|
const { rotateSpeed, panSpeed, zoomSpeed, rotateStick, panStick, buttonDeadzone, buttonZoomIn, buttonZoomOut } = this.#options;
|
|
54
55
|
this.#queueRotation(deltaTime, rotateSpeed, rotateStick);
|
|
55
56
|
this.#queuePan(deltaTime, panSpeed, panStick);
|
|
@@ -64,11 +65,7 @@ var GamepadTrackballControls = class extends GamepadControls {
|
|
|
64
65
|
*/
|
|
65
66
|
#queueRotation(deltaTime, rotateSpeed, rotateStick) {
|
|
66
67
|
const controls = this.#controls;
|
|
67
|
-
if (controls.noRotate)
|
|
68
|
-
controls._movePrev.copy(controls._moveCurr);
|
|
69
|
-
controls._lastAngle = 0;
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
68
|
+
if (controls.noRotate) return;
|
|
72
69
|
const rotate = this.gamepadInput.stick(rotateStick.xAxis, rotateStick.yAxis, rotateStick.pipeline);
|
|
73
70
|
if (rotate.x === 0 && rotate.y === 0) return;
|
|
74
71
|
const scale = rotateSpeed * deltaTime * Math.PI;
|
|
@@ -84,10 +81,7 @@ var GamepadTrackballControls = class extends GamepadControls {
|
|
|
84
81
|
*/
|
|
85
82
|
#queuePan(deltaTime, panSpeed, panStick) {
|
|
86
83
|
const controls = this.#controls;
|
|
87
|
-
if (controls.noPan)
|
|
88
|
-
controls._panStart.copy(controls._panEnd);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
84
|
+
if (controls.noPan) return;
|
|
91
85
|
const pan = this.gamepadInput.stick(panStick.xAxis, panStick.yAxis, panStick.pipeline);
|
|
92
86
|
if (pan.x === 0 && pan.y === 0) return;
|
|
93
87
|
const scale = panSpeed * deltaTime * this.#getInputDampingFactor();
|
|
@@ -105,10 +99,7 @@ var GamepadTrackballControls = class extends GamepadControls {
|
|
|
105
99
|
*/
|
|
106
100
|
#queueZoom(deltaTime, zoomSpeed, buttonDeadzone, buttonZoomIn, buttonZoomOut) {
|
|
107
101
|
const controls = this.#controls;
|
|
108
|
-
if (controls.noZoom)
|
|
109
|
-
controls._zoomStart.copy(controls._zoomEnd);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
102
|
+
if (controls.noZoom) return;
|
|
112
103
|
const input = this.gamepadInput;
|
|
113
104
|
const triggerIn = input.buttonValue(buttonZoomIn);
|
|
114
105
|
const triggerOut = input.buttonValue(buttonZoomOut);
|
|
@@ -7,7 +7,7 @@ import { TransformControls } from "three/addons/controls/TransformControls.js";
|
|
|
7
7
|
*
|
|
8
8
|
* Every property has a sensible default, so you only need to pass the properties you want to override.
|
|
9
9
|
*/
|
|
10
|
-
type GamepadTransformControlsOptions = GamepadControlsOptions & {
|
|
10
|
+
export type GamepadTransformControlsOptions = GamepadControlsOptions & {
|
|
11
11
|
/**
|
|
12
12
|
* Screen-relative translation speed multiplier.
|
|
13
13
|
* @default 1.0
|
|
@@ -91,7 +91,7 @@ type GamepadTransformControlsOptions = GamepadControlsOptions & {
|
|
|
91
91
|
* stick starts a native-style transform interaction, and releasing it ends
|
|
92
92
|
* the interaction while keeping the active axis highlighted.
|
|
93
93
|
*/
|
|
94
|
-
declare class GamepadTransformControls extends GamepadControls {
|
|
94
|
+
export declare class GamepadTransformControls extends GamepadControls {
|
|
95
95
|
#private;
|
|
96
96
|
/**
|
|
97
97
|
* @param controls - A Three.js `TransformControls` instance.
|
|
@@ -107,7 +107,7 @@ declare class GamepadTransformControls extends GamepadControls {
|
|
|
107
107
|
*/
|
|
108
108
|
protected onUpdate(deltaTime: number): void;
|
|
109
109
|
/**
|
|
110
|
-
*
|
|
110
|
+
* Disables gamepad updates and ends only this wrapper's active transform.
|
|
111
111
|
*/
|
|
112
112
|
dispose(): void;
|
|
113
113
|
/**
|
|
@@ -117,5 +117,4 @@ declare class GamepadTransformControls extends GamepadControls {
|
|
|
117
117
|
*/
|
|
118
118
|
protected onGamepadDisconnected(gamepad: Gamepad): void;
|
|
119
119
|
}
|
|
120
|
-
//#endregion
|
|
121
|
-
export { GamepadTransformControls, GamepadTransformControlsOptions };
|
|
120
|
+
//#endregion
|
|
@@ -100,6 +100,7 @@ var GamepadTransformControls = class extends GamepadControls {
|
|
|
100
100
|
#rotationQuaternion2;
|
|
101
101
|
#tempQuaternion;
|
|
102
102
|
#isTransforming = false;
|
|
103
|
+
#transformStarted = false;
|
|
103
104
|
#rotationAmount = 0;
|
|
104
105
|
#freeRotationX = 0;
|
|
105
106
|
#freeRotationY = 0;
|
|
@@ -158,16 +159,21 @@ var GamepadTransformControls = class extends GamepadControls {
|
|
|
158
159
|
* @param deltaTime - Seconds since the last frame.
|
|
159
160
|
*/
|
|
160
161
|
onUpdate(deltaTime) {
|
|
162
|
+
const controls = this.#controls;
|
|
163
|
+
if (!this.#canApplyInput()) return;
|
|
164
|
+
if (controls.dragging && !this.#isTransforming) return;
|
|
161
165
|
const startedButtons = this.#getStartedButtons();
|
|
162
166
|
this.#handleModeAndAxisButtons(startedButtons);
|
|
167
|
+
if (!this.#canApplyInput()) return;
|
|
163
168
|
if (startedButtons.has(this.#options.buttonReset)) this.#resetActiveTransform();
|
|
164
|
-
|
|
169
|
+
if (!this.#canApplyInput()) return;
|
|
165
170
|
const object = controls.object;
|
|
166
|
-
if (
|
|
171
|
+
if (object === void 0) {
|
|
167
172
|
this.#endTransform(true);
|
|
168
173
|
return;
|
|
169
174
|
}
|
|
170
175
|
const axis = this.#ensureValidAxis();
|
|
176
|
+
if (!this.#canApplyInput()) return;
|
|
171
177
|
if (axis === null) {
|
|
172
178
|
this.#endTransform(true);
|
|
173
179
|
return;
|
|
@@ -179,17 +185,26 @@ var GamepadTransformControls = class extends GamepadControls {
|
|
|
179
185
|
return;
|
|
180
186
|
}
|
|
181
187
|
if (!this.#isTransforming) this.#startTransform(object);
|
|
188
|
+
if (!this.#canApplyInput()) return;
|
|
189
|
+
if (!this.#transformStarted) {
|
|
190
|
+
this.#transformStarted = true;
|
|
191
|
+
controls.dispatchEvent({
|
|
192
|
+
type: "mouseDown",
|
|
193
|
+
mode: controls.mode
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
if (!this.#canApplyInput()) return;
|
|
182
197
|
if (this.#applyCurrentTransform(object, axis, deltaTime, transform.x, transform.y)) {
|
|
183
198
|
controls.dispatchEvent({ type: "change" });
|
|
184
199
|
controls.dispatchEvent({ type: "objectChange" });
|
|
185
200
|
}
|
|
186
201
|
}
|
|
187
202
|
/**
|
|
188
|
-
*
|
|
203
|
+
* Disables gamepad updates and ends only this wrapper's active transform.
|
|
189
204
|
*/
|
|
190
205
|
dispose() {
|
|
191
|
-
this.#endTransform(true);
|
|
192
206
|
super.dispose();
|
|
207
|
+
this.#endTransform(true);
|
|
193
208
|
}
|
|
194
209
|
/**
|
|
195
210
|
* Ends any active transform if the active gamepad disconnects mid-drag.
|
|
@@ -200,6 +215,13 @@ var GamepadTransformControls = class extends GamepadControls {
|
|
|
200
215
|
this.#endTransform(true);
|
|
201
216
|
super.onGamepadDisconnected(gamepad);
|
|
202
217
|
}
|
|
218
|
+
#canApplyInput() {
|
|
219
|
+
if (!this.#controls.enabled) {
|
|
220
|
+
this.#endTransform(true);
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
return this.enabled && this.gamepad !== null;
|
|
224
|
+
}
|
|
203
225
|
/**
|
|
204
226
|
* Applies mode, space, and axis button transitions from the current frame.
|
|
205
227
|
*
|
|
@@ -207,16 +229,16 @@ var GamepadTransformControls = class extends GamepadControls {
|
|
|
207
229
|
*/
|
|
208
230
|
#handleModeAndAxisButtons(startedButtons) {
|
|
209
231
|
const { buttonTranslate, buttonRotate, buttonScale, buttonToggleSpace, buttonAxisX, buttonAxisY, buttonAxisZ, buttonAxisComposite, buttonAxisPrevious, buttonAxisNext } = this.#options;
|
|
210
|
-
if (startedButtons.has(buttonTranslate)) this.#setMode("translate");
|
|
211
|
-
if (startedButtons.has(buttonRotate)) this.#setMode("rotate");
|
|
212
|
-
if (startedButtons.has(buttonScale)) this.#setMode("scale");
|
|
213
|
-
if (startedButtons.has(buttonToggleSpace)) this.#toggleSpace();
|
|
214
|
-
if (startedButtons.has(buttonAxisX)) this.#selectAxis("X");
|
|
215
|
-
if (startedButtons.has(buttonAxisY)) this.#selectAxis("Y");
|
|
216
|
-
if (startedButtons.has(buttonAxisZ)) this.#selectAxis("Z");
|
|
217
|
-
if (startedButtons.has(buttonAxisComposite)) this.#cycleCompositeAxis();
|
|
218
|
-
if (startedButtons.has(buttonAxisPrevious)) this.#cycleAxis(-1);
|
|
219
|
-
if (startedButtons.has(buttonAxisNext)) this.#cycleAxis(1);
|
|
232
|
+
if (startedButtons.has(buttonTranslate) && this.#canApplyInput()) this.#setMode("translate");
|
|
233
|
+
if (startedButtons.has(buttonRotate) && this.#canApplyInput()) this.#setMode("rotate");
|
|
234
|
+
if (startedButtons.has(buttonScale) && this.#canApplyInput()) this.#setMode("scale");
|
|
235
|
+
if (startedButtons.has(buttonToggleSpace) && this.#canApplyInput()) this.#toggleSpace();
|
|
236
|
+
if (startedButtons.has(buttonAxisX) && this.#canApplyInput()) this.#selectAxis("X");
|
|
237
|
+
if (startedButtons.has(buttonAxisY) && this.#canApplyInput()) this.#selectAxis("Y");
|
|
238
|
+
if (startedButtons.has(buttonAxisZ) && this.#canApplyInput()) this.#selectAxis("Z");
|
|
239
|
+
if (startedButtons.has(buttonAxisComposite) && this.#canApplyInput()) this.#cycleCompositeAxis();
|
|
240
|
+
if (startedButtons.has(buttonAxisPrevious) && this.#canApplyInput()) this.#cycleAxis(-1);
|
|
241
|
+
if (startedButtons.has(buttonAxisNext) && this.#canApplyInput()) this.#cycleAxis(1);
|
|
220
242
|
}
|
|
221
243
|
/**
|
|
222
244
|
* Switches TransformControls mode and refreshes the active axis.
|
|
@@ -226,12 +248,14 @@ var GamepadTransformControls = class extends GamepadControls {
|
|
|
226
248
|
#setMode(mode) {
|
|
227
249
|
if (this.#controls.mode === mode) return;
|
|
228
250
|
this.#endTransform(false);
|
|
251
|
+
if (!this.#canApplyInput()) return;
|
|
229
252
|
this.#controls.setMode(mode);
|
|
230
|
-
this.#ensureValidAxis();
|
|
253
|
+
if (this.#canApplyInput()) this.#ensureValidAxis();
|
|
231
254
|
}
|
|
232
255
|
#toggleSpace() {
|
|
233
256
|
const nextSpace = this.#controls.space === "world" ? "local" : "world";
|
|
234
257
|
this.#endTransform(false);
|
|
258
|
+
if (!this.#canApplyInput()) return;
|
|
235
259
|
this.#controls.setSpace(nextSpace);
|
|
236
260
|
}
|
|
237
261
|
/**
|
|
@@ -242,6 +266,7 @@ var GamepadTransformControls = class extends GamepadControls {
|
|
|
242
266
|
#selectAxis(axis) {
|
|
243
267
|
if (!this.#isAxisAllowed(this.#controls.mode, axis)) return;
|
|
244
268
|
this.#endTransform(false);
|
|
269
|
+
if (!this.#canApplyInput()) return;
|
|
245
270
|
this.#activeAxisByMode[this.#controls.mode] = axis;
|
|
246
271
|
this.#ensureValidAxis();
|
|
247
272
|
}
|
|
@@ -269,6 +294,7 @@ var GamepadTransformControls = class extends GamepadControls {
|
|
|
269
294
|
return;
|
|
270
295
|
}
|
|
271
296
|
this.#endTransform(false);
|
|
297
|
+
if (!this.#canApplyInput()) return;
|
|
272
298
|
const current = this.#activeAxisByMode[this.#controls.mode];
|
|
273
299
|
const currentIndex = current === null ? -1 : axes.indexOf(current);
|
|
274
300
|
const nextIndex = currentIndex === -1 ? 0 : (currentIndex + direction + axes.length) % axes.length;
|
|
@@ -356,12 +382,8 @@ var GamepadTransformControls = class extends GamepadControls {
|
|
|
356
382
|
#startTransform(object) {
|
|
357
383
|
const controls = this.#controls;
|
|
358
384
|
this.#captureTransformStart(object);
|
|
359
|
-
controls.dragging = true;
|
|
360
385
|
this.#isTransforming = true;
|
|
361
|
-
controls.
|
|
362
|
-
type: "mouseDown",
|
|
363
|
-
mode: controls.mode
|
|
364
|
-
});
|
|
386
|
+
controls.dragging = true;
|
|
365
387
|
}
|
|
366
388
|
/**
|
|
367
389
|
* Ends an active TransformControls drag interaction.
|
|
@@ -369,15 +391,17 @@ var GamepadTransformControls = class extends GamepadControls {
|
|
|
369
391
|
* @param clearAxis - Whether to clear the highlighted axis after ending.
|
|
370
392
|
*/
|
|
371
393
|
#endTransform(clearAxis) {
|
|
394
|
+
if (!this.#isTransforming) return;
|
|
372
395
|
const controls = this.#controls;
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}
|
|
396
|
+
const started = this.#transformStarted;
|
|
397
|
+
const mode = controls.mode;
|
|
398
|
+
this.#isTransforming = false;
|
|
399
|
+
this.#transformStarted = false;
|
|
400
|
+
if (started) controls.dispatchEvent({
|
|
401
|
+
type: "mouseUp",
|
|
402
|
+
mode
|
|
403
|
+
});
|
|
404
|
+
controls.dragging = false;
|
|
381
405
|
if (clearAxis) this.#setActiveAxis(null);
|
|
382
406
|
}
|
|
383
407
|
#resetActiveTransform() {
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "three-gamepad-controls",
|
|
3
3
|
"description": "Gamepad support for Three.js controls.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.24.1",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"homepage": "https://github.com/luckasnix/three-gamepad-controls#readme",
|
|
6
7
|
"author": {
|
|
7
8
|
"name": "Kasnix",
|
|
@@ -34,7 +35,6 @@
|
|
|
34
35
|
"controls",
|
|
35
36
|
"gamepad"
|
|
36
37
|
],
|
|
37
|
-
"license": "MIT",
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
@@ -46,23 +46,24 @@
|
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@biomejs/biome": "2.5.
|
|
50
|
-
"@commitlint/cli": "21.2.
|
|
51
|
-
"@commitlint/config-conventional": "21.2.
|
|
52
|
-
"@commitlint/types": "21.2.
|
|
49
|
+
"@biomejs/biome": "2.5.14",
|
|
50
|
+
"@commitlint/cli": "21.2.3",
|
|
51
|
+
"@commitlint/config-conventional": "21.2.3",
|
|
52
|
+
"@commitlint/types": "21.2.3",
|
|
53
53
|
"@types/node": "24.13.3",
|
|
54
|
-
"@types/three": "0.
|
|
55
|
-
"@vitest/
|
|
54
|
+
"@types/three": "0.186.0",
|
|
55
|
+
"@vitest/browser-playwright": "5.0.2",
|
|
56
|
+
"@vitest/coverage-v8": "5.0.2",
|
|
56
57
|
"husky": "9.1.7",
|
|
57
|
-
"
|
|
58
|
-
"three": "0.
|
|
59
|
-
"tsdown": "0.
|
|
58
|
+
"playwright": "1.63.0",
|
|
59
|
+
"three": "0.186.0",
|
|
60
|
+
"tsdown": "0.23.0",
|
|
60
61
|
"typescript": "7.0.2",
|
|
61
|
-
"vitest": "5.0.
|
|
62
|
+
"vitest": "5.0.2"
|
|
62
63
|
},
|
|
63
64
|
"peerDependencies": {
|
|
64
|
-
"@types/three": "~0.
|
|
65
|
-
"three": "~0.
|
|
65
|
+
"@types/three": "~0.186.0",
|
|
66
|
+
"three": "~0.186.0"
|
|
66
67
|
},
|
|
67
68
|
"scripts": {
|
|
68
69
|
"build": "tsc && tsdown",
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Lucas Alves Costa
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|