Generating a Three.js Rainy Night City Scene with Large Language Models
This article walks through building a rainy-night convenience store scene in Three.js with AI coding tools. It covers the basic setup, neon lighting, wet street reflections, and rain particles, then explains the scale, performance, and detail challenges that came up and how prompt-driven iteration helped resolve them.
Large language models are changing how front-end and 3D visualization work gets done. Setting up a Web 3D project has traditionally taken a lot of time on scene initialization, coordinate calculations, and lighting and shadow tuning. With AI coding tools, developers can turn an idea into a working, interactive Web 3D piece much faster. This article uses a “rainy-night convenience store” scene as an example. It explains how to use AI to generate Three.js code and discusses the technical challenges and tuning strategies that come up along the way.
1. Core Tech Stack and How AI Fits In
WebGL and Three.js form the core of this kind of scene. Three.js wraps the low-level WebGL API and provides a higher-level scene graph. When working with an AI coding tool, the key step is translating a natural-language request into JavaScript that follows Three.js conventions.
Start by giving the AI clear context. For example, you might ask it to “use the latest version of Three.js and build a basic skeleton with a scene, a perspective camera, and a WebGL renderer.” The AI can quickly generate standard initialization code with Scene, PerspectiveCamera, and WebGLRenderer, and it typically adds a requestAnimationFrame render loop. This saves you from looking up documentation and writing boilerplate, so you can go from zero to a running scene quickly.
2. Breaking Down the Visual Elements
The rainy-night convenience store gets its look from three elements: neon lights at night, reflections on wet streets, and falling rain particles. With AI assistance, each element can be broken down and implemented separately.
2.1 Neon Lighting and Materials
The defining feature of a convenience store on a rainy night is its neon sign. If you ask the AI to “add a glowing effect at the store sign position and create a halo around it,” it will usually suggest PointLight or RectAreaLight to simulate an area light source. It may also use an emissiveMap to make the sign glow more strongly.
For the wet street, adjust the physical properties of MeshStandardMaterial. Ask the AI for a ground material with low roughness and high metalness so that it reflects the store’s light.
2.2 Dynamic Rain Particle System
Rain drives the sense of motion in the scene. In traditional Three.js development, particle systems often require complex geometry and shader code. With AI assistance, you can describe the requirement directly: “Create a particle system with 2000 raindrops using a Points object. The raindrops should fall along the Y axis and reset their position after they hit the ground.”
The generated code is usually based on BufferGeometry. It updates a Float32Array of vertex positions to animate the falling rain. Here is the core logic, shown for illustration:
// Core particle system logic generated with AI assistance (illustrative example)const rainCount = 2000;const rainGeometry = new THREE.BufferGeometry();const rainPositions = new Float32Array(rainCount * 3);for (let i = 0; i < rainCount * 3; i += 3) {rainPositions[i] = Math.random() * 200 - 100;rainPositions[i + 1] = Math.random() * 160;rainPositions[i + 2] = Math.random() * 200 - 100;}rainGeometry.setAttribute('position', new THREE.BufferAttribute(rainPositions, 3));const rainMaterial = new THREE.PointsMaterial({ color: 0xaaaaaa, size: 0.1, transparent: true });const rain = new THREE.Points(rainGeometry, rainMaterial);// Animation update logicfunction updateRain() {const positions = rainGeometry.attributes.position.array;for (let i = 1; i < positions.length; i += 3) {positions[i] -= 0.5; // Falling speedif (positions[i] < 0) {positions[i] = 160; // Reset height}}rainGeometry.attributes.position.needsUpdate = true;}
3. Challenges and Tuning: Not a One-Shot Process
AI is good at producing quick prototypes, but building a complex 3D scene does not usually go smoothly on the first try. Spatial proportions, rendering performance, and visual details all need repeated back-and-forth with the AI.
3.1 Fixing Spatial Proportions
Language models do not have a precise sense of real-world scale. In the first version of the code, the store building may be too large, or the street may be too narrow for the perspective camera to frame the scene properly.
Strategy: Use modular prompts with explicit numeric constraints. Instead of asking for “a bigger building,” ask for “a box geometry 20 units wide, 10 units high, and 15 units deep as the main store body.” Once you set a base unit, ask the AI to build the surrounding elements relative to that main body. This keeps the overall proportions consistent.
3.2 Rendering Performance Bottlenecks
Scenes with many particles, complex lighting, and high-resolution textures often run into frame rate drops. AI-generated code tends to focus on getting features working and pays less attention to performance.
Strategy: Ask the AI to refactor for performance. For example, you can ask it to “keep the particle count within a reasonable range and reuse shared material objects,” or to “enable antialiasing on the renderer, but cap the pixel ratio at the device pixel ratio.” For shadows, you can ask it to keep the shadowMap resolution at or below 2048 and to tighten the shadow camera frustum so that unnecessary objects do not cast shadows.
3.3 Iterating on Fine Details
AI handles large-scale architecture well, but it often misses small visual details. Examples include ripples where raindrops hit the ground or water vapor on the store’s glass windows. These details usually need step-by-step guidance.
Strategy: Use an incremental approach. Do not ask the AI to implement every effect at once. Split the scene into separate modules: environment, main lighting, rain effects, and interaction logic. After each module is built and verified, ask the AI to add the next feature on top of it. This reduces the chance of generation errors and makes it easier to find the source of a bug.
4. Best Practices and Engineering Recommendations
Based on this work, these practices help when using AI for 3D front-end development:
- Manage assets as an engineering concern. High-resolution textures and model files are often large. In production, host them on object storage and deliver them through a CDN, a common industry approach, so the page loads quickly.
- Keep a structured prompt library. Save your basic Three.js initialization code, commonly used material parameters, and lighting setups as reusable prompt templates. This improves the accuracy and consistency of generated code.
- Keep human review in the loop. AI is an efficient code generator, but it does not replace an architect. Developers still need a solid understanding of Three.js and computer graphics so they can quickly adjust shader code or scene graph structure when the output does not match expectations.
5. Conclusion
Building a Three.js rainy-night convenience store scene with AI coding tools shows that AI works well for turning an idea into a runnable Web 3D prototype. It lowers the barrier between a concept and working code. Production delivery still depends on developer judgment. Through repeated refinement of proportions, performance, and details, developers and AI settle into a working relationship: AI handles the heavy lifting of code and boilerplate, while developers focus on architecture, visual tuning, and user experience. As models improve at understanding context, this kind of collaborative workflow should unlock more potential in future Web 3D applications.
