971176fc4f
- welcome: one-page menu (vitrine brand lockup, landing-size h1, controls grid with pad variant), pre-boot spinner veil - in-game: live colour + legs/rollers quickbar bottom-left, back button, big mode readout top-right, telemetry stack bottom-right (peers, speed, odometer, fps, ctrl rate) - ghosts: snapshot interpolation at 15 Hz replaces the exponential chase (no more micro-stutter, background tabs degrade gracefully) - modules landed with this batch: ceremony (entrance/respawn), fx (wireframe/glitch), controls stack, ball actor, comic stickers Co-authored-by: Cursor <cursoragent@cursor.com>
141 lines
5.4 KiB
HTML
141 lines
5.4 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>fx demo - glitch materialization</title>
|
|
<style>
|
|
html, body { margin: 0; height: 100%; background: #0b0d10; overflow: hidden; }
|
|
#app { position: fixed; inset: 0; }
|
|
#replay {
|
|
position: fixed; top: 16px; left: 16px; z-index: 10;
|
|
font: 700 13px/1 "SF Mono", ui-monospace, Menlo, monospace;
|
|
letter-spacing: 0.14em;
|
|
color: #ff7a2f; background: rgba(11, 13, 16, 0.85);
|
|
border: 1px solid #ff7a2f; border-radius: 4px;
|
|
padding: 10px 18px; cursor: pointer;
|
|
text-shadow: 0 0 8px rgba(255, 122, 47, 0.5);
|
|
}
|
|
#replay:hover { background: rgba(255, 122, 47, 0.15); box-shadow: 0 0 14px rgba(255, 122, 47, 0.35); }
|
|
#replay:active { transform: translateY(1px); }
|
|
#status {
|
|
position: fixed; bottom: 14px; left: 16px; z-index: 10;
|
|
font: 11px/1.4 ui-monospace, Menlo, monospace;
|
|
color: #3d4652; letter-spacing: 0.08em; user-select: none;
|
|
}
|
|
</style>
|
|
<script type="importmap">
|
|
{
|
|
"imports": {
|
|
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js",
|
|
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/"
|
|
}
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id="app"></div>
|
|
<button id="replay" type="button" aria-label="Replay the glitch materialization">REPLAY</button>
|
|
<div id="status">loading rig...</div>
|
|
<script type="module">
|
|
import * as THREE from "three";
|
|
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
|
|
import { RoomEnvironment } from "three/addons/environments/RoomEnvironment.js";
|
|
import { loadKinematics, buildRig, groundFullBody } from "../duck.js";
|
|
import { VARIANTS, materialHookFor } from "../variants.js";
|
|
import * as fx from "./fx-glitch.js";
|
|
|
|
const mount = document.getElementById("app");
|
|
const statusEl = document.getElementById("status");
|
|
|
|
const scene = new THREE.Scene();
|
|
scene.background = new THREE.Color(0x0b0d10);
|
|
|
|
const camera = new THREE.PerspectiveCamera(40, 1, 0.02, 30);
|
|
camera.position.set(0.42, 0.22, 0.5);
|
|
|
|
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
|
renderer.setPixelRatio(Math.min(2, window.devicePixelRatio));
|
|
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
|
mount.appendChild(renderer.domElement);
|
|
|
|
const pmrem = new THREE.PMREMGenerator(renderer);
|
|
scene.environment = pmrem.fromScene(new RoomEnvironment()).texture;
|
|
scene.environmentIntensity = 0.45;
|
|
|
|
// Same light rig as the live playground.
|
|
scene.add(new THREE.AmbientLight(0xffffff, 0.6));
|
|
const keyLight = new THREE.DirectionalLight(0xffffff, 1.6);
|
|
keyLight.position.set(2, 4, 2);
|
|
scene.add(keyLight);
|
|
const fill = new THREE.DirectionalLight(0xffffff, 0.4);
|
|
fill.position.set(-2, 2, 1.5);
|
|
scene.add(fill);
|
|
const rim = new THREE.DirectionalLight(0xffb366, 0.7);
|
|
rim.position.set(0, 3, -2);
|
|
scene.add(rim);
|
|
|
|
// Ground: dark disc + faint grid.
|
|
const ground = new THREE.Mesh(
|
|
new THREE.CircleGeometry(1.4, 64).rotateX(-Math.PI / 2),
|
|
new THREE.MeshStandardMaterial({ color: 0x11141a, roughness: 0.95, metalness: 0 }),
|
|
);
|
|
scene.add(ground);
|
|
const grid = new THREE.GridHelper(2.4, 48, 0x232a33, 0x161b22);
|
|
grid.position.y = 0.001;
|
|
scene.add(grid);
|
|
|
|
const controls = new OrbitControls(camera, renderer.domElement);
|
|
controls.enableDamping = true;
|
|
controls.target.set(0, 0.1, 0);
|
|
controls.minDistance = 0.15;
|
|
controls.maxDistance = 3;
|
|
|
|
function resize() {
|
|
const w = mount.clientWidth, h = mount.clientHeight;
|
|
camera.aspect = w / h;
|
|
camera.updateProjectionMatrix();
|
|
renderer.setSize(w, h);
|
|
}
|
|
window.addEventListener("resize", resize);
|
|
resize();
|
|
|
|
// ── Isolated duck rig (classic variant, standing pose) ────────────
|
|
// MODEL_DIR is page-relative ("./robot/mjlab") and resolves wrong from
|
|
// /fx/; mesh_dir inside the JSON is root-absolute so only this differs.
|
|
const k = await loadKinematics("../robot/mjlab/kinematics.json");
|
|
const rig = await buildRig(k, { materialForMesh: materialHookFor(VARIANTS.classic) });
|
|
groundFullBody(rig, 0);
|
|
scene.add(rig.placer);
|
|
|
|
// Aim the camera at the duck's actual center.
|
|
const box = new THREE.Box3().setFromObject(rig.placer);
|
|
const center = box.getCenter(new THREE.Vector3());
|
|
controls.target.copy(center);
|
|
|
|
fx.init({ THREE, scene, rig, camera, renderer });
|
|
statusEl.textContent = `fx: ${fx.name} | drag to orbit`;
|
|
|
|
document.getElementById("replay").addEventListener("click", () => fx.start());
|
|
|
|
// Debug hook for deterministic mid-effect screenshots.
|
|
window.fx = {
|
|
start: () => fx.start(),
|
|
setProgress: (p) => fx.setProgress(p),
|
|
isDone: () => fx.isDone(),
|
|
};
|
|
|
|
const clock = new THREE.Clock();
|
|
renderer.setAnimationLoop(() => {
|
|
const dt = Math.min(0.05, clock.getDelta());
|
|
fx.update(dt, clock.elapsedTime);
|
|
controls.update();
|
|
renderer.render(scene, camera);
|
|
});
|
|
|
|
// Auto-play once everything is loaded.
|
|
setTimeout(() => fx.start(), 500);
|
|
</script>
|
|
</body>
|
|
</html>
|