Prompt specification
Build or customize the Three.js 3D scene "Handcart turning into a Balat side lane" 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: Handcart turning into a Balat side lane
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/handcart-turning-into-a-balat-side-lane-x2922
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Balat's hillside streets in Istanbul. Create a compact referenced vignette with handcart, narrow lane, and everyday shopfront. Show the turning path and preserve pedestrian access beside the doorway. Voxel style.
Working Three.js Starter (handcart-turning-into-a-balat-side-lane-x2922):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Balat — Hillside Street Vignette</title>
<style>
:root {
--ink: #243331;
--paper: rgba(247, 240, 219, 0.92);
--turquoise: #38c9bd;
--gold: #e6ae52;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd9d5;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#viewport {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 5;
background: var(--paper);
border: 1px solid rgba(36, 51, 49, 0.14);
box-shadow: 0 12px 36px rgba(33, 47, 44, 0.14);
backdrop-filter: blur(10px);
}
#title-card {
top: 22px;
left: 22px;
width: min(340px, calc(100vw - 44px));
padding: 17px 18px 16px;
border-radius: 4px;
}
.eyebrow {
margin-bottom: 7px;
color: #61716d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 31px;
font-weight: 600;
letter-spacing: -0.025em;
line-height: 1;
}
#title-card p {
margin: 10px 0 14px;
max-width: 29em;
color: #53635f;
font-size: 12px;
line-height: 1.5;
}
.legend {
display: grid;
gap: 8px;
padding-top: 12px;
border-top: 1px solid rgba(36, 51, 49, 0.12);
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
font-size: 11px;
font-weight: 650;
}
.swatch {
width: 24px;
height: 8px;
flex: 0 0 auto;
border-radius: 2px;
}
.swatch.turn {
background: var(--turquoise);
box-shadow: 0 0 0 2px rgba(56, 201, 189, 0.16);
}
.swatch.access {
background: #f3dfaa;
border: 1px solid var(--gold);
}
#controls-card {
right: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
border-radius: 4px;
}
button {
appearance: none;
border: 1px solid rgba(36, 51, 49, 0.17);
border-radius: 3px;
padding: 8px 10px;
background: #fffdf4;
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
}
button:hover {
background: #f1e9d4;
}
#hint {
color: #65736f;
font-size: 10px;
white-space: nowrap;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #cbd9d5;
color: #43534f;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 680px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 14px;
}
h1 {
font-size: 25px;
}
#title-card p {
display: none;
}
.legend {
padding-top: 9px;
}
#controls-card {
right: 12px;
bottom: 12px;
}
#hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="viewport" aria-label="Interactive voxel model of a Balat hillside street"></canvas>
<section id="title-card" class="panel">
<div class="eyebrow">Istanbul · Compact streetscape study</div>
<h1>Balat Hillside</h1>
<p>
A stepped lane, painted masonry, a working handcart, and a small everyday
shop. The turquoise sweep indicates the handcart’s turning route; the pale
pavers preserve a pedestrian approach beside the doorway.
</p>
<div class="legend" aria-label="Scene legend">
<div class="legend-row">
<span class="swatch turn"></span>
<span>Handcart turning sweep</span>
</div>
<div class="legend-row">
<span class="swatch access"></span>
<span>Clear pedestrian access</span>
</div>
</div>
</section>
<section id="controls-card" class="panel">
<button id="toggle-path" type="button" aria-pressed="true">Hide route</button>
<button id="reset-view" type="button">Reset view</button>
<span id="hint">Drag to orbit · Scroll to zoom</span>
</section>
<div id="loading">Building Balat…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#viewport");
const loading = document.querySelector("#loading");
const pathToggle = document.querySelector("#toggle-path");
const resetViewButton = document.querySelector("#reset-view");
// ---------------------------------------------------------------------
// Renderer, scene and camera
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#cbd9d5");
scene.fog = new THREE.Fog("#cbd9d5", 35, 70);
const camera = new THREE.OrthographicCamera(-10, 10, 8, -8, 0.1, 100);
const cameraState = {
target: new THREE.Vector3(0, 2.15, 0),
yaw: 0.66,
pitch: 0.69,
radius: 28,
zoom: 1
};
function updateCamera() {
const { target, yaw, pitch, radius } = cameraState;
const horizontal = Math.cos(pitch) * radius;
camera.position.set(
target.x + Math.sin(yaw) * horizontal,
target.y + Math.sin(pitch) * radius,
target.z + Math.cos(yaw) * horizontal
);
camera.lookAt(target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(15.6, 19.5 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
renderer.setSize(width, height, false);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
// ---------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight("#fff4d6", "#6d8179", 2.2);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff0cf", 3.5);
sun.position.set(-10, 18, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 50;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b8d8d4", 1.15);
fill.position.set(10, 8, -10);
scene.add(fill);
// ---------------------------------------------------------------------
// Small 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.02
})
);
}
return materialCache.get(color);
}
const boxGeometry = new THREE.BoxGeometry(1, 1, 1);
function box(parent, width, height, depth, x, y, z, color, castShadow = true) {
const mesh = new THREE.Mesh(boxGeometry, material(color));
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function groundY(z) {
const row = THREE.MathUtils.clamp(Math.floor((8 - z) / 1), 0, 16);
return row * 0.105;
}
function laneCenter(z) {
if (z >= 2) {
return THREE.MathUtils.lerp(-0.82, 0, (z - 2) / 6);
}
return THREE.MathUtils.lerp(0, 0.72, (2 - z) / 10);
}
let randomSeed = 72831;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function choose(items) {
return items[Math.floor(random() * items.length)];
}
const sceneRoot = new THREE.Group();
scene.add(sceneRoot);
// ---------------------------------------------------------------------
// Base and stepped cobbled lane
// ---------------------------------------------------------------------
const shadowFloor = new THREE.Mesh(
new THREE.PlaneGeometry(120, 120),
new THREE.MeshStandardMaterial({ color: "#c6d4d0", roughness: 1 })
);
shadowFloor.rotation.x = -Math.PI / 2;
shadowFloor.position.y = -1.73;
shadowFloor.receiveShadow = true;
scene.add(shadowFloor);
box(sceneRoot, 17.5, 1.25, 17.5, 0, -1.02, 0, "#65736e");
box(sceneRoot, 17.75, 0.12, 17.75, 0, -0.34, 0, "#87908a");
const cobbleColors = [
"#89918a",
"#9a9d94",
"#7f8983",
"#a3a298",
"#92958c",
"#b0aa9b"
];
const curbColors = ["#c2b9a5", "#aaa592", "#d0c4ae"];
for (let row = 0; row < 16; row++) {
const z = 7.5 - row;
const top = row * 0.105;
const centerX = laneCenter(z);
// Lane foundation.
box(sceneRoot, 5.45, 0.18, 1.015, centerX, top - 0.09, z, "#777f79");
// Stepped side ground.
for (const side of [-1, 1]) {
const inner = centerX + side * 2.72;
const outer = side * 8.25;
const width = Math.abs(outer - inner);
const middle = (inner + outer) / 2;
const height = top + 0.34;
box(
sceneRoot,
width,
height,
1.015,
middle,
top - height / 2,
z,
side < 0 ? "#879087" : "#89908a"
);
box(
sceneRoot,
0.16,
top + 0.56,
1.01,
side * 8.25,
top - (top + 0.56) / 2 + 0.08,
z,
choose(["#747d77", "#818981", "#6e7772"])
);
}
// Raised edge stones.
for (const side of [-1, 1]) {
box(
sceneRoot,
0.23,
0.16,
0.98,
centerX + side * 2.66,
top + 0.08,
z,
choose(curbColors)
);
}
// Individual voxel cobbles, arranged in two rows per terrace.
for (let sub = 0; sub < 2; sub++) {
const cobbleZ = z + (sub === 0 ? -0.25 : 0.25);
for (let column = 0; column < 6; column++) {
const offset = -2.13 + column * 0.85;
const cobble = box(
sceneRoot,
0.73 + random() * 0.08,
0.085 + random() * 0.018,
0.42,
centerX + offset + (random() - 0.5) * 0.04,
top + 0.045,
cobbleZ,
choose(cobbleColors),
false
);
cobble.rotation.y = (random() - 0.5) * 0.075;
}
}
}
// ---------------------------------------------------------------------
// Building details
// ---------------------------------------------------------------------
function steppedRoof(parent, x, z, width, depth, baseY, color = "#ad5845") {
for (let layer = 0; layer < 4; layer++) {
box(
parent,
width + 0.52 - layer * 0.38,
0.22,
depth + 0.52 - layer * 0.34,
x,
baseY + 0.12 + layer * 0.205,
z,
color
);
}
box(
parent,
0.42,
0.25,
depth + 0.22,
x,
baseY + 0.87,
z,
"#8f4739"
);
}
function frontWindow(parent, x, y, z, width = 1.12, height = 1.35, shutters = "#557c73") {
box(parent, width, height, 0.11, x, y, z, "#294847");
box(parent, width + 0.18, 0.11, 0.16, x, y + height / 2, z + 0.025, "#eee3c7");
box(parent, width + 0.18, 0.11, 0.16, x, y - height / 2, z + 0.025, "#eee3c7");
box(parent, 0.1, height + 0.15, 0.16, x - width / 2, y, z + 0.025, "#eee3c7");
box(parent, 0.1, height + 0.15, 0.16, x + width / 2, y, z + 0.025, "#eee3c7");
if (shutters) {
box(parent, width * 0.36, height * 0.94, 0.13, x - width * 0.69, y, z + 0.04, shutters);
box(parent, width * 0.36, height * 0.94, 0.13, x + width * 0.69, y, z + 0.04, shutters);
}
}
function sideWindow(parent, x, y, z, width = 1.12, height = 1.35, shutters = "#557c73") {
box(parent, 0.11, height, width, x, y, z, "#294847");
box(parent, 0.16, 0.11, width + 0.18, x + 0.025, y + height / 2, z, "#eee3c7");
box(parent, 0.16, 0.11, width + 0.18, x + 0.025, y - height / 2, z, "#eee3c7");
box(parent, 0.16, height + 0.15, 0.1, x + 0.025, y, z - width / 2, "#eee3c7");
box(parent, 0.16, height + 0.15, 0.1, x + 0.025, y, z + width / 2, "#eee3c7");
if (shutters) {
box(parent, 0.13, height * 0.94, width * 0.36, x + 0.04, y, z - width * 0.69, shutters);
box(parent, 0.13, height * 0.94, width * 0.36, x + 0.04, y, z + width * 0.69, shutters);
}
}
function addBalcony(parent, x, y, z, length = 2.2, direction = 1) {
const outerX = x + direction * 0.7;
box(parent, 0.92, 0.17, length, outerX - direction * 0.3, y, z, "#dfd0ae");
box(parent, 0.08, 0.09, length + 0.12, outerX, y + 0.76, z, "#496b64");
box(parent, 0.08, 0.09, 0.09, outerX, y + 0.76, z - length / 2, "#496b64");
box(parent, 0.08, 0.09, 0.09, outerX, y + 0.76, z + length / 2, "#496b64");
for (const end of [-1, 1]) {
box(parent, 0.65, 0.08, 0.08, outerX - direction * 0.32, y + 0.76, z + end * length / 2, "#496b64");
}
for (let i = 0; i < 5; i++) {
box(
parent,
0.07,
0.69,
0.07,
outerX,
y + 0.39,
z - length * 0.42 + i * length * 0.21,
"#496b64"
);
}
}
// Left foreground house.
const leftFront = new THREE.Group();
sceneRoot.add(leftFront);
const leftFrontX = -5.25;
const leftFrontZ = 3.35;
const leftFrontWidth = 4.7;
const leftFrontDepth = 7.2;
const leftFrontHeight = 5.35;
box(leftFront, leftFrontWidth, leftFrontHeight, leftFrontDepth, leftFrontX, 2.76, leftFrontZ, "#bd704e");
box(leftFront, leftFrontWidth + 0.12, 0.22, leftFrontDepth + 0.1, leftFrontX, 0.11, leftFrontZ, "#d9b681");
steppedRoof(leftFront, leftFrontX, leftFrontZ, leftFrontWidth, leftFrontDepth, 5.43, "#a85140");
sideWindow(leftFront, -2.87, 2.15, 4.95, 1.05, 1.28, "#557d72");
sideWindow(leftFront, -2.87, 2.15, 2.35, 1.05, 1.28, "#557d72");
sideWindow(leftFront, -2.87, 4.28, 3.65, 1.0, 1.15, "#557d72");
addBalcony(leftFront, -2.88, 3.13, 3.65, 2.05, 1);
box(leftFront, 0.12, 2.18, 0.98, -2.84, 1.22, 0.45, "#284846");
box(leftFront, 0.18, 2.38, 1.14, -2.79, 1.27, 0.45, "#e6d3ad");
box(leftFront, 0.18, 0.12, 1.15, -2.73, 2.47, 0.45, "#e6d3ad");
box(leftFront, 0.2, 0.1, 0.1, -2.67, 1.2, 0.62, "#d5ad65");
box(leftFront, 0.62, 1.08, 0.66, -4.1, 5.78, 1.25, "#dfc3a2");
box(leftFront, 0.78, 0.17, 0.82, -4.1, 6.34, 1.25, "#8b4639");
// Left rear, taller painted house.
const leftBack = new THREE.Group();
sceneRoot.add(leftBack);
const leftBackX = -5.25;
const leftBackZ = -4.25;
const leftBackWidth = 4.8;
const leftBackDepth = 6.5;
const leftBackHeight = 6.35;
box(leftBack, leftBackWidth, leftBackHeight, leftBackDepth, leftBackX, 4.0, leftBackZ, "#4f8c87");
box(leftBack, leftBackWidth + 0.12, 0.25, leftBackDepth + 0.1, leftBackX, 0.84, leftBackZ, "#dfd0ac");
steppedRoof(leftBack, leftBackX, leftBackZ, leftBackWidth, leftBackDepth, 7.17, "#9c4f40");
sideWindow(leftBack, -2.82, 2.2, -5.25, 1.08, 1.36, "#bb684b");
sideWindow(leftBack, -2.82, 4.45, -5.25, 1.08, 1.36, "#bb684b");
sideWindow(leftBack, -2.82, 2.2, -2.9, 1.08, 1.36, "#bb684b");
sideWindow(leftBack, -2.82, 4.45, -2.9, 1.08, 1.36, "#bb684b");
addBalcony(leftBack, -2.82, 3.36, -2.9, 2.0, 1);
box(leftBack, 1.32, 0.18, 0.42, -5.2, 6.56, -0.91, "#eeddb9");
// Right rear house.
const rightBack = new THREE.Group();
sceneRoot.add(rightBack);
const rightBackX = 4.75;
const rightBackZ = -3.55;
const rightBackWidth = 5.1;
const rightBackDepth = 6.7;
const rightBackHeight = 6.05;
box(rightBack, rightBackWidth, rightBackHeight, rightBackDepth, rightBackX, 3.86, rightBackZ, "#c76059");
box(rightBack, rightBackWidth + 0.12, 0.23, rightBackDepth + 0.1, rightBackX, 0.85, rightBackZ, "#e7d8b5");
steppedRoof(rightBack, rightBackX, rightBackZ, rightBackWidth, rightBackDepth, 6.88, "#97473c");
frontWindow(rightBack, 3.1, 2.3, -0.16, 1.08, 1.32, "#497a71");
frontWindow(rightBack, 5.1, 2.3, -0.16, 1.08, 1.32, "#497a71");
frontWindow(rightBack, 4.1, 4.55, -0.16, 1.05, 1.18, "#497a71");
box(rightBack, 0.56, 1.0, 0.58, 6.2, 7.32, -5.2, "#d9c1a1");
box(rightBack, 0.72, 0.16, 0.74, 6.2, 7.86, -5.2, "#874238");
// Shop and everyday frontage.
const shop = new THREE.Group();
sceneRoot.add(shop);
const shopX = 4.6;
const shopZ = 3.5;
const shopWidth = 5.0;
const shopDepth = 7.0;
const shopHeight = 4.6;
box(shop, shopWidth, shopHeight, shopDepth, shopX, 2.38, shopZ, "#dfbd72");
box(shop, shopWidth + 0.1, 0.22, shopDepth + 0.08, shopX, 0.1, shopZ, "#e8d6ae");
steppedRoof(shop, shopX, shopZ, shopWidth, shopDepth, 4.68, "#a85643");
// Green lower shopfront.
box(shop, 4.96, 1.02, 0.11, shopX, 0.67, 7.055, "#416c60");
// Doorway, deliberately kept separate from the cart and turning route.
box(shop, 1.37, 2.42, 0.15, 3.25, 1.33, 7.08, "#e5d5b4");
box(shop, 1.11, 2.18, 0.18, 3.25, 1.26, 7.14, "#344c45");
box(shop, 0.06, 0.92, 0.07, 3.52, 1.26, 7.25, "#78948a");
box(shop, 0.08, 0.1, 0.1, 3.53, 1.15, 7.29, "#d4a75c");
box(shop, 1.48, 0.18, 0.55, 3.25, 0.12, 7.24, "#b9ad94");
// Shop window.
box(shop, 1.75, 1.66, 0.12, 5.38, 1.95, 7.08, "#e8d8b5");
box(shop, 1.53, 1.43, 0.15, 5.38, 1.95, 7.14, "#284847");
box(shop, 0.08, 1.43, 0.08, 5.38, 1.95, 7.23, "#769087");
box(shop, 1.53, 0.08, 0.08, 5.38, 1.95, 7.23, "#769087");
// Striped voxel awning.
for (let i = 0; i < 8; i++) {
box(
shop,
0.62,
0.18,
1.16,
2.66 + i * 0.62,
3.08,
7.58,
i % 2 === 0 ? "#f1e1bd" : "#4f786c"
);
}
box(shop, 5.12, 0.18, 0.18, shopX, 3.0, 8.12, "#36584f");
function textPanel(parent, text, subline, width, height, x, y, z) {
const textCanvas = document.createElement("canvas");
textCanvas.width = 512;
textCanvas.height = 160;
const context = textCanvas.getContext("2d");
context.fillStyle = "#315b52";
context.fillRect(0, 0, 512, 160);
context.strokeStyle = "#e6d6b0";
context.lineWidth = 8;
context.strokeRect(8, 8, 496, 144);
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = "#f4e6c6";
context.font = "bold 70px Georgia";
context.fillText(text, 256, 68);
context.fillStyle = "#e6d6b0";
context.font = "bold 24px sans-serif";
context.fillText(subline, 256, 124);
const texture = new THREE.CanvasTexture(textCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const panelMaterial = new THREE.MeshBasicMaterial({ map: texture });
const panel = new THREE.Mesh(new THREE.PlaneGeometry(width, height), panelMaterial);
panel.position.set(x, y, z);
parent.add(panel);
return panel;
}
textPanel(shop, "BALAT", "MARKET · EVERY DAY", 2.62, 0.81, 4.73, 4.12, 7.065);
textPanel(shop, "TEA", "LOCAL", 0.9, 0.45, 2.25, 3.55, 7.07);
// Small wall lamp.
box(shop, 0.12, 0.12, 0.42, 4.15, 3.03, 7.26, "#344842");
box(shop, 0.38, 0.46, 0.38, 4.15, 2.77, 7.45, "#d9b76b");
const lampGlow = new THREE.Mesh(
new THREE.BoxGeometry(0.24, 0.28, 0.05),
new THREE.MeshStandardMaterial({
color: "#ffe5a1",
emissive: "#ffbd56",
emissiveIntensity: 1.6
})
);
lampGlow.position.set(4.15, 2.77, 7.67);
shop.add(lampGlow);
// ---------------------------------------------------------------------
// Laundry line and small urban details
// ---------------------------------------------------------------------
box(sceneRoot, 5.75, 0.055, 0.055, -0.15, 6.56, -1.35, "#46514b");
const clothColors = ["#e5c56e", "#d47d64", "#e9dfc6", "#6e9b91"];
for (let i = 0; i < 4; i++) {
box(
sceneRoot,
0.44,
0.62 + (i % 2) * 0.13,
0.07,
-1.75 + i * 0.9,
6.16,
-1.35,
clothColors[i]
);
}
const bulbMaterial = new THREE.MeshStandardMaterial({
color: "#ffe1a0",
emissive: "#ffc66c",
emissiveIntensity: 1.35,
roughness: 0.45
});
for (let i = 0; i < 7; i++) {
const bulb = box(sceneRoot, 0.11, 0.15, 0.11, -2.2 + i * 0.68, 6.42, -1.35, bulbMaterial, false);
bulb.castShadow = false;
}
function pottedPlant(parent, x, y, z, scale = 1) {
box(parent, 0.42 * scale, 0.42 * scale, 0.42 * scale, x, y + 0.21 * scale, z, "#ae654c");
box(parent, 0.28 * scale, 0.34 * scale, 0.28 * scale, x, y + 0.53 * scale, z, "#477761");
box(parent, 0.32 * scale, 0.25 * scale, 0.32 * scale, x + 0.12 * scale, y + 0.76 * scale, z - 0.03, "#5d896c");
box(parent, 0.22 * scale, 0.23 * scale, 0.22 * scale, x - 0.1 * scale, y + 0.75 * scale, z + 0.08, "#769b70");
}
pottedPlant(sceneRoot, 6.55, groundY(6.1), 6.1, 0.9);
pottedPlant(sceneRoot, -2.2, groundY(5.7), 5.7, 0.72);
// Produce crates beside the shop.
function crate(parent, x, y, z, color) {
box(parent, 0.65, 0.12, 0.6, x, y + 0.06, z, "#92613f");
box(parent, 0.65, 0.36, 0.09, x, y + 0.25, z - 0.255, color);
box(parent, 0.65, 0.36, 0.09, x, y + 0.25, z + 0.255, color);
box(parent, 0.09, 0.36, 0.6, x - 0.28, y + 0.25, z, color);
box(parent, 0.09, 0.36, 0.6, x + 0.28, y + 0.25, z, color);
}
crate(shop, 6.23, groundY(6.8), 6.8, "#b27843");
crate(shop, 6.25, groundY(6.8) + 0.35, 6.8, "#a66c3e");
for (let i = 0; i < 8; i++) {
box(
shop,
0.15,
0.15,
0.15,
6.04 + (i % 4) * 0.14,
groundY(6.8) + 0.55,
6.66 + Math.floor(i / 4) * 0.18,
i % 3 === 0 ? "#c8a34d" : "#b75f42"
);
}
// ---------------------------------------------------------------------
// Voxel handcart, parked beside the wall and outside the route
// ---------------------------------------------------------------------
const cart = new THREE.Group();
cart.position.set(-2.33, groundY(3.35), 3.35);
cart.rotation.y = -0.12;
sceneRoot.add(cart);
// Cart bed and side rails.
box(cart, 1.48, 0.17, 1.68, 0, 0.86, -0.22, "#9a633d");
box(cart, 0.12, 0.53, 1.72, -0.69, 1.12, -0.22, "#b77a48");
box(cart, 0.12, 0.53, 1.72, 0.69, 1.12, -0.22, "#b77a48");
box(cart, 1.48, 0.53, 0.12, 0, 1.12, -1.02, "#b77a48");
// Axle.
box(cart, 1.94, 0.13, 0.13, 0, 0.51, -0.48, "#4b4036");
// Block-built wheels.
for (const side of [-1, 1]) {
const wheelCenterX = side * 0.88;
const wheelCenterY = 0.5;
const wheelCenterZ = -0.48;
for (let i = 0; i < 10; i++) {
const angle = (i / 10) * Math.PI * 2;
const block = box(
cart,
0.19,
0.2,
0.26,
wheelCenterX,
wheelCenterY + Math.sin(angle) * 0.43,
wheelCenterZ + Math.cos(angle) * 0.43,
"#4b4036"
);
block.rotation.x = angle;
}
box(cart, 0.13, 0.78, 0.1, wheelCenterX, wheelCenterY, wheelCenterZ, "#806043");
box(cart, 0.13, 0.1, 0.78, wheelCenterX, wheelCenterY, wheelCenterZ, "#806043");
box(cart, 0.22, 0.22, 0.22, wheelCenterX, wheelCenterY, wheelCenterZ, "#b08352");
}
// Handles.
box(cart, 0.12, 0.13, 2.35, -0.48, 0.75, 0.93, "#9b633d");
box(cart, 0.12, 0.13, 2.35, 0.48, 0.75, 0.93, "#9b633d");
box(cart, 0.13, 0.13, 0.46, -0.48, 0.75, 2.02, "#513f33");
box(cart, 0.13, 0.13, 0.46, 0.48, 0.75, 2.02, "#513f33");
// Sacks and boxes in the cart.
box(cart, 0.68, 0.58, 0.68, -0.28, 1.24, -0.42, "#c7b58e");
box(cart, 0.58, 0.52, 0.64, 0.3, 1.2, -0.4, "#b9aa84");
box(cart, 0.55, 0.42, 0.56, 0.18, 1.63, -0.43, "#8d6845");
box(cart, 0.12, 0.13, 0.12, -0.27, 1.58, -0.42, "#8b543d");
// ---------------------------------------------------------------------
// Turning route and clear pedestrian access
// ---------------------------------------------------------------------
const routeGroup = new THREE.Group();
sceneRoot.add(routeGroup);
const routeMaterial = new THREE.MeshStandardMaterial({
color: "#36cbbd",
emissive: "#0f8e86",
emissiveIntensity: 0.75,
roughness: 0.55
});
const routePoints = [
new THREE.Vector3(-1.08, 0, 8.35),
new THREE.Vector3(-0.98, 0, 6.65),
new THREE.Vector3(-1.08, 0, 5.45),
new THREE.Vector3(-0.65, 0, 4.45),
new THREE.Vector3(0.15, 0, 3.0),
new THREE.Vector3(0.66, 0, 1.35),
new THREE.Vector3(0.46, 0, -0.65),
new THREE.Vector3(0.72, 0, -2.65),
new THREE.Vector3(1.04, 0, -5.2)
];
const routeCurve = new THREE.CatmullRomCurve3(routePoints, false, "catmullrom", 0.32);
const dashCount = 48;
for (let i = 0; i < dashCount; i++) {
const t = i / (dashCount - 1);
const point = routeCurve.getPointAt(t);
const tangent = routeCurve.getTangentAt(t);
const angle = Math.atan2(tangent.x, tangent.z);
const dash = box(
routeGroup,
0.16,
0.055,
0.46,
point.x,
groundY(point.z) + 0.145,
point.z,
routeMaterial,
false
);
dash.rotation.y = angle;
dash.castShadow = false;
}
// Small directional chevrons clarify the turn.
for (const t of [0.19, 0.43, 0.72]) {
const point = routeCurve.getPointAt(t);
const tangent = routeCurve.getTangentAt(t);
const angle = Math.atan2(tangent.x, tangent.z);
const arrow = new THREE.Group();
arrow.position.set(point.x, groundY(point.z) + 0.19, point.z);
arrow.rotation.y = angle;
routeGroup.add(arrow);
const left = box(arrow, 0.075, 0.05, 0.4, -0.105, 0, 0.07, routeMaterial, false);
const right = box(arrow, 0.075, 0.05, 0.4, 0.105, 0, 0.07, routeMaterial, false);
left.rotation.y = -0.55;
right.rotation.y = 0.55;
}
// Pale paver field immediately beside the shop doorway.
const accessGroup = new THREE.Group();
sceneRoot.add(accessGroup);
const paverColors = ["#eee0b8", "#e5d5aa", "#f2e5c0", "#dfcf9f"];
const paverXs = [1.95, 2.5, 3.05, 3.6];
const paverZs = [5.62, 6.12, 6.62];
for (let row = 0; row < paverZs.length; row++) {
for (let column = 0; column < paverXs.length; column++) {
box(
accessGroup,
0.49,
0.09,
0.44,
paverXs[column],
groundY(paverZs[row]) + 0.13,
paverZs[row],
paverColors[(row + column) % paverColors.length],
false
);
}
}
// Gold border markers define the pedestrian-clear zone without blocking it.
const accessMarker = "#d59a43";
const markerXs = [1.69, 3.85];
const markerZs = [5.35, 6.91];
for (const x of markerXs) {
for (const z of markerZs) {
box(
accessGroup,
0.12,
0.12,
0.12,
x,
groundY(z) + 0.17,
z,
accessMarker,
false
);
}
}
// A single low guide mark points from the lane to the clear doorway approach.
const approach = box(
accessGroup,
0.11,
0.055,
0.55,
2.62,
groundY(6.05) + 0.17,
6.03,
accessMarker,
false
);
approach.rotation.y = 0.32;
// ---------------------------------------------------------------------
// Direct camera controls — no addons or external controls library
// ---------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.yaw -= deltaX * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + deltaY * 0.004,
0.34,
1.18
);
updateCamera();
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * (event.deltaY > 0 ? 0.9 : 1.1),
0.72,
1.85
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") cameraState.yaw += 0.08;
if (event.key === "ArrowRight") cameraState.yaw -= 0.08;
if (event.key === "ArrowUp") cameraState.pitch = Math.min(1.18, cameraState.pitch + 0.05);
if (event.key === "ArrowDown") cameraState.pitch = Math.max(0.34, cameraState.pitch - 0.05);
if (event.key === "+" || event.key === "=") cameraState.zoom = Math.min(1.85, cameraState.zoom + 0.08);
if (event.key === "-") cameraState.zoom = Math.max(0.72, cameraState.zoom - 0.08);
updateCamera();
});
function resetView() {
cameraState.yaw = 0.66;
cameraState.pitch = 0.69;
cameraState.radius = 28;
cameraState.zoom = 1;
cameraState.target.set(0, 2.15, 0);
updateCamera();
}
resetViewButton.addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
pathToggle.addEventListener("click", () => {
routeGroup.visible = !routeGroup.visible;
const visible = routeGroup.visible;
pathToggle.textContent = visible ? "Hide route" : "Show route";
pathToggle.setAttribute("aria-pressed", String(visible));
});
// A gentle initial reveal.
renderer.render(scene, camera);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 350);
});
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```