Building a Rainy Night Convenience Store Scene in Three.js with AI-Assisted Coding

    This article describes a hands-on experiment in building an atmospheric rainy-night convenience store scene with Three.js and an AI programming tool. It covers lighting, rain particles, reflective wet ground, and store lighting, and it walks through the iterative fixes for proportions, performance, and detail. It closes with practical tips for working with AI coding tools.

    From Idea to Prototype: A Practical Look at Efficiency

    In the early stages of creative validation, developers often run into a frustrating problem. No matter how vivid the mental image is, if it cannot quickly become an interactive prototype, the idea is hard to evaluate and iterate on. Traditional Three.js scene development usually takes hours or even days of coding, which breaks the flow of creative work. With the natural language understanding and code generation capabilities of current AI programming tools, developers can turn a vague concept such as “a convenience store on a rainy night” directly into a runnable 3D scene framework.

    This article documents a hands-on experiment: using an AI programming tool to build an atmospheric rainy-night convenience store scene with Three.js. The implementation did not succeed in one pass. It involved several rounds of human-AI collaboration covering proportion adjustments, performance optimization, and detail refinement. Still, the overall experience showed that AI-assisted programming can shorten the distance from idea to finished work to a matter of minutes.

    1. Scene Goals and Technical Breakdown

    Before writing code, define the core visual elements of the scene and break them down into concrete Three.js implementation approaches.

    Visual Goal Technical Elements Difficulty
    Night base color Deep blue ambient light + low-intensity hemisphere light Low
    Realistic rain curtain Particle system + linear velocity field Medium
    Store glow Point light + rectangular area light to simulate a light box sign Medium
    Wet ground reflections Mirror reflection material or reflective plane High
    Urban atmosphere Fog + distant box-shaped building silhouettes Low

    2. Building the Rainy Night City, Step by Step

    1. Base Scene and Environment Setup

    The first step is building the basic structure of the scene. Create the main scene with THREE.Scene, set up a THREE.PerspectiveCamera as the main view, and initialize a WebGLRenderer. The night atmosphere starts with lighting:

    1. const scene = new THREE.Scene();
    2. scene.background = new THREE.Color(0x0a0e1a); // Deep navy night sky
    3. scene.fog = new THREE.FogExp2(0x0a0e1a, 0.008); // Exponential fog adds depth
    4. const ambientLight = new THREE.AmbientLight(0x404060, 0.6);
    5. const hemiLight = new THREE.HemisphereLight(0x1a2b4a, 0x2a1a0a, 0.4);
    6. scene.add(ambientLight, hemiLight);

    Fog is essential for a rainy night scene. It hides the simplified geometry in the distance and adds aerial perspective that makes the scene feel more realistic.

    2. Rain Effect: Particle System

    Rain has a strong effect on immersion. Use THREE.Points with a custom particle texture to generate a large number of raindrop particles within a defined volume above the scene:

    1. const rainCount = 8000;
    2. const rainGeometry = new THREE.BufferGeometry();
    3. const positions = new Float32Array(rainCount * 3);
    4. for (let i = 0; i < rainCount; i++) {
    5. positions[i * 3] = (Math.random() - 0.5) * 120;
    6. positions[i * 3 + 1] = Math.random() * 40;
    7. positions[i * 3 + 2] = (Math.random() - 0.5) * 120;
    8. }
    9. rainGeometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
    10. const rainMaterial = new THREE.PointsMaterial({
    11. color: 0xaaccff,
    12. size: 0.15,
    13. transparent: true,
    14. opacity: 0.6,
    15. blending: THREE.AdditiveBlending
    16. });
    17. const rain = new THREE.Points(rainGeometry, rainMaterial);
    18. scene.add(rain);

    In the animation loop, each frame moves the raindrops downward along the Y axis and resets any particle that falls below the boundary:

    1. const velocities = new Float32Array(rainCount);
    2. for (let i = 0; i < rainCount; i++) velocities[i] = 0.2 + Math.random() * 0.3;
    3. function animateRain() {
    4. const pos = rain.geometry.attributes.position.array;
    5. for (let i = 0; i < rainCount; i++) {
    6. pos[i * 3 + 1] -= velocities[i];
    7. if (pos[i * 3 + 1] < 0) {
    8. pos[i * 3 + 1] = 40;
    9. }
    10. }
    11. rain.geometry.attributes.position.needsUpdate = true;
    12. }

    3. Convenience Store Structure

    The store is built with a modular approach. The floor, walls, glass windows, and door are assembled one at a time, and the overall proportions are based on a real street-side convenience store. The key visual point is the interior light spilling outward, so the walls need large glass areas.

    • Use THREE.BoxGeometry to build the main frame, and use a light gray material to approximate a concrete texture.
    • Use THREE.MeshPhysicalMaterial with the transmission property enabled for the glass windows, to simulate light passing through.
    • Use THREE.PlaneGeometry with an emissive map for the store sign, and add an outer glow to make the store logo stand out.

    The sign lighting is the visual anchor of the rainy night store. Use THREE.RectAreaLight to simulate the interior illumination of the light box, so the light spreads evenly across the ground:

    1. const signLight = new THREE.RectAreaLight(0xffcc66, 2, 6, 1);
    2. signLight.position.set(0, 4.5, 1.5);
    3. scene.add(signLight);

    4. Wet Ground and Reflections

    The ground is the finishing touch for the rainy night atmosphere. A water ripple texture cannot respond dynamically to changing light, so this scene uses a real-time reflective surface, THREE.Reflector. To optimize performance, it does not reflect every object in the scene. It reflects only the key nodes, namely the lights and the main store structure.

    If the reflection library is not available, use MeshStandardMaterial with an envMap environment map to approximate the wet effect. Render the same scene into a cube texture, then apply it to the ground with low roughness.

    5. Background Details

    To keep the store from looking isolated, place low-polygon building blocks behind the store and across the street. Add a strip of traffic light trails, simulated with moving linear lights that trace car headlights, to reinforce the sense of being in a city.

    Building blocks can be generated in a loop:

    1. for (let i = 0; i < 20; i++) {
    2. const w = 3 + Math.random() * 8;
    3. const h = 5 + Math.random() * 15;
    4. const d = 3 + Math.random() * 6;
    5. const building = new THREE.Mesh(
    6. new THREE.BoxGeometry(w, h, d),
    7. buildingMaterial
    8. );
    9. building.position.set(
    10. (Math.random() - 0.5) * 80,
    11. h / 2,
    12. -20 - Math.random() * 30
    13. );
    14. scene.add(building);
    15. }

    3. Three Key Stages of Human-AI Collaborative Debugging

    Throughout the implementation, three types of problems best showed the value of the AI programming tool: proportion imbalance, performance bottlenecks, and missing details.

    1. Proportion Correction

    In the first generated scene, the convenience store was about 9 units tall, but the raindrop size and street width still used default values from an indoor scene, which threw the proportions off. By describing to the tool that “the store sign should be larger relative to the raindrops, and the street should be wide enough for two cars to pass side by side,” the developer got the tool to adjust the geometry dimensions at the parameter level. This shows that more precise descriptions produce more effective corrective code.

    2. Performance Optimization

    The initial particle count was set to 15,000, and real-time reflection was enabled for the full scene. On integrated graphics, the frame rate dropped below 25 fps. By asking the tool to halve the particle count and limit the reflection area to a small region near the ground plane, the frame rate recovered to above 50 fps. This also confirms a basic point: realism does not come from adding more features. It comes from meeting visual priorities at the lowest reasonable cost.

    3. Detail Completion

    The details of a rainy night go beyond raindrops. Breathing-like sign flicker, warm steam drifting from the store entrance, and the stretched reflections of distant headlights on the water all strengthen the narrative. Over several rounds of conversation, these “small details” were described to the tool one by one. The tool broke each one down into a matching timer or particle field and merged it into the main loop.

    4. Practical Lessons for Using AI Programming Tools More Effectively

    This experiment produced three direct lessons. They also apply to other developers who want to use AI to prototype 3D ideas.

    1. Describe spatial relationships. Do not just say “it should rain.” Explain where the rain falls, for example: “rain falls from above toward the area in front of the store, covering roughly 10 × 10 meters, with particles about 2 pixels in size.” The clearer the spatial description, the more accurate the generated coordinates and dimensions.
    2. Generate and verify in stages. Do not have the tool generate the entire scene at once. Move forward in four stages: environment, main subjects, effects, and interaction. Verify the visual result at each stage before building the next layer.
    3. Keep control of core per-frame logic. Lighting updates in the frame loop and particle velocity updates should be maintained by the developer. Let the tool generate static objects and material structures. This division of labor was the most efficient approach.

    5. Conclusion

    With AI programming tools, building an atmospheric, interactive third-person rainy night scene went from several hours of work to a multi-round conversation lasting about half an hour. This does not mean AI replaces the developer’s aesthetic judgment and technical decisions. Instead, it frees developers from repetitive geometry construction and coordinate calculation, so more of their effort can go into creative work and expression.

    The value of technology lies in shortening the cycle between discovering an error and fixing