Building a 3D Rainy Night City Scene Using an AI Coding Assistant
This article explores how to leverage an AI coding assistant to efficiently build a 3D rainy night city scene prototype. It introduces a spec-driven, iterative development methodology, covering scene skeleton creation, layered visual effects, performance budgeting, interaction design, and acceptance criteria. The piece emphasizes that while AI accelerates coding, human engineering judgment and strict validation remain essential for a stable and playable result.
Building a 3D Rainy Night City Scene Using an AI Coding Assistant
1. Background: The Real Barrier in 3D Prototyping is Beyond “Writing Code”
A rainy night convenience store city is a classic 3D scene prototype: it consists of building blocks, roads, storefronts, signs, streetlights, awnings, puddles, raindrops, fog effects, reflections, and camera interactions. For experienced developers, none of these elements are complex in isolation. However, when combined into a runnable scene, issues related to proportion, lighting, materials, performance, and detail control often surface simultaneously.
The true value of an AI coding assistant is not “generating a complete final product in one go,” but rather quickly translating the scene description in a developer’s mind into a runnable skeleton, and then progressively filling in proportions, performance, and details through multiple rounds of communication. It acts more like a fast-executing collaborative developer: capable of generating code, explaining errors, and proposing structural suggestions, while engineering judgment, acceptance criteria, and performance boundaries still require human oversight. Setting the goal as “getting the final product from a single prompt” often results in code with a loose structure, uncontrollable dependencies, and unpredictable performance. Conversely, aiming for “spec-driven, incremental iteration, and acceptable in each round” is more likely to yield stable results.
2. Overall Solution: Spec-Driven over Vague Descriptions
It is recommended to split the project into six layers: Requirements, Scene Description, Rendering, Interaction, Performance, and Acceptance. The Requirements layer defines “what is needed”; the Scene Description layer translates requirements into configurable parameters; the Rendering layer handles the scene graph, materials, lighting, and post-processing; the Interaction layer manages camera, touch, and hotspots; the Performance layer defines budgets and downgrade strategies; the Acceptance layer uses checklists to verify visual, functional, and performance metrics.
A key practice here is “spec first.” Instead of merely telling the AI assistant to “make a rainy night convenience store,” you should provide units, coordinates, size ranges, camera height, target platform, performance budget, and prohibitions. For example:
const sceneSpec = {units: "meter",camera: { fov: 60, near: 0.1, far: 200, eye: [0, 1.6, 8] },store: { width: 6, height: 3, depth: 5, facadeColor: "#f2f2f2", signEmissive: "#ffcc66" },street: { width: 8, sidewalk: 2, wetness: 0.7 },rain: { layers: 3, particlesPerLayer: 4000, fallSpeed: 12 },lighting: { ambient: 0.15, streetLightColor: "#9bb7ff", storeLightColor: "#ffd28a" },budget: { maxLights: 8, maxDrawCalls: 300, targetFps: 50 }};
This configuration does not rely on any specific product capability but serves as a universal scene description method. The AI assistant can generate scene construction functions based on this config, while the developer reviews whether the parameters are reasonable. Proportion issues usually stem from inconsistent units, incorrect camera heights, or mismatched scales between buildings and roads; performance issues typically arise from too many dynamic lights, transparent material sorting, real-time reflections, and particle overdraw; detail issues come from a lack of hierarchy in signs, awnings, puddles, shelves, and indoor warm lighting. Writing all these into the spec can significantly reduce ineffective rework.
3. Prompt Organization: Making the Assistant Output “Acceptable Increments”
The recommended prompt structure includes: Role, Goal, Technical Constraints, Input/Output, Acceptance Criteria, and Prohibitions. Example:
Role: Senior 3D Frontend Engineer.Goal: Generate the first runnable skeleton for the rainy night convenience store city.Technical Constraints: Use browser 3D rendering standards; units in meters; camera height 1.6 meters; no unaudited dependencies.Output: File structure, key code, run instructions, acceptance checklist.Acceptance: Page loads; camera movable; ground, road, store blocks, and basic lighting visible; no console errors.Prohibitions: Hardcoded keys; excessive post-processing; unaudited third-party assets.
Round one only builds the skeleton: ground, roads, store blocks, camera, and basic lighting. Round two adds rainy night visuals: fog, cool ambient light, streetlights, sign emissive materials, and wet ground materials. Round three adds rain effects and reflections: layered rain screens, puddles, and low-cost reflection alternatives. Round four focuses on performance optimization: merging geometry, instancing, controlling light count, and reducing shadow and post-processing overhead. Round five handles interaction and acceptance: mobile touch, hotspots, load failure fallback, and downgrade strategies. Each round requires the assistant to provide a change log and an acceptance checklist to avoid situations where “it looks changed but cannot be verified.”
4. Scene Skeleton: Ensure Runnability Before Atmosphere
The scene skeleton should prioritize correct coordinates, proportions, and camera relationships. The convenience store can initially be represented by a cuboid, with its facade facing the street, the sign placed above the facade, the awning slightly protruding, and streetlights arranged along the street. At the code level, abstract functions can be used for organization, preventing you from getting bogged down in material details right from the start:
function buildScene(spec) {const scene = createScene();scene.fog = createFog(spec.scene.fogColor, spec.scene.fogDensity);const camera = createCamera(spec.camera);const renderer = createRenderer({ antialias: true, alpha: false });addGround(scene, spec.street);addRoad(scene, spec.street);addStore(scene, spec.store);addStreetLights(scene, spec.lighting, spec.budget.maxLights);addRain(scene, spec.rain);const controls = createCameraControls(camera, renderer.domElement);animate(() => {updateRain(scene, deltaTime);controls.update();renderer.render(scene, camera);});}
The focus of this skeleton is not the details of a specific API, but its structure: the separation of configuration, construction, render loop, and update logic. AI assistants are well-suited for generating such skeletons, but developers must check whether units are consistent, whether the camera clips through objects, whether the number of lights exceeds the budget, whether raindrops follow the camera, and whether transparent materials cause sorting issues.
5. Rainy Night Visuals: Layered Implementation of Lighting, Materials, Rain, and Reflection
A rainy night atmosphere is not simply achieved by darkening the scene. It is recommended to implement it in layers: the first layer is a low-intensity ambient light and cool directional light to establish the overall tone; the second layer is the warm light inside the store and the self-emissive signs to create a cool-warm contrast; the third layer is cone-shaped streetlights or local light spots to enhance street depth; the fourth layer is fog and low contrast to compress distant details; the fifth layer is wet ground materials, using low roughness, normal map perturbation, and environment reflection approximation to represent water reflections; the sixth layer is raindrop particles, using layering, instancing, and frustum culling to control overhead.
Wet ground is a typical balancing point between performance and visual effect. Real-time screen space reflections (SSR) look good but are expensive. Alternatives like environment map approximations, local puddle patches, and low-resolution reflection proxies can be used instead. Raindrop particles should not be increased infinitely; their density should be adjusted dynamically based on screen space and camera distance. Transparent rain screens require attention to render order and overdraw to avoid fill-rate bottlenecks caused by stacking a large number of semi-transparent faces. Sign emissive effects can use emissive materials or post-processing bloom, but post-processing effects should provide a downgrade toggle.
6. Performance Optimization: Bake Budgets into Acceptance Checklists
Performance traps in rainy night scenes mainly involve dynamic lights, shadows, transparent particles, real-time reflections, and post-processing. It is recommended to define budgets early in the project: maximum dynamic lights, draw calls, triangle count, texture memory, target frame rate, and first-screen load time. Example budgets should act as project parameters rather than fixed conclusions.
Optimization techniques include: merging static geometry; using instancing for repeated streetlights, raindrops, and road piles; using low Level of Detail (LOD) for distant buildings; controlling shadow map resolution and shadow-casting objects; reducing transparent material overlap; moving raindrop updates to the GPU or batching updates; providing low, medium, and high tiers for post-processing effects; and reducing particle counts and reflection quality on mobile. During acceptance, look beyond average frame rate to also consider frame rate stability, load time, memory usage, and console errors. AI assistants can help generate performance checklists, but final numbers must be tested on target devices.
7. Interaction and Acceptance: Playability Comes from Verifiable Details
For the interaction layer, it is recommended to implement basic camera controls first, then add mobile touch, click hotspots, and scene switching. The convenience store can feature low-cost interactions like sign toggles, rain shelter areas under awnings, and flickering streetlights, but each interaction should have clear acceptance criteria: whether clicks hit the target, whether state is recoverable, whether it works on mobile, and whether it impacts performance. The acceptance checklist should cover four categories: visual, functional, performance, and compatibility. Visual acceptance includes proportions, cool-warm contrast, rainy night layering, and material consistency; functional acceptance includes camera, touch, hotspots, and load failure fallback; performance acceptance includes frame rate, draw calls, and memory; compatibility acceptance includes different resolutions, different browsers, and downgrade strategies for low-performance devices.
8. Engineering Boundaries: AI Accelerates Iteration but Doesn’t Replace Judgment
When using an AI coding assistant, code review and dependency audits must be retained. Generated code may contain unnecessary dependencies, incorrect API usage, uncontrollable resource references, or performance risks. Hardcoded keys should be prohibited, external resource sources restricted, and generated code subjected to static analysis and runtime validation. For 3D scenes, particular attention should be paid to coordinate units, camera near/far clipping planes, light count, transparent sorting, and object creation within animation loops. AI coding assistants are best suited for “skeleton generation, repetitive code, error explanation, configuration sorting, and acceptance checklist generation,” while scene proportions, performance budgets, visual direction, and final quality should remain the developer’s responsibility. Combining “rapid generation” with “strict acceptance” is the true way to turn the rainy night city in your mind into a runnable, playable, and sustainably iterable work.
