- Documentation
- Bibliothèque d'expériences
- Points d'intérêt sur une image
Points d'intérêt sur une image Suivi d'images
Les mêmes points numérotés, sur un poster : une carte ou un schéma avec des étiquettes qui s'ouvrent au toucher.
Code
Le code de cette expérience, séparé en fichiers comme vous les garderiez : HTML, CSS et JavaScript. La page en ligne les garde dans un seul fichier ; copiez chaque partie dans son fichier et la page marche pareil.
<!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 file (A-Frame)</title>
<!-- A scene file drawn by an A-Frame scene. Open ?scene=your.json to try another one.
Order: A-Frame, Tempusxr for A-Frame, the trackers the scene needs, then the scene loader. -->
<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>
<script src="/packages/sdk-tracker-world/dist/index.umd.cjs"></script>
<script src="/packages/sdk-aframe/dist/scene.umd.cjs"></script>
<!-- Only used with ?capture: the photo and video buttons. -->
<script src="/packages/sdk-capture/dist/index.umd.cjs"></script>
<script src="/packages/sdk-aframe/dist/capture.umd.cjs"></script>
<link rel="stylesheet" href="page.css" />
</head>
<body>
<!-- That is the whole experience: the scene file says what to show, where, and what happens. -->
<a-scene
id="scene"
renderer="alpha: true"
vr-mode-ui="enabled: false"
device-orientation-permission-ui="enabled: false"
>
<a-camera look-controls="enabled: false" wasd-controls="enabled: false"></a-camera>
</a-scene>
<script src="page.js"></script>
</body>
</html>
body {
margin: 0;
}
// Relative to this folder: a host with clean URLs serves this page as /examples/scene/aframe/, one folder deeper.
const src = new URL(
new URLSearchParams(location.search).get('scene') || 'scene.json',
new URL('/examples/scene/', location.href),
).href;
const scene = document.getElementById('scene');
scene.setAttribute(
'tempusxr-scene',
`src: ${src}; dracoPath: /node_modules/three/examples/jsm/libs/draco/; basisPath: /node_modules/three/examples/jsm/libs/basis/`,
);
// ?capture adds the photo and video shutter: the picture, the 3D and the sound of the scene together.
if (new URLSearchParams(location.search).has('capture'))
scene.setAttribute('tempusxr-capture', 'video: true; microphone: true');
scene.addEventListener(
'tempusxr-scene-ready',
(event) => (window.__experience = event.detail),
);
<!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 file (Three.js)</title>
<!-- A scene file opened with loadScene from Three.js code. 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"
}
}
</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="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;
}
#error {
color: #ff7b6b;
white-space: pre-wrap;
}
import { loadScene } from '@tempusxr/sdk-three';
import '@tempusxr/sdk-tracker-image';
import '@tempusxr/sdk-tracker-world';
const status = document.getElementById('status');
// Relative to this folder: a host with clean URLs serves this page as /examples/scene/three/, one folder deeper.
const src = new URL(
new URLSearchParams(location.search).get('scene') || 'scene.json',
new URL('/examples/scene/', location.href),
).href;
try {
// One call: reads the file, loads the targets and assets, builds the 3D content, connects the behaviors.
const experience = await loadScene(src, {
container: '#ar',
onProgress: ({ loaded, total }) => (status.textContent = `Loading ${loaded} / ${total}`),
decoders: {
basisPath: '/node_modules/three/examples/jsm/libs/basis/',
dracoPath: '/node_modules/three/examples/jsm/libs/draco/',
},
});
window.__experience = experience;
// ?capture adds the photo and video shutter: the picture, the 3D and the sound of the scene together.
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';
const start = document.getElementById('start');
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) {
status.textContent = 'This experience could not be opened.';
document.getElementById('error').textContent = `${error.code ?? 'error'}: ${error.message}`;
}
{
"version": 1,
"id": "hotspots-on-an-image",
"name": "Hotspots on a poster",
"tracker": {
"kind": "image",
"targets": [
{
"id": "poster",
"file": "../poster-video/poster.txr"
}
]
},
"assets": [
{
"id": "picture",
"type": "image",
"src": "../poster-video/poster.png"
}
],
"nodes": [
{
"id": "poster-node",
"asset": "picture",
"anchor": "poster",
"fit": "image",
"position": [0, 0, 0.01],
"hotspots": [
{
"id": "sun",
"position": [0, 0.1, 0.02],
"title": "The sun",
"text": "Numbered points follow the picture."
},
{
"id": "title",
"position": [0, 0.38, 0.02],
"title": "The title",
"text": "Tap a number to read its label."
}
]
}
],
"meta": {
"title": "Hotspots on an image"
}
}
<!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 };
}