Building a Rainy-Night 3D Town with an AI Coding Assistant: An Engineering Workflow
This article explains how to use an AI coding assistant to turn a rainy-night town concept into a runnable, interactive 3D application. It covers requirement abstraction and acceptance criteria, layered architecture, scale and modularity, materials and lighting, rain effects, interaction and render-loop design, performance budgets, collaboration methods, quality assurance, and deployment. The focus is on treating code generation as part of a small software engineering workflow rather than a one-shot output, and on using the assistant for drafting, debugging, refactoring, and option comparison while keeping engineering judgment in control.
1. The Real Problem: Building a Runnable System, Not Generating a Code Snippet
Turning a rainy-night town in your head into a runnable, interactive 3D work with an AI coding assistant looks like a linear process: describe the requirement, generate code, run it, and inspect the result. In practice, it is closer to a small software engineering effort. It involves scene abstraction, resource organization, the rendering pipeline, interaction logic, performance budgeting, quality acceptance, and iterative collaboration. An AI coding assistant can significantly reduce the cost of moving from an idea to a minimal runnable prototype, but developers still need to communicate, verify, and adjust repeatedly to check whether proportions are accurate, performance meets the bar, and details create atmosphere.
A more reasonable approach is therefore not to expect a one-shot result, but to split the goal into a verifiable engineering loop: first get rendering and interaction working in a minimal scene, then gradually add materials, lighting, rain effects, and detail. Set clear acceptance criteria for each stage, such as whether the camera view is reasonable, the scene proportion is credible, the frame rate is stable, the experience runs on mobile, and resource loading is controllable. In this process, the AI coding assistant handles code drafting, refactoring suggestions, debugging support, and option comparison, while final quality is still backed by the developer’s engineering judgment.
2. Requirement Abstraction and Acceptance Criteria
Before starting, break the “rainy-night town” into executable requirements. Define at least four dimensions:
- Visual goals: low-light night scene, wet ground, warm light from a convenience store, cool street lighting, rain streaks and fog, and distant light attenuation.
- Interaction goals: camera roaming, view constraints, hotspot inspection, and lightweight interactions such as light toggling or rain-intensity adjustment.
- Performance goals: target devices, resolution, minimum frame rate, initial load time, and memory ceiling.
- Maintainability goals: separate scene data from rendering logic, make assets replaceable, and make parameters configurable for later iteration.
These goals should be written as verifiable items, not vague descriptions. For example, “good rainy-night atmosphere” should become “the ground has wet reflections, rain streaks are visible in the foreground without blocking the subject, fog adds depth to the background, and the overall tone is cool while the convenience-store area forms a warm focal point.” Only when acceptance criteria are clear can code generated by an AI coding assistant be evaluated and corrected more easily.
3. Layered Architecture: Decoupling Scene Data, Rendering Logic, and Interaction
A maintainable 3D town should not pile all logic into one file. A layered structure is recommended:
- Scene description layer: uses structured data to describe objects, transforms, material references, and interaction markers.
- Resource layer: manages geometry, textures, audio, and configuration in a unified way.
- Rendering layer: handles the camera, lighting, materials, post-processing, and the render loop.
- Interaction layer: handles input, camera control, hotspots, and state toggles.
- Performance and diagnostics layer: tracks frame rate, draw calls, resource counts, and load times.
An illustrative scene description looks like this:
scene = {unit: "meter",camera: { position: [0, 1.6, 8], target: [0, 1.2, 0] },objects: [{ type: "road", transform: { position: [0, 0, 0], scale: [20, 0.1, 30] } },{ type: "store", transform: { position: [2, 0, -4], rotation: [0, 0.2, 0] } },{ type: "streetLight", transform: { position: [-3, 3, -2] } },{ type: "rainVolume", transform: { position: [0, 4, 0], scale: [20, 8, 30] } }]}
The benefit is that adjusting scene proportions does not require changing rendering code, adding objects does not require copying logic, and performance optimization can batch-process and cull by object category.
4. Proportion, Scale, and Scene Modularity
The most common problem exposed in 3D scenes is distorted proportion. Camera height, doorway size, street width, light height, and raindrop scale must be consistent. Use meters as the logical unit: first determine camera eye height and convenience-store facade height, then derive street and building scale. If the camera eye height is too high, the scene looks like a model diorama; if it is too low, it creates a sense of pressure. A convenience store that is too large loses its everyday feel, while one that is too small struggles to become a visual focal point.
Scene modularity is equally important. Roads, curbs, store facades, awnings, light poles, puddles, and rain curtains should be reusable modules that form a block through transforms and parameter combinations. For repeated elements such as streetlights, railings, raindrops, and ground ripples, prefer instancing or batched drawing to prevent object count growth from causing draw calls to spike. Proportion and modularity are not mere art details; they are the foundation for later performance and maintainability.
5. Materials and Lighting: Layering, Not Brightness, Drives the Rainy-Night Mood
The key to a rainy-night scene is not making the image brighter but establishing cool-warm contrast and layered reflections. Inside the convenience store, use a warmer local light source to create a visual focal point; the street can use cooler ambient light and streetlight illumination. Ground materials should convey wetness: lower roughness and stronger reflections, but reflections should not be too strong or the surface will look like a mirror. Puddles can be implemented through local materials or masks, with irregular transitions at the edges.
For lighting, control the number of light sources and shadow cost. Not all lights need to cast shadows. The main foreground light can keep shadows, while distant lights can be approximated with emissive materials and glow. Fog can enhance depth, but avoid making the foreground gray; use distance fog or height fog to control the falloff range. Tone mapping and exposure should be managed consistently to avoid local overexposure. At this stage, an AI coding assistant is best suited to generating parameterized material configurations and lighting debug panels, but final parameters must be calibrated against the actual rendered image.
6. Rain Effects and Atmosphere: Balancing Particles, Shaders, and Performance
Rain effects usually consist of rain streaks, ground ripples, fog, and water-surface reflections. Rain streaks should not use many independent objects; use a particle system or shader to draw them in screen space or within a volume. An illustrative rain-streak shader pseudocode looks like this:
float rainStreak(vec2 uv, float time) {float column = fract(sin(floor(uv.x * 80.0)) * 43758.5453);float fall = fract(uv.y * 6.0 - time * 2.0);float mask = step(0.96, column);float fade = smoothstep(0.0, 0.2, fall) * smoothstep(1.0, 0.8, fall);return mask * fade;}
These effects require control over density, speed, and opacity. Too dense, and rain streaks occlude the subject and increase blending cost; too sparse, and the atmosphere is lost. Ground ripples can be implemented with a limited number of ring patches or shader-based perturbation, restricted to the near-camera area. Fog, rain sound, and distant light flicker can enhance immersion, but audio and animation should support degradation and disabling.
7. Interaction Design and the Render Loop
Interaction should be designed around exploration, not piling on complex features. Camera roaming needs pitch and movement limits to avoid clipping and motion sickness; hotspot inspection should provide clear feedback; light or rain-intensity adjustment should use lightweight state management. The render loop should keep a single responsibility: update input, update animations, update rain effects, render the frame, and schedule the next frame. Pseudocode:
function frame(now) {updateCamera(inputState);updateRain(now);updateSceneAnimations(now);render(scene, camera);scheduleNext(frame);}
Interaction state should be separated from scene data so input logic does not directly modify render objects. For mobile, also consider touch input, pixel ratio limits, and battery consumption.
8. Performance Budget and Optimization Checklist
Performance optimization should start with an upfront budget, not with fixes after stuttering appears. Use the following checklist:
- Control draw calls: merge static geometry and use instancing for repeated objects.
- Control texture size: allocate resolution according to screen contribution and use lower-resolution textures for distant objects.
- Use levels of detail: simplify distant geometry and preserve detail in the foreground.
- Limit shadows: reduce the number of shadow-casting lights and narrow shadow ranges.
- Use dynamic resolution: lower rendering resolution when frame rate drops, then raise it again after stability returns.
- Use culling and visibility: frustum culling, distance culling, and occlusion culling.
- Degrade rain effects: reduce particle count, opacity layers, and ripple count.
- Manage resource loading: load only necessary assets on the initial screen and lazy-load the rest.
Add frame rate, draw call, triangle count, and memory statistics panels early in development. An AI coding assistant can help generate statistics code and optimization suggestions, but validation must happen on real devices. Performance optimization often affects visual detail, so it must be weighed together with visual acceptance criteria.
9. Working Effectively with an AI Coding Assistant
To involve an AI coding assistant effectively, prompts should include five elements: goal, constraints, input, output, and acceptance. For example: the goal is to implement a rainy street prototype using browser-based 3D APIs; constraints are a single runnable file, a target frame rate not below a certain threshold, and a fixed camera height; input is the scene description structure; output is rendering and interaction code; acceptance is that the initial screen loads, the camera can roam, and rain effects can be toggled. During iteration, do not ask for too much at once; add capabilities incrementally around a minimal runnable version.
Developers should always review code for resource disposal, event unbinding, duplicate render-loop registration, material sharing, exception handling, and mobile compatibility. An AI coding assistant is good for quickly producing drafts and comparison options, but it should not replace human judgment about proportion, performance, and detail. The idea that a result is not always achieved in one step is the normal state of 3D project iteration.
10. Quality Assurance and Deployment
After the scene is complete, perform cross-browser and multi-device testing to check initial loading, resource failure fallback, degradation on low-performance devices, and interaction usability. Static assets can be accelerated through general content delivery capabilities, while logs and error monitoring help locate loading failures and runtime exceptions. The final delivery should include configuration instructions, an asset replacement guide, and performance acceptance records, so the work is not only a demo but also an engineering asset that can continue to be iterated.
Conclusion
An AI coding assistant can quickly turn an idea such as a rainy-night town into a runnable prototype, but high-quality results depend on engineering breakdown, clear acceptance criteria, continuous debugging, and performance governance. Proportion, lighting, rain effects, and interaction all require repeated communication and calibration. By managing scene data, rendering logic, interaction state, and performance budgets in layers, a single inspiration attempt can become a reusable, extensible, and deliverable 3D application practice.
