- Docs
- Experience Library
- Business card
Business card Image tracking
Call, email and website buttons appear on the card.
Code
The code of this experience, split in the files you would keep: HTML, CSS and JavaScript. The live page keeps them in one file; copy each part into its own file and the page works the same.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<title>Tempusxr business card</title>
<!-- Plain HTML, no JavaScript framework: A-Frame, Tempusxr, the image tracker. Needs pnpm build. -->
<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>
<link rel="stylesheet" href="page.css" />
</head>
<body>
<!--
The interface is a block of HTML. Buttons that only make sense once the card is seen carry
data-tx-show="found". Open card.png on a screen (or print it), then point the camera at it.
-->
<div id="ui" class="tx-overlay">
<div data-tx-slot="top-left" class="pill" data-tx-show="found">Alex Martin</div>
<div data-tx-slot="top-right" class="tx-rail">
<button class="tx-btn" type="button" data-tx-action="info" aria-label="Help">?</button>
</div>
<div data-tx-slot="center" data-tx-show="scanning" class="pill">
Point the camera at the business card
</div>
<div data-tx-slot="bottom" class="contact" data-tx-show="found">
<button class="tx-cta" type="button" data-tx-action="call">Call</button>
<button class="tx-cta" type="button" data-tx-action="mail">Email</button>
<button class="tx-cta" type="button" data-tx-action="web">Website</button>
</div>
<div class="tx-modal" data-tx-modal="info" hidden>
<div class="tx-panel">
<button class="tx-close" type="button" data-tx-action="close" aria-label="Close">
x
</button>
<h2>Business card</h2>
<p>
Open <code>card.png</code> on a screen or print it, and point your camera at it. Buttons
to call, write or visit the website appear on top of the camera.
</p>
</div>
</div>
</div>
<a-scene
tempusxr="tracker: image; targets: card.txr; overlay: #ui"
renderer="alpha: true"
vr-mode-ui="enabled: false"
>
<a-camera
position="0 0 0"
look-controls="enabled: false"
wasd-controls="enabled: false"
></a-camera>
<a-light type="ambient" intensity="1"></a-light>
<a-entity tempusxr-image-target="index: 0">
<!-- A glow around the card, sized to the real card -->
<a-plane
tempusxr-image-plane
width="1"
height="0.57"
color="#fecb02"
opacity="0.18"
></a-plane>
<!-- A small badge floating above the top right corner -->
<a-circle position="0.42 0.2 0.12" radius="0.045" color="#fecb02"></a-circle>
<a-ring
position="0.42 0.2 0.125"
radius-inner="0.05"
radius-outer="0.06"
color="#ffffff"
></a-ring>
</a-entity>
</a-scene>
<script src="page.js"></script>
</body>
</html>
body {
margin: 0;
}
.pill {
padding: 6px 16px;
border-radius: 999px;
background: rgba(0, 0, 0, 0.55);
color: #fff;
font-weight: 700;
}
.contact {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 10px;
}
.contact .tx-cta {
flex: 1 1 8em;
min-width: 0;
}
const links = {
call: 'tel:+33612345678',
mail: 'mailto:alex@dreamxr.io',
web: 'https://dreamxr.io',
};
document.getElementById('ui').addEventListener('click', (event) => {
const action = event.target.closest('[data-tx-action]')?.dataset.txAction;
if (links[action]) window.open(links[action], '_self');
});
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<title>Tempusxr business card (Three.js)</title>
<!-- Three.js with the SDK, as a page without a bundler loads it. Needs pnpm build. -->
<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>
<link rel="stylesheet" href="page.css" />
</head>
<body>
<!--
The interface is a block of HTML. Buttons that only make sense once the card is seen carry
data-tx-show="found". Open card.png on a screen (or print it), then point the camera at it.
-->
<div id="ui" class="tx-overlay">
<div data-tx-slot="top-left" class="pill" data-tx-show="found">Alex Martin</div>
<div data-tx-slot="top-right" class="tx-rail">
<button class="tx-btn" type="button" data-tx-action="info" aria-label="Help">?</button>
</div>
<div data-tx-slot="center" data-tx-show="scanning" class="pill">
Point the camera at the business card
</div>
<div data-tx-slot="bottom" class="contact" data-tx-show="found">
<button class="tx-cta" type="button" data-tx-action="call">Call</button>
<button class="tx-cta" type="button" data-tx-action="mail">Email</button>
<button class="tx-cta" type="button" data-tx-action="web">Website</button>
</div>
<div class="tx-modal" data-tx-modal="info" hidden>
<div class="tx-panel">
<button class="tx-close" type="button" data-tx-action="close" aria-label="Close">
x
</button>
<h2>Business card</h2>
<p>
Open <code>card.png</code> on a screen or print it, and point your camera at it. Buttons
to call, write or visit the website appear on top of the camera.
</p>
</div>
</div>
</div>
<div id="ar"></div>
<script type="module" src="page.js"></script>
</body>
</html>
html,
body {
margin: 0;
height: 100%;
background: #111;
}
.pill {
padding: 6px 16px;
border-radius: 999px;
background: rgba(0, 0, 0, 0.55);
color: #fff;
font-weight: 700;
}
.contact {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 10px;
}
.contact .tx-cta {
flex: 1 1 8em;
min-width: 0;
}
import * as THREE from 'three';
import { create } from '@tempusxr/sdk-three';
import '@tempusxr/sdk-tracker-image';
const ar = create({
container: '#ar',
overlay: document.getElementById('ui'),
cameraOptions: { idealWidth: 640, idealHeight: 480 },
});
window.__ar = ar;
const tracker = await ar.use('image', { targets: ['/examples/business-card/card.txr'] });
const size = tracker.anchors[0]?.size ?? { width: 1, height: 0.57 };
const content = new THREE.Group();
content.add(new THREE.AmbientLight(0xffffff, 1.5));
// A glow around the card, sized to the real card.
content.add(
new THREE.Mesh(
new THREE.PlaneGeometry(size.width, size.height),
new THREE.MeshBasicMaterial({ color: '#fecb02', transparent: true, opacity: 0.18 }),
),
);
// A small badge floating above the top right corner.
const badge = new THREE.Mesh(
new THREE.CircleGeometry(0.045, 32),
new THREE.MeshBasicMaterial({ color: '#fecb02' }),
);
badge.position.set(0.42, 0.2, 0.12);
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.05, 0.06, 32),
new THREE.MeshBasicMaterial({ color: '#ffffff' }),
);
ring.position.set(0.42, 0.2, 0.125);
content.add(badge, ring);
ar.attach(tracker.anchors[0], content);
const links = {
call: 'tel:+33612345678',
mail: 'mailto:alex@dreamxr.io',
web: 'https://dreamxr.io',
};
document.getElementById('ui').addEventListener('click', (event) => {
const action = event.target.closest('[data-tx-action]')?.dataset.txAction;
if (links[action]) window.open(links[action], '_self');
});
await ar.start();
{
"version": 1,
"id": "business-card-scene",
"name": "Business card, as a scene file",
"tracker": {
"kind": "image",
"targets": [
{
"id": "card",
"file": "card.txr"
}
]
},
"assets": [
{
"id": "name",
"type": "text",
"text": "Alex Martin",
"color": "#fecb02",
"size": 0.09
}
],
"nodes": [
{
"id": "name-node",
"asset": "name",
"anchor": "card",
"position": [0, 0.42, 0.06]
}
],
"controls": [
{
"id": "call",
"type": "button",
"label": "Call"
},
{
"id": "mail",
"type": "button",
"label": "Email"
},
{
"id": "web",
"type": "button",
"label": "Website"
}
],
"behaviors": [
{
"on": "press",
"control": "call",
"do": "openUrl",
"url": "tel:+33612345678"
},
{
"on": "press",
"control": "mail",
"do": "openUrl",
"url": "mailto:alex@dreamxr.io"
},
{
"on": "press",
"control": "web",
"do": "openUrl",
"url": "https://dreamxr.io"
}
],
"meta": {
"title": "Business card",
"description": "Show card.png to the camera: buttons to call, write or visit the website."
}
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<title>Tempusxr scene</title>
<!-- A scene file, opened the way the Viewer opens it. Open ?scene=your.json to try another one. -->
<script type="importmap">
{
"imports": {
"three": "/node_modules/three/build/three.module.js",
"three/addons/": "/node_modules/three/examples/jsm/",
"@tempusxr/scene": "/packages/scene/dist/index.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",
"@tempusxr/sdk-tracker-world": "/packages/sdk-tracker-world/dist/index.js",
"@tempusxr/sdk-capture": "/packages/sdk-capture/dist/index.js",
"@tempusxr/ui": "/packages/ui/dist/index.js"
}
}
</script>
<link rel="stylesheet" href="page.css" />
</head>
<body>
<div id="ar"></div>
<div id="gate">
<div id="status">Loading...</div>
<button id="start" type="button" disabled>Start</button>
<div id="qr" hidden><span>Scan to open on your phone</span></div>
<div id="error"></div>
</div>
<script type="module" src="page.js"></script>
</body>
</html>
html,
body {
margin: 0;
height: 100%;
background: #111;
color: #fff;
font:
16px/1.5 system-ui,
sans-serif;
}
#gate {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-content: center;
gap: 14px;
padding: 24px;
text-align: center;
background: #111;
}
#gate[hidden] {
display: none;
}
#start {
padding: 14px 32px;
border: 0;
border-radius: 999px;
background: #fecb02;
color: #1b1b1b;
font: inherit;
font-weight: 700;
}
#start:disabled {
opacity: 0.4;
}
#qr {
display: grid;
justify-items: center;
gap: 6px;
color: #a49cb1;
font-size: 14px;
}
#qr[hidden] {
display: none;
}
#qr svg {
width: 168px;
height: 168px;
border-radius: 10px;
}
#error {
color: #ff7b6b;
white-space: pre-wrap;
}
import { loadScene } from '@tempusxr/sdk-three';
import '@tempusxr/sdk-tracker-image';
import '@tempusxr/sdk-tracker-world';
import { qrSvg } from '@tempusxr/ui';
import { addTestToggle } from '/examples/test-mode.js';
import { launchOnIphone } from '/examples/launch-ar.js';
addTestToggle(document.getElementById('gate'));
const status = document.getElementById('status');
const start = document.getElementById('start');
const sceneUrl = new URLSearchParams(location.search).get('scene') || 'scene.json';
const events = (window.__events = []);
// On a computer, show the QR code of this page, so a phone can scan it from the screen.
if (matchMedia('(pointer: fine)').matches) {
const box = document.getElementById('qr');
box.insertAdjacentHTML('afterbegin', qrSvg(location.href, { ecc: 'Q' }));
box.hidden = false;
}
try {
const experience = await loadScene(sceneUrl, {
container: '#ar',
onProgress: ({ loaded, total }) => (status.textContent = `Loading ${loaded} / ${total}`),
onEvent: (event) => events.push(event),
// Models with KTX2 textures need the Basis transcoder files.
decoders: {
basisPath: '/node_modules/three/examples/jsm/libs/basis/',
dracoPath: '/node_modules/three/examples/jsm/libs/draco/',
},
// ?analytics sends opened, found, tap and time events to the dev server, which prints them.
...(new URLSearchParams(location.search).has('analytics')
? { analytics: { endpoint: '/__analytics' } }
: {}),
});
window.__experience = experience;
// ?capture adds the photo and video shutter. Videos hold the sound of the scene and of the room
// (the phone asks for the microphone the first time).
if (new URLSearchParams(location.search).has('capture')) {
const { enableCapture } = await import('@tempusxr/sdk-capture');
window.__capture = enableCapture(experience, { microphone: true });
}
status.textContent = experience.scene.meta?.title ?? 'Ready';
start.disabled = false;
// The tap is what lets the phone play sound and video later.
start.addEventListener('click', async () => {
document.getElementById('gate').hidden = true;
await experience.start();
});
} catch (error) {
// A world scene on an iPhone: Safari has no WebXR, so Variant Launch opens it in an App Clip.
if (error.code === 'unsupported' && launchOnIphone()) status.textContent = 'Opening AR...';
else status.textContent = 'This experience could not be opened.';
const lines = [`${error.code ?? 'error'}: ${error.message}`];
for (const issue of error.issues ?? []) lines.push(`${issue.code} ${issue.path}`);
document.getElementById('error').textContent = lines.join('\n');
window.__loadError = { code: error.code, file: error.file, issues: error.issues };
}