This document provides instructions for AI coding assistants (Antigravity, Claude, Copilot, Cursor, etc.) working on Aframe-nft.
- Target branch is
dev:devis the active development branch. All Pull Requests must targetdev(notmain).mainis reserved for stable releases.
- Always branch off
origin/dev:- Never commit directly to
devormain. - Always update
devfirst (git checkout dev && git pull --ff-only origin dev) and create a new feature/fix branch:git checkout -b <type>-<short-description>
- Never commit directly to
- Conventional Commits:
- Every commit must strictly follow Conventional Commits:
feat: <description>(new feature)fix: <description>(bug fix)docs: <description>(documentation updates)test: <description>(adding or refactoring tests)refactor: <description>(code restructuring without behavioral change)chore: <description>(maintenance, dependencies, config)
- Reference issues in the commit message or body where appropriate (
Fixes #NN).
- Every commit must strictly follow Conventional Commits:
- GPG Signing:
- All commits must be GPG-signed (
git commit -Sor withcommit.gpgsign=true).
- All commits must be GPG-signed (
- Project Purpose:
Aframe-nftis a WebAR component library for A-Frame enabling markerless Natural Feature Tracking (NFT) image targets powered byjsartoolkitNFT. - Core Tech Stack:
- A-Frame (
1.8.0) @webarkit/jsartoolkit-nft(1.16.0)@webarkit/camera-view(0.1.0)@webarkit/oneeurofilter-ts(0.3.0)- Vite (
8.x), Vitest (5.x) +jsdom
- A-Frame (
- Key Modules (
src/):src/registerNFT.js: A-Frame glue:arnftsystem,nft-anchorcomponent, and<a-nft>primitive.src/markerRegistry.js: Bookkeeping for target URLs and reusable/shared target IDs (_targets,_inFlight,_byId). One loaded target per URL; multiple<a-nft>share one target ID.src/markerLoader.js: Loads target descriptor sets (.fset,.fset3,.iset, optional.zft) into the tracker.src/frames.js: Per-frame routing of tracker poses andlosttransitions to registered anchors.src/trackerFactory.js: Factory creating tracker on the same thread or in a Web Worker (worker: true), with automatic fallback.src/trackerSettings.js: Translates system attributes to jsartoolkitNFT tracker configuration.src/poseFilter.js&src/so3.js: 1€ pose smoothing with Lie group SO(3) rigid rotation math.src/nftMath.js: Marker centering, scaling, lift geometry, and matrix conversions.src/cameraConstraints.js: Maps idealvideoWidthandvideoHeightthrough CameraView.
- Separation of Concerns:
- Pure logic belongs in DOM-free modules in
src/and must be covered by unit tests intest/. - DOM/A-Frame interactions belong in
src/registerNFT.js.
- Pure logic belongs in DOM-free modules in
- Test-Driven Development (TDD):
- Always write failing tests first when fixing bugs or adding functionality.
- Run tests with:
npm test -- --run
- Bundle Generation (
dist/):dist/AframeNft.jsis committed in git and validated by CI.- Whenever any file in
src/is modified, you MUST rebuilddist/before committing:npm run build
- Windows CRLF / Git Status Guard:
- On Windows checkouts with
core.autocrlf,dist/NFTTracker*.jsfiles may appear modified ingit statusdue to CRLF/LF line ending differences even when there are no real content changes. - Verify with
git diff --ignore-space-at-eol -- dist/NFTTracker*.js. If the diff shows no real content change, restore them before committing:git checkout -- dist/NFTTracker*.js - If a dependency update or build produces genuine code changes in worker files, keep and commit them.
- On Windows checkouts with
- Examples & Routing:
- Examples reside under
examples/. Keep the index atexamples/index.html. - Do NOT create a root
index.html(it would cause Vite to return 200 on missing assets/descriptors instead of 404).
- Examples reside under
- One tracker per scene: AR tracking is managed at
<a-scene>level by thearnftsystem, never instantiated per<a-nft>. - One load per descriptor URL: Distinct
<a-nft>tags referencing the sameurlshare one tracker target ID and loaded dataset. - Anchor Lifecycle:
- Removing an
<a-nft>element unregisters it from the system and hides its mesh (onLost()). - Appending the same element again restores tracking on the entity's
loadedevent (_nftAnchorLoadedListener). - Changing
urlat runtime unregisters the old target, clears state, and registers the new URL.
- Removing an
- Visibility: Content stays hidden (
mesh.visible = false) until the first valid pose is applied. Poses are written directly inonPose()to avoid 1-frame latency.