@displayxr/inline3d-tools 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +351 -0
- package/LICENSE +190 -0
- package/README.md +192 -1
- package/bin/inline3d-tools.mjs +40 -0
- package/lib/assets/asset-check.mjs +262 -0
- package/lib/assets/blender/prep.py +74 -0
- package/lib/assets/prep.mjs +50 -0
- package/lib/check/analyze.mjs +244 -0
- package/lib/check/cdp.mjs +174 -0
- package/lib/check/cli.mjs +66 -0
- package/lib/check/fake-env.js +435 -0
- package/lib/check/png.mjs +75 -0
- package/lib/check/probe.js +245 -0
- package/lib/check/run.mjs +811 -0
- package/lib/check/server.mjs +33 -0
- package/lib/gen.mjs +172 -0
- package/lib/mcp.mjs +168 -0
- package/lib/scaffold.mjs +62 -0
- package/package.json +50 -4
- package/templates/app.js +153 -0
- package/templates/esm/index.html +29 -0
- package/templates/style.css +17 -0
- package/templates/vite/index.html +20 -0
- package/templates/vite/package.template.json +18 -0
|
@@ -0,0 +1,811 @@
|
|
|
1
|
+
// inline3d-check — orchestration: load the page twice in headless Chrome (once with the fake
|
|
2
|
+
// DisplayXR inline-3D environment, once plain), collect evidence, and turn it into checks.
|
|
3
|
+
import { readFileSync, existsSync, statSync } from 'node:fs';
|
|
4
|
+
import { resolve, dirname, relative, join, sep } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { launchChrome, withTimeout } from './cdp.mjs';
|
|
7
|
+
import { serveDir } from './server.mjs';
|
|
8
|
+
import { decodePng } from './png.mjs';
|
|
9
|
+
import {
|
|
10
|
+
crop, halves, contentStats, regionDiff, compareEyes, blockDisparity, quantile, flatWideVerdict, sbsPairVerdict, shibataZoneMm, fromBase64Rgba,
|
|
11
|
+
} from './analyze.mjs';
|
|
12
|
+
|
|
13
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const PROBE_SRC = readFileSync(join(HERE, 'probe.js'), 'utf8');
|
|
15
|
+
const FAKE_SRC = readFileSync(join(HERE, 'fake-env.js'), 'utf8');
|
|
16
|
+
export const VERSION = JSON.parse(readFileSync(join(HERE, '..', '..', 'package.json'), 'utf8')).version;
|
|
17
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
18
|
+
const DOCS = 'node_modules/@displayxr/inline3d/docs';
|
|
19
|
+
const MPP = 0.3456 / 1920; // metres per CSS px on the fake panel (see fake-env.js)
|
|
20
|
+
|
|
21
|
+
// ------------------------------------------------------------------------------ target
|
|
22
|
+
export async function resolveTarget(target, rootOpt) {
|
|
23
|
+
if (/^https?:\/\//i.test(target)) return { url: target, server: null, kind: 'url' };
|
|
24
|
+
// A local target may carry a query/hash for the page (`page.html?debug`).
|
|
25
|
+
const qi = target.search(/[?#]/);
|
|
26
|
+
const suffix = qi >= 0 ? target.slice(qi) : '';
|
|
27
|
+
if (qi >= 0) target = target.slice(0, qi);
|
|
28
|
+
const abs = resolve(target);
|
|
29
|
+
if (!existsSync(abs)) throw new Error(`target not found: ${target}`);
|
|
30
|
+
const isDir = statSync(abs).isDirectory();
|
|
31
|
+
const root = resolve(rootOpt || (isDir ? abs : dirname(abs)));
|
|
32
|
+
if (abs !== root && !abs.startsWith(root + sep)) throw new Error(`target ${abs} is outside --root ${root}`);
|
|
33
|
+
const server = await serveDir(root);
|
|
34
|
+
let rel = relative(root, abs).split(sep).join('/');
|
|
35
|
+
if (isDir && rel && !rel.endsWith('/')) rel += '/';
|
|
36
|
+
return { url: `${server.url}/${rel}${suffix}`, server, kind: isDir ? 'dir' : 'file', root, file: abs };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ------------------------------------------------------------------------------ page plumbing
|
|
40
|
+
async function ev(page, expression) {
|
|
41
|
+
const r = await page.send('Runtime.evaluate', { expression, awaitPromise: true, returnByValue: true });
|
|
42
|
+
if (r.exceptionDetails) throw new Error(`page evaluate failed: ${r.exceptionDetails.exception?.description || r.exceptionDetails.text}`);
|
|
43
|
+
return r.result.value;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function collect(page, pageOrigin) {
|
|
47
|
+
const log = { console: [], exceptions: [], network: [], logEntries: [], scripts: [] };
|
|
48
|
+
page.on('Runtime.consoleAPICalled', (p) => {
|
|
49
|
+
const text = (p.args || []).map((a) => (a.value !== undefined ? (typeof a.value === 'string' ? a.value : JSON.stringify(a.value)) : a.description || a.type)).join(' ');
|
|
50
|
+
const fr = p.stackTrace && p.stackTrace.callFrames && p.stackTrace.callFrames[0];
|
|
51
|
+
log.console.push({ type: p.type, text: text.slice(0, 600), at: fr ? `${fr.url}:${fr.lineNumber + 1}` : undefined });
|
|
52
|
+
});
|
|
53
|
+
page.on('Runtime.exceptionThrown', (p) => {
|
|
54
|
+
const d = p.exceptionDetails || {};
|
|
55
|
+
log.exceptions.push({ text: ((d.exception && d.exception.description) || d.text || 'exception').slice(0, 600), at: d.url ? `${d.url}:${(d.lineNumber || 0) + 1}` : undefined });
|
|
56
|
+
});
|
|
57
|
+
page.on('Log.entryAdded', (p) => {
|
|
58
|
+
const e = p.entry || {};
|
|
59
|
+
log.logEntries.push({ level: e.level, source: e.source, text: (e.text || '').slice(0, 400), url: e.url });
|
|
60
|
+
});
|
|
61
|
+
const reqs = new Map();
|
|
62
|
+
page.on('Network.responseReceived', (p) => {
|
|
63
|
+
const u = p.response.url;
|
|
64
|
+
reqs.set(p.requestId, { url: u, type: p.type, status: p.response.status });
|
|
65
|
+
if (p.response.status >= 400) log.network.push({ url: u, status: p.response.status, type: p.type });
|
|
66
|
+
});
|
|
67
|
+
page.on('Network.loadingFailed', (p) => {
|
|
68
|
+
if (p.canceled || /ERR_ABORTED/.test(p.errorText || '')) return;
|
|
69
|
+
const r = reqs.get(p.requestId);
|
|
70
|
+
log.network.push({ url: r ? r.url : `request ${p.requestId}`, error: p.errorText, type: p.type });
|
|
71
|
+
});
|
|
72
|
+
page.on('Network.loadingFinished', (p) => {
|
|
73
|
+
const r = reqs.get(p.requestId);
|
|
74
|
+
if (!r || !pageOrigin) return;
|
|
75
|
+
if (!['Document', 'Script'].includes(r.type)) return;
|
|
76
|
+
let u;
|
|
77
|
+
try { u = new URL(r.url); } catch { return; }
|
|
78
|
+
if (u.origin !== pageOrigin) return;
|
|
79
|
+
if (/\/node_modules\/|\/js\/inline3d[^/]*\.js$|@displayxr|\/vendor\/|\/dist\/|\/\.vite\/deps\//.test(u.pathname)) return;
|
|
80
|
+
log.scripts.push({ requestId: p.requestId, url: r.url, type: r.type });
|
|
81
|
+
});
|
|
82
|
+
return log;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function preparePage(conn, { fake, cfg, viewport }) {
|
|
86
|
+
const page = await conn.newPage();
|
|
87
|
+
await page.send('Page.enable');
|
|
88
|
+
await page.send('Runtime.enable');
|
|
89
|
+
await page.send('Log.enable');
|
|
90
|
+
await page.send('Network.enable');
|
|
91
|
+
await page.send('Network.setCacheDisabled', { cacheDisabled: false });
|
|
92
|
+
await page.send('Emulation.setDeviceMetricsOverride', { width: viewport.width, height: viewport.height, deviceScaleFactor: viewport.dpr, mobile: false });
|
|
93
|
+
await page.send('Emulation.setFocusEmulationEnabled', { enabled: true }).catch(() => {});
|
|
94
|
+
const src = `window.__DXR_CHECK_CFG = ${JSON.stringify(cfg)};\n${PROBE_SRC}\n${fake ? FAKE_SRC : ''}`;
|
|
95
|
+
await page.send('Page.addScriptToEvaluateOnNewDocument', { source: src });
|
|
96
|
+
return page;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function navigate(page, url, timeoutMs) {
|
|
100
|
+
const loaded = new Promise((r) => page.on('Page.loadEventFired', () => r(true)));
|
|
101
|
+
const nav = await page.send('Page.navigate', { url });
|
|
102
|
+
if (nav.errorText) throw new Error(`navigation failed: ${nav.errorText}`);
|
|
103
|
+
return withTimeout(loaded, timeoutMs, 'page load event').catch(() => false);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function screenshot(page) {
|
|
107
|
+
const { data } = await page.send('Page.captureScreenshot', { format: 'png', captureBeyondViewport: false });
|
|
108
|
+
return decodePng(Buffer.from(data, 'base64'));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function staticScan(page, log) {
|
|
112
|
+
const findings = { isSessionSupported: [], uaSniff: [], importMaps: [] };
|
|
113
|
+
for (const s of log.scripts.slice(0, 40)) {
|
|
114
|
+
let body = '';
|
|
115
|
+
try {
|
|
116
|
+
const r = await page.send('Network.getResponseBody', { requestId: s.requestId });
|
|
117
|
+
body = r.base64Encoded ? Buffer.from(r.body, 'base64').toString('utf8') : r.body;
|
|
118
|
+
} catch { continue; }
|
|
119
|
+
if (body.length > 3_000_000) continue;
|
|
120
|
+
if (/isSessionSupported\s*\(\s*['"`]inline-3d/.test(body)) findings.isSessionSupported.push(s.url);
|
|
121
|
+
if (/navigator\.(userAgent|userAgentData)/.test(body) && /displayxr/i.test(body)) findings.uaSniff.push(s.url);
|
|
122
|
+
if (s.type === 'Document') {
|
|
123
|
+
const re = /<script[^>]*type\s*=\s*["']importmap["'][^>]*>([\s\S]*?)<\/script>/gi;
|
|
124
|
+
let m;
|
|
125
|
+
while ((m = re.exec(body))) {
|
|
126
|
+
try { findings.importMaps.push({ url: s.url, imports: JSON.parse(m[1]).imports || {} }); } catch { findings.importMaps.push({ url: s.url, error: 'invalid JSON' }); }
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return findings;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ------------------------------------------------------------------------------ the fake run
|
|
134
|
+
async function fakeRun(conn, url, opt, origin) {
|
|
135
|
+
const page = await preparePage(conn, { fake: true, cfg: { maxTextureSize: opt.maxTexture || 0 }, viewport: opt.viewport });
|
|
136
|
+
const log = collect(page, origin);
|
|
137
|
+
const t0 = Date.now();
|
|
138
|
+
const loaded = await navigate(page, url, opt.loadTimeoutMs);
|
|
139
|
+
const deadline = Date.now() + opt.timeoutMs;
|
|
140
|
+
let summary = null, scrolled = 0;
|
|
141
|
+
const cssSeen = new Map(); // layer index -> union of problems over time
|
|
142
|
+
let readySince = 0;
|
|
143
|
+
while (Date.now() < deadline) {
|
|
144
|
+
await sleep(250);
|
|
145
|
+
summary = await ev(page, '__dxrCheck.summary()').catch(() => summary);
|
|
146
|
+
if (!summary) continue;
|
|
147
|
+
const open = summary.layers.filter((l) => l.open);
|
|
148
|
+
const sinceLoad = Date.now() - t0;
|
|
149
|
+
if (!summary.sessionRequests.length && sinceLoad > opt.noSessionGiveUpMs) break;
|
|
150
|
+
if (summary.sessionRequests.length && !open.length && sinceLoad > 3000 && scrolled < 6) {
|
|
151
|
+
// Lazy windows activate when they intersect the viewport: scroll the page to find them.
|
|
152
|
+
scrolled++;
|
|
153
|
+
await ev(page, `window.scrollBy(0, Math.round(innerHeight * 0.8)), window.scrollY`);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (!open.length) continue;
|
|
157
|
+
for (const l of open.slice(0, 4)) {
|
|
158
|
+
const a = await ev(page, `__dxrProbe.cssAudit(__dxrCheck.layerCanvas(${l.index}))`).catch(() => null);
|
|
159
|
+
if (!a) continue;
|
|
160
|
+
const cur = cssSeen.get(l.index) || { problems: new Map(), decorations: new Set(), animations: new Map() };
|
|
161
|
+
for (const p of a.problems) cur.problems.set(`${p.element}|${p.prop}`, p);
|
|
162
|
+
for (const d of a.decorations) cur.decorations.add(d);
|
|
163
|
+
for (const an of a.animations) cur.animations.set(`${an.element}|${an.props}`, an);
|
|
164
|
+
cssSeen.set(l.index, cur);
|
|
165
|
+
}
|
|
166
|
+
const youngest = Math.min(...open.map((l) => l.ageMs));
|
|
167
|
+
if (youngest < opt.settleMs) continue;
|
|
168
|
+
// Ready when every open layer's canvas holds something in both halves (content loaded).
|
|
169
|
+
let allDrawn = true;
|
|
170
|
+
for (const l of open.slice(0, 4)) {
|
|
171
|
+
const s = await ev(page, `__dxrCheck.snap(${l.index}, 128)`).catch(() => null);
|
|
172
|
+
if (!s || !s.sw) { allDrawn = false; break; }
|
|
173
|
+
const [L, R] = halves(fromBase64Rgba(s.rgba, s.sw, s.sh));
|
|
174
|
+
if (contentStats(L).blank || contentStats(R).blank) { allDrawn = false; break; }
|
|
175
|
+
}
|
|
176
|
+
if (allDrawn) {
|
|
177
|
+
if (!readySince) readySince = Date.now();
|
|
178
|
+
if (Date.now() - readySince >= 400) break;
|
|
179
|
+
} else readySince = 0;
|
|
180
|
+
}
|
|
181
|
+
summary = await ev(page, '__dxrCheck.summary()').catch(() => summary);
|
|
182
|
+
const layers = [];
|
|
183
|
+
for (const l of (summary ? summary.layers : []).filter((x) => x.open).slice(0, 4)) {
|
|
184
|
+
const snap = await ev(page, `__dxrCheck.snap(${l.index}, 640)`).catch((e) => ({ error: String(e) }));
|
|
185
|
+
const buffer = await ev(page, `__dxrProbe.bufferInfo(__dxrCheck.layerCanvas(${l.index}))`).catch(() => null);
|
|
186
|
+
const occlusion = await ev(page, `__dxrProbe.occlusionAudit(__dxrCheck.layerCanvas(${l.index}))`).catch(() => null);
|
|
187
|
+
const css = await ev(page, `__dxrProbe.cssAudit(__dxrCheck.layerCanvas(${l.index}))`).catch(() => null);
|
|
188
|
+
const seen = cssSeen.get(l.index);
|
|
189
|
+
if (css && seen) {
|
|
190
|
+
for (const p of css.problems) seen.problems.set(`${p.element}|${p.prop}`, p);
|
|
191
|
+
for (const d of css.decorations) seen.decorations.add(d);
|
|
192
|
+
for (const an of css.animations) seen.animations.set(`${an.element}|${an.props}`, an);
|
|
193
|
+
}
|
|
194
|
+
const cssAll = seen
|
|
195
|
+
? { problems: [...seen.problems.values()], decorations: [...seen.decorations], animations: [...seen.animations.values()] }
|
|
196
|
+
: css || { problems: [], decorations: [], animations: [] };
|
|
197
|
+
layers.push({ ...l, snap, buffer, occlusion, css: cssAll });
|
|
198
|
+
}
|
|
199
|
+
const shaderErrors = await ev(page, '__dxrProbe.shaderErrors').catch(() => []);
|
|
200
|
+
const scrollY = await ev(page, 'window.scrollY').catch(() => 0);
|
|
201
|
+
const media = await ev(page, `__dxrProbe.mediaElements(__dxrCheck.layers.filter(r => !r.layer.closed).map(r => r.canvas))`).catch(() => []);
|
|
202
|
+
let shot = null;
|
|
203
|
+
try { shot = await screenshot(page); } catch { /* none */ }
|
|
204
|
+
const statics = await staticScan(page, log);
|
|
205
|
+
const scroll = opt.noScroll ? null : await scrollSweep(page, layers).catch((e) => ({ error: String(e) }));
|
|
206
|
+
const loss = opt.noLoss ? null : await layerLossProbe(page, layers).catch((e) => ({ error: String(e) }));
|
|
207
|
+
await page.close();
|
|
208
|
+
return { loaded, summary, layers, log, shaderErrors, media, shot, scrollY, scrolled, statics, scroll, loss, ms: Date.now() - t0 };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Scroll the whole page past each woven canvas and audit what sits over it at every step: a
|
|
212
|
+
// sticky header that only reaches the tile once the page scrolls is invisible to the end-of-run
|
|
213
|
+
// audit. Restores the scroll position.
|
|
214
|
+
async function scrollSweep(page, layers) {
|
|
215
|
+
if (!layers.length) return { steps: 0, layers: [] };
|
|
216
|
+
const y0 = await ev(page, 'window.scrollY');
|
|
217
|
+
const max = await ev(page, 'Math.max(0, document.documentElement.scrollHeight - innerHeight)');
|
|
218
|
+
const vh = await ev(page, 'innerHeight');
|
|
219
|
+
const step = Math.max(40, Math.round(vh * 0.25));
|
|
220
|
+
const ys = [];
|
|
221
|
+
for (let y = 0; y <= max && ys.length < 16; y += step) ys.push(y);
|
|
222
|
+
if (max > 0 && ys[ys.length - 1] !== max) ys.push(max);
|
|
223
|
+
const per = layers.map((l) => ({ selector: l.selector, maxCovered: 0, maxCoveredAt: null, maxFrost: 0, coverers: new Map(), effects: new Map(), samples: 0 }));
|
|
224
|
+
for (const y of ys) {
|
|
225
|
+
await ev(page, `window.scrollTo(0, ${y})`);
|
|
226
|
+
await sleep(60);
|
|
227
|
+
for (let i = 0; i < layers.length; i++) {
|
|
228
|
+
const a = await ev(page, `__dxrProbe.occlusionAudit(__dxrCheck.layerCanvas(${layers[i].index}), 7, 5)`).catch(() => null);
|
|
229
|
+
if (!a || !a.visible || !a.total || a.total < 0.5 * 35) continue; // mostly off screen: not judged here
|
|
230
|
+
const r = per[i];
|
|
231
|
+
r.samples++;
|
|
232
|
+
if (a.coveredFraction > r.maxCovered) { r.maxCovered = a.coveredFraction; r.maxCoveredAt = y; }
|
|
233
|
+
if (a.frostFraction > r.maxFrost) { r.maxFrost = a.frostFraction; r.maxFrostAt = y; }
|
|
234
|
+
for (const c of a.coverers) r.coverers.set(c.selector, Math.max(r.coverers.get(c.selector) || 0, c.hits));
|
|
235
|
+
for (const e of a.effects || []) r.effects.set(e.selector, e.props);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
await ev(page, `window.scrollTo(0, ${y0})`);
|
|
239
|
+
await sleep(100);
|
|
240
|
+
return {
|
|
241
|
+
steps: ys.length,
|
|
242
|
+
layers: per.map((r) => ({ ...r, coverers: [...r.coverers.keys()], effects: [...r.effects.entries()].map(([selector, props]) => ({ selector, props })) })),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// End the inline-3D session (as the browser does when the weave goes away) and look at what each
|
|
247
|
+
// woven canvas shows a second later: an addScene page whose onLayerLost does nothing is left
|
|
248
|
+
// showing its last side-by-side pair, unwoven.
|
|
249
|
+
async function layerLossProbe(page, layers) {
|
|
250
|
+
if (!layers.length) return null;
|
|
251
|
+
// Before: each canvas in view, as the woven run left it (its side-by-side pair).
|
|
252
|
+
const rectOf = (i) => ev(page, `(() => { const c = __dxrCheck.layerCanvas(${i}); if (!c) return null; c.scrollIntoView({ block: 'center', inline: 'center' }); const cs = getComputedStyle(c); const r = c.getBoundingClientRect(); return { x: r.left, y: r.top, width: r.width, height: r.height, shown: cs.display !== 'none' && cs.visibility !== 'hidden' && r.width > 0 && r.height > 0 }; })()`).catch(() => null);
|
|
253
|
+
const grab = async (rect) => { try { const shot = await screenshot(page); return regionOf(shot, rect); } catch { return null; } };
|
|
254
|
+
const before = [];
|
|
255
|
+
for (const l of layers.slice(0, 4)) {
|
|
256
|
+
const rect = await rectOf(l.index);
|
|
257
|
+
await sleep(150);
|
|
258
|
+
before.push(rect && rect.shown ? { rect, reg: await grab(rect) } : null);
|
|
259
|
+
}
|
|
260
|
+
const n = await ev(page, '__dxrCheck.endSessions()');
|
|
261
|
+
if (!n) return { ended: 0, layers: [] };
|
|
262
|
+
await sleep(1200);
|
|
263
|
+
const out = [];
|
|
264
|
+
for (let i = 0; i < before.length; i++) {
|
|
265
|
+
const l = layers[i], b = before[i];
|
|
266
|
+
if (!b || !b.reg) { out.push({ selector: l.selector, shown: !!b, measured: false }); continue; }
|
|
267
|
+
const rect = await rectOf(l.index);
|
|
268
|
+
if (!rect || !rect.shown) { out.push({ selector: l.selector, shown: false }); continue; }
|
|
269
|
+
await sleep(250);
|
|
270
|
+
const reg = await grab(rect);
|
|
271
|
+
if (!reg) { out.push({ selector: l.selector, shown: true, measured: false }); continue; }
|
|
272
|
+
const diff = regionDiff(b.reg, reg);
|
|
273
|
+
const st = contentStats(reg);
|
|
274
|
+
// Unchanged since the woven run = still the side-by-side pair (nothing went flat). A mono view
|
|
275
|
+
// (one picture across the canvas) or a 2D fallback differs from it by far more than this.
|
|
276
|
+
const frozen = diff < 2.5 && !contentStats(b.reg).blank;
|
|
277
|
+
out.push({ selector: l.selector, shown: true, measured: true, sbs: frozen || sbsPairVerdict(reg).sbs, frozen, diff: +diff.toFixed(2), blank: st.blank });
|
|
278
|
+
}
|
|
279
|
+
return { ended: n, layers: out };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// ------------------------------------------------------------------------------ the plain run
|
|
283
|
+
async function plainRun(conn, url, opt, fake, origin) {
|
|
284
|
+
const page = await preparePage(conn, { fake: false, cfg: {}, viewport: opt.viewport });
|
|
285
|
+
const log = collect(page, origin);
|
|
286
|
+
const t0 = Date.now();
|
|
287
|
+
const loaded = await navigate(page, url, opt.loadTimeoutMs);
|
|
288
|
+
const selectors = fake.layers.map((l) => l.selector);
|
|
289
|
+
// Judge each canvas that wove in the 3D run IN VIEW (a lazy page only renders what is on
|
|
290
|
+
// screen), waiting until it shows something or the budget runs out.
|
|
291
|
+
const deadline = Date.now() + opt.plainTimeoutMs;
|
|
292
|
+
const regions = [];
|
|
293
|
+
let shot = null;
|
|
294
|
+
await sleep(600);
|
|
295
|
+
const measure = (s) => ev(page, `(() => { const el = document.querySelector(${JSON.stringify(s)}); if (!el) return { selector: ${JSON.stringify(s)}, missing: true }; const cs = getComputedStyle(el); let r = el.getBoundingClientRect(); if (r.top < 0 || r.bottom > innerHeight || r.left < 0 || r.right > innerWidth) { el.scrollIntoView({ block: 'center', inline: 'center' }); r = el.getBoundingClientRect(); } return { selector: ${JSON.stringify(s)}, rect: { x: r.left, y: r.top, width: r.width, height: r.height }, visible: cs.display !== 'none' && cs.visibility !== 'hidden' && parseFloat(cs.opacity) > 0 && r.width > 0 && r.height > 0 }; })()`).catch(() => ({ selector: s, missing: true }));
|
|
296
|
+
for (const s of selectors) {
|
|
297
|
+
let m = await measure(s);
|
|
298
|
+
while (!m.missing && m.visible) {
|
|
299
|
+
try { shot = await screenshot(page); } catch { shot = null; break; }
|
|
300
|
+
m.stats = regionStats(shot, m.rect);
|
|
301
|
+
const reg = regionOf(shot, m.rect);
|
|
302
|
+
m.sbs = reg ? sbsPairVerdict(reg).sbs : false;
|
|
303
|
+
if (!m.stats.blank || Date.now() > deadline) break;
|
|
304
|
+
await sleep(400);
|
|
305
|
+
m = { ...(await measure(s)) };
|
|
306
|
+
}
|
|
307
|
+
regions.push(m);
|
|
308
|
+
}
|
|
309
|
+
if (!selectors.length) await sleep(1500);
|
|
310
|
+
if (fake.scrollY !== undefined) await ev(page, `window.scrollTo(0, ${fake.scrollY || 0})`).catch(() => {});
|
|
311
|
+
await sleep(150);
|
|
312
|
+
try { shot = await screenshot(page); } catch { /* keep */ }
|
|
313
|
+
const media = await ev(page, `__dxrProbe.mediaElements([])`).catch(() => []);
|
|
314
|
+
const shaderErrors = await ev(page, '__dxrProbe.shaderErrors').catch(() => []);
|
|
315
|
+
const sessionAttempt = await ev(page, `!!navigator.xr`).catch(() => null);
|
|
316
|
+
await page.close();
|
|
317
|
+
return { loaded, regions, media, shot, log, shaderErrors, hasXR: sessionAttempt, ms: Date.now() - t0 };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function regionOf(shot, rect) {
|
|
321
|
+
const x = Math.max(0, rect.x), y = Math.max(0, rect.y);
|
|
322
|
+
const w = Math.min(shot.width, rect.x + rect.width) - x, h = Math.min(shot.height, rect.y + rect.height) - y;
|
|
323
|
+
if (w < 4 || h < 4) return null;
|
|
324
|
+
return crop(shot, x, y, w, h);
|
|
325
|
+
}
|
|
326
|
+
function regionStats(shot, rect) {
|
|
327
|
+
const r = rect && regionOf(shot, rect);
|
|
328
|
+
return r ? contentStats(r) : { blank: true, contentFraction: 0 };
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// ------------------------------------------------------------------------------ log classification
|
|
332
|
+
const GL_RE = /GL_INVALID|WebGL: INVALID|WebGL: CONTEXT_LOST|WebGL: too many errors|GL ERROR|Shader Error|Failed to compile|could not compile|ERROR: 0:\d+|program not valid|WebGLProgram|link failed/i;
|
|
333
|
+
function classify(log, shaderErrors) {
|
|
334
|
+
const ignoreUrl = (u) => /favicon\.ico/.test(u || '');
|
|
335
|
+
const errors = [], gl = [], warnings = [], sdkWarnings = [];
|
|
336
|
+
for (const c of log.console) {
|
|
337
|
+
if (GL_RE.test(c.text)) { gl.push(c.text); continue; }
|
|
338
|
+
if (c.type === 'error' || c.type === 'assert') errors.push(`console.error: ${c.text}`);
|
|
339
|
+
else if (c.type === 'warning') {
|
|
340
|
+
if (/^\[inline3d\]/.test(c.text)) sdkWarnings.push(c.text);
|
|
341
|
+
else warnings.push(c.text);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
for (const e of log.exceptions) errors.push(`uncaught: ${e.text}${e.at ? ` (${e.at})` : ''}`);
|
|
345
|
+
for (const e of log.logEntries) {
|
|
346
|
+
if (GL_RE.test(e.text)) { gl.push(e.text); continue; }
|
|
347
|
+
if (e.level === 'error' && !ignoreUrl(e.url) && e.source !== 'network') errors.push(`${e.source}: ${e.text}`);
|
|
348
|
+
}
|
|
349
|
+
for (const n of log.network) {
|
|
350
|
+
if (ignoreUrl(n.url)) continue;
|
|
351
|
+
errors.push(n.status ? `HTTP ${n.status} ${n.url}` : `request failed (${n.error}) ${n.url}`);
|
|
352
|
+
}
|
|
353
|
+
for (const s of shaderErrors || []) gl.push(s);
|
|
354
|
+
return { errors: dedupe(errors), gl: dedupe(gl), warnings: dedupe(warnings), sdkWarnings: dedupe(sdkWarnings) };
|
|
355
|
+
}
|
|
356
|
+
const dedupe = (a) => [...new Set(a)].slice(0, 25);
|
|
357
|
+
|
|
358
|
+
// ------------------------------------------------------------------------------ checks
|
|
359
|
+
function check(id, letter, title, status, summary, extra = {}) {
|
|
360
|
+
return { id, letter, title, status, summary, ...extra };
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function buildChecks(fake, plain, opt) {
|
|
364
|
+
const checks = [];
|
|
365
|
+
const S = fake.summary || { sessionRequests: [], layers: [], maxLiveSessions: 0, framesWithViews: 0, isSessionSupportedCalls: [], activeModeIndex: 1 };
|
|
366
|
+
const okSessions = S.sessionRequests.filter((r) => r.ok && r.mode === 'inline-3d');
|
|
367
|
+
const open = fake.layers;
|
|
368
|
+
const primary = open[0] || null;
|
|
369
|
+
|
|
370
|
+
// per-layer pixel analysis
|
|
371
|
+
for (const l of open) {
|
|
372
|
+
const s = l.snap;
|
|
373
|
+
if (!s || !s.sw || s.error) { l.px = null; continue; }
|
|
374
|
+
const buf = fromBase64Rgba(s.rgba, s.sw, s.sh);
|
|
375
|
+
const [L, R] = halves(buf);
|
|
376
|
+
const statsL = contentStats(L), statsR = contentStats(R);
|
|
377
|
+
const fw = flatWideVerdict(buf);
|
|
378
|
+
const blocks = !statsL.blank && !statsR.blank && !fw.cmp.identical ? blockDisparity(L, R) : [];
|
|
379
|
+
l.px = { statsL, statsR, cmp: fw.cmp, flatWide: fw.flatWide, sameScene: fw.sameScene, seam: fw.seam, matchRatio: fw.matchRatio, blocks, eyeW: L.width };
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// (a) session
|
|
383
|
+
{
|
|
384
|
+
let status = 'pass', summary;
|
|
385
|
+
if (!okSessions.length) {
|
|
386
|
+
status = 'fail';
|
|
387
|
+
summary = S.sessionRequests.length
|
|
388
|
+
? `requested ${S.sessionRequests.map((r) => r.mode).join(', ')}, never 'inline-3d'`
|
|
389
|
+
: 'the page never requested an inline-3d session (createInline3D() was not called, or ran after an error)';
|
|
390
|
+
} else if (!open.length) {
|
|
391
|
+
status = 'fail';
|
|
392
|
+
summary = S.layers.length
|
|
393
|
+
? 'a layer was created but none was still open at the end (closed, removed, or the session ended)'
|
|
394
|
+
: 'a session started but no canvas was registered (no addImage/addVideo/addScene/addModel/addSplat/addPlayer, or a lazy tile that never entered the viewport)';
|
|
395
|
+
} else if (!primary.px) {
|
|
396
|
+
status = 'fail';
|
|
397
|
+
summary = 'could not read the woven canvas back';
|
|
398
|
+
} else if (primary.px.statsL.blank && primary.px.statsR.blank) {
|
|
399
|
+
status = 'fail';
|
|
400
|
+
summary = `session + ${open.length} layer(s), ${S.framesWithViews} frames with views, but the canvas stayed empty`;
|
|
401
|
+
} else {
|
|
402
|
+
summary = `inline-3d session, ${open.length} open layer(s) (${open.map((l) => l.selector).join(', ')}), ${S.framesWithViews} frames with two views`;
|
|
403
|
+
}
|
|
404
|
+
checks.push(check('session', 'a', 'Reached a 3D session and drew into the woven canvas', status, summary, {
|
|
405
|
+
details: { sessions: S.sessionRequests, layers: S.layers.map((l) => ({ selector: l.selector, open: l.open, ageMs: Math.round(l.ageMs) })), scrolledToFind: fake.scrolled },
|
|
406
|
+
hint: status === 'fail' ? 'Detect with createInline3D() and branch on wall.supported; register the canvas with one add*() call. A lazy tile (the default) only gets a layer once it is on screen.' : undefined,
|
|
407
|
+
doc: `${DOCS}/authoring-inline-3d.md`,
|
|
408
|
+
}));
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// (b) stereo
|
|
412
|
+
{
|
|
413
|
+
let status = 'skip', summary = 'no woven canvas to inspect';
|
|
414
|
+
const details = [];
|
|
415
|
+
const flatRequested = S.activeModeIndex === 0 || (primary && primary.rig && primary.rig.ipdFactor === 0);
|
|
416
|
+
for (const l of open) {
|
|
417
|
+
if (!l.px) continue;
|
|
418
|
+
const { cmp, blocks, sameScene } = l.px;
|
|
419
|
+
const ds = blocks.map((b) => b.d);
|
|
420
|
+
const range = ds.length >= 3 ? quantile(ds, 0.95) - quantile(ds, 0.05) : 0;
|
|
421
|
+
details.push({ selector: l.selector, identical: cmp.identical, differingFraction: +cmp.differingFraction.toFixed(4), bestShiftPx: cmp.bestShift, madBest: +cmp.madBest.toFixed(2), baseline: +cmp.baseline.toFixed(2), disparityRangePx: +range.toFixed(2), blocks: blocks.length, blockMatchRatio: +l.px.matchRatio.toFixed(2), seamRatio: +l.px.seam.ratio.toFixed(2), sameScene });
|
|
422
|
+
}
|
|
423
|
+
const d0 = details[0];
|
|
424
|
+
if (d0) {
|
|
425
|
+
if (flatRequested) { status = 'warn'; summary = 'the page switched the display to 2D (setStereoEnabled(false) / a zero-ipd rig): eyes are expected to match'; }
|
|
426
|
+
else if (open[0].px.statsL.blank || open[0].px.statsR.blank) { status = 'skip'; summary = 'an eye is blank (see eyes-not-blank)'; }
|
|
427
|
+
else if (d0.identical) { status = 'fail'; summary = 'left and right eyes are the SAME picture: a duplicated flat image, not stereo'; }
|
|
428
|
+
else if (!d0.sameScene) { status = 'fail'; summary = 'the two halves are not two views of one scene (see no-flat-sbs)'; }
|
|
429
|
+
else if (d0.blocks >= 3 && d0.disparityRangePx < 0.25) { status = 'warn'; summary = `eyes differ only by a uniform shift (${d0.bestShiftPx}px): the content is flat, at a single depth`; }
|
|
430
|
+
else { status = 'pass'; summary = `eyes differ (${(d0.differingFraction * 100).toFixed(1)}% of pixels), disparity range ${d0.disparityRangePx}px across ${d0.blocks} matched blocks`; }
|
|
431
|
+
}
|
|
432
|
+
checks.push(check('stereo', 'b', 'Left and right eyes differ (real stereo)', status, summary, {
|
|
433
|
+
details,
|
|
434
|
+
hint: status === 'fail' ? 'Render each view with its own projectionMatrix and transform.matrix into layer.getViewport(view) (EyeCamera.setFromView in ./three). Never draw one mono camera into both halves.' : undefined,
|
|
435
|
+
doc: `${DOCS}/authoring-inline-3d.md#3-live-scene-threejs--webgl--addscenecanvas-onframe-opts`,
|
|
436
|
+
}));
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// (c) eyes not blank
|
|
440
|
+
{
|
|
441
|
+
let status = 'skip', summary = 'no woven canvas to inspect';
|
|
442
|
+
const details = [];
|
|
443
|
+
for (const l of open) {
|
|
444
|
+
if (!l.px) continue;
|
|
445
|
+
const f = (st) => ({ blank: st.blank, black: !!st.black, transparent: !!st.transparent, contentPct: +(st.contentFraction * 100).toFixed(2), meanLum: +st.meanLum.toFixed(1) });
|
|
446
|
+
details.push({ selector: l.selector, left: f(l.px.statsL), right: f(l.px.statsR) });
|
|
447
|
+
}
|
|
448
|
+
if (details.length) {
|
|
449
|
+
const bad = details.filter((d) => d.left.blank || d.right.blank);
|
|
450
|
+
status = bad.length ? 'fail' : 'pass';
|
|
451
|
+
summary = bad.length
|
|
452
|
+
? bad.map((d) => `${d.selector}: ${d.left.blank ? `left eye ${d.left.black ? 'black' : d.left.transparent ? 'empty/transparent' : 'flat-filled'}` : ''}${d.left.blank && d.right.blank ? ', ' : ''}${d.right.blank ? `right eye ${d.right.black ? 'black' : d.right.transparent ? 'empty/transparent' : 'flat-filled'}` : ''}`).join('; ')
|
|
453
|
+
: `both eyes hold content in ${details.length} canvas(es)`;
|
|
454
|
+
}
|
|
455
|
+
checks.push(check('eyes-not-blank', 'c', 'Neither eye is black or blank', status, summary, {
|
|
456
|
+
details,
|
|
457
|
+
hint: status === 'fail' ? 'Validate before you clear: skip the clear when views.length < 2 or a viewport is null, and repaint the last good frame. Check the asset loaded, the camera faces the subject, and that pixelRatio is 1 when you use getViewport().' : undefined,
|
|
458
|
+
doc: `${DOCS}/authoring-inline-3d.md`,
|
|
459
|
+
}));
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// (d) no raw side-by-side shown flat, no full-width flat picture in a woven canvas
|
|
463
|
+
{
|
|
464
|
+
const fails = [], warns = [];
|
|
465
|
+
for (const l of open) {
|
|
466
|
+
if (l.px && l.px.flatWide) fails.push(`${l.selector}: one full-width flat picture is drawn into the woven canvas (the halves run on across the middle), so each eye sees a different half`);
|
|
467
|
+
if (l.joinSamples >= 3 && l.joinExposed / l.joinSamples > 0.3) warns.push(`${l.selector}: uncovered and holding pixels during the join window (${l.joinExposed}/${l.joinSamples} samples in the first 1.2 s): the browser may flash the raw side-by-side pair. Cover it until handle.firstWoven.`);
|
|
468
|
+
}
|
|
469
|
+
if (fake.shot) {
|
|
470
|
+
for (const m of fake.media) {
|
|
471
|
+
const r = regionOf(fake.shot, m.rect);
|
|
472
|
+
if (r && sbsPairVerdict(r).sbs) fails.push(`${m.selector} (${m.tag}, not woven) shows a raw side-by-side pair flat in the 3D run`);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
if (plain && plain.shot) {
|
|
476
|
+
const seen = new Set();
|
|
477
|
+
for (const r of plain.regions || []) {
|
|
478
|
+
if (r.missing || !r.visible) continue;
|
|
479
|
+
if (r.sbs) { fails.push(`${r.selector} shows a raw side-by-side pair flat in the plain (2D) browser`); seen.add(r.selector); }
|
|
480
|
+
}
|
|
481
|
+
for (const m of plain.media) {
|
|
482
|
+
if (seen.has(m.selector)) continue;
|
|
483
|
+
const reg = regionOf(plain.shot, m.rect);
|
|
484
|
+
if (reg && sbsPairVerdict(reg).sbs) fails.push(`${m.selector} (${m.tag}) shows a raw side-by-side pair flat in the plain (2D) browser`);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
const status = fails.length ? 'fail' : warns.length ? 'warn' : open.length || (plain && plain.shot) ? 'pass' : 'skip';
|
|
488
|
+
checks.push(check('no-flat-sbs', 'd', 'No raw side-by-side shown flat; no full-width flat image in a woven canvas', status,
|
|
489
|
+
fails[0] || warns[0] || 'no flat side-by-side pair and no full-width picture in a woven canvas', {
|
|
490
|
+
details: { fails, warns },
|
|
491
|
+
hint: fails.length ? 'In 2D, show ONE eye (the left half) or a mono render, never the packed pair. In 3D, draw a flat picture into each eye viewport (or call setStereoEnabled(false)), never across the whole canvas.' : warns.length ? 'Stack an opaque cover over the canvas and remove it (hard cut) on await handle.firstWoven, plus a timeout and a catch so it always comes off.' : undefined,
|
|
492
|
+
doc: `${DOCS}/woven-canvas-rules.md`,
|
|
493
|
+
}));
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// (e) buffer not clamped
|
|
497
|
+
{
|
|
498
|
+
const fails = [], warns = [], details = [];
|
|
499
|
+
for (const l of open) {
|
|
500
|
+
const b = l.buffer;
|
|
501
|
+
if (!b) continue;
|
|
502
|
+
const limit = opt.maxTexture || b.maxTextureSize || 16384;
|
|
503
|
+
details.push({ selector: l.selector, ...b, limit });
|
|
504
|
+
if (b.drawingBufferWidth != null && (b.drawingBufferWidth < b.width || b.drawingBufferHeight < b.height)) {
|
|
505
|
+
fails.push(`${l.selector}: canvas is ${b.width}x${b.height} but the drawing buffer is ${b.drawingBufferWidth}x${b.drawingBufferHeight}: the browser clamped it, and getViewport() (which splits canvas.width) puts the eye boundary off-centre`);
|
|
506
|
+
} else if (Math.max(b.width, b.height) > limit) {
|
|
507
|
+
fails.push(`${l.selector}: canvas ${b.width}x${b.height} exceeds the ${limit} texture limit`);
|
|
508
|
+
} else if (!opt.maxTexture && Math.max(b.width, b.height) > 4096) {
|
|
509
|
+
warns.push(`${l.selector}: canvas ${b.width}x${b.height} would be clamped on a tablet with MAX_TEXTURE_SIZE 4096 (rerun with --max-texture 4096)`);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
const status = fails.length ? 'fail' : warns.length ? 'warn' : details.length ? 'pass' : 'skip';
|
|
513
|
+
checks.push(check('buffer', 'e', `Drawing buffer not clamped${opt.maxTexture ? ` (simulated MAX_TEXTURE_SIZE ${opt.maxTexture})` : ''}`, status,
|
|
514
|
+
fails[0] || warns[0] || (details.length ? details.map((d) => `${d.selector} ${d.width}x${d.height}${d.drawingBufferWidth != null ? ` (buffer ${d.drawingBufferWidth}x${d.drawingBufferHeight})` : ''}`).join('; ') : 'no woven canvas'), {
|
|
515
|
+
details,
|
|
516
|
+
hint: fails.length || warns.length ? 'Cap devicePixelRatio at 2, keep width = 2 x eye width and both sides within min(MAX_TEXTURE_SIZE, MAX_RENDERBUFFER_SIZE, MAX_VIEWPORT_DIMS), and draw into gl.drawingBufferWidth/Height. ./viewer, ./model, ./splat, addImage and addVideo clamp for you.' : undefined,
|
|
517
|
+
doc: `${DOCS}/woven-canvas-rules.md#5-pitfalls-from-production-september-2026`,
|
|
518
|
+
}));
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// (f1) CSS on the woven canvas and its ancestors
|
|
522
|
+
{
|
|
523
|
+
const problems = [], decorations = [], animations = [];
|
|
524
|
+
for (const l of open) {
|
|
525
|
+
for (const p of l.css.problems) problems.push(`${l.selector}: ${p.text}`);
|
|
526
|
+
for (const d of l.css.decorations) decorations.push(`${l.selector}: ${d} on the canvas`);
|
|
527
|
+
for (const a of l.css.animations) animations.push(`${l.selector}: ${a.element} animates ${a.props.join(', ')}`);
|
|
528
|
+
}
|
|
529
|
+
const status = problems.length ? 'fail' : decorations.length || animations.length ? 'warn' : open.length ? 'pass' : 'skip';
|
|
530
|
+
checks.push(check('css', 'f', 'No CSS transform/filter/opacity/mask/blend on the woven canvas or its ancestors', status,
|
|
531
|
+
problems[0] || decorations[0] || animations[0] || 'no render-surface CSS on the canvas or its ancestors', {
|
|
532
|
+
details: { problems: dedupe(problems), decorations: dedupe(decorations), animations: dedupe(animations) },
|
|
533
|
+
hint: status !== 'pass' && status !== 'skip' ? 'Remove filter, opacity < 1, mask, clip-path, mix-blend-mode, backdrop-filter and non-translate transforms from the canvas and every ancestor; do rounded corners with cornerRadius, soft edges with feather, everything else inside the canvas per eye. Don\'t animate the tile\'s box.' : undefined,
|
|
534
|
+
doc: `${DOCS}/woven-canvas-rules.md#7-no-css-effects-on-a-woven-canvas-or-on-any-of-its-ancestors`,
|
|
535
|
+
}));
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// (f2) one session; no double registration; no overlapping woven canvases
|
|
539
|
+
{
|
|
540
|
+
const fails = [], warns = [];
|
|
541
|
+
if (S.maxLiveSessions > 1) fails.push(`${S.maxLiveSessions} inline-3d sessions were live at once: call createInline3D() once per document (the managers overwrite each other's rect list every frame)`);
|
|
542
|
+
else if (okSessions.length > 1) warns.push(`${okSessions.length} sessions were created one after another (close() the old one first, or keep one manager for the document)`);
|
|
543
|
+
for (const l of S.layers) if (l.sameCanvasLiveAtCreate > 0) warns.push(`${l.selector} was registered again while its first layer was live (add*() on the same canvas is not a content swap: remove() first)`);
|
|
544
|
+
for (let i = 0; i < open.length; i++) for (let j = i + 1; j < open.length; j++) {
|
|
545
|
+
const a = open[i].occlusion && open[i].occlusion.rect, b = open[j].occlusion && open[j].occlusion.rect;
|
|
546
|
+
if (!a || !b || !open[i].occlusion.visible || !open[j].occlusion.visible) continue;
|
|
547
|
+
const ix = Math.max(0, Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x));
|
|
548
|
+
const iy = Math.max(0, Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y));
|
|
549
|
+
if (ix * iy > 0.02 * Math.min(a.width * a.height, b.width * b.height)) fails.push(`woven canvases ${open[i].selector} and ${open[j].selector} overlap: hide the one underneath (display:none) while the other shows`);
|
|
550
|
+
}
|
|
551
|
+
const status = fails.length ? 'fail' : warns.length ? 'warn' : okSessions.length ? 'pass' : 'skip';
|
|
552
|
+
checks.push(check('single-session', 'f', 'One createInline3D session; no double registration or overlapping woven canvases', status,
|
|
553
|
+
fails[0] || warns[0] || `${okSessions.length} session, ${S.layers.length} layer(s)`, {
|
|
554
|
+
details: { sessions: okSessions.length, maxLive: S.maxLiveSessions, fails, warns },
|
|
555
|
+
doc: `${DOCS}/woven-canvas-rules.md#1-one-inline-3d-session-per-document`,
|
|
556
|
+
}));
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// (f3) opaque element over the canvas / a cover that never comes off
|
|
560
|
+
{
|
|
561
|
+
const fails = [], warns = [], details = [];
|
|
562
|
+
for (const l of open) {
|
|
563
|
+
const o = l.occlusion;
|
|
564
|
+
if (!o) continue;
|
|
565
|
+
details.push({ selector: l.selector, visible: o.visible, coveredPct: Math.round(o.coveredFraction * 100), frostPct: Math.round(o.frostFraction * 100), coverers: o.coverers.slice(0, 3), coveredAtCreatePct: l.coverAtCreate && l.coverAtCreate.total ? Math.round(l.coverAtCreate.coveredFraction * 100) : null });
|
|
566
|
+
if (!o.visible) { fails.push(`${l.selector} is not visible at the end of the run (display:none, visibility:hidden or zero size)`); continue; }
|
|
567
|
+
if (!o.total) continue; // off screen
|
|
568
|
+
const top = o.coverers[0] && o.coverers[0].selector;
|
|
569
|
+
const createTop = l.coverAtCreate && l.coverAtCreate.coverers && l.coverAtCreate.coverers[0] && l.coverAtCreate.coverers[0].selector;
|
|
570
|
+
// Sticky/fixed page chrome over part of a tile is fine (draw-order occlusion), and a tile
|
|
571
|
+
// that is mostly scrolled off screen cannot be judged by its visible sliver: the scroll
|
|
572
|
+
// sweep below covers both. What fails here is something else painted over most of the tile.
|
|
573
|
+
if (o.onScreenFraction !== undefined && o.onScreenFraction < 0.5 && !(createTop && createTop === top)) continue;
|
|
574
|
+
if (o.coveredFraction - (o.chromeFraction || 0) >= 0.5 || (createTop && createTop === top && o.coveredFraction >= 0.5)) {
|
|
575
|
+
if (createTop && createTop === top) fails.push(`${l.selector}: the cover ${top} that was over the canvas when it was registered is still there ${Math.round(l.ageMs / 100) / 10}s later (it never came off: remove it on handle.firstWoven, plus a timeout and a catch)`);
|
|
576
|
+
else fails.push(`${l.selector}: ${Math.round(o.coveredFraction * 100)}% of the canvas is under an opaque element (${top}): nothing with a background may sit above a woven canvas; put backdrops under it`);
|
|
577
|
+
}
|
|
578
|
+
// Partial chrome over a tile (a sticky header, a buy card, a caption) is fine on a
|
|
579
|
+
// draw-order browser, opaque or translucent: it occludes that part as 2D. Not judged.
|
|
580
|
+
if (o.frostFraction >= 0.9) warns.push(`${l.selector}: a backdrop-filter covers the whole tile, so the whole tile goes mono; frost only a partial region`);
|
|
581
|
+
}
|
|
582
|
+
// The scroll sweep: what sits over each tile at ANY scroll position (sticky chrome reaches a
|
|
583
|
+
// tile only once the page scrolls).
|
|
584
|
+
const sweep = fake.scroll && fake.scroll.layers ? fake.scroll.layers : [];
|
|
585
|
+
for (const r of sweep) {
|
|
586
|
+
for (const e of r.effects) warns.push(`${r.selector}: ${e.selector} passes over the tile while scrolling with ${e.props}: a pixel-moving filter, blend mode or 3D context cannot be lifted over the weave as 2D, so the tile weaves through it. Use a plain background (opaque or translucent), or a partial backdrop-filter on DisplayXR Browser 0.1.16+`);
|
|
587
|
+
if (r.maxFrost >= 0.9) warns.push(`${r.selector}: at scroll ${r.maxFrostAt ?? '?'} a backdrop-filter covers the whole tile (the whole tile goes mono); frost only a partial region`);
|
|
588
|
+
if (r.maxCovered >= 0.9 && r.samples > 1) warns.push(`${r.selector}: at scroll ${r.maxCoveredAt}px ${Math.round(r.maxCovered * 100)}% of the tile is under ${r.coverers[0] || 'an opaque element'}: a tall sticky panel or a later section painted over the canvas hides the tile while it keeps rendering`);
|
|
589
|
+
}
|
|
590
|
+
if (sweep.length) details.push({ scrollSweep: { steps: fake.scroll.steps, layers: sweep.map((r) => ({ selector: r.selector, maxCoveredPct: Math.round(r.maxCovered * 100), maxFrostPct: Math.round(r.maxFrost * 100), coverers: r.coverers.slice(0, 4), effects: r.effects })) } });
|
|
591
|
+
const status = fails.length ? 'fail' : warns.length ? 'warn' : details.length ? 'pass' : 'skip';
|
|
592
|
+
checks.push(check('overlay', 'f', 'No opaque element over the 3D canvas; the firstWoven cover comes off', status,
|
|
593
|
+
fails[0] || warns[0] || (details.length ? 'canvas uncovered at the end of the run' : 'no woven canvas'), {
|
|
594
|
+
details,
|
|
595
|
+
doc: `${DOCS}/woven-canvas-rules.md#9-nothing-with-a-background-sits-above-the-woven-canvas-black-goes-under-it`,
|
|
596
|
+
}));
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// (f4) layer loss: after the session ends, no tile may be left showing its side-by-side pair
|
|
600
|
+
{
|
|
601
|
+
const L = fake.loss;
|
|
602
|
+
const fails = [], warns = [];
|
|
603
|
+
if (L && L.layers) {
|
|
604
|
+
for (const r of L.layers) {
|
|
605
|
+
if (!r.shown || !r.measured) continue;
|
|
606
|
+
if (r.sbs) fails.push(`${r.selector}: after the inline-3D session ended, the canvas still shows its side-by-side pair (unwoven, two half-width copies). An addScene page must pass onLayerLost and draw ONE mono view across the canvas there (or hide it behind a 2D fallback); an empty onLayerLost is the same as none`);
|
|
607
|
+
else if (r.blank) warns.push(`${r.selector}: after the inline-3D session ended, the canvas is empty: draw a mono view in onLayerLost (or show a 2D fallback)`);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
const status = !L || L.error || !L.ended ? 'skip' : fails.length ? 'fail' : warns.length ? 'warn' : 'pass';
|
|
611
|
+
checks.push(check('layer-lost', 'f', 'When the 3D layer goes away, the page goes flat (onLayerLost), not a raw pair', status,
|
|
612
|
+
fails[0] || warns[0] || (status === 'skip' ? (L && L.error ? `probe failed: ${L.error}` : 'no session to end') : `${L.layers.filter((r) => r.measured).length} canvas(es) went flat after the session ended`), {
|
|
613
|
+
details: L,
|
|
614
|
+
hint: fails.length || warns.length ? 'wall.addScene(canvas, onFrame, { onLayerLost: () => startMonoLoop() }): render one camera across the whole canvas on your own requestAnimationFrame, the same path as !wall.supported. SceneViewer: onLayerLost: viewer.onLayerLost. ./splat and ./model do this for you.' : undefined,
|
|
615
|
+
doc: `${DOCS}/authoring-inline-3d.md#3-live-scene-threejs--webgl--addscenecanvas-onframe-opts`,
|
|
616
|
+
}));
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// (g) console / GL
|
|
620
|
+
{
|
|
621
|
+
const c = classify(fake.log, fake.shaderErrors);
|
|
622
|
+
const status = c.errors.length || c.gl.length ? 'fail' : c.sdkWarnings.length ? 'warn' : 'pass';
|
|
623
|
+
checks.push(check('console', 'g', 'No console errors, shader or GL errors', status,
|
|
624
|
+
c.gl[0] ? `GL/shader: ${c.gl[0]}` : c.errors[0] || (c.sdkWarnings[0] ? `SDK warning: ${c.sdkWarnings[0]}` : 'clean console'), {
|
|
625
|
+
details: c,
|
|
626
|
+
hint: c.sdkWarnings.length && !c.errors.length && !c.gl.length ? 'The SDK warns ([inline3d] ...) only about a page mistake it detected. Read the message: it names the fix.' : undefined,
|
|
627
|
+
}));
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// (h) 2D fallback
|
|
631
|
+
if (plain) {
|
|
632
|
+
const c = classify(plain.log, plain.shaderErrors);
|
|
633
|
+
const fails = [], details = { errors: c.errors, gl: c.gl, regions: [] };
|
|
634
|
+
if (c.errors.length) fails.push(`errors without inline 3D: ${c.errors[0]}`);
|
|
635
|
+
if (c.gl.length) fails.push(`GL/shader errors without inline 3D: ${c.gl[0]}`);
|
|
636
|
+
for (const r of plain.regions || []) {
|
|
637
|
+
if (r.missing) { details.regions.push({ selector: r.selector, missing: true }); continue; }
|
|
638
|
+
const st = r.visible ? r.stats || null : null;
|
|
639
|
+
details.regions.push({ selector: r.selector, visible: r.visible, contentPct: st ? +(st.contentFraction * 100).toFixed(2) : null });
|
|
640
|
+
if (r.visible && st && st.blank) {
|
|
641
|
+
// Something else may stand in for it (an <img> fallback over the same box).
|
|
642
|
+
fails.push(`${r.selector}: shows nothing in a plain browser (draw a mono view, or show a 2D fallback)`);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
if (!plain.regions.length && !fake.layers.length && !c.errors.length) details.note = 'no woven canvas in the 3D run to compare against';
|
|
646
|
+
checks.push(check('fallback-2d', 'h', 'Still renders in a plain browser (2D fallback)', fails.length ? 'fail' : 'pass',
|
|
647
|
+
fails[0] || `no errors without inline 3D; ${details.regions.filter((r) => r.contentPct > 0).length}/${details.regions.length} canvas region(s) show content`, {
|
|
648
|
+
details,
|
|
649
|
+
hint: fails.length ? 'Branch on wall.supported (or the viewer\'s mono path): render one camera to the canvas, or show an <img>/poster. Never leave the canvas empty or show the packed pair.' : undefined,
|
|
650
|
+
doc: `${DOCS}/authoring-inline-3d.md#detecting-support--do-this-not-that`,
|
|
651
|
+
}));
|
|
652
|
+
} else {
|
|
653
|
+
checks.push(check('fallback-2d', 'h', 'Still renders in a plain browser (2D fallback)', 'skip', 'skipped (--no-fallback)'));
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// detection anti-patterns (static + runtime)
|
|
657
|
+
{
|
|
658
|
+
const warns = [];
|
|
659
|
+
const st = fake.statics;
|
|
660
|
+
if (S.isSessionSupportedCalls.some((c) => c.mode === 'inline-3d') || st.isSessionSupported.length) warns.push(`gates on navigator.xr.isSessionSupported('inline-3d') (${st.isSessionSupported[0] || 'at runtime'}): it can resolve false before the weave service binds. Use createInline3D() / inline3DAvailable().`);
|
|
661
|
+
if (st.uaSniff.length) warns.push(`reads the user agent next to "DisplayXR" (${st.uaSniff[0]}): detect by capability (createInline3D, inline3DAvailable), never the UA string (the Android browser sends a desktop UA).`);
|
|
662
|
+
checks.push(check('detection', 'f', 'Detects support by capability, not isSessionSupported or the UA string', warns.length ? 'warn' : 'pass', warns[0] || 'no isSessionSupported/UA gating seen', { details: warns, approximate: true }));
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// version pins (import maps + package.json)
|
|
666
|
+
{
|
|
667
|
+
const warns = [], seen = [];
|
|
668
|
+
const exact = (u, name) => new RegExp(`${name.replace(/[/.]/g, (c) => `\\${c}`)}@\\d+\\.\\d+\\.\\d+(?![\\w.-]*[x*])`).test(u);
|
|
669
|
+
for (const m of fake.statics.importMaps) {
|
|
670
|
+
for (const [k, v] of Object.entries(m.imports || {})) {
|
|
671
|
+
if (!/^https?:/.test(v)) continue;
|
|
672
|
+
for (const name of ['@displayxr/inline3d', 'playcanvas', 'three']) {
|
|
673
|
+
if (k === name || k.startsWith(`${name}/`)) {
|
|
674
|
+
seen.push(`${k} -> ${v}`);
|
|
675
|
+
if (!exact(v, name)) warns.push(`import map pins ${k} loosely (${v}): pin an exact version`);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
if (opt.packageJson) {
|
|
681
|
+
const deps = { ...(opt.packageJson.dependencies || {}), ...(opt.packageJson.devDependencies || {}) };
|
|
682
|
+
for (const name of ['@displayxr/inline3d', 'playcanvas', 'three']) {
|
|
683
|
+
if (!deps[name]) continue;
|
|
684
|
+
seen.push(`${name}@${deps[name]}`);
|
|
685
|
+
if (!/^\d+\.\d+\.\d+$/.test(deps[name])) warns.push(`package.json pins ${name} as "${deps[name]}": pin an exact version`);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
checks.push(check('pins', '-', 'Exact version pins for @displayxr/inline3d, playcanvas, three', warns.length ? 'warn' : seen.length ? 'pass' : 'skip', warns[0] || (seen.length ? seen.join('; ') : 'no CDN import map or package.json found'), { details: { seen, warns }, approximate: true }));
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// depth / comfort (measured)
|
|
692
|
+
{
|
|
693
|
+
let status = 'skip', summary = 'no stereo pair to measure';
|
|
694
|
+
let details = null;
|
|
695
|
+
const zone = shibataZoneMm(0.65);
|
|
696
|
+
if (primary && primary.px && primary.px.blocks.length >= 3 && primary.occlusion) {
|
|
697
|
+
const k = (primary.occlusion.rect.width / primary.px.eyeW) * MPP * 1000; // mm per eye px
|
|
698
|
+
const ds = primary.px.blocks.map((b) => b.d * k);
|
|
699
|
+
const p05 = quantile(ds, 0.05), p50 = quantile(ds, 0.5), p95 = quantile(ds, 0.95);
|
|
700
|
+
details = { frontMostMm: +p05.toFixed(2), medianMm: +p50.toFixed(2), backMostMm: +p95.toFixed(2), comfortZoneMm: { front: +zone.frontMm.toFixed(1), behind: +zone.behindMm.toFixed(1) }, blocks: ds.length, sign: '- = in front of the glass, + = behind' };
|
|
701
|
+
const warns = [];
|
|
702
|
+
if (p05 < -zone.frontMm) warns.push(`pops out ${(-p05).toFixed(1)} mm (comfort zone ${zone.frontMm.toFixed(1)} mm in front)`);
|
|
703
|
+
if (p95 > zone.behindMm) warns.push(`recedes ${p95.toFixed(1)} mm (comfort zone ${zone.behindMm.toFixed(1)} mm behind)`);
|
|
704
|
+
const span = Math.max(1e-6, p95 - p05);
|
|
705
|
+
if (Math.abs(p50) > Math.max(1.5, 0.6 * span) && (p05 > 0 || p95 < 0)) warns.push(`the subject sits entirely ${p50 > 0 ? 'behind' : 'in front of'} the glass (median ${p50.toFixed(1)} mm): centre it on z = 0`);
|
|
706
|
+
status = warns.length ? 'warn' : 'pass';
|
|
707
|
+
summary = warns.length ? warns.join('; ') : `screen disparity ${p05.toFixed(1)} … ${p95.toFixed(1)} mm (median ${p50.toFixed(1)}), inside the comfort zone`;
|
|
708
|
+
}
|
|
709
|
+
checks.push(check('depth', '-', 'Depth sits on the glass and inside the comfort zone (measured, approximate)', status, summary, { details, approximate: true, doc: `${DOCS}/making-3d-look-right.md` }));
|
|
710
|
+
}
|
|
711
|
+
return checks;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
function rigInfo(fake) {
|
|
715
|
+
const p = fake.layers[0];
|
|
716
|
+
if (!p) return { type: null, comfort: null };
|
|
717
|
+
const rig = p.rig;
|
|
718
|
+
if (!rig) return { type: 'display', source: p.init && p.init.virtualDisplayHeight ? 'virtualDisplayHeight' : 'browser default', virtualDisplayHeight: p.init ? p.init.virtualDisplayHeight || null : null, comfort: null, rigPushes: p.rigPushes };
|
|
719
|
+
const type = rig.type === 'camera' ? 'camera' : 'display';
|
|
720
|
+
const out = { type, rigPushes: p.rigPushes, ...Object.fromEntries(Object.entries(rig).filter(([k]) => k !== 'type')) };
|
|
721
|
+
if (type === 'camera') {
|
|
722
|
+
const ipd = typeof rig.ipdFactor === 'number' ? rig.ipdFactor : 1;
|
|
723
|
+
const m2v = rig.metersToVirtual || 1;
|
|
724
|
+
const dio = typeof rig.convergenceDiopters === 'number' ? rig.convergenceDiopters : 0;
|
|
725
|
+
out.comfort = +(ipd * m2v * dio * 0.65).toFixed(3);
|
|
726
|
+
out.comfortNote = 'ipdFactor x metersToVirtual x convergenceDiopters x 0.65 m (nominal viewer); keep <= 1';
|
|
727
|
+
} else {
|
|
728
|
+
out.comfort = null;
|
|
729
|
+
out.comfortNote = 'display rig: ipdFactor/parallaxFactor are relative comfort dials in [0,1]';
|
|
730
|
+
}
|
|
731
|
+
return out;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
// ------------------------------------------------------------------------------ entry point
|
|
735
|
+
export async function runCheck(target, opt = {}) {
|
|
736
|
+
const o = {
|
|
737
|
+
root: undefined,
|
|
738
|
+
maxTexture: 0,
|
|
739
|
+
timeoutMs: 15000,
|
|
740
|
+
loadTimeoutMs: 20000,
|
|
741
|
+
plainTimeoutMs: 6000,
|
|
742
|
+
settleMs: 1600,
|
|
743
|
+
noSessionGiveUpMs: 5000,
|
|
744
|
+
fallback: true,
|
|
745
|
+
viewport: { width: 1280, height: 800, dpr: 1 },
|
|
746
|
+
...opt,
|
|
747
|
+
};
|
|
748
|
+
const t0 = Date.now();
|
|
749
|
+
const tgt = await resolveTarget(target, o.root);
|
|
750
|
+
if (tgt.kind !== 'url' && !o.packageJson) {
|
|
751
|
+
for (let d = tgt.kind === 'dir' ? tgt.file : dirname(tgt.file); d.startsWith(tgt.root) || d === tgt.root; d = dirname(d)) {
|
|
752
|
+
const pj = join(d, 'package.json');
|
|
753
|
+
if (existsSync(pj)) { try { o.packageJson = JSON.parse(readFileSync(pj, 'utf8')); } catch { /* ignore */ } break; }
|
|
754
|
+
if (d === tgt.root || dirname(d) === d) break;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
let origin = null;
|
|
758
|
+
try { origin = new URL(tgt.url).origin; } catch { /* keep null */ }
|
|
759
|
+
const browser = await launchChrome({
|
|
760
|
+
width: o.viewport.width,
|
|
761
|
+
height: o.viewport.height,
|
|
762
|
+
extraArgs: o.maxTexture ? [`--webgl_or_caps_max_texture_size_limit_${o.maxTexture}`] : [],
|
|
763
|
+
});
|
|
764
|
+
let fake, plain = null;
|
|
765
|
+
try {
|
|
766
|
+
fake = await fakeRun(browser.conn, tgt.url, o, origin);
|
|
767
|
+
if (o.fallback) plain = await plainRun(browser.conn, tgt.url, o, fake, origin);
|
|
768
|
+
} finally {
|
|
769
|
+
await browser.close();
|
|
770
|
+
if (tgt.server) await tgt.server.close();
|
|
771
|
+
}
|
|
772
|
+
const checks = buildChecks(fake, plain, o);
|
|
773
|
+
const verdict = checks.some((c) => c.status === 'fail') ? 'fail' : checks.some((c) => c.status === 'warn') ? 'warn' : 'pass';
|
|
774
|
+
const S = fake.summary || {};
|
|
775
|
+
return {
|
|
776
|
+
tool: 'inline3d-check',
|
|
777
|
+
version: VERSION,
|
|
778
|
+
target,
|
|
779
|
+
url: tgt.url,
|
|
780
|
+
verdict,
|
|
781
|
+
durationMs: Date.now() - t0,
|
|
782
|
+
options: { maxTexture: o.maxTexture || null, viewport: o.viewport, fallback: o.fallback },
|
|
783
|
+
environment: { fakeDisplay: { widthM: 0.3456, heightM: 0.1944, pixels: [1920, 1080], viewerM: 0.65, eyeSeparationM: 0.063 } },
|
|
784
|
+
checks,
|
|
785
|
+
info: {
|
|
786
|
+
rig: rigInfo(fake),
|
|
787
|
+
comfort: rigInfo(fake).comfort,
|
|
788
|
+
layers: fake.layers.map((l) => ({ selector: l.selector, rect: l.occlusion && l.occlusion.rect, buffer: l.buffer && { width: l.buffer.width, height: l.buffer.height, contextType: l.buffer.contextType }, ageMs: Math.round(l.ageMs) })),
|
|
789
|
+
frames: S.frames || 0,
|
|
790
|
+
framesWithViews: S.framesWithViews || 0,
|
|
791
|
+
modeRequests: S.modeRequests || [],
|
|
792
|
+
fakeRunMs: fake.ms,
|
|
793
|
+
plainRunMs: plain ? plain.ms : null,
|
|
794
|
+
},
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
export function formatHuman(r) {
|
|
799
|
+
const icon = { pass: 'PASS', fail: 'FAIL', warn: 'WARN', skip: 'skip' };
|
|
800
|
+
const lines = [];
|
|
801
|
+
lines.push(`inline3d-check ${r.version} ${r.url}`);
|
|
802
|
+
for (const c of r.checks) {
|
|
803
|
+
lines.push(` ${icon[c.status].padEnd(4)} ${c.letter !== '-' ? `(${c.letter}) ` : ' '}${c.id.padEnd(15)} ${c.summary}${c.approximate ? ' [approx]' : ''}`);
|
|
804
|
+
if ((c.status === 'fail' || c.status === 'warn') && c.hint) lines.push(` fix: ${c.hint}`);
|
|
805
|
+
if ((c.status === 'fail' || c.status === 'warn') && c.doc) lines.push(` see: ${c.doc}`);
|
|
806
|
+
}
|
|
807
|
+
const rig = r.info.rig;
|
|
808
|
+
lines.push(` rig: ${rig.type || 'n/a'}${rig.type === 'camera' ? `, comfort ${rig.comfort} (keep <= 1)` : ''}${rig.virtualDisplayHeight ? `, virtualDisplayHeight ${rig.virtualDisplayHeight}` : ''}`);
|
|
809
|
+
lines.push(` verdict: ${r.verdict.toUpperCase()} in ${(r.durationMs / 1000).toFixed(1)} s`);
|
|
810
|
+
return lines.join('\n');
|
|
811
|
+
}
|