Building a Rainy Night City Scene with AI Coding Tools: A Three.js Practical Guide
This article presents a practical workflow for building an interactive rainy night street scene in Three.js using natural-language-driven AI coding tools. It covers translating atmosphere into a structured scene breakdown, fixing scale and camera setup to avoid rework, implementing wet, bright, and foggy visuals, setting a quantifiable performance budget with degradation strategies, adding playable interactions, and running a four-round iteration and acceptance checklist. Readers will learn how to turn creative ideas into a runnable, interactive browser scene with stable quality.
1. Background and Problem Definition
In 3D web creation, a scene like a “rainy night convenience store” looks simple but actually tests geometry modeling, materials and lighting, particle systems, and real-time performance control at the same time. The core takeaway from the original practice is that AI coding tools can quickly turn ideas into something that actually runs and can be played with, but they rarely get everything right in one pass—scale, performance, and details still require repeated refinement. Setting aside any specific product, this article frames the work as a general technical problem: how to use natural language to reliably produce a high-quality, interactive Three.js rainy night street scene.
Three constraints need to be clear. First, the runtime is the browser, limited by a single-threaded main loop and GPU memory bandwidth. Second, a rainy night theme naturally includes many transparent and emissive elements, which can easily cause overdraw. Third, the scene must be “playable,” meaning the camera, interactions, and animation must work—not just produce a static render.
2. Scene Breakdown: Translating “Atmosphere” into Engineering Structure
Natural language descriptions are often subjective, while the rendering pipeline only understands structured data. So the first step is to build a scene inventory that breaks the atmosphere into computable modules:
- Spatial skeleton: ground, curbs, building blocks, awnings, and street depth.
- Functional subjects: storefront windows, shelf silhouettes, checkout counter, and entrance steps.
- Atmosphere layer: rain particles, wet ground reflections, neon and light-box emission, and volumetric fog.
- Interaction layer: camera roaming, rain intensity switching, light toggling, and view reset.
It helps to constrain generation with a structured prompt, for example:
Scene: convenience store at a night street cornerStyle: realistic-leaning cartoon, low-saturation cool tones + warm light-box contrastComposition: 45-degree top-down view, street converging into the distanceElements: wet ground, rain streaks, emissive signage, glass storefrontPerformance: target 60fps, particle cap 3000, no real-time shadowsOutput: single HTML file, modular functions
The value of this approach is turning a “feeling” into verifiable metrics, which reduces back-and-forth later.
3. Scale and Camera: The Most Common Source of Rework
The original text notes that scale required repeated discussion, a typical pain point in 3D generation. The root cause is the lack of a consistent unit and reference objects. Engineering suggestions:
- Set 1 unit = 1 meter, human eye height 1.6–1.7, step height 0.15, door width 0.9–1.0.
- Place a “reference box” representing people and vehicles first, confirm the block relationships, then refine.
- Use a perspective camera with a focal length in the 45–55 degree range to avoid wide-angle distortion swallowing the street depth.
Sample code:
const camera = new THREE.PerspectiveCamera(50, innerWidth/innerHeight, 0.1, 200);camera.position.set(6, 4.2, 9);camera.lookAt(0, 1.4, -6);// Consistent unit conventionconst UNIT = { human: 1.7, step: 0.15, door: 0.95, floorToCeiling: 2.8 };
When scale looks wrong, check the camera distance and field of view first instead of blindly scaling models; scaling also breaks material texture density and light attenuation.
4. Implementing the Rainy Night Look
The key to a rainy night is not “raining” but three things: wet, bright, and fog.
- Wet: use low-roughness ground materials with normal perturbation to create irregular highlights; reuse a normal map to create a water-film texture.
- Bright: let emissive materials handle signage and light boxes, combined with tone mapping and slight bloom to form a warm-cool contrast.
- Fog: use linear or exponential fog to compress distant contrast so the street converges naturally.
For rain particles, use a single geometry to carry all raindrops and offset them by time in the vertex shader, avoiding per-particle object creation:
const rainGeo = new THREE.BufferGeometry();const count = 3000;const pos = new Float32Array(count * 3);for (let i = 0; i < count; i++) {pos[i*3] = (Math.random()-0.5) * 40;pos[i*3+1] = Math.random() * 20;pos[i*3+2] = (Math.random()-0.5) * 40;}rainGeo.setAttribute('position', new THREE.BufferAttribute(pos, 3));const rainMat = new THREE.PointsMaterial({ color: 0xaaccff, size: 0.06, transparent: true, opacity: 0.6 });const rain = new THREE.Points(rainGeo, rainMat);
Updating only rain.position.y or a time uniform each frame produces a looping fall at very low cost.
5. Performance Budget: Turning “Smooth” into a Quantifiable Target
Performance problems must be constrained during generation, not patched afterward. Build a budget table:
| Item | Suggested cap | Notes |
|---|---|---|
| Draw calls | < 120 | Merge static geometry, reuse materials |
| Triangles | < 150k | Use low-poly or billboards for distant objects |
| Particles | 2000–4000 | Single draw call |
| Shadows | Off or one light only | Rainy night relies on emission for shape |
| Post-processing | 1–2 passes | Prioritize bloom, avoid multiple blurs |
A degradation strategy matters too: when the frame rate drops below a threshold, automatically reduce particle count, disable bloom, and lower the pixel ratio.
const dpr = Math.min(devicePixelRatio, 1.75);renderer.setPixelRatio(dpr);let frames = 0, last = performance.now();function tick(now) {frames++;if (now - last > 1000) {const fps = frames * 1000 / (now - last);if (fps < 45) rainGeo.setDrawRange(0, 1500);frames = 0; last = now;}requestAnimationFrame(tick);}
6. Interaction and “Playable” Design
To make a work playable, provide at least three types of interaction: camera roaming (orbit controls or first-person), environment switching (rain intensity, lighting), and state reset. Interactions should avoid conflicting with scrolling and reserve touch support for mobile. Example:
controls.enableDamping = true;controls.minDistance = 3;controls.maxDistance = 24;controls.maxPolarAngle = Math.PI * 0.49; // Prevent going undergroundwindow.addEventListener('keydown', (e) => {if (e.key === 'r') controls.reset();if (e.key === 'l') neonGroup.visible = !neonGroup.visible;});
7. Iteration Workflow and Acceptance Checklist
A four-round iteration is recommended: round one confirms blocks and camera only; round two adds materials and lighting; round three adds particles and fog; round four polishes performance and interaction. Each round outputs a runnable version for quick judgment.
Acceptance checklist:
- Scale: whether people, doors, and steps are in proportion;
- Lighting: whether the warm-cool contrast holds and shadows are not dead black;
- Performance: whether the target device hits the frame rate and degradation works;
- Interaction: whether the camera clips through geometry and reset is reliable;
- Compatibility: whether mobile touch and window resizing work correctly.
8. Conclusion
Building a rainy night city with AI coding tools is essentially translating aesthetic judgment into engineering constraints. As long as you keep consistent units, define a clear performance budget, and iterate and accept in layers, you can reliably turn “inspiration” into a runnable, interactive work. If you need to distribute the work, you can combine general cloud capabilities such as object storage and a content delivery network for static hosting, letting more people experience the creation instantly.
