Prompt specification
Build or customize the Three.js 3D scene "Accidental Bump and Careful Repair" 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: Accidental Bump and Careful Repair
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/accidental-bump-and-careful-repair-x3702
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring character choices and their visible consequences. Animate a character bumping a lightweight pot, noticing the change, and setting it upright. Preserve object continuity and make each state transition visible. Voxel style.
Working Three.js Starter (accidental-bump-and-careful-repair-x3702):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The Lightweight Pot</title>
<style>
:root {
--ink: #20323b;
--paper: #fff8e9;
--yellow: #ffd166;
--mint: #57c7b6;
--coral: #ef765f;
--blue: #4e7aa8;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c8dce0;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", monospace;
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
button {
font: inherit;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel,
#status-card {
pointer-events: auto;
}
#title-card {
position: absolute;
top: 18px;
left: 18px;
max-width: 490px;
padding: 16px 18px;
background: var(--paper);
border: 3px solid var(--ink);
box-shadow: 6px 6px 0 rgba(32, 50, 59, 0.24);
}
#title-card h1 {
margin: 0;
font-size: clamp(1.2rem, 2.3vw, 2rem);
line-height: 1;
letter-spacing: -0.05em;
}
#title-card p {
margin: 9px 0 0;
max-width: 430px;
font-size: 0.78rem;
line-height: 1.5;
}
#control-panel {
position: absolute;
top: 18px;
right: 18px;
width: min(330px, calc(100vw - 36px));
max-height: calc(100vh - 36px);
overflow: auto;
padding: 16px;
background: var(--paper);
border: 3px solid var(--ink);
box-shadow: 6px 6px 0 rgba(32, 50, 59, 0.24);
}
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 0 8px;
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.section-label + .section-label {
margin-top: 17px;
}
.hint {
color: #66777d;
font-size: 0.65rem;
font-weight: 500;
letter-spacing: 0;
text-transform: none;
}
.choice-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.choice {
position: relative;
min-height: 72px;
padding: 10px 9px;
color: var(--ink);
text-align: left;
background: #e8eee8;
border: 2px solid var(--ink);
box-shadow: 3px 3px 0 var(--ink);
cursor: pointer;
transition:
transform 100ms ease,
box-shadow 100ms ease,
background 100ms ease;
}
.choice:hover:not(:disabled) {
transform: translate(-1px, -1px);
box-shadow: 4px 4px 0 var(--ink);
}
.choice.selected {
background: var(--yellow);
transform: translate(2px, 2px);
box-shadow: 1px 1px 0 var(--ink);
}
.choice:disabled {
cursor: default;
opacity: 0.62;
}
.choice strong {
display: block;
margin-bottom: 5px;
font-size: 0.88rem;
}
.choice small {
display: block;
font-size: 0.62rem;
line-height: 1.35;
}
.swatch {
display: inline-block;
width: 10px;
height: 10px;
margin-right: 5px;
border: 1px solid var(--ink);
vertical-align: 1px;
}
#character-description,
#action-description {
min-height: 2.5em;
margin: 8px 0 0;
color: #53666d;
font-size: 0.67rem;
line-height: 1.45;
}
#consequence {
margin: 10px 0 13px;
padding: 10px;
background: #e8eee8;
border: 2px dashed var(--ink);
font-size: 0.7rem;
line-height: 1.5;
}
#consequence strong {
display: block;
margin-bottom: 3px;
}
.button-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
}
#start-button,
#reset-button {
min-height: 44px;
border: 2px solid var(--ink);
box-shadow: 3px 3px 0 var(--ink);
cursor: pointer;
font-weight: 900;
}
#start-button {
background: var(--mint);
color: var(--ink);
}
#reset-button {
padding: 0 12px;
background: var(--paper);
color: var(--ink);
}
#start-button:active:not(:disabled),
#reset-button:active:not(:disabled) {
transform: translate(2px, 2px);
box-shadow: 1px 1px 0 var(--ink);
}
#start-button:disabled {
cursor: default;
opacity: 0.62;
}
#status-card {
position: absolute;
left: 18px;
bottom: 18px;
width: min(510px, calc(100vw - 36px));
padding: 13px 15px 14px;
background: rgba(255, 248, 233, 0.95);
border: 3px solid var(--ink);
box-shadow: 6px 6px 0 rgba(32, 50, 59, 0.24);
}
#status-title {
margin: 0;
font-size: 0.9rem;
}
#status-detail {
min-height: 2.7em;
margin: 5px 0 10px;
color: #53666d;
font-size: 0.68rem;
line-height: 1.4;
}
#timeline {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 4px;
margin-bottom: 7px;
}
.phase {
padding: 5px 3px;
border: 2px solid var(--ink);
background: #e0e7df;
text-align: center;
font-size: 0.55rem;
font-weight: 800;
text-transform: uppercase;
}
.phase.current {
background: var(--yellow);
}
.phase.done {
background: var(--mint);
}
#progress-track {
height: 8px;
overflow: hidden;
background: #d9dfd8;
border: 2px solid var(--ink);
}
#progress-fill {
width: 0%;
height: 100%;
background: var(--coral);
}
#camera-hint {
position: absolute;
right: 18px;
bottom: 18px;
padding: 8px 10px;
color: #31464f;
background: rgba(255, 248, 233, 0.82);
border: 2px solid rgba(32, 50, 59, 0.5);
font-size: 0.62rem;
}
@media (max-width: 760px) {
#title-card {
top: 10px;
left: 10px;
right: 10px;
max-width: none;
padding: 11px 13px;
}
#title-card p {
display: none;
}
#control-panel {
top: auto;
right: 10px;
bottom: 10px;
width: calc(100vw - 20px);
max-height: 48vh;
padding: 12px;
}
#status-card {
top: 67px;
bottom: auto;
left: 10px;
width: calc(100vw - 20px);
padding: 9px 11px;
}
#status-detail {
min-height: 0;
}
#camera-hint {
display: none;
}
.choice {
min-height: 58px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel scene with a character, a pot, and visible consequences"></canvas>
<div id="ui">
<header id="title-card">
<h1>THE LIGHTWEIGHT POT</h1>
<p>
Choose a character and an impulse. The pot, its contents, and every
transition remain continuous so the consequences are easy to read.
</p>
</header>
<aside id="control-panel" aria-label="Scene controls">
<div class="section-label">
<span>1. Character</span>
<span class="hint">changes the force</span>
</div>
<div class="choice-grid">
<button class="choice selected" data-character="pip" type="button">
<strong><span class="swatch" style="background:#57c7b6"></span>Pip</strong>
<small>Light steps<br>smaller wobble</small>
</button>
<button class="choice" data-character="mox" type="button">
<strong><span class="swatch" style="background:#ef765f"></span>Mox</strong>
<small>Heavy stride<br>stronger bump</small>
</button>
</div>
<p id="character-description"></p>
<div class="section-label">
<span>2. Impulse</span>
<span class="hint">changes the spill</span>
</div>
<div class="choice-grid">
<button class="choice selected" data-action="gentle" type="button">
<strong>Nudge</strong>
<small>Light touch<br>one cube spills</small>
</button>
<button class="choice" data-action="bold" type="button">
<strong>Bump</strong>
<small>Hard hit<br>three cubes spill</small>
</button>
</div>
<p id="action-description"></p>
<div id="consequence"></div>
<div class="button-row">
<button id="start-button" type="button">Start sequence</button>
<button id="reset-button" type="button">Reset</button>
</div>
</aside>
<section id="status-card" aria-live="polite">
<h2 id="status-title">Ready when you are</h2>
<p id="status-detail">
Choose Pip or Mox, then choose a nudge or a bump.
</p>
<div id="timeline">
<div class="phase">Walk</div>
<div class="phase">Bump</div>
<div class="phase">Notice</div>
<div class="phase">Move</div>
<div class="phase">Upright</div>
</div>
<div id="progress-track">
<div id="progress-fill"></div>
</div>
</section>
<div id="camera-hint">Drag to orbit · Wheel to zoom · Double-click to reset view</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
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.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc8dce0);
scene.fog = new THREE.Fog(0xc8dce0, 19, 38);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Custom camera controls: no addons are imported.
const orbit = {
yaw: 0.67,
pitch: 0.58,
distance: 15.5,
target: new THREE.Vector3(-0.65, 0.7, 0.15)
};
function updateCamera() {
const horizontal = orbit.distance * Math.cos(orbit.pitch);
camera.position.set(
orbit.target.x + horizontal * Math.sin(orbit.yaw),
orbit.target.y + orbit.distance * Math.sin(orbit.pitch),
orbit.target.z + horizontal * Math.cos(orbit.yaw)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.yaw = 0.67;
orbit.pitch = 0.58;
orbit.distance = 15.5;
orbit.target.set(-0.65, 0.7, 0.15);
}
updateCamera();
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
orbit.yaw -= dx * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + dy * 0.005,
0.25,
1.25
);
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.distance = THREE.MathUtils.clamp(
orbit.distance * Math.exp(event.deltaY * 0.001),
9,
24
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
const hemiLight = new THREE.HemisphereLight(0xf5fbff, 0x8e9b78, 2.0);
scene.add(hemiLight);
const sun = new THREE.DirectionalLight(0xfff2d5, 3.2);
sun.position.set(-5, 10, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0005;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x9ec9ff, 1.2);
rimLight.position.set(7, 5, -6);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Materials and voxel helpers
// -------------------------------------------------------------------------
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.0,
...options
});
}
function addBox(parent, size, position, material, castShadow = true) {
const geometry = new THREE.BoxGeometry(...size);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const tileColors = [
0xd8d7b9,
0xd2d4b4,
0xcbd2ad,
0xe0dcc2,
0xc6cfa9
];
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.95,
vertexColors: true
});
const tileGeometry = new THREE.BoxGeometry(0.96, 0.18, 0.96);
const tileCount = 14 * 10;
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
tileCount
);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
let tileIndex = 0;
for (let x = 0; x < 14; x++) {
for (let z = 0; z < 10; z++) {
dummy.position.set(x - 6.5, -0.09, z - 4.5);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
color.setHex(
tileColors[
(x * 3 + z * 5 + Math.floor((x + z) / 3)) % tileColors.length
]
);
tiles.setColorAt(tileIndex, color);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
scene.add(tiles);
const baseMaterial = standardMaterial(0x87978b);
addBox(
scene,
[14.4, 0.42, 10.4],
[0, -0.34, 0],
baseMaterial,
false
);
const darkWood = standardMaterial(0x735646);
const lightWood = standardMaterial(0xb98558);
const leafMaterial = standardMaterial(0x4d8c63);
const leafLight = standardMaterial(0x78aa70);
const flowerMaterial = standardMaterial(0xe38a91);
function makePlant(x, z, scale = 1) {
const plant = new THREE.Group();
plant.position.set(x, 0, z);
plant.scale.setScalar(scale);
scene.add(plant);
addBox(plant, [0.75, 0.42, 0.75], [0, 0.21, 0], lightWood);
addBox(plant, [0.62, 0.08, 0.62], [0, 0.45, 0], darkWood);
addBox(plant, [0.12, 0.85, 0.12], [0, 0.88, 0], darkWood);
addBox(plant, [0.48, 0.28, 0.35], [0.2, 1.12, 0], leafMaterial);
addBox(plant, [0.38, 0.25, 0.35], [-0.2, 1.4, 0.04], leafLight);
addBox(plant, [0.28, 0.24, 0.28], [0.18, 1.72, 0], leafMaterial);
addBox(plant, [0.2, 0.2, 0.2], [0.18, 1.94, 0], flowerMaterial);
return plant;
}
makePlant(-4.8, -2.8, 1.05);
makePlant(-5.7, -1.9, 0.72);
makePlant(5.5, -3.0, 0.9);
function makeCrate(x, z, size = 0.8) {
const crate = new THREE.Group();
crate.position.set(x, 0, z);
scene.add(crate);
addBox(crate, [size, size, size], [0, size / 2, 0], lightWood);
addBox(
crate,
[size + 0.05, 0.12, size + 0.05],
[0, size * 0.72, 0],
darkWood
);
addBox(
crate,
[size + 0.05, 0.12, size + 0.05],
[0, size * 0.25, 0],
darkWood
);
return crate;
}
makeCrate(4.6, -2.5, 0.78);
makeCrate(5.5, -2.1, 0.62);
// A low voxel wall gives the diorama a backdrop.
for (let i = 0; i < 8; i++) {
const height = 0.45 + (i % 3) * 0.22;
addBox(
scene,
[1.0, height, 0.45],
[-5.7 + i * 1.0, height / 2, -4.15],
i % 2 === 0 ? baseMaterial : tileMaterial,
false
);
}
// -------------------------------------------------------------------------
// Pot and its home marker
// -------------------------------------------------------------------------
const POT_HOME = new THREE.Vector3(2.1, 0, 0);
const markerMaterial = standardMaterial(0xe3b94f);
const marker = new THREE.Group();
marker.position.copy(POT_HOME);
scene.add(marker);
addBox(marker, [0.52, 0.025, 0.08], [0, 0.014, -0.73], markerMaterial, false);
addBox(marker, [0.52, 0.025, 0.08], [0, 0.014, 0.73], markerMaterial, false);
addBox(marker, [0.08, 0.025, 0.52], [-0.73, 0.014, 0], markerMaterial, false);
addBox(marker, [0.08, 0.025, 0.52], [0.73, 0.014, 0], markerMaterial, false);
const pot = new THREE.Group();
pot.position.copy(POT_HOME);
scene.add(pot);
const potMaterial = standardMaterial(0xd77850);
const potLightMaterial = standardMaterial(0xf09a68);
const potDarkMaterial = standardMaterial(0xa94e3d);
const potInsideMaterial = standardMaterial(0x713e38);
// Stepped, hollow voxel pot.
addBox(pot, [1.08, 0.18, 1.08], [0, 0.09, 0], potDarkMaterial);
addBox(pot, [1.02, 0.48, 0.15], [0, 0.40, -0.45], potMaterial);
addBox(pot, [1.02, 0.48, 0.15], [0, 0.40, 0.45], potMaterial);
addBox(pot, [0.15, 0.48, 0.78], [-0.45, 0.40, 0], potMaterial);
addBox(pot, [0.15, 0.48, 0.78], [0.45, 0.40, 0], potMaterial);
addBox(pot, [1.25, 0.38, 0.15], [0, 0.82, -0.57], potLightMaterial);
addBox(pot, [1.25, 0.38, 0.15], [0, 0.82, 0.57], potLightMaterial);
addBox(pot, [0.15, 0.38, 1.0], [-0.57, 0.82, 0], potLightMaterial);
addBox(pot, [0.15, 0.38, 1.0], [0.57, 0.82, 0], potLightMaterial);
// Thick square rim.
addBox(pot, [1.40, 0.13, 0.22], [0, 1.06, -0.59], potLightMaterial);
addBox(pot, [1.40, 0.13, 0.22], [0, 1.06, 0.59], potLightMaterial);
addBox(pot, [0.22, 0.13, 1.02], [-0.59, 1.06, 0], potLightMaterial);
addBox(pot, [0.22, 0.13, 1.02], [0.59, 1.06, 0], potLightMaterial);
// Dark inner floor makes the open top readable.
addBox(pot, [1.03, 0.05, 1.03], [0, 0.56, 0], potInsideMaterial);
// Blocky handles.
for (const side of [-1, 1]) {
addBox(pot, [0.26, 0.12, 0.24], [side * 0.69, 0.61, 0], potDarkMaterial);
addBox(pot, [0.26, 0.12, 0.24], [side * 0.69, 0.94, 0], potDarkMaterial);
addBox(pot, [0.12, 0.43, 0.24], [side * 0.82, 0.775, 0], potDarkMaterial);
}
// These are the only contents. They are never replaced during the sequence.
const berryColors = [0x51b9b0, 0xf3c44e, 0x6d8ed9];
const berryMaterials = berryColors.map((c) => standardMaterial(c));
const berries = [];
const berryHomePositions = [
new THREE.Vector3(-0.22, 0.72, 0.13),
new THREE.Vector3(0.20, 0.72, -0.10),
new THREE.Vector3(0.00, 0.73, 0.18)
];
berryHomePositions.forEach((position, index) => {
const berry = addBox(
pot,
[0.22, 0.22, 0.22],
position.toArray(),
berryMaterials[index]
);
berry.userData.homePosition = position.clone();
berries.push(berry);
});
// -------------------------------------------------------------------------
// Voxel character
// -------------------------------------------------------------------------
const character = new THREE.Group();
scene.add(character);
const characterVisual = new THREE.Group();
character.add(characterVisual);
const skinMaterial = standardMaterial(0xe6b487);
const hairMaterial = standardMaterial(0x49362f);
const shoeMaterial = standardMaterial(0x293c49);
const eyeMaterial = standardMaterial(0x17252c);
const bodyMaterial = standardMaterial(0x57c7b6);
const accentMaterial = standardMaterial(0xf4c95d);
addBox(characterVisual, [0.60, 0.72, 0.48], [0, 1.13, 0], bodyMaterial);
addBox(characterVisual, [0.64, 0.12, 0.52], [0, 1.47, 0], accentMaterial);
const head = new THREE.Group();
head.position.set(0, 1.80, 0);
characterVisual.add(head);
addBox(head, [0.68, 0.64, 0.66], [0, 0, 0], skinMaterial);
addBox(head, [0.72, 0.14, 0.70], [0, 0.35, 0], hairMaterial);
addBox(head, [0.12, 0.35, 0.68], [-0.31, 0.18, 0], hairMaterial);
addBox(head, [0.08, 0.09, 0.09], [0.36, 0.06, -0.16], eyeMaterial);
addBox(head, [0.08, 0.09, 0.09], [0.36, 0.06, 0.16], eyeMaterial);
addBox(head, [0.12, 0.10, 0.11], [0.39, -0.05, 0], skinMaterial);
const pipHat = new THREE.Group();
head.add(pipHat);
addBox(pipHat, [0.76, 0.14, 0.73], [0, 0.46, 0], accentMaterial);
addBox(pipHat, [0.35, 0.07, 0.76], [0.48, 0.38, 0], accentMaterial);
const moxBackpack = new THREE.Group();
characterVisual.add(moxBackpack);
addBox(moxBackpack, [0.24, 0.48, 0.44], [-0.43, 1.14, 0], accentMaterial);
addBox(moxBackpack, [0.09, 0.40, 0.08], [-0.28, 1.16, -0.18], darkWood);
addBox(moxBackpack, [0.09, 0.40, 0.08], [-0.28, 1.16, 0.18], darkWood);
const legs = [];
const shoes = [];
for (const z of [-0.17, 0.17]) {
const leg = new THREE.Group();
leg.position.set(0, 0.75, z);
characterVisual.add(leg);
addBox(leg, [0.24, 0.58, 0.24], [0, -0.24, 0], bodyMaterial);
const shoe = addBox(
leg,
[0.38, 0.18, 0.28],
[0.07, -0.66, 0],
shoeMaterial
);
legs.push(leg);
shoes.push(shoe);
}
const arms = [];
for (const z of [-0.39, 0.39]) {
const arm = new THREE.Group();
arm.position.set(0.04, 1.43, z);
characterVisual.add(arm);
addBox(arm, [0.22, 0.56, 0.22], [0, -0.24, 0], bodyMaterial);
addBox(arm, [0.25, 0.20, 0.25], [0, -0.60, 0], skinMaterial);
arms.push(arm);
}
// -------------------------------------------------------------------------
// Notice bubble and impact pixels
// -------------------------------------------------------------------------
const bubble = new THREE.Group();
scene.add(bubble);
bubble.visible = false;
const bubbleBackMaterial = standardMaterial(0x20323b);
const bubbleFrontMaterial = standardMaterial(0xfff8e9);
const bubbleMarkMaterial = standardMaterial(0xf0ad2f);
addBox(bubble, [0.70, 0.82, 0.12], [0, 0, -0.04], bubbleBackMaterial, false);
addBox(bubble, [0.58, 0.70, 0.13], [0, 0, 0.035], bubbleFrontMaterial, false);
addBox(bubble, [0.10, 0.27, 0.09], [0, 0.13, 0.13], bubbleMarkMaterial, false);
addBox(bubble, [0.11, 0.11, 0.09], [0, -0.17, 0.13], bubbleMarkMaterial, false);
const impactBurst = new THREE.Group();
impactBurst.position.set(POT_HOME.x - 0.78, 0.76, 0);
scene.add(impactBurst);
impactBurst.visible = false;
const burstMaterial = new THREE.MeshBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 1
});
const burstDirections = [
new THREE.Vector3(-1, 0.2, 0),
new THREE.Vector3(-0.7, 0.8, 0),
new THREE.Vector3(-0.7, -0.5, 0),
new THREE.Vector3(0.2, 1, 0),
new THREE.Vector3(0.2, -1, 0),
new THREE.Vector3(0.8, 0.4, 0)
];
for (const direction of burstDirections) {
const pixel = addBox(
impactBurst,
[0.14, 0.14, 0.14],
[0, 0, 0],
burstMaterial,
false
);
pixel.userData.direction = direction;
}
// -------------------------------------------------------------------------
// State and choices
// -------------------------------------------------------------------------
const profiles = {
pip: {
name: "Pip",
force: 0.78,
stepFrequency: 10.2,
stepAmplitude: 0.43,
description:
"Pip approaches with quick, light steps. Pip transmits less force, so the pot rocks through a smaller arc."
},
mox: {
name: "Mox",
force: 1.18,
stepFrequency: 7.2,
stepAmplitude: 0.57,
description:
"Mox approaches with a heavier stride. The extra momentum creates a larger tilt and a longer slide."
}
};
const actions = {
gentle: {
name: "Nudge",
angle: 34,
slide: 0.42,
spills: 1,
description:
"A light nudge exposes one berry cube. The pot tilts, rocks, and remains light enough for the character to lift."
},
bold: {
name: "Bump",
angle: 68,
slide: 0.94,
spills: 3,
description:
"A hard bump throws all three berry cubes onto the floor and sends the pot into a pronounced, springy wobble."
}
};
const state = {
character: "pip",
action: "gentle",
running: false,
completed: false,
elapsed: 0,
duration: 6.7,
phase: -1,
finalShown: false
};
const startButton = document.querySelector("#start-button");
const resetButton = document.querySelector("#reset-button");
const statusTitle = document.querySelector("#status-title");
const statusDetail = document.querySelector("#status-detail");
const progressFill = document.querySelector("#progress-fill");
const phaseElements = [...document.querySelectorAll(".phase")];
const characterDescription = document.querySelector("#character-description");
const actionDescription = document.querySelector("#action-description");
const consequence = document.querySelector("#consequence");
const CHARACTER_START = new THREE.Vector3(-5.2, 0, 2.35);
const CHARACTER_CONTROL = new THREE.Vector3(-2.55, 0, 0);
const CONTACT_POINT = new THREE.Vector3(0.65, 0, 0);
const RIGHT_POINT = new THREE.Vector3(1.15, 0, 1.15);
const RIGHT_CONTROL = new THREE.Vector3(0.28, 0, 1.55);
const TIME = {
impact: 1.6,
impactEnd: 1.95,
noticeEnd: 2.9,
rightStart: 4.3,
rightEnd: 5.65
};
function selectedProfile() {
return profiles[state.character];
}
function selectedAction() {
return actions[state.action];
}
function predictedTilt() {
return Math.min(
74,
selectedAction().angle * selectedProfile().force
);
}
function setStatus(title, detail) {
if (statusTitle.textContent !== title) statusTitle.textContent = title;
if (statusDetail.textContent !== detail) statusDetail.textContent = detail;
}
function updateChoiceUI() {
document.querySelectorAll("[data-character]").forEach((button) => {
const selected = button.dataset.character === state.character;
button.classList.toggle("selected", selected);
button.disabled = state.running || state.completed;
});
document.querySelectorAll("[data-action]").forEach((button) => {
const selected = button.dataset.action === state.action;
button.classList.toggle("selected", selected);
button.disabled = state.running || state.completed;
});
startButton.disabled = state.running || state.completed;
startButton.textContent = state.completed
? "Sequence complete"
: state.running
? "Playing sequence…"
: "Start sequence";
characterDescription.textContent = selectedProfile().description;
actionDescription.textContent = selectedAction().description;
const tilt = Math.round(predictedTilt());
const spillText =
selectedAction().spills === 1 ? "1 cube spills" : "3 cubes spill";
consequence.innerHTML = `
<strong>Expected consequence</strong>
${tilt}° tip · ${spillText}<br>
The same pot is then lifted and rotated upright.
`;
}
function applyCharacterChoice() {
if (state.character === "pip") {
bodyMaterial.color.setHex(0x57c7b6);
accentMaterial.color.setHex(0xf4c95d);
pipHat.visible = true;
moxBackpack.visible = false;
} else {
bodyMaterial.color.setHex(0xef765f);
accentMaterial.color.setHex(0x4e7aa8);
pipHat.visible = false;
moxBackpack.visible = true;
}
}
function updateTimeline(phase) {
phaseElements.forEach((element, index) => {
element.classList.toggle("current", index === phase);
element.classList.toggle("done", phase >= 0 && index < phase);
});
}
function setPhase(phase) {
if (state.phase === phase) return;
state.phase = phase;
updateTimeline(phase);
const profile = selectedProfile();
const action = selectedAction();
if (phase === 0) {
setStatus(
`${profile.name} walks toward the pot`,
"The pot is still upright. The character closes the distance without replacing any scene objects."
);
} else if (phase === 1) {
setStatus(
"Contact — the lightweight pot tips",
`${action.name} transfers momentum into the same pot. It tilts approximately ${Math.round(predictedTilt())} degrees and slides slightly.`
);
} else if (phase === 2) {
setStatus(
`${profile.name} notices the change`,
"The character stops and looks back. The exclamation bubble appears while the pot continues its visible wobble."
);
} else if (phase === 3) {
setStatus(
"Moving around the fallen pot",
"The character circles to the front edge, keeping the pot, handles, and spilled contents physically continuous."
);
} else if (phase === 4) {
setStatus(
"Lifting and rotating the pot upright",
"The character grips the rim. The original pot mesh rises slightly and rotates smoothly back to zero degrees."
);
}
}
document.querySelectorAll("[data-character]").forEach((button) => {
button.addEventListener("click", () => {
if (state.running || state.completed) return;
state.character = button.dataset.character;
applyCharacterChoice();
updateChoiceUI();
});
});
document.querySelectorAll("[data-action]").forEach((button) => {
button.addEventListener("click", () => {
if (state.running || state.completed) return;
state.action = button.dataset.action;
updateChoiceUI();
});
});
// -------------------------------------------------------------------------
// Animation helpers
// -------------------------------------------------------------------------
function clamp01(value) {
return THREE.MathUtils.clamp(value, 0, 1);
}
function easeOutCubic(value) {
const x = clamp01(value);
return 1 - Math.pow(1 - x, 3);
}
function easeInOutCubic(value) {
const x = clamp01(value);
return x < 0.5
? 4 * x * x * x
: 1 - Math.pow(-2 * x + 2, 3) / 2;
}
function quadraticBezier(a, b, c, t) {
const oneMinusT = 1 - t;
return new THREE.Vector3(
oneMinusT * oneMinusT * a.x +
2 * oneMinusT * t * b.x +
t * t * c.x,
0,
oneMinusT * oneMinusT * a.z +
2 * oneMinusT * t * b.z +
t * t * c.z
);
}
function maxTiltRadians() {
return THREE.MathUtils.degToRad(predictedTilt());
}
function updatePot(time) {
const profile = selectedProfile();
const action = selectedAction();
const tilt = maxTiltRadians();
const slide = action.slide * profile.force;
let angle = 0;
let x = POT_HOME.x;
let z = POT_HOME.z;
let y = 0;
if (time >= TIME.impact) {
const u = clamp01((time - TIME.impact) / 0.9);
const eased = easeOutCubic(u);
angle = -tilt * eased;
x = POT_HOME.x + slide * eased;
z = POT_HOME.z - 0.13 * profile.force * eased;
// The lightweight pot continues to rock while the character notices.
if (time > 2.5 && time < TIME.rightStart) {
const settle = clamp01(
(time - 2.5) / (TIME.rightStart - 2.5)
);
angle +=
Math.sin(settle * Math.PI * 4) *
0.055 *
(1 - settle);
}
}
if (time >= TIME.rightStart) {
const u = clamp01(
(time - TIME.rightStart) / (TIME.rightEnd - TIME.rightStart)
);
const eased = easeInOutCubic(u);
const tiltedX = POT_HOME.x + slide;
const tiltedZ = POT_HOME.z - 0.13 * profile.force;
angle = THREE.MathUtils.lerp(-tilt, 0, eased);
x = THREE.MathUtils.lerp(tiltedX, POT_HOME.x, eased);
z = THREE.MathUtils.lerp(tiltedZ, POT_HOME.z, eased);
y = Math.sin(u * Math.PI) * 0.17;
}
pot.position.set(x, y, z);
pot.rotation.set(0, 0, angle);
pot.updateMatrixWorld(true);
}
function updateCharacter(time) {
const profile = selectedProfile();
let position = CHARACTER_START.clone();
let yaw = 0;
let bob = 0;
let crouch = 0;
let legSwing = 0;
let armA = 0.05;
let armB = -0.05;
if (time < TIME.impact) {
const u = clamp01(time / TIME.impact);
position = quadraticBezier(
CHARACTER_START,
CHARACTER_CONTROL,
CONTACT_POINT,
u
);
const walkTime = time * profile.stepFrequency;
legSwing = Math.sin(walkTime) * profile.stepAmplitude;
bob = Math.abs(Math.sin(walkTime)) * 0.045;
armA = -legSwing * 0.55;
armB = legSwing * 0.55;
} else if (time < TIME.impactEnd) {
const u = clamp01(
(time - TIME.impact) / (TIME.impactEnd - TIME.impact)
);
const eased = easeOutCubic(u);
position.copy(CONTACT_POINT);
position.x += Math.sin(u * Math.PI) * 0.09;
armA = THREE.MathUtils.lerp(0.25, 1.35, eased);
armB = THREE.MathUtils.lerp(-0.05, 0.7, eased);
bob = 0.015;
} else if (time < TIME.noticeEnd) {
const u = clamp01(
(time - TIME.impactEnd) / (TIME.noticeEnd - TIME.impactEnd)
);
const eased = easeInOutCubic(u);
position.copy(CONTACT_POINT);
position.x -= eased * 0.11;
armA = THREE.MathUtils.lerp(1.35, 0.12, eased);
armB = THREE.MathUtils.lerp(0.7, -0.05, eased);
} else if (time < TIME.rightStart) {
const u = clamp01(
(time - TIME.noticeEnd) / (TIME.rightStart - TIME.noticeEnd)
);
const eased = easeInOutCubic(u);
position = quadraticBezier(
CONTACT_POINT,
RIGHT_CONTROL,
RIGHT_POINT,
u
);
yaw = 0.95 * eased;
const walkTime = time * profile.stepFrequency;
legSwing = Math.sin(walkTime) * profile.stepAmplitude;
bob = Math.abs(Math.sin(walkTime)) * 0.04;
armA = -legSwing * 0.5;
armB = legSwing * 0.5;
} else if (time < TIME.rightEnd) {
const u = clamp01(
(time - TIME.rightStart) / (TIME.rightEnd - TIME.rightStart)
);
position.copy(RIGHT_POINT);
yaw = 0.95;
armA = 1.22 + Math.sin(u * Math.PI) * 0.16;
armB = 0.55 + Math.sin(u * Math.PI) * 0.12;
crouch = Math.sin(u * Math.PI) * 0.17;
legSwing = 0.13;
} else {
position.copy(RIGHT_POINT);
yaw = 0.95;
armA = 0.12;
armB = -0.05;
bob = Math.sin((time - TIME.rightEnd) * 3) * 0.008;
}
character.position.copy(position);
character.rotation.y = yaw;
characterVisual.position.y = bob - crouch;
legs[0].rotation.z = legSwing;
legs[1].rotation.z = -legSwing;
arms[0].rotation.z = armA;
arms[1].rotation.z = armB;
// The head tips slightly during the noticing beat.
const noticeAmount =
time >= TIME.impactEnd && time < TIME.noticeEnd
? Math.sin(
((time - TIME.impactEnd) /
(TIME.noticeEnd - TIME.impactEnd)) *
Math.PI
)
: 0;
head.rotation.z = -noticeAmount * 0.10;
}
function updateBubble(time) {
let scale = 0;
if (time >= TIME.impactEnd && time < TIME.noticeEnd + 0.12) {
const inAmount = clamp01(
(time - TIME.impactEnd) / 0.18
);
const outAmount =
time > TIME.noticeEnd
? clamp01((TIME.noticeEnd + 0.12 - time) / 0.12)
: 1;
scale = easeOutCubic(inAmount) * outAmount;
}
bubble.visible = scale > 0.01;
if (bubble.visible) {
bubble.position.copy(character.position);
bubble.position.y += 2.60;
bubble.quaternion.copy(camera.quaternion);
bubble.scale.setScalar(scale);
}
}
function updateImpactBurst(time) {
const active = time >= TIME.impact && time <= TIME.impact + 0.48;
impactBurst.visible = active;
if (!active) return;
const u = clamp01((time - TIME.impact) / 0.48);
burstMaterial.opacity = 1 - u;
impactBurst.children.forEach((pixel, index) => {
const direction = pixel.userData.direction;
pixel.position.copy(direction).multiplyScalar(u * 0.62);
pixel.position.y += Math.sin(u * Math.PI) * 0.12;
pixel.rotation.set(u * 2, u * 3, u * 4 + index);
pixel.scale.setScalar(Math.max(0.05, 1 - u * 0.85));
});
}
// Each berry is detached only after it has physically reached the rim.
// Object3D.attach preserves its world transform, so the cube never jumps.
const spillStates = berries.map(() => ({
active: false,
startTime: 0,
startPosition: new THREE.Vector3(),
startQuaternion: new THREE.Quaternion(),
targetPosition: new THREE.Vector3(),
targetQuaternion: new THREE.Quaternion()
}));
function updateSpills(time) {
const spillCount = selectedAction().spills;
berries.forEach((berry, index) => {
const spill = spillStates[index];
if (index >= spillCount || spill.active) return;
const eventTime = TIME.impact + 0.18 + index * 0.17;
if (time < eventTime) return;
pot.updateMatrixWorld(true);
berry.getWorldPosition(spill.startPosition);
berry.getWorldQuaternion(spill.startQuaternion);
scene.attach(berry);
spill.active = true;
spill.startTime = eventTime;
spill.targetPosition.set(
POT_HOME.x + 0.92 + index * 0.44,
0.115,
POT_HOME.z - 0.05 - index * 0.34
);
spill.targetQuaternion.setFromEuler(
new THREE.Euler(
index * 0.7 + 0.4,
index * 1.1,
index * 0.9
)
);
});
spillStates.forEach((spill, index) => {
if (!spill.active) return;
const u = clamp01(
(time - spill.startTime) / (1.05 + index * 0.08)
);
const eased = easeOutCubic(u);
berries[index].position.lerpVectors(
spill.startPosition,
spill.targetPosition,
eased
);
berries[index].position.y +=
Math.sin(u * Math.PI) * (0.75 + index * 0.08);
berries[index].quaternion.slerpQuaternions(
spill.startQuaternion,
spill.targetQuaternion,
eased
);
});
}
// -------------------------------------------------------------------------
// Reset and sequence control
// -------------------------------------------------------------------------
function resetScene() {
state.running = false;
state.completed = false;
state.elapsed = 0;
state.phase = -1;
state.finalShown = false;
pot.position.copy(POT_HOME);
pot.rotation.set(0, 0, 0);
pot.updateMatrixWorld(true);
berries.forEach((berry, index) => {
pot.add(berry);
berry.position.copy(berry.userData.homePosition);
berry.quaternion.identity();
berry.scale.setScalar(1);
spillStates[index].active = false;
});
bubble.visible = false;
impactBurst.visible = false;
burstMaterial.opacity = 1;
updatePot(0);
updateCharacter(0);
updateSpills(0);
progressFill.style.width = "0%";
updateTimeline(-1);
setStatus(
"Ready when you are",
"Choose Pip or Mox, then choose a nudge or a bump."
);
updateChoiceUI();
}
function startSequence() {
if (state.running || state.completed) return;
resetScene();
state.running = true;
updateChoiceUI();
setPhase(0);
}
function completeSequence() {
state.running = false;
state.completed = true;
state.elapsed = state.duration;
updatePot(state.elapsed);
updateCharacter(state.elapsed);
updateSpills(state.elapsed);
progressFill.style.width = "100%";
updateTimeline(5);
state.phase = 4;
setStatus(
"Upright again — consequences remain",
"The original pot is upright on its marker. Spilled cubes stay on the floor, making the chosen character and impulse visible."
);
updateChoiceUI();
}
startButton.addEventListener("click", startSequence);
resetButton.addEventListener("click", resetScene);
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && !state.running && !state.completed) {
event.preventDefault();
startSequence();
}
if (event.key.toLowerCase() === "r") {
resetScene();
}
});
// -------------------------------------------------------------------------
// Main loop
// -------------------------------------------------------------------------
function updatePhaseFromTime(time) {
let phase = 0;
if (time >= TIME.rightStart) phase = 4;
else if (time >= TIME.noticeEnd) phase = 3;
else if (time >= TIME.impactEnd) phase = 2;
else if (time >= TIME.impact) phase = 1;
setPhase(phase);
if (phase === 4 && time >= TIME.rightEnd && !state.finalShown) {
state.finalShown = true;
setStatus(
"Upright again — consequences remain",
"The original pot is upright on its marker. Spilled cubes stay on the floor, making the chosen character and impulse visible."
);
}
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (state.running) {
state.elapsed = Math.min(
state.elapsed + delta,
state.duration
);
updatePot(state.elapsed);
updateCharacter(state.elapsed);
updateSpills(state.elapsed);
updateBubble(state.elapsed);
updateImpactBurst(state.elapsed);
updatePhaseFromTime(state.elapsed);
progressFill.style.width = `${
(state.elapsed / state.duration) * 100
}%`;
if (state.elapsed >= state.duration) {
completeSequence();
}
} else {
updatePot(state.elapsed);
updateCharacter(state.elapsed);
updateSpills(state.elapsed);
updateBubble(state.elapsed);
updateImpactBurst(state.elapsed);
}
updateCamera();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
applyCharacterChoice();
updateChoiceUI();
resetScene();
animate();
</script>
</body>
</html>
```