Building a Rainy Night Town 3D Scene with AI Coding Tools: A Practical Case Study
This article describes how a developer built an interactive 3D web scene of a small town on a rainy night with an AI coding tool. It covers breaking a visual idea into technical requirements, building the scene in iterative rounds, adding rain and lighting effects, optimizing performance, and practical tips for working with AI coding assistants.
1. Background: When Creative Ideas Meet AI Coding Tools
Many developers have had this experience. An image forms in their mind: a small town street corner on a rainy night, a convenience store glowing with warm light, neon reflecting off wet pavement, and rain clearly visible under the streetlights. When they start writing code for it, however, the tedious details often discourage them. 3D scene development involves geometric modeling, materials and lighting, particle systems, and rendering performance. Writing everything from scratch takes a long time, and debugging can drain the enthusiasm for the creative work.
AI coding tools have matured enough to change this. Developers can describe the scene and its interactions in natural language, have the tool generate a basic code framework, and then refine proportions, optimize performance, and add details over several rounds of conversation. This article uses a “rainy night town” scene as an example to review the process and extract a reusable approach.
2. Overall Technical Plan
2.1 Requirement Breakdown
Before starting, break the general description of a rainy night town into elements that can be implemented:
- Static scene: streets, buildings, the convenience store as the main building, signboards, street lamps, and roadside trees;
- Dynamic effects: falling rain streaks, reflections in puddles on the ground, neon signs that pulse and flicker, and warm light spilling out of the convenience store;
- Interaction: drag with the mouse to rotate the view, scroll to zoom, and click to switch between day and night or change the rain intensity;
- Performance constraint: keep the frame rate smooth on typical consumer devices, with controlled rendering cost.
2.2 Technology Choice
Web-based 3D scenes commonly use rendering libraries that wrap low-level graphics APIs. These libraries provide abstractions such as scene graphs, cameras, geometries, materials, lights, and post-processing. Developers can focus on what to place, how it lights up, and how it moves, without working directly with the underlying graphics API. Rain can be built with a particle system or custom shaders. Puddle reflections can be approximated with planar reflection or screen-space techniques.
3. Step-by-Step Implementation
3.1 First Round: Building the Scene Skeleton
When describing the requirements to an AI coding tool, a structured prompt works well. For example:
Create a web-based 3D scene that includes:1. A wet asphalt street with low-rise buildings on both sides;2. A convenience store at the street corner with large glass display windows and warm yellow light glowing from inside;3. A night setting with bluish ambient light, plus several street lamps and neon signs;4. Mouse orbit controls for the camera.
The tool typically generates a single-file page that includes renderer initialization, scene setup, and an animation loop. The key at this stage is to get something running first. Don’t worry about the details yet.
3.2 Second Round: Adding Rain
The classic way to build rain is a particle system. Generate a large number of thin line segments or point sprites above the scene, move them downward each frame, and recycle them to the top once they fall below the boundary. Example code:
const RAIN_COUNT = 8000;const positions = new Float32Array(RAIN_COUNT * 3);const velocities = new Float32Array(RAIN_COUNT);for (let i = 0; i < RAIN_COUNT; i++) {positions[i * 3] = (Math.random() - 0.5) * 100; // xpositions[i * 3 + 1] = Math.random() * 50; // ypositions[i * 3 + 2] = (Math.random() - 0.5) * 100; // zvelocities[i] = 0.5 + Math.random() * 0.5; // falling speed}function updateRain() {for (let i = 0; i < RAIN_COUNT; i++) {positions[i * 3 + 1] -= velocities[i];if (positions[i * 3 + 1] < 0) positions[i * 3 + 1] = 50;}rainGeometry.attributes.position.needsUpdate = true;}
When requesting this from the tool, you can add more specific constraints to make the effect more lifelike. For example, ask for rain streaks tilted to suggest wind, or for small splash particles where drops hit the road.
3.3 Third Round: Lighting and Atmosphere
The atmosphere of a rainy night depends mostly on the contrast between light and shadow:
- Wet ground reflections: Raise the specular highlights and reflectivity of the road material, or use a mirror-like reflection plane, so that neon and streetlight glows stretch into long reflections.
- Volumetric light effect: Place semi-transparent cones below the street lamps to simulate light shafts. Rain that passes through them appears lit, which adds visual depth.
- Color palette: Use cool blue ambient light for the environment, and warm point lights for the convenience store windows and signs. The warm and cool contrast defines the mood.
The most common problem at this stage is incorrect proportions, such as buildings that are too tall, signs that are too large, or rain streaks that are too thick. The fix is to give the tool explicit reference sizes, such as “the convenience store is about 3 meters tall, the street is about 8 meters wide, and each rain streak is about 0.3 meters long.” Vague instructions like “make it a bit smaller” work much less well.
3.4 Performance Optimization
A first version often runs but stutters. Common optimizations include:
- Merging static geometry: Combine buildings, roads, and other stationary objects into a few meshes to reduce the number of draw calls.
- Controlling particle count and update frequency: Scale the number of rain particles to the device’s capability, and update distant rain less often.
- Reducing the number of lights: Real-time point lights are expensive. Bake distant lights into emissive textures and keep only a few real light sources near the camera.
- On-demand rendering: Lower the render rate when the view is still, and restore the full frame rate during interaction.
Ask the tool to identify performance bottlenecks first, with a prompt such as “Analyze the rendering cost of the current code and propose optimizations.” Then confirm each change one at a time. This usually works much better than asking for a general “optimize this.”
4. Lessons on Working Efficiently with AI Coding Tools
The process did not succeed on the first try. Proportions, performance, and details each required repeated back-and-forth. The main lessons are:
- Break requirements into stages: Build the skeleton first, then the effects, then the optimizations. Focus each round on one goal. Long requirement lists in a single prompt can lower the quality of the generated code.
- Describe things with measurable terms: Specific dimensions, color values, and frame rate targets are far more useful than “looks nicer.”
- Keep control of debugging: Read and understand the key logic in the generated code so you can locate problems yourself, rather than relying on the tool to retry repeatedly.
- Expect iteration: Treat the tool as a very fast partner that needs clear instructions. The communication cost is part of the development process.
5. Conclusion and Outlook
AI coding tools have made it much easier to turn an idea into a 3D work that runs and can be explored interactively. The same natural-language-driven approach also applies to data visualization, product prototype demos, and teaching materials, not only creative demos. Teams that want to deploy this kind of interactive application in the cloud can also use general-purpose cloud capabilities, such as object storage for hosting static assets and container platforms for running server-side services, to move from a local prototype to a live service. As tools improve at understanding complex scenes, developers will likely spend more of their time on creative design and architecture decisions, while repetitive coding work shrinks further.
