Real2Code: Reconstruct Articulated Objects via Code Generation

Zhao Mandi, Yijia Weng, Dominik Bauer, Shuran Song

Introduction

Reconstructing a rigid object from images is a well-studied problem, but reconstructing an articulated object—like a multi-drawer cabinet, a laptop, or a jewelry box—is significantly more complex. It requires not only capturing the 3D shape but also understanding its kinematics: which parts move, where the joints are located, and the range of motion.

Real2Code is a novel framework designed to reconstruct complex articulated objects from a few unposed RGB images by representing their moving parts as Python code. By leveraging fine-tuned Large Language Models (LLMs) to predict joint parameters from oriented bounding boxes, the approach scales elegantly to objects with many parts and generalizes to real-world environments without requiring depth data or camera information.

Real2Code transforms unstructured RGB images into interactable digital twins.

The Challenge of Articulated Objects

Existing "real-to-sim" methods struggle with three primary issues:

  1. Complexity Scaling: Most models are designed for objects with only one or two moving parts. As the number of joints increases, these models often run out of memory or rely on fixed output sizes that cannot handle variable structures.
  2. Data Requirements: Many methods require precise depth data, camera poses, or "before-and-after" interaction videos to infer joint mechanics.
  3. Simulation Readiness: The output of current methods often requires significant manual cleanup before the reconstructed object can be deployed in a physics simulator like MuJoCo.

The Real2Code Pipeline

Real2Code addresses these challenges by breaking the problem into a multi-stage pipeline that transitions from raw pixels to structured code.

The Real2Code pipeline: from pose-free RGBs to segmented point clouds, bounding boxes, and finally, code generation.
  • Part Reconstruction: The system uses a fine-tuned Segment Anything Model (SAM) to identify individual parts. To ensure consistency across different camera views, it integrates DUSt3R, a state-of-the-art stereo reconstruction model that provides dense 3D point maps without needing camera poses.
  • Shape Completion: Because internal structures (like the inside of a drawer) are often occluded, a Convolutional Occupancy Network is used to "fill in the blanks," creating watertight 3D meshes for each part.
  • The OBB Abstraction: Feeding raw point clouds to an LLM is computationally prohibitive. Instead, Real2Code simplifies each part into an Oriented Bounding Box (OBB). This provides a concise geometric summary: center, rotation, and dimensions.
  • Joint Prediction via LLM: A fine-tuned CodeLlama-7B model takes the list of OBBs and generates Python code (specifically in the MJCF format used by MuJoCo). Rather than forcing the LLM to regress exact continuous coordinates—a task LLMs typically struggle with—the problem is formulated as a classification task. The LLM selects which OBB axis and which box edge the joint is aligned with.

Key Insights and Results

Real2Code was trained primarily on the PartNet-Mobility dataset and evaluated on both synthetic data and a custom dataset of real-world furniture captured with a smartphone.

  • Code as a Universal Schema: By framing reconstruction as code generation (next-token prediction), the model naturally handles objects with any number of joints. It simply continues generating lines of code until the entire object is described.
  • Structural Extrapolation: Remarkably, the model—trained on objects with a maximum of 7 parts—successfully reconstructed objects with up to 10 parts. This indicates that the LLM learned the underlying logic of articulation rather than merely memorizing training shapes.
  • Superior Accuracy and Quality: Real2Code significantly outperforms baselines like Ditto and PARIS. On complex objects (6-15 parts), Real2Code maintains high joint prediction accuracy, whereas prior methods suffer from memory exhaustion or plummeting performance. Furthermore, the dedicated shape completion step yields much cleaner surface reconstructions.
  • Real-World Generalization: The model successfully reconstructed "in-the-wild" objects from just a handful of pose-free RGB images, demonstrating that robust vision foundation models (SAM and DUSt3R) can effectively bridge the synthetic-to-real gap.

Limitations and Future Work

While highly effective, Real2Code has a few limitations. Currently, the pipeline processes one object at a time; reconstructing an entire room would require an initial instance segmentation step. Additionally, relying on SAM and a 7B-parameter LLM introduces computational overhead compared to smaller, end-to-end networks.

The current method also assumes hinges align with the edges of a part's bounding box. While true for most furniture, this fails for objects with internal or diagonal hinges. Future work could address this by adding an offset prediction head to the LLM. Finally, as a modular pipeline, cascading errors are possible: if the initial part segmentation fails, downstream joint prediction will likely be compromised.

Summary updated

BibTeX
@inproceedings{mandi2025real,
  author = {Zhao Mandi and Yijia Weng and Dominik Bauer and Shuran Song},
  title = {{Real2Code: Reconstruct Articulated Objects via Code Generation}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=CAssIgPN4I},
}
Figure