Skip to content

Commit 26a7a84

Browse files
committed
feat(build): configure Vite for ESM-only build and update dependencies
1 parent 75527aa commit 26a7a84

File tree

5 files changed

+234
-194
lines changed

5 files changed

+234
-194
lines changed

examples/simple-marker/index.html

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ <h3>Event Log:</h3>
3131

3232
<video id="video" autoplay playsinline></video>
3333

34+
<!-- Only showing the <script type="module"> block; keep the rest unchanged -->
3435
<script type="module">
35-
import { ArtoolkitPlugin } from '../../src/plugin.js';
36+
import { ArtoolkitPlugin } from '../../dist/arjs-plugin-artoolkit.es.js';
3637

3738
const statusEl = document.getElementById('status');
3839
const logEl = document.getElementById('log');
@@ -56,7 +57,6 @@ <h3>Event Log:</h3>
5657
if (type === 'error') statusEl.classList.add('error');
5758
}
5859

59-
// Minimal eventBus / core used by the plugin
6060
const eventBus = {
6161
_h: new Map(),
6262
on(e, h) { if (!this._h.has(e)) this._h.set(e, []); this._h.get(e).push(h); },
@@ -69,46 +69,43 @@ <h3>Event Log:</h3>
6969

7070
async function start() {
7171
try {
72-
log('Creating ArtoolkitPlugin instance...');
73-
plugin = new ArtoolkitPlugin({ worker: true,
74-
// ESM bundle path served by your dev server
75-
artoolkitModuleUrl: '../../node_modules/@ar-js-org/artoolkit5-js/dist/ARToolkit.js',
76-
cameraParametersUrl: "../../examples/simple-marker/data/camera_para.dat"
72+
log('Creating ArtoolkitPlugin instance (dist build)…');
73+
plugin = new ArtoolkitPlugin({
74+
worker: true,
75+
cameraParametersUrl: '/examples/simple-marker/data/camera_para.dat',
76+
// minConfidence: 0.6,
7777
});
7878
await plugin.init(core);
7979
await plugin.enable();
8080

81-
// wire event handlers
8281
eventBus.on('ar:workerReady', () => {
8382
log('Worker ready');
8483
setStatus('Worker ready. Start camera and then load marker.', 'success');
8584
loadMarkerBtn.disabled = false;
8685
});
8786

88-
eventBus.on('ar:markerFound', d => log(`markerFound: ${JSON.stringify(d)}`));
89-
eventBus.on('ar:markerUpdated', d => log(`markerUpdated: ${JSON.stringify(d)}`));
90-
eventBus.on('ar:markerLost', d => log(`markerLost: ${JSON.stringify(d)}`));
9187
eventBus.on('ar:workerError', e => {
9288
log(`workerError: ${JSON.stringify(e)}`);
9389
setStatus('Worker error (see console)', 'error');
9490
});
91+
9592
eventBus.on('ar:getMarker', (e) => console.log('[example] ar:getMarker', e));
93+
eventBus.on('ar:markerFound', d => log(`markerFound: ${JSON.stringify(d)}`));
94+
eventBus.on('ar:markerUpdated', d => log(`markerUpdated: ${JSON.stringify(d)}`));
95+
eventBus.on('ar:markerLost', d => log(`markerLost: ${JSON.stringify(d)}`));
9696

97-
// Also log detectionResult from plugin console.log (plugin logs detectionResult)
98-
setStatus('Plugin initialized. Waiting for worker...', 'normal');
97+
setStatus('Plugin initialized. Waiting for worker…', 'normal');
9998
} catch (err) {
10099
log('Init error: ' + (err && err.message ? err.message : err));
101100
setStatus('Initialization error', 'error');
102101
}
103102
}
104103

105-
// Start camera when user clicks (to ensure user gesture)
106104
startCamBtn.addEventListener('click', async () => {
107105
try {
108106
startCamBtn.disabled = true;
109-
log('Starting camera...');
107+
log('Starting camera');
110108
video.srcObject = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' } });
111-
// emit engine:update frames using createImageBitmap
112109
const canvas = document.createElement('canvas');
113110
const ctx = canvas.getContext('2d');
114111
let id = 0;
@@ -119,8 +116,7 @@ <h3>Event Log:</h3>
119116
canvas.height = video.videoHeight;
120117
ctx.drawImage(video, 0, 0);
121118
const imageBitmap = await createImageBitmap(canvas);
122-
// emit engine:update; plugin will transfer the ImageBitmap to the worker
123-
eventBus.emit('engine:update', { id: ++id, imageBitmap, width: canvas.width, height: canvas.height });
119+
core.eventBus.emit('engine:update', { id: ++id, imageBitmap, width: canvas.width, height: canvas.height });
124120
requestAnimationFrame(tick);
125121
}
126122
requestAnimationFrame(tick);
@@ -133,13 +129,11 @@ <h3>Event Log:</h3>
133129
}
134130
});
135131

136-
// Load marker button uses plugin.loadMarker(...)
137132
loadMarkerBtn.addEventListener('click', async () => {
138133
if (!plugin) return log('Plugin not ready');
139134
loadMarkerBtn.disabled = true;
140-
setStatus('Loading marker...', 'normal');
135+
setStatus('Loading marker', 'normal');
141136
try {
142-
// Use absolute/site-root-relative URL so worker can fetch it.
143137
const patternUrl = '/examples/simple-marker/data/patt.hiro';
144138
log(`Requesting loadMarker for ${patternUrl}`);
145139
const res = await plugin.loadMarker(patternUrl, 1);
@@ -153,7 +147,6 @@ <h3>Event Log:</h3>
153147
}
154148
});
155149

156-
// initialize plugin but don't start camera automatically
157150
start();
158151
</script>
159152
</body>

0 commit comments

Comments
 (0)