Prompt specification
Build or customize the Three.js 3D scene "Resident entering a Bukchon hillside courtyard" 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: Resident entering a Bukchon hillside courtyard
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/resident-entering-a-bukchon-hillside-courtyard-x3018
Scene Description Prompt:
Animate a resident entering a voxel Bukchon hillside courtyard from a stepped lane, keeping interiors schematic. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (resident-entering-a-bukchon-hillside-courtyard-x3018):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bukchon Courtyard Arrival</title>
<style>
:root {
--ink: #27312f;
--paper: rgba(248, 245, 235, 0.92);
--line: rgba(39, 49, 47, 0.14);
--accent: #b76543;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd8d4;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
z-index: 2;
pointer-events: none;
}
.title-card {
top: 24px;
left: 24px;
max-width: 360px;
}
.eyebrow {
margin: 0 0 7px;
color: #64716d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 4vw, 48px);
font-weight: 500;
letter-spacing: -0.035em;
line-height: 0.98;
}
.subtitle {
margin: 10px 0 0;
color: #52615d;
font-size: 13px;
line-height: 1.5;
}
.controls {
right: 24px;
top: 24px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
min-height: 38px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--paper);
color: var(--ink);
box-shadow: 0 8px 30px rgba(45, 58, 54, 0.10);
backdrop-filter: blur(12px);
cursor: pointer;
font: inherit;
font-size: 12px;
font-weight: 700;
transition:
transform 150ms ease,
background 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: #fffdf7;
}
button:active { transform: translateY(0); }
.hint {
left: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--paper);
box-shadow: 0 8px 30px rgba(45, 58, 54, 0.08);
backdrop-filter: blur(12px);
color: #586560;
font-size: 11px;
line-height: 1;
}
.dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(183, 101, 67, 0.14);
}
#status {
right: 24px;
bottom: 24px;
color: #52615d;
font-size: 11px;
letter-spacing: 0.04em;
}
#loading {
position: fixed;
inset: 0;
z-index: 5;
display: grid;
place-items: center;
background: #cbd8d4;
transition: opacity 400ms ease, visibility 400ms ease;
}
#loading.done {
opacity: 0;
visibility: hidden;
}
.loader {
display: grid;
justify-items: center;
gap: 14px;
color: #52615d;
font-size: 11px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.loader-cube {
width: 26px;
height: 26px;
background: #b76543;
animation: cube-turn 1.2s ease-in-out infinite;
}
@keyframes cube-turn {
0%, 100% { transform: rotate(0deg) scale(0.9); }
50% { transform: rotate(90deg) scale(1.05); }
}
@media (max-width: 680px) {
.title-card { top: 18px; left: 18px; }
.subtitle { max-width: 250px; }
.controls { top: auto; right: 18px; bottom: 62px; }
.hint { left: 18px; bottom: 18px; }
#status { display: none; }
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="hud title-card">
<p class="eyebrow">Bukchon · Seoul</p>
<h1>Courtyard<br>Arrival</h1>
<p class="subtitle">
A resident descends the stepped lane into a quiet voxel hanok courtyard.
</p>
</header>
<nav class="hud controls" aria-label="Animation controls">
<button id="pause" type="button">Pause</button>
<button id="replay" type="button">Replay arrival</button>
</nav>
<div class="hud hint">
<span class="dot"></span>
<span>Drag to orbit · Wheel to zoom · Arrow keys to move</span>
</div>
<div class="hud" id="status">Resident approaching</div>
<div id="loading">
<div class="loader">
<div class="loader-cube"></div>
<span>Building courtyard</span>
</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, scene, and camera
// ---------------------------------------------------------------------
const stage = document.querySelector("#stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd8d4);
scene.fog = new THREE.Fog(0xcbd8d4, 36, 72);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
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.08;
stage.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(
0xe7f1ee,
0x8d795e,
2.1
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe7c4, 3.25);
sun.position.set(-12, 24, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc8dce2, 0.65);
fill.position.set(18, 10, -18);
scene.add(fill);
// ---------------------------------------------------------------------
// Small voxel construction helpers
// ---------------------------------------------------------------------
const materialCache = new Map();
function material(color) {
if (color && color.isMaterial) return color;
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0
})
);
}
return materialCache.get(color);
}
function box(
parent,
width,
height,
depth,
x,
y,
z,
color,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function groupAt(x, y, z, parent = scene) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
return group;
}
// A stepped, tiled roof with the ridge running along local X.
function voxelRoof(
parent,
width,
depth,
x,
y,
z,
rotation = 0
) {
const roof = new THREE.Group();
roof.position.set(x, y, z);
roof.rotation.y = rotation;
parent.add(roof);
const steps = 9;
const segment = depth / steps;
const halfDepth = depth / 2;
const rise = 1.32;
for (let i = 0; i < steps; i++) {
const localZ = -halfDepth + (i + 0.5) * segment;
const normalized = Math.abs(localZ) / halfDepth;
const stepY = rise * (1 - normalized);
const stepWidth = width * (0.94 + normalized * 0.11);
box(
roof,
stepWidth,
0.29,
segment + 0.055,
0,
stepY,
localZ,
i % 2 === 0 ? 0x343c3e : 0x465052
);
}
box(roof, width + 0.58, 0.32, 0.3, 0, -0.03, -halfDepth, 0x293234);
box(roof, width + 0.58, 0.32, 0.3, 0, -0.03, halfDepth, 0x293234);
box(roof, width + 0.22, 0.28, 0.38, 0, rise + 0.05, 0, 0x252d2f);
for (const side of [-1, 1]) {
box(
roof,
0.25,
0.42,
0.58,
side * (width / 2 - 0.02),
0.3,
0,
0x242c2e
);
}
return roof;
}
function latticeDoor(parent, x, y, z, width, height, rotation = 0) {
const door = new THREE.Group();
door.position.set(x, y, z);
door.rotation.y = rotation;
parent.add(door);
box(door, width, height, 0.13, 0, 0, 0, 0x59483a);
const divisions = 4;
for (let i = 1; i < divisions; i++) {
box(
door,
0.055,
height - 0.08,
0.17,
-width / 2 + (width * i) / divisions,
0,
0,
0xbaa486
);
}
for (const localY of [-height * 0.28, height * 0.28]) {
box(
door,
width - 0.08,
0.055,
0.17,
0,
localY,
0,
0xbaa486
);
}
}
// ---------------------------------------------------------------------
// Landscape and paving
// ---------------------------------------------------------------------
box(scene, 58, 1.4, 50, 0, -3.25, 0, 0x9fa98c, false);
box(scene, 20, 2.7, 18.5, 0, -1.45, 0, 0xc9c1ab, false);
box(scene, 20.4, 0.18, 18.9, 0, -0.22, 0, 0xe0d6c0, false);
const pavingColors = [
0xd8d0bd,
0xe1dac8,
0xcfc7b4,
0xdad3c2
];
let tileIndex = 0;
for (let z = -1.1; z <= 7.1; z += 1.38) {
for (let x = -4.2; x <= 4.2; x += 1.38) {
box(
scene,
1.25,
0.12,
1.25,
x,
-0.02,
z,
pavingColors[tileIndex++ % pavingColors.length],
false
);
}
}
// Distant stepped hills and a schematic modern neighborhood.
const hillColors = [0x91a49b, 0xa4b1a3, 0xb1b9aa];
for (let i = 0; i < 10; i++) {
const h = 3.2 + (i % 4) * 1.15;
box(
scene,
7.5,
h,
6.5,
-29 + i * 6.2,
-2.9 + h / 2,
-25 - (i % 2) * 2.2,
hillColors[i % hillColors.length],
false
);
}
for (let i = 0; i < 11; i++) {
const h = 2.3 + (i * 7 % 5) * 0.65;
const x = -24 + i * 4.7;
const z = -17.5 - (i % 3) * 2.6;
box(scene, 3.4, h, 3.2, x, -2.5 + h / 2, z, 0xd1d4cc, false);
box(scene, 3.7, 0.32, 3.5, x, -2.5 + h, z, 0x9da6a2, false);
if (i % 3 === 0) {
box(
scene,
1.1,
1.25,
1.2,
x + 0.65,
-2.5 + h + 0.62,
z,
0xb9c0bd,
false
);
}
}
// Cubic clouds.
const cloud = groupAt(0, 0, 0);
box(cloud, 5.5, 0.7, 1.5, -3, 11.7, -21, 0xe8eeea, false);
box(cloud, 3.4, 1.2, 1.7, 0, 12, -21, 0xe8eeea, false);
box(cloud, 4.5, 0.8, 1.4, 3.2, 11.7, -21, 0xe8eeea, false);
// ---------------------------------------------------------------------
// Stepped hillside lane
// ---------------------------------------------------------------------
const stepPositions = [];
function stepTop(index) {
return 4.3 - index * (3.9 / 9);
}
for (let i = 0; i < 10; i++) {
const x = 15.2 - i * 0.83;
const z = 11.2 - i * 0.62;
const top = stepTop(i);
const bottom = -0.14;
const height = top - bottom;
stepPositions.push(new THREE.Vector3(x, top + 0.035, z));
box(
scene,
2.85,
height,
2.55,
x,
bottom + height / 2,
z,
i % 2 === 0 ? 0xbab3a2 : 0xc5bdaa
);
// Low edge stones emphasize each tread.
box(
scene,
0.13,
0.18,
2.35,
x + 1.32,
top + 0.08,
z,
0x928b7d,
false
);
}
// Retaining blocks on the uphill side of the lane.
for (let i = 0; i < 11; i++) {
box(
scene,
1.8,
1.0,
1.35,
17.1,
0.2 + i * 0.38,
6.1 + i * 0.56,
i % 2 ? 0xaaa38f : 0xb7af9c
);
}
// ---------------------------------------------------------------------
// Back hanok hall
// ---------------------------------------------------------------------
const backHall = groupAt(0, 0, -6.8);
box(backHall, 14.3, 0.28, 5.9, 0, -0.04, 0, 0xb7aa91);
box(backHall, 14, 3.2, 0.24, 0, 1.6, -2.9, 0xe3ded0);
box(backHall, 0.25, 3.2, 5.8, -7, 1.6, 0, 0xe5dfd2);
box(backHall, 0.25, 3.2, 5.8, 7, 1.6, 0, 0xe5dfd2);
// Front plaster wall and wood structure.
box(backHall, 14, 1.05, 0.2, 0, 0.5, 2.9, 0xe8e1d3);
box(backHall, 14, 2.0, 0.2, 0, 2.05, 2.9, 0xded8ca);
for (const x of [-6.55, -3.25, 0, 3.25, 6.55]) {
box(backHall, 0.23, 3.2, 0.34, x, 1.6, 3.03, 0x675140);
}
box(backHall, 14.1, 0.23, 0.38, 0, 1.05, 3.03, 0x675140);
box(backHall, 14.1, 0.23, 0.38, 0, 3.05, 3.03, 0x675140);
for (const x of [-4.9, -1.65, 1.65, 4.9]) {
latticeDoor(backHall, x, 1.02, 3.16, 2.25, 1.85);
}
voxelRoof(backHall, 14.9, 6.75, 0, 3.2, 0);
// ---------------------------------------------------------------------
// Left hanok wing
// ---------------------------------------------------------------------
const leftWing = groupAt(-7.2, 0, -1.5);
box(leftWing, 5.65, 0.28, 10.7, 0, -0.04, 0, 0xb7aa91);
box(leftWing, 0.25, 3.2, 10.5, -2.8, 1.6, 0, 0xe2dccf);
box(leftWing, 5.5, 3.2, 0.24, 0, 1.6, -5.25, 0xe4ded1);
box(leftWing, 5.5, 3.2, 0.24, 0, 1.6, 5.25, 0xe4ded1);
const leftFacade = new THREE.Group();
leftFacade.position.set(2.8, 0, 0);
leftFacade.rotation.y = Math.PI / 2;
leftWing.add(leftFacade);
box(leftFacade, 10.5, 1.05, 0.2, 0, 0.5, 0, 0xe9e2d5);
box(leftFacade, 10.5, 2.0, 0.2, 0, 2.05, 0, 0xded8ca);
for (const x of [-4.9, -2.45, 0, 2.45, 4.9]) {
box(leftFacade, 0.23, 3.2, 0.34, x, 1.6, 0.12, 0x675140);
}
box(leftFacade, 10.55, 0.23, 0.38, 0, 1.05, 0.12, 0x675140);
box(leftFacade, 10.55, 0.23, 0.38, 0, 3.05, 0.12, 0x675140);
for (const x of [-3.7, -1.25, 1.25, 3.7]) {
latticeDoor(leftFacade, x, 1.02, 0.14, 1.95, 1.85);
}
voxelRoof(leftWing, 11.35, 6.35, 0, 3.2, 0, Math.PI / 2);
// ---------------------------------------------------------------------
// Right pavilion: open facade and deliberately schematic interior
// ---------------------------------------------------------------------
const rightPavilion = groupAt(6.4, 0, -4.0);
box(rightPavilion, 8.45, 0.3, 6.45, 0, -0.02, 0, 0xb89f7e);
box(rightPavilion, 8.2, 3.15, 0.23, 0, 1.58, -3.2, 0xe4dece);
box(rightPavilion, 0.22, 3.15, 6.2, -4.1, 1.58, 0, 0xe4dece);
// The camera-facing side is cut down to expose the interior massing.
box(rightPavilion, 0.22, 1.1, 6.2, 4.1, 0.55, 0, 0xded7c7);
for (const x of [-4.0, 0, 4.0]) {
box(rightPavilion, 0.25, 3.2, 0.38, x, 1.6, 3.12, 0x675140);
}
box(rightPavilion, 8.4, 0.25, 0.38, 0, 3.05, 3.12, 0x675140);
// Simple interior planes and furniture blocks only.
box(rightPavilion, 3.0, 1.35, 0.12, -2.35, 0.68, -0.8, 0xd6cfbf);
box(rightPavilion, 1.8, 1.35, 0.12, 2.5, 0.68, -0.8, 0xd6cfbf);
box(rightPavilion, 2.7, 0.75, 1.0, -2.35, 0.48, -2.35, 0xa88768);
box(rightPavilion, 1.8, 0.62, 0.75, 2.55, 0.42, -2.25, 0x9d8065);
box(rightPavilion, 1.3, 0.58, 0.7, 0.1, 0.4, -1.8, 0xb59675);
voxelRoof(rightPavilion, 9.25, 7.2, 0, 3.2, 0);
// ---------------------------------------------------------------------
// Courtyard gate aligned with the descending lane
// ---------------------------------------------------------------------
const gate = groupAt(7.25, 0, 5.25);
gate.rotation.y = -2.0;
box(gate, 0.34, 2.7, 0.42, -1.4, 1.35, 0, 0x6d5744);
box(gate, 0.34, 2.7, 0.42, 1.4, 1.35, 0, 0x6d5744);
box(gate, 3.25, 0.28, 0.45, 0, 2.52, 0, 0x594839);
box(gate, 0.5, 0.9, 0.48, -1.4, 0.45, 0, 0xc4b9a3);
box(gate, 0.5, 0.9, 0.48, 1.4, 0.45, 0, 0xc4b9a3);
voxelRoof(gate, 3.75, 2.15, 0, 2.7, 0);
// ---------------------------------------------------------------------
// Courtyard vegetation and small objects
// ---------------------------------------------------------------------
function makeTree(x, z, scale = 1) {
const tree = groupAt(x, 0, z);
tree.scale.setScalar(scale);
box(tree, 0.62, 2.7, 0.62, 0, 1.35, 0, 0x7f6148);
box(tree, 0.4, 1.0, 0.4, -0.55, 2.2, 0, 0x7f6148);
box(tree, 0.36, 0.95, 0.36, 0.55, 2.35, 0.15, 0x7f6148);
const leafBlocks = [
[-0.8, 3.0, -0.4, 1.65],
[0.7, 3.15, -0.15, 1.85],
[0, 3.75, 0.25, 2.05],
[-0.65, 3.85, 0.6, 1.45],
[0.8, 3.8, 0.65, 1.35],
[0, 3.05, 0.95, 1.55]
];
leafBlocks.forEach((entry, index) => {
box(
tree,
entry[3],
entry[3] * 0.85,
entry[3],
entry[0],
entry[1],
entry[2],
index % 2 === 0 ? 0x748c61 : 0x81986a
);
});
return tree;
}
makeTree(-2.45, 5.65, 1.0);
makeTree(16.2, 12.8, 0.72);
// Stone lantern with a warm emissive cube.
const lantern = groupAt(3.35, 0, 1.55);
box(lantern, 0.82, 0.28, 0.82, 0, 0.14, 0, 0xa9a18e);
box(lantern, 0.45, 1.0, 0.45, 0, 0.75, 0, 0xb5ad9a);
box(lantern, 0.88, 0.18, 0.88, 0, 1.3, 0, 0xc1b9a6);
const lanternGlass = new THREE.MeshStandardMaterial({
color: 0xffd68a,
emissive: 0xff9b35,
emissiveIntensity: 1.65,
roughness: 0.5
});
box(lantern, 0.43, 0.48, 0.43, 0, 1.62, 0, lanternGlass);
box(lantern, 1.0, 0.22, 1.0, 0, 1.98, 0, 0x454a47);
const lanternLight = new THREE.PointLight(0xffb35f, 1.0, 5.5, 2);
lanternLight.position.set(0, 1.65, 0);
lantern.add(lanternLight);
// Low bench.
box(scene, 2.15, 0.18, 0.62, -0.5, 0.48, 7.25, 0x8c674d);
box(scene, 0.22, 0.5, 0.48, -1.25, 0.24, 7.25, 0x6f513e);
box(scene, 0.22, 0.5, 0.48, 0.25, 0.24, 7.25, 0x6f513e);
// Stone water basin.
const basin = groupAt(4.55, 0, 5.15);
box(basin, 1.2, 0.48, 1.2, 0, 0.24, 0, 0xaaa18c);
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x78a9ad,
roughness: 0.22,
metalness: 0.05
});
box(basin, 0.78, 0.05, 0.78, 0, 0.5, 0, waterMaterial);
// Small clay planters by the pavilion.
for (const [x, z] of [[2.9, -0.25], [9.85, -0.25]]) {
box(scene, 0.55, 0.58, 0.55, x, 0.29, z, 0xa76e50);
box(scene, 0.68, 0.22, 0.68, x, 0.63, z, 0x748960);
}
// ---------------------------------------------------------------------
// Resident model
// ---------------------------------------------------------------------
const resident = new THREE.Group();
scene.add(resident);
const bodyRig = new THREE.Group();
resident.add(bodyRig);
const coatColor = 0xb76846;
const darkCloth = 0x394846;
const skinColor = 0xd4a17e;
const hairColor = 0x2c302e;
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.17, 0.82, 0);
rightLeg.position.set(0.17, 0.82, 0);
bodyRig.add(leftLeg, rightLeg);
box(leftLeg, 0.26, 0.72, 0.29, 0, -0.35, 0, darkCloth);
box(rightLeg, 0.26, 0.72, 0.29, 0, -0.35, 0, darkCloth);
box(leftLeg, 0.29, 0.16, 0.42, 0, -0.73, 0.07, 0x2e3534);
box(rightLeg, 0.29, 0.16, 0.42, 0, -0.73, 0.07, 0x2e3534);
box(bodyRig, 0.65, 0.75, 0.37, 0, 1.18, 0, coatColor);
box(bodyRig, 0.69, 0.16, 0.4, 0, 0.85, 0, 0x8f4f39);
box(bodyRig, 0.2, 0.13, 0.03, 0, 1.24, 0.205, 0xe3b48f);
box(bodyRig, 0.46, 0.44, 0.43, 0, 1.76, 0, skinColor);
box(bodyRig, 0.49, 0.16, 0.46, 0, 1.99, -0.015, hairColor);
box(bodyRig, 0.13, 0.28, 0.46, -0.18, 1.86, -0.02, hairColor);
box(bodyRig, 0.055, 0.055, 0.025, -0.11, 1.79, 0.225, 0x303230);
box(bodyRig, 0.055, 0.055, 0.025, 0.11, 1.79, 0.225, 0x303230);
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.43, 1.43, 0);
rightArm.position.set(0.43, 1.43, 0);
bodyRig.add(leftArm, rightArm);
box(leftArm, 0.22, 0.62, 0.25, 0, -0.28, 0, coatColor);
box(rightArm, 0.22, 0.62, 0.25, 0, -0.28, 0, coatColor);
box(leftArm, 0.2, 0.18, 0.21, 0, -0.66, 0, skinColor);
box(rightArm, 0.2, 0.18, 0.21, 0, -0.66, 0, skinColor);
// Small shoulder bag.
box(bodyRig, 0.37, 0.43, 0.17, 0.43, 0.88, 0.02, 0x8d5e45);
box(bodyRig, 0.08, 0.68, 0.07, 0.3, 1.25, 0.02, 0x6c4937);
// ---------------------------------------------------------------------
// Resident route: down the lane, through the gate, into the courtyard
// ---------------------------------------------------------------------
const routePoints = stepPositions.map(point => point.clone());
routePoints.push(
new THREE.Vector3(7.1, 0.08, 5.25),
new THREE.Vector3(5.7, 0.06, 4.62),
new THREE.Vector3(3.8, 0.06, 3.72),
new THREE.Vector3(1.8, 0.06, 3.02),
new THREE.Vector3(-0.2, 0.06, 2.82)
);
const route = new THREE.CatmullRomCurve3(
routePoints,
false,
"centripetal"
);
// ---------------------------------------------------------------------
// Custom camera controls — no examples or addons
// ---------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(1.2, 1.1, 1.2);
const spherical = new THREE.Spherical(29, 0.92, 0.62);
let desiredRadius = spherical.radius;
let desiredPhi = spherical.phi;
let desiredTheta = spherical.theta;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
desiredTheta -= dx * 0.005;
desiredPhi = THREE.MathUtils.clamp(
desiredPhi - dy * 0.005,
0.34,
1.38
);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius * Math.exp(event.deltaY * 0.001),
13,
48
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
desiredRadius = 29;
desiredPhi = 0.92;
desiredTheta = 0.62;
cameraTarget.set(1.2, 1.1, 1.2);
});
window.addEventListener("keydown", event => {
if (event.target instanceof HTMLButtonElement) return;
switch (event.code) {
case "ArrowLeft":
desiredTheta += 0.12;
break;
case "ArrowRight":
desiredTheta -= 0.12;
break;
case "ArrowUp":
desiredPhi = Math.max(0.34, desiredPhi - 0.08);
break;
case "ArrowDown":
desiredPhi = Math.min(1.38, desiredPhi + 0.08);
break;
case "Equal":
case "NumpadAdd":
desiredRadius = Math.max(13, desiredRadius - 1.5);
break;
case "Minus":
case "NumpadSubtract":
desiredRadius = Math.min(48, desiredRadius + 1.5);
break;
case "Space":
event.preventDefault();
togglePause();
break;
}
});
// ---------------------------------------------------------------------
// Animation state and UI
// ---------------------------------------------------------------------
const pauseButton = document.querySelector("#pause");
const replayButton = document.querySelector("#replay");
const status = document.querySelector("#status");
const animationDuration = 22;
let animationElapsed = 0;
let paused = false;
let completed = false;
function updateStatus() {
if (paused) {
status.textContent = "Arrival paused";
} else if (completed) {
status.textContent = "Resident has entered the courtyard";
} else {
status.textContent = "Resident approaching";
}
}
function togglePause() {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
updateStatus();
}
pauseButton.addEventListener("click", togglePause);
replayButton.addEventListener("click", () => {
animationElapsed = 0;
completed = false;
paused = false;
pauseButton.textContent = "Pause";
updateStatus();
});
function shortestAngleLerp(from, to, amount) {
const difference = Math.atan2(
Math.sin(to - from),
Math.cos(to - from)
);
return from + difference * amount;
}
// ---------------------------------------------------------------------
// Render loop
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused && !completed) {
animationElapsed += delta;
if (animationElapsed >= animationDuration) {
animationElapsed = animationDuration;
completed = true;
updateStatus();
}
}
const progress = THREE.MathUtils.clamp(
animationElapsed / animationDuration,
0,
1
);
const pathPosition = route.getPointAt(progress);
const tangent = route.getTangentAt(progress);
resident.position.copy(pathPosition);
const targetYaw = Math.atan2(tangent.x, tangent.z);
resident.rotation.y = shortestAngleLerp(
resident.rotation.y,
targetYaw,
1 - Math.exp(-delta * 9)
);
const movement = completed
? Math.max(0, 1 - (animationElapsed - animationDuration) / 0.7)
: 1;
const walkPhase = animationElapsed * 8.1;
const legSwing = Math.sin(walkPhase) * 0.46 * movement;
const armSwing = Math.sin(walkPhase) * 0.38 * movement;
leftLeg.rotation.x = legSwing;
rightLeg.rotation.x = -legSwing;
leftArm.rotation.x = -armSwing;
rightArm.rotation.x = armSwing;
const bob = Math.abs(Math.sin(walkPhase)) * 0.035 * movement;
bodyRig.position.y = bob;
bodyRig.rotation.z = Math.sin(walkPhase * 0.5) * 0.012 * movement;
// Damped camera orbit.
const cameraDamping = 1 - Math.exp(-delta * 9);
spherical.radius += (desiredRadius - spherical.radius) * cameraDamping;
spherical.phi += (desiredPhi - spherical.phi) * cameraDamping;
spherical.theta += (desiredTheta - spherical.theta) * cameraDamping;
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
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();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("done");
});
</script>
</body>
</html>
```