Prompt specification
Build or customize the Three.js 3D scene "Resident carrying baskets along a coastal stair" 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 carrying baskets along a coastal stair
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/resident-carrying-baskets-along-a-coastal-stair-x2954
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: Resident carrying baskets along a coastal stair. Create a compact Sidi Bou Said vignette with an original resident, stepped lane, and sea-view opening. Keep daily activity grounded in the spatial setting rather than tourist stereotypes.
Working Three.js Starter (resident-carrying-baskets-along-a-coastal-stair-x2954):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The Lane Home — Sidi Bou Said</title>
<style>
:root {
--blue: #174f9b;
--ink: #17354c;
--paper: rgba(250, 249, 242, 0.92);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9d7df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#stage,
canvas {
display: block;
width: 100%;
height: 100%;
}
#stage {
position: fixed;
inset: 0;
touch-action: none;
}
.caption {
position: fixed;
z-index: 2;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 18px 20px 17px;
border: 1px solid rgba(23, 79, 155, 0.18);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 12px 36px rgba(19, 49, 67, 0.12);
backdrop-filter: blur(8px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--blue);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0 0 8px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(26px, 4vw, 38px);
font-weight: 500;
line-height: 1.05;
}
.caption p {
margin: 0;
max-width: 34ch;
color: #38576d;
font-size: 13px;
line-height: 1.55;
}
.caption strong {
color: var(--ink);
font-weight: 700;
}
.controls {
position: fixed;
z-index: 3;
right: 22px;
bottom: 20px;
display: flex;
align-items: center;
gap: 12px;
color: rgba(23, 53, 76, 0.8);
font-size: 11px;
letter-spacing: 0.03em;
}
.controls span {
padding: 8px 11px;
border-radius: 3px;
background: rgba(250, 249, 242, 0.76);
box-shadow: 0 5px 18px rgba(19, 49, 67, 0.08);
pointer-events: none;
}
button {
border: 1px solid rgba(23, 79, 155, 0.3);
border-radius: 3px;
padding: 9px 12px;
background: rgba(250, 249, 242, 0.9);
color: var(--blue);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
}
button:hover,
button:focus-visible {
background: #fff;
outline: 2px solid rgba(23, 79, 155, 0.2);
outline-offset: 2px;
}
@media (max-width: 600px) {
.caption {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 14px 16px;
}
.caption p {
max-width: 42ch;
}
.controls {
right: 12px;
bottom: 12px;
}
.controls span {
display: none;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive voxel scene of a resident carrying baskets down coastal steps"></main>
<section class="caption">
<div class="eyebrow">Sidi Bou Said · Late morning</div>
<h1>The lane home</h1>
<p>
<strong>Yasmine, a local resident,</strong> returns from the neighborhood
market with two grocery baskets, taking the familiar stepped lane beside
the sea.
</p>
</section>
<nav class="controls" aria-label="Scene controls">
<span>Drag to orbit · Scroll to zoom</span>
<button id="reset" type="button">Reset view</button>
</nav>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#b9d7df");
scene.fog = new THREE.Fog("#b9d7df", 28, 64);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
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;
stage.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-10, 10, 8, -8, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.9, -0.3);
const view = {
yaw: 0.62,
pitch: 0.54,
radius: 24,
zoom: 1
};
const defaultView = { ...view };
function updateCamera() {
const horizontal = Math.cos(view.pitch) * view.radius;
camera.position.set(
cameraTarget.x + Math.sin(view.yaw) * horizontal,
cameraTarget.y + Math.sin(view.pitch) * view.radius,
cameraTarget.z + Math.cos(view.yaw) * horizontal
);
camera.lookAt(cameraTarget);
camera.zoom = view.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const aspect = window.innerWidth / window.innerHeight;
const halfHeight = Math.max(6.2, 8.6 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// Materials are shared so the scene remains lightweight.
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0
})
);
}
return materialCache.get(color);
}
function addBox(
parent,
width,
height,
depth,
x,
y,
z,
color,
options = {}
) {
const geometry = new THREE.BoxGeometry(width, height, depth);
const mesh = new THREE.Mesh(geometry, getMaterial(color));
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.rotation) {
mesh.rotation.set(...options.rotation);
}
parent.add(mesh);
return mesh;
}
function addBoxBetween(parent, start, end, width, depth, color) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const midpoint = a.clone().add(b).multiplyScalar(0.5);
const mesh = addBox(
parent,
width,
length,
depth,
midpoint.x,
midpoint.y,
midpoint.z,
color
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
// Lighting
const hemisphere = new THREE.HemisphereLight("#e9f7ff", "#b89d78", 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff0cf", 3.1);
sun.position.set(-9, 17, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const seaMaterial = new THREE.MeshStandardMaterial({
color: "#4f93ae",
roughness: 0.5,
metalness: 0.03
});
const sea = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
seaMaterial
);
sea.rotation.x = -Math.PI / 2;
sea.position.y = -0.45;
sea.receiveShadow = true;
scene.add(sea);
// The island and the two raised side terraces.
addBox(scene, 16, 0.8, 11, 0, -0.75, -1.15, "#b8a27d");
addBox(scene, 5.6, 0.45, 10.8, -4.8, -0.125, -1.1, "#d8c8a6");
addBox(scene, 5.0, 0.45, 10.8, 4.65, -0.125, -1.1, "#d8c8a6");
addBox(scene, 9.1, 0.45, 2.3, -0.15, -0.125, -4.8, "#d8c8a6");
// Low, broken-looking coastal masonry along the visible cliff edge.
for (let i = 0; i < 12; i++) {
const x = -7.15 + i * 1.3;
const height = 0.28 + (i % 3) * 0.055;
addBox(
scene,
1.22,
height,
0.4,
x,
-0.51,
4.25,
i % 2 ? "#cdbb98" : "#d9c8a5"
);
}
// Stepped lane, descending toward the sea-view opening.
const stepDepth = 0.74;
const stepWidth = 3.28;
const stairStartZ = -4.05;
for (let i = 0; i < 9; i++) {
const top = 2.7 - i * 0.27;
const bottom = -0.35;
const z = stairStartZ + i * stepDepth;
const height = top - bottom;
addBox(
scene,
stepWidth,
height,
stepDepth,
0,
bottom + height / 2,
z,
i % 2 ? "#e7deca" : "#eee7d7"
);
// Narrow cobalt nosings make the stair rhythm legible.
addBox(
scene,
stepWidth - 0.22,
0.035,
0.065,
0,
top + 0.012,
z + stepDepth / 2 - 0.035,
"#b8b6aa"
);
for (const side of [-1, 1]) {
const parapetX = side * 1.79;
addBox(
scene,
0.28,
0.72,
stepDepth,
parapetX,
top + 0.36,
z,
"#f2efe5"
);
addBox(
scene,
0.32,
0.075,
stepDepth,
parapetX,
top + 0.755,
z,
"#215ca5"
);
}
}
// Small landing at the bottom.
addBox(scene, 3.3, 0.89, 1.05, 0, 0.095, 2.75, "#eee7d7");
// A central gap in the sea wall creates the sea-view opening.
addBox(scene, 6.15, 1.12, 0.38, -4.58, 0.24, 3.65, "#f3f0e6");
addBox(scene, 5.65, 1.12, 0.38, 4.325, 0.24, 3.65, "#f3f0e6");
addBox(scene, 6.2, 0.09, 0.44, -4.58, 0.845, 3.65, "#245ea6");
addBox(scene, 5.7, 0.09, 0.44, 4.325, 0.845, 3.65, "#245ea6");
// Blue tile returns emphasize the cut edges of the opening.
addBox(scene, 0.08, 1.08, 0.43, -1.5, 0.25, 3.65, "#245ea6");
addBox(scene, 0.08, 1.08, 0.43, 1.5, 0.25, 3.65, "#245ea6");
function addFrontDoor(x, facadeZ, baseY, number) {
addBox(scene, 1.16, 2.12, 0.10, x, baseY + 1.06, facadeZ + 0.035, "#173b70");
addBox(scene, 0.53, 2.02, 0.12, x - 0.275, baseY + 1.03, facadeZ + 0.08, "#286bb7");
addBox(scene, 0.53, 2.02, 0.12, x + 0.275, baseY + 1.03, facadeZ + 0.08, "#286bb7");
addBox(scene, 0.035, 2.02, 0.15, x, baseY + 1.03, facadeZ + 0.09, "#174f9b");
addBox(scene, 1.24, 0.12, 0.16, x, baseY + 2.12, facadeZ + 0.08, "#faf7ee");
addBox(scene, 1.12, 0.035, 0.14, x, baseY + 0.04, facadeZ + 0.09, "#d8c8a6");
// Small glazed panel and handle.
addBox(scene, 0.27, 0.32, 0.03, x, baseY + 1.58, facadeZ + 0.155, "#9bc2ce");
addBox(scene, 0.045, 0.19, 0.05, x + 0.17, baseY + 0.95, facadeZ + 0.17, "#d5b66e");
// House-number tile.
addBox(scene, 0.26, 0.26, 0.035, x + 0.88, baseY + 1.72, facadeZ + 0.075, "#1d579d");
addBox(
scene,
0.12,
0.035,
0.045,
x + 0.88,
baseY + 1.72,
facadeZ + 0.105,
"#f4efe1"
);
}
function addFrontWindow(x, facadeZ, y, width = 1.05) {
addBox(scene, width, 1.04, 0.075, x, y, facadeZ + 0.035, "#203f55");
addBox(scene, 0.035, 1.02, 0.12, x, y, facadeZ + 0.09, "#efece2");
for (const side of [-1, 1]) {
addBox(
scene,
width * 0.48,
1.08,
0.11,
x + side * width * 0.72,
y,
facadeZ + 0.09,
"#2a6bb6"
);
for (let i = 0; i < 3; i++) {
addBox(
scene,
width * 0.32,
0.025,
0.025,
x + side * width * 0.72,
y - 0.29 + i * 0.29,
facadeZ + 0.16,
"#174f9b"
);
}
}
addBox(scene, width + 0.28, 0.09, 0.18, x, y - 0.57, facadeZ + 0.08, "#faf7ee");
}
function addSideWindow(x, z, y, inwardSign) {
addBox(scene, 0.075, 1.02, 0.91, x, y, z, "#203f55");
addBox(scene, 0.11, 1.02, 0.035, x + inwardSign * 0.02, y, z, "#f0ede3");
for (const side of [-1, 1]) {
addBox(
scene,
0.11,
1.08,
0.32,
x + inwardSign * 0.055,
y,
z + side * 0.61,
"#286bb7"
);
}
}
function addHouse(x, z, width, depth, height, baseY, doorX, windowX) {
const top = baseY + height;
const facadeZ = z + depth / 2;
addBox(
scene,
width,
height,
depth,
x,
baseY + height / 2,
z,
"#f2efe5"
);
// Slightly projecting corner blocks give the cuboid a voxel-built edge.
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
addBox(
scene,
0.30,
height,
0.30,
x + sx * (width / 2 - 0.12),
baseY + height / 2,
z + sz * (depth / 2 - 0.12),
"#f8f5eb"
);
}
}
// Roof parapets.
addBox(scene, width + 0.08, 0.42, 0.18, x, top + 0.21, z + depth / 2 - 0.08, "#faf7ee");
addBox(scene, width + 0.08, 0.42, 0.18, x, top + 0.21, z - depth / 2 + 0.08, "#faf7ee");
addBox(scene, 0.18, 0.42, depth, x - width / 2 + 0.08, top + 0.21, z, "#faf7ee");
addBox(scene, 0.18, 0.42, depth, x + width / 2 - 0.08, top + 0.21, z, "#faf7ee");
// Roof utility box and short vent pipe.
addBox(scene, 0.9, 0.55, 0.85, x + 0.55, top + 0.28, z - 0.35, "#e8e3d7");
addBox(scene, 0.18, 0.9, 0.18, x - 0.65, top + 0.45, z + 0.45, "#c8c4b9");
addFrontDoor(doorX, facadeZ, baseY);
addFrontWindow(windowX, facadeZ, baseY + 3.42, 1.0);
// Thin facade courses.
addBox(
scene,
width - 0.4,
0.025,
0.025,
x,
baseY + 2.34,
facadeZ + 0.025,
"#ddd8ca"
);
return { facadeZ, top };
}
// The three compact houses forming the stepped lane.
const leftHouse = addHouse(
-4.75, -1.50, 5.20, 6.20, 5.40, 0.10,
-3.92, -5.78
);
const rightHouse = addHouse(
4.65, -2.00, 4.90, 5.80, 5.60, 0.10,
3.47, 5.52
);
const backHouse = addHouse(
-0.15, -5.18, 4.45, 2.20, 5.75, 0.10,
0.50, -1.28
);
// Lane-facing windows.
addSideWindow(-2.13, -0.65, 3.15, 1);
addSideWindow(-2.13, -3.08, 3.15, 1);
addSideWindow(2.18, -1.52, 3.30, -1);
addSideWindow(2.18, -3.55, 3.30, -1);
// A narrow upper window on the rear house.
addFrontWindow(-0.15, backHouse.facadeZ, 4.60, 0.82);
// Ordinary domestic details.
function addPottedBasil(x, y, z, scale = 1) {
addBox(scene, 0.44 * scale, 0.38 * scale, 0.44 * scale, x, y + 0.19 * scale, z, "#b97855");
addBox(scene, 0.49 * scale, 0.07 * scale, 0.49 * scale, x, y + 0.39 * scale, z, "#9e6047");
addBox(scene, 0.07 * scale, 0.42 * scale, 0.07 * scale, x, y + 0.57 * scale, z, "#507447");
addBox(scene, 0.31 * scale, 0.27 * scale, 0.30 * scale, x - 0.10 * scale, y + 0.66 * scale, z, "#4d7d43");
addBox(scene, 0.26 * scale, 0.24 * scale, 0.29 * scale, x + 0.12 * scale, y + 0.70 * scale, z + 0.03, "#679551");
addBox(scene, 0.25 * scale, 0.22 * scale, 0.25 * scale, x + 0.02 * scale, y + 0.83 * scale, z, "#7aa15c");
}
addPottedBasil(-3.28, 0.1, 1.92, 0.95);
addPottedBasil(3.05, 0.1, 1.25, 0.78);
addPottedBasil(-7.00, 0.1, 2.25, 0.85);
// Wall lamp beside the left doorway.
addBox(scene, 0.11, 0.11, 0.34, -3.14, 2.10, 1.77, "#344b58");
addBox(scene, 0.25, 0.32, 0.25, -3.14, 2.03, 1.96, "#304958");
addBox(scene, 0.17, 0.18, 0.03, -3.14, 2.01, 2.10, "#f1d99b");
// A broom leaning beside a doorway.
const broom = new THREE.Group();
broom.position.set(4.67, 0.1, 1.18);
broom.rotation.z = -0.22;
scene.add(broom);
addBox(broom, 0.055, 1.18, 0.055, 0, 0.72, 0, "#8b6a46");
addBox(broom, 0.34, 0.22, 0.18, 0, 0.12, 0, "#9a744a");
addBox(broom, 0.10, 0.05, 0.10, 0, 1.32, 0, "#274d72");
// A modest bench beside the opening.
addBox(scene, 1.7, 0.15, 0.48, 3.65, 0.68, 2.72, "#356b91");
addBox(scene, 1.7, 0.48, 0.12, 3.65, 1.00, 2.48, "#2d6087");
addBox(scene, 0.16, 0.58, 0.40, 2.95, 0.36, 2.72, "#4e5360");
addBox(scene, 0.16, 0.58, 0.40, 4.35, 0.36, 2.72, "#4e5360");
// A small stack of utility crates, suggesting everyday deliveries.
addBox(scene, 0.78, 0.42, 0.65, 5.52, 0.31, 2.55, "#8d704e");
addBox(scene, 0.72, 0.36, 0.60, 5.50, 0.69, 2.53, "#a58358");
addBox(scene, 0.76, 0.055, 0.64, 5.52, 0.49, 2.55, "#6f583f");
addBox(scene, 0.70, 0.055, 0.59, 5.50, 0.88, 2.53, "#6f583f");
// Pixel-like water glints, placed deterministically.
let seed = 9173;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
const glintColors = ["#74adba", "#89bdc3", "#659eaf"];
for (let i = 0; i < 54; i++) {
const x = -24 + random() * 48;
const z = 5.1 + random() * 31;
const width = 0.35 + random() * 1.7;
addBox(
scene,
width,
0.014,
0.07 + random() * 0.08,
x,
-0.425,
z,
glintColors[i % glintColors.length],
{ castShadow: false, receiveShadow: false }
);
}
// Resident: Yasmine, an original character in ordinary contemporary clothes.
const resident = new THREE.Group();
resident.position.set(0, 1.35, -0.35);
resident.rotation.y = -0.06;
scene.add(resident);
const skin = "#a97152";
const shirt = "#956b60";
const trousers = "#3f514c";
const shoes = "#303638";
const hair = "#302a27";
// Shoes and trouser legs, with one foot placed on the next tread.
addBox(resident, 0.25, 0.22, 0.40, -0.18, 0.12, 0.17, shoes);
addBox(resident, 0.25, 0.22, 0.40, 0.18, 0.12, -0.17, shoes);
addBox(resident, 0.24, 0.55, 0.25, -0.18, 0.47, 0.10, trousers);
addBox(resident, 0.24, 0.55, 0.25, 0.18, 0.47, -0.15, trousers);
// Torso and simple work shirt.
addBox(resident, 0.70, 0.72, 0.40, 0, 1.13, 0.02, shirt);
addBox(resident, 0.74, 0.14, 0.43, 0, 0.83, 0.02, "#856057");
addBox(resident, 0.13, 0.16, 0.05, 0, 1.47, 0.23, "#d7c8ae");
// Head, short hair, and small facial features.
addBox(resident, 0.44, 0.48, 0.42, 0, 1.80, 0.02, skin);
addBox(resident, 0.48, 0.14, 0.46, 0, 2.01, 0.01, hair);
addBox(resident, 0.47, 0.22, 0.12, 0, 1.92, -0.18, hair);
addBox(resident, 0.18, 0.17, 0.09, 0, 1.79, 0.25, skin);
addBox(resident, 0.045, 0.045, 0.025, -0.09, 1.86, 0.235, "#282927");
addBox(resident, 0.045, 0.045, 0.025, 0.09, 1.86, 0.235, "#282927");
addBox(resident, 0.10, 0.025, 0.025, 0, 1.66, 0.235, "#784b42");
// Bent arms hold one basket in each hand.
for (const side of [-1, 1]) {
addBoxBetween(
resident,
[side * 0.37, 1.40, 0.03],
[side * 0.68, 1.05, 0.06],
0.23,
0.23,
shirt
);
addBoxBetween(
resident,
[side * 0.68, 1.05, 0.06],
[side * 0.87, 0.79, 0.10],
0.18,
0.18,
skin
);
addBox(
resident,
0.19,
0.18,
0.19,
side * 0.87,
0.77,
0.10,
skin
);
}
function addBasket(x, z, variant) {
const basket = new THREE.Group();
basket.position.set(x, 0, z);
resident.add(basket);
const wicker = "#a77a46";
const wickerDark = "#7c5938";
// Bottom.
addBox(basket, 0.68, 0.08, 0.54, 0, 0.05, 0, wickerDark);
// Horizontal woven bands.
for (const y of [0.16, 0.31, 0.46]) {
addBox(basket, 0.71, 0.055, 0.57, 0, y, 0, wicker);
}
// Vertical slats on all four sides.
for (let i = 0; i < 5; i++) {
const xx = -0.27 + i * 0.135;
addBox(basket, 0.048, 0.40, 0.06, xx, 0.30, 0.275, wicker);
addBox(basket, 0.048, 0.40, 0.06, xx, 0.30, -0.275, wicker);
}
for (let i = 0; i < 4; i++) {
const zz = -0.18 + i * 0.12;
addBox(basket, 0.06, 0.40, 0.045, 0.335, 0.30, zz, wicker);
addBox(basket, 0.06, 0.40, 0.045, -0.335, 0.30, zz, wicker);
}
// Rectangular woven handle.
addBox(basket, 0.055, 0.36, 0.065, -0.24, 0.64, 0, wickerDark);
addBox(basket, 0.055, 0.36, 0.065, 0.24, 0.64, 0, wickerDark);
addBox(basket, 0.53, 0.065, 0.07, 0, 0.81, 0, wickerDark);
if (variant === 0) {
// Greens and vegetables.
addBox(basket, 0.23, 0.20, 0.23, -0.13, 0.57, 0.02, "#557d42");
addBox(basket, 0.22, 0.19, 0.22, 0.13, 0.57, 0.08, "#6d944e");
addBox(basket, 0.18, 0.16, 0.19, 0.01, 0.65, -0.07, "#86a65d");
addBox(basket, 0.13, 0.13, 0.13, 0.16, 0.64, -0.12, "#bd6244");
} else {
// Wrapped bread, fruit, and a small parcel.
addBox(basket, 0.30, 0.17, 0.23, -0.08, 0.57, 0.02, "#c89455");
addBox(basket, 0.18, 0.17, 0.18, 0.17, 0.56, 0.10, "#d7ad68");
addBox(basket, 0.17, 0.15, 0.17, 0.14, 0.66, -0.10, "#ba5942");
addBox(basket, 0.21, 0.13, 0.16, -0.17, 0.61, -0.14, "#d6c4a0");
}
}
addBasket(-0.87, 0.12, 0);
addBasket( 0.87, 0.12, 1);
// A little life in the lane: clean laundry on a rooftop line.
const laundryLine = addBox(
scene,
3.25,
0.025,
0.025,
-4.75,
5.72,
-3.65,
"#535b5c",
{ castShadow: false }
);
laundryLine.rotation.y = 0.12;
addBox(scene, 0.52, 0.72, 0.045, -5.35, 5.32, -3.55, "#d8d8cd");
addBox(scene, 0.46, 0.61, 0.045, -4.42, 5.39, -3.44, "#8eb0b9");
// Direct camera controls, without importing any addon.
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
view.yaw -= dx * 0.005;
view.pitch = THREE.MathUtils.clamp(
view.pitch + dy * 0.004,
0.20,
1.08
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.zoom = THREE.MathUtils.clamp(
view.zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.85
);
updateCamera();
},
{ passive: false }
);
function resetView() {
Object.assign(view, defaultView);
updateCamera();
}
document.querySelector("#reset").addEventListener("click", resetView);
renderer.domElement.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetView();
}
});
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```