You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This proposal suggests extracting a pure C++ core engine (ARToolKitNFT_core.h / ARToolKitNFT_core.cpp) from ARToolKitNFT_js.cpp and ARToolKitNFT_js_td.cpp.
This unified core will:
Eliminate the ~95% code duplication between the single-threaded (ARToolKitNFT_js) and multi-threaded (ARToolKitNFT_js_td) implementations in jsartoolkitNFT.
Decouple pure computer vision and tracking logic from Emscripten Embind / emscripten::val.
Provide a reusable, native C++ NFT tracking class that external engines (such as WebAR-Canvas and native C++ projects) can import and consume directly without JavaScript binding overhead.
Current Architecture & Code Duplication
Currently in emscripten/:
ARToolKitNFT_js.cpp (~20.3 KB) and ARToolKitNFT_js_td.cpp (~21.6 KB) are essentially copy-pasted duplicates of each other.
The only functional difference between them is the KPM detection strategy:
ARToolKitNFT_js: runs kpmMatching() synchronously on the calling thread.
ARToolKitNFT_js_td: runs kpmMatching() asynchronously on a background worker thread via trackingSub.c (trackingInit*).
Emscripten coupling: Both classes include <emscripten.h> and <emscripten/val.h> directly in their headers. However, across the entire 650+ lines of C++, emscripten::val is used in only two methods:
getNFTMarkerInfo(int markerIndex) (to construct a JS object with .pose and properties)
getCameraLens() (to return typed_memory_view)
Impact on Downstream Native Engines: Because ARToolKitNFT is coupled with emscripten::val and Embind (which requires RTTI), native C++ rendering engines (like WebAR-Canvas, which runs Google Filament under -fno-rtti) cannot directly #include or link ARToolKitNFT. Instead, downstream projects must duplicate tracking code and write their own tracker class (ARNFTTracker.cpp) from scratch.
Why ARToolKitJS.cpp Is Out of Scope
As observed during architectural analysis, ARToolKitJS.cpp should NOT be part of this unified core:
ARToolKitJS.cpp is a legacy procedural C interface (extern "C") that manages a global map of arController instances and exposes flat C functions (ccall/cwrap).
It mixes legacy fiducial square/pattern/barcode markers (arDetectMarker) with NFT.
Refactoring ARToolKitJS.cpp would introduce unnecessary legacy baggage without tangible benefit. It can remain as a legacy wrapper or be deprecated independently.
Summary
This proposal suggests extracting a pure C++ core engine (
ARToolKitNFT_core.h/ARToolKitNFT_core.cpp) fromARToolKitNFT_js.cppandARToolKitNFT_js_td.cpp.This unified core will:
ARToolKitNFT_js) and multi-threaded (ARToolKitNFT_js_td) implementations injsartoolkitNFT.emscripten::val.Current Architecture & Code Duplication
Currently in
emscripten/:ARToolKitNFT_js.cpp(~20.3 KB) andARToolKitNFT_js_td.cpp(~21.6 KB) are essentially copy-pasted duplicates of each other.ARToolKitNFT_js: runskpmMatching()synchronously on the calling thread.ARToolKitNFT_js_td: runskpmMatching()asynchronously on a background worker thread viatrackingSub.c(trackingInit*).<emscripten.h>and<emscripten/val.h>directly in their headers. However, across the entire 650+ lines of C++,emscripten::valis used in only two methods:getNFTMarkerInfo(int markerIndex)(to construct a JS object with.poseand properties)getCameraLens()(to returntyped_memory_view)ARToolKitNFTis coupled withemscripten::valand Embind (which requires RTTI), native C++ rendering engines (like WebAR-Canvas, which runs Google Filament under-fno-rtti) cannot directly#includeor linkARToolKitNFT. Instead, downstream projects must duplicate tracking code and write their own tracker class (ARNFTTracker.cpp) from scratch.Why
ARToolKitJS.cppIs Out of ScopeAs observed during architectural analysis,
ARToolKitJS.cppshould NOT be part of this unified core:ARToolKitJS.cppis a legacy procedural C interface (extern "C") that manages a global map ofarControllerinstances and exposes flat C functions (ccall/cwrap).arDetectMarker) with NFT.jsartoolkitNFTapplications already use the object-orientedARToolKitNFTclass via Embind. Square marker methods are being deprecated (ref Deprecate square-marker ARHandle methods that have no effect on NFT #659).ARToolKitJS.cppwould introduce unnecessary legacy baggage without tangible benefit. It can remain as a legacy wrapper or be deprecated independently.Proposed Architecture:
ARToolKitNFT_core1. Pure C++ Core (
ARToolKitNFT_core.h/.cpp)NFTMarkerState,float pose[3][4],const ARdouble* getCameraLens()).DetectionMode::SYNCHRONOUS: Direct execution ofkpmMatching()on the current thread.DetectionMode::ASYNCHRONOUS_THREAD: Delegates totrackingSub.c/ worker thread when pthreads/threading is enabled.loadCamera(),setCamera(),recalculateCameraLens()addNFTMarkers(),decompressZFT()passVideoData()detectNFTMarker(),trackMarkers()2. Embind Layer (
ARToolKitNFT_js.cpp/ARToolKitNFT_js_bindings.cpp)ARToolKitNFTCore.emscripten::valonly where JavaScript needs it (getNFTMarkerInfo,getCameraLens).ARToolKitNFT_js.cppandARToolKitNFT_js_td.cpp.3. Native Integration (WebAR-Canvas & Native Applications)
ARToolKitNFT_coreand consume it natively, eliminating the need to maintain an externalARNFTTrackerimplementation.Relationship with WebARKitLib #75 & jsartoolkitNFT #453
trackingMod,markerDecompress, andtrackingSubintoWebARKitLib.WebARKitLib,ARToolKitNFT_corecould either:WebARKitLib(e.g.lib/SRC/WebARKit/andinclude/WebARKit/), makingWebARKitLiba fully featured C++ NFT tracking library.jsartoolkitNFTas the foundation from which Embind bindings are generated.Feedback and discussion on this architecture from maintainers and contributors are welcome!