Skip to content

Commit 7420477

Browse files
committed
feat(docs): update README and index.html for ESM module usage and paths
1 parent 2d37129 commit 7420477

File tree

4 files changed

+63
-30
lines changed

4 files changed

+63
-30
lines changed

README.md

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ ARToolKit marker detection plugin for AR.js core with WebAssembly support.
44

55
## Features
66

7-
- Web Worker-based detection — marker detection runs off the main thread
7+
- Web Worker-based detection — marker detection runs off the main thread (Browser Module Worker)
88
- ImageBitmap support — zero-copy frame transfer (browser)
9-
- Cross-platform — browser Workers and Node.js worker_threads (stub path)
109
- ARToolKit integration — square pattern markers
1110
- Event-driven API — marker found/updated/lost + raw getMarker forwarding
1211
- Filtering — only forwards PATTERN_MARKER events above a minimum confidence
@@ -17,26 +16,53 @@ ARToolKit marker detection plugin for AR.js core with WebAssembly support.
1716
npm install @ar-js-org/arjs-plugin-artoolkit
1817
```
1918

20-
## Configuration (module + assets)
19+
## Using the ESM build (recommended)
2120

22-
To ensure the Worker can import ARToolKit in the browser, pass an explicit ESM URL (recommended):
21+
When you import the built ESM bundle from `dist/`, the worker and ARToolKit are already bundled and referenced correctly. You do NOT need to pass `artoolkitModuleUrl`.
22+
23+
Example:
24+
25+
```html
26+
<script type="module">
27+
import { ArtoolkitPlugin } from '/dist/arjs-plugin-artoolkit.esm.js';
28+
29+
const engine = { eventBus: /* your event bus */ };
30+
31+
const plugin = new ArtoolkitPlugin({
32+
worker: true,
33+
cameraParametersUrl: '/path/to/camera_para.dat',
34+
minConfidence: 0.6
35+
});
36+
37+
await plugin.init(engine);
38+
await plugin.enable();
39+
</script>
40+
```
41+
42+
Serving notes:
43+
- Serve from a web server so `/dist` assets resolve. The build is configured with `base: './'`, so the worker asset is referenced relative to the ESM file (e.g., `/dist/assets/worker-*.js`).
44+
- In your own apps, place `dist/` where you serve static assets and import the ESM with the appropriate path (absolute or relative).
45+
46+
## Using source (development mode)
47+
48+
If you develop against `src/` (not the built `dist/`), the worker will attempt to dynamically import ARToolKit. In that case you should provide `artoolkitModuleUrl` or ensure your dev server can resolve `@ar-js-org/artoolkit5-js`.
2349

2450
```js
2551
const plugin = new ArtoolkitPlugin({
2652
worker: true,
27-
artoolkitModuleUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/ARToolkit.js', // explicit ESM
28-
cameraParametersUrl: '/path/to/camera_para.dat', // optional override
29-
wasmBaseUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/', // optional; if your build needs it
30-
minConfidence: 0.6 // forward only confident detections
53+
artoolkitModuleUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/ARToolkit.js', // provide when using src/
54+
cameraParametersUrl: '/path/to/camera_para.dat',
55+
wasmBaseUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/', // optional; if your build requires it
56+
minConfidence: 0.6
3157
});
3258
```
3359

34-
CDN fallback (if you don’t serve node_modules):
35-
- Set `artoolkitModuleUrl` to a CDN ESM endpoint, e.g. a jsDelivr/UNPKG URL for the package’s ESM bundle.
60+
CDN fallback (for source/dev):
61+
- Set `artoolkitModuleUrl` to a CDN ESM endpoint (e.g., jsDelivr/UNPKG) for `@ar-js-org/artoolkit5-js`.
3662

3763
Notes:
3864
- The previous “loader.js” and manual WASM placement flow is no longer used.
39-
- If your ARToolKit build fetches auxiliary assets (WASM, data), set `wasmBaseUrl` accordingly.
65+
- In the `dist/` build, ARToolKit is bundled and `artoolkitModuleUrl` is NOT needed.
4066

4167
## Usage
4268

@@ -49,7 +75,7 @@ const plugin = new ArtoolkitPlugin({
4975
worker: true,
5076
lostThreshold: 5, // frames before a marker is considered lost
5177
frameDurationMs: 100, // expected ms per frame (affects lost timing)
52-
artoolkitModuleUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/ARToolkit.js',
78+
// artoolkitModuleUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/ARToolkit.js', // Only for src/dev
5379
cameraParametersUrl: '/data/camera_para.dat',
5480
minConfidence: 0.6
5581
});
@@ -114,7 +140,7 @@ const { markerId, size } = await plugin.loadMarker('/examples/simple-marker/data
114140

115141
A complete webcam-based example is available under `examples/simple-marker/`.
116142

117-
Serve from the repository root so that ES modules and node_modules paths resolve:
143+
Serve from the repository root so that `dist/` and example paths resolve:
118144

119145
```bash
120146
# From repository root
@@ -142,9 +168,9 @@ The example demonstrates:
142168
lostThreshold?: number; // Frames before 'lost' (default: 5)
143169
frameDurationMs?: number; // ms per frame (default: 200)
144170
sweepIntervalMs?: number; // Lost-sweep interval (default: 100)
145-
artoolkitModuleUrl?: string; // ESM URL for ARToolKit (recommended)
171+
artoolkitModuleUrl?: string; // Only needed when using source/dev; NOT needed for dist build
146172
cameraParametersUrl?: string;// Camera params file URL
147-
wasmBaseUrl?: string; // Base URL for ARToolKit assets (if required)
173+
wasmBaseUrl?: string; // Base URL for ARToolKit assets (if required by your build)
148174
minConfidence?: number; // Minimum confidence to forward getMarker (default: 0.6)
149175
}
150176
```
@@ -160,7 +186,10 @@ The example demonstrates:
160186

161187
## Troubleshooting
162188

163-
- “Failed to resolve module specifier” in the Worker:
189+
- Worker asset 404:
190+
- Ensure you import the ESM from `/dist/arjs-plugin-artoolkit.esm.js` and that `/dist/assets/worker-*.js` is served.
191+
- The build uses `base: './'`, so worker URLs are relative to the ESM file location.
192+
- “Failed to resolve module specifier” in the Worker (source/dev only):
164193
- Provide `artoolkitModuleUrl` or serve `/node_modules` from your dev server
165194
- Worker not starting:
166195
- Serve via HTTP/HTTPS; ensure ES modules and Workers are supported

examples/simple-marker/README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ npm install
1515
### 2. Serve the Example
1616

1717
You must serve from the repository root so that:
18-
- ES modules resolve (../../src/plugin.js)
19-
- The worker module URL (../../node_modules/...) is reachable
18+
- The built ESM (`/dist/arjs-plugin-artoolkit.esm.js`) and worker asset (`/dist/assets/worker-*.js`) resolve
19+
- Example paths under `/examples/simple-marker/` resolve
2020

2121
You can use any static file server. Examples:
2222

@@ -56,19 +56,26 @@ If you're using VS Code with the Live Server extension:
5656

5757
## Module resolution
5858

59-
The example config (in `index.html`) passes explicit URLs so the worker can import ARToolKit and camera params:
59+
When importing the built ESM from `dist/`, ARToolKit is bundled and no extra configuration is required:
6060

6161
```js
62+
import { ArtoolkitPlugin } from '/dist/arjs-plugin-artoolkit.esm.js';
63+
6264
const plugin = new ArtoolkitPlugin({
6365
worker: true,
64-
artoolkitModuleUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/ARToolkit.js',
6566
cameraParametersUrl: '/examples/simple-marker/data/camera_para.dat'
6667
});
6768
```
6869

69-
If your server can’t serve `/node_modules`, either:
70-
- Adjust `artoolkitModuleUrl` to a path your server exposes, or
71-
- Use a CDN ESM URL as a fallback (see project README for details)
70+
If you develop against `src/` instead, provide an explicit ARToolKit module URL:
71+
72+
```js
73+
const plugin = new ArtoolkitPlugin({
74+
worker: true,
75+
artoolkitModuleUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/ARToolkit.js',
76+
cameraParametersUrl: '/examples/simple-marker/data/camera_para.dat'
77+
});
78+
```
7279

7380
## What’s Happening
7481

@@ -93,10 +100,9 @@ The `data/patt.hiro` file is a standard ARToolKit pattern. You can replace it wi
93100
Key parts of the example:
94101

95102
```javascript
96-
// Create plugin instance with worker enabled and explicit module/params URLs
103+
// Create plugin instance with worker enabled (no artoolkitModuleUrl needed with dist)
97104
const plugin = new ArtoolkitPlugin({
98105
worker: true,
99-
artoolkitModuleUrl: '/node_modules/@ar-js-org/artoolkit5-js/dist/ARToolkit.js',
100106
cameraParametersUrl: '/examples/simple-marker/data/camera_para.dat'
101107
});
102108

@@ -113,9 +119,7 @@ console.log(`Marker loaded with ID: ${result.markerId}`);
113119

114120
- Worker not loading?
115121
- Ensure you’re serving via HTTP/HTTPS from the repository root (not `file://`)
116-
- Check console for module resolution/CORS errors
117-
- Module import errors?
118-
- Make sure `/node_modules/@ar-js-org/artoolkit5-js/dist/ARToolkit.js` is reachable, or use a CDN URL
122+
- Confirm `/dist/arjs-plugin-artoolkit.esm.js` and `/dist/assets/worker-*.js` are reachable
119123
- Marker not loading?
120124
- Verify the pattern file path is correct and accessible
121125
- Ensure the worker is ready before calling `loadMarker()`

examples/simple-marker/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ <h3>Event Log:</h3>
3333

3434
<!-- Only showing the <script type="module"> block; keep the rest unchanged -->
3535
<script type="module">
36-
import { ArtoolkitPlugin } from '../../dist/arjs-plugin-artoolkit.es.js';
36+
import { ArtoolkitPlugin } from '../../dist/arjs-plugin-artoolkit.esm.js';
3737

3838
const statusEl = document.getElementById('status');
3939
const logEl = document.getElementById('log');

vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default defineConfig({
88
entry: 'src/index.js',
99
name: 'ARjsPluginARtoolkit',
1010
fileName: (format) => `arjs-plugin-artoolkit.${format}.js`,
11-
formats: ['es'], // ESM-only build
11+
formats: ['esm'], // ESM-only build
1212
},
1313
rollupOptions: {
1414
output: {

0 commit comments

Comments
 (0)