feat(nft): let a consumer supply its own NFTDetector
I maintainer di solito rispondono entro 1 giorno
@kalwalt ci sta già lavorando.
Dal 17/11/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Summary
Give ARToolKitNFTCore an injection point for an externally supplied NFTDetector, so a consumer can run the KPM pass wherever it wants — in a Web Worker, for instance — without WebARKitLib knowing anything about it.
No worker code, no JavaScript and no new dependency enters this repository: only a third Detector value, a factory in the config, a hook that tells the detector what the core accepted, and one documentation fix.
Why
kalwalt/WebAR-Canvas#16 needs the KPM pass off the browser's main thread: while nothing is tracked the core detects on every frame, and a pass costs about 45 ms, which holds the app near 20 fps.
The threaded path already in this repository does solve it — measured in that issue's spike, the mean main-thread tick goes from 20.0 ms to 1.07 ms and long frames from 181 to 1 per 10 s. But WEBARKIT_NFT_THREADS compiles to pthreads, which on the web means SharedArrayBuffer, which means the page must be cross-origin isolated (COOP/COEP). That was verified, not assumed: without the headers the app does not start at all (DataCloneError: SharedArrayBuffer transfer requires self.crossOriginIsolated), and a pthreads build therefore cannot fall back at run time — the consumer has to ship two builds and choose at load.
A detector that lives in a Web Worker with its own WASM instance needs none of that: no shared memory, no isolation, one build, and a page that works on GitHub Pages and inside other sites. The cost is a frame copy per pass and code in the consumer, which is where it belongs.
What is already here
NFTDetector is already the right abstraction: start(), collect(), idle(), waitIdle(), with SyncKpmDetector and ThreadedKpmDetector behind it, and its documentation already allows a pass that does not finish inside start().
What is missing is only the way in. ARToolKitNFTCore::createDetector() is private, not virtual, and switches on config.detector over the two implementations compiled into this library. The detector is created lazily, on the first addNFTMarkers(), and reused for later batches.
Proposed change
- A third value,
NFTTrackingConfig::Detector::External. - A factory in
NFTTrackingConfig, in the style of theclockpointer that is already there, with a context pointer beside it, because one tracker owns one detector and a bare function pointer carries no state:
class NFTDetector; // forward-declared, so the header still needs no AR/ar.h
std::unique_ptr<NFTDetector> (*makeDetector)(void *user) = nullptr;
void *makeDetectorUser = nullptr;
- A branch at the top of
createDetector()forExternal, which returnsconfig.makeDetector(config.makeDetectorUser)and logs an error when the factory is null. It works in builds withoutWEBARKIT_NFT_THREADStoo. - A hook on
NFTDetector, default no-op, telling the detector what the core accepted:
/** Called after the core accepted a batch of markers, with the pages it assigned. Default: nothing. */
virtual void markersAdded(const std::vector<int> &pages,
const std::vector<std::string> &datasetPathnames) {}
/** Called when the core loaded or replaced the camera. Default: nothing. */
virtual void cameraChanged(/* see below */) {}
The signatures are a proposal to refine. The requirement behind them: whatever these hooks pass must be usable by a detector that does not share memory with the core — values or file paths, never a pointer into the core's heap (an ARParamLT * would be useless to another WASM instance).
Without this hook the consumer has to forward the camera and the dataset paths itself and rely on loading markers one at a time so that its own numbering matches the core's. That works, but the agreement is implicit: if the core's page numbering ever changed, an external detector would report poses for the wrong markers and nothing would notice. The hook makes the contract explicit, which is why it is worth the few lines.
waitIdle()'s documentation. It currently says "Blocks until no pass is running". A detector that runs in a worker cannot block the main thread; it can only abandon the pass. That is safe here — the threedropRunningSearch()call sites (setupAR2(),deleteCamera(), andaddNFTMarkers()beforekpmSetRefDataSet()) exist so that no pass reads a KPM handle while it is replaced, and the code's own comment already says the abandoned pass's result belongs to the old marker set and is dropped. A detector that shares no memory has nothing to protect; the core only needsidle()to be true afterwards and the nextcollect()to return false.
So the comment should read, in substance: ends the running pass — waits for it (threaded) or abandons it (external); its result is never collected. An external detector is then expected to discard a late result of an abandoned pass, typically with a generation counter of its own.
Non-goals
- No worker, JavaScript or Emscripten code in this repository.
SyncandThreadedbehave exactly as today;singleThreadPreset()andthreadedPreset()are untouched.- No existing API breaks: the enum gains a value, the config gains two fields defaulting to null,
NFTDetectorgains two virtuals with default implementations.
Acceptance criteria
- A test detector supplied through the factory receives
start(), is collected from, and drives the core to a pose, in a build withWEBARKIT_NFT_THREADSoff. -
config.detector == Externalwith a null factory fails with a clear error instead of crashing. - The hooks report the same pages the core returns from
addNFTMarkers(), for a batch of more than one marker. - Abandoning a pass leaves the core able to start the next one; a result delivered after the abandon is not mistaken for a current one.
- The existing single-thread and threaded tests still pass, unchanged.
Size
About 30 lines of library code and about 40 of tests, as estimated from the spike in kalwalt/WebAR-Canvas#16.
References
kalwalt/WebAR-Canvas#16— the consumer, with the spike's measurements and the isolation findings.#94andkalwalt/WebAR-Canvas#11— the precedent for an upstream change driven by a consumer.
- Lingua principale
- C++
- Stelle
- 21
- Fork
- 8
- Merge medio
- 3h 42m
- PR unite (30g)
- 22
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di webarkit/WebARKitLib
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
webarkit/WebARKitLib#131 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
webarkit/WebARKitLib#114 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 93/100
webarkit/WebARKitLib#107 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
webarkit/WebARKitLib#130 ·
I maintainer di solito rispondono entro 1 giorno
-
build: native build fails with GCC 15 (ubuntu-26.04): implicit fopen64 in vendored ioapi.cForse già presa @kalwalt l’ha presa 6 giorni fa. Apertabug CI
webarkit/WebARKitLib#118 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di webarkit/WebARKitLib
Issue simili
-
bug fixed form parser medium priority tokenizer
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
compatibility prio:normal
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
NatronGitHub/openfx-misc#320 ·
I maintainer di solito rispondono entro 1 giorno
-
[Windows] Hidden title bar: a maximized window restored from minimized on a secondary monitor gets the primary monitor's work area as its client areaForse già presa @lijy91 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
libnativeapi/nativeapi#53 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
I maintainer di solito rispondono entro 1 giorno
-
agent-ready area:analysis bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
pauljohanneskraft/Acai#609 ·
I maintainer di solito rispondono entro 10 giorni