- Docs
- Image tracking examples
Multi-targets
One target file with several images, and different content on each. The page follows one image at a time, the one the camera sees.
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
Each tempusxr-image-target has an index: the position of the image in the .txr file (card, poster, art). Make the file with the image compiler, giving the images in that order.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<title>Multi-targets (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>
<!--
One .txr file with three images: card.png, poster.png and art.png (index 0, 1, 2).
Each image gets its own content. Only one is followed at a time (maxTrack defaults to 1).
-->
<a-scene
tempusxr="tracker: image; targets: /examples/tracking/multi.txr"
renderer="alpha: true"
vr-mode-ui="enabled: false"
>
<a-camera></a-camera>
<a-light type="ambient" intensity="0.9"></a-light>
<a-light type="directional" position="0.5 1 1" intensity="0.8"></a-light>
<a-entity tempusxr-image-target="index: 0">
<a-box position="0 0 0.12" scale="0.25 0.25 0.25" color="#fecb02"></a-box>
</a-entity>
<a-entity tempusxr-image-target="index: 1">
<a-sphere position="0 0 0.2" radius="0.18" color="#ff5e62"></a-sphere>
</a-entity>
<a-entity tempusxr-image-target="index: 2">
<a-cone
position="0 0 0.2"
rotation="90 0 0"
radius-bottom="0.15"
height="0.35"
color="#3d7a68"
></a-cone>
</a-entity>
</a-scene>
</body>
</html>
Three.js
tracker.anchors has one anchor per image, in file order. Attach a different group to each one.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<title>Multi-targets (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>
<!--
One .txr file with three images: card.png, poster.png and art.png (index 0, 1, 2).
Each image gets its own content. Only one is followed at a time (maxTrack defaults to 1).
-->
<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/tracking/multi.txr'] });
const shapes = [
// card.png: a box
[new THREE.BoxGeometry(0.25, 0.25, 0.25), '#fecb02', 0.12],
// poster.png: a sphere
[new THREE.SphereGeometry(0.18, 32, 16), '#ff5e62', 0.2],
// art.png: a cone
[new THREE.ConeGeometry(0.15, 0.35, 32).rotateX(Math.PI / 2), '#3d7a68', 0.2],
];
shapes.forEach(([geometry, color, lift], index) => {
const content = new THREE.Group();
content.add(new THREE.AmbientLight(0xffffff, 1.2));
const sun = new THREE.DirectionalLight(0xffffff, 1.5);
sun.position.set(0.5, 1, 1);
content.add(sun);
const mesh = new THREE.Mesh(geometry, new THREE.MeshStandardMaterial({ color }));
mesh.position.z = lift;
content.add(mesh);
ar.attach(tracker.anchors[index], content);
});
await ar.start();
</script>
</body>
</html>
What to remember
maxTrackdefaults to 1: the tracker follows one image at a time, which is the fastest setting.- The three images come from the finished examples, compiled together in
examples/tracking/multi.txr.


