Tempusxr Français
Menu
  1. Docs
  2. Get started

Your first scene file

A scene file describes a whole experience in JSON: what to track, what to show on it, and what happens when people look at it or tap it. You write no JavaScript. The same file runs in A-Frame, in Three.js and in the Viewer.

1. Write the scene

Save this as scene.json. It tracks the starter poster, writes a title on it, and plays a clip on it.

{
  "version": 1,
  "id": "my-first-scene",
  "tracker": {
    "kind": "image",
    "targets": [{ "id": "poster", "file": "https://tempusxr.vercel.app/starter/poster.txr" }]
  },
  "assets": [
    { "id": "clip", "type": "video", "src": "https://tempusxr.vercel.app/starter/clip.mp4", "loop": true },
    { "id": "title", "type": "text", "text": "Hello AR", "color": "#fecb02", "size": 0.1 }
  ],
  "nodes": [
    { "id": "video", "asset": "clip", "anchor": "poster", "fit": "image", "position": [0, 0, 0.01] },
    { "id": "heading", "asset": "title", "anchor": "poster", "position": [0, 0.7, 0.05] }
  ],
  "behaviors": [
    { "on": "found", "target": "poster", "do": "play", "node": "video" },
    { "on": "lost", "target": "poster", "do": "pause", "node": "video" },
    { "on": "tap", "node": "heading", "do": "openUrl", "url": "https://dreamxr.io" }
  ]
}

Positions are in image widths: 1 is the width of the picture, and +Z comes out of the picture toward you.

2. Write the page

With A-Frame, one attribute opens the scene:

<script src="https://aframe.io/releases/1.8.0/aframe.min.js"></script>
<script src="https://tempusxr.vercel.app/v1/tempusxr-aframe.min.js"></script>
<script src="https://tempusxr.vercel.app/v1/tempusxr-image.min.js"></script>

<a-scene tempusxr-scene="src: scene.json" renderer="alpha: true" vr-mode-ui="enabled: false">
  <a-camera look-controls="enabled: false" wasd-controls="enabled: false"></a-camera>
</a-scene>

The page shows a loading line, then a Start button (a tap lets the phone play sound and video). With Three.js the same thing is one call, loadScene('scene.json', { container: '#ar' }): see Open a scene file with loadScene.

3. Put both files online and open the page on a phone

Put index.html and scene.json in one folder on any HTTPS host (see your first experience for the quickest ways), open the address on the phone, allow the camera, and point it at https://tempusxr.vercel.app/starter/poster.png on another screen.

What to try next