Building a Rainy Night City with AI Coding Tools: A Practical Engineering Guide

    This article presents a practical engineering methodology for using AI coding tools to generate runnable Three.js scenes from natural language descriptions. It covers translating visual atmosphere into measurable parameters, fixing scale and coordinate issues with unit conventions and automated checks, managing performance budgets for rain and reflections, iterating on details through specific visual checklists, and validating the final result with an acceptance checklist.

    1. From a Single Prompt to a Runnable World

    Describing a rainy night city in natural language and having an AI coding tool produce a runnable Three.js scene is no longer a demo-level toy. It is a real, usable development paradigm. However, the actual experience is rarely “one sentence, done”: distorted proportions, sudden performance drops, and missing details are recurring problems. This article is not about the pros and cons of a specific tool. Instead, it discusses a general engineering method for this class of AI-assisted 3D scene generation—how to translate a vague visual impression into technical specifications that a machine can execute, verify, and iterate on.

    The most common pitfall in practice is treating a creative description as a requirements document. A sentence like “a convenience store on a rainy night, warm light, reflective wet ground” is automatically completed by the human brain with perspective, scale, materials, and atmosphere. But a model can only generate code based on text probabilities. It does not know whether your “convenience store” is three meters or eight meters wide, or whether you are targeting mobile or desktop. Therefore, the first step of a professional approach is always to break the image down into measurable engineering constraints.

    2. Scene Breakdown: Translating “Atmosphere” into Parameters

    The visual impact of a rainy night city comes from the unity of three opposing pairs: cold and warm, dry and wet, static and dynamic. In engineering terms, these can be mapped to configurable parameters:

    • Cold: The color temperature of ambient light and fog is low. Use scene.fog for depth attenuation so distant buildings naturally fade into the night.
    • Warm: Use warm-colored point lights inside the convenience store, the reverse of high color temperature, to create a visual anchor.
    • Wet: The ground uses a low-roughness, high-reflectivity material, combined with normal perturbation to create a water film texture.
    • Dynamic: Rain streaks are represented by a particle system or instanced geometry, with random wind disturbance.

    Writing these into structured prompt fragments significantly improves the hit rate. A reusable prompt skeleton is as follows:

    1. Scene: night city street, a convenience store as the visual center
    2. Scale: street width 8 units, convenience store frontage 6 units, floor height 3.2 units
    3. Camera: perspective camera, initial position (0, 1.7, 12), looking at (0, 1.6, 0)
    4. Lighting: cool low-intensity ambient light + warm point light in the store + one street lamp
    5. Material: wet asphalt ground, roughness 0.15, with slight normal perturbation
    6. Animation: moderate rain, 6000 particles, 15 degrees diagonal
    7. Performance: target 60 FPS, downgrade to 30 FPS on mobile

    The key is not flowery wording, but that every dimension has a value, a default, and an acceptance criterion.

    3. Scale and Coordinates: The First Killer of AI-Generated Scenes

    Scale problems are a common challenge in almost all generative 3D scenes. Models tend to generate relative relationships that “look right” but lack a unified unit system. The result is doors taller than people and signs wider than buildings. There are three layers to the solution:

    The first layer is to define units and the origin first. Specify that 1 unit = 1 meter, the ground is y=0, and the street extends along the z-axis, with all objects aligned to the ground. Write this convention into the first line of the prompt and repeat it in every subsequent round of conversation.

    The second layer is to calibrate with “anchor objects.” First have the tool generate a 1.8-unit-tall human reference or a 1-meter-square floor tile, then generate the buildings. With a reference, the model’s judgment of scale becomes much more stable.

    The third layer is to leave verification to code rather than your eyes. Immediately after generation, add bounding box printing and out-of-bounds warnings:

    1. const box = new THREE.Box3().setFromObject(scene);
    2. console.log('Scene bounding box', box.min, box.max);
    3. if (box.max.y > 12) console.warn('Abnormal building height, check floor height and number of floors');

    This “generate + self-check” loop is far more efficient than repeated verbal corrections.

    4. Performance Budget: The Hidden Bomb in Rainy Night Scenes

    Rain, reflections, and multiple light sources are three sources of pressure on 3D performance. Transparent particles require sorting and blending, reflections require an extra rendering pass, and multiple lights amplify fragment shading costs. The professional approach is to set a budget first, then discuss effects:

    • Keep draw calls within a reasonable range; merge geometry or use instancing for static objects.
    • Prioritize a single-draw-call instanced solution for rain streaks, avoiding thousands of independent meshes.
    • Do not enable real-time reflections by default; use a simplified solution such as an environment map or planar reflection first.
    • Set an upper limit on pixel ratio to avoid uncontrolled rendering resolution on high-DPI screens.
    • Provide quality tiers, automatically disabling reflections and reducing particle counts on low-end devices.

    A simplified adaptive downgrade example:

    1. const isMobile = /Mobi|Android/i.test(navigator.userAgent);
    2. const quality = isMobile ? 'low' : 'high';
    3. const rainCount = quality === 'high' ? 6000 : 2000;
    4. renderer.setPixelRatio(Math.min(devicePixelRatio, quality === 'high' ? 2 : 1.25));

    It is important to emphasize that any performance number must be based on real device testing. Devices, browsers, and drivers vary greatly, and there is no universal “safe threshold.”

    5. Detail Iteration: Turning “Make It More Realistic” into Executable Instructions

    “Details are not enough” is the vaguest and most difficult feedback to handle. The solution is to break the feeling into a specific list of visual cues and issue them one by one:

    1. The frequency and amplitude of the sign’s self-illumination and tube flickering.
    2. The distribution density and reflection intensity of puddles on the ground.
    3. Whether raindrops hitting the ground create small splashes.
    4. The relationship between rain traces on glass and the transmission of warm interior light.
    5. The layering of distant car light trails and fog.

    Change only one or two groups of variables per round and keep a rollback version. This both helps locate the source of a problem and prevents the model from changing too much in one round and breaking the whole scene.

    6. Acceptance Checklist: Making It “Playable” Rather Than Just “Viewable”

    A qualified interactive work must pass at least four gates: it loads, it is operable, it runs continuously, and it degrades gracefully. It is recommended to fix this as a checklist:

    • The first screen loads without errors, and missing resources have fallbacks.
    • The camera can rotate and zoom freely without going underground or out of bounds.
    • After running continuously for ten minutes, the frame rate shows no significant degradation and memory does not keep growing.
    • On low-end devices, after automatic downgrade, interaction still works normally.
    • Key parameters are centralized in a configuration object for easy secondary adjustment.

    7. Conclusion

    Building a rainy night city with AI coding tools—the real barrier is not “whether it can be generated” but “whether it can be constrained.” Translating atmosphere into parameters, leaving scale to units and self-checks, writing performance into a budget, and breaking details into a checklist—this methodology applies to any AI-assisted 3D creation and to the broader engineering practice of “natural language to runnable code.” When constraints are clear enough, bringing creativity to life turns from a coincidence into an inevitability.