v3: HUD shows opencv download progress (cv:loading N%) and retries load when tapping back to opencv
This commit is contained in:
@@ -26,6 +26,7 @@ const ENGINES = ['opencv', 'posit'];
|
|||||||
let engine = localStorage.getItem('nbx.engine') || 'opencv';
|
let engine = localStorage.getItem('nbx.engine') || 'opencv';
|
||||||
if (!ENGINES.includes(engine)) engine = 'opencv';
|
if (!ENGINES.includes(engine)) engine = 'opencv';
|
||||||
let cvState = 'idle'; // idle | loading | ready | failed
|
let cvState = 'idle'; // idle | loading | ready | failed
|
||||||
|
let cvNote = ''; // download % / init stage while loading
|
||||||
function setEngine(e) { engine = e; localStorage.setItem('nbx.engine', e); }
|
function setEngine(e) { engine = e; localStorage.setItem('nbx.engine', e); }
|
||||||
|
|
||||||
/* Camera-frame correction for the POSIT path (unchanged from v2; the opencv path
|
/* Camera-frame correction for the POSIT path (unchanged from v2; the opencv path
|
||||||
@@ -72,7 +73,7 @@ function updateDbg(fusedQuat, markerCount, extra) {
|
|||||||
const up = _dbgV.set(0, 1, 0).applyQuaternion(camera3.quaternion).clone();
|
const up = _dbgV.set(0, 1, 0).applyQuaternion(camera3.quaternion).clone();
|
||||||
const v3 = v => `(${v.x.toFixed(2)},${v.y.toFixed(2)},${v.z.toFixed(2)})`;
|
const v3 = v => `(${v.x.toFixed(2)},${v.y.toFixed(2)},${v.z.toFixed(2)})`;
|
||||||
const modeLine = engine === 'opencv'
|
const modeLine = engine === 'opencv'
|
||||||
? `axis ${cvSolver ? cvSolver.getAxisMode() : 'std'} cv:${cvState}`
|
? `axis ${cvSolver ? cvSolver.getAxisMode() : 'std'} cv:${cvState}${cvNote ? ' ' + cvNote : ''}`
|
||||||
: `rot ${getRotMode()} cam ${camMode}`;
|
: `rot ${getRotMode()} cam ${camMode}`;
|
||||||
dbgEl.textContent =
|
dbgEl.textContent =
|
||||||
`eng ${engine} ${freezeGhosts ? 'FROZEN' : 'moving'}\n` +
|
`eng ${engine} ${freezeGhosts ? 'FROZEN' : 'moving'}\n` +
|
||||||
@@ -131,12 +132,13 @@ async function applyLanding() {
|
|||||||
* posit engine takes over automatically — visitors always get a working exhibit. */
|
* posit engine takes over automatically — visitors always get a working exhibit. */
|
||||||
function ensureOpenCV() {
|
function ensureOpenCV() {
|
||||||
if (cvState === 'ready' || cvState === 'loading') return;
|
if (cvState === 'ready' || cvState === 'loading') return;
|
||||||
|
// 'failed' falls through: tapping back to opencv retries the load
|
||||||
cvState = 'loading';
|
cvState = 'loading';
|
||||||
loadOpenCV().then(() => {
|
loadOpenCV('/vendor/opencv.js', (p) => { cvNote = typeof p === 'number' ? p + '%' : String(p); }).then(() => {
|
||||||
cvState = 'ready';
|
cvState = 'ready'; cvNote = '';
|
||||||
if (engine === 'opencv') toast('Tracking engine ready');
|
if (engine === 'opencv') toast('Tracking engine ready');
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
cvState = 'failed';
|
cvState = 'failed'; cvNote = '';
|
||||||
console.warn('opencv.js unavailable, falling back to posit', e);
|
console.warn('opencv.js unavailable, falling back to posit', e);
|
||||||
if (engine === 'opencv') { setEngine('posit'); toast('Using classic tracking'); }
|
if (engine === 'opencv') { setEngine('posit'); toast('Using classic tracking'); }
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user