- Docs
- Image tracking examples
Minimal
The smallest page that puts 3D content on an image: one target file, one box. Use it as the starting point of every other example.
Try it
Open the demos on a phone: the camera needs a secure page. Then point the camera at the picture below, shown on a second screen or printed.
A-Frame
One a-scene with the tempusxr component names the tracker and the target file. Content goes inside an entity marked tempusxr-image-target: it follows image number index, and hides when the image is lost.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<title>Minimal (A-Frame)</title>
<!-- A-Frame, Tempusxr and the image tracker, as plain script tags. -->
<script src="/node_modules/aframe/dist/aframe-v1.8.0.min.js"></script>
<script src="/packages/sdk-aframe/dist/index.umd.cjs"></script>
<script src="/packages/sdk-tracker-image/dist/index.umd.cjs"></script>
</head>
<body>
<!-- Show poster.png to the camera. The box sticks to the poster. -->
<a-scene
tempusxr="tracker: image; targets: /examples/poster-video/poster.txr"
renderer="alpha: true"
vr-mode-ui="enabled: false"
>
<a-camera></a-camera>
<a-entity tempusxr-image-target="index: 0">
<a-box position="0 0 0.15" scale="0.3 0.3 0.3" color="#fecb02"></a-box>
</a-entity>
</a-scene>
</body>
</html>
Three.js
create() builds the camera, the stage and the overlay. ar.use('image', ...) loads the target file and gives one anchor per image. ar.attach(anchor, object) makes an object follow that anchor.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<title>Minimal (Three.js)</title>
<!-- Three.js with the SDK, as a page without a bundler loads it. -->
<script type="importmap">
{
"imports": {
"three": "/node_modules/three/build/three.module.js",
"@tempusxr/sdk-core": "/packages/sdk-core/dist/index.js",
"@tempusxr/sdk-three": "/packages/sdk-three/dist/index.js",
"@tempusxr/sdk-tracker-image": "/packages/sdk-tracker-image/dist/index.js"
}
}
</script>
<style>
html,
body {
margin: 0;
height: 100%;
background: #111;
}
</style>
</head>
<body>
<!-- Show poster.png to the camera. The box sticks to the poster. -->
<div id="ar"></div>
<script type="module">
import * as THREE from 'three';
import { create } from '@tempusxr/sdk-three';
import '@tempusxr/sdk-tracker-image';
const ar = create({ container: '#ar' });
window.__ar = ar;
const tracker = await ar.use('image', { targets: ['/examples/poster-video/poster.txr'] });
// The anchor is the poster: 1 unit wide, centered, and +Z comes out of it toward you.
const box = new THREE.Mesh(
new THREE.BoxGeometry(0.3, 0.3, 0.3),
new THREE.MeshBasicMaterial({ color: '#fecb02' }),
);
box.position.z = 0.15;
const content = new THREE.Group();
content.add(box);
ar.attach(tracker.anchors[0], content);
await ar.start();
</script>
</body>
</html>
What to remember
- The anchor is the image: 1 unit wide, centered, and +Z comes out of it toward you. A box 0.3 wide is 30 percent of the image width.
- No overlay code is needed: the built-in interface shows the buttons and the error screens.
