LLM Spatial Reasoning Evaluation: A Practical Guide to Parametric 3D Generation

    Evaluating a large language model's spatial reasoning takes more than checking whether a generated script runs without errors. This guide uses a parametric 3D scene—a pelican leaning forward on a dark green steel bicycle at dusk—to show how to convert subjective visual judgment into executable assertions. It covers scenario selection, a prompt skeleton with acceptance criteria written in, single-source-of-truth parameters and derived geometry, chain paths built from external tangents, crank-phase-driven inverse kinematics, automated parameter-sweep regression, and a scoring rubric. The takeaway: the bottleneck is constraint solving and causal modeling, not modeling the shape.

    1. Background: From “It Runs” to “It Fits”

    When evaluating an LLM’s code generation ability, a common mistake is treating “the script executes without errors” as the success criterion. Rendering an object that looks plausible and building a self-consistent, constraint-verifiable 3D assembly are capabilities of two different orders of magnitude.

    The former relies on surface-level pattern matching: given a description of a familiar object, the model assembles a rough silhouette. The latter requires the model to do three things:

    1. Establish a single source of truth for parameters: every geometric quantity is derived from a small set of global constants, and no magic numbers disconnected from those constants may appear inside function bodies.
    2. Solve spatial constraints: the relative placement of parts is determined by geometric relationships (tangency, envelope, contact) rather than hard-coded coordinates.
    3. Maintain phase consistency: the current state of a moving mechanism (crank angle) must drive all related parts (pedal, foot, chain) to update in sync.

    So the core question of the evaluation can be stated in one sentence: has the model actually built a causal chain of “parameter → geometry → constraint,” or has it merely recalled a static shape?

    2. Evaluation Vehicle: One Prompt Plus Parameter-Perturbation Acceptance

    2.1 Scenario Selection Principles

    A good evaluation scenario should satisfy three conditions: it contains a transmission mechanism (testing derived calculations such as chain and gear ratio), it contains flexible/envelope relationships (testing width coupling), and it contains phase-driven contact constraints (testing kinematic consistency). A typical prompt: on a coastal boardwalk at dusk, a seabird leans forward riding a dark green steel-frame bicycle, both wings extended forward to grip the handlebar, one webbed foot pressing a pedal while the other hangs in the air at the lowest point of the return stroke; the frame is a classic diamond type, a canvas tool bag hangs from the down tube, a roll of fishing net is strapped to the rear rack; the crank is driving the rear wheel and the chain is under tension.

    The prompt must explicitly require delivery of a script that runs in headless batch mode (executed from the command line with --background), not an interactive session. This constraint immediately eliminates any approach that depends on manual GUI intervention.

    2.2 Prompt Skeleton (Illustrative)

    1. Design the scene from the text below only; no reference images are provided. Deliver a complete, runnable script.
    2. 1. Scene and narrative: ... (dusk, materials, posture, transmission state)
    3. 2. Parameters and coupling: the following constants go at the top of the script; all geometry must be derived from them
    4. PELICAN_WINGSPAN = 1.15 # wingspan; controls handlebar width and grip spacing
    5. BICYCLE_WHEELBASE = 1.02 # wheelbase; drives frame geometry
    6. CHAINRING_TEETH = 44 # chainring teeth; drives chain length and gear ratio
    7. COG_TEETH = 16 # rear cog teeth
    8. CRANK_PHASE = 35.0 # crank phase angle; drives pedal and foot contact
    9. 3. Acceptance: change only the numbers, not the code, then re-run and check that
    10. the handlebar is wider and the grips still enclose the wing tips; the chain path is
    11. recomputed with no interpenetration and no sag;
    12. the stance foot still contacts the pedal surface and the airborne foot is still low on the return stroke.

    The key is the third section: writing the acceptance criteria into the prompt turns the evaluation from “look at the render” into “run the assertions.”

    3. Implementation of Parameter Coupling

    3.1 Single Source of Truth and Derived Quantities

    1. import math
    2. # ---- Global constants: the single source of truth ----
    3. PELICAN_WINGSPAN = 1.15
    4. BICYCLE_WHEELBASE = 1.02
    5. CHAINRING_TEETH = 44
    6. COG_TEETH = 16
    7. CRANK_PHASE_DEG = 35.0
    8. # ---- Derived quantities ----
    9. CHAIN_PITCH = 0.0127 # chain pitch
    10. R_RING = CHAIN_PITCH * CHAINRING_TEETH / (2*math.pi) # chainring pitch radius
    11. R_COG = CHAIN_PITCH * COG_TEETH / (2*math.pi) # cog pitch radius
    12. GEAR_RATIO = CHAINRING_TEETH / COG_TEETH
    13. BAR_WIDTH = PELICAN_WINGSPAN * 0.92 # total handlebar width
    14. GRIP_GAP = PELICAN_WINGSPAN * 0.86 # grip spacing

    The test is simple: search the whole file for numeric literals. Apart from constant definitions and dimensionless ratio factors, no coordinate-like magic numbers should appear.

    3.2 Chain Path: External Tangents, Not a Polyline

    A taut chain means it consists of two external tangent segments between the chainring and the cog plus two arcs, with the length determined by the center distance and the radius difference:

    $L \approx 2d + \pi (R_1 + R_2) + \frac{(R_1 - R_2)^2}{d}$

    1. def chain_path(c1, r1, c2, r2, seg=48):
    2. d = (c2 - c1).length
    3. a = math.acos(max(-1.0, min(1.0, (r1 - r2) / d))) # tangent point phase
    4. up, dn = [], []
    5. for i in range(seg + 1):
    6. t = a + (2*math.pi - 2*a) * i / seg
    7. up.append(c1 + Vector((r1*math.cos(t), r1*math.sin(t), 0)))
    8. t2 = -a - (2*math.pi - 2*a) * i / seg
    9. dn.append(c2 + Vector((r2*math.cos(t2), r2*math.sin(t2), 0)))
    10. return up, dn

    When the chainring tooth count changes from 44 to 52, r1 grows and the tangent phase a changes automatically, so the chain length and routing are recomputed. That is the dividing line between “coupled” and “decorative.”

    3.3 Crank Phase and Foot Contact

    The pedal position is uniquely determined by the phase, and the foot is solved with two-segment inverse kinematics (hip–knee–ankle) so that the ankle end lands at a fixed offset above the pedal surface along its normal:

    1. def pedal_pos(crank_len, phase_deg, side=+1):
    2. t = math.radians(phase_deg) * side
    3. return Vector((crank_len*math.cos(t), crank_len*math.sin(t), 0))
    4. def solve_leg(hip, ankle, l1, l2):
    5. d = (ankle - hip).length
    6. d = min(d, l1 + l2 - 1e-4)
    7. cos_k = (l1*l1 + l2*l2 - d*d) / (2*l1*l2)
    8. return math.acos(max(-1.0, min(1.0, cos_k))) # knee angle

    Change the phase to 140° and the two pedals swap heights, so the stance foot and the airborne foot exchange roles automatically with no code change.

    4. Automated Acceptance: Turning Subjective Judgment into Assertions

    1. def assert_scene():
    2. assert abs(handlebar_width() - PELICAN_WINGSPAN*0.92) < 1e-6
    3. assert grips_contain_wing_tips() # grips enclose the wing tips
    4. assert chain_clearance() > 0.002 # no interpenetration
    5. assert chain_sag() < 1e-3 # no sag
    6. p = pedal_pos(CRANK_LEN, CRANK_PHASE_DEG)
    7. assert abs(contact_gap(p, stance_foot()) ) < 0.005
    8. assert airborne_foot_height() > 0.02 # airborne foot low on the return stroke

    A parameter-sweep regression is recommended: combine wingspan values {1.15, 1.35}, tooth counts {44, 52}, and phases {35, 140, 215}; only a full pass counts as a pass.

    5. Scoring Dimensions and Reading the Results

    Dimension What to observe Weight
    Executability Runs once in headless batch mode with no manual patching 20%
    Parameter purity No disconnected magic numbers; changing a number triggers recomputation 20%
    Geometric correctness Chain tangency, closed frame, no interpenetration 25%
    Constraint satisfaction Grip envelope, foot contact, airborne determination 25%
    Code quality Naming, comments, structural layering 10%

    In practice, model performance is usually gradient-distributed: the first solutions to arrive often run but are loosely coupled in their parameters; the middle solutions recompute the chain correctly but ignore foot contact; the failing solutions hard-code coordinates, so changing one number misaligns everything. The conclusion: the bottleneck of spatial reasoning is not shape modeling, but constraint solving and causal modeling.

    6. Engineering Recommendations

    • Add it to CI: write the parameter sweep and assertions as regression cases that run automatically whenever the model or the prompt changes.
    • Keep artifacts: archive render frames and logs to object storage for side-by-side comparison.
    • Elastic compute: run batch sweeps on the elastic capacity of a container platform, using a task queue to smooth peaks.
    • Observability: track failure rates and latency distributions with a log service and monitoring alerts.
    • Platformization: enterprises can build the evaluation pipeline on the model services and compute resources of cloud platforms such as Baidu AI Cloud, with unified management of prompts, parameter sets, and scorecards.

    7. Conclusion

    Evaluating an LLM’s spatial reasoning should not stop at “does the image look good.” Putting acceptance criteria into the prompt, expressing geometric relationships as executable assertions, and turning parameter perturbation into regression tests is what cleanly separates “looks right” from “is right.” This method depends on no particular toolchain and transfers directly to mechanical assemblies, building components, and robot poses—a pragmatic path for assessing the real engineering value of code generation.