Building a Rainy Night 3D City with AI Coding Tools: A Practical Guide
This article presents a general, tool-agnostic workflow for building a browser-based rainy night 3D city with AI coding tools. It covers translating creative ideas into structured prompts, splitting the scene into layers, fixing scale and composition issues, combining rain, fog, reflections, and lighting, iterating in small reversible steps, managing performance budgets, and adding low-cost interactions, plus a checklist of common pitfalls.
1. Introduction: Why a Rainy Night City Tests AI Coding Capabilities
Building a small city on a rainy night in the browser may look like a purely visual task, but it actually tests several engineering dimensions at once: geometric modeling, materials and lighting, particle systems, camera control, performance budgeting, and interaction design. It requires developers to translate a vague idea into structured requirements, and then handle typical problems across multiple iterations, such as distorted proportions, dropping frame rates, and missing details.
AI coding tools have improved significantly in recent years and can generate runnable scene code from natural language descriptions. In practice, however, they rarely get it right on the first attempt: building proportions, camera framing, rain density, and ground reflection intensity all require repeated discussion and fine-tuning. Setting aside the specifics of any particular product, this article abstracts a general workflow that helps readers reliably turn “an idea in their head” into something that runs and can be played with.
2. Requirement Translation: Writing Ideas as Structured, Machine-Executable Descriptions
The most common problem with natural language descriptions is ambiguity. To get usable code from an AI coding tool, a requirement description should include five categories of elements:
- Scene subjects: convenience store, street, buildings, signs, pedestrians, and so on;
- Spatial relationships: main street width, spacing between buildings, initial camera position and orientation;
- Time and environment: night, rain, fog, wet ground;
- Visual style: realistic or low-poly, warm-cool contrast, neon color palette;
- Engineering constraints: target frame rate, resolution limit, mobile support.
A reusable description template looks like this:
Scene: rainy night city street, a convenience store in the centerComposition: camera across the street, slightly top-down, longer focal lengthEnvironment: moderate rain, medium visibility, wet reflective groundStyle: low-poly + neon warm-cool contrastConstraints: desktop target 60fps, graceful degradation on mobile
Once the idea is written as this kind of field-based description, every later revision can be traced to a specific field instead of a vague “it just feels wrong.”
3. Scene Breakdown: Layered Modeling and Module Boundaries
A common trait of high-quality results is clear layering. It is recommended to split the scene into four layers, each with a defined responsibility and interface:
- Terrain and road layer: road surface, curbs, crosswalks, standing water areas;
- Building layer: main building bodies, doors and windows, signs, awnings;
- Prop layer: vending machines, trash bins, bicycles, utility poles;
- Atmosphere layer: rain, fog, lighting, reflections, post color grading.
The benefit of layering is that adjusting the atmosphere will not break building proportions, and swapping props will not affect the road structure. Explicitly declaring module boundaries in the prompt can significantly reduce coupling in the generated code.
A schematic module skeleton:
const world = new THREE.Group();world.add(createGround());world.add(createBuildings());world.add(createProps());world.add(createAtmosphere());scene.add(world);
4. Scale and Composition: The Most Common Source of Rework
The original text mentions that “proportions require repeated discussion,” which is the most widespread pain point in practice. There are three reasons: natural language lacks scale anchors; perspective makes distant objects appear smaller; and generated code often uses default units, causing door height and street width to mismatch.
Ways to improve:
- Introduce real-world scale anchors, for example “the convenience store door is about 2.2 meters high, and the main street is about 8 meters wide”;
- Specify camera parameters clearly, using a longer focal length to reduce wide-angle distortion;
- Lock the composition first, then add details, to avoid the composition collapsing after details pile up.
const camera = new THREE.PerspectiveCamera(45, w / h, 0.1, 200);camera.position.set(0, 6, 18);camera.lookAt(0, 2, 0);
5. Rainy Night Atmosphere: Rain, Fog, Reflections, and Lighting
The texture of a rainy night comes from four elements working together:
- Rain: usually represented by a large number of thin particles or instanced geometry, with adjustable density and wind direction;
- Fog: compresses the contrast of distant views to create depth;
- Reflections: wet ground can use planes with high roughness contrast combined with lighting to form highlight bands;
- Lighting: contrast between cool ambient light and warm sign light is the core of the “rainy night feel.”
scene.fog = new THREE.FogExp2(0x0a0f1a, 0.035);renderer.toneMapping = THREE.ACESFilmicToneMapping;renderer.toneMappingExposure = 1.1;
It should be emphasized that rain volume and frame rate are roughly linearly related, so the number of rain streaks must be included in the performance budget rather than stacked without limit.
6. Iteration Strategy: Small Validations and Rollback
Do not ask for a complete city in one shot. A “three-stage” iteration is recommended:
- Skeleton round: generate only the ground, main building, and camera, and confirm composition and proportions;
- Atmosphere round: add rain, fog, and lighting, and confirm the style;
- Detail round: add sign text, props, and interactions.
Keep a rollback-able version after each round. When the result deviates from expectations, roll back only the most recent round and fix the corresponding field, avoiding the uncertainty of a full rewrite.
7. Performance Governance: Making the Work Actually Playable
Runnable does not mean playable. It is recommended to establish a clear budget:
- Draw batches: merge static geometry to reduce the number of independent meshes;
- Particle scale: set a configurable upper limit for rain, with automatic degradation on mobile;
- Shadows: limit the number of shadow-casting lights, and switch to baked or decal shadows when necessary;
- Resolution: dynamically adjust render resolution based on device capability.
const isMobile = window.innerWidth < 768;const rainCount = isMobile ? 1200 : 4000;renderer.setPixelRatio(Math.min(devicePixelRatio, isMobile ? 1.5 : 2));
8. Interaction and Playability
The “playable” quality of the work comes from low-cost but high-perception interactions: switching day and night, adjusting rain volume, first-person roaming, clicking signs to trigger lighting changes. Interactions should act on the atmosphere and lighting layers, avoiding changes to building structures, thereby maintaining stability.
9. Common Pitfalls Checklist
- Describing only style without scale, causing repeated proportion rework;
- Maxing out rain and shadows at the same time, causing frame rates to plummet;
- Details before composition, resulting in a cluttered final image;
- Generating everything at once, making problems hard to locate;
- Ignoring mobile degradation, so the work only runs on desktop.
10. Conclusion
Building a rainy night city with AI coding tools is essentially a joint exercise in “requirements engineering + graphics engineering.” Making ideas field-based, layering the scene, quantifying the budget, and slicing iterations small can converge uncertainty into a controllable process. With general capabilities on cloud platforms such as Baidu AI Cloud, including containerized deployment, object storage, and log monitoring, the work can further evolve into an engineering form that is publishable, observable, and continuously iterable.
