Skip to content

Commit a1f78b3

Browse files
committed
scaffold ARToolKit plugin with initial setup and basic functionality
1 parent 71751d4 commit a1f78b3

File tree

9 files changed

+148
-1
lines changed

9 files changed

+148
-1
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-24.04
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version-file: .nvmrc
20+
cache: npm
21+
- name: Install
22+
run: npm ci
23+
- name: Run tests
24+
run: npm test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,6 @@ dist
137137
# Vite logs files
138138
vite.config.js.timestamp-*
139139
vite.config.ts.timestamp-*
140+
141+
# jetbrains IDEs files
142+
.idea/

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v22.21.1

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
# arjs-plugin-artoolkit
1+
# arjs-plugin-artoolkit
2+
```markdown
3+
# @ar-js-org/arjs-plugin-artoolkit
4+
5+
Minimal ARToolKit detection plugin scaffold for AR.js core.
6+
7+
## Usage
8+
9+
Register with the Engine plugin manager:
10+
11+
```js
12+
import { ArtoolkitPlugin } from '@ar-js-org/arjs-plugin-artoolkit';
13+
14+
engine.pluginManager.register('artoolkit', new ArtoolkitPlugin({ /* options */ }));
15+
await engine.pluginManager.enable('artoolkit');
16+
```
17+
18+
The plugin emits events on the engine event bus:
19+
- `ar:markerFound`
20+
- `ar:markerUpdated`
21+
- `ar:markerLost`
22+
23+
This repo contains a skeleton. Detection and worker/WASM integration will be implemented in follow-up work.
24+
```

package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@ar-js-org/arjs-plugin-artoolkit",
3+
"version": "0.1.0",
4+
"description": "ARToolKit detection plugin for AR.js core (ECS plugin)",
5+
"main": "dist/index.js",
6+
"module": "src/index.js",
7+
"type": "module",
8+
"scripts": {
9+
"build": "echo \"build step (none yet)\"",
10+
"test": "vitest",
11+
"lint": "eslint . --ext .js",
12+
"prepare": "husky install"
13+
},
14+
"keywords": [
15+
"arjs",
16+
"artoolkit",
17+
"ar",
18+
"plugin"
19+
],
20+
"author": "AR.js contributors",
21+
"license": "MIT",
22+
"devDependencies": {
23+
"eslint": "^9.39.0",
24+
"husky": "^9.1.7",
25+
"vitest": "^4.0.6"
26+
}
27+
}

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { ArtoolkitPlugin } from './plugin.js';
2+
export { convertModelViewToThreeMatrix } from './utils/matrix.js';

src/plugin.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Minimal ARToolKit plugin skeleton.
3+
* Conforms to the Engine Plugin contract: init(core), enable(), disable(), dispose()
4+
* Emits events via core.eventBus: 'ar:markerFound', 'ar:markerUpdated', 'ar:markerLost'
5+
*/
6+
export class ArtoolkitPlugin {
7+
constructor(options = {}) {
8+
this.options = options;
9+
this.core = null;
10+
this.enabled = false;
11+
this._onUpdate = null;
12+
}
13+
14+
async init(core) {
15+
this.core = core;
16+
// load resources if needed
17+
return this;
18+
}
19+
20+
async enable() {
21+
if (!this.core) throw new Error('Plugin not initialized');
22+
this.enabled = true;
23+
this._onUpdate = (payload) => this._onFrameUpdate(payload);
24+
this.core.eventBus.on('engine:update', this._onUpdate);
25+
return this;
26+
}
27+
28+
async disable() {
29+
this.enabled = false;
30+
if (this._onUpdate) this.core.eventBus.off('engine:update', this._onUpdate);
31+
return this;
32+
}
33+
34+
dispose() {
35+
return this.disable();
36+
}
37+
38+
_onFrameUpdate({ deltaTime, context }) {
39+
// stub: read frame from context/resources and run detection
40+
// when detection occurs, emit:
41+
// this.core.eventBus.emit('ar:markerFound', { id, poseMatrix, confidence, corners });
42+
}
43+
44+
getMarkerState(markerId) {
45+
return null;
46+
}
47+
}

src/utils/matrix.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// small set of conversion helpers for ARToolKit → Three.js coordinate conventions
2+
export function convertModelViewToThreeMatrix(modelViewArray) {
3+
// Input: Float32Array(16) from artoolkit (row-major or library-specific)
4+
// Output: Float32Array(16) ready to use with THREE.Matrix4.fromArray (column-major)
5+
// Concrete conversion will be implemented when integrating artoolkit5-js.
6+
const out = new Float32Array(16);
7+
for (let i = 0; i < 16; i++) out[i] = modelViewArray[i];
8+
return out;
9+
}

tests/matrix.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { convertModelViewToThreeMatrix } from '../src/utils/matrix.js';
3+
4+
describe('matrix utils', () => {
5+
it('returns a Float32Array of length 16', () => {
6+
const inArr = new Float32Array(16).fill(0);
7+
const out = convertModelViewToThreeMatrix(inArr);
8+
expect(out).toBeInstanceOf(Float32Array);
9+
expect(out.length).toBe(16);
10+
});
11+
});

0 commit comments

Comments
 (0)