Multimodal Code Generation in Practice: Building and Validating 3D Spatial Models
This article examines a hands-on test of multimodal code generation for 3D spatial modeling: constructing a roughly 450-square-meter restaurant interior from scratch with rendering scripts, then switching the same camera between the bare shell and the finished layout. It explains why spatial tasks demand both code reasoning and visual feedback, breaks the workflow into five reusable steps (explicit hard constraints, layered construction, screenshot-driven self-checking, same-camera consistency checks, and interactive delivery), and provides an acceptance checklist, common failure modes, and engineering recommendations. Readers will learn how to turn "looks correct" into verifiable, repeatable delivery for 3D scenes and interactive prototypes.
1. Background: Why “Can Write Code” Is Not “Can Deliver Space”
Over the past year, the focus of code generation has shifted from “can it autocomplete a function” to “can it deliver end to end.” As models take on entire pages, full scripts, and even 3D scenes, the evaluation criteria change too: it is no longer enough for a snippet to run. The output must satisfy hard constraints, remain interactive, and hold up under frame-by-frame inspection.
The original experiment is representative. Given a bare space of about 450 square meters, the task was to build a freely walkable restaurant from scratch using 3D rendering scripts, with support for instant switching between the “shell” and “finished” states from the same camera position. The difficulty is not the amount of code but the density of constraints:
- Structural constraints are fixed: load-bearing columns, door and window openings, and main corridor width are hard boundaries. Any coordinate drift breaks realism.
- Zoning constraints are coupled: the facade, main hall, private rooms, and dining area must all hold at once, and circulation must stay continuous.
- Comparison constraints require consistency: before/after views from the same camera mean the camera, scale, and origin must be reused exactly. Clipping and misalignment are magnified instantly.
- Detail constraints depend on vision: partition orientation, cup wall thickness, and soup surface zoning are nearly impossible to catch by reading code alone.
This shows that spatial generation needs a closed loop of “code reasoning + visual feedback,” not a single long-text output.
2. Capability Abstraction: From Writing Pages to “Pan-Code” Expression
The industry summarizes this capability as “pan-code expression”: video frames, 3D geometry and materials, and interaction and physics rules can all be mapped to executable code structures. Its value is a unified medium of expression—anything that can be parameterized can be generated, reused, and audited.
In a 3D scene, this expression typically falls into three layers:
- Structure layer: walls, columns, door and window openings, and floor elevations define the spatial skeleton.
- Layout layer: furniture, booths, partitions, and equipment define functional zones and circulation.
- Presentation layer: materials, lighting, soup surfaces, and cup bodies define realism.
Adding multimodal visual capability lets the model “look at” its own output after generation, using the rendered result as a feedback signal for iterative correction. This is the part that pure text reasoning struggles to cover.
3. Method Breakdown: A Reusable Five-Step Pipeline
3.1 Constraints First: Write Invariants as an Explicit List
Structure the hard constraints before generation so the model does not “optimize away” key structures. Example:
hard constraints:grid: 0.1morigin: intersection of main corridor axis and street-facing edgekeep: [load-bearing columns x4, door opening, clear corridor width 2.6m]camera: fixed camera list (facade/hall/private room/dining)mode:compare: ["shell", "finished"] # share the same camera and origin
The key point: units, origin, retained items, and the camera list must be declared explicitly. Otherwise, same-camera comparison will inevitably fail.
3.2 Modular Construction: Skeleton First, Then Fill
Generate in the order “structure - layout - presentation,” with each layer previewable on its own. Pseudocode:
scene = Scene(origin="axis_entry", unit="m")scene.add_structure(columns=4, openings=["door","window"], corridor_width=2.6)scene.add_layout(zones=["facade","hall","private_room","dining"])scene.add_material(style="wood_grille+glass")scene.lock_camera(["street","hall","room","table"])
The point of layering is that errors can be traced to a specific layer instead of being hunted inside mixed code.
3.3 Visual Self-Check: A Screenshot-Driven Correction Loop
Immediately after generation, render screenshots from the fixed cameras and compare item by item. Typical issues include: a grille blocking a door opening, partitions misaligned with the soup surface, tables and chairs intruding into the corridor, and missing thickness in close-ups. The correction loop can be abstracted as:
render -> capture(fixed_camera) -> diff/checklist -> patch -> render
The key is “fixed camera + checklist,” which makes every round of correction verifiable.
3.4 Consistency Check: Same-Camera Before/After Comparison
The shell and the finished version must share camera parameters and origin, or the comparison is meaningless. Acceptance focuses on three points: whether column positions have shifted, whether the clear corridor width has been encroached on, and whether sightlines through the door openings stay connected.
3.5 Delivery Format: An Interactive Page, Not a Static Artifact
The final output should support multiple camera views and free dragging, which requires decoupling the interaction layer from the scene layer: camera control, mode switching, and the render loop each stay independent, making future extension easier.
4. Acceptance Checklist: Turning “Looks Right” into “Decidable”
- Structure: column, opening, and corridor coordinates match the list item by item.
- Layout: zones are complete, circulation is unobstructed, and no furniture crosses boundaries.
- Comparison: switching cameras shows no jumps, and scale stays unified.
- Details: partition orientation is correct, cups have wall thickness, and the liquid surface zoning is clear.
- Interaction: camera switching, dragging, and mode switching all run stably.
5. Common Failure Modes and How to Avoid Them
- Constraints get “beautified”: the model tends to sacrifice the corridor for aesthetics, so lock constraints explicitly.
- Scale drift: inconsistent units cause overall scaling, so fix the unit and origin.
- Visual blind spots: code can look reasonable but clip after rendering, so screenshot verification is mandatory.
- One-shot output: very long generation makes errors hard to localize, so iterate in layers.
6. Engineering Recommendations
For enterprise adoption, this pipeline can connect to general cloud capabilities: use object storage to keep multi-round render snapshots, a message queue to decouple generation from validation tasks, a container platform to host headless rendering, and logging and monitoring with alerts to track failure rates and correction rounds. Baidu AI Cloud can provide support in these general categories, making “generate - validate - deliver” an observable, rollback-capable pipeline.
7. Conclusion
The spatial modeling test shows that the dividing line for next-generation code generation is closed-loop capability: whether hard constraints can be written clearly, whether generation can be layered, and whether visual feedback can drive self-correction. With this method, teams can bring 3D scenes, interactive prototypes, and complex pages into the same delivery system and significantly reduce rework costs.
