AI-Assisted Coding for a Rainy-Night 3D Town Scene in the Browser

    This article presents a practical, staged workflow for using AI coding assistance to build a browser-based rainy-night town and convenience store 3D scene. It covers acceptance criteria, scene layering, real-world scale, rain particle pooling, lighting and materials, performance budgeting, and iteration, with pseudocode and checklists for turning a visual idea into a runnable, tunable prototype.

    Building a “rainy-night town + convenience store” 3D scene in the browser may look like a purely visual creative task, but in practice it involves scene modeling, lighting and materials, particle systems, interaction controls, rendering performance, and engineering maintainability. The value of AI-assisted coding is not “generate a complete finished piece from one sentence.” It is the ability to turn an idea into a runnable first version quickly, then approach the target through multiple rounds of dialogue, runtime validation, and performance tuning. Using a rainy-night convenience store town as an example, this article abstracts a reusable practice method.

    1. Define the Goal: What Counts as “Runnable and Playable”

    Before generating code, define acceptance criteria. Otherwise, it is easy to end up in a state where “the image looks acceptable, but it cannot be interacted with, performance is unstable, and details are out of control.” Split the goal into four layers:

    1. Runnable: The page loads reliably, and the scene, camera, render loop, and basic interaction work correctly.
    2. Interactive: Users can rotate the view, zoom, and move. When needed, they can trigger door opening, lighting changes, or rain-intensity adjustment.
    3. Atmospheric: The rainy-night feel comes from fog, low-color-temperature ambient light, warm convenience store light, wet-ground reflections, rain particles, and neon accents, not simply from piling up models.
    4. Within a Performance Budget: Maintain a usable frame rate on ordinary laptops and mobile devices. Avoid endlessly increasing light sources, shadows, and particle counts.

    These four layers also map to the prompt structure used with an AI coding assistant: first describe the runtime environment, then the scene composition, then the visual style, and finally the performance constraints and acceptance conditions.

    2. Collaboration Workflow: Generate in Stages, Not All at Once

    AI-assisted coding works well with staged delivery. A recommended workflow is:

    • Stage 1: Build the skeleton. Generate an empty scene, perspective camera, renderer, basic lighting, ground, and simple box buildings, and make sure it runs.
    • Stage 2: Fix proportions. Add convenience store dimensions, road width, camera height, and fog attenuation range. Solve the “proportions look wrong” problem first.
    • Stage 3: Add atmosphere. Add rain particles, wet ground materials, warm convenience store light, light boxes, and a sense of reflection.
    • Stage 4: Tune performance. Reduce draw calls, merge static objects, limit shadow-casting lights, use object pools for rain, and adapt pixel ratio.
    • Stage 5: Add interaction and fault tolerance. Add view controls, window resize handling, and low-performance degradation strategies.

    Each dialogue should include the previous stage’s runtime result and a specific problem, such as “the current rain particle count is too high and the frame rate has dropped,” “the convenience store is too large,” or “the fog is too dense and distant buildings disappear.” This kind of feedback is easier to turn into actionable changes than “make it look better.”

    3. Scene Structure: Organize the Rainy-Night Town in Layers

    Split the scene into the following layers:

    1. Environment layer: sky color, fog, ground, roads, and distant building silhouettes.
    2. Subject layer: convenience store building, doors and windows, shelf silhouettes, light boxes, and entrance canopy.
    3. Atmosphere layer: rain particles, ground puddles, light glow, and warm light spill from the convenience store.
    4. Interaction layer: camera controls, light switches, rain-intensity adjustment, and performance monitoring.

    A generic pseudocode structure:

    1. scene = createScene()
    2. camera = createPerspectiveCamera({fov: 60, near: 0.1, far: 200})
    3. renderer = createRenderer({antialias: true, powerPreference: "high-performance"})
    4. scene.fog = createFog({color: "#0b1020", near: 8, far: 60})
    5. scene.add(createGround({size: 120, wetness: 0.8}))
    6. scene.add(createRoad({width: 10, length: 100}))
    7. scene.add(createConvenienceStore({width: 6, depth: 8, height: 3.2}))
    8. scene.add(createRainSystem({count: 12000, area: 80, height: 20}))
    9. onFrame(dt => {
    10. updateCameraControls(dt)
    11. rain.update(dt)
    12. renderer.render(scene, camera)
    13. })

    The key here is not the specific interfaces but the layered approach: the environment layer handles the overall mood, the subject layer handles recognition, the atmosphere layer handles the rainy-night texture, and the interaction layer handles playability. With this separation, it becomes easier to replace materials, reduce particle counts, or adjust the camera later.

    4. Scale and Detail: Rainy-Night Atmosphere Starts with Correct Proportions

    Many 3D scenes fail to look convincing not because the materials are insufficiently complex, but because the proportions are distorted. The convenience store door height, canopy height, road width, camera height, and fog distance must form a reasonable relationship. Start with real-world scale: door height around 2.2 meters, floor height around 3 meters, convenience store frontage 6 to 8 meters, road width 8 to 12 meters, and initial camera height 1.6 to 2.2 meters. The fog near and far ranges should also match the scene scale; otherwise, the result can look “too gray nearby and completely black in the distance.”

    For details, the high-recognition elements of a rainy-night convenience store include warm interior light, cool ambient light, water streaks on glass, puddles at the entrance, edge glow from light boxes, streaking raindrops, and distant building silhouettes. Do not pile on every detail at once. Prioritize by recognition: first ensure the convenience store outline and warm light, then add puddle reflections, and finally add rain and glow.

    5. Rain Particles: Object Pools Are More Stable Than Frequent Allocation

    Rain particles are numerous and short-lived, so an object pool is appropriate. After each raindrop hits the ground, reset its position and speed instead of repeatedly creating and destroying objects. A generic example:

    1. class RainPool {
    2. constructor(capacity, area, height) {
    3. this.particles = []
    4. for (let i = 0; i < capacity; i++) {
    5. this.particles.push(this.resetParticle({}, area, height))
    6. }
    7. }
    8. resetParticle(p, area, height) {
    9. p.x = (Math.random() - 0.5) * area
    10. p.z = (Math.random() - 0.5) * area
    11. p.y = Math.random() * height
    12. p.speed = 8 + Math.random() * 6
    13. return p
    14. }
    15. update(dt, area, height) {
    16. for (const p of this.particles) {
    17. p.y -= p.speed * dt
    18. if (p.y < 0) {
    19. this.resetParticle(p, area, height)
    20. }
    21. }
    22. }
    23. }

    If the frame rate is insufficient, first reduce the particle count, shrink the rain area, or lower the rain update frequency, rather than blindly adding post-processing effects. On mobile, use fewer particles, shorter rain streaks, and a lower pixel ratio.

    6. Lighting and Materials: Create Depth with Few Light Sources

    Avoid using too many real-time shadow-casting lights in a rainy-night scene. Use one main directional light to simulate environmental direction, a small number of warm point lights or emissive materials inside the convenience store, and self-lit outlines for distant buildings. Wet ground can be expressed by increasing roughness variation, layering puddle textures, and strengthening highlights rather than using full mirror reflection. Glass can use slight transparency, water streaks, and warm interior light shining through.

    For performance, limit shadow map size and shadow camera range, and let only the convenience store entrance and nearby ground receive shadows. Distant buildings can disable shadows and use fog and low-contrast silhouettes to create depth.

    7. Performance Budget: Monitor First, Then Optimize

    Add monitoring for frame rate, draw calls, particle count, and pixel ratio early in development. Common optimizations include:

    • Merge or instance static buildings to reduce draw calls.
    • Use object pools and batch updates for rain.
    • Use level of detail or simplified models for distant objects.
    • Limit the number of real-time shadow-casting lights.
    • Adapt pixel ratio based on device capability.
    • Pause or reduce update frequency when the window is not visible.
    • Disable glow, reduce particle count, and lower fog sampling on low-performance devices.

    These optimizations do not all need to be implemented at the beginning, but they should have a place in the performance budget. AI-assisted coding can quickly generate monitoring panels and degradation logic, but developers still need to tune parameters based on actual runtime results.

    8. Acceptance and Iteration: Turn “Feel” into Checkable Items

    Final acceptance should cover whether the page loads reliably, whether camera interaction is smooth, whether the convenience store is recognizable enough, whether the rainy-night atmosphere works, whether the frame rate is acceptable on ordinary devices, whether window resizing works correctly, and whether low-performance degradation takes effect. Change only one class of issue per iteration: for example, adjust proportions only in one round, rain and fog in the next, and lighting and performance in the following round. This maintains the efficiency of AI-assisted coding while preventing the scene from becoming increasingly chaotic.

    Overall, AI-assisted coding is well suited to turning 3D ideas such as a rainy-night town into a runnable prototype quickly, but it is not a one-shot “magic” delivery. Proportions, performance, and details still require developers to complete the work through runtime validation, clear feedback, and continuous tuning. Breaking an idea into acceptance-oriented engineering steps is the key to making it truly run in the browser.