@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
package/dist/models.js
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
// @margo/core-built 0.1.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
const i=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
|
+
import { n as e } from "./errors-XvcwUnU4.js";
|
|
5
|
+
import { n as t, t as n } from "./scene-scope-DufD_3B6.js";
|
|
6
|
+
import { t as r } from "./scene-owner-BRObO-WJ.js";
|
|
7
|
+
import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
8
|
+
import { Geometry as a, PbrMaterial as o } from "@margoengine/core";
|
|
9
|
+
import { Quaternion as s } from "@margoengine/math/quaternion";
|
|
10
|
+
//#region src/models.ts
|
|
11
|
+
function c(e = 8, t = 12) {
|
|
12
|
+
let n = [], r = [];
|
|
13
|
+
for (let r = 0; r <= e; r++) for (let i = 0; i <= t; i++) {
|
|
14
|
+
let a = r / e * Math.PI, o = i / t * 2 * Math.PI;
|
|
15
|
+
n.push(Math.sin(a) * Math.cos(o), Math.cos(a), Math.sin(a) * Math.sin(o));
|
|
16
|
+
}
|
|
17
|
+
for (let n = 0; n < e; n++) for (let e = 0; e < t; e++) {
|
|
18
|
+
let i = n * (t + 1) + e, a = i + t + 1;
|
|
19
|
+
r.push(i, i + 1, a, i + 1, a + 1, a);
|
|
20
|
+
}
|
|
21
|
+
return new a(n, n, r);
|
|
22
|
+
}
|
|
23
|
+
function l(e = 12) {
|
|
24
|
+
let t = [], n = [], r = [];
|
|
25
|
+
for (let r of [-.5, .5]) for (let i = 0; i <= e; i++) {
|
|
26
|
+
let a = i / e * 2 * Math.PI;
|
|
27
|
+
t.push(Math.cos(a), Math.sin(a), r), n.push(Math.cos(a), Math.sin(a), 0);
|
|
28
|
+
}
|
|
29
|
+
for (let t = 0; t < e; t++) r.push(t, t + 1, t + e + 1, t + 1, t + e + 2, t + e + 1);
|
|
30
|
+
for (let i of [-.5, .5]) {
|
|
31
|
+
let a = t.length / 3;
|
|
32
|
+
t.push(0, 0, i), n.push(0, 0, Math.sign(i));
|
|
33
|
+
for (let r = 0; r <= e; r++) {
|
|
34
|
+
let a = r / e * 2 * Math.PI;
|
|
35
|
+
t.push(Math.cos(a), Math.sin(a), i), n.push(0, 0, Math.sign(i));
|
|
36
|
+
}
|
|
37
|
+
for (let t = 0; t < e; t++) i > 0 ? r.push(a, a + 1 + t, a + 2 + t) : r.push(a, a + 2 + t, a + 1 + t);
|
|
38
|
+
}
|
|
39
|
+
return new a(t, n, r);
|
|
40
|
+
}
|
|
41
|
+
var u = {
|
|
42
|
+
x: 0,
|
|
43
|
+
y: 0,
|
|
44
|
+
z: -1
|
|
45
|
+
}, d = (() => {
|
|
46
|
+
let e = [];
|
|
47
|
+
for (let t of [
|
|
48
|
+
1,
|
|
49
|
+
5,
|
|
50
|
+
10,
|
|
51
|
+
15,
|
|
52
|
+
20
|
|
53
|
+
]) {
|
|
54
|
+
e.push([0, t]);
|
|
55
|
+
let n = t === 1 ? 4 : t + 4;
|
|
56
|
+
for (let r = t; r < n; r++) e.push([r, r + 1]);
|
|
57
|
+
}
|
|
58
|
+
return e;
|
|
59
|
+
})(), f = class e {
|
|
60
|
+
static attach(t, n, r = {}) {__margoAssertCore(t,__margoCoreRequirement("0.1.0",import.meta.url));
|
|
61
|
+
return new e(t, n, r);
|
|
62
|
+
}
|
|
63
|
+
constructor(e, a, u) {
|
|
64
|
+
if (this.xr = e, this.engine = a, this.controllerParts = /* @__PURE__ */ new Map(), this.handParts = /* @__PURE__ */ new Map(), this.q = [
|
|
65
|
+
0,
|
|
66
|
+
0,
|
|
67
|
+
0,
|
|
68
|
+
1
|
|
69
|
+
], this.rotation = new s(), this.joint = { elements: /* @__PURE__ */ new Float32Array(16) }, this.bone = {
|
|
70
|
+
x: 0,
|
|
71
|
+
y: 0,
|
|
72
|
+
z: 0
|
|
73
|
+
}, this.disposed = !1, typeof e?.onFrame != "function" || !Array.isArray(e.controllers)) throw TypeError("XRModels.attach needs an XR from XR.create; pass the XR, then the engine");
|
|
74
|
+
this.settings = {
|
|
75
|
+
controllers: u.controllers ?? !0,
|
|
76
|
+
hands: u.hands ?? !0
|
|
77
|
+
}, this.materials = {
|
|
78
|
+
body: new o({
|
|
79
|
+
color: u.color ?? "#d9dde2",
|
|
80
|
+
roughness: .6
|
|
81
|
+
}),
|
|
82
|
+
pressed: new o({
|
|
83
|
+
color: u.pressedColor ?? "#3d8fe0",
|
|
84
|
+
roughness: .5
|
|
85
|
+
}),
|
|
86
|
+
hand: new o({
|
|
87
|
+
color: u.handColor ?? "#e3bfa3",
|
|
88
|
+
roughness: .8
|
|
89
|
+
})
|
|
90
|
+
}, this.geometry = {
|
|
91
|
+
sphere: c(),
|
|
92
|
+
cylinder: l()
|
|
93
|
+
};
|
|
94
|
+
let d = i(a), f = d.sceneOf(e) ?? n(d).scene;
|
|
95
|
+
this.scope = t(d, f), this.unsubscribe = e.onFrame(() => this.update()), f && (this.release = r(f, () => this.dispose()));
|
|
96
|
+
}
|
|
97
|
+
controllerMeshes(e) {
|
|
98
|
+
return this.controllerParts.get(e)?.meshes;
|
|
99
|
+
}
|
|
100
|
+
handMeshes(e) {
|
|
101
|
+
return this.handParts.get(e);
|
|
102
|
+
}
|
|
103
|
+
part(e, t, n) {
|
|
104
|
+
return this.scope.run(() => this.engine.createMesh()).setGeometry(this.geometry.cylinder).setMaterial(this.materials.body).setScale(t).setPosition(n).setParent(e);
|
|
105
|
+
}
|
|
106
|
+
controller(e) {
|
|
107
|
+
let t = this.controllerParts.get(e);
|
|
108
|
+
if (t) return t;
|
|
109
|
+
let n = this.scope.run(() => this.engine.createMesh()), r = e.handedness === "left" ? 1 : -1, i = this.part(n, [
|
|
110
|
+
.018,
|
|
111
|
+
.02,
|
|
112
|
+
.13
|
|
113
|
+
], [
|
|
114
|
+
0,
|
|
115
|
+
0,
|
|
116
|
+
.01
|
|
117
|
+
]), a = this.part(n, [
|
|
118
|
+
.026,
|
|
119
|
+
.026,
|
|
120
|
+
.035
|
|
121
|
+
], [
|
|
122
|
+
0,
|
|
123
|
+
-.012,
|
|
124
|
+
-.065
|
|
125
|
+
]), o = this.part(n, [
|
|
126
|
+
.007,
|
|
127
|
+
.012,
|
|
128
|
+
.03
|
|
129
|
+
], [
|
|
130
|
+
0,
|
|
131
|
+
-.04,
|
|
132
|
+
-.035
|
|
133
|
+
]), s = this.part(n, [
|
|
134
|
+
.006,
|
|
135
|
+
.012,
|
|
136
|
+
.045
|
|
137
|
+
], [
|
|
138
|
+
r * .019,
|
|
139
|
+
0,
|
|
140
|
+
.005
|
|
141
|
+
]), c = this.part(n, [
|
|
142
|
+
.008,
|
|
143
|
+
.008,
|
|
144
|
+
.012
|
|
145
|
+
], [
|
|
146
|
+
0,
|
|
147
|
+
-.012,
|
|
148
|
+
-.088
|
|
149
|
+
]), l = this.part(n, [
|
|
150
|
+
.015,
|
|
151
|
+
.015,
|
|
152
|
+
.002
|
|
153
|
+
], [
|
|
154
|
+
0,
|
|
155
|
+
-.012,
|
|
156
|
+
-.083
|
|
157
|
+
]);
|
|
158
|
+
return t = {
|
|
159
|
+
root: n,
|
|
160
|
+
trigger: o,
|
|
161
|
+
squeeze: s,
|
|
162
|
+
stick: c,
|
|
163
|
+
pad: l,
|
|
164
|
+
palm: r,
|
|
165
|
+
meshes: [
|
|
166
|
+
n,
|
|
167
|
+
i,
|
|
168
|
+
a,
|
|
169
|
+
o,
|
|
170
|
+
s,
|
|
171
|
+
c,
|
|
172
|
+
l
|
|
173
|
+
]
|
|
174
|
+
}, this.controllerParts.set(e, t), t;
|
|
175
|
+
}
|
|
176
|
+
hand(e) {
|
|
177
|
+
let t = this.handParts.get(e);
|
|
178
|
+
if (t) return t;
|
|
179
|
+
let n = (e) => this.scope.run(() => this.engine.createMesh()).setGeometry(e).setMaterial(this.materials.hand);
|
|
180
|
+
return t = {
|
|
181
|
+
joints: Array.from({ length: 25 }, () => n(this.geometry.sphere)),
|
|
182
|
+
bones: d.map(() => n(this.geometry.cylinder))
|
|
183
|
+
}, this.handParts.set(e, t), t;
|
|
184
|
+
}
|
|
185
|
+
update() {
|
|
186
|
+
if (this.disposed) return;
|
|
187
|
+
let e = /* @__PURE__ */ new Set();
|
|
188
|
+
for (let t of this.xr.controllers) {
|
|
189
|
+
let n = t.source, r = n.skipRendering === !0;
|
|
190
|
+
if (e.add(n), n.hand && this.settings.hands) {
|
|
191
|
+
let e = this.hand(n), i = !r && t.handTracked[0] === 1;
|
|
192
|
+
this.placeHand(e, t, i);
|
|
193
|
+
} else if (!n.hand && this.settings.controllers && n.gripSpace) {
|
|
194
|
+
let e = this.controller(n);
|
|
195
|
+
this.placeController(e, t, !r && !!t.grip);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
for (let [t, n] of this.controllerParts) if (!e.has(t)) {
|
|
199
|
+
for (let e of n.meshes) e.dispose();
|
|
200
|
+
this.controllerParts.delete(t);
|
|
201
|
+
}
|
|
202
|
+
for (let [t, n] of this.handParts) if (!e.has(t)) {
|
|
203
|
+
for (let e of [...n.joints, ...n.bones]) e.dispose();
|
|
204
|
+
this.handParts.delete(t);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
placeController(e, t, n) {
|
|
208
|
+
for (let t of e.meshes) t.visible = n;
|
|
209
|
+
if (!n) return;
|
|
210
|
+
let { position: r, orientation: i } = t.grip.transform, a = t.buttons, o = t.axes, s = t.source.gamepad?.mapping === "xr-standard", c = s ? a[0] : 0, l = s ? a[3] : 0, u = s && t.axisCount > 2 ? o[2] : 0, d = s && t.axisCount > 3 ? o[3] : 0, f = (e) => s && e < t.buttonCount && a[e * 3 + 1] === 1;
|
|
211
|
+
e.root.setPosition([
|
|
212
|
+
r.x,
|
|
213
|
+
r.y,
|
|
214
|
+
r.z
|
|
215
|
+
]).setQuaternion([
|
|
216
|
+
i.x,
|
|
217
|
+
i.y,
|
|
218
|
+
i.z,
|
|
219
|
+
i.w
|
|
220
|
+
]), e.trigger.setRotation([
|
|
221
|
+
c * .35,
|
|
222
|
+
0,
|
|
223
|
+
0
|
|
224
|
+
]).setMaterial(f(0) ? this.materials.pressed : this.materials.body), e.squeeze.setPosition([
|
|
225
|
+
e.palm * (.019 - .004 * l),
|
|
226
|
+
0,
|
|
227
|
+
.005
|
|
228
|
+
]).setMaterial(f(1) ? this.materials.pressed : this.materials.body), e.stick.setRotation([
|
|
229
|
+
-d * .4,
|
|
230
|
+
0,
|
|
231
|
+
u * .4
|
|
232
|
+
]).setPosition([
|
|
233
|
+
0,
|
|
234
|
+
-.012,
|
|
235
|
+
f(3) ? -.086 : -.088
|
|
236
|
+
]).setMaterial(f(3) ? this.materials.pressed : this.materials.body), e.pad.setMaterial(f(2) ? this.materials.pressed : this.materials.body);
|
|
237
|
+
}
|
|
238
|
+
placeHand(e, t, n) {
|
|
239
|
+
let r = t.handMatrices, i = t.handRadii, a = this.q;
|
|
240
|
+
for (let t = 0; t < 25; t++) {
|
|
241
|
+
let o = e.joints[t];
|
|
242
|
+
if (o.visible = n, !n) continue;
|
|
243
|
+
let s = i[t] > 0 ? i[t] : .008;
|
|
244
|
+
for (let e = 0; e < 16; e++) this.joint.elements[e] = r[t * 16 + e];
|
|
245
|
+
o.setPosition([
|
|
246
|
+
r[t * 16 + 12],
|
|
247
|
+
r[t * 16 + 13],
|
|
248
|
+
r[t * 16 + 14]
|
|
249
|
+
]).setQuaternion(this.rotation.setFromRotationMatrix(this.joint).toArray(a)).setScale([
|
|
250
|
+
s,
|
|
251
|
+
s,
|
|
252
|
+
s
|
|
253
|
+
]);
|
|
254
|
+
}
|
|
255
|
+
for (let t = 0; t < d.length; t++) {
|
|
256
|
+
let o = e.bones[t], [s, c] = d[t];
|
|
257
|
+
if (o.visible = n, !n) continue;
|
|
258
|
+
let l = r[s * 16 + 12], f = r[s * 16 + 13], p = r[s * 16 + 14], m = r[c * 16 + 12] - l, h = r[c * 16 + 13] - f, g = r[c * 16 + 14] - p, _ = Math.hypot(m, h, g), v = .6 * Math.min(i[s] > 0 ? i[s] : .008, i[c] > 0 ? i[c] : .008);
|
|
259
|
+
_ ? o.setPosition([
|
|
260
|
+
l + m / 2,
|
|
261
|
+
f + h / 2,
|
|
262
|
+
p + g / 2
|
|
263
|
+
]).setQuaternion(this.rotation.setFromUnitVectors(u, this.towards(m / _, h / _, g / _)).toArray(a)).setScale([
|
|
264
|
+
v,
|
|
265
|
+
v,
|
|
266
|
+
_
|
|
267
|
+
]) : o.visible = !1;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
towards(e, t, n) {
|
|
271
|
+
return this.bone.x = e, this.bone.y = t, this.bone.z = n, this.bone;
|
|
272
|
+
}
|
|
273
|
+
dispose() {
|
|
274
|
+
if (!this.disposed) {
|
|
275
|
+
this.disposed = !0, this.unsubscribe(), this.release?.();
|
|
276
|
+
for (let e of this.controllerParts.values()) for (let t of e.meshes) t.dispose();
|
|
277
|
+
for (let e of this.handParts.values()) for (let t of [...e.joints, ...e.bones]) t.dispose();
|
|
278
|
+
this.controllerParts.clear(), this.handParts.clear();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
[Symbol.dispose]() {
|
|
282
|
+
this.dispose();
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
function p(e, t) {
|
|
286
|
+
for (let [n, r] of Object.entries(e.layouts ?? {})) if (n === t || n.split("-").includes(t)) return r;
|
|
287
|
+
}
|
|
288
|
+
async function m(t, n, { fallback: r = "generic-trigger", signal: i } = {}) {
|
|
289
|
+
let a = new URL(String(n).endsWith("/") ? String(n) : `${n}/`, globalThis.location?.href), o = async (t) => {
|
|
290
|
+
let n = await fetch(t, { signal: i });
|
|
291
|
+
if (!n.ok) throw e("failed", `${t} answered ${n.status}; serve the input profile assets at the base URL`);
|
|
292
|
+
return n.json();
|
|
293
|
+
}, s = await o(new URL("profilesList.json", a)), c = [...t.profiles, r].find((e) => Object.hasOwn(s, e));
|
|
294
|
+
if (!c) throw e("unsupported", `No input profile listed for ${t.profiles.join(", ") || "this source"}; pass a listed fallback`);
|
|
295
|
+
let l = new URL(s[c].path, a), u = await o(l), d = p(u, t.handedness);
|
|
296
|
+
if (!d) throw e("unsupported", `Profile ${c} has no layout for handedness '${t.handedness}'; use another profile`);
|
|
297
|
+
return {
|
|
298
|
+
id: c,
|
|
299
|
+
profile: u,
|
|
300
|
+
layout: d,
|
|
301
|
+
assetUrl: new URL(d.assetPath ?? `${t.handedness}.glb`, l).href
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
function h(e, t) {
|
|
305
|
+
let n = {};
|
|
306
|
+
for (let t of Object.keys(e.components ?? {})) n[t] = {
|
|
307
|
+
state: "default",
|
|
308
|
+
button: 0,
|
|
309
|
+
xAxis: 0,
|
|
310
|
+
yAxis: 0
|
|
311
|
+
};
|
|
312
|
+
let r = e.gamepad?.buttons ?? [], i = e.gamepad?.axes ?? [];
|
|
313
|
+
for (let e = 0; e < r.length && e < t.buttonCount; e++) {
|
|
314
|
+
let i = r[e];
|
|
315
|
+
if (!i || !n[i]) continue;
|
|
316
|
+
let a = n[i];
|
|
317
|
+
a.button = t.buttons[e * 3], a.state = t.buttons[e * 3 + 1] ? "pressed" : t.buttons[e * 3 + 2] ? "touched" : "default";
|
|
318
|
+
}
|
|
319
|
+
for (let e = 0; e < i.length && e < t.axisCount; e++) {
|
|
320
|
+
let r = i[e];
|
|
321
|
+
r && n[r.componentId] && (n[r.componentId][r.axis] = t.axes[e]);
|
|
322
|
+
}
|
|
323
|
+
return n;
|
|
324
|
+
}
|
|
325
|
+
function g(e, t) {
|
|
326
|
+
let n = e.states.includes(t.state);
|
|
327
|
+
switch (e.componentProperty) {
|
|
328
|
+
case "button": return n ? t.button : 0;
|
|
329
|
+
case "xAxis": return n ? (t.xAxis + 1) / 2 : .5;
|
|
330
|
+
case "yAxis": return n ? (t.yAxis + 1) / 2 : .5;
|
|
331
|
+
default: return +!!n;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
//#endregion
|
|
335
|
+
export { d as HAND_BONES, f as XRModels, h as componentStates, m as fetchProfile, p as profileLayout, g as responseWeight };
|