Building Interactive 3D Spaces with LLM Code Generation: A "Pan-Coding" Walkthrough

    This article explores "pan-coding," an approach where large language models generate any formally expressible artifact—from 3D scene geometry and lighting to interaction logic—rather than just text-based code. Through a hands-on case study, it walks through converting a 450 m² bare commercial space into a fully navigable, interactive 3D restaurant scene with immutable structural constraints, dual bare/finished states, camera presets, and a screenshot-based visual feedback loop. The article distills the workflow into key engineering practices: constraint-first modeling, modular generation, shared skeleton architecture with toggleable decoration layers, and visual self-checking.

    From Writing Code to “Pan-Coding”: Expanding the Capability Boundary

    Traditionally, asking a large language model to write code means producing text-based outputs: web pages, scripts, API logic. A more ambitious idea has recently emerged in the industry—“pan-coding.” The core premise: anything that can be formally expressed can be described in code, and therefore generated by a model with coding capability. This includes:

    • Every frame of a video (which can be described by per-frame rendering code);
    • The geometry, materials, and lighting of a 3D scene (which can be described by scene-graph code);
    • Interaction logic and physical rules (which can be described by state machines and constraint code).

    Code generation alone is not sufficient for these tasks. The success of a 3D scene is ultimately judged by its visual result: a slightly offset coordinate, a wrong scale, or intersecting meshes are nearly impossible to detect by reading code alone. That’s why the combination of “code generation + visual understanding” becomes essential: the model writes code, takes a screenshot preview of the rendered result, inspects it, and revises—forming a closed loop of generate → render → observe → correct.

    The following complete walkthrough demonstrates how this methodology plays out in practice.

    The Task: Turning a 450 m² Bare Space into a Navigable 3D Interior

    The task is defined as follows: given the floor-plan constraints of a 450 m² bare commercial space, build a complete, walkable 3D restaurant scene from scratch that satisfies these hard requirements:

    1. Locked spatial constraints: load-bearing columns, door and window openings, and the main corridor width must not be moved;
    2. Multi-zone layout: the plan must cover the storefront, main hall, and private dining rooms;
    3. State switching: the same camera position must support toggling between “bare shell” and “finished” states;
    4. Interactivity: support multiple camera presets and free drag-based roaming.

    The difficulty of this task is not modeling any single object, but global consistency. When the same camera position switches back and forth between two states, any coordinate or scale deviation is exposed at the instant of switching. Therefore the entire solution must first establish a rigorous spatial coordinate system and constraint layer, and only then add decorative layers on top.

    Engineering Breakdown: Five Key Steps

    1. Establish the Coordinate System and Immutable Constraint Layer

    The first step is to translate the floor-plan constraints into fixed data in code. Load-bearing columns, doors, windows, and corridors exist as immutable objects; all subsequent layouts must reference them:

    1. // Immutable constraints: column positions (illustrative)
    2. const columns = [
    3. { x: -9, z: -6 }, { x: -9, z: 6 },
    4. { x: 9, z: -6 }, { x: 9, z: 6 },
    5. ];
    6. const MAIN_CORRIDOR_WIDTH = 2.6; // Main corridor width along the axis

    The benefit: no matter how the layout code evolves, constraint validation logic can run independently. The moment a piece of furniture intrudes into the main corridor or intersects a column, the code raises an alert—no need to wait for a human to spot it in the render.

    2. Build the Space in Modules

    The scene is divided into four modules—storefront, main hall, private rooms, and dining-table props—each encapsulated as an independent function and composed through a unified spatial registry. The value of modularization: the model can iterate module by module; when something goes wrong, the blast radius is limited, and locating the problematic area from screenshots is much easier.

    3. Dual-State Design: “Bare” vs. “Finished”

    The most robust approach for switching states at the same camera position is not maintaining two separate scenes, but maintaining one shared skeleton: walls, columns, door and window openings always exist. The “finished” state simply overlays decoration layers (ceilings, booth seating, wooden slats, tables, chairs, lighting) onto the skeleton; switching is just toggling visibility:

    1. function toggleState(decorated) {
    2. decorGroup.visible = decorated; // Decoration layer
    3. rawGroup.visible = !decorated; // Bare-shell marker layer
    4. renderer.render(scene, camera);
    5. }

    Because the skeleton is fully shared, there is no structural jump when switching. Visually, it reads as “this space got renovated,” not “this is a different scene.”

    4. The Visual Self-Check Loop: Catching Problems Code Can’t Reveal

    This is the step that most clearly differentiates pan-coding from ordinary code generation. Several classes of issues are extremely hard to expose at the code level:

    • Wooden slats blocking a private room’s doorway, killing the visual permeability of the entrance;
    • The divider of a divided hot pot misaligned with the red and white broth areas;
    • Teacups at close range having no wall thickness, looking like flat stickers.

    The solution is to have the model invoke a rendering tool to take screenshots after generating code, look at the image, and then go back and fix the code. For example, when checking a dining table up close, visually verify the alignment of the divider with the broth colors and the 3D presence of the cup walls, then fine-tune the geometric parameters. This “the image is the ground truth” iteration upgrades 3D generation from blind code writing to feedback-driven creation.

    5. Interaction Layer: Camera Presets and Free Roaming

    Finally, attach camera controls to the scene: four presets—street view, main hall, private room, and close-up dining table—plus free drag rotation and zooming. Camera switches use interpolated animation of position and orientation for a coherent feel; free dragging lets reviewers orbit around any angle to check for mesh intersections.

    Results and Lessons Learned

    In the finished scene, starting from the street view: the signage, entrance porch, and the interior depth visible through the glass connect naturally. Inside the main hall, the four load-bearing columns and the 2.6 m main corridor stay exactly in place, with tables and booth seating unfolding along the sides. Moving toward the back, private-room doorways, wooden slats, and circulation lines align, so the interior dining table is visible directly from the entrance. Zooming the camera to a close-up of the table, details such as the divided hot pot’s divider and the teacup wall thickness also hold up.

    Three general lessons can be distilled from this case:

    1. Constraints first: Solidify immutable conditions into a code-level data layer, then let generation operate within those constraints. This is the prerequisite for results that “look real.”
    2. Visual feedback is not optional: For any task whose output is a picture, you must establish a screenshot-based self-check loop. Pure code review cannot catch spatial errors.
    3. Shared skeleton + toggleable decoration layers: For scenes requiring multiple state comparisons, one skeleton plus show/hide layers is far more stable than maintaining multiple separate scenes.

    Conclusion

    The significance of “pan-coding” is that a large model’s coding ability is evolving from “producing text” to “producing perceivable worlds.” When a model can both write code and see the rendered result of that code, production workflows for spatial design, interactive prototypes, and even video content can be reorganized. For developers, mastering this engineering method—“constraint modeling + modular generation + visual self-checking”—matters more than chasing any particular tool: it is the general path to turning LLM capability into reliable output.