From Writing Code to Building Spaces: A Practical Guide to 3D Spatial Generation with Multimodal LLMs

    This article explores how multimodal large language models extend programming beyond traditional code into what is often called "general-purpose programming," where visual scenes and spatial constraints are translated into executable code. Using the example of converting an empty 450-square-meter shell into a walkable restaurant, it explains why spatial generation is harder than web generation, outlines a four-step closed loop of constraint structuring, modular construction, visual self-checking, and delivery, and shares engineering recommendations for rendering, storage, monitoring, and automated validation.

    1. From Writing Web Pages to Building Spaces: The Boundary of General-Purpose Programming

    We used to judge a model’s programming ability by whether it could write clean business logic, read error messages, and locate bugs. Once a model can also understand visual input, that boundary expands considerably. Every frame in a video, the geometry and material parameters in a 3D scene, and even interaction logic and physical rules can be abstracted into executable code. This capability is commonly referred to as general-purpose programming.

    The technical idea is straightforward. Traditional code generation maps symbols to symbols, while general-purpose programming maps perception to symbols: the model first interprets a reference image or spatial constraint, then outputs structured code that can run. In practice, developers can describe a spatial intent in natural language, have the model generate scene code based on a general-purpose 3D rendering library, and validate the result through preview screenshots in a closed loop.

    2. Task Definition: Why Spatial Generation Is Harder Than Web Generation

    Consider converting an empty shell of about 450 square meters into a walkable dining space. The difficulty comes from four types of constraints:

    • Hard constraints cannot move: load-bearing columns, door and window openings, and main aisle width are structural conditions. Any coordinate offset breaks realism.
    • Multi-zone coordination: the storefront, main hall, private rooms, and dining area must share a consistent scale and circulation path. A locally reasonable layout is not necessarily reasonable as a whole.
    • Same-camera comparison: the system must switch between the bare shell and the finished space from the same viewpoint, where any scale error is directly magnified.
    • Credible details: close-up elements such as the direction of pot dividers, cup wall thickness, and soup surface position are almost impossible to catch by reading code alone.

    Together, these constraints lead to one conclusion: spatial generation is not a one-shot code output, but an iterative process of generate, render, observe, and correct.

    3. Practical Workflow: A Four-Step Closed Loop

    Step 1: Structure the Constraints

    First, convert natural-language requirements into a machine-verifiable checklist, such as main aisle width, column grid coordinates, floor height, door opening dimensions, and area ratios for each zone. A configuration object is recommended for unified management:

    1. const constraints = {
    2. axisWidth: 2.6,
    3. columns: [{ x: -4, z: 0 }, { x: 4, z: 0 }],
    4. zones: { lobby: 180, privateRoom: 120, dining: 150 }
    5. };

    Step 2: Build in Modules

    Split the scene into a structure layer, a surface layer, a furniture layer, and a detail layer, and generate and validate each layer independently. The structure layer handles the column grid and walls, the surface layer handles the storefront and grille, the furniture layer handles booth seating and dining tables, and the detail layer handles pots and cups. The benefit of layering is that errors can be localized, so a single clipping issue does not force a full rewrite.

    Step 3: Visual Self-Check

    Have the model invoke preview capabilities to take screenshots and check them item by item against the constraint checklist: whether the grille blocks the door opening, whether the divider is misaligned with the split between the red and white soup sections, and whether tables and chairs intrude into the main aisle. This step upgrades “reading code” to “viewing the rendered image” and is the key dividing line for spatial generation quality.

    Step 4: Delivery and Reuse

    The final output should be a complete page that supports multiple camera positions, free dragging, and viewpoint switching, while retaining a parameterized entry point. This makes it easier to reuse the same workflow for spaces with different areas and different business types.

    4. Engineering Recommendations

    • Use a container platform to host rendering and preview services to keep the environment consistent.
    • Use object storage to save scene assets and screenshot snapshots for version comparison.
    • Use logging services and monitoring alerts to track generation failure rates and rendering time.
    • Write constraint validation as automated test cases and include them in continuous integration.

    5. Conclusion

    The real value of general-purpose programming is not writing a few lines of code for us, but compiling spatial intent directly into a runnable scene. When a model can both write code reliably and understand rendered images, developers are no longer facing a black-box generator, but a spatial collaborator that can self-check and rework.