Tempusxr Français
  1. Docs
  2. Experience Library
  3. Three files only

Three files only Image tracking

The smallest page: the engine of your choice, Tempusxr and one tracker. A yellow box sticks to the poster.

Open in A-FrameOpen in Three.jsBack to the Experience Library

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>Three files only (A-Frame)</title>
    <!-- Three files: A-Frame, Tempusxr for A-Frame, and the tracking you want (image here).
         Served from the CDN, the same lines read:
           https://cdn.jsdelivr.net/npm/aframe@1.8.0/dist/aframe.min.js
           https://tempusxr.vercel.app/v1/tempusxr-aframe.min.js
           https://tempusxr.vercel.app/v1/tempusxr-image.min.js -->
    <script src="/node_modules/aframe/dist/aframe-v1.8.0.min.js"></script>
    <script src="/release/tempusxr-aframe.min.js"></script>
    <script src="/release/tempusxr-image.min.js"></script>
    <link rel="stylesheet" href="page.css" />
  </head>
  <body>
    <!-- Show poster.png to the camera: a yellow box sticks to it. -->
    <a-scene
      tempusxr="tracker: image; targets: /examples/poster-video/poster.txr"
      renderer="alpha: true"
      vr-mode-ui="enabled: false"
    >
      <a-camera look-controls="enabled: false" wasd-controls="enabled: false"></a-camera>
      <a-light type="ambient" intensity="1.2"></a-light>
      <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>
body {
  margin: 0;
}
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
    <title>Three files only (Three.js)</title>
    <!-- Three files: Three.js, Tempusxr for Three.js, and the tracking you want (image here).
         "@tempusxr/sdk-core" and "@tempusxr/sdk-three" are the same file. "three/addons/" is read only by
         a scene with Draco or KTX2 compressed models. Served from the CDN, the lines read:
           https://cdn.jsdelivr.net/npm/three@0.187.0/build/three.module.js
           https://tempusxr.vercel.app/v1/tempusxr-three.esm.js
           https://tempusxr.vercel.app/v1/tempusxr-image.esm.js -->
    <script type="importmap">
      {
        "imports": {
          "three": "/node_modules/three/build/three.module.js",
          "three/addons/": "/node_modules/three/examples/jsm/",
          "@tempusxr/sdk-core": "/release/tempusxr-three.esm.js",
          "@tempusxr/sdk-three": "/release/tempusxr-three.esm.js"
        }
      }
    </script>
    <link rel="stylesheet" href="page.css" />
  </head>
  <body>
    <!-- Show poster.png to the camera: a yellow box sticks to it. -->
    <div id="ar"></div>
    <script type="module" src="page.js"></script>
  </body>
</html>
html,
body {
  margin: 0;
  height: 100%;
  background: #111;
}
import * as THREE from 'three';
import { create } from '@tempusxr/sdk-three';
import '/release/tempusxr-image.esm.js';

const ar = create({ container: '#ar' });
window.__ar = ar;
const tracker = await ar.use('image', { targets: ['/examples/poster-video/poster.txr'] });
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();

Open on your phone

Scan this code with the phone camera.

Open on this device