Three.js and AI-Assisted Development: Building a 3D Rainy Night City Scene
Learn how to use AI coding tools and Three.js to turn a rainy-night convenience store concept into an interactive browser-based 3D scene. This guide covers scene planning, structured prompts, geometry and materials, rain particles, iterative visual refinement, and performance optimization.
Web3D is becoming increasingly common in front-end development, but turning an imaginative concept—such as a cyberpunk convenience store on a rainy night—into an interactive browser-based scene still involves a substantial technical learning curve and many implementation details.
Large language models (LLMs) and AI coding tools offer a practical way to streamline that process. Using a small-town convenience store on a rainy night as an example, this guide explores how to combine AI-assisted development with Three.js to move from concept to a working scene, then refine its appearance and performance.
1. Plan the Technology Stack and Scene
Three.js provides the foundation for this project. As a JavaScript library that abstracts much of WebGL, it makes 3D graphics programming more accessible. An AI coding tool acts as a development assistant, interpreting natural-language requirements and generating the corresponding Three.js code.
Before generating code, break the scene into its main components:
- Base environment: A nighttime street, puddles with reflections, and a skybox.
- Main building: A convenience store with an illuminated sign, glass doors, and shelves.
- Lighting: Dim ambient light, with most illumination coming from point lights inside the store, neon signage, and distant streetlights.
- Animated effects: Continuously falling rain particles and flickering neon lights.
This breakdown gives the AI a clearer specification than a single broad request to create a rainy-night scene.
2. Build the Core Scene with AI Assistance
Generating a 3D scene requires more than entering “create a convenience store on a rainy night.” Structured prompts help guide the tool toward usable code, one part of the scene at a time.
Initialize the Scene and Camera
Start with the Three.js essentials: a scene, camera, renderer, and camera controls. Specify the relevant parameters when describing the requirements to the coding tool.
The following example illustrates the scene, camera, and renderer setup:
// Basic scene initializationconst scene = new THREE.Scene();scene.fog = new THREE.FogExp2(0x0a0a0a, 0.02); // Add fog to create a sense of depthconst camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);camera.position.set(0, 5, 15); // Set an elevated view of the street cornerconst renderer = new THREE.WebGLRenderer({ antialias: true });renderer.setSize(window.innerWidth, window.innerHeight);renderer.shadowMap.enabled = true; // Enable shadowsdocument.body.appendChild(renderer.domElement);
Combine Geometry and Materials
A detailed modeling and model-loading workflow can be cumbersome for an initial prototype. AI can help generate a low-poly convenience store assembled from basic shapes such as BoxGeometry and PlaneGeometry.
Describe the intended material properties, including glass transparency and metalness, to guide the tool toward suitable MeshStandardMaterial or MeshPhysicalMaterial settings.
For example, the store’s glass doors should allow the illuminated interior to remain visible. Ask the tool to create a physical material with appropriate roughness and transmission, then pair it with an environment map to improve realism.
Implement the Rain Particle System
Rain is central to the scene’s atmosphere. Implementing a particle system manually involves buffer geometry, particle positions, and repeated vertex updates. An AI coding tool can generate this logic from a focused description:
Create a rain particle system that covers the scene. The particles should fall downward at a constant speed and reset to their starting height after reaching the ground.
The following example demonstrates the basic approach:
// Basic rain particle systemconst rainGeometry = new THREE.BufferGeometry();const rainCount = 15000;const positions = new Float32Array(rainCount * 3);for (let i = 0; i < rainCount * 3; i += 3) {positions[i] = Math.random() * 400 - 200;positions[i + 1] = Math.random() * 160;positions[i + 2] = Math.random() * 400 - 200;}rainGeometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));const rainMaterial = new THREE.PointsMaterial({color: 0xaaaaaa,size: 0.1,transparent: true});const rain = new THREE.Points(rainGeometry, rainMaterial);scene.add(rain);// Update Y coordinates in the animation loop to make the rain fallfunction updateRain() {const pos = rainGeometry.attributes.position.array;for (let i = 0; i < rainCount * 3; i += 3) {pos[i + 1] -= 0.5; // Downward movement per updateif (pos[i + 1] < 0) {pos[i + 1] = 160; // Reset the particle height}}rainGeometry.attributes.position.needsUpdate = true;}
3. Refine the Scene Through Iteration
AI coding tools can accelerate development, but the first result will not always match the intended design. Proportions, performance, and visual details usually require several rounds of feedback and adjustment.
Correct Proportions and Spatial Relationships
The initial scene might contain an oversized store or misplaced streetlights. Rather than searching through the code for every coordinate, provide a specific correction:
The convenience store is too wide and makes the street look narrow. Scale the building to 0.6 times its current size and move the streetlight back by 5 units.
This gives the tool concrete instructions for updating the relevant scale and position properties. Review the resulting scene to confirm that the changes produce the intended layout.
Improve Visual Detail
A building assembled from basic geometry can look rigid or unfinished. To give the store sign a neon appearance, ask the tool to add emissive properties to its material and random flickering behavior in the animation loop.
Puddle reflections also contribute strongly to the rainy-night atmosphere. The Three.js Reflector component can provide planar reflections without requiring a more elaborate reflection setup.
4. Optimize Performance and Prepare for Deployment
As the scene becomes more detailed, tens of thousands of rain particles and reflection effects can put pressure on the frame rate. AI-generated code often prioritizes functionality, so developers still need to guide performance improvements.
Optimize the Particle System and Reduce Detail
Rendering large numbers of particles with PointsMaterial still carries a cost. Ask the AI to replace the rain material with a custom ShaderMaterial and calculate the falling displacement in the shader. This reduces the CPU work involved in updating particle positions.
For mobile devices, adjust the particle count based on device performance. Halving rainCount is one way to reduce the workload.
Bake Lighting and Limit Shadows
Real-time shadows can be expensive. In this scene, concentrate shadow coverage around the convenience store rather than across the entire environment.
Guide the tool to adjust the relevant light’s shadow.camera near and far clipping planes and its shadow-map resolution through shadow.mapSize.width and shadow.mapSize.height.
For static building elements, pre-baked lightmaps can replace some real-time shadow work.
Check the Render Loop and Resource Cleanup
Verify that the generated code uses requestAnimationFrame rather than setInterval for the animation loop.
When the scene is destroyed or its component is unmounted, call renderer.dispose() and dispose of geometries and materials as well. Resource cleanup is essential to avoiding memory leaks.
5. Conclusion
Combining AI coding tools with Three.js changes how developers can approach browser-based 3D graphics. The tools can help turn a scene concept into a working, interactive prototype, while developers retain responsibility for proportions, visual quality, and performance.
The most effective workflow is collaborative: describe the scene in structured steps, inspect the generated result, give concrete feedback, and guide optimization where needed.
This approach shifts more effort away from repetitive API calls and low-level implementation details and toward scene design, interaction, and artistic expression. As code-generation models continue to improve, the path from an imagined scene to an interactive 3D experience may become increasingly direct.
