Building a Rainy Night City Scene in Three.js with AI Coding Assistants
Learn how to use AI coding assistants to build a rainy night convenience store scene in Three.js. This article covers scene requirement breakdown, prompt design, iterative refinement of proportions and visual details, and performance optimization for particle systems, geometry merging, and shadows.
In traditional web 3D development, turning a creative idea in your head into a runnable scene often involves tedious API lookups, math calculations, and endless parameter tuning. However, as large language models and AI coding assistants mature, developers can now focus more on creativity itself while delegating the underlying implementation to AI. This article uses the example of building a “rainy night convenience store” scene to explore how to leverage AI coding tools through natural language conversation and iteration to quickly generate and refine a Three.js-based 3D web project.
1. Breaking Down Requirements and Choosing the Tech Stack
To build an immersive rainy night convenience store scene, the visual elements first need to be broken down. The core of this scene lies in the interplay of “rain,” “night,” and “neon lighting.”
- Environment and lighting: A night scene calls for low-intensity ambient light, supplemented by point lights and spotlights to simulate streetlights and the neon glow of the store sign. A rainy night also carries a gloomy tone, so fog effects are needed to enhance depth and atmosphere.
- Geometry and materials: The store structure, street, and signage can be assembled from basic geometry. In terms of materials, the wet street surface needs reflective properties (MeshStandardMaterial with adjusted roughness and metalness parameters), while the neon sign requires an emissive material.
- Particle system (raindrops): Rain is the soul of the scene. For performance reasons, complex solid models are unsuitable; instead, a Points particle system based on BufferGeometry should be used, with custom shaders or texture mapping to convey the motion of falling raindrops.
For the tech stack, Three.js—the leading WebGL wrapper library—provides comprehensive support for lighting, materials, and geometry, making it the ideal framework for this scene.
2. Prompt Design and Initial Code Generation
When working with an AI coding assistant, precise prompts are the key to getting high-quality code. Rather than vaguely asking for “a rainy night convenience store,” structure your requirements and describe them module by module.
Prompt design principles:
- Specify the tech stack: State that you want the latest version of Three.js with ES Modules syntax.
- Describe the scene structure: List the required objects (ground, main building, glass doors and windows, glowing sign).
- Set the lighting and atmosphere: Request ambient fog, neon point lights, directional lights, and so on.
- Require an animation loop: Explicitly ask for the falling raindrop animation and the render loop.
Based on these principles, once you send your instructions to an AI coding tool, it typically generates a complete HTML/JS file structure covering scene initialization, camera configuration, renderer setup, and basic object placement. Here is a typical example of AI-generated code:
import * as THREE from 'three';// 1. Scene and fogconst scene = new THREE.Scene();scene.fog = new THREE.FogExp2(0x0a0a12, 0.015); // deep blue night fog// 2. Camera and rendererconst camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);camera.position.set(0, 5, 15);const renderer = new THREE.WebGLRenderer({ antialias: true });renderer.setSize(window.innerWidth, window.innerHeight);renderer.shadowMap.enabled = true;document.body.appendChild(renderer.domElement);// 3. Ground material (simulating wet reflections)const groundGeometry = new THREE.PlaneGeometry(50, 50);const groundMaterial = new THREE.MeshStandardMaterial({color: 0x111111,roughness: 0.2,metalness: 0.8});const ground = new THREE.Mesh(groundGeometry, groundMaterial);ground.rotation.x = -Math.PI / 2;scene.add(ground);// 4. Neon light sourceconst neonLight = new THREE.PointLight(0xff00ff, 2, 20);neonLight.position.set(0, 3, 2);scene.add(neonLight);// (raindrop particle system and building model code omitted)
3. Fixing Scene Proportions Through Multi-Turn Iteration
Although AI coding assistants can quickly produce a runnable code skeleton, in practice the first output rarely comes out perfect. Proportion problems and missing details are common in the initial code.
- Adjusting proportions and spatial relationships: The AI-generated convenience store might have an oversized door frame or an undersized sign. Instead of rewriting the code, simply tell the assistant in natural language: “Scale the convenience store building’s width by 1.5x, raise the neon sign by 2 units, and match its size to the door frame.” This kind of multi-turn, conversational fine-tuning quickly corrects spatial proportions.
- Enhancing visual details: To improve realism, ask the AI to add details. For example: “The ground looks too smooth—add some normal map textures to convey the graininess of asphalt. Also, give the store’s glass a semi-transparent physical material with reflections.” Through iteration, the scene’s texture gradually becomes richer.
This communication style dramatically reduces trial-and-error cost. Developers no longer need to dig through documentation for specific parameter names—just describe the visual effect, and the AI translates it into the corresponding code logic.
4. Overcoming Performance Bottlenecks and Optimizing Rendering
In web 3D development, performance optimization is a constant concern. Once the scene includes thousands of raindrop particles and complex lighting, dropping frame rates often become the main obstacle to a usable result.
AI coding assistants, when generating the initial code, tend to sacrifice performance for visual quality. For example, the initial raindrop system might contain tens of thousands of particles, each undergoing complex lighting calculations. At this point, you can guide the AI toward targeted optimizations:
- Particle count control and optimization: Ask the assistant to reduce the particle count to a reasonable range (e.g., 5,000), switch to PointsMaterial with a custom texture, and disable lighting calculations for the particle system (
lights: false), relying solely on texture colors. - Geometry merging: For small, non-deforming objects around the convenience store that share the same material (such as trash cans and streetlight poles), instruct the AI to merge them with
BufferGeometryUtils.mergeGeometries, greatly reducing draw calls. - Shadow optimization: Real-time shadow computation is extremely expensive. You can ask the AI to disable shadow casting for small objects, keeping shadow reception only for the large building and the ground—or adopt the idea of baked lightmaps, pre-rendering static lighting and shadows into textures.
After a few rounds of performance-tuning dialogue, the AI coding assistant can produce code that balances visual quality with frame rate, allowing this rainy night convenience store scene to run smoothly even on mid- and low-end devices.
5. Final Thoughts
This practice shows that using LLM-powered AI coding tools to build Three.js 3D scenes has moved from concept to practical reality. It is not always a one-shot solution—scene proportions, performance overhead, and fine details still require repeated communication and iteration between the developer and the tool—but there is no denying that this workflow has significantly lowered the barrier to 3D development.
For developers, an AI assistant is no longer just a code completion tool; it is more like a junior engineer who understands natural language descriptions of visual effects. It helps turn fleeting ideas into runnable, interactive prototypes, freeing developers to devote more energy to core business logic and creative design.
