A Practical Guide to Building a Rainy Night City Scene with AI-Assisted 3D Development
This article walks through a practical workflow for creating a 3D rainy night city scene using an AI coding assistant and a WebGL-based 3D library. It covers structured requirement breakdown, first-pass code generation, iterative refinement of atmosphere and proportions, performance optimization, and deployment. The goal is to show how developers can combine natural language prompts with their own aesthetic and engineering judgment to turn an idea into a running, interactive 3D experience in hours.
From Idea to Running Code: The Value of AI-Assisted Creative Coding
Many developers have experienced this: a vivid image in mind—a rainy night, a street corner, a warmly lit convenience store, wet asphalt reflecting light—but turning that mental picture into a 3D scene that runs in the browser, with a viewport you can orbit and zoom, involves a lot of tedious engineering: scene initialization, camera and controller setup, lighting calculations, particle systems, material tuning, and render performance optimization.
AI coding assistants have changed this workflow. By describing the desired effect in natural language, the AI can generate a structurally complete 3D scene code skeleton. The developer then iterates with the AI through several rounds of focused communication, adjusting proportions, details, and performance. This is not a “one-shot magic” approach; it is an efficient collaboration model—the AI quickly produces a runnable first version, while the human handles aesthetic judgment and engineering oversight.
This article uses a “rainy night city” scene as a case study to walk through the entire path.
Decomposing the Requirement: Translating a Scene into Technical Elements
Before describing the requirements to the AI, it helps to structure the scene yourself. A typical rainy night city scene includes:
- Environment basics: night sky background, fog (to create depth), ground with a wet reflective material.
- Buildings: several low-poly building blocks arranged with varying heights and gaps to create street depth; a convenience store as the visual focal point, with glowing windows and a sign.
- Lighting system: ambient light (cool tones to simulate moonlight or skylight), point lights (street lamps, warm store lights), and emissive materials (neon signs).
- Rain effect: usually implemented with a particle system; each raindrop is a thin line or small plane, moving downward with a slight wind offset.
- Interaction controls: an orbit controller for rotating and zooming the view.
Using this checklist as the backbone of your prompt is far more effective than simply saying “make me a rainy city.”
Scene Setup: First-Pass Generation and Core Structure
A good first prompt might be: “Create a rainy night city scene using a browser-friendly WebGL 3D library, including fog, a reflective ground, a few buildings, a convenience store with warm glowing lights, rain particle effects, and orbit camera controls.”
The AI will typically generate code similar to the following structure:
// Scene and fogconst scene = new THREE.Scene();scene.fog = new THREE.FogExp2(0x0a0a1a, 0.02);// Camera and rendererconst camera = new THREE.PerspectiveCamera(60, innerWidth / innerHeight, 0.1, 200);const renderer = new THREE.WebGLRenderer({ antialias: true });renderer.setSize(innerWidth, innerHeight);document.body.appendChild(renderer.domElement);// Cool ambient light + warm point light for the storescene.add(new THREE.AmbientLight(0x334466, 0.6));const shopLight = new THREE.PointLight(0xffcc88, 2, 30);shopLight.position.set(0, 4, 5);scene.add(shopLight);
The rain can be implemented with a set of line particles:
const rainCount = 3000;const positions = new Float32Array(rainCount * 6);for (let i = 0; i < rainCount; i++) {const x = (Math.random() - 0.5) * 100;const y = Math.random() * 50;const z = (Math.random() - 0.5) * 100;positions.set([x, y, z, x, y - 0.8, z], i * 6); // Each drop is a short vertical line}const rainGeo = new THREE.BufferGeometry();rainGeo.setAttribute('position', new THREE.BufferAttribute(positions, 3));const rain = new THREE.LineSegments(rainGeo, new THREE.LineBasicMaterial({ color: 0x8899bb, transparent: true, opacity: 0.4 }));scene.add(rain);
In the animation loop, you update the raindrop positions to move downward and loop them back to the top. For the wet ground, a material with low roughness combined with a light source gives a reasonable approximation without needing complex real-time reflections.
Iterative Refinement: Proportions, Atmosphere, and Details
The first version runs, but it may lack the desired atmosphere. This stage is where human-AI collaboration really shines. Common issues and communication strategies include:
- Scale problems: buildings too tall, streets too narrow, raindrops too large. Provide concrete numeric constraints, e.g., “buildings should be 8–15 meters high, street width about 12 meters, raindrop line segments no longer than 0.6 meters.”
- Weak atmosphere: the night scene looks flat or gray. Request “increase fog density, change ambient light to a blue-purple tone, make the store window use an emissive material and add a bright sign with a subtle bloom effect.”
- Missing details: add neon signs, specular highlights for puddles on the road, randomly lit windows, and other elements to make the scene feel alive.
A good rule of thumb: focus on only one or two issues per iteration, and give verifiable descriptions (numbers, color tendencies, relative positions) rather than vague requests like “make it look better.”
Performance Optimization: Making the Scene Run Smoothly
Particle count, light count, and material complexity are the three biggest performance killers. Practical recommendations:
- Control particle scale: 3,000–8,000 raindrops are dense enough on mainstream devices; halve the count for mobile.
- Limit dynamic lights: real-time point lights are expensive. Use a few key lights and fake illumination with emissive materials, or use light maps when necessary.
- Merge static geometry: merge buildings, ground, and other static objects into fewer draw calls.
- Resolution adaptation: reduce the render pixel ratio for low-end devices.
You can ask the AI to generate a version with “performance toggles” that switch between high and low quality with a single parameter.
Deployment and Sharing
The finished scene is a single-file page that can be placed directly on any static hosting environment. If you need stable, long-term public access, you can combine a general-purpose object storage and content delivery network (CDN), and optionally set up logging and monitoring alerts to observe traffic and ensure availability.
Conclusion
The value of a project like the “rainy night city” is not in its technical difficulty but in verifying an efficient creative path: a clear structured description → AI generates a runnable skeleton → multiple focused iterations → performance and detail polishing. AI coding assistants have compressed the distance from “in your head” to “in the browser” to a matter of hours, but the developer’s aesthetic sense, decomposition skills, and engineering experience still define the ceiling of what the final work can achieve.
