Building a Rainy Night City Scene with AI Coding Tools
This article presents a practical methodology for using AI coding tools to build a rainy night convenience store scene in Three.js. It explains how to translate atmospheric descriptions into engineering constraints, how to break generation into verifiable steps, and how to handle scale, wet-floor reflections, rain particles, lighting, post-processing, and performance budgets. A troubleshooting checklist and engineering advice for turning a demo into a maintainable project are also included.
1. Introduction: Why a Rainy Night Town Is an Ideal Test for AI Coding
Once generative coding tools became part of the daily development workflow, a common expectation emerged: can you describe a scene in natural language and get a runnable, interactive 3D scene directly? A rainy night convenience store is an ideal test case for this capability—it involves geometry modeling, scale constraints, materials and lighting, particle systems, post-processing, and performance budgets all at once. If any one of these gets out of control, the image immediately looks “off.”
The practical conclusion is not mysterious: AI coding tools can indeed turn ideas into a runnable demo quickly, but they rarely get it right on the first try. Scale, performance, and details usually require multiple rounds of communication and iteration. This article strips away product-specific attributes and abstracts the process into a general “AI-assisted Three.js scene development methodology” that developers and teams can reuse.
2. Requirement Breakdown: Translating “Atmosphere” into Executable Engineering Constraints
Phrases like “rainy night, convenience store, warm lighting” in natural language are atmospheric descriptors that a machine cannot execute directly. The first step must be translating “atmosphere → parameters”:
- Scene scale: Use a real convenience store as a reference—floor height around 2.8–3.2 m, door width 0.9–1.2 m, shelf height 1.4–1.8 m, street width 6–8 m. Writing these numbers into the prompt is the most effective way to avoid “scale collapse.”
- Time and environment: Nighttime, light to moderate rain, low illumination, high-humidity reflections.
- Visual anchors: Warm indoor light (around 2700–3000K) contrasted with cool ambient light (around 6500–8000K); wet ground producing mirror reflections and trailing highlights.
- Interaction goals: Walkable, doors that open and close, switchable rain intensity, and an FPS display.
It is recommended to explicitly state constraint priorities in the prompt, for example: “First ensure correct scale, then ensure performance targets are met, and finally add details,” so the model makes predictable trade-offs when conflicts arise.
3. Prompt and Iteration Strategy: Turning One-Shot Generation into Controlled Convergence
A single generation can rarely cover all constraints. A more reliable approach is to break the task into several verifiable small steps:
- Skeleton first: Generate only the box layout of the ground, walls, doors, windows, and shelves, without loading any materials or effects.
- Scale calibration: Use objects with known dimensions (such as a 1.7 m tall human reference or a standard door frame) for visual verification.
- Materials and lighting: Add wet-floor reflections, glass transmission, and self-illuminated signage.
- Particles and post-processing: Add rain streaks, splashes, fog, and light bloom last.
- Performance closure: When the frame rate is below target, reduce elements in reverse rather than continuing to pile on details.
A reusable prompt skeleton example:
Build a Three.js scene: a corner convenience store on a rainy night with light rain.Hard constraints: floor height 3.0m, door width 1.0m, shelf height 1.6m, street width 7m.Lighting: warm indoor light 2800K, cool ambient light 7000K, wet-floor reflections.Performance: target 60fps, with mobile fallback.Output: a single HTML file with basic walk controls and rain intensity toggle.
4. Key Technical Areas and Implementation Points
1. Scale and Camera
Scale problems are often not calculation errors by the model but a lack of a reference frame. Recommended practices include: using a perspective camera with a fixed field of view around 50°; extracting key dimensions into centrally managed constants; and displaying bounding boxes and a ground grid during debugging.
const DIM = { floorHeight: 3.0, doorWidth: 1.0, shelfHeight: 1.6, streetWidth: 7.0 };const camera = new THREE.PerspectiveCamera(50, innerWidth / innerHeight, 0.1, 200);
2. Wet Ground and Reflections
The realism of wet ground comes from “lower roughness + reflections + normal perturbation.” The general approach is to use a low-roughness material combined with planar reflections or an environment map, then overlay a layer of subtle ripple normals to avoid reflections that are too perfect and look like a mirror.
3. Rain and Particles
Rain streaks are usually implemented with line segments or stretched sprites, recycling particles around the camera position to avoid unbounded growth. The key is to control the total particle count and update frequency, and to automatically downgrade on mobile.
// Example: recycle a fixed number of particles falling, avoiding continuous memory growthpositions[i * 6 + 1] -= speed * dt;if (positions[i * 6 + 1] < 0) positions[i * 6 + 1] = 20;
4. Lighting and Post-Processing
Night scenes are the most sensitive to lighting. Recommendations: use a small number of point/area lights indoors to shape warm zones, and low-intensity cool ambient light outdoors; keep bloom intensity restrained to avoid signage blurring into a single mass; use fog to compress distant contrast and strengthen depth.
5. Performance Budget
Set the budget before writing effects: draw calls, triangle counts, texture sizes, and particle counts should all have upper limits. Downgrade strategies include lowering the pixel ratio, reducing post-processing passes, shrinking shadow maps, and switching particle density based on device capability.
5. Common Issues and Troubleshooting Checklist
- Scale distortion: Check whether reference objects are missing and whether constants are centrally managed.
- Washed-out image: Ambient light is too strong or fog density is too high, lowering contrast.
- Unnatural reflections: Roughness is too low or normal perturbation is missing.
- Sudden frame rate drop: Particle or post-processing overhead is too high; prioritize adding a downgrade switch.
- Broken interaction: Control events are too tightly coupled with the render loop; decouple them into independent state.
6. Engineering Recommendations: From Demo to Maintainable Project
When a scene needs long-term maintenance, split the single file into four layers: scene construction, material library, effects modules, and performance monitoring; centralize adjustable parameters into a configuration object; integrate general capabilities such as logging and monitoring alerts to collect frame rate and exceptions; use object storage for static assets and a container platform for build and preview environments. This way, AI-generated code can move from “it runs” to “maintainable.”
7. Conclusion
The value of AI coding tools lies in shortening the distance from “idea to runnable work,” but scale, performance, and details still require developers to repeatedly calibrate with engineering judgment. Translating atmosphere into parameters, breaking generation into small steps, and setting budgets upfront are the three most valuable lessons to retain from this workflow.
