Prompt specification
Build or customize the Three.js 3D scene "Traditional toy fair corner" 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: Traditional toy fair corner
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/traditional-toy-fair-corner-x0379
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a spinning top. Compose a tabletop fair with spinning tops, hoops, and carved toys; a demonstrator launches one top while visitors compare distinct silhouettes and motion patterns. Voxel style.
Working Three.js Starter (traditional-toy-fair-corner-x0379):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#efe0bd">
<title>The Whirl Fair — Voxel Spinning Top Demonstrator</title>
<style>
:root {
--ink: #38291f;
--paper: #fff5d9;
--paper-2: #f7e7bd;
--red: #d9573f;
--red-dark: #9f352a;
--teal: #327f78;
--gold: #e4ad3d;
--blue: #416e9b;
--muted: #766553;
--line: #3b2b21;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eadbb8;
color: var(--ink);
font-family: "Courier New", Courier, monospace;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
background:
radial-gradient(circle at 48% 42%, #fff8df 0%, #eadbb8 66%, #d9c69f 100%);
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
image-rendering: pixelated;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: rgba(255, 247, 222, 0.95);
border: 3px solid var(--line);
box-shadow: 6px 6px 0 rgba(56, 41, 31, 0.88);
}
.brand {
top: 22px;
left: 22px;
width: min(430px, calc(100vw - 390px));
padding: 17px 19px 16px;
transform: rotate(-0.6deg);
}
.brand::before {
content: "";
position: absolute;
top: -10px;
left: 17px;
width: 78px;
height: 18px;
background: var(--red);
border: 2px solid var(--line);
transform: rotate(2deg);
}
.eyebrow {
margin: 0 0 7px;
color: var(--red-dark);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(27px, 3vw, 44px);
line-height: 0.95;
letter-spacing: -0.08em;
text-transform: uppercase;
}
.brand p:last-child {
max-width: 350px;
margin: 11px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.controls {
top: 22px;
right: 22px;
width: 330px;
padding: 17px;
}
.controls-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 15px;
}
.controls-heading h2 {
margin: 0;
font-size: 15px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.ticket-no {
padding: 4px 7px;
border: 2px solid var(--line);
background: var(--gold);
font-size: 10px;
font-weight: 700;
}
.section-label {
margin: 14px 0 8px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.choices {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.choice {
position: relative;
min-height: 58px;
padding: 9px 8px 8px;
overflow: hidden;
color: var(--ink);
text-align: left;
background: var(--paper-2);
border: 2px solid var(--line);
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease,
box-shadow 120ms ease;
}
.choice:hover {
transform: translateY(-2px);
background: #fff8e8;
}
.choice.active {
background: var(--accent, var(--gold));
box-shadow: inset 0 -5px 0 rgba(56, 41, 31, 0.16);
transform: translateY(-2px);
}
.choice::after {
content: "";
position: absolute;
right: 6px;
bottom: 6px;
width: 8px;
height: 8px;
background: var(--accent, var(--ink));
border: 1px solid var(--line);
opacity: 0.35;
}
.choice strong {
display: block;
margin-bottom: 4px;
font-size: 11px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.choice span {
display: block;
max-width: 120px;
color: var(--muted);
font-size: 9px;
line-height: 1.25;
}
.choice.active span {
color: rgba(56, 41, 31, 0.78);
}
.readout {
display: grid;
grid-template-columns: repeat(3, 1fr);
margin-top: 15px;
border: 2px solid var(--line);
background: #f4e3b8;
}
.readout div {
padding: 8px 5px 7px;
text-align: center;
border-right: 1px solid rgba(56, 41, 31, 0.28);
}
.readout div:last-child {
border-right: 0;
}
.readout small {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.13em;
}
.readout strong {
display: block;
font-size: 10px;
white-space: nowrap;
}
.launch {
position: fixed;
z-index: 12;
left: 50%;
bottom: 24px;
display: flex;
align-items: center;
gap: 14px;
min-width: 260px;
padding: 0;
color: #fff7de;
background: var(--red);
border: 3px solid var(--line);
box-shadow: 7px 7px 0 rgba(56, 41, 31, 0.9);
cursor: pointer;
transform: translateX(-50%) rotate(0.5deg);
transition:
transform 120ms ease,
background 120ms ease;
}
.launch:hover {
background: #e5654b;
transform: translateX(-50%) translateY(-3px) rotate(0.5deg);
}
.launch:active {
transform: translateX(-50%) translateY(3px);
box-shadow: 3px 3px 0 rgba(56, 41, 31, 0.9);
}
.launch.is-live {
background: var(--teal);
}
.launch-icon {
display: grid;
place-items: center;
width: 57px;
align-self: stretch;
background: var(--gold);
color: var(--ink);
border-right: 3px solid var(--line);
font-size: 25px;
font-weight: 700;
}
.launch-copy {
padding: 13px 18px 13px 0;
text-align: left;
}
.launch-copy strong {
display: block;
font-size: 14px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.launch-copy small {
display: block;
margin-top: 4px;
color: rgba(255, 247, 222, 0.82);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.hint {
position: fixed;
z-index: 8;
left: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px 11px;
color: #efe2c3;
background: rgba(56, 41, 31, 0.83);
border: 1px solid rgba(255, 245, 217, 0.24);
font-size: 9px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.hint b {
color: var(--gold);
font-size: 14px;
}
.corner-note {
position: fixed;
z-index: 5;
right: 28px;
bottom: 24px;
color: rgba(56, 41, 31, 0.55);
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
writing-mode: vertical-rl;
}
@media (max-width: 820px) {
.brand {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.brand p:last-child {
display: none;
}
h1 {
font-size: 28px;
}
.controls {
top: auto;
right: 12px;
bottom: 12px;
width: min(330px, calc(100vw - 24px));
padding: 12px;
}
.controls-heading {
margin-bottom: 9px;
}
.section-label {
margin-top: 9px;
}
.choice {
min-height: 49px;
padding: 7px;
}
.choice span {
display: none;
}
.readout {
margin-top: 10px;
}
.launch {
top: 128px;
bottom: auto;
left: 50%;
min-width: 220px;
}
.launch-copy {
padding: 10px 13px 10px 0;
}
.launch-icon {
width: 48px;
}
.hint,
.corner-note {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive voxel tabletop fair"></div>
<header class="brand panel">
<p class="eyebrow">Tabletop No. 07 · Voxel Play Fair</p>
<h1>The Whirl Fair</h1>
<p>
Compare carved silhouettes, choose a motion pattern, and watch the
demonstrator launch a champion through the miniature competition table.
</p>
</header>
<aside class="controls panel" aria-label="Fair controls">
<div class="controls-heading">
<h2>Compare the Spin</h2>
<span class="ticket-no">PASS 07</span>
</div>
<p class="section-label">01 · Choose a silhouette</p>
<div class="choices" id="silhouetteChoices">
<button class="choice active" data-silhouette="0" style="--accent:#d9573f">
<strong>Penny</strong>
<span>Wide belly, quick gyre</span>
</button>
<button class="choice" data-silhouette="1" style="--accent:#327f78">
<strong>Comet</strong>
<span>Long tail, bright orbit</span>
</button>
<button class="choice" data-silhouette="2" style="--accent:#9b643c">
<strong>Acorn</strong>
<span>Low, sturdy glider</span>
</button>
<button class="choice" data-silhouette="3" style="--accent:#416e9b">
<strong>Crown</strong>
<span>Tall handle, sharp spiral</span>
</button>
</div>
<p class="section-label">02 · Choose a motion</p>
<div class="choices" id="motionChoices">
<button class="choice active" data-motion="0" style="--accent:#e4ad3d">
<strong>Glide</strong>
<span>Wide, measured oval</span>
</button>
<button class="choice" data-motion="1" style="--accent:#d9573f">
<strong>Orbit</strong>
<span>Slow perimeter sweep</span>
</button>
<button class="choice" data-motion="2" style="--accent:#327f78">
<strong>Spiral</strong>
<span>Fast tightening turns</span>
</button>
</div>
<div class="readout" aria-live="polite">
<div>
<small>SPIN</small>
<strong id="rpm">0 RPM</strong>
</div>
<div>
<small>WOBBLE</small>
<strong id="wobble">0.6°</strong>
</div>
<div>
<small>STATE</small>
<strong id="stateText">READY</strong>
</div>
</div>
</aside>
<button class="launch" id="launchButton" aria-label="Launch the selected spinning top">
<span class="launch-icon">↻</span>
<span class="launch-copy">
<strong id="launchLabel">Launch the Top</strong>
<small id="launchSub">Penny · Glide pattern</small>
</span>
</button>
<div class="hint"><b>↔</b> Drag to orbit · Scroll to zoom</div>
<div class="corner-note">Hand-carved voxel curiosities · Fairground edition</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const container = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: false,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 0.85));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeadbb8);
scene.fog = new THREE.Fog(0xeadbb8, 33, 65);
const camera = new THREE.OrthographicCamera(-15, 15, 10, -10, 0.1, 100);
const cameraTarget = new THREE.Vector3(-0.5, 1.9, -0.25);
let cameraYaw = 0.61;
let cameraPitch = 0.67;
let cameraZoom = 1.15;
const cameraRadius = 27;
const hemi = new THREE.HemisphereLight(0xfff2c9, 0x6e5846, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff4d5, 3.15);
sun.position.set(-10, 17, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.00045;
scene.add(sun);
const warmFill = new THREE.DirectionalLight(0xe78253, 0.7);
warmFill.position.set(12, 7, -10);
scene.add(warmFill);
const SURFACE = 1.91;
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function box(width, height, depth, color, x = 0, y = 0, z = 0, parent = scene) {
const geometry = new THREE.BoxGeometry(width, height, depth);
const mesh = new THREE.Mesh(
geometry,
(typeof color === "string" || typeof color === "number") ? material(color) : color
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function groupAt(x, y, z, parent = scene) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
return group;
}
function smoothstep(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function makeTextPlane(text, subtitle, width, height, options = {}) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = options.background || "#f6e4b5";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = options.border || "#3b2b21";
ctx.lineWidth = 16;
ctx.strokeRect(8, 8, canvas.width - 16, canvas.height - 16);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = options.color || "#3b2b21";
ctx.font = `900 ${subtitle ? 76 : 92}px monospace`;
ctx.fillText(text, canvas.width / 2, subtitle ? 92 : 130);
if (subtitle) {
ctx.font = "bold 31px monospace";
ctx.fillStyle = options.subtitleColor || "#795e43";
ctx.fillText(subtitle, canvas.width / 2, 180);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({ map: texture })
);
mesh.castShadow = false;
mesh.receiveShadow = false;
return mesh;
}
// -------------------------------------------------------------------------
// Booth, table, and fairground
// -------------------------------------------------------------------------
box(48, 0.45, 39, 0xcbb58c, 0, -0.28, 0);
box(23.5, 0.08, 15.4, 0xb96449, 0, -0.015, 0);
box(22.7, 0.025, 14.6, 0xd28a60, 0, 0.035, 0);
// Table legs and supports.
for (const x of [-7.35, 7.35]) {
for (const z of [-4.1, 4.1]) {
box(0.72, 1.55, 0.72, 0x65452e, x, 0.72, z);
box(0.9, 0.2, 0.9, 0x3f2d22, x, 0.12, z);
}
}
box(15.2, 0.32, 0.35, 0x765035, 0, 0.55, -4.1);
box(15.2, 0.32, 0.35, 0x765035, 0, 0.55, 4.1);
// Main demonstration table.
box(18.4, 0.68, 11.3, 0x5f3e29, 0, 1.48, 0);
box(18.65, 0.16, 11.55, 0xa96e3d, 0, 1.79, 0);
box(17.85, 0.09, 10.75, 0xc88b4e, 0, 1.865, 0);
box(16.9, 0.035, 2.25, 0xb84f3c, 0, 1.93, 0.15);
box(16.9, 0.012, 0.12, 0xf0bc54, 0, 1.957, -0.78);
box(16.9, 0.012, 0.12, 0xf0bc54, 0, 1.957, 1.08);
// Front table label.
const tableLabel = makeTextPlane(
"DEMONSTRATION TABLE",
"SPIN / COMPARE / CROWN A CHAMPION",
6.4,
0.74,
{ background: "#f4dfad", color: "#493326" }
);
tableLabel.position.set(0, 1.25, 5.69);
scene.add(tableLabel);
// Back booth posts.
for (const x of [-8.35, 8.35]) {
box(0.38, 5.5, 0.38, 0x765038, x, 2.75, -5.9);
box(0.62, 0.26, 0.62, 0x4f3628, x, 0.13, -5.9);
}
box(17.2, 0.35, 0.35, 0x765038, 0, 5.25, -5.9);
// Striped voxel awning.
const awningColors = [0xcf5941, 0xf0dba8];
for (let i = 0; i < 12; i++) {
const x = -8.025 + i * 1.45;
const color = awningColors[i % 2];
box(1.45, 0.18, 1.85, color, x, 4.96, -4.98);
box(1.45, 0.18, 1.85, color, x, 5.22, -6.38);
box(1.15, 0.42, 0.18, color, x, 4.62, -4.02);
}
box(16.9, 0.17, 0.23, 0x805332, 0, 4.72, -4.0);
// Main fair sign.
box(8.2, 1.62, 0.26, 0x593b29, 0, 3.92, -4.82);
const fairSign = makeTextPlane(
"THE WHIRL FAIR",
"VOXEL TABLETOP GAMES",
7.75,
1.37,
{ background: "#f3dda7", color: "#8d382e", subtitleColor: "#5a4130" }
);
fairSign.position.set(0, 3.92, -4.675);
scene.add(fairSign);
// Small pennants.
const pennantColors = [0xd9573f, 0xe4ad3d, 0x327f78, 0x416e9b];
for (let i = 0; i < 15; i++) {
const x = -7.4 + i * 1.05;
box(0.32, 0.32, 0.12, pennantColors[i % pennantColors.length], x, 5.05, -3.91);
}
// -------------------------------------------------------------------------
// Distinct top silhouettes
// -------------------------------------------------------------------------
const topConfigs = [
{
name: "Penny",
kind: "classic",
accent: 0xd9573f,
secondary: 0xf0bc54,
description: "Wide belly, quick gyre"
},
{
name: "Comet",
kind: "comet",
accent: 0x327f78,
secondary: 0xf0bc54,
description: "Long tail, bright orbit"
},
{
name: "Acorn",
kind: "acorn",
accent: 0x9b643c,
secondary: 0xd7a565,
description: "Low, sturdy glider"
},
{
name: "Crown",
kind: "crown",
accent: 0x416e9b,
secondary: 0xe4ad3d,
description: "Tall handle, sharp spiral"
}
];
function buildTop(config) {
const group = new THREE.Group();
if (config.kind === "classic") {
box(0.26, 0.16, 0.26, 0x3b3029, 0, 0.08, 0, group);
box(1.12, 0.24, 1.12, config.accent, 0, 0.27, 0, group);
box(0.92, 0.24, 0.92, config.secondary, 0, 0.50, 0, group);
box(0.68, 0.25, 0.68, config.accent, 0, 0.72, 0, group);
box(0.28, 0.34, 0.28, config.secondary, 0, 0.98, 0, group);
box(0.54, 0.22, 0.54, config.secondary, 0, 1.23, 0, group);
box(0.13, 0.12, 0.13, 0xfff0b9, 0, 1.38, 0, group);
}
if (config.kind === "comet") {
box(0.25, 0.16, 0.25, 0x302b27, 0, 0.08, 0, group);
box(0.56, 0.35, 0.56, config.accent, 0, 0.31, 0, group);
box(0.76, 0.12, 0.76, config.secondary, 0, 0.54, 0, group);
box(0.43, 0.22, 0.43, config.accent, 0, 0.70, 0, group);
box(0.24, 0.54, 0.24, config.accent, 0, 1.02, 0, group);
box(0.48, 0.18, 0.42, config.secondary, 0, 1.34, 0, group);
box(0.72, 0.10, 0.23, config.secondary, 0, 0.22, -0.52, group);
box(0.42, 0.08, 0.18, 0xf5dc91, 0, 0.15, -0.80, group);
}
if (config.kind === "acorn") {
box(0.32, 0.16, 0.32, 0x332923, 0, 0.08, 0, group);
box(1.08, 0.34, 1.08, config.accent, 0, 0.31, 0, group);
box(1.22, 0.16, 1.22, config.secondary, 0, 0.55, 0, group);
box(0.78, 0.34, 0.78, config.accent, 0, 0.77, 0, group);
box(0.25, 0.26, 0.25, 0x5b3b28, 0, 1.05, 0, group);
box(0.12, 0.13, 0.12, 0x68462d, 0, 1.22, 0, group);
}
if (config.kind === "crown") {
box(0.28, 0.16, 0.28, 0x302b27, 0, 0.08, 0, group);
box(0.66, 0.16, 0.66, config.accent, 0, 0.24, 0, group);
box(1.26, 0.16, 1.26, config.secondary, 0, 0.40, 0, group);
box(0.76, 0.32, 0.76, config.accent, 0, 0.63, 0, group);
box(0.54, 0.20, 0.54, config.secondary, 0, 0.87, 0, group);
box(0.25, 0.42, 0.25, config.accent, 0, 1.13, 0, group);
box(0.48, 0.18, 0.48, config.secondary, 0, 1.39, 0, group);
box(0.12, 0.12, 0.12, 0xf8e6ae, 0, 1.53, 0, group);
}
return group;
}
// Gallery pedestals.
const galleryX = [-5.7, -3.55, -1.4, 0.75];
const galleryTops = [];
const pedestalRims = [];
topConfigs.forEach((config, index) => {
const x = galleryX[index];
const z = -4.03;
box(1.58, 0.22, 1.58, 0x765038, x, SURFACE + 0.11, z);
const rimMaterial = new THREE.MeshStandardMaterial({
color: config.accent,
roughness: 0.8
});
for (const dx of [-0.67, 0.67]) {
for (const dz of [-0.67, 0.67]) {
box(0.18, 0.32, 0.18, rimMaterial, x + dx, SURFACE + 0.17, z + dz);
}
}
const top = buildTop(config);
top.scale.setScalar(0.67);
top.position.set(x, SURFACE + 0.23, z);
scene.add(top);
galleryTops.push(top);
pedestalRims.push(rimMaterial);
});
// -------------------------------------------------------------------------
// Hoops and carved toys
// -------------------------------------------------------------------------
function makeHoop(x, z, radius, color, flat = false) {
const hoop = new THREE.Group();
hoop.position.set(x, SURFACE + (flat ? 0.08 : radius + 0.08), z);
const segments = 10;
for (let i = 0; i < segments; i++) {
const a1 = (i / segments) * Math.PI * 2;
const a2 = ((i + 1) / segments) * Math.PI * 2;
const x1 = Math.cos(a1) * radius;
const y1 = Math.sin(a1) * radius;
const x2 = Math.cos(a2) * radius;
const y2 = Math.sin(a2) * radius;
const length = Math.hypot(x2 - x1, y2 - y1);
const segment = box(length + 0.08, 0.16, 0.19, color);
if (flat) {
segment.position.set((x1 + x2) / 2, 0, (y1 + y2) / 2);
segment.rotation.y = -Math.atan2(y2 - y1, x2 - x1);
} else {
segment.position.set((x1 + x2) / 2, (y1 + y2) / 2, 0);
segment.rotation.z = Math.atan2(y2 - y1, x2 - x1);
}
hoop.add(segment);
}
scene.add(hoop);
return hoop;
}
makeHoop(6.25, -2.3, 1.2, 0x327f78, false);
makeHoop(7.05, 1.35, 0.88, 0xd9573f, true);
// Carved wooden animal.
const animal = groupAt(-6.2, SURFACE, 1.75);
animal.rotation.y = -0.25;
box(1.35, 0.65, 0.72, 0xb9793f, 0, 0.62, 0, animal);
box(0.62, 0.63, 0.62, 0xc98b4d, 0.79, 0.98, 0, animal);
box(0.24, 0.35, 0.28, 0xb9793f, 0.66, 1.40, 0, animal);
box(0.24, 0.35, 0.28, 0xb9793f, 0.94, 1.40, 0, animal);
box(0.32, 0.30, 0.42, 0xe0aa62, 1.06, 0.90, 0, animal);
box(0.12, 0.11, 0.12, 0x33251e, 1.22, 1.02, 0.16, animal);
box(0.12, 0.11, 0.12, 0x33251e, 1.22, 1.02, -0.16, animal);
for (const x of [-0.42, 0.36]) {
for (const z of [-0.23, 0.23]) {
box(0.25, 0.52, 0.25, 0x85502e, x, 0.24, z, animal);
}
}
box(0.48, 0.16, 0.16, 0x85502e, -0.83, 0.78, 0, animal);
// Carved boat.
const boat = groupAt(-5.7, SURFACE, 3.45);
boat.rotation.y = 0.28;
box(1.85, 0.42, 0.78, 0x9c6238, 0, 0.25, 0, boat);
box(1.45, 0.22, 0.62, 0xc18149, 0, 0.53, 0, boat);
box(0.14, 1.25, 0.14, 0x67432c, 0.1, 1.16, 0, boat);
box(0.76, 0.42, 0.10, 0xe0ad4f, 0.48, 1.48, 0, boat);
box(0.42, 0.28, 0.42, 0x327f78, -0.52, 0.76, 0, boat);
// Stacking toy.
const stack = groupAt(-7.7, SURFACE, -1.45);
const stackColors = [0xd9573f, 0xe4ad3d, 0x327f78, 0x416e9b];
for (let i = 0; i < 4; i++) {
const size = 1.08 - i * 0.18;
box(size, 0.26, size, stackColors[i], 0, 0.14 + i * 0.28, 0, stack);
}
box(0.18, 0.34, 0.18, 0xf1cb68, 0, 1.40, 0, stack);
// -------------------------------------------------------------------------
// Voxel people
// -------------------------------------------------------------------------
function makePerson({
x,
y = 0,
z,
scale = 1,
shirt = 0x416e9b,
pants = 0x4a3a30,
skin = 0xd9a273,
hat = null,
rotation = 0
}) {
const person = groupAt(x, y, z);
person.scale.setScalar(scale);
person.rotation.y = rotation;
for (const side of [-1, 1]) {
box(0.23, 0.65, 0.25, pants, side * 0.19, 0.34, 0, person);
box(0.27, 0.13, 0.40, 0x352922, side * 0.19, 0.08, 0.05, person);
}
box(0.72, 0.86, 0.44, shirt, 0, 1.05, 0, person);
box(0.78, 0.12, 0.48, 0x6f5138, 0, 0.67, 0, person);
box(0.56, 0.56, 0.54, skin, 0, 1.72, 0, person);
box(0.60, 0.17, 0.58, 0x4b3528, 0, 2.01, -0.01, person);
box(0.13, 0.13, 0.15, skin, 0, 1.68, 0.34, person);
for (const side of [-1, 1]) {
box(0.10, 0.10, 0.07, 0x30251f, side * 0.13, 1.78, 0.285, person);
}
const leftArm = groupAt(-0.48, 1.42, 0, person);
const rightArm = groupAt(0.48, 1.42, 0, person);
box(0.20, 0.72, 0.22, shirt, 0, -0.34, 0, leftArm);
box(0.20, 0.72, 0.22, shirt, 0, -0.34, 0, rightArm);
box(0.21, 0.18, 0.23, skin, 0, -0.76, 0, leftArm);
box(0.21, 0.18, 0.23, skin, 0, -0.76, 0, rightArm);
if (hat !== null) {
box(0.70, 0.17, 0.66, hat, 0, 2.08, 0, person);
box(0.66, 0.24, 0.48, hat, 0, 2.22, 0.02, person);
}
return {
group: person,
leftArm,
rightArm,
head: person.children.find(child => child.geometry?.parameters?.width === 0.56),
baseY: y,
phase: Math.random() * Math.PI * 2
};
}
const visitors = [
makePerson({
x: -9.5, z: 1.2, scale: 1.0, shirt: 0x327f78,
hat: 0xe4ad3d, rotation: Math.PI / 2
}),
makePerson({
x: -9.1, z: -2.6, scale: 0.92, shirt: 0xd9573f,
pants: 0x5c4739, rotation: Math.PI / 2
}),
makePerson({
x: 9.25, z: 2.8, scale: 1.02, shirt: 0x416e9b,
hat: 0x9b643c, rotation: -Math.PI / 2
}),
makePerson({
x: 8.9, z: -1.9, scale: 0.93, shirt: 0xe4ad3d,
skin: 0xb97d56, rotation: -Math.PI / 2
}),
makePerson({
x: 1.2, z: 7.25, scale: 1.05, shirt: 0xd9573f,
hat: 0x327f78, rotation: Math.PI
}),
makePerson({
x: -3.5, z: 7.05, scale: 0.9, shirt: 0x327f78,
rotation: Math.PI
})
];
// Demonstrator standing on the table.
const demonstrator = makePerson({
x: -1.55,
y: SURFACE,
z: 0.65,
scale: 1.08,
shirt: 0xf2dfb0,
pants: 0x75472f,
skin: 0xc9895d,
hat: 0xd9573f,
rotation: 0.08
});
// Apron and demonstration badge.
box(0.52, 0.73, 0.08, 0x327f78, 0, 1.02, 0.26, demonstrator.group);
box(0.23, 0.15, 0.06, 0xe4ad3d, -0.18, 1.40, 0.27, demonstrator.group);
// Launch pad.
const launchPad = groupAt(-0.35, SURFACE + 0.025, 0.65);
for (let i = 0; i < 16; i++) {
const a = (i / 16) * Math.PI * 2;
const marker = box(0.18, 0.035, 0.18, 0xf0bc54,
Math.cos(a) * 0.74,
0,
Math.sin(a) * 0.74,
launchPad
);
marker.rotation.y = a;
}
// -------------------------------------------------------------------------
// Motion paths
// -------------------------------------------------------------------------
const motionConfigs = [
{
name: "Glide",
color: 0xe4ad3d,
rate: 0.9,
spin: 9.2
},
{
name: "Orbit",
color: 0xd9573f,
rate: 0.65,
spin: 6.3
},
{
name: "Spiral",
color: 0x327f78,
rate: 1.05,
spin: 13.1
}
];
function pathPoint(motionIndex, angle) {
if (motionIndex === 0) {
return new THREE.Vector3(
4.6 * Math.sin(angle * 0.7),
SURFACE + 0.055,
2.25 * Math.cos(angle * 0.7)
);
}
if (motionIndex === 1) {
return new THREE.Vector3(
5.25 * Math.cos(angle * 0.45),
SURFACE + 0.055,
2.72 * Math.sin(angle * 0.45)
);
}
const radius = 4.72 + 0.72 * Math.sin(angle * 0.5);
return new THREE.Vector3(
radius * Math.cos(angle * 2),
SURFACE + 0.055,
radius * 0.52 * Math.sin(angle * 2)
);
}
const pathGroups = [];
motionConfigs.forEach((motion, motionIndex) => {
const pathGroup = new THREE.Group();
const samples = motionIndex === 2 ? 120 : 80;
const maxAngle = motionIndex === 2 ? Math.PI * 4 : Math.PI * 2;
for (let i = 0; i < samples; i++) {
const point = pathPoint(motionIndex, (i / samples) * maxAngle);
box(
0.11,
0.025,
0.11,
motion.color,
point.x,
point.y + 0.015,
point.z,
pathGroup
);
}
pathGroup.visible = motionIndex === 0;
scene.add(pathGroup);
pathGroups.push(pathGroup);
});
// -------------------------------------------------------------------------
// Demo top and trail
// -------------------------------------------------------------------------
const demoRoot = new THREE.Group();
const demoSpin = new THREE.Group();
demoRoot.add(demoSpin);
scene.add(demoRoot);
const demoModels = topConfigs.map(config => {
const model = buildTop(config);
demoSpin.add(model);
return model;
});
demoModels.forEach((model, index) => {
model.visible = index === 0;
});
const trailGeometry = new THREE.BoxGeometry(0.10, 0.10, 0.10);
const trail = [];
for (let i = 0; i < 13; i++) {
const particleMaterial = new THREE.MeshBasicMaterial({
color: topConfigs[0].accent,
transparent: true,
opacity: 0,
depthWrite: false
});
const particle = new THREE.Mesh(trailGeometry, particleMaterial);
particle.visible = false;
scene.add(particle);
trail.push(particle);
}
const trailHistory = [];
const startPosition = new THREE.Vector3(-0.35, SURFACE + 0.06, 0.65);
let selectedSilhouette = 0;
let selectedMotion = 0;
let running = false;
let demoTime = 0;
let sceneTime = 0;
let statTimer = 0;
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
const silhouetteButtons = [...document.querySelectorAll("[data-silhouette]")];
const motionButtons = [...document.querySelectorAll("[data-motion]")];
const launchButton = document.querySelector("#launchButton");
const launchLabel = document.querySelector("#launchLabel");
const launchSub = document.querySelector("#launchSub");
const rpmReadout = document.querySelector("#rpm");
const wobbleReadout = document.querySelector("#wobble");
const stateReadout = document.querySelector("#stateText");
function updateLaunchCopy() {
const top = topConfigs[selectedSilhouette];
const motion = motionConfigs[selectedMotion];
launchLabel.textContent = running ? "Relauch the Top" : "Launch the Top";
launchSub.textContent = `${top.name} · ${motion.name} pattern`;
}
function resetDemo() {
running = false;
demoTime = 0;
demoRoot.position.copy(startPosition);
demoRoot.rotation.set(0, 0, 0);
demoSpin.rotation.set(0, 0, 0);
trailHistory.length = 0;
trail.forEach(particle => {
particle.visible = false;
particle.material.opacity = 0;
});
launchButton.classList.remove("is-live");
stateReadout.textContent = "READY";
updateLaunchCopy();
}
function selectSilhouette(index) {
selectedSilhouette = index;
demoModels.forEach((model, modelIndex) => {
model.visible = modelIndex === index;
});
pedestalRims.forEach((rim, rimIndex) => {
rim.color.setHex(topConfigs[rimIndex].accent);
rim.emissive.setHex(rimIndex === index ? topConfigs[rimIndex].accent : 0x000000);
rim.emissiveIntensity = rimIndex === index ? 0.24 : 0;
});
trail.forEach(particle => {
particle.material.color.setHex(topConfigs[index].accent);
});
silhouetteButtons.forEach((button, buttonIndex) => {
button.classList.toggle("active", buttonIndex === index);
});
resetDemo();
}
function selectMotion(index) {
selectedMotion = index;
pathGroups.forEach((pathGroup, pathIndex) => {
pathGroup.visible = pathIndex === index;
});
motionButtons.forEach((button, buttonIndex) => {
button.classList.toggle("active", buttonIndex === index);
});
resetDemo();
}
silhouetteButtons.forEach(button => {
button.addEventListener("click", () => {
selectSilhouette(Number(button.dataset.silhouette));
});
});
motionButtons.forEach(button => {
button.addEventListener("click", () => {
selectMotion(Number(button.dataset.motion));
});
});
launchButton.addEventListener("click", () => {
running = true;
demoTime = 0;
trailHistory.length = 0;
launchButton.classList.add("is-live");
stateReadout.textContent = "LIVE";
updateLaunchCopy();
});
// -------------------------------------------------------------------------
// Direct camera controls — no addons
// -------------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraYaw -= deltaX * 0.006;
cameraPitch = THREE.MathUtils.clamp(cameraPitch + deltaY * 0.0045, 0.30, 1.22);
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.75
);
}, { passive: false });
function updateCamera() {
const horizontal = cameraRadius * Math.cos(cameraPitch);
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * cameraRadius,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const baseHeight = aspect < 1.15 ? 21 / aspect : 21;
camera.left = (-baseHeight * aspect) / 2 / cameraZoom;
camera.right = (baseHeight * aspect) / 2 / cameraZoom;
camera.top = baseHeight / 2 / cameraZoom;
camera.bottom = -baseHeight / 2 / cameraZoom;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 0.85));
renderer.setSize(width, height, false);
updateCamera();
}
window.addEventListener("resize", resize);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
sceneTime += delta;
// Visitors shift their weight and watch the table.
visitors.forEach((visitor, index) => {
visitor.group.position.y =
visitor.baseY + Math.sin(sceneTime * 1.45 + visitor.phase) * 0.022;
visitor.rightArm.rotation.z =
Math.sin(sceneTime * 1.1 + visitor.phase) * 0.035;
});
// Gallery tops turn very slowly so their silhouettes remain readable.
galleryTops.forEach((top, index) => {
top.rotation.y = sceneTime * (0.22 + index * 0.035) + index * 0.7;
});
const motion = motionConfigs[selectedMotion];
if (running) {
demoTime += delta;
const angle = demoTime * motion.rate;
const targetPosition = pathPoint(selectedMotion, angle);
const launchBlend = smoothstep(demoTime / 1.15);
demoRoot.position.lerpVectors(startPosition, targetPosition, launchBlend);
demoRoot.position.y = SURFACE + 0.06 + Math.abs(Math.sin(demoTime * 8)) * 0.018;
const wobbleZ = Math.sin(demoTime * 6.2) * 0.065;
const wobbleX = Math.cos(demoTime * 5.3) * 0.045;
demoRoot.rotation.z = wobbleZ;
demoRoot.rotation.x = wobbleX;
demoSpin.rotation.y += delta * motion.spin;
trailHistory.push(demoRoot.position.clone());
if (trailHistory.length > 26) trailHistory.shift();
trail.forEach((particle, index) => {
const historyIndex = trailHistory.length - 1 - index * 2;
if (historyIndex >= 0) {
const point = trailHistory[historyIndex];
particle.visible = true;
particle.position.set(
point.x,
point.y + 0.13 + Math.sin(sceneTime * 9 + index) * 0.025,
point.z
);
particle.material.opacity = 0.64 * (1 - index / trail.length);
const scale = 0.65 + (1 - index / trail.length) * 0.65;
particle.scale.setScalar(scale);
} else {
particle.visible = false;
particle.material.opacity = 0;
}
});
const launchPulse = Math.max(0, 1 - demoTime / 1.05);
demonstrator.rightArm.rotation.z = -0.28 - launchPulse * 1.02;
demonstrator.leftArm.rotation.z = -0.12 + launchPulse * 0.24;
} else {
demoRoot.position.copy(startPosition);
demoRoot.rotation.set(0, 0, 0);
demoSpin.rotation.y += delta * 0.42;
demonstrator.rightArm.rotation.z = -0.22 + Math.sin(sceneTime * 1.7) * 0.035;
demonstrator.leftArm.rotation.z = -0.08;
}
// Gentle demonstrator motion.
demonstrator.group.position.y =
SURFACE + Math.sin(sceneTime * 1.8) * 0.012;
statTimer += delta;
if (statTimer > 0.1) {
statTimer = 0;
const rpm = running ? motion.spin * 60 / (Math.PI * 2) : 0;
const wobble = running
? Math.hypot(demoRoot.rotation.x, demoRoot.rotation.z) * 180 / Math.PI
: 0.6;
rpmReadout.textContent = `${rpm.toFixed(0)} RPM`;
wobbleReadout.textContent = `${wobble.toFixed(1)}°`;
stateReadout.textContent = running ? "LIVE" : "READY";
}
updateCamera();
renderer.render(scene, camera);
}
selectSilhouette(0);
selectMotion(0);
resize();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```