Prompt specification
Build or customize the Three.js 3D scene "Sibling helps organize supplies" 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: Sibling helps organize supplies
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sibling-helps-organize-supplies-x3890
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Animate an older child placing clean folded clothes into a low drawer while an adult holds a wrapped baby nearby; keep the sequence calm and nonclinical.
Working Three.js Starter (sibling-helps-organize-supplies-x3890):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>A Quiet Moment</title>
<style>
:root {
color-scheme: light;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9dfd1;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas.dragging {
cursor: grabbing;
}
.caption {
position: fixed;
left: clamp(18px, 3vw, 42px);
top: clamp(18px, 3vw, 38px);
z-index: 2;
max-width: 320px;
pointer-events: none;
color: #4f4238;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}
.caption h1 {
margin: 0 0 7px;
font-size: clamp(22px, 3vw, 34px);
font-weight: 650;
letter-spacing: -0.025em;
}
.caption p {
margin: 0;
font-size: 14px;
line-height: 1.45;
color: #6f6055;
}
.replay {
position: fixed;
right: clamp(18px, 3vw, 42px);
top: clamp(18px, 3vw, 38px);
z-index: 3;
appearance: none;
border: 1px solid rgba(87, 70, 56, 0.22);
border-radius: 999px;
padding: 10px 17px;
color: #5b493d;
background: rgba(255, 250, 242, 0.78);
backdrop-filter: blur(8px);
box-shadow: 0 5px 18px rgba(79, 61, 45, 0.1);
font: inherit;
font-size: 13px;
cursor: pointer;
transition: transform 160ms ease, background 160ms ease;
}
.replay:hover {
transform: translateY(-1px);
background: rgba(255, 252, 247, 0.95);
}
.replay:active {
transform: translateY(0);
}
.hint {
position: fixed;
left: 50%;
bottom: 18px;
z-index: 2;
transform: translateX(-50%);
padding: 7px 12px;
border-radius: 999px;
color: rgba(78, 65, 55, 0.72);
background: rgba(255, 250, 242, 0.58);
font-size: 11px;
letter-spacing: 0.025em;
pointer-events: none;
white-space: nowrap;
}
@media (max-width: 650px) {
.caption p {
display: none;
}
.hint {
bottom: 12px;
}
}
</style>
</head>
<body>
<section class="caption" aria-label="Scene description">
<h1>A quiet moment</h1>
<p>Clean clothes go into the low drawer while a grown-up holds a sleepy baby nearby.</p>
</section>
<button class="replay" id="replay" type="button">Replay</button>
<div class="hint">Drag to look around · Scroll to move closer</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera, and lighting
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"A low-poly home scene showing a child putting folded clothes into a drawer while an adult holds a baby."
);
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeadfd2);
scene.fog = new THREE.Fog(0xeadfd2, 10, 19);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
40
);
const cameraTarget = new THREE.Vector3(0.05, 1.22, 0.5);
let targetTheta = 0.08;
let targetPhi = 1.16;
let targetRadius = window.innerWidth / window.innerHeight < 0.8 ? 10.2 : 8.4;
let currentTheta = targetTheta;
let currentPhi = targetPhi;
let currentRadius = targetRadius;
function updateCamera() {
currentTheta += (targetTheta - currentTheta) * 0.075;
currentPhi += (targetPhi - currentPhi) * 0.075;
currentRadius += (targetRadius - currentRadius) * 0.075;
const sinPhi = Math.sin(currentPhi);
camera.position.set(
cameraTarget.x + currentRadius * sinPhi * Math.sin(currentTheta),
cameraTarget.y + currentRadius * Math.cos(currentPhi),
cameraTarget.z + currentRadius * sinPhi * Math.cos(currentTheta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff6e7, 0x927866, 1.65);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xffedcf, 2.65);
sunlight.position.set(-3.5, 7.5, 5.5);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -7;
sunlight.shadow.camera.right = 7;
sunlight.shadow.camera.top = 7;
sunlight.shadow.camera.bottom = -3;
sunlight.shadow.camera.near = 0.5;
sunlight.shadow.camera.far = 18;
sunlight.shadow.bias = -0.00035;
sunlight.shadow.normalBias = 0.025;
scene.add(sunlight);
const warmFill = new THREE.PointLight(0xffd7a6, 18, 12, 2);
warmFill.position.set(4.2, 3.2, 3.2);
scene.add(warmFill);
const ambient = new THREE.AmbientLight(0xffffff, 0.22);
scene.add(ambient);
// -------------------------------------------------------------------------
// Geometry and material helpers
// -------------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
const M = {
wall: material(0xf1e6d8),
floor: material(0xc99f75),
floorEdge: material(0xb88761),
rug: material(0xb96954),
rugInset: material(0xd68a6c),
wood: material(0xb47b52),
woodLight: material(0xd3a273),
woodDark: material(0x8c593d),
drawerInside: material(0xc99a6d),
sage: material(0x7e9a7b),
sageDark: material(0x5f7b61),
cream: material(0xf0e4cd),
coral: material(0xc96f58),
mustard: material(0xc59a45),
teal: material(0x668e8b),
blue: material(0x71869b),
skinChild: material(0xc88f66),
skinAdult: material(0xb97855),
skinBaby: material(0xd5a07a),
hairBrown: material(0x503a2c),
hairDark: material(0x3e3029),
eye: material(0x28231f),
white: material(0xf8f0df),
plant: material(0x58795b),
plantLight: material(0x76976b),
pot: material(0xb86e51),
basket: material(0xc59a67)
};
function enableShadows(object) {
object.traverse((child) => {
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
}
});
return object;
}
function addBox(parent, mat, w, h, d, x, y, z) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
mat,
radiusTop,
radiusBottom,
height,
segments,
x,
y,
z,
openEnded = false
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments,
1,
openEnded
),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addSphere(parent, mat, radius, x, y, z, detail = 1) {
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, detail),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const up = new THREE.Vector3(0, 1, 0);
const segmentDirection = new THREE.Vector3();
function setSegment(mesh, a, b) {
segmentDirection.subVectors(b, a);
const length = segmentDirection.length();
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(up, segmentDirection.normalize());
mesh.scale.set(1, length, 1);
}
function addLimb(parent, mat, radius) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, 1, 7),
mat
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeHead(parent, radius, skin, hair, isBaby = false) {
const head = new THREE.Group();
parent.add(head);
const face = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, isBaby ? 1 : 2),
skin
);
face.castShadow = true;
face.receiveShadow = true;
head.add(face);
const hairCap = new THREE.Mesh(
new THREE.SphereGeometry(
radius * 1.035,
9,
5,
0,
Math.PI * 2,
0,
isBaby ? 1.15 : 1.42
),
hair
);
hairCap.position.y = radius * 0.035;
hairCap.castShadow = true;
head.add(hairCap);
const eyeY = radius * 0.06;
const eyeZ = radius * 0.88;
const eyeSize = radius * (isBaby ? 0.075 : 0.055);
addSphere(head, M.eye, eyeSize, -radius * 0.31, eyeY, eyeZ, 0);
addSphere(head, M.eye, eyeSize, radius * 0.31, eyeY, eyeZ, 0);
if (!isBaby) {
addSphere(
head,
skin,
radius * 0.105,
0,
-radius * 0.12,
radius * 0.93,
0
);
addBox(
head,
M.hairDark,
radius * 0.22,
radius * 0.035,
radius * 0.035,
0,
-radius * 0.34,
radius * 0.86
);
const earGeometry = new THREE.IcosahedronGeometry(radius * 0.14, 0);
for (const side of [-1, 1]) {
const ear = new THREE.Mesh(earGeometry, skin);
ear.position.set(side * radius * 0.94, -radius * 0.04, 0);
ear.castShadow = true;
head.add(ear);
}
}
return head;
}
function makeFoldedGarment(parent, mat, width = 0.58, depth = 0.42) {
const garment = new THREE.Group();
parent.add(garment);
addBox(garment, mat, width, 0.075, depth, 0, 0, 0);
addBox(
garment,
mat,
width * 0.88,
0.018,
depth * 0.74,
0,
0.047,
0.015
);
addBox(
garment,
mat,
width * 0.18,
0.055,
depth * 0.64,
-width * 0.48,
-0.006,
0
);
addBox(
garment,
mat,
width * 0.18,
0.055,
depth * 0.64,
width * 0.48,
-0.006,
0
);
return garment;
}
function makeClothesStack() {
const stack = new THREE.Group();
scene.add(stack);
const colors = [M.sage, M.cream, M.coral];
colors.forEach((color, index) => {
const garment = makeFoldedGarment(stack, color);
garment.position.y = (index - 1) * 0.095;
garment.rotation.y = (index - 1) * 0.035;
});
addBox(stack, M.white, 0.09, 0.012, 0.05, 0.14, 0.193, 0.09);
enableShadows(stack);
return stack;
}
// -------------------------------------------------------------------------
// Room
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(15, 12),
M.floor
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
addBox(scene, M.wall, 12, 5.4, 0.2, 0, 2.7, -1.72);
addBox(scene, M.wall, 0.2, 5.4, 10, -5.6, 2.7, 2.2);
addBox(scene, M.floorEdge, 12, 0.16, 0.08, 0, 0.08, -1.59);
addBox(scene, M.floorEdge, 0.08, 0.16, 10, -5.47, 0.08, 2.2);
const rug = new THREE.Mesh(
new THREE.CylinderGeometry(3.25, 3.25, 0.035, 48),
M.rug
);
rug.position.set(-0.05, 0.025, 1.0);
rug.scale.z = 0.62;
rug.receiveShadow = true;
scene.add(rug);
const rugInset = new THREE.Mesh(
new THREE.CylinderGeometry(2.48, 2.48, 0.012, 40),
M.rugInset
);
rugInset.position.set(-0.05, 0.047, 1.0);
rugInset.scale.z = 0.62;
rugInset.receiveShadow = true;
scene.add(rugInset);
// -------------------------------------------------------------------------
// Low wooden cabinet and open drawer
// -------------------------------------------------------------------------
const cabinet = new THREE.Group();
cabinet.position.set(-0.55, 0, -0.15);
scene.add(cabinet);
addBox(cabinet, M.wood, 0.17, 2.22, 1.25, -1.27, 1.11, -0.02);
addBox(cabinet, M.wood, 0.17, 2.22, 1.25, 1.27, 1.11, -0.02);
addBox(cabinet, M.wood, 2.7, 0.17, 1.3, 0, 0.13, -0.02);
addBox(cabinet, M.woodDark, 2.43, 2.08, 0.12, 0, 1.13, -0.62);
addBox(cabinet, M.woodLight, 2.78, 0.15, 1.32, 0, 2.22, -0.02);
addBox(cabinet, M.wood, 2.38, 0.14, 1.18, 0, 1.2, -0.02);
// Closed upper drawer.
addBox(cabinet, M.woodLight, 2.34, 0.82, 0.16, 0, 1.69, 0.59);
addBox(cabinet, M.woodDark, 0.48, 0.065, 0.08, 0, 1.7, 0.71);
addBox(cabinet, M.woodDark, 0.065, 0.065, 0.09, -0.2, 1.7, 0.675);
addBox(cabinet, M.woodDark, 0.065, 0.065, 0.09, 0.2, 1.7, 0.675);
// Open lower drawer.
addBox(cabinet, M.drawerInside, 2.22, 0.10, 1.25, 0, 0.39, 0.66);
addBox(cabinet, M.wood, 0.12, 0.52, 1.25, -1.08, 0.66, 0.66);
addBox(cabinet, M.wood, 0.12, 0.52, 1.25, 1.08, 0.66, 0.66);
addBox(cabinet, M.woodDark, 2.14, 0.48, 0.09, 0, 0.65, 0.08);
addBox(cabinet, M.woodLight, 2.37, 0.72, 0.16, 0, 0.72, 1.31);
addBox(cabinet, M.woodDark, 0.5, 0.065, 0.08, 0, 0.74, 1.43);
addBox(cabinet, M.woodDark, 0.065, 0.065, 0.09, -0.2, 0.74, 1.395);
addBox(cabinet, M.woodDark, 0.065, 0.065, 0.09, 0.2, 0.74, 1.395);
// A previously folded item makes the drawer feel lived-in.
const drawerItem = makeFoldedGarment(cabinet, M.blue, 0.56, 0.42);
drawerItem.position.set(0.56, 0.49, 0.67);
drawerItem.rotation.y = -0.07;
// -------------------------------------------------------------------------
// Laundry basket
// -------------------------------------------------------------------------
const basket = new THREE.Group();
basket.position.set(-3.35, 0, 0.05);
scene.add(basket);
addCylinder(basket, M.basket, 0.42, 0.34, 0.54, 12, 0, 0.28, 0, true);
for (const y of [0.09, 0.45]) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(y < 0.2 ? 0.35 : 0.41, 0.027, 5, 16),
M.woodDark
);
ring.rotation.x = Math.PI / 2;
ring.position.y = y;
ring.castShadow = true;
basket.add(ring);
}
const basketClothes = makeFoldedGarment(basket, M.mustard, 0.56, 0.38);
basketClothes.position.set(-0.04, 0.43, 0.02);
basketClothes.rotation.y = 0.18;
const basketClothes2 = makeFoldedGarment(basket, M.cream, 0.48, 0.36);
basketClothes2.position.set(0.08, 0.51, -0.03);
basketClothes2.rotation.y = -0.2;
// -------------------------------------------------------------------------
// Plant and wall art
// -------------------------------------------------------------------------
const plant = new THREE.Group();
plant.position.set(3.45, 0, -0.88);
scene.add(plant);
addCylinder(plant, M.pot, 0.34, 0.25, 0.55, 9, 0, 0.28, 0);
addCylinder(plant, M.woodDark, 0.31, 0.31, 0.035, 9, 0, 0.56, 0);
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2 + 0.3;
const height = 0.95 + (i % 3) * 0.19;
const radius = 0.25 + (i % 2) * 0.1;
const stem = addCylinder(
plant,
M.plant,
0.018,
0.024,
height,
6,
Math.cos(angle) * 0.1,
height * 0.5 + 0.5,
Math.sin(angle) * 0.08
);
stem.rotation.z = Math.cos(angle) * 0.12;
stem.rotation.x = Math.sin(angle) * 0.1;
const leaf = new THREE.Mesh(
new THREE.IcosahedronGeometry(1, 1),
i % 2 ? M.plant : M.plantLight
);
leaf.position.set(
Math.cos(angle) * radius,
0.78 + (i % 3) * 0.2,
Math.sin(angle) * radius
);
leaf.scale.set(0.13, 0.34, 0.065);
leaf.rotation.set(
Math.sin(angle) * 0.55,
angle,
Math.cos(angle) * 0.65
);
leaf.castShadow = true;
plant.add(leaf);
}
const art = new THREE.Group();
art.position.set(-0.25, 3.18, -1.56);
scene.add(art);
addBox(art, M.woodDark, 1.03, 0.78, 0.08, 0, 0, 0);
addBox(art, M.cream, 0.87, 0.62, 0.025, 0, 0, 0.055);
const sun = new THREE.Mesh(
new THREE.CircleGeometry(0.16, 16),
M.mustard
);
sun.position.set(-0.16, 0.08, 0.075);
art.add(sun);
addBox(art, M.sage, 0.47, 0.12, 0.015, 0.08, -0.19, 0.075);
addBox(art, M.coral, 0.22, 0.19, 0.015, -0.27, -0.08, 0.075);
// -------------------------------------------------------------------------
// Older child
// -------------------------------------------------------------------------
const child = new THREE.Group();
child.position.set(-1.9, 0, 1.55);
child.rotation.y = Math.PI / 2;
scene.add(child);
// Legs and shoes.
for (const side of [-1, 1]) {
addCylinder(
child,
M.mustard,
0.105,
0.12,
0.68,
7,
side * 0.16,
0.4,
0
);
addBox(child, M.woodDark, 0.24, 0.13, 0.38, side * 0.16, 0.08, 0.08);
}
const childUpper = new THREE.Group();
childUpper.position.y = 0.77;
child.add(childUpper);
addCylinder(childUpper, M.coral, 0.31, 0.26, 0.59, 7, 0, 0.28, 0);
addCylinder(childUpper, M.skinChild, 0.085, 0.09, 0.14, 7, 0, 0.64, 0);
const childHead = makeHead(
childUpper,
0.27,
M.skinChild,
M.hairBrown
);
childHead.position.set(0, 0.84, 0.015);
const childArms = [];
for (const side of [-1, 1]) {
childArms.push({
side,
upper: addLimb(childUpper, M.coral, 0.095),
lower: addLimb(childUpper, M.skinChild, 0.075),
hand: addSphere(childUpper, M.skinChild, 0.09, 0, 0, 0)
});
}
enableShadows(child);
// -------------------------------------------------------------------------
// Adult and wrapped baby
// -------------------------------------------------------------------------
const adult = new THREE.Group();
adult.position.set(2.35, 0, 0.05);
scene.add(adult);
for (const side of [-1, 1]) {
addCylinder(
adult,
M.teal,
0.13,
0.145,
0.95,
7,
side * 0.19,
0.53,
0
);
addBox(adult, M.woodDark, 0.27, 0.14, 0.43, side * 0.19, 0.09, 0.1);
}
const adultUpper = new THREE.Group();
adultUpper.position.y = 1.03;
adult.add(adultUpper);
addCylinder(adultUpper, M.teal, 0.4, 0.34, 0.84, 8, 0, 0.43, 0);
addCylinder(adultUpper, M.skinAdult, 0.095, 0.11, 0.16, 7, 0, 0.91, 0);
const adultHead = makeHead(
adultUpper,
0.31,
M.skinAdult,
M.hairDark
);
adultHead.position.set(0, 1.15, 0.015);
adultHead.rotation.x = 0.12;
const adultArms = [];
for (const side of [-1, 1]) {
adultArms.push({
side,
upper: addLimb(adultUpper, M.teal, 0.115),
lower: addLimb(adultUpper, M.skinAdult, 0.085),
hand: addSphere(adultUpper, M.skinAdult, 0.10, 0, 0, 0)
});
}
const baby = new THREE.Group();
baby.position.set(0, 1.48, 0.63);
adult.add(baby);
addCylinder(baby, M.cream, 0.18, 0.29, 0.63, 8, 0, 0, 0);
addCylinder(baby, M.sage, 0.205, 0.22, 0.11, 8, 0, 0.08, 0.01);
addCylinder(baby, M.coral, 0.205, 0.22, 0.095, 8, 0, -0.12, -0.005);
const babyHead = makeHead(
baby,
0.185,
M.skinBaby,
M.sage,
true
);
babyHead.position.set(0, 0.37, 0.015);
const babyBlanketBand = new THREE.Mesh(
new THREE.TorusGeometry(0.205, 0.018, 5, 14),
M.white
);
babyBlanketBand.rotation.x = Math.PI / 2;
babyBlanketBand.position.set(0, 0.09, 0);
baby.add(babyBlanketBand);
enableShadows(adult);
baby.rotation.x = -0.08;
// Position the adult's arms around the baby.
const adultShoulder = new THREE.Vector3();
const adultElbow = new THREE.Vector3();
const adultHand = new THREE.Vector3();
for (const arm of adultArms) {
adultShoulder.set(arm.side * 0.38, 0.72, 0);
adultElbow.set(arm.side * 0.49, 0.47, 0.27);
adultHand.set(arm.side * 0.3, 0.37, 0.62);
setSegment(arm.upper, adultShoulder, adultElbow);
setSegment(arm.lower, adultElbow, adultHand);
arm.hand.position.copy(adultHand);
}
// -------------------------------------------------------------------------
// Animated folded clothes
// -------------------------------------------------------------------------
const clothesStack = makeClothesStack();
const drawerClothesPosition = new THREE.Vector3(-0.95, 0.63, 0.73);
const drawerClothesQuaternion = new THREE.Quaternion().setFromEuler(
new THREE.Euler(0, -0.05, 0)
);
const releaseStartPosition = new THREE.Vector3();
const releaseStartQuaternion = new THREE.Quaternion();
const holdPosition = new THREE.Vector3();
const holdQuaternion = new THREE.Quaternion();
const holdLocalPosition = new THREE.Vector3();
let releaseCaptured = false;
let runStart = performance.now();
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function smooth01(value) {
const x = clamp(value, 0, 1);
return x * x * (3 - 2 * x);
}
function poseChild(t) {
const reach = smooth01((t - 0.8) / 3.0);
const withdraw = smooth01((t - 5.6) / 1.8);
const handY = lerp(lerp(0.28, 0.06, reach), 0.28, withdraw);
const handZ = lerp(lerp(0.16, 0.72, reach), 0.16, withdraw);
childUpper.rotation.x =
lerp(0.015, 0.27, reach) * (1 - withdraw);
childUpper.rotation.z =
Math.sin(t * 0.7) * 0.006 * (1 - reach * 0.6);
childHead.rotation.y = lerp(0.08, -0.22, withdraw);
childHead.rotation.x = lerp(0.01, 0.1, reach);
for (const arm of childArms) {
const shoulder = new THREE.Vector3(arm.side * 0.27, 0.44, 0.015);
const hand = new THREE.Vector3(arm.side * 0.14, handY, handZ);
const elbow = new THREE.Vector3(
arm.side * 0.36,
lerp(0.43, handY, 0.48) - 0.025,
handZ * 0.51
);
setSegment(arm.upper, shoulder, elbow);
setSegment(arm.lower, elbow, hand);
arm.hand.position.copy(hand);
}
holdLocalPosition.set(0, handY + 0.09, handZ + 0.025);
childUpper.localToWorld(holdPosition.copy(holdLocalPosition));
childUpper.getWorldQuaternion(holdQuaternion);
}
function updateClothes(t) {
if (t < 4.55) {
holdLocalPosition.set(0, 0.06 + 0.09, 0.72 + 0.025);
childUpper.localToWorld(holdPosition.copy(holdLocalPosition));
childUpper.getWorldQuaternion(holdQuaternion);
clothesStack.position.copy(holdPosition);
clothesStack.quaternion.copy(holdQuaternion);
releaseCaptured = false;
return;
}
if (!releaseCaptured) {
releaseStartPosition.copy(holdPosition);
releaseStartQuaternion.copy(holdQuaternion);
releaseCaptured = true;
}
const place = smooth01((t - 4.55) / 1.05);
clothesStack.position.lerpVectors(
releaseStartPosition,
drawerClothesPosition,
place
);
clothesStack.quaternion.slerpQuaternions(
releaseStartQuaternion,
drawerClothesQuaternion,
place
);
if (t >= 5.6) {
clothesStack.position.copy(drawerClothesPosition);
clothesStack.quaternion.copy(drawerClothesQuaternion);
}
}
function poseAdult(t) {
const breathing = Math.sin(t * 1.15) * 0.006;
adultUpper.position.y = 1.03 + breathing;
adultUpper.rotation.z = Math.sin(t * 0.62) * 0.008;
adultHead.rotation.y = Math.sin(t * 0.38) * 0.025;
baby.rotation.z = Math.sin(t * 0.82) * 0.028;
baby.rotation.x = -0.08 + Math.sin(t * 0.7) * 0.018;
baby.position.y = 1.48 + breathing * 0.45;
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit and zoom
// -------------------------------------------------------------------------
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
targetTheta = clamp(targetTheta - dx * 0.005, -0.52, 0.58);
targetPhi = clamp(targetPhi - dy * 0.004, 0.84, 1.39);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
renderer.domElement.classList.remove("dragging");
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
targetRadius = clamp(
targetRadius + event.deltaY * 0.006,
5.8,
13
);
},
{ passive: false }
);
// Replay button.
document.getElementById("replay").addEventListener("click", () => {
runStart = performance.now();
releaseCaptured = false;
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
if (window.innerWidth / window.innerHeight < 0.8) {
targetRadius = Math.max(targetRadius, 10.2);
}
});
function animate(now) {
const t = (now - runStart) / 1000;
poseChild(t);
updateClothes(t);
poseAdult(t);
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```