Download index.html from SAFWAAN/timewalk: direct link, hf CLI and curl.
- Browser
- Download file 5.28 kB
-
https://huggingface.co/spaces/SAFWAAN/timewalk/resolve/main/index.html
- Command line
-
hf download hf://spaces/SAFWAAN/timewalk/index.html
-
curl -L -o index.html https://huggingface.co/spaces/SAFWAAN/timewalk/resolve/main/index.html
5.28 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>Timewalk: walk into old photos of Calcutta</title> | |
| <meta name="description" content="Walkable 3D worlds made from public-domain photos of 19th-century Calcutta. Built on Vast.ai."> | |
| <style> | |
| :root { color-scheme: dark; } | |
| * { box-sizing: border-box; } | |
| html, body { margin: 0; height: 100%; background: #14110d; color: #f2e6cf; font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; } | |
| canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; } | |
| .bar { position: fixed; top: 16px; left: 16px; right: 16px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; pointer-events: none; } | |
| .bar > * { pointer-events: auto; } | |
| h1 { margin: 0 12px 0 0; font-size: 17px; font-weight: 650; letter-spacing: .02em; } | |
| button { font: inherit; color: inherit; background: rgba(20,17,13,.72); border: 1px solid rgba(242,230,207,.28); border-radius: 6px; padding: 6px 12px; cursor: pointer; } | |
| button[aria-pressed="true"] { background: #f2e6cf; color: #14110d; border-color: #f2e6cf; } | |
| .hint, .status { position: fixed; left: 16px; background: rgba(20,17,13,.72); border-radius: 6px; padding: 6px 10px; font-size: 13px; } | |
| .hint { bottom: 16px; } | |
| .status { bottom: 56px; } | |
| .status:empty { display: none; } | |
| .src { position: fixed; right: 16px; bottom: 16px; font-size: 12px; max-width: 46ch; text-align: right; background: rgba(20,17,13,.72); border-radius: 6px; padding: 6px 10px; } | |
| a { color: inherit; } | |
| .own { background: rgba(20,17,13,.72); border: 1px solid rgba(242,230,207,.28); border-radius: 6px; padding: 6px 12px; text-decoration: none; } | |
| </style> | |
| <script type="importmap"> | |
| { "imports": { | |
| "three": "./vendor/three/build/three.module.js", | |
| "three/addons/": "./vendor/three/examples/jsm/", | |
| "@sparkjsdev/spark": "./vendor/spark/spark.module.js" | |
| } } | |
| </script> | |
| </head> | |
| <body> | |
| <canvas id="view"></canvas> | |
| <div class="bar"> | |
| <h1>Timewalk</h1> | |
| <div id="worlds"></div> | |
| <button id="reset">Back to the photo's spot</button> | |
| <a class="own" href="https://github.com/safwaankira/timewalk#make-your-own-world" target="_blank" rel="noopener">Use your own photo</a> | |
| </div> | |
| <div class="status" id="status"></div> | |
| <div class="hint">WASD to walk · drag to look · R / F up and down · Shift faster</div> | |
| <div class="src" id="src"></div> | |
| <script type="module"> | |
| import * as THREE from "three"; | |
| import { SparkRenderer, SplatMesh, SparkControls } from "@sparkjsdev/spark"; | |
| let WORLDS = [ | |
| { slug: "old-court-house-1865", name: "Old Court House Street, 1865", | |
| credit: 'Samuel Bourne, "Calcutta. Old Court House Street", 1863–70. Cleveland Museum of Art, CC0.' }, | |
| { slug: "upper-chitpore-road-1890s", name: "Upper Chitpore Road, 1890s", | |
| credit: 'Photochrom after Dr. Kurt Boeck, "India. Calcutta. Upper Chitpore Road", c. 1890–1910. Cleveland Museum of Art, CC0.' }, | |
| ]; | |
| const $ = (id) => document.getElementById(id); | |
| const canvas = $("view"); | |
| const renderer = new THREE.WebGLRenderer({ canvas, antialias: false }); | |
| renderer.setPixelRatio(Math.min(devicePixelRatio, 2)); | |
| const scene = new THREE.Scene(); | |
| const camera = new THREE.PerspectiveCamera(70, 1, 0.01, 2000); | |
| scene.add(new SparkRenderer({ renderer })); | |
| const controls = new SparkControls({ canvas }); | |
| const rig = new THREE.Object3D(); | |
| rig.add(camera); | |
| scene.add(rig); | |
| let current = null; | |
| function resize() { | |
| renderer.setSize(innerWidth, innerHeight, false); | |
| camera.aspect = innerWidth / Math.max(1, innerHeight); | |
| camera.updateProjectionMatrix(); | |
| } | |
| addEventListener("resize", resize); | |
| resize(); | |
| function resetView() { rig.position.set(0, 0, 0); rig.quaternion.identity(); } | |
| async function show(w) { | |
| for (const b of $("worlds").children) b.setAttribute("aria-pressed", String(b.dataset.slug === w.slug)); | |
| $("src").textContent = w.credit; | |
| $("status").textContent = "Loading the world…"; | |
| if (current) { scene.remove(current); current.dispose?.(); current = null; } | |
| const base = `worlds/${w.slug}/`; | |
| let meta; | |
| try { meta = await (await fetch(base + "world.json")).json(); } | |
| catch { $("status").textContent = "This world isn't uploaded yet."; return; } | |
| const mesh = new SplatMesh({ url: base + "world.compressed.ply" }); | |
| if (meta.matrix) { | |
| mesh.matrixAutoUpdate = false; | |
| mesh.matrix.copy(new THREE.Matrix4().set(...meta.matrix.flat())); | |
| mesh.matrixWorldNeedsUpdate = true; | |
| } | |
| controls.fpsMovement.moveSpeed = Math.max(0.05, (meta.move_scale || 1) * 0.6); | |
| current = mesh; | |
| scene.add(mesh); | |
| resetView(); | |
| try { await mesh.initialized; $("status").textContent = ""; } | |
| catch (e) { $("status").textContent = "Couldn't load this world: " + e; } | |
| } | |
| try { | |
| const list = await (await fetch("worlds.json", { cache: "no-store" })).json(); | |
| if (Array.isArray(list) && list.length) WORLDS = list; | |
| } catch {} | |
| for (const w of WORLDS) { | |
| const b = document.createElement("button"); | |
| b.textContent = w.name; b.dataset.slug = w.slug; b.onclick = () => show(w); | |
| $("worlds").append(b, " "); | |
| } | |
| $("reset").onclick = resetView; | |
| renderer.setAnimationLoop(() => { controls.update(rig, camera); renderer.render(scene, camera); }); | |
| show(WORLDS[0]); | |
| </script> | |
| </body> | |
| </html> | |