A Practical Guide to Building a Three.js Rainy Night Scene with an AI Coding Assistant
This article explores how an AI coding assistant can support the development of a Three.js rainy night convenience-store scene. It covers requirement definition, stepwise delivery, iteration feedback, wet-ground reflection, raindrop particles, neon glow, and performance budgeting, and summarizes practical lessons for AI-assisted 3D development.
A Practical Guide to Building a Three.js Rainy Night Scene with an AI Coding Assistant
1. Project Background: Why Use a “Rainy Night Scene” as a Practice Case
In 3D visualization, the “rainy night convenience store” is a highly suitable comprehensive practice scene. It looks simple, but it actually covers many core topics in graphics development: geometry modeling, materials and lighting, particle systems, post-processing, camera animation, and performance optimization. The rainy-night atmosphere depends on the coordination of multiple visual elements, including wet-ground reflections, neon lights, and raindrop particles. If any one of these elements is handled poorly, the overall effect suffers noticeably.
In the past, completing such a scene independently required a solid understanding of graphics and familiarity with the API details of a 3D rendering library. Today, with an intelligent coding assistant, developers who are less familiar with graphics programming can describe requirements in natural language and quickly generate runnable scene code. This article uses that case as the main thread and reviews the complete development workflow and the pitfalls encountered along the way.
2. Overall Workflow: From Idea to Runnable Result
2.1 Define Requirements and Set the Tone First
Before starting, clarify the core atmosphere and elements of the scene. For a rainy night convenience store, the requirements can be broken down as follows:
- Main building: a convenience store with a large glass display window, with warm yellow light glowing from inside;
- Street environment: wet asphalt that reflects the lights;
- Atmosphere elements: continuous falling rain, an occasionally flickering neon sign, and halos around streetlights;
- Camera presentation: a slow dolly-in or orbiting camera animation that creates a cinematic feel.
Giving this list to the intelligent coding assistant as the first-round prompt works much better than a vague request such as “help me make a rainy night scene.” The more specific the requirements, the higher the chance that the generated code will match expectations.
2.2 Deliver Step by Step and Avoid Generating a Huge Codebase at Once
An important practical lesson is: do not expect one generation to get everything right in a single pass. Proportion issues, performance bottlenecks, and missing details are normal and require repeated communication and iteration. The recommended order is as follows:
- Build the skeleton: first generate the basic scene initialization code (scene, camera, renderer, lights) and confirm that it renders correctly;
- Model the main subjects: gradually add the convenience store building and the street, repeatedly calibrating object proportions and positions;
- Render the atmosphere: add raindrop particles, fog effects, and ground reflection;
- Add animation and interaction: add camera movement, neon flickering, and mouse interaction;
- Tune performance: handle performance issues uniformly at the end.
The following is an illustrative scene initialization code snippet:
const scene = new THREE.Scene();scene.fog = new THREE.FogExp2(0x0a0a12, 0.02);const camera = new THREE.PerspectiveCamera(45, innerWidth / innerHeight, 0.1, 100);camera.position.set(8, 3, 12);const renderer = new THREE.WebGLRenderer({ antialias: true });renderer.setPixelRatio(Math.min(devicePixelRatio, 2));renderer.toneMapping = THREE.ACESFilmicToneMapping;document.body.appendChild(renderer.domElement);
2.3 Key Techniques for Iterative Communication
When collaborating with a coding assistant, the quality of feedback directly determines iteration efficiency:
- Describe the phenomenon rather than guessing the cause: for example, “the window light does not reach the ground” is easier to locate than “the lighting code has a bug”;
- Point out the specific direction of proportion deviation: quantified descriptions such as “the convenience store is too large relative to the street; the building height should be about 1.5 times the road width” are very effective;
- Solve one problem at a time: raising multiple issues at once can easily cause the assistant to change the wrong place;
- Ask for explanations of key parameters: have the assistant explain the meaning of parameters such as fog density and particle count so they can be adjusted independently later.
3. Core Technical Points
3.1 Wet-Ground Reflection
The soul of the rainy-night atmosphere lies in ground reflection. There are several implementation options: a simple approach is to use a high-gloss standard material with an environment map; a more realistic approach is to use planar reflection so that the ground reflects the scene content in real time. The former has lower performance overhead and suits most scenes; the latter offers stronger visual impact but requires attention to mobile performance.
3.2 Raindrop Particle System
Raindrops can be simulated with a large number of thin line segments or small planes, combined with vertical falling and a slight tilt angle. Key optimization points:
- Use a single geometry (InstancedMesh or BufferGeometry) for batch rendering to avoid a large number of independent objects;
- Adjust the particle count dynamically according to device performance: desktop devices can handle thousands, while mobile devices should use fewer;
- Reset raindrops to the top after they reach “ground height” to form a loop.
3.3 Neon Lights and Glow
The neon effect is achieved through emissive materials combined with bloom post-processing. The flicker animation can use a noise function to control emissive intensity, simulating the effect of poor contact in a light tube:
const flicker = Math.sin(t * 8) > -0.6 ? 1.0 : 0.3;neonMaterial.emissiveIntensity = baseIntensity * flicker;
3.4 Performance Budget Awareness
As a scene becomes more complex, performance issues tend to appear at once. In practice, the metrics to watch include draw call count, triangle count, and per-frame rendering time. Common optimization methods include merging geometries, reducing the number of real-time lights (replacing them with baking or fake lighting), and limiting the pixel ratio cap. It is advisable to introduce a performance panel early in development rather than waiting until the scene stutters.
4. Lessons Learned and Further Thoughts
Looking back at the entire development process, several general conclusions can be drawn:
- AI coding assistants are good at “0 to 0.8”: they can quickly build a structurally complete first version with a reasonable visual effect, freeing developers from repetitive labor; but the final 0.2 of detail polishing—proportion fine-tuning, atmosphere control, and performance trade-offs—still depends on human aesthetic judgment.
- Prompt engineering is requirements engineering: translating a vague “feeling” into quantifiable descriptions (color, proportion, motion style) is the core capability for efficient human-AI collaboration.
- Iterative delivery is better than one-shot generation: small steps with validation at each step can significantly reduce rework costs.
This workflow applies not only to 3D visual demonstrations but can also be transferred to data dashboards, product prototypes, interactive holograms, and other scenarios. For developers, the important thing is not a specific tool, but mastering the collaboration methodology of “creative decomposition—stepwise generation—professional feedback.” When ideas in your mind can become truly runnable and playable works within minutes, the lowering of technical barriers will bring liberation of creativity.
