@holoscript/core 8.0.12 → 8.0.14
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/README.md +14 -0
- package/bin/holo-decision.mjs +133 -0
- package/dist/{GLTFPipeline-L76YTXKA.js → GLTFPipeline-6LS3UDYX.js} +6 -6
- package/dist/{GLTFPipeline-ZWJN7GI6.cjs → GLTFPipeline-VTI6PRRQ.cjs} +10 -10
- package/dist/{HoloCompositionParser-FLBZKFD3.js → HoloCompositionParser-GILABNN3.js} +5 -5
- package/dist/{HoloCompositionParser-3XEC7IJC.cjs → HoloCompositionParser-ZVRYVEA5.cjs} +12 -12
- package/dist/{HoloScriptPlusParser-RNUCHOAJ.cjs → HoloScriptPlusParser-WTPRPRPR.cjs} +8 -8
- package/dist/{HoloScriptPlusParser-55AY4MUF.js → HoloScriptPlusParser-ZP53ECSL.js} +5 -5
- package/dist/{SceneIRCompiler-KWUFHZ4O.cjs → SceneIRCompiler-7KQ5NKAU.cjs} +11 -11
- package/dist/{SceneIRCompiler-63KA3M2F.js → SceneIRCompiler-VX75RB6H.js} +6 -6
- package/dist/{chunk-EM2OGPYE.js → chunk-2GKF7JQ6.js} +3 -3
- package/dist/{chunk-HVX7QQYK.js → chunk-3KHRZTNW.js} +3 -3
- package/dist/{chunk-UTUD6GJI.js → chunk-42Z3SVHQ.js} +3 -3
- package/dist/{chunk-Z4IUBW46.js → chunk-47XZ62KM.js} +112 -55
- package/dist/{chunk-GGR7QUKK.cjs → chunk-4CRMVEON.cjs} +37 -37
- package/dist/{chunk-QBY7LRN2.js → chunk-4NEPHK2K.js} +3 -3
- package/dist/{chunk-65S62L4D.cjs → chunk-5B2AJKA5.cjs} +20 -20
- package/dist/{chunk-PJFTTSKE.js → chunk-5T6BWIB7.js} +4 -4
- package/dist/{chunk-KFVNCW4Q.js → chunk-62OYZT6Q.js} +3 -3
- package/dist/{chunk-3KMANSQJ.cjs → chunk-645EWDZW.cjs} +4 -4
- package/dist/{chunk-BP4KTMLY.js → chunk-6FCNMTL5.js} +4 -4
- package/dist/{chunk-77QI552M.js → chunk-73EDVY5D.js} +3 -3
- package/dist/{chunk-7IDJDMPU.cjs → chunk-7FYSSI3C.cjs} +27 -2
- package/dist/{chunk-WNYXT4TE.cjs → chunk-7ITJP33Q.cjs} +3 -3
- package/dist/chunk-7ZKQ32XK.js +1571 -0
- package/dist/{chunk-P7JEKJTZ.cjs → chunk-B6JHTTMR.cjs} +25 -14
- package/dist/{chunk-FG6PYGIZ.js → chunk-BLCWQ225.js} +4 -4
- package/dist/{chunk-7NPZZZD7.js → chunk-C73GVAYC.js} +16 -9
- package/dist/{chunk-RMOEL2GD.cjs → chunk-CESMPUEZ.cjs} +3794 -1137
- package/dist/{chunk-SQXAZHDG.js → chunk-CHIZSMWD.js} +3 -3
- package/dist/{chunk-G35CAQ7I.cjs → chunk-D44CEFY4.cjs} +5 -5
- package/dist/chunk-ERYKKPHW.cjs +1884 -0
- package/dist/{chunk-TYNRXRHF.js → chunk-EYHPTJ3F.js} +3695 -1045
- package/dist/{chunk-J3UHV5T4.cjs → chunk-FGXJPJ3W.cjs} +4 -4
- package/dist/{chunk-IJU6AS67.cjs → chunk-FHR2AVMA.cjs} +23 -23
- package/dist/{chunk-LMB555QB.cjs → chunk-FOM36K5I.cjs} +18 -18
- package/dist/{chunk-JBYBMBMW.js → chunk-FWKEY4LD.js} +3 -2
- package/dist/{chunk-ZRPALBQB.cjs → chunk-GGH3ZYDB.cjs} +5 -5
- package/dist/{chunk-2BYAUHBO.js → chunk-GI5YYZH6.js} +3 -3
- package/dist/{chunk-VTEXJOSD.cjs → chunk-GYJLP4BO.cjs} +30 -30
- package/dist/{chunk-OC6GV5QH.cjs → chunk-HCONR4J6.cjs} +38 -38
- package/dist/{chunk-B3CWTCK2.js → chunk-IA7FCSRY.js} +27 -2
- package/dist/{chunk-5FYMCVBY.js → chunk-IXFNA5TT.js} +4 -4
- package/dist/{chunk-G6KACNMO.js → chunk-JCVSCKUH.js} +4 -4
- package/dist/{chunk-FHVPN7BN.js → chunk-JQCXLKAU.js} +3 -3
- package/dist/{chunk-F3YT6GUF.cjs → chunk-KLM6QD6D.cjs} +14 -14
- package/dist/{chunk-UGQ3QNV6.js → chunk-KOGPVAP6.js} +24 -8
- package/dist/{chunk-CKV5NYAE.js → chunk-KYJD2UMV.js} +4 -4
- package/dist/{chunk-LB3ZZMKT.cjs → chunk-L4DBUX3N.cjs} +10 -10
- package/dist/{chunk-RXQNRZ5F.js → chunk-LGRKBTPM.js} +3 -3
- package/dist/{chunk-OMNHTCS4.cjs → chunk-LHUDAJQT.cjs} +3 -2
- package/dist/{chunk-PDXX5UI4.cjs → chunk-LQNL3IYV.cjs} +38 -38
- package/dist/{chunk-WWNCM473.js → chunk-M7XR3F53.js} +4 -4
- package/dist/{chunk-IFW5IW4L.cjs → chunk-ML4V5PVU.cjs} +670 -627
- package/dist/{chunk-656IAS7B.cjs → chunk-N7IYRAFG.cjs} +21 -14
- package/dist/chunk-N7MIIDLI.cjs +1605 -0
- package/dist/{chunk-USOUXQYD.js → chunk-NWKARJM2.js} +130 -22
- package/dist/{chunk-VVAAZITA.cjs → chunk-OOP4S3GU.cjs} +5 -5
- package/dist/{chunk-TX6ZBIF4.js → chunk-ORBVCOTC.js} +3 -3
- package/dist/{chunk-RRQIAJLQ.cjs → chunk-OSKGCXAQ.cjs} +5 -5
- package/dist/{chunk-QEDMOGF3.cjs → chunk-P65OIMJT.cjs} +7 -7
- package/dist/{chunk-QM7FJB5W.js → chunk-PSWCJQS4.js} +4 -4
- package/dist/{chunk-7N63JHUN.cjs → chunk-PZ46WRHX.cjs} +8 -8
- package/dist/{chunk-AATYYLYK.js → chunk-Q4J2K7FI.js} +16 -5
- package/dist/chunk-QLPRI3QW.js +1875 -0
- package/dist/{chunk-WTH23ISI.js → chunk-R5VKLUMR.js} +4 -4
- package/dist/{chunk-NQN5LFN4.cjs → chunk-REN3LHO6.cjs} +19 -19
- package/dist/{chunk-JEJ7TT54.js → chunk-RVN7OPCP.js} +4 -4
- package/dist/{chunk-ZK7KX5CD.cjs → chunk-SE2Y5BSL.cjs} +6 -6
- package/dist/{chunk-2X3IPCBK.cjs → chunk-SKVBUGMC.cjs} +7 -7
- package/dist/{chunk-GZPUA2TL.cjs → chunk-SNMQUWIO.cjs} +10 -10
- package/dist/{chunk-OIBRWLPY.cjs → chunk-TKDDIE3T.cjs} +54 -3
- package/dist/{chunk-5H5GFBMG.cjs → chunk-TMNAKNV2.cjs} +112 -55
- package/dist/{chunk-5LVFTGKH.js → chunk-TZQKJOPC.js} +3 -3
- package/dist/{chunk-TSTFYGGX.js → chunk-UKEK2NZJ.js} +3 -3
- package/dist/{chunk-3IUHTGDD.cjs → chunk-VA7THINF.cjs} +38 -38
- package/dist/{chunk-Z557DVYN.js → chunk-VMCR5QVI.js} +4 -4
- package/dist/{chunk-IS7NTKY5.cjs → chunk-VTFLKSJL.cjs} +14 -14
- package/dist/{chunk-VO52AJD5.js → chunk-VXHB6ZHY.js} +4 -4
- package/dist/{chunk-S4O7CFHQ.cjs → chunk-VZI7S7P6.cjs} +7 -7
- package/dist/{chunk-BQJ3YBF3.js → chunk-W4AJMMQR.js} +667 -628
- package/dist/{chunk-2KKOYZYI.cjs → chunk-XZC75AJ4.cjs} +5 -5
- package/dist/{chunk-FWCHPCD4.js → chunk-Y2OCKXVD.js} +4 -4
- package/dist/{chunk-EI5G5JLY.cjs → chunk-YBM34FUJ.cjs} +134 -22
- package/dist/{chunk-DUG3OQAS.js → chunk-YDSNDCV3.js} +3 -3
- package/dist/{chunk-566ZB4LZ.cjs → chunk-YM7UUYR5.cjs} +5 -5
- package/dist/{chunk-BCP4E7MD.cjs → chunk-YMI3ED3B.cjs} +26 -10
- package/dist/{chunk-CP7V3ATL.js → chunk-Z7NUL73U.js} +51 -4
- package/dist/cli/holoscript-runner.cjs +11 -11
- package/dist/cli/holoscript-runner.js +4 -4
- package/dist/compiler/agent-inference.cjs +8 -8
- package/dist/compiler/agent-inference.js +4 -4
- package/dist/compiler/android-xr.cjs +7 -7
- package/dist/compiler/android-xr.js +5 -5
- package/dist/compiler/android.cjs +6 -6
- package/dist/compiler/android.js +4 -4
- package/dist/compiler/context.cjs +6 -6
- package/dist/compiler/context.js +3 -3
- package/dist/compiler/daimon-seed.cjs +9 -9
- package/dist/compiler/daimon-seed.js +4 -4
- package/dist/compiler/domain-block-utils.cjs +165 -165
- package/dist/compiler/domain-block-utils.js +4 -4
- package/dist/compiler/dtdl.cjs +7 -7
- package/dist/compiler/dtdl.js +4 -4
- package/dist/compiler/gltf-pipeline.cjs +8 -8
- package/dist/compiler/gltf-pipeline.js +1 -1
- package/dist/compiler/godot.cjs +6 -6
- package/dist/compiler/godot.js +5 -5
- package/dist/compiler/incremental.cjs +8 -8
- package/dist/compiler/incremental.js +3 -3
- package/dist/compiler/index.cjs +871 -207
- package/dist/compiler/index.d.ts +21 -1
- package/dist/compiler/index.js +696 -60
- package/dist/compiler/ios.cjs +6 -6
- package/dist/compiler/ios.js +4 -4
- package/dist/compiler/llm-provider-capabilities.cjs +6 -6
- package/dist/compiler/llm-provider-capabilities.js +3 -3
- package/dist/compiler/openxr.cjs +6 -6
- package/dist/compiler/openxr.js +5 -5
- package/dist/compiler/sdf.cjs +7 -7
- package/dist/compiler/sdf.js +5 -5
- package/dist/compiler/state.cjs +6 -6
- package/dist/compiler/state.js +4 -4
- package/dist/compiler/trait-composition.cjs +7 -7
- package/dist/compiler/trait-composition.js +3 -3
- package/dist/compiler/unity.cjs +6 -6
- package/dist/compiler/unity.js +5 -5
- package/dist/compiler/unreal.cjs +7 -7
- package/dist/compiler/unreal.js +5 -5
- package/dist/compiler/urdf.cjs +14 -14
- package/dist/compiler/urdf.js +5 -5
- package/dist/compiler/usd-physics.cjs +7 -7
- package/dist/compiler/usd-physics.js +4 -4
- package/dist/compiler/visionos.cjs +6 -6
- package/dist/compiler/visionos.js +5 -5
- package/dist/compiler/vrchat.cjs +7 -7
- package/dist/compiler/vrchat.js +5 -5
- package/dist/compiler/wasm.cjs +10 -10
- package/dist/compiler/wasm.js +5 -5
- package/dist/compiler/webgpu.cjs +6 -6
- package/dist/compiler/webgpu.js +5 -5
- package/dist/constants.cjs +3 -3
- package/dist/constants.js +1 -1
- package/dist/entries/scripting.cjs +6 -6
- package/dist/entries/scripting.js +2 -2
- package/dist/evolution/index.cjs +21 -17
- package/dist/evolution/index.d.ts +9 -0
- package/dist/evolution/index.js +6 -6
- package/dist/index.cjs +930 -703
- package/dist/index.d.ts +70 -5
- package/dist/index.js +192 -109
- package/dist/parser.cjs +19 -19
- package/dist/parser.js +5 -5
- package/dist/reconstruction/index.cjs +127 -38
- package/dist/reconstruction/index.d.ts +159 -0
- package/dist/reconstruction/index.js +11 -2
- package/dist/runtime.d.ts +1 -0
- package/dist/traitDocs/traitDocs.cjs +8 -8
- package/dist/traitDocs/traitDocs.js +2 -2
- package/dist/traits/index.cjs +566 -471
- package/dist/traits/index.js +93 -11
- package/package.json +25 -41
- package/dist/chunk-G3BM3CT4.cjs +0 -639
- package/dist/chunk-KEYG7HGY.js +0 -1062
- package/dist/chunk-QX34ELJ7.js +0 -625
- package/dist/chunk-W2GA3EQB.cjs +0 -1065
package/dist/chunk-QX34ELJ7.js
DELETED
|
@@ -1,625 +0,0 @@
|
|
|
1
|
-
import { createHoloMapRuntime, HOLOMAP_DEFAULTS } from './chunk-Z4IUBW46.js';
|
|
2
|
-
|
|
3
|
-
// src/reconstruction/FusedAttentionKernel.ts
|
|
4
|
-
var FUSED_ATTENTION_WGSL = `
|
|
5
|
-
struct Params {
|
|
6
|
-
qRows: u32,
|
|
7
|
-
kRows: u32,
|
|
8
|
-
dModel: u32,
|
|
9
|
-
vCols: u32,
|
|
10
|
-
scale: f32,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
@group(0) @binding(0) var<storage, read> q: array<f32>;
|
|
14
|
-
@group(0) @binding(1) var<storage, read> k: array<f32>;
|
|
15
|
-
@group(0) @binding(2) var<storage, read> v: array<f32>;
|
|
16
|
-
@group(0) @binding(3) var<storage, read_write> out: array<f32>;
|
|
17
|
-
@group(0) @binding(4) var<uniform> params: Params;
|
|
18
|
-
|
|
19
|
-
fn qIndex(row: u32, col: u32) -> u32 {
|
|
20
|
-
return row * params.dModel + col;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
fn kIndex(row: u32, col: u32) -> u32 {
|
|
24
|
-
return row * params.dModel + col;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
fn vIndex(row: u32, col: u32) -> u32 {
|
|
28
|
-
return row * params.vCols + col;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
fn oIndex(row: u32, col: u32) -> u32 {
|
|
32
|
-
return row * params.vCols + col;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@compute @workgroup_size(1, 1, 1)
|
|
36
|
-
fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
37
|
-
let qRow = gid.x;
|
|
38
|
-
if (qRow >= params.qRows) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
var maxScore = -1e30;
|
|
43
|
-
for (var kRow: u32 = 0u; kRow < params.kRows; kRow = kRow + 1u) {
|
|
44
|
-
var dot = 0.0;
|
|
45
|
-
for (var d: u32 = 0u; d < params.dModel; d = d + 1u) {
|
|
46
|
-
dot = dot + q[qIndex(qRow, d)] * k[kIndex(kRow, d)];
|
|
47
|
-
}
|
|
48
|
-
let score = dot * params.scale;
|
|
49
|
-
if (score > maxScore) {
|
|
50
|
-
maxScore = score;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
var denom = 0.0;
|
|
55
|
-
for (var kRow: u32 = 0u; kRow < params.kRows; kRow = kRow + 1u) {
|
|
56
|
-
var dot = 0.0;
|
|
57
|
-
for (var d: u32 = 0u; d < params.dModel; d = d + 1u) {
|
|
58
|
-
dot = dot + q[qIndex(qRow, d)] * k[kIndex(kRow, d)];
|
|
59
|
-
}
|
|
60
|
-
denom = denom + exp(dot * params.scale - maxScore);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
for (var c: u32 = 0u; c < params.vCols; c = c + 1u) {
|
|
64
|
-
var acc = 0.0;
|
|
65
|
-
for (var kRow: u32 = 0u; kRow < params.kRows; kRow = kRow + 1u) {
|
|
66
|
-
var dot = 0.0;
|
|
67
|
-
for (var d: u32 = 0u; d < params.dModel; d = d + 1u) {
|
|
68
|
-
dot = dot + q[qIndex(qRow, d)] * k[kIndex(kRow, d)];
|
|
69
|
-
}
|
|
70
|
-
let w = exp(dot * params.scale - maxScore) / max(denom, 1e-9);
|
|
71
|
-
acc = acc + w * v[vIndex(kRow, c)];
|
|
72
|
-
}
|
|
73
|
-
out[oIndex(qRow, c)] = acc;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
`;
|
|
77
|
-
function cpuFusedAttention(input) {
|
|
78
|
-
const { q, k, v, qRows, kRows, dModel, vCols } = input;
|
|
79
|
-
const out = new Float32Array(qRows * vCols);
|
|
80
|
-
const scale = 1 / Math.sqrt(Math.max(dModel, 1));
|
|
81
|
-
for (let qr = 0; qr < qRows; qr += 1) {
|
|
82
|
-
let maxScore = -Number.MAX_VALUE;
|
|
83
|
-
const scores = new Float32Array(kRows);
|
|
84
|
-
for (let kr = 0; kr < kRows; kr += 1) {
|
|
85
|
-
let dot = 0;
|
|
86
|
-
for (let d = 0; d < dModel; d += 1) {
|
|
87
|
-
dot += q[qr * dModel + d] * k[kr * dModel + d];
|
|
88
|
-
}
|
|
89
|
-
const s = dot * scale;
|
|
90
|
-
scores[kr] = s;
|
|
91
|
-
if (s > maxScore) maxScore = s;
|
|
92
|
-
}
|
|
93
|
-
let denom = 0;
|
|
94
|
-
for (let kr = 0; kr < kRows; kr += 1) {
|
|
95
|
-
const ex = Math.exp(scores[kr] - maxScore);
|
|
96
|
-
scores[kr] = ex;
|
|
97
|
-
denom += ex;
|
|
98
|
-
}
|
|
99
|
-
for (let c = 0; c < vCols; c += 1) {
|
|
100
|
-
let acc = 0;
|
|
101
|
-
for (let kr = 0; kr < kRows; kr += 1) {
|
|
102
|
-
const w = scores[kr] / Math.max(denom, 1e-9);
|
|
103
|
-
acc += w * v[kr * vCols + c];
|
|
104
|
-
}
|
|
105
|
-
out[qr * vCols + c] = acc;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return out;
|
|
109
|
-
}
|
|
110
|
-
async function webGpuFusedAttention(input) {
|
|
111
|
-
const nav = globalThis.navigator;
|
|
112
|
-
const gpu = nav.gpu;
|
|
113
|
-
if (!gpu) {
|
|
114
|
-
throw new Error("WebGPU not available");
|
|
115
|
-
}
|
|
116
|
-
const adapter = await gpu.requestAdapter();
|
|
117
|
-
if (!adapter) {
|
|
118
|
-
throw new Error("No WebGPU adapter");
|
|
119
|
-
}
|
|
120
|
-
const device = await adapter.requestDevice();
|
|
121
|
-
const { q, k, v, qRows, kRows, dModel, vCols } = input;
|
|
122
|
-
const qBytes = q.byteLength;
|
|
123
|
-
const kBytes = k.byteLength;
|
|
124
|
-
const vBytes = v.byteLength;
|
|
125
|
-
const outElems = qRows * vCols;
|
|
126
|
-
const outBytes = outElems * 4;
|
|
127
|
-
const qBuf = device.createBuffer({
|
|
128
|
-
size: Math.max(4, qBytes),
|
|
129
|
-
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST
|
|
130
|
-
});
|
|
131
|
-
const kBuf = device.createBuffer({
|
|
132
|
-
size: Math.max(4, kBytes),
|
|
133
|
-
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST
|
|
134
|
-
});
|
|
135
|
-
const vBuf = device.createBuffer({
|
|
136
|
-
size: Math.max(4, vBytes),
|
|
137
|
-
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST
|
|
138
|
-
});
|
|
139
|
-
const outBuf = device.createBuffer({
|
|
140
|
-
size: Math.max(4, outBytes),
|
|
141
|
-
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST
|
|
142
|
-
});
|
|
143
|
-
const uniBuf = device.createBuffer({
|
|
144
|
-
size: 256,
|
|
145
|
-
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
146
|
-
});
|
|
147
|
-
const uniformData = new ArrayBuffer(256);
|
|
148
|
-
const u32 = new Uint32Array(uniformData, 0, 4);
|
|
149
|
-
const f32 = new Float32Array(uniformData, 16, 1);
|
|
150
|
-
u32[0] = qRows;
|
|
151
|
-
u32[1] = kRows;
|
|
152
|
-
u32[2] = dModel;
|
|
153
|
-
u32[3] = vCols;
|
|
154
|
-
f32[0] = 1 / Math.sqrt(Math.max(dModel, 1));
|
|
155
|
-
device.queue.writeBuffer(qBuf, 0, q.buffer, q.byteOffset, q.byteLength);
|
|
156
|
-
device.queue.writeBuffer(kBuf, 0, k.buffer, k.byteOffset, k.byteLength);
|
|
157
|
-
device.queue.writeBuffer(vBuf, 0, v.buffer, v.byteOffset, v.byteLength);
|
|
158
|
-
device.queue.writeBuffer(uniBuf, 0, uniformData);
|
|
159
|
-
const module = device.createShaderModule({ code: FUSED_ATTENTION_WGSL });
|
|
160
|
-
const bindLayout = device.createBindGroupLayout({
|
|
161
|
-
entries: [
|
|
162
|
-
{
|
|
163
|
-
binding: 0,
|
|
164
|
-
visibility: GPUShaderStage.COMPUTE,
|
|
165
|
-
buffer: { type: "read-only-storage" }
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
binding: 1,
|
|
169
|
-
visibility: GPUShaderStage.COMPUTE,
|
|
170
|
-
buffer: { type: "read-only-storage" }
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
binding: 2,
|
|
174
|
-
visibility: GPUShaderStage.COMPUTE,
|
|
175
|
-
buffer: { type: "read-only-storage" }
|
|
176
|
-
},
|
|
177
|
-
{ binding: 3, visibility: GPUShaderStage.COMPUTE, buffer: { type: "storage" } },
|
|
178
|
-
{ binding: 4, visibility: GPUShaderStage.COMPUTE, buffer: { type: "uniform" } }
|
|
179
|
-
]
|
|
180
|
-
});
|
|
181
|
-
const pipelineLayout = device.createPipelineLayout({ bindGroupLayouts: [bindLayout] });
|
|
182
|
-
const pipeline = await device.createComputePipelineAsync({
|
|
183
|
-
layout: pipelineLayout,
|
|
184
|
-
compute: { module, entryPoint: "main" }
|
|
185
|
-
});
|
|
186
|
-
const bindGroup = device.createBindGroup({
|
|
187
|
-
layout: bindLayout,
|
|
188
|
-
entries: [
|
|
189
|
-
{ binding: 0, resource: { buffer: qBuf } },
|
|
190
|
-
{ binding: 1, resource: { buffer: kBuf } },
|
|
191
|
-
{ binding: 2, resource: { buffer: vBuf } },
|
|
192
|
-
{ binding: 3, resource: { buffer: outBuf } },
|
|
193
|
-
{ binding: 4, resource: { buffer: uniBuf } }
|
|
194
|
-
]
|
|
195
|
-
});
|
|
196
|
-
const encoder = device.createCommandEncoder();
|
|
197
|
-
const pass = encoder.beginComputePass();
|
|
198
|
-
pass.setPipeline(pipeline);
|
|
199
|
-
pass.setBindGroup(0, bindGroup);
|
|
200
|
-
pass.dispatchWorkgroups(qRows, 1, 1);
|
|
201
|
-
pass.end();
|
|
202
|
-
const readBuf = device.createBuffer({
|
|
203
|
-
size: Math.max(4, outBytes),
|
|
204
|
-
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
|
|
205
|
-
});
|
|
206
|
-
encoder.copyBufferToBuffer(outBuf, 0, readBuf, 0, outBytes);
|
|
207
|
-
device.queue.submit([encoder.finish()]);
|
|
208
|
-
await readBuf.mapAsync(GPUMapMode.READ);
|
|
209
|
-
const mapped = new Float32Array(readBuf.getMappedRange());
|
|
210
|
-
const copy = new Float32Array(outElems);
|
|
211
|
-
copy.set(mapped);
|
|
212
|
-
readBuf.unmap();
|
|
213
|
-
qBuf.destroy();
|
|
214
|
-
kBuf.destroy();
|
|
215
|
-
vBuf.destroy();
|
|
216
|
-
outBuf.destroy();
|
|
217
|
-
uniBuf.destroy();
|
|
218
|
-
readBuf.destroy();
|
|
219
|
-
return copy;
|
|
220
|
-
}
|
|
221
|
-
var CpuFusedAttentionBackend = class {
|
|
222
|
-
constructor() {
|
|
223
|
-
this.name = "cpu";
|
|
224
|
-
}
|
|
225
|
-
async compute(input) {
|
|
226
|
-
return cpuFusedAttention(input);
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
var WebGpuFusedAttentionBackend = class {
|
|
230
|
-
constructor() {
|
|
231
|
-
this.name = "webgpu";
|
|
232
|
-
}
|
|
233
|
-
async compute(input) {
|
|
234
|
-
try {
|
|
235
|
-
return await webGpuFusedAttention(input);
|
|
236
|
-
} catch {
|
|
237
|
-
return cpuFusedAttention(input);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
async function createFusedAttentionBackend() {
|
|
242
|
-
if (typeof navigator !== "undefined" && "gpu" in navigator) {
|
|
243
|
-
return new WebGpuFusedAttentionBackend();
|
|
244
|
-
}
|
|
245
|
-
return new CpuFusedAttentionBackend();
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// src/reconstruction/TrajectoryMemory.ts
|
|
249
|
-
var TRAJECTORY_DEFAULTS = {
|
|
250
|
-
maxKeyframes: 512,
|
|
251
|
-
keyframeStrideMeters: 0.25,
|
|
252
|
-
loopClosureThreshold: 0.92
|
|
253
|
-
};
|
|
254
|
-
function createTrajectoryMemory(_config) {
|
|
255
|
-
throw new Error(
|
|
256
|
-
"TrajectoryMemory is scaffolded in Sprint 1; implementation lands in Sprint 2. See reconstruction/RFC-HoloMap.md \xA7Trajectory"
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// src/reconstruction/AnchorContext.ts
|
|
261
|
-
var ANCHOR_DEFAULTS = {
|
|
262
|
-
warmupFrames: 30,
|
|
263
|
-
minConfidence: 0.75,
|
|
264
|
-
maxDriftBeforeReanchor: 2
|
|
265
|
-
};
|
|
266
|
-
function createAnchorContext(_config) {
|
|
267
|
-
throw new Error(
|
|
268
|
-
"AnchorContext is scaffolded in Sprint 1; implementation lands in Sprint 2. See reconstruction/RFC-HoloMap.md \xA7Anchor"
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// src/reconstruction/mobileSensorBundle.ts
|
|
273
|
-
var HOLOMAP_MOBILE_SENSOR_BUNDLE_VERSION = "holomap-mobile-sensor-bundle/v1";
|
|
274
|
-
var ARCORE_DEPTH_RECOMMENDED_RANGE_MILLIMETERS = {
|
|
275
|
-
near: 500,
|
|
276
|
-
far: 5e3
|
|
277
|
-
};
|
|
278
|
-
function finiteNumber(value) {
|
|
279
|
-
return Number.isFinite(value);
|
|
280
|
-
}
|
|
281
|
-
function finiteArray(values, expectedLength) {
|
|
282
|
-
if (values.length !== expectedLength) return false;
|
|
283
|
-
for (let i = 0; i < values.length; i += 1) {
|
|
284
|
-
if (!finiteNumber(Number(values[i]))) return false;
|
|
285
|
-
}
|
|
286
|
-
return true;
|
|
287
|
-
}
|
|
288
|
-
function clampUnit(value) {
|
|
289
|
-
if (!Number.isFinite(value)) return 0;
|
|
290
|
-
return Math.max(0, Math.min(1, value));
|
|
291
|
-
}
|
|
292
|
-
function requirePositiveInteger(value, name) {
|
|
293
|
-
if (!Number.isInteger(value) || value <= 0) {
|
|
294
|
-
throw new Error(`${name} must be a positive integer`);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
function normalizeArCoreDepthRange(range) {
|
|
298
|
-
const near = range?.near ?? ARCORE_DEPTH_RECOMMENDED_RANGE_MILLIMETERS.near;
|
|
299
|
-
const far = range?.far ?? ARCORE_DEPTH_RECOMMENDED_RANGE_MILLIMETERS.far;
|
|
300
|
-
if (!finiteNumber(near) || near <= 0)
|
|
301
|
-
throw new Error("arCoreDepthRange.near must be positive finite");
|
|
302
|
-
if (!finiteNumber(far) || far <= near)
|
|
303
|
-
throw new Error("arCoreDepthRange.far must be finite and greater than near");
|
|
304
|
-
return { near, far };
|
|
305
|
-
}
|
|
306
|
-
function requirePlane(width, height, values, name, maxValue) {
|
|
307
|
-
requirePositiveInteger(width, `${name}.width`);
|
|
308
|
-
requirePositiveInteger(height, `${name}.height`);
|
|
309
|
-
const expected = width * height;
|
|
310
|
-
if (values.length !== expected) {
|
|
311
|
-
throw new Error(`${name}.values length must be ${expected}`);
|
|
312
|
-
}
|
|
313
|
-
for (let i = 0; i < values.length; i += 1) {
|
|
314
|
-
const value = Number(values[i]);
|
|
315
|
-
if (!Number.isFinite(value) || value < 0 || value > maxValue) {
|
|
316
|
-
throw new Error(`${name}.values[${i}] must be a finite value from 0 to ${maxValue}`);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
function nearestPlaneIndex(x, y, srcWidth, srcHeight, dstWidth, dstHeight) {
|
|
321
|
-
const sx = Math.min(srcWidth - 1, Math.max(0, Math.floor((x + 0.5) * srcWidth / dstWidth)));
|
|
322
|
-
const sy = Math.min(srcHeight - 1, Math.max(0, Math.floor((y + 0.5) * srcHeight / dstHeight)));
|
|
323
|
-
return sy * srcWidth + sx;
|
|
324
|
-
}
|
|
325
|
-
function arCoreDepthMillimetersToUnit(depthMillimeters, range) {
|
|
326
|
-
if (!Number.isFinite(depthMillimeters) || depthMillimeters <= 0) return 1;
|
|
327
|
-
return clampUnit((depthMillimeters - range.near) / (range.far - range.near));
|
|
328
|
-
}
|
|
329
|
-
function arCoreDepthCellIsTrusted(depthMillimeters, range) {
|
|
330
|
-
return Number.isFinite(depthMillimeters) && depthMillimeters > 0 && depthMillimeters <= range.far;
|
|
331
|
-
}
|
|
332
|
-
function toUint8Array(values, name) {
|
|
333
|
-
const out = new Uint8Array(values.length);
|
|
334
|
-
for (let i = 0; i < values.length; i += 1) {
|
|
335
|
-
const value = Number(values[i]);
|
|
336
|
-
if (!Number.isFinite(value) || value < 0 || value > 255) {
|
|
337
|
-
throw new Error(`${name}[${i}] must be a finite byte`);
|
|
338
|
-
}
|
|
339
|
-
out[i] = Math.round(value);
|
|
340
|
-
}
|
|
341
|
-
return out;
|
|
342
|
-
}
|
|
343
|
-
function toFloat32UnitArray(values, name) {
|
|
344
|
-
const out = new Float32Array(values.length);
|
|
345
|
-
for (let i = 0; i < values.length; i += 1) {
|
|
346
|
-
const value = Number(values[i]);
|
|
347
|
-
if (!Number.isFinite(value)) throw new Error(`${name}[${i}] must be finite`);
|
|
348
|
-
out[i] = clampUnit(value);
|
|
349
|
-
}
|
|
350
|
-
return out;
|
|
351
|
-
}
|
|
352
|
-
function confidenceToUnitArray(plane) {
|
|
353
|
-
const out = new Float32Array(plane.values.length);
|
|
354
|
-
for (let i = 0; i < plane.values.length; i += 1) {
|
|
355
|
-
const value = Number(plane.values[i]);
|
|
356
|
-
if (!Number.isFinite(value)) throw new Error(`sceneDepthConfidence[${i}] must be finite`);
|
|
357
|
-
if (plane.encoding === "unit") out[i] = clampUnit(value);
|
|
358
|
-
else if (plane.encoding === "arkit-0-2") out[i] = clampUnit(value / 2);
|
|
359
|
-
else out[i] = clampUnit(value / 255);
|
|
360
|
-
}
|
|
361
|
-
return out;
|
|
362
|
-
}
|
|
363
|
-
function arCoreDepthFrameToMobileSensorFrame(frame, depthRangeMillimeters) {
|
|
364
|
-
requirePositiveInteger(frame.width, "arCoreFrame.width");
|
|
365
|
-
requirePositiveInteger(frame.height, "arCoreFrame.height");
|
|
366
|
-
if (frame.stride !== 3 && frame.stride !== 4) {
|
|
367
|
-
throw new Error("arCoreFrame.stride must be 3 or 4");
|
|
368
|
-
}
|
|
369
|
-
if (!finiteNumber(frame.timestampMs)) throw new Error("arCoreFrame.timestampMs must be finite");
|
|
370
|
-
if (!Number.isInteger(frame.index) || frame.index < 0) {
|
|
371
|
-
throw new Error("arCoreFrame.index must be a non-negative integer");
|
|
372
|
-
}
|
|
373
|
-
if (!finiteArray(frame.rgb, frame.width * frame.height * frame.stride)) {
|
|
374
|
-
throw new Error("arCoreFrame.rgb length/content invalid");
|
|
375
|
-
}
|
|
376
|
-
const depth = frame.depthImage16Bits;
|
|
377
|
-
const range = normalizeArCoreDepthRange(depthRangeMillimeters);
|
|
378
|
-
requirePlane(depth.width, depth.height, depth.millimeters, "arCoreFrame.depthImage16Bits", 65535);
|
|
379
|
-
if (frame.rawDepthConfidenceImage) {
|
|
380
|
-
const confidence = frame.rawDepthConfidenceImage;
|
|
381
|
-
requirePlane(
|
|
382
|
-
confidence.width,
|
|
383
|
-
confidence.height,
|
|
384
|
-
confidence.values,
|
|
385
|
-
"arCoreFrame.rawDepthConfidenceImage",
|
|
386
|
-
255
|
|
387
|
-
);
|
|
388
|
-
if (confidence.width !== depth.width || confidence.height !== depth.height) {
|
|
389
|
-
throw new Error("arCoreFrame.rawDepthConfidenceImage dimensions must match depthImage16Bits");
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
const pixelCount = frame.width * frame.height;
|
|
393
|
-
const normalizedDepth = new Float32Array(pixelCount);
|
|
394
|
-
const metricDepthMeters = new Float32Array(pixelCount);
|
|
395
|
-
const normalizedConfidence = new Float32Array(pixelCount);
|
|
396
|
-
for (let y = 0; y < frame.height; y += 1) {
|
|
397
|
-
for (let x = 0; x < frame.width; x += 1) {
|
|
398
|
-
const dstIndex = y * frame.width + x;
|
|
399
|
-
const srcIndex = nearestPlaneIndex(
|
|
400
|
-
x,
|
|
401
|
-
y,
|
|
402
|
-
depth.width,
|
|
403
|
-
depth.height,
|
|
404
|
-
frame.width,
|
|
405
|
-
frame.height
|
|
406
|
-
);
|
|
407
|
-
const depthMillimeters = Number(depth.millimeters[srcIndex]);
|
|
408
|
-
normalizedDepth[dstIndex] = arCoreDepthMillimetersToUnit(depthMillimeters, range);
|
|
409
|
-
metricDepthMeters[dstIndex] = arCoreDepthCellIsTrusted(depthMillimeters, range) ? depthMillimeters / 1e3 : 0;
|
|
410
|
-
const sensorConfidence = frame.rawDepthConfidenceImage ? clampUnit(Number(frame.rawDepthConfidenceImage.values[srcIndex]) / 255) : 1;
|
|
411
|
-
normalizedConfidence[dstIndex] = arCoreDepthCellIsTrusted(depthMillimeters, range) ? sensorConfidence : 0;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
return {
|
|
415
|
-
index: frame.index,
|
|
416
|
-
timestampMs: frame.timestampMs,
|
|
417
|
-
width: frame.width,
|
|
418
|
-
height: frame.height,
|
|
419
|
-
stride: frame.stride,
|
|
420
|
-
rgb: frame.rgb,
|
|
421
|
-
sceneDepth: {
|
|
422
|
-
width: frame.width,
|
|
423
|
-
height: frame.height,
|
|
424
|
-
values: normalizedDepth
|
|
425
|
-
},
|
|
426
|
-
sceneDepthMeters: {
|
|
427
|
-
width: frame.width,
|
|
428
|
-
height: frame.height,
|
|
429
|
-
values: metricDepthMeters
|
|
430
|
-
},
|
|
431
|
-
sceneDepthConfidence: {
|
|
432
|
-
width: frame.width,
|
|
433
|
-
height: frame.height,
|
|
434
|
-
encoding: "unit",
|
|
435
|
-
values: normalizedConfidence
|
|
436
|
-
},
|
|
437
|
-
cameraTransformColumnMajor4x4: frame.cameraTransformColumnMajor4x4,
|
|
438
|
-
devicePose: frame.devicePose
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
function createArCoreDepthMobileSensorBundle(input) {
|
|
442
|
-
if (!input.bundleId) throw new Error("arCoreBundle.bundleId missing");
|
|
443
|
-
if (!Array.isArray(input.frames) || input.frames.length === 0) {
|
|
444
|
-
throw new Error("arCoreBundle.frames missing");
|
|
445
|
-
}
|
|
446
|
-
return {
|
|
447
|
-
schemaVersion: HOLOMAP_MOBILE_SENSOR_BUNDLE_VERSION,
|
|
448
|
-
bundleId: input.bundleId,
|
|
449
|
-
capture: {
|
|
450
|
-
platform: "android-arcore-depth",
|
|
451
|
-
deviceModel: input.deviceModel,
|
|
452
|
-
coordinateSystem: "arcore-right-handed-y-up",
|
|
453
|
-
intrinsics: input.intrinsics
|
|
454
|
-
},
|
|
455
|
-
frames: input.frames.map(
|
|
456
|
-
(frame) => arCoreDepthFrameToMobileSensorFrame(frame, input.depthRangeMillimeters)
|
|
457
|
-
)
|
|
458
|
-
};
|
|
459
|
-
}
|
|
460
|
-
function normalizeQuaternion(q) {
|
|
461
|
-
const len = Math.hypot(q[0], q[1], q[2], q[3]);
|
|
462
|
-
if (len <= 1e-12) return [0, 0, 0, 1];
|
|
463
|
-
return [q[0] / len, q[1] / len, q[2] / len, q[3] / len];
|
|
464
|
-
}
|
|
465
|
-
function cameraPoseFromColumnMajorTransform(transform, confidence = 1) {
|
|
466
|
-
if (transform.length !== 16 || !finiteArray(transform, 16)) {
|
|
467
|
-
throw new Error("cameraTransformColumnMajor4x4 must contain 16 finite numbers");
|
|
468
|
-
}
|
|
469
|
-
const m00 = Number(transform[0]);
|
|
470
|
-
const m01 = Number(transform[4]);
|
|
471
|
-
const m02 = Number(transform[8]);
|
|
472
|
-
const m10 = Number(transform[1]);
|
|
473
|
-
const m11 = Number(transform[5]);
|
|
474
|
-
const m12 = Number(transform[9]);
|
|
475
|
-
const m20 = Number(transform[2]);
|
|
476
|
-
const m21 = Number(transform[6]);
|
|
477
|
-
const m22 = Number(transform[10]);
|
|
478
|
-
const trace = m00 + m11 + m22;
|
|
479
|
-
let rotation;
|
|
480
|
-
if (trace > 0) {
|
|
481
|
-
const s = Math.sqrt(trace + 1) * 2;
|
|
482
|
-
rotation = [(m21 - m12) / s, (m02 - m20) / s, (m10 - m01) / s, 0.25 * s];
|
|
483
|
-
} else if (m00 > m11 && m00 > m22) {
|
|
484
|
-
const s = Math.sqrt(1 + m00 - m11 - m22) * 2;
|
|
485
|
-
rotation = [0.25 * s, (m01 + m10) / s, (m02 + m20) / s, (m21 - m12) / s];
|
|
486
|
-
} else if (m11 > m22) {
|
|
487
|
-
const s = Math.sqrt(1 + m11 - m00 - m22) * 2;
|
|
488
|
-
rotation = [(m01 + m10) / s, 0.25 * s, (m12 + m21) / s, (m02 - m20) / s];
|
|
489
|
-
} else {
|
|
490
|
-
const s = Math.sqrt(1 + m22 - m00 - m11) * 2;
|
|
491
|
-
rotation = [(m02 + m20) / s, (m12 + m21) / s, 0.25 * s, (m10 - m01) / s];
|
|
492
|
-
}
|
|
493
|
-
return {
|
|
494
|
-
position: [Number(transform[12]), Number(transform[13]), Number(transform[14])],
|
|
495
|
-
rotation: normalizeQuaternion(rotation),
|
|
496
|
-
confidence: clampUnit(confidence)
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
function validateMobileSensorBundle(bundle) {
|
|
500
|
-
const errors = [];
|
|
501
|
-
if (bundle.schemaVersion !== HOLOMAP_MOBILE_SENSOR_BUNDLE_VERSION)
|
|
502
|
-
errors.push("schemaVersion mismatch");
|
|
503
|
-
if (!bundle.bundleId) errors.push("bundleId missing");
|
|
504
|
-
if (!bundle.capture?.platform) errors.push("capture.platform missing");
|
|
505
|
-
const intrinsics = bundle.capture?.intrinsics;
|
|
506
|
-
if (!intrinsics) {
|
|
507
|
-
errors.push("capture.intrinsics missing");
|
|
508
|
-
} else {
|
|
509
|
-
for (const key of ["width", "height", "fx", "fy", "cx", "cy"]) {
|
|
510
|
-
if (!finiteNumber(intrinsics[key]) || intrinsics[key] <= 0) {
|
|
511
|
-
errors.push(`capture.intrinsics.${key} must be positive finite`);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
if (!intrinsics.source) errors.push("capture.intrinsics.source missing");
|
|
515
|
-
}
|
|
516
|
-
if (!Array.isArray(bundle.frames) || bundle.frames.length === 0) errors.push("frames missing");
|
|
517
|
-
for (const frame of bundle.frames ?? []) {
|
|
518
|
-
const prefix = `frame[${frame?.index ?? "?"}]`;
|
|
519
|
-
if (!Number.isInteger(frame.index) || frame.index < 0)
|
|
520
|
-
errors.push(`${prefix}.index must be a non-negative integer`);
|
|
521
|
-
if (!finiteNumber(frame.timestampMs)) errors.push(`${prefix}.timestampMs must be finite`);
|
|
522
|
-
if (!Number.isInteger(frame.width) || frame.width <= 0)
|
|
523
|
-
errors.push(`${prefix}.width must be positive integer`);
|
|
524
|
-
if (!Number.isInteger(frame.height) || frame.height <= 0)
|
|
525
|
-
errors.push(`${prefix}.height must be positive integer`);
|
|
526
|
-
if (frame.stride !== 3 && frame.stride !== 4) errors.push(`${prefix}.stride must be 3 or 4`);
|
|
527
|
-
const pixelCount = frame.width * frame.height;
|
|
528
|
-
if (!finiteArray(frame.rgb, pixelCount * frame.stride))
|
|
529
|
-
errors.push(`${prefix}.rgb length/content invalid`);
|
|
530
|
-
if (frame.sceneDepth) {
|
|
531
|
-
if (frame.sceneDepth.width !== frame.width || frame.sceneDepth.height !== frame.height) {
|
|
532
|
-
errors.push(`${prefix}.sceneDepth dimensions must match frame`);
|
|
533
|
-
}
|
|
534
|
-
if (!finiteArray(frame.sceneDepth.values, pixelCount))
|
|
535
|
-
errors.push(`${prefix}.sceneDepth values invalid`);
|
|
536
|
-
}
|
|
537
|
-
if (frame.sceneDepthMeters) {
|
|
538
|
-
if (frame.sceneDepthMeters.width !== frame.width || frame.sceneDepthMeters.height !== frame.height) {
|
|
539
|
-
errors.push(`${prefix}.sceneDepthMeters dimensions must match frame`);
|
|
540
|
-
}
|
|
541
|
-
if (!finiteArray(frame.sceneDepthMeters.values, pixelCount))
|
|
542
|
-
errors.push(`${prefix}.sceneDepthMeters values invalid`);
|
|
543
|
-
}
|
|
544
|
-
if (frame.sceneDepthConfidence) {
|
|
545
|
-
if (frame.sceneDepthConfidence.width !== frame.width || frame.sceneDepthConfidence.height !== frame.height) {
|
|
546
|
-
errors.push(`${prefix}.sceneDepthConfidence dimensions must match frame`);
|
|
547
|
-
}
|
|
548
|
-
if (!finiteArray(frame.sceneDepthConfidence.values, pixelCount)) {
|
|
549
|
-
errors.push(`${prefix}.sceneDepthConfidence values invalid`);
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
if (frame.cameraTransformColumnMajor4x4 && !finiteArray(frame.cameraTransformColumnMajor4x4, 16)) {
|
|
553
|
-
errors.push(`${prefix}.cameraTransformColumnMajor4x4 invalid`);
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
return errors;
|
|
557
|
-
}
|
|
558
|
-
function mobileSensorBundleToFrames(bundle) {
|
|
559
|
-
const errors = validateMobileSensorBundle(bundle);
|
|
560
|
-
if (errors.length > 0)
|
|
561
|
-
throw new Error(`Invalid HoloMap mobile sensor bundle: ${errors.join("; ")}`);
|
|
562
|
-
return bundle.frames.map((frame) => ({
|
|
563
|
-
index: frame.index,
|
|
564
|
-
timestampMs: frame.timestampMs,
|
|
565
|
-
width: frame.width,
|
|
566
|
-
height: frame.height,
|
|
567
|
-
stride: frame.stride,
|
|
568
|
-
rgb: toUint8Array(frame.rgb, `frame[${frame.index}].rgb`),
|
|
569
|
-
depth: frame.sceneDepth ? toFloat32UnitArray(frame.sceneDepth.values, `frame[${frame.index}].sceneDepth`) : void 0,
|
|
570
|
-
depthMeters: frame.sceneDepthMeters ? new Float32Array(Array.from(frame.sceneDepthMeters.values, Number)) : void 0,
|
|
571
|
-
depthConfidence: frame.sceneDepthConfidence ? confidenceToUnitArray(frame.sceneDepthConfidence) : void 0,
|
|
572
|
-
cameraIntrinsics: {
|
|
573
|
-
width: bundle.capture.intrinsics.width,
|
|
574
|
-
height: bundle.capture.intrinsics.height,
|
|
575
|
-
fx: bundle.capture.intrinsics.fx,
|
|
576
|
-
fy: bundle.capture.intrinsics.fy,
|
|
577
|
-
cx: bundle.capture.intrinsics.cx,
|
|
578
|
-
cy: bundle.capture.intrinsics.cy
|
|
579
|
-
},
|
|
580
|
-
devicePose: frame.cameraTransformColumnMajor4x4 ? cameraPoseFromColumnMajorTransform(
|
|
581
|
-
frame.cameraTransformColumnMajor4x4,
|
|
582
|
-
frame.devicePose?.confidence ?? 1
|
|
583
|
-
) : frame.devicePose
|
|
584
|
-
}));
|
|
585
|
-
}
|
|
586
|
-
async function replayMobileSensorBundle(bundle, config = {}) {
|
|
587
|
-
const frames = mobileSensorBundleToFrames(bundle);
|
|
588
|
-
const runtime = createHoloMapRuntime();
|
|
589
|
-
await runtime.init({
|
|
590
|
-
...HOLOMAP_DEFAULTS,
|
|
591
|
-
seed: 0,
|
|
592
|
-
modelHash: bundle.bundleId,
|
|
593
|
-
videoHash: bundle.bundleId,
|
|
594
|
-
targetFPS: 1e5,
|
|
595
|
-
...config
|
|
596
|
-
});
|
|
597
|
-
const steps = [];
|
|
598
|
-
try {
|
|
599
|
-
for (const frame of frames) {
|
|
600
|
-
const step = await runtime.step(frame);
|
|
601
|
-
if (step) steps.push(step);
|
|
602
|
-
}
|
|
603
|
-
const manifest = await runtime.finalize();
|
|
604
|
-
const meshAnchorCount = bundle.frames.reduce(
|
|
605
|
-
(sum, frame) => sum + (frame.meshAnchors?.length ?? 0),
|
|
606
|
-
0
|
|
607
|
-
);
|
|
608
|
-
return {
|
|
609
|
-
source: {
|
|
610
|
-
bundleId: bundle.bundleId,
|
|
611
|
-
platform: bundle.capture.platform,
|
|
612
|
-
frameCount: bundle.frames.length,
|
|
613
|
-
meshAnchorCount
|
|
614
|
-
},
|
|
615
|
-
steps,
|
|
616
|
-
manifest
|
|
617
|
-
};
|
|
618
|
-
} finally {
|
|
619
|
-
await runtime.dispose();
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
export { ANCHOR_DEFAULTS, ARCORE_DEPTH_RECOMMENDED_RANGE_MILLIMETERS, HOLOMAP_MOBILE_SENSOR_BUNDLE_VERSION, TRAJECTORY_DEFAULTS, arCoreDepthFrameToMobileSensorFrame, cameraPoseFromColumnMajorTransform, createAnchorContext, createArCoreDepthMobileSensorBundle, createFusedAttentionBackend, createTrajectoryMemory, mobileSensorBundleToFrames, replayMobileSensorBundle, validateMobileSensorBundle };
|
|
624
|
-
//# sourceMappingURL=chunk-QX34ELJ7.js.map
|
|
625
|
-
//# sourceMappingURL=chunk-QX34ELJ7.js.map
|