@margoengine/xr 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +592 -3
- package/dist/ar-extra.d.ts +167 -0
- package/dist/ar-extra.js +247 -0
- package/dist/ar.d.ts +177 -0
- package/dist/ar.js +195 -0
- package/dist/body.d.ts +58 -0
- package/dist/body.js +134 -0
- package/dist/controller.d.ts +32 -0
- package/dist/device-check.d.ts +39 -0
- package/dist/device-check.js +155 -0
- package/dist/errors-XvcwUnU4.js +7 -0
- package/dist/eye-target.d.ts +25 -0
- package/dist/eyes.d.ts +24 -0
- package/dist/gizmo.d.ts +165 -0
- package/dist/gizmo.js +198 -0
- package/dist/hands.d.ts +48 -0
- package/dist/hands.js +198 -0
- package/dist/hit-test.d.ts +69 -0
- package/dist/index.d.ts +148 -0
- package/dist/index.js +957 -0
- package/dist/interaction.d.ts +136 -0
- package/dist/interaction.js +205 -0
- package/dist/launch.d.ts +65 -0
- package/dist/launch.js +54 -0
- package/dist/layers-BTUTAawG.js +391 -0
- package/dist/layers.d.ts +247 -0
- package/dist/layers.js +1 -0
- package/dist/locomotion.d.ts +63 -0
- package/dist/locomotion.js +184 -0
- package/dist/models.d.ts +136 -0
- package/dist/models.js +335 -0
- package/dist/near.d.ts +465 -0
- package/dist/near.js +643 -0
- package/dist/occlusion.d.ts +49 -0
- package/dist/occlusion.js +218 -0
- package/dist/performance.d.ts +67 -0
- package/dist/performance.js +78 -0
- package/dist/pointer.d.ts +93 -0
- package/dist/pointer.js +205 -0
- package/dist/reflection.d.ts +70 -0
- package/dist/reflection.js +147 -0
- package/dist/renderer.d.ts +21 -0
- package/dist/scene-owner-BRObO-WJ.js +15 -0
- package/dist/scene-owner.d.ts +3 -0
- package/dist/scene-scope-DufD_3B6.js +42 -0
- package/dist/session.d.ts +60 -0
- package/dist/session.js +68 -0
- package/dist/shared/xr-run.d.ts +64 -0
- package/dist/types.d.ts +221 -0
- package/package.json +153 -6
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type XRLayersHost } from './layers.js';
|
|
2
|
+
import type { XREyeTarget } from './eye-target.js';
|
|
3
|
+
/** XR host accepted by the smooth locomotion controller. */
|
|
4
|
+
export interface SmoothLocomotionHost extends XRLayersHost {
|
|
5
|
+
onEye(callback: (target: XREyeTarget) => void): () => void;
|
|
6
|
+
}
|
|
7
|
+
/** Comfort and movement options; speeds use metres and radians per second. */
|
|
8
|
+
export interface SmoothLocomotionOptions {
|
|
9
|
+
/** Translation speed. Default 2 metres/second. */
|
|
10
|
+
speed?: number;
|
|
11
|
+
/** Turning speed. Default Math.PI / 2 radians/second. */
|
|
12
|
+
turnSpeed?: number;
|
|
13
|
+
/** Movement controller. Default 'left'. */
|
|
14
|
+
moveHand?: 'left' | 'right';
|
|
15
|
+
/** Turning controller. Default 'right'. */
|
|
16
|
+
turnHand?: 'left' | 'right';
|
|
17
|
+
/** Movement direction. Default 'head'; controller uses its grip or target ray. */
|
|
18
|
+
direction?: 'head' | 'controller';
|
|
19
|
+
/** Radial dead zone, 0 <= value < 1. Default 0.15. */
|
|
20
|
+
deadZone?: number;
|
|
21
|
+
/** Thumbstick axes [horizontal, vertical]. Default [2, 3], the xr-standard thumbstick. */
|
|
22
|
+
axes?: readonly [number, number];
|
|
23
|
+
/** Use a soft stereo angular field-of-view restrictor. Default true. */
|
|
24
|
+
vignette?: boolean;
|
|
25
|
+
/** Full angular opening at maximum movement. Default Math.PI / 2 (90 degrees). */
|
|
26
|
+
fieldOfView?: number;
|
|
27
|
+
/** Soft angular border in radians. Default 0.2. */
|
|
28
|
+
feather?: number;
|
|
29
|
+
/** Exponential fade response in seconds. Default 0.15. */
|
|
30
|
+
fade?: number;
|
|
31
|
+
/** Stop and release resources when aborted. */
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
}
|
|
34
|
+
/** Smooth planar movement and turning alongside teleport, with a stereo comfort vignette. */
|
|
35
|
+
export declare class SmoothLocomotion {
|
|
36
|
+
private readonly xr;
|
|
37
|
+
private readonly movement;
|
|
38
|
+
private readonly stops;
|
|
39
|
+
private readonly overlay;
|
|
40
|
+
private readonly options;
|
|
41
|
+
private readonly session;
|
|
42
|
+
private floor;
|
|
43
|
+
private amount;
|
|
44
|
+
private disposed;
|
|
45
|
+
/** Enable thumbstick translation and turning. Default true. Teleport and snap turning remain available. */
|
|
46
|
+
enabled: boolean;
|
|
47
|
+
/** Current vignette strength, from zero to one. */
|
|
48
|
+
get comfort(): number;
|
|
49
|
+
/** Attaches to an active XR session. Session end disposes it; attach again after entering the next session. */
|
|
50
|
+
static attach(xr: SmoothLocomotionHost, options?: SmoothLocomotionOptions): SmoothLocomotion;
|
|
51
|
+
private constructor();
|
|
52
|
+
/** Teleport to a floor point in the current reference space. Default yaw 0. */
|
|
53
|
+
teleport(target: readonly [number, number, number], yaw?: number): void;
|
|
54
|
+
/** Snap turn about the current tracked feet by yaw radians. */
|
|
55
|
+
turn(yaw: number): void;
|
|
56
|
+
private live;
|
|
57
|
+
private update;
|
|
58
|
+
private turnAxis;
|
|
59
|
+
private stick;
|
|
60
|
+
/** Unsubscribe and release the vignette buffers. Idempotent. */
|
|
61
|
+
dispose(): void;
|
|
62
|
+
[Symbol.dispose]: () => void;
|
|
63
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// @margo/core-built 0.1.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
|
|
4
|
+
import { n as e } from "./errors-XvcwUnU4.js";
|
|
5
|
+
import { t } from "./layers-BTUTAawG.js";
|
|
6
|
+
//#region src/locomotion.ts
|
|
7
|
+
var n = class n {
|
|
8
|
+
get comfort() {
|
|
9
|
+
return this.amount;
|
|
10
|
+
}
|
|
11
|
+
static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
|
|
12
|
+
return new n(e, t);
|
|
13
|
+
}
|
|
14
|
+
constructor(n, i) {
|
|
15
|
+
this.xr = n, this.stops = [], this.overlay = new r(), this.floor = 0, this.amount = 0, this.disposed = !1, this.enabled = !0;
|
|
16
|
+
let a = this.options = {
|
|
17
|
+
speed: 2,
|
|
18
|
+
turnSpeed: Math.PI / 2,
|
|
19
|
+
moveHand: "left",
|
|
20
|
+
turnHand: "right",
|
|
21
|
+
direction: "head",
|
|
22
|
+
deadZone: .15,
|
|
23
|
+
axes: [2, 3],
|
|
24
|
+
vignette: !0,
|
|
25
|
+
fieldOfView: Math.PI / 2,
|
|
26
|
+
feather: .2,
|
|
27
|
+
fade: .15,
|
|
28
|
+
...i
|
|
29
|
+
};
|
|
30
|
+
for (let [e, t] of Object.entries({
|
|
31
|
+
speed: a.speed,
|
|
32
|
+
turnSpeed: a.turnSpeed,
|
|
33
|
+
feather: a.feather,
|
|
34
|
+
fade: a.fade
|
|
35
|
+
})) if (!Number.isFinite(t) || t < 0) throw RangeError(`${e} must be finite and nonnegative; pass a movement option such as { speed: 2 }`);
|
|
36
|
+
if (!Number.isFinite(a.deadZone) || a.deadZone < 0 || a.deadZone >= 1 || !Number.isFinite(a.fieldOfView) || a.fieldOfView <= 0 || a.fieldOfView >= Math.PI) throw RangeError("Use a deadZone in [0, 1) and a fieldOfView in (0, Math.PI); pass { deadZone: 0.15, fieldOfView: Math.PI / 2 }");
|
|
37
|
+
if (a.axes.length !== 2 || a.axes.some((e) => !Number.isSafeInteger(e) || e < 0) || a.axes[0] === a.axes[1]) throw RangeError("axes must be two distinct nonnegative integer indices; pass [2, 3] for xr-standard");
|
|
38
|
+
if (!["left", "right"].includes(a.moveHand) || !["left", "right"].includes(a.turnHand) || !["head", "controller"].includes(a.direction)) throw TypeError("Choose left/right hands and head/controller direction; pass { moveHand: \"left\", direction: \"head\" }");
|
|
39
|
+
if (typeof n?.onEye != "function" || typeof n?.onFrame != "function") throw TypeError("SmoothLocomotion needs an XR with stereo eye hooks; pass the XR from XR.create");
|
|
40
|
+
if (!n.session) throw e("state", "SmoothLocomotion needs an active session; await xr.requestSession first");
|
|
41
|
+
this.session = n.session, a.axes = [a.axes[0], a.axes[1]], i.signal?.throwIfAborted(), this.movement = t.attach(n);
|
|
42
|
+
let o = () => this.dispose();
|
|
43
|
+
if (this.session.addEventListener("end", o), this.stops.push(() => this.session.removeEventListener("end", o)), this.stops.push(n.onFrame((e) => this.update(e)), n.onEye((e) => {
|
|
44
|
+
a.vignette && this.amount > 1e-4 && this.overlay.draw(e, this.amount, a.fieldOfView, a.feather);
|
|
45
|
+
})), i.signal) {
|
|
46
|
+
let e = () => this.dispose();
|
|
47
|
+
i.signal.addEventListener("abort", e, { once: !0 }), this.stops.push(() => i.signal.removeEventListener("abort", e));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
teleport(e, t = 0) {
|
|
51
|
+
this.live(), this.movement.teleport(e, t), this.floor = e[1];
|
|
52
|
+
}
|
|
53
|
+
turn(e) {
|
|
54
|
+
this.live(), this.movement.turn(e);
|
|
55
|
+
}
|
|
56
|
+
live() {
|
|
57
|
+
if (this.disposed) throw e("disposed", "SmoothLocomotion is disposed; attach a new controller");
|
|
58
|
+
if (this.xr.session !== this.session) throw e("state", "The XR session changed; attach a new locomotion controller");
|
|
59
|
+
}
|
|
60
|
+
update(e) {
|
|
61
|
+
if (e.frame.session !== this.session || this.xr.session !== this.session) return;
|
|
62
|
+
let t = Math.max(0, Math.min(Number.isFinite(e.delta) ? e.delta : 0, .1));
|
|
63
|
+
if (t === 0) return;
|
|
64
|
+
let n = e.viewer, r = 0;
|
|
65
|
+
if (this.enabled && n && t > 0) {
|
|
66
|
+
let i = e.inputs.find((e) => e.source.handedness === this.options.moveHand), a = e.inputs.find((e) => e.source.handedness === this.options.turnHand), [o, s] = this.stick(i?.source), c = this.turnAxis(a?.source), l = this.options.direction === "head" ? n : i?.grip ?? i?.targetRay, u = 0, d = 0;
|
|
67
|
+
if (l) {
|
|
68
|
+
let e = l.transform.matrix, n = Math.hypot(e[8], e[10]);
|
|
69
|
+
n > 1e-8 && (u = (e[10] * o + e[8] * s) / n * this.options.speed * t, d = (-e[8] * o + e[10] * s) / n * this.options.speed * t);
|
|
70
|
+
}
|
|
71
|
+
let f = -c * this.options.turnSpeed * t, p = n.transform.position;
|
|
72
|
+
(u || d || f) && this.movement.teleport([
|
|
73
|
+
p.x + u,
|
|
74
|
+
this.floor,
|
|
75
|
+
p.z + d
|
|
76
|
+
], f), r = Math.max(u || d ? Math.hypot(o, s) : 0, f ? Math.abs(c) : 0);
|
|
77
|
+
}
|
|
78
|
+
this.amount += (r - this.amount) * (this.options.fade === 0 ? 1 : -Math.expm1(-t / this.options.fade));
|
|
79
|
+
}
|
|
80
|
+
turnAxis(e) {
|
|
81
|
+
let t = e?.gamepad;
|
|
82
|
+
if (!t?.connected) return 0;
|
|
83
|
+
let n = t.axes[this.options.axes[0]] ?? 0, r = Math.abs(n), i = this.options.deadZone;
|
|
84
|
+
return Number.isFinite(n) && r > i ? Math.sign(n) * (Math.min(1, r) - i) / (1 - i) : 0;
|
|
85
|
+
}
|
|
86
|
+
stick(e) {
|
|
87
|
+
let t = e?.gamepad, [n, r] = this.options.axes;
|
|
88
|
+
if (!t || !t.connected) return [0, 0];
|
|
89
|
+
let i = t.axes[n] ?? 0, a = t.axes[r] ?? 0;
|
|
90
|
+
if (!Number.isFinite(i) || !Number.isFinite(a)) return [0, 0];
|
|
91
|
+
let o = Math.hypot(i, a), s = this.options.deadZone, c = o > s ? (Math.min(1, o) - s) / (1 - s) / o : 0;
|
|
92
|
+
return [i * c, a * c];
|
|
93
|
+
}
|
|
94
|
+
dispose() {
|
|
95
|
+
if (!this.disposed) {
|
|
96
|
+
this.disposed = !0, this.movement.dispose();
|
|
97
|
+
for (let e of this.stops) e();
|
|
98
|
+
this.stops.length = 0, this.overlay.dispose();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
[Symbol.dispose ?? Symbol()]() {
|
|
102
|
+
this.dispose();
|
|
103
|
+
}
|
|
104
|
+
}, r = class {
|
|
105
|
+
constructor() {
|
|
106
|
+
this.eyes = /* @__PURE__ */ new Map();
|
|
107
|
+
}
|
|
108
|
+
draw(e, t, n, r) {
|
|
109
|
+
let { device: i, encoder: a, image: o, view: s } = e, c = o.colorTexture.format;
|
|
110
|
+
if (this.device !== i || this.format !== c) {
|
|
111
|
+
this.dispose(), this.device = i, this.format = c;
|
|
112
|
+
let e = i.createShaderModule({ code: "\nstruct Params { viewport:vec4f, projection:vec4f, comfort:vec4f }\n@group(0) @binding(0) var<uniform> u:Params;\n@vertex fn vertex(@builtin(vertex_index) i:u32)->@builtin(position) vec4f {\nreturn vec4f(array<vec2f,3>(vec2f(-1,-1),vec2f(3,-1),vec2f(-1,3))[i],0,1); }\n@fragment fn fragment(@builtin(position) p:vec4f)->@location(0) vec4f {\nlet ndc=(p.xy-u.viewport.xy)/u.viewport.zw*2.0-1.0;\nlet ray=vec2f((ndc.x+u.projection.z)/u.projection.x,(-ndc.y+u.projection.w)/u.projection.y);\nlet angle=atan(length(ray));\nlet a=smoothstep(u.comfort.y,u.comfort.y+max(u.comfort.z,0.00001),angle)*u.comfort.x;\nreturn vec4f(0,0,0,a); }" });
|
|
113
|
+
this.pipeline = i.createRenderPipeline({
|
|
114
|
+
layout: "auto",
|
|
115
|
+
vertex: {
|
|
116
|
+
module: e,
|
|
117
|
+
entryPoint: "vertex"
|
|
118
|
+
},
|
|
119
|
+
fragment: {
|
|
120
|
+
module: e,
|
|
121
|
+
entryPoint: "fragment",
|
|
122
|
+
targets: [{
|
|
123
|
+
format: c,
|
|
124
|
+
blend: {
|
|
125
|
+
color: {
|
|
126
|
+
srcFactor: "one",
|
|
127
|
+
dstFactor: "one-minus-src-alpha"
|
|
128
|
+
},
|
|
129
|
+
alpha: {
|
|
130
|
+
srcFactor: "one",
|
|
131
|
+
dstFactor: "one-minus-src-alpha"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}]
|
|
135
|
+
},
|
|
136
|
+
primitive: { topology: "triangle-list" }
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
let l = this.eyes.get(e.index);
|
|
140
|
+
if (!l) {
|
|
141
|
+
let t = i.createBuffer({
|
|
142
|
+
size: 48,
|
|
143
|
+
usage: 72
|
|
144
|
+
});
|
|
145
|
+
l = {
|
|
146
|
+
buffer: t,
|
|
147
|
+
group: i.createBindGroup({
|
|
148
|
+
layout: this.pipeline.getBindGroupLayout(0),
|
|
149
|
+
entries: [{
|
|
150
|
+
binding: 0,
|
|
151
|
+
resource: { buffer: t }
|
|
152
|
+
}]
|
|
153
|
+
})
|
|
154
|
+
}, this.eyes.set(e.index, l);
|
|
155
|
+
}
|
|
156
|
+
let { x: u, y: d, width: f, height: p } = o.viewport, m = s.projectionMatrix;
|
|
157
|
+
i.queue.writeBuffer(l.buffer, 0, new Float32Array([
|
|
158
|
+
u,
|
|
159
|
+
d,
|
|
160
|
+
f,
|
|
161
|
+
p,
|
|
162
|
+
m[0],
|
|
163
|
+
m[5],
|
|
164
|
+
m[8],
|
|
165
|
+
m[9],
|
|
166
|
+
t,
|
|
167
|
+
n / 2,
|
|
168
|
+
r,
|
|
169
|
+
0
|
|
170
|
+
]));
|
|
171
|
+
let h = a.beginRenderPass({ colorAttachments: [{
|
|
172
|
+
view: o.colorTexture.createView(o.getViewDescriptor()),
|
|
173
|
+
loadOp: "load",
|
|
174
|
+
storeOp: "store"
|
|
175
|
+
}] });
|
|
176
|
+
h.setViewport(u, d, f, p, 0, 1), h.setScissorRect(u, d, f, p), h.setPipeline(this.pipeline), h.setBindGroup(0, l.group), h.draw(3), h.end();
|
|
177
|
+
}
|
|
178
|
+
dispose() {
|
|
179
|
+
for (let e of this.eyes.values()) e.buffer.destroy();
|
|
180
|
+
this.eyes.clear(), this.pipeline = void 0, this.device = void 0;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
//#endregion
|
|
184
|
+
export { n as SmoothLocomotion };
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { type EngineKernel, type Mesh } from '@margoengine/core';
|
|
2
|
+
import type { XRController } from './controller.js';
|
|
3
|
+
import type { XRInputSource } from './types.js';
|
|
4
|
+
/** What the models need of an `XR`: its controllers and a per-frame hook. */
|
|
5
|
+
export interface XRModelsHost {
|
|
6
|
+
readonly controllers: readonly XRController[];
|
|
7
|
+
onFrame(callback: () => void): () => void;
|
|
8
|
+
}
|
|
9
|
+
/** Options for {@link XRModels.attach}. */
|
|
10
|
+
export interface XRModelsOptions {
|
|
11
|
+
/** Draw a controller at each held controller's grip. Default true. */
|
|
12
|
+
controllers?: boolean;
|
|
13
|
+
/** Draw each tracked hand's joints and bones. Default true. */
|
|
14
|
+
hands?: boolean;
|
|
15
|
+
/** Controller colour. Default '#d9dde2'. */
|
|
16
|
+
color?: string;
|
|
17
|
+
/** Colour of a pressed trigger, squeeze, touchpad or thumbstick. Default '#3d8fe0'. */
|
|
18
|
+
pressedColor?: string;
|
|
19
|
+
/** Hand colour. Default '#e3bfa3'. */
|
|
20
|
+
handColor?: string;
|
|
21
|
+
}
|
|
22
|
+
/** The 25 joints' bones: [from, to] in the Hand Input Module's order, the wrist to each metacarpal included. */
|
|
23
|
+
export declare const HAND_BONES: readonly (readonly [number, number])[];
|
|
24
|
+
/**
|
|
25
|
+
* Draws a model at every controller's grip and every tracked hand's joints, kept in step with `xr.controllers` each XR
|
|
26
|
+
* frame: a held controller with its trigger, squeeze and thumbstick moving as they are used, a hand as spheres at its
|
|
27
|
+
* joints sized by their radii and cylinders along its bones. An input source with `skipRendering` true (the system
|
|
28
|
+
* already shows it) and an untracked one are hidden. `dispose()` removes the meshes.
|
|
29
|
+
*/
|
|
30
|
+
export declare class XRModels {
|
|
31
|
+
private readonly xr;
|
|
32
|
+
private readonly engine;
|
|
33
|
+
private readonly controllerParts;
|
|
34
|
+
private readonly handParts;
|
|
35
|
+
private readonly materials;
|
|
36
|
+
private readonly geometry;
|
|
37
|
+
private readonly unsubscribe;
|
|
38
|
+
/** Runs mesh creation in the scene the models belong to; XR frames arrive with any scene active. */
|
|
39
|
+
private readonly scope;
|
|
40
|
+
private readonly release?;
|
|
41
|
+
private readonly q;
|
|
42
|
+
private readonly rotation;
|
|
43
|
+
private readonly joint;
|
|
44
|
+
private readonly bone;
|
|
45
|
+
private readonly settings;
|
|
46
|
+
private disposed;
|
|
47
|
+
/**
|
|
48
|
+
* Starts drawing `xr`'s inputs in `engine`, in the scene `xr` is in (for a host that is no plugin, the scene set up or
|
|
49
|
+
* drawn when `attach` is called). The models go when that scene is disposed.
|
|
50
|
+
*/
|
|
51
|
+
static attach(xr: XRModelsHost, engine: EngineKernel, options?: XRModelsOptions): XRModels;
|
|
52
|
+
private constructor();
|
|
53
|
+
/** The meshes of `source`'s controller model, root first, or undefined before it is first seen. */
|
|
54
|
+
controllerMeshes(source: XRInputSource): readonly Mesh[] | undefined;
|
|
55
|
+
/** The joint and bone meshes of `source`'s hand, or undefined before it is first tracked. */
|
|
56
|
+
handMeshes(source: XRInputSource): {
|
|
57
|
+
joints: readonly Mesh[];
|
|
58
|
+
bones: readonly Mesh[];
|
|
59
|
+
} | undefined;
|
|
60
|
+
private part;
|
|
61
|
+
private controller;
|
|
62
|
+
private hand;
|
|
63
|
+
/** Moves every model to this frame's poses; runs from the XR frame hook. */
|
|
64
|
+
update(): void;
|
|
65
|
+
private placeController;
|
|
66
|
+
private placeHand;
|
|
67
|
+
private towards;
|
|
68
|
+
/** Removes every model and stops following the session. Safe to call twice. */
|
|
69
|
+
dispose(): void;
|
|
70
|
+
/** Same as {@link XRModels.dispose}, for `using`. */
|
|
71
|
+
[Symbol.dispose](): void;
|
|
72
|
+
}
|
|
73
|
+
/** One component's state, as the input profile assets describe it. */
|
|
74
|
+
export interface ComponentState {
|
|
75
|
+
readonly state: 'default' | 'touched' | 'pressed';
|
|
76
|
+
/** The button's value, 0 to 1. */
|
|
77
|
+
readonly button: number;
|
|
78
|
+
/** The x and y axes, -1 to 1, where the component has them. */
|
|
79
|
+
readonly xAxis: number;
|
|
80
|
+
readonly yAxis: number;
|
|
81
|
+
}
|
|
82
|
+
/** The parts of an input profile asset file that the model needs: its layouts by handedness. */
|
|
83
|
+
export interface InputProfile {
|
|
84
|
+
readonly profileId: string;
|
|
85
|
+
readonly layouts: Readonly<Record<string, {
|
|
86
|
+
readonly assetPath?: string;
|
|
87
|
+
readonly rootNodeName?: string;
|
|
88
|
+
readonly gamepad?: {
|
|
89
|
+
readonly buttons: readonly (string | null)[];
|
|
90
|
+
readonly axes: readonly ({
|
|
91
|
+
readonly componentId: string;
|
|
92
|
+
readonly axis: 'xAxis' | 'yAxis';
|
|
93
|
+
} | null)[];
|
|
94
|
+
};
|
|
95
|
+
readonly components: Readonly<Record<string, {
|
|
96
|
+
readonly visualResponses?: Readonly<Record<string, {
|
|
97
|
+
readonly componentProperty: 'button' | 'xAxis' | 'yAxis' | 'state';
|
|
98
|
+
readonly states: readonly ('default' | 'touched' | 'pressed')[];
|
|
99
|
+
readonly valueNodeProperty: 'transform' | 'visibility';
|
|
100
|
+
} | null>>;
|
|
101
|
+
}>>;
|
|
102
|
+
}>>;
|
|
103
|
+
}
|
|
104
|
+
/** What {@link fetchProfile} found for an input source. */
|
|
105
|
+
export interface FoundProfile {
|
|
106
|
+
/** The profile id that matched, from the source's `profiles`, most specific first. */
|
|
107
|
+
readonly id: string;
|
|
108
|
+
readonly profile: InputProfile;
|
|
109
|
+
/** The layout for the source's handedness. */
|
|
110
|
+
readonly layout: InputProfile['layouts'][string];
|
|
111
|
+
/** Absolute URL of the layout's model file. */
|
|
112
|
+
readonly assetUrl: string;
|
|
113
|
+
}
|
|
114
|
+
/** The layout of `profile` for `handedness`: its own key, or a key that joins several handednesses with hyphens. */
|
|
115
|
+
export declare function profileLayout(profile: InputProfile, handedness: string): InputProfile['layouts'][string] | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* Finds `source`'s model in the input profile assets served at `base` (a folder URL holding `profilesList.json` and a
|
|
118
|
+
* folder per profile): the first of `source.profiles` that the list holds, else `fallback`, then its `profile.json`
|
|
119
|
+
* and the layout for the source's handedness. Margo ships no such files; serve the assets your app uses.
|
|
120
|
+
* @throws MargoError 'unsupported' when no profile of the source or the fallback is listed; 'failed' when a file fails.
|
|
121
|
+
*/
|
|
122
|
+
export declare function fetchProfile(source: Pick<XRInputSource, 'profiles' | 'handedness'>, base: string | URL, { fallback, signal }?: {
|
|
123
|
+
fallback?: string;
|
|
124
|
+
signal?: AbortSignal;
|
|
125
|
+
}): Promise<FoundProfile>;
|
|
126
|
+
/** Each component's state this frame, from the layout's gamepad mapping and `controller`'s buttons and axes. */
|
|
127
|
+
export declare function componentStates(layout: InputProfile['layouts'][string], controller: Pick<XRController, 'buttons' | 'axes' | 'buttonCount' | 'axisCount'>): Record<string, ComponentState>;
|
|
128
|
+
/**
|
|
129
|
+
* How far a visual response goes, 0 (its `_min` node, or hidden) to 1 (its `_max` node, or shown): the button value,
|
|
130
|
+
* an axis mapped from -1..1 to 0..1, or for `state` whether the component is in one of the response's states. Outside
|
|
131
|
+
* those states a response rests: 0 for a button or a state, 0.5 for an axis.
|
|
132
|
+
*/
|
|
133
|
+
export declare function responseWeight(response: {
|
|
134
|
+
componentProperty: 'button' | 'xAxis' | 'yAxis' | 'state';
|
|
135
|
+
states: readonly string[];
|
|
136
|
+
}, component: ComponentState): number;
|