Prompt specification
Build or customize the Three.js 3D scene "Rearrange storefront displays along a narrow shopping street" 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: Rearrange storefront displays along a narrow shopping street
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/rearrange-storefront-displays-along-a-narrow-shopping-x3040
Scene Description Prompt:
Rearrange fictional voxel shop displays along a narrow Tokyo Yanaka street while keeping entrances and pedestrian routes open. Three.js from cdnjs, one HTML file.
Working Three.js Starter (rearrange-storefront-displays-along-a-narrow-shopping-x3040):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Yanaka — Small Street, Open Doors</title>
<style>
:root {
--ink: #24312f;
--muted: #65706c;
--paper: rgba(250, 247, 238, 0.91);
--line: rgba(48, 63, 58, 0.16);
--green: #477565;
--amber: #c47a3b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #bdd7da;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
top: 22px;
left: 22px;
width: min(380px, calc(100vw - 44px));
padding: 22px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 20px;
background: var(--paper);
box-shadow:
0 18px 50px rgba(42, 54, 50, 0.16),
inset 0 0 0 1px rgba(61, 77, 70, 0.06);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
user-select: none;
}
.kicker {
margin-bottom: 9px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 48px);
font-weight: 760;
line-height: 0.96;
letter-spacing: -0.055em;
}
.intro {
margin: 15px 0 18px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-bottom: 16px;
}
.stat {
padding: 10px 8px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.42);
}
.stat strong,
.stat span {
display: block;
}
.stat strong {
margin-bottom: 3px;
font-size: 15px;
letter-spacing: -0.02em;
}
.stat span {
color: var(--muted);
font-size: 9px;
line-height: 1.25;
text-transform: uppercase;
letter-spacing: 0.06em;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin: 0 0 16px;
color: var(--muted);
font-size: 10px;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 3px;
}
.swatch.route {
background: #d9c9a8;
border: 1px solid #b49d72;
}
.swatch.display {
background: var(--amber);
}
.swatch.entry {
background: var(--green);
}
button {
appearance: none;
border: 0;
border-radius: 11px;
padding: 11px 14px;
background: var(--ink);
color: #fffdf5;
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.03em;
cursor: pointer;
transition:
transform 150ms ease,
background 150ms ease,
opacity 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: #39534b;
}
button:active {
transform: translateY(0);
}
button:focus-visible {
outline: 3px solid rgba(71, 117, 101, 0.35);
outline-offset: 2px;
}
#shuffle {
width: 100%;
background: var(--green);
}
.selection {
margin-top: 12px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.selection-label {
color: var(--amber);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#selection-title {
margin: 5px 0 4px;
font-size: 16px;
font-weight: 750;
letter-spacing: -0.02em;
}
#selection-copy {
min-height: 34px;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.viewbar {
position: fixed;
z-index: 10;
right: 22px;
bottom: 22px;
display: flex;
gap: 7px;
padding: 7px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 15px;
background: rgba(250, 247, 238, 0.86);
box-shadow: 0 12px 34px rgba(42, 54, 50, 0.14);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.viewbar button {
background: transparent;
color: var(--ink);
padding: 10px 13px;
}
.viewbar button:hover,
.viewbar button.active {
background: var(--ink);
color: #fffdf5;
}
.hint {
position: fixed;
z-index: 9;
right: 22px;
top: 22px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 11px;
background: rgba(250, 247, 238, 0.72);
color: rgba(36, 49, 47, 0.68);
font-size: 10px;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
pointer-events: none;
}
#toast {
position: fixed;
z-index: 20;
left: 50%;
bottom: 86px;
transform: translate(-50%, 12px);
padding: 10px 15px;
border-radius: 999px;
background: rgba(36, 49, 47, 0.92);
color: #fffdf5;
font-size: 11px;
opacity: 0;
pointer-events: none;
transition:
opacity 180ms ease,
transform 180ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 700px) {
.panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 17px;
}
h1 {
font-size: 31px;
}
.intro {
margin: 10px 0 13px;
font-size: 11px;
}
.stats {
margin-bottom: 12px;
}
.selection,
.hint {
display: none;
}
.viewbar {
right: 12px;
bottom: 12px;
left: 12px;
justify-content: center;
}
.viewbar button {
flex: 1;
padding: 10px 7px;
font-size: 10px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel shopping street"></canvas>
<section class="panel">
<div class="kicker">Yanaka / Walkable retail study</div>
<h1>Small Street,<br />Open Doors</h1>
<p class="intro">
Ten fictional neighborhood shops arranged around a protected 2.4 m
pedestrian spine. Window displays can be rearranged without moving
entrances or blocking circulation.
</p>
<div class="stats">
<div class="stat">
<strong>2.4 m</strong>
<span>Clear route</span>
</div>
<div class="stat">
<strong>10</strong>
<span>Shop bays</span>
</div>
<div class="stat">
<strong>0</strong>
<span>Route blockers</span>
</div>
</div>
<div class="legend">
<span><i class="swatch route"></i>Pedestrian route</span>
<span><i class="swatch display"></i>Display bay</span>
<span><i class="swatch entry"></i>Open entry</span>
</div>
<button id="shuffle" type="button">Re-layout window displays</button>
<div class="selection" aria-live="polite">
<div class="selection-label">Shop finder</div>
<div id="selection-title">Select a storefront</div>
<div id="selection-copy">
Click any shop to inspect its fictional concept and circulation notes.
</div>
</div>
</section>
<div class="hint">Drag to look · Wheel to zoom · Shift-drag to pan · Click a shop</div>
<nav class="viewbar" aria-label="Camera views">
<button type="button" data-view="overview" class="active">Overview</button>
<button type="button" data-view="walk">Street view</button>
<button type="button" data-view="route">Route plan</button>
</nav>
<div id="toast" role="status"></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("#scene");
const shuffleButton = document.querySelector("#shuffle");
const selectionTitle = document.querySelector("#selection-title");
const selectionCopy = document.querySelector("#selection-copy");
const toast = document.querySelector("#toast");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xbdd7da);
scene.fog = new THREE.Fog(0xbdd7da, 20, 44);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
90
);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.13;
const hemisphere = new THREE.HemisphereLight(0xeaf7ff, 0x746a5c, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffefd2, 3.1);
sun.position.set(-9, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 20;
sun.shadow.camera.bottom = -20;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.0007;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc8e7ff, 0.7);
fill.position.set(8, 7, -12);
scene.add(fill);
const materialCache = new Map();
function material(color, options = {}) {
const key = `${color}-${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.0,
...options
})
);
}
return materialCache.get(key);
}
function addBox(parent, size, position, mat, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function mulberry32(seed) {
return function random() {
let t = (seed += 0x6d2b79f5);
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function makeSignTexture(name, japanese, background, foreground) {
const signCanvas = document.createElement("canvas");
signCanvas.width = 1024;
signCanvas.height = 256;
const context = signCanvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, 1024, 256);
context.strokeStyle = foreground;
context.lineWidth = 10;
context.strokeRect(14, 14, 996, 228);
context.fillStyle = foreground;
context.textAlign = "center";
context.textBaseline = "middle";
context.font = `800 ${name.length > 13 ? 65 : 76}px Arial, sans-serif`;
context.fillText(name, 512, 102);
context.globalAlpha = 0.88;
context.font = '500 38px "Yu Gothic", "Hiragino Kaku Gothic ProN", sans-serif';
context.fillText(japanese, 512, 182);
context.globalAlpha = 1;
const texture = new THREE.CanvasTexture(signCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function makeLabelTexture(text, background, foreground) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 384;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, 384, 128);
context.strokeStyle = foreground;
context.lineWidth = 8;
context.strokeRect(8, 8, 368, 112);
context.fillStyle = foreground;
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "800 50px Arial, sans-serif";
context.fillText(text, 192, 66);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
function makeSignPlane(name, japanese, background, foreground, width, height) {
return new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: makeSignTexture(name, japanese, background, foreground),
side: THREE.DoubleSide
})
);
}
function makeLabelPlane(text, background, foreground, width, height) {
return new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: makeLabelTexture(text, background, foreground),
side: THREE.DoubleSide
})
);
}
// Street paving: a subtly lighter central pedestrian route.
const streetBase = addBox(
scene,
[6.9, 0.16, 29.4],
[0, -0.13, 0],
material(0x777a72),
false
);
streetBase.receiveShadow = true;
const columns = 14;
const rows = 58;
const tileGeometry = new THREE.BoxGeometry(0.49, 0.075, 0.49);
const tileMaterial = material(0xffffff, { roughness: 1 });
const paving = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
columns * rows
);
const matrix = new THREE.Matrix4();
const quaternion = new THREE.Quaternion();
const scale = new THREE.Vector3(1, 1, 1);
const tileColor = new THREE.Color();
const initialRandom = mulberry32(1908);
let tileIndex = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const x = -3.25 + column * 0.5;
const z = -14.25 + row * 0.5;
const isRoute = Math.abs(x) < 1.05;
matrix.compose(
new THREE.Vector3(x, -0.025, z),
quaternion,
scale
);
paving.setMatrixAt(tileIndex, matrix);
const variation = (initialRandom() - 0.5) * 0.1;
if (isRoute) {
tileColor.setHSL(0.105, 0.17, 0.71 + variation);
} else {
tileColor.setHSL(0.12, 0.035, 0.48 + variation);
}
paving.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
paving.instanceMatrix.needsUpdate = true;
if (paving.instanceColor) paving.instanceColor.needsUpdate = true;
paving.receiveShadow = true;
scene.add(paving);
// Brass-edged route boundary. These are flush inlays, not obstacles.
for (const side of [-1, 1]) {
addBox(
scene,
[0.055, 0.018, 29.1],
[side * 1.22, 0.035, 0],
material(0xb99b62, { metalness: 0.45, roughness: 0.55 }),
false
);
}
const shopGroups = [];
const shopRecords = [];
const shopSpecs = [
[
{
name: "NEKO COFFEE",
japanese: "ネコ珈琲",
accent: 0xbd6848,
wall: 0xc9b59d,
sign: "#70483d",
ink: "#fff2d9",
height: 3.65,
type: "Coffee & neighborhood counter",
note: "The recessed entry remains on the north half of the bay. A shallow display ledge keeps the doorway and route clear."
},
{
name: "YAOBATEN",
japanese: "柴本店",
accent: 0x596d63,
wall: 0xb8c1ad,
sign: "#40564d",
ink: "#f6edd3",
height: 4.15,
type: "Small grocery & pantry",
note: "Produce crates stay inside the window bay. The 1.05 m entry is aligned with the shop's recessed threshold."
},
{
name: "SORA BOOKS",
japanese: "空書房",
accent: 0x5a7890,
wall: 0xd5c9b8,
sign: "#405d70",
ink: "#f6f0df",
height: 3.85,
type: "Independent bookseller",
note: "Book stacks are grouped on a 0.4 m facade ledge. Customers remain outside the marked pedestrian spine."
},
{
name: "MAME KITCHEN",
japanese: "豆厨房",
accent: 0xc08b43,
wall: 0xcbb89e,
sign: "#83562f",
ink: "#fff3d5",
height: 3.45,
type: "Tofu, tea & tiny lunches",
note: "A compact lunch display faces the window without occupying the recessed door swing or the walkway."
},
{
name: "KISSA 03",
japanese: "喫茶零三",
accent: 0x765b79,
wall: 0xb8a6a6,
sign: "#58435c",
ink: "#f8e7da",
height: 4.35,
type: "Eight-seat neighborhood café",
note: "The entrance is placed nearest the rear edge of the bay; outdoor furniture is omitted to preserve circulation."
}
],
[
{
name: "HOSHI CRAFT",
japanese: "星工房",
accent: 0x4f7b71,
wall: 0xbec8bb,
sign: "#385c55",
ink: "#fff3d8",
height: 3.75,
type: "Ceramics & small objects",
note: "The display cluster is attached to the facade and never projects beyond half a meter into the side clearance."
},
{
name: "PEACH LAB",
japanese: "桃研究所",
accent: 0xd47c7c,
wall: 0xd2b6a8,
sign: "#9d5157",
ink: "#fff0df",
height: 4.05,
type: "Soft goods & stationery",
note: "A continuous sill supports the window arrangement. The clear entry zone is visibly separate from the merchandise."
},
{
name: "TIN TOY",
japanese: "ブリキ玩具",
accent: 0xc19642,
wall: 0xc8bca4,
sign: "#73582d",
ink: "#fff0cd",
height: 3.55,
type: "Retro toy repair shop",
note: "Tiny robots and tin figures occupy one window bay. The sidewalk remains free of freestanding display boards."
},
{
name: "ASAHI DELI",
japanese: "朝日の惣菜",
accent: 0x9b5943,
wall: 0xcdb69d,
sign: "#743e31",
ink: "#fff0d4",
height: 3.95,
type: "Neighborhood deli",
note: "Food samples sit behind the facade line, while the doorway and tactile circulation strip remain unobstructed."
},
{
name: "KADO NOOK",
japanese: "花道的小径",
accent: 0x667b56,
wall: 0xc3c4ad,
sign: "#485a40",
ink: "#f8f1d8",
height: 4.25,
type: "Flowers and quiet gifts",
note: "The flower arrangement is elevated above the pedestrian zone and kept within the storefront footprint."
}
]
];
const wallMaterials = new Map();
function createShop(side, z, spec, shopIndex) {
const root = new THREE.Group();
root.position.set(side * 3.45, 0, z);
scene.add(root);
const width = 4.4;
const height = spec.height;
if (!wallMaterials.has(spec.wall)) {
wallMaterials.set(spec.wall, material(spec.wall));
}
const wallMat = wallMaterials.get(spec.wall);
const trimMat = material(0xeee2c9);
const darkMat = material(0x263c3d, { roughness: 0.32, metalness: 0.12 });
const woodMat = material(0x725342);
const roofMat = material(0x4e5b58);
// Main volume and thin street-facing facade.
addBox(root, [3.9, height, width], [side * 2.0, height / 2 + 0.12, 0], wallMat);
addBox(root, [0.12, height, width - 0.08], [-side * 0.015, height / 2 + 0.12, 0], wallMat);
addBox(root, [4.08, 0.18, width + 0.22], [side * 2.0, height + 0.19, 0], roofMat);
addBox(root, [0.16, 0.18, width + 0.1], [-side * 0.04, height + 0.03, 0], trimMat);
// Facade frame and base trim.
addBox(root, [0.13, 0.24, width], [-side * 0.08, 0.28, 0], trimMat);
addBox(root, [0.14, height, 0.13], [-side * 0.07, height / 2 + 0.15, -width / 2 + 0.06], trimMat);
addBox(root, [0.14, height, 0.13], [-side * 0.07, height / 2 + 0.15, width / 2 - 0.06], trimMat);
// Recessed entry, deliberately separate from the display window.
const doorZ = -width * 0.235;
const doorMat = material(0x36504e, { roughness: 0.28, metalness: 0.16 });
addBox(root, [0.15, 2.16, 1.08], [-side * 0.075, 1.2, doorZ], doorMat);
addBox(root, [0.12, 2.3, 0.09], [-side * 0.16, 1.22, doorZ - 0.57], woodMat);
addBox(root, [0.12, 2.3, 0.09], [-side * 0.16, 1.22, doorZ + 0.57], woodMat);
addBox(root, [0.12, 0.1, 1.23], [-side * 0.16, 2.37, doorZ], woodMat);
addBox(root, [0.1, 2.12, 0.035], [-side * 0.17, 1.19, doorZ], material(0x718783));
addBox(root, [0.1, 0.055, 0.13], [-side * 0.2, 1.08, doorZ + 0.35], material(0xd5b66e, { metalness: 0.5 }));
const openSign = makeLabelPlane("OPEN", "#477565", "#fff7df", 0.62, 0.2);
openSign.position.set(-side * 0.165, 1.78, doorZ);
openSign.rotation.y = side === 1 ? -Math.PI / 2 : Math.PI / 2;
root.add(openSign);
// Display window.
const windowZ = width * 0.205;
const glassMat = material(0x30494a, { roughness: 0.2, metalness: 0.22 });
addBox(root, [0.12, 1.27, 1.68], [-side * 0.13, 1.26, windowZ], glassMat);
addBox(root, [0.13, 1.35, 0.07], [-side * 0.2, 1.26, windowZ], trimMat);
addBox(root, [0.13, 0.07, 1.75], [-side * 0.2, 1.26, windowZ], trimMat);
addBox(root, [0.42, 0.11, 1.82], [-side * 0.22, 0.58, windowZ], woodMat);
// Awning with alternating fabric panels.
const awningMatA = material(spec.accent);
const awningMatB = material(0xf1dfbd);
const panelCount = 8;
const panelWidth = (width * 0.94) / panelCount;
for (let panel = 0; panel < panelCount; panel++) {
const panelZ = -width * 0.47 + panelWidth * (panel + 0.5);
addBox(
root,
[0.78, 0.085, panelWidth * 0.96],
[-side * 0.39, 2.58, panelZ],
panel % 2 === 0 ? awningMatA : awningMatB
);
}
addBox(
root,
[0.075, 0.28, width * 0.96],
[-side * 0.77, 2.45, 0],
awningMatA
);
// Main shop sign.
addBox(
root,
[0.15, 0.76, width * 0.79],
[-side * 0.23, height - 0.39, 0],
woodMat
);
const sign = makeSignPlane(
spec.name,
spec.japanese,
spec.sign,
spec.ink,
width * 0.75,
0.66
);
sign.position.set(-side * 0.315, height - 0.39, 0);
sign.rotation.y = side === 1 ? -Math.PI / 2 : Math.PI / 2;
root.add(sign);
// Upper facade details.
addBox(
root,
[0.44, 0.5, 0.72],
[-side * 0.24, height - 0.97, width * 0.34],
material(0xd5d7cd, { metalness: 0.18 })
);
addBox(
root,
[0.06, 0.4, 0.56],
[-side * 0.475, height - 0.97, width * 0.34],
material(0x7e8983)
);
addBox(
root,
[0.08, height - 0.28, 0.08],
[-side * 0.17, height / 2 + 0.12, -width * 0.44],
material(0x64706b, { metalness: 0.28 })
);
// Small roof blocks provide a voxel silhouette.
addBox(root, [0.8, 0.35, 0.8], [side * 2.65, height + 0.43, -0.7], roofMat);
addBox(root, [0.58, 0.28, 0.58], [side * 3.1, height + 0.39, 0.65], roofMat);
// Hanging lantern.
const lantern = new THREE.Group();
lantern.position.set(-side * 0.69, 2.03, width * 0.34);
root.add(lantern);
const lanternMat = material(spec.accent, {
emissive: spec.accent,
emissiveIntensity: 0.18
});
addBox(lantern, [0.34, 0.45, 0.34], [0, 0, 0], lanternMat);
addBox(lantern, [0.38, 0.055, 0.38], [0, 0.21, 0], woodMat);
addBox(lantern, [0.38, 0.055, 0.38], [0, -0.21, 0], woodMat);
addBox(lantern, [0.025, 0.47, 0.38], [0, 0, 0], woodMat);
const displayRoot = new THREE.Group();
displayRoot.position.z = windowZ;
root.add(displayRoot);
const shop = {
root,
side,
spec,
shopIndex,
width,
windowZ,
displayRoot,
accent: spec.accent
};
root.userData.shop = shop;
shopGroups.push(root);
shopRecords.push(shop);
return shop;
}
function makeDisplayItem(kind, accent) {
const group = new THREE.Group();
const accentMat = material(accent);
const creamMat = material(0xeadcbf);
const darkMat = material(0x394542);
const greenMat = material(0x567858);
const potMat = material(0xa96948);
if (kind === "books") {
for (let index = 0; index < 4; index++) {
const book = addBox(
group,
[0.25, 0.052, 0.2],
[0, 0.035 + index * 0.055, 0],
index % 2 === 0 ? accentMat : creamMat
);
book.rotation.y = (index - 1.5) * 0.08;
}
} else if (kind === "plush") {
addBox(group, [0.23, 0.25, 0.2], [0, 0.13, 0], accentMat);
addBox(group, [0.22, 0.19, 0.2], [0, 0.34, 0], creamMat);
addBox(group, [0.07, 0.08, 0.07], [-0.08, 0.46, 0], accentMat);
addBox(group, [0.07, 0.08, 0.07], [0.08, 0.46, 0], accentMat);
addBox(group, [0.03, 0.03, 0.02], [-0.055, 0.37, 0.105], darkMat);
addBox(group, [0.03, 0.03, 0.02], [0.055, 0.37, 0.105], darkMat);
} else if (kind === "plant") {
addBox(group, [0.18, 0.18, 0.18], [0, 0.09, 0], potMat);
addBox(group, [0.035, 0.22, 0.035], [0, 0.27, 0], greenMat);
addBox(group, [0.18, 0.08, 0.09], [-0.06, 0.35, 0], greenMat);
addBox(group, [0.1, 0.09, 0.18], [0.07, 0.4, 0], greenMat);
addBox(group, [0.14, 0.08, 0.09], [0, 0.49, 0], greenMat);
} else if (kind === "tea") {
addBox(group, [0.24, 0.18, 0.2], [0, 0.11, 0], accentMat);
addBox(group, [0.16, 0.035, 0.15], [0, 0.215, 0], creamMat);
addBox(group, [0.06, 0.06, 0.13], [0.16, 0.13, 0], accentMat);
addBox(group, [0.045, 0.15, 0.045], [-0.16, 0.15, 0], accentMat);
addBox(group, [0.13, 0.045, 0.045], [-0.16, 0.22, 0], accentMat);
} else if (kind === "robot") {
addBox(group, [0.19, 0.22, 0.16], [0, 0.13, 0], accentMat);
addBox(group, [0.16, 0.13, 0.15], [0, 0.31, 0], creamMat);
addBox(group, [0.035, 0.035, 0.02], [-0.045, 0.33, 0.08], darkMat);
addBox(group, [0.035, 0.035, 0.02], [0.045, 0.33, 0.08], darkMat);
addBox(group, [0.05, 0.14, 0.05], [-0.13, 0.15, 0], creamMat);
addBox(group, [0.05, 0.14, 0.05], [0.13, 0.15, 0], creamMat);
addBox(group, [0.06, 0.1, 0.06], [-0.055, 0.01, 0], darkMat);
addBox(group, [0.06, 0.1, 0.06], [0.055, 0.01, 0], darkMat);
} else {
const glowMat = material(0xffd57e, {
emissive: 0xffa646,
emissiveIntensity: 0.8
});
addBox(group, [0.19, 0.04, 0.19], [0, 0.025, 0], darkMat);
addBox(group, [0.035, 0.25, 0.035], [0, 0.16, 0], darkMat);
addBox(group, [0.25, 0.16, 0.25], [0, 0.34, 0], glowMat);
}
return group;
}
function populateDisplay(shop, random) {
while (shop.displayRoot.children.length) {
shop.displayRoot.remove(shop.displayRoot.children[0]);
}
const kinds = ["books", "plush", "plant", "tea", "robot", "lamp"];
const count = 3 + Math.floor(random() * 2);
const selected = [...kinds].sort(() => random() - 0.5).slice(0, count);
selected.forEach((kind, index) => {
const item = makeDisplayItem(kind, shop.accent);
const spacing = 1.12 / Math.max(1, count - 1);
const z = count === 1
? 0
: -0.56 + index * spacing + (random() - 0.5) * 0.07;
item.position.set(
-shop.side * (0.22 + random() * 0.065),
0.64,
z
);
item.rotation.y = (random() - 0.5) * 0.32;
shop.displayRoot.add(item);
});
shop.root.traverse((object) => {
if (object.isMesh) {
object.userData.shopIndex = shop.shopIndex;
}
});
}
let shopIndex = 0;
const layoutRandom = mulberry32(202503);
for (const side of [-1, 1]) {
const sideSpecs = side === -1 ? shopSpecs[0] : shopSpecs[1];
const positions = [-10.15, -5.05, 0, 5.05, 10.15];
positions.forEach((z, index) => {
const shop = createShop(side, z, sideSpecs[index], shopIndex++);
populateDisplay(shop, layoutRandom);
});
}
// Facade planters remain outside the 2.4 m route.
function createPlanter(x, z, accent, random) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
addBox(group, [0.48, 0.42, 0.48], [0, 0.22, 0], material(0x9a654c));
addBox(group, [0.53, 0.08, 0.53], [0, 0.46, 0], material(0x704b3b));
const greenMat = material(accent);
for (let index = 0; index < 7; index++) {
const leaf = addBox(
group,
[0.16, 0.17, 0.16],
[
(random() - 0.5) * 0.31,
0.56 + random() * 0.22,
(random() - 0.5) * 0.31
],
greenMat
);
leaf.rotation.set(random(), random(), random());
}
}
createPlanter(-2.9, -7.55, 0x5f7d5f, layoutRandom);
createPlanter(2.9, -2.55, 0x6e8759, layoutRandom);
createPlanter(-2.9, 2.55, 0x71865b, layoutRandom);
createPlanter(2.9, 7.55, 0x55735b, layoutRandom);
// Voxel bicycles, parked tight to the storefronts.
function beam(parent, start, end, thickness, mat) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = new THREE.Vector3().subVectors(b, a);
const midpoint = new THREE.Vector3().addVectors(a, b).multiplyScalar(0.5);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(thickness, direction.length(), thickness),
mat
);
mesh.position.copy(midpoint);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
parent.add(mesh);
}
function createBicycle(side, z) {
const group = new THREE.Group();
group.position.set(side * 2.87, 0, z);
group.rotation.y = side === 1 ? -0.08 : 0.08;
scene.add(group);
const frameMat = material(side === 1 ? 0x9e5546 : 0x486a68, {
metalness: 0.25
});
const tireMat = material(0x303333);
for (const wheelZ of [-0.5, 0.5]) {
const wheel = new THREE.Mesh(
new THREE.TorusGeometry(0.3, 0.045, 6, 12),
tireMat
);
wheel.position.set(0, 0.33, wheelZ);
wheel.castShadow = true;
group.add(wheel);
}
beam(group, [0, 0.33, -0.5], [0, 0.73, -0.12], 0.045, frameMat);
beam(group, [0, 0.73, -0.12], [0, 0.33, 0.5], 0.045, frameMat);
beam(group, [0, 0.33, -0.5], [0, 0.33, 0.5], 0.045, frameMat);
beam(group, [0, 0.33, 0.5], [0, 0.79, 0.28], 0.045, frameMat);
beam(group, [0, 0.79, 0.28], [0, 0.73, -0.12], 0.045, frameMat);
beam(group, [0, 0.79, 0.28], [0, 0.92, 0.25], 0.045, frameMat);
addBox(group, [0.18, 0.06, 0.29], [0, 0.83, -0.16], material(0x4b413a));
addBox(group, [0.46, 0.045, 0.06], [0, 0.95, 0.26], darkBikeHandle());
}
function darkBikeHandle() {
return material(0x37413f, { metalness: 0.35 });
}
createBicycle(1, -7.55);
createBicycle(-1, 2.55);
createBicycle(1, 7.55);
// Utility poles and overhead cables create a compact Yanaka-like canopy.
const poleMat = material(0x68645b);
const poleXs = [-3.15];
const poleZs = [-13.5, -3, 7.5, 15];
for (const z of poleZs) {
addBox(scene, [0.16, 5.7, 0.16], [-3.15, 2.85, z], poleMat);
addBox(scene, [1.0, 0.1, 0.11], [-2.75, 5.15, z], poleMat);
addBox(scene, [0.16, 0.23, 0.16], [-3.15, 5.35, z], material(0x9e8068));
}
function createCable(points, radius = 0.018, color = 0x39413f) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point))
);
const cable = new THREE.Mesh(
new THREE.TubeGeometry(curve, 24, radius, 4, false),
material(color)
);
scene.add(cable);
return cable;
}
for (let index = 0; index < poleZs.length - 1; index++) {
const z1 = poleZs[index];
const z2 = poleZs[index + 1];
createCable([
[-3.15, 5.35, z1],
[-3.05, 4.95, (z1 + z2) / 2],
[-3.15, 5.35, z2]
]);
}
for (const z of [-8.5, 0, 8.5]) {
createCable([
[-3.35, 5.75, z],
[0, 5.05, z + 0.1],
[3.35, 5.75, z]
], 0.014, 0x4d5049);
}
// Distant voxel clouds.
const cloudMat = material(0xf4f3e8, { roughness: 1 });
addBox(scene, [2.6, 0.8, 1.2], [-5, 9.2, -19], cloudMat, false);
addBox(scene, [1.6, 1.1, 1.4], [-4.2, 9.55, -18.8], cloudMat, false);
addBox(scene, [3.2, 0.7, 1.3], [6, 8.7, -22], cloudMat, false);
// A few pedestrians use the central spine rather than the shop displays.
const pedestrians = [];
function createPerson(x, z, shirtColor, skinColor, speed, phase) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const shirtMat = material(shirtColor);
const skinMat = material(skinColor);
const pantsMat = material(0x3d4748);
const hairMat = material(0x343332);
addBox(group, [0.32, 0.43, 0.23], [0, 0.84, 0], shirtMat);
addBox(group, [0.22, 0.22, 0.22], [0, 1.17, 0], skinMat);
addBox(group, [0.235, 0.09, 0.235], [0, 1.29, 0], hairMat);
addBox(group, [0.11, 0.42, 0.12], [-0.09, 0.3, 0], pantsMat);
addBox(group, [0.11, 0.42, 0.12], [0.09, 0.3, 0], pantsMat);
addBox(group, [0.09, 0.35, 0.1], [-0.21, 0.83, 0], shirtMat);
addBox(group, [0.09, 0.35, 0.1], [0.21, 0.83, 0], shirtMat);
const bag = addBox(
group,
[0.19, 0.24, 0.12],
[0.25, 0.64, 0],
material(0xb38154)
);
bag.castShadow = true;
pedestrians.push({
group,
speed,
phase,
baseX: x
});
}
createPerson(-0.35, -8.5, 0xb45e50, 0xe1b38d, 0.42, 0.2);
createPerson(0.42, -1.8, 0x4f7885, 0xd4a17b, -0.34, 1.1);
createPerson(-0.15, 5.8, 0x8a7b9d, 0xe7bd98, 0.31, 2.4);
// Custom camera controls — no addons.
const currentCamera = {
target: new THREE.Vector3(0, 1.15, -1),
yaw: 0.08,
pitch: 0.27,
distance: 22
};
const desiredCamera = {
target: currentCamera.target.clone(),
yaw: currentCamera.yaw,
pitch: currentCamera.pitch,
distance: currentCamera.distance
};
function applyCamera() {
const horizontal = desiredCamera.distance * Math.cos(desiredCamera.pitch);
camera.position.set(
desiredCamera.target.x + Math.sin(desiredCamera.yaw) * horizontal,
desiredCamera.target.y + Math.sin(desiredCamera.pitch) * desiredCamera.distance,
desiredCamera.target.z + Math.cos(desiredCamera.yaw) * horizontal
);
camera.lookAt(desiredCamera.target);
}
function setView(view) {
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === view);
});
if (view === "overview") {
desiredCamera.target.set(0, 1.15, -1);
desiredCamera.yaw = 0.08;
desiredCamera.pitch = 0.27;
desiredCamera.distance = 22;
} else if (view === "walk") {
desiredCamera.target.set(0, 1.55, 5.2);
desiredCamera.yaw = 0;
desiredCamera.pitch = 0.055;
desiredCamera.distance = 11.8;
} else {
desiredCamera.target.set(0, 0, 0);
desiredCamera.yaw = 0;
desiredCamera.pitch = 1.36;
desiredCamera.distance = 17.5;
}
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let dragging = false;
let dragMoved = false;
let previousX = 0;
let previousY = 0;
let shiftPressed = false;
function updatePointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
dragMoved = false;
previousX = event.clientX;
previousY = event.clientY;
shiftPressed = event.shiftKey;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 2) dragMoved = true;
if (event.shiftKey || shiftPressed) {
const right = new THREE.Vector3(
Math.cos(desiredCamera.yaw),
0,
-Math.sin(desiredCamera.yaw)
);
const forward = new THREE.Vector3(
Math.sin(desiredCamera.yaw),
0,
Math.cos(desiredCamera.yaw)
);
desiredCamera.target
.addScaledVector(right, -dx * desiredCamera.distance * 0.0013)
.addScaledVector(forward, -dy * desiredCamera.distance * 0.0013);
desiredCamera.target.x = THREE.MathUtils.clamp(
desiredCamera.target.x,
-5,
5
);
desiredCamera.target.z = THREE.MathUtils.clamp(
desiredCamera.target.z,
-14,
14
);
} else {
desiredCamera.yaw -= dx * 0.0045;
desiredCamera.pitch = THREE.MathUtils.clamp(
desiredCamera.pitch + dy * 0.0035,
0.035,
1.46
);
}
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
canvas.classList.remove("dragging");
if (dragMoved) return;
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(shopGroups, true);
const hit = intersections.find(
(intersection) =>
intersection.object.userData.shopIndex !== undefined
);
if (!hit) return;
const shop = shopRecords[hit.object.userData.shopIndex];
selectionTitle.textContent = shop.spec.name;
selectionCopy.textContent =
`${shop.spec.type}. ${shop.spec.note} ` +
"Entrance: 1.05 m clear · Display depth: under 0.5 m.";
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
canvas.classList.remove("dragging");
});
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.distance = THREE.MathUtils.clamp(
desiredCamera.distance * Math.exp(event.deltaY * 0.001),
7,
30
);
},
{ passive: false }
);
const keyState = new Set();
window.addEventListener("keydown", (event) => {
keyState.add(event.key.toLowerCase());
if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(event.key)) {
event.preventDefault();
}
});
window.addEventListener("keyup", (event) => {
keyState.delete(event.key.toLowerCase());
});
function updateKeyboardCamera(dt) {
const speed = 4.5 * dt;
const forward = new THREE.Vector3(
Math.sin(desiredCamera.yaw),
0,
Math.cos(desiredCamera.yaw)
);
const right = new THREE.Vector3(
Math.cos(desiredCamera.yaw),
0,
-Math.sin(desiredCamera.yaw)
);
if (keyState.has("w") || keyState.has("arrowup")) {
desiredCamera.target.addScaledVector(forward, speed);
}
if (keyState.has("s") || keyState.has("arrowdown")) {
desiredCamera.target.addScaledVector(forward, -speed);
}
if (keyState.has("d") || keyState.has("arrowright")) {
desiredCamera.target.addScaledVector(right, speed);
}
if (keyState.has("a") || keyState.has("arrowleft")) {
desiredCamera.target.addScaledVector(right, -speed);
}
desiredCamera.target.x = THREE.MathUtils.clamp(
desiredCamera.target.x,
-5,
5
);
desiredCamera.target.z = THREE.MathUtils.clamp(
desiredCamera.target.z,
-14,
14
);
}
let toastTimer;
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toast.classList.remove("show");
}, 1800);
}
shuffleButton.addEventListener("click", () => {
const random = Math.random;
shopRecords.forEach((shop) => {
populateDisplay(shop, random);
});
showToast("Displays re-laid out · entrances and 2.4 m route preserved");
});
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateKeyboardCamera(dt);
const smoothing = reducedMotion ? 1 : 1 - Math.exp(-dt * 8);
currentCamera.target.lerp(
desiredCamera.target,
smoothing
);
currentCamera.yaw = THREE.MathUtils.lerp(
currentCamera.yaw,
desiredCamera.yaw,
smoothing
);
currentCamera.pitch = THREE.MathUtils.lerp(
currentCamera.pitch,
desiredCamera.pitch,
smoothing
);
currentCamera.distance = THREE.MathUtils.lerp(
currentCamera.distance,
desiredCamera.distance,
smoothing
);
const horizontal =
currentCamera.distance * Math.cos(currentCamera.pitch);
camera.position.set(
currentCamera.target.x +
Math.sin(currentCamera.yaw) * horizontal,
currentCamera.target.y +
Math.sin(currentCamera.pitch) * currentCamera.distance,
currentCamera.target.z +
Math.cos(currentCamera.yaw) * horizontal
);
camera.lookAt(currentCamera.target);
pedestrians.forEach((pedestrian) => {
pedestrian.group.position.z += pedestrian.speed * dt;
pedestrian.group.position.y =
Math.abs(Math.sin(elapsed * 5 + pedestrian.phase)) * 0.018;
pedestrian.group.rotation.y = pedestrian.speed > 0 ? 0 : Math.PI;
if (pedestrian.group.position.z > 13) {
pedestrian.group.position.z = -13;
} else if (pedestrian.group.position.z < -13) {
pedestrian.group.position.z = 13;
}
});
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
applyCamera();
animate();
</script>
</body>
</html>
```