Prompt specification
Build or customize the Three.js 3D scene "Rain redirects a picnic route" 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: Rain redirects a picnic route
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/rain-redirects-a-picnic-route-x3894
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a low-poly family changing its picnic plans when rain arrives. The family starts toward the lawn carrying one basket and a rolled blanket. After the first raindrops appear, the leading figure stops, looks toward the pavilion, and turns onto the side path; the others follow. Keep the basket and blanket attached to their carriers throughout the change of direction. Finish with the group unpacking beneath the roof while the empty lawn remains visible in the background.
Working Three.js Starter (rain-redirects-a-picnic-route-x3894):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Picnic Change of Plans</title>
<style>
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9ddeb;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
}
.title-card {
position: fixed;
top: 22px;
left: 24px;
z-index: 2;
max-width: min(430px, calc(100vw - 48px));
padding: 16px 19px;
border: 1px solid rgba(255,255,255,.55);
border-radius: 16px;
color: #173044;
background: rgba(245,251,255,.82);
box-shadow: 0 12px 35px rgba(34,67,83,.14);
backdrop-filter: blur(10px);
pointer-events: none;
}
.title-card h1 {
margin: 0 0 5px;
font-size: clamp(20px, 3vw, 30px);
line-height: 1.05;
letter-spacing: -.035em;
}
.title-card p {
margin: 0;
color: #4a6473;
font-size: 14px;
line-height: 1.45;
}
.status {
position: fixed;
top: 26px;
right: 24px;
z-index: 3;
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border-radius: 999px;
color: #254354;
background: rgba(255,255,255,.82);
border: 1px solid rgba(255,255,255,.7);
box-shadow: 0 8px 25px rgba(34,67,83,.13);
backdrop-filter: blur(9px);
font-size: 13px;
font-weight: 700;
pointer-events: none;
}
.status-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: #f2b84b;
box-shadow: 0 0 0 4px rgba(242,184,75,.17);
transition: background .3s, box-shadow .3s;
}
.controls {
position: fixed;
z-index: 4;
left: 50%;
bottom: 22px;
width: min(620px, calc(100vw - 36px));
transform: translateX(-50%);
display: grid;
grid-template-columns: auto auto 1fr;
align-items: center;
gap: 10px;
padding: 11px 13px;
border: 1px solid rgba(255,255,255,.62);
border-radius: 17px;
background: rgba(248,252,255,.86);
box-shadow: 0 12px 35px rgba(34,67,83,.16);
backdrop-filter: blur(12px);
}
button {
appearance: none;
border: 0;
border-radius: 10px;
padding: 9px 13px;
color: white;
background: #28647d;
font: inherit;
font-size: 13px;
font-weight: 750;
cursor: pointer;
transition: transform .15s, background .15s;
}
button:hover { background: #1f5368; }
button:active { transform: translateY(1px); }
button.secondary { color: #31566a; background: #e3edf1; }
button.secondary:hover { background: #d5e3e9; }
.timeline {
position: relative;
height: 7px;
overflow: hidden;
border-radius: 999px;
background: #d4e2e8;
}
.timeline-fill {
position: absolute;
inset: 0 auto 0 0;
width: 0%;
border-radius: inherit;
background: linear-gradient(90deg, #e4ac3c, #4b91a5);
}
@media (max-width: 650px) {
.title-card {
top: 14px;
left: 14px;
padding: 13px 15px;
}
.title-card p { display: none; }
.status {
top: auto;
right: 14px;
bottom: 91px;
max-width: calc(100vw - 28px);
}
.controls {
bottom: 14px;
grid-template-columns: auto 1fr;
}
.timeline { grid-column: 1 / -1; }
}
</style>
</head>
<body>
<div class="title-card">
<h1>Picnic, pivoted.</h1>
<p>A low-poly family heads for the lawn, spots the rain, and follows the side path to the pavilion.</p>
</div>
<div class="status" aria-live="polite">
<span class="status-dot"></span>
<span id="statusText">Out for a picnic</span>
</div>
<div class="controls">
<button id="playButton" type="button">Pause</button>
<button id="replayButton" class="secondary" type="button">Replay</button>
<div class="timeline" aria-hidden="true">
<div id="timelineFill" class="timeline-fill"></div>
</div>
</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 lighting
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ 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.05;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
const sunnySky = new THREE.Color(0xb9ddeb);
const rainySky = new THREE.Color(0x8297a2);
scene.background = sunnySky.clone();
scene.fog = new THREE.Fog(sunnySky.clone(), 28, 64);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
camera.position.set(23, 15.5, 26);
const cameraTarget = new THREE.Vector3(-1, 0.3, 0);
camera.lookAt(cameraTarget);
const hemi = new THREE.HemisphereLight(0xe8f6ff, 0x66804e, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.0);
sun.position.set(-10, 19, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 23;
sun.shadow.camera.bottom = -23;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa8d8ef, 0.8);
fill.position.set(15, 9, -12);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and helpers
// -------------------------------------------------------------------------
const standard = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...extra
});
const lawnMaterial = standard(0x78a95f);
const lawnDark = new THREE.Color(0x78a95f);
const lawnWet = new THREE.Color(0x527b4b);
const pathMaterial = standard(0xc8b891);
const pathEdgeMaterial = standard(0x9d906e);
function shadowify(object) {
object.traverse(child => {
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
}
});
return object;
}
function makeBox(w, h, d, material, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
return shadowify(mesh);
}
function makeCylinder(rt, rb, h, segments, material, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
material
);
mesh.position.set(x, y, z);
return shadowify(mesh);
}
function seededRandom(seed) {
return function () {
seed |= 0;
seed = seed + 0x6D2B79F5 | 0;
let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
const random = seededRandom(72831);
// -------------------------------------------------------------------------
// Lawn, paths, trees, and small landscape details
// -------------------------------------------------------------------------
const lawn = makeBox(29, 0.28, 25, lawnMaterial, 0, -0.16, -1);
scene.add(lawn);
const lawnBorder = makeBox(29.5, 0.38, 25.5, standard(0x6e8752), 0, -0.31, -1);
scene.add(lawnBorder);
function createRibbon(curve, width, material, y = 0.035) {
const segments = 90;
const positions = [];
const indices = [];
const point = new THREE.Vector3();
const tangent = new THREE.Vector3();
for (let i = 0; i <= segments; i++) {
const u = i / segments;
curve.getPointAt(u, point);
curve.getTangentAt(u, tangent).normalize();
const sideX = -tangent.z;
const sideZ = tangent.x;
const half = width * 0.5;
positions.push(
point.x + sideX * half, y, point.z + sideZ * half,
point.x - sideX * half, y, point.z - sideZ * half
);
if (i < segments) {
const a = i * 2;
indices.push(a, a + 2, a + 1, a + 1, a + 2, a + 3);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return shadowify(new THREE.Mesh(geometry, material));
}
const entryCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-9.4, 0, 14),
new THREE.Vector3(-9.0, 0, 10.5),
new THREE.Vector3(-7.0, 0, 6.8),
new THREE.Vector3(-4.0, 0, 3.4)
]);
const sideCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-4.0, 0, 3.4),
new THREE.Vector3(-1.5, 0, 1.7),
new THREE.Vector3(0.7, 0, 0.1),
new THREE.Vector3(3.0, 0, -1.5),
new THREE.Vector3(5.5, 0, -3.2),
new THREE.Vector3(7.5, 0, -4.5),
new THREE.Vector3(8.8, 0, -5.0)
]);
scene.add(createRibbon(entryCurve, 2.15, pathMaterial, 0.035));
scene.add(createRibbon(sideCurve, 1.65, pathMaterial, 0.04));
const stoneMaterial = standard(0xd9cfb4);
for (let i = 0; i < 9; i++) {
const u = i / 8;
const p = entryCurve.getPointAt(u);
const stone = makeCylinder(0.52, 0.58, 0.10, 7, stoneMaterial, p.x, 0.07, p.z);
stone.scale.z = 0.72;
stone.rotation.y = random() * Math.PI;
scene.add(stone);
}
const trunkMaterial = standard(0x76543d);
const leafMaterials = [
standard(0x4f8752),
standard(0x61965a),
standard(0x3f7450)
];
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
group.add(makeCylinder(0.18, 0.25, 1.8, 7, trunkMaterial, 0, 0.9, 0));
const lower = new THREE.Mesh(
new THREE.ConeGeometry(1.25, 2.55, 6),
leafMaterials[0]
);
lower.position.y = 2.25;
group.add(shadowify(lower));
const upper = new THREE.Mesh(
new THREE.ConeGeometry(0.92, 2.15, 6),
leafMaterials[1]
);
upper.position.y = 3.45;
group.add(shadowify(upper));
scene.add(group);
}
[
[-13.0, -8.5, 1.05],
[-10.7, -11.4, 1.18],
[-6.7, -12.2, 0.95],
[-1.6, -12.0, 1.12],
[3.4, -11.7, 1.04],
[12.8, -10.8, 1.18],
[-14.0, 3.5, 0.88]
].forEach(args => createTree(...args));
const flowerColors = [0xf4d45d, 0xf7f1e6, 0xe58a91, 0xbca6e8];
for (let i = 0; i < 40; i++) {
const x = -13 + random() * 25;
const z = -11 + random() * 20;
if (x > 6.2 && z < 0) continue;
const flower = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.08 + random() * 0.05, 0),
standard(flowerColors[i % flowerColors.length])
);
flower.position.set(x, 0.12, z);
scene.add(flower);
}
// -------------------------------------------------------------------------
// Pavilion
// -------------------------------------------------------------------------
const pavilion = new THREE.Group();
pavilion.position.set(10, 0, -6);
scene.add(pavilion);
const wood = standard(0x9a6842);
const darkWood = standard(0x70482f);
const roofMaterial = standard(0x9d4d3d);
pavilion.add(makeBox(6.35, 0.09, 4.65, standard(0xb68a5b), 0, 0.045, 0));
const postPositions = [
[-2.85, -2.0], [2.85, -2.0],
[-2.85, 2.0], [2.85, 2.0]
];
postPositions.forEach(([x, z]) => {
pavilion.add(makeBox(0.22, 3.3, 0.22, darkWood, x, 1.7, z));
});
pavilion.add(makeBox(5.9, 0.18, 0.18, wood, 0, 3.28, -1.98));
pavilion.add(makeBox(5.9, 0.18, 0.18, wood, 0, 3.28, 1.98));
const roofWidth = 6.6;
const roofDepth = 4.8;
const eaveHeight = 3.35;
const ridgeHeight = 4.65;
const halfWidth = roofWidth / 2;
const rise = ridgeHeight - eaveHeight;
const slopeLength = Math.hypot(halfWidth, rise);
const roofAngle = Math.atan2(rise, halfWidth);
const leftRoof = makeBox(slopeLength + 0.16, 0.17, roofDepth + 0.45, roofMaterial);
leftRoof.position.set(-halfWidth / 2, eaveHeight + rise / 2, 0);
leftRoof.rotation.z = roofAngle;
pavilion.add(leftRoof);
const rightRoof = makeBox(slopeLength + 0.16, 0.17, roofDepth + 0.45, roofMaterial);
rightRoof.position.set(halfWidth / 2, eaveHeight + rise / 2, 0);
rightRoof.rotation.z = -roofAngle;
pavilion.add(rightRoof);
const gableShape = new THREE.Shape();
gableShape.moveTo(-halfWidth, eaveHeight);
gableShape.lineTo(halfWidth, eaveHeight);
gableShape.lineTo(0, ridgeHeight);
gableShape.closePath();
const gableMaterial = standard(0xd3ad7b, { side: THREE.DoubleSide });
[-roofDepth / 2, roofDepth / 2].forEach(z => {
const gable = new THREE.Mesh(new THREE.ShapeGeometry(gableShape), gableMaterial);
gable.position.z = z;
gable.castShadow = true;
pavilion.add(gable);
});
// Picnic table at the back-right of the shelter.
const table = new THREE.Group();
table.position.set(1.45, 0, -0.65);
pavilion.add(table);
table.add(makeBox(2.0, 0.14, 0.75, wood, 0, 1.05, 0));
table.add(makeBox(2.0, 0.12, 0.38, wood, 0, 0.55, 0.74));
table.add(makeBox(2.0, 0.12, 0.38, wood, 0, 0.55, -0.74));
[-0.72, 0.72].forEach(x => {
table.add(makeBox(0.15, 1.0, 1.2, darkWood, x, 0.5, 0));
});
// -------------------------------------------------------------------------
// Low-poly family figures
// -------------------------------------------------------------------------
const skinMaterials = [
standard(0xd89a73),
standard(0xa9694d),
standard(0xe1b08b),
standard(0xb97955)
];
const hairMaterials = [
standard(0x3c2b25),
standard(0x53372b),
standard(0x7a4a2e),
standard(0x302b32)
];
function createFigure(config) {
const root = new THREE.Group();
root.scale.setScalar(config.scale);
const bodyMaterial = standard(config.color);
const trousersMaterial = standard(config.trousers);
const skinMaterial = skinMaterials[config.skin];
const hairMaterial = hairMaterials[config.hair];
const torso = new THREE.Mesh(
new THREE.CylinderGeometry(0.29, 0.37, 0.72, 7),
bodyMaterial
);
torso.position.y = 1.12;
root.add(shadowify(torso));
const belt = new THREE.Mesh(
new THREE.CylinderGeometry(0.335, 0.35, 0.10, 7),
standard(0x5a4538)
);
belt.position.y = 0.82;
root.add(shadowify(belt));
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.17, 0.78, 0);
rightLeg.position.set(0.17, 0.78, 0);
root.add(leftLeg, rightLeg);
[leftLeg, rightLeg].forEach(leg => {
leg.add(makeCylinder(0.105, 0.12, 0.66, 6, trousersMaterial, 0, -0.32, 0));
const shoe = makeBox(0.22, 0.14, 0.34, darkWood, 0, -0.66, 0.06);
leg.add(shoe);
});
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.39, 1.43, 0);
rightArm.position.set(0.39, 1.43, 0);
root.add(leftArm, rightArm);
[leftArm, rightArm].forEach(arm => {
arm.add(makeCylinder(0.09, 0.105, 0.57, 6, bodyMaterial, 0, -0.28, 0));
arm.add(makeBox(0.16, 0.16, 0.16, skinMaterial, 0, -0.60, 0));
});
const headPivot = new THREE.Group();
headPivot.position.y = 1.71;
root.add(headPivot);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.265, 8, 6),
skinMaterial
);
head.scale.set(1, 1.08, 0.94);
headPivot.add(shadowify(head));
const hair = new THREE.Mesh(
new THREE.SphereGeometry(0.277, 8, 5, 0, Math.PI * 2, 0, Math.PI * 0.58),
hairMaterial
);
hair.position.y = 0.075;
hair.scale.set(1.02, 1.03, 1.01);
headPivot.add(shadowify(hair));
const eyeMaterial = standard(0x24313a);
[-0.085, 0.085].forEach(x => {
const eye = new THREE.Mesh(new THREE.SphereGeometry(0.025, 5, 4), eyeMaterial);
eye.position.set(x, 0.015, 0.247);
headPivot.add(eye);
});
const nose = new THREE.Mesh(
new THREE.ConeGeometry(0.035, 0.09, 5),
skinMaterial
);
nose.rotation.x = Math.PI / 2;
nose.position.set(0, -0.035, 0.285);
headPivot.add(nose);
if (config.scarf) {
const scarf = new THREE.Mesh(
new THREE.TorusGeometry(0.255, 0.055, 5, 10),
standard(config.scarf)
);
scarf.rotation.x = Math.PI / 2;
scarf.position.y = 1.51;
root.add(shadowify(scarf));
}
root.userData = {
leftArm,
rightArm,
leftLeg,
rightLeg,
headPivot
};
return root;
}
// One basket and one rolled blanket, initially attached to their carriers.
function createBasket() {
const group = new THREE.Group();
const wicker = standard(0xb87b3e);
const darkWicker = standard(0x805027);
const bowl = new THREE.Mesh(
new THREE.CylinderGeometry(0.31, 0.24, 0.36, 8, 1, true),
wicker
);
group.add(shadowify(bowl));
group.add(makeCylinder(0.245, 0.245, 0.055, 8, darkWicker, 0, -0.18, 0));
for (let i = 0; i < 8; i++) {
const a = i / 8 * Math.PI * 2;
const slat = makeBox(0.045, 0.31, 0.035, darkWicker,
Math.sin(a) * 0.275, -0.005, Math.cos(a) * 0.275);
slat.rotation.y = a;
group.add(slat);
}
[-0.235, 0.235].forEach(x => {
group.add(makeBox(0.045, 0.43, 0.045, darkWicker, x, 0.39, 0));
});
group.add(makeBox(0.51, 0.045, 0.045, darkWicker, 0, 0.60, 0));
const food = [];
const bread = makeBox(0.22, 0.13, 0.16, standard(0xe3ad5b), 0.02, 0.12, 0.02);
const apple = new THREE.Mesh(new THREE.IcosahedronGeometry(0.105, 1), standard(0xc84e43));
apple.position.set(-0.11, 0.18, -0.04);
const juice = makeCylinder(0.065, 0.065, 0.23, 7, standard(0xf0b649), 0.12, 0.16, -0.05);
group.add(bread, apple, juice);
food.push(bread, apple, juice);
group.userData.food = food;
return group;
}
function createRolledBlanket() {
const group = new THREE.Group();
const blanketMaterial = standard(0xcb6f68);
const stripeMaterial = standard(0xf2d49c);
const roll = new THREE.Mesh(
new THREE.CylinderGeometry(0.17, 0.17, 0.86, 9),
blanketMaterial
);
roll.rotation.z = Math.PI / 2;
group.add(shadowify(roll));
[-0.27, 0.27].forEach(x => {
const strap = new THREE.Mesh(
new THREE.TorusGeometry(0.174, 0.018, 4, 10),
stripeMaterial
);
strap.rotation.y = Math.PI / 2;
strap.position.x = x;
group.add(shadowify(strap));
});
return group;
}
const actorConfigs = [
{
name: "Parent",
scale: 1.0,
color: 0x347f91,
trousers: 0x33495d,
skin: 0,
hair: 0,
scarf: 0xe7b84b,
delay: 0,
initial: [-7.0, 9.2],
end: [8.45, -5.0],
carries: "basket"
},
{
name: "Parent",
scale: 0.96,
color: 0xd96d5f,
trousers: 0x454b61,
skin: 1,
hair: 1,
scarf: 0xf0d16b,
delay: 0.35,
initial: [-8.4, 10.2],
end: [9.25, -4.75],
carries: null
},
{
name: "Child",
scale: 0.73,
color: 0xe6b84d,
trousers: 0x5b6e80,
skin: 2,
hair: 2,
scarf: null,
delay: 0.70,
initial: [-9.7, 11.0],
end: [10.05, -4.85],
carries: "blanket"
},
{
name: "Child",
scale: 0.68,
color: 0x8d70b5,
trousers: 0x374e63,
skin: 3,
hair: 3,
scarf: null,
delay: 1.05,
initial: [-11.0, 11.8],
end: [8.75, -6.1],
carries: null
}
];
const stopPoint = new THREE.Vector3(-4, 0.04, 3.4);
const actors = [];
actorConfigs.forEach((config, index) => {
const approachCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(config.initial[0], 0.04, config.initial[1]),
new THREE.Vector3(
config.initial[0] + (index === 0 ? 0.75 : 0.45),
0.04,
config.initial[1] - 1.65
),
new THREE.Vector3(
config.initial[0] + (index === 0 ? 1.85 : 1.55),
0.04,
config.initial[1] - 3.25
),
stopPoint.clone()
]);
const routePoints = [
stopPoint.clone(),
new THREE.Vector3(-1.5, 0.04, 1.7),
new THREE.Vector3(0.7, 0.04, 0.1),
new THREE.Vector3(3.0, 0.04, -1.5),
new THREE.Vector3(5.5, 0.04, -3.2),
new THREE.Vector3(7.4, 0.04, -4.45),
new THREE.Vector3(config.end[0], 0.04, config.end[1])
];
const routeCurve = new THREE.CatmullRomCurve3(routePoints);
const root = createFigure(config);
root.position.copy(approachCurve.getPointAt(0));
scene.add(root);
const actor = {
config,
root,
approachCurve,
routeCurve,
yaw: 0,
currentYaw: 0,
arrivalTime: 0
};
actors.push(actor);
});
const basket = createBasket();
basket.position.set(0.57, 0.59, 0.17);
actors[0].root.add(basket);
actors[0].root.userData.rightArm.rotation.x = -0.08;
actors[0].root.userData.rightArm.rotation.z = -0.08;
const blanketRoll = createRolledBlanket();
blanketRoll.position.set(-0.34, 1.02, 0.22);
actors[2].root.add(blanketRoll);
actors[2].root.userData.leftArm.rotation.x = -0.34;
actors[2].root.userData.leftArm.rotation.z = 0.22;
// -------------------------------------------------------------------------
// The blanket spread and picnic food on the pavilion floor
// -------------------------------------------------------------------------
const spreadGroup = new THREE.Group();
spreadGroup.position.set(9.15, 0.12, -5.58);
spreadGroup.visible = false;
scene.add(spreadGroup);
const spreadMaterial = standard(0xc96762, {
transparent: true,
opacity: 0
});
const patchMaterial = standard(0xf0d19b, {
transparent: true,
opacity: 0
});
const bluePatchMaterial = standard(0x668ca2, {
transparent: true,
opacity: 0
});
spreadGroup.add(makeBox(3.25, 0.045, 2.25, spreadMaterial));
spreadGroup.add(makeBox(0.42, 0.012, 2.25, patchMaterial, -0.85, 0.03, 0));
spreadGroup.add(makeBox(3.25, 0.012, 0.36, bluePatchMaterial, 0, 0.031, -0.55));
const basketTarget = new THREE.Vector3(8.35, 0.29, -6.0);
const rollTarget = new THREE.Vector3(9.65, 0.24, -6.25);
const foodTargets = [
new THREE.Vector3(8.95, 0.25, -5.43),
new THREE.Vector3(9.42, 0.26, -5.72),
new THREE.Vector3(9.83, 0.27, -5.35)
];
// -------------------------------------------------------------------------
// Rain and a low-poly cloud
// -------------------------------------------------------------------------
const rainCount = 230;
const rainPositions = new Float32Array(rainCount * 6);
const rainSeeds = [];
for (let i = 0; i < rainCount; i++) {
rainSeeds.push({
x: -14 + random() * 21,
z: -12 + random() * 22,
y: random() * 10
});
}
const rainGeometry = new THREE.BufferGeometry();
rainGeometry.setAttribute("position", new THREE.BufferAttribute(rainPositions, 3));
const rainMaterial = new THREE.LineBasicMaterial({
color: 0xc5e6f2,
transparent: true,
opacity: 0
});
const rain = new THREE.LineSegments(rainGeometry, rainMaterial);
rain.frustumCulled = false;
scene.add(rain);
const cloudGroup = new THREE.Group();
cloudGroup.position.set(-2.5, 8.5, -13);
scene.add(cloudGroup);
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0x87949b,
roughness: 1,
flatShading: true,
transparent: true,
opacity: 0
});
[
[-1.2, 0, 0, 1.15],
[0, 0.35, 0, 1.4],
[1.35, -0.05, 0, 1.05],
[0.55, -0.3, 0.15, 1.2]
].forEach(([x, y, z, s]) => {
const puff = new THREE.Mesh(
new THREE.IcosahedronGeometry(s, 1),
cloudMaterial
);
puff.position.set(x, y, z);
cloudGroup.add(puff);
});
// Small raindrop splash rings on the lawn.
const splashMaterial = new THREE.MeshBasicMaterial({
color: 0xd4edf3,
transparent: true,
opacity: 0,
side: THREE.DoubleSide
});
const splashes = [];
for (let i = 0; i < 22; i++) {
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.07, 0.095, 8),
splashMaterial.clone()
);
ring.rotation.x = -Math.PI / 2;
ring.position.set(
-13.5 + random() * 20,
0.045,
-11.5 + random() * 20
);
scene.add(ring);
splashes.push({ mesh: ring, phase: random() });
}
// -------------------------------------------------------------------------
// Timeline and animation helpers
// -------------------------------------------------------------------------
const RAIN_START = 3.4;
const APPROACH_DURATION = 4.8;
const TURN_START = 6.35;
const ROUTE_DURATION = 5.6;
const clamp01 = value => Math.max(0, Math.min(1, value));
const smooth = value => {
const x = clamp01(value);
return x * x * (3 - 2 * x);
};
const shortestAngle = angle => Math.atan2(Math.sin(angle), Math.cos(angle));
function dampAngle(current, target, lambda, dt) {
return current + shortestAngle(target - current) * (1 - Math.exp(-lambda * dt));
}
let elapsed = 0;
let playing = true;
let basketDetached = false;
let rollDetached = false;
let spreadVisible = false;
const foodDetached = [false, false, false];
const basketStart = new THREE.Vector3();
const rollStart = new THREE.Vector3();
const rollStartScale = new THREE.Vector3();
const foodStarts = foodTargets.map(() => new THREE.Vector3());
function updateActors(t, dt) {
const picnicCenter = new THREE.Vector3(9.25, 0, -5.55);
const pavilionPosition = new THREE.Vector3(10, 0, -6);
actors.forEach((actor, index) => {
const { config, root } = actor;
const approachEnd = APPROACH_DURATION + config.delay;
const sideStart = TURN_START + config.delay;
const arrival = sideStart + ROUTE_DURATION;
actor.arrivalTime = arrival;
let position;
let tangent;
let moving = false;
if (t < approachEnd) {
const u = clamp01((t - config.delay) / APPROACH_DURATION);
position = actor.approachCurve.getPointAt(u);
tangent = actor.approachCurve.getTangentAt(Math.min(u, 0.9999));
moving = u < 0.999;
} else if (t < sideStart) {
position = actor.approachCurve.getPointAt(1);
tangent = actor.approachCurve.getTangentAt(0.9999);
} else if (t < arrival) {
const u = clamp01((t - sideStart) / ROUTE_DURATION);
position = actor.routeCurve.getPointAt(u);
tangent = actor.routeCurve.getTangentAt(Math.min(u, 0.9999));
moving = true;
} else {
position = actor.routeCurve.getPointAt(1);
tangent = actor.routeCurve.getTangentAt(0.9999);
}
root.position.copy(position);
let targetYaw = Math.atan2(tangent.x, tangent.z);
// Once parked under the roof, everyone turns toward the picnic.
if (t > arrival + 0.45) {
const toPicnic = picnicCenter.clone().sub(root.position);
targetYaw = Math.atan2(toPicnic.x, toPicnic.z);
}
actor.yaw = targetYaw;
actor.currentYaw = dampAngle(actor.currentYaw, targetYaw, moving ? 8 : 5, dt);
root.rotation.y = actor.currentYaw;
const gait = t * 8.4 + index * 1.4;
const swing = moving ? 0.52 : 0;
root.userData.leftLeg.rotation.x = Math.sin(gait) * swing;
root.userData.rightLeg.rotation.x = -Math.sin(gait) * swing;
if (config.carries === "basket") {
root.userData.rightArm.rotation.x = -0.08 + (moving ? Math.sin(gait) * 0.06 : 0);
} else if (config.carries === "blanket") {
root.userData.leftArm.rotation.x = -0.34 + (moving ? -Math.sin(gait) * 0.04 : 0);
} else {
root.userData.leftArm.rotation.x = -Math.sin(gait) * swing * 0.75;
root.userData.rightArm.rotation.x = Math.sin(gait) * swing * 0.75;
}
// Unpacking gestures begin after the group is sheltered.
if (t > 13.25) {
const unpackPhase = t * 3.2 + index * 1.3;
if (index === 0) {
root.userData.rightArm.rotation.x = -0.72 + Math.sin(unpackPhase) * 0.16;
} else if (index === 2) {
root.userData.leftArm.rotation.x = -0.62 + Math.sin(unpackPhase + 1) * 0.14;
} else {
root.userData.rightArm.rotation.x = -0.48 + Math.sin(unpackPhase + 2) * 0.18;
}
}
// The leader visibly looks toward the pavilion before changing direction.
const isLeader = index === 0;
const leaderLookStart = APPROACH_DURATION;
const leaderLookEnd = TURN_START;
let headTarget = 0;
if (isLeader && t >= leaderLookStart && t <= leaderLookEnd) {
const toPavilion = pavilionPosition.clone().sub(root.position);
const worldLookYaw = Math.atan2(toPavilion.x, toPavilion.z);
headTarget = shortestAngle(worldLookYaw - root.rotation.y);
} else if (!isLeader && t > approachEnd && t < sideStart) {
const leaderPosition = actors[0].root.position;
const toLeader = leaderPosition.clone().sub(root.position);
const worldLookYaw = Math.atan2(toLeader.x, toLeader.z);
headTarget = shortestAngle(worldLookYaw - root.rotation.y) * 0.55;
}
root.userData.headPivot.rotation.y = dampAngle(
root.userData.headPivot.rotation.y,
headTarget,
8,
dt
);
root.userData.headPivot.rotation.x = t > arrival ? 0.08 : 0;
});
}
function updateBasketAndBlanket(t) {
if (t >= 13.05 && !basketDetached) {
scene.attach(basket);
basket.getWorldPosition(basketStart);
basketDetached = true;
}
if (basketDetached) {
const u = smooth((t - 13.05) / 1.0);
basket.position.lerpVectors(basketStart, basketTarget, u);
basket.position.y += Math.sin(u * Math.PI) * 0.45;
basket.rotation.y = Math.sin(u * Math.PI) * 0.08;
}
if (t >= 13.85 && !rollDetached) {
scene.attach(blanketRoll);
blanketRoll.getWorldPosition(rollStart);
rollStartScale.copy(blanketRoll.scale);
rollDetached = true;
}
if (rollDetached) {
const u = smooth((t - 13.85) / 1.05);
blanketRoll.position.lerpVectors(rollStart, rollTarget, u);
blanketRoll.position.y += Math.sin(u * Math.PI) * 0.28;
const shrink = THREE.MathUtils.lerp(1, 0.18, u);
blanketRoll.scale.set(
rollStartScale.x * shrink,
rollStartScale.y * shrink,
rollStartScale.z * shrink
);
blanketRoll.visible = u < 0.99;
}
if (t >= 14.15 && !spreadVisible) {
spreadVisible = true;
spreadGroup.visible = true;
}
if (spreadVisible) {
const u = smooth((t - 14.15) / 1.0);
spreadGroup.scale.set(
THREE.MathUtils.lerp(0.08, 1, u),
1,
THREE.MathUtils.lerp(0.08, 1, u)
);
spreadMaterial.opacity = u;
patchMaterial.opacity = u;
bluePatchMaterial.opacity = u;
}
const foodTimes = [14.85, 15.12, 15.38];
const foodItems = basket.userData.food;
foodItems.forEach((item, i) => {
if (t >= foodTimes[i] && !foodDetached[i]) {
scene.attach(item);
item.getWorldPosition(foodStarts[i]);
foodDetached[i] = true;
}
if (foodDetached[i]) {
const u = smooth((t - foodTimes[i]) / 0.85);
item.position.lerpVectors(foodStarts[i], foodTargets[i], u);
item.position.y += Math.sin(u * Math.PI) * 0.38;
item.rotation.y += 0.035;
}
});
}
function updateWeather(t, dt) {
const rainAmount = smooth((t - RAIN_START) / 1.35);
rainMaterial.opacity = rainAmount * 0.58;
rain.visible = rainAmount > 0.005;
for (let i = 0; i < rainCount; i++) {
const seed = rainSeeds[i];
const y = 0.25 + ((seed.y - t * 7.8) % 10 + 10) % 10;
const x = seed.x - ((t * 0.7) % 1.8);
const z = seed.z + ((t * 0.22) % 0.7);
const index = i * 6;
rainPositions[index] = x;
rainPositions[index + 1] = y;
rainPositions[index + 2] = z;
rainPositions[index + 3] = x + 0.035;
rainPositions[index + 4] = y - 0.46;
rainPositions[index + 5] = z;
}
rainGeometry.attributes.position.needsUpdate = true;
cloudMaterial.opacity = rainAmount * 0.86;
cloudGroup.position.x = -2.5 - ((t * 0.06) % 1.2);
splashes.forEach(({ mesh, phase }) => {
const cycle = (t * 1.8 + phase) % 1;
mesh.material.opacity = rainAmount * Math.max(0, 1 - cycle) * 0.45;
const scale = 0.5 + cycle * 2.2;
mesh.scale.setScalar(scale);
});
scene.background.copy(sunnySky).lerp(rainySky, rainAmount * 0.82);
scene.fog.color.copy(scene.background);
lawnMaterial.color.copy(lawnDark).lerp(lawnWet, rainAmount * 0.6);
sun.intensity = THREE.MathUtils.lerp(3.0, 1.05, rainAmount);
hemi.intensity = THREE.MathUtils.lerp(2.15, 1.45, rainAmount);
// A subtle push toward the pavilion keeps the final action readable.
const ending = smooth((t - 10.5) / 3.0);
const desiredCamera = new THREE.Vector3(23, 15.5, 26).lerp(
new THREE.Vector3(21.5, 13.8, 24),
ending
);
const desiredTarget = new THREE.Vector3(-1, 0.3, 0).lerp(
new THREE.Vector3(0.3, 0.35, -1.3),
ending
);
camera.position.lerp(desiredCamera, 1 - Math.exp(-dt * 1.5));
cameraTarget.lerp(desiredTarget, 1 - Math.exp(-dt * 1.5));
camera.lookAt(cameraTarget);
}
// -------------------------------------------------------------------------
// UI and render loop
// -------------------------------------------------------------------------
const playButton = document.getElementById("playButton");
const replayButton = document.getElementById("replayButton");
const statusText = document.getElementById("statusText");
const timelineFill = document.getElementById("timelineFill");
const statusDot = document.querySelector(".status-dot");
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Pause" : "Play";
});
replayButton.addEventListener("click", () => {
window.location.reload();
});
let previousPhase = "";
function updateStatus(t) {
let phase;
if (t < RAIN_START) phase = "Out for a picnic";
else if (t < APPROACH_DURATION) phase = "The first raindrops";
else if (t < TURN_START) phase = "Wait — the pavilion!";
else if (t < 11.95) phase = "Taking the side path";
else if (t < 13.1) phase = "Under the roof";
else phase = "Unpacking together";
if (phase !== previousPhase) {
statusText.textContent = phase;
previousPhase = phase;
statusDot.style.background = phase === "The first raindrops" || phase === "Wait — the pavilion!"
? "#5d91a7"
: phase === "Taking the side path"
? "#d49a3e"
: phase === "Unpacking together"
? "#4c9b69"
: "#f2b84b";
}
timelineFill.style.width = `${clamp01(t / 18) * 100}%`;
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (playing) elapsed += dt;
updateActors(elapsed, dt);
updateBasketAndBlanket(elapsed);
updateWeather(elapsed, dt);
updateStatus(elapsed);
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
animate();
</script>
</body>
</html>
```