Prompt specification
Build or customize the Three.js 3D scene "Yanaka shopper and bicycle at a small storefront" 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: Yanaka shopper and bicycle at a small storefront
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/yanaka-shopper-and-bicycle-at-a-small-storefront-x3038
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: Yanaka shopper and bicycle at a small storefront. Create a compact referenced neighborhood vignette with shopper, parked bicycle, and original goods display. Preserve a clear walking route through the narrow street frontage.
Working Three.js Starter (yanaka-shopper-and-bicycle-at-a-small-storefront-x3038):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#d9dfd7">
<title>Yanaka Shopper's Block</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9dfd7;
color: #233d38;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.card {
position: fixed;
top: 22px;
left: 22px;
z-index: 10;
width: min(360px, calc(100vw - 44px));
padding: 18px 19px 16px;
border: 1px solid rgba(35, 61, 56, 0.15);
border-radius: 18px;
background: rgba(249, 247, 237, 0.88);
box-shadow: 0 14px 40px rgba(37, 54, 47, 0.13);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: #b65f45;
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: clamp(25px, 4vw, 38px);
font-weight: 600;
line-height: 1;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 14px;
color: #60716a;
font-size: 12px;
line-height: 1.55;
}
.tags {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.tag {
padding: 5px 8px;
border: 1px solid rgba(35, 61, 56, 0.13);
border-radius: 999px;
background: rgba(255, 255, 255, 0.55);
color: #4f675f;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.controls {
position: fixed;
right: 20px;
bottom: 20px;
z-index: 10;
display: flex;
gap: 7px;
padding: 7px;
border: 1px solid rgba(35, 61, 56, 0.15);
border-radius: 14px;
background: rgba(249, 247, 237, 0.88);
box-shadow: 0 10px 30px rgba(37, 54, 47, 0.12);
backdrop-filter: blur(10px);
}
button {
min-width: 40px;
height: 38px;
padding: 0 12px;
border: 0;
border-radius: 9px;
background: #294c43;
color: #fffdf2;
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease;
}
button:hover {
background: #b65f45;
transform: translateY(-1px);
}
button:active {
transform: translateY(1px);
}
.hint {
position: fixed;
left: 22px;
bottom: 22px;
z-index: 10;
max-width: min(430px, calc(100vw - 180px));
padding: 9px 12px;
border-radius: 10px;
background: rgba(249, 247, 237, 0.78);
color: #62736d;
font-size: 10px;
line-height: 1.45;
pointer-events: none;
backdrop-filter: blur(8px);
}
.route {
color: #a05b43;
font-weight: 800;
}
@media (max-width: 640px) {
.card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 15px;
}
.subtitle {
display: none;
}
.tags {
margin-top: 10px;
}
.hint {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel scene of a Yanaka shopper, parked bicycle, and small neighborhood storefront"
></canvas>
<section class="card">
<div class="eyebrow">Voxel neighborhood study</div>
<h1>Yanaka<br>Shopper’s Block</h1>
<p class="subtitle">
A compact old-neighborhood storefront, an original goods window,
a browsing shopper, and a bicycle tucked close to the facade.
</p>
<div class="tags">
<span class="tag">Tokyo backstreet</span>
<span class="tag">Original voxel goods</span>
<span class="tag">Clear walking route</span>
</div>
</section>
<div class="hint">
Drag to orbit · Scroll or pinch to zoom · Arrow keys rotate ·
<span class="route">The pale sidewalk band remains unobstructed.</span>
</div>
<nav class="controls" aria-label="Camera controls">
<button id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button id="zoomOut" type="button" aria-label="Zoom out">−</button>
<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 canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#d9dfd7");
scene.fog = new THREE.Fog("#d9dfd7", 22, 42);
const camera = new THREE.OrthographicCamera(-8, 8, 5, -5, 0.1, 100);
const hemi = new THREE.HemisphereLight("#f7f1d8", "#78827a", 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff0cf", 3.4);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.0005;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b7d1d3", 1.15);
fill.position.set(9, 6, -7);
scene.add(fill);
const materialCache = new Map();
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function material(color) {
if (color && color.isMaterial) return color;
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0
})
);
}
return materialCache.get(color);
}
function cube(
width,
height,
depth,
x,
y,
z,
color,
parent = scene,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(unitBox, material(color));
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function cylinder(
radiusTop,
radiusBottom,
height,
x,
y,
z,
color,
parent = scene,
segments = 8
) {
const geometry = new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
);
const mesh = new THREE.Mesh(geometry, material(color));
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beam(parent, a, b, radius, color) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
6,
1,
false
);
const mesh = new THREE.Mesh(geometry, material(color));
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function textPanel({
width,
height,
x,
y,
z,
title,
subtitle,
background = "#23483f",
foreground = "#fff8dc"
}) {
const textureCanvas = document.createElement("canvas");
textureCanvas.width = 1024;
textureCanvas.height = 192;
const ctx = textureCanvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, 1024, 192);
ctx.strokeStyle = foreground;
ctx.globalAlpha = 0.55;
ctx.lineWidth = 4;
ctx.strokeRect(16, 16, 992, 160);
ctx.globalAlpha = 1;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
ctx.font = "700 86px Georgia, serif";
ctx.fillText(title, 512, 78);
if (subtitle) {
ctx.font = "700 24px sans-serif";
ctx.letterSpacing = "5px";
ctx.fillText(subtitle, 512, 145);
}
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true
})
);
mesh.position.set(x, y, z);
scene.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Diorama base, narrow road, sidewalk, and curbs
// ---------------------------------------------------------------------
cube(13.4, 0.48, 8.7, 0, -0.25, 1.05, "#aeb4a9");
cube(13.4, 0.10, 3.85, 0, 0.035, 4.15, "#626965");
cube(13.4, 0.10, 3.85, 0, 0.018, 4.16, "#737a75");
cube(12.9, 0.18, 2.55, -0.05, 0.12, 1.28, "#b9b8a9");
const tileColors = ["#d3d0bd", "#ccc9b6", "#d8d4c1", "#c7c5b2"];
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 12; col++) {
const color = tileColors[(row + col * 3) % tileColors.length];
cube(
0.96,
0.035,
0.76,
-5.55 + col * 1.02,
0.225,
0.53 + row * 0.83,
color,
scene,
false,
true
);
}
}
for (let i = 0; i < 14; i++) {
cube(
0.91,
0.22,
0.18,
-5.85 + i * 0.91,
0.10,
2.62,
i % 2 ? "#c6c3b1" : "#d1cdbb"
);
}
// A restrained tactile strip marks the edge without blocking the route.
for (let i = 0; i < 43; i++) {
cube(
0.17,
0.035,
0.12,
-6.05 + i * 0.29,
0.255,
2.38,
"#c9a65e",
scene,
false,
true
);
}
// Small road details.
cylinder(0.35, 0.35, 0.025, -3.8, 0.105, 4.25, "#5f6662", scene, 12);
cylinder(0.29, 0.29, 0.028, -3.8, 0.12, 4.25, "#777d77", scene, 12);
for (let i = 0; i < 6; i++) {
cube(
0.70,
0.025,
0.045,
4.55,
0.108,
2.92 + i * 0.11,
"#4e5652",
scene,
false
);
}
// ---------------------------------------------------------------------
// Main compact storefront
// ---------------------------------------------------------------------
const store = new THREE.Group();
scene.add(store);
// Foundation and interior.
cube(6.65, 0.22, 2.75, 0.40, 0.32, -1.18, "#74624d", store);
cube(6.60, 3.08, 0.18, 0.40, 1.85, -2.40, "#bca987", store);
cube(0.18, 3.08, 2.45, -2.84, 1.85, -1.18, "#c8b99d", store);
cube(0.18, 3.08, 2.45, 3.64, 1.85, -1.18, "#c8b99d", store);
cube(6.50, 0.08, 2.40, 0.40, 0.45, -1.18, "#8a7458", store);
// Warm recessed interior back wall.
cube(4.55, 2.20, 0.10, 1.05, 1.55, -2.27, "#554d3e", store);
// Upper residential facade.
cube(6.65, 1.95, 2.45, 0.40, 4.67, -1.18, "#d7c9ad", store);
cube(6.90, 0.18, 2.65, 0.40, 5.70, -1.18, "#695d50", store);
cube(6.85, 0.08, 2.58, 0.40, 5.82, -1.18, "#87745e", store);
// Ground-floor frame.
cube(0.16, 2.42, 0.18, -2.75, 1.57, 0.00, "#65543f", store);
cube(0.16, 2.42, 0.18, -1.32, 1.57, 0.00, "#65543f", store);
cube(0.16, 2.42, 0.18, 3.52, 1.57, 0.00, "#65543f", store);
cube(4.88, 0.16, 0.22, 1.10, 0.43, 0.01, "#65543f", store);
cube(4.88, 0.16, 0.22, 1.10, 2.73, 0.01, "#65543f", store);
// Door recess, glass, frame, and handle.
cube(1.20, 2.20, 0.07, -2.05, 1.52, -0.08, "#3f443e", store);
cube(1.05, 2.04, 0.025, -2.05, 1.50, -0.025, "#71847b", store);
cube(0.06, 2.04, 0.06, -2.05, 1.50, 0.04, "#493e31", store);
cube(1.06, 0.06, 0.06, -2.05, 1.50, 0.04, "#493e31", store);
cube(0.08, 0.38, 0.08, -1.68, 1.35, 0.12, "#c89549", store);
// Display-window framing.
for (const x of [-1.25, 0.00, 1.25, 2.50, 3.45]) {
cube(0.075, 2.20, 0.12, x, 1.57, 0.05, "#554735", store);
}
cube(4.80, 0.08, 0.13, 1.10, 1.40, 0.05, "#554735", store);
// Clear glazing; merchandise remains visible.
const glass = new THREE.MeshBasicMaterial({
color: "#dce8dc",
transparent: true,
opacity: 0.13,
depthWrite: false,
side: THREE.DoubleSide
});
cube(4.72, 2.18, 0.018, 1.10, 1.56, 0.075, glass, store, false, false);
// Sign fascia.
cube(6.65, 0.72, 0.30, 0.40, 3.26, 0.02, "#24483f", store);
textPanel({
width: 4.90,
height: 0.70,
x: 0.55,
y: 3.27,
z: 0.181,
title: "YANAKA",
subtitle: "NEIGHBORHOOD GOODS"
});
// Striped awning, kept above the walking path.
const awning = new THREE.Group();
store.add(awning);
const stripeColors = ["#f2e5c7", "#477565"];
for (let i = 0; i < 11; i++) {
const panel = cube(
0.46,
0.075,
1.12,
-1.35 + i * 0.46,
2.88,
0.55,
stripeColors[i % 2],
awning
);
panel.rotation.x = 0.085;
}
for (let i = 0; i < 11; i++) {
cube(
0.46,
0.24,
0.065,
-1.35 + i * 0.46,
2.62,
1.08,
stripeColors[i % 2],
awning
);
}
// Upper windows, frames, and slatted shutters.
for (const x of [-1.35, 2.05]) {
cube(1.75, 1.05, 0.08, x, 4.65, 0.075, "#4e5a54", store);
cube(1.46, 0.82, 0.04, x, 4.65, 0.13, "#91a69b", store);
cube(0.065, 0.86, 0.07, x, 4.65, 0.18, "#e4d8bc", store);
cube(1.49, 0.065, 0.07, x, 4.65, 0.18, "#e4d8bc", store);
for (let i = 0; i < 6; i++) {
cube(
0.50,
0.045,
0.045,
x - 0.48 + i * 0.19,
4.18,
0.17,
"#847966",
store
);
}
}
// Roof edge and a very small rooftop utility detail.
cube(6.95, 0.14, 2.75, 0.40, 5.86, -1.15, "#685c4d", store);
cube(0.68, 0.45, 0.62, 2.35, 6.15, -1.62, "#8c958d", store);
cube(0.74, 0.08, 0.68, 2.35, 6.40, -1.62, "#65736c", store);
beam(store, [-2.35, 5.82, -1.45], [-2.35, 7.02, -1.45], 0.025, "#4f5c56");
beam(store, [-2.35, 6.85, -1.45], [-1.75, 6.85, -1.45], 0.018, "#4f5c56");
// ---------------------------------------------------------------------
// Original goods display
// ---------------------------------------------------------------------
const goods = new THREE.Group();
store.add(goods);
// Display plinth and shelves.
cube(4.50, 0.48, 0.75, 1.10, 0.68, -0.55, "#9a7854", goods);
cube(4.50, 0.09, 0.80, 1.10, 0.96, -0.55, "#d3aa74", goods);
cube(4.45, 0.09, 0.62, 1.10, 1.43, -0.58, "#73573d", goods);
cube(4.45, 0.09, 0.62, 1.10, 2.00, -0.58, "#73573d", goods);
// Hanging cloth bags.
const bagColors = ["#d89358", "#7a9d83", "#e0bd76"];
for (let i = 0; i < 3; i++) {
const x = -0.80 + i * 0.62;
cube(0.43, 0.50, 0.13, x, 2.22, -0.72, bagColors[i], goods);
beam(
goods,
[x - 0.13, 2.47, -0.72],
[x - 0.05, 2.61, -0.72],
0.025,
"#614735"
);
beam(
goods,
[x + 0.13, 2.47, -0.72],
[x + 0.05, 2.61, -0.72],
0.025,
"#614735"
);
cube(0.35, 0.04, 0.15, x, 2.55, -0.72, "#614735", goods);
}
// Standing books and boxed goods.
const bookColors = ["#c95f48", "#416c63", "#d8b95d", "#6f8190"];
for (let i = 0; i < 9; i++) {
const x = -0.75 + i * 0.105;
const height = 0.27 + (i % 3) * 0.035;
cube(
0.075,
height,
0.22,
x,
2.20 + height / 2,
-0.42,
bookColors[i % bookColors.length],
goods
);
}
for (let i = 0; i < 4; i++) {
cube(
0.36,
0.25,
0.28,
0.50 + i * 0.44,
1.60,
-0.46,
i % 2 ? "#d7b06e" : "#668c78",
goods
);
cube(
0.23,
0.09,
0.015,
0.50 + i * 0.44,
1.60,
-0.313,
"#f3e5c3",
goods
);
}
// Ceramic pots.
function makePot(x, y, z, scale, color) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
goods.add(group);
cylinder(0.18, 0.13, 0.31, 0, 0.155, 0, color, group, 8);
cylinder(0.20, 0.20, 0.045, 0, 0.325, 0, color, group, 8);
cylinder(0.145, 0.145, 0.012, 0, 0.35, 0, "#4b4638", group, 8);
return group;
}
makePot(2.62, 1.02, -0.43, 1.0, "#b66e4e");
makePot(3.05, 1.02, -0.45, 0.72, "#d6b16e");
// Small jars on the middle shelf.
for (let i = 0; i < 5; i++) {
const x = -0.63 + i * 0.39;
cylinder(
0.115,
0.115,
0.25,
x,
1.60,
-0.46,
i % 2 ? "#c98a55" : "#829477",
goods,
8
);
cylinder(
0.12,
0.12,
0.045,
x,
1.745,
-0.46,
"#e2d6b6",
goods,
8
);
}
// A small original potted plant.
const plant = new THREE.Group();
plant.position.set(3.02, 2.055, -0.48);
goods.add(plant);
cylinder(0.16, 0.12, 0.22, 0, 0.11, 0, "#b4664e", plant, 8);
cube(0.10, 0.28, 0.10, 0, 0.34, 0, "#426c4e", plant);
cube(0.28, 0.09, 0.10, -0.07, 0.43, 0, "#5d845d", plant);
cube(0.10, 0.09, 0.27, 0.08, 0.49, 0, "#76966a", plant);
cube(0.09, 0.20, 0.09, 0.08, 0.61, 0, "#426c4e", plant);
// Small product labels along the shelf edge.
for (const x of [-0.78, 0.05, 1.05, 2.25, 3.02]) {
cube(
0.34,
0.13,
0.025,
x,
1.07,
-0.115,
"#efe2bf",
goods
);
cube(
0.19,
0.025,
0.01,
x,
1.08,
-0.095,
"#846b51",
goods,
false
);
}
// ---------------------------------------------------------------------
// Small neighboring facade for neighborhood context
// ---------------------------------------------------------------------
const neighbor = new THREE.Group();
scene.add(neighbor);
cube(1.70, 4.72, 2.50, -4.02, 2.60, -1.12, "#aeb8ad", neighbor);
cube(1.88, 0.18, 2.65, -4.02, 5.02, -1.12, "#67766f", neighbor);
cube(1.20, 2.60, 0.08, -4.02, 1.60, 0.16, "#78847c", neighbor);
for (let i = 0; i < 13; i++) {
cube(
1.17,
0.035,
0.05,
-4.02,
0.42 + i * 0.19,
0.215,
"#65736c",
neighbor
);
}
cube(0.78, 0.80, 0.06, -4.02, 3.82, 0.17, "#5f6d67", neighbor);
cube(0.62, 0.64, 0.04, -4.02, 3.82, 0.215, "#91a69b", neighbor);
beam(
neighbor,
[-3.52, 0.45, 0.25],
[-3.52, 4.95, 0.25],
0.045,
"#6d766d"
);
// ---------------------------------------------------------------------
// Voxel shopper
// ---------------------------------------------------------------------
const shopper = new THREE.Group();
shopper.position.set(-0.78, 0.255, 1.48);
shopper.rotation.y = -0.07;
scene.add(shopper);
// Shoes and trousers.
cube(0.34, 0.13, 0.20, 0.13, 0.07, -0.10, "#453b32", shopper);
cube(0.34, 0.13, 0.20, -0.14, 0.07, 0.10, "#453b32", shopper);
cube(0.17, 0.52, 0.19, 0.10, 0.36, -0.10, "#394a50", shopper);
cube(0.17, 0.50, 0.19, -0.12, 0.35, 0.10, "#394a50", shopper);
// Coat, hem, and scarf.
cube(0.46, 0.62, 0.38, -0.01, 0.88, 0, "#4d7a70", shopper);
cube(0.50, 0.13, 0.41, -0.01, 0.61, 0, "#426b62", shopper);
cube(0.48, 0.12, 0.40, 0, 1.20, 0, "#d7a54f", shopper);
cube(0.08, 0.32, 0.15, 0.24, 1.05, 0.08, "#d7a54f", shopper);
// Head, hair, face pixels.
cube(0.37, 0.40, 0.36, 0.02, 1.47, 0, "#d5a17c", shopper);
cube(0.39, 0.11, 0.38, 0.01, 1.69, 0, "#5a5147", shopper);
cube(0.12, 0.20, 0.38, -0.13, 1.52, 0, "#5a5147", shopper);
cube(0.065, 0.065, 0.08, 0.235, 1.48, 0, "#d5a17c", shopper);
cube(0.025, 0.035, 0.035, 0.215, 1.52, -0.095, "#3b342d", shopper);
cube(0.025, 0.035, 0.035, 0.215, 1.52, 0.095, "#3b342d", shopper);
// Arms.
cube(0.17, 0.47, 0.16, 0.03, 0.91, -0.27, "#4d7a70", shopper);
cube(0.15, 0.42, 0.15, -0.07, 0.94, 0.27, "#4d7a70", shopper);
cube(0.14, 0.13, 0.14, 0.03, 0.64, -0.27, "#d5a17c", shopper);
cube(0.14, 0.13, 0.14, -0.10, 0.69, 0.27, "#d5a17c", shopper);
// Canvas shopping tote.
cube(0.34, 0.38, 0.16, -0.08, 0.49, 0.38, "#d6bc83", shopper);
beam(
shopper,
[-0.20, 0.66, 0.38],
[-0.08, 0.79, 0.38],
0.022,
"#765f43"
);
beam(
shopper,
[0.04, 0.66, 0.38],
[-0.08, 0.79, 0.38],
0.022,
"#765f43"
);
cube(0.20, 0.10, 0.15, -0.10, 0.71, 0.38, "#728a57", shopper);
cube(0.09, 0.18, 0.09, -0.16, 0.79, 0.37, "#59794b", shopper);
// ---------------------------------------------------------------------
// Parked voxel bicycle, tucked against the facade
// ---------------------------------------------------------------------
const bicycle = new THREE.Group();
bicycle.position.set(2.33, 0.26, 0.34);
bicycle.rotation.y = -0.10;
scene.add(bicycle);
const tireMaterial = new THREE.MeshStandardMaterial({
color: "#343b38",
roughness: 0.92
});
const metalMaterial = new THREE.MeshStandardMaterial({
color: "#b96045",
roughness: 0.67,
metalness: 0.18
});
const spokeMaterial = new THREE.MeshStandardMaterial({
color: "#c5bca5",
roughness: 0.68,
metalness: 0.25
});
function wheel(centerX) {
const wheelMesh = new THREE.Mesh(
new THREE.TorusGeometry(0.34, 0.045, 4, 12),
tireMaterial
);
wheelMesh.rotation.y = Math.PI / 2;
wheelMesh.position.set(centerX, 0.38, 0);
wheelMesh.castShadow = true;
bicycle.add(wheelMesh);
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
beam(
bicycle,
[centerX, 0.38, 0],
[
centerX,
0.38 + Math.cos(angle) * 0.30,
Math.sin(angle) * 0.30
],
0.012,
spokeMaterial
);
}
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.14, 8),
spokeMaterial
);
hub.rotation.x = Math.PI / 2;
hub.position.set(centerX, 0.38, 0);
bicycle.add(hub);
}
wheel(-0.64);
wheel(0.64);
const rear = [-0.64, 0.38, 0];
const front = [0.64, 0.38, 0];
const crank = [-0.10, 0.35, 0];
const seat = [-0.30, 0.82, 0];
const head = [0.40, 0.77, 0];
beam(bicycle, rear, crank, 0.030, metalMaterial);
beam(bicycle, crank, seat, 0.030, metalMaterial);
beam(bicycle, seat, rear, 0.030, metalMaterial);
beam(bicycle, seat, head, 0.034, metalMaterial);
beam(bicycle, crank, head, 0.034, metalMaterial);
beam(bicycle, head, front, 0.032, metalMaterial);
beam(bicycle, head, [0.46, 1.02, 0], 0.028, metalMaterial);
// Handlebar and saddle.
beam(bicycle, [0.46, 1.02, -0.22], [0.46, 1.02, 0.22], 0.026, "#3d4945");
cube(0.30, 0.07, 0.17, -0.31, 0.89, 0, "#453c32");
beam(bicycle, seat, [-0.30, 0.89, 0], 0.025, "#3d4945");
// Crank, pedal, chain guard.
beam(bicycle, [-0.10, 0.35, -0.12], [-0.10, 0.35, 0.12], 0.025, "#414a46");
cube(0.19, 0.035, 0.08, -0.01, 0.30, -0.14, "#444b47");
cube(0.08, 0.12, 0.045, -0.10, 0.32, 0.14, "#444b47");
// Front basket, built from voxel-like bars.
cube(0.38, 0.06, 0.32, 0.72, 0.71, 0, "#b79a68");
cube(0.38, 0.24, 0.045, 0.72, 0.82, 0.15, "#b79a68");
cube(0.38, 0.24, 0.045, 0.72, 0.82, -0.15, "#b79a68");
cube(0.045, 0.24, 0.32, 0.91, 0.82, 0, "#b79a68");
cube(0.045, 0.24, 0.32, 0.53, 0.82, 0, "#b79a68");
cube(0.27, 0.12, 0.20, 0.70, 0.81, 0, "#d8b857");
// Parked kickstand.
beam(bicycle, [-0.12, 0.34, 0], [-0.29, 0.02, 0.24], 0.018, "#45514c");
// ---------------------------------------------------------------------
// Warm shop light and subtle atmosphere
// ---------------------------------------------------------------------
const shopLight = new THREE.PointLight("#f0a85d", 10, 5.5, 2);
shopLight.position.set(0.7, 2.2, -0.7);
store.add(shopLight);
// ---------------------------------------------------------------------
// Custom orthographic camera controls
// ---------------------------------------------------------------------
const target = new THREE.Vector3(-0.15, 2.05, 0.25);
const view = {
theta: 0.70,
phi: 1.02,
zoom: 1
};
const defaultView = {
theta: 0.70,
phi: 1.02,
zoom: 1
};
function updateCamera() {
const distance = 18;
const sinPhi = Math.sin(view.phi);
camera.position.set(
target.x + distance * sinPhi * Math.cos(view.theta),
target.y + distance * Math.cos(view.phi),
target.z + distance * sinPhi * Math.sin(view.theta)
);
camera.lookAt(target);
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
const desiredWidth = 14.3;
const desiredHeight = Math.max(9.6, desiredWidth / aspect);
const halfHeight = (desiredHeight / 2) / view.zoom;
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
updateCamera();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
let activePointerId = null;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
activePointerId = event.pointerId;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.focus();
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointerId) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(
view.phi - dy * 0.005,
0.42,
1.36
);
updateCamera();
});
function endDrag(event) {
if (event.pointerId !== activePointerId) return;
dragging = false;
activePointerId = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.zoom = THREE.MathUtils.clamp(
view.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.65
);
resize();
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
let handled = true;
if (event.key === "ArrowLeft") view.theta -= 0.08;
else if (event.key === "ArrowRight") view.theta += 0.08;
else if (event.key === "ArrowUp") {
view.phi = Math.max(0.42, view.phi - 0.06);
} else if (event.key === "ArrowDown") {
view.phi = Math.min(1.36, view.phi + 0.06);
} else {
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
document.querySelector("#zoomIn").addEventListener("click", () => {
view.zoom = Math.min(1.65, view.zoom * 1.12);
resize();
});
document.querySelector("#zoomOut").addEventListener("click", () => {
view.zoom = Math.max(0.68, view.zoom / 1.12);
resize();
});
document.querySelector("#reset").addEventListener("click", () => {
view.theta = defaultView.theta;
view.phi = defaultView.phi;
view.zoom = defaultView.zoom;
resize();
});
window.addEventListener("resize", resize);
// Gentle life in the otherwise quiet street scene.
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
shopper.position.y = 0.255 + Math.sin(elapsed * 1.45) * 0.006;
shopper.rotation.z = Math.sin(elapsed * 0.72) * 0.006;
renderer.render(scene, camera);
}
resize();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```