Prompt specification
Build or customize the Three.js 3D scene "Carrier-to-resting-area arrival" 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: Carrier-to-resting-area arrival
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/carrier-to-resting-area-arrival-x3842
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: carrier-to-resting-area arrival. Animate a newly arrived cat cautiously leaving an open carrier and approaching a quiet mat; human figures remain at a distance and movement stays slow.
Working Three.js Starter (carrier-to-resting-area-arrival-x3842):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Three.js — A Quiet Arrival</title>
<style>
:root {
--ink: #344441;
--muted: #6c7975;
--paper: rgba(255, 253, 247, 0.9);
--line: rgba(70, 86, 81, 0.16);
--sage: #638b80;
--sage-dark: #42685f;
--peach: #d9a37f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e3d9;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#viewport,
#viewport canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#viewport canvas {
touch-action: none;
cursor: grab;
}
#viewport canvas.grabbing {
cursor: grabbing;
}
.intro {
position: fixed;
top: 24px;
left: 24px;
z-index: 5;
width: min(390px, calc(100vw - 48px));
padding: 19px 21px 18px;
border: 1px solid rgba(255, 255, 255, 0.66);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 14px 45px rgba(53, 69, 64, 0.13);
backdrop-filter: blur(14px);
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: var(--sage-dark);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--peach);
content: "";
box-shadow: 0 0 0 4px rgba(217, 163, 127, 0.15);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 43px);
font-weight: 500;
letter-spacing: -0.035em;
line-height: 1.02;
}
.intro p {
margin: 11px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.5;
}
.distance-badge {
position: fixed;
top: 24px;
right: 24px;
z-index: 5;
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 999px;
background: rgba(255, 253, 247, 0.86);
color: #52645f;
font-size: 12px;
font-weight: 700;
box-shadow: 0 9px 30px rgba(53, 69, 64, 0.1);
backdrop-filter: blur(12px);
}
.distance-badge i {
width: 8px;
height: 8px;
border-radius: 50%;
background: #79a88d;
box-shadow: 0 0 0 4px rgba(121, 168, 141, 0.16);
}
.view-tools {
position: fixed;
right: 24px;
bottom: 138px;
z-index: 5;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 8px;
}
.view-tools button {
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 11px;
background: rgba(255, 253, 247, 0.88);
color: var(--ink);
font-size: 12px;
font-weight: 700;
cursor: pointer;
box-shadow: 0 8px 24px rgba(53, 69, 64, 0.1);
backdrop-filter: blur(10px);
}
.view-tools button:hover {
background: #fffdf7;
transform: translateY(-1px);
}
.timeline-card {
position: fixed;
left: 50%;
bottom: 22px;
z-index: 6;
width: min(760px, calc(100vw - 40px));
padding: 15px 17px 13px;
transform: translateX(-50%);
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 18px;
background: rgba(255, 253, 247, 0.93);
box-shadow: 0 16px 50px rgba(53, 69, 64, 0.16);
backdrop-filter: blur(16px);
}
.timeline-top {
display: flex;
align-items: center;
gap: 13px;
}
.control-button {
flex: 0 0 auto;
min-width: 76px;
padding: 9px 12px;
border: 0;
border-radius: 10px;
background: var(--sage-dark);
color: white;
font-size: 12px;
font-weight: 800;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
.control-button:hover {
background: #34584f;
transform: translateY(-1px);
}
.control-button.secondary {
min-width: 65px;
background: #e8e5dc;
color: #53615d;
}
.control-button.secondary:hover {
background: #dedbd1;
}
.timeline-track {
flex: 1;
min-width: 0;
}
#timeline {
width: 100%;
height: 6px;
margin: 0;
border-radius: 99px;
outline: none;
appearance: none;
background:
linear-gradient(
to right,
var(--sage) 0%,
var(--sage) var(--progress, 0%),
#deddd5 var(--progress, 0%),
#deddd5 100%
);
cursor: pointer;
}
#timeline::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 3px solid #fffdf7;
border-radius: 50%;
appearance: none;
background: var(--sage-dark);
box-shadow: 0 2px 8px rgba(44, 68, 61, 0.24);
}
#timeline::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #fffdf7;
border-radius: 50%;
background: var(--sage-dark);
box-shadow: 0 2px 8px rgba(44, 68, 61, 0.24);
}
.time {
flex: 0 0 auto;
min-width: 76px;
color: var(--muted);
font-variant-numeric: tabular-nums;
font-size: 12px;
text-align: right;
}
.stage-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-top: 11px;
}
.stage-label {
overflow: hidden;
color: #53645f;
font-size: 12px;
font-weight: 700;
text-overflow: ellipsis;
white-space: nowrap;
}
.stages {
display: flex;
gap: 6px;
}
.stage-dot {
width: 7px;
height: 7px;
border-radius: 2px;
background: #d5d5cd;
transition: background 200ms ease, transform 200ms ease;
}
.stage-dot.active {
background: var(--peach);
transform: scale(1.35);
}
.stage-dot.done {
background: var(--sage);
}
.hint {
position: fixed;
left: 24px;
bottom: 24px;
z-index: 4;
color: rgba(62, 76, 71, 0.67);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.02em;
pointer-events: none;
}
@media (max-width: 720px) {
.intro {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 15px 17px;
}
.intro p {
max-width: 310px;
font-size: 12px;
}
.distance-badge {
display: none;
}
.timeline-card {
bottom: 12px;
width: calc(100vw - 24px);
padding: 12px;
}
.timeline-top {
gap: 8px;
}
.control-button {
min-width: 58px;
padding: 9px;
}
.time {
min-width: 65px;
font-size: 11px;
}
.hint {
display: none;
}
.view-tools {
right: 14px;
bottom: 124px;
}
}
</style>
</head>
<body>
<div id="viewport" aria-label="Interactive voxel scene of a cat leaving a carrier"></div>
<header class="intro">
<div class="eyebrow">Voxel story · 36 seconds</div>
<h1>A quiet arrival</h1>
<p>
A newly arrived cat cautiously leaves an open carrier and makes its way
toward a calm resting mat. The people stay safely back.
</p>
</header>
<div class="distance-badge">
<i></i>
Quiet space · no direct contact
</div>
<div class="view-tools">
<button id="resetView" type="button">Reset view</button>
</div>
<div class="timeline-card">
<div class="timeline-top">
<button id="playPause" class="control-button" type="button">Ⅱ Pause</button>
<div class="timeline-track">
<input
id="timeline"
type="range"
min="0"
max="36"
step="0.01"
value="0"
aria-label="Animation timeline"
/>
</div>
<div id="time" class="time">0:00 / 0:36</div>
<button id="replay" class="control-button secondary" type="button">
Replay
</button>
</div>
<div class="stage-row">
<div id="stageName" class="stage-label" aria-live="polite">
Inside the carrier
</div>
<div class="stages" aria-hidden="true">
<span class="stage-dot active"></span>
<span class="stage-dot"></span>
<span class="stage-dot"></span>
<span class="stage-dot"></span>
<span class="stage-dot"></span>
</div>
</div>
</div>
<div class="hint">Drag to orbit · Scroll or pinch to zoom</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const timeline = document.getElementById("timeline");
const playButton = document.getElementById("playPause");
const replayButton = document.getElementById("replay");
const resetViewButton = document.getElementById("resetView");
const timeLabel = document.getElementById("time");
const stageName = document.getElementById("stageName");
const stageDots = [...document.querySelectorAll(".stage-dot")];
const DURATION = 36;
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e3d9);
scene.fog = new THREE.Fog(0xe8e3d9, 20, 36);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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;
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff9eb, 0x8c9d96, 2.2);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xffefd3, 3.1);
sunlight.position.set(-3.5, 10, 7);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -9;
sunlight.shadow.camera.right = 9;
sunlight.shadow.camera.top = 8;
sunlight.shadow.camera.bottom = -8;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 25;
sunlight.shadow.normalBias = 0.025;
scene.add(sunlight);
const fillLight = new THREE.DirectionalLight(0xcfe2df, 1.15);
fillLight.position.set(8, 5, -5);
scene.add(fillLight);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0,
...options
});
const M = {
floorA: material(0xe8e2d6),
floorB: material(0xeee8dc),
grout: material(0xd4cec2),
wall: material(0xe5e0d5),
wallTrim: material(0xf3eee4),
frame: material(0xf8f3e8),
sky: material(0xafc9cb, { roughness: 0.55 }),
cloud: material(0xf5f0df),
carrier: material(0x728b8b),
carrierDark: material(0x506c6e),
carrierPad: material(0xb7c4b4),
matEdge: material(0x638f86),
mat: material(0xd7cbb2),
matTuft: material(0xe8deca),
cat: material(0x8e8276),
catLight: material(0xb8aa96),
catDark: material(0x504b46),
eye: material(0x202925, { roughness: 0.38 }),
nose: material(0xb9827d),
teal: material(0x5f9187),
wood: material(0xa98568),
woodDark: material(0x7f654f),
shirtA: material(0x78999b),
shirtB: material(0xc48f75),
pants: material(0x5f6870),
skinA: material(0xd5a47e),
skinB: material(0x9f6f52),
hairA: material(0x4d4038),
hairB: material(0x6b5547),
pot: material(0xb97f63),
leaf: material(0x6e9471),
leafLight: material(0x87aa79),
water: material(0x86adb0, { roughness: 0.35 }),
bookA: material(0xc98d72),
bookB: material(0x7f9c9b),
art: material(0xd9b6a0)
};
function addBox(
parent,
width,
height,
depth,
mat,
x = 0,
y = 0,
z = 0,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Cutaway room
// -------------------------------------------------------------------------
const room = new THREE.Group();
scene.add(room);
addBox(room, 13.2, 0.12, 9.2, M.grout, 0, -0.12, 0, false);
for (let x = -6; x <= 6; x++) {
for (let z = -4; z <= 4; z++) {
const tileMaterial = (x + z) % 2 === 0 ? M.floorA : M.floorB;
addBox(
room,
0.975,
0.11,
0.975,
tileMaterial,
x,
-0.055,
z,
false
);
}
}
addBox(room, 13.1, 4.8, 0.18, M.wall, 0, 2.35, -4.55);
addBox(room, 0.18, 4.8, 9.2, M.wall, -6.55, 2.35, 0);
addBox(room, 13.05, 0.18, 0.08, M.wallTrim, 0, 0.1, -4.43);
addBox(room, 0.08, 0.18, 9.1, M.wallTrim, -6.43, 0.1, 0);
// Window and blocky clouds.
addBox(room, 2.8, 1.9, 0.1, M.frame, -2.4, 2.75, -4.38);
addBox(room, 2.5, 1.6, 0.06, M.sky, -2.4, 2.75, -4.4);
addBox(room, 0.09, 1.68, 0.1, M.frame, -2.4, 2.75, -4.32);
addBox(room, 2.58, 0.09, 0.1, M.frame, -2.4, 2.75, -4.32);
addBox(room, 0.55, 0.2, 0.035, M.cloud, -3.0, 3.05, -4.34);
addBox(room, 0.28, 0.32, 0.035, M.cloud, -2.8, 3.0, -4.33);
addBox(room, 0.38, 0.16, 0.035, M.cloud, -1.85, 2.4, -4.33);
// Soft, geometric sunlight patch on the floor.
const sunPatch = new THREE.Mesh(
new THREE.BoxGeometry(3.5, 0.012, 1.7),
new THREE.MeshStandardMaterial({
color: 0xffedb9,
transparent: true,
opacity: 0.18,
depthWrite: false,
roughness: 1
})
);
sunPatch.position.set(-2.1, 0.008, 0.65);
sunPatch.rotation.y = -0.28;
scene.add(sunPatch);
// Wall shelf and books.
addBox(room, 2.1, 0.13, 0.38, M.wood, 0.75, 2.15, -4.18);
addBox(room, 0.12, 0.4, 0.12, M.woodDark, 0.1, 1.95, -4.18);
addBox(room, 0.12, 0.4, 0.12, M.woodDark, 1.4, 1.95, -4.18);
addBox(room, 0.18, 0.46, 0.25, M.bookA, 0.2, 2.44, -4.16);
addBox(room, 0.16, 0.38, 0.24, M.bookB, 0.43, 2.41, -4.16);
addBox(room, 0.2, 0.52, 0.25, M.art, 0.67, 2.47, -4.16);
// Simple wall art.
addBox(room, 1.25, 1.45, 0.1, M.frame, 4.8, 2.65, -4.4);
addBox(room, 1.02, 1.22, 0.08, M.art, 4.8, 2.65, -4.32);
addBox(room, 0.42, 0.48, 0.06, M.teal, 4.58, 2.48, -4.26);
addBox(room, 0.55, 0.28, 0.06, M.cloud, 4.96, 2.9, -4.25);
// -------------------------------------------------------------------------
// Open voxel carrier
// -------------------------------------------------------------------------
const carrier = new THREE.Group();
carrier.position.set(-3.85, 0, 0.2);
scene.add(carrier);
addBox(carrier, 2.32, 0.16, 1.58, M.carrier, 0, 0.1, 0);
addBox(carrier, 1.98, 0.045, 1.3, M.carrierPad, 0, 0.202, 0);
// Back and roof.
addBox(carrier, 0.1, 1.38, 1.5, M.carrierDark, -1.1, 0.84, 0);
for (let x = -0.92; x <= 0.92; x += 0.46) {
addBox(carrier, 0.065, 0.08, 1.5, M.carrier, x, 1.5, 0);
}
addBox(carrier, 0.08, 0.08, 1.5, M.carrier, -1.1, 1.5, 0);
addBox(carrier, 0.08, 0.08, 1.5, M.carrier, 1.1, 1.5, 0);
// Side grids.
for (const z of [-0.75, 0.75]) {
for (let x = -0.9; x <= 0.9; x += 0.45) {
addBox(carrier, 0.065, 1.38, 0.065, M.carrier, x, 0.84, z);
}
addBox(carrier, 2.15, 0.07, 0.07, M.carrier, 0, 0.48, z);
addBox(carrier, 2.15, 0.07, 0.07, M.carrier, 0, 1.22, z);
addBox(carrier, 2.15, 0.07, 0.07, M.carrier, 0, 0.17, z);
}
// Front frame leaves the center opening unobstructed.
addBox(carrier, 0.09, 1.4, 0.09, M.carrierDark, 1.13, 0.84, -0.75);
addBox(carrier, 0.09, 1.4, 0.09, M.carrierDark, 1.13, 0.84, 0.75);
addBox(carrier, 0.1, 0.09, 1.58, M.carrierDark, 1.13, 1.5, 0);
addBox(carrier, 0.1, 0.08, 1.58, M.carrierDark, 1.13, 0.18, 0);
// The door is visibly swung open.
const openDoor = new THREE.Group();
openDoor.position.set(1.15, 0.18, -0.73);
openDoor.rotation.y = 1.08;
carrier.add(openDoor);
addBox(openDoor, 0.085, 0.085, 1.45, M.carrierDark, 0, 0, 0.72);
addBox(openDoor, 0.085, 0.085, 1.45, M.carrierDark, 0, 1.27, 0.72);
for (let z = 0.08; z <= 1.35; z += 0.25) {
addBox(openDoor, 0.065, 1.28, 0.065, M.carrier, 0, 0.635, z);
}
addBox(openDoor, 0.085, 0.065, 1.45, M.carrier, 0, 0.63, 0.72);
addBox(carrier, 0.055, 0.18, 0.32, M.carrierPad, 1.2, 1.3, 0.28);
// -------------------------------------------------------------------------
// Quiet mat and other room props
// -------------------------------------------------------------------------
addBox(scene, 2.58, 0.05, 1.86, M.matEdge, 3.18, 0.025, 1.46);
addBox(scene, 2.34, 0.07, 1.62, M.mat, 3.18, 0.065, 1.46);
for (let x = 2.55; x <= 3.8; x += 0.62) {
for (let z = 0.96; z <= 1.96; z += 0.5) {
addBox(scene, 0.34, 0.012, 0.26, M.matTuft, x, 0.106, z, false);
}
}
// Voxel plant.
const plant = new THREE.Group();
plant.position.set(5.65, 0, -3.65);
scene.add(plant);
addBox(plant, 0.58, 0.55, 0.58, M.pot, 0, 0.275, 0);
addBox(plant, 0.48, 0.12, 0.48, M.woodDark, 0, 0.56, 0);
addBox(plant, 0.13, 1.25, 0.13, M.leaf, 0, 1.12, 0);
addBox(plant, 0.65, 0.15, 0.18, M.leaf, 0.25, 1.35, 0);
addBox(plant, 0.55, 0.14, 0.16, M.leafLight, -0.25, 1.65, 0);
addBox(plant, 0.18, 0.65, 0.18, M.leaf, 0.04, 1.8, 0);
addBox(plant, 0.45, 0.14, 0.16, M.leafLight, 0.22, 2.03, 0);
// Small block-built water bowl.
addBox(scene, 0.78, 0.12, 0.78, M.teal, 5.05, 0.06, 2.55);
addBox(scene, 0.55, 0.08, 0.55, M.water, 5.05, 0.12, 2.55);
// -------------------------------------------------------------------------
// Distant human figures
// -------------------------------------------------------------------------
const humans = [];
function makeSeatedHuman(x, z, shirt, skin, hair, phase) {
const root = new THREE.Group();
root.position.set(x, 0, z);
scene.add(root);
const torso = new THREE.Group();
root.add(torso);
addBox(torso, 0.62, 0.78, 0.36, shirt, 0, 1.18, 0);
addBox(torso, 0.66, 0.13, 0.39, shirt, 0, 1.49, 0);
addBox(torso, 0.54, 0.24, 0.38, M.pants, 0, 0.72, 0.04);
for (const side of [-1, 1]) {
addBox(torso, 0.22, 0.25, 0.66, M.pants, side * 0.17, 0.72, 0.32);
addBox(torso, 0.21, 0.52, 0.22, M.pants, side * 0.17, 0.35, 0.56);
addBox(torso, 0.24, 0.12, 0.34, M.woodDark, side * 0.17, 0.08, 0.62);
addBox(torso, 0.19, 0.56, 0.2, shirt, side * 0.4, 1.18, 0);
addBox(torso, 0.17, 0.19, 0.18, skin, side * 0.4, 0.83, 0.03);
}
const head = new THREE.Group();
head.position.set(0, 1.92, 0);
torso.add(head);
addBox(head, 0.44, 0.45, 0.42, skin, 0, 0, 0);
addBox(head, 0.46, 0.13, 0.44, hair, 0, 0.21, -0.01);
addBox(head, 0.1, 0.1, 0.08, skin, 0, -0.02, 0.25);
addBox(head, 0.05, 0.05, 0.04, M.eye, -0.11, 0.06, 0.22);
addBox(head, 0.05, 0.05, 0.04, M.eye, 0.11, 0.06, 0.22);
humans.push({ root, torso, head, phase });
}
function makeStandingHuman(x, z, shirt, skin, hair, phase) {
const root = new THREE.Group();
root.position.set(x, 0, z);
scene.add(root);
const torso = new THREE.Group();
root.add(torso);
addBox(torso, 0.62, 0.83, 0.38, shirt, 0, 1.43, 0);
addBox(torso, 0.66, 0.14, 0.41, shirt, 0, 1.78, 0);
addBox(torso, 0.54, 0.25, 0.37, M.pants, 0, 0.91, 0);
for (const side of [-1, 1]) {
addBox(torso, 0.22, 0.76, 0.23, M.pants, side * 0.17, 0.43, 0);
addBox(torso, 0.25, 0.13, 0.35, M.woodDark, side * 0.17, 0.07, 0.07);
addBox(torso, 0.19, 0.66, 0.21, shirt, side * 0.4, 1.41, 0);
addBox(torso, 0.18, 0.19, 0.19, skin, side * 0.4, 1.0, 0.02);
}
const head = new THREE.Group();
head.position.set(0, 2.18, 0);
torso.add(head);
addBox(head, 0.44, 0.46, 0.42, skin, 0, 0, 0);
addBox(head, 0.46, 0.14, 0.44, hair, 0, 0.21, -0.01);
addBox(head, 0.1, 0.1, 0.08, skin, 0, -0.02, 0.25);
addBox(head, 0.05, 0.05, 0.04, M.eye, -0.11, 0.06, 0.22);
addBox(head, 0.05, 0.05, 0.04, M.eye, 0.11, 0.06, 0.22);
humans.push({ root, torso, head, phase });
}
// Bench for the seated observer.
addBox(scene, 2.55, 0.16, 0.58, M.wood, 3.28, 0.58, -3.77);
addBox(scene, 2.55, 0.72, 0.12, M.wood, 3.28, 1.02, -4.02);
addBox(scene, 0.18, 0.58, 0.45, M.woodDark, 2.15, 0.28, -3.78);
addBox(scene, 0.18, 0.58, 0.45, M.woodDark, 4.4, 0.28, -3.78);
makeSeatedHuman(3.28, -3.46, M.shirtA, M.skinA, M.hairA, 0.4);
makeStandingHuman(-4.72, -3.42, M.shirtB, M.skinB, M.hairB, 2.1);
// -------------------------------------------------------------------------
// Voxel cat
// -------------------------------------------------------------------------
const catRoot = new THREE.Group();
const catModel = new THREE.Group();
catRoot.add(catModel);
scene.add(catRoot);
const bodyRig = new THREE.Group();
catModel.add(bodyRig);
addBox(bodyRig, 1.06, 0.4, 0.46, M.cat, -0.06, 0.57, 0);
addBox(bodyRig, 0.58, 0.42, 0.47, M.cat, 0.34, 0.58, 0);
addBox(bodyRig, 0.58, 0.18, 0.49, M.catLight, 0.34, 0.42, 0);
// Tabby-like voxel markings.
for (const x of [-0.38, -0.08, 0.22]) {
addBox(bodyRig, 0.11, 0.035, 0.43, M.catDark, x, 0.79, 0);
}
for (const x of [-0.34, -0.05, 0.24]) {
addBox(bodyRig, 0.035, 0.18, 0.47, M.catDark, x, 0.6, 0);
}
// A small teal collar helps identify the cat.
addBox(bodyRig, 0.095, 0.105, 0.49, M.teal, 0.48, 0.4, 0);
const headPivot = new THREE.Group();
headPivot.position.set(0.49, 0.72, 0);
bodyRig.add(headPivot);
addBox(headPivot, 0.53, 0.47, 0.47, M.cat, 0.2, 0.08, 0);
addBox(headPivot, 0.2, 0.15, 0.31, M.catLight, 0.46, -0.025, 0);
addBox(headPivot, 0.055, 0.05, 0.065, M.nose, 0.575, 0.005, 0);
for (const z of [-0.13, 0.13]) {
addBox(headPivot, 0.055, 0.065, 0.06, M.eye, 0.47, 0.16, z);
}
// Blocky ears.
const earLeft = new THREE.Group();
const earRight = new THREE.Group();
earLeft.position.set(0.08, 0.32, -0.16);
earRight.position.set(0.29, 0.32, 0.16);
headPivot.add(earLeft, earRight);
for (const ear of [earLeft, earRight]) {
addBox(ear, 0.19, 0.23, 0.14, M.cat, 0, 0.08, 0);
addBox(ear, 0.12, 0.12, 0.1, M.catDark, 0, 0.2, 0);
addBox(ear, 0.055, 0.13, 0.045, M.catLight, 0.055, 0.06, 0);
}
// Fine, voxel whiskers.
for (const side of [-1, 1]) {
addBox(headPivot, 0.2, 0.018, 0.018, M.frame, 0.49, -0.055, side * 0.22);
addBox(headPivot, 0.15, 0.018, 0.018, M.frame, 0.47, -0.09, side * 0.31);
}
// Four articulated-looking legs.
const legs = [];
const legData = [
{ x: 0.31, z: -0.17, offset: 0, front: true },
{ x: 0.31, z: 0.17, offset: Math.PI, front: true },
{ x: -0.34, z: -0.17, offset: Math.PI, front: false },
{ x: -0.34, z: 0.17, offset: 0, front: false }
];
for (const data of legData) {
const pivot = new THREE.Group();
pivot.position.set(data.x, 0.44, data.z);
catModel.add(pivot);
addBox(pivot, 0.145, 0.28, 0.145, M.cat, 0, -0.13, 0);
addBox(pivot, 0.13, 0.23, 0.13, M.cat, 0, -0.31, 0);
addBox(pivot, 0.2, 0.1, 0.21, M.catLight, 0.025, -0.42, 0);
legs.push({ pivot, ...data });
}
// Segmented voxel tail.
const tailRoot = new THREE.Group();
tailRoot.position.set(-0.57, 0.58, 0);
catModel.add(tailRoot);
const tailSegments = [];
let tailParent = tailRoot;
for (let i = 0; i < 7; i++) {
const segment = new THREE.Group();
segment.position.set(i === 0 ? 0 : -0.145, i === 0 ? 0 : 0.025, 0);
tailParent.add(segment);
const size = 0.16 - i * 0.011;
addBox(segment, size, size, size, i % 2 ? M.catDark : M.cat, -0.055, 0, 0);
tailSegments.push(segment);
tailParent = segment;
}
// -------------------------------------------------------------------------
// Animation path: carrier → threshold → mat
// -------------------------------------------------------------------------
const keyframes = [
{ t: 0.0, x: -3.68, y: 0.21, z: 0.20, h: 0.0 },
{ t: 2.2, x: -3.68, y: 0.21, z: 0.20, h: 0.0 },
{ t: 6.4, x: -1.18, y: 0.0, z: 0.20, h: 0.0 },
{ t: 8.2, x: -1.18, y: 0.0, z: 0.20, h: 0.0 },
{ t: 9.9, x: -0.55, y: 0.0, z: 0.32, h: -0.12 },
{ t: 12.1, x: -0.55, y: 0.0, z: 0.32, h: -0.12 },
{ t: 18.3, x: 2.10, y: 0.0, z: 1.08, h: -0.28 },
{ t: 20.4, x: 2.10, y: 0.0, z: 1.08, h: -0.28 },
{ t: 25.3, x: 2.90, y: 0.105, z: 1.42, h: -0.22 },
{ t: 28.9, x: 3.40, y: 0.105, z: 1.62, h: -0.48 },
{ t: 35.0, x: 3.12, y: 0.105, z: 1.48, h: -0.72 }
];
const cumulativeDistance = [0];
for (let i = 1; i < keyframes.length; i++) {
const a = keyframes[i - 1];
const b = keyframes[i];
cumulativeDistance[i] =
cumulativeDistance[i - 1] +
Math.hypot(b.x - a.x, b.z - a.z);
}
const clamp01 = (value) => Math.max(0, Math.min(1, value));
const lerp = THREE.MathUtils.lerp;
const smooth01 = (value) => {
const x = clamp01(value);
return x * x * (3 - 2 * x);
};
function samplePath(time) {
let index = keyframes.length - 2;
for (let i = 0; i < keyframes.length - 1; i++) {
if (time <= keyframes[i + 1].t) {
index = i;
break;
}
}
const a = keyframes[index];
const b = keyframes[index + 1];
const span = Math.max(0.0001, b.t - a.t);
const raw = clamp01((time - a.t) / span);
const eased = smooth01(raw);
const distance = lerp(
cumulativeDistance[index],
cumulativeDistance[index + 1],
eased
);
const moving = Math.hypot(b.x - a.x, b.z - a.z) > 0.01;
return {
x: lerp(a.x, b.x, eased),
y: lerp(a.y, b.y, eased),
z: lerp(a.z, b.z, eased),
h: lerp(a.h, b.h, eased),
distance,
moving
};
}
const stages = [
{ until: 2.2, label: "Inside the carrier" },
{ until: 6.4, label: "A cautious step out" },
{ until: 12.1, label: "Sniffing the threshold" },
{ until: 20.4, label: "A slow, unhurried approach" },
{ until: 28.9, label: "Testing the quiet mat" },
{ until: Infinity, label: "Settled on the mat" }
];
let elapsed = 0;
let playing = true;
let lastTime = performance.now();
function updateCat(time) {
const pose = samplePath(time);
catRoot.position.set(pose.x, pose.y, pose.z);
catRoot.rotation.y = pose.h;
const walkPhase = (pose.distance / 0.48) * Math.PI * 2;
catModel.position.y = pose.moving
? Math.abs(Math.sin(walkPhase)) * 0.026
: 0;
catModel.rotation.z = pose.moving ? Math.sin(walkPhase) * 0.012 : 0;
for (const leg of legs) {
const swing = pose.moving
? Math.sin(walkPhase + leg.offset) * 0.34
: 0;
leg.pivot.rotation.z = swing;
leg.pivot.rotation.x = pose.moving
? Math.cos(walkPhase + leg.offset) * 0.025
: 0;
}
let headYaw = 0;
let headPitch = 0;
if (time < 2.2) {
headYaw = Math.sin(time * 0.75) * 0.17;
headPitch = 0.04 + Math.sin(time * 1.1) * 0.025;
} else if (time < 6.4) {
headYaw = 0.045;
headPitch = 0.08;
} else if (time < 9.9) {
headYaw = Math.sin(time * 1.5) * 0.07;
headPitch = 0.28 + Math.sin(time * 4.2) * 0.045;
} else if (time < 12.1) {
headYaw = -0.1;
headPitch = 0.25;
} else if (time < 18.3) {
headYaw = Math.sin(time * 0.65) * 0.035;
headPitch = 0.015;
} else if (time < 20.4) {
// A brief, alert glance toward the distant people.
headYaw = 0.67;
headPitch = -0.025;
} else if (time < 25.3) {
headYaw = -0.035;
headPitch = 0.06;
} else if (time < 28.9) {
headYaw = Math.sin(time * 1.4) * 0.07;
headPitch = 0.23;
} else {
headYaw = Math.sin(time * 0.45) * 0.035;
headPitch = 0.055;
}
headPivot.rotation.y = headYaw;
headPivot.rotation.z = headPitch;
const earTwitch = Math.max(
0,
Math.sin((time - 3.7) * 1.7) - 0.93
) * 3.5;
earLeft.rotation.z = -earTwitch;
earRight.rotation.z = earTwitch * 0.55;
const rest = smooth01((time - 28.9) / 5.7);
bodyRig.position.y = -0.13 * rest;
headPivot.position.y = 0.72 - 0.075 * rest;
tailRoot.rotation.z = -0.6 * rest;
tailRoot.rotation.y = Math.sin(time * 1.25) * 0.045 * (1 - rest * 0.5);
tailSegments.forEach((segment, index) => {
segment.rotation.z =
-0.08 * rest +
Math.sin(time * 1.25 - index * 0.28) * 0.018;
segment.rotation.y =
Math.sin(time * 0.85 - index * 0.2) * 0.012;
});
return pose;
}
function updateHumans(time) {
for (const human of humans) {
// Only minute breathing and head shifts; they never approach the cat.
human.torso.scale.y = 1 + Math.sin(time * 0.58 + human.phase) * 0.006;
human.head.rotation.y = Math.sin(time * 0.18 + human.phase) * 0.025;
human.root.rotation.z = Math.sin(time * 0.31 + human.phase) * 0.0018;
}
}
function updateUI(time) {
const progress = (time / DURATION) * 100;
timeline.value = time.toFixed(2);
timeline.style.setProperty("--progress", `${progress}%`);
const seconds = Math.floor(time);
timeLabel.textContent = `0:${String(seconds).padStart(2, "0")} / 0:36`;
let stageIndex = stages.findIndex((stage) => time < stage.until);
if (stageIndex < 0) stageIndex = stages.length - 1;
stageName.textContent = stages[stageIndex].label;
stageDots.forEach((dot, index) => {
dot.classList.toggle("active", index === stageIndex);
dot.classList.toggle("done", index < stageIndex);
});
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, reset
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.88,
phi: 1.03,
radius: 15.4,
target: new THREE.Vector3(-0.35, 0.72, -0.15)
};
const defaultCamera = { ...cameraState };
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.cos(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.sin(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.classList.add("grabbing");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.theta = THREE.MathUtils.clamp(
cameraState.theta - deltaX * 0.0055,
-0.15,
1.65
);
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.0045,
0.48,
1.34
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
renderer.domElement.classList.remove("grabbing");
if (event?.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
9.5,
23
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
cameraState.radius = defaultCamera.radius;
updateCamera();
});
resetViewButton.addEventListener("click", () => {
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
cameraState.radius = defaultCamera.radius;
updateCamera();
});
// -------------------------------------------------------------------------
// Playback UI
// -------------------------------------------------------------------------
function updatePlayButton() {
if (elapsed >= DURATION) {
playButton.textContent = "▶ Play";
} else if (playing) {
playButton.textContent = "Ⅱ Pause";
} else {
playButton.textContent = "▶ Play";
}
}
playButton.addEventListener("click", () => {
if (elapsed >= DURATION) elapsed = 0;
playing = !playing;
updatePlayButton();
});
replayButton.addEventListener("click", () => {
elapsed = 0;
playing = true;
updatePlayButton();
});
timeline.addEventListener("input", () => {
elapsed = Number(timeline.value);
playing = false;
updatePlayButton();
});
document.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.code === "Space") {
event.preventDefault();
playButton.click();
} else if (event.key.toLowerCase() === "r") {
replayButton.click();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Main loop
// -------------------------------------------------------------------------
function animate(now) {
const delta = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (playing) {
elapsed = Math.min(DURATION, elapsed + delta);
if (elapsed >= DURATION) {
playing = false;
updatePlayButton();
}
}
updateCat(elapsed);
updateHumans(now / 1000);
updateUI(elapsed);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera();
updatePlayButton();
requestAnimationFrame(animate);
</script>
</body>
</html>
```