feat(nft): let a consumer supply its own NFTDetector
メンテナーはふだん 1 日以内に返信
@kalwalt がすでに取り組んでいます。
2026年11月17日 から。
評価
この issue はまだ評価されていません。
説明
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.
- 主要言語
- C++
- スター
- 21
- フォーク
- 8
- 平均マージ
- 3時間 42分
- マージ済み PR(30日)
- 22
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
webarkit/WebARKitLib のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
webarkit/WebARKitLib#131 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
webarkit/WebARKitLib#114 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 93/100
webarkit/WebARKitLib#107 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
webarkit/WebARKitLib#130 ·
メンテナーはふだん 1 日以内に返信
-
build: native build fails with GCC 15 (ubuntu-26.04): implicit fopen64 in vendored ioapi.c対応中かも @kalwalt が 6 日前に担当しました。 オープンbug CI
webarkit/WebARKitLib#118 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
webarkit/WebARKitLib の issue をすべて見る
似ている issue
-
bug fixed form parser medium priority tokenizer
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
compatibility prio:normal
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
NatronGitHub/openfx-misc#320 ·
メンテナーはふだん 1 日以内に返信
-
[Windows] Hidden title bar: a maximized window restored from minimized on a secondary monitor gets the primary monitor's work area as its client area対応中かも @lijy91 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
libnativeapi/nativeapi#53 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
agent-ready area:analysis bug
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
pauljohanneskraft/Acai#609 ·
メンテナーはふだん 10 日以内に返信