SpatialGrammar: A Domain-Specific Language for LLM-Based 3D Indoor Scene Generation

Song Tang, Kaiyong Zhao, Yuliang Li, Qingsong Yan, Penglei Sun, Junyi Zou, Qiang Wang, Xiaowen ChuarXiv 2026

TL;DR

Large Language Models (LLMs) frequently struggle with 3D scene generation due to the high cognitive load of predicting raw 6-DoF coordinates or verbose code. This paper introduces SpatialGrammar, a domain-specific language (DSL) that simplifies 3D scene generation into intuitive 2D Bird's-Eye View (BEV) grid placements with hierarchical sub-layouts. By making this representation deterministically compilable, the authors enable closed-loop agentic refinement and successfully train a highly efficient 104M-parameter model entirely on synthetic data.

What Problem Does This Paper Address?

Automatically generating interactive 3D indoor environments from natural language prompts is a cornerstone task for virtual reality, gaming, and embodied AI. However, current LLM-based approaches suffer from severe spatial inaccuracies, such as floating objects, wall penetrations, and overlapping furniture.

The root cause is representational: standard formats are either too geometric (raw 6-DoF coordinates) or too verbose (deeply nested JSON or complex Python scripts). This makes it incredibly difficult for language models to reason about spatial relationships and physical constraints. The field lacks a representation that is simultaneously token-efficient, intuitive for LLMs to write, and strictly verifiable under physical laws.

Methods

The authors tackle this challenge by introducing a complete ecosystem centered around a novel domain-specific language:

  1. SpatialGrammar DSL: Instead of forcing LLMs to internalize 3D physics, the language encodes geometric priors directly. It assumes a gravity-aligned world where most objects rest on a common ground plane, reducing the problem to 2D grid placement. It consists of two components:
  2. LLMSLI: For furniture and object layouts.
  3. LLMSLB: For architectural structures (walls, doors, windows).
  4. Hierarchical Sub-Layouts: To handle complex arrangements—like a chessboard with pieces or supplies on a desk—SpatialGrammar supports recursive sub-layouts anchored to specific faces of a parent object.
  5. SG-Agent: A tool-augmented, closed-loop system that uses the Model Context Protocol (MCP). It generates the DSL code, compiles it into 3D bounding boxes, runs collision checks in a lightweight 3D sandbox ("Draft Engine"), and iteratively refines the code based on symbolic and visual feedback.
  6. SG-Mini: A compact 104M-parameter Small Language Model (SLM) trained via a three-stage pipeline (Pre-training, Supervised Fine-Tuning, and Direct Preference Optimization). To teach the model to avoid spatial errors, the authors developed an Error Chain method that deliberately injects compounding semantic, spatial, collision, and syntax errors to create realistic negative examples for preference learning.
An overview of how the LLM agent uses the SpatialGrammar DSL to generate complete 3D indoor scenes.

Datasets

  • Training Data: The authors did not use human-annotated datasets. Instead, they built a programmatic synthetic data engine using parameterized templates for common room types (living rooms, bedrooms, offices) to generate thousands of validated, collision-free SpatialGrammar programs.
  • Evaluation Benchmark: The models were evaluated on a newly curated benchmark of 159 test scenes spanning five scenarios of increasing complexity: single-object placement, multi-object generation, multi-turn editing, hierarchical placement, and architectural generation. Performance was verified using 1,198 atomic checks.

Key Insights and Ideas

  • Dimensionality Reduction Relieves Cognitive Load: Abstracting 3D scene generation into a 2D BEV grid aligns perfectly with how humans reason about floor plans. It eliminates the need for the LLM to calculate continuous metric heights or complex rotations.
  • Generation as Iterative Debugging: By making the language deterministically compilable, the system transforms scene generation from an unpredictable optimization problem into an iterative program-editing task. The compiler acts as a verification oracle, providing clear, actionable error messages (e.g., "Sofa overlaps with coffee table at position (3,4)").
  • Composition via Face-Anchoring: The face-anchored sub-layout mechanism elegantly unifies diverse placement types. The exact same mechanism handles a TV on a stand, a picture frame on a vertical wall, or a fan on a ceiling.
Figure 2: Each row shows DSL code (left), semantic interme- diate representation (middle), and final render (right). Top: LLMSLI places furniture on a BEV grid with a sub-layout attaching a TV onto the stand. Bottom: LLMSLB defines walls and openings, with a sub-layout mounting an air conditioner on the wall.

Key Results

The framework was evaluated using the Decomposed Requirements Following Ratio (DRFR), collision rates ($\text{CR}_{\text{obj}}$), and aesthetic scores:

  • State-of-the-Art Agent Performance: SG-Agent achieved the highest instruction-following accuracy (DRFR of 0.83 on multi-object and 0.93 on hierarchical tasks) while maintaining a near-zero collision rate, outperforming strong baselines like HoloDeck and DirectLayout.
  • Highly Competitive Small Model: Despite having only 104M parameters, SG-Mini outperformed much larger non-BEV models and achieved a 0.99 DRFR on single-object placement tasks. It also significantly beat DirectLayout on hierarchical placement (0.69 vs 0.61 DRFR).
  • Grid Size Trade-offs: Ablation studies demonstrated that a 100cm grid cell size provides the optimal sweet spot, maximizing instruction following while keeping token counts low and minimizing adjacent footprint collisions.

Limitations and Future Work

  • SG-Mini Capabilities: Due to its strict parameter budget, the lightweight SG-Mini model is currently restricted to single-shot generation and lacks the contextual memory required for multi-turn conversational editing.
  • VLM Evaluation Noise: The visual feedback loop and aesthetic scoring rely on Vision-Language Models (like Gemini), which can still be noisy and struggle with dense, cluttered 3D spatial reasoning.
  • Dynamic Physics: The current grammar assumes static, gravity-aligned structures and does not yet support complex, non-axis-aligned physics or dynamic object interactions.

Summary updated

BibTeX
@misc{tang2026spatialgrammar,
  author = {Song Tang and Kaiyong Zhao and Yuliang Li and Qingsong Yan and Penglei Sun and Junyi Zou and Qiang Wang and Xiaowen Chu},
  title = {{SpatialGrammar: A Domain-Specific Language for LLM-Based 3D Indoor Scene Generation}},
  year = {2026},
  eprint = {2604.27555},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2604.27555},
}

Loading related content...

Figure