Prompt specification
Build or customize the Three.js 3D scene "School Relay Practice Track" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: School Relay Practice Track
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/school-relay-practice-track-x3635
Scene Description Prompt:
Build a small track with three original runners and visible exchange areas. Show sequence, timing, and baton ownership without requiring realistic musculoskeletal simulation. Use Three.js from cdnjs in a single HTML file, with visible voxel blocks.
Technical checks: Place the outgoing runner in the same exchange zone used by the incoming runner. Keep the baton transfer and runner motion continuous through the exchange.
Return one complete HTML document that works with the cdnjs Three.js r160 module inside a sandbox with scripts allowed. Make the requested subject visible at the default camera. Use procedural assets and local button handlers. Do not use native form submission, pointer lock, external assets or runtime requests other than Three.js.
Working Three.js Starter (school-relay-practice-track-x3635):
```html
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Relevo Voxel — Sequência, tempo e bastão</title>
<link rel="icon" href="data:,">
<style>
:root {
--bg: #07131f;
--panel: rgba(8, 22, 35, 0.88);
--panel-strong: rgba(9, 28, 44, 0.96);
--line: rgba(170, 218, 235, 0.18);
--text: #eef9fc;
--muted: #9db8c5;
--accent: #ffd166;
--cyan: #42e8d0;
--pink: #ff6b8a;
--purple: #9b7cff;
}
* {
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
border-radius: 16px;
}
#titlePanel {
top: 16px;
left: 16px;
width: min(390px, calc(100vw - 32px));
padding: 17px 18px 15px;
}
.eyebrow {
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 3px;
font-size: clamp(25px, 3vw, 36px);
line-height: 1;
letter-spacing: -0.04em;
}
.subtitle {
margin: 7px 0 13px;
color: var(--muted);
font-size: 13px;
}
.objective {
border-left: 3px solid var(--accent);
padding: 8px 10px;
background: rgba(255, 209, 102, 0.08);
color: #dcebf0;
font-size: 12px;
line-height: 1.45;
}
.objective strong {
display: block;
margin-bottom: 2px;
color: var(--text);
font-size: 11px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.panelActions {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 12px;
}
.smallButton, .controlButton, .checkpoint {
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.055);
border-radius: 9px;
padding: 8px 10px;
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}
.smallButton:hover, .controlButton:hover, .checkpoint:hover {
background: rgba(255, 255, 255, 0.12);
border-color: rgba(255, 209, 102, 0.55);
}
.smallButton:active, .controlButton:active, .checkpoint:active {
transform: translateY(1px);
}
#statusPanel {
top: 16px;
right: 16px;
width: min(330px, calc(100vw - 32px));
padding: 15px 16px;
}
.statusTop {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
}
#phase {
color: var(--accent);
font-size: 12px;
font-weight: 850;
letter-spacing: 0.12em;
}
#clock {
font-variant-numeric: tabular-nums;
font-size: 19px;
font-weight: 850;
letter-spacing: -0.03em;
}
.ownerRow {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
}
.ownerCaption {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#owner {
margin-top: 3px;
font-size: 17px;
font-weight: 900;
}
#ownerDot {
width: 15px;
height: 15px;
flex: 0 0 auto;
border-radius: 4px;
background: var(--accent);
box-shadow: 0 0 0 5px rgba(255, 209, 102, 0.1);
}
#stateCopy {
min-height: 54px;
margin: 12px 0 9px;
color: #d4e5eb;
font-size: 12px;
line-height: 1.45;
}
#timingNote {
color: var(--accent);
font-size: 11px;
font-weight: 750;
}
#auditResult {
margin-top: 11px;
border-radius: 9px;
padding: 9px 10px;
background: rgba(66, 232, 208, 0.08);
border: 1px solid rgba(66, 232, 208, 0.22);
color: #bdf9ef;
font-size: 11px;
line-height: 1.4;
}
#bottomPanel {
left: 50%;
bottom: 16px;
transform: translateX(-50%);
width: min(940px, calc(100vw - 32px));
padding: 13px 15px 14px;
}
.timelineControls {
display: flex;
align-items: center;
gap: 8px;
}
.controlButton {
min-height: 34px;
white-space: nowrap;
}
#playButton {
min-width: 84px;
color: #07131f;
background: var(--accent);
border-color: var(--accent);
}
#speedButton {
min-width: 66px;
}
#timeline {
--p: 12%;
flex: 1;
min-width: 80px;
height: 6px;
margin: 0 5px;
appearance: none;
border-radius: 999px;
background: linear-gradient(
to right,
var(--accent) 0%,
var(--accent) var(--p),
rgba(255, 255, 255, 0.13) var(--p),
rgba(255, 255, 255, 0.13) 100%
);
cursor: pointer;
}
#timeline::-webkit-slider-thumb {
width: 17px;
height: 17px;
appearance: none;
border: 3px solid #07131f;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 2px var(--accent);
}
#timeline::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #07131f;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 2px var(--accent);
}
.checkpointRow {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 6px;
margin-top: 9px;
}
.checkpoint {
padding: 5px 8px;
color: var(--muted);
background: transparent;
}
.checkpoint::before {
content: "";
display: inline-block;
width: 6px;
height: 6px;
margin-right: 6px;
border-radius: 2px;
background: var(--accent);
vertical-align: 1px;
}
.sequence {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-top: 10px;
}
.legCard {
position: relative;
min-height: 67px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 11px;
padding: 10px 11px 9px 45px;
background: rgba(255, 255, 255, 0.035);
text-align: left;
cursor: pointer;
transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}
.legCard:hover {
transform: translateY(-2px);
border-color: rgba(255, 255, 255, 0.32);
}
.legCard.active {
background: rgba(255, 209, 102, 0.1);
border-color: rgba(255, 209, 102, 0.62);
}
.legCard.done {
opacity: 0.62;
}
.legNumber {
position: absolute;
top: 10px;
left: 10px;
width: 26px;
height: 26px;
display: grid;
place-items: center;
border-radius: 7px;
color: #07131f;
background: var(--leg-color);
font-size: 13px;
font-weight: 950;
}
.legName {
display: block;
font-size: 13px;
font-weight: 900;
}
.legPath {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
line-height: 1.3;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 13px;
margin-top: 10px;
color: var(--muted);
font-size: 10px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.legend i {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 3px;
}
.legend .batonKey {
background: var(--accent);
box-shadow: 0 0 10px rgba(255, 209, 102, 0.5);
}
.legend .zoneKey {
border: 2px solid var(--cyan);
background: rgba(66, 232, 208, 0.15);
}
#cameraHint {
position: fixed;
z-index: 8;
left: 18px;
bottom: 170px;
color: rgba(220, 237, 243, 0.6);
font-size: 10px;
pointer-events: none;
}
@media (max-width: 820px) {
#titlePanel {
width: 280px;
padding: 13px 14px;
}
#statusPanel {
width: 270px;
padding: 12px 13px;
}
#titlePanel .objective,
#titlePanel .panelActions {
display: none;
}
#stateCopy {
min-height: 42px;
}
#bottomPanel {
padding: 10px;
}
.timelineControls {
flex-wrap: wrap;
}
#timeline {
order: 2;
flex-basis: 100%;
margin: 5px 0 0;
}
#cameraHint {
display: none;
}
}
@media (max-width: 620px) {
#titlePanel {
top: 8px;
left: 8px;
width: calc(55vw - 12px);
}
#statusPanel {
top: 8px;
right: 8px;
width: calc(45vw - 12px);
}
#titlePanel .subtitle,
#auditResult,
#timingNote {
display: none;
}
#clock {
font-size: 15px;
}
#phase {
font-size: 9px;
}
#owner {
font-size: 13px;
}
#stateCopy {
font-size: 10px;
min-height: 50px;
}
#bottomPanel {
bottom: 8px;
width: calc(100vw - 16px);
}
.sequence {
gap: 5px;
}
.legCard {
min-height: 62px;
padding: 8px 7px 7px 34px;
}
.legNumber {
left: 6px;
top: 8px;
width: 22px;
height: 22px;
}
.legName {
font-size: 11px;
}
.legPath {
font-size: 9px;
}
.legend {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Cena tridimensional de uma corrida de revezamento com três corredores e duas zonas de troca"></canvas>
<section id="titlePanel" class="panel">
<div class="eyebrow">Laboratório de revezamento</div>
<h1>RELEVO VOXEL</h1>
<p class="subtitle">3 corredores • 2 áreas de troca • 1 bastão</p>
<div class="objective">
<strong>Objetivo de aprendizagem</strong>
Identificar a sequência dos trechos, o tempo de cada passagem e quem possui o bastão.
</div>
<div class="panelActions">
<button id="resetCamera" class="smallButton" type="button">↺ Câmera padrão</button>
<button id="auditButton" class="smallButton" type="button">✓ Testar geometria</button>
</div>
</section>
<section id="statusPanel" class="panel" aria-live="polite">
<div class="statusTop">
<span id="phase">TRECHO 1</span>
<span id="clock">00:00.0 / 00:36.0</span>
</div>
<div class="ownerRow">
<div>
<div class="ownerCaption">Posse do bastão</div>
<div id="owner">LUMA</div>
</div>
<div id="ownerDot" aria-hidden="true"></div>
</div>
<p id="stateCopy"></p>
<div id="timingNote"></div>
<div id="auditResult">AUDITORIA: verificando posições e transferências…</div>
</section>
<section id="bottomPanel" class="panel">
<div class="timelineControls">
<button id="restartButton" class="controlButton" type="button">↺ Reiniciar</button>
<button id="playButton" class="controlButton" type="button">▶ Reproduzir</button>
<button id="speedButton" class="controlButton" type="button">1×</button>
<input id="timeline" type="range" min="0" max="36000" step="10" value="4200" aria-label="Linha do tempo da corrida">
</div>
<div class="checkpointRow" aria-label="Estados importantes">
<button class="checkpoint" type="button" data-time="0">Início</button>
<button class="checkpoint" type="button" data-time="10.5">Passe 1 · Zona 1</button>
<button class="checkpoint" type="button" data-time="23.5">Passe 2 · Zona 2</button>
<button class="button checkpoint" type="button" data-time="36">Final</button>
</div>
<div class="sequence" aria-label="Sequência dos corredores">
<button class="legCard active" type="button" data-time="5" style="--leg-color:#ff6b5f">
<span class="legNumber">1</span>
<span class="legName">LUMA</span>
<span class="legPath">Partida → Zona 1<br>entrega para Nix</span>
</button>
<button class="legCard" type="button" data-time="17" style="--leg-color:#42e8d0">
<span class="legNumber">2</span>
<span class="legName">NIX</span>
<span class="legPath">Zona 1 → Zona 2<br>entrega para Oro</span>
</button>
<button class="legCard" type="button" data-time="30" style="--leg-color:#ffd447">
<span class="legNumber">3</span>
<span class="legName">ORO</span>
<span class="legPath">Zona 2 → Final<br>leva o bastão</span>
</button>
</div>
<div class="legend">
<span><i class="batonKey"></i> bastão voxel</span>
<span><i class="zoneKey"></i> área de troca</span>
<span>Movimento esquemático, sem simulação biomecânica</span>
</div>
</section>
<div id="cameraHint">Arraste para orbitar • roda do mouse para zoom • botão para restaurar</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131f);
scene.fog = new THREE.Fog(0x07131f, 30, 58);
const camera = new THREE.PerspectiveCamera(44, window.innerWidth / window.innerHeight, 0.1, 100);
const controls = {
target: new THREE.Vector3(0, 1.0, 0),
radius: 29,
azimuth: 0.58,
elevation: 0.42,
dragging: false,
lastX: 0,
lastY: 0
};
function updateCamera() {
const horizontal = controls.radius * Math.cos(controls.elevation);
camera.position.set(
controls.target.x + horizontal * Math.sin(controls.azimuth),
controls.target.y + controls.radius * Math.sin(controls.elevation),
controls.target.z + horizontal * Math.cos(controls.azimuth)
);
camera.lookAt(controls.target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xbfefff, 0x15202c, 1.8);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0cf, 3.1);
sun.position.set(7, 16, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -19;
sun.shadow.camera.right = 19;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0005;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x54d9ff, 1.2);
rim.position.set(-12, 7, -10);
scene.add(rim);
const materialCache = new Map();
function getMaterial(color) {
const key = String(color);
if (!materialCache.has(key)) {
materialCache.set(key, new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.03
}));
}
return materialCache.get(key);
}
function box(w, h, d, color, x, y, z, parent = scene, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
getMaterial(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabelTexture(title, subtitle, accent) {
const c = document.createElement("canvas");
c.width = 512;
c.height = 144;
const ctx = c.getContext("2d");
ctx.fillStyle = "rgba(7, 19, 31, 0.94)";
ctx.fillRect(0, 0, c.width, c.height);
ctx.fillStyle = accent;
ctx.fillRect(0, 0, 12, c.height);
ctx.strokeStyle = "rgba(255,255,255,0.16)";
ctx.lineWidth = 4;
ctx.strokeRect(2, 2, c.width - 4, c.height - 4);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#f2fbfd";
ctx.font = "900 52px system-ui, sans-serif";
ctx.fillText(title, 262, subtitle ? 53 : 73);
if (subtitle) {
ctx.fillStyle = accent;
ctx.font = "800 24px system-ui, sans-serif";
ctx.fillText(subtitle, 262, 104);
}
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
return texture;
}
function makeLabelSprite(title, subtitle, accent, width = 2.3, height = 0.65) {
const material = new THREE.SpriteMaterial({
map: makeLabelTexture(title, subtitle, accent),
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, height, 1);
return sprite;
}
function makeFloorText(text, accent) {
const c = document.createElement("canvas");
c.width = 768;
c.height = 160;
const ctx = c.getContext("2d");
ctx.clearRect(0, 0, c.width, c.height);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "900 76px system-ui, sans-serif";
ctx.fillStyle = accent;
ctx.fillText(text, 384, 82);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
});
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(3.5, 0.73), material);
mesh.rotation.x = -Math.PI / 2;
return mesh;
}
const TRACK_Y = 0.52;
const START_X = -12.6;
const FINISH_X = 13.6;
const ZONE_1 = Object.freeze({ x: -3.0, z: 0 });
const ZONE_2 = Object.freeze({ x: 6.5, z: 0 });
const DURATION = 36;
// Pista voxel: base, faixa central e bordas em pequenos blocos.
box(44, 0.5, 18, 0x101c28, 0, -0.34, 0, scene, false);
box(30.2, 0.48, 6.8, 0x172736, 0, 0.12, 0);
box(29.7, 0.12, 2.9, 0x173746, 0, 0.40, 0, scene, false);
box(29.7, 0.08, 5.75, 0x112a37, 0, 0.37, 0, scene, false);
for (let i = 0; i < 33; i++) {
const x = -14.4 + i * 0.9;
const edgeColor = i % 2 === 0 ? 0xe8f2ed : 0xffb84d;
box(0.58, 0.19, 0.38, edgeColor, x, 0.48, 3.18, scene, false);
box(0.58, 0.19, 0.38, edgeColor, x, 0.48, -3.18, scene, false);
}
// Setas pixeladas indicando o sentido da corrida.
function addArrow(x, z, color) {
box(0.55, 0.055, 0.22, color, x, 0.49, z, scene, false);
box(0.34, 0.055, 0.22, color, x + 0.22, 0.49, z - 0.18, scene, false);
box(0.34, 0.055, 0.22, color, x + 0.22, 0.49, z + 0.18, scene, false);
}
addArrow(-9.2, -0.55, 0x8bd9e7);
addArrow(1.1, -0.55, 0x8bd9e7);
addArrow(10.8, -0.55, 0x8bd9e7);
// Linha de chegada em blocos alternados.
for (let ix = 0; ix < 2; ix++) {
for (let iz = 0; iz < 6; iz++) {
box(0.42, 0.07, 0.46, (ix + iz) % 2 ? 0xf4fbfc : 0x17212a,
13.35 + ix * 0.42, 0.49, -1.4 + iz * 0.46, scene, false);
}
}
function createExchangeZone(zone, index, accent) {
const group = new THREE.Group();
scene.add(group);
const tileColors = [0x173d49, 0x20515c, 0x18343f];
for (let ix = -2; ix <= 2; ix++) {
for (let iz = -2; iz <= 3; iz++) {
const color = tileColors[(ix + iz + 5) % tileColors.length];
box(0.60, 0.055, 0.70, color,
zone.x + ix * 0.62, 0.49, 0.15 + iz * 0.72,
group, false);
}
}
// Contorno voxel da área de troca.
box(0.13, 0.12, 4.35, accent, zone.x - 1.58, 0.55, 0.15, group, false);
box(0.13, 0.12, 4.35, accent, zone.x + 1.58, 0.55, 0.15, group, false);
box(3.28, 0.12, 0.13, accent, zone.x, 0.55, -2.03, group, false);
box(3.28, 0.12, 0.13, accent, zone.x, 0.55, 2.33, group, false);
// Balizas nos cantos traseiros.
const beaconMaterial = new THREE.MeshStandardMaterial({
color: accent,
emissive: accent,
emissiveIntensity: 0.7,
roughness: 0.45
});
for (const dx of [-1.58, 1.58]) {
const beacon = new THREE.Mesh(new THREE.BoxGeometry(0.28, 1.45, 0.28), beaconMaterial);
beacon.position.set(zone.x + dx, 1.12, -2.35);
beacon.castShadow = true;
group.add(beacon);
box(0.40, 0.18, 0.40, 0xf2fbfd, zone.x + dx, 1.88, -2.35, group, false);
}
const sign = makeLabelSprite(`ZONA ${index}`, `PASSE ${index}`, accent, 3.0, 0.84);
sign.position.set(zone.x, 3.15, -2.45);
group.add(sign);
const floorText = makeFloorText(`ZONA ${index}`, accent);
floorText.position.set(zone.x, 0.535, -1.24);
group.add(floorText);
// Pequeno bloco marca a posição de espera do receptor.
for (let i = -1; i <= 1; i++) {
box(0.30, 0.06, 0.30, accent, zone.x + i * 0.42, 0.54, 1.45, group, false);
}
}
createExchangeZone(ZONE_1, 1, "#42e8d0");
createExchangeZone(ZONE_2, 2, "#ff6b8a");
const startSign = makeLabelSprite("PARTIDA", "TRECHO 1", "#8bd9e7", 2.2, 0.65);
startSign.position.set(-13.2, 2.65, -2.55);
scene.add(startSign);
const finishSign = makeLabelSprite("FINAL", "TRECHO 3", "#ffd166", 2.1, 0.65);
finishSign.position.set(14.0, 2.75, -2.55);
scene.add(finishSign);
// Arquibancada voxel ao fundo.
box(12.5, 0.55, 2.0, 0x243747, 0, 0.25, -6.3);
box(12.5, 0.45, 1.25, 0x304b5b, 0, 0.72, -6.8);
box(12.5, 0.45, 1.05, 0x3b5968, 0, 1.15, -7.4);
const spectatorColors = [0xff6b5f, 0x42e8d0, 0xffd166, 0x9b7cff, 0x8bd9e7];
for (let i = 0; i < 18; i++) {
const row = i % 3;
const x = -5.3 + Math.floor(i / 3) * 1.65 + (row % 2) * 0.25;
const z = -6.4 - row * 0.55;
const y = 1.55 + row * 0.42;
box(0.42, 0.52, 0.40, spectatorColors[i % spectatorColors.length], x, y, z, scene, false);
box(0.33, 0.33, 0.33, 0xd39b76, x, y + 0.40, z, scene, false);
}
const runnerConfigs = {
LUMA: {
name: "LUMA",
shirt: 0xff6b5f,
shorts: 0xf7efd9,
skin: 0x8b4a32,
hair: 0x241921,
accent: "#ff6b5f",
phase: 0.0
},
NIX: {
name: "NIX",
shirt: 0x42e8d0,
shorts: 0x18324a,
skin: 0xd69b73,
hair: 0x12223b,
accent: "#42e8d0",
phase: 1.7
},
ORO: {
name: "ORO",
shirt: 0xffd447,
shorts: 0x7c4bd4,
skin: 0x71412e,
hair: 0x171923,
accent: "#ffd447",
phase: 3.4
}
};
function createVoxelRunner(config) {
const root = new THREE.Group();
scene.add(root);
const legL = new THREE.Group();
const legR = new THREE.Group();
legL.position.set(0, 0.82, -0.18);
legR.position.set(0, 0.82, 0.18);
root.add(legL, legR);
box(0.28, 0.70, 0.26, config.skin, 0, -0.34, 0, legL);
box(0.28, 0.70, 0.26, config.skin, 0, -0.34, 0, legR);
box(0.48, 0.17, 0.30, 0xf5f8f3, 0.12, -0.72, 0, legL);
box(0.48, 0.17, 0.30, 0xf5f8f3, 0.12, -0.72, 0, legR);
box(0.63, 0.25, 0.54, config.shorts, 0, 0.83, 0, root);
box(0.72, 0.82, 0.58, config.shirt, 0, 1.24, 0, root);
box(0.18, 0.76, 0.61, config.accent, 0, 1.24, 0, root);
box(0.58, 0.20, 0.42, config.skin, 0, 1.73, 0, root);
box(0.58, 0.58, 0.58, config.skin, 0, 1.98, 0, root);
box(0.63, 0.17, 0.63, config.hair, -0.02, 2.31, 0, root);
box(0.11, 0.12, 0.10, 0x121820, 0.305, 2.04, -0.15, root);
box(0.11, 0.12, 0.10, 0x121820, 0.305, 2.04, 0.15, root);
box(0.11, 0.11, 0.12, config.skin, 0.34, 1.91, 0, root);
const armL = new THREE.Group();
const armR = new THREE.Group();
armL.position.set(0, 1.53, -0.47);
armR.position.set(0, 1.53, 0.47);
root.add(armL, armR);
box(0.22, 0.57, 0.22, config.shirt, 0, -0.25, 0, armL);
box(0.22, 0.57, 0.22, config.shirt, 0, -0.25, 0, armR);
box(0.24, 0.19, 0.24, config.skin, 0, -0.61, 0, armL);
box(0.24, 0.19, 0.24, config.skin, 0, -0.61, 0, armR);
// Detalhes individuais para diferenciar os três corredores.
if (config.name === "LUMA") {
box(0.16, 0.13, 0.66, 0xffd166, 0.30, 2.23, 0, root);
box(0.12, 0.38, 0.66, config.hair, -0.27, 2.02, 0, root);
} else if (config.name === "NIX") {
box(0.38, 0.10, 0.65, 0x10283c, 0.35, 2.18, 0, root);
box(0.12, 0.36, 0.16, config.hair, -0.29, 2.00, -0.18, root);
} else {
box(0.24, 0.25, 0.28, config.hair, -0.13, 2.48, 0, root);
box(0.12, 0.34, 0.62, config.hair, -0.27, 2.01, 0, root);
}
const label = makeLabelSprite(config.name, "", config.accent, 1.55, 0.46);
label.position.set(0, 2.93, 0);
root.add(label);
root.userData.parts = { legL, legR, armL, armR };
return root;
}
const runnerObjects = {
LUMA: createVoxelRunner(runnerConfigs.LUMA),
NIX: createVoxelRunner(runnerConfigs.NIX),
ORO: createVoxelRunner(runnerConfigs.ORO)
};
// Bastão voxel amarelo, com extremidades brancas.
const baton = new THREE.Group();
scene.add(baton);
box(0.66, 0.15, 0.15, 0xffd447, 0, 0, 0, baton);
box(0.18, 0.17, 0.17, 0xf4fbfc, -0.42, 0, 0, baton);
box(0.18, 0.17, 0.17, 0xf4fbfc, 0.42, 0, 0, baton);
box(0.18, 0.17, 0.17, 0xff6b5f, 0.15, 0, 0, baton);
// Moldura de posse sob o corredor que está com o bastão.
const ownerHalo = new THREE.Group();
const haloMaterial = new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0xffd166,
emissiveIntensity: 0.45,
roughness: 0.55
});
box(1.50, 0.055, 0.075, 0xffd166, 0, 0, -0.56, ownerHalo, false);
box(1.50, 0.055, 0.075, 0xffd166, 0, 0, 0.56, ownerHalo, false);
box(0.075, 0.055, 1.20, 0xffd166, -0.71, 0, 0, ownerHalo, false);
box(0.075, 0.055, 1.20, 0xffd166, 0.71, 0, 0, ownerHalo, false);
ownerHalo.traverse(child => {
if (child.isMesh) child.material = haloMaterial;
});
scene.add(ownerHalo);
const clamp01 = x => Math.max(0, Math.min(1, x));
const smooth = x => {
const u = clamp01(x);
return u * u * (3 - 2 * u);
};
const lerp = (a, b, u) => a + (b - a) * u;
/*
Invariante central do modelo:
- Nix espera na Zona 1, no mesmo x do primeiro passe.
- Ao assumir o trecho 2, Nix começa na Zona 1 e segue para a Zona 2.
- Oro espera e recebe na Zona 2.
- Durante qualquer passe, o bastão permanece no x da zona da troca.
*/
function evaluateState(t) {
let phaseName;
let owner;
let ownerId;
let focusId;
let stateCopy;
let timingNote;
const luma = { x: START_X, z: 0, moving: true, waiting: false };
const nix = { x: ZONE_1.x, z: 1.35, moving: false, waiting: true };
const oro = { x: ZONE_2.x, z: 1.35, moving: false, waiting: true };
if (t < 10) {
const u = t / 10;
luma.x = lerp(START_X, ZONE_1.x, u);
luma.z = 0;
phaseName = "TRECHO 1";
owner = "LUMA";
ownerId = "LUMA";
focusId = "LUMA";
stateCopy = "Luma corre até a Zona 1. Nix já espera nessa mesma zona.";
timingNote = `Passe 1 em ${(10 - t).toFixed(1)} s`;
} else if (t < 11) {
const u = smooth((t - 10) / 1);
luma.x = ZONE_1.x;
luma.z = lerp(0, -0.75, u);
luma.moving = false;
nix.x = ZONE_1.x;
nix.z = lerp(1.35, 0.75, u);
phaseName = "PASSE 1 · ZONA 1";
owner = "LUMA → NIX";
ownerId = "TRANSFER_1";
focusId = "LUMA";
stateCopy = "Passe 1 na Zona 1: Luma entrega o bastão a Nix.";
timingNote = "Transferência 1: destinatário e entregador na Zona 1";
} else if (t < 23) {
const u = (t - 11) / 12;
luma.x = ZONE_1.x;
luma.z = -1.35;
luma.moving = false;
nix.x = lerp(ZONE_1.x, ZONE_2.x, u);
nix.z = lerp(0.75, 0, smooth(u / 0.08));
nix.moving = true;
nix.waiting = false;
phaseName = "TRECHO 2";
owner = "NIX";
ownerId = "NIX";
focusId = "NIX";
stateCopy = "Nix iniciou o segundo trecho na Zona 1 e segue até a Zona 2.";
timingNote = `Passe 2 em ${(23 - t).toFixed(1)} s`;
} else if (t < 24) {
const u = smooth((t - 23) / 1);
luma.x = ZONE_1.x;
luma.z = -1.35;
nix.x = ZONE_2.x;
nix.z = lerp(0, -0.75, u);
nix.moving = false;
oro.x = ZONE_2.x;
oro.z = lerp(1.35, 0.75, u);
phaseName = "PASSE 2 · ZONA 2";
owner = "NIX → ORO";
ownerId = "TRANSFER_2";
focusId = "NIX";
stateCopy = "Passe 2 na Zona 2: Nix entrega o bastão a Oro.";
timingNote = "Transferência 2: destinatário e entregador na Zona 2";
} else {
const u = (t - 24) / 12;
luma.x = ZONE_1.x;
luma.z = -1.35;
nix.x = ZONE_2.x;
nix.z = -1.35;
nix.moving = false;
oro.x = lerp(ZONE_2.x, FINISH_X, u);
oro.z = lerp(0.75, 0, smooth(u / 0.08));
oro.moving = true;
oro.waiting = false;
phaseName = "TRECHO 3";
owner = "ORO";
ownerId = "ORO";
focusId = "ORO";
stateCopy = "Oro assumiu o bastão na Zona 2 e corre até a final.";
timingNote = `Final em ${(DURATION - t).toFixed(1)} s`;
}
let batonState;
if (t < 10) {
batonState = {
x: luma.x,
z: luma.z - 0.58,
rotationY: 0
};
} else if (t < 11) {
const u = smooth((t - 10) / 1);
batonState = {
x: ZONE_1.x,
z: lerp(luma.z - 0.58, nix.z + 0.58, u),
rotationY: Math.PI / 2
};
} else if (t < 23) {
batonState = {
x: nix.x,
z: nix.z + 0.58,
rotationY: 0
};
} else if (t < 24) {
const u = smooth((t - 23) / 1);
batonState = {
x: ZONE_2.x,
z: lerp(nix.z + 0.58, oro.z + 0.58, u),
rotationY: Math.PI / 2
};
} else {
batonState = {
x: oro.x,
z: oro.z + 0.58,
rotationY: 0
};
}
return {
t,
phaseName,
owner,
ownerId,
focusId,
stateCopy,
timingNote,
runners: { LUMA: luma, NIX: nix, ORO: oro },
baton: batonState
};
}
function updateRunner(name, runnerState, state) {
const root = runnerObjects[name];
const config = runnerConfigs[name];
root.position.set(runnerState.x, TRACK_Y, runnerState.z);
const parts = root.userData.parts;
const stride = runnerState.moving
? Math.sin(state.t * 10.5 + config.phase) * 0.64
: 0;
parts.legL.rotation.z = stride;
parts.legR.rotation.z = -stride;
parts.armL.rotation.z = -stride * 0.72;
parts.armR.rotation.z = stride * 0.72;
if (runnerState.waiting) {
parts.legL.rotation.z = 0.06;
parts.legR.rotation.z = -0.04;
parts.armL.rotation.z = 0.05;
parts.armR.rotation.z = -0.05;
}
if (state.ownerId === "TRANSFER_1") {
if (name === "LUMA") parts.armR.rotation.z = -1.05;
if (name === "NIX") parts.armL.rotation.z = 0.95;
}
if (state.ownerId === "TRANSFER_2") {
if (name === "NIX") parts.armR.rotation.z = -1.05;
if (name === "ORO") parts.armL.rotation.z = 0.95;
}
}
function applyState(state) {
for (const name of Object.keys(runnerObjects)) {
updateRunner(name, state.runners[name], state);
}
const bob = state.runners[state.focusId].moving ? Math.sin(state.t * 12) * 0.035 : 0;
baton.position.set(state.baton.x, TRACK_Y + 1.10 + bob, state.baton.z);
baton.rotation.y = state.baton.rotationY;
const focus = state.runners[state.focusId];
ownerHalo.position.set(focus.x, TRACK_Y + 0.015, focus.z);
haloMaterial.color.set(runnerConfigs[state.focusId].accent);
haloMaterial.emissive.set(runnerConfigs[state.focusId].accent);
}
const timeline = document.getElementById("timeline");
const playButton = document.getElementById("playButton");
const speedButton = document.getElementById("speedButton");
const phaseElement = document.getElementById("phase");
const clockElement = document.getElementById("clock");
const ownerElement = document.getElementById("owner");
const ownerDot = document.getElementById("ownerDot");
const stateCopyElement = document.getElementById("stateCopy");
const timingNoteElement = document.getElementById("timingNote");
const auditResult = document.getElementById("auditResult");
const legCards = [...document.querySelectorAll(".legCard")];
let currentTime = 4.2;
let playing = !window.matchMedia("(prefers-reduced-motion: reduce)").matches;
let speed = 1;
function formatTime(seconds) {
const minutes = Math.floor(seconds / 60).toString().padStart(2, "0");
const remainder = (seconds % 60).toFixed(1).padStart(4, "0");
return `${minutes}:${remainder}`;
}
function updateUI(state) {
phaseElement.textContent = state.phaseName;
clockElement.textContent = `${formatTime(state.t)} / ${formatTime(DURATION)}`;
ownerElement.textContent = state.owner;
ownerDot.style.background = state.ownerId.startsWith("TRANSFER")
? "#ffd166"
: runnerConfigs[state.focusId].accent;
stateCopyElement.textContent = state.stateCopy;
timingNoteElement.textContent = state.timingNote;
timeline.value = Math.round(state.t * 1000);
const percentage = (state.t / DURATION) * 100;
timeline.style.setProperty("--p", `${percentage}%`);
playButton.textContent = playing ? "❚❚ Pausar" : "▶ Reproduzir";
speedButton.textContent = `${speed}×`;
const activeCard = state.t < 10 ? 0 : state.t < 23 ? 1 : 2;
legCards.forEach((card, index) => {
card.classList.toggle("active", index === activeCard);
card.classList.toggle("done", index === 0 ? state.t >= 11 : index === 1 ? state.t >= 24 : false);
});
}
function refresh() {
const state = evaluateState(currentTime);
applyState(state);
updateUI(state);
}
playButton.addEventListener("click", () => {
if (currentTime >= DURATION) currentTime = 0;
playing = !playing;
refresh();
});
document.getElementById("restartButton").addEventListener("click", () => {
currentTime = 0;
playing = false;
refresh();
});
speedButton.addEventListener("click", () => {
speed = speed === 1 ? 2 : speed === 2 ? 0.5 : 1;
refresh();
});
timeline.addEventListener("input", event => {
currentTime = Number(event.target.value) / 1000;
playing = false;
refresh();
});
document.querySelectorAll("[data-time]").forEach(button => {
button.addEventListener("click", () => {
currentTime = Number(button.dataset.time);
playing = false;
refresh();
});
});
/*
Auditoria sobre a geometria realmente aplicada aos objetos.
Ela força estados críticos, lê as posições dos runners e do bastão
e confirma que não há passagem entre zonas nem salto do receptor.
*/
function runGeometryAudit() {
const checks = [];
function inspect(time, check) {
const state = evaluateState(time);
applyState(state);
scene.updateMatrixWorld(true);
check(state);
}
inspect(5, () => {
const p = runnerObjects.NIX.position;
checks.push({
ok: Math.abs(p.x - ZONE_1.x) < 0.001 && Math.abs(p.z) <= 2,
text: "Nix espera na Zona 1"
});
});
inspect(10.5, () => {
const a = runnerObjects.LUMA.position;
const n = runnerObjects.NIX.position;
const b = baton.position;
checks.push({
ok:
Math.abs(a.x - ZONE_1.x) < 0.001 &&
Math.abs(n.x - ZONE_1.x) < 0.001 &&
Math.abs(b.x - ZONE_1.x) < 0.001 &&
Math.abs(b.x - ZONE_2.x) > 5,
text: "Passe 1 e bastão na Zona 1"
});
});
inspect(11.1, () => {
const p = runnerObjects.NIX.position;
checks.push({
ok:
p.x >= ZONE_1.x - 0.001 &&
p.x <= ZONE_1.x + 0.20 &&
Math.abs(p.x - ZONE_2.x) > 5,
text: "Nix inicia o trecho 2 na Zona 1, sem salto"
});
});
inspect(23.5, () => {
const n = runnerObjects.NIX.position;
const o = runnerObjects.ORO.position;
const b = baton.position;
checks.push({
ok:
Math.abs(n.x - ZONE_2.x) < 0.001 &&
Math.abs(o.x - ZONE_2.x) < 0.001 &&
Math.abs(b.x - ZONE_2.x) < 0.001,
text: "Passe 2 e bastão na Zona 2"
});
});
inspect(24.1, () => {
const p = runnerObjects.ORO.position;
checks.push({
ok:
p.x >= ZONE_2.x - 0.001 &&
p.x <= ZONE_2.x + 0.20 &&
Math.abs(p.x - ZONE_1.x) > 5,
text: "Oro inicia o trecho 3 na Zona 2, sem salto"
});
});
const passed = checks.filter(check => check.ok).length;
const allPassed = passed === checks.length;
auditResult.textContent = allPassed
? `AUDITORIA ${passed}/${checks.length} ✓ Zonas, bastão e posições de recepção coerentes.`
: `AUDITORIA ${passed}/${checks.length} ✕ ${checks.find(check => !check.ok)?.text || "Falha geométrica"}`;
auditResult.style.background = allPassed
? "rgba(66, 232, 208, 0.08)"
: "rgba(255, 107, 138, 0.10)";
auditResult.style.borderColor = allPassed
? "rgba(66, 232, 208, 0.22)"
: "rgba(255, 107, 138, 0.35)";
auditResult.style.color = allPassed ? "#bdf9ef" : "#ffc0ce";
checks.forEach(check => console.assert(check.ok, check.text));
refresh();
return checks;
}
document.getElementById("auditButton").addEventListener("click", runGeometryAudit);
// Controles de câmera implementados diretamente, sem addons.
function resetCamera() {
controls.radius = 29;
controls.azimuth = 0.58;
controls.elevation = 0.42;
controls.target.set(0, 1.0, 0);
updateCamera();
}
document.getElementById("resetCamera").addEventListener("click", resetCamera);
canvas.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.azimuth -= dx * 0.006;
controls.elevation = THREE.MathUtils.clamp(controls.elevation + dy * 0.004, 0.20, 0.88);
updateCamera();
});
function stopDragging(event) {
controls.dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("wheel", event => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.018,
18,
45
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("resize", () => {
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
});
runGeometryAudit();
refresh();
let previousTime = performance.now();
function animate(now) {
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing) {
currentTime += delta * speed;
if (currentTime >= DURATION) {
currentTime = DURATION;
playing = false;
}
}
refresh();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```