Skip to content

Commit 7834f8e

Browse files
committed
feat: refactor imports to use bundled library and enhance ECS core exports
1 parent 5e3c5fd commit 7834f8e

File tree

3 files changed

+41
-38
lines changed

3 files changed

+41
-38
lines changed

examples/minimal/app.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@
33
* Demonstrates the new ECS architecture with plugins
44
*/
55

6-
import { Engine } from '../../src/core/engine.js';
6+
/*import { Engine } from '../../src/core/engine.js';
77
import { CaptureSystem } from '../../src/systems/capture-system.js';
88
import { webcamPlugin } from '../../plugins/source/webcam.js';
99
import { videoPlugin } from '../../plugins/source/video.js';
1010
import { imagePlugin } from '../../plugins/source/image.js';
1111
import { defaultProfilePlugin } from '../../plugins/profile/default-policy.js';
12-
import { EVENTS, RESOURCES, SOURCE_TYPES } from '../../src/core/components.js';
12+
import { EVENTS, RESOURCES, SOURCE_TYPES } from '../../src/core/components.js';*/
13+
14+
import {
15+
Engine,
16+
CaptureSystem,
17+
webcamPlugin,
18+
videoPlugin,
19+
imagePlugin,
20+
defaultProfilePlugin,
21+
EVENTS,
22+
RESOURCES,
23+
SOURCE_TYPES,
24+
} from '../../dist/arjs-core.mjs';
1325

1426
// Create the engine
1527
const engine = new Engine();

examples/vite-artoolkit/main.js

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// Example: AR.js Core ECS + ArtoolkitPlugin with Start/Stop/Load buttons
2+
// Import everything from the bundled lib.
23

3-
import { Engine } from '../../src/core/engine.js';
4-
import { CaptureSystem } from '../../src/systems/capture-system.js';
5-
import { SOURCE_TYPES } from '../../src/core/components.js';
6-
import { FramePumpSystem } from '../../src/systems/frame-pump-system.js';
7-
8-
import { webcamPlugin } from '../../plugins/source/webcam.js';
9-
import { defaultProfilePlugin } from '../../plugins/profile/default-policy.js';
10-
import { imagePlugin as artookit } from '../../plugins';
4+
import {
5+
Engine,
6+
CaptureSystem,
7+
FramePumpSystem,
8+
SOURCE_TYPES,
9+
webcamPlugin,
10+
defaultProfilePlugin,
11+
} from '../../dist/arjs-core.mjs';
1112

1213
// UI
1314
const statusEl = document.getElementById('status');
@@ -26,21 +27,18 @@ function attachVideoToViewport(ctx) {
2627
if (!viewport) return;
2728

2829
try {
29-
// Detach from body if plugin appended it
3030
if (videoEl.parentNode && videoEl.parentNode !== viewport) {
3131
videoEl.parentNode.removeChild(videoEl);
3232
}
3333
} catch {}
3434

35-
// Ensure attributes optimal for inline playback
3635
try {
3736
videoEl.setAttribute('playsinline', '');
3837
videoEl.setAttribute('autoplay', '');
3938
videoEl.muted = true;
4039
videoEl.controls = false;
4140
} catch {}
4241

43-
// Override any offscreen styles the source plugin applied
4442
Object.assign(videoEl.style, {
4543
position: 'relative',
4644
top: '0px',
@@ -81,19 +79,19 @@ let cameraStarted = false;
8179
async function bootstrap() {
8280
engine = new Engine();
8381

84-
// Register core/source plugins
82+
// Register core/source plugins from the bundled lib
8583
engine.pluginManager.register(defaultProfilePlugin.id, defaultProfilePlugin);
8684
engine.pluginManager.register(webcamPlugin.id, webcamPlugin);
8785

88-
// Load ArtoolkitPlugin ESM from bundled vendor (ensure assets folder is present and served)
86+
// Load ArtoolkitPlugin ESM (local vendor or CDN)
8987
const mod = await import('./vendor/arjs-plugin-artoolkit/arjs-plugin-artoolkit.esm.js');
9088
const ArtoolkitPlugin = mod.ArtoolkitPlugin || mod.default;
9189

9290
// Set up UI listeners BEFORE enable to avoid missing early 'ready'
9391
engine.eventBus.on('ar:workerReady', () => {
9492
log('Worker ready');
9593
setStatus('Worker ready. You can start the webcam and load the marker.', 'success');
96-
loadBtn.disabled = false; // allow loading even before camera (matches minimal example)
94+
loadBtn.disabled = false;
9795
});
9896
engine.eventBus.on('ar:workerError', (e) => {
9997
log(`workerError: ${JSON.stringify(e)}`);
@@ -109,13 +107,11 @@ async function bootstrap() {
109107
await engine.pluginManager.enable(defaultProfilePlugin.id, ctx);
110108
await engine.pluginManager.enable(webcamPlugin.id, ctx);
111109

112-
// Create ARToolKit plugin and wire it EXPLICITLY to this engine context
110+
// Create ARToolKit plugin and wire it to this engine context
113111
artoolkit = new ArtoolkitPlugin({
114112
cameraParametersUrl: '/examples/vite-artoolkit/data/camera_para.dat',
115113
minConfidence: 0.6,
116114
});
117-
118-
// IMPORTANT: bind to engine context so events go to engine.eventBus
119115
await artoolkit.init(ctx);
120116
await artoolkit.enable();
121117

@@ -129,17 +125,6 @@ async function bootstrap() {
129125
loadBtn.disabled = false;
130126
} else {
131127
setStatus('Plugin initialized. Waiting for worker…', 'normal');
132-
// Tiny watchdog in case the ready event is missed due to external wiring
133-
const t0 = Date.now();
134-
const iv = setInterval(() => {
135-
if (artoolkit.workerReady) {
136-
loadBtn.disabled = false;
137-
setStatus('Worker ready. You can start the webcam and load the marker.', 'success');
138-
clearInterval(iv);
139-
} else if (Date.now() - t0 > 5000) {
140-
clearInterval(iv);
141-
}
142-
}, 100);
143128
}
144129

145130
// UI initial state
@@ -223,7 +208,6 @@ async function loadMarker() {
223208
log('loadMarker failed: ' + (err?.message || err));
224209
setStatus('Failed to load marker', 'error');
225210
} finally {
226-
// Re-enable for retry/replace
227211
loadBtn.disabled = false;
228212
}
229213
}

src/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
// Public entry for the AR.js Core library.
2-
// Re-export the modules you want consumers to import from 'ar.js-core'.
3-
4-
// Core
1+
// New ECS Core exports
52
export { Engine } from './core/engine.js';
6-
export { PluginManager } from './core/plugin-manager.js';
3+
export { ECS } from './core/ecs.js';
74
export { EventBus } from './core/event-bus.js';
8-
export * as Components from './core/components.js';
5+
export { PluginManager } from './core/plugin-manager.js';
6+
export {
7+
COMPONENTS,
8+
RESOURCES,
9+
EVENTS,
10+
CAPTURE_STATES,
11+
SOURCE_TYPES,
12+
DEVICE_PROFILES,
13+
QUALITY_TIERS,
14+
} from './core/components.js';
915

1016
// Systems
1117
export { CaptureSystem } from './systems/capture-system.js';
18+
export { FramePumpSystem } from './systems/frame-pump-system.js';
1219

13-
// Source plugins
20+
// Source plugins (exposed for examples/consumers)
1421
export { webcamPlugin } from '../plugins/source/webcam.js';
1522
export { videoPlugin } from '../plugins/source/video.js';
1623
export { imagePlugin } from '../plugins/source/image.js';

0 commit comments

Comments
 (0)