Prompt specification
Build or customize the Three.js 3D scene "Silent Character Reaction Gallery" 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: Silent Character Reaction Gallery
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/silent-character-reaction-gallery-x3719
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a small voxel stage with four original characters. A harmless wind-up toy suddenly unfolds a paper flower in the center. Give the characters different authored reactions: one leans forward, another pauses with raised brows, a third steps back, and one continues looking at a nearby prop. Make the reactions readable through head direction, body pose, and timing rather than floating emotion labels. Offer a replay that uses the same event with a second set of reactions. Present the characters as fictional performances, without claiming that a particular facial arrangement reliably identifies someone's actual feelings.
Working Three.js Starter (silent-character-reaction-gallery-x3719):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>The Paper Bloom — A Voxel Performance</title>
<style>
:root {
color-scheme: dark;
--ink: #f6f3ec;
--muted: #b8c0d0;
--panel: rgba(18, 23, 35, 0.78);
--border: rgba(255, 255, 255, 0.13);
--accent: #ffc96b;
--accent-2: #f58fa8;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #141925;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overscroll-behavior: none;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
#vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 46%, transparent 35%, rgba(5, 8, 15, 0.24) 78%),
linear-gradient(to bottom, rgba(6, 9, 16, 0.18), transparent 28%);
}
.ui {
position: fixed;
z-index: 3;
pointer-events: none;
}
.panel {
border: 1px solid var(--border);
background: var(--panel);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#brand {
top: 22px;
left: 22px;
max-width: 390px;
padding: 15px 17px 14px;
border-radius: 16px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--accent);
box-shadow: 0 0 18px rgba(255, 201, 107, 0.55);
content: "";
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 34px);
line-height: 1;
letter-spacing: -0.04em;
}
#brand p {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
#controls {
top: 22px;
right: 22px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 9px;
pointer-events: auto;
}
button {
min-height: 42px;
padding: 0 15px;
border: 1px solid var(--border);
border-radius: 12px;
background: rgba(20, 26, 40, 0.88);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
letter-spacing: 0.01em;
cursor: pointer;
transition:
transform 140ms ease,
border-color 140ms ease,
background 140ms ease,
opacity 140ms ease;
}
button:hover:not(:disabled) {
transform: translateY(-2px);
border-color: rgba(255, 255, 255, 0.28);
background: rgba(33, 41, 59, 0.95);
}
button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 3px;
}
button:disabled {
opacity: 0.38;
cursor: not-allowed;
}
#play {
border-color: rgba(255, 201, 107, 0.35);
background: var(--accent);
color: #272018;
}
#play:hover:not(:disabled) {
background: #ffd88f;
}
#cast {
bottom: 22px;
left: 22px;
padding: 12px 14px;
border-radius: 14px;
}
#cast-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 9px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#blocking {
color: var(--accent-2);
}
#roster {
display: flex;
flex-wrap: wrap;
gap: 8px 13px;
}
.cast-member {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 11px;
font-weight: 750;
}
.swatch {
width: 8px;
height: 8px;
border-radius: 2px;
}
#timeline {
bottom: 22px;
left: 50%;
width: min(520px, calc(100vw - 570px));
min-width: 310px;
transform: translateX(-50%);
padding: 11px 13px 12px;
border-radius: 14px;
}
.timeline-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
font-size: 10px;
}
#status {
overflow: hidden;
color: var(--ink);
font-weight: 750;
text-overflow: ellipsis;
white-space: nowrap;
}
#clock {
flex: 0 0 auto;
color: var(--muted);
font-variant-numeric: tabular-nums;
}
.track {
position: relative;
height: 6px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.1);
}
#progress {
position: absolute;
inset: 0 auto 0 0;
width: 0;
border-radius: inherit;
background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
#cue {
position: absolute;
top: -3px;
bottom: -3px;
left: 16.875%;
width: 2px;
border-radius: 2px;
background: rgba(255, 255, 255, 0.72);
box-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
}
#note {
right: 22px;
bottom: 22px;
max-width: 285px;
padding: 12px 14px;
border-radius: 14px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
#note strong {
display: block;
margin-bottom: 3px;
color: var(--ink);
font-size: 10px;
letter-spacing: 0.02em;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #141925;
color: var(--muted);
font-size: 13px;
transition: opacity 250ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 920px) {
#brand {
max-width: 300px;
}
#brand p {
display: none;
}
#timeline {
bottom: 92px;
width: calc(100vw - 44px);
min-width: 0;
}
#note {
max-width: 270px;
}
}
@media (max-width: 620px) {
#brand {
top: 12px;
left: 12px;
padding: 11px 13px;
}
#brand .eyebrow {
margin-bottom: 5px;
}
#controls {
top: 12px;
right: 12px;
flex-direction: column;
align-items: stretch;
}
button {
min-height: 38px;
padding: 0 11px;
font-size: 11px;
}
#cast {
right: 12px;
bottom: 12px;
left: 12px;
padding: 10px 12px;
}
#note {
display: none;
}
#timeline {
bottom: 91px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Interactive voxel stage with four fictional performers and a wind-up toy that unfolds a paper flower"
></canvas>
<div id="vignette"></div>
<section id="brand" class="ui panel" aria-label="Performance title">
<div class="eyebrow">A four-performer voxel study</div>
<h1>The Paper Bloom</h1>
<p>
Drag to orbit the stage. Scroll to zoom. The second run uses the same
unfolding cue with different authored body timing.
</p>
</section>
<nav id="controls" class="ui" aria-label="Performance controls">
<button id="play" type="button">Wind the toy</button>
<button id="replay" type="button" disabled>Replay · alternate blocking</button>
</nav>
<section id="cast" class="ui panel" aria-label="Fictional cast">
<div id="cast-heading">
<span>Fictional cast</span>
<span id="blocking">Blocking A</span>
</div>
<div id="roster">
<span class="cast-member">
<i class="swatch" style="background:#4fc3c7"></i>Pip
</span>
<span class="cast-member">
<i class="swatch" style="background:#a88ad8"></i>Nia
</span>
<span class="cast-member">
<i class="swatch" style="background:#e9825b"></i>Oren
</span>
<span class="cast-member">
<i class="swatch" style="background:#8cb8ef"></i>Miso
</span>
</div>
</section>
<section id="timeline" class="ui panel" aria-label="Performance timeline">
<div class="timeline-row">
<span id="status">Ready for the cue</span>
<span id="clock">0.0 / 8.0 s</span>
</div>
<div class="track" aria-hidden="true">
<div id="progress"></div>
<div id="cue"></div>
</div>
</section>
<aside id="note" class="ui panel">
<strong>Fictional performance, not emotion detection.</strong>
The body, gaze, brows, and timing are authored stage actions. They do not
reliably identify anyone’s actual feelings.
</aside>
<div id="loading">Building the voxel stage…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, camera, and direct orbit controls
// ------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x141925);
scene.fog = new THREE.Fog(0x141925, 17, 31);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraTarget = new THREE.Vector3(0, 0.82, 0);
const cameraOrbit = {
yaw: 0.34,
phi: 1.02,
radius: window.innerWidth < 700 ? 14.2 : 11.5
};
function updateCamera() {
const sinPhi = Math.sin(cameraOrbit.phi);
camera.position.set(
cameraTarget.x + cameraOrbit.radius * sinPhi * Math.sin(cameraOrbit.yaw),
cameraTarget.y + cameraOrbit.radius * Math.cos(cameraOrbit.phi),
cameraTarget.z + cameraOrbit.radius * sinPhi * Math.cos(cameraOrbit.yaw)
);
camera.lookAt(cameraTarget);
}
updateCamera();
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraOrbit.yaw -= dx * 0.006;
cameraOrbit.phi = THREE.MathUtils.clamp(
cameraOrbit.phi - dy * 0.005,
0.62,
1.36
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraOrbit.radius = THREE.MathUtils.clamp(
cameraOrbit.radius + event.deltaY * 0.009,
8.2,
17
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraOrbit.yaw = 0.34;
cameraOrbit.phi = 1.02;
cameraOrbit.radius = window.innerWidth < 700 ? 14.2 : 11.5;
updateCamera();
});
// ------------------------------------------------------------
// Lighting and reusable voxel construction
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xcbd8ff, 0x4d3346, 2.05);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe3b8, 3.4);
keyLight.position.set(-4.5, 8.5, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 24;
keyLight.shadow.bias = -0.0007;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x7ba7ff, 1.35);
fillLight.position.set(5, 4, -5);
scene.add(fillLight);
const bloomLight = new THREE.PointLight(0xff9fbc, 0, 4.5, 2);
bloomLight.position.set(0, 1.9, 0);
scene.add(bloomLight);
const materialCache = new Map();
function material(color, roughness = 0.78, metalness = 0) {
const key = `${color}-${roughness}-${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true
})
);
}
return materialCache.get(key);
}
function box(parent, size, position, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
options.material || material(color, options.roughness, options.metalness)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function group(parent, position = [0, 0, 0]) {
const result = new THREE.Group();
result.position.set(position[0], position[1], position[2]);
parent.add(result);
return result;
}
function clamp01(value) {
return Math.max(0, Math.min(1, value));
}
function smoothstep(start, end, value) {
const t = clamp01((value - start) / (end - start));
return t * t * (3 - 2 * t);
}
function easeOutBack(t) {
const c1 = 1.70158;
const c3 = c1 + 1;
const x = clamp01(t);
return 1 + c3 * Math.pow(x - 1, 3) + c1 * Math.pow(x - 1, 2);
}
// ------------------------------------------------------------
// Small tiled stage
// ------------------------------------------------------------
const stage = group(scene);
box(
stage,
[8.7, 0.5, 6.5],
[0, -0.25, 0],
0x2c3245
);
box(
stage,
[8.38, 0.12, 6.18],
[0, 0.035, 0],
0x3b4358
);
const floorColors = [
0x475168,
0x4b566c,
0x424c62,
0x505b70,
0x465167
];
for (let row = 0; row < 9; row++) {
for (let column = 0; column < 12; column++) {
const x = -3.74 + column * 0.68;
const z = -2.72 + row * 0.68;
const color = floorColors[(row * 3 + column * 2) % floorColors.length];
box(
stage,
[0.63, 0.07, 0.63],
[x, 0.105, z],
color
);
}
}
// A low, irregular voxel border gives the stage a handmade footprint.
const borderBlocks = [
[-4.08, 0.18, -2.85, 0.34, 0.5, 0.55],
[-3.42, 0.16, -2.98, 0.6, 0.42, 0.3],
[3.55, 0.18, -2.93, 0.7, 0.48, 0.32],
[4.05, 0.16, -2.48, 0.28, 0.44, 0.95],
[-4.12, 0.16, 2.55, 0.28, 0.42, 0.65],
[4.05, 0.15, 2.73, 0.3, 0.4, 0.48]
];
for (const b of borderBlocks) {
box(stage, [b[3], b[4], b[5]], [b[0], b[1], b[2]], 0x697188);
}
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
material(0x171c28, 0.98)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.515;
ground.receiveShadow = true;
scene.add(ground);
// ------------------------------------------------------------
// Wind-up toy and hinged paper flower
// ------------------------------------------------------------
const toy = group(stage, [0, 0.14, 0]);
box(toy, [0.86, 0.46, 0.68], [0, 0.27, 0], 0xe9c987, {
roughness: 0.7
});
box(toy, [0.7, 0.12, 0.72], [0, 0.52, 0], 0x8e5f55);
box(toy, [0.48, 0.4, 0.48], [0, 0.65, 0.27], 0xf0d6a0);
box(toy, [0.075, 0.085, 0.04], [-0.115, 0.69, 0.515], 0x252a37);
box(toy, [0.075, 0.085, 0.04], [0.115, 0.69, 0.515], 0x252a37);
box(toy, [0.1, 0.045, 0.045], [0, 0.56, 0.516], 0x6c3e45);
box(toy, [0.27, 0.16, 0.34], [-0.25, 0.08, 0.12], 0x5c4150);
box(toy, [0.27, 0.16, 0.34], [0.25, 0.08, 0.12], 0x5c4150);
box(toy, [0.1, 0.18, 0.1], [-0.42, 0.35, -0.08], 0xb68a52, {
metalness: 0.35,
roughness: 0.45
});
box(toy, [0.1, 0.18, 0.1], [0.42, 0.35, -0.08], 0xb68a52, {
metalness: 0.35,
roughness: 0.45
});
const windupKey = group(toy, [0.52, 0.36, -0.04]);
box(windupKey, [0.2, 0.08, 0.08], [0, 0, 0], 0xcda55d, {
metalness: 0.55,
roughness: 0.35
});
box(windupKey, [0.08, 0.42, 0.08], [0.13, 0.14, 0], 0xcda55d, {
metalness: 0.55,
roughness: 0.35
});
box(windupKey, [0.08, 0.08, 0.42], [0.13, 0.31, 0], 0xcda55d, {
metalness: 0.55,
roughness: 0.35
});
box(windupKey, [0.08, 0.42, 0.08], [0.13, -0.12, 0], 0xcda55d, {
metalness: 0.55,
roughness: 0.35
});
box(windupKey, [0.08, 0.08, 0.42], [0.13, -0.28, 0], 0xcda55d, {
metalness: 0.55,
roughness: 0.35
});
const stem = box(stage, [0.09, 1.18, 0.09], [0, 0.64, -0.08], 0x5e9d68);
const flower = group(stage, [0, 1.75, -0.08]);
const petalHinges = [];
const petalColors = [
0xf58fa8,
0xffb2bd,
0xf7c76f,
0xffd8a0,
0xf58fa8,
0xffb2bd,
0xf7c76f,
0xffd8a0
];
for (let i = 0; i < 8; i++) {
const radial = group(flower);
radial.rotation.y = (i / 8) * Math.PI * 2;
const hinge = group(radial);
hinge.rotation.x = -Math.PI / 2;
petalHinges.push(hinge);
box(
hinge,
[0.58, 0.065, 0.57],
[0, 0, 0.29],
petalColors[i]
);
box(
hinge,
[0.43, 0.06, 0.37],
[0, 0.025, 0.72],
petalColors[(i + 1) % petalColors.length]
);
box(
hinge,
[0.065, 0.075, 0.57],
[0, 0.045, 0.29],
0xffe0d2
);
}
box(flower, [0.29, 0.22, 0.29], [0, 0.04, 0], 0xffd76e);
box(flower, [0.15, 0.08, 0.15], [0, 0.18, 0], 0xffe7a0);
// ------------------------------------------------------------
// Nearby prop: a bright, slowly turning voxel pinwheel
// ------------------------------------------------------------
const propPosition = new THREE.Vector3(3.5, 0.14, -0.65);
const prop = group(stage, [propPosition.x, propPosition.y, propPosition.z]);
box(prop, [0.62, 0.16, 0.62], [0, 0.08, 0], 0x596176);
box(prop, [0.1, 1.08, 0.1], [0, 0.64, 0], 0xc8d0dc, {
metalness: 0.4,
roughness: 0.4
});
const pinwheel = group(prop, [0, 1.18, 0]);
for (let i = 0; i < 4; i++) {
const blade = group(pinwheel);
blade.rotation.y = (i / 4) * Math.PI * 2;
blade.rotation.x = 0.16;
box(blade, [0.25, 0.08, 0.58], [0, 0, 0.3], i % 2 ? 0x65d6d3 : 0xffc45f);
}
box(pinwheel, [0.19, 0.19, 0.19], [0, 0, 0], 0xf4f0df);
// ------------------------------------------------------------
// Four original voxel characters
// ------------------------------------------------------------
function createCharacter(config) {
const root = group(stage, [config.position[0], 0.14, config.position[2]]);
root.rotation.y = config.yaw;
const upper = group(root, [0, 0.64, 0]);
const head = group(upper, [0, 0.78, 0]);
const skin = config.skin;
const hair = config.hair;
// Legs and shoes.
const legs = [];
for (const side of [-1, 1]) {
const leg = group(root, [side * 0.16, 0.64, 0]);
box(leg, [0.22, 0.52, 0.25], [0, -0.25, 0], config.trousers);
box(leg, [0.29, 0.14, 0.38], [0, -0.55, 0.07], 0x29313f);
legs.push(leg);
}
// Torso and outfit.
box(upper, [0.62, 0.66, 0.38], [0, 0.34, 0], config.coat);
box(upper, [0.13, 0.58, 0.04], [-0.17, 0.33, 0.205], config.accent);
box(upper, [0.13, 0.58, 0.04], [0.17, 0.33, 0.205], config.accent);
box(upper, [0.17, 0.13, 0.17], [0, -0.015, 0], skin);
// Head.
box(head, [0.59, 0.58, 0.52], [0, 0.28, 0], skin);
box(head, [0.63, 0.15, 0.56], [0, 0.57, -0.015], hair);
// Small side locks distinguish silhouettes.
box(head, [0.11, 0.31, 0.52], [-0.29, 0.37, -0.01], hair);
box(head, [0.11, 0.31, 0.52], [0.29, 0.37, -0.01], hair);
// Eyes, pupils, nose, and mouth.
const eyes = [];
for (const side of [-1, 1]) {
box(head, [0.105, 0.105, 0.035], [side * 0.13, 0.29, 0.274], 0xf7f3e8);
const pupil = box(
head,
[0.047, 0.057, 0.025],
[side * 0.13, 0.29, 0.298],
0x202633
);
eyes.push(pupil);
}
box(head, [0.075, 0.08, 0.07], [0, 0.19, 0.293], skin);
// Hair accessories.
if (config.id === "pip") {
box(head, [0.67, 0.13, 0.58], [0, 0.66, -0.01], 0xffc85c);
box(head, [0.48, 0.08, 0.26], [0, 0.61, 0.37], 0xffc85c);
} else if (config.id === "nia") {
box(head, [0.22, 0.22, 0.22], [-0.34, 0.72, -0.04], 0x5f3862);
box(head, [0.22, 0.22, 0.22], [0.34, 0.72, -0.04], 0x5f3862);
} else if (config.id === "oren") {
box(head, [0.69, 0.2, 0.59], [0, 0.66, -0.01], 0x754b43);
box(head, [0.43, 0.08, 0.28], [0, 0.58, 0.38], 0x754b43);
} else if (config.id === "miso") {
box(head, [0.67, 0.18, 0.58], [0, 0.66, -0.01], 0x7db1e5);
box(head, [0.12, 0.18, 0.12], [0, 0.82, 0], 0x7db1e5);
}
// Brows are independent meshes so they can be visibly raised.
const brows = [];
for (const side of [-1, 1]) {
const brow = box(
head,
[0.17, 0.035, 0.04],
[side * 0.13, 0.43, 0.286],
hair
);
brows.push(brow);
}
box(head, [0.13, 0.027, 0.028], [0, 0.11, 0.278], 0x744c51);
// Arms.
const arms = [];
for (const side of [-1, 1]) {
const arm = group(upper, [side * 0.4, 0.57, 0]);
box(arm, [0.19, 0.4, 0.23], [0, -0.19, 0], config.coat);
box(arm, [0.2, 0.16, 0.2], [0, -0.45, 0], skin);
arms.push(arm);
}
return {
...config,
root,
upper,
head,
legs,
arms,
brows,
eyes,
basePosition: new THREE.Vector3(
config.position[0],
0.14,
config.position[2]
),
outward: new THREE.Vector3(
config.position[0],
0,
config.position[2]
).normalize()
};
}
const characters = [
createCharacter({
id: "pip",
position: [-3.0, 0, 1.0],
yaw: 0.12,
headYaw: 0.27,
coat: 0x4fc3c7,
trousers: 0x315e78,
accent: 0xffcc68,
skin: 0xf0bf98,
hair: 0x423343
}),
createCharacter({
id: "nia",
position: [3.0, 0, 0.8],
yaw: -0.15,
headYaw: -0.27,
coat: 0xa88ad8,
trousers: 0x55406f,
accent: 0x79c9ad,
skin: 0x8d5947,
hair: 0x322a38
}),
createCharacter({
id: "oren",
position: [-2.2, 0, -2.0],
yaw: 0.42,
headYaw: 0.08,
coat: 0xe9825b,
trousers: 0x744b55,
accent: 0xf2c26f,
skin: 0xd69b73,
hair: 0x50372e
}),
createCharacter({
id: "miso",
position: [2.35, 0, -1.8],
yaw: 0.78,
headYaw: 0.035,
coat: 0x8cb8ef,
trousers: 0x4d6190,
accent: 0xffb35f,
skin: 0xf0cfad,
hair: 0x493948
})
];
const byId = Object.fromEntries(characters.map((c) => [c.id, c]));
function resetCharacter(c) {
c.root.position.copy(c.basePosition);
c.root.rotation.y = c.yaw;
c.upper.position.set(0, 0.64, 0);
c.upper.rotation.set(0, 0, 0);
c.head.rotation.set(0, c.headYaw, 0);
for (const leg of c.legs) leg.rotation.set(0, 0, 0);
for (const arm of c.arms) arm.rotation.set(0, 0, 0);
for (const brow of c.brows) brow.position.y = 0.43;
for (const eye of c.eyes) eye.position.x = eye.position.x > 0 ? 0.13 : -0.13;
}
// ------------------------------------------------------------
// Authored performance blocks
// ------------------------------------------------------------
const CUE = 1.35;
const DURATION = 8.0;
function applyBlocking(c, q, blocking, ambientTime, index) {
resetCharacter(c);
const idlePhase = ambientTime * 2.1 + index * 1.7;
let idleAmount = 1;
// Nia's idle motion visibly pauses at the authored hold.
if (c.id === "nia" && q >= 0.1 && q < 2.4) {
idleAmount = 0;
}
if (blocking === 0) {
if (c.id === "pip") {
// A sustained forward lean, beginning just after the bloom.
const lean = smoothstep(0.05, 1.25, q);
c.upper.rotation.x = 0.43 * lean;
c.upper.rotation.y = 0.18 * lean;
c.upper.position.z = 0.11 * lean;
c.head.rotation.x = -0.17 * lean;
c.head.rotation.y += 0.05 * lean;
c.arms[0].rotation.x = -0.28 * lean;
c.arms[1].rotation.x = -0.18 * lean;
}
if (c.id === "nia") {
// A quick brow lift, small backward torso pause, and head tilt.
const lift = smoothstep(0.1, 0.48, q);
c.brows.forEach((brow) => {
brow.position.y = 0.43 + 0.115 * lift;
});
c.upper.rotation.x = -0.065 * lift;
c.head.rotation.x = -0.1 * lift;
c.head.rotation.z = 0.075 * lift;
}
if (c.id === "oren") {
// One deliberate backward step, with alternating feet.
const step = smoothstep(0.16, 0.9, q);
const stride = Math.sin(Math.max(0, q - 0.16) * 8.5) *
(1 - smoothstep(0.85, 1.4, q));
c.root.position.addScaledVector(c.outward, 0.76 * step);
c.legs[0].rotation.x = 0.5 * stride;
c.legs[1].rotation.x = -0.48 * stride;
c.upper.rotation.x = 0.07 * step;
c.head.rotation.y -= 0.11 * step;
}
if (c.id === "miso") {
// The body and head continue to address the nearby pinwheel.
c.head.rotation.y = c.headYaw + 0.025 * Math.sin(ambientTime * 1.4);
c.arms[0].rotation.x = -0.08;
}
} else {
if (c.id === "pip") {
// A shorter, quicker lean followed by a steadier hold.
const lean = smoothstep(0.02, 0.5, q);
const settle = 0.82 + 0.18 * smoothstep(0.65, 1.45, q);
c.upper.rotation.x = 0.34 * lean * settle;
c.upper.rotation.y = 0.22 * lean;
c.upper.position.z = 0.075 * lean;
c.head.rotation.x = -0.21 * lean;
c.head.rotation.y += 0.08 * lean;
c.arms[0].rotation.x = -0.2 * lean;
}
if (c.id === "nia") {
// A slower brow lift followed by a small torso recoil.
const lift = smoothstep(0.18, 0.9, q);
const recoil = smoothstep(0.58, 1.05, q);
c.brows.forEach((brow) => {
brow.position.y = 0.43 + 0.125 * lift;
});
c.upper.rotation.x = -0.09 * recoil;
c.upper.rotation.y = -0.055 * recoil;
c.head.rotation.x = -0.075 * lift;
c.head.rotation.z = -0.055 * recoil;
}
if (c.id === "oren") {
// A quicker retreat that partly settles while keeping the step legible.
const step = smoothstep(0.06, 0.5, q) *
(1 - 0.42 * smoothstep(1.05, 2.1, q));
const stride = Math.sin(Math.max(0, q - 0.06) * 11) *
(1 - smoothstep(0.62, 1.2, q));
c.root.position.addScaledVector(c.outward, 0.72 * step);
c.legs[0].rotation.x = 0.42 * stride;
c.legs[1].rotation.x = -0.55 * stride;
c.upper.rotation.x = 0.045 * step;
c.head.rotation.y -= 0.14 * step;
}
if (c.id === "miso") {
// The alternate take keeps the same propward attention.
c.head.rotation.y = c.headYaw - 0.035;
c.arms[0].rotation.x = -0.1;
c.arms[1].rotation.x = -0.04;
}
}
// Quiet ambient motion remains separate from the authored reaction.
c.upper.position.y += Math.sin(idlePhase) * 0.012 * idleAmount;
c.head.rotation.y += Math.sin(idlePhase * 0.73) * 0.014 * idleAmount;
c.arms[0].rotation.x += Math.sin(idlePhase) * 0.035 * idleAmount;
c.arms[1].rotation.x -= Math.sin(idlePhase) * 0.03 * idleAmount;
}
// ------------------------------------------------------------
// Timeline and interface
// ------------------------------------------------------------
const playButton = document.querySelector("#play");
const replayButton = document.querySelector("#replay");
const statusElement = document.querySelector("#status");
const clockElement = document.querySelector("#clock");
const progressElement = document.querySelector("#progress");
const blockingElement = document.querySelector("#blocking");
let playing = false;
let performanceTime = 0;
let activeBlocking = 0;
let hasCompleted = false;
function updateInterface() {
const progress = Math.min(1, performanceTime / DURATION);
progressElement.style.width = `${progress * 100}%`;
clockElement.textContent = `${performanceTime.toFixed(1)} / ${DURATION.toFixed(1)} s`;
blockingElement.textContent = `Blocking ${activeBlocking === 0 ? "A" : "B"}`;
if (!playing && !hasCompleted) {
statusElement.textContent = "Ready for the cue";
} else if (!playing && hasCompleted) {
statusElement.textContent = "Performance complete";
} else if (performanceTime < CUE) {
statusElement.textContent = "Winding the clockwork key";
} else if (performanceTime < CUE + 0.9) {
statusElement.textContent = "The paper flower unfolds";
} else if (performanceTime < 5.6) {
statusElement.textContent = "Four authored reactions in motion";
} else {
statusElement.textContent = "Holding the final tableau";
}
}
function startPerformance() {
performanceTime = 0;
playing = true;
hasCompleted = false;
playButton.disabled = true;
replayButton.disabled = true;
characters.forEach(resetCharacter);
updateInterface();
}
function finishPerformance() {
playing = false;
hasCompleted = true;
performanceTime = DURATION;
playButton.disabled = false;
playButton.textContent = "Run again";
replayButton.disabled = false;
replayButton.textContent =
activeBlocking === 0
? "Replay · alternate blocking"
: "Replay · first blocking";
updateInterface();
}
playButton.addEventListener("click", startPerformance);
replayButton.addEventListener("click", () => {
activeBlocking = activeBlocking === 0 ? 1 : 0;
startPerformance();
});
// ------------------------------------------------------------
// Main animation
// ------------------------------------------------------------
function updateToyAndFlower(time) {
const beforeCue = time < CUE;
const windSpeed = beforeCue ? 3.2 + 4.5 * smoothstep(0, CUE, time) : 6.5;
windupKey.rotation.x = -time * windSpeed;
const spring = beforeCue
? Math.sin(time * 30) * 0.012 * smoothstep(CUE - 0.38, CUE, time)
: 0;
toy.position.y = 0.14 + spring;
toy.rotation.z = spring * 0.35;
const stemRise = smoothstep(CUE, CUE + 0.16, time);
const stemScale = 0.035 + 0.965 * stemRise;
stem.scale.y = stemScale;
stem.position.y = 0.58 + 0.59 * stemScale;
flower.position.y = 0.58 + 1.18 * stemScale;
flower.rotation.y = Math.max(0, time - CUE) * 0.13;
let totalOpen = 0;
petalHinges.forEach((hinge, i) => {
const start = CUE + 0.07 + i * 0.035;
const amount = smoothstep(start, start + 0.38, time);
const eased = easeOutBack(amount);
hinge.rotation.x = -Math.PI / 2 + (Math.PI / 2) * eased;
totalOpen += amount;
});
const openAmount = totalOpen / petalHinges.length;
bloomLight.intensity = 1.8 * openAmount;
bloomLight.position.y = flower.position.y + 0.1;
}
let previousTime = performance.now();
function animate(now) {
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing) {
performanceTime += delta;
if (performanceTime >= DURATION) {
finishPerformance();
}
}
const ambientTime = now / 1000;
characters.forEach((character, index) => {
applyBlocking(
character,
performanceTime - CUE,
activeBlocking,
ambientTime,
index
);
});
updateToyAndFlower(performanceTime);
// The prop keeps moving independently of the performance cue.
pinwheel.rotation.y = ambientTime * 1.15;
pinwheel.rotation.z = Math.sin(ambientTime * 1.6) * 0.045;
updateInterface();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
});
characters.forEach(resetCharacter);
updateInterface();
document.querySelector("#loading").classList.add("hidden");
requestAnimationFrame(animate);
</script>
</body>
</html>
```