Prompt specification
Build or customize the Three.js 3D scene "Sun-angle urban design table" 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: Sun-angle urban design table
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sun-angle-urban-design-table-x1256
Scene Description Prompt:
Allow independent solar azimuth and elevation controls over a bounded street scene; display light direction and resulting shadows while labeling inputs geometric rather than automatic astronomical calculations. Build this with Three.js from cdnjs as a low-poly scene in one HTML file.
Working Three.js Starter (sun-angle-urban-design-table-x1256):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Solar Vector Lab — Street Scene</title>
<style>
:root {
--ink: #f3f7f8;
--muted: #9fb0b8;
--panel: rgba(15, 28, 37, 0.93);
--panel-line: rgba(255, 255, 255, 0.11);
--accent: #f6b84b;
--accent-soft: rgba(246, 184, 75, 0.16);
--cyan: #75d4d1;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbdde7;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
top: 20px;
left: 20px;
width: 370px;
max-height: calc(100vh - 40px);
overflow: auto;
padding: 20px;
border: 1px solid var(--panel-line);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 24px 70px rgba(18, 35, 46, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(16px) saturate(125%);
scrollbar-width: thin;
scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}
.eyebrow {
margin: 0 0 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 25px;
line-height: 1.05;
letter-spacing: -0.035em;
}
.intro {
margin: 10px 0 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.rule {
height: 1px;
margin: 17px 0;
background: var(--panel-line);
}
.section-label {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 14px;
color: #dce7eb;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-label span {
color: var(--accent);
font-variant-numeric: tabular-nums;
}
.control + .control {
margin-top: 17px;
}
.control-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
}
.control-heading label {
color: #eef4f6;
font-size: 13px;
font-weight: 700;
}
.control-heading small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 400;
}
.number-wrap {
position: relative;
flex: 0 0 auto;
}
.number-wrap input {
width: 76px;
padding: 7px 25px 7px 8px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 8px;
outline: none;
background: rgba(255, 255, 255, 0.06);
color: var(--accent);
font-size: 13px;
font-weight: 800;
font-variant-numeric: tabular-nums;
text-align: right;
}
.number-wrap input:focus {
border-color: rgba(246, 184, 75, 0.65);
box-shadow: 0 0 0 3px var(--accent-soft);
}
.number-wrap::after {
position: absolute;
top: 50%;
right: 8px;
color: var(--muted);
content: "°";
font-size: 11px;
transform: translateY(-50%);
pointer-events: none;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 3px 0;
border-radius: 99px;
outline: none;
appearance: none;
background:
linear-gradient(
to right,
var(--accent) 0%,
var(--accent) var(--pct),
rgba(255, 255, 255, 0.13) var(--pct),
rgba(255, 255, 255, 0.13) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #172630;
border-radius: 50%;
appearance: none;
background: var(--accent);
box-shadow: 0 0 0 1px rgba(246, 184, 75, 0.5);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #172630;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px rgba(246, 184, 75, 0.5);
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: #70848e;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.presets {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
margin-top: 11px;
}
.presets button,
.camera-buttons button {
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 8px;
background: rgba(255, 255, 255, 0.045);
color: #cbd8dd;
cursor: pointer;
transition:
background 120ms ease,
color 120ms ease,
border-color 120ms ease;
}
.presets button {
padding: 7px 0;
font-size: 10px;
font-weight: 800;
}
.presets button:hover,
.camera-buttons button:hover {
border-color: rgba(246, 184, 75, 0.4);
background: var(--accent-soft);
color: var(--accent);
}
.direction-card {
display: grid;
grid-template-columns: 132px 1fr;
gap: 15px;
align-items: center;
}
.compass {
position: relative;
width: 126px;
height: 126px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 50%;
background:
radial-gradient(circle, rgba(255, 255, 255, 0.055) 0 48%, transparent 49%),
repeating-conic-gradient(
from 0deg,
rgba(255, 255, 255, 0.08) 0deg 1deg,
transparent 1deg 30deg
);
box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.15);
}
.compass::after {
position: absolute;
inset: 38px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 50%;
content: "";
}
.cardinal {
position: absolute;
z-index: 2;
color: #8fa3ad;
font-size: 9px;
font-weight: 900;
}
.cardinal.n {
top: 5px;
left: 50%;
transform: translateX(-50%);
}
.cardinal.e {
top: 50%;
right: 6px;
transform: translateY(-50%);
}
.cardinal.s {
bottom: 5px;
left: 50%;
transform: translateX(-50%);
}
.cardinal.w {
top: 50%;
left: 5px;
transform: translateY(-50%);
}
#azNeedle {
position: absolute;
z-index: 3;
inset: 0;
transform: rotate(0deg);
transition: transform 80ms linear;
pointer-events: none;
}
#azNeedle::before {
position: absolute;
top: 18px;
bottom: 50%;
left: 50%;
border-left: 1px dashed rgba(246, 184, 75, 0.55);
content: "";
}
#azNeedle span {
position: absolute;
top: 10px;
left: 50%;
color: var(--accent);
font-size: 20px;
line-height: 1;
text-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
transform: translateX(-50%);
}
.vector-info {
min-width: 0;
}
.vector-label {
margin-bottom: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.vector-value {
margin-bottom: 12px;
color: #eff7f8;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
font-size: 11px;
line-height: 1.45;
white-space: nowrap;
}
.elevation-meter {
margin-top: 12px;
}
.elevation-meter header {
display: flex;
justify-content: space-between;
margin-bottom: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.elevation-track {
position: relative;
height: 5px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.12);
}
#elevationFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan), var(--accent));
transition: width 80ms linear;
}
.options {
display: grid;
gap: 9px;
}
.option {
display: flex;
align-items: center;
justify-content: space-between;
color: #cdd9de;
font-size: 11px;
cursor: pointer;
}
.option input {
width: 34px;
height: 18px;
accent-color: var(--accent);
cursor: pointer;
}
.geometric-note {
margin: 13px 0 0;
padding: 11px 12px;
border: 1px solid rgba(117, 212, 209, 0.15);
border-radius: 10px;
background: rgba(117, 212, 209, 0.055);
color: #9eb6bd;
font-size: 10px;
line-height: 1.55;
}
.geometric-note strong {
color: var(--cyan);
}
.camera-buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.camera-buttons button {
padding: 9px 8px;
font-size: 10px;
font-weight: 800;
}
.scene-badge {
position: fixed;
z-index: 8;
top: 20px;
right: 20px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.25);
border-radius: 12px;
background: rgba(19, 37, 47, 0.78);
box-shadow: 0 12px 35px rgba(27, 49, 61, 0.16);
color: #eaf2f4;
backdrop-filter: blur(12px);
}
.scene-badge strong {
display: block;
color: var(--accent);
font-size: 9px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.scene-badge span {
display: block;
margin-top: 3px;
color: #b3c3ca;
font-size: 10px;
}
.scene-legend {
position: fixed;
z-index: 8;
right: 20px;
bottom: 20px;
width: 225px;
padding: 13px 14px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 12px;
background: rgba(19, 37, 47, 0.78);
color: #c5d2d7;
backdrop-filter: blur(12px);
font-size: 10px;
line-height: 1.5;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
}
.legend-row + .legend-row {
margin-top: 6px;
}
.legend-swatch {
width: 19px;
height: 3px;
flex: 0 0 auto;
border-radius: 99px;
background: var(--accent);
}
.legend-swatch.shadow {
background: rgba(28, 39, 43, 0.55);
box-shadow: 2px 2px 0 rgba(255, 255, 255, 0.24);
}
.help {
position: fixed;
z-index: 7;
bottom: 20px;
left: 50%;
padding: 9px 13px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 99px;
background: rgba(19, 37, 47, 0.73);
color: #d5e0e4;
backdrop-filter: blur(10px);
font-size: 10px;
transform: translateX(-50%);
pointer-events: none;
white-space: nowrap;
}
@media (max-width: 760px) {
.panel {
top: 10px;
left: 10px;
width: min(350px, calc(100vw - 20px));
max-height: calc(100vh - 20px);
padding: 16px;
}
.scene-badge,
.scene-legend {
display: none;
}
.help {
right: 10px;
bottom: 10px;
left: auto;
max-width: calc(100vw - 20px);
overflow: hidden;
text-overflow: ellipsis;
transform: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive low-poly street scene"></div>
<main class="panel">
<p class="eyebrow">Geometric daylight controls</p>
<h1>Solar Vector Lab</h1>
<p class="intro">
Place a directional light over a bounded street block and inspect its
geometric direction and cast shadows.
</p>
<div class="rule"></div>
<div class="section-label"><span>01</span> Light placement</div>
<div class="control">
<div class="control-heading">
<div>
<label for="azimuthRange">Azimuth</label>
<small>Clockwise bearing from scene north</small>
</div>
<div class="number-wrap">
<input
id="azimuthNumber"
type="number"
min="0"
max="360"
step="1"
value="45"
aria-label="Azimuth in degrees"
>
</div>
</div>
<input
id="azimuthRange"
type="range"
min="0"
max="360"
step="1"
value="45"
>
<div class="range-ends">
<span>0° north</span>
<span>90° east</span>
<span>180° south</span>
<span>270° west</span>
</div>
<div class="presets" aria-label="Azimuth presets">
<button type="button" data-azimuth="0">N</button>
<button type="button" data-azimuth="90">E</button>
<button type="button" data-azimuth="180">S</button>
<button type="button" data-azimuth="270">W</button>
</div>
</div>
<div class="control">
<div class="control-heading">
<div>
<label for="elevationRange">Elevation</label>
<small>Angle above the horizontal ground plane</small>
</div>
<div class="number-wrap">
<input
id="elevationNumber"
type="number"
min="0"
max="90"
step="1"
value="35"
aria-label="Elevation in degrees"
>
</div>
</div>
<input
id="elevationRange"
type="range"
min="0"
max="90"
step="1"
value="35"
>
<div class="range-ends">
<span>0° horizon</span>
<span>45°</span>
<span>90° zenith</span>
</div>
</div>
<div class="rule"></div>
<div class="section-label"><span>02</span> Direction readout</div>
<div class="direction-card">
<div class="compass" aria-label="Azimuth compass">
<span class="cardinal n">N</span>
<span class="cardinal e">E</span>
<span class="cardinal s">S</span>
<span class="cardinal w">W</span>
<div id="azNeedle"><span>▲</span></div>
</div>
<div class="vector-info">
<div class="vector-label">Vector to source</div>
<div id="sourceVector" class="vector-value">—</div>
<div class="vector-label">Vector of ray travel</div>
<div id="rayVector" class="vector-value">—</div>
<div class="elevation-meter">
<header>
<span>Elevation</span>
<span id="elevationReadout">35°</span>
</header>
<div class="elevation-track">
<div id="elevationFill"></div>
</div>
</div>
</div>
</div>
<div class="rule"></div>
<div class="section-label"><span>03</span> Display</div>
<div class="options">
<label class="option">
<span>Directional shadows · 2048 map</span>
<input id="shadowToggle" type="checkbox" checked>
</label>
<label class="option">
<span>Show source arrow and marker</span>
<input id="arrowToggle" type="checkbox" checked>
</label>
</div>
<p class="geometric-note">
<strong>Geometric, not astronomical.</strong>
Azimuth is a bearing in the scene: 0° points toward −Z, and angles increase
clockwise. Elevation is measured directly above the ground plane. No
location, date, time, or solar-position equation is used.
</p>
<div class="rule"></div>
<div class="section-label"><span>04</span> Camera</div>
<div class="camera-buttons">
<button id="resetView" type="button">Reset oblique view</button>
<button id="topView" type="button">Top view</button>
</div>
</main>
<div class="scene-badge">
<strong>Live shadow study</strong>
<span>Bounded street block · directional light</span>
</div>
<div class="scene-legend">
<div class="legend-row">
<span class="legend-swatch"></span>
<span>Orange arrow points toward the light source.</span>
</div>
<div class="legend-row">
<span class="legend-swatch shadow"></span>
<span>Shadows travel opposite the source vector.</span>
</div>
</div>
<div class="help">
Drag to orbit · wheel or pinch to zoom · right-drag to pan
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbdde7);
scene.fog = new THREE.Fog(0xcbdde7, 110, 190);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
300
);
const hemisphere = new THREE.HemisphereLight(0xd9efff, 0x6b654d, 0.85);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedc9, 2.8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -58;
sun.shadow.camera.right = 58;
sun.shadow.camera.top = 58;
sun.shadow.camera.bottom = -58;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 180;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.035;
scene.add(sun);
scene.add(sun.target);
const materialCache = new Map();
function standardMaterial(color, extra = {}) {
const key = `${color}-${JSON.stringify(extra)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...extra
})
);
}
return materialCache.get(key);
}
function addBox(
width,
height,
depth,
color,
x,
y,
z,
castShadow = true,
receiveShadow = true,
material = null
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material || standardMaterial(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
scene.add(mesh);
return mesh;
}
function addCylinder(
radiusTop,
radiusBottom,
height,
color,
x,
y,
z,
segments = 6
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
standardMaterial(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// Bounded city-block base.
addBox(88, 0.8, 66, 0x7e9681, 0, -0.4, 0, false, true);
addBox(86, 0.12, 64, 0xa8b99b, 0, 0.06, 0, false, true);
// Road, curbs, and sidewalks.
addBox(12.4, 0.16, 64, 0x3c464a, 0, 0.14, 0, false, true);
const sidewalkMaterial = standardMaterial(0xc9c7ba);
const curbMaterial = standardMaterial(0xe2dfd1);
for (const side of [-1, 1]) {
addBox(
4.8,
0.26,
64,
0xc9c7ba,
side * 8.5,
0.13,
0,
false,
true,
sidewalkMaterial
);
addBox(
0.28,
0.31,
64,
0xe2dfd1,
side * 6.16,
0.155,
0,
false,
true,
curbMaterial
);
}
// Lane markings.
const yellowPaint = standardMaterial(0xe5c45d);
const whitePaint = standardMaterial(0xe7e4d8);
for (let z = -29; z <= 29; z += 6) {
addBox(
0.18,
0.025,
3.0,
0xe5c45d,
0,
0.235,
z,
false,
false,
yellowPaint
);
}
for (const side of [-1, 1]) {
addBox(
0.12,
0.025,
61,
0xe7e4d8,
side * 4.8,
0.235,
0,
false,
false,
whitePaint
);
}
// Pedestrian crossing.
for (let i = -5; i <= 5; i++) {
addBox(
0.64,
0.028,
3.1,
0xf0eee4,
i * 0.86,
0.24,
10,
false,
false,
whitePaint
);
}
// Low-poly building row.
const buildingColors = [
0xd88d67,
0x7da9a4,
0xd3b26f,
0x8ea5bf,
0xc47770,
0xa9b7a0,
0xd9a36f,
0x71999b
];
const windowMaterial = standardMaterial(0x3e5967, {
roughness: 0.36,
metalness: 0.12
});
const doorMaterial = standardMaterial(0x5c443c);
function addBuilding(side, z, width, height, depth, color, colorIndex) {
const x = side * 17.8;
const base = 0.12;
addBox(
width,
height,
depth,
color,
x,
base + height / 2,
z
);
const roofColor = new THREE.Color(color).multiplyScalar(0.82);
addBox(
width + 0.45,
0.35,
depth + 0.45,
roofColor.getHex(),
x,
base + height + 0.1,
z
);
// Small rooftop service box.
addBox(
2.1,
0.8,
1.6,
0x768285,
x + 1.2,
base + height + 0.65,
z - 1.5
);
const innerFaceX = side * (17.8 - width / 2 - 0.045);
const floorCount = Math.max(2, Math.floor((height - 1.4) / 2.5));
for (let row = 0; row < floorCount; row++) {
const y = 2.3 + row * 2.45;
if (y + 0.65 > height) continue;
for (const offsetZ of [-depth * 0.29, 0, depth * 0.29]) {
addBox(
0.09,
1.12,
1.55,
0x3e5967,
innerFaceX,
base + y,
z + offsetZ,
false,
false,
windowMaterial
);
}
}
// Door facing the street.
addBox(
0.11,
2.15,
1.45,
0x5c443c,
side * (17.8 - width / 2 - 0.06),
base + 1.08,
z + depth * 0.31,
false,
false,
doorMaterial
);
}
const buildingRows = [
{ z: -23, width: 10.5, height: 9.5, depth: 10.5 },
{ z: -9.5, width: 11, height: 13.5, depth: 10.5 },
{ z: 5.5, width: 10.5, height: 8.5, depth: 10.5 },
{ z: 21, width: 11, height: 12, depth: 11.5 }
];
let buildingIndex = 0;
for (const side of [-1, 1]) {
for (const row of buildingRows) {
addBuilding(
side,
row.z,
row.width,
row.height,
row.depth,
buildingColors[buildingIndex % buildingColors.length],
buildingIndex
);
buildingIndex++;
}
}
// Street trees.
const trunkMaterial = standardMaterial(0x76513b);
const leafMaterials = [
standardMaterial(0x527c58),
standardMaterial(0x668a60),
standardMaterial(0x769469)
];
function addTree(x, z, variant = 0) {
addCylinder(0.25, 0.36, 2.8, 0x76513b, x, 1.67, z, 6);
const crown = new THREE.Mesh(
new THREE.DodecahedronGeometry(2.05, 0),
leafMaterials[variant % leafMaterials.length]
);
crown.position.set(x, 4.05, z);
crown.scale.set(1.05, 1.18, 1.05);
crown.rotation.y = variant * 0.72;
crown.castShadow = true;
crown.receiveShadow = true;
scene.add(crown);
const upperCrown = new THREE.Mesh(
new THREE.DodecahedronGeometry(1.35, 0),
leafMaterials[(variant + 1) % leafMaterials.length]
);
upperCrown.position.set(x + 0.35, 5.25, z - 0.15);
upperCrown.castShadow = true;
scene.add(upperCrown);
}
let treeIndex = 0;
for (const side of [-1, 1]) {
for (const z of [-27, -13, 0, 15, 28]) {
addTree(side * 9.25, z, treeIndex++);
}
}
// Street lamps.
const lampMaterial = standardMaterial(0x34464a, {
roughness: 0.55,
metalness: 0.28
});
function addStreetLamp(side, z) {
const x = side * 6.85;
addCylinder(0.10, 0.16, 5.4, 0x34464a, x, 2.95, z, 6);
addBox(
1.75,
0.13,
0.14,
0x34464a,
side * 6.05,
5.55,
z,
true,
true,
lampMaterial
);
addBox(
0.72,
0.20,
0.44,
0x526266,
side * 5.35,
5.48,
z,
true,
true,
lampMaterial
);
}
for (const side of [-1, 1]) {
for (const z of [-21, -3, 16]) {
addStreetLamp(side, z);
}
}
// Low-poly planters and short boundary walls.
for (const side of [-1, 1]) {
for (const z of [-28, 27]) {
addBox(
3.4,
0.65,
1.3,
0x8c7863,
side * 18,
0.4,
z
);
}
}
// Text sprite helper for the in-scene north marker.
function makeTextSprite(text, color = "#f4f0d7") {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = color;
context.font = "900 82px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 128, 64);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(3.6, 1.8, 1);
return sprite;
}
// North arrow lying on the ground.
const northShape = new THREE.Shape();
northShape.moveTo(0, 2.5);
northShape.lineTo(-1.15, -1.35);
northShape.lineTo(0, -0.65);
northShape.lineTo(1.15, -1.35);
northShape.closePath();
const northArrow = new THREE.Mesh(
new THREE.ShapeGeometry(northShape),
standardMaterial(0x245e64)
);
northArrow.rotation.x = -Math.PI / 2;
northArrow.position.set(-29, 0.145, -22);
northArrow.receiveShadow = true;
scene.add(northArrow);
const northLabel = makeTextSprite("N");
northLabel.position.set(-29, 1.05, -27);
scene.add(northLabel);
// Symbolic source marker and direction arrow.
const vectorOrigin = new THREE.Vector3(0, 0.48, 0);
const sourceDirection = new THREE.Vector3(0, 1, 0);
const directionArrow = new THREE.ArrowHelper(
sourceDirection,
vectorOrigin,
18,
0xf6a82e,
2.1,
0.9
);
directionArrow.line.material.transparent = true;
directionArrow.line.material.opacity = 0.96;
directionArrow.line.material.depthTest = false;
directionArrow.line.material.depthWrite = false;
directionArrow.line.renderOrder = 20;
directionArrow.cone.material.transparent = true;
directionArrow.cone.material.opacity = 0.96;
directionArrow.cone.material.depthTest = false;
directionArrow.cone.material.depthWrite = false;
directionArrow.cone.renderOrder = 20;
scene.add(directionArrow);
const sourceMarker = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.78, 1),
new THREE.MeshBasicMaterial({
color: 0xffb13b,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
})
);
sourceMarker.renderOrder = 21;
scene.add(sourceMarker);
// Direct camera controls: orbit, pan, wheel zoom, and pinch zoom.
const cameraTarget = new THREE.Vector3(0, 2.4, 0);
const homeRadius = window.innerWidth < 760 ? 118 : 92;
const spherical = new THREE.Spherical(homeRadius, 1.07, 0.72);
const pointers = new Map();
let gesture = null;
function applyCamera() {
spherical.phi = THREE.MathUtils.clamp(spherical.phi, 0.16, 1.46);
spherical.radius = THREE.MathUtils.clamp(spherical.radius, 42, 170);
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
gesture = {
type: event.button === 2 || event.shiftKey ? "pan" : "orbit",
pointerId: event.pointerId,
x: event.clientX,
y: event.clientY
};
} else if (pointers.size === 2) {
gesture = {
type: "pinch",
distance: pointerDistance(),
radius: spherical.radius
};
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size >= 2 && gesture?.type === "pinch") {
const distance = pointerDistance();
if (distance > 0 && gesture.distance > 0) {
spherical.radius = gesture.radius * distance / gesture.distance;
gesture.distance = distance;
}
applyCamera();
return;
}
if (!gesture || gesture.pointerId !== event.pointerId) return;
const dx = event.clientX - gesture.x;
const dy = event.clientY - gesture.y;
if (gesture.type === "orbit") {
spherical.theta -= dx * 0.005;
spherical.phi -= dy * 0.005;
} else if (gesture.type === "pan") {
camera.updateMatrixWorld();
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const scale =
2 *
spherical.radius *
Math.tan(THREE.MathUtils.degToRad(camera.fov * 0.5)) /
renderer.domElement.clientHeight;
cameraTarget.addScaledVector(right, -dx * scale);
cameraTarget.addScaledVector(forward, -dy * scale);
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -38, 38);
cameraTarget.z = THREE.MathUtils.clamp(cameraTarget.z, -30, 30);
}
gesture.x = event.clientX;
gesture.y = event.clientY;
applyCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
gesture = null;
} else if (pointers.size === 1) {
const [pointerId, point] = pointers.entries().next().value;
gesture = {
type: "orbit",
pointerId,
x: point.x,
y: point.y
};
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius *= Math.exp(event.deltaY * 0.001);
applyCamera();
},
{ passive: false }
);
document.getElementById("resetView").addEventListener("click", () => {
cameraTarget.set(0, 2.4, 0);
spherical.set(homeRadius, 1.07, 0.72);
applyCamera();
});
document.getElementById("topView").addEventListener("click", () => {
cameraTarget.set(0, 0, 0);
spherical.set(homeRadius, 0.17, 0);
applyCamera();
});
// UI state and geometric sun-direction calculation.
const azimuthRange = document.getElementById("azimuthRange");
const azimuthNumber = document.getElementById("azimuthNumber");
const elevationRange = document.getElementById("elevationRange");
const elevationNumber = document.getElementById("elevationNumber");
const azNeedle = document.getElementById("azNeedle");
const elevationFill = document.getElementById("elevationFill");
const elevationReadout = document.getElementById("elevationReadout");
const sourceVectorElement = document.getElementById("sourceVector");
const rayVectorElement = document.getElementById("rayVector");
let azimuth = 45;
let elevation = 35;
function formatVector(vector) {
const format = (value) =>
`${value >= 0 ? "+" : ""}${value.toFixed(3)}`;
return `${format(vector.x)} ${format(vector.y)} ${format(vector.z)}`;
}
function updateSun() {
const az = THREE.MathUtils.degToRad(azimuth);
const el = THREE.MathUtils.degToRad(elevation);
// Scene convention:
// +X = east, +Y = up, -Z = north.
sourceDirection.set(
Math.sin(az) * Math.cos(el),
Math.sin(el),
-Math.cos(az) * Math.cos(el)
).normalize();
sun.target.position.set(0, 0, 0);
sun.target.updateMatrixWorld();
sun.position.copy(sourceDirection).multiplyScalar(72);
directionArrow.position.copy(vectorOrigin);
directionArrow.setDirection(sourceDirection);
directionArrow.setLength(18, 2.1, 0.9);
sourceMarker.position
.copy(vectorOrigin)
.addScaledVector(sourceDirection, 18);
const rayDirection = sourceDirection.clone().multiplyScalar(-1);
azimuthRange.value = azimuth;
elevationRange.value = elevation;
azimuthNumber.value = azimuth;
elevationNumber.value = elevation;
azimuthRange.style.setProperty(
"--pct",
`${(azimuth / 360) * 100}%`
);
elevationRange.style.setProperty(
"--pct",
`${(elevation / 90) * 100}%`
);
azNeedle.style.transform = `rotate(${azimuth}deg)`;
elevationFill.style.width = `${(elevation / 90) * 100}%`;
elevationReadout.textContent = `${elevation}°`;
sourceVectorElement.textContent = formatVector(sourceDirection);
rayVectorElement.textContent = formatVector(rayDirection);
}
function setAzimuth(value) {
if (!Number.isFinite(value)) return;
azimuth = THREE.MathUtils.clamp(value, 0, 360);
updateSun();
}
function setElevation(value) {
if (!Number.isFinite(value)) return;
elevation = THREE.MathUtils.clamp(value, 0, 90);
updateSun();
}
azimuthRange.addEventListener("input", () => {
setAzimuth(Number(azimuthRange.value));
});
elevationRange.addEventListener("input", () => {
setElevation(Number(elevationRange.value));
});
azimuthNumber.addEventListener("input", () => {
if (azimuthNumber.value !== "") {
setAzimuth(Number(azimuthNumber.value));
}
});
elevationNumber.addEventListener("input", () => {
if (elevationNumber.value !== "") {
setElevation(Number(elevationNumber.value));
}
});
azimuthNumber.addEventListener("change", () => {
setAzimuth(Number(azimuthNumber.value));
});
elevationNumber.addEventListener("change", () => {
setElevation(Number(elevationNumber.value));
});
document.querySelectorAll("[data-azimuth]").forEach((button) => {
button.addEventListener("click", () => {
setAzimuth(Number(button.dataset.azimuth));
});
});
document.getElementById("shadowToggle").addEventListener("change", (event) => {
renderer.shadowMap.enabled = event.target.checked;
sun.castShadow = event.target.checked;
renderer.shadowMap.needsUpdate = true;
});
document.getElementById("arrowToggle").addEventListener("change", (event) => {
directionArrow.visible = event.target.checked;
sourceMarker.visible = event.target.checked;
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
updateSun();
applyCamera();
resize();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
// A subtle pulse keeps the symbolic source easy to locate.
const pulse = 1 + Math.sin(clock.getElapsedTime() * 2.2) * 0.055;
sourceMarker.scale.setScalar(pulse);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```