Building a Rainy Night Town with Three.js and an AI Coding Assistant: From Idea to Running Demo
This article documents the process of building an interactive Three.js "rainy night town" scene with the help of an AI coding assistant. It covers why a rainy-night scene is a great practice project for Web 3D beginners, how to translate a visual idea into a technical requirements checklist, key implementation details (fog, warm-cool lighting contrast, wet-ground reflections, and a performance-friendly rain particle system), the practical realities of iterating with AI-generated code, and a reusable methodology for turning creative ideas into runnable 3D prototypes with LLM-based coding tools.
1. Why a “Rainy Night Town” Makes a Great Practice Project
In Web 3D development, the biggest pain point for beginners is often not writing code itself, but knowing where to start: how to organize a scene, lay out lighting, drive animations, and make performance trade-offs. A concrete, visually vivid goal—such as “a convenience store corner on a rainy night”—turns out to be an ideal practice vehicle.
There are three reasons:
- A concrete target with clear acceptance criteria. Keywords like “rainy night,” “convenience store,” “neon signs,” and “wet pavement” naturally define the visual acceptance standard for the scene. Whether it’s done or not is obvious at a glance.
- Broad technical coverage. A rainy-night scene touches geometry modeling, material reflection, particle systems (raindrops), lights and shadows, fog, and animation loops—nearly all of Three.js’s core knowledge modules. Finishing one small scene is close to completing an introductory course.
- Atmosphere-driven with high fault tolerance. Rainy-night scenes inherently carry a hazy, low-contrast visual tone. Flaws in model details get masked by the atmosphere, making it perfect for fast iteration and quick results.
In this practice, I used an AI coding assistant to build the entire scene, aiming to verify one thing: can today’s LLM-based coding tools quickly turn a vague creative idea into a genuinely runnable, playable piece of work?
2. From Idea to Requirements: Translating the “Picture” into a Technical Checklist
Telling the AI “build me a rainy-night convenience store” will produce results, but most likely a rough placeholder scene. To keep the output controllable, the first step is translating the visual impression into a technical requirements checklist. My breakdown was:
- Scene skeleton: A small street whose centerpiece is a convenience store with a glass storefront, surrounded by building silhouettes, streetlights, and signage.
- Lighting system: Overall ambient light that is dim and cool-toned, warm light spilling out from inside the store, and neon signs providing accent colors—creating a warm-cool contrast.
- Rain elements: Continuously falling raindrop particles, ground reflections (simulating puddles), and water streaks or fog on the windows.
- Dynamic elements: Raindrop animation, flickering sign lights, and subtle brightness changes inside the store to make the scene feel “alive.”
- Interaction and camera: An orbit camera supporting mouse-drag rotation and scroll-wheel zoom, giving users room to play.
After sending this checklist to the coding assistant, the generated code structure was noticeably better organized. This confirms a general lesson: when collaborating with AI, the more granular your requirement breakdown, the higher the quality of the first-round output.
3. Core Technical Implementation Details
3.1 Scene and Camera: Atmosphere Starts with Fog
Fog is the first ingredient of a rainy night. In Three.js, scene fog quickly darkens the distance and creates depth:
const scene = new THREE.Scene();scene.background = new THREE.Color(0x0a0d14);scene.fog = new THREE.FogExp2(0x0a0d14, 0.045);
Exponential fog suits night scenes better than linear fog because its falloff is more natural—distant buildings blend softly into the night instead of hitting a visible “fog wall.” For the camera, use a perspective camera with a slightly elevated downward angle so reflections from the wet ground enter the frame.
3.2 Lighting Design: Warm-Cool Contrast Is the Soul of a Rainy Night
The whole scene uses only three types of light sources:
- Ambient light: Extremely low intensity with a cool tone—responsible for making things “visible” rather than “clearly lit.”
- Point light: One warm-white point light inside the store, shining through the glass storefront to illuminate a small area in front of the door.
- Point lights / emissive materials: Neon signs are implemented with emissive materials, paired with low-intensity colored point lights that bleed color onto their surroundings.
const shopLight = new THREE.PointLight(0xffd9a0, 2.5, 18);shopLight.position.set(0, 3, 4);scene.add(shopLight);
A practical tip: for night scenes, don’t chase physically accurate lighting. Instead, establish the atmospheric baseline first, then add detail lights. Once the warm-cool contrast works, the scene immediately gains a “cinematic” feel.
3.3 Wet-Ground Reflections: Balancing Effect and Cost
Puddle reflections are the finishing touch of a rainy-night scene, but real-time planar reflection is expensive. Two common compromises are used in practice:
- MeshStandardMaterial with adjustable roughness: Lower the ground’s roughness and raise its metalness, combined with an environment map, to get a blurry yet believable reflective feel.
- Enable reflective materials only on the main ground area, and use dark, glossy materials for distant ground instead.
In the AI-generated first version, the ground was a single matte plane with no reflection at all. This is a typical case requiring multiple rounds of communication: AI can quickly deliver a “working” implementation, but the details that make it “look good” need to be pointed out and iterated on by a human.
3.4 Rain Particles: A Performance-First Approach
Raindrops are implemented with a particle system, and the key is not to create an independent object for each drop:
const rainCount = 4000;const positions = new Float32Array(rainCount * 3);// Initialize a random distribution, move everything down each frame,// and reset drops that fall out of range back to the top
Use BufferGeometry to write vertex data once, update only the position array each frame, and render with PointsMaterial. Four thousand raindrops still hold a stable 60 FPS on mid-range devices. This leads to a useful rule of thumb: particle count, shadow map resolution, and the reflection toggle are the three big performance dials of a rainy-night scene—spend your budget on the rain and reflections that most affect the visuals.
4. Iterative Communication: AI Is Not One-Shot Magic
To be honest, this project was not perfect on the first generation. The actual process involved multiple rounds of adjustments:
- Proportion issues: In the first version, the store was too small relative to a human viewpoint and the signage too large. I had to explicitly provide reference size relationships and regenerate.
- Performance issues: The first version enabled real-time shadows across the whole scene, and the frame rate dropped noticeably. Switching to a single shadow map on the main light source restored smoothness.
- Detail issues: Window water streaks, sign flicker rhythm, and similar points fall into the “AI won’t do it unless you say it” category and need to be described one by one.
My takeaway in one sentence: treat AI as an extremely fast junior engineer who needs clear work orders. The more specific your acceptance criteria, the fewer rounds of rework. Each round of communication works best when it revolves around two points: “what’s wrong” and “what’s expected.”
5. Methodology Summary
Looking back at the whole process, using AI coding tools to build Web 3D creative works can be distilled into a general path:
- Picture first: Write down the scene’s emotional keywords, then translate them into a technical checklist.
- Small steps, fast iterations: Have the AI produce a minimal runnable version first, then add details item by item—avoid losing control with one giant prompt.
- Human gatekeeping: Proportions, color schemes, and performance—these “aesthetic and engineering judgments” still need human oversight.
- Performance budget: Keep clear priorities among particles, shadows, and reflections; secure the frame rate first, then the details.
For developers, the real value of these tools is not replacing coding, but compressing the distance from idea to prototype. When an idea can become a draggable, rotatable, shareable 3D world in minutes, the cost of trial and error drops dramatically—and the willingness to create naturally grows. Perhaps on the next rainy night, the little town in your mind deserves to be built right away.
