Building a Rainy Night City Scene with AI Coding Tools: A Three.js Guide

    This article explains how to use AI coding tools to build an interactive rainy night city scene in Three.js. It covers translating visual requirements into structured prompts, a layered architecture, scale calibration rules, performance optimizations with quality presets, and a convergent multi-turn iteration workflow, plus a troubleshooting order for common rendering issues.

    1. Introduction: Why a Rainy Night City Tests AI Coding Tools

    Building a rainy night city on the web may look like a purely visual topic, but it simultaneously challenges rendering pipelines, geometric proportions, lighting strategy, particle systems, and interaction logic. The core observation from the original practice is that AI coding tools let creators turn an idea into something that actually runs and can be explored, yet the process rarely lands perfectly on the first attempt: proportions, performance, and details still take repeated discussion.

    That observation is worth generalizing. The value of AI coding tools is not “generating a perfect result in one shot” but compressing the time from zero to a runnable prototype, so developers can focus their energy on aesthetic judgment and engineering tradeoffs. This article therefore avoids any specific tool and reframes the topic as a general technical question: how to systematically build a high-performance, interactive Three.js rainy night scene with AI assistance.

    2. Requirement Breakdown: Translating “Rainy Night City” into Engineering Language

    Before writing code, the vague mental image must be broken down into an implementable technical checklist. This step is also the decisive factor in prompt quality.

    • Scene subjects: one street, several low-rise buildings, one convenience store glowing with warm light, wet pavement.
    • Atmosphere: low nighttime illumination, strong contrast between cool ambient light and warm point lights, rain streaks, reflections on standing water, distant haze.
    • Interaction: a freely roaming camera, toggleable rain intensity, switchable view presets.
    • Engineering constraints: runs in the browser, degrades on mobile, stable frame rate, controlled asset size.

    Writing these items into a structured prompt is far more reliable than a single sentence like “make a rainy night convenience store.” A recommended prompt skeleton:

    1. Role: Senior WebGL engineer
    2. Goal: Build a rainy night street scene with Three.js
    3. Must include: 1 street, 5-8 low-rise buildings, 1 glowing convenience store, rain particles, wet-ground reflections
    4. Technical requirements: use instanced geometry, cap the pixel ratio, provide quality preset switching
    5. Output: a single HTML file that runs directly in the browser
    6. Constraints: no large external textures; generate materials procedurally

    This four-part structure of “role + goal + constraints + deliverable” noticeably reduces the number of back-and-forth rounds.

    3. Layered Scene Architecture: Skeleton First, Details Later

    Multi-round iteration is often inefficient because details and skeleton get mixed together from the start. A safer approach is to proceed in layers.

    The first layer is layout and proportion. Use simple BoxGeometry placeholders to fix the proportional relationships between street width, building height, and camera height. The only goal at this stage is “looks right,” with no materials involved.

    The second layer is the lighting skeleton. The key to a night scene is the rhythm of light and dark: push ambient light very low, use a few point lights to create focal points, and let the convenience store be the only warm light source, forming the narrative center.

    The third layer is materials and reflections. The expressiveness of slippery pavement comes mainly from reflections rather than textures, approximated with planar reflections or a combination of environment maps and roughness maps.

    The fourth layer is particles and post-processing. Render rain streaks with Points or InstancedMesh, then finish the atmosphere with fog and slight bloom.

    The benefit of layering is that when one layer looks wrong, you only discuss that layer with the tool instead of rewriting everything.

    4. Scale Calibration: The Most Common Failure Point in AI-Generated Scenes

    The original practice noted that “proportions take repeated discussion,” which is a very common pattern. The reason is that models tend to generate scenes that “look rich,” making buildings too tall and streets too narrow, which produces a sense of oppression and clipping while the camera roams.

    Three rules can constrain this in engineering terms:

    1. Use a human baseline. Set camera eye height to about 1.6 to 1.7 units, floor height to about 3 units, and street width to no less than 6 units.
    2. Manage key dimensions centrally with constants, so everything can be adjusted at once instead of through a global search.
    1. const SCALE = {
    2. eyeHeight: 1.65,
    3. floorHeight: 3.0,
    4. streetWidth: 8.0,
    5. buildingMin: 2,
    6. buildingMax: 4,
    7. };
    1. Run a clipping self-check early. Move the camera forward at a constant speed along a fixed path and watch whether it passes through geometry. This exposes layout flaws before details are finished.

    5. Performance Optimization: Four Cost Hotspots in a Rainy Night Scene

    The rainy night theme is naturally “heavy,” so performance constraints must be written in during generation rather than patched on afterward.

    • Too many draw calls: repeated objects such as buildings, window panes, and curbs should be batched with instanced rendering.
    • Uncontrolled pixel ratio: capping the device pixel ratio is the most direct win on mobile.
    • Stacking reflections and post-processing: enabling reflections and bloom together is costly, so quality presets should be provided.
    • Linearly growing particle counts: rain volume should be configurable, and lower presets should reduce both particle counts and post-processing intensity.

    A simplified quality preset example:

    1. const QUALITY = {
    2. high: { pixelRatio: 2.0, rainCount: 12000, bloom: true },
    3. medium: { pixelRatio: 1.5, rainCount: 6000, bloom: true },
    4. low: { pixelRatio: 1.0, rainCount: 2500, bloom: false },
    5. };

    Note that the specific values must be measured and calibrated on target devices; there is no universal “optimal parameter” set. If the scene needs to stay online long term, you can further use object storage to host static assets, a content delivery network to reduce load latency, and logging services plus monitoring and alerting to observe real users’ frame rates and load times. These are general cloud capability categories, not any single vendor’s proprietary solution.

    6. Multi-Turn Dialogue Methodology: Making Communication Converge

    Repeated discussion is not the problem; the problem is overturning the previous round every time. Practices that converge:

    • Change only one variable per round. Adjusting proportions, lighting, and rain volume at the same time makes it impossible to tell where an effect came from.
    • Require incremental delivery. Have the tool patch existing code instead of rewriting the whole file.
    • Define acceptance criteria. Replace “make it more realistic” with decidable conditions such as “the camera moves forward for 10 seconds without clipping” or “the low preset stays above a given frame rate threshold.”
    • Keep rollback-able versions. Archive each round once it is confirmed working, so a good result is not overwritten by later edits.

    7. Common Problems and Troubleshooting Order

    When the image looks “wrong,” troubleshoot in a fixed order rather than by random trial: first check proportions and camera parameters, then light intensity and color temperature contrast, then material roughness and reflection settings, then particle density and fog concentration, and only last touch post-processing. The vast majority of “plastic-looking,” “foggy gray,” or “can’t see anything” problems come from the first three steps.

    8. Conclusion

    Building a rainy night city with AI coding tools yields something more valuable than any specific image: a transferable way of working. Structure creativity into constraints, advance the scene in layers, set performance and proportion as hard metrics up front, and turn multi-round iteration into a convergent process. With this method, the distance from inspiration to a runnable, explorable Web 3D piece shrinks to one focused afternoon.