diff --git a/README.md b/README.md index c67e6e2..14b37af 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,169 @@ -# arjs-plugin-artoolkit -```markdown # @ar-js-org/arjs-plugin-artoolkit -Minimal ARToolKit detection plugin scaffold for AR.js core. +ARToolKit marker detection plugin for AR.js core with WebAssembly support. + +## Features + +- Web Worker-based detection — marker detection runs off the main thread +- ImageBitmap support — zero-copy frame transfer (browser) +- Cross-platform — browser Workers and Node.js worker_threads (stub path) +- ARToolKit integration — square pattern markers +- Event-driven API — marker found/updated/lost + raw getMarker forwarding +- Filtering — only forwards PATTERN_MARKER events above a minimum confidence + +## Installation + +```bash +npm install @ar-js-org/arjs-plugin-artoolkit +``` + +## Configuration (module + assets) + +To ensure the Worker can import ARToolKit in the browser, pass an explicit ESM URL (recommended): + +```js +const plugin = new ArtoolkitPlugin({ + worker: true, + artoolkitModuleUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/ARToolkit.js', // explicit ESM + cameraParametersUrl: '/path/to/camera_para.dat', // optional override + wasmBaseUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/', // optional; if your build needs it + minConfidence: 0.6 // forward only confident detections +}); +``` + +CDN fallback (if you don’t serve node_modules): +- Set `artoolkitModuleUrl` to a CDN ESM endpoint, e.g. a jsDelivr/UNPKG URL for the package’s ESM bundle. + +Notes: +- The previous “loader.js” and manual WASM placement flow is no longer used. +- If your ARToolKit build fetches auxiliary assets (WASM, data), set `wasmBaseUrl` accordingly. ## Usage -Register with the Engine plugin manager: +### Register and enable ```js import { ArtoolkitPlugin } from '@ar-js-org/arjs-plugin-artoolkit'; -engine.pluginManager.register('artoolkit', new ArtoolkitPlugin({ /* options */ })); +const plugin = new ArtoolkitPlugin({ + worker: true, + lostThreshold: 5, // frames before a marker is considered lost + frameDurationMs: 100, // expected ms per frame (affects lost timing) + artoolkitModuleUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/ARToolkit.js', + cameraParametersUrl: '/data/camera_para.dat', + minConfidence: 0.6 +}); + +engine.pluginManager.register('artoolkit', plugin); await engine.pluginManager.enable('artoolkit'); ``` -The plugin emits events on the engine event bus: -- `ar:markerFound` -- `ar:markerUpdated` -- `ar:markerLost` +### Events + +The plugin emits the following events on your engine’s event bus: + +```js +// Marker first detected +engine.eventBus.on('ar:markerFound', ({ id, poseMatrix, confidence, corners }) => { + // poseMatrix is Float32Array(16) +}); + +// Marker updated (tracking) +engine.eventBus.on('ar:markerUpdated', (data) => { + // same shape as markerFound +}); + +// Marker lost +engine.eventBus.on('ar:markerLost', ({ id }) => {}); + +// Worker lifecycle +engine.eventBus.on('ar:workerReady', () => {}); +engine.eventBus.on('ar:workerError', (error) => {}); + +// Raw ARToolKit getMarker (filtered: PATTERN_MARKER only, above minConfidence) +engine.eventBus.on('ar:getMarker', (payload) => { + // payload = { type, matrix: number[16], marker: { idPatt, cfPatt, idMatrix?, cfMatrix?, vertex? } } +}); +``` + +### Sending frames + +```js +// Create ImageBitmap from a