The user is asking for a single HTML file that loads three.js r160 via importmap. Procedural neon city, glowing windows (use a canvas texture? No external assets — procedural textures via canvas are fine), reflective wet ground (use reflections... MeshStandardMaterial with envMap? Simplest is a plane with high metalness and low roughness, plus fake reflections via mirrored building clones? Simpler: use a dark reflective plane with specular highlights from lights, or use a Reflector-like effect — but no OrbitControls or external addons. Can implement simple planar reflection by cloning the scene and flipping it... that's heavy. Alternative: use a large plane with MeshPhongMaterial that has a specular map? Without envMap, reflections will just be highlights from point lights. Can generate a procedural gradient environment map via PMREMGenerator with a simple scene? Actually THREE.PMREMGenerator can generate from a Scene. Can create a small scene with a gradient sky, generate envmap, apply to ground with metalness 1, roughness ~0.15 — gives a nice wet look.
Buildings: InstancedMesh with per-instance colors? Glowing windows: use a procedural canvas texture of a window grid, applied as emissive map. But instanced meshes share textures. Can create several building materials with different canvas textures (say 6 variants), each with an InstancedMesh. Varying height via instance matrix scaling — but the texture stretches. Acceptable. Or use per-building boxes with shared geometry and textures. Hundreds of buildings — use InstancedMesh with per-instance scale. Window texture with emissive map: emissive is uniform. Use instanceColor for tinting? Does instanceColor affect diffuse and emissive? In three, instanceColor only affects diffuse color. Can set emissiveMap and emissive white, and use instanceColor for hue variation of the windows... emissive isn't multiplied by instanceColor. Hmm.
Simpler, more polished approach: create about 5 building variants with canvas textures (dark facades with randomly lit windows, emissiveMap = same canvas so windows glow). Use InstancedMesh per variant with random scale/position. Vary window density via texture repeat? Can't do per-instance. Fine.
Neon signs: add glowing edge strips? Add a few emissive boxes as rooftop neon.
Ground: large plane, MeshStandardMaterial metalness 0.9 roughness 0.25, color nearly black, envMap from gradient. Add grid of glowing street lines: emissive planes slightly above ground along roads.
Cars: moving glowing boxes — use InstancedMesh with emissive material, update matrix each frame along road lines. Use a few rows of roads.
Fog: scene.fog dark purple. Background: gradient via scene background canvas texture, or a large sphere with shader. Use fog color matching.
Camera: slow orbit around center, looking at center, slight bobbing.
Road layout: grid of blocks. Buildings placed in blocks with roads between. City size about 20x20 blocks? "Hundreds of buildings" — e.g. 12x12 grid of blocks, 1-4 buildings per block → about 300. Roads between blocks.
Coordinate setup: block size B=22, road width R=8. Grid N=11 blocks. Position x = (i - N/2)*(B+R). Buildings per block: subdivide block into 2x2 lots with random heights.
Cars: for each road line (both directions), spawn cars moving in +x or +z. Update instance matrix. Use MeshBasicMaterial with instanceColor for car colors (red/white neon). Use small boxes.
Street lines: glowing lines along road centerlines — thin emissive planes, cyan/magenta. Use a single merged geometry or many planes. Use InstancedMesh of planes.
Point lights: a few colored point lights for atmosphere. Too many lights hurts performance. Use about 6 point lights, plus ambient/hemisphere.
Ground reflections: envMap gives glossy feel. Plus mirrored fake reflections: skip. Keep metalness ground with roughness ~0.1 and envMapIntensity, plus emissive street lines reflecting? envMap won't include buildings. To fake wet reflections of neon, could also add a second ground plane below? Simpler trick: place vertically flipped, dimmed clones of the buildings below the ground and make the ground semi-transparent? Heavy. Alternative: use Reflector from addons — not allowed (no other dependencies. Reflector is in three/addons and available on unpkg, but "no other dependencies" — three addons are part of the three package. But user said use three.module.js via importmap. Keep simple, skip true reflections. Fake it with glossy ground + point lights + emissive lines creating light pools.
Actually can cheaply fake reflections: draw a dark gradient on the ground material's... skip. Use a MeshStandardMaterial ground with envMap from a generated gradient scene containing some bright neon colors near horizon — gives color variation in reflections. Also add a subtle mirror trick: for the nearest buildings, create flipped clones? Skip for code brevity.
Better: use fog and bloom? Bloom needs postprocessing addons. Skip. Use additive glow sprites? Can add glow via sprite texture (canvas radial gradient) around car and signs. Nice touch: sprites for street glow.
Keep code organized. Write the file.
Key parts:
1. importmap: {"three": "https://unpkg.com/three@0.160.0/build/three.module.js"}
2. Renderer with ACESFilmicToneMapping, sRGB.
3. Scene fog: new THREE.FogExp2(0x05010f, 0.0075) or linear fog.
4. Background gradient: large sphere with vertex color, or canvas texture on scene.background? Use a big inverted sphere with ShaderMaterial gradient (top dark blue to purple horizon glow). Simpler: canvas texture on scene.background — but background texture is screen-space (flat). Gradient canvas as background works but doesn't rotate with camera... actually scene.background with a texture is static in screen space — acceptable as gradient? Fixed vertically. Fine. But fog color needs to match horizon. Use gradient sphere for consistency with orbit. Use ShaderMaterial BackSide sphere.
5. Env map: create a small scene with gradient sphere + a few bright emissive boxes, use PMREMGenerator.fromScene. Apply to ground material's envMap.
6. Window texture: canvas 64x128, dark base, randomly lit windows in colors (warm yellow, cyan, pink). Use as map and emissiveMap. texture.magFilter = NearestFilter for crispness. 4-6 variants with different palettes.
Buildings: BoxGeometry(1,1,1). For each building, matrix scale (w,h,d), position y=h/2. InstancedMesh per variant, count ~80. Also rooftop neon: small emissive boxes on some — another InstancedMesh of basic material, instanceColor.
7. Ground plane 600x600, standard material, metalness .95 roughness .18 color 0x0a0a12, envMap, envMapIntensity 1.
8. Street lines: plane geometry rotated flat, additive-blended MeshBasicMaterial, cyan/magenta, along road centerlines. Use InstancedMesh with instanceColor. Roads at x = (i - N/2 + .5)*(B+R)... define road positions between blocks.
9. Cars: InstancedMesh of boxes (2x1x1), MeshBasicMaterial white, instanceColor for headlight colors. Cars move along roads, wrap around. Store per-car data (axis, lane offset, speed, position). Update matrices each frame. instanceMatrix.setUsage(DynamicDrawUsage).
10. Lights: hemisphere (purple/dark), a few colored point lights along main streets.
11. Stars? Points in sky. Nice touch, cheap. Add.
12. Animation loop with clock. Camera orbit: radius ~90, height 30-40, slow rotation, lookAt(0, 10, 0).
Grid config: N=10 blocks, B=20, R=8, spacing S=B+R=28. City extent about 280. Ground 800. Fog density tuned.
Road centerlines: between blocks: for i in 0..N (inclusive)? Roads at boundaries: position = (i - N/2)*S, i in 0..N gives N+1 lines? Blocks centered at (i - (N-1)/2)*S for i in 0..N-1. Roads between at ((i+0.5-N/2)*S) for i in -? Let's compute: block centers c_i = (i - (N-1)/2)*S, i=0..N-1. Road centers r_j = (j - N/2)*S, j=0..N. So N+1 roads each direction.
Cars: for each road in x direction (z=r_j), cars with z=r_j ± 2 (lane), moving in x. Similarly z roads. Total maybe 200 cars. InstancedMesh count = total cars.
Street glow lines: for each road, a thin plane (width 0.6) along the length, alternating cyan/magenta, additive, y=0.05. Instanced planes: geometry PlaneGeometry(1,1) rotated -PI/2. Instance scale (length, roadWidth?) actually the plane is in XZ after rotation. Scale x and z. Use instanceColor.
Also add crosswalk-style glow? Keep simple.
Car glow sprites: maybe skip sprites for cars (perf), but add sprites for some neon signs. Add glow sprites above the city? Keep: create radial gradient texture. Use for street lamp glows — add street lamps: emissive small spheres on poles along roads? Could be many. Keep: add sprite glow at each road intersection? N+1 squared intersections = 121 sprites — use Points with additive material, size attenuation. Nice.
Building variants: makeBuildingTexture(hue palette). Windows: grid cols=8, rows vary. Random lit probability 0.35. Colors from palette. texture wrap repeat? With instanced scaling, texture stretches per face. To reduce stretching, set repeat based on average? Can't per instance. Accept. Or use separate meshes per building with per-building texture repeat cloned material — 300 materials is heavy but fine? 300 draw calls... acceptable on modern GPUs but instancing is cleaner. Compromise: make 6 variants. Each variant's InstancedMesh with height variation via scale. Windows will stretch vertically but with dark facade it's mostly fine. Also set texture repeat (2, 4) so windows appear smaller. Stretching will vary — acceptable aesthetic.
Actually can do better: use onBeforeCompile to vary UV scale per instance? Overkill. Fine.
Rooftop neon: InstancedMesh of thin boxes on top of some buildings, basic material with instanceColor, additive.
Let's write code.
const N=10, B=20, R=8, S=B+R;
Ground size 900.
Building placement: for each block (i,j), maybe skip some blocks as plazas. 4 lots per block: 2x2, each lot about B/2 with margin. Height: base random 6..48, taller near center: h *= (1.6 - dist/maxDist). Random width 6..9.
Count buildings per variant: assign variant by index mod 6.
Point lights: 6 colored (magenta, cyan, orange) at street intersections, intensity ~2, distance 60. Plus hemisphere.
Tone mapping exposure 1.1.
Stars: Points, 800 stars on upper hemisphere of radius 400, size 1.2, sizeAttenuation true... at 400 distance with attenuation they'll be tiny. Use size 2, fog:false on the material. Points material has fog property. Set fog: false.
Sky sphere: radius 450, shader gradient from horizon color 0x1a0b2e-ish to zenith 0x02010a, plus subtle horizon glow. BackSide, fog false, depthWrite false.
Fog: FogExp2(0x0b0518, 0.0055). Camera orbit radius 95, height 38 + sin bob. lookAt(0,12,0).
Environment for ground: create env scene: gradient sphere + a few large emissive boxes as neon blobs? PMREMGenerator.fromScene(envScene, 0.04). envScene: sphere with same gradient shader, plus several emissive colored boxes near horizon. Then ground.envMap = envRT.texture; also set scene.environment? Setting scene.environment affects all standard materials — buildings are standard material with emissiveMap. environment adds ambient reflections — could be nice for buildings slightly. Set scene.environment = envRT.texture with low envMapIntensity on buildings (0.3), ground 1.0.
Car update: per car {roadIndex, axis ('x' or 'z'), dir, speed, pos, lane}. Compute matrix: position along road, y=0.6. Rotation to orient along axis. Use dummy Object3D.
Car orientation: box geometry (length 2.4 along x, height 0.8, width 1.1). Cars on x roads: no rotation. z roads: rotate 90°.
Wrap pos when exceeding extent: pos = ((pos + half) % extent) - half, handle negative modulo.
Street lamps/intersection glow points: Points geometry at intersections y=1, vertex colors, PointsMaterial size 3, additive, transparent, depthWrite false, fog false? Keep fog true for depth cue... additive with fog can darken weirdly. Set fog: false and rely on distance? Points size attenuates. Fine.
Also add glow sprites to nearest buildings? Skip.
Renderer: antialias true, setPixelRatio min(devicePixelRatio,2).
Write HTML.
Window texture generation:
function makeBuildingTexture(palette){
const c=document.createElement('canvas'); c.width=64;c.height=128; ctx...
fill with dark #05060c... base color slightly tinted.
window grid: cols 6, rows 20? Each window 6x4 px with spacing.
for each cell: if rand<0.4 lit: pick color from palette, fillRect with slight glow (draw slightly larger semi-transparent behind).
texture = new THREE.CanvasTexture(c); magFilter Nearest; colorSpace SRGB.
Material: MeshStandardMaterial({map:tex, emissiveMap:tex, emissive:0xffffff, emissiveIntensity:1, roughness:0.8, metalness:0.2}). But map's dark facade is affected by lights. emissiveMap makes windows glow white * texture color. Good.
Top face of box will also have window texture — looks weird from above but camera is low. Set material array? Box with single material. Top face shows windows — camera looking down slightly sees roof. Could set roof to dark: use material array of 6 materials [side,side,roof,roof(bottom),side,side]. Roof material dark standard. Do that: materials array [w,w,roof,roof,w,w]. InstancedMesh supports material array? Yes, with geometry groups — BoxGeometry has groups. InstancedMesh with material array works.
Rooftop neon strip: InstancedMesh box (w*0.9, 0.3, d*0.9) placed on some buildings' roof edges? Just thin glowing box on roof: basic material, instanceColor, additive blending, toneMapped false for punch.
Car material: MeshBasicMaterial({toneMapped:false}) white, instanceColor for colors. Additive? Keep normal so cars occlude. Bright colors.
Counts: blocks 10x10=100, about 4 buildings each = about 400 buildings. 6 instanced meshes.
Road extent: extent = N*S = 280. Half = 140. Cars wrap at ±150.
Street lines: for each road j (0..N): line along x at z=r_j: plane scale (extent+40, 0.8) — plane geometry rotated. Color alternates cyan (0x00ffff) / magenta. Also dim wide plane for road surface? Ground is already glossy. Add slightly brighter road strips? Skip.
Also lane glow lines on both edges of road? Keep single center line, plus maybe 2 edge lines per road → 3 lines per road, 22 roads, 66 line instances per direction... total about 132. Fine, use one InstancedMesh with instanceColor.
Edge lines: offset ±(R/2 - 0.5), dimmer (multiply color). Center brighter.
Let's write final code carefully.
Camera orbit: t*0.05 rad/s → slow. angle = t*0.06. radius = 100 + sin(t*0.1)*8. height = 34 + sin(t*0.13)*6.
Stars: 600 points.
Point light flicker: subtle intensity noise.
Write it all.
Sky shader:
varying vec3 vWorldPosition? Use position-based: vY = normalize(position).y. frag: mix(horizon, zenith, pow(max(vY,0),0.6)). Below horizon fade darker. Add subtle band glow near horizon: add color * exp(-abs(vY)*8)*glow.
ShaderMaterial with side BackSide, depthWrite false, fog false. Mesh at y0 center, follows camera? Radius 450, camera within 110 — fine, static.
PMREM: const pmrem = new THREE.PMREMGenerator(renderer); envScene with sphere (clone of sky shader material) plus colored boxes. envRT = pmrem.fromScene(envScene, 0, 0.1, 1000)? Signature is fromScene(scene, sigma, near, far). Use fromScene(envScene, 0.05). Set scene.environment = envRT.texture.
Buildings material envMapIntensity 0.25. Ground envMapIntensity 1.2.
Ground: PlaneGeometry(1200,1200), rotate. Standard, color 0x05050a, metalness 1.0, roughness 0.22, envMapIntensity 1.2. Metal with roughness 0.22 and envmap reflects env colors — wet look.
Also add subtle specular from point lights on ground — metalness 1 gives point light reflections. Good.
OK, write the file. Keep code reasonably compact but readable.
Car colors: palette [white, red, cyan, orange, pink, yellow].
Car count: 260.
Per frame update: dummy.position.set. dummy.rotation.y. updateMatrix. setMatrixAt. Then instanceMatrix.needsUpdate.
Store cars in array of objects.
Road positions r_j = (j - N/2)*S, j=0..N → values -140..140 step 28. Block centers c_i=(i-(N-1)/2)*S → -126..126. Good.
Skip some blocks randomly (0.08) for plazas. Could add one tall "hero" tower in center.
Height: h = (6 + Math.random()**2 * 46) * centerBoost. centerBoost = 1.8 - 1.2*dist/halfDiag... compute maxH around 70 near center.
Building width: lot = B/2=10. w = 5+rand*4, d similar, place lots at block center ± B/4.
Rooftop neon on buildings with h>25: probability 0.5.
Sign sprites: skip.
Street lamp glow points at intersections: (r_j, r_k) grid → 121 points, y=0.5, colors alternating.
Flicker: pointLights intensity = base*(0.85+0.15*sin(t*speed+phase)).
Write.
Also handle resize.
Let me write the final HTML now.
One concern: InstancedMesh with material array — supported? InstancedMesh inherits Mesh. Rendering with groups works. Yes.
Emissive on instanced buildings: emissive white * emissiveMap. All windows same intensity — fine.
Also set texture.colorSpace = THREE.SRGBColorSpace on canvas textures.
Car headlight glow: additive plane under each car? Skip.
Let me write code.
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x0a0616, 0.006);
Renderer tone mapping ACESFilmic, exposure 1.15.
Sky sphere radius 500. Fog exp2 0.006 at distance 100-300: buildings far at ~300 are heavily fogged. FogExp2 0.006 → factor at 300: exp(-(0.006*300)^2)= exp(-3.24)=0.04 — too much. Use 0.0045: at 250: exp(-(1.125)^2)=exp(-1.27)=0.28. Hmm, want visible falloff. City half-diagonal ~200. Camera radius 100, far buildings ~300 away. Use density 0.0038: at 300 → exp(-1.3)=0.27. OK. Choose 0.004.
Fog color should match horizon: 0x0d0722? Horizon color 0x2a1245 purple-ish. Fog color 0x120a2a. Sky horizon mix. Fine.
Writing.
Building count: 100 blocks, 4 lots = up to 400 buildings. Good "hundreds".
Code:
...
importmap script, module script.
Full JS:
import * as THREE from 'three';
// renderer, scene, camera
// sky
// env
// ground
// building textures and meshes
// rooftop neon
// street lines
// cars
// stars, intersection glow
// lights
// animate
Compose window texture:
function buildingTexture(palette, litChance){
const W=64,H=128; canvas; ctx.fillStyle='#07080f'; fillRect.
const cols=6, rows=16; cw=W/cols, ch=H/rows;
for y rows, x cols: if(Math.random()