Building a Three.js Rainy Night Street Scene with AI Coding Assistants

    This article explores how AI coding assistants can accelerate the development of a real-time 3D rainy night street scene using Three.js. It covers scene construction, core rendering technologies such as particle systems and wet road reflections, performance optimization strategies, and a comparative analysis of traditional versus AI-assisted development workflows. Readers will gain insights into leveraging AI for rapid prototyping and creative development in 3D graphics.

    Introduction: Bridging the Gap Between Creative Inspiration and Runnable Work

    In the realm of digital content creation, transforming a mental image into an interactive 3D scene typically involves multiple stages: modeling, coding, debugging, and optimization. In a traditional development workflow, building a rainy city street scene with a basic atmospheric feel could take days or even weeks. However, with the rapid advancement of intelligent coding tools, this process is being significantly compressed—developers can now dedicate more energy to creative conception and artistic expression rather than getting bogged down in repetitive code debugging.

    Using a “rainy night convenience store” as a practical example, this article provides a comprehensive review of how to build a real-time 3D scene with both visual appeal and interactive performance in the browser, powered by an AI coding assistant. This is not just a simple tutorial, but an in-depth analysis of the new “AI-assisted creative development” workflow.

    Scene Construction: From Spatial Layout to Visual Storytelling

    1. Core Framework and Physical Environment

    Building any 3D scene should begin with a clear plan for the spatial structure. For the rainy night convenience store scene, we need to consider the following core layers:

    • Ground and Road System: Use a large, dark-colored plane to simulate wet asphalt, enhanced with roughness maps and reflective materials to capture the post-rain texture.
    • Main Building Module: As the visual center of the scene, the convenience store needs a prominent storefront sign, transparent glass windows, and warm internal lighting.
    • Surrounding Environment Elements: Adjacent building outlines, sparsely distributed streetlights, and distant building skylines work together to create depth and perspective in the cityscape.

    When using an AI coding assistant, you first need to clearly describe the spatial scale and visual tone of the scene. For instance: “Generate a city street segment 50 units wide and 30 units deep. The ground needs a certain reflective effect, and the convenience store should be located in the middle of the north side of the road.” The assistant will then generate the foundational scene structure code, including the scene, camera, renderer, and basic object layout.

    2. Exploratory Construction: From Vague Requirements to Precise Expression

    A common misconception in actual development is expecting the AI to generate perfect code in a single attempt. In this practice, we went through multiple rounds of iterative dialogue to gradually refine the scene. The initial generation might only contain rough geometric shapes, lacking fine materials and lighting layers. An effective optimization approach is a “progressive detailing” strategy:

    • Geometric Level: Add details like eaves, steps, and outdoor AC units to buildings to enhance realism.
    • Material Level: Utilize environment maps and physical materials (e.g., MeshStandardMaterial) to replace basic materials, achieving complex optical effects like glass translucency, metallic reflections, and wet road surfaces.
    • Lighting System: Differentiate between global ambient light, point lights (streetlights/windows), and area lights (store signs) to create a visual rhythm with cool and warm contrasts.

    The value of the AI assistant lies in “rapid trial and error.” When we input instructions like “add puddle reflections to the road” or “adjust the streetlights to warm yellow with a halo,” the assistant quickly provides the corresponding code snippets, allowing for immediate visual verification.

    Core Technical Analysis: Procedural Generation and Real-time Rendering

    1. Rain Particle System

    Rain is the core of the scene’s dynamic atmosphere. Achieving a realistic rainfall effect typically involves a particle system:

    1. // Create a sample rain particle system
    2. const rainGeo = new THREE.BufferGeometry();
    3. const rainCount = 15000;
    4. const positions = new Float32Array(rainCount * 3);
    5. for (let i = 0; i < rainCount * 3; i += 3) {
    6. positions[i] = Math.random() * 100 - 50;
    7. positions[i + 1] = Math.random() * 30;
    8. positions[i + 2] = Math.random() * 60 - 30;
    9. }
    10. rainGeo.setAttribute('position', new THREE.BufferAttribute(positions, 3));
    11. const rainMaterial = new THREE.PointsMaterial({
    12. color: 0xaaaaaa,
    13. size: 0.15,
    14. transparent: true,
    15. opacity: 0.6
    16. });
    17. const rain = new THREE.Points(rainGeo, rainMaterial);
    18. scene.add(rain);
    19. // Update particle y-axis position in the animation loop to simulate falling

    The AI assistant can further optimize this, for instance, by adding diagonal movement trajectories to simulate wind, or adjusting particle size and transparency based on their distance from the camera.

    2. Road Reflections and Water Surface Effects

    The reflection on a wet road is the finishing touch for the rainy night atmosphere. The main implementation approaches include:

    • Reflection Maps (CubeCamera): Use real-time reflections for the ground material. This is performance-intensive but highly realistic.
    • Roughness Mapping: Set the ground roughness to a low value, combined with a high-resolution environment map, to achieve a mirror-like reflection effect.
    • Puddle Planes + Dynamic Disturbance: Overlay plane geometries in low-lying areas, using semi-transparent materials and normal maps to simulate water ripples.

    After weighing the options, we combined roughness mapping with local reflection planes in our scene, achieving a visually satisfying result while maintaining a good frame rate.

    3. Lighting Layers and Post-Processing

    The lighting design for a rainy night follows the principle of “highlighting warm, bright colors against a dark base”:

    • The base lighting is a deep blue ambient light, with intensity kept below 0.2.
    • The convenience store windows and signs use warm yellow (approx. 3000K color temperature) point lights, projecting a noticeable light decay range to simulate realistic illumination.
    • Streetlights act as secondary light sources, primarily cool white, with halo textures added to enhance volumetric feel.

    The renderer is configured with PostProcessing effects, including Bloom and Vignette, which naturally focuses the user’s gaze on the store area and strengthens the narrative of the scene.

    Performance Optimization: Balancing Visual Effects and Resource Consumption

    1. Geometry Simplification and Merging

    The initial scene generation often results in an excessive polygon count. Optimization methods include:

    • Removing invisible faces (e.g., building backsides).
    • Merging geometries with the same material into a single mesh to reduce draw calls.
    • Adopting LOD (Level of Detail) technology to switch model complexity based on viewing distance.

    2. Light Baking and Dynamic Lighting Balance

    For static lighting that does not need real-time changes, light maps can be used to pre-bake lighting information, drastically reducing runtime computational load. For dynamic objects (like moving characters or vehicles), simple point lights are used for approximate illumination.

    3. Particle System Performance Tuning

    The number of particles directly impacts rendering performance. You can enable the frustumCulled property in the particle material so that particles outside the camera frustum are not rendered. Additionally, using texture atlases (sprite sheets) instead of individual particle textures can reduce texture switching overhead.

    Development Comparison: Traditional vs. AI-Assisted

    To objectively evaluate the value of the AI assistant, we conducted parallel testing: developing the same rainy night scene using traditional hand-written code versus AI-assisted methods.

    Development Phase Traditional Time AI-Assisted Time
    Scene setup & basic geometry 3 hours 40 minutes
    Material system & texture coordination 2.5 hours 1 hour
    Particle effects & animation scripts 4 hours 1.5 hours
    Performance tuning & bug fixing 3 hours 1.5 hours
    Total 12.5 hours 4 hours 20 minutes

    The root of this efficiency boost is not that the assistant does all the work, but that it greatly accelerates the “search-attempt-verify” loop. In traditional development, developers must frequently consult documentation, search for lighting formulas, or particle control algorithms. In the AI-assisted mode, simply describing the requirement in natural language yields a runnable code block.

    It must also be noted that AI assistants are not omnipotent. In areas involving complex physical interaction logic (e.g., rainwater flowing along object surfaces) or writing custom shaders, the accuracy of the generated code drops significantly. Developers still need a solid foundation in computer graphics to make corrections.

    Conclusion and Outlook: A New Paradigm of Human-Machine Collaboration

    Through the construction of this rainy night convenience store scene, we validated the outstanding value of AI coding assistants in rapid creative prototyping, 3D scene building, and visual effect experimentation. It does not replace the developer; rather, it acts as an experienced, highly responsive “pair programming partner.”

    The ideal workflow should involve humans defining “what to do” and “what it should look like,” while intelligent tools handle “how to implement” and “how to optimize.” In this model, individual creativity is no longer limited by memorizing programming language details or API proficiency, but rather depends on the boundaries of imagination and the height of aesthetic judgment.

    As the capabilities of intelligent programming models continue to iterate, we have reason to believe that the barrier to 3D content creation will further lower. More creative digital spaces will be produced more rapidly, injecting new vitality into fields like virtual reality, digital twins, and online education. For developers, mastering how to collaborate efficiently with AI will be key to embracing this wave of transformation.