Building a 3D Rainy Night City Scene with AI Coding: A Practical Guide

    This article walks through building a walkable 3D rainy-night city block with AI coding tools, focusing on the workflow rather than one-shot generation. It covers translating atmospheric descriptions into engineering constraints, structuring prompts, layering the scene from ground and buildings to props, atmosphere and interaction, fixing proportion and composition issues, combining lighting, materials and particle effects for wet-night realism, enforcing performance budgets with instancing and adaptive degradation, and iterating prompts through verifiable feedback. Readers will find reusable configuration and code snippets for scale validation, rain particles and frame-rate-based fallback.

    1. Introduction: From One Idea to a Walkable Rainy Night Town

    In 3D graphics development, a scene like a “rainy night convenience store” looks simple but actually tests geometry modeling, materials and lighting, particle systems, camera control, and rendering performance all at once. In the past, such work usually required developers to write large amounts of boilerplate code line by line and tune parameters through repeated trial and error. As intelligent coding tools have matured, natural language descriptions can now be turned directly into runnable front-end code, significantly shortening the cycle for validating an idea.

    It is worth stressing that these tools are not magic that produces a finished result from a single description. The real collaboration is closer to developing alongside a highly capable partner who needs clear constraints: whether proportions are coherent, whether performance is acceptable, and whether details are in place usually take several rounds of discussion and correction. Using the construction of a rainy night town as a thread, this article abstracts a reusable practical method.

    2. Requirement Breakdown: Turning “Atmosphere” into Executable Technical Constraints

    Words like “rainy night, damp, neon, quiet” in natural language are descriptions at the level of feeling, and a machine cannot execute them directly. The first step is to translate feelings into engineering constraints:

    • Scene scale: use meters to fix street width, store frontage, floor height, and human eye height (camera height is usually 1.6–1.7 m).
    • Time and environment: night, low illumination, and high humidity mean low ambient light + multiple local light sources + highly reflective ground.
    • Weather: rain as a large number of thin, elongated particles, combined with ground ripples and water streaks on glass.
    • Interaction goals: free roaming, pushing the door open to enter, and switching viewpoints.
    • Performance budget: define the target frame rate and device tier, for example 60fps on a mid-range laptop and 30fps on mobile devices.

    Writing the above items as a structured prompt is far more stable than a single sentence like “make a rainy night convenience store.” A sample:

    1. Role: Senior front-end graphics engineer
    2. Goal: A single-file runnable 3D rainy night block scene
    3. Constraints:
    4. 1) Units unified in meters; street width 8m, store frontage 6m, depth 5m, floor height 3.2m
    5. 2) First-person camera, eye height 1.65m, with mouse look and WASD movement
    6. 3) Lighting: extremely low ambient intensity, 2 area lights inside the store, self-illuminated signage
    7. 4) Wet slippery ground: high roughness contrast + reflection, raindrops create ripples
    8. 5) Performance: draw calls < 200, triangles < 300k, particles < 8000
    9. Output: complete code + explanation of key parameters

    3. Scene Skeleton: Modular Organization Beats One-Shot Generation

    Having the model output all the code at once often becomes hard to maintain as the volume grows. A safer approach is to proceed in layers, each of which can run and be accepted independently:

    1. Ground and roads: plane mesh + lane markings + curbs, establishing a scale reference first.
    2. Building blocks: assemble the block outline from simple boxes to validate perspective and proportion.
    3. Convenience store body: display window, door, shelves, checkout counter, light box.
    4. Atmosphere layer: rain, fog, reflections, signage glow.
    5. Interaction layer: movement, collision, door opening, viewpoint switching.

    This coarse-to-fine order exposes proportion problems early, instead of forcing a rebuild after details have piled up.

    4. Proportion and Composition: The Most Common Source of Rework

    In practice, the most frequent rework is not code errors but “it looks wrong.” Common causes and fixes:

    • Missing reference objects: add trash bins, fire hydrants, steps, bicycles, and other objects of known size so the eye can judge proportion.
    • Wrong camera eye height: too high creates a “model sandbox” feel, too low feels oppressive and distorted.
    • Street too wide or too narrow: 8–10 m is an easily readable two-lane scale; a pedestrian alley of 3–4 m is enough.
    • Sign and door frame out of proportion: sign height is usually kept at 1/4–1/3 of the floor height.

    A reusable validation snippet:

    1. // Constrain key dimensions with real-world scale to avoid a "sandbox" feel
    2. const UNIT = 1; // 1 unit = 1 meter
    3. const config = {
    4. streetWidth: 8 * UNIT,
    5. shop: { width: 6 * UNIT, depth: 5 * UNIT, height: 3.2 * UNIT },
    6. cameraHeight: 1.65 * UNIT,
    7. signHeight: 0.9 * UNIT
    8. };
    9. console.assert(config.signHeight < config.shop.height / 3, 'Sign is too tall');

    5. Rainy Night Texture: Coordinating Lighting, Materials, and Particles

    The core of a rainy night atmosphere is not “how much rain falls” but the interaction between light and wet surfaces.

    • Low-illumination base: push ambient light very low so local light sources become the subject of the composition.
    • Three-point local lighting: cool white area light inside the store, warm self-illuminated signage, street lamps as rim light.
    • Wet ground reflection: lower roughness and raise reflection intensity so light sources stretch into vertical bands on the ground.
    • Layered rain: sparse large drops in the foreground, dense rain curtain in the midground, fog instead of particles in the background, balancing look and cost.
    • Water streaks on glass: simulate with semi-transparent overlays plus normal perturbation, far cheaper than real fluid simulation.

    The particle system can be abstracted into a general pattern:

    1. // Rain: recycle particles around the camera to control memory and draw cost
    2. function createRain(count = 6000, area = 40, height = 20) {
    3. const positions = new Float32Array(count * 3);
    4. for (let i = 0; i < count; i++) {
    5. positions[i * 3] = (Math.random() - 0.5) * area;
    6. positions[i * 3 + 1] = Math.random() * height;
    7. positions[i * 3 + 2] = (Math.random() - 0.5) * area;
    8. }
    9. const geometry = new THREE.BufferGeometry();
    10. geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
    11. return new THREE.Points(geometry, new THREE.PointsMaterial({
    12. color: 0xaaccff, size: 0.02, transparent: true, opacity: 0.6
    13. }));
    14. }

    6. Performance Optimization: Treat the Budget as a Hard Constraint

    Atmosphere-heavy scenes are the easiest to end up “good-looking but laggy,” so optimization should start from metrics:

    • Merge draw calls: combine static geometry into a single mesh and reuse materials as much as possible.
    • Geometry reuse and instancing: use instanced rendering for repeated objects such as street lamps, shelves, and awnings.
    • Reflection cost control: render ground reflections with a low-resolution render target, or switch to baked pseudo-reflections.
    • Selective post-processing: prioritize bloom, and toggle depth of field and screen-space reflections by device tier.
    • Tiered degradation: automatically reduce particle count and reflection resolution based on frame rate.
    1. // Simple adaptive degradation: cut particles and reflection when frame rate stays low
    2. let lowFrames = 0;
    3. function adapt(dt) {
    4. if (dt > 1 / 40) lowFrames++; else lowFrames = Math.max(0, lowFrames - 1);
    5. if (lowFrames > 90) {
    6. rain.geometry.setDrawRange(0, 3000);
    7. renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1));
    8. lowFrames = 0;
    9. }
    10. }

    7. Prompt Iteration Strategy for Human–AI Collaboration

    The efficiency of multiple rounds depends on whether feedback is verifiable. Three principles are recommended:

    1. Change only one dimension at a time: proportion first, then lighting, then details, to avoid changes interfering with each other.
    2. Give quantifiable feedback: instead of “the ground looks weird,” say “the ground reflection is too strong, raise roughness to 0.4.”
    3. Ask for explanations of key parameters: have the tool explain what each value does, making it easier to judge whether it is reasonable.

    When results deviate from expectations, check three things first: whether units are unified, whether camera parameters are reasonable, and whether light intensity matches material roughness.

    8. Delivery and Reuse

    The final output should stay in the form of “single-file runnable + centralized parameter configuration,” gathering adjustable items into a unified configuration object so the block layout, weather intensity, and device tier can be swapped later. For long-term evolution, the configuration can be externalized into a common data format, separating scene generation logic from data to form a reusable scene template.

    9. Conclusion

    Building a rainy night town with intelligent coding tools is valuable not because of “one-sentence generation” but because it lowers the cost of validating an idea enough to let developers focus their energy on aesthetic judgment and experience design. Proportion, performance, and detail still need people to check and discuss repeatedly. This collaboration mode of “humans set the direction, tools handle implementation” is exactly the effective path for quickly turning ideas in your head into runnable, playable work today.