A Practical Guide to AI Coding for Three.js Rainy Night Scenes
This article explains how to use natural language with AI coding tools to build a Three.js rainy night street scene that actually runs, looks right, and stays maintainable. It covers translating vague mood into measurable scene constraints, a four-stage small-step iteration strategy, key techniques for rain, wet reflections, glow, fog, and glass streaks, plus performance budgets, mobile fallback paths, deployment on general cloud services, and a final acceptance checklist.
1. Why a “Rainy Night Town” Is an Ideal Test of AI Coding
When you drive AI coding tools with natural language to generate 3D scenes, the difference over the past two years is less about “can it generate” and more about “can the result run, look right, and keep evolving.” A rainy night theme compresses three hard problems at once. First, spatial proportion: once street width, step height, or sign dimensions drift, the image immediately feels plastic. Second, dynamics and performance: rain streaks, wet ground reflections, and neon glow all cost per frame. Third, detail density: the water film on slick pavement, streaks on glass, and layering of distant buildings—missing any one of them collapses the atmosphere.
So treating “build a rainy night town” as a practice exercise is really about training a reusable collaboration workflow: translate a fuzzy image into structured constraints, converge through small iterations, then use engineering measures to hold performance and maintainability.
2. Translating “Atmosphere” into Machine-Executable Constraints
When you describe atmosphere in natural language, models easily produce results that “look right but are proportioned wrong.” A reliable approach is to write a scene specification first, breaking subjective impressions into quantifiable items:
- Spatial scale: main street clear width about 8–10 units, sidewalk raised 0.15 units above the road, convenience store doorway about 2.2 units high;
- Camera and composition: eye height 1.6 units (close to human eye level), initial camera at a 15° angle to the street axis to avoid full symmetry;
- Lighting structure: one key light (cool white, simulating a street lamp) + warm storefront sign light as a visual anchor + very low ambient light;
- Weather and materials: rain as thin strips rather than point particles, low ground roughness with medium metalness to form broken highlights;
- Performance red lines: draw calls kept in double digits, a clear per-frame logic and render budget, and a mobile fallback.
An illustrative requirement can be written as a structured snippet so the model understands it reliably:
Scene: night street + one convenience storeScale: street width 9, sidewalk height 0.15, doorway height 2.2Camera: eye height 1.6, 15 degrees to street axis, slow forward/back dollyLighting: cool white street lamp as key, warm sign as fill, ambient intensity 0.05Materials: asphalt low roughness, localized puddles high reflection; glass with water streaksConstraints: total draw calls < 40; particle cap 3000; low-end fallback supported
The value of this step is replacing an instruction like “make it more realistic,” which cannot converge, with acceptance conditions you can judge as pass or fail.
3. Iteration Strategy: Small Commits, Skeleton Before Skin
In practice, things rarely land in one pass, and problems usually cluster in proportion, performance, and detail. Advance in four stages, each required to be runnable:
- Skeleton stage: generate only the ground, curbs, building blocks, and camera control; confirm perspective and scale;
- Lighting stage: add the key light, emissive signage, and fog; confirm light-dark relationships and the visual focus;
- Dynamics stage: wire in rain streaks, ripples, glass water streaks, and a slight camera breathing motion;
- Polish stage: fill in sign typography, shelf silhouettes, ground water film distribution, and distant building layers.
Changing only one variable at a time is the key to controlling rework cost. For example, changing “the image is not realistic enough” into “change step height from 0.3 to 0.15 and set camera eye height to 1.6” is what lets the model output hit the target reliably.
4. Technical Points for Rainy Night Texture
Rain: prefer GPU-friendly strips or line segments, and recycle the same batch of particles around the camera position instead of creating objects endlessly; attenuating streak length and opacity with distance noticeably reduces the “white noise dots” look.
Wet reflections: no need to chase a true mirror. A common compromise is low-roughness floor tiles + screen-space reflections or a planar reflection map, then overlaying a noise mask to create uneven wet and dry areas.
Glow and fog: emissive materials with post-processing glow turn the sign into an image anchor; fog compresses distant contrast, hides scene edges, and reduces the modeling pressure of far detail.
Glass water streaks: use a procedurally generated normal/roughness map that stretches streaks along the gravity direction, far cheaper than modeling each drop.
Illustrative code (only expressing the general idea, not a specific API):
// Pseudocode: rain streak recycling + distance attenuationconst rainCount = 3000;positions.forEach((p, i) => {p.y -= speed * dt;if (p.y < 0) p.y = height; // recycle, avoid frequent creationalpha[i] = clamp(1 - dist(i) / far, 0, 1);});
5. Performance Budget and Fallback Path
Write the budget down before you start rather than optimizing afterward: draw calls, triangle count, particle cap, and post-processing toggles should all have thresholds. Provide a fallback chain for mobile or low-end environments: turn off glow → lower the particle cap → reduce reflection map resolution → switch distant scenery to billboards. Fallbacks should be configuration items rather than rewritten branches, which helps long-term maintenance.
6. From Local Demo to Online: General Cloud Capabilities
For others to open and play with the work, you need a stable way to host it. Only general categories are needed here: put static assets in object storage and accelerate the first screen through a content delivery network; after containerizing, hand off to a container platform for rolling release; send logs to a log service, and watch error rate and response latency with monitoring and alerting. Baidu AI Cloud offers corresponding capabilities in these general categories, and you can choose specs by actual traffic without over-provisioning for a single demo.
7. Acceptance Checklist
- Scale: are human eye height and the doorway and step proportions natural;
- Composition: is there an obvious visual focus and layering in the distance;
- Dynamics: do rain streaks recycle, and is there a configurable particle cap;
- Performance: can draw calls and fallback toggles be switched with one action;
- Maintainability: are scene parameters centrally managed rather than scattered in logic.
8. Conclusion
The real value of AI coding tools is not writing all the code for developers, but shrinking the time to turn “an idea in your head” into a runnable prototype from days to hours. Proportion, performance, and detail still need people to check and to communicate repeatedly, but once you structure requirements, make iterations small, and move budgets to the front, a seemingly emotional topic like a rainy night town can become a stable, reusable engineering practice.
