Benchmarking LLMs on Spatial Reasoning: A Code-Based 3D Scene Evaluation Method

    Spatial reasoning is one of the hardest capabilities to measure in code-generating LLMs. This article explains why spatial reasoning serves as an effective probe of true structural understanding, presents a framework that decomposes it into six observable sub-skills, and details a practical evaluation pipeline built on scripted 3D scene creation—with layered task sets, controlled variables, automated geometric assertions, failure-mode classification, and engineering practices for continuous regression testing.

    Benchmarking LLMs on Spatial Reasoning: A Code-Based 3D Scene Evaluation Method

    Why Spatial Reasoning Is the “Deep Water” of Code Generation

    In code generation benchmarks, tasks like function completion, algorithm problems, and CRUD APIs have become heavily saturated—differences between models have compressed into a very narrow range. The capability that is both hardest to differentiate and hardest to fake is spatial reasoning: the model must mentally construct a 3D structure purely from textual descriptions, without any visual feedback, then translate that structure into correct coordinates, rotations, and hierarchical relationships.

    These tasks share three characteristics:

    1. Impossible to guess: a small geometric error immediately breaks the rendered result—there is no “close enough” gray zone.
    2. Strongly coupled constraints: position, orientation, scale, occlusion, materials, and lighting all interact, so one mistake cascades.
    3. Automatically verifiable: outputs are executable scripts and geometric data, which can be judged with assertions rather than subjective human scoring.

    Spatial reasoning is therefore an effective probe of whether a model truly “understands structure” rather than merely “memorized a template.”

    Breaking Down the Capability: What to Evaluate

    It’s best to decompose “spatial reasoning” into six independently observable sub-capabilities rather than issuing one vague score:

    • Coordinate system and axis understanding: correctly distinguishing right-handed vs. left-handed systems, Up-axis direction, and default units and scale.
    • Relative positioning and nesting: expressing “attached,” “stacked,” and “symmetric” relationships via parent-child hierarchies, instead of hard-coding absolute coordinates for every object.
    • Rotation and orientation: appropriate handling of Euler angle order, gimbal lock, and quaternions; semantic correctness of orientation (e.g., “handle facing outward”).
    • Occlusion and depth consistency: whether front/back relationships stay consistent across multiple viewpoints; no self-intersections, interpenetration, or floating objects.
    • Parameterization and constraint satisfaction: satisfying all stated numeric constraints such as “radius 2, height 5, spacing no less than 0.5.”
    • Maintainability: using variables, loops, and function abstractions for repeated structures rather than hundreds of lines of hard-coded values.

    Why Move from Declarative Rendering to Scripted Modeling

    Early evaluation setups often used declarative 3D rendering libraries in the browser, but they quickly hit a ceiling:

    • Declarative APIs sit at a high abstraction level; models just stack components, and real coordinate and transform reasoning never gets exposed.
    • They lack industrial-grade modeling semantics (Boolean operations, modifiers, constraints, material nodes), limiting expressiveness for complex shapes.
    • Scenes are hard to feed into automated verification pipelines—judgment depends on eyeballing screenshots.

    Switching to the scripting interface of professional 3D creation software significantly improves signal quality. A script is a “developer of the model’s thought process”: its understanding of spatial relationships is directly exposed as variables, transformation matrices, and loop parameters, and the output can be programmatically parsed and asserted against.

    Evaluation Design

    4.1 Layered Task Set

    Level Example Task Primary Skills Tested
    L1 Generate a single rounded box above the origin Axes, scale
    L2 Three cubes evenly spaced along the X axis Relative positioning, loop abstraction
    L3 Spiral staircase (given radius, turns, number of steps) Parameterization, accumulated rotation
    L4 Wall with cutout holes Boolean operations, occlusion
    L5 Robot arm hierarchy with end effector oriented toward a target point Nested transforms, orientation solving
    L6 Symmetric furniture made of 20 parts with distinct materials Composite constraints, maintainability

    4.2 Controlling Variables

    Use the same prompt, the same runtime version, the same random seed, and the same number of samples (n ≥ 5, reporting pass rate). Temperature and maximum output length should be identical across evaluated models. Participants should be anonymized as “Model A/B/C,” recording only capabilities and failure types without brand attribution.

    4.3 Prompt Template (Example)

    1. Task: construct {target object} in a 3D scene.
    2. Constraints:
    3. 1. Use {Up axis} as the vertical direction, units in meters;
    4. 2. Must satisfy: {numeric constraint list};
    5. 3. Generate repeated structures with loops or functions; hard-coded coordinates are forbidden;
    6. 4. Output a single executable script, including necessary scene cleanup and camera setup.

    Automated Verification: Scoring Without Eyes

    1. # Pseudocode: geometric assertion checks
    2. scene = run_script(candidate_script, timeout=120)
    3. # 1. Executability
    4. assert scene.exit_code == 0
    5. # 2. Bounding box and scale
    6. bbox = scene.world_bbox()
    7. assert abs(bbox.height - 5.0) < 1e-3
    8. # 3. Count and naming
    9. assert len(scene.meshes_named("step")) == 24
    10. # 4. No interpenetration (contact tolerance allowed)
    11. assert scene.self_intersection_ratio() < 0.01
    12. # 5. Symmetry
    13. assert scene.mirror_symmetry_error(axis="X") < 0.02
    14. # 6. Multi-view depth consistency
    15. for cam in scene.cameras:
    16. assert scene.render_ok(cam)

    Metrics fall into four categories: executability rate (whether the script runs), constraint satisfaction rate (proportion of numeric conditions met), geometric health (self-intersections, floating objects, flipped normals), and structural quality (degree of abstraction and parameterization). The first two are objective; the latter two can be semi-automated.

    Failure Mode Classification (More Valuable Than a Total Score)

    In practice, the most common errors cluster tightly:

    1. Axis confusion: using Z or Y for the vertical direction inconsistently with the runtime default, making the whole object “lie flat.”
    2. Wrong rotation order: incorrect Euler angle ordering causes twisting or breaks in spiral structures.
    3. Absolute coordinates instead of relative relationships: the first object is correct, but subsequent placements are guesses that misalign as counts grow.
    4. Scale runaway: inconsistent units make objects huge or tiny, breaking camera framing.
    5. Missing hierarchy: parent-child relationships replaced by flat layouts, so end effectors don’t follow.
    6. Silent failures: calling nonexistent APIs or parameters—the script “runs but generates nothing.”

    Categorizing failures by type reveals whether the model “can’t do the math” or “can’t write engineering code.”

    Engineering Recommendations

    Integrate the evaluation into your development pipeline rather than running one-off scores:

    • Containerized execution: run scripts in a fixed image on a container platform for environment consistency and resource isolation;
    • Artifact archiving: store scripts, renders, and logs in object storage for traceability and comparison;
    • Regression baselines: trigger regression runs on every model or prompt change and report pass-rate deltas;
    • Observability: use logging services and monitoring alerts to track timeout rates and drift in failure-type distributions;
    • Data flywheel: feed failed samples back as training/optimization material to create an iteration loop.

    Any general-purpose cloud infrastructure—such as Baidu AI Cloud—can host this workflow by reusing standard categories of services like containers, object storage, logging, and monitoring, without building the underlying infrastructure yourself.

    Limitations and Caveats

    • Prompt sensitivity: minor wording changes can cause large swings; fix the template and report variance.
    • Randomness: sample multiple times—single runs have no statistical meaning.
    • Avoid benchmark gaming: keep a private held-out task set to prevent overfitting.
    • Don’t overstate capability: an executable script does not equal correct spatial understanding; pair it with geometric assertions.
    • Compute cost: rendering and verification are slow; filter with static assertions before rendering.

    Conclusion

    Evaluating spatial reasoning by generating 3D scenes through code essentially externalizes the “model’s internal spatial representation” into an executable, assertable, regression-testable engineering artifact. Compared with declarative rendering, scripted modeling is more expressive and yields purer signals; compared with human visual inspection, geometric assertions are more objective. The truly valuable output is not a single total score but an evaluation system combining a layered task set + automated verification + failure-mode classification—one that continuously tells your team exactly which layer of spatial reasoning the model falls short on, and where the next round of optimization should be invested.