Building a 3D Rainy Night City with AI Coding Tools

    This article explains how to use AI coding tools to build a runnable, interactive, and performance-controlled 3D rainy night city scene for the web. It breaks the scene into five layers, shows how to turn vague creative ideas into executable prompt constraints covering scale, composition, lighting, and performance, and presents a four-round iteration method for convergence. It also includes a troubleshooting checklist and engineering recommendations for moving from a demo to a maintainable project.

    1. Introduction: Turning a Mental Image into a Runnable Scene

    Building an atmospheric 3D scene on the web used to require art assets, modeling experience, and a large amount of hand-written rendering code. As AI coding tools and high-performance large models have matured, developers can now describe a target image in natural language, have the model generate scene code based on a general-purpose web graphics library, and then enter an iterative loop of “generate, run, observe, and fix.”

    This article uses “a convenience store in a rainy night city” as the technical vehicle to discuss a general question: how to reliably produce a runnable, interactive, and performance-controlled 3D scene with the help of AI coding capabilities. It does not involve any specific vendor product, and all capability descriptions are limited to general industry technology.

    One expectation needs to be made clear up front: this kind of generation is not “right the first time.” Scale, performance, and details usually require multiple rounds of communication and constraints before converging to a usable state. Understanding this matters more than chasing a “one prompt, finished product” result.

    2. Technical Foundation: What Makes Up a Rainy Night Scene

    Whether written by a human or a model, a rainy night city scene can be broken into five layers:

    1. Scene and camera layer: the scene container, perspective camera, and orbit controls, which determine the viewing angle and interaction mode.
    2. Geometry and material layer: ground, building blocks, storefront windows, signage, and awnings; materials must distinguish rough ground from smooth glass.
    3. Lighting layer: ambient base light, directional light, neon point lights, and warm indoor light. The rainy night atmosphere is mainly created by “low ambient light plus high-contrast local light.”
    4. Weather and post-processing layer: rain particles, ground reflections, fog, and slight bloom, used to unify the color tone and depth of field.
    5. Performance and lifecycle layer: pixel ratio cap, geometry reuse, frame rate monitoring, and resource disposal.

    When generating code, the model’s most common deviations concentrate in the “scale” of layer 1, the “atmosphere intensity” of layer 4, and the “performance budget” of layer 5. Prompts must therefore explicitly cover these three areas.

    3. Prompt Engineering: Writing Vague Ideas as Executable Constraints

    A vague “make a rainy night convenience store” will produce a result that “looks right but has odd proportions.” The effective approach is to describe things in layers:

    • Goal and runtime environment: a single HTML file, a general-purpose 3D library loaded via CDN, no build tools required, runs as soon as it is opened.
    • Scale constraints: relative relationships in meters, for example a storefront about 6 meters wide, a floor height of about 3 meters, a street about 12 meters wide, and an initial camera height of about 1.6 meters (roughly human eye level).
    • Composition constraints: the camera sits diagonally across the street, the line of sight tilts slightly downward, and the convenience store sits in the right third of the frame.
    • Lighting constraints: low ambient light intensity, warm indoor light as the main source, cool-colored point light for the signage, and wet, highly reflective ground.
    • Performance constraints: pixel ratio no higher than 2, rain using a single geometry with multiple instances, real-time shadows disabled or limited to a single shadow-casting light.

    An illustrative prompt structure is shown below (pseudocode, expressing only the organization):

    1. Goal: single-file runnable rainy night street 3D scene
    2. Scale: storefront 6m wide, floor height 3m, street width 12m, camera height 1.6m
    3. Composition: diagonal across-the-street view, subject offset to the right
    4. Lighting: low ambient light + warm indoor light + cool-colored sign point light
    5. Weather: rain particles + high ground reflectivity + light fog
    6. Performance: pixel ratio <= 2, instanced rain, at most 1 shadow-casting light
    7. Output: complete HTML with initialization, render loop, and window resize handling

    The value of this approach is that it translates “aesthetic demands” into “verifiable parameters,” which significantly improves the usability rate of the model’s output.

    4. Generation and Iteration: The Four-Round Convergence Method

    Round one, get the skeleton running. Only ask for a runnable minimal loop: scene, camera, controls, one ground plane, one box-shaped building, and one light. The goal is to confirm the environment is correct, not to pursue the visuals.

    Round two, fix the scale. This is the most error-prone step. If the building looks too tall or the street too narrow, do not vaguely say “the proportions are wrong”; instead give specific numeric ranges, such as “change the floor height to 3 meters, the storefront to 6 meters, and the street width to no less than 10 meters.” Numeric feedback significantly reduces back-and-forth.

    Round three, inject the atmosphere. Add rain particles, fog, ground reflections, and signage light in sequence. This stage requires controlling variables, adding only one element at a time, so the source of any problem is easy to locate.

    Round four, converge on performance and details. Watch the frame rate and first-screen time; if frames drop, handle it in the order of “first reduce pixel ratio, then reduce particle count, and finally simplify materials.” For details, add awning dripping, water-streak textures on the glass, and slight sign flickering, but treat these as optional to avoid stacking too much at once.

    5. Common Problems and Troubleshooting Checklist

    • The whole scene is too dark or too bright: adjust ambient light and fog density first, rather than repeatedly changing material colors.
    • Distorted scale: use a “human-eye-height camera plus a known storefront width” as a reference anchor, which is more reliable than text description.
    • Stuttering: mostly caused by too high a pixel ratio, too many particles, and too many real-time lights and shadows.
    • The rain “doesn’t look like rain”: rain streaks need to tilt along the gravity direction, have random lengths and low opacity, and be paired with ground ripples or reflections.
    • Layout breaks after window resizing: make sure the renderer size and camera aspect ratio are updated together in the resize event.

    When troubleshooting, follow the “single-variable change” principle: change only one thing at a time and run to verify immediately.

    6. Engineering Recommendations: From Demo to Maintainable

    When a scene moves from a demo to a project, three things need to be added:

    1. Structural separation: split scene initialization, resource loading, the render loop, and UI interaction into independent modules, making it easier for the model to generate in blocks and for humans to review.
    2. Resources and deployment: static assets can be hosted on general-purpose object storage, paired with a content delivery network to reduce first-screen latency; logs and monitoring alerts track online error rates and load times.
    3. Observability: measure frame time in the render loop and automatically degrade quality when it exceeds a threshold (turning off reflections, lowering particle count); this is a common adaptive quality strategy in the industry.

    7. Conclusion

    The real value of AI coding tools is not to replace developers in making aesthetic decisions, but to push implementation cost low enough that developers can focus their energy on composition, atmosphere, and interaction design. Master the three principles of “numeric scale, layered constraints, and single-variable iteration,” and you can reliably turn an idea for a rainy night city into a work that truly runs and can be played with.