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

    This article walks through building a rainy night city scene in Three.js with the help of AI coding tools. It explains how to turn a vague visual idea into a structured, machine-executable specification, how to lock down proportions before adding atmosphere, how to set a performance budget upfront, and how to drive iteration with observable differences. It also covers basic interaction and engineering cleanup, so developers can compress the distance from idea to runnable work into a few rounds of conversation.

    1. Why a Rainy Night Town Is an Ideal Test of AI Coding

    Rainy night scenes are a classic challenge in 3D visualization because they test three kinds of ability at once: rendering, physical intuition, and engineering constraints. Reflections on wet ground require materials and lighting to work together sensibly; the layering of rain streaks must be visually distinguishable while keeping cost under control; and the glow of neon and signs must look good without blurring into a single mass. Anchoring the scene to a concrete subject such as a convenience store grounds these abstract lighting problems in measurable scale—shelf height, door width, step depth. Any distorted proportion is noticed by viewers immediately.

    For this reason, the quality of such a piece does not depend on whether one effect is dazzling, but on whether the overall system is internally consistent. When generating a prototype with an AI coding tool, the real difficulty is not “can it be written,” but “can it converge on the correct solution through repeated conversation.”

    2. Translating a Vague Idea into a Machine-Executable Specification

    When people describe an image in natural language, they automatically fill in a great deal of implicit information; a model does not. To make generated results stable, requirements must be structured first. A four-layer breakdown works well:

    1. Scene layer: time, weather, location, camera height and angle (for example, a street corner, eye level, slightly looking down).
    2. Object layer: building masses, doors and windows, signs, shelves, ground, curbs—list them one by one instead of saying vaguely “a street.”
    3. Relationship layer: relative sizes and spacing between objects, which is the main source of proportion distortion.
    4. Presentation layer: light source types, color temperature tendency, reflection intensity, fog density, rain direction and density.

    A reusable prompt skeleton is below. The key is to replace adjectives with verifiable constraints:

    1. Build a Three.js scene with the following requirements:
    2. [Scene] Night, light rain, city street corner; camera at 1.6m height, looking 45 degrees diagonally forward
    3. [Scale] Convenience store 6m wide, 8m deep, 3.2m floor height; glass door 1.2m wide, 2.1m high
    4. [Composition] Main building, glass curtain wall, entrance sign, two steps, sidewalk, street lamp, several shelves
    5. [Lighting] One cool ambient light + warm sign face light + diffuse ceiling light indoors
    6. [Rendering] Enable shadows; ground material with controllable roughness and reflection; add light fog
    7. [Output] A single HTML file, no external resource dependencies, parameters centralized in a config object

    The last line matters most: requiring adjustable parameters to be managed centrally means later tweaks only touch the config, rather than making the model rewrite the entire logic.

    3. Proportions: Build the Skeleton First, Then the Atmosphere

    Proportion distortion almost always comes from “piling on details first, adjusting sizes later.” A safer order is to block out the masses with untextured boxes, confirm the proportions among door, windows, steps, and shelves, and only then replace materials and add decoration. You can have the tool first output a pure geometry white model along with a dimension list, verify it manually, and then move to the presentation stage.

    If the dimensions the model gives contradict each other, do not say vaguely “that’s wrong.” Point out the specific conflict instead, for example, “the floor height is 3.2m, but a 2.1m door plus a 1.4m sign band already exceeds it,” so the correction has a clear target.

    4. Performance: Set the Budget Upfront Rather Than Fixing It Later

    Frame rate bottlenecks in a rainy night scene usually concentrate in three places: large-area transparency and reflection, the number of dynamic particles, and shadow map resolution. The more effective engineering approach is to define the budget first, then write the implementation.

    1. // Example: centralized performance budget config
    2. const CONFIG = {
    3. rain: { count: 6000, area: 24, speed: 18 },
    4. shadow: { mapSize: 1024, casters: ['building', 'shelves'] },
    5. ground: { roughness: 0.25, metalness: 0.1 },
    6. fog: { density: 0.02 },
    7. pixelRatioCap: 1.5
    8. };

    Supporting strategies include: rendering particles as a single batched geometry rather than many separate objects; keeping reflection only on a few key surfaces such as the ground; whitelisting shadow casters; capping the device pixel ratio; and automatically degrading particle count and shadow precision on low-end devices. These are general rendering optimization practices and do not depend on any specific tool.

    5. Detail Iteration: Drive Communication with Observable Differences

    Repeated conversation is often inefficient because feedback stays at “it feels off.” Turning feedback into observable items noticeably speeds up convergence: whether the sign brightness overpowers the indoor light, whether rain streaks are too thick in the foreground, whether ground reflection makes step edges disappear, whether fog swallows distant outlines.

    It is recommended to change only one or two variables per round and keep the previous version so you can roll back. A workable iteration rhythm: white model to fix proportions → materials and lighting to set the tone → particles and fog to establish atmosphere → interaction and camera to shape the experience.

    6. Interaction and Engineering Cleanup

    A piece that is “playable” needs basic interaction: dragging with the mouse to change the view, scrolling to adjust distance, and pressing keys to switch day/night or rain intensity. Engineering details should also be covered—adaptation when the window size changes, pausing rendering when the page is not visible, and protection around resource release and repeated initialization.

    If you use general cloud product capabilities on Baidu AI Cloud for hosting and distribution, object storage can hold static resources, a content delivery network can accelerate access, and log and monitoring services with alerting can track anomalies, forming a closed loop from development to launch.

    7. Conclusion

    The value of AI coding tools lies not in generating a perfect result in one shot, but in compressing the distance from “idea to runnable work” into a few rounds of conversation. What truly determines the quality of the finished piece is still the developer’s judgment about scale, lighting, and performance budget. Structure the requirements, quantify the constraints, and keep iterations small, and the rainy night town will light up on screen.