Evaluating Spatial Reasoning and Code Generation in Large Language Models

    Large language models can generate impressive-looking code, but fluent code does not guarantee correct spatial relationships or satisfied task constraints. This article presents a practical evaluation methodology for 3D scene and animation generation tasks, arguing that assessment should shift from "can it generate" to "can it be verified." It covers a layered task suite, a script-driven 3D pipeline broken into inspectable stages, reproducible scoring mechanisms, and the safeguards needed to move from demos to engineering adoption.

    1. From “Can Generate” to “Can Verify”

    When developers work with LLMs that can generate code, their core concern is usually not whether the answer reads fluently, but whether the model can turn natural-language requirements into executable, verifiable, and maintainable programs. For 3D scene and animation generation, this question is especially sharp: code that runs successfully does not mean the spatial relationships are correct, and a visually appealing frame does not mean the model satisfied every task constraint.

    For example, a request to “generate a rod passing through the center of a ring, and make the ring rotate around the rod’s axis” involves at least five kinds of requirements: object modeling, positional relationships, orientation control, rotation center, and temporal change. The model may produce both a ring and a rod but place the rod beside the ring; or the initial frame may look correct, yet once the animation starts, the ring orbits the world origin instead. Both cases show that a static screenshot or code length alone cannot tell you much about capability.

    Evaluation should therefore focus on general technical questions: How does the model express spatial relationships? How does it translate those relationships into code? How does it correct errors given execution feedback? And can the final artifact enter a real development workflow? One-off demos without controlled conditions cannot support conclusions like “comprehensively leading” or “roughly on par.”

    2. Spatial Reasoning Is a Cluster of Interrelated Abilities

    2.1 Converting Natural Language into Explicit Constraints

    Descriptive terms in 3D tasks—“above,” “inside,” “along,” “through”—must be converted into checkable geometric conditions.

    “An object sits above a platform” might mean only that its vertical coordinate is higher, or it might require the object’s bottom face to touch the platform’s top surface. “Inside a container” might mean the center point lies within the container, or that no part of the object crosses its boundary. These interpretations must not be conflated.

    A reliable generation workflow should first clarify the coordinate system, units, object dimensions, and constraint interpretation. For highly ambiguous requirements, the model should ask the user or state its assumptions explicitly—rather than generate a scene directly and leave interpretation problems to be discovered in the rendered output.

    2.2 Local Coordinates vs. World Coordinates

    Complex scenes typically involve parent-child hierarchies. A child object’s position and rotation are usually defined relative to its parent, and its final world pose results from all accumulated transforms.

    Common errors include treating local translation as world translation, or applying transforms redundantly after setting up parent-child relationships. For example, a robotic arm’s end-effector position cannot be judged from the effector object’s own coordinates alone; it also depends on the translations and rotations of upstream joints.

    Evaluation tasks should cover translation, rotation, scaling, and their combinations, and should verify the order of transformations. Rotating-then-translating does not generally equal translating-then-rotating. These tasks reveal spatial reasoning more effectively than simply placing multiple cubes on a plane.

    2.3 Geometric Structure vs. What Is Visible

    Geometric correctness and visual visibility are two separate dimensions. An object may exist correctly in the scene but be occluded, cropped by the camera, or hard to recognize due to material and lighting settings.

    So “the target is not visible in the frame” cannot be equated with “the target was not generated”; conversely, apparent contact from one camera angle does not prove actual 3D contact.

    Scene-structure checks and image checks should be used together. The former validates position, size, hierarchy, and motion relationships; the latter validates composition, visibility, and presentation quality. They complement rather than replace each other.

    3. Why Script-Driven 3D Tasks

    Script-driven 3D creation maps requirements onto scene objects, transforms, materials, cameras, and animation settings, making it well suited to repeatable evaluation pipelines. However, different runtime environments have different ranges of applicability—no environment type is inherently better at revealing model capability.

    Real-time interactive 3D environments are better suited to checking interactive response, dynamic presentation, and runtime performance; environments supporting modeling and offline rendering are better suited to checking geometry processing, scene organization, lighting, and animation output. The choice should be driven by the target task.

    If the research focus is spatial reasoning, minimize irrelevant API-memorization burden. For example, provide the same interface documentation and base scripts for all objects under evaluation, so the model can concentrate on object placement, orientation, and motion constraints. Otherwise, failures may stem from unfamiliarity with the runtime rather than weak spatial reasoning.

    At the same time, keep end-to-end tasks to measure actual delivery capability. The two test types answer different questions:

    • Controlled geometry tasks: with sufficient environment information, can the model correctly handle spatial constraints?
    • End-to-end creation tasks: can the model complete the full path from requirement understanding to an executable artifact?

    4. Build a Layered Task Set; Avoid Concluding from a Single Case

    4.1 Foundation Layer: Position, Scale, and Orientation

    Foundation tasks should include object creation, specified dimensions, alignment, contact, spacing, and orientation control. For example, place three objects of different heights on a plane so their bottoms align at the same level while maintaining required horizontal spacing.

    This layer checks whether the model distinguishes center positions from boundary positions. Setting all object centers at the same height does not guarantee bottom alignment.

    4.2 Relationship Layer: Containment, Penetration, Connection, and Occlusion

    Relationship tasks may require one object to pass through another object’s opening, or multiple parts to form a closed structure. These require joint consideration of size matching, relative orientation, and geometric relationships between objects.

    Do not accept deliverables based on a single image. Combine multi-view rendering, bounding checks, and, where necessary, geometric tests to confirm constraints hold in reality. Note that bounding-box checks are usually only a rough filter: intersecting bounding boxes do not imply actual surface contact, and a contained bounding box does not necessarily mean an object lies within a complex container’s effective interior volume.

    4.3 Dynamics Layer: Trajectories and Temporal Constraints

    Animation tasks should verify object behavior across the entire time interval, not just the first and last frames. Check whether the rotation axis stays consistent, whether prohibited interpenetrations occur during motion, and whether actions occur in the specified order.

    For rotations, also pay attention to the angle-interpolation method to avoid unintended winding paths. For looping animations, check continuity at the period boundary to prevent noticeable jumps between the last and first frames.

    4.4 Creative Layer: Open Requirements and Deliverable Quality

    Creative coding can use relatively open tasks—for example, expressing “aggregation and dispersion” through geometric forms—but must retain explicit acceptance boundaries: duration, object-count range, motion continuity, and output requirements.

    Open-ended tasks have no unique correct answer, so a single overall score is inappropriate. A more sensible approach is to evaluate constraint adherence, visual expression, code organization, and modifiability separately, with multiple reviewers judging independently against the same rubric.

    5. Breaking “Code-Generated Video” into an Inspectable Pipeline

    Generating video through code typically means a program builds the scene, defines how objects change over time, renders images frame by frame, and composites them into a video. This differs from directly generating video content; its advantages are controllable parameters, reproducible processes, and relatively clear local adjustments.

    The full pipeline can be divided into five stages:

    1. Scene initialization: define coordinates, dimensions, objects, materials, and lighting.
    2. Motion definition: describe displacement, rotation, and shape changes using time functions or keyframes.
    3. Camera design: set viewpoints and motion paths so key events remain visible.
    4. Frame-by-frame generation: output the image sequence under consistent scene configuration.
    5. Output acceptance: check the frame sequence, duration, visual continuity, and whether the final file is valid.

    Every stage can fail. A scene script may run successfully, but if the camera never covers the target region, the deliverable fails; all images may be generated, but if some frames are missing, the task is not complete. Evaluation reports should identify which stage failed, instead of lumping different problems together as “generation failure.”

    6. Designing Reproducible Scoring and Verification

    6.1 First-Pass Success vs. Post-Repair Success

    First-run success reflects direct delivery capability; success after fixing errors using error logs reflects the ability to exploit feedback. Both matter, but they must be tracked separately.

    Also record the number of repair rounds, execution counts, and the degree of human intervention. If a task required developers to modify key geometric logic to make it pass, it should not be counted as fully autonomous completion.

    6.2 Separate Hard Constraints from Soft Quality

    Hard constraints include whether the script executes, whether objects exist, whether dimensions meet requirements, and whether the animation covers the specified time range. Soft quality includes composition, motion pacing, material coherence, and creative expression.

    Adopt a “check hard constraints first, then evaluate soft quality” workflow. A visually beautiful frame missing a key object should not mask task failure.

    Below is an illustrative verification logic, independent of any specific runtime. It is not a directly callable interface:

    1. Read task constraints
    2. Execute scene generation script
    3. If execution fails:
    4. Save error information
    5. Mark execution-stage failure
    6. Otherwise:
    7. Check objects and geometric relationships
    8. Check motion timing
    9. Generate previews from multiple views and key moments
    10. Check visual visibility
    11. Summarize which constraints passed and which remain unsatisfied

    Judgments about position, contact, and angles need tolerances; requiring floating-point values to match exactly is impractical. Tolerances should be determined in advance according to scene scale, computational precision, and task requirements, and applied uniformly across all tests.

    6.3 Control the Evaluation Conditions

    Prompts, base files, runtime environments, allowed dependencies, resource budgets, and feedback counts should be kept consistent. If some tests allow example code while others do not, the results will be contaminated by differences in external conditions.

    For generation processes with randomness, run multiple independent trials and report success counts, typical errors, and result variance. Being first to finish only reflects timing performance on one run; it cannot substitute for conclusions about correctness, stability, or overall capability.

    7. From Demo to Engineering Adoption: Required Safeguards

    Auto-generated scripts should execute in isolated environments with restricted file access, network access, and resource consumption, preventing unreviewed code from affecting production systems. Execution logs, task inputs, generated code, and output files should be stored together for reproducibility and problem tracing.

    Scene code should also feature centralized parameter management, clear structure, and controlled modification scope. A script that runs but scatters parameters everywhere tends to be expensive to adjust later. Evaluations can include local-modification tasks—for example, changing only an object’s dimensions while keeping other relationships intact—and observe whether the result introduces unrelated changes.

    Teams can organize the workflow as: requirement specification → generation → static checks → isolated execution → geometric verification → visual review → archiving. When scaling execution, general-purpose compute resources, object storage, task queues, logging, and monitoring capabilities can be used, but specific configurations should be determined by task scale and security requirements. Do not generalize performance or cost conclusions from a single demo.

    8. Forming a Meaningful Final Assessment

    Evaluating spatial reasoning and creative code capability should ultimately answer four questions: which tasks can be completed stably, which constraints are error-prone, whether failures can be effectively repaired, and how much human effort is still needed for the artifact to enter an engineering pipeline.

    A good conclusion describes capability boundaries rather than merely rankings. For example: basic layout tasks perform consistently, but complex hierarchical transformations require extra checking; static scenes satisfy constraints, but long-running animations still require trajectory and loop-continuity verification. Conclusions like these are far more useful for actual selection and development decisions.

    The most valuable capability is the model’s ability to convert language requirements into explicit constraints, implement those constraints as reliable code, and continuously converge with the help of execution and verification feedback. Only by jointly examining correctness, stability, repair ability, and delivery quality can an impressive demo become a reproducible, auditable, and engineering-grade technical judgment.