Prompt specification
Build or customize the Three.js 3D scene "Family Picnic Setup Scene" 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: Family Picnic Setup Scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/family-picnic-setup-scene-x3683
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing characters with varied ages, proportions, and mobility. Build an original park picnic where characters share carrying, arranging, and playing tasks. Show varied participation without assigning caregiving or work roles by stereotype. Voxel style.
Working Three.js Starter (family-picnic-setup-scene-x3683):
```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="#d8eadc" />
<title>Pocket Park Picnic — A Shared Afternoon</title>
<style>
:root {
--ink: #193b34;
--muted: #58746b;
--paper: rgba(255, 252, 240, 0.92);
--line: rgba(25, 59, 52, 0.14);
--accent: #ee775d;
--accent-2: #287e70;
--shadow: 0 14px 40px rgba(31, 65, 54, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cfe7d9;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active { cursor: grabbing; }
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.panel {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow: var(--shadow);
backdrop-filter: blur(14px) saturate(1.12);
-webkit-backdrop-filter: blur(14px) saturate(1.12);
}
.brand {
position: absolute;
top: 22px;
left: 22px;
width: min(420px, calc(100vw - 44px));
padding: 18px 20px 17px;
border-radius: 22px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--accent-2);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--accent);
box-shadow: 13px 0 0 #f0bd4e;
margin-right: 13px;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 38px);
line-height: 1;
letter-spacing: -0.045em;
}
.brand p {
margin: 9px 0 0;
max-width: 350px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.top-controls {
position: absolute;
top: 22px;
right: 22px;
display: flex;
gap: 8px;
pointer-events: auto;
}
.icon-button {
min-height: 44px;
padding: 0 15px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--paper);
color: var(--ink);
box-shadow: 0 8px 24px rgba(31, 65, 54, 0.11);
cursor: pointer;
font-size: 13px;
font-weight: 750;
transition: transform 160ms ease, background 160ms ease;
}
.icon-button:hover {
transform: translateY(-2px);
background: #fffdf5;
}
.icon-button:focus-visible,
.task-button:focus-visible {
outline: 3px solid rgba(238, 119, 93, 0.38);
outline-offset: 3px;
}
.story-card {
position: absolute;
left: 22px;
bottom: 116px;
width: min(350px, calc(100vw - 44px));
padding: 15px 17px;
border-radius: 18px;
}
.story-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 6px;
}
.story-number {
color: var(--accent);
font-size: 12px;
font-weight: 900;
letter-spacing: 0.12em;
}
.story-title {
margin: 0 0 4px;
font-size: 18px;
letter-spacing: -0.025em;
}
.story-copy {
margin: 0;
color: var(--muted);
font-size: 12.5px;
line-height: 1.45;
}
.task-dock {
position: absolute;
left: 50%;
bottom: 20px;
width: min(720px, calc(100vw - 36px));
transform: translateX(-50%);
padding: 12px;
border-radius: 20px;
pointer-events: auto;
}
.progress-track {
height: 4px;
overflow: hidden;
margin: 0 4px 10px;
border-radius: 999px;
background: rgba(25, 59, 52, 0.10);
}
#progress-fill {
width: 100%;
height: 100%;
transform: scaleX(0);
transform-origin: left center;
background: linear-gradient(90deg, #ef795e, #efb84e, #2b8978);
border-radius: inherit;
}
.task-list {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
}
.task-button {
display: flex;
align-items: center;
gap: 10px;
min-width: 0;
padding: 10px 11px;
border: 1px solid transparent;
border-radius: 13px;
background: transparent;
color: var(--muted);
cursor: pointer;
text-align: left;
transition: background 160ms ease, color 160ms ease, border-color 160ms ease;
}
.task-button:hover {
background: rgba(40, 126, 112, 0.08);
color: var(--ink);
}
.task-button.active {
background: #fffdf5;
border-color: rgba(25, 59, 52, 0.10);
color: var(--ink);
box-shadow: 0 5px 14px rgba(31, 65, 54, 0.08);
}
.task-dot {
flex: 0 0 auto;
display: grid;
place-items: center;
width: 29px;
height: 29px;
border-radius: 9px;
color: white;
font-size: 10px;
font-weight: 900;
background: var(--dot);
}
.task-label {
overflow: hidden;
font-size: 12px;
font-weight: 800;
white-space: nowrap;
text-overflow: ellipsis;
}
.camera-hint {
position: absolute;
right: 22px;
bottom: 116px;
padding: 9px 12px;
border-radius: 11px;
background: rgba(255, 252, 240, 0.76);
color: var(--muted);
font-size: 11px;
backdrop-filter: blur(10px);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #d6e9dc;
transition: opacity 450ms ease, visibility 450ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
.loader-box {
text-align: center;
color: var(--ink);
}
.loader-cubes {
display: flex;
justify-content: center;
gap: 5px;
margin-bottom: 17px;
}
.loader-cubes i {
width: 14px;
height: 14px;
background: var(--accent);
animation: hop 900ms infinite ease-in-out;
}
.loader-cubes i:nth-child(2) {
background: #efbd51;
animation-delay: 120ms;
}
.loader-cubes i:nth-child(3) {
background: #2c8877;
animation-delay: 240ms;
}
.loader-box strong {
display: block;
font-size: 15px;
}
.loader-box small {
display: block;
margin-top: 6px;
color: var(--muted);
}
@keyframes hop {
0%, 70%, 100% { transform: translateY(0); }
35% { transform: translateY(-8px); }
}
@media (max-width: 720px) {
.brand {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.brand p { display: none; }
.top-controls {
top: 101px;
right: 12px;
}
.icon-button {
min-height: 38px;
padding: 0 11px;
font-size: 12px;
}
.story-card {
left: 12px;
bottom: 102px;
width: min(310px, calc(100vw - 24px));
padding: 12px 14px;
}
.story-copy { font-size: 11.5px; }
.camera-hint { display: none; }
.task-dock {
bottom: 10px;
width: calc(100vw - 20px);
padding: 9px;
}
.task-button {
justify-content: center;
padding: 8px 5px;
}
.task-dot {
width: 25px;
height: 25px;
}
.task-label {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
* { scroll-behavior: auto !important; }
.loader-cubes i { animation: none; }
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel picnic scene"></main>
<div class="hud">
<header class="brand panel">
<div class="eyebrow">Pocket Park Picnic</div>
<h1>A shared afternoon</h1>
<p>Five guests of different ages, builds, and ways of moving take turns carrying, arranging, and playing.</p>
</header>
<div class="top-controls">
<button class="icon-button" id="pause-button" type="button" aria-pressed="false">Pause</button>
<button class="icon-button" id="reset-view" type="button">Reset view</button>
</div>
<section class="story-card panel" aria-live="polite">
<div class="story-top">
<span class="story-number" id="story-number">01 / 04</span>
<span class="story-number" id="story-tag">SHARED TASK</span>
</div>
<h2 class="story-title" id="story-title">The snack run</h2>
<p class="story-copy" id="story-copy">Everyone carries a piece of the picnic, choosing a comfortable pace and way to move.</p>
</section>
<nav class="task-dock panel" aria-label="Picnic activity timeline">
<div class="progress-track" aria-hidden="true"><div id="progress-fill"></div></div>
<div class="task-list">
<button class="task-button active" type="button" data-start="0" style="--dot:#ee775d">
<span class="task-dot">01</span><span class="task-label">Carry</span>
</button>
<button class="task-button" type="button" data-start="9" style="--dot:#efb84e">
<span class="task-dot">02</span><span class="task-label">Arrange</span>
</button>
<button class="task-button" type="button" data-start="17" style="--dot:#2d8878">
<span class="task-dot">03</span><span class="task-label">Play</span>
</button>
<button class="task-button" type="button" data-start="27" style="--dot:#8d6bb1">
<span class="task-dot">04</span><span class="task-label">Share</span>
</button>
</div>
</nav>
<div class="camera-hint">Drag to orbit · Shift/right-drag to pan · Scroll to zoom</div>
</div>
<div id="loading" role="status" aria-label="Loading picnic scene">
<div class="loader-box">
<div class="loader-cubes"><i></i><i></i><i></i></div>
<strong>Setting out the picnic</strong>
<small>Building a little park, one block at a time.</small>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
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.08;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcfe8dc);
scene.fog = new THREE.Fog(0xcfe8dc, 27, 48);
const camera = new THREE.OrthographicCamera(-10, 10, 8, -8, 0.1, 100);
const view = {
yaw: 0.66,
phi: 0.88,
zoom: 1,
target: new THREE.Vector3(0, 0.3, 0)
};
const hemisphere = new THREE.HemisphereLight(0xf6fff2, 0x6d8c70, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2cf, 3.4);
sun.position.set(-9, 16, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.normalBias = 0.025;
sun.shadow.bias = -0.0002;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbde7ef, 0.8);
fill.position.set(10, 7, -9);
scene.add(fill);
const materials = new Map();
function material(color) {
if (!materials.has(color)) {
materials.set(color, new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0
}));
}
return materials.get(color);
}
function box(parent, w, h, d, color, x = 0, y = 0, z = 0, castShadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material(color));
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function group(parent = scene) {
const g = new THREE.Group();
parent.add(g);
return g;
}
function clamp(v, min, max) {
return Math.max(min, Math.min(max, v));
}
function smooth(v) {
const x = clamp(v, 0, 1);
return x * x * (3 - 2 * x);
}
function lerp(a, b, t) {
return a + (b - a) * t;
}
function damp(current, target, lambda, dt) {
return THREE.MathUtils.lerp(current, target, 1 - Math.exp(-lambda * dt));
}
function angleLerp(a, b, t) {
let difference = ((b - a + Math.PI) % (Math.PI * 2)) - Math.PI;
if (difference < -Math.PI) difference += Math.PI * 2;
return a + difference * t;
}
// ---------------------------------------------------------------------
// Voxel park
// ---------------------------------------------------------------------
const park = group();
box(park, 30, 0.5, 24, 0x8fc68e, 0, -0.28, 0, false);
box(park, 29.7, 0.08, 23.7, 0x9bcf96, 0, -0.005, 0, false);
// Soft, square-edged grass patches.
const grassPatches = [
[-10.2, 1.5, 2.2, 0.65, 1.5],
[8.7, -4.8, 2.6, 0.65, 1.8],
[-2.7, 7.2, 4.2, 0.65, 1.0],
[10.0, 4.0, 1.6, 0.65, 2.8],
[-7.0, -8.5, 2.8, 0.65, 1.2]
];
for (const [x, z, w, h, d] of grassPatches) {
box(park, w, 0.055, d, 0x83ba80, x, 0.015, z, false);
}
// Stepped path into the picnic area.
for (let i = 0; i < 10; i++) {
box(park, 2.55, 0.055, 0.69, i % 2 ? 0xdcc89d : 0xe4d2aa,
1.15, 0.035, 4.65 + i * 0.72, false);
box(park, 2.1, 0.058, 0.66, 0xe5d3aa,
1.15, 0.036, 4.65 + i * 0.72, false);
}
function makeTree(x, z, scale = 1, palette = [0x4f8e59, 0x67a865, 0x79b66e]) {
const tree = group(park);
tree.position.set(x, 0, z);
box(tree, 0.48 * scale, 2.7 * scale, 0.48 * scale, 0x80583d, 0, 1.35 * scale, 0);
box(tree, 0.68 * scale, 0.25 * scale, 0.68 * scale, 0x80583d, 0, 0.2 * scale, 0);
box(tree, 2.9 * scale, 1.55 * scale, 2.45 * scale, palette[0], 0, 3.25 * scale, 0);
box(tree, 2.05 * scale, 1.45 * scale, 2.0 * scale, palette[1], -0.75 * scale, 4.12 * scale, 0.18 * scale);
box(tree, 2.05 * scale, 1.45 * scale, 2.0 * scale, palette[2], 0.78 * scale, 4.0 * scale, -0.1 * scale);
box(tree, 1.55 * scale, 1.2 * scale, 1.55 * scale, palette[1], 0.15 * scale, 4.85 * scale, 0.18 * scale);
}
makeTree(-10.1, -6.8, 1.05);
makeTree(-7.8, -8.8, 0.88);
makeTree(8.6, -7.6, 1.0);
makeTree(10.6, 2.8, 1.14, [0x437e54, 0x5b9b5d, 0x6eac64]);
makeTree(-11.0, 6.4, 1.1);
makeTree(8.7, 8.7, 0.9);
makeTree(12.2, -2.0, 0.74);
// Small block-built pond.
const pond = group(park);
pond.position.set(-7.0, 0.03, -4.6);
box(pond, 3.2, 0.05, 2.15, 0x6ebbc0, 0, 0, 0, false);
box(pond, 2.3, 0.055, 1.42, 0x82cdd0, -0.2, 0.01, -0.05, false);
box(pond, 0.75, 0.06, 0.46, 0x9bdbd8, 0.75, 0.015, 0.36, false);
// Bench.
const bench = group(park);
bench.position.set(-1.7, 0, -7.5);
box(bench, 3.1, 0.18, 0.22, 0x986744, 0, 0.82, 0);
box(bench, 3.1, 0.18, 0.22, 0x986744, 0, 1.25, -0.38);
for (const x of [-1.15, 1.15]) {
box(bench, 0.18, 0.9, 0.18, 0x47534c, x, 0.45, 0);
box(bench, 0.18, 1.4, 0.18, 0x47534c, x, 0.7, -0.34);
}
// Picnic blanket, built from alternating square tiles.
const blanketGroup = group(park);
const tileSize = 0.48;
const columns = 14;
const rows = 10;
const blanketCenterX = 2.1;
const blanketCenterZ = 1.15;
const tileMatrices = [[], []];
for (let row = 0; row < rows; row++) {
for (let col = 0; col < columns; col++) {
const x = blanketCenterX + (col - (columns - 1) / 2) * tileSize;
const z = blanketCenterZ + (row - (rows - 1) / 2) * tileSize;
const colorIndex = (row + col) % 2;
tileMatrices[colorIndex].push(new THREE.Matrix4().makeTranslation(x, 0.055, z));
}
}
const tileGeometry = new THREE.BoxGeometry(tileSize * 0.94, 0.065, tileSize * 0.94);
[0xf4d5bd, 0xd96f5b].forEach((color, index) => {
const tiles = new THREE.InstancedMesh(tileGeometry, material(color), tileMatrices[index].length);
tileMatrices[index].forEach((matrix, i) => tiles.setMatrixAt(i, matrix));
tiles.instanceMatrix.needsUpdate = true;
tiles.receiveShadow = true;
blanketGroup.add(tiles);
});
// Supply table.
const table = group(park);
table.position.set(-6.0, 0, 0.65);
box(table, 2.25, 0.18, 1.35, 0xb77a4c, 0, 1.08, 0);
box(table, 1.7, 0.14, 0.95, 0xc78b58, 0, 1.22, 0);
for (const x of [-0.87, 0.87]) {
for (const z of [-0.46, 0.46]) {
box(table, 0.16, 1.0, 0.16, 0x6d5142, x, 0.5, z);
}
}
box(table, 0.75, 0.52, 0.62, 0xd49a61, -0.48, 1.55, -0.12);
box(table, 0.62, 0.36, 0.52, 0xe7bd79, 0.45, 1.48, 0.12);
box(table, 0.22, 0.34, 0.22, 0x6a9b67, 0.73, 1.56, -0.36);
// Flowers and tiny plants.
function makeFlower(x, z, color, scale = 1) {
const flower = group(park);
flower.position.set(x, 0, z);
flower.scale.setScalar(scale);
box(flower, 0.07, 0.35, 0.07, 0x4f8b56, 0, 0.17, 0, false);
box(flower, 0.18, 0.18, 0.18, color, 0, 0.38, 0, false);
box(flower, 0.13, 0.13, 0.13, 0xf3c85b, 0, 0.39, 0, false);
}
makeFlower(-8.3, 2.5, 0xe8896f);
makeFlower(-8.8, 3.1, 0xf0bf51, 0.8);
makeFlower(7.6, 4.5, 0xb88ac2, 0.9);
makeFlower(8.0, 5.0, 0xe8896f, 0.7);
makeFlower(-4.6, -6.3, 0xf1ca59);
makeFlower(6.8, -7.7, 0xe8896f, 0.9);
// ---------------------------------------------------------------------
// Picnic objects
// ---------------------------------------------------------------------
function makeBasket(parent, scale = 1) {
const basket = group(parent);
basket.scale.setScalar(scale);
box(basket, 0.86, 0.38, 0.58, 0xb67a42, 0, 0.22, 0);
box(basket, 0.91, 0.09, 0.63, 0xd29b59, 0, 0.43, 0);
for (const x of [-0.35, 0, 0.35]) {
box(basket, 0.07, 0.4, 0.62, 0xe0ad68, x, 0.22, 0);
}
box(basket, 0.7, 0.07, 0.07, 0x8c5d37, 0, 0.72, -0.2);
box(basket, 0.7, 0.07, 0.07, 0x8c5d37, 0, 0.72, 0.2);
box(basket, 0.07, 0.36, 0.07, 0x8c5d37, -0.35, 0.59, 0);
box(basket, 0.07, 0.36, 0.07, 0x8c5d37, 0.35, 0.59, 0);
box(basket, 0.24, 0.2, 0.24, 0xe56f54, -0.16, 0.58, 0.02);
box(basket, 0.22, 0.18, 0.22, 0x78a85f, 0.16, 0.56, 0.03);
return basket;
}
const centralBasket = makeBasket(park, 0.95);
centralBasket.position.set(2.05, 0.09, 0.62);
function makePlacedItem(index, color) {
const item = group(park);
const points = [
[1.08, 0.52],
[1.52, 2.18],
[3.78, 2.62],
[4.52, 0.82],
[2.88, 2.68]
];
item.position.set(points[index][0], 0.105, points[index][1]);
if (index === 0) {
box(item, 0.67, 0.08, 0.54, 0xfff4d8, 0, 0.02, 0);
box(item, 0.2, 0.2, 0.2, 0xe56c54, -0.13, 0.16, 0.03);
box(item, 0.18, 0.18, 0.18, 0xefb74a, 0.13, 0.15, -0.03);
box(item, 0.08, 0.12, 0.08, 0x557b45, 0.13, 0.29, -0.03);
} else if (index === 1) {
box(item, 0.56, 0.1, 0.45, 0xf4dfb8, 0, 0.04, 0);
box(item, 0.35, 0.13, 0.3, 0x87a961, -0.08, 0.15, 0);
box(item, 0.31, 0.1, 0.24, 0xe9c36f, 0.13, 0.14, 0.03);
} else if (index === 2) {
box(item, 0.55, 0.08, 0.43, 0xfff0d2, 0, 0.02, 0);
box(item, 0.19, 0.34, 0.19, 0x8bc6c3, -0.16, 0.2, 0);
box(item, 0.19, 0.34, 0.19, 0x9b78ae, 0.16, 0.2, 0.02);
box(item, 0.23, 0.04, 0.23, 0xfff9e9, -0.16, 0.39, 0);
box(item, 0.23, 0.04, 0.23, 0xfff9e9, 0.16, 0.39, 0.02);
} else if (index === 3) {
box(item, 0.68, 0.2, 0.54, color, 0, 0.12, 0);
box(item, 0.55, 0.07, 0.42, 0x784f3c, 0, 0.25, 0);
box(item, 0.18, 0.18, 0.18, 0xefb74d, -0.14, 0.35, 0.02);
box(item, 0.16, 0.16, 0.16, 0xe66c53, 0.13, 0.34, -0.03);
} else {
box(item, 0.62, 0.08, 0.46, 0x8cb5a1, 0, 0.03, 0);
box(item, 0.22, 0.12, 0.22, 0xd89055, -0.15, 0.14, 0);
box(item, 0.22, 0.12, 0.22, 0xe2ae63, 0.13, 0.14, 0.02);
box(item, 0.22, 0.12, 0.22, 0xcf8350, 0, 0.14, -0.13);
}
return item;
}
const placedItems = [
makePlacedItem(0, 0x789d83),
makePlacedItem(1, 0xd89257),
makePlacedItem(2, 0x8fc6c1),
makePlacedItem(3, 0xba7c58),
makePlacedItem(4, 0x85b29b)
];
// ---------------------------------------------------------------------
// Characters
// ---------------------------------------------------------------------
function addHair(head, style, color) {
if (style === "bob") {
box(head, 0.49, 0.15, 0.45, color, 0, 0.19, -0.01);
box(head, 0.12, 0.36, 0.43, color, -0.21, 0.03, -0.02);
box(head, 0.12, 0.36, 0.43, color, 0.21, 0.03, -0.02);
box(head, 0.45, 0.31, 0.1, color, 0, 0.02, -0.21);
} else if (style === "tuft") {
box(head, 0.47, 0.14, 0.43, color, 0, 0.19, 0);
box(head, 0.15, 0.18, 0.15, color, -0.14, 0.31, -0.01);
box(head, 0.16, 0.18, 0.16, color, 0.03, 0.34, -0.02);
box(head, 0.13, 0.17, 0.13, color, 0.18, 0.29, 0);
} else if (style === "gray") {
box(head, 0.47, 0.15, 0.44, color, 0, 0.19, -0.01);
box(head, 0.11, 0.28, 0.4, color, -0.22, 0.04, -0.02);
box(head, 0.11, 0.28, 0.4, color, 0.22, 0.04, -0.02);
box(head, 0.44, 0.19, 0.1, color, 0, 0.1, -0.21);
} else {
box(head, 0.47, 0.15, 0.44, color, 0, 0.19, 0);
box(head, 0.12, 0.24, 0.42, color, -0.22, 0.07, -0.01);
box(head, 0.12, 0.24, 0.42, color, 0.22, 0.07, -0.01);
}
}
function createWheelchair(figure) {
const wheelchair = group(figure);
const wheels = [];
box(wheelchair, 0.7, 0.12, 0.65, 0x314b50, 0, 0.43, -0.02);
box(wheelchair, 0.7, 0.58, 0.11, 0x3e6465, 0, 0.76, -0.31);
box(wheelchair, 0.12, 0.48, 0.12, 0x516f70, -0.32, 0.47, -0.27);
box(wheelchair, 0.12, 0.48, 0.12, 0x516f70, 0.32, 0.47, -0.27);
for (const side of [-1, 1]) {
const wheel = group(wheelchair);
wheel.position.set(side * 0.43, 0.34, -0.02);
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
box(wheel, 0.13, 0.13, 0.13, 0x26383d,
0, Math.sin(angle) * 0.31, Math.cos(angle) * 0.31);
}
box(wheel, 0.18, 0.18, 0.18, 0x9eb6ae, 0, 0, 0);
box(wheel, 0.15, 0.15, 0.1, 0xe3b34c, 0, 0, 0.34);
wheels.push(wheel);
box(wheelchair, 0.12, 0.12, 0.12, 0x26383d, side * 0.27, 0.14, 0.38);
box(wheelchair, 0.1, 0.1, 0.47, 0x516f70, side * 0.31, 0.39, 0.08);
box(wheelchair, 0.1, 0.28, 0.1, 0x516f70, side * 0.3, 0.63, -0.3);
box(wheelchair, 0.27, 0.08, 0.08, 0x516f70, side * 0.3, 0.78, -0.3);
}
box(wheelchair, 0.65, 0.08, 0.1, 0x516f70, 0, 0.86, -0.35);
return wheels;
}
function createCharacter(config) {
const root = group();
const figure = group(root);
figure.scale.setScalar(config.scale);
const upper = group(figure);
const torsoWidth = config.build?.torsoWidth || 0.53;
const shoulder = config.build?.shoulder || 0.35;
const seated = !!config.seated;
const hipsY = seated ? 0.53 : 0.67;
const torsoY = seated ? 0.83 : 0.98;
const headY = seated ? 1.38 : 1.55;
const armY = seated ? 1.08 : 1.22;
box(upper, torsoWidth * 0.92, 0.18, 0.31, config.pants, 0, hipsY, 0);
box(upper, torsoWidth, 0.61, 0.31, config.shirt, 0, torsoY, 0);
box(upper, torsoWidth + 0.035, 0.08, 0.33, config.shirt, 0, torsoY + 0.24, 0);
const head = group(upper);
head.position.y = headY;
box(head, 0.44, 0.42, 0.4, config.skin, 0, 0, 0);
box(head, 0.06, 0.07, 0.06, config.skin, 0, -0.03, 0.225);
box(head, 0.05, 0.055, 0.035, 0x26312f, -0.105, 0.025, 0.215);
box(head, 0.05, 0.055, 0.035, 0x26312f, 0.105, 0.025, 0.215);
box(head, 0.085, 0.025, 0.03, 0x8a5046, 0, -0.105, 0.215);
addHair(head, config.hairStyle, config.hair);
if (config.glasses) {
box(head, 0.11, 0.075, 0.025, 0x46514d, -0.105, 0.025, 0.24);
box(head, 0.11, 0.075, 0.025, 0x46514d, 0.105, 0.025, 0.24);
box(head, 0.1, 0.025, 0.025, 0x46514d, 0, 0.025, 0.245);
}
const armL = group(upper);
const armR = group(upper);
armL.position.set(-shoulder, armY, 0);
armR.position.set(shoulder, armY, 0);
for (const arm of [armL, armR]) {
box(arm, 0.17, 0.21, 0.19, config.shirt, 0, -0.09, 0);
box(arm, 0.145, 0.31, 0.155, config.skin, 0, -0.34, 0);
box(arm, 0.17, 0.15, 0.17, config.skin, 0, -0.53, 0);
}
const legL = group(figure);
const legR = group(figure);
if (seated) {
legL.position.set(-0.14, 0.49, 0.03);
legR.position.set(0.14, 0.49, 0.03);
for (const leg of [legL, legR]) {
box(leg, 0.18, 0.18, 0.42, config.pants, 0, 0, 0.2);
box(leg, 0.16, 0.38, 0.16, config.pants, 0, -0.18, 0.4);
box(leg, 0.19, 0.14, 0.29, config.shoes, 0, -0.39, 0.47);
}
} else {
legL.position.set(-0.135, 0.67, 0);
legR.position.set(0.135, 0.67, 0);
for (const leg of [legL, legR]) {
box(leg, 0.19, 0.54, 0.2, config.pants, 0, -0.27, 0);
box(leg, 0.22, 0.13, 0.31, config.shoes, 0, -0.58, 0.06);
}
}
let wheels = [];
if (seated) wheels = createWheelchair(figure);
let cane = null;
if (config.cane) {
cane = group(figure);
cane.position.set(0.43, 0.035, 0.12);
cane.rotation.z = -0.08;
box(cane, 0.065, 0.74, 0.065, 0x73523e, 0, 0.37, 0);
box(cane, 0.19, 0.08, 0.1, 0x5a4336, 0, 0.76, 0);
box(cane, 0.09, 0.08, 0.09, 0x313b38, 0, 0.04, 0);
}
const carry = group(figure);
carry.position.set(0, seated ? 0.69 : 1.05, 0.43);
if (config.carryType === "basket") {
box(carry, 0.6, 0.26, 0.4, 0xc28a50, 0, 0, 0);
box(carry, 0.63, 0.06, 0.43, 0xe1ac67, 0, 0.15, 0);
box(carry, 0.28, 0.18, 0.27, 0xe86f56, -0.1, 0.25, 0);
box(carry, 0.25, 0.17, 0.24, 0x6c9d62, 0.12, 0.23, 0.01);
} else if (config.carryType === "crate") {
box(carry, 0.68, 0.36, 0.45, 0xce9360, 0, 0, 0);
box(carry, 0.72, 0.07, 0.49, 0xe2aa70, 0, 0.2, 0);
box(carry, 0.16, 0.25, 0.48, 0x9d6844, -0.22, 0, 0);
box(carry, 0.16, 0.25, 0.48, 0x9d6844, 0.22, 0, 0);
} else if (config.carryType === "dish") {
box(carry, 0.6, 0.08, 0.43, 0xfff0d2, 0, 0, 0);
box(carry, 0.2, 0.16, 0.19, 0xe98162, -0.12, 0.1, 0);
box(carry, 0.18, 0.14, 0.18, 0xefbd52, 0.12, 0.09, 0.01);
} else {
box(carry, 0.58, 0.08, 0.4, config.carryColor, 0, 0, 0);
box(carry, 0.15, 0.18, 0.15, 0x9ac8c3, -0.14, 0.11, 0);
box(carry, 0.17, 0.13, 0.17, 0xefb64e, 0.13, 0.09, 0.01);
}
return {
root,
figure,
upper,
head,
armL,
armR,
legL,
legR,
carry,
cane,
wheels,
config,
angle: 0,
walkPhase: 0,
wheelAngle: 0
};
}
const configurations = [
{
scale: 0.77,
skin: 0x9b603a,
hair: 0x2d211c,
hairStyle: "tuft",
shirt: 0xefbd4e,
pants: 0x405b76,
shoes: 0x49372f,
build: { torsoWidth: 0.48, shoulder: 0.3 },
carryType: "tray",
carryColor: 0x83b9a2,
speed: 1.25,
carryStart: 0.8,
carryEnd: 4.4,
arrangeStart: 0.1,
arrangeEnd: 1.4
},
{
scale: 1.09,
skin: 0xc98d65,
hair: 0x493126,
hairStyle: "crop",
shirt: 0x2e8c7d,
pants: 0x354b61,
shoes: 0xede4d4,
build: { torsoWidth: 0.51, shoulder: 0.35 },
carryType: "basket",
carryColor: 0xe4aa65,
speed: 1.02,
carryStart: 1.2,
carryEnd: 6.0,
arrangeStart: 0.2,
arrangeEnd: 1.8
},
{
scale: 1.0,
skin: 0x70462f,
hair: 0x1e1917,
hairStyle: "crop",
shirt: 0xe9755e,
pants: 0x4b4f66,
shoes: 0x3a302d,
build: { torsoWidth: 0.68, shoulder: 0.4 },
carryType: "crate",
carryColor: 0xe6a65e,
speed: 0.9,
carryStart: 1.7,
carryEnd: 6.8,
arrangeStart: 0.4,
arrangeEnd: 2.3
},
{
scale: 0.88,
skin: 0xe0b18c,
hair: 0xd8d8cf,
hairStyle: "gray",
shirt: 0x8c70ad,
pants: 0x4a5660,
shoes: 0x59443b,
build: { torsoWidth: 0.52, shoulder: 0.34 },
carryType: "dish",
carryColor: 0xe8a65f,
cane: true,
glasses: true,
speed: 0.72,
carryStart: 2.2,
carryEnd: 8.2,
arrangeStart: 0.7,
arrangeEnd: 2.8
},
{
scale: 0.98,
skin: 0xb97954,
hair: 0x262a2d,
hairStyle: "bob",
shirt: 0x4c7fa8,
pants: 0x354b60,
shoes: 0xe9dfcc,
seated: true,
build: { torsoWidth: 0.55, shoulder: 0.36 },
carryType: "tray",
carryColor: 0xd78a62,
speed: 0.95,
carryStart: 1.5,
carryEnd: 6.3,
arrangeStart: 0.2,
arrangeEnd: 1.9
}
];
const characters = configurations.map(createCharacter);
const supplyPoints = [
[-6.45, -0.55],
[-5.35, 0.08],
[-6.65, 1.15],
[-5.25, 1.78],
[-6.55, 2.35]
];
const dropPoints = [
[0.05, -0.15],
[0.85, 1.05],
[4.35, -0.25],
[4.72, 1.45],
[0.18, 2.48]
];
const arrangePoints = [
[1.08, 0.52],
[1.52, 2.18],
[3.78, 2.62],
[4.52, 0.82],
[2.88, 2.68]
];
const playPoints = [
[2.15, -2.25],
[4.45, -3.78],
[0.48, -4.42],
[-0.45, -2.95],
[2.78, -1.42]
];
const restPoints = [
[0.35, 2.72],
[1.28, 3.38],
[3.83, 2.82],
[4.85, 1.32],
[2.38, -0.46]
];
// Voxel toss ball.
const ball = group();
box(ball, 0.33, 0.33, 0.33, 0xf2bd43, 0, 0, 0);
box(ball, 0.11, 0.34, 0.35, 0xef775c, 0, 0, 0);
box(ball, 0.36, 0.12, 0.35, 0x6ba99b, 0, 0, 0);
// Tiny block butterflies.
const butterflies = [];
for (let i = 0; i < 3; i++) {
const butterfly = group();
box(butterfly, 0.07, 0.07, 0.18, 0x594a43, 0, 0, 0, false);
const wingL = box(butterfly, 0.22, 0.05, 0.19, i === 1 ? 0xefbd4f : 0xe97963, -0.11, 0.03, 0, false);
const wingR = box(butterfly, 0.22, 0.05, 0.19, i === 1 ? 0xefbd4f : 0xe97963, 0.11, 0.03, 0, false);
butterflies.push({ root: butterfly, wingL, wingR, offset: i * 2.1 });
}
// ---------------------------------------------------------------------
// Timeline and animation
// ---------------------------------------------------------------------
const phases = [
{
key: "carry", label: "Carry", number: "01 / 04", start: 0, end: 9,
title: "The snack run",
copy: "Everyone carries a piece of the picnic, choosing a comfortable pace and way to move."
},
{
key: "arrange", label: "Arrange", number: "02 / 04", start: 9, end: 17,
title: "Blanket setup",
copy: "The same guests make the picnic ready, working from different seats, heights, and positions."
},
{
key: "play", label: "Play", number: "03 / 04", start: 17, end: 27,
title: "Pass and play",
copy: "The turn travels around the circle. Every guest gets a chance to throw, catch, and cheer."
},
{
key: "share", label: "Share", number: "04 / 04", start: 27, end: 32,
title: "A little rest together",
copy: "The picnic is shared without fixed jobs. Everyone can switch tasks whenever the next turn comes around."
}
];
const cycleLength = 32;
let simulationTime = 0.6;
let paused = false;
let lastPhaseKey = "";
function currentPhase() {
const wrapped = ((simulationTime % cycleLength) + cycleLength) % cycleLength;
const phase = phases.find(item => wrapped >= item.start && wrapped < item.end) || phases[phases.length - 1];
const local = wrapped - phase.start;
return {
...phase,
local,
progress: local / (phase.end - phase.start)
};
}
function pointTarget(a, b, t) {
return new THREE.Vector3(lerp(a[0], b[0], t), 0, lerp(a[1], b[1], t));
}
function targetFor(character, index, phase) {
const c = character.config;
const local = phase.local;
if (phase.key === "carry") {
const t = smooth((local - c.carryStart) / (c.carryEnd - c.carryStart));
return {
position: pointTarget(supplyPoints[index], dropPoints[index], t),
moving: local >= c.carryStart && local <= c.carryEnd
};
}
if (phase.key === "arrange") {
const t = smooth((local - c.arrangeStart) / (c.arrangeEnd - c.arrangeStart));
return {
position: pointTarget(dropPoints[index], arrangePoints[index], t),
moving: local >= c.arrangeStart && local <= c.arrangeEnd
};
}
if (phase.key === "play") {
const t = smooth(local / 2.8);
return {
position: pointTarget(arrangePoints[index], playPoints[index], t),
moving: local < 2.8
};
}
if (local < 2.3) {
return { position: pointTarget(restPoints[index], restPoints[index], 0), moving: false };
}
const t = smooth((local - 2.3) / 2.7);
return {
position: pointTarget(restPoints[index], supplyPoints[index], t),
moving: local >= 2.3
};
}
const storyNumber = document.getElementById("story-number");
const storyTitle = document.getElementById("story-title");
const storyCopy = document.getElementById("story-copy");
const progressFill = document.getElementById("progress-fill");
const taskButtons = [...document.querySelectorAll(".task-button")];
function updateInterface(phase) {
if (phase.key !== lastPhaseKey) {
lastPhaseKey = phase.key;
storyNumber.textContent = phase.number;
storyTitle.textContent = phase.title;
storyCopy.textContent = phase.copy;
taskButtons.forEach(button => {
const start = Number(button.dataset.start);
button.classList.toggle("active", start === phase.start);
});
}
progressFill.style.transform = `scaleX(${phase.progress})`;
}
function computeBall(phase) {
if (phase.key === "play") {
if (phase.local < 2) {
return {
visible: true,
position: new THREE.Vector3(1.45, 0.62, -3.25),
from: 0, to: 0, u: 0
};
}
const segmentLength = 1.36;
const segmentTime = phase.local - 2;
const segment = Math.floor(segmentTime / segmentLength) % characters.length;
const next = (segment + 1) % characters.length;
const u = (segmentTime % segmentLength) / segmentLength;
const from = characters[segment].root.position;
const to = characters[next].root.position;
const fromHeight = characters[segment].config.seated ? 1.16 : 1.26;
const toHeight = characters[next].config.seated ? 1.16 : 1.26;
const position = new THREE.Vector3(
lerp(from.x, to.x, u),
lerp(fromHeight, toHeight, u) + Math.sin(Math.PI * u) * 1.25,
lerp(from.z, to.z, u)
);
return { visible: true, position, from: segment, to: next, u };
}
if (phase.key === "share" && phase.local < 2.3) {
return {
visible: true,
position: new THREE.Vector3(2.1, 0.42, 1.0),
from: 0, to: 0, u: 0
};
}
return { visible: false, position: new THREE.Vector3(), from: 0, to: 0, u: 0 };
}
const blanketCenter = new THREE.Vector3(2.1, 0, 1.15);
const playCenter = new THREE.Vector3(1.45, 0, -3.25);
function updateCharacters(phase, dt, elapsed) {
// First place everyone, then calculate the shared ball path.
characters.forEach((character, index) => {
const target = targetFor(character, index, phase);
const previousX = character.root.position.x;
const previousZ = character.root.position.z;
character.root.position.copy(target.position);
const dx = character.root.position.x - previousX;
const dz = character.root.position.z - previousZ;
const distance = Math.hypot(dx, dz);
const speed = distance / Math.max(dt, 0.001);
const walking = target.moving ? clamp(speed * 0.72, 0.18, 1) : 0;
character.walkPhase += dt * (6 + character.config.speed * 2.5) * walking;
let desiredAngle = character.angle;
if (distance > 0.001) {
desiredAngle = Math.atan2(dx, dz);
} else if (phase.key === "play") {
desiredAngle = Math.atan2(
playCenter.x - character.root.position.x,
playCenter.z - character.root.position.z
);
} else if (phase.key !== "carry") {
desiredAngle = Math.atan2(
blanketCenter.x - character.root.position.x,
blanketCenter.z - character.root.position.z
);
} else {
desiredAngle = Math.atan2(
blanketCenter.x - character.root.position.x,
blanketCenter.z - character.root.position.z
);
}
character.angle = angleLerp(character.angle, desiredAngle, 1 - Math.exp(-7 * dt));
character.root.rotation.y = character.angle;
});
const ballInfo = computeBall(phase);
ball.visible = ballInfo.visible;
if (ball.visible) ball.position.copy(ballInfo.position);
characters.forEach((character, index) => {
const c = character.config;
const walking = character.walkPhase;
const walkAmount = character.root.position.distanceTo(
new THREE.Vector3(character.root.position.x, 0, character.root.position.z)
) > 0 ? 1 : 1; // Kept separate from position logic for readable posing.
let leftArm = 0.03;
let rightArm = 0.03;
if (phase.key === "carry") {
leftArm = -1.03;
rightArm = c.cane ? -0.04 : -1.03;
} else if (phase.key === "arrange") {
const reach = Math.sin(elapsed * 3.2 + index * 1.4) * 0.14;
leftArm = -0.78 + reach;
rightArm = -0.78 - reach;
} else if (phase.key === "play") {
leftArm = -0.46;
rightArm = -0.46;
if (index === ballInfo.from && ballInfo.u < 0.78) {
const throwMotion = Math.sin(Math.PI * clamp(ballInfo.u / 0.62, 0, 1));
rightArm = -0.18 - throwMotion * 1.45;
leftArm = -0.64;
}
if (index === ballInfo.to) {
leftArm = -0.92;
rightArm = -0.92;
}
} else {
leftArm = -0.12 + Math.sin(elapsed * 1.4 + index) * 0.04;
rightArm = -0.12 - Math.sin(elapsed * 1.4 + index) * 0.04;
}
character.armL.rotation.x = damp(character.armL.rotation.x, leftArm, 9, dt);
character.armR.rotation.x = damp(character.armR.rotation.x, rightArm, 9, dt);
character.armL.rotation.z = 0.035;
character.armR.rotation.z = -0.035;
const stride = Math.sin(walking);
if (!c.seated) {
character.legL.rotation.x = stride * 0.52;
character.legR.rotation.x = -stride * 0.52;
character.upper.position.y = Math.abs(Math.sin(walking * 2)) * 0.025;
character.upper.rotation.z = Math.sin(walking) * 0.018;
} else {
character.legL.rotation.x = 0;
character.legR.rotation.x = 0;
character.upper.position.y = Math.sin(elapsed * 1.8 + index) * 0.006;
character.upper.rotation.z = 0;
}
character.head.rotation.y = Math.sin(elapsed * 0.8 + index * 1.3) * 0.055;
character.carry.visible = phase.key === "carry";
character.wheels.forEach(wheel => {
character.wheelAngle += dt * 4.5;
wheel.rotation.x = character.wheelAngle;
});
});
return ballInfo;
}
function updatePicnicItems(phase) {
placedItems.forEach((item, index) => {
let reveal = 0;
if (phase.key === "arrange") {
const c = characters[index].config;
reveal = smooth((phase.local - c.arrangeEnd + 0.12) / 0.65);
} else if (phase.key !== "carry") {
reveal = 1;
}
item.visible = reveal > 0.01;
const scale = Math.max(0.001, reveal);
item.scale.set(scale, scale, scale);
});
if (phase.key === "carry") {
centralBasket.visible = phase.local > 7.25;
const scale = phase.local > 7.25 ? 1 : 0.001;
centralBasket.scale.set(0.95 * scale, 0.95 * scale, 0.95 * scale);
} else {
centralBasket.visible = true;
centralBasket.scale.set(0.95, 0.95, 0.95);
}
}
function updateButterflies(elapsed) {
butterflies.forEach((butterfly, index) => {
const t = elapsed * 0.34 + butterfly.offset;
butterfly.root.position.set(
1.2 + Math.cos(t) * (5.2 + index * 0.5),
2.7 + Math.sin(t * 1.7) * 0.55 + index * 0.18,
-0.8 + Math.sin(t * 0.83) * (3.6 + index * 0.4)
);
butterfly.root.rotation.y = -t - 0.6;
const flap = Math.sin(elapsed * 9 + index) * 0.65;
butterfly.wingL.rotation.y = flap;
butterfly.wingR.rotation.y = -flap;
});
}
// ---------------------------------------------------------------------
// Direct camera controls: no addons or example modules
// ---------------------------------------------------------------------
let frustumHeight = 18;
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
frustumHeight = aspect < 0.8 ? 22 : aspect < 1.2 ? 20 : 18;
camera.left = (-frustumHeight * aspect) / 2;
camera.right = (frustumHeight * aspect) / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
camera.updateProjectionMatrix();
}
function updateCamera() {
const radius = 28;
camera.position.set(
view.target.x + radius * Math.sin(view.phi) * Math.sin(view.yaw),
view.target.y + radius * Math.cos(view.phi),
view.target.z + radius * Math.sin(view.phi) * Math.cos(view.yaw)
);
camera.zoom = view.zoom;
camera.updateProjectionMatrix();
camera.lookAt(view.target);
}
function resetView() {
view.yaw = 0.66;
view.phi = 0.88;
view.zoom = 1;
view.target.set(0, 0.3, 0);
updateCamera();
}
const pointers = new Map();
let pinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(values[0].x - values[1].x, values[0].y - values[1].y);
}
function panCamera(dx, dy) {
const right = new THREE.Vector3(Math.cos(view.yaw), 0, -Math.sin(view.yaw));
const forward = new THREE.Vector3(-Math.sin(view.yaw), 0, -Math.cos(view.yaw));
view.target.addScaledVector(right, -dx * 0.014);
view.target.addScaledVector(forward, dy * 0.011);
view.target.x = clamp(view.target.x, -7, 7);
view.target.z = clamp(view.target.z, -6, 6);
}
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) pinchDistance = pointerDistance();
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size >= 2) {
const newDistance = pointerDistance();
if (pinchDistance > 0 && newDistance > 0) {
view.zoom = clamp(view.zoom * (newDistance / pinchDistance), 0.65, 2.25);
}
pinchDistance = newDistance;
} else if (event.shiftKey || event.buttons === 2) {
panCamera(dx, dy);
} else {
view.yaw -= dx * 0.006;
view.phi = clamp(view.phi + dy * 0.0045, 0.42, 1.22);
}
});
function removePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
pointers.set([...pointers.keys()][0], remaining);
pinchDistance = 0;
} else if (pointers.size === 0) {
pinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", removePointer);
renderer.domElement.addEventListener("pointercancel", removePointer);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
view.zoom = clamp(view.zoom * Math.exp(-event.deltaY * 0.001), 0.65, 2.25);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetView);
document.getElementById("reset-view").addEventListener("click", resetView);
const pauseButton = document.getElementById("pause-button");
function togglePause() {
paused = !paused;
pauseButton.textContent = paused ? "Play" : "Pause";
pauseButton.setAttribute("aria-pressed", String(paused));
}
pauseButton.addEventListener("click", togglePause);
taskButtons.forEach(button => {
button.addEventListener("click", () => {
simulationTime = Number(button.dataset.start) + 0.01;
});
});
window.addEventListener("keydown", event => {
if (event.code === "Space" && event.target.tagName !== "BUTTON") {
event.preventDefault();
togglePause();
}
if (event.key === "ArrowLeft") view.yaw += 0.12;
if (event.key === "ArrowRight") view.yaw -= 0.12;
if (event.key === "ArrowUp") view.phi = clamp(view.phi - 0.08, 0.42, 1.22);
if (event.key === "ArrowDown") view.phi = clamp(view.phi + 0.08, 0.42, 1.22);
if (event.key === "+" || event.key === "=") view.zoom = clamp(view.zoom * 1.1, 0.65, 2.25);
if (event.key === "-") view.zoom = clamp(view.zoom / 1.1, 0.65, 2.25);
});
window.addEventListener("resize", resize);
resize();
resetView();
// ---------------------------------------------------------------------
// Render loop
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
if (!paused) simulationTime += dt;
const phase = currentPhase();
updateInterface(phase);
updatePicnicItems(phase);
updateCharacters(phase, dt, elapsed);
updateButterflies(elapsed);
ball.rotation.x += dt * 2.2;
ball.rotation.y += dt * 1.7;
updateCamera();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => loading.classList.add("hidden"));
</script>
</body>
</html>
```