Evaluating Spatial Reasoning and 3D Code Generation in LLMs: A Practical Benchmarking Framework

    This article presents a reproducible framework for evaluating how well large language models handle spatial reasoning and 3D code generation. It breaks the capability into six levels, defines a layered task suite from object placement to animated video, introduces a unified script interface and execution sandbox, and combines automated metrics with blind human review to support fair multi-model comparison and reliable engineering decisions.

    Evaluating Spatial Reasoning and 3D Code Generation in LLMs: A Practical Benchmarking Framework

    1. Background: Why Scripted Evaluation Matters

    Generating 3D scenes, animations, and even videos directly from natural language is becoming a key test of a large model’s “spatial reasoning” and “creative coding” abilities. Unlike traditional text generation, these tasks require the model to understand coordinate systems, scale, relative positions, occlusion, camera projection, lighting direction, temporal changes, and code executability — all at once. A single demo or a few subjective screenshots can’t tell whether a model has genuine, stable spatial reasoning or is merely fitting common templates.

    Evaluation should therefore strip away the capability differences of specific rendering libraries or modeling tools and reduce the problem to: “Can the model produce an executable, verifiable, and reproducible 3D scene script?” Using a unified 3D script interface instead of a particular rendering library’s API offers several immediate benefits:

    1. A script interface can explicitly expose transforms, hierarchies, cameras, materials, lighting, and animation parameters, making automated checks easy.
    2. Different models run in the same execution sandbox, reducing environment variance.
    3. Rendered results can be captured as screenshots or sampled into frames for visual review and temporal consistency analysis.
    4. Failed code can be recorded, repaired, and counted, producing quantifiable robustness metrics.

    It’s worth stressing that the goal is not to prove that one model is “better,” but to establish a reusable methodology that helps developers and enterprises make more reliable decisions in multi-model comparison, engineering selection, and regression testing.

    2. Capability Breakdown: What Spatial Reasoning and Creative Coding Actually Test

    Spatial reasoning can be decomposed into at least six levels:

    1. Basic geometry and scale: Can the model correctly create primitives such as cubes, spheres, and cylinders with reasonable units and dimensions?
    2. Relative position and orientation: Can it set positions and rotations from descriptions like “to the left,” “in front,” “diagonally above,” and “facing the target”?
    3. Occlusion and containment: Can it handle front/back occlusion, nesting, and enclosure relationships between objects?
    4. Camera and projection: Can it set camera position, look-at target, and field of view, and understand framing?
    5. Hierarchical transforms: Can it correctly organize parent-child nodes, local vs. world coordinates, and avoid rotation-order and scale-inheritance errors?
    6. Temporal and physical plausibility: In animation tasks, can it keep keyframes continuous, motion direction consistent, and speed changes reasonable?

    Creative coding ability shows up in converting open-ended descriptions into structured scripts, using functions and data structures appropriately, handling edge cases, fixing code after errors, and producing distinctive compositions within constraints. Combining the two, an evaluation task set should include both “hard constraints that can be automatically asserted” and “soft quality that requires human judgment.”

    3. Designing a Reproducible Task Suite

    Structure the task suite in difficulty tiers rather than throwing a single complex prompt at the model. Each tier should specify clear coordinate conventions, unit conventions, output formats, and acceptance criteria.

    • L1 — Single object placement: Create an object of a specified size at a given coordinate; check type, position, size, and material parameters.
    • L2 — Multi-object relationships: Create three objects such that one lies to the front-left of another and maintains a specified distance from the third; check relative positions and distance errors.
    • L3 — Camera framing: Given a subject with specified camera height, distance, and look-at target, the subject should appear near the center of the frame; check camera parameters and projection visibility.
    • L4 — Hierarchy and rotation: A child object must rotate with its parent while preserving its local offset; check the hierarchy structure and final world coordinates.
    • L5 — Animation and video: Generate a looping animation with temporally continuous keyframes; sample frames and check motion direction and occlusion changes.
    • L6 — Error recovery: Inject missing parameters or invalid types, and observe whether the model can repair the script based on execution errors.

    Prompts should avoid vague instructions like “make it look nicer” and instead provide verifiable constraints, for example: “Use a right-handed coordinate system with meters as units. The subject’s center is 1 meter above the origin. The camera is 6 meters in front of the subject at a height of 3 meters, facing the subject’s center.” Keep a small number of open-ended descriptions to assess creative coding quality.

    4. A Unified Script Interface and Execution Sandbox

    To reduce bias from tool-specific APIs, define an abstract scene description interface and have models output either a structured scene or an executable script. The following pseudocode expresses only generic capabilities and depends on no particular rendering library:

    1. type SceneSpec = {
    2. units: "meter";
    3. objects: Array<{
    4. id: string;
    5. shape: "box" | "sphere" | "cylinder";
    6. size: [number, number, number];
    7. transform: {
    8. position: [number, number, number];
    9. rotation: [number, number, number];
    10. scale: [number, number, number];
    11. };
    12. material: { color: string; roughness: number };
    13. }>;
    14. camera: {
    15. position: [number, number, number];
    16. target: [number, number, number];
    17. fov: number;
    18. };
    19. lights: Array<{
    20. type: "point" | "directional";
    21. position: [number, number, number];
    22. intensity: number;
    23. }>;
    24. animations?: Array<{
    25. target: string;
    26. property: "position" | "rotation";
    27. keyframes: Array<{ t: number; value: number[] }>;
    28. }>;
    29. };
    30. function generateScene(prompt: string): SceneSpec {
    31. // The model outputs a structured scene description or script.
    32. // The executor handles validation, rendering, screenshots, and frame sampling.
    33. throw new Error("implemented by candidate model");
    34. }

    The execution sandbox should restrict network access, CPU time, memory, and output file size, and apply static checks and runtime isolation to scripts. For batch evaluation, generic container platforms, object storage, and log monitoring capabilities — such as those offered by Baidu AI Cloud — can handle task scheduling, artifact storage, and exception tracking. The point is not to lock into one environment, but to guarantee that every candidate model is compared under identical resource budgets, timeouts, and rendering parameters.

    5. Automated Metrics and Human Review

    Automated metrics should cover two categories: “code executability” and “spatial correctness.” Executability includes first-run success rate, timeout rate, exception type distribution, and repair rounds. Spatial correctness includes object type match rate, position error, distance error, rotation angle error, camera parameter error, hierarchy match rate, and keyframe continuity. For rendered results, capture screenshots from fixed viewpoints and compute subject-area coverage, occlusion assertions, and visual similarity. For video, sample frames at fixed intervals and check motion direction, loop closure, and temporal jitter.

    Human review covers creative quality that automated assertions can’t easily capture: whether the composition is clear, the subject stands out, the animation feels natural, and the code is maintainable. Use blind review: hide model names, randomize the order, have multiple reviewers score against a unified rubric, and record disagreements. The final output should not be a single total score but a capability radar and a collection of failure cases, making problems easier to localize.

    6. Designing Multi-Model Comparison Experiments

    The most common pitfalls in multi-model comparison are “different prompts, different budgets, different retry counts.” A more rigorous approach:

    • Fix the task set, prompt templates, temperature, maximum output length, execution sandbox, and rendering parameters.
    • Sample each task multiple times and report means with confidence intervals.
    • Allow the same number of automated repair attempts for failed tasks, and report first-pass rate and post-repair pass rate separately.
    • Retain all artifacts, including raw outputs, execution logs, screenshots, sampled video frames, and scoring records.

    When analyzing results, break them down by capability dimension rather than looking only at overall pass rate. One model may score high on basic geometry but make many camera and hierarchical transform errors; another may have strong code executability but conservative creative compositions. Only after this breakdown can you judge whether a model fits a specific use case — such as batch-generating product showcase scenes, educational demo animations, or interactive creative prototypes.

    7. Extending from 3D Scenes to Video

    When generating video purely from code, the time dimension needs extra attention. Evaluation should check keyframe counts, timestamp monotonicity, first/last-frame closure, motion direction consistency, and the plausibility of occlusion changes. After sampling frames, compare subject position changes between adjacent frames for smoothness, and look for jumps, clipping (object interpenetration), or camera shake. For looping animations, verify that the first and last states match; for physics-like animations, check whether falling, collision, and rotation follow basic common sense.

    8. Engineering Recommendations

    First, define the coordinate system and rotation order explicitly — a large share of failures come from inconsistent conventions, not model capability. Second, avoid over-relying on a rendering library’s default behavior; express key spatial relationships as assertable structured data. Third, keep failure cases and repair traces — they are far more diagnostic than average scores. Fourth, enforce security isolation: forbid untrusted network requests and file operations. Fifth, control evaluation costs: run regression tests on a small task set first, then move to a larger set for in-depth assessment.

    9. Conclusion

    A model’s spatial reasoning and 3D code generation abilities cannot be judged from demo videos alone. A more reliable approach is to build executable scenes through a unified script interface, design layered tasks across geometry, transforms, cameras, lighting, animation, and video consistency, and combine automated assertions, rendered comparisons, frame sampling, and blind review into a reproducible evaluation pipeline. For developers and enterprises, this methodology supports both multi-model comparison and ongoing regression testing — turning “it looks like it can generate” into a verifiable, maintainable, and deployable engineering capability.