Prompt specification
Build or customize the Three.js 3D scene "Protected Cycle Lane Junction Module" 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: Protected Cycle Lane Junction Module
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/protected-cycle-lane-junction-module-x2089
Scene Description Prompt:
Use Three.js from cdnjs to model a short cycle lane with a physical separator and one crossing transition. Make the route continuous and distinguish the riding surface from the sidewalk. Deliver one self-contained HTML file with stylized solid shapes.
Working Three.js Starter (protected-cycle-lane-junction-module-x2089):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Protected Cycle Lane</title>
<style>
:root {
--ink: #17343a;
--panel: rgba(248, 250, 246, 0.9);
--teal: #16b7a0;
--orange: #f0a15b;
--sidewalk: #d8d4c7;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dfe8e3;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--ink);
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.panel {
position: fixed;
top: 22px;
left: 22px;
z-index: 5;
width: min(330px, calc(100vw - 44px));
padding: 19px 20px 17px;
border: 1px solid rgba(23, 52, 58, 0.12);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 14px 40px rgba(36, 65, 68, 0.14);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 5px;
color: #668087;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0 0 7px;
font-size: 25px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.subtitle {
margin: 0;
color: #5d7378;
font-size: 13px;
line-height: 1.45;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px 14px;
margin-top: 16px;
padding-top: 14px;
border-top: 1px solid rgba(23, 52, 58, 0.11);
font-size: 12px;
font-weight: 650;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
white-space: nowrap;
}
.swatch {
width: 14px;
height: 14px;
flex: 0 0 auto;
border: 1px solid rgba(23, 52, 58, 0.12);
border-radius: 4px;
}
.controls {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 6;
display: flex;
gap: 8px;
}
button {
min-height: 38px;
padding: 0 14px;
border: 1px solid rgba(23, 52, 58, 0.14);
border-radius: 11px;
background: rgba(248, 250, 246, 0.92);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 8px 25px rgba(36, 65, 68, 0.12);
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
transform: translateY(-2px);
background: #fff;
}
.hint {
position: fixed;
left: 22px;
bottom: 22px;
z-index: 5;
padding: 9px 12px;
border-radius: 10px;
background: rgba(248, 250, 246, 0.78);
color: #60777c;
font-size: 11px;
font-weight: 650;
pointer-events: none;
}
.world-label {
position: fixed;
z-index: 4;
padding: 6px 9px;
border: 1px solid rgba(23, 52, 58, 0.14);
border-radius: 8px;
background: rgba(250, 251, 247, 0.88);
color: #28474d;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -130%);
pointer-events: none;
box-shadow: 0 5px 18px rgba(36, 65, 68, 0.1);
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 14px;
background: rgba(23, 52, 58, 0.38);
}
@media (max-width: 700px) {
.panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
h1 { font-size: 21px; }
.subtitle { font-size: 12px; }
.legend { margin-top: 11px; padding-top: 11px; }
.controls { right: 12px; bottom: 12px; }
.hint { display: none; }
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive three-dimensional model of a protected cycle lane"></div>
<section class="panel">
<div class="eyebrow">Urban Mobility Study</div>
<h1>Protected Cycle Lane</h1>
<p class="subtitle">A continuous teal riding surface follows the curb, crosses one side street, and reconnects beyond the crossing.</p>
<div class="legend" aria-label="Material legend">
<div class="legend-item">
<span class="swatch" style="background:#16b7a0"></span>
Riding surface
</div>
<div class="legend-item">
<span class="swatch" style="background:#f0a15b"></span>
Crossing transition
</div>
<div class="legend-item">
<span class="swatch" style="background:#d8d4c7"></span>
Sidewalk
</div>
<div class="legend-item">
<span class="swatch" style="background:#f2eee2"></span>
Physical separator
</div>
</div>
</section>
<div class="hint">Drag to orbit · Scroll or pinch to zoom</div>
<div class="controls">
<button id="resetView" type="button">Reset view</button>
<button id="topView" type="button">Top view</button>
</div>
<div id="crossingLabel" class="world-label">Crossing transition</div>
<div id="sidewalkLabel" class="world-label">Raised sidewalk</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const mount = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dfe8e3");
scene.fog = new THREE.Fog("#dfe8e3", 34, 58);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, 0.2, 0);
const desired = {
theta: 0.72,
phi: 0.84,
radius: 24
};
const current = {
theta: desired.theta,
phi: desired.phi,
radius: desired.radius
};
function updateCamera() {
const sinPhi = Math.sin(current.phi);
camera.position.set(
target.x + current.radius * sinPhi * Math.sin(current.theta),
target.y + current.radius * Math.cos(current.phi),
target.z + current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight("#f6fff8", "#7a8a82", 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff6dc", 3.15);
sun.position.set(9, 16, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.00035;
scene.add(sun);
const material = (color, roughness = 0.8, metalness = 0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const materials = {
base: material("#c9d3c7", 0.95),
asphalt: material("#4b5960", 0.98),
crossRoad: material("#536269", 0.98),
sidewalk: material("#d8d4c7", 0.93),
pavingSeam: material("#c2beb3", 0.96),
curb: material("#eeeade", 0.9),
lane: material("#16b7a0", 0.72),
transition: material("#f0a15b", 0.72),
separator: material("#f2eee2", 0.82),
separatorFoot: material("#526168", 0.9),
reflector: material("#ff654a", 0.48),
marking: material("#f8f2df", 0.85),
yellow: material("#efd071", 0.83),
trunk: material("#886448", 0.95),
leafA: material("#4e8e67", 0.93),
leafB: material("#75aa78", 0.92),
leafC: material("#3f7658", 0.94),
bench: material("#b77c4d", 0.84),
metal: material("#46575e", 0.52, 0.28),
planter: material("#9d9b8f", 0.95)
};
function box(width, height, depth, mat, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, mat, parent = scene, radialSegments = 8) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = new THREE.Vector3().subVectors(end, start);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), radialSegments),
mat
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
function flatBar(x1, z1, x2, z2, width, mat, y, parent = scene) {
const dx = x2 - x1;
const dz = z2 - z1;
const length = Math.hypot(dx, dz);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.025, width),
mat
);
mesh.position.set((x1 + x2) / 2, y, (z1 + z2) / 2);
mesh.rotation.y = -Math.atan2(dz, dx);
mesh.castShadow = false;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Raised model base.
box(19.8, 0.6, 19.8, materials.base, 0, -0.43, 0);
// Main north-south road and the single east-west crossing street.
box(10, 0.14, 18.4, materials.asphalt, 0, -0.02, 0);
box(19.2, 0.15, 3.2, materials.crossRoad, 0, -0.005, 0);
// Four raised sidewalk blocks, split by the cross street.
const sidewalkCenters = [-5.35, 5.35];
const sidewalkSides = [-6.45, 6.45];
for (const x of sidewalkSides) {
for (const z of sidewalkCenters) {
box(2.9, 0.31, 7.4, materials.sidewalk, x, 0.035, z);
// Fine paving seams distinguish the pedestrian surface.
for (const seamZ of [z - 2.7, z - 1.35, z, z + 1.35, z + 2.7]) {
box(2.76, 0.012, 0.025, materials.pavingSeam, x, 0.196, seamZ);
}
box(0.025, 0.012, 7.15, materials.pavingSeam, x, 0.196, z);
}
}
// Curbs along the main road, omitted at the crossing.
for (const x of [-5.06, 5.06]) {
for (const z of sidewalkCenters) {
box(0.22, 0.42, 7.15, materials.curb, x, 0.11, z);
}
}
// Cross-street edge curbs on the outer sidewalk blocks.
for (const x of sidewalkSides) {
for (const z of [-1.67, 1.67]) {
box(2.85, 0.39, 0.18, materials.curb, x, 0.095, z);
}
}
// Continuous riding surface: teal before and after one amber crossing.
const laneX = -4.05;
const laneWidth = 1.75;
box(laneWidth, 0.08, 7.2, materials.lane, laneX, 0.105, -5.2);
box(laneWidth, 0.08, 3.2, materials.transition, laneX, 0.105, 0);
box(laneWidth, 0.08, 7.2, materials.lane, laneX, 0.105, 5.2);
// Fine white edge lines keep the riding surface visually distinct.
for (const x of [laneX - laneWidth / 2 + 0.08, laneX + laneWidth / 2 - 0.08]) {
box(0.045, 0.025, 7.05, materials.marking, x, 0.158, -5.2);
box(0.045, 0.025, 3.05, materials.marking, x, 0.158, 0);
box(0.045, 0.025, 7.05, materials.marking, x, 0.158, 5.2);
}
// Physical separator: modular raised blocks on the road side.
// The separator deliberately stops at the crossing transition.
function addSeparatorRun(startZ, endZ) {
const total = endZ - startZ;
const count = 5;
const gap = 0.24;
const blockLength = (total - gap * (count - 1)) / count;
for (let i = 0; i < count; i++) {
const z = startZ + blockLength / 2 + i * (blockLength + gap);
box(
0.44, 0.055, blockLength + 0.06,
materials.separatorFoot,
-2.96, 0.085, z
);
box(
0.30, 0.34, blockLength,
materials.separator,
-2.96, 0.255, z
);
box(
0.026, 0.11, Math.min(0.30, blockLength * 0.45),
materials.reflector,
-2.797, 0.285, z
);
}
}
addSeparatorRun(-8.35, -2.08);
addSeparatorRun(2.08, 8.35);
// Main-road center dashes.
for (const z of [-7.4, -5.4, -3.4, 3.4, 5.4, 7.4]) {
box(0.12, 0.02, 0.92, materials.yellow, 0, 0.073, z);
}
// Cross-street markings outside the main road.
for (const x of [-8.45, -6.95, 6.95, 8.45]) {
box(0.88, 0.02, 0.11, materials.marking, x, 0.085, 0);
}
// Direction chevrons on the transition.
for (const z of [-0.75, 0, 0.75]) {
flatBar(laneX - 0.29, z - 0.14, laneX, z + 0.18, 0.075, materials.marking, 0.17);
flatBar(laneX, z + 0.18, laneX + 0.29, z - 0.14, 0.075, materials.marking, 0.17);
}
// Stylized bicycle symbols painted on the riding surface.
function addBicycleSymbol(z, scale = 1) {
const group = new THREE.Group();
group.position.set(laneX, 0.176, z);
group.scale.setScalar(scale);
scene.add(group);
const wheelGeometry = new THREE.TorusGeometry(0.27, 0.035, 6, 24);
for (const wheelZ of [-0.42, 0.42]) {
const wheel = new THREE.Mesh(wheelGeometry, materials.marking);
wheel.rotation.x = Math.PI / 2;
wheel.position.z = wheelZ;
group.add(wheel);
}
const rear = [0, 0, -0.42];
const front = [0, 0, 0.42];
const crank = [-0.02, 0, -0.04];
const seat = [-0.03, 0, 0.20];
const handle = [0.04, 0, 0.35];
cylinderBetween(rear, seat, 0.026, materials.marking, group, 6);
cylinderBetween(rear, crank, 0.026, materials.marking, group, 6);
cylinderBetween(crank, seat, 0.026, materials.marking, group, 6);
cylinderBetween(seat, handle, 0.026, materials.marking, group, 6);
cylinderBetween(crank, handle, 0.026, materials.marking, group, 6);
cylinderBetween(handle, front, 0.026, materials.marking, group, 6);
box(0.18, 0.025, 0.07, materials.marking, -0.035, 0.015, 0.22, group);
box(0.26, 0.025, 0.055, materials.marking, 0.04, 0.015, 0.39, group);
}
addBicycleSymbol(-5.75, 0.9);
addBicycleSymbol(5.75, 0.9);
function addTree(x, z, variant = 0) {
const group = new THREE.Group();
group.position.set(x, 0.19, z);
scene.add(group);
const planter = new THREE.Mesh(
new THREE.CylinderGeometry(0.62, 0.68, 0.23, 12),
materials.planter
);
planter.position.y = 0.115;
planter.castShadow = true;
planter.receiveShadow = true;
group.add(planter);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.18, 1.45, 8),
materials.trunk
);
trunk.position.y = 0.88;
trunk.castShadow = true;
group.add(trunk);
const crownMaterials = [materials.leafA, materials.leafB, materials.leafC];
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.82, 1),
crownMaterials[variant % crownMaterials.length]
);
crown.position.y = 2.0;
crown.scale.set(0.95, 1.15, 0.95);
crown.castShadow = true;
group.add(crown);
const top = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.53, 1),
crownMaterials[(variant + 1) % crownMaterials.length]
);
top.position.set(0.23, 2.53, -0.12);
top.castShadow = true;
group.add(top);
}
addTree(-6.65, -6.55, 0);
addTree(-6.65, 6.65, 1);
addTree(6.65, -6.55, 2);
addTree(6.65, 6.65, 0);
function addBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.19, z);
group.rotation.y = rotation;
scene.add(group);
box(1.55, 0.12, 0.42, materials.bench, 0, 0.56, 0, group);
box(1.55, 0.40, 0.10, materials.bench, 0, 0.86, -0.18, group);
for (const legX of [-0.56, 0.56]) {
box(0.09, 0.52, 0.09, materials.metal, legX, 0.26, 0, group);
box(0.09, 0.68, 0.09, materials.metal, legX, 0.52, -0.16, group);
}
}
addBench(6.22, -3.2, Math.PI / 2);
addBench(6.22, 3.1, Math.PI / 2);
addBench(-6.22, 3.2, Math.PI / 2);
// A few simple street lights add scale without distracting from the route.
function addLamp(x, z) {
const group = new THREE.Group();
group.position.set(x, 0.19, z);
scene.add(group);
cylinderBetween([0, 0, 0], [0, 2.65, 0], 0.055, materials.metal, group, 8);
cylinderBetween([0, 2.65, 0], [0.44, 2.88, 0], 0.05, materials.metal, group, 8);
const light = new THREE.Mesh(
new THREE.SphereGeometry(0.16, 12, 8),
materials.marking
);
light.position.set(0.47, 2.84, 0);
light.castShadow = true;
group.add(light);
}
addLamp(-7.35, -2.6);
addLamp(7.35, 2.6);
// Project HTML labels directly from scene positions.
const labels = [
{
element: document.getElementById("crossingLabel"),
position: new THREE.Vector3(-4.05, 0.42, 0)
},
{
element: document.getElementById("sidewalkLabel"),
position: new THREE.Vector3(6.45, 0.65, -2.8)
}
];
function updateLabels() {
const width = renderer.domElement.clientWidth;
const height = renderer.domElement.clientHeight;
for (const label of labels) {
const projected = label.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.opacity = visible ? "1" : "0";
label.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
// Direct camera controls: orbit, wheel zoom, and pinch zoom.
const pointers = new Map();
let lastX = 0;
let lastY = 0;
let pinchDistance = 0;
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
lastX = event.clientX;
lastY = event.clientY;
} else if (pointers.size === 2) {
const values = [...pointers.values()];
pinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
desired.theta -= dx * 0.006;
desired.phi = clamp(desired.phi - dy * 0.005, 0.08, 1.40);
lastX = event.clientX;
lastY = event.clientY;
} else if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (pinchDistance > 0) {
desired.radius = clamp(
desired.radius * (pinchDistance / distance),
12,
36
);
}
pinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
desired.radius = clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
12,
36
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
desired.theta = 0.72;
desired.phi = 0.84;
desired.radius = 24;
});
document.getElementById("resetView").addEventListener("click", () => {
desired.theta = 0.72;
desired.phi = 0.84;
desired.radius = 24;
});
document.getElementById("topView").addEventListener("click", () => {
desired.theta = 0;
desired.phi = 0.08;
desired.radius = 25;
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
function animate() {
requestAnimationFrame(animate);
current.theta += (desired.theta - current.theta) * 0.09;
current.phi += (desired.phi - current.phi) * 0.09;
current.radius += (desired.radius - current.radius) * 0.09;
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```