Building a Rainy Night City Scene in Three.js with AI-Assisted Development
This article explores how to use large language models and intelligent coding tools to build an interactive rainy-night convenience store scene with Three.js. It covers scene planning, iterative prompting, particle-based rain, lighting and reflections, manual refinement, and performance optimization for browser-based 3D applications.
Exploring AI-Assisted Three.js Development Through a Rainy Night City Scene
Traditional Web 3D development often requires strong graphics programming skills and significant effort to implement lighting, particle effects, and complete geometric environments. With the rapid development of large language models and intelligent coding tools, however, developers can now turn creative ideas into runnable, interactive 3D experiences much faster.
This article uses a rainy-night convenience store and small-town scene as an example to examine how AI can assist Three.js development, while also sharing practical lessons about technical implementation and performance optimization.
1. Breaking Down the Scene and Choosing the Technology
Before implementation, the concept of a “rainy night in a small city” should be divided into its key visual components. A typical scene includes the following elements:
- Environment and buildings: A simple street layout, a convenience store, signage, a road surface, and a dark background in the distance.
- Lighting and atmosphere: Warm interior lighting from the store, cool neon glow from the sign, and reflections or light patterns from streetlights on the wet pavement.
- Particle effects: Falling rain and splash ripples created when raindrops hit the ground.
Three.js is a natural choice for this type of browser-based project. It provides native WebGL rendering, good cross-platform support, and applications that can be accessed directly through a web browser for easy sharing and demonstration. Combined with modern frontend build tools, it also supports modular development.
2. AI-Assisted Development and Iterative Prompting
The main advantage of using intelligent coding tools for 3D development is rapid prototyping. Instead of writing the initialization code for the Scene, Camera, and Renderer from scratch, developers can describe the desired result in natural language and ask a large language model to generate the initial structure.
However, AI-generated code rarely produces the ideal result in a single attempt. Scale, performance, and visual details usually require multiple rounds of discussion and correction. The following staged prompting strategy is effective.
First Round: Establish the Structure
The first prompt should focus on the overall scene:
Use Three.js to create a rainy-night convenience store scene. Include a box-shaped building, a simple roof, a plane for the road, ambient light, directional light, and basic orbit controls.
Second Round: Add Visual Details
After the initial framework runs successfully, details can be introduced incrementally:
Add a glowing sign to the convenience store using
MeshBasicMaterialand emissive material properties. Add puddles to the road, using a material with high metalness and low roughness to simulate wet reflections.
Third Round: Add Dynamic Effects
The final stage can introduce motion and atmosphere:
Add a rain particle system using a
Pointsobject with tens of thousands of randomly falling particles. Adjust the particle color and opacity so that the rain remains visible against the dark background.
This progression—building the structure, adding visual elements, and then introducing dynamic effects—helps the model maintain context. It also reduces the risk of generating an excessively large and error-prone code block in one step.
3. Core Technical Challenges and Manual Intervention
Although AI can quickly generate application logic, many visual effects in 3D graphics depend on carefully tuned mathematical parameters. Developers still need to review and adjust the generated code.
3.1 Controlling Spatial Proportions and Geometry
When creating geometry, AI often relies on generic default values. This can produce unbalanced proportions, such as a door that is too small or a roof that is too flat. Developers should manually inspect parameters in BoxGeometry, PlaneGeometry, and related classes, then adjust them according to the scene’s coordinate system.
// A proportionally unbalanced version that AI might generateconst shopGeometry = new THREE.BoxGeometry(5, 2, 5);// A manually adjusted versionconst shopGeometry = new THREE.BoxGeometry(8, 4, 6);
3.2 Rain Particles and Performance Bottlenecks
When asked to increase rain density, an AI model may create tens of thousands of separate objects and update each one every frame. This can cause severe performance problems, especially on lower-end devices.
A better approach is to replace individual meshes with a particle system based on BufferGeometry and Points. This reduces CPU overhead and allows the GPU to handle particle rendering more efficiently. The system should also include reset logic or object pooling: when a raindrop falls below the ground, move it back to a higher position so that the rainfall can continue indefinitely.
3.3 Faking Wet-Surface Reflections
Physically accurate water reflections are expensive to calculate. An AI-generated implementation may attempt to use real-time planar reflections, which can consume substantial rendering resources.
A lighter alternative is to guide the implementation toward a visual approximation. For example, a blurred nighttime texture can be applied to the road material and combined with a high-intensity environment map to simulate glossy wet pavement at a much lower performance cost.
4. Performance Optimization and User Experience
Once the main features are complete, optimization becomes essential to maintaining a smooth experience. Whether the scene is being tested locally or later deployed through a container platform or object storage service, rendering performance should remain a priority.
4.1 Adaptive Rendering Resolution
Limit the pixel ratio to prevent excessive rendering costs on high-resolution displays:
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
This avoids unnecessary GPU workload on 4K and other high-density screens.
4.2 Shadow Optimization
Shadows help create depth in a rainy-night scene, but enabling PCFSoftShadowMap increases rendering overhead. One way to balance quality and performance is to reduce the shadow camera’s view volume so that it covers only the area around the convenience store. The shadow map resolution can also be lowered when appropriate.
4.3 Post-Processing
A post-processing effect such as UnrealBloomPass can strengthen the nighttime atmosphere and make neon lights appear more dramatic. Bloom resolution and threshold values should be controlled carefully, however. Excessive bloom can make the entire image look washed out and gray.
5. Conclusion and Future Outlook
This project demonstrates that intelligent coding tools have moved beyond experimentation and become practical assistants for Web 3D development. They are particularly useful for turning an initial idea into a working, interactive prototype, significantly reducing the cost of validating a creative concept.
AI still cannot fully replace a developer’s graphics programming experience. Developers need to remain involved in adjusting model proportions, restructuring particle systems for performance, and tuning lighting and materials to achieve the desired visual result.
As large language models become better at understanding domain-specific code, and as they integrate more closely with computing and storage services such as Baidu AI Cloud, more automated workflows for producing high-quality 3D applications may emerge. For developers, learning how to guide and collaborate with large language models will become an increasingly important productivity skill.
