- Docs
- Build with the SDK
Use it with Three.js
npm install @tempusxr/sdk-three @tempusxr/sdk-tracker-image three
Without npm, use the three-file page in Install the SDK.
import * as THREE from 'three';
import { create } from '@tempusxr/sdk-three';
import '@tempusxr/sdk-tracker-image'; // loading it registers the 'image' tracker
const ar = create({ container: '#ar' });
const tracker = await ar.use('image', { targets: ['/plan.txr'], maxTrack: 2 });
tracker.anchors.forEach((anchor) => {
const cube = new THREE.Mesh(new THREE.BoxGeometry(0.3, 0.3, 0.3), new THREE.MeshNormalMaterial());
ar.attach(anchor, cube);
});
ar.on('found', (anchor) => console.log('found', anchor.id));
ar.on('lost', (anchor) => console.log('lost', anchor.id));
await ar.start();
create(options)
| Option | Default | Meaning |
|---|---|---|
container | required | Element or selector. It is made full screen (fullscreen: false to keep your own layout). |
overlay | default | 'default', 'none' or your own element. |
language, labels | browser | 'fr' or 'en', and any text you want to replace. |
cameraOptions | 1280x720 | { facing, idealWidth, idealHeight, idealFrameRate }. Use 640x480 for image tracking. |
stage | { near, far, maxPixelRatio, createRenderer }. |
What you get back: ar.scene (a Three.js scene), ar.stage.camera, ar.ui (the overlay), ar.adjust (size and turn chosen with the buttons), attach(anchor, object), detach(object), use(kind, options), on(event, handler), start(), stop(), dispose().
Front camera. cameraOptions: { facing: 'user' } works: the video and the 3D canvas are mirrored together, like a mirror (content, text included, is mirrored too). The overlay is not mirrored.
Image tracker options (ar.use('image', options)): targets (a URL or bytes, or a list), maxTrack, warmupTolerance, missTolerance, smoothing ({ minCutOff, beta } or false).
An anchor is the pose of one image: id, kind, targetIndex, visible, matrix (4x4, column major, camera space, one array reused for the life of the anchor), size ({ width, height } in anchor units: width 1, height = image proportions), and events found, lost, update.