Prompt specification
Build or customize the Three.js 3D scene "Pedestrian signal state model" 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: Pedestrian signal state model
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/pedestrian-signal-state-model-x0421
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a simplified crossing pole with distinct stop and walk symbols beside a miniature roadway; identify each state through shape as well as color. Stylized solid forms.
Working Three.js Starter (pedestrian-signal-state-model-x0421):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Crossing Pole — Stop / Walk</title>
<style>
html,body{margin:0;height:100%;overflow:hidden;background:#f2eee6;
font-family:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}
#app{position:fixed;inset:0}
canvas{display:block;touch-action:none}
.card{position:fixed;background:rgba(255,255,255,.86);border:1px solid rgba(0,0,0,.08);
border-radius:14px;box-shadow:0 10px 26px rgba(0,0,0,.10);padding:14px 16px}
#panel{left:16px;top:16px;max-width:290px}
#panel h1{margin:0 0 2px;font-size:15px;letter-spacing:.01em;color:#22252a}
#panel p{margin:0 0 11px;font-size:11.5px;color:#7d7d7d;line-height:1.35}
.row{display:flex;align-items:center;gap:10px;margin:8px 0}
.ico{width:30px;height:30px;flex:none;display:grid;place-items:center}
.ico svg{width:30px;height:30px;display:block}
.lbl{font-size:12.5px;color:#33343a;line-height:1.3}
.lbl b{font-weight:650}
.lbl span{display:block;font-size:10.5px;color:#8a8a8a}
.btns{display:flex;gap:8px;margin-top:12px}
button{font:inherit;font-size:11.5px;padding:7px 11px;border-radius:9px;cursor:pointer;
border:1px solid rgba(0,0,0,.14);background:#fff;color:#33343a;transition:.15s}
button:hover{background:#f2f2f0}
button.on{background:#2b2f36;color:#fff;border-color:#2b2f36}
#hint{right:16px;bottom:14px;font-size:11px;color:#8b8b8b;background:rgba(255,255,255,.7);
border-radius:9px;padding:6px 11px}
</style>
</head>
<body>
<div id="app"></div>
<div id="panel" class="card">
<h1>Crossing Pole — Stop & Walk</h1>
<p>Each state is coded twice: by <b>colour</b> and by <b>shape</b> (panel outline + pictogram).</p>
<div class="row">
<div class="ico">
<svg viewBox="0 0 40 40">
<polygon points="14,2 26,2 38,14 38,26 26,38 14,38 2,26 2,14" fill="#d8403a"/>
<g fill="#fff">
<rect x="13" y="16" width="14" height="12" rx="3"/>
<rect x="13" y="7" width="3.4" height="12" rx="1.7"/>
<rect x="17.4" y="4.5" width="3.4" height="14.5" rx="1.7"/>
<rect x="21.8" y="6" width="3.4" height="13" rx="1.7"/>
<rect x="26" y="9" width="3.4" height="10" rx="1.7"/>
<rect x="8" y="15" width="4" height="10" rx="2" transform="rotate(35 10 20)"/>
</g>
</svg>
</div>
<div class="lbl"><b>STOP</b><span>red octagon · raised hand</span></div>
</div>
<div class="row">
<div class="ico">
<svg viewBox="0 0 40 40">
<rect x="3" y="3" width="34" height="34" rx="5" fill="#21b573"/>
<g fill="#fff" stroke="#fff" stroke-linecap="round">
<circle cx="23" cy="8.5" r="4"/>
<line x1="20.5" y1="13" x2="18.5" y2="24" stroke-width="6"/>
<line x1="19.5" y1="15" x2="28" y2="19" stroke-width="3.4"/>
<line x1="18.5" y1="17" x2="11.5" y2="21" stroke-width="3.4"/>
<line x1="18.5" y1="24" x2="26" y2="31" stroke-width="4"/>
<line x1="18.5" y1="24" x2="12" y2="32" stroke-width="4"/>
<line x1="26" y1="31" x2="30" y2="31" stroke-width="3"/>
</g>
</svg>
</div>
<div class="lbl"><b>WALK</b><span>green square · walking person</span></div>
</div>
<div class="btns">
<button id="mono">Shape only (grey)</button>
<button id="reset">Reset view</button>
</div>
</div>
<div id="hint" class="card">drag · orbit | wheel · zoom | double-click · reset</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ─────────────────────────── renderer / scene ─────────────────────────── */
const renderer = new THREE.WebGLRenderer({ antialias:true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
document.getElementById('app').appendChild(renderer.domElement);
const scene = new THREE.Scene();
const bgColor = new THREE.Color(0xf2eee6);
scene.background = bgColor.clone();
const camera = new THREE.PerspectiveCamera(42, innerWidth/innerHeight, 0.1, 220);
/* ─────────────────────────── material registry ────────────────────────── */
const tracked = [];
function M(color, opts = {}){
const m = new THREE.MeshStandardMaterial({ color, roughness:0.85, metalness:0.0, ...opts });
m.userData.base = m.color.clone();
tracked.push(m);
return m;
}
const C = {
sand: M(0xe4dac7),
plinth: M(0xc9bda9),
grass: M(0x9dc97c),
walk: M(0xd3cec4),
curb: M(0xbdb6a8),
road: M(0x4d5259),
paint: M(0xf6f4ec),
yellow: M(0xe8bb3a),
steel: M(0x9aa4ad,{roughness:0.42,metalness:0.35}),
charcoal:M(0x3a3f47,{roughness:0.55}),
dark: M(0x24272c),
red: M(0xd8403a,{roughness:0.6}),
green: M(0x21b573,{roughness:0.6}),
white: M(0xfbfaf7,{roughness:0.7}),
car: M(0xe2673c),
glass: M(0x39485a,{roughness:0.25,metalness:0.1}),
tire: M(0x26282c,{roughness:0.95}),
leaf: M(0x6fae63),
leaf2: M(0x5b9c54),
bark: M(0x8a6a4a),
jacket: M(0x4a7fb5),
pants: M(0x39404d),
skin: M(0xe8b98f)
};
/* ─────────────────────────── shape helpers ────────────────────────────── */
function roundedRect(w,h,r){
r = Math.min(r, w/2, h/2);
const s = new THREE.Shape(), x = -w/2, y = -h/2;
s.moveTo(x+r, y);
s.lineTo(x+w-r, y); s.quadraticCurveTo(x+w, y, x+w, y+r);
s.lineTo(x+w, y+h-r); s.quadraticCurveTo(x+w, y+h, x+w-r, y+h);
s.lineTo(x+r, y+h); s.quadraticCurveTo(x, y+h, x, y+h-r);
s.lineTo(x, y+r); s.quadraticCurveTo(x, y, x+r, y);
return s;
}
const stadium = (len,w) => roundedRect(len, w, w/2);
function circleShape(r){ const s = new THREE.Shape(); s.moveTo(r,0); s.absarc(0,0,r,0,Math.PI*2,false); return s; }
function octagonShape(r){
const s = new THREE.Shape();
for(let i=0;i<8;i++){
const a = Math.PI/8 + i*Math.PI/4;
const x = Math.cos(a)*r, y = Math.sin(a)*r;
i ? s.lineTo(x,y) : s.moveTo(x,y);
}
s.closePath(); return s;
}
function plate(shape, depth, mat, z = 0){
const geo = new THREE.ExtrudeGeometry(shape, { depth, bevelEnabled:false, curveSegments:28 });
const m = new THREE.Mesh(geo, mat);
m.position.z = z; m.castShadow = true; m.receiveShadow = true;
return m;
}
function box(w,h,d,mat,x=0,y=0,z=0){
const m = new THREE.Mesh(new THREE.BoxGeometry(w,h,d), mat);
m.position.set(x,y,z); m.castShadow = true; m.receiveShadow = true; return m;
}
function cyl(rt,rb,h,mat,x=0,y=0,z=0,seg=28){
const m = new THREE.Mesh(new THREE.CylinderGeometry(rt,rb,h,seg), mat);
m.position.set(x,y,z); m.castShadow = true; m.receiveShadow = true; return m;
}
/* ─────────────────────────── pictograms ──────────────────────────────── */
// raised open hand (STOP)
function makeHand(){
const g = new THREE.Group(), w = C.white;
const palm = plate(roundedRect(0.21,0.23,0.055),0.03,w,0);
palm.position.set(0,-0.06,0);
g.add(palm);
const fingers = [[-0.075,0.155],[-0.025,0.178],[0.025,0.165],[0.072,0.138]];
for(const [x,h] of fingers){
const f = plate(roundedRect(0.05,h,0.025),0.03,w,0);
f.position.set(x, 0.05 + h/2 - 0.015, 0); g.add(f);
}
const thumb = plate(stadium(0.145,0.055),0.03,w,0);
thumb.position.set(-0.148,0.005,0); thumb.rotation.z = Math.PI*0.30; g.add(thumb);
const cuff = plate(roundedRect(0.20,0.07,0.02),0.03,w,0);
cuff.position.set(0,-0.205,0); g.add(cuff);
return g;
}
// walking person (WALK)
function makeWalker(){
const g = new THREE.Group(), w = C.white;
const seg = (a,b,t)=>{
const len = Math.hypot(b[0]-a[0], b[1]-a[1]);
const m = plate(stadium(len,t),0.03,w,0);
m.position.set((a[0]+b[0])/2,(a[1]+b[1])/2,0);
m.rotation.z = Math.atan2(b[1]-a[1], b[0]-a[0]);
g.add(m);
};
seg([-0.02,0.16],[0.01,-0.02],0.105); // torso
const head = plate(circleShape(0.076),0.03,w,0);
head.position.set(0.075,0.255,0); g.add(head); // head
seg([0.00,0.14],[0.17,0.03],0.05); // front arm
seg([-0.02,0.13],[-0.16,0.02],0.05); // back arm
seg([-0.02,-0.01],[0.12,-0.13],0.065); // front thigh
seg([0.12,-0.13],[0.17,-0.28],0.055); // front shin
seg([-0.02,-0.01],[-0.13,-0.11],0.065); // back thigh
seg([-0.13,-0.11],[-0.07,-0.27],0.055); // back shin
seg([0.17,-0.28],[0.245,-0.285],0.04); // front foot
seg([-0.07,-0.27],[-0.145,-0.245],0.04); // back foot
return g;
}
/* ─────────────────────────── miniature roadway ────────────────────────── */
const ground = box(26, 0.7, 13, C.sand, 0, -0.35, 0); // diorama slab
const plinth = box(26.8, 0.22, 13.8, C.plinth, 0, -0.8, 0); // display rim
scene.add(ground, plinth);
scene.add(box(26, 0.12, 3.2, C.grass, 0, 0.06, 4.4)); // grass bands
scene.add(box(26, 0.12, 3.2, C.grass, 0, 0.06, -4.4));
scene.add(box(26, 0.20, 1.5, C.walk, 0, 0.10, 2.05)); // pavements
scene.add(box(26, 0.20, 1.5, C.walk, 0, 0.10, -2.05));
scene.add(box(26, 0.06, 2.6, C.road, 0, 0.03, 0)); // carriageway
scene.add(box(26, 0.30, 0.16, C.curb, 0, 0.15, 1.32)); // kerbs
scene.add(box(26, 0.30, 0.16, C.curb, 0, 0.15, -1.32));
// lane edge lines
scene.add(box(26, 0.02, 0.09, C.paint, 0, 0.065, 1.22));
scene.add(box(26, 0.02, 0.09, C.paint, 0, 0.065, -1.22));
// centre dashes (skip the crossing zone)
for(let x = -11.5; x < -1.0; x += 2.4) scene.add(box(1.15, 0.02, 0.12, C.yellow, x, 0.065, 0));
for(let x = 5.2; x < 12; x += 2.4) scene.add(box(1.15, 0.02, 0.12, C.yellow, x, 0.065, 0));
// zebra crossing
for(let i = 0; i < 5; i++) scene.add(box(0.55, 0.02, 2.5, C.paint, 0.85 + i*0.92, 0.065, 0));
/* ─────────────────────────── crossing pole ───────────────────────────── */
const signal = new THREE.Group();
signal.position.set(2.2, 0, 2.05);
signal.rotation.y = 0.42;
scene.add(signal);
signal.add(cyl(0.32,0.37,0.09, C.dark, 0, 0.245, 0)); // base plate
signal.add(cyl(0.19,0.23,0.28, C.dark, 0, 0.43, 0)); // collar
signal.add(cyl(0.115,0.14,4.0, C.steel, 0, 2.26, 0)); // mast
signal.add(box(0.44, 2.65, 0.12, C.charcoal, 0, 3.05, -0.06)); // backplate
signal.add(box(0.78, 0.07, 0.44, C.charcoal, 0, 4.29, 0.13)); // rain hood
// ── STOP head: octagonal bezel + octagonal red face + hand
const stopHead = new THREE.Group();
stopHead.position.set(0, 3.66, 0);
signal.add(stopHead);
stopHead.add(plate(octagonShape(0.58), 0.28, C.charcoal, 0));
stopHead.add(plate(octagonShape(0.47), 0.04, C.red, 0.28));
stopHead.add(plate(octagonShape(0.415),0.03, C.white, 0.32));
stopHead.add(plate(octagonShape(0.365),0.03, C.red, 0.35));
const hand = makeHand(); hand.position.z = 0.38; stopHead.add(hand);
// ── WALK head: square bezel + square green face + walker
const walkHead = new THREE.Group();
walkHead.position.set(0, 2.40, 0);
signal.add(walkHead);
walkHead.add(plate(roundedRect(1.02,1.02,0.13), 0.28, C.charcoal, 0));
walkHead.add(plate(roundedRect(0.94,0.94,0.10), 0.05, C.white, 0.28));
walkHead.add(plate(roundedRect(0.84,0.84,0.08), 0.05, C.green, 0.33));
const walker = makeWalker(); walker.position.z = 0.38; walkHead.add(walker);
/* ─────────────────────────── props ───────────────────────────────────── */
// car
const car = new THREE.Group(); car.position.set(-6.2, 0.06, 0); scene.add(car);
car.add(box(1.95, 0.52, 0.98, C.car, 0, 0.42, 0));
car.add(box(1.02, 0.48, 0.86, C.car, 0.02, 0.88, 0));
car.add(box(0.86, 0.30, 0.90, C.glass, 0.02, 0.92, 0));
car.add(box(0.90, 0.16, 0.92, C.car, 0.02, 1.10, 0));
for(const [x,z] of [[0.62,0.52],[0.62,-0.52],[-0.62,0.52],[-0.62,-0.52]]){
const wh = new THREE.Mesh(new THREE.CylinderGeometry(0.27,0.27,0.22,20), C.tire);
wh.rotation.x = Math.PI/2; wh.position.set(x,0.27,z); wh.castShadow = true; car.add(wh);
}
car.add(box(0.12,0.14,0.16, C.paint, 0.99, 0.52, 0.28));
car.add(box(0.12,0.14,0.16, C.paint, 0.99, 0.52,-0.28));
// trees
function tree(x,z,s=1){
const t = new THREE.Group(); t.position.set(x,0.12,z); t.scale.setScalar(s); scene.add(t);
t.add(cyl(0.13,0.18,1.05, C.bark, 0, 0.52, 0));
const a = new THREE.Mesh(new THREE.IcosahedronGeometry(0.92,1), C.leaf);
a.position.y = 1.75; a.castShadow = true; t.add(a);
const b = new THREE.Mesh(new THREE.IcosahedronGeometry(0.66,1), C.leaf2);
b.position.set(0.42,1.42,0.2); b.castShadow = true; t.add(b);
}
tree(-4.6, 4.55, 1.0);
tree(8.4, -4.7, 1.25);
tree(-9.6,-4.5, 0.85);
// waiting pedestrian
const ped = new THREE.Group(); ped.position.set(3.75, 0.20, 2.35); scene.add(ped);
ped.add(cyl(0.115,0.115,0.52, C.jacket, 0, 0.72, 0));
const ph = new THREE.Mesh(new THREE.SphereGeometry(0.135,18,14), C.skin);
ph.position.y = 1.10; ph.castShadow = true; ped.add(ph);
ped.add(cyl(0.055,0.05,0.46, C.pants, -0.06, 0.25, 0));
ped.add(cyl(0.055,0.05,0.46, C.pants, 0.06, 0.25, 0));
// bollards
for(const x of [-1.2, 0.2]){
const b = cyl(0.085,0.095,0.72, C.charcoal, x, 0.56, 2.62);
scene.add(b);
}
/* ─────────────────────────── lighting ────────────────────────────────── */
scene.add(new THREE.HemisphereLight(0xffffff, 0xbfae90, 0.95));
const sun = new THREE.DirectionalLight(0xfff4e2, 1.7);
sun.position.set(9, 13, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18; sun.shadow.camera.right = 18;
sun.shadow.camera.top = 16; sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1; sun.shadow.camera.far = 50;
sun.shadow.bias = -0.0006; sun.shadow.normalBias = 0.02;
scene.add(sun);
/* ─────────────────────────── camera controls (hand rolled) ────────────── */
const target = new THREE.Vector3(0.2, 1.35, 0.2);
const sph = new THREE.Spherical(19.5, Math.PI*0.36, Math.PI*0.30);
function applyCamera(){
sph.phi = THREE.MathUtils.clamp(sph.phi, 0.18, 1.44);
sph.radius = THREE.MathUtils.clamp(sph.radius, 8, 38);
camera.position.setFromSpherical(sph).add(target);
camera.lookAt(target);
}
applyCamera();
let dragging = false, lx = 0, ly = 0;
const el = renderer.domElement;
el.addEventListener('pointerdown', e => { dragging = true; lx = e.clientX; ly = e.clientY; el.setPointerCapture(e.pointerId); });
el.addEventListener('pointermove', e => {
if(!dragging) return;
sph.theta -= (e.clientX - lx) * 0.006;
sph.phi -= (e.clientY - ly) * 0.005;
lx = e.clientX; ly = e.clientY; applyCamera();
});
el.addEventListener('pointerup', e => { dragging = false; });
el.addEventListener('pointercancel', e => { dragging = false; });
el.addEventListener('wheel', e => { e.preventDefault(); sph.radius *= 1 + e.deltaY*0.0011; applyCamera(); }, {passive:false});
el.addEventListener('dblclick', () => { sph.set(19.5, Math.PI*0.36, Math.PI*0.30); applyCamera(); });
/* ─────────────────────────── grey "shape only" mode ───────────────────── */
let mono = false;
const monoBtn = document.getElementById('mono');
function toGrey(c){
const l = 0.2126*c.r + 0.7152*c.g + 0.0722*c.b;
return new THREE.Color().setRGB(l, l, l);
}
monoBtn.addEventListener('click', () => {
mono = !mono;
monoBtn.classList.toggle('on', mono);
for(const m of tracked) m.color.copy(mono ? toGrey(m.userData.base) : m.userData.base);
scene.background.copy(mono ? toGrey(bgColor) : bgColor);
});
document.getElementById('reset').addEventListener('click', () => {
sph.set(19.5, Math.PI*0.36, Math.PI*0.30); applyCamera();
});
/* ─────────────────────────── resize + loop ───────────────────────────── */
addEventListener('resize', () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
renderer.setAnimationLoop(() => renderer.render(scene, camera));
</script>
</body>
</html>
```
**How the two states are distinguished**
| State | Colour | Panel outline | Pictogram |
|---|---|---|---|
| STOP | red | **octagon** | raised open hand |
| WALK | green | **square** | walking person |
Each aspect sits in its own bezel (an octagonal housing above, a square housing below) on a single mast beside a miniature diorama roadway with kerbs, pavements, zebra crossing, lane markings, a car, trees and a waiting pedestrian. The **"Shape only (grey)"** button strips all colour so the two states remain legible purely by outline and pictogram.
Everything is built from extruded `THREE.Shape`s, boxes and cylinders for the stylized solid look, and the orbit/zoom camera is implemented directly in the file — no addons or example scripts are loaded.
```