Prompt specification
Build or customize the Three.js 3D scene "Pedestrians and a shop beneath Jaipur's landmark facade" 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: Pedestrians and a shop beneath Jaipur's landmark facade
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/pedestrians-and-a-shop-beneath-jaipur-s-landmark-facad-x2990
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a low-poly street vignette beneath part of Jaipur's Hawa Mahal. Show a selective pink facade backdrop with tiered openings and projecting bays based on a reference, without trying to model the entire monument. At street level, add an original small shop, a shaded counter, folded fabric, and a narrow pedestrian strip. Two pedestrians stop at the shop while another continues along the frontage. Keep the ordinary commerce visually distinct from the architectural backdrop. Use an eye-level corner view with enough upward angle to show the facade layers. Treat the street arrangement as a stylized vignette rather than an exact surveyed reconstruction.
Working Three.js Starter (pedestrians-and-a-shop-beneath-jaipur-s-landmark-facad-x2990):
```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="#d2b19d">
<title>Hawa Mahal Street Vignette</title>
<style>
:root {
color-scheme: light;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d3bdab;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(48, 29, 29, 0.09), transparent 28%),
radial-gradient(
ellipse at center,
transparent 48%,
rgba(48, 28, 27, 0.18) 100%
);
mix-blend-mode: multiply;
}
.title-card {
position: fixed;
top: clamp(18px, 3vw, 36px);
left: clamp(18px, 3vw, 38px);
max-width: 360px;
pointer-events: none;
color: #4a2928;
text-shadow: 0 1px 0 rgba(255, 245, 229, 0.45);
}
.eyebrow {
margin: 0 0 7px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
opacity: 0.72;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 4vw, 48px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 0;
max-width: 310px;
font-size: 12px;
line-height: 1.45;
opacity: 0.72;
}
.controls {
position: fixed;
right: clamp(14px, 2.5vw, 30px);
bottom: clamp(14px, 2.5vw, 28px);
display: flex;
align-items: center;
gap: 10px;
padding: 9px 10px 9px 14px;
border: 1px solid rgba(73, 42, 39, 0.18);
border-radius: 999px;
color: #4c302d;
background: rgba(255, 244, 226, 0.68);
box-shadow: 0 8px 28px rgba(60, 37, 31, 0.12);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
font-size: 11px;
}
.controls span {
white-space: nowrap;
opacity: 0.76;
}
button {
appearance: none;
border: 0;
border-radius: 999px;
padding: 8px 12px;
color: #fff7e9;
background: #356b68;
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease;
}
button:hover {
background: #285a57;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
@media (max-width: 620px) {
.subtitle {
max-width: 250px;
}
.controls {
left: 14px;
right: 14px;
justify-content: space-between;
}
.controls span {
overflow: hidden;
text-overflow: ellipsis;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly Jaipur street scene"></canvas>
<div class="vignette"></div>
<header class="title-card">
<p class="eyebrow">Jaipur · A stylized street study</p>
<h1>Hawa Mahal<br>Corner</h1>
<p class="subtitle">
A selective pink facade, an everyday fabric kiosk, and a narrow strip
of pedestrian life.
</p>
</header>
<div class="controls">
<span>Drag to orbit · Wheel to zoom · Shift-drag to pan</span>
<button id="reset-view" type="button">Reset view</button>
</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 resetButton = document.querySelector("#reset-view");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd6c5b6);
scene.fog = new THREE.Fog(0xd6c5b6, 28, 65);
const camera = new THREE.PerspectiveCamera(
50,
innerWidth / innerHeight,
0.1,
120
);
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.08;
const clock = new THREE.Clock();
// ------------------------------------------------------------------
// Materials
// ------------------------------------------------------------------
function standardMaterial(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
metalness: 0,
flatShading: true,
...extra
});
}
const M = {
road: standardMaterial(0x88786c),
roadEdge: standardMaterial(0x6e625b),
pavement: standardMaterial(0xc4a48e),
pavementLight: standardMaterial(0xd2b49d),
curb: standardMaterial(0xe0c5ab),
grout: standardMaterial(0x9d806e),
facade: standardMaterial(0xcf7779),
facadeAlt: standardMaterial(0xdb8584),
facadeTrim: standardMaterial(0xedb0a2),
facadeLight: standardMaterial(0xf2c2ae),
facadeShadow: standardMaterial(0x9e545e),
recess: standardMaterial(0x53343d),
shopWall: standardMaterial(0xe2c79e),
shopSide: standardMaterial(0xc9874c),
teal: standardMaterial(0x276d70),
tealLight: standardMaterial(0x4c9290),
counterDark: standardMaterial(0x263f40),
brass: standardMaterial(0xb98949),
wood: standardMaterial(0x80513a),
cream: standardMaterial(0xf0dfbb),
skinA: standardMaterial(0x9a5c3d),
skinB: standardMaterial(0xb87850),
skinC: standardMaterial(0x754633),
hair: standardMaterial(0x292428),
saffron: standardMaterial(0xd47a2c),
indigo: standardMaterial(0x354d78),
coral: standardMaterial(0xbd5e56),
leaf: standardMaterial(0x536b42)
};
function meshBox(width, height, depth, material, x, y, z, parent = scene, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function meshCylinder(
radiusTop,
radiusBottom,
height,
segments,
material,
x,
y,
z,
parent = scene,
cast = true
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------------
// Lighting
// ------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xffe8cc, 0x665862, 1.8);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffd4a0, 3.5);
sun.position.set(-10, 20, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xaac6dc, 0.85);
fill.position.set(14, 8, -9);
scene.add(fill);
// ------------------------------------------------------------------
// Street and pavement
// ------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
M.road
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
// The pale pedestrian strip is intentionally narrow.
meshBox(34, 0.16, 4.25, M.pavement, 2, 0.08, 2.02, scene, false);
meshBox(34, 0.19, 0.23, M.curb, 2, 0.095, 4.23, scene, false);
meshBox(34, 0.025, 0.10, M.roadEdge, 2, 0.025, 4.39, scene, false);
// Sparse paving joints.
for (let x = -13; x <= 16; x += 2.15) {
meshBox(0.018, 0.012, 4.05, M.grout, x, 0.17, 2.02, scene, false);
}
for (const z of [0.72, 2.0, 3.32]) {
meshBox(33, 0.012, 0.018, M.grout, 2, 0.172, z, scene, false);
}
// A small drain and an irregular patch break up the road.
meshBox(0.92, 0.025, 0.34, M.roadEdge, 7.6, 0.025, 4.06, scene, false);
for (let i = 0; i < 6; i++) {
meshBox(0.07, 0.03, 0.28, M.brass, 7.25 + i * 0.14, 0.042, 4.06, scene, false);
}
const roadPatch = meshBox(1.7, 0.012, 0.75, M.roadEdge, -7.8, 0.018, 7.4, scene, false);
roadPatch.rotation.y = 0.22;
// ------------------------------------------------------------------
// Selective Hawa Mahal-inspired pink facade
//
// This is a deliberately partial, stylized facade section rather than
// a surveyed reconstruction: five tiers of arched openings, repeated
// projecting jharokha-like bays, deep pink recesses and small domes.
// ------------------------------------------------------------------
const facade = new THREE.Group();
facade.position.set(3.3, 0, -2.9);
scene.add(facade);
const facadeWidth = 18;
const storyHeight = 2.6;
const storyBases = [0.55, 3.35, 6.15, 8.95, 11.75];
const bayXs = [-6, -4, -2, 0, 2, 4, 6];
const openingBottom = 0.28;
const openingTop = 2.25;
const openingWidth = 0.98;
meshBox(18.7, 0.5, 1.2, M.facadeShadow, 0, 0.25, -0.05, facade);
function createFacetedPanel() {
const shape = new THREE.Shape();
shape.moveTo(-facadeWidth / 2, 0);
shape.lineTo(facadeWidth / 2, 0);
shape.lineTo(facadeWidth / 2, storyHeight);
shape.lineTo(-facadeWidth / 2, storyHeight);
shape.closePath();
for (const x of bayXs) {
const radius = openingWidth / 2;
const spring = openingTop - radius;
const hole = new THREE.Path();
hole.moveTo(x - radius, openingBottom);
hole.lineTo(x - radius, spring);
hole.absarc(x, spring, radius, Math.PI, 0, true);
hole.lineTo(x + radius, openingBottom);
hole.closePath();
shape.holes.push(hole);
}
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.55,
bevelEnabled: false,
curveSegments: 6
});
geometry.computeVertexNormals();
return geometry;
}
const panelGeometry = createFacetedPanel();
function addOpeningTrim(x, base, z = 0.61) {
const radius = openingWidth / 2;
const spring = openingTop - radius;
const arch = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.052, 4, 12, Math.PI),
M.facadeLight
);
arch.position.set(x, spring, z);
arch.castShadow = true;
facade.add(arch);
meshBox(
0.095,
spring - openingBottom,
0.105,
M.facadeLight,
x - radius,
(spring + openingBottom) / 2,
z,
facade
);
meshBox(
0.095,
spring - openingBottom,
0.105,
M.facadeLight,
x + radius,
(spring + openingBottom) / 2,
z,
facade
);
}
function addLattice(x, base, z = 0.61) {
const latticeBottom = base + 0.39;
const latticeTop = base + 1.83;
for (const offset of [-0.27, 0, 0.27]) {
meshBox(
0.045,
latticeTop - latticeBottom,
0.055,
M.facadeTrim,
x + offset,
(latticeTop + latticeBottom) / 2,
z,
facade,
false
);
}
for (const y of [0.76, 1.16, 1.56]) {
meshBox(
0.77,
0.04,
0.055,
M.facadeTrim,
x,
base + y,
z,
facade,
false
);
}
}
function addProjectingBay(x, base, central = false) {
if (central) {
// Wider central projection.
meshBox(2.55, 0.16, 1.65, M.facadeTrim, x, base + 0.13, 1.04, facade);
meshBox(2.72, 0.16, 1.76, M.facadeLight, x, base + 2.34, 1.04, facade);
meshBox(0.13, 2.08, 0.16, M.facadeTrim, x - 1.05, base + 1.18, 1.47, facade);
meshBox(0.13, 2.08, 0.16, M.facadeTrim, x + 1.05, base + 1.18, 1.47, facade);
meshBox(2.28, 0.08, 0.1, M.facadeLight, x, base + 0.49, 1.78, facade);
for (let i = -3; i <= 3; i++) {
meshBox(
0.055,
0.29,
0.055,
M.facadeTrim,
x + i * 0.32,
base + 0.31,
1.78,
facade,
false
);
}
addLattice(x, base, 1.38);
addOpeningTrim(x, base, 1.38);
} else {
// Smaller repeated bays.
meshBox(1.55, 0.13, 0.91, M.facadeTrim, x, base + 0.13, 0.82, facade);
meshBox(1.67, 0.15, 1.01, M.facadeLight, x, base + 2.34, 0.83, facade);
meshBox(0.105, 2.05, 0.13, M.facadeTrim, x - 0.69, base + 1.18, 1.08, facade);
meshBox(0.105, 2.05, 0.13, M.facadeTrim, x + 0.69, base + 1.18, 1.08, facade);
meshBox(1.35, 0.075, 0.09, M.facadeLight, x, base + 0.48, 1.2, facade);
for (let i = -2; i <= 2; i++) {
meshBox(
0.05,
0.27,
0.05,
M.facadeTrim,
x + i * 0.26,
base + 0.31,
1.2,
facade,
false
);
}
addLattice(x, base);
addOpeningTrim(x, base);
}
}
storyBases.forEach((base, storyIndex) => {
const wallMaterial = storyIndex % 2 ? M.facadeAlt : M.facade;
const panel = new THREE.Mesh(panelGeometry, wallMaterial);
panel.position.y = base;
panel.castShadow = true;
panel.receiveShadow = true;
facade.add(panel);
// A recessed dark backing makes each actual opening read as deep shade.
meshBox(
facadeWidth - 0.08,
storyHeight - 0.05,
0.08,
M.recess,
0,
base + storyHeight / 2,
-0.13,
facade,
false
);
meshBox(18.15, 0.16, 0.82, M.facadeTrim, 0, base - 0.08, 0.28, facade);
meshBox(18.35, 0.18, 0.94, M.facadeLight, 0, base + storyHeight, 0.3, facade);
bayXs.forEach((x) => {
addProjectingBay(x, base, Math.abs(x) < 0.001);
});
});
// Rooftop parapet and small low-poly domes.
meshBox(18.5, 0.28, 1.05, M.facadeShadow, 0, 14.43, 0.24, facade);
meshBox(18.7, 0.18, 1.12, M.facadeLight, 0, 14.64, 0.25, facade);
function addDome(x, y, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
facade.add(group);
meshCylinder(0.82, 0.9, 0.38, 8, M.facadeTrim, 0, 0.2, 0, group);
const domeGeometry = new THREE.SphereGeometry(
1,
10,
5,
0,
Math.PI * 2,
0,
Math.PI / 2
);
const dome = new THREE.Mesh(domeGeometry, M.facadeLight);
dome.scale.set(1.02, 0.66, 1.02);
dome.position.y = 0.39;
dome.castShadow = true;
group.add(dome);
meshCylinder(0.07, 0.1, 0.33, 6, M.brass, 0, 1.08, 0, group);
meshBox(0.11, 0.11, 0.11, M.brass, 0, 1.27, 0, group);
}
[-6, -3, 0, 3, 6].forEach((x, i) => {
addDome(x, 14.68, 0.28, i === 2 ? 1.25 : 0.92);
});
// ------------------------------------------------------------------
// Original small textile shop
// ------------------------------------------------------------------
const shop = new THREE.Group();
shop.position.set(-4.15, 0, 0);
scene.add(shop);
meshBox(5.25, 3.05, 2.8, M.shopWall, 0, 1.525, -1.5, shop);
// Distinct painted side and roof trim.
meshBox(0.12, 2.85, 2.62, M.shopSide, 2.63, 1.47, -1.5, shop);
meshBox(5.52, 0.22, 3.02, M.teal, 0, 3.12, -1.5, shop);
meshBox(5.64, 0.09, 3.08, M.brass, 0, 3.27, -1.5, shop);
// Recessed shop opening and counter.
meshBox(4.83, 1.55, 0.12, M.counterDark, -0.03, 1.05, -0.045, shop);
meshBox(4.9, 0.16, 0.91, M.wood, -0.03, 1.35, 0.34, shop);
meshBox(4.7, 0.78, 0.1, M.teal, -0.03, 0.75, 0.72, shop);
// Sign generated locally with CanvasTexture.
function makeShopSignTexture() {
const signCanvas = document.createElement("canvas");
signCanvas.width = 1024;
signCanvas.height = 256;
const ctx = signCanvas.getContext("2d");
ctx.fillStyle = "#245f61";
ctx.fillRect(0, 0, 1024, 256);
ctx.strokeStyle = "#d9a65a";
ctx.lineWidth = 10;
ctx.strokeRect(18, 18, 988, 220);
ctx.textAlign = "center";
ctx.fillStyle = "#f4dfb7";
ctx.font = "700 88px Georgia, serif";
ctx.fillText("KORA", 512, 117);
ctx.fillStyle = "#e7b06d";
ctx.font = "700 35px sans-serif";
ctx.letterSpacing = "7px";
ctx.fillText("FOLDED FABRIC", 512, 176);
const texture = new THREE.CanvasTexture(signCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const shopSign = new THREE.Mesh(
new THREE.PlaneGeometry(4.62, 0.83),
standardMaterial(0xffffff, { map: makeShopSignTexture() })
);
shopSign.position.set(-0.04, 2.78, -0.015);
shopSign.receiveShadow = true;
shop.add(shopSign);
// A striped, sloping awning makes the shaded counter immediately legible.
function makeAwningTexture() {
const awningCanvas = document.createElement("canvas");
awningCanvas.width = 768;
awningCanvas.height = 128;
const ctx = awningCanvas.getContext("2d");
const stripeWidth = 64;
for (let x = 0; x < 768; x += stripeWidth) {
ctx.fillStyle = (x / stripeWidth) % 2 ? "#d7973d" : "#ead9b4";
ctx.fillRect(x, 0, stripeWidth, 128);
}
ctx.fillStyle = "rgba(71,42,32,0.15)";
ctx.fillRect(0, 103, 768, 25);
const texture = new THREE.CanvasTexture(awningCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const awning = meshBox(
5.55,
0.12,
1.48,
standardMaterial(0xffffff, { map: makeAwningTexture() }),
-0.02,
2.38,
0.55,
shop
);
awning.rotation.x = 0.12;
meshBox(5.55, 0.12, 0.12, M.teal, -0.02, 2.31, 1.27, shop);
for (const x of [-2.64, 2.58]) {
meshCylinder(0.045, 0.045, 1.28, 8, M.brass, x, 1.81, 1.13, shop);
}
// Folded fabric stacks on the counter.
const fabricColors = [
M.saffron,
M.indigo,
M.tealLight,
M.coral,
M.cream,
standardMaterial(0x8e5c91)
];
function foldedFabric(x, y, z, material, width = 0.76, depth = 0.48) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = (Math.random() - 0.5) * 0.15;
shop.add(group);
for (let i = 0; i < 3; i++) {
const layer = meshBox(
width,
0.105,
depth,
i === 1 ? M.cream : material,
(i - 1) * 0.018,
i * 0.105,
0,
group
);
layer.rotation.y = (i - 1) * 0.025;
}
}
foldedFabric(-1.72, 1.45, 0.28, M.saffron);
foldedFabric(-0.92, 1.45, 0.32, M.indigo);
foldedFabric(-0.1, 1.45, 0.26, M.tealLight);
foldedFabric(0.72, 1.45, 0.3, M.coral);
foldedFabric(1.42, 1.45, 0.26, fabricColors[5], 0.64, 0.44);
// Bolts and a hanging cloth establish the shop as ordinary trade.
const boltColors = [M.saffron, M.indigo, M.coral, M.tealLight];
boltColors.forEach((material, i) => {
meshCylinder(
0.16,
0.18,
0.92,
8,
material,
1.93 + i * 0.18,
1.9,
-0.18,
shop
);
});
const hangingCloth = meshBox(
0.72,
1.15,
0.055,
M.coral,
2.29,
1.55,
0.1,
shop
);
hangingCloth.rotation.z = -0.025;
// Chalkboard leaning beside the counter.
function makeChalkTexture() {
const chalkCanvas = document.createElement("canvas");
chalkCanvas.width = 512;
chalkCanvas.height = 640;
const ctx = chalkCanvas.getContext("2d");
ctx.fillStyle = "#243c3b";
ctx.fillRect(0, 0, 512, 640);
ctx.strokeStyle = "#b88750";
ctx.lineWidth = 20;
ctx.strokeRect(14, 14, 484, 612);
ctx.textAlign = "center";
ctx.fillStyle = "#eadcb9";
ctx.font = "700 56px sans-serif";
ctx.fillText("TODAY", 256, 145);
ctx.font = "500 38px sans-serif";
ctx.fillText("COTTON", 256, 250);
ctx.fillText("SILK", 256, 310);
ctx.font = "700 64px Georgia, serif";
ctx.fillText("240", 256, 445);
ctx.font = "500 30px sans-serif";
ctx.fillText("per metre", 256, 500);
const texture = new THREE.CanvasTexture(chalkCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const chalkboard = new THREE.Group();
chalkboard.position.set(3.03, 0.72, 0.87);
chalkboard.rotation.y = -0.15;
chalkboard.rotation.x = -0.12;
shop.add(chalkboard);
meshBox(0.94, 1.23, 0.12, M.wood, 0, 0, 0, chalkboard);
const chalkFace = new THREE.Mesh(
new THREE.PlaneGeometry(0.82, 1.1),
standardMaterial(0xffffff, { map: makeChalkTexture() })
);
chalkFace.position.z = 0.067;
chalkboard.add(chalkFace);
// ------------------------------------------------------------------
// Low-poly pedestrians
// ------------------------------------------------------------------
function makePerson({
shirt = M.indigo,
lower = M.facadeShadow,
skin = M.skinA,
hair = M.hair,
skirt = false,
scale = 1
} = {}) {
const group = new THREE.Group();
group.scale.setScalar(scale);
const legs = [];
const arms = [];
for (const side of [-1, 1]) {
const legPivot = new THREE.Group();
legPivot.position.set(side * 0.115, 0.91, 0);
group.add(legPivot);
meshCylinder(
0.085,
0.10,
0.69,
6,
lower,
0,
-0.345,
0,
legPivot
);
meshBox(
0.19,
0.12,
0.31,
M.hair,
0,
-0.745,
0.07,
legPivot
);
legs.push(legPivot);
}
const torso = meshCylinder(
0.22,
skirt ? 0.34 : 0.27,
0.65,
7,
shirt,
0,
1.22,
0,
group
);
torso.scale.z = 0.72;
if (skirt) {
meshCylinder(
0.26,
0.37,
0.38,
8,
lower,
0,
0.88,
0,
group
);
}
meshCylinder(0.075, 0.08, 0.13, 7, skin, 0, 1.59, 0, group);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.205, 1),
skin
);
head.position.set(0, 1.76, 0);
head.scale.set(0.9, 1.08, 0.92);
head.castShadow = true;
group.add(head);
const hairCap = new THREE.Mesh(
new THREE.SphereGeometry(0.212, 8, 4, 0, Math.PI * 2, 0, Math.PI * 0.53),
hair
);
hairCap.position.set(0, 1.8, -0.018);
hairCap.scale.set(0.95, 0.92, 0.95);
hairCap.castShadow = true;
group.add(hairCap);
const nose = new THREE.Mesh(
new THREE.ConeGeometry(0.052, 0.115, 4),
skin
);
nose.rotation.x = Math.PI / 2;
nose.position.set(0, 1.75, 0.19);
group.add(nose);
for (const side of [-1, 1]) {
const armPivot = new THREE.Group();
armPivot.position.set(side * 0.285, 1.43, 0);
group.add(armPivot);
meshCylinder(
0.065,
0.075,
0.52,
6,
shirt,
0,
-0.25,
0,
armPivot
);
meshCylinder(
0.055,
0.06,
0.2,
6,
skin,
0,
-0.57,
0,
armPivot
);
arms.push(armPivot);
}
group.userData = {
legs,
arms,
head
};
return group;
}
// Shopper 1: warm kurta, facing the counter.
const shopperOne = makePerson({
shirt: M.saffron,
lower: M.indigo,
skin: M.skinB,
scale: 1.02
});
shopperOne.position.set(-5.05, 0.17, 1.38);
shopperOne.rotation.y = Math.PI - 0.12;
shopperOne.userData.arms[1].rotation.x = -0.58;
shopperOne.userData.arms[0].rotation.x = 0.15;
scene.add(shopperOne);
// Shopper 2: lighter clothes and a small shopping bag.
const shopperTwo = makePerson({
shirt: M.cream,
lower: M.coral,
skin: M.skinA,
hair: M.hair,
skirt: true,
scale: 0.95
});
shopperTwo.position.set(-3.12, 0.17, 1.53);
shopperTwo.rotation.y = Math.PI + 0.18;
shopperTwo.userData.arms[0].rotation.x = -0.28;
shopperTwo.userData.head.rotation.y = -0.15;
scene.add(shopperTwo);
const tote = meshBox(
0.3,
0.35,
0.12,
M.teal,
0.34,
0.73,
0.02,
shopperTwo
);
tote.rotation.z = -0.1;
// Passing pedestrian continues along the frontage.
const walker = makePerson({
shirt: M.tealLight,
lower: M.facadeShadow,
skin: M.skinC,
scale: 1.04
});
walker.position.set(5.8, 0.17, 2.68);
walker.rotation.y = Math.PI / 2;
scene.add(walker);
// ------------------------------------------------------------------
// Small street details
// ------------------------------------------------------------------
// A woven basket by the shop.
meshCylinder(0.31, 0.25, 0.42, 8, M.brass, 1.05, 0.37, -0.48, shop);
meshCylinder(0.33, 0.33, 0.06, 8, M.wood, 1.05, 0.61, -0.48, shop);
// A little plant beside the pavement edge.
meshCylinder(0.24, 0.19, 0.36, 7, M.coral, -8.0, 0.34, 2.9);
const plant = new THREE.Group();
plant.position.set(-8.0, 0.63, 2.9);
scene.add(plant);
for (let i = 0; i < 5; i++) {
const leaf = meshBox(
0.12,
0.5,
0.045,
M.leaf,
Math.sin(i * 1.7) * 0.12,
0.2 + (i % 2) * 0.05,
Math.cos(i * 1.7) * 0.1,
plant
);
leaf.rotation.z = Math.sin(i) * 0.55;
leaf.rotation.x = Math.cos(i) * 0.45;
}
// ------------------------------------------------------------------
// Camera controls implemented without addons
// ------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(-0.35, 5.75, -0.35);
const initialView = {
target: cameraTarget.clone(),
radius: 24,
theta: 0.55,
phi: 1.67
};
let cameraRadius = initialView.radius;
let cameraTheta = initialView.theta;
let cameraPhi = initialView.phi;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
updateCamera();
const pointers = new Map();
let dragState = null;
let pinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragState = {
x: event.clientX,
y: event.clientY,
pan: event.button === 2 || event.shiftKey
};
canvas.classList.add("dragging");
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0 && distance > 0) {
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * (pinchDistance / distance),
9,
38
);
updateCamera();
}
pinchDistance = distance;
return;
}
if (!dragState) return;
const dx = event.clientX - dragState.x;
const dy = event.clientY - dragState.y;
dragState.x = event.clientX;
dragState.y = event.clientY;
const shouldPan = dragState.pan || event.shiftKey;
if (shouldPan) {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(camera.quaternion);
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(camera.quaternion);
const panScale = cameraRadius * 0.00125;
cameraTarget.addScaledVector(right, -dx * panScale);
cameraTarget.addScaledVector(up, dy * panScale);
cameraTarget.y = THREE.MathUtils.clamp(cameraTarget.y, 1.3, 11.5);
} else {
cameraTheta -= dx * 0.005;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi + dy * 0.0045,
0.62,
1.69
);
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
dragState = null;
pinchDistance = 0;
canvas.classList.remove("dragging");
} else if (pointers.size === 1) {
const [remaining] = [...pointers.values()];
dragState = {
x: remaining.x,
y: remaining.y,
pan: false
};
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
9,
38
);
updateCamera();
},
{ passive: false }
);
function resetView() {
cameraTarget.copy(initialView.target);
cameraRadius = initialView.radius;
cameraTheta = initialView.theta;
cameraPhi = initialView.phi;
updateCamera();
}
resetButton.addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "arrowleft") cameraTheta += 0.08;
else if (key === "arrowright") cameraTheta -= 0.08;
else if (key === "arrowup") cameraPhi -= 0.05;
else if (key === "arrowdown") cameraPhi += 0.05;
else if (key === "+" || key === "=") cameraRadius -= 0.8;
else if (key === "-" || key === "_") cameraRadius += 0.8;
else if (key === "r") {
resetView();
return;
} else {
return;
}
cameraPhi = THREE.MathUtils.clamp(cameraPhi, 0.62, 1.69);
cameraRadius = THREE.MathUtils.clamp(cameraRadius, 9, 38);
updateCamera();
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
// ------------------------------------------------------------------
// Animation
// ------------------------------------------------------------------
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
// The passing pedestrian walks continuously along the frontage.
walker.position.x = -4.6 + ((elapsed * 0.72 + 10.4) % 24);
walker.position.y = 0.17 + Math.abs(Math.sin(elapsed * 5.2)) * 0.025;
const gait = Math.sin(elapsed * 5.2);
walker.userData.legs[0].rotation.x = gait * 0.52;
walker.userData.legs[1].rotation.x = -gait * 0.52;
walker.userData.arms[0].rotation.x = -gait * 0.42;
walker.userData.arms[1].rotation.x = gait * 0.42;
// Small, quiet movements distinguish the two people pausing at the shop.
shopperOne.rotation.z = Math.sin(elapsed * 1.1) * 0.006;
shopperTwo.userData.head.rotation.y =
-0.15 + Math.sin(elapsed * 0.55) * 0.06;
shopperTwo.userData.arms[0].rotation.x =
-0.28 + Math.sin(elapsed * 0.7) * 0.025;
hangingCloth.rotation.z = -0.025 + Math.sin(elapsed * 0.8) * 0.008;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```