From 10b75e112fe06faadbc4992236ddfd28329802e9 Mon Sep 17 00:00:00 2001 From: Walter Perdan Date: Wed, 10 Jun 2026 17:32:52 +0200 Subject: [PATCH 1/2] feat(#36): add live-webcam Teblid AR example + examples index New live-camera AR example using the Teblid tracker, built on the static example's conventions (consume matrixGL_RH directly, projection as-is, no pose correction) + a continuous bufferCopy main<->worker ping-pong loop + a getUserMedia feed. RGBA end-to-end (tracker converts internally). Cube + axes anchored at the marker origin, hidden when not found; on-screen Marker-tracked/Searching status (console logging kept). - examples/worker_teblid_webcam_threejs.js (dedicated bufferCopy worker, emits matrixGL_RH) - examples/threejs_teblid_webcam_worker_ES6.js (start() module / live loop) - examples/threejs_teblid_webcam_ES6_example.html (page + camera bootstrap) - examples/index.html (grouped landing page) - docs/design-webcam-teblid-example.md (design + decision log) No existing example modified or removed. No library changes / no rebuild. Known limitation (not this PR): tracking is not declared lost when the marker leaves frame -- see webarkit/WebARKitLib#46. Refs #36 Co-Authored-By: Claude Opus 4.8 --- docs/design-webcam-teblid-example.md | 129 ++++++++++ examples/index.html | 88 +++++++ .../threejs_teblid_webcam_ES6_example.html | 124 +++++++++ examples/threejs_teblid_webcam_worker_ES6.js | 242 ++++++++++++++++++ examples/worker_teblid_webcam_threejs.js | 81 ++++++ 5 files changed, 664 insertions(+) create mode 100644 docs/design-webcam-teblid-example.md create mode 100644 examples/index.html create mode 100644 examples/threejs_teblid_webcam_ES6_example.html create mode 100644 examples/threejs_teblid_webcam_worker_ES6.js create mode 100644 examples/worker_teblid_webcam_threejs.js diff --git a/docs/design-webcam-teblid-example.md b/docs/design-webcam-teblid-example.md new file mode 100644 index 0000000..9ed5a41 --- /dev/null +++ b/docs/design-webcam-teblid-example.md @@ -0,0 +1,129 @@ +# Design: Live-webcam Teblid AR example (issue #36) + +Branch: `feat/teblid-webcam-example` (webarkit/webarkit-testing). Adds a new +working live-camera AR example using the Teblid tracker, plus an `index.html` +landing page for all examples. **No existing example is modified or removed** +(the cleanup half of #36 is deferred). + +Depends on the library fixes merged in webarkit/WebARKitLib#45 (#43 scale-factor, +#35 projection X-sign, #42 D*R*D handedness) — so the example consumes +`matrixGL_RH` directly with no render-side pose correction. + +## Understanding Summary + +- **What:** a new live-webcam AR example using the **Teblid** tracker, *added* + to `examples/` (nothing removed), plus a new `examples/index.html` listing all + examples. +- **Why:** the existing webcam examples are broken; we need a working live + reference built on the now-correct library. +- **Who:** WebARKit developers wanting a live-camera Teblid starting point. +- **Shape:** the static-image example's *conventions* (consume `matrixGL_RH` + directly, projection as-is, no pose hack) + the bufferCopy example's + *continuous main↔worker ping-pong loop* + a `getUserMedia` feed. +- **Hard constraints:** don't touch/delete the other examples; RGBA end-to-end + (the tracker converts via `convert2Grayscale`); **never mirror the processed + feed**; no library changes and no rebuild (pure example HTML/JS). + +## Assumptions + +- **Files:** `threejs_teblid_webcam_ES6_example.html`, + `threejs_teblid_webcam_worker_ES6.js` (the `start()` module), + `worker_teblid_webcam_threejs.js` (dedicated worker), `index.html`. +- **Marker:** `data/pinball.jpg`, decoded to RGBA via the static example's + Image → canvas → `getImageData` → `loadTrackerGrayImage` path. +- **Content:** cube (0.6) at +Z 0.3 **+ `AxesHelper`**, attached to `root`, + anchored at the marker origin (object 0,0,0 = reference top-left). +- **Capture:** 640×480, `facingMode:"environment"`, reusing `initCamera.js`; + capture size taken from `video.videoWidth/Height` (actual, not requested); + `CAPTURE_W`/`CAPTURE_H` constants at the top of the HTML. +- **No build artifacts, no library edits.** Uses the existing `dist/WebARKit.js`. + +## Decision Log + +| Decision | Alternatives | Why | +|---|---|---| +| **bufferCopy ping-pong** (recycle one transferable `ArrayBuffer`) | getImageData one-way per frame; SharedArrayBuffer zero-copy | Continuous video needs to avoid per-frame allocation/GC; SAB needs COOP/COEP headers (out of scope). The bufferCopy example exists for exactly this. | +| **New dedicated `worker_teblid_webcam_threejs.js`** emitting `matrixGL_RH` | Modify `worker_bufferCopy_threejs.js`; reuse static `worker_threejs.js` | Isolation honors "don't touch other examples"; the static worker can't ping-pong (one-way transfer). One duplicated ~80-line worker is acceptable. | +| **Match-aspect display, projection as-is** | Letterbox-pad + `ratioW/ratioH` projection scaling (bufferCopy style); CSS cover, no compensation | Same proven convention as the corrected static example; no projection arithmetic to get wrong; exact AR alignment. Letterbox bars on mismatched windows are acceptable. | +| **640×480 `environment`, reuse `initCamera.js`** | 1280×720 default; `user` (front) default | Fast, lands on the factor-1.0 path, ideal for pointing at a printout; front feeds invite mirroring which would break handedness. Resolution is a constant so the "also works at 1280×720" criterion is one edit away. | +| **Consume `matrixGL_RH` directly, no correction** | Re-add an example-side pose tweak | The library now emits a correct D*R*D pose + standard projection (#45). | +| **Hide content on `not found`** (`world = null`) | Freeze last pose (static example behavior) | Live tracking: content should disappear when the marker leaves frame. | +| **Use actual `video.videoWidth/Height`** | Trust the requested 640×480 | Browsers may not honor the exact request; using the real size keeps tracker init + projection consistent. | +| **`index.html`: grouped, relative links, "under review (#36)" group** | Flat alphabetical; delete legacy now | Honest about state without removing anything pre-audit; relative links work from `examples/` on any static server. | +| **cube + axes** | cube-only | Axes give an immediate, unambiguous read of the marker frame (red→right, green→up, blue→toward viewer). | + +## Final Design + +### Files (4 new; nothing else touched) + +1. **`examples/threejs_teblid_webcam_ES6_example.html`** — `