Spaces:
Running
Upload airport_building_preview_three.html
Browse files🏙️ Procedural 3D City Dashboard (WebGL + GPT-5 Experiment)
🎯 Overview
This project is an AI-assisted no-code experiment built with Three.js and enhanced by GPT-5.
It procedurally generates a colorful, realistic 3D city—complete with buildings, streets, cars, pedestrians, and airport runways—directly in the browser.
The scene is fully interactive with cinematic sunlight, depth effects, and UE-style post-processing.
🧩 Features
🌇 Procedural World Generation
Buildings: randomized architecture styles (brick, glass, painted) with PBR-style materials
Dynamic streets with crosswalks, reflections, and light variation
Cars & pedestrians that move procedurally
Airport area with planes, signals, and runways
☀️ Lighting & Environment
Physically-based sunlight system with color shift (warm at dawn/dusk, white at noon)
Soft shadows, fog, and ambient hemisphere lighting
Night mode adds emissive window lights to buildings
🎨 Visual Effects (Unreal-style)
Bloom, Depth of Field, Vignette, FXAA, SSAO, and Clarity filter
Auto-focus on selected objects (Depth of Field)
Real-time exposure & sharpness controls
🧠 Dashboard & UI
Dockable panels for:
City controls
Post-FX sliders
Object info inspector
Close buttons for each panel and a “Hide All (H)” hotkey
Preset: Clarity → disables blur, boosts contrast, and sharpens details
|
@@ -0,0 +1,807 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Procedural 3D City + Airport (UE-style Features)</title>
|
| 7 |
+
<style>
|
| 8 |
+
:root { --ui: rgba(255,255,255,.85); --accent:#1a56db; }
|
| 9 |
+
html, body { margin:0; height:100%; background:#cfe6ff; color:#0b1220; font-family:Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }
|
| 10 |
+
#app { position:fixed; inset:0; }
|
| 11 |
+
.ui { position:fixed; top:12px; left:12px; display:flex; flex-direction:column; gap:10px; background:var(--ui); padding:12px 14px; border-radius:14px; box-shadow:0 10px 30px rgba(0,0,0,.18); backdrop-filter: blur(6px); z-index:10; max-width: 430px; }
|
| 12 |
+
.ui h1 { margin:0; font-size:14px; opacity:.95; letter-spacing:.5px; font-weight:700; }
|
| 13 |
+
.row { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
|
| 14 |
+
.row label { width:160px; font-size:12px; opacity:.9; }
|
| 15 |
+
.row input[type="range"] { width:180px; }
|
| 16 |
+
.btn { cursor:pointer; border:1px solid #b9c7e6; background:#eef4ff; padding:8px 10px; border-radius:8px; color:#0b1220; font-size:12px; }
|
| 17 |
+
.btn:hover { border-color:#90a7d9; }
|
| 18 |
+
.credit { position:fixed; right:12px; bottom:10px; font-size:12px; opacity:.7; }
|
| 19 |
+
.legend { font-size:11px; opacity:.8; }
|
| 20 |
+
.panel { position:fixed; right:12px; top:12px; width:420px; background:var(--ui); padding:10px 12px; border-radius:12px; box-shadow:0 10px 30px rgba(0,0,0,.18); backdrop-filter: blur(6px); z-index:10; }
|
| 21 |
+
.panel h2 { margin:0 0 6px; font-size:13px; }
|
| 22 |
+
.log, .infoBody { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size:11px; max-height:200px; overflow:auto; background:#f4f7ff; border:1px solid #b9c7e6; border-radius:8px; padding:8px; color:#0b1220; }
|
| 23 |
+
.pass { color:#148a3b; }
|
| 24 |
+
.fail { color:#b00020; }
|
| 25 |
+
.dashboard { position:fixed; right:12px; top:260px; width:420px; background:var(--ui); padding:10px 12px; border-radius:12px; box-shadow:0 10px 30px rgba(0,0,0,.18); backdrop-filter: blur(6px); z-index:10; }
|
| 26 |
+
.dashboard .row { gap:6px; }
|
| 27 |
+
.dashboard label { width:auto; }
|
| 28 |
+
.miniwrap { display:flex; gap:10px; align-items:flex-start; }
|
| 29 |
+
#minimap { width:170px; height:170px; background:#f4f7ff; border:1px solid #b9c7e6; border-radius:8px; }
|
| 30 |
+
.filters { display:grid; grid-template-columns:repeat(2, minmax(0,1fr)); gap:6px; font-size:12px; }
|
| 31 |
+
.searchbar { display:flex; gap:6px; }
|
| 32 |
+
.searchbar input { flex:1; padding:6px 8px; background:#f4f7ff; border:1px solid #b9c7e6; border-radius:8px; color:#0b1220; font-size:12px; }
|
| 33 |
+
.infopanel { position:fixed; right:12px; bottom:12px; width:420px; background:var(--ui); padding:10px 12px; border-radius:12px; box-shadow:0 10px 30px rgba(0,0,0,.18); backdrop-filter: blur(6px); z-index:10; }
|
| 34 |
+
.infopanel h3 { margin:0 0 6px; font-size:13px; }
|
| 35 |
+
.hidden { display:none !important; }
|
| 36 |
+
.icon { position:absolute; top:6px; right:8px; border:none; background:rgba(0,0,0,.08); color:#0b1220; border-radius:6px; padding:2px 6px; cursor:pointer; font-size:12px; }
|
| 37 |
+
.icon:hover { background:rgba(0,0,0,.15); }
|
| 38 |
+
.ui .icon { right:8px; }
|
| 39 |
+
.panel .icon, .dashboard .icon, .infopanel .icon { right:8px; }
|
| 40 |
+
.btn.small { padding:4px 8px; font-size:12px; }
|
| 41 |
+
.dock { position:fixed; left:50%; transform:translateX(-50%); bottom:12px; display:flex; gap:8px; align-items:center; background:var(--ui); padding:6px 10px; border-radius:999px; box-shadow:0 8px 24px rgba(0,0,0,.18); z-index:11; backdrop-filter: blur(6px); }
|
| 42 |
+
</style>
|
| 43 |
+
|
| 44 |
+
<!-- Import Map: resolves 'three' & addons to full URLs (fixes module specifier error) -->
|
| 45 |
+
<script type="importmap">
|
| 46 |
+
{
|
| 47 |
+
"imports": {
|
| 48 |
+
"three": "https://unpkg.com/three@0.160.0/build/three.module.js",
|
| 49 |
+
"three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/"
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
</script>
|
| 53 |
+
</head>
|
| 54 |
+
<body>
|
| 55 |
+
<div id="app"></div>
|
| 56 |
+
<div id="uiPanel" class="ui"><button class="icon x" data-hide="uiPanel" title="Close">✕</button><button class="icon min" data-hide="uiPanel" title="Close">—</button>
|
| 57 |
+
<h1>Procedural City (3D)</h1>
|
| 58 |
+
<div class="row"><label># Buildings</label><input id="count" type="range" min="1" max="20" step="1" value="9"><span id="countVal">9</span></div>
|
| 59 |
+
<div class="row"><label>Max Floors</label><input id="floors" type="range" min="6" max="60" step="2" value="24"><span id="floorsVal">24</span></div>
|
| 60 |
+
<div class="row"><label>Footprint Variance</label><input id="variance" type="range" min="0" max="1" step="0.01" value="0.5"><span id="varianceVal">0.50</span></div>
|
| 61 |
+
<div class="row"><label>Cars</label><input id="cars" type="range" min="0" max="50" step="1" value="16"><span id="carsVal">16</span></div>
|
| 62 |
+
<div class="row"><label>People</label><input id="people" type="range" min="0" max="60" step="1" value="20"><span id="peopleVal">20</span></div>
|
| 63 |
+
<div class="row"><label>Airport</label><input id="airportOn" type="checkbox" checked></div>
|
| 64 |
+
<div class="row"><label>Planes</label><input id="planes" type="range" min="0" max="12" step="1" value="4"><span id="planesVal">4</span></div>
|
| 65 |
+
<div class="row"><label>Streets</label><input id="streetsOn" type="checkbox" checked></div>
|
| 66 |
+
<div class="row"><label>Night Mode</label><input id="night" type="checkbox"></div>
|
| 67 |
+
<div class="row"><label>Cinematic Bloom</label><input id="bloom" type="checkbox"></div>
|
| 68 |
+
<div class="row"><label>Auto Orbit</label><input id="orbit" type="checkbox" checked></div>
|
| 69 |
+
|
| 70 |
+
<!-- UE-like rendering controls -->
|
| 71 |
+
<div class="row"><label>SSAO (ambient occlusion)</label><input id="ssao" type="checkbox" checked></div>
|
| 72 |
+
<div class="row"><label>Depth of Field</label><input id="dof" type="checkbox"></div>
|
| 73 |
+
<div class="row"><label>DOF Focus Distance</label><input id="dofFocus" type="range" min="5" max="150" step="1" value="40"><span id="dofFocusVal">40</span></div>
|
| 74 |
+
<div class="row"><label>DOF Aperture</label><input id="dofAperture" type="range" min="0" max="0.002" step="0.00005" value="0.00025"><span id="dofApertureVal">0.00025</span></div>
|
| 75 |
+
<div class="row"><label>Exposure</label><input id="exposure" type="range" min="0.6" max="1.6" step="0.01" value="1.0"><span id="exposureVal">1.00</span></div>
|
| 76 |
+
<div class="row"><label>FXAA (anti‑aliasing)</label><input id="fxaa" type="checkbox" checked></div>
|
| 77 |
+
<div class="row"><label>Vignette</label><input id="vignette" type="checkbox"></div>
|
| 78 |
+
<div class="row"><label>Sun Elevation</label><input id="sunElev" type="range" min="5" max="85" step="1" value="55"><span id="sunElevVal">55°</span></div>
|
| 79 |
+
<div class="row"><label>Sun Azimuth</label><input id="sunAzi" type="range" min="0" max="360" step="1" value="45"><span id="sunAziVal">45°</span></div>
|
| 80 |
+
|
| 81 |
+
<div class="row"><button class="btn" id="regen">Regenerate (R)</button><button class="btn" id="pause">Pause Build</button><button class="btn" id="runTests">Run Tests</button></div>
|
| 82 |
+
<div class="legend">Sunlight + UE-style pipeline • Mouse: drag/orbit • wheel: zoom • right-drag: pan • Click objects for details</div>
|
| 83 |
+
</div>
|
| 84 |
+
|
| 85 |
+
<div id="testsPanel" class="panel"><button class="icon x" data-hide="testsPanel" title="Close">✕</button>
|
| 86 |
+
<h2>Runtime Tests</h2>
|
| 87 |
+
<div class="log" id="testLog">Waiting…</div>
|
| 88 |
+
</div>
|
| 89 |
+
|
| 90 |
+
<div id="dashPanel" class="dashboard"><button class="icon x" data-hide="dashPanel" title="Close">✕</button>
|
| 91 |
+
<h2>Interactive Dashboard</h2>
|
| 92 |
+
<div class="searchbar">
|
| 93 |
+
<input id="search" placeholder="Search e.g. plane:2, car:5, person:3, building:7"/>
|
| 94 |
+
<button class="btn" id="searchBtn">Find</button>
|
| 95 |
+
</div>
|
| 96 |
+
<div class="miniwrap">
|
| 97 |
+
<canvas id="minimap" width="170" height="170"></canvas>
|
| 98 |
+
<div class="filters">
|
| 99 |
+
<label><input type="checkbox" id="fPlanes" checked> Planes</label>
|
| 100 |
+
<label><input type="checkbox" id="fCars" checked> Cars</label>
|
| 101 |
+
<label><input type="checkbox" id="fPeople" checked> People</label>
|
| 102 |
+
<label><input type="checkbox" id="fBuildings" checked> Buildings</label>
|
| 103 |
+
<label><input type="checkbox" id="fStreets" checked> Streets</label>
|
| 104 |
+
<label><input type="checkbox" id="fAirport" checked> Airport</label>
|
| 105 |
+
</div>
|
| 106 |
+
</div>
|
| 107 |
+
</div>
|
| 108 |
+
|
| 109 |
+
<div id="infoPanel" class="infopanel"><button class="icon x" data-hide="infoPanel" title="Close">✕</button>
|
| 110 |
+
<h3>Selected Object</h3>
|
| 111 |
+
<div class="infoBody" id="info">Click a plane/car/person/building…</div>
|
| 112 |
+
</div>
|
| 113 |
+
|
| 114 |
+
<div class="credit">Sunlit preview • UE-style: Sky/Env, SSAO, DOF, FXAA, Vignette • Procedural city+airport • Interactive dashboard</div>
|
| 115 |
+
|
| 116 |
+
<!-- Dock before scripts so listeners can bind safely -->
|
| 117 |
+
<div class="dock" id="dock">
|
| 118 |
+
<span>Panels:</span>
|
| 119 |
+
<button class="btn small" data-show="uiPanel">UI</button>
|
| 120 |
+
<button class="btn small" data-show="testsPanel">Tests</button>
|
| 121 |
+
<button class="btn small" data-show="dashPanel">Dashboard</button>
|
| 122 |
+
<button class="btn small" data-show="infoPanel">Info</button>
|
| 123 |
+
<button class="btn small" id="toggleAll">Hide All (H)</button>
|
| 124 |
+
</div>
|
| 125 |
+
|
| 126 |
+
<script type="module">
|
| 127 |
+
import * as THREE from 'three';
|
| 128 |
+
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
| 129 |
+
import { Sky } from 'three/addons/objects/Sky.js';
|
| 130 |
+
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
|
| 131 |
+
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
|
| 132 |
+
import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
|
| 133 |
+
import { SSAOPass } from 'three/addons/postprocessing/SSAOPass.js';
|
| 134 |
+
import { BokehPass } from 'three/addons/postprocessing/BokehPass.js';
|
| 135 |
+
import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';
|
| 136 |
+
import { FXAAShader } from 'three/addons/shaders/FXAAShader.js';
|
| 137 |
+
import { VignetteShader } from 'three/addons/shaders/VignetteShader.js';
|
| 138 |
+
|
| 139 |
+
// --- Core Scene ---
|
| 140 |
+
const app = document.getElementById('app');
|
| 141 |
+
const renderer = new THREE.WebGLRenderer({ antialias:true });
|
| 142 |
+
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
|
| 143 |
+
renderer.setSize(innerWidth, innerHeight);
|
| 144 |
+
renderer.shadowMap.enabled = true;
|
| 145 |
+
renderer.shadowMap.type = THREE.PCFSoftShadowMap; // softer shadows
|
| 146 |
+
renderer.outputColorSpace = THREE.SRGBColorSpace;
|
| 147 |
+
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
| 148 |
+
renderer.toneMappingExposure = 1.0; // daylight baseline (slider below)
|
| 149 |
+
app.appendChild(renderer.domElement);
|
| 150 |
+
|
| 151 |
+
const scene = new THREE.Scene();
|
| 152 |
+
scene.background = new THREE.Color(0xcfe6ff); // clear sky backdrop
|
| 153 |
+
|
| 154 |
+
const camera = new THREE.PerspectiveCamera(60, innerWidth/innerHeight, 0.1, 5000);
|
| 155 |
+
camera.position.set(64, 40, 64);
|
| 156 |
+
|
| 157 |
+
const controls = new OrbitControls(camera, renderer.domElement);
|
| 158 |
+
controls.enableDamping = true;
|
| 159 |
+
controls.target.set(0, 8, 0);
|
| 160 |
+
|
| 161 |
+
// Physically based sky & environment (UE-like)
|
| 162 |
+
const sky = new Sky();
|
| 163 |
+
sky.scale.setScalar(10000);
|
| 164 |
+
scene.add(sky);
|
| 165 |
+
const skyUniforms = sky.material.uniforms;
|
| 166 |
+
skyUniforms[ 'turbidity' ].value = 2.0;
|
| 167 |
+
skyUniforms[ 'rayleigh' ].value = 2.5;
|
| 168 |
+
skyUniforms[ 'mieCoefficient' ].value = 0.005;
|
| 169 |
+
skyUniforms[ 'mieDirectionalG' ].value = 0.8;
|
| 170 |
+
|
| 171 |
+
const sunVec = new THREE.Vector3();
|
| 172 |
+
function setSun(elevDeg, aziDeg){
|
| 173 |
+
const phi = THREE.MathUtils.degToRad(90 - elevDeg);
|
| 174 |
+
const theta = THREE.MathUtils.degToRad(aziDeg);
|
| 175 |
+
sunVec.setFromSphericalCoords(1, phi, theta);
|
| 176 |
+
sky.material.uniforms['sunPosition'].value.copy(sunVec);
|
| 177 |
+
sun.position.copy(sunVec.clone().multiplyScalar(200));
|
| 178 |
+
// Warm sun at low elevation, cooler at high
|
| 179 |
+
const t = elevDeg/85; // 0..1
|
| 180 |
+
const hue = 0.1 + (1-t)*0.05; // 0.15 -> 0.1
|
| 181 |
+
const sat = 0.55 - t*0.25; // more saturated at low sun
|
| 182 |
+
const light = 0.95 - (1-t)*0.25;
|
| 183 |
+
sun.color = new THREE.Color().setHSL(hue, sat, light);
|
| 184 |
+
sun.intensity = 1.2 + t*0.6;
|
| 185 |
+
hemi.intensity = 0.7 + t*0.3;
|
| 186 |
+
updateEnvironment();
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
const pmrem = new THREE.PMREMGenerator(renderer);
|
| 190 |
+
let envRT = null;
|
| 191 |
+
function updateEnvironment(){
|
| 192 |
+
if (envRT) envRT.dispose();
|
| 193 |
+
envRT = pmrem.fromScene(sky, 0.5);
|
| 194 |
+
scene.environment = envRT.texture;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
// Daytime lights (synced to sky sun)
|
| 198 |
+
const hemi = new THREE.HemisphereLight(0xffffff, 0xcad7ea, 0.9);
|
| 199 |
+
scene.add(hemi);
|
| 200 |
+
const sun = new THREE.DirectionalLight(0xffffff, 1.5);
|
| 201 |
+
sun.castShadow = true;
|
| 202 |
+
sun.shadow.mapSize.set(2048,2048);
|
| 203 |
+
sun.shadow.camera.left = sun.shadow.camera.bottom = -160;
|
| 204 |
+
sun.shadow.camera.right = sun.shadow.camera.top = 160;
|
| 205 |
+
scene.add(sun);
|
| 206 |
+
|
| 207 |
+
setSun(55, 45); // initial
|
| 208 |
+
|
| 209 |
+
// Distance fog
|
| 210 |
+
scene.fog = new THREE.FogExp2(0xdfeffd, 0.002);
|
| 211 |
+
|
| 212 |
+
// Postprocessing chain (UE-style order)
|
| 213 |
+
const composer = new EffectComposer(renderer);
|
| 214 |
+
const renderPass = new RenderPass(scene, camera);
|
| 215 |
+
composer.addPass(renderPass);
|
| 216 |
+
|
| 217 |
+
const ssaoPass = new SSAOPass(scene, camera, innerWidth, innerHeight);
|
| 218 |
+
ssaoPass.kernelRadius = 13; // stronger occlusion
|
| 219 |
+
ssaoPass.minDistance = 0.0005; ssaoPass.maxDistance = 0.12;
|
| 220 |
+
composer.addPass(ssaoPass);
|
| 221 |
+
|
| 222 |
+
const dofPass = new BokehPass(scene, camera, { focus: 40, aperture: 0.00025, maxblur: 0.01 });
|
| 223 |
+
dofPass.enabled = false;
|
| 224 |
+
composer.addPass(dofPass);
|
| 225 |
+
|
| 226 |
+
const bloomPass = new UnrealBloomPass(new THREE.Vector2(innerWidth, innerHeight), 0.0, 0.7, 0.85); // day off
|
| 227 |
+
composer.addPass(bloomPass);
|
| 228 |
+
|
| 229 |
+
const fxaaPass = new ShaderPass(FXAAShader);
|
| 230 |
+
fxaaPass.material.uniforms['resolution'].value.set(1/innerWidth, 1/innerHeight);
|
| 231 |
+
composer.addPass(fxaaPass);
|
| 232 |
+
|
| 233 |
+
const vignettePass = new ShaderPass(VignetteShader);
|
| 234 |
+
vignettePass.uniforms[ 'offset' ].value = 1.0;
|
| 235 |
+
vignettePass.uniforms[ 'darkness' ].value = 1.2;
|
| 236 |
+
vignettePass.enabled = false;
|
| 237 |
+
composer.addPass(vignettePass);
|
| 238 |
+
|
| 239 |
+
// Ground (PBR asphalt with env)
|
| 240 |
+
const groundGeo = new THREE.PlaneGeometry(1200, 1200);
|
| 241 |
+
const asphaltTex = makeAsphaltTexture();
|
| 242 |
+
asphaltTex.wrapS = asphaltTex.wrapT = THREE.RepeatWrapping;
|
| 243 |
+
asphaltTex.repeat.set(60,60);
|
| 244 |
+
const groundMat = new THREE.MeshStandardMaterial({ color: 0xd5dbe6, metalness:0.05, roughness:0.95, map: asphaltTex, envMapIntensity: 0.3 });
|
| 245 |
+
const ground = new THREE.Mesh(groundGeo, groundMat);
|
| 246 |
+
ground.rotation.x = -Math.PI/2;
|
| 247 |
+
ground.receiveShadow = true;
|
| 248 |
+
scene.add(ground);
|
| 249 |
+
|
| 250 |
+
// City holders
|
| 251 |
+
const city = new THREE.Group();
|
| 252 |
+
const streetLayer = new THREE.Group();
|
| 253 |
+
const trafficLayer = new THREE.Group();
|
| 254 |
+
const peopleLayer = new THREE.Group();
|
| 255 |
+
const airportLayer = new THREE.Group();
|
| 256 |
+
const planeLayer = new THREE.Group();
|
| 257 |
+
scene.add(city, streetLayer, trafficLayer, peopleLayer, airportLayer, planeLayer);
|
| 258 |
+
|
| 259 |
+
// ---------- Procedural Textures ----------
|
| 260 |
+
// Color helpers
|
| 261 |
+
function hslHex(h, s, l){ return new THREE.Color().setHSL(h, s, l).getHex(); }
|
| 262 |
+
function pick(arr){ return arr[Math.floor(Math.random()*arr.length)]; }
|
| 263 |
+
|
| 264 |
+
// Diverse facade textures
|
| 265 |
+
function makeBrickTexture(hue=0.02){
|
| 266 |
+
const c=document.createElement('canvas'); c.width=256; c.height=256; const x=c.getContext('2d');
|
| 267 |
+
x.fillStyle='#c7b5a3'; x.fillRect(0,0,256,256);
|
| 268 |
+
const h = hue*360; // slight hue tint
|
| 269 |
+
for(let yy=0; yy<16; yy++){
|
| 270 |
+
for(let xx=0; xx<32; xx++){
|
| 271 |
+
const off=(yy%2)*4; const w=6, hgt=8; const x0=xx*8 - off; const y0=yy*16 + (Math.random()*2-1);
|
| 272 |
+
const l=45+Math.random()*15, s=25+Math.random()*20; // varied brick colors
|
| 273 |
+
x.fillStyle=`hsl(${h}, ${s}%, ${l}%)`; x.fillRect(x0, y0, w, hgt);
|
| 274 |
+
x.fillStyle='rgba(0,0,0,0.06)'; x.fillRect(x0, y0+hgt-1, w, 1);
|
| 275 |
+
}
|
| 276 |
+
}
|
| 277 |
+
const tex=new THREE.CanvasTexture(c); tex.wrapS=tex.wrapT=THREE.RepeatWrapping; tex.anisotropy=8; return tex;
|
| 278 |
+
}
|
| 279 |
+
function makeGlassTexture(hue=0.55){
|
| 280 |
+
const c=document.createElement('canvas'); c.width=256; c.height=256; const x=c.getContext('2d');
|
| 281 |
+
const grad=x.createLinearGradient(0,0,0,256); grad.addColorStop(0,`hsla(${hue*360},60%,88%,1)`); grad.addColorStop(1,'#cfe6ff');
|
| 282 |
+
x.fillStyle=grad; x.fillRect(0,0,256,256);
|
| 283 |
+
x.strokeStyle='rgba(255,255,255,0.35)'; x.lineWidth=2;
|
| 284 |
+
for(let i=0;i<256;i+=16){ x.beginPath(); x.moveTo(i,0); x.lineTo(i,256); x.stroke(); }
|
| 285 |
+
for(let j=0;j<256;j+=24){ x.beginPath(); x.moveTo(0,j); x.lineTo(256,j); x.stroke(); }
|
| 286 |
+
const tex=new THREE.CanvasTexture(c); tex.wrapS=tex.wrapT=THREE.RepeatWrapping; tex.anisotropy=8; return tex;
|
| 287 |
+
}
|
| 288 |
+
function makePaintTexture(hue=0.1){
|
| 289 |
+
const c=document.createElement('canvas'); c.width=256; c.height=256; const x=c.getContext('2d');
|
| 290 |
+
x.fillStyle=`hsl(${hue*360}, 55%, 78%)`; x.fillRect(0,0,256,256);
|
| 291 |
+
// subtle panels
|
| 292 |
+
x.fillStyle='rgba(255,255,255,0.15)';
|
| 293 |
+
for(let i=0;i<256;i+=24){ x.fillRect(i,0,2,256); }
|
| 294 |
+
for(let j=0;j<256;j+=32){ x.fillRect(0,j,256,2); }
|
| 295 |
+
const tex=new THREE.CanvasTexture(c); tex.wrapS=tex.wrapT=THREE.RepeatWrapping; tex.anisotropy=8; return tex;
|
| 296 |
+
}
|
| 297 |
+
function makeWindowMaskTexture(){
|
| 298 |
+
const c=document.createElement('canvas'); c.width=128; c.height=128; const x=c.getContext('2d');
|
| 299 |
+
x.clearRect(0,0,128,128);
|
| 300 |
+
for(let y=6;y<128;y+=10){ for(let x0=6;x0<128;x0+=12){ if(Math.random()>0.55){ x.fillStyle='rgba(255,255,255,0.9)'; x.fillRect(x0, y, 6, 6);} } }
|
| 301 |
+
const tex=new THREE.CanvasTexture(c); tex.wrapS=tex.wrapT=THREE.RepeatWrapping; tex.anisotropy=4; return tex;
|
| 302 |
+
}
|
| 303 |
+
function makeCrosswalkTexture(){
|
| 304 |
+
const c=document.createElement('canvas'); c.width=256; c.height=256; const x=c.getContext('2d');
|
| 305 |
+
x.fillStyle='#c9d4e6'; x.fillRect(0,0,256,256);
|
| 306 |
+
x.fillStyle='rgba(255,255,255,0.95)';
|
| 307 |
+
for(let i=0;i<256;i+=24){ x.fillRect(i,0,12,256); }
|
| 308 |
+
return new THREE.CanvasTexture(c);
|
| 309 |
+
}
|
| 310 |
+
function makeAsphaltTexture() {
|
| 311 |
+
const c = document.createElement('canvas'); c.width = 256; c.height = 256; const ctx = c.getContext('2d');
|
| 312 |
+
ctx.fillStyle = '#e2e7f1'; ctx.fillRect(0,0,256,256);
|
| 313 |
+
for(let i=0;i<1600;i++){ const a = 70+Math.random()*80; ctx.fillStyle = `rgba(${a},${a},${a},${Math.random()*0.05})`; ctx.fillRect(Math.random()*256, Math.random()*256, 1, 1); }
|
| 314 |
+
return new THREE.CanvasTexture(c);
|
| 315 |
+
}
|
| 316 |
+
function makeLaneTexture() { // road with dashed lines
|
| 317 |
+
const c = document.createElement('canvas'); c.width = 256; c.height = 256; const ctx = c.getContext('2d');
|
| 318 |
+
ctx.fillStyle = '#c9d4e6'; ctx.fillRect(0,0,256,256);
|
| 319 |
+
ctx.strokeStyle = '#ffffff'; ctx.lineWidth = 6; ctx.setLineDash([18,18]);
|
| 320 |
+
ctx.beginPath(); ctx.moveTo(128,0); ctx.lineTo(128,256); ctx.stroke();
|
| 321 |
+
return new THREE.CanvasTexture(c);
|
| 322 |
+
}
|
| 323 |
+
function makeRunwayTexture() { // runway with centerline + side markings
|
| 324 |
+
const c = document.createElement('canvas'); c.width = 1024; c.height = 256; const ctx = c.getContext('2d');
|
| 325 |
+
ctx.fillStyle = '#bac8df'; ctx.fillRect(0,0,1024,256);
|
| 326 |
+
ctx.strokeStyle = '#ffffff'; ctx.lineWidth = 10; ctx.setLineDash([40,40]);
|
| 327 |
+
ctx.beginPath(); ctx.moveTo(0,128); ctx.lineTo(1024,128); ctx.stroke();
|
| 328 |
+
ctx.setLineDash([]); ctx.lineWidth = 6;
|
| 329 |
+
ctx.beginPath(); ctx.moveTo(0,40); ctx.lineTo(1024,40); ctx.moveTo(0,216); ctx.lineTo(1024,216); ctx.stroke();
|
| 330 |
+
return new THREE.CanvasTexture(c);
|
| 331 |
+
}
|
| 332 |
+
function makeFacadeTexture() { // legacy (kept for fallback)
|
| 333 |
+
const c = document.createElement('canvas'); c.width = 128; c.height = 128; const ctx = c.getContext('2d');
|
| 334 |
+
ctx.fillStyle = '#d7e1f2'; ctx.fillRect(0,0,128,128);
|
| 335 |
+
for (let x=0; x<128; x+=8){ ctx.fillStyle = x%16===0? '#c8d4eb':'#e7edf8'; ctx.fillRect(x,0,2,128); }
|
| 336 |
+
for (let y = 6; y < 128; y += 10) { for (let x = 6; x < 128; x += 12) { ctx.fillStyle = '#cfd9ec'; ctx.fillRect(x, y, 6, 6); } }
|
| 337 |
+
const tex = new THREE.CanvasTexture(c);
|
| 338 |
+
tex.anisotropy = renderer.capabilities.getMaxAnisotropy();
|
| 339 |
+
tex.wrapS = tex.wrapT = THREE.RepeatWrapping;
|
| 340 |
+
return tex;
|
| 341 |
+
}
|
| 342 |
+
function buildingMaterial(style='paint', hue=Math.random()){
|
| 343 |
+
let map; let metal=0.2, rough=0.85, emissive=0x000000, emissiveMap=null, envI=0.6;
|
| 344 |
+
if(style==='brick'){ map = makeBrickTexture(hue); metal=0.05; rough=0.95; envI=0.25; }
|
| 345 |
+
else if(style==='glass'){ map = makeGlassTexture(hue); metal=0.75; rough=0.15; envI=1.2; }
|
| 346 |
+
else { map = makePaintTexture(hue); metal=0.25; rough=0.6; envI=0.6; }
|
| 347 |
+
// window mask for night glow
|
| 348 |
+
emissiveMap = makeWindowMaskTexture();
|
| 349 |
+
return new THREE.MeshStandardMaterial({ color: hslHex(hue, 0.35, style==='glass'?0.8:0.65), metalness:metal, roughness:rough, map, envMapIntensity: envI, emissive: emissive, emissiveMap, emissiveIntensity: 0.0 });
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
// ---------- UI ----------
|
| 353 |
+
const ui = {
|
| 354 |
+
count: document.getElementById('count'), countVal: document.getElementById('countVal'),
|
| 355 |
+
floors: document.getElementById('floors'), floorsVal: document.getElementById('floorsVal'),
|
| 356 |
+
variance: document.getElementById('variance'), varianceVal: document.getElementById('varianceVal'),
|
| 357 |
+
cars: document.getElementById('cars'), carsVal: document.getElementById('carsVal'),
|
| 358 |
+
people: document.getElementById('people'), peopleVal: document.getElementById('peopleVal'),
|
| 359 |
+
airportOn: document.getElementById('airportOn'), planes: document.getElementById('planes'), planesVal: document.getElementById('planesVal'),
|
| 360 |
+
streetsOn: document.getElementById('streetsOn'), night: document.getElementById('night'), bloom: document.getElementById('bloom'),
|
| 361 |
+
orbit: document.getElementById('orbit'), regen: document.getElementById('regen'), pause: document.getElementById('pause'),
|
| 362 |
+
runTests: document.getElementById('runTests'), testLog: document.getElementById('testLog'),
|
| 363 |
+
// dashboard
|
| 364 |
+
minimap: document.getElementById('minimap'),
|
| 365 |
+
fPlanes: document.getElementById('fPlanes'), fCars: document.getElementById('fCars'), fPeople: document.getElementById('fPeople'), fBuildings: document.getElementById('fBuildings'), fStreets: document.getElementById('fStreets'), fAirport: document.getElementById('fAirport'),
|
| 366 |
+
search: document.getElementById('search'), searchBtn: document.getElementById('searchBtn'),
|
| 367 |
+
info: document.getElementById('info'),
|
| 368 |
+
// UE-like controls
|
| 369 |
+
ssao: document.getElementById('ssao'), dof: document.getElementById('dof'), dofFocus: document.getElementById('dofFocus'), dofAperture: document.getElementById('dofAperture'),
|
| 370 |
+
dofFocusVal: document.getElementById('dofFocusVal'), dofApertureVal: document.getElementById('dofApertureVal'),
|
| 371 |
+
fxaa: document.getElementById('fxaa'), vignette: document.getElementById('vignette'),
|
| 372 |
+
exposure: document.getElementById('exposure'), exposureVal: document.getElementById('exposureVal'),
|
| 373 |
+
sunElev: document.getElementById('sunElev'), sunElevVal: document.getElementById('sunElevVal'),
|
| 374 |
+
sunAzi: document.getElementById('sunAzi'), sunAziVal: document.getElementById('sunAziVal')
|
| 375 |
+
};
|
| 376 |
+
function syncUI(){
|
| 377 |
+
ui.countVal.textContent = ui.count.value;
|
| 378 |
+
ui.floorsVal.textContent = ui.floors.value;
|
| 379 |
+
ui.varianceVal.textContent = (+ui.variance.value).toFixed(2);
|
| 380 |
+
ui.carsVal.textContent = ui.cars.value;
|
| 381 |
+
ui.peopleVal.textContent = ui.people.value;
|
| 382 |
+
ui.planesVal.textContent = ui.planes.value;
|
| 383 |
+
ui.dofFocusVal.textContent = ui.dofFocus.value;
|
| 384 |
+
ui.dofApertureVal.textContent = (+ui.dofAperture.value).toFixed(5);
|
| 385 |
+
ui.exposureVal.textContent = (+ui.exposure.value).toFixed(2);
|
| 386 |
+
ui.sunElevVal.textContent = ui.sunElev.value + '°';
|
| 387 |
+
ui.sunAziVal.textContent = ui.sunAzi.value + '°';
|
| 388 |
+
}
|
| 389 |
+
syncUI();
|
| 390 |
+
['input','change'].forEach(ev => {
|
| 391 |
+
[ui.count, ui.floors, ui.variance, ui.cars, ui.people, ui.planes].forEach(el=> el.addEventListener(ev, syncUI));
|
| 392 |
+
[ui.fPlanes, ui.fCars, ui.fPeople, ui.fBuildings, ui.fStreets, ui.fAirport].forEach(el=> el.addEventListener(ev, updateFilters));
|
| 393 |
+
[ui.dofFocus, ui.dofAperture, ui.exposure, ui.sunElev, ui.sunAzi].forEach(el=> el.addEventListener(ev, ()=>{ syncUI(); applyUEControls(); }));
|
| 394 |
+
[ui.ssao, ui.dof, ui.fxaa, ui.vignette, ui.bloom].forEach(el=> el && el.addEventListener('change', applyUEControls));
|
| 395 |
+
});
|
| 396 |
+
|
| 397 |
+
// ---------- Generators ----------
|
| 398 |
+
const rng = (seed => () => (seed = (seed*9301 + 49297) % 233280) / 233280)(Math.random()*1e9);
|
| 399 |
+
const BUILDINGS = [];
|
| 400 |
+
|
| 401 |
+
function clearGroup(g){ while(g.children.length){ const ch=g.children.pop(); ch.traverse(o=>{ if(o.geometry) o.geometry.dispose(); if(o.material){ if(Array.isArray(o.material)) o.material.forEach(m=>m.map?.dispose()); o.material.map?.dispose(); o.material.dispose(); }}); } }
|
| 402 |
+
function clearAll(){ BUILDINGS.length=0; clearGroup(city); clearGroup(streetLayer); clearGroup(trafficLayer); clearGroup(peopleLayer); clearGroup(airportLayer); clearGroup(planeLayer); idCounters = { building:0, car:0, person:0, plane:0 }; idMap.clear(); }
|
| 403 |
+
|
| 404 |
+
function createBuilding(x, z, maxFloors, variance) {
|
| 405 |
+
const group = new THREE.Group(); group.position.set(x, 0, z);
|
| 406 |
+
const baseW = 2 + rng()*3; const baseD = 2 + rng()*3; const levels = 4 + Math.floor(rng()*maxFloors);
|
| 407 |
+
const steps = 1 + Math.floor(rng()*3);
|
| 408 |
+
const stepHeights = []; let remaining = levels;
|
| 409 |
+
for (let i=0;i<steps;i++) { const seg = i===steps-1 ? remaining : 1 + Math.floor(rng()*Math.max(1, remaining-1)); stepHeights.push(seg); remaining -= seg; }
|
| 410 |
+
let currentY = 0; let w = baseW, d = baseD;
|
| 411 |
+
const style = pick(['brick','glass','paint','paint','brick']);
|
| 412 |
+
const hue = Math.random();
|
| 413 |
+
const mat = buildingMaterial(style, hue);
|
| 414 |
+
const floorsMeshes = [];
|
| 415 |
+
for (let s=0; s<steps; s++) {
|
| 416 |
+
if (s>0) { w *= 0.9 + (rng()-0.5)*variance*0.4; d *= 0.9 + (rng()-0.5)*variance*0.4; }
|
| 417 |
+
const h = stepHeights[s] * 0.6;
|
| 418 |
+
const geo = new THREE.BoxGeometry(w, h, d);
|
| 419 |
+
const mesh = new THREE.Mesh(geo, mat.clone());
|
| 420 |
+
mesh.castShadow = true; mesh.receiveShadow = true;
|
| 421 |
+
mesh.position.y = currentY + h/2; mesh.userData._targetY = mesh.position.y; mesh.position.y = 0;
|
| 422 |
+
group.add(mesh); floorsMeshes.push(mesh); currentY += h;
|
| 423 |
+
}
|
| 424 |
+
// Rooftop detail
|
| 425 |
+
if (rng() > 0.4) {
|
| 426 |
+
if (rng() > 0.5) {
|
| 427 |
+
const dish = new THREE.Mesh(new THREE.ConeGeometry(0.4, 0.6, 16), new THREE.MeshStandardMaterial({color:0x7ea8ff, metalness:.6, roughness:.3, envMapIntensity:.6}));
|
| 428 |
+
dish.position.set( (rng()-.5)*w*0.5, currentY + 0.4, (rng()-.5)*d*0.5 ); dish.rotation.x = -Math.PI/2 * (0.6 + rng()*0.4); dish.castShadow = true; group.add(dish);
|
| 429 |
+
} else {
|
| 430 |
+
const tank = new THREE.Mesh(new THREE.CylinderGeometry(0.4,0.4,0.6,20), new THREE.MeshStandardMaterial({color:0x8aa1bf, metalness:.4, roughness:.5, envMapIntensity:.6}));
|
| 431 |
+
tank.position.set( (rng()-.5)*w*0.5, currentY + 0.35, (rng()-.5)*d*0.5 ); tank.castShadow = true; group.add(tank);
|
| 432 |
+
}
|
| 433 |
+
}
|
| 434 |
+
const id = nextId('building');
|
| 435 |
+
group.userData = { kind:'building', id, style, hue };
|
| 436 |
+
BUILDINGS.push({ group, floorsMeshes, progress:0 });
|
| 437 |
+
return group;
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
function generateStreets(grid, spacing){
|
| 441 |
+
const laneTex = makeLaneTexture(); laneTex.wrapS = laneTex.wrapT = THREE.RepeatWrapping; laneTex.repeat.set(1, 10);
|
| 442 |
+
const roadMat = new THREE.MeshStandardMaterial({ map: laneTex, roughness:0.9, metalness:0.05, envMapIntensity:0.2 });
|
| 443 |
+
for(let i=-(grid-1)/2;i<=(grid-1)/2;i++){
|
| 444 |
+
const roadZ = new THREE.Mesh(new THREE.PlaneGeometry(3.2, grid*spacing + 10), roadMat);
|
| 445 |
+
roadZ.rotation.x = -Math.PI/2; roadZ.position.set(i*spacing, 0.01, 0);
|
| 446 |
+
roadZ.receiveShadow = true; streetLayer.add(roadZ);
|
| 447 |
+
const roadX = new THREE.Mesh(new THREE.PlaneGeometry(grid*spacing + 10, 3.2), roadMat);
|
| 448 |
+
roadX.rotation.x = -Math.PI/2; roadX.position.set(0, 0.01, i*spacing);
|
| 449 |
+
roadX.receiveShadow = true; streetLayer.add(roadX);
|
| 450 |
+
}
|
| 451 |
+
// Add crosswalks at a few intersections for color/realism
|
| 452 |
+
const cwTex = makeCrosswalkTexture(); cwTex.wrapS=cwTex.wrapT=THREE.RepeatWrapping; cwTex.repeat.set(0.3,0.3);
|
| 453 |
+
const cwMat = new THREE.MeshStandardMaterial({ map:cwTex, transparent:true, opacity:0.85, roughness:0.9 });
|
| 454 |
+
for(let gx=-1; gx<=1; gx++){
|
| 455 |
+
for(let gz=-1; gz<=1; gz++){
|
| 456 |
+
if(Math.random()>0.6){
|
| 457 |
+
const m=new THREE.Mesh(new THREE.PlaneGeometry(6,6), cwMat);
|
| 458 |
+
m.rotation.x=-Math.PI/2; m.position.set(gx*spacing, 0.022, gz*spacing); m.receiveShadow=true; streetLayer.add(m);
|
| 459 |
+
}
|
| 460 |
+
}
|
| 461 |
+
}
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
// Airport (daylight look)
|
| 465 |
+
function generateAirport(grid, spacing){
|
| 466 |
+
const offsetX = grid*spacing*0.8;
|
| 467 |
+
const offsetZ = -grid*spacing*1.2;
|
| 468 |
+
const rwTex = makeRunwayTexture(); rwTex.wrapS = rwTex.wrapT = THREE.RepeatWrapping; rwTex.repeat.set(1, 2);
|
| 469 |
+
const runway = new THREE.Mesh(new THREE.PlaneGeometry(400, 40), new THREE.MeshStandardMaterial({ map: rwTex, roughness:0.9, envMapIntensity:0.2 }));
|
| 470 |
+
runway.rotation.x = -Math.PI/2; runway.position.set(offsetX, 0.02, offsetZ);
|
| 471 |
+
runway.receiveShadow = true; airportLayer.add(runway);
|
| 472 |
+
const taxi = new THREE.Mesh(new THREE.PlaneGeometry(400, 16), new THREE.MeshStandardMaterial({ color:0xb7c6de, roughness:0.92, envMapIntensity:0.2 }));
|
| 473 |
+
taxi.rotation.x = -Math.PI/2; taxi.position.set(offsetX, 0.021, offsetZ+36);
|
| 474 |
+
taxi.receiveShadow = true; airportLayer.add(taxi);
|
| 475 |
+
const termMat = new THREE.MeshStandardMaterial({ color:0xbcd6f5, metalness:0.3, roughness:0.35, envMapIntensity:0.6 });
|
| 476 |
+
const term = new THREE.Mesh(new THREE.BoxGeometry(60, 10, 24), termMat);
|
| 477 |
+
term.position.set(offsetX-140, 5, offsetZ+48); term.castShadow=true; term.receiveShadow=true; airportLayer.add(term);
|
| 478 |
+
for(let i=0;i<4;i++){
|
| 479 |
+
const jet = new THREE.Mesh(new THREE.BoxGeometry(6, 3, 12), new THREE.MeshStandardMaterial({ color:0x9fc3ff, metalness:.4, roughness:.35, envMapIntensity:.6 }));
|
| 480 |
+
jet.position.set(offsetX-110 + i*16, 2.2, offsetZ+40); jet.castShadow=true; airportLayer.add(jet);
|
| 481 |
+
}
|
| 482 |
+
const tower = new THREE.Mesh(new THREE.CylinderGeometry(1.6,1.6,24,12), new THREE.MeshStandardMaterial({ color:0xa7b6cc, metalness:.3, roughness:.6, envMapIntensity:.5 }));
|
| 483 |
+
tower.position.set(offsetX+170, 12, offsetZ+50); tower.castShadow=true; airportLayer.add(tower);
|
| 484 |
+
airportLayer.userData = { kind:'airport' };
|
| 485 |
+
return { offsetX, offsetZ };
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
// Simple cars
|
| 489 |
+
const carGeo = new THREE.BoxGeometry(0.9, 0.5, 1.6);
|
| 490 |
+
function randomCarMat(){ return new THREE.MeshStandardMaterial({ color: new THREE.Color().setHSL(Math.random(), 0.65, 0.55).getHex(), metalness:0.65, roughness:0.35, envMapIntensity:1.0 }); }
|
| 491 |
+
function spawnCars(count, grid, spacing){
|
| 492 |
+
trafficLayer.clear();
|
| 493 |
+
for(let i=0;i<count;i++){
|
| 494 |
+
const mesh = new THREE.Mesh(carGeo, randomCarMat());
|
| 495 |
+
mesh.castShadow = true; mesh.receiveShadow = true;
|
| 496 |
+
const laneIndex = Math.floor(Math.random()*grid) - (grid-1)/2;
|
| 497 |
+
const vertical = Math.random() > 0.5;
|
| 498 |
+
const id = nextId('car');
|
| 499 |
+
mesh.userData = { kind:'car', id, vertical, laneIndex, t: Math.random()*Math.PI*2, speed: 6 + Math.random()*8, offset: (Math.random()-.5)*1.0 };
|
| 500 |
+
idMap.set(`car:${id}`, mesh);
|
| 501 |
+
trafficLayer.add(mesh);
|
| 502 |
+
}
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
// People as capsules
|
| 506 |
+
const personGeo = new THREE.CapsuleGeometry(0.15, 0.4, 4, 8);
|
| 507 |
+
function spawnPeople(count, grid, spacing){
|
| 508 |
+
peopleLayer.clear();
|
| 509 |
+
for(let i=0;i<count;i++){
|
| 510 |
+
const mat = new THREE.MeshStandardMaterial({ color: new THREE.Color().setHSL(Math.random(),0.45,0.55).getHex(), roughness:0.6, metalness:0.1, envMapIntensity:0.3 });
|
| 511 |
+
const p = new THREE.Mesh(personGeo, mat);
|
| 512 |
+
p.castShadow = true; p.receiveShadow = true;
|
| 513 |
+
const side = Math.random() > 0.5 ? 1 : -1;
|
| 514 |
+
const laneIndex = Math.floor(Math.random()*grid) - (grid-1)/2;
|
| 515 |
+
const vertical = Math.random() > 0.5;
|
| 516 |
+
const id = nextId('person');
|
| 517 |
+
p.userData = { kind:'person', id, vertical, laneIndex, t: Math.random()*Math.PI*2, speed: 1 + Math.random()*1.5, side };
|
| 518 |
+
idMap.set(`person:${id}`, p);
|
| 519 |
+
peopleLayer.add(p);
|
| 520 |
+
}
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
// Planes (simple)
|
| 524 |
+
const wingGeo = new THREE.BoxGeometry(6, 0.2, 1.2);
|
| 525 |
+
const bodyGeo = new THREE.CylinderGeometry(0.6, 0.8, 8, 12);
|
| 526 |
+
function makePlaneMesh(){
|
| 527 |
+
const g = new THREE.Group();
|
| 528 |
+
const body = new THREE.Mesh(bodyGeo, new THREE.MeshStandardMaterial({ color:0xf4f7ff, metalness:.5, roughness:.35, envMapIntensity:0.8 }));
|
| 529 |
+
body.rotation.z = Math.PI/2; body.castShadow = true; g.add(body);
|
| 530 |
+
const wing = new THREE.Mesh(wingGeo, new THREE.MeshStandardMaterial({ color:0x9ec3ff, metalness:.4, roughness:.35, envMapIntensity:0.8 }));
|
| 531 |
+
wing.position.set(0,0,0); g.add(wing);
|
| 532 |
+
const tail = new THREE.Mesh(new THREE.BoxGeometry(2, 1.2, 0.2), new THREE.MeshStandardMaterial({ color:0x9ec3ff, metalness:.4, roughness:.35, envMapIntensity:0.8 }));
|
| 533 |
+
tail.position.set(-3,0,0); g.add(tail);
|
| 534 |
+
return g;
|
| 535 |
+
}
|
| 536 |
+
|
| 537 |
+
function spawnPlanes(count, airport){
|
| 538 |
+
planeLayer.clear();
|
| 539 |
+
if (!airport) return;
|
| 540 |
+
for(let i=0;i<count;i++){
|
| 541 |
+
const plane = makePlaneMesh();
|
| 542 |
+
const t0 = Math.random()*Math.PI*2;
|
| 543 |
+
const id = nextId('plane');
|
| 544 |
+
plane.userData = { kind:'plane', id, t: t0, phase: Math.random(), speed: 0.25 + Math.random()*0.35, ox: airport.offsetX, oz: airport.offsetZ };
|
| 545 |
+
plane.position.set(airport.offsetX-180 + Math.random()*360, 1.5, airport.offsetZ+ (Math.random()<0.5?-6:6));
|
| 546 |
+
plane.castShadow = true; plane.receiveShadow = true;
|
| 547 |
+
idMap.set(`plane:${id}`, plane);
|
| 548 |
+
planeLayer.add(plane);
|
| 549 |
+
}
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
function generateCity(){
|
| 553 |
+
clearAll();
|
| 554 |
+
const N = +ui.count.value; const maxFloors = +ui.floors.value; const variance = +ui.variance.value;
|
| 555 |
+
const spacing = 8; const grid = Math.ceil(Math.sqrt(N));
|
| 556 |
+
let placed = 0;
|
| 557 |
+
for (let gx=0; gx<grid && placed < N; gx++) {
|
| 558 |
+
for (let gz=0; gz<grid && placed < N; gz++) {
|
| 559 |
+
const jitterX = (rng()-.5)*2; const jitterZ = (rng()-.5)*2;
|
| 560 |
+
const x = (gx - (grid-1)/2) * spacing + jitterX;
|
| 561 |
+
const z = (gz - (grid-1)/2) * spacing + jitterZ;
|
| 562 |
+
const b = createBuilding(x, z, maxFloors, variance);
|
| 563 |
+
city.add(b); placed++;
|
| 564 |
+
}
|
| 565 |
+
}
|
| 566 |
+
if (ui.streetsOn.checked) generateStreets(grid, spacing);
|
| 567 |
+
const airport = ui.airportOn.checked ? generateAirport(grid, spacing) : null;
|
| 568 |
+
spawnCars(+ui.cars.value, grid, spacing);
|
| 569 |
+
spawnPeople(+ui.people.value, grid, spacing);
|
| 570 |
+
spawnPlanes(+ui.planes.value, airport);
|
| 571 |
+
updateFilters();
|
| 572 |
+
}
|
| 573 |
+
|
| 574 |
+
// Build animation state
|
| 575 |
+
let paused = false; function setPaused(v){ paused = v; ui.pause.textContent = v ? 'Resume Build' : 'Pause Build'; }
|
| 576 |
+
setPaused(false);
|
| 577 |
+
|
| 578 |
+
// ---- Interaction: filters / search / picking ----
|
| 579 |
+
function updateFilters(){
|
| 580 |
+
planeLayer.visible = ui.fPlanes.checked;
|
| 581 |
+
trafficLayer.visible = ui.fCars.checked;
|
| 582 |
+
peopleLayer.visible = ui.fPeople.checked;
|
| 583 |
+
city.visible = ui.fBuildings.checked;
|
| 584 |
+
streetLayer.visible = ui.fStreets.checked;
|
| 585 |
+
airportLayer.visible = ui.fAirport.checked;
|
| 586 |
+
}
|
| 587 |
+
|
| 588 |
+
const raycaster = new THREE.Raycaster();
|
| 589 |
+
const mouse = new THREE.Vector2();
|
| 590 |
+
renderer.domElement.addEventListener('click', (e)=>{
|
| 591 |
+
const rect = renderer.domElement.getBoundingClientRect();
|
| 592 |
+
mouse.x = ((e.clientX - rect.left) / rect.width) * 2 - 1;
|
| 593 |
+
mouse.y = -((e.clientY - rect.top) / rect.height) * 2 + 1;
|
| 594 |
+
raycaster.setFromCamera(mouse, camera);
|
| 595 |
+
const targets = [ ...planeLayer.children, ...trafficLayer.children, ...peopleLayer.children ];
|
| 596 |
+
city.children.forEach(g=> g.traverse(o=>{ if (o.isMesh) targets.push(o); }));
|
| 597 |
+
const hits = raycaster.intersectObjects(targets, true);
|
| 598 |
+
if (hits.length){
|
| 599 |
+
const obj = findRoot(hits[0].object);
|
| 600 |
+
showInfo(obj);
|
| 601 |
+
}
|
| 602 |
+
});
|
| 603 |
+
|
| 604 |
+
function findRoot(o){
|
| 605 |
+
while(o && !o.userData?.kind && o.parent) o = o.parent;
|
| 606 |
+
return o;
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
let idCounters = { building:0, car:0, person:0, plane:0 };
|
| 610 |
+
const idMap = new Map();
|
| 611 |
+
function nextId(kind){ idCounters[kind]++; return idCounters[kind]; }
|
| 612 |
+
|
| 613 |
+
ui.searchBtn.addEventListener('click', ()=> searchAndFocus(ui.search.value.trim()));
|
| 614 |
+
ui.search.addEventListener('keydown', (e)=>{ if(e.key==='Enter') searchAndFocus(ui.search.value.trim()); });
|
| 615 |
+
|
| 616 |
+
function searchAndFocus(q){
|
| 617 |
+
const m = q.match(/^(plane|car|person|building):\s*(\d+)$/i);
|
| 618 |
+
if(!m){ ui.info.textContent = 'Use format kind:id e.g. plane:2'; return; }
|
| 619 |
+
const key = `${m[1].toLowerCase()}:${+m[2]}`;
|
| 620 |
+
const target = idMap.get(key);
|
| 621 |
+
if(!target){ ui.info.textContent = `Not found: ${key}`; return; }
|
| 622 |
+
showInfo(target);
|
| 623 |
+
const pos = new THREE.Vector3(); target.getWorldPosition(pos);
|
| 624 |
+
controls.target.copy(pos);
|
| 625 |
+
camera.position.lerp(pos.clone().add(new THREE.Vector3(12,8,12)), 0.5);
|
| 626 |
+
}
|
| 627 |
+
|
| 628 |
+
function showInfo(obj){
|
| 629 |
+
if(!obj) return;
|
| 630 |
+
const k = obj.userData?.kind || 'mesh';
|
| 631 |
+
const id = obj.userData?.id ?? '—';
|
| 632 |
+
const pos = new THREE.Vector3(); obj.getWorldPosition(pos);
|
| 633 |
+
let text = `Kind: ${k}\nID: ${id}\nPosition: ${pos.x.toFixed(2)}, ${pos.y.toFixed(2)}, ${pos.z.toFixed(2)}`;
|
| 634 |
+
if(k==='plane'){ const d = obj.userData; text += `\nSpeed: ${(d.speed*100).toFixed(1)} kn (sim)\nPhase: ${d.t.toFixed(2)}`; }
|
| 635 |
+
if(k==='car'){ const d = obj.userData; text += `\nSpeed: ${(d.speed).toFixed(1)} m/s\nVertical lane: ${d.vertical}`; }
|
| 636 |
+
if(k==='person'){ const d = obj.userData; text += `\nWalk speed: ${d.speed.toFixed(2)} m/s`; }
|
| 637 |
+
if(k==='building'){ text += `\nFloors: ${obj.children?.length || 0}`; }
|
| 638 |
+
ui.info.textContent = text;
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
// Apply UE-like control changes
|
| 642 |
+
function applyUEControls(){
|
| 643 |
+
// post-process toggles
|
| 644 |
+
ssaoPass.enabled = ui.ssao.checked;
|
| 645 |
+
dofPass.enabled = ui.dof.checked;
|
| 646 |
+
vignettePass.enabled = ui.vignette.checked;
|
| 647 |
+
bloomPass.strength = (ui.bloom.checked ? (ui.night.checked ? 0.8 : 0.15) : 0);
|
| 648 |
+
fxaaPass.enabled = ui.fxaa.checked;
|
| 649 |
+
// dof params
|
| 650 |
+
dofPass.materialBokeh.uniforms[ 'focus' ].value = +ui.dofFocus.value;
|
| 651 |
+
dofPass.materialBokeh.uniforms[ 'aperture' ].value = +ui.dofAperture.value;
|
| 652 |
+
// exposure
|
| 653 |
+
renderer.toneMappingExposure = +ui.exposure.value;
|
| 654 |
+
// sky / sun
|
| 655 |
+
setSun(+ui.sunElev.value, +ui.sunAzi.value);
|
| 656 |
+
}
|
| 657 |
+
|
| 658 |
+
// UI events
|
| 659 |
+
document.getElementById('regen').addEventListener('click', generateCity);
|
| 660 |
+
document.getElementById('pause').addEventListener('click', () => setPaused(!paused));
|
| 661 |
+
document.getElementById('runTests').addEventListener('click', runTests);
|
| 662 |
+
document.getElementById('orbit').addEventListener('change', ()=>{});
|
| 663 |
+
document.getElementById('night').addEventListener('change', ()=>{
|
| 664 |
+
const isNight = ui.night.checked;
|
| 665 |
+
scene.background.set(isNight?0x070a12:0xcfe6ff);
|
| 666 |
+
scene.fog.color.set(isNight?0x070a12:0xdfeffd);
|
| 667 |
+
hemi.intensity = isNight?0.6:0.9;
|
| 668 |
+
renderer.toneMappingExposure = isNight?1.25: +ui.exposure.value;
|
| 669 |
+
updateNightMaterials(isNight);
|
| 670 |
+
applyUEControls();
|
| 671 |
+
});
|
| 672 |
+
function updateNightMaterials(isNight){
|
| 673 |
+
city.traverse(o=>{
|
| 674 |
+
if(o.isMesh && o.material){
|
| 675 |
+
if(isNight){ o.material.emissiveIntensity = (o.material.emissiveMap? (0.6+Math.random()*0.6):0.0); }
|
| 676 |
+
else { o.material.emissiveIntensity = 0.0; }
|
| 677 |
+
o.material.needsUpdate = true;
|
| 678 |
+
}
|
| 679 |
+
});
|
| 680 |
+
}
|
| 681 |
+
document.getElementById('bloom').addEventListener('change', applyUEControls);
|
| 682 |
+
document.getElementById('ssao').addEventListener('change', applyUEControls);
|
| 683 |
+
document.getElementById('dof').addEventListener('change', applyUEControls);
|
| 684 |
+
document.getElementById('fxaa').addEventListener('change', applyUEControls);
|
| 685 |
+
document.getElementById('vignette').addEventListener('change', applyUEControls);
|
| 686 |
+
|
| 687 |
+
window.addEventListener('keydown', (e)=>{ if (e.key.toLowerCase()==='r') generateCity(); if (e.key.toLowerCase()==='p') setPaused(!paused); });
|
| 688 |
+
|
| 689 |
+
// Initial gen & apply
|
| 690 |
+
generateCity();
|
| 691 |
+
applyUEControls();
|
| 692 |
+
|
| 693 |
+
// Resize
|
| 694 |
+
addEventListener('resize', ()=>{
|
| 695 |
+
camera.aspect = innerWidth/innerHeight; camera.updateProjectionMatrix();
|
| 696 |
+
renderer.setSize(innerWidth, innerHeight); composer.setSize(innerWidth, innerHeight);
|
| 697 |
+
bloomPass.setSize(innerWidth, innerHeight);
|
| 698 |
+
ssaoPass.setSize(innerWidth, innerHeight);
|
| 699 |
+
fxaaPass.material.uniforms['resolution'].value.set(1/innerWidth, 1/innerHeight);
|
| 700 |
+
});
|
| 701 |
+
|
| 702 |
+
// ---- Minimap ----
|
| 703 |
+
const mm = ui.minimap.getContext('2d');
|
| 704 |
+
function drawMinimap(){
|
| 705 |
+
const w = ui.minimap.width, h = ui.minimap.height;
|
| 706 |
+
mm.clearRect(0,0,w,h);
|
| 707 |
+
mm.fillStyle = '#f4f7ff'; mm.fillRect(0,0,w,h);
|
| 708 |
+
mm.strokeStyle = '#90a7d9'; mm.strokeRect(0,0,w,h);
|
| 709 |
+
const scale = 0.4; const cx = w/2, cz = h/2;
|
| 710 |
+
function p(x,z){ return [ cx + x*scale, cz + z*scale ]; }
|
| 711 |
+
if (planeLayer.visible){ mm.fillStyle = '#1a56db'; planeLayer.children.forEach(o=>{ const v=new THREE.Vector3(); o.getWorldPosition(v); const [x,z]=p(v.x,v.z); mm.fillRect(x-2,z-2,4,4); }); }
|
| 712 |
+
if (trafficLayer.visible){ mm.fillStyle = '#148a3b'; trafficLayer.children.forEach(o=>{ const v=new THREE.Vector3(); o.getWorldPosition(v); const [x,z]=p(v.x,v.z); mm.fillRect(x-2,z-2,4,4); }); }
|
| 713 |
+
if (peopleLayer.visible){ mm.fillStyle = '#c77d00'; peopleLayer.children.forEach(o=>{ const v=new THREE.Vector3(); o.getWorldPosition(v); const [x,z]=p(v.x,v.z); mm.fillRect(x-1,z-1,2,2); }); }
|
| 714 |
+
if (airportLayer.visible){ mm.strokeStyle = '#1a56db'; mm.beginPath(); mm.moveTo(p(80,-96)[0], p(80,-96)[1]); mm.lineTo(p(280,-96)[0], p(280,-96)[1]); mm.stroke(); }
|
| 715 |
+
}
|
| 716 |
+
|
| 717 |
+
// Animate
|
| 718 |
+
let t = 0; function animate(){ requestAnimationFrame(animate); t += 0.016;
|
| 719 |
+
if (ui.orbit.checked) { const r = 72; const speed = 0.07; camera.position.x = Math.cos(t*speed)*r; camera.position.z = Math.sin(t*speed)*r; camera.lookAt(controls.target); } else { controls.update(); }
|
| 720 |
+
if (!paused){ for(const b of BUILDINGS){ b.progress = Math.min(1, b.progress + 0.01 + Math.random()*0.01); const eased = b.progress < .5 ? 2*b.progress*b.progress : 1 - Math.pow(-2*b.progress+2, 2)/2; const n=b.floorsMeshes.length; const reveal=Math.floor(eased*n); for(let i=0;i<n;i++){ const m=b.floorsMeshes[i]; const targetY=m.userData._targetY; if(i<reveal){ m.position.y += (targetY - m.position.y)*0.2; } else if(i===reveal){ const phase = (eased*n)-reveal; m.position.y = targetY*phase; } else { m.position.y = 0; } } } }
|
| 721 |
+
const roadLen = 120; trafficLayer.children.forEach(car=>{ const d = car.userData; const L = roadLen; d.t = (d.t + d.speed*0.016/L) % (Math.PI*2); if (d.vertical) { car.position.set(d.laneIndex*8 + d.offset, 0.3, Math.sin(d.t)*L/2); car.rotation.y = d.t>Math.PI?0:Math.PI; } else { car.position.set(Math.sin(d.t)*L/2, 0.3, d.laneIndex*8 + d.offset); car.rotation.y = d.t>Math.PI?Math.PI/2:-Math.PI/2; } });
|
| 722 |
+
peopleLayer.children.forEach(p=>{ const d=p.userData; const L=60; d.t=(d.t + d.speed*0.016/L)%(Math.PI*2); if(d.vertical){ p.position.set(d.laneIndex*8 + 2.4*d.side, 0.55, Math.sin(d.t)*L/2); } else { p.position.set(Math.sin(d.t)*L/2, 0.55, d.laneIndex*8 + 2.4*d.side); } p.rotation.y += 0.02; });
|
| 723 |
+
planeLayer.children.forEach(plane=>{ const d = plane.userData; d.t = (d.t + d.speed*0.016) % (Math.PI*2); const phase = d.t; const ox = d.ox, oz = d.oz; const runwayX = ox - 180 + (phase/Math.PI*2)*360; if (phase < Math.PI*0.25) { plane.position.set(runwayX, 1.5, oz+16); plane.rotation.y = 0; plane.rotation.x = 0; } else if (phase < Math.PI*0.5) { const k = (phase - Math.PI*0.25)/(Math.PI*0.25); plane.position.set(runwayX, 1.5 + k*6, oz+10); plane.rotation.x = -0.25*k; plane.rotation.y = 0; } else if (phase < Math.PI*1.3) { const k = (phase - Math.PI*0.5)/(Math.PI*0.8); plane.position.set(ox-180 + 360 + k*120, 7.5 + Math.sin(k*Math.PI)*40, oz+10 - k*80); plane.rotation.x = -0.25 + 0.15*Math.sin(k*Math.PI*0.7); plane.rotation.y = 0.2; } else { const k = (phase - Math.PI*1.3)/(Math.PI*0.7); plane.position.set(ox+60 - k*300, 20 - Math.min(19.5, k*22), oz+10 + k*6); plane.rotation.x = -0.1 + 0.1*k; plane.rotation.y = Math.PI; } });
|
| 724 |
+
city.traverse(obj=>{ if(obj.isMesh && obj.material && obj.material.map){ const tex=obj.material.map; tex.offset.x = (tex.offset.x + 0.00025) % 1; } });
|
| 725 |
+
composer.render();
|
| 726 |
+
drawMinimap();
|
| 727 |
+
} animate();
|
| 728 |
+
|
| 729 |
+
// -----------------------------
|
| 730 |
+
// Tests (kept + added)
|
| 731 |
+
// -----------------------------
|
| 732 |
+
function log(msg, ok=true){ const div = document.createElement('div'); div.className = ok ? 'pass' : 'fail'; div.textContent = (ok ? '✔ ' : '✖ ') + msg; ui.testLog.appendChild(div); ui.testLog.scrollTop = ui.testLog.scrollHeight; console[(ok?'log':'error')](msg); }
|
| 733 |
+
function resetLog(){ ui.testLog.textContent=''; }
|
| 734 |
+
function runTests(){ resetLog(); try{
|
| 735 |
+
// Existing tests (unchanged)
|
| 736 |
+
log('Scene created', !!scene);
|
| 737 |
+
log('City group exists', city instanceof THREE.Group);
|
| 738 |
+
const want = +ui.count.value; generateCity(); log(`Generated BUILDINGS == slider (${want})`, BUILDINGS.length === want);
|
| 739 |
+
let allFloors = true, mapsOK = true; for (const b of BUILDINGS){ if(!b.floorsMeshes || b.floorsMeshes.length===0) allFloors=false; for(const m of b.floorsMeshes){ if(!m.material || !m.material.map) mapsOK=false; } }
|
| 740 |
+
log('Each building has at least one floor', allFloors);
|
| 741 |
+
log('Window material maps attached', mapsOK);
|
| 742 |
+
const before = ui.pause.textContent; ui.pause.click(); const toggled = ui.pause.textContent !== before; ui.pause.click(); log('Pause/Resume button toggles label', toggled);
|
| 743 |
+
log('Orbit checkbox present', ui.orbit instanceof HTMLInputElement);
|
| 744 |
+
// Airport tests
|
| 745 |
+
ui.airportOn.checked = true; generateCity();
|
| 746 |
+
log('Airport layer has content when enabled', airportLayer.children.length>0);
|
| 747 |
+
ui.planes.value = 3; syncUI(); generateCity();
|
| 748 |
+
log('Planes spawned > 0 when enabled', planeLayer.children.length>0);
|
| 749 |
+
// Post FX tests
|
| 750 |
+
ui.ssao.checked = true; applyUEControls(); log('SSAO enabled', ssaoPass.enabled);
|
| 751 |
+
ui.dof.checked = true; applyUEControls(); log('DOF enabled', dofPass.enabled);
|
| 752 |
+
ui.fxaa.checked = true; applyUEControls(); log('FXAA enabled', fxaaPass.enabled);
|
| 753 |
+
ui.vignette.checked = true; applyUEControls(); log('Vignette enabled', vignettePass.enabled);
|
| 754 |
+
|
| 755 |
+
// New tests we add now
|
| 756 |
+
const mat = buildingMaterial('brick', 0.1);
|
| 757 |
+
log('buildingMaterial returns MeshStandardMaterial', mat && mat.isMeshStandardMaterial === true);
|
| 758 |
+
const streetsBefore = streetLayer.children.length; generateStreets(3, 8); const streetsAfter = streetLayer.children.length; log('generateStreets adds meshes', streetsAfter > streetsBefore);
|
| 759 |
+
log('Dock element exists', !!document.getElementById('dock'));
|
| 760 |
+
} catch(e){ log('Tests crashed: '+e.message, false); } }
|
| 761 |
+
runTests();
|
| 762 |
+
|
| 763 |
+
// --- Panel show/hide logic ---
|
| 764 |
+
const dock = document.getElementById('dock');
|
| 765 |
+
if (dock) {
|
| 766 |
+
document.querySelectorAll('[data-hide]').forEach(btn=>{
|
| 767 |
+
btn.addEventListener('click', ()=>{
|
| 768 |
+
const id = btn.getAttribute('data-hide');
|
| 769 |
+
document.getElementById(id)?.classList.add('hidden');
|
| 770 |
+
});
|
| 771 |
+
});
|
| 772 |
+
dock.querySelectorAll('[data-show]').forEach(btn=>{
|
| 773 |
+
btn.addEventListener('click', ()=>{
|
| 774 |
+
const id = btn.getAttribute('data-show');
|
| 775 |
+
document.getElementById(id)?.classList.remove('hidden');
|
| 776 |
+
});
|
| 777 |
+
});
|
| 778 |
+
let allHidden = false;
|
| 779 |
+
function setAllHidden(v){
|
| 780 |
+
allHidden = v;
|
| 781 |
+
['uiPanel','testsPanel','dashPanel','infoPanel'].forEach(id=>{
|
| 782 |
+
const el = document.getElementById(id);
|
| 783 |
+
if (!el) return;
|
| 784 |
+
if (v) el.classList.add('hidden'); else el.classList.remove('hidden');
|
| 785 |
+
});
|
| 786 |
+
document.getElementById('toggleAll').textContent = (v? 'Show All (H)' : 'Hide All (H)');
|
| 787 |
+
}
|
| 788 |
+
document.getElementById('toggleAll').addEventListener('click', ()=> setAllHidden(!allHidden));
|
| 789 |
+
window.addEventListener('keydown', (e)=>{
|
| 790 |
+
if (e.key.toLowerCase()==='h') setAllHidden(!allHidden);
|
| 791 |
+
if (e.key==='1') document.getElementById('uiPanel')?.classList.toggle('hidden');
|
| 792 |
+
if (e.key==='2') document.getElementById('testsPanel')?.classList.toggle('hidden');
|
| 793 |
+
if (e.key==='3') document.getElementById('dashPanel')?.classList.toggle('hidden');
|
| 794 |
+
if (e.key==='4') document.getElementById('infoPanel')?.classList.toggle('hidden');
|
| 795 |
+
});
|
| 796 |
+
} else {
|
| 797 |
+
console.warn('Dock element not found; panel toggles disabled');
|
| 798 |
+
}
|
| 799 |
+
</script>
|
| 800 |
+
|
| 801 |
+
<script>
|
| 802 |
+
if (!('importMap' in document.createElement('script'))) {
|
| 803 |
+
const el = document.getElementById('testLog'); if (el) { const warn = document.createElement('div'); warn.className = 'fail'; warn.textContent = 'Your browser may not support import maps. Please use a modern Chromium/Firefox/Safari.'; el.appendChild(warn); }
|
| 804 |
+
}
|
| 805 |
+
</script>
|
| 806 |
+
</body>
|
| 807 |
+
</html>
|