@margoengine/xr 0.0.0-stage → 1.0.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 +842 -2
- package/dist/ar-extra.d.ts +232 -0
- package/dist/ar-extra.js +315 -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 +45 -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 +1103 -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 +152 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,1103 @@
|
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
const r=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
|
+
import { n as e } from "./errors-XvcwUnU4.js";
|
|
5
|
+
import { t } from "./scene-scope-DufD_3B6.js";
|
|
6
|
+
import { Camera as n, engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
7
|
+
import { Engine as i } from "@margoengine/core";
|
|
8
|
+
import { MargoError as a } from "@margoengine/math/errors";
|
|
9
|
+
function o(e) {
|
|
10
|
+
return e?.adapterInfo?.vendor === "margo-webgl2" ? "webgl2" : "native";
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region ../shared/view-rect.js
|
|
14
|
+
function s(e) {
|
|
15
|
+
return e?.view?.viewport;
|
|
16
|
+
}
|
|
17
|
+
function c(e, t) {
|
|
18
|
+
let n = s(t);
|
|
19
|
+
if (!n) return;
|
|
20
|
+
e.setViewport(n[0], n[1], n[2], n[3], 0, 1);
|
|
21
|
+
let r = t.view.scissor ?? n;
|
|
22
|
+
e.setScissorRect(r[0], r[1], r[2], r[3]);
|
|
23
|
+
}
|
|
24
|
+
function l() {
|
|
25
|
+
return globalThis[Symbol.for("margoengine.layers")];
|
|
26
|
+
}
|
|
27
|
+
function u(e) {
|
|
28
|
+
return l()?.maskOf(e) ?? 1;
|
|
29
|
+
}
|
|
30
|
+
function d(e, t) {
|
|
31
|
+
if (!Number.isInteger(e) || e < 0 || e > 4294967295) throw RangeError(`${t} ${e} is not a 32-bit layer mask; pass an integer from 0 to 0xffffffff`);
|
|
32
|
+
return e >>> 0;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region ../shared/mesh-source.js
|
|
36
|
+
var f = Symbol.for("margoengine.mesh-sources.v1"), p = globalThis[f] ?? /* @__PURE__ */ new WeakMap();
|
|
37
|
+
globalThis[f] || Object.defineProperty(globalThis, f, { value: p });
|
|
38
|
+
var m = Symbol.for("margoengine.geometry-surfaces.v1"), h = globalThis[m] ?? /* @__PURE__ */ new WeakMap();
|
|
39
|
+
globalThis[m] || Object.defineProperty(globalThis, m, { value: h });
|
|
40
|
+
function g(e) {
|
|
41
|
+
if (e?.geometry) return {
|
|
42
|
+
kind: "core",
|
|
43
|
+
geometry: e.geometry
|
|
44
|
+
};
|
|
45
|
+
let t = e && p.get(e);
|
|
46
|
+
if (!t || t.model.disposed) return null;
|
|
47
|
+
try {
|
|
48
|
+
e.check?.();
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
kind: "pbr",
|
|
54
|
+
source: t
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region ../shared/unit-light.js
|
|
59
|
+
function _(e, t, n) {
|
|
60
|
+
let r = Math.hypot(n[0], n[1], n[2]);
|
|
61
|
+
e[t] = n[0] / r, e[t + 1] = n[1] / r, e[t + 2] = n[2] / r, e[t + 3] = n[3];
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region ../shared/hdr-format.js
|
|
65
|
+
var v = (e) => typeof e == "string" && e.endsWith("float");
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region ../shared/pbr-transmission.js
|
|
68
|
+
function y(e) {
|
|
69
|
+
return !!e.tint && !e.renderState && !e.extension?.replacesPhysical;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/renderer.ts
|
|
73
|
+
var b = class {
|
|
74
|
+
constructor(e) {
|
|
75
|
+
this.device = e, this.resources = /* @__PURE__ */ new Map(), this.eyes = [], this.used = /* @__PURE__ */ new Set(), this.pbr = /* @__PURE__ */ new Map();
|
|
76
|
+
}
|
|
77
|
+
configure(e, t) {
|
|
78
|
+
this.dispose(), this.context = e;
|
|
79
|
+
let n = this.device.createShaderModule({ code: e.shader });
|
|
80
|
+
this.pipeline = this.device.createRenderPipeline({
|
|
81
|
+
...e.descriptor,
|
|
82
|
+
multisample: { count: 4 },
|
|
83
|
+
vertex: {
|
|
84
|
+
...e.descriptor.vertex,
|
|
85
|
+
module: n
|
|
86
|
+
},
|
|
87
|
+
fragment: {
|
|
88
|
+
module: n,
|
|
89
|
+
entryPoint: "fragment",
|
|
90
|
+
targets: [{ format: t }]
|
|
91
|
+
},
|
|
92
|
+
depthStencil: {
|
|
93
|
+
format: "depth24plus",
|
|
94
|
+
depthWriteEnabled: !0,
|
|
95
|
+
depthCompare: "less-equal"
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
let r = this.device.createShaderModule({ code: "@group(0) @binding(0) var depth:texture_depth_multisampled_2d;\n@vertex fn vertex(@builtin(vertex_index) i:u32)->@builtin(position) vec4f{return vec4f(array<vec2f,3>(vec2f(-1,-1),vec2f(3,-1),vec2f(-1,3))[i],0,1);}\n@fragment fn fragment(@builtin(position) p:vec4f)->@builtin(frag_depth) f32{let q=vec2i(p.xy);return min(min(textureLoad(depth,q,0),textureLoad(depth,q,1)),min(textureLoad(depth,q,2),textureLoad(depth,q,3)));}" });
|
|
99
|
+
this.depthPipeline = this.device.createRenderPipeline({
|
|
100
|
+
layout: "auto",
|
|
101
|
+
vertex: {
|
|
102
|
+
module: r,
|
|
103
|
+
entryPoint: "vertex"
|
|
104
|
+
},
|
|
105
|
+
fragment: {
|
|
106
|
+
module: r,
|
|
107
|
+
entryPoint: "fragment",
|
|
108
|
+
targets: []
|
|
109
|
+
},
|
|
110
|
+
depthStencil: {
|
|
111
|
+
format: "depth24plus",
|
|
112
|
+
depthWriteEnabled: !0,
|
|
113
|
+
depthCompare: "always"
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
render(e, t, n, r, i, o, s) {
|
|
118
|
+
let c = this.device, l = this.pipeline, d = /* @__PURE__ */ new Set();
|
|
119
|
+
for (let t of e.meshes.values()) {
|
|
120
|
+
let e = g(t);
|
|
121
|
+
e?.kind === "pbr" && d.add(e.source.model);
|
|
122
|
+
}
|
|
123
|
+
for (let [e, t] of this.pbr) if (!d.has(e) || e.disposed) {
|
|
124
|
+
for (let e of t) e.dispose();
|
|
125
|
+
this.pbr.delete(e);
|
|
126
|
+
}
|
|
127
|
+
for (let e of d) !e.disposed && !this.pbr.has(e) && this.pbr.set(e, []);
|
|
128
|
+
let f = this.used;
|
|
129
|
+
f.clear();
|
|
130
|
+
for (let e of this.resources.values()) e.count = 0;
|
|
131
|
+
for (let t of e.meshes.values()) if (t.geometry && e.store.visible[t.id] && (s === void 0 || u(t) & s)) {
|
|
132
|
+
let n = t.geometry;
|
|
133
|
+
f.add(n);
|
|
134
|
+
let r = this.resources.get(n);
|
|
135
|
+
if (!r) {
|
|
136
|
+
let t = [], i = (e, n) => {
|
|
137
|
+
if (e.byteLength > c.limits.maxBufferSize) throw RangeError("XR buffer exceeds device limit; use a smaller geometry or split it");
|
|
138
|
+
let r = c.createBuffer({
|
|
139
|
+
size: e.byteLength,
|
|
140
|
+
usage: n | GPUBufferUsage.COPY_DST
|
|
141
|
+
});
|
|
142
|
+
return t.push(r), c.queue.writeBuffer(r, 0, e), r;
|
|
143
|
+
};
|
|
144
|
+
try {
|
|
145
|
+
let t = new Float32Array(e.store.capacity * 24);
|
|
146
|
+
r = {
|
|
147
|
+
vertex: i(n.vertices, GPUBufferUsage.VERTEX),
|
|
148
|
+
index: i(n.indices, GPUBufferUsage.INDEX),
|
|
149
|
+
instance: i(t, GPUBufferUsage.VERTEX),
|
|
150
|
+
data: t,
|
|
151
|
+
count: 0
|
|
152
|
+
}, this.resources.set(n, r);
|
|
153
|
+
} catch (e) {
|
|
154
|
+
for (let e of t) e.destroy();
|
|
155
|
+
throw e;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (r.data.length < e.store.capacity * 24) {
|
|
159
|
+
let t = new Float32Array(e.store.capacity * 24);
|
|
160
|
+
if (t.byteLength > c.limits.maxBufferSize) throw RangeError("XR buffer exceeds device limit; lower the engine store capacity");
|
|
161
|
+
let n = c.createBuffer({
|
|
162
|
+
size: t.byteLength,
|
|
163
|
+
usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
|
|
164
|
+
});
|
|
165
|
+
r.instance.destroy(), r.instance = n, r.data = t;
|
|
166
|
+
}
|
|
167
|
+
let i = r.count++ * 24;
|
|
168
|
+
r.data.set(t.matrix, i), r.data.set(t.material.data, i + 16);
|
|
169
|
+
}
|
|
170
|
+
for (let [e, t] of this.resources) f.has(e) ? c.queue.writeBuffer(t.instance, 0, t.data, 0, t.count * 24) : (t.vertex.destroy(), t.index.destroy(), t.instance.destroy(), this.resources.delete(e));
|
|
171
|
+
let p = c.createCommandEncoder(), m = [];
|
|
172
|
+
for (let u = 0; u < r.views.length; u++) {
|
|
173
|
+
let d = r.views[u], f = t.getViewSubImage(n, d), h = f.getViewDescriptor(), g = this.eyes[u];
|
|
174
|
+
if (!g) {
|
|
175
|
+
let e = c.createBuffer({
|
|
176
|
+
size: 128,
|
|
177
|
+
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
178
|
+
});
|
|
179
|
+
try {
|
|
180
|
+
g = {
|
|
181
|
+
uniform: e,
|
|
182
|
+
group: c.createBindGroup({
|
|
183
|
+
layout: l.getBindGroupLayout(0),
|
|
184
|
+
entries: [{
|
|
185
|
+
binding: 0,
|
|
186
|
+
resource: { buffer: e }
|
|
187
|
+
}]
|
|
188
|
+
}),
|
|
189
|
+
data: /* @__PURE__ */ new Float32Array(32)
|
|
190
|
+
}, this.eyes.push(g);
|
|
191
|
+
} catch (t) {
|
|
192
|
+
throw e.destroy(), t;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
let y = t.projection?.(d) ?? d.projectionMatrix, b = d.transform.inverse.matrix, x = g.data;
|
|
196
|
+
for (let e = 0; e < 4; e++) for (let t = 0; t < 4; t++) x[e * 4 + t] = y[t] * b[e * 4] + y[4 + t] * b[e * 4 + 1] + y[8 + t] * b[e * 4 + 2] + y[12 + t] * b[e * 4 + 3];
|
|
197
|
+
let S = d.transform.position;
|
|
198
|
+
if (x[16] = S.x, x[17] = S.y, x[18] = S.z, x[19] = 1, _(x, 20, e.lighting.direction), x.set(e.lighting.radiance, 24), x.fill(1, 28, 31), e.lighting.ambient && x.set(e.lighting.ambient, 28), c.queue.writeBuffer(g.uniform, 0, x), !f.depthStencilTexture && !t.present) throw new a("unsupported", "XR projection layer has no depth texture; use a runtime that provides a depth buffer for the layer");
|
|
199
|
+
if (g.color?.width !== f.colorTexture.width || g.color?.height !== f.colorTexture.height || g.color?.format !== f.colorTexture.format) {
|
|
200
|
+
g.color?.destroy(), g.depth?.destroy(), g.color = void 0, g.depth = void 0, g.colorView = g.depthView = g.depthGroup = void 0;
|
|
201
|
+
try {
|
|
202
|
+
g.color = c.createTexture({
|
|
203
|
+
size: [f.colorTexture.width, f.colorTexture.height],
|
|
204
|
+
format: f.colorTexture.format,
|
|
205
|
+
sampleCount: 4,
|
|
206
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT
|
|
207
|
+
}), g.depth = c.createTexture({
|
|
208
|
+
size: [f.colorTexture.width, f.colorTexture.height],
|
|
209
|
+
format: "depth24plus",
|
|
210
|
+
sampleCount: 4,
|
|
211
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING
|
|
212
|
+
}), g.colorView = g.color.createView(), g.depthView = g.depth.createView(), g.depthGroup = c.createBindGroup({
|
|
213
|
+
layout: this.depthPipeline.getBindGroupLayout(0),
|
|
214
|
+
entries: [{
|
|
215
|
+
binding: 0,
|
|
216
|
+
resource: g.depthView
|
|
217
|
+
}]
|
|
218
|
+
});
|
|
219
|
+
} catch (e) {
|
|
220
|
+
throw g.color?.destroy(), g.depth?.destroy(), g.color = g.depth = void 0, g.colorView = g.depthView = g.depthGroup = void 0, e;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
let C = Object.assign(Object.create(e.camera), {
|
|
224
|
+
matrix: x.subarray(0, 16),
|
|
225
|
+
position: [
|
|
226
|
+
S.x,
|
|
227
|
+
S.y,
|
|
228
|
+
S.z
|
|
229
|
+
]
|
|
230
|
+
});
|
|
231
|
+
if (s !== void 0) {
|
|
232
|
+
let e = f.viewport;
|
|
233
|
+
g.view = {
|
|
234
|
+
id: `xr-${u}`,
|
|
235
|
+
camera: C,
|
|
236
|
+
viewport: [
|
|
237
|
+
e.x,
|
|
238
|
+
e.y,
|
|
239
|
+
e.width,
|
|
240
|
+
e.height
|
|
241
|
+
],
|
|
242
|
+
index: u,
|
|
243
|
+
count: r.views.length,
|
|
244
|
+
layers: s
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
let w = {
|
|
248
|
+
...this.context,
|
|
249
|
+
...s === void 0 ? {} : { view: g.view },
|
|
250
|
+
backend: "webgpu",
|
|
251
|
+
device: c,
|
|
252
|
+
encoder: p,
|
|
253
|
+
width: f.colorTexture.width,
|
|
254
|
+
height: f.colorTexture.height,
|
|
255
|
+
format: f.colorTexture.format,
|
|
256
|
+
color: g.colorView,
|
|
257
|
+
depth: g.depthView,
|
|
258
|
+
camera: C,
|
|
259
|
+
descriptor: {
|
|
260
|
+
...this.context.descriptor,
|
|
261
|
+
multisample: { count: 4 },
|
|
262
|
+
depthStencil: {
|
|
263
|
+
format: "depth24plus",
|
|
264
|
+
depthWriteEnabled: !0,
|
|
265
|
+
depthCompare: "less-equal"
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
for (let [e, t] of this.pbr) {
|
|
270
|
+
let n = t[u];
|
|
271
|
+
n || (n = e.createRenderer(c), t[u] = n), n.prepare(w);
|
|
272
|
+
}
|
|
273
|
+
let T = !v(f.colorTexture.format) && this.glass(), E = f.colorTexture.createView(h), D = f.viewport, O = (e) => {
|
|
274
|
+
let t = p.beginRenderPass({
|
|
275
|
+
colorAttachments: [{
|
|
276
|
+
view: g.colorView,
|
|
277
|
+
resolveTarget: E,
|
|
278
|
+
loadOp: e ? "clear" : "load",
|
|
279
|
+
storeOp: T ? "store" : "discard",
|
|
280
|
+
clearValue: {
|
|
281
|
+
r: 0,
|
|
282
|
+
g: 0,
|
|
283
|
+
b: 0,
|
|
284
|
+
a: +!i
|
|
285
|
+
}
|
|
286
|
+
}],
|
|
287
|
+
depthStencilAttachment: {
|
|
288
|
+
view: g.depthView,
|
|
289
|
+
depthLoadOp: e ? "clear" : "load",
|
|
290
|
+
depthStoreOp: "store",
|
|
291
|
+
depthClearValue: 1
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
return t.setViewport(D.x, D.y, D.width, D.height, 0, 1), t;
|
|
295
|
+
}, k = O(!0);
|
|
296
|
+
k.setPipeline(l), k.setBindGroup(0, g.group);
|
|
297
|
+
for (let [e, t] of this.resources) t.count && (k.setVertexBuffer(0, t.vertex), k.setVertexBuffer(1, t.instance), k.setIndexBuffer(t.index, "uint32"), k.drawIndexed(e.indices.length, t.count));
|
|
298
|
+
let A = T ? { snapshot(e, t) {
|
|
299
|
+
return e.end(), p.beginRenderPass({ colorAttachments: [{
|
|
300
|
+
view: g.colorView,
|
|
301
|
+
resolveTarget: t.createView(),
|
|
302
|
+
loadOp: "load",
|
|
303
|
+
storeOp: "store"
|
|
304
|
+
}] }).end(), O(!1);
|
|
305
|
+
} } : void 0;
|
|
306
|
+
for (let e of this.pbr.values()) k = e[u].draw(w, k, d.transform.inverse.matrix, A) ?? k;
|
|
307
|
+
if (k.end(), !f.depthStencilTexture) continue;
|
|
308
|
+
let j = p.beginRenderPass({
|
|
309
|
+
colorAttachments: [],
|
|
310
|
+
depthStencilAttachment: {
|
|
311
|
+
view: f.depthStencilTexture.createView(h),
|
|
312
|
+
depthLoadOp: "clear",
|
|
313
|
+
depthStoreOp: "store",
|
|
314
|
+
depthClearValue: 1
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
j.setViewport(D.x, D.y, D.width, D.height, 0, 1), j.setPipeline(this.depthPipeline), j.setBindGroup(0, g.depthGroup), j.draw(3), j.end();
|
|
318
|
+
let M = () => p.beginRenderPass({
|
|
319
|
+
colorAttachments: [],
|
|
320
|
+
depthStencilAttachment: {
|
|
321
|
+
view: g.depthView,
|
|
322
|
+
depthLoadOp: "load",
|
|
323
|
+
depthStoreOp: "discard"
|
|
324
|
+
}
|
|
325
|
+
}).end();
|
|
326
|
+
o ? m.push(M) : M();
|
|
327
|
+
}
|
|
328
|
+
if (o) for (let [e, i] of r.views.entries()) {
|
|
329
|
+
let r = t.getViewSubImage(n, i);
|
|
330
|
+
if (o({
|
|
331
|
+
index: e,
|
|
332
|
+
device: c,
|
|
333
|
+
encoder: p,
|
|
334
|
+
image: r,
|
|
335
|
+
view: i,
|
|
336
|
+
scene: {
|
|
337
|
+
texture: this.eyes[e].depth,
|
|
338
|
+
projection: t.projection?.(i) ?? i.projectionMatrix,
|
|
339
|
+
origin: [r.viewport.x, r.viewport.y],
|
|
340
|
+
clear: 1
|
|
341
|
+
},
|
|
342
|
+
binding: t
|
|
343
|
+
}) === !1) return;
|
|
344
|
+
}
|
|
345
|
+
for (let e of m) e();
|
|
346
|
+
c.queue.submit([p.finish()]), t.present?.(n);
|
|
347
|
+
}
|
|
348
|
+
glass() {
|
|
349
|
+
for (let e of this.pbr.keys()) for (let t of e.primitives) if (y(t.material)) return !0;
|
|
350
|
+
return !1;
|
|
351
|
+
}
|
|
352
|
+
dispose() {
|
|
353
|
+
for (let e of this.pbr.values()) for (let t of e) t.dispose();
|
|
354
|
+
this.pbr.clear(), this.context = void 0;
|
|
355
|
+
for (let e of this.resources.values()) e.vertex.destroy(), e.index.destroy(), e.instance.destroy();
|
|
356
|
+
this.resources.clear();
|
|
357
|
+
for (let e of this.eyes) e.uniform.destroy(), e.color?.destroy(), e.depth?.destroy();
|
|
358
|
+
this.eyes.length = 0, this.pipeline = this.depthPipeline = void 0;
|
|
359
|
+
}
|
|
360
|
+
}, x = Symbol.for("margoengine.premultiplied-canvas");
|
|
361
|
+
function S(e, t) {
|
|
362
|
+
let n = e?.canvas;
|
|
363
|
+
if (!n) return !1;
|
|
364
|
+
let r = !!n[x];
|
|
365
|
+
return n[x] = t, r;
|
|
366
|
+
}
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region src/eyes.ts
|
|
369
|
+
var C = "@vertex fn vertex(@builtin(vertex_index) i: u32) -> @builtin(position) vec4f {\n return vec4f(array<vec2f, 3>(vec2f(-1, -1), vec2f(3, -1), vec2f(-1, 3))[i], 0, 1);\n}\n@fragment fn fragment() -> @location(0) vec4f {\n return vec4f(1);\n}\n", w = "@vertex fn vertex(@builtin(vertex_index) i: u32) -> @builtin(position) vec4f {\n return vec4f(array<vec2f, 3>(vec2f(-1, -1), vec2f(3, -1), vec2f(-1, 3))[i], 0, 1);\n}\n@fragment fn fragment() -> @location(0) vec4f {\n return vec4f(0);\n}\n", T = 1e-6;
|
|
370
|
+
function E(e, t, n) {
|
|
371
|
+
let r = e > 1 ? "texture_depth_multisampled_2d" : "texture_depth_2d", i = "0.0";
|
|
372
|
+
for (let t = 0; t < e; t++) i += ` + select(0.0, 1.0, textureLoad(d, q, ${t}) > 0.0)`;
|
|
373
|
+
let a = n ? "textureLoad(k, q, 0).r" : `(${i}) / ${e}.0`, o = "textureLoad(d, q, 0)";
|
|
374
|
+
for (let t = 1; t < e; t++) o = `max(${o}, textureLoad(d, q, ${t}))`;
|
|
375
|
+
return `@group(0) @binding(0) var c: texture_2d<f32>;
|
|
376
|
+
@group(0) @binding(1) var d: ${r};
|
|
377
|
+
@group(0) @binding(2) var<uniform> o: vec4i;
|
|
378
|
+
${n ? "@group(0) @binding(3) var k: texture_2d<f32>;" : ""}
|
|
379
|
+
@vertex fn vertex(@builtin(vertex_index) i: u32) -> @builtin(position) vec4f {
|
|
380
|
+
return vec4f(array<vec2f, 3>(vec2f(-1, -1), vec2f(3, -1), vec2f(-1, 3))[i], 0, 1);
|
|
381
|
+
}
|
|
382
|
+
@fragment fn color(@builtin(position) p: vec4f) -> @location(0) vec4f {
|
|
383
|
+
let q = vec2i(p.xy) - o.xy;
|
|
384
|
+
let c = textureLoad(c, q, 0);
|
|
385
|
+
${t ? `return vec4f(c.rgb, clamp(max(max(${a}, c.a), max(c.r, max(c.g, c.b))), 0.0, 1.0));` : "return vec4f(c.rgb, 1.0);"}
|
|
386
|
+
}
|
|
387
|
+
@fragment fn depth(@builtin(position) p: vec4f) -> @builtin(frag_depth) f32 {
|
|
388
|
+
let q = vec2i(p.xy) - o.xy;
|
|
389
|
+
return 1.0 - ${o};
|
|
390
|
+
}
|
|
391
|
+
`;
|
|
392
|
+
}
|
|
393
|
+
var D = class {
|
|
394
|
+
constructor(e, t) {
|
|
395
|
+
this.engine = e, this.device = t, this.eyes = [], this.views = [], this.offset = /* @__PURE__ */ new Int32Array(4), this.options = {
|
|
396
|
+
views: this.views,
|
|
397
|
+
delta: 0,
|
|
398
|
+
culling: !0
|
|
399
|
+
}, this.ar = !1, this.alphaPipelines = /* @__PURE__ */ new Map(), this.alphaGraphs = /* @__PURE__ */ new Map(), this.alphaDescriptor = {
|
|
400
|
+
colorAttachments: [{
|
|
401
|
+
view: void 0,
|
|
402
|
+
loadOp: "load",
|
|
403
|
+
storeOp: "store"
|
|
404
|
+
}],
|
|
405
|
+
depthStencilAttachment: {
|
|
406
|
+
view: void 0,
|
|
407
|
+
depthReadOnly: !0
|
|
408
|
+
},
|
|
409
|
+
label: "XR AR alpha"
|
|
410
|
+
}, this.clearAlpha = (e) => {
|
|
411
|
+
if (!this.ar || e.backend !== "webgpu" || e.device !== this.device || !this.eyes.some((t) => t.view.id === e.view?.id)) return;
|
|
412
|
+
let t = e.descriptor.depthStencil.format, n = e.descriptor.multisample?.count ?? 1, r = `${e.format} ${t} ${n}`, i = this.alphaPipelines.get(r);
|
|
413
|
+
if (!i) {
|
|
414
|
+
let a = this.alphaModule ??= this.device.createShaderModule({
|
|
415
|
+
code: w,
|
|
416
|
+
label: "XR AR alpha"
|
|
417
|
+
});
|
|
418
|
+
i = this.device.createRenderPipeline({
|
|
419
|
+
layout: "auto",
|
|
420
|
+
vertex: {
|
|
421
|
+
module: a,
|
|
422
|
+
entryPoint: "vertex"
|
|
423
|
+
},
|
|
424
|
+
fragment: {
|
|
425
|
+
module: a,
|
|
426
|
+
entryPoint: "fragment",
|
|
427
|
+
targets: [{
|
|
428
|
+
format: e.format,
|
|
429
|
+
writeMask: 8
|
|
430
|
+
}]
|
|
431
|
+
},
|
|
432
|
+
depthStencil: {
|
|
433
|
+
format: t,
|
|
434
|
+
depthWriteEnabled: !1,
|
|
435
|
+
depthCompare: "equal"
|
|
436
|
+
},
|
|
437
|
+
multisample: { count: n },
|
|
438
|
+
label: "XR AR alpha"
|
|
439
|
+
}), this.alphaPipelines.set(r, i);
|
|
440
|
+
}
|
|
441
|
+
let a = this.alphaDescriptor, o = a.depthStencilAttachment;
|
|
442
|
+
a.colorAttachments[0].view = e.color, o.view = e.depth, t.includes("stencil") ? o.stencilReadOnly = !0 : delete o.stencilReadOnly;
|
|
443
|
+
let s = e.encoder.beginRenderPass(a);
|
|
444
|
+
c(s, e), s.setPipeline(i), s.draw(3), s.end();
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
watchAlpha() {
|
|
448
|
+
let e = this.engine.frameGraph;
|
|
449
|
+
this.alphaGraphs.has(e) || this.alphaGraphs.set(e, e.add({
|
|
450
|
+
name: "xr:ar-alpha",
|
|
451
|
+
order: T,
|
|
452
|
+
execute: this.clearAlpha
|
|
453
|
+
}));
|
|
454
|
+
}
|
|
455
|
+
place(e, t, n) {
|
|
456
|
+
let r = t.transform.matrix, i = e.camera, a = e.projection;
|
|
457
|
+
i.position = [
|
|
458
|
+
r[12],
|
|
459
|
+
r[13],
|
|
460
|
+
r[14]
|
|
461
|
+
], i.target = [
|
|
462
|
+
r[12] - r[8],
|
|
463
|
+
r[13] - r[9],
|
|
464
|
+
r[14] - r[10]
|
|
465
|
+
], i.up = [
|
|
466
|
+
r[4],
|
|
467
|
+
r[5],
|
|
468
|
+
r[6]
|
|
469
|
+
];
|
|
470
|
+
for (let e = 0; e < 16; e++) a[e] = n[e];
|
|
471
|
+
for (let e = 0; e < 16; e += 4) a[e + 2] = n[e + 3] - n[e + 2];
|
|
472
|
+
i.near = this.engine.camera.near, i.far = this.engine.camera.far, i.fov = 2 * Math.atan(1 / n[5]) * 180 / Math.PI;
|
|
473
|
+
}
|
|
474
|
+
eye(e) {
|
|
475
|
+
let t = this.eyes[e];
|
|
476
|
+
if (!t) {
|
|
477
|
+
let r = /* @__PURE__ */ new Float64Array(16), i = new n();
|
|
478
|
+
i.project = (e) => e.set(r), t = {
|
|
479
|
+
camera: i,
|
|
480
|
+
projection: r,
|
|
481
|
+
uniform: this.device.createBuffer({
|
|
482
|
+
size: 16,
|
|
483
|
+
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
484
|
+
}),
|
|
485
|
+
view: {
|
|
486
|
+
camera: i,
|
|
487
|
+
viewport: [
|
|
488
|
+
0,
|
|
489
|
+
0,
|
|
490
|
+
1,
|
|
491
|
+
1
|
|
492
|
+
],
|
|
493
|
+
id: `xr-${e}`,
|
|
494
|
+
target: void 0
|
|
495
|
+
}
|
|
496
|
+
}, this.eyes[e] = t;
|
|
497
|
+
}
|
|
498
|
+
return t;
|
|
499
|
+
}
|
|
500
|
+
size(e, t, n) {
|
|
501
|
+
if (e.color?.width === t && e.color.height === n) return;
|
|
502
|
+
e.color?.destroy(), e.depth?.destroy(), this.dropCover(e), e.color = e.depth = e.colorGroup = e.depthGroup = void 0;
|
|
503
|
+
let r = this.engine.renderTarget;
|
|
504
|
+
e.color = this.device.createTexture({
|
|
505
|
+
size: [t, n],
|
|
506
|
+
format: r.format,
|
|
507
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING,
|
|
508
|
+
label: "XR eye"
|
|
509
|
+
}), e.depth = this.device.createTexture({
|
|
510
|
+
size: [t, n],
|
|
511
|
+
format: r.depthFormat,
|
|
512
|
+
sampleCount: r.samples,
|
|
513
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING,
|
|
514
|
+
label: "XR eye depth"
|
|
515
|
+
}), e.view.target = {
|
|
516
|
+
color: e.color,
|
|
517
|
+
depth: e.depth
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
dropCover(e) {
|
|
521
|
+
e.cover?.samples.destroy(), e.cover?.resolved.destroy(), e.cover = void 0;
|
|
522
|
+
}
|
|
523
|
+
cover(e, t, n) {
|
|
524
|
+
let r = e.cover;
|
|
525
|
+
if (!r) {
|
|
526
|
+
let t = [e.depth.width, e.depth.height], n = (e, n) => this.device.createTexture({
|
|
527
|
+
size: t,
|
|
528
|
+
format: "r8unorm",
|
|
529
|
+
sampleCount: e,
|
|
530
|
+
usage: n,
|
|
531
|
+
label: "XR eye coverage"
|
|
532
|
+
});
|
|
533
|
+
r = e.cover = {
|
|
534
|
+
samples: n(4, GPUTextureUsage.RENDER_ATTACHMENT),
|
|
535
|
+
resolved: n(1, GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING)
|
|
536
|
+
}, e.colorGroup = void 0;
|
|
537
|
+
}
|
|
538
|
+
let i = t.beginRenderPass({
|
|
539
|
+
colorAttachments: [{
|
|
540
|
+
view: r.samples.createView(),
|
|
541
|
+
resolveTarget: r.resolved.createView(),
|
|
542
|
+
loadOp: "clear",
|
|
543
|
+
storeOp: "discard"
|
|
544
|
+
}],
|
|
545
|
+
depthStencilAttachment: {
|
|
546
|
+
view: e.depth.createView(),
|
|
547
|
+
depthReadOnly: !0,
|
|
548
|
+
...e.depth.format.includes("stencil") ? { stencilReadOnly: !0 } : {}
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
return i.setPipeline(n), i.draw(3), i.end(), r.resolved;
|
|
552
|
+
}
|
|
553
|
+
build(e, t, n) {
|
|
554
|
+
let r = `${e} ${t}`;
|
|
555
|
+
if (this.pipelines?.key === r && (!n || this.pipelines.depth)) return;
|
|
556
|
+
let { samples: i, depthFormat: a } = this.engine.renderTarget, s = t && i > 1 && o(this.device) === "webgl2", c = this.device.createShaderModule({
|
|
557
|
+
code: E(i, t, s),
|
|
558
|
+
label: "XR eye blit"
|
|
559
|
+
}), l = s ? this.device.createShaderModule({
|
|
560
|
+
code: C,
|
|
561
|
+
label: "XR eye coverage"
|
|
562
|
+
}) : null, u = this.device.createBindGroupLayout({ entries: [
|
|
563
|
+
{
|
|
564
|
+
binding: 0,
|
|
565
|
+
visibility: 2,
|
|
566
|
+
texture: { sampleType: "unfilterable-float" }
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
binding: 1,
|
|
570
|
+
visibility: 2,
|
|
571
|
+
texture: {
|
|
572
|
+
sampleType: "depth",
|
|
573
|
+
multisampled: i > 1
|
|
574
|
+
}
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
binding: 2,
|
|
578
|
+
visibility: 2,
|
|
579
|
+
buffer: {}
|
|
580
|
+
},
|
|
581
|
+
...s ? [{
|
|
582
|
+
binding: 3,
|
|
583
|
+
visibility: 2,
|
|
584
|
+
texture: { sampleType: "unfilterable-float" }
|
|
585
|
+
}] : []
|
|
586
|
+
] }), d = this.device.createPipelineLayout({ bindGroupLayouts: [u] }), f = {
|
|
587
|
+
module: c,
|
|
588
|
+
entryPoint: "vertex"
|
|
589
|
+
};
|
|
590
|
+
this.pipelines = {
|
|
591
|
+
key: r,
|
|
592
|
+
color: this.device.createRenderPipeline({
|
|
593
|
+
layout: d,
|
|
594
|
+
vertex: f,
|
|
595
|
+
fragment: {
|
|
596
|
+
module: c,
|
|
597
|
+
entryPoint: "color",
|
|
598
|
+
targets: [{ format: e }]
|
|
599
|
+
}
|
|
600
|
+
}),
|
|
601
|
+
depth: n ? this.device.createRenderPipeline({
|
|
602
|
+
layout: d,
|
|
603
|
+
vertex: f,
|
|
604
|
+
fragment: {
|
|
605
|
+
module: c,
|
|
606
|
+
entryPoint: "depth",
|
|
607
|
+
targets: []
|
|
608
|
+
},
|
|
609
|
+
depthStencil: {
|
|
610
|
+
format: "depth24plus",
|
|
611
|
+
depthWriteEnabled: !0,
|
|
612
|
+
depthCompare: "always"
|
|
613
|
+
}
|
|
614
|
+
}) : void 0,
|
|
615
|
+
cover: l ? this.device.createRenderPipeline({
|
|
616
|
+
layout: "auto",
|
|
617
|
+
vertex: {
|
|
618
|
+
module: l,
|
|
619
|
+
entryPoint: "vertex"
|
|
620
|
+
},
|
|
621
|
+
fragment: {
|
|
622
|
+
module: l,
|
|
623
|
+
entryPoint: "fragment",
|
|
624
|
+
targets: [{ format: "r8unorm" }]
|
|
625
|
+
},
|
|
626
|
+
depthStencil: {
|
|
627
|
+
format: a,
|
|
628
|
+
depthWriteEnabled: !1,
|
|
629
|
+
depthCompare: "less"
|
|
630
|
+
},
|
|
631
|
+
multisample: { count: i }
|
|
632
|
+
}) : void 0
|
|
633
|
+
};
|
|
634
|
+
for (let e of this.eyes) e.colorGroup = e.depthGroup = void 0;
|
|
635
|
+
}
|
|
636
|
+
render(t, n, r, i, a, o, s) {
|
|
637
|
+
let c = this.views, l = [];
|
|
638
|
+
c.length = 0;
|
|
639
|
+
for (let e = 0; e < r.views.length; e++) {
|
|
640
|
+
let i = r.views[e], o = t.getViewSubImage(n, i), u = this.eye(e);
|
|
641
|
+
this.place(u, i, t.projection?.(i) ?? i.projectionMatrix), this.size(u, o.viewport.width, o.viewport.height), u.view.clear = a ? { color: "#000000" } : void 0, u.view.layers = s, c.push(u.view), l.push(o);
|
|
642
|
+
}
|
|
643
|
+
this.options.delta = i, this.ar = a, a ? (this.watchAlpha(), this.premultipliedBefore ??= S(this.engine, !0)) : this.unmark(), this.engine.render(this.options);
|
|
644
|
+
let u = this.device.createCommandEncoder({ label: "XR eyes" });
|
|
645
|
+
for (let t = 0; t < l.length; t++) {
|
|
646
|
+
let n = l[t], r = this.eyes[t], { x: i, y: o, width: s, height: c } = n.viewport, d = n.getViewDescriptor(), f = n.depthStencilTexture;
|
|
647
|
+
if (f && f.format !== "depth24plus") throw e("unsupported", `The XR layer's depth is ${f.format}; create the layer with depth24plus`);
|
|
648
|
+
this.build(n.colorTexture.format, a, !!f);
|
|
649
|
+
let p = this.pipelines;
|
|
650
|
+
this.offset[0] = i, this.offset[1] = o, this.device.queue.writeBuffer(r.uniform, 0, this.offset);
|
|
651
|
+
let m = p.cover && this.cover(r, u, p.cover);
|
|
652
|
+
r.colorGroup ??= this.device.createBindGroup({
|
|
653
|
+
layout: p.color.getBindGroupLayout(0),
|
|
654
|
+
entries: [
|
|
655
|
+
{
|
|
656
|
+
binding: 0,
|
|
657
|
+
resource: r.color.createView()
|
|
658
|
+
},
|
|
659
|
+
{
|
|
660
|
+
binding: 1,
|
|
661
|
+
resource: r.depth.createView({ aspect: "depth-only" })
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
binding: 2,
|
|
665
|
+
resource: { buffer: r.uniform }
|
|
666
|
+
},
|
|
667
|
+
...m ? [{
|
|
668
|
+
binding: 3,
|
|
669
|
+
resource: m.createView()
|
|
670
|
+
}] : []
|
|
671
|
+
]
|
|
672
|
+
});
|
|
673
|
+
let h = u.beginRenderPass({ colorAttachments: [{
|
|
674
|
+
view: n.colorTexture.createView(d),
|
|
675
|
+
loadOp: "load",
|
|
676
|
+
storeOp: "store"
|
|
677
|
+
}] });
|
|
678
|
+
if (h.setViewport(i, o, s, c, 0, 1), h.setPipeline(p.color), h.setBindGroup(0, r.colorGroup), h.draw(3), h.end(), !f || !p.depth) continue;
|
|
679
|
+
let g = u.beginRenderPass({
|
|
680
|
+
colorAttachments: [],
|
|
681
|
+
depthStencilAttachment: {
|
|
682
|
+
view: f.createView(d),
|
|
683
|
+
depthLoadOp: "load",
|
|
684
|
+
depthStoreOp: "store"
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
g.setViewport(i, o, s, c, 0, 1), g.setPipeline(p.depth), g.setBindGroup(0, r.colorGroup), g.draw(3), g.end();
|
|
688
|
+
}
|
|
689
|
+
if (o) {
|
|
690
|
+
for (let e = 0; e < l.length; e++) if (o({
|
|
691
|
+
index: e,
|
|
692
|
+
device: this.device,
|
|
693
|
+
encoder: u,
|
|
694
|
+
image: l[e],
|
|
695
|
+
view: r.views[e],
|
|
696
|
+
scene: {
|
|
697
|
+
texture: this.eyes[e].depth,
|
|
698
|
+
projection: this.eyes[e].projection,
|
|
699
|
+
origin: [0, 0],
|
|
700
|
+
clear: 0
|
|
701
|
+
},
|
|
702
|
+
binding: t
|
|
703
|
+
}) === !1) return;
|
|
704
|
+
}
|
|
705
|
+
this.device.queue.submit([u.finish()]), t.present?.(n);
|
|
706
|
+
}
|
|
707
|
+
unmark() {
|
|
708
|
+
this.premultipliedBefore !== void 0 && (S(this.engine, this.premultipliedBefore), this.premultipliedBefore = void 0);
|
|
709
|
+
}
|
|
710
|
+
dispose() {
|
|
711
|
+
this.unmark(), this.ar = !1;
|
|
712
|
+
for (let e of this.eyes) e.color?.destroy(), e.depth?.destroy(), this.dropCover(e), e.uniform.destroy();
|
|
713
|
+
this.eyes.length = 0, this.views.length = 0, this.pipelines = void 0;
|
|
714
|
+
for (let e of this.alphaGraphs.values()) e();
|
|
715
|
+
this.alphaGraphs.clear(), this.alphaPipelines.clear(), this.alphaModule = void 0;
|
|
716
|
+
}
|
|
717
|
+
}, O = class {
|
|
718
|
+
constructor(e) {
|
|
719
|
+
if (this.source = e, this.targetRay = null, this.grip = null, this.targetRayMatrix = /* @__PURE__ */ new Float32Array(16), this.gripMatrix = /* @__PURE__ */ new Float32Array(16), this.buttons = /* @__PURE__ */ new Float32Array(96), this.axes = /* @__PURE__ */ new Float32Array(16), this.handMatrices = /* @__PURE__ */ new Float32Array(400), this.handTracked = /* @__PURE__ */ new Uint8Array(25), this.handRadii = /* @__PURE__ */ new Float32Array(25), this.buttonCount = 0, this.axisCount = 0, this.joints = e.hand ? Array.from(e.hand.values()) : [], this.joints.length > 25) throw RangeError("XR hand exceeds 25 joints; the controller buffers hold the 25 WebXR hand joints");
|
|
720
|
+
}
|
|
721
|
+
update(e, t) {
|
|
722
|
+
this.targetRay = e.getPose(this.source.targetRaySpace, t), this.grip = this.source.gripSpace ? e.getPose(this.source.gripSpace, t) : null, this.targetRayMatrix.fill(0), this.gripMatrix.fill(0), this.targetRay && this.targetRayMatrix.set(this.targetRay.transform.matrix), this.grip && this.gripMatrix.set(this.grip.transform.matrix);
|
|
723
|
+
let n = this.source.gamepad;
|
|
724
|
+
if (this.buttonCount = n?.buttons.length ?? 0, this.axisCount = n?.axes.length ?? 0, this.buttonCount > 32 || this.axisCount > 16) throw RangeError("XR gamepad exceeds controller buffer capacity; at most 32 buttons and 16 axes are supported");
|
|
725
|
+
if (this.buttons.fill(0), this.axes.fill(0), n) {
|
|
726
|
+
for (let e = 0; e < this.buttonCount; e++) {
|
|
727
|
+
let t = n.buttons[e];
|
|
728
|
+
this.buttons[e * 3] = t.value, this.buttons[e * 3 + 1] = +t.pressed, this.buttons[e * 3 + 2] = +t.touched;
|
|
729
|
+
}
|
|
730
|
+
this.axes.set(n.axes);
|
|
731
|
+
}
|
|
732
|
+
this.handMatrices.fill(0), this.handTracked.fill(0), this.handRadii.fill(0);
|
|
733
|
+
for (let n = 0; n < this.joints.length; n++) {
|
|
734
|
+
let r = e.getJointPose?.(this.joints[n], t);
|
|
735
|
+
r && (this.handMatrices.set(r.transform.matrix, n * 16), this.handTracked[n] = 1, this.handRadii[n] = r.radius ?? 0);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}, k = [
|
|
739
|
+
"point",
|
|
740
|
+
"plane",
|
|
741
|
+
"mesh"
|
|
742
|
+
], A = class t {
|
|
743
|
+
constructor(e, t, n, r) {
|
|
744
|
+
this.host = e, this.session = t, this.source = n, this.transient = r, this.cancelled = !1, this.ended = () => this.cancel(), t.addEventListener("end", this.ended, { once: !0 });
|
|
745
|
+
}
|
|
746
|
+
static async create(n, r = {}) {
|
|
747
|
+
let i = n?.session;
|
|
748
|
+
if (!i) throw e("state", "HitTest needs an active XR session; await xr.requestSession first");
|
|
749
|
+
if (i.enabledFeatures && !i.enabledFeatures.includes("hit-test")) throw e("unsupported", "The XR session has no 'hit-test' feature; request it in requiredFeatures or optionalFeatures");
|
|
750
|
+
if (!i.requestHitTestSource || !i.requestHitTestSourceForTransientInput) throw e("unsupported", "This browser has no WebXR hit testing; use an AR-capable browser and device");
|
|
751
|
+
let a = [...r.entityTypes ?? ["plane"]];
|
|
752
|
+
if (!a.length || a.some((e) => !k.includes(e))) throw TypeError("HitTest entityTypes must list 'point', 'plane' or 'mesh'");
|
|
753
|
+
let o = r.offsetRay === void 0 ? void 0 : M(r.offsetRay), s = r.from ?? "viewer";
|
|
754
|
+
if (s !== "viewer" && (typeof s != "object" || !s)) throw TypeError("HitTest from must be 'viewer', an XRInputSource or {profile}");
|
|
755
|
+
if (s !== "viewer" && "profile" in s) {
|
|
756
|
+
if (typeof s.profile != "string" || !s.profile) throw TypeError("HitTest profile must be a non-empty string such as 'generic-touchscreen'");
|
|
757
|
+
let e = await i.requestHitTestSourceForTransientInput({
|
|
758
|
+
profile: s.profile,
|
|
759
|
+
entityTypes: a,
|
|
760
|
+
...o && { offsetRay: o }
|
|
761
|
+
});
|
|
762
|
+
return new t(n, i, void 0, e);
|
|
763
|
+
}
|
|
764
|
+
let c = s === "viewer" ? await i.requestReferenceSpace("viewer") : s.targetRaySpace;
|
|
765
|
+
if (!c) throw TypeError("HitTest input source has no targetRaySpace; pass an XRInputSource");
|
|
766
|
+
let l = await i.requestHitTestSource({
|
|
767
|
+
space: c,
|
|
768
|
+
entityTypes: a,
|
|
769
|
+
...o && { offsetRay: o }
|
|
770
|
+
});
|
|
771
|
+
return new t(n, i, l, void 0);
|
|
772
|
+
}
|
|
773
|
+
get active() {
|
|
774
|
+
return !this.cancelled;
|
|
775
|
+
}
|
|
776
|
+
results(e) {
|
|
777
|
+
let t = this.host.referenceSpace;
|
|
778
|
+
if (this.cancelled || !t || e?.session !== this.session) return [];
|
|
779
|
+
let n = [];
|
|
780
|
+
if (this.source) for (let r of e.getHitTestResults?.(this.source) ?? []) {
|
|
781
|
+
let e = j(r, t);
|
|
782
|
+
e && n.push(e);
|
|
783
|
+
}
|
|
784
|
+
if (this.transient) for (let r of e.getHitTestResultsForTransientInput?.(this.transient) ?? []) for (let e of r.results) {
|
|
785
|
+
let i = j(e, t, r.inputSource);
|
|
786
|
+
i && n.push(i);
|
|
787
|
+
}
|
|
788
|
+
return n;
|
|
789
|
+
}
|
|
790
|
+
first(e) {
|
|
791
|
+
return this.results(e)[0] ?? null;
|
|
792
|
+
}
|
|
793
|
+
anchor(t) {
|
|
794
|
+
return t?.result?.createAnchor ? t.result.createAnchor() : Promise.reject(e("unsupported", "This hit cannot be anchored; request the 'anchors' feature on a supporting browser"));
|
|
795
|
+
}
|
|
796
|
+
cancel() {
|
|
797
|
+
this.cancelled || (this.cancelled = !0, this.session.removeEventListener("end", this.ended), this.source?.cancel(), this.transient?.cancel());
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
function j(e, t, n) {
|
|
801
|
+
let r = e.getPose(t);
|
|
802
|
+
if (!r) return null;
|
|
803
|
+
let { matrix: i, position: a, orientation: o } = r.transform;
|
|
804
|
+
return {
|
|
805
|
+
matrix: Float32Array.from(i),
|
|
806
|
+
position: [
|
|
807
|
+
a.x,
|
|
808
|
+
a.y,
|
|
809
|
+
a.z
|
|
810
|
+
],
|
|
811
|
+
orientation: [
|
|
812
|
+
o.x,
|
|
813
|
+
o.y,
|
|
814
|
+
o.z,
|
|
815
|
+
o.w
|
|
816
|
+
],
|
|
817
|
+
result: e,
|
|
818
|
+
...n && { inputSource: n }
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
function M(t) {
|
|
822
|
+
let n = t.origin ?? [
|
|
823
|
+
0,
|
|
824
|
+
0,
|
|
825
|
+
0
|
|
826
|
+
], r = t.direction ?? [
|
|
827
|
+
0,
|
|
828
|
+
0,
|
|
829
|
+
-1
|
|
830
|
+
];
|
|
831
|
+
if (![...n, ...r].every((e) => typeof e == "number" && Number.isFinite(e)) || n.length !== 3) throw TypeError("HitTest offsetRay needs finite [x, y, z] origin and direction");
|
|
832
|
+
if (r.length !== 3 || !Math.hypot(r[0], r[1], r[2])) throw RangeError("HitTest offsetRay direction must be non-zero; pass a direction such as [0, 0, -1]");
|
|
833
|
+
let i = globalThis.XRRay;
|
|
834
|
+
if (!i) throw e("unsupported", "This browser has no XRRay; omit offsetRay");
|
|
835
|
+
return new i({
|
|
836
|
+
x: n[0],
|
|
837
|
+
y: n[1],
|
|
838
|
+
z: n[2],
|
|
839
|
+
w: 1
|
|
840
|
+
}, {
|
|
841
|
+
x: r[0],
|
|
842
|
+
y: r[1],
|
|
843
|
+
z: r[2],
|
|
844
|
+
w: 0
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
//#endregion
|
|
848
|
+
//#region src/index.ts
|
|
849
|
+
var N = () => globalThis, P = () => globalThis.navigator?.xr, F = /* @__PURE__ */ new WeakSet();
|
|
850
|
+
async function I(e, t = {}) {
|
|
851
|
+
let n = globalThis.navigator?.gpu;
|
|
852
|
+
if (!n) throw new a("unsupported", "createXREngine needs WebGPU; use a browser with WebGPU and WebXR");
|
|
853
|
+
let o = Object.getOwnPropertyDescriptor(n, "requestAdapter"), s = n.requestAdapter;
|
|
854
|
+
Object.defineProperty(n, "requestAdapter", {
|
|
855
|
+
configurable: !0,
|
|
856
|
+
writable: !0,
|
|
857
|
+
value: (e) => s.call(n, {
|
|
858
|
+
...e,
|
|
859
|
+
xrCompatible: !0
|
|
860
|
+
})
|
|
861
|
+
});
|
|
862
|
+
let c;
|
|
863
|
+
try {
|
|
864
|
+
c = await i.create(e, {
|
|
865
|
+
...t,
|
|
866
|
+
backend: "webgpu"
|
|
867
|
+
});
|
|
868
|
+
} finally {
|
|
869
|
+
o ? Object.defineProperty(n, "requestAdapter", o) : delete n.requestAdapter;
|
|
870
|
+
}
|
|
871
|
+
let l = r(c).gpu;
|
|
872
|
+
return l && F.add(l), c;
|
|
873
|
+
}
|
|
874
|
+
var L = /* @__PURE__ */ new WeakMap();
|
|
875
|
+
function R(e) {
|
|
876
|
+
let t = L.get(e);
|
|
877
|
+
if (!t) {
|
|
878
|
+
let n = t = /* @__PURE__ */ new Set();
|
|
879
|
+
L.set(e, n), e.lost.then((e) => {
|
|
880
|
+
for (let t of [...n]) t.lostDevice(e);
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
return t;
|
|
884
|
+
}
|
|
885
|
+
var z = class e {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
|
|
886
|
+
get layers() {
|
|
887
|
+
return this.mask;
|
|
888
|
+
}
|
|
889
|
+
set layers(e) {
|
|
890
|
+
this.mask = e === void 0 ? void 0 : d(e, "XR layers");
|
|
891
|
+
}
|
|
892
|
+
static async isSupported(e = "immersive-vr") {
|
|
893
|
+
return !P() || e !== "inline" && (!N().XRGPUBinding || !globalThis.navigator?.gpu) ? !1 : P().isSessionSupported(e);
|
|
894
|
+
}
|
|
895
|
+
static attach(t, n = {}) {__margoAssertCore(t,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
896
|
+
return e.create(t, n);
|
|
897
|
+
}
|
|
898
|
+
static async create(n, i = {}) {
|
|
899
|
+
let { signal: o } = i;
|
|
900
|
+
o?.throwIfAborted(), i.layers !== void 0 && d(i.layers, "XR layers");
|
|
901
|
+
let s = r(n);
|
|
902
|
+
if (s.backend !== "webgpu") throw new a("unsupported", "XR requires WebGPU or the full WebGL2 compatibility layer; use autoEngine with loadCompat; see https://margoengine.com/errors#webgpu");
|
|
903
|
+
if (s.disposed || s.hasPlugin("xr")) throw new a("state", "XR requires a live WebGPU engine without an XR plugin; create the engine with backend 'webgpu' and call XR.create once.");
|
|
904
|
+
if (!P()) throw new a("unsupported", "WebXR is unavailable; use a WebXR browser over HTTPS or localhost.");
|
|
905
|
+
if (s.gpu && F.has(s.gpu)) {
|
|
906
|
+
let t = new e(s.gpu, !0);
|
|
907
|
+
return t.layers = i.layers, s.use(t), t;
|
|
908
|
+
}
|
|
909
|
+
let c = t(s), l = await navigator.gpu.requestAdapter({ xrCompatible: !!N().XRGPUBinding });
|
|
910
|
+
if (!l) throw new a("unsupported", "XR-compatible WebGPU adapter unavailable; use a headset browser with WebGPU XR support.; see https://margoengine.com/errors#webgpu");
|
|
911
|
+
if (l.info?.vendor === "margo-webgl2" && !N().XRGPUBinding?.webgl) throw new a("unsupported", "XR needs the browser's own WebGPU (XRGPUBinding) or, on the WebGL2 compatibility layer, its route: call installXR() from the layer's xr entry first; see https://margoengine.com/errors#webgpu");
|
|
912
|
+
o?.throwIfAborted();
|
|
913
|
+
let u = s.gpu ? [...s.gpu.features].filter((e) => l.features?.has(e)) : [], f = await l.requestDevice({ requiredFeatures: u }), p = new e(f);
|
|
914
|
+
p.layers = i.layers;
|
|
915
|
+
try {
|
|
916
|
+
return o?.throwIfAborted(), c.run(() => s.use(p)), p;
|
|
917
|
+
} catch (e) {
|
|
918
|
+
throw p.dispose(), e;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
constructor(e, t = !1) {
|
|
922
|
+
this.device = e, this.name = "xr", this.session = null, this.handle = null, this.pending = !1, this.disposed = !1, this.lost = !1, this.last = null, this.mode = "immersive-vr", this.listeners = /* @__PURE__ */ new Set(), this.controllers = [], this.state = {
|
|
923
|
+
time: 0,
|
|
924
|
+
delta: 0,
|
|
925
|
+
frame: null,
|
|
926
|
+
viewer: null,
|
|
927
|
+
inputs: this.controllers
|
|
928
|
+
}, this.renderOptions = {
|
|
929
|
+
culling: !1,
|
|
930
|
+
delta: 0
|
|
931
|
+
}, this.insideFrame = !1, this.resume = !1, this.seeThrough = !1, this.eyeListeners = /* @__PURE__ */ new Set(), this.drawEye = (e) => {
|
|
932
|
+
for (let t of this.eyeListeners) if (t(e), this.disposed) return !1;
|
|
933
|
+
return !this.disposed;
|
|
934
|
+
}, this.uncaptured = (e) => {
|
|
935
|
+
this.disposed || this.fail(new a("failed", `XR GPU error: ${e.error.message}`));
|
|
936
|
+
}, this.frame = (e, t) => {
|
|
937
|
+
if (this.handle = null, !(this.disposed || t.session !== this.session)) try {
|
|
938
|
+
this.insideFrame = !0;
|
|
939
|
+
let n = this.last === null ? 0 : Math.max(0, Math.min((e - this.last) / 1e3, .1));
|
|
940
|
+
this.last = e;
|
|
941
|
+
let r = t.getViewerPose(this.space);
|
|
942
|
+
for (let e = 0; e < this.controllers.length; e++) this.controllers[e].update(t, this.space);
|
|
943
|
+
this.state.time = e, this.state.delta = n, this.state.frame = t, this.state.viewer = r;
|
|
944
|
+
for (let e of this.listeners) e(this.state);
|
|
945
|
+
let i = this.callback?.(this.state) !== !1;
|
|
946
|
+
if (this.disposed || t.session !== this.session) return;
|
|
947
|
+
i && this.renderFrame(), this.session === t.session && !this.disposed && (this.handle = t.session.requestAnimationFrame(this.frame));
|
|
948
|
+
} catch (e) {
|
|
949
|
+
this.fail(e);
|
|
950
|
+
} finally {
|
|
951
|
+
this.insideFrame = !1;
|
|
952
|
+
}
|
|
953
|
+
}, this.sourcesChanged = () => {
|
|
954
|
+
let e = this.session?.inputSources ?? [];
|
|
955
|
+
for (let t = this.controllers.length - 1; t >= 0; t--) Array.prototype.includes.call(e, this.controllers[t].source) || this.controllers.splice(t, 1);
|
|
956
|
+
for (let t of e) this.controllers.some((e) => e.source === t) || this.controllers.push(new O(t));
|
|
957
|
+
}, this.ended = () => {
|
|
958
|
+
let e = this.session;
|
|
959
|
+
e && this.handle !== null && e.cancelAnimationFrame(this.handle), e?.removeEventListener("end", this.ended), e?.removeEventListener("inputsourceschange", this.sourcesChanged), this.controllers.length = 0, this.session = null, this.handle = null, this.last = null, this.callback = void 0, this.space = void 0, this.binding = void 0, this.seeThrough = !1, this.layer?.destroy(), this.layer = void 0, this.renderer?.dispose(), this.eyes?.dispose(), this.resume && (this.resume = !1, !this.disposed && !this.engine.disposed && this.engine.start());
|
|
960
|
+
}, this.route = t ? "engine" : "separate", t || (this.renderer = new b(e)), R(e).add(this), t || e.addEventListener("uncapturederror", this.uncaptured);
|
|
961
|
+
}
|
|
962
|
+
lostDevice(e) {
|
|
963
|
+
this.disposed || (this.lost = !0, this.fail(new a("failed", `XR GPU device lost: ${e.message}; create a new XR with XR.create.`)));
|
|
964
|
+
}
|
|
965
|
+
setup(e) {
|
|
966
|
+
this.engine = e, this.route === "engine" && (this.eyes = new D(e, this.device));
|
|
967
|
+
}
|
|
968
|
+
onFrame(e) {
|
|
969
|
+
if (typeof e != "function") throw TypeError("xr.onFrame needs a function; pass (state) => {...}");
|
|
970
|
+
return this.listeners.add(e), () => void this.listeners.delete(e);
|
|
971
|
+
}
|
|
972
|
+
onEye(e) {
|
|
973
|
+
if (typeof e != "function") throw TypeError("xr.onEye needs a function; pass (target) => {...}");
|
|
974
|
+
if (this.disposed) throw new a("disposed", "XR is disposed; create a new XR before adding an eye effect");
|
|
975
|
+
return this.eyeListeners.add(e), () => void this.eyeListeners.delete(e);
|
|
976
|
+
}
|
|
977
|
+
get referenceSpace() {
|
|
978
|
+
return this.space;
|
|
979
|
+
}
|
|
980
|
+
useReferenceSpace(e) {
|
|
981
|
+
if (!this.session || !this.space) throw new a("state", "useReferenceSpace needs an active session; call it after xr.requestSession resolves");
|
|
982
|
+
if (!e || typeof e != "object") throw TypeError("useReferenceSpace needs an XRReferenceSpace; pass xr.referenceSpace.getOffsetReferenceSpace(transform)");
|
|
983
|
+
this.space = e;
|
|
984
|
+
}
|
|
985
|
+
get projectionLayer() {
|
|
986
|
+
return this.layer;
|
|
987
|
+
}
|
|
988
|
+
get layerBinding() {
|
|
989
|
+
return this.session && this.binding && this.layer ? {
|
|
990
|
+
binding: this.binding,
|
|
991
|
+
device: this.device
|
|
992
|
+
} : void 0;
|
|
993
|
+
}
|
|
994
|
+
setLayers(e, t) {
|
|
995
|
+
if (!this.session || !this.layer) throw new a("state", "setLayers needs an immersive session; call it after xr.requestSession resolves");
|
|
996
|
+
if (this.layer.baseLayer) throw new a("unsupported", "Composition layers need the browser's own XRGPUBinding; the WebGL2 layer's route shows a single XRWebGLLayer");
|
|
997
|
+
this.seeThrough = e.length > 0, this.session.updateRenderState({ layers: [
|
|
998
|
+
...e,
|
|
999
|
+
this.layer,
|
|
1000
|
+
...t
|
|
1001
|
+
] });
|
|
1002
|
+
}
|
|
1003
|
+
registerPasses(e) {
|
|
1004
|
+
e.add({
|
|
1005
|
+
name: "xr-scene-descriptor",
|
|
1006
|
+
order: -1e6,
|
|
1007
|
+
execute: (e) => {
|
|
1008
|
+
e.backend === "webgpu" && (this.context = e);
|
|
1009
|
+
}
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
async requestSession(e = "immersive-vr", t = {}) {
|
|
1013
|
+
if (this.disposed || this.lost) throw new a("disposed", "XR is disposed or its device was lost; create a new XR with XR.create.");
|
|
1014
|
+
if (this.session || this.pending) throw new a("state", "An XR session is already active or pending; await xr.end() before requesting another.");
|
|
1015
|
+
if (![
|
|
1016
|
+
"inline",
|
|
1017
|
+
"immersive-vr",
|
|
1018
|
+
"immersive-ar"
|
|
1019
|
+
].includes(e)) throw TypeError("Unknown XR mode; use 'inline', 'immersive-vr' or 'immersive-ar'");
|
|
1020
|
+
if (e !== "inline" && !N().XRGPUBinding) throw new a("unsupported", "Native WebGPU XR bindings are unavailable; desktop rendering remains active. Use a browser with XRGPUBinding or request an inline session.");
|
|
1021
|
+
t.signal?.throwIfAborted();
|
|
1022
|
+
let n = t.referenceSpace ?? (e === "inline" ? "viewer" : "local");
|
|
1023
|
+
if (![
|
|
1024
|
+
"viewer",
|
|
1025
|
+
"local",
|
|
1026
|
+
"local-floor",
|
|
1027
|
+
"bounded-floor",
|
|
1028
|
+
"unbounded"
|
|
1029
|
+
].includes(n)) throw TypeError("Unknown XR reference space; use 'viewer', 'local', 'local-floor', 'bounded-floor' or 'unbounded'");
|
|
1030
|
+
if (t.framebufferScale !== void 0 && (!Number.isFinite(Math.fround(t.framebufferScale)) || Math.fround(t.framebufferScale) <= 0)) throw RangeError("framebufferScale must be finite and positive; pass 1 for the runtime recommendation");
|
|
1031
|
+
this.pending = !0;
|
|
1032
|
+
let r;
|
|
1033
|
+
try {
|
|
1034
|
+
if (e === "inline" && [...t.requiredFeatures ?? [], ...t.optionalFeatures ?? []].includes("webgpu")) throw TypeError("WebGPU XR bindings do not support inline sessions; remove 'webgpu' from the features or request an immersive mode");
|
|
1035
|
+
if (r = await P().requestSession(e, {
|
|
1036
|
+
...t.init,
|
|
1037
|
+
requiredFeatures: [.../* @__PURE__ */ new Set([
|
|
1038
|
+
...e === "inline" || N().XRGPUBinding?.webgl ? [] : ["webgpu"],
|
|
1039
|
+
...n === "viewer" ? [] : [n],
|
|
1040
|
+
...t.requiredFeatures ?? []
|
|
1041
|
+
])],
|
|
1042
|
+
optionalFeatures: t.optionalFeatures ?? []
|
|
1043
|
+
}), this.disposed || this.lost) throw new a("disposed", "XR was disposed during session negotiation; keep the XR alive until requestSession settles.");
|
|
1044
|
+
if (t.signal?.throwIfAborted(), this.session = r, r.addEventListener("end", this.ended, { once: !0 }), this.mode = e, this.callback = t.onFrame, r.addEventListener("inputsourceschange", this.sourcesChanged), this.sourcesChanged(), e === "inline") {
|
|
1045
|
+
if (this.space = await r.requestReferenceSpace(n), this.disposed || this.session !== r) throw new a("state", "XR session ended during initialization; request a new session.");
|
|
1046
|
+
return t.signal?.throwIfAborted(), this.last = null, this.handle = r.requestAnimationFrame(this.frame), r;
|
|
1047
|
+
}
|
|
1048
|
+
this.binding = new (N()).XRGPUBinding(r, this.device);
|
|
1049
|
+
let i = this.binding.getPreferredColorFormat();
|
|
1050
|
+
if (this.layer = this.binding.createProjectionLayer({
|
|
1051
|
+
colorFormat: i,
|
|
1052
|
+
depthStencilFormat: "depth24plus",
|
|
1053
|
+
...t.framebufferScale === void 0 ? {} : { scaleFactor: t.framebufferScale }
|
|
1054
|
+
}), r.updateRenderState({
|
|
1055
|
+
...this.layer.baseLayer ? { baseLayer: this.layer.baseLayer } : { layers: [this.layer] },
|
|
1056
|
+
depthNear: this.engine.camera.near,
|
|
1057
|
+
depthFar: this.engine.camera.far
|
|
1058
|
+
}), this.space = await r.requestReferenceSpace(n), this.disposed || this.session !== r) throw new a("state", "XR session ended during initialization; request a new session.");
|
|
1059
|
+
if (t.signal?.throwIfAborted(), this.eyes) return this.engine.stop(), this.resume = !0, this.last = null, this.handle = r.requestAnimationFrame(this.frame), r;
|
|
1060
|
+
if (this.engine.render({ culling: !1 }), !this.context) throw new a("state", "WebGPU scene descriptor unavailable; add the XR plugin before the first frame renders.");
|
|
1061
|
+
return this.renderer.configure(this.context, i), this.engine.stop(), this.resume = !0, this.last = null, this.handle = r.requestAnimationFrame(this.frame), r;
|
|
1062
|
+
} catch (e) {
|
|
1063
|
+
if (r) try {
|
|
1064
|
+
await r.end();
|
|
1065
|
+
} catch {} finally {
|
|
1066
|
+
this.session === r && this.ended();
|
|
1067
|
+
}
|
|
1068
|
+
throw e;
|
|
1069
|
+
} finally {
|
|
1070
|
+
this.pending = !1;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
renderFrame() {
|
|
1074
|
+
if (!this.insideFrame || this.disposed || !this.session) throw new a("state", "renderFrame requires an active XR frame; call it inside the session onFrame callback.");
|
|
1075
|
+
let { viewer: e, delta: t } = this.state;
|
|
1076
|
+
this.mode !== "inline" && this.eyes ? e && this.eyes.render(this.binding, this.layer, e, t, this.mode === "immersive-ar" || this.seeThrough, this.eyeListeners.size ? this.drawEye : void 0, this.mask) : this.mode !== "inline" && (this.renderOptions.delta = t, this.engine.render(this.renderOptions), e && this.renderer.render(this.engine, this.binding, this.layer, e, this.mode === "immersive-ar" || this.seeThrough, this.eyeListeners.size ? this.drawEye : void 0, this.mask));
|
|
1077
|
+
}
|
|
1078
|
+
fail(e) {
|
|
1079
|
+
this.end().catch((e) => this.engine.onError(e)), this.engine.onError(e);
|
|
1080
|
+
}
|
|
1081
|
+
async end() {
|
|
1082
|
+
let e = this.session;
|
|
1083
|
+
if (e) try {
|
|
1084
|
+
await e.end();
|
|
1085
|
+
} finally {
|
|
1086
|
+
this.session === e && this.ended();
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
dispose() {
|
|
1090
|
+
if (this.disposed) return;
|
|
1091
|
+
this.disposed = !0, this.eyeListeners.clear();
|
|
1092
|
+
let e = this.session;
|
|
1093
|
+
this.ended(), this.device.removeEventListener("uncapturederror", this.uncaptured), L.get(this.device)?.delete(this), this.route === "separate" && this.device.destroy(), e && e.end().catch((e) => this.engine.onError(e)), this.engine?.sceneOf(this)?.removePlugin(this.name);
|
|
1094
|
+
}
|
|
1095
|
+
[Symbol.dispose ?? Symbol()]() {
|
|
1096
|
+
this.dispose();
|
|
1097
|
+
}
|
|
1098
|
+
};
|
|
1099
|
+
function B(e, t = "immersive-vr", n = {}) {
|
|
1100
|
+
return e.requestSession(t, n);
|
|
1101
|
+
}
|
|
1102
|
+
//#endregion
|
|
1103
|
+
export { A as HitTest, z as XR, z as XRManager, O as XRController, I as createXREngine, B as useXRSession };
|