Building a Rainy Night City Scene with AI Coding Tools: A Practical Guide
Learn how to turn a creative prompt into a runnable Three.js rainy night city using AI coding tools. This guide covers prompt engineering, modular scaling, lighting and reflection trade-offs, particle budgeting, interaction state machines, and a multi-round iteration workflow for stable results.
1. From an Idea to a Runnable Scene: Where It Usually Goes Wrong
The first time many people use AI coding tools to generate a 3D scene, they hit the same gap: the description is complete, but the result does not feel right. Building proportions are off, rain looks like white noise, the frame rate drops sharply, and neon lights overexpose into a blur. On the surface, the model seems “not smart enough.” In reality, the requirements were never translated into machine-executable constraints.
The biggest difference between a 3D scene and a web form is that a 3D scene is a continuous, multi-dimensional, tightly coupled system. Change one parameter, and lighting, occlusion, reflections, and particle counts all shift in a chain reaction. So before handing a sensory description like “rainy night city” to an AI coding tool, you must first do an engineering breakdown: define the scale unit, fix the camera position, cap the number of light sources, and identify interactive objects. Without these anchors, the output will keep oscillating between “looks right” and “runs smoothly.”
Another point that is often overlooked is playability. A good-looking static screenshot does not mean the work is done. What makes people want to interact are the small details: pushing a door open, windshield wipers, ripples in puddles, distant headlights sweeping past. These interactions must have interfaces reserved in the first version of the architecture, not forced in at the end.
2. Prompt Engineering: Translating Visual Language into Engineering Constraints
An effective prompt is not a pile of adjectives; it is a layered declaration. Organize it in four layers:
- Goal layer: one sentence describing the final deliverable, for example “a single-file runnable Three.js scene with an orbit camera and basic interactions.”
- Structure layer: specify which object groups make up the scene, such as ground, building blocks, rain particle system, light group, and post-processing.
- Constraint layer: give hard boundaries, such as “building height no more than 1.5 times the camera height,” “no more than 4 real-time lights,” “particle cap of 20,000.”
- Acceptance layer: list self-checkable conditions, such as “first render completes within 3 seconds” and “automatically reduce particle count when frame rate falls below a threshold.”
A sample prompt skeleton can be written as structured text:
Goal: generate a single-file Three.js rainy night street scene, interactiveStructure: ground (with puddle reflections) / building blocks (3) / rain particles / neon light group / post-processingConstraints: unit = meter; real-time lights <= 4; particle cap = 20000; no external texturesAcceptance: load < 3s; auto-reduce particles on low-end devices; camera cannot pass through walls
The value of this approach is that it turns “feel” into “verifiable conditions.” When the result falls short, you can point to exactly which layer failed, instead of vaguely asking to “optimize it a bit more.”
3. Scene Layering and Scale Control: Why Small Towns Always Look Fake
The credibility of a rainy night small town comes 80% from scale. Common mistakes are random block sizes, inconsistent floor heights, and street widths that are out of balance with building heights. The solution is to first establish a modular system: use 3 meters per floor and 4 meters per bay as the baseline, and combine all blocks in integer multiples. Street width should be 0.6 to 1.2 times the building height to create a sense of pressure and depth.
For layering, split the scene into five groups so you can tune and degrade them separately:
- Terrain layer: road surface, curbs, puddle areas, responsible for receiving reflections.
- Block layer: distant silhouettes, mid-ground main buildings, foreground convenience store, using detail density to separate depth.
- Lighting layer: ambient base light, neon key light, local point lights, dynamic car headlights.
- Particle layer: rain streaks, ground splashes, fog.
- Interaction layer: doors, flickering signs, windshield wipers, camera roaming.
In code, use group objects for unified management, making it easy to scale and toggle visibility as a whole:
const city = new THREE.Group();const terrain = new THREE.Group();const blocks = new THREE.Group();const lights = new THREE.Group();const rain = new THREE.Group();city.add(terrain, blocks, lights, rain);scene.add(city);// Scale by a unified module to avoid adjusting each object's proportionscity.scale.setScalar(1.0);
4. The Core of Rainy Night Texture: Balancing Light, Reflections, and Particles
Rainy nights are hard because they simultaneously demand high-contrast lighting, wet reflections, and high-density particles, and all three consume performance.
For lighting, follow “few but precise”: one low-intensity ambient light as the base, one or two key lights to shape silhouettes, and emissive materials to simulate signs and warm indoor window light, avoiding an explosion of real light sources. Emissive materials combined with post-processing bloom can create neon spill with almost no increase in real-time lights.
For reflections, do not pursue scene-wide mirror surfaces. Use higher reflection quality materials only for puddle areas, and use rougher materials on the rest of the road to catch blurred highlights, creating a “wet but not mirrored” realism. This trade-off concentrates the cost on the focal point of the frame.
Particles are the performance disaster zone. Make rain streaks a particle system that loops within the camera area, constrain the range with a bounding box, and recycle anything outside it; also provide count presets that switch automatically based on frame rate.
function setRainQuality(level){ // level: 0 low, 1 medium, 2 highconst presets = [4000, 12000, 20000];rain.geometry.setDrawRange(0, presets[level]);}// Simple adaptation: lower the level on sustained frame dropslet acc = 0, frames = 0;function adapt(dt){acc += dt; frames++;if(acc > 2){const fps = frames / acc;if(fps < 40) setRainQuality(Math.max(0, currentLevel - 1));acc = 0; frames = 0;}}
5. Interaction and Playability: Making People Stay 30 Seconds Longer
Playability comes from “predictable feedback.” Three low-cost, high-return interaction points: first, the store door opens and closes with warm light spilling out; second, the sign flickers on an irregular rhythm; third, when the camera roams at a low angle, puddles produce ripples. In implementation, abstract interactions into a state machine to avoid scattered logic:
const door = { open:false, angle:0, target:0 };function toggleDoor(){ door.target = door.open ? 0 : Math.PI/2.2; door.open = !door.open; }function updateDoor(dt){door.angle += (door.target - door.angle) * Math.min(1, dt*6);doorMesh.rotation.y = door.angle;}
Once the interaction layer is decoupled from the rendering layer, adding windshield wipers, passing headlights, or day-night switching later will not require changing the main loop structure.
6. Multi-Round Iteration: Minimizing Communication Cost
Getting it right in one shot is the exception; convergence over multiple rounds is the norm. The key to efficient iteration is to change only one class of variables per round and keep a rollback version. Recommended rhythm:
- Round one: define only the skeleton and scale, disable particles and post-processing, confirm composition.
- Round two: add lighting and emissive materials, confirm light and dark relationships.
- Round three: connect particles and reflections, enable performance presets.
- Round four: add interactions and details, polish the experience.
- Round five: implement degradation strategies and fallback handling to ensure low-end devices remain usable.
Keep feedback as quantified as possible: change “buildings too tall” to “reduce main building height from 24 meters to 18 meters”; change “rain too dense” to “lower the particle cap to 12000 and increase transparency.” Quantified feedback lets AI coding tools converge stably instead of drifting randomly.
7. Common Pitfalls Checklist
- Missing units break scale: always declare “1 unit = 1 meter.”
- Too many real-time lights: prefer emissive materials plus bloom instead.
- Scene-wide high reflections: enable high reflections only for puddle areas.
- Particles with no recycling: always implement bounding-box looping and count presets.
- Interaction logic coupled into the render loop: isolate it with a state machine.
- No degradation plan: low-end devices need clear quality presets and automatic switching.
8. Conclusion
Building a rainy night small town with AI coding tools is essentially training yourself to “translate aesthetic judgment into engineering constraints.” When you can break a scene into layers, write feelings as thresholds, and turn interactions into state machines, the controllability of the generated result improves significantly. Scale relies on modules, texture relies on trade-offs between light and reflection, smoothness relies on particle budgets and adaptive degradation, and completeness relies on convergence through round after round of quantified feedback. Once you master this method, any scene in your mind can be reliably turned into a runnable, playable work.
