Prompt specification
Build or customize the Three.js 3D scene "Circular Lane and One Entry Merge" 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: Circular Lane and One Entry Merge
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/circular-lane-and-one-entry-merge-x2133
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a roundabout and its entry merges. Model a small circular roadway with an entry lane and visible vehicle footprints. Mark the merge region and distinguish it from the central landscaped island. Stylized solid forms.
Working Three.js Starter (circular-lane-and-one-entry-merge-x2133):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Roundabout Entry Merge</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: #eee9dc;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.title-card {
position: fixed;
top: 22px;
left: 24px;
z-index: 5;
max-width: min(390px, calc(100vw - 48px));
padding: 16px 19px;
border: 1px solid rgba(40, 52, 54, 0.12);
border-radius: 16px;
background: rgba(255, 253, 246, 0.9);
box-shadow: 0 12px 34px rgba(46, 55, 52, 0.12);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 5px;
color: #df7442;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: #29383a;
font-size: clamp(22px, 3vw, 31px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.subtitle {
margin: 8px 0 0;
color: #667171;
font-size: 13px;
line-height: 1.45;
}
.legend {
position: fixed;
left: 24px;
bottom: 24px;
z-index: 5;
display: grid;
gap: 9px;
padding: 13px 15px;
border: 1px solid rgba(40, 52, 54, 0.12);
border-radius: 14px;
background: rgba(255, 253, 246, 0.9);
box-shadow: 0 12px 30px rgba(46, 55, 52, 0.1);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
color: #4a5757;
font-size: 12px;
font-weight: 650;
}
.swatch {
width: 17px;
height: 17px;
flex: 0 0 auto;
border-radius: 5px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.merge { background: #ee8b55; }
.island { background: #729b68; }
.road { background: #455356; }
.controls {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 5;
padding: 10px 13px;
border: 1px solid rgba(40, 52, 54, 0.12);
border-radius: 12px;
color: #687373;
background: rgba(255, 253, 246, 0.82);
box-shadow: 0 10px 24px rgba(46, 55, 52, 0.09);
font-size: 11px;
font-weight: 650;
pointer-events: none;
}
@media (max-width: 650px) {
.title-card { top: 14px; left: 14px; }
.legend { left: 14px; bottom: 14px; }
.controls { right: 14px; bottom: 14px; }
.subtitle { display: none; }
}
</style>
</head>
<body>
<div class="title-card">
<div class="eyebrow">Roadway study</div>
<h1>Roundabout Entry Merge</h1>
<p class="subtitle">A stylized three-dimensional view showing the circulating roadway, merging vehicles, and the landscaped central island.</p>
</div>
<div class="legend" aria-label="Scene legend">
<div class="legend-row"><span class="swatch merge"></span>Marked merge region</div>
<div class="legend-row"><span class="swatch island"></span>Central landscaped island</div>
<div class="legend-row"><span class="swatch road"></span>Vehicle carriageway</div>
</div>
<div class="controls">Drag to orbit · Scroll to zoom</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ 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.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive 3D roundabout with an entry merge");
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee9dc);
scene.fog = new THREE.Fog(0xeee9dc, 44, 88);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
150
);
const hemi = new THREE.HemisphereLight(0xfff8e8, 0x6f806b, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d2, 3.25);
sun.position.set(-13, 24, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -29;
sun.shadow.camera.right = 29;
sun.shadow.camera.top = 29;
sun.shadow.camera.bottom = -29;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc9dcff, 0.65);
fill.position.set(15, 9, -16);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const materials = {
ground: new THREE.MeshStandardMaterial({ color: 0xeee9dc, roughness: 1 }),
earth: new THREE.MeshStandardMaterial({ color: 0xb69772, roughness: 0.95 }),
lawn: new THREE.MeshStandardMaterial({ color: 0xadc18f, roughness: 1 }),
islandGrass: new THREE.MeshStandardMaterial({ color: 0x729b68, roughness: 0.95 }),
mound: new THREE.MeshStandardMaterial({ color: 0x83aa73, roughness: 0.95 }),
road: new THREE.MeshStandardMaterial({ color: 0x455356, roughness: 0.92 }),
curb: new THREE.MeshStandardMaterial({ color: 0xe8dfca, roughness: 0.88 }),
walkway: new THREE.MeshStandardMaterial({ color: 0xc9bda2, roughness: 0.95 }),
marking: new THREE.MeshStandardMaterial({
color: 0xfff2d3,
roughness: 0.72,
emissive: 0x332b18,
emissiveIntensity: 0.06
}),
merge: new THREE.MeshStandardMaterial({
color: 0xee8b55,
roughness: 0.78,
side: THREE.DoubleSide
}),
mergeEdge: new THREE.LineBasicMaterial({ color: 0xffd58c }),
trunk: new THREE.MeshStandardMaterial({ color: 0x7d5437, roughness: 1 }),
canopy: new THREE.MeshStandardMaterial({
color: 0x56875e,
roughness: 1,
flatShading: true
}),
canopyLight: new THREE.MeshStandardMaterial({
color: 0x79a66b,
roughness: 1,
flatShading: true
}),
glass: new THREE.MeshStandardMaterial({
color: 0x263b46,
roughness: 0.28,
metalness: 0.12
}),
tire: new THREE.MeshStandardMaterial({ color: 0x202729, roughness: 0.92 }),
headlight: new THREE.MeshStandardMaterial({
color: 0xfff4c7,
emissive: 0xffd985,
emissiveIntensity: 0.55
}),
taillight: new THREE.MeshStandardMaterial({
color: 0xd94d3f,
emissive: 0x9d1f18,
emissiveIntensity: 0.25
})
};
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function horizontalShape(points) {
const shape = new THREE.Shape();
points.forEach(([x, z], index) => {
if (index === 0) shape.moveTo(x, -z);
else shape.lineTo(x, -z);
});
shape.closePath();
return shape;
}
function extrudeHorizontal(points, depth, material, baseY = 0) {
const geometry = new THREE.ExtrudeGeometry(horizontalShape(points), {
depth,
bevelEnabled: false,
curveSegments: 64
});
geometry.rotateX(-Math.PI / 2);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.y = baseY;
mesh.receiveShadow = true;
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
function annulus(innerRadius, outerRadius, depth, material, baseY = 0) {
const shape = new THREE.Shape();
shape.absarc(0, 0, outerRadius, 0, Math.PI * 2, false);
const hole = new THREE.Path();
hole.absarc(0, 0, innerRadius, 0, Math.PI * 2, true);
shape.holes.push(hole);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: false,
curveSegments: 96
});
geometry.rotateX(-Math.PI / 2);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.y = baseY;
mesh.receiveShadow = true;
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
function roundedRectangle(width, length, radius) {
const x = -width / 2;
const y = -length / 2;
const shape = new THREE.Shape();
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + length - radius);
shape.quadraticCurveTo(x + width, y + length, x + width - radius, y + length);
shape.lineTo(x + radius, y + length);
shape.quadraticCurveTo(x, y + length, x, y + length - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
function createFlatArrow(color = 0xfff2d3, opacity = 1) {
const shape = new THREE.Shape();
shape.moveTo(-0.14, -0.65);
shape.lineTo(0.14, -0.65);
shape.lineTo(0.14, 0.14);
shape.lineTo(0.4, 0.14);
shape.lineTo(0, 0.72);
shape.lineTo(-0.4, 0.14);
shape.lineTo(-0.14, 0.14);
shape.closePath();
const geometry = new THREE.ShapeGeometry(shape);
geometry.rotateX(-Math.PI / 2);
const material = new THREE.MeshStandardMaterial({
color,
transparent: opacity < 1,
opacity,
roughness: 0.8,
side: THREE.DoubleSide
});
return new THREE.Mesh(geometry, material);
}
function addTree(x, z, baseY, scale = 1, light = false) {
const group = new THREE.Group();
group.position.set(x, baseY, z);
group.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.15, 0.22, 1.15, 7),
materials.trunk
);
trunk.position.y = 0.575;
trunk.castShadow = true;
trunk.receiveShadow = true;
group.add(trunk);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.88, 1),
light ? materials.canopyLight : materials.canopy
);
crown.position.y = 1.62;
crown.scale.set(1, 1.15, 0.94);
crown.rotation.set(0.08, 0.4, -0.06);
crown.castShadow = true;
crown.receiveShadow = true;
group.add(crown);
scene.add(group);
return group;
}
function addBush(x, z, y, scale = 1) {
const bush = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.48, 1),
materials.canopyLight
);
bush.position.set(x, y + 0.35, z);
bush.scale.set(scale * 1.2, scale * 0.78, scale);
bush.rotation.y = Math.random() * Math.PI;
bush.castShadow = true;
bush.receiveShadow = true;
scene.add(bush);
}
function createLabel(text, background, foreground = "#fffaf0") {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 160;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.beginPath();
ctx.roundRect(8, 8, 624, 144, 30);
ctx.fillStyle = background;
ctx.fill();
ctx.lineWidth = 5;
ctx.strokeStyle = "rgba(255,255,255,0.62)";
ctx.stroke();
ctx.fillStyle = foreground;
ctx.font = "800 48px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 320, 82);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(4.4, 1.1, 1);
sprite.renderOrder = 10;
return sprite;
}
// -------------------------------------------------------------------------
// Diorama base
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.78;
ground.receiveShadow = true;
scene.add(ground);
const plinth = new THREE.Mesh(
new THREE.CylinderGeometry(25, 25, 0.68, 80),
materials.earth
);
plinth.position.y = -0.42;
plinth.receiveShadow = true;
plinth.castShadow = true;
scene.add(plinth);
const lawnBase = new THREE.Mesh(
new THREE.CylinderGeometry(24.88, 24.88, 0.13, 80),
materials.lawn
);
lawnBase.position.y = -0.015;
lawnBase.receiveShadow = true;
scene.add(lawnBase);
// -------------------------------------------------------------------------
// Roundabout and entry
// -------------------------------------------------------------------------
annulus(8.15, 8.68, 0.10, materials.walkway, 0.00);
annulus(8.15, 8.52, 0.20, materials.curb, 0.03);
annulus(4.85, 8.15, 0.12, materials.road, 0.04);
annulus(4.48, 4.85, 0.25, materials.curb, 0.03);
const approachWalk = [
[-2.48, 24], [2.48, 24], [2.48, 15],
[3.75, 9.4], [2.18, 5.35], [-2.18, 5.35],
[-3.75, 9.4], [-2.48, 15]
];
const approachRoad = [
[-1.85, 24], [1.85, 24], [1.85, 15],
[3.18, 9.4], [1.82, 5.7], [-1.82, 5.7],
[-3.18, 9.4], [-1.85, 15]
];
extrudeHorizontal(approachWalk, 0.10, materials.walkway, 0.00);
extrudeHorizontal(approachRoad, 0.11, materials.road, 0.045);
// Merge area: deliberately orange and separate from the green island.
const mergePoints = [
[-2.75, 9.75],
[2.75, 9.75],
[1.75, 5.4],
[-1.75, 5.4]
];
const mergeGeometry = new THREE.ShapeGeometry(horizontalShape(mergePoints));
mergeGeometry.rotateX(-Math.PI / 2);
const mergeSurface = new THREE.Mesh(mergeGeometry, materials.merge);
mergeSurface.position.y = 0.176;
mergeSurface.receiveShadow = true;
scene.add(mergeSurface);
const mergeBorderPoints = mergePoints.map(
([x, z]) => new THREE.Vector3(x, 0.194, z)
);
const mergeBorder = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(mergeBorderPoints),
materials.mergeEdge
);
scene.add(mergeBorder);
// -------------------------------------------------------------------------
// Road markings
// -------------------------------------------------------------------------
const dashGeometry = new THREE.BoxGeometry(0.66, 0.025, 0.13);
const laneRadius = 6.18;
const dashCount = 42;
const dashStart = 0.38;
for (let i = 0; i < dashCount; i++) {
const theta =
dashStart + (i / (dashCount - 1)) * (Math.PI * 2 - dashStart * 2);
const dash = new THREE.Mesh(dashGeometry, materials.marking);
dash.position.set(
Math.sin(theta) * laneRadius,
0.178,
Math.cos(theta) * laneRadius
);
dash.rotation.y = theta;
dash.receiveShadow = true;
scene.add(dash);
}
for (let i = 0; i < 6; i++) {
const dash = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.025, 1.15),
materials.marking
);
dash.position.set(0, 0.175, 13.5 + i * 1.65);
scene.add(dash);
}
for (const side of [-1, 1]) {
const line = new THREE.Mesh(
new THREE.BoxGeometry(0.09, 0.025, 10.5),
materials.marking
);
line.position.set(side * 1.65, 0.175, 18.1);
scene.add(line);
}
// Yield triangles before the merge.
for (let i = 0; i < 5; i++) {
const triangleGeometry = new THREE.BufferGeometry();
triangleGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
-0.23, 0, -0.16,
0.23, 0, -0.16,
0.00, 0, 0.22
], 3)
);
triangleGeometry.computeVertexNormals();
const triangle = new THREE.Mesh(triangleGeometry, materials.marking);
triangle.position.set(-1.15 + i * 0.575, 0.178, 10.65);
triangle.rotation.y = Math.PI;
scene.add(triangle);
}
// Approach arrows.
for (const z of [20.9, 14.7]) {
const arrow = createFlatArrow();
arrow.position.set(0, 0.181, z);
scene.add(arrow);
}
// Pale directional arrows within the orange merge field.
for (const z of [8.75, 7.35, 5.95]) {
const arrow = createFlatArrow(0xffedcf, 0.96);
arrow.position.set(0, 0.198, z);
arrow.scale.setScalar(0.76);
scene.add(arrow);
}
// Circular direction arrows.
for (const theta of [0.95, 2.35, 3.72, 5.15]) {
const arrow = createFlatArrow();
arrow.position.set(
Math.sin(theta) * 6.73,
0.179,
Math.cos(theta) * 6.73
);
arrow.rotation.y = theta - Math.PI / 2;
arrow.scale.setScalar(0.82);
scene.add(arrow);
}
// -------------------------------------------------------------------------
// Central landscaped island
// -------------------------------------------------------------------------
const island = new THREE.Mesh(
new THREE.CylinderGeometry(4.49, 4.54, 0.18, 80),
materials.islandGrass
);
island.position.y = 0.18;
island.receiveShadow = true;
island.castShadow = true;
scene.add(island);
const islandMound = new THREE.Mesh(
new THREE.CylinderGeometry(2.15, 2.48, 0.24, 48),
materials.mound
);
islandMound.position.set(0, 0.38, -0.45);
islandMound.receiveShadow = true;
islandMound.castShadow = true;
scene.add(islandMound);
addTree(-2.35, -0.95, 0.27, 1.02, false);
addTree(1.85, -1.55, 0.27, 0.94, true);
addTree(2.50, 1.18, 0.27, 0.84, false);
addTree(-1.55, 1.85, 0.27, 0.80, true);
addTree(0.18, 0.32, 0.50, 1.10, false);
addBush(-2.9, 1.55, 0.27, 0.72);
addBush(1.05, 2.45, 0.27, 0.68);
addBush(2.8, -0.25, 0.27, 0.62);
addBush(-0.65, -2.75, 0.27, 0.72);
addBush(-2.95, -1.45, 0.27, 0.54);
// -------------------------------------------------------------------------
// Vehicles
// -------------------------------------------------------------------------
function createCar(color, scale = 1) {
const group = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.42,
metalness: 0.08
});
// Pale footprint makes each vehicle legible from above.
const footprintGeometry = new THREE.ShapeGeometry(
roundedRectangle(1.34, 2.46, 0.28)
);
footprintGeometry.rotateX(-Math.PI / 2);
const footprint = new THREE.Mesh(
footprintGeometry,
new THREE.MeshBasicMaterial({
color: 0xe5ece9,
transparent: true,
opacity: 0.24,
depthWrite: false
})
);
footprint.position.y = 0.012;
group.add(footprint);
const bodyGeometry = new THREE.ExtrudeGeometry(
roundedRectangle(1.15, 2.25, 0.25),
{
depth: 0.40,
bevelEnabled: true,
bevelSize: 0.055,
bevelThickness: 0.055,
bevelSegments: 2,
curveSegments: 8
}
);
bodyGeometry.rotateX(-Math.PI / 2);
const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
body.position.y = 0.28;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const cabinGeometry = new THREE.ExtrudeGeometry(
roundedRectangle(0.91, 1.10, 0.19),
{
depth: 0.28,
bevelEnabled: true,
bevelSize: 0.035,
bevelThickness: 0.035,
bevelSegments: 2,
curveSegments: 8
}
);
cabinGeometry.rotateX(-Math.PI / 2);
const cabin = new THREE.Mesh(cabinGeometry, materials.glass);
cabin.position.set(0, 0.68, -0.05);
cabin.castShadow = true;
group.add(cabin);
const roofGeometry = new THREE.ExtrudeGeometry(
roundedRectangle(0.80, 0.87, 0.16),
{
depth: 0.055,
bevelEnabled: true,
bevelSize: 0.018,
bevelThickness: 0.018,
bevelSegments: 1,
curveSegments: 8
}
);
roofGeometry.rotateX(-Math.PI / 2);
const roof = new THREE.Mesh(roofGeometry, bodyMaterial);
roof.position.set(0, 0.97, -0.07);
roof.castShadow = true;
group.add(roof);
const wheelGeometry = new THREE.CylinderGeometry(0.28, 0.28, 0.18, 14);
for (const x of [-0.61, 0.61]) {
for (const z of [-0.73, 0.73]) {
const wheel = new THREE.Mesh(wheelGeometry, materials.tire);
wheel.position.set(x, 0.26, z);
wheel.rotation.z = Math.PI / 2;
wheel.castShadow = true;
group.add(wheel);
}
}
for (const x of [-0.34, 0.34]) {
const headlight = new THREE.Mesh(
new THREE.BoxGeometry(0.23, 0.12, 0.035),
materials.headlight
);
headlight.position.set(x, 0.44, 1.13);
group.add(headlight);
const taillight = new THREE.Mesh(
new THREE.BoxGeometry(0.21, 0.11, 0.035),
materials.taillight
);
taillight.position.set(x, 0.44, -1.13);
group.add(taillight);
}
group.scale.setScalar(scale);
scene.add(group);
return group;
}
// Two vehicles queue on the entry.
const entryCarA = createCar(0x467c9d);
entryCarA.position.set(0.10, 0.16, 18.2);
entryCarA.rotation.y = Math.PI;
const entryCarB = createCar(0xe66c52);
entryCarB.position.set(0.45, 0.16, 12.9);
entryCarB.rotation.y = Math.PI;
// Animated circulating vehicles.
const circulatingCars = [
{ car: createCar(0xf0b84b), angle: 0.72, radius: 6.63, speed: 0.072 },
{ car: createCar(0x4d9a86), angle: 2.65, radius: 6.58, speed: 0.067 },
{ car: createCar(0xe9e4d8), angle: 4.55, radius: 6.62, speed: 0.070 }
];
// -------------------------------------------------------------------------
// Light urban context
// -------------------------------------------------------------------------
function addBuilding(x, z, width, depth, height, color) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const body = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
new THREE.MeshStandardMaterial({ color, roughness: 0.92 })
);
body.position.y = height / 2;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const roof = new THREE.Mesh(
new THREE.BoxGeometry(width + 0.35, 0.24, depth + 0.35),
new THREE.MeshStandardMaterial({ color: 0xd6cbb7, roughness: 0.95 })
);
roof.position.y = height + 0.12;
roof.castShadow = true;
group.add(roof);
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0x526b70,
roughness: 0.4,
metalness: 0.08
});
for (let i = 0; i < 3; i++) {
const windowBand = new THREE.Mesh(
new THREE.BoxGeometry(width * 0.72, 0.55, 0.04),
windowMaterial
);
windowBand.position.set(0, 1.05 + i * 0.92, depth / 2 + 0.025);
group.add(windowBand);
}
scene.add(group);
}
addBuilding(-13.5, -11.2, 7.2, 6.0, 3.4, 0xc88768);
addBuilding(9.8, -13.0, 6.4, 5.2, 3.0, 0x78939b);
addBuilding(15.0, 3.8, 5.0, 6.6, 2.6, 0xbca36e);
addTree(-17.4, -5.8, 0, 1.20, false);
addTree(-17.5, 3.5, 0, 1.08, true);
addTree(14.0, -6.5, 0, 1.15, false);
addTree(16.7, 10.4, 0, 1.02, true);
addTree(-10.8, 13.8, 0, 0.95, false);
addTree(8.4, 15.2, 0, 1.10, true);
// -------------------------------------------------------------------------
// Labels
// -------------------------------------------------------------------------
const mergeLabel = createLabel("MERGE ZONE", "#d96f3e");
mergeLabel.position.set(3.65, 1.45, 8.05);
scene.add(mergeLabel);
const islandLabel = createLabel("LANDSCAPED ISLAND", "#527d50");
islandLabel.position.set(-2.35, 3.0, -2.05);
scene.add(islandLabel);
// -------------------------------------------------------------------------
// Direct camera controls — no addons
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 0.35, 3.4),
radius: 30,
theta: 0.72,
phi: 0.94,
desiredRadius: 30,
desiredTheta: 0.72,
desiredPhi: 0.94,
dragging: false,
previousX: 0,
previousY: 0
};
function updateCamera(instant = false) {
if (instant) {
controls.radius = controls.desiredRadius;
controls.theta = controls.desiredTheta;
controls.phi = controls.desiredPhi;
}
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
renderer.domElement.addEventListener("pointerdown", event => {
controls.dragging = true;
controls.previousX = event.clientX;
controls.previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!controls.dragging) return;
const dx = event.clientX - controls.previousX;
const dy = event.clientY - controls.previousY;
controls.desiredTheta -= dx * 0.006;
controls.desiredPhi = THREE.MathUtils.clamp(
controls.desiredPhi + dy * 0.0045,
0.34,
1.30
);
controls.previousX = event.clientX;
controls.previousY = event.clientY;
});
function endDrag(event) {
controls.dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
controls.desiredRadius = THREE.MathUtils.clamp(
controls.desiredRadius + event.deltaY * 0.018,
17,
45
);
}, { passive: false });
updateCamera(true);
// -------------------------------------------------------------------------
// Animation and resize
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
// Smooth camera interpolation.
controls.radius += (controls.desiredRadius - controls.radius) * 0.08;
controls.theta += (controls.desiredTheta - controls.theta) * 0.11;
controls.phi += (controls.desiredPhi - controls.phi) * 0.11;
updateCamera();
for (const item of circulatingCars) {
item.angle += item.speed * dt;
const x = Math.sin(item.angle) * item.radius;
const z = Math.cos(item.angle) * item.radius;
const dx = Math.cos(item.angle);
const dz = -Math.sin(item.angle);
item.car.position.set(x, 0.16, z);
item.car.rotation.y = Math.atan2(dx, dz);
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
</script>
</body>
</html>
```