@iwsdk/xr-input 0.3.2 → 0.4.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/generated-profiles.d.ts +6 -0
- package/dist/gamepad/generated-profiles.d.ts.map +1 -1
- package/dist/gamepad/generated-profiles.js +6 -3
- package/dist/gamepad/generated-profiles.js.map +1 -1
- package/dist/gamepad/stateful-button-axes-device.d.ts +81 -0
- package/dist/gamepad/stateful-button-axes-device.d.ts.map +1 -0
- package/dist/gamepad/stateful-button-axes-device.js +197 -0
- package/dist/gamepad/stateful-button-axes-device.js.map +1 -0
- package/dist/gamepad/stateful-gamepad.d.ts +4 -54
- package/dist/gamepad/stateful-gamepad.d.ts.map +1 -1
- package/dist/gamepad/stateful-gamepad.js +7 -183
- package/dist/gamepad/stateful-gamepad.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/pointer/cursor-visual.d.ts.map +1 -1
- package/dist/pointer/cursor-visual.js +1 -0
- package/dist/pointer/cursor-visual.js.map +1 -1
- package/dist/pointer/ray-pointer.d.ts.map +1 -1
- package/dist/pointer/ray-pointer.js +2 -1
- package/dist/pointer/ray-pointer.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/visual/adapter/base-visual-adapter.d.ts +1 -1
- package/dist/visual/adapter/base-visual-adapter.d.ts.map +1 -1
- package/dist/visual/adapter/base-visual-adapter.js +10 -4
- package/dist/visual/adapter/base-visual-adapter.js.map +1 -1
- package/dist/xr-input-manager.d.ts +1 -0
- package/dist/xr-input-manager.d.ts.map +1 -1
- package/dist/xr-input-manager.js +9 -2
- package/dist/xr-input-manager.js.map +1 -1
- package/package.json +7 -3
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
export declare enum AxesState {
|
|
8
|
+
Default = 0,
|
|
9
|
+
Up = 1,
|
|
10
|
+
Down = 2,
|
|
11
|
+
Left = 3,
|
|
12
|
+
Right = 4
|
|
13
|
+
}
|
|
14
|
+
export type ButtonAxesComponentType = 'trigger' | 'squeeze' | 'thumbstick' | 'touchpad' | 'button';
|
|
15
|
+
export type ButtonAxesComponentConfig = {
|
|
16
|
+
type: ButtonAxesComponentType;
|
|
17
|
+
gamepadIndices: Partial<{
|
|
18
|
+
button: number;
|
|
19
|
+
xAxis: number;
|
|
20
|
+
yAxis: number;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
23
|
+
export type ButtonAxesLayout = {
|
|
24
|
+
selectComponentId: string;
|
|
25
|
+
components: Record<string, ButtonAxesComponentConfig>;
|
|
26
|
+
};
|
|
27
|
+
export type ButtonLike = {
|
|
28
|
+
pressed: boolean;
|
|
29
|
+
touched?: boolean;
|
|
30
|
+
value?: number;
|
|
31
|
+
};
|
|
32
|
+
export declare class StatefulButtonAxesDevice {
|
|
33
|
+
readonly buttonMapping: Map<string, number>;
|
|
34
|
+
readonly axesMapping: Map<string, {
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
}>;
|
|
38
|
+
axesThreshold: number;
|
|
39
|
+
protected readonly selectComponentId: string;
|
|
40
|
+
private readonly pressedArrs;
|
|
41
|
+
private readonly touchedArrs;
|
|
42
|
+
private readonly valueArrs;
|
|
43
|
+
private readonly axesStates;
|
|
44
|
+
private readonly axes2DValues;
|
|
45
|
+
private readonly axesValues;
|
|
46
|
+
private currentIndex;
|
|
47
|
+
private previousIndex;
|
|
48
|
+
constructor(layout: ButtonAxesLayout, buttonCount: number);
|
|
49
|
+
update(buttons: ArrayLike<ButtonLike>, axes: ArrayLike<number>): void;
|
|
50
|
+
private getButtonState;
|
|
51
|
+
getButtonPressedByIdx(idx: number): boolean;
|
|
52
|
+
getButtonPressed(id: string): boolean;
|
|
53
|
+
getButtonTouchedByIdx(idx: number): boolean;
|
|
54
|
+
getButtonTouched(id: string): boolean;
|
|
55
|
+
getButtonValueByIdx(idx: number): number;
|
|
56
|
+
getButtonValue(id: string): number;
|
|
57
|
+
getButtonDownByIdx(idx: number): boolean;
|
|
58
|
+
getButtonDown(id: string): boolean;
|
|
59
|
+
getButtonUpByIdx(idx: number): boolean;
|
|
60
|
+
getButtonUp(id: string): boolean;
|
|
61
|
+
getSelectStart(): boolean;
|
|
62
|
+
getSelectEnd(): boolean;
|
|
63
|
+
getSelecting(): boolean;
|
|
64
|
+
getAxesValues(id: string): {
|
|
65
|
+
x: number;
|
|
66
|
+
y: number;
|
|
67
|
+
} | undefined;
|
|
68
|
+
getAxesState(id: string): AxesState | undefined;
|
|
69
|
+
get2DInputValue(id: string): number | undefined;
|
|
70
|
+
getAxesEnteringState(id: string, state: AxesState): boolean;
|
|
71
|
+
getAxesLeavingState(id: string, state: AxesState): boolean;
|
|
72
|
+
getAxesEnteringUp(id: string): boolean;
|
|
73
|
+
getAxesEnteringDown(id: string): boolean;
|
|
74
|
+
getAxesEnteringLeft(id: string): boolean;
|
|
75
|
+
getAxesEnteringRight(id: string): boolean;
|
|
76
|
+
getAxesLeavingUp(id: string): boolean;
|
|
77
|
+
getAxesLeavingDown(id: string): boolean;
|
|
78
|
+
getAxesLeavingLeft(id: string): boolean;
|
|
79
|
+
getAxesLeavingRight(id: string): boolean;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=stateful-button-axes-device.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stateful-button-axes-device.d.ts","sourceRoot":"","sources":["../../src/gamepad/stateful-button-axes-device.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,oBAAY,SAAS;IACnB,OAAO,IAAI;IACX,EAAE,IAAI;IACN,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KA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
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
var AxesState;
|
|
8
|
+
(function (AxesState) {
|
|
9
|
+
AxesState[AxesState["Default"] = 0] = "Default";
|
|
10
|
+
AxesState[AxesState["Up"] = 1] = "Up";
|
|
11
|
+
AxesState[AxesState["Down"] = 2] = "Down";
|
|
12
|
+
AxesState[AxesState["Left"] = 3] = "Left";
|
|
13
|
+
AxesState[AxesState["Right"] = 4] = "Right";
|
|
14
|
+
})(AxesState || (AxesState = {}));
|
|
15
|
+
class StatefulButtonAxesDevice {
|
|
16
|
+
constructor(layout, buttonCount) {
|
|
17
|
+
this.buttonMapping = new Map();
|
|
18
|
+
this.axesMapping = new Map();
|
|
19
|
+
this.axesThreshold = 0.8;
|
|
20
|
+
this.axesStates = new Map();
|
|
21
|
+
this.axes2DValues = new Map();
|
|
22
|
+
this.axesValues = new Map();
|
|
23
|
+
this.currentIndex = 1;
|
|
24
|
+
this.previousIndex = 0;
|
|
25
|
+
this.selectComponentId = layout.selectComponentId;
|
|
26
|
+
this.pressedArrs = [
|
|
27
|
+
new Int8Array(buttonCount).fill(0),
|
|
28
|
+
new Int8Array(buttonCount).fill(0),
|
|
29
|
+
];
|
|
30
|
+
this.touchedArrs = [
|
|
31
|
+
new Int8Array(buttonCount).fill(0),
|
|
32
|
+
new Int8Array(buttonCount).fill(0),
|
|
33
|
+
];
|
|
34
|
+
this.valueArrs = [
|
|
35
|
+
new Float32Array(buttonCount).fill(0),
|
|
36
|
+
new Float32Array(buttonCount).fill(0),
|
|
37
|
+
];
|
|
38
|
+
Object.entries(layout.components).forEach(([id, config]) => {
|
|
39
|
+
const buttonIdx = config.gamepadIndices.button;
|
|
40
|
+
if (buttonIdx !== undefined) {
|
|
41
|
+
this.buttonMapping.set(id, buttonIdx);
|
|
42
|
+
}
|
|
43
|
+
if (config.type === 'thumbstick' || config.type === 'touchpad') {
|
|
44
|
+
const xAxis = config.gamepadIndices.xAxis;
|
|
45
|
+
const yAxis = config.gamepadIndices.yAxis;
|
|
46
|
+
if (xAxis !== undefined && yAxis !== undefined) {
|
|
47
|
+
this.axesMapping.set(id, { x: xAxis, y: yAxis });
|
|
48
|
+
this.axesValues.set(id, { x: 0, y: 0 });
|
|
49
|
+
this.axes2DValues.set(id, 0);
|
|
50
|
+
this.axesStates.set(id, {
|
|
51
|
+
prev: AxesState.Default,
|
|
52
|
+
curr: AxesState.Default,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
update(buttons, axes) {
|
|
59
|
+
var _a;
|
|
60
|
+
this.currentIndex = 1 - this.currentIndex;
|
|
61
|
+
this.previousIndex = 1 - this.previousIndex;
|
|
62
|
+
for (let idx = 0; idx < this.pressedArrs[this.currentIndex].length; idx++) {
|
|
63
|
+
const button = buttons[idx];
|
|
64
|
+
this.pressedArrs[this.currentIndex][idx] = (button === null || button === void 0 ? void 0 : button.pressed) ? 1 : 0;
|
|
65
|
+
this.touchedArrs[this.currentIndex][idx] = (button === null || button === void 0 ? void 0 : button.touched) ? 1 : 0;
|
|
66
|
+
this.valueArrs[this.currentIndex][idx] = (_a = button === null || button === void 0 ? void 0 : button.value) !== null && _a !== void 0 ? _a : 0;
|
|
67
|
+
}
|
|
68
|
+
this.axesMapping.forEach(({ x: xIdx, y: yIdx }, id) => {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
const axesValue = this.axesValues.get(id);
|
|
71
|
+
const axesState = this.axesStates.get(id);
|
|
72
|
+
axesState.prev = axesState.curr;
|
|
73
|
+
axesValue.x = (_a = axes[xIdx]) !== null && _a !== void 0 ? _a : 0;
|
|
74
|
+
axesValue.y = (_b = axes[yIdx]) !== null && _b !== void 0 ? _b : 0;
|
|
75
|
+
const { x, y } = axesValue;
|
|
76
|
+
const value2D = Math.sqrt(x * x + y * y);
|
|
77
|
+
this.axes2DValues.set(id, value2D);
|
|
78
|
+
if (value2D < this.axesThreshold) {
|
|
79
|
+
axesState.curr = AxesState.Default;
|
|
80
|
+
}
|
|
81
|
+
else if (Math.abs(x) > Math.abs(y)) {
|
|
82
|
+
axesState.curr = x > 0 ? AxesState.Right : AxesState.Left;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
axesState.curr = y > 0 ? AxesState.Down : AxesState.Up;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
getButtonState(id, stateArr) {
|
|
90
|
+
const idx = this.buttonMapping.get(id);
|
|
91
|
+
return idx !== undefined ? stateArr[this.currentIndex][idx] : 0;
|
|
92
|
+
}
|
|
93
|
+
getButtonPressedByIdx(idx) {
|
|
94
|
+
return !!this.pressedArrs[this.currentIndex][idx];
|
|
95
|
+
}
|
|
96
|
+
getButtonPressed(id) {
|
|
97
|
+
return !!this.getButtonState(id, this.pressedArrs);
|
|
98
|
+
}
|
|
99
|
+
getButtonTouchedByIdx(idx) {
|
|
100
|
+
return !!this.touchedArrs[this.currentIndex][idx];
|
|
101
|
+
}
|
|
102
|
+
getButtonTouched(id) {
|
|
103
|
+
return !!this.getButtonState(id, this.touchedArrs);
|
|
104
|
+
}
|
|
105
|
+
getButtonValueByIdx(idx) {
|
|
106
|
+
var _a;
|
|
107
|
+
return (_a = this.valueArrs[this.currentIndex][idx]) !== null && _a !== void 0 ? _a : 0;
|
|
108
|
+
}
|
|
109
|
+
getButtonValue(id) {
|
|
110
|
+
const idx = this.buttonMapping.get(id);
|
|
111
|
+
return idx !== undefined ? this.valueArrs[this.currentIndex][idx] : 0;
|
|
112
|
+
}
|
|
113
|
+
getButtonDownByIdx(idx) {
|
|
114
|
+
return ((this.pressedArrs[this.currentIndex][idx] &
|
|
115
|
+
~this.pressedArrs[this.previousIndex][idx]) !==
|
|
116
|
+
0);
|
|
117
|
+
}
|
|
118
|
+
getButtonDown(id) {
|
|
119
|
+
const idx = this.buttonMapping.get(id);
|
|
120
|
+
return idx !== undefined
|
|
121
|
+
? (this.pressedArrs[this.currentIndex][idx] &
|
|
122
|
+
~this.pressedArrs[this.previousIndex][idx]) !==
|
|
123
|
+
0
|
|
124
|
+
: false;
|
|
125
|
+
}
|
|
126
|
+
getButtonUpByIdx(idx) {
|
|
127
|
+
return ((~this.pressedArrs[this.currentIndex][idx] &
|
|
128
|
+
this.pressedArrs[this.previousIndex][idx]) !==
|
|
129
|
+
0);
|
|
130
|
+
}
|
|
131
|
+
getButtonUp(id) {
|
|
132
|
+
const idx = this.buttonMapping.get(id);
|
|
133
|
+
return idx !== undefined
|
|
134
|
+
? (~this.pressedArrs[this.currentIndex][idx] &
|
|
135
|
+
this.pressedArrs[this.previousIndex][idx]) !==
|
|
136
|
+
0
|
|
137
|
+
: false;
|
|
138
|
+
}
|
|
139
|
+
getSelectStart() {
|
|
140
|
+
return this.getButtonDown(this.selectComponentId);
|
|
141
|
+
}
|
|
142
|
+
getSelectEnd() {
|
|
143
|
+
return this.getButtonUp(this.selectComponentId);
|
|
144
|
+
}
|
|
145
|
+
getSelecting() {
|
|
146
|
+
return this.getButtonPressed(this.selectComponentId);
|
|
147
|
+
}
|
|
148
|
+
getAxesValues(id) {
|
|
149
|
+
return this.axesValues.get(id);
|
|
150
|
+
}
|
|
151
|
+
getAxesState(id) {
|
|
152
|
+
var _a;
|
|
153
|
+
return (_a = this.axesStates.get(id)) === null || _a === void 0 ? void 0 : _a.curr;
|
|
154
|
+
}
|
|
155
|
+
get2DInputValue(id) {
|
|
156
|
+
return this.axes2DValues.get(id);
|
|
157
|
+
}
|
|
158
|
+
getAxesEnteringState(id, state) {
|
|
159
|
+
const axesState = this.axesStates.get(id);
|
|
160
|
+
return axesState
|
|
161
|
+
? axesState.curr === state && axesState.prev !== state
|
|
162
|
+
: false;
|
|
163
|
+
}
|
|
164
|
+
getAxesLeavingState(id, state) {
|
|
165
|
+
const axesState = this.axesStates.get(id);
|
|
166
|
+
return axesState
|
|
167
|
+
? axesState.curr !== state && axesState.prev === state
|
|
168
|
+
: false;
|
|
169
|
+
}
|
|
170
|
+
getAxesEnteringUp(id) {
|
|
171
|
+
return this.getAxesEnteringState(id, AxesState.Up);
|
|
172
|
+
}
|
|
173
|
+
getAxesEnteringDown(id) {
|
|
174
|
+
return this.getAxesEnteringState(id, AxesState.Down);
|
|
175
|
+
}
|
|
176
|
+
getAxesEnteringLeft(id) {
|
|
177
|
+
return this.getAxesEnteringState(id, AxesState.Left);
|
|
178
|
+
}
|
|
179
|
+
getAxesEnteringRight(id) {
|
|
180
|
+
return this.getAxesEnteringState(id, AxesState.Right);
|
|
181
|
+
}
|
|
182
|
+
getAxesLeavingUp(id) {
|
|
183
|
+
return this.getAxesLeavingState(id, AxesState.Up);
|
|
184
|
+
}
|
|
185
|
+
getAxesLeavingDown(id) {
|
|
186
|
+
return this.getAxesLeavingState(id, AxesState.Down);
|
|
187
|
+
}
|
|
188
|
+
getAxesLeavingLeft(id) {
|
|
189
|
+
return this.getAxesLeavingState(id, AxesState.Left);
|
|
190
|
+
}
|
|
191
|
+
getAxesLeavingRight(id) {
|
|
192
|
+
return this.getAxesLeavingState(id, AxesState.Right);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export { AxesState, StatefulButtonAxesDevice };
|
|
197
|
+
//# sourceMappingURL=stateful-button-axes-device.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stateful-button-axes-device.js","sources":["../../src/gamepad/stateful-button-axes-device.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;AAKG;IAES;AAAZ,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,SAAA,CAAA,SAAA,CAAA,GAAA,CAAA,CAAA,GAAA,SAAW;AACX,IAAA,SAAA,CAAA,SAAA,CAAA,IAAA,CAAA,GAAA,CAAA,CAAA,GAAA,IAAM;AACN,IAAA,SAAA,CAAA,SAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAQ;AACR,IAAA,SAAA,CAAA,SAAA,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AI,CAAC,mBAAmB,CAAC,EAAE,EAAE,SAAS,CAAC,IAAI,CAAC;IACrD;AAEA,IAAA,kBAAkB,CAAC,EAAU,EAAA;QAC3B,OAAO,IAAI,CAAC,mBAAmB,CAAC,EAAE,EAAE,SAAS,CAAC,IAAI,CAAC;IACrD;AAEA,IAAA,mBAAmB,CAAC,EAAU,EAAA;QAC5B,OAAO,IAAI,CAAC,mBAAmB,CAAC,EAAE,EAAE,SAAS,CAAC,KAAK,CAAC;IACtD;AACD;;;;"}
|
|
@@ -4,14 +4,9 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { InputConfig } from '../visual/adapter/base-visual-adapter.js';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Up = 1,
|
|
11
|
-
Down = 2,
|
|
12
|
-
Left = 3,
|
|
13
|
-
Right = 4
|
|
14
|
-
}
|
|
7
|
+
import type { InputConfig } from '../visual/adapter/base-visual-adapter.js';
|
|
8
|
+
import { StatefulButtonAxesDevice } from './stateful-button-axes-device.js';
|
|
9
|
+
export { AxesState } from './stateful-button-axes-device.js';
|
|
15
10
|
export declare enum InputComponent {
|
|
16
11
|
Trigger = "xr-standard-trigger",
|
|
17
12
|
Squeeze = "xr-standard-squeeze",
|
|
@@ -24,56 +19,11 @@ export declare enum InputComponent {
|
|
|
24
19
|
Thumbrest = "thumbrest",
|
|
25
20
|
Menu = "menu"
|
|
26
21
|
}
|
|
27
|
-
export declare class StatefulGamepad {
|
|
22
|
+
export declare class StatefulGamepad extends StatefulButtonAxesDevice {
|
|
28
23
|
readonly handedness: XRHandedness;
|
|
29
24
|
readonly gamepad: Gamepad;
|
|
30
25
|
readonly inputSource: XRInputSource;
|
|
31
|
-
readonly buttonMapping: Map<string, number>;
|
|
32
|
-
readonly axesMapping: Map<string, {
|
|
33
|
-
x: number;
|
|
34
|
-
y: number;
|
|
35
|
-
}>;
|
|
36
|
-
axesThreshold: number;
|
|
37
|
-
private axesStates;
|
|
38
|
-
private axes2DValues;
|
|
39
|
-
private pressedArrs;
|
|
40
|
-
private touchedArrs;
|
|
41
|
-
private valueArrs;
|
|
42
|
-
private axesValues;
|
|
43
|
-
private selectComponentId;
|
|
44
|
-
private currentIndex;
|
|
45
|
-
private previousIndex;
|
|
46
26
|
constructor({ inputSource, layout }: InputConfig);
|
|
47
27
|
update(): void;
|
|
48
|
-
private getButtonState;
|
|
49
|
-
getButtonPressedByIdx(idx: number): boolean;
|
|
50
|
-
getButtonPressed(id: string): boolean;
|
|
51
|
-
getButtonTouchedByIdx(idx: number): boolean;
|
|
52
|
-
getButtonTouched(id: string): boolean;
|
|
53
|
-
getButtonValueByIdx(idx: number): number;
|
|
54
|
-
getButtonValue(id: string): number;
|
|
55
|
-
getButtonDownByIdx(idx: number): boolean;
|
|
56
|
-
getButtonDown(id: string): boolean;
|
|
57
|
-
getButtonUpByIdx(idx: number): boolean;
|
|
58
|
-
getButtonUp(id: string): boolean;
|
|
59
|
-
getSelectStart(): boolean;
|
|
60
|
-
getSelectEnd(): boolean;
|
|
61
|
-
getSelecting(): boolean;
|
|
62
|
-
getAxesValues(id: string): {
|
|
63
|
-
x: number;
|
|
64
|
-
y: number;
|
|
65
|
-
} | undefined;
|
|
66
|
-
getAxesState(id: string): AxesState | undefined;
|
|
67
|
-
get2DInputValue(id: string): number | undefined;
|
|
68
|
-
getAxesEnteringState(id: string, state: AxesState): boolean;
|
|
69
|
-
getAxesLeavingState(id: string, state: AxesState): boolean;
|
|
70
|
-
getAxesEnteringUp(id: string): boolean;
|
|
71
|
-
getAxesEnteringDown(id: string): boolean;
|
|
72
|
-
getAxesEnteringLeft(id: string): boolean;
|
|
73
|
-
getAxesEnteringRight(id: string): boolean;
|
|
74
|
-
getAxesLeavingUp(id: string): boolean;
|
|
75
|
-
getAxesLeavingDown(id: string): boolean;
|
|
76
|
-
getAxesLeavingLeft(id: string): boolean;
|
|
77
|
-
getAxesLeavingRight(id: string): boolean;
|
|
78
28
|
}
|
|
79
29
|
//# sourceMappingURL=stateful-gamepad.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateful-gamepad.d.ts","sourceRoot":"","sources":["../../src/gamepad/stateful-gamepad.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;
|
|
1
|
+
{"version":3,"file":"stateful-gamepad.d.ts","sourceRoot":"","sources":["../../src/gamepad/stateful-gamepad.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE7D,oBAAY,cAAc;IACxB,OAAO,wBAAwB;IAC/B,OAAO,wBAAwB;IAC/B,QAAQ,yBAAyB;IACjC,UAAU,2BAA2B;IACrC,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,IAAI,SAAS;CACd;AAED,qBAAa,eAAgB,SAAQ,wBAAwB;IAC3D,SAAgB,UAAU,EAAE,YAAY,CAAC;IACzC,SAAgB,OAAO,EAAE,OAAO,CAAC;IACjC,SAAgB,WAAW,EAAE,aAAa,CAAC;gBAE/B,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,WAAW;IAOhD,MAAM;CAGP"}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
+
import { StatefulButtonAxesDevice } from './stateful-button-axes-device.js';
|
|
2
|
+
export { AxesState } from './stateful-button-axes-device.js';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
6
|
*
|
|
4
7
|
* This source code is licensed under the MIT license found in the
|
|
5
8
|
* LICENSE file in the root directory of this source tree.
|
|
6
9
|
*/
|
|
7
|
-
var AxesState;
|
|
8
|
-
(function (AxesState) {
|
|
9
|
-
AxesState[AxesState["Default"] = 0] = "Default";
|
|
10
|
-
AxesState[AxesState["Up"] = 1] = "Up";
|
|
11
|
-
AxesState[AxesState["Down"] = 2] = "Down";
|
|
12
|
-
AxesState[AxesState["Left"] = 3] = "Left";
|
|
13
|
-
AxesState[AxesState["Right"] = 4] = "Right";
|
|
14
|
-
})(AxesState || (AxesState = {}));
|
|
15
10
|
var InputComponent;
|
|
16
11
|
(function (InputComponent) {
|
|
17
12
|
InputComponent["Trigger"] = "xr-standard-trigger";
|
|
@@ -25,188 +20,17 @@ var InputComponent;
|
|
|
25
20
|
InputComponent["Thumbrest"] = "thumbrest";
|
|
26
21
|
InputComponent["Menu"] = "menu";
|
|
27
22
|
})(InputComponent || (InputComponent = {}));
|
|
28
|
-
class StatefulGamepad {
|
|
23
|
+
class StatefulGamepad extends StatefulButtonAxesDevice {
|
|
29
24
|
constructor({ inputSource, layout }) {
|
|
30
|
-
|
|
31
|
-
this.axesMapping = new Map();
|
|
32
|
-
this.axesThreshold = 0.8;
|
|
33
|
-
this.axesStates = new Map();
|
|
34
|
-
this.axes2DValues = new Map();
|
|
35
|
-
this.axesValues = new Map();
|
|
36
|
-
this.currentIndex = 1;
|
|
37
|
-
this.previousIndex = 0;
|
|
25
|
+
super(layout, inputSource.gamepad.buttons.length);
|
|
38
26
|
this.handedness = inputSource.handedness;
|
|
39
27
|
this.gamepad = inputSource.gamepad;
|
|
40
28
|
this.inputSource = inputSource;
|
|
41
|
-
this.selectComponentId = layout.selectComponentId;
|
|
42
|
-
const numButtons = this.gamepad.buttons.length;
|
|
43
|
-
this.pressedArrs = [
|
|
44
|
-
new Int8Array(numButtons).fill(0),
|
|
45
|
-
new Int8Array(numButtons).fill(0),
|
|
46
|
-
];
|
|
47
|
-
this.touchedArrs = [
|
|
48
|
-
new Int8Array(numButtons).fill(0),
|
|
49
|
-
new Int8Array(numButtons).fill(0),
|
|
50
|
-
];
|
|
51
|
-
this.valueArrs = [
|
|
52
|
-
new Float32Array(numButtons).fill(0),
|
|
53
|
-
new Float32Array(numButtons).fill(0),
|
|
54
|
-
];
|
|
55
|
-
Object.entries(layout.components).forEach(([id, config]) => {
|
|
56
|
-
const buttonIdx = config.gamepadIndices['button'];
|
|
57
|
-
if (buttonIdx !== undefined) {
|
|
58
|
-
this.buttonMapping.set(id, buttonIdx);
|
|
59
|
-
}
|
|
60
|
-
if (config.type === 'thumbstick' || config.type === 'touchpad') {
|
|
61
|
-
this.axesMapping.set(id, {
|
|
62
|
-
x: config.gamepadIndices.xAxis,
|
|
63
|
-
y: config.gamepadIndices.yAxis,
|
|
64
|
-
});
|
|
65
|
-
this.axesValues.set(id, { x: 0, y: 0 });
|
|
66
|
-
this.axes2DValues.set(id, 0);
|
|
67
|
-
this.axesStates.set(id, {
|
|
68
|
-
prev: AxesState.Default,
|
|
69
|
-
curr: AxesState.Default,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
29
|
}
|
|
74
30
|
update() {
|
|
75
|
-
this.
|
|
76
|
-
this.previousIndex = 1 - this.previousIndex;
|
|
77
|
-
this.gamepad.buttons.forEach((button, idx) => {
|
|
78
|
-
this.pressedArrs[this.currentIndex][idx] = button.pressed ? 1 : 0;
|
|
79
|
-
this.touchedArrs[this.currentIndex][idx] = button.touched ? 1 : 0;
|
|
80
|
-
this.valueArrs[this.currentIndex][idx] = button.value;
|
|
81
|
-
});
|
|
82
|
-
this.axesMapping.forEach(({ x: xIdx, y: yIdx }, id) => {
|
|
83
|
-
const axesValue = this.axesValues.get(id);
|
|
84
|
-
const axesState = this.axesStates.get(id);
|
|
85
|
-
axesState.prev = axesState.curr;
|
|
86
|
-
axesValue.x = this.gamepad.axes[xIdx];
|
|
87
|
-
axesValue.y = this.gamepad.axes[yIdx];
|
|
88
|
-
const { x, y } = axesValue;
|
|
89
|
-
const value2D = Math.sqrt(x * x + y * y);
|
|
90
|
-
this.axes2DValues.set(id, value2D);
|
|
91
|
-
if (value2D < this.axesThreshold) {
|
|
92
|
-
axesState.curr = AxesState.Default;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
if (Math.abs(x) > Math.abs(y)) {
|
|
96
|
-
axesState.curr = x > 0 ? AxesState.Right : AxesState.Left;
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
axesState.curr = y > 0 ? AxesState.Down : AxesState.Up;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
getButtonState(id, stateArr) {
|
|
105
|
-
const idx = this.buttonMapping.get(id);
|
|
106
|
-
return idx !== undefined ? stateArr[this.currentIndex][idx] : 0;
|
|
107
|
-
}
|
|
108
|
-
getButtonPressedByIdx(idx) {
|
|
109
|
-
return !!this.pressedArrs[this.currentIndex][idx];
|
|
110
|
-
}
|
|
111
|
-
getButtonPressed(id) {
|
|
112
|
-
return !!this.getButtonState(id, this.pressedArrs);
|
|
113
|
-
}
|
|
114
|
-
getButtonTouchedByIdx(idx) {
|
|
115
|
-
return !!this.touchedArrs[this.currentIndex][idx];
|
|
116
|
-
}
|
|
117
|
-
getButtonTouched(id) {
|
|
118
|
-
return !!this.getButtonState(id, this.touchedArrs);
|
|
119
|
-
}
|
|
120
|
-
getButtonValueByIdx(idx) {
|
|
121
|
-
var _a;
|
|
122
|
-
return (_a = this.valueArrs[this.currentIndex][idx]) !== null && _a !== void 0 ? _a : 0;
|
|
123
|
-
}
|
|
124
|
-
getButtonValue(id) {
|
|
125
|
-
const idx = this.buttonMapping.get(id);
|
|
126
|
-
return idx !== undefined ? this.valueArrs[this.currentIndex][idx] : 0;
|
|
127
|
-
}
|
|
128
|
-
getButtonDownByIdx(idx) {
|
|
129
|
-
return ((this.pressedArrs[this.currentIndex][idx] &
|
|
130
|
-
~this.pressedArrs[this.previousIndex][idx]) !==
|
|
131
|
-
0);
|
|
132
|
-
}
|
|
133
|
-
getButtonDown(id) {
|
|
134
|
-
const idx = this.buttonMapping.get(id);
|
|
135
|
-
return idx !== undefined
|
|
136
|
-
? (this.pressedArrs[this.currentIndex][idx] &
|
|
137
|
-
~this.pressedArrs[this.previousIndex][idx]) !==
|
|
138
|
-
0
|
|
139
|
-
: false;
|
|
140
|
-
}
|
|
141
|
-
getButtonUpByIdx(idx) {
|
|
142
|
-
return ((~this.pressedArrs[this.currentIndex][idx] &
|
|
143
|
-
this.pressedArrs[this.previousIndex][idx]) !==
|
|
144
|
-
0);
|
|
145
|
-
}
|
|
146
|
-
getButtonUp(id) {
|
|
147
|
-
const idx = this.buttonMapping.get(id);
|
|
148
|
-
return idx !== undefined
|
|
149
|
-
? (~this.pressedArrs[this.currentIndex][idx] &
|
|
150
|
-
this.pressedArrs[this.previousIndex][idx]) !==
|
|
151
|
-
0
|
|
152
|
-
: false;
|
|
153
|
-
}
|
|
154
|
-
getSelectStart() {
|
|
155
|
-
return this.getButtonDown(this.selectComponentId);
|
|
156
|
-
}
|
|
157
|
-
getSelectEnd() {
|
|
158
|
-
return this.getButtonUp(this.selectComponentId);
|
|
159
|
-
}
|
|
160
|
-
getSelecting() {
|
|
161
|
-
return this.getButtonPressed(this.selectComponentId);
|
|
162
|
-
}
|
|
163
|
-
getAxesValues(id) {
|
|
164
|
-
return this.axesValues.get(id);
|
|
165
|
-
}
|
|
166
|
-
getAxesState(id) {
|
|
167
|
-
var _a;
|
|
168
|
-
return (_a = this.axesStates.get(id)) === null || _a === void 0 ? void 0 : _a.curr;
|
|
169
|
-
}
|
|
170
|
-
get2DInputValue(id) {
|
|
171
|
-
return this.axes2DValues.get(id);
|
|
172
|
-
}
|
|
173
|
-
getAxesEnteringState(id, state) {
|
|
174
|
-
const axesState = this.axesStates.get(id);
|
|
175
|
-
return axesState
|
|
176
|
-
? axesState.curr === state && axesState.prev !== state
|
|
177
|
-
: false;
|
|
178
|
-
}
|
|
179
|
-
getAxesLeavingState(id, state) {
|
|
180
|
-
const axesState = this.axesStates.get(id);
|
|
181
|
-
return axesState
|
|
182
|
-
? axesState.curr !== state && axesState.prev === state
|
|
183
|
-
: false;
|
|
184
|
-
}
|
|
185
|
-
getAxesEnteringUp(id) {
|
|
186
|
-
return this.getAxesEnteringState(id, AxesState.Up);
|
|
187
|
-
}
|
|
188
|
-
getAxesEnteringDown(id) {
|
|
189
|
-
return this.getAxesEnteringState(id, AxesState.Down);
|
|
190
|
-
}
|
|
191
|
-
getAxesEnteringLeft(id) {
|
|
192
|
-
return this.getAxesEnteringState(id, AxesState.Left);
|
|
193
|
-
}
|
|
194
|
-
getAxesEnteringRight(id) {
|
|
195
|
-
return this.getAxesEnteringState(id, AxesState.Right);
|
|
196
|
-
}
|
|
197
|
-
getAxesLeavingUp(id) {
|
|
198
|
-
return this.getAxesLeavingState(id, AxesState.Up);
|
|
199
|
-
}
|
|
200
|
-
getAxesLeavingDown(id) {
|
|
201
|
-
return this.getAxesLeavingState(id, AxesState.Down);
|
|
202
|
-
}
|
|
203
|
-
getAxesLeavingLeft(id) {
|
|
204
|
-
return this.getAxesLeavingState(id, AxesState.Left);
|
|
205
|
-
}
|
|
206
|
-
getAxesLeavingRight(id) {
|
|
207
|
-
return this.getAxesLeavingState(id, AxesState.Right);
|
|
31
|
+
super.update(this.gamepad.buttons, this.gamepad.axes);
|
|
208
32
|
}
|
|
209
33
|
}
|
|
210
34
|
|
|
211
|
-
export {
|
|
35
|
+
export { InputComponent, StatefulGamepad };
|
|
212
36
|
//# sourceMappingURL=stateful-gamepad.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateful-gamepad.js","sources":["../../src/gamepad/stateful-gamepad.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;AAKG;
|
|
1
|
+
{"version":3,"file":"stateful-gamepad.js","sources":["../../src/gamepad/stateful-gamepad.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAAA;;;;;AAKG;IAMS;AAAZ,CAAA,UAAY,cAAc,EAAA;AACxB,IAAA,cAAA,CAAA,SAAA,CAAA,GAAA,qBAA+B;AAC/B,IAAA,cAAA,CAAA,SAAA,CAAA,GAAA,qBAA+B;AAC/B,IAAA,cAAA,CAAA,UAAA,CAAA,GAAA,sBAAiC;AACjC,IAAA,cAAA,CAAA,YAAA,CAAA,GAAA,wBAAqC;AACrC,IAAA,cAAA,CAAA,UAAA,CAAA,GAAA,UAAqB;AACrB,IAAA,cAAA,CAAA,UAAA,CAAA,GAAA,UAAqB;AACrB,IAAA,cAAA,CAAA,UAAA,CAAA,GAAA,UAAqB;AACrB,IAAA,cAAA,CAAA,UAAA,CAAA,GAAA,UAAqB;AACrB,IAAA,cAAA,CAAA,WAAA,CAAA,GAAA,WAAuB;AACvB,IAAA,cAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACf,CAAC,EAXW,cAAc,KAAd,cAAc,GAAA,EAAA,CAAA,CAAA;AAapB,MAAO,eAAgB,SAAQ,wBAAwB,CAAA;AAK3D,IAAA,WAAA,CAAY,EAAE,WAAW,EAAE,MAAM,EAAe,EAAA;QAC9C,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,OAAQ,CAAC,OAAO,CAAC,MAAM,CAAC;AAClD,QAAA,IAAI,CAAC,UAAU,GAAG,WAAW,CAAC,UAAU;AACxC,QAAA,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC,OAAQ;AACnC,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW;IAChC;IAEA,MAAM,GAAA;AACJ,QAAA,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IACvD;AACD;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
export * from './gamepad/stateful-button-axes-device.js';
|
|
7
8
|
export * from './gamepad/stateful-gamepad.js';
|
|
8
9
|
export * from './gamepad/input-profiles.js';
|
|
9
10
|
export * from './visual/adapter/base-visual-adapter.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yCAAyC,CAAC;AAGxD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,sCAAsC,CAAC;AACrD,cAAc,2CAA2C,CAAC;AAG1D,cAAc,yCAAyC,CAAC;AACxD,cAAc,gCAAgC,CAAC;AAG/C,cAAc,qCAAqC,CAAC;AAGpD,cAAc,oBAAoB,CAAC;AAGnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,0CAA0C,CAAC;AACzD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yCAAyC,CAAC;AAGxD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,sCAAsC,CAAC;AACrD,cAAc,2CAA2C,CAAC;AAG1D,cAAc,yCAAyC,CAAC;AACxD,cAAc,gCAAgC,CAAC;AAG/C,cAAc,qCAAqC,CAAC;AAGpD,cAAc,oBAAoB,CAAC;AAGnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { AxesState,
|
|
1
|
+
export { AxesState, StatefulButtonAxesDevice } from './gamepad/stateful-button-axes-device.js';
|
|
2
|
+
export { InputComponent, StatefulGamepad } from './gamepad/stateful-gamepad.js';
|
|
2
3
|
export { DEFAULT_PROFILES_PATH, fetchJsonFile, fetchProfile, fetchProfileSync, fetchProfilesList, loadInputProfile } from './gamepad/input-profiles.js';
|
|
3
4
|
export { XRInputVisualAdapter } from './visual/adapter/base-visual-adapter.js';
|
|
4
5
|
export { XRControllerVisualAdapter } from './visual/adapter/controller-visual-adapter.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cursor-visual.d.ts","sourceRoot":"","sources":["../../src/pointer/cursor-visual.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAW3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AA6BpD;;;;;GAKG;AACH,qBAAa,YAAY;IAMrB,OAAO,CAAC,QAAQ;IALlB,OAAO,CAAC,MAAM,CAA0C;IACxD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAK;gBAGb,QAAQ,EAAE,QAAQ,EAC1B,YAAY,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"cursor-visual.d.ts","sourceRoot":"","sources":["../../src/pointer/cursor-visual.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAW3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AA6BpD;;;;;GAKG;AACH,qBAAa,YAAY;IAMrB,OAAO,CAAC,QAAQ;IALlB,OAAO,CAAC,MAAM,CAA0C;IACxD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAK;gBAGb,QAAQ,EAAE,QAAQ,EAC1B,YAAY,EAAE,MAAM;IAgBtB;;OAEG;IACH,sBAAsB,CACpB,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,GACf,IAAI;IA0CP;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIlC;;OAEG;IACH,OAAO,IAAI,IAAI;CAKhB"}
|