# vveicao/freeorbit4d architecture

> Architecture diagram of the GitHub repository vveicao/freeorbit4d, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vveicao/freeorbit4d
- Repository: https://github.com/vveicao/freeorbit4d

## Overview

1. **What this repository is**
   FreeOrbit4D is a multi-stage pipeline for turning a single monocular video into a **foreground-complete 4D reconstruction** and then **re-rendering that scene from new camera trajectories**. The top-level product is an output video under `outputs/.../rendering/.../inference/output_video.mp4`, plus optional interactive 4D visualization artifacts.

2. **Top-level orchestration boundary**
   The main entrypoint is `run_pipeline.py`, which dispatches into `pipeline/full_pipeline.py` or stage-specific pipeline modules in `pipeline/`. This is the primary architecture boundary: the repo is organized as a **pipeline controller** above a set of **processing/rendering subsystems**.

3. **Pipeline stages**
   The pipeline is explicitly split into:
   - `stage_0_pipeline.py`: initial video/data preparation
   - `stage_1_pipeline.py`: reconstruction
   - `stage_1a_pointcloud_pipeline.py`: point-cloud-centric processing
   - `stage_1b_rendering_pipeline.py`: view synthesis / rendering
   - `stage_2_pipeline.py`: final generation/refinement
   This division mirrors the repo’s scripts (`scripts/0_*`, `scripts/1_*`, `scripts/2_*`) and makes the data flow easy to diagram as a left-to-right multi-stage DAG.

4. **Input preparation and scene configuration**
   Inputs are either bundled demos under `demo/` or user videos configured through YAML files in `configs/`. Scene configs describe the input media, masks, trajectory settings, and output naming. For custom videos, `scripts/prep_interactive_mask.py` provides a Gradio-based annotation tool to create the foreground mask and a scene config in `configs/user/`.

5. **Stage 0: multiview generation and data preparation**
   The `scripts/0_0_gen_multiviews.py` and `scripts/0_1_data_preparation.py` steps, together with `core/data_processor.py` and `core/multiview.py`, handle the conversion from raw video to structured frame data suitable for later geometry processing. This is where the repo likely establishes per-frame image sets, masks, and any multi-view or pseudo-view inputs needed by downstream models.

6. **Stage 1: reconstruction core**
   The reconstruction subsystem is centered in `core/`:
   - `core/alignment.py` aligns estimated geometry/camera outputs
   - `core/pointcloud.py` manages 3D/4D point cloud representation
   - `core/rendering.py` handles image synthesis from reconstructed geometry
   - `core/data_processor.py` and `core/multiview.py` feed the reconstruction logic
   This is the main geometry boundary: raw video/masks in, aligned 4D proxy out.

7. **Foreground/background separation**
   The repo makes the foreground a first-class component. Scripts `1_0_run_foreground.py` and `1_1_run_background.py` indicate that reconstruction is split into foreground and background tracks, likely because the method is designed around a **single fully visible foreground subject**. The README’s input constraints reinforce that this is a major architectural assumption, not just a usage detail.

8. **Alignment and point-cloud fusion**
   `scripts/1_2_align.py`, `scripts/1_2_visualization.py`, and `core/alignment.py` suggest a dedicated stage for consolidating estimated poses/structure into a coherent scene representation. The architecture here is: model outputs → geometric alignment → fused point cloud / 4D proxy → visualization or rendering. The visualization script provides an inspection boundary between reconstruction and downstream synthesis.

9. **Trajectory authoring and rendering**
   Camera redirection is handled by `scripts/1_3_cam_traj.py` and `scripts/1_4_rendering.py`. The trajectory editor is interactive and produces JSON camera paths that are later consumed by the rendering stage. This cleanly separates:
   - trajectory design
   - reconstruction reuse
   - final video rendering
   So re-rendering can skip reconstruction entirely via `--resume_from render`.

10. **Stage 2: generative refinement**
   `scripts/2_0_Wan2.2-VACE-Fun-A14B.py` and the vendored `generative-models/` directory indicate a later synthesis/refinement step that uses external generative video tooling. Architecturally, this is an optional downstream generation layer sitting on top of the reconstructed/rendered scene, not part of the core geometric reconstruction path.

11. **Model implementation stack**
   The `page-4d/` subtree contains a substantial VGGT-based model implementation, duplicated in two variants:
   - `page-4d/vggt/`
   - `page-4d/vggt_t_mask_mlp_fin10/`
   These include transformer layers, tracking heads, camera heads, depth heads, aggregators, and geometry utilities. This subtree is the learned-model boundary of the system: backbone, task heads, and tracking/camera estimation are encapsulated here rather than in the pipeline code.

12. **External dependencies and vendored components**
   The repository includes submodules and vendored code for major external systems:
   - `DiffSynth-Studio/`
   - `generative-models/`
   - `page-4d/vggt/dependency/`
   These are used to avoid depending on live upstream APIs during execution. The README also references pretrained checkpoints for VGGT/SAM2/Wan2.2-VACE and other model dependencies, so checkpoint availability is part of the runtime architecture.

13. **Shared utilities**
   `utils/` contains cross-cutting infrastructure: config loading, camera math, depth utilities, video/image I/O, point-cloud helpers, logging, seeding, and trajectory helpers. These are not a distinct stage, but they define the common data contracts passed between pipeline modules and scripts.

14. **Repository structure for reproducibility**
   The `configs/scenes/` folder, `demo/` inputs, `assets/` visuals, `docs/` usage guides, and `download_checkpoints.sh` together form the operational layer of the architecture. They are what make the pipeline reproducible: the code expects a prepared scene directory, specific checkpoints, and well-formed config files to move data cleanly from raw input to reconstruction to rerendered output.

Main entry points: [`pipeline/stage_1_pipeline.py`](https://github.com/vveicao/freeorbit4d/blob/main/pipeline/stage_1_pipeline.py) (Stage 1), [`pipeline/full_pipeline.py`](https://github.com/vveicao/freeorbit4d/blob/main/pipeline/full_pipeline.py) (Full pipeline), [`pipeline/stage_0_pipeline.py`](https://github.com/vveicao/freeorbit4d/blob/main/pipeline/stage_0_pipeline.py) (Stage 0), [`run_pipeline.py`](https://github.com/vveicao/freeorbit4d/blob/main/run_pipeline.py) (Run pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Orchestration"]
  node_run_pipeline_py["Run pipeline<br/>entrypoint<br/>[run_pipeline.py]"]
  node_full_pipeline_py["Full pipeline<br/>orchestrator<br/>[full_pipeline.py]"]
end

subgraph group_stages["Pipeline stages"]
  node_stage0_py["Stage 0<br/>pipeline stage"]
  node_stage1_py["Stage 1<br/>pipeline stage"]
  node_stage1a_py["Pointcloud stage<br/>pipeline stage"]
  node_stage1b_py["Rendering stage<br/>pipeline stage"]
  node_stage2_py["Stage 2<br/>pipeline stage"]
  node_prep_mask_py["Mask prep<br/>interactive tool"]
  node_cam_traj_py["Camera traj<br/>trajectory editor<br/>[1_3_cam_traj.py]"]
  node_render_py["Render run<br/>render driver<br/>[1_4_rendering.py]"]
end

subgraph group_geometry["Geometry core"]
  node_data_proc_py["Data proc<br/>scene prep<br/>[data_processor.py]"]
  node_multiview_py["Multiview<br/>view builder<br/>[multiview.py]"]
  node_align_py["Alignment<br/>geometry fusion<br/>[alignment.py]"]
  node_pointcloud_py["Point cloud<br/>scene proxy<br/>[pointcloud.py]"]
  node_core_render_py["Core render<br/>synthesis<br/>[rendering.py]"]
end

subgraph group_models["Learned models"]
  node_vggt_py["VGGT model<br/>transformer model<br/>[vggt.py]"]
  node_track_head_py["Track head<br/>tracking head<br/>[track_head.py]"]
  node_camera_head_py["Camera head<br/>pose head<br/>[camera_head.py]"]
  node_vit_py["ViT layers<br/>backbone layers"]
end

subgraph group_external["External stacks"]
  node_diffsynth_dir["DiffSynth<br/>vendored external"]
  node_genmodels_dir["Gen models<br/>vendored external"]
end

subgraph group_support["Support code"]
  node_config_py["Config<br/>[config.py]"]
  node_camera_py["Camera utils<br/>camera math<br/>[camera.py]"]
  node_traj_py["Trajectory utils<br/>path utils<br/>[trajectory.py]"]
end

node_run_pipeline_py -->|"dispatches"| node_full_pipeline_py
node_run_pipeline_py -->|"dispatches"| node_stage0_py
node_run_pipeline_py -->|"dispatches"| node_stage1_py
node_run_pipeline_py -->|"dispatches"| node_stage1b_py
node_full_pipeline_py -->|"runs"| node_stage0_py
node_full_pipeline_py -->|"runs"| node_stage1_py
node_full_pipeline_py -->|"runs"| node_stage1a_py
node_full_pipeline_py -->|"runs"| node_stage1b_py
node_full_pipeline_py -->|"runs"| node_stage2_py
node_stage0_py -->|"uses"| node_prep_mask_py
node_stage0_py -->|"uses"| node_data_proc_py
node_stage0_py -->|"uses"| node_multiview_py
node_stage1_py -->|"uses"| node_vggt_py
node_stage1_py -->|"uses"| node_track_head_py
node_stage1_py -->|"uses"| node_camera_head_py
node_stage1_py -->|"uses"| node_vit_py
node_stage1_py -->|"feeds"| node_align_py
node_stage1a_py -->|"updates"| node_pointcloud_py
node_stage1a_py -->|"feeds"| node_align_py
node_stage1b_py -->|"uses"| node_core_render_py
node_cam_traj_py -->|"uses"| node_traj_py
node_cam_traj_py -->|"uses"| node_config_py
node_render_py -->|"uses"| node_core_render_py
node_render_py -->|"uses"| node_camera_py
node_core_render_py -->|"reads"| node_pointcloud_py
node_align_py -->|"produces"| node_pointcloud_py
node_data_proc_py -->|"uses"| node_camera_py
node_vggt_py -->|"contains"| node_track_head_py
node_vggt_py -->|"contains"| node_camera_head_py
node_vggt_py -->|"built on"| node_vit_py
node_stage2_py -->|"uses"| node_genmodels_dir
node_stage2_py -->|"uses"| node_diffsynth_dir

click node_run_pipeline_py "https://github.com/vveicao/freeorbit4d/blob/main/run_pipeline.py"
click node_full_pipeline_py "https://github.com/vveicao/freeorbit4d/blob/main/pipeline/full_pipeline.py"
click node_stage0_py "https://github.com/vveicao/freeorbit4d/blob/main/pipeline/stage_0_pipeline.py"
click node_stage1_py "https://github.com/vveicao/freeorbit4d/blob/main/pipeline/stage_1_pipeline.py"
click node_stage1a_py "https://github.com/vveicao/freeorbit4d/blob/main/pipeline/stage_1a_pointcloud_pipeline.py"
click node_stage1b_py "https://github.com/vveicao/freeorbit4d/blob/main/pipeline/stage_1b_rendering_pipeline.py"
click node_stage2_py "https://github.com/vveicao/freeorbit4d/blob/main/pipeline/stage_2_pipeline.py"
click node_prep_mask_py "https://github.com/vveicao/freeorbit4d/blob/main/scripts/prep_interactive_mask.py"
click node_cam_traj_py "https://github.com/vveicao/freeorbit4d/blob/main/scripts/1_3_cam_traj.py"
click node_render_py "https://github.com/vveicao/freeorbit4d/blob/main/scripts/1_4_rendering.py"
click node_data_proc_py "https://github.com/vveicao/freeorbit4d/blob/main/core/data_processor.py"
click node_multiview_py "https://github.com/vveicao/freeorbit4d/blob/main/core/multiview.py"
click node_align_py "https://github.com/vveicao/freeorbit4d/blob/main/core/alignment.py"
click node_pointcloud_py "https://github.com/vveicao/freeorbit4d/blob/main/core/pointcloud.py"
click node_core_render_py "https://github.com/vveicao/freeorbit4d/blob/main/core/rendering.py"
click node_vggt_py "https://github.com/vveicao/freeorbit4d/blob/main/page-4d/vggt/models/vggt.py"
click node_track_head_py "https://github.com/vveicao/freeorbit4d/blob/main/page-4d/vggt/heads/track_head.py"
click node_camera_head_py "https://github.com/vveicao/freeorbit4d/blob/main/page-4d/vggt/heads/camera_head.py"
click node_vit_py "https://github.com/vveicao/freeorbit4d/blob/main/page-4d/vggt/layers/vision_transformer.py"
click node_diffsynth_dir "https://github.com/vveicao/freeorbit4d/tree/main/DiffSynth-Studio"
click node_genmodels_dir "https://github.com/vveicao/freeorbit4d/tree/main/generative-models"
click node_config_py "https://github.com/vveicao/freeorbit4d/blob/main/utils/config.py"
click node_camera_py "https://github.com/vveicao/freeorbit4d/blob/main/utils/camera.py"
click node_traj_py "https://github.com/vveicao/freeorbit4d/blob/main/utils/trajectory.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_run_pipeline_py,node_full_pipeline_py toneBlue
class node_stage0_py,node_stage1_py,node_stage1a_py,node_stage1b_py,node_stage2_py,node_prep_mask_py,node_cam_traj_py,node_render_py toneAmber
class node_data_proc_py,node_multiview_py,node_align_py,node_pointcloud_py,node_core_render_py toneMint
class node_vggt_py,node_track_head_py,node_camera_head_py,node_vit_py toneRose
class node_diffsynth_dir,node_genmodels_dir toneIndigo
class node_config_py,node_camera_py,node_traj_py toneTeal
```

## Components

### Orchestration

Top-level entrypoints and pipeline dispatch.

- [Run pipeline](https://github.com/vveicao/freeorbit4d/blob/main/run_pipeline.py): entrypoint · Main command-line entry for selecting the full or stage-specific pipeline. · `run_pipeline.py`
- [Full pipeline](https://github.com/vveicao/freeorbit4d/blob/main/pipeline/full_pipeline.py): orchestrator · Coordinates the end-to-end multi-stage processing flow. · `pipeline/full_pipeline.py`

### Pipeline stages

Stage-by-stage video-to-4D processing and rendering.

- [Stage 0](https://github.com/vveicao/freeorbit4d/blob/main/pipeline/stage_0_pipeline.py): pipeline stage · Initial video and data preparation stage. · `pipeline/stage_0_pipeline.py`
- [Stage 1](https://github.com/vveicao/freeorbit4d/blob/main/pipeline/stage_1_pipeline.py): pipeline stage · Primary reconstruction stage. · `pipeline/stage_1_pipeline.py`
- [Pointcloud stage](https://github.com/vveicao/freeorbit4d/blob/main/pipeline/stage_1a_pointcloud_pipeline.py): pipeline stage · Point-cloud-centric reconstruction and fusion stage. · `pipeline/stage_1a_pointcloud_pipeline.py`
- [Rendering stage](https://github.com/vveicao/freeorbit4d/blob/main/pipeline/stage_1b_rendering_pipeline.py): pipeline stage · View synthesis and rendering stage. · `pipeline/stage_1b_rendering_pipeline.py`
- [Stage 2](https://github.com/vveicao/freeorbit4d/blob/main/pipeline/stage_2_pipeline.py): pipeline stage · Final generative refinement or downstream synthesis stage. · `pipeline/stage_2_pipeline.py`
- [Mask prep](https://github.com/vveicao/freeorbit4d/blob/main/scripts/prep_interactive_mask.py): interactive tool · Gradio-based tool for interactive mask creation and scene config setup. · `scripts/prep_interactive_mask.py`
- [Camera traj](https://github.com/vveicao/freeorbit4d/blob/main/scripts/1_3_cam_traj.py): trajectory editor · Interactive camera-path authoring for rerendering. · `scripts/1_3_cam_traj.py`
- [Render run](https://github.com/vveicao/freeorbit4d/blob/main/scripts/1_4_rendering.py): render driver · Consumes trajectories and reconstructed scene data to generate the output video. · `scripts/1_4_rendering.py`

### Geometry core

Shared reconstruction, alignment, and rendering logic.

- [Data proc](https://github.com/vveicao/freeorbit4d/blob/main/core/data_processor.py): scene prep · Converts raw video and masks into structured frame-level inputs. · `core/data_processor.py`
- [Multiview](https://github.com/vveicao/freeorbit4d/blob/main/core/multiview.py): view builder · Builds multiview or pseudo-view inputs for downstream geometry estimation. · `core/multiview.py`
- [Alignment](https://github.com/vveicao/freeorbit4d/blob/main/core/alignment.py): geometry fusion · Aligns model outputs into a coherent scene representation. · `core/alignment.py`
- [Point cloud](https://github.com/vveicao/freeorbit4d/blob/main/core/pointcloud.py): scene proxy · Represents the reconstructed 3D/4D proxy geometry. · `core/pointcloud.py`
- [Core render](https://github.com/vveicao/freeorbit4d/blob/main/core/rendering.py): synthesis · Renders images from the reconstructed geometry and camera state. · `core/rendering.py`

### Learned models

VGGT-based model implementations used by reconstruction.

- [VGGT model](https://github.com/vveicao/freeorbit4d/blob/main/page-4d/vggt/models/vggt.py): transformer model · Main learned reconstruction model wrapper. · `page-4d/vggt/models/vggt.py`
- [Track head](https://github.com/vveicao/freeorbit4d/blob/main/page-4d/vggt/heads/track_head.py): tracking head · Predicts feature tracks used for geometry recovery. · `page-4d/vggt/heads/track_head.py`
- [Camera head](https://github.com/vveicao/freeorbit4d/blob/main/page-4d/vggt/heads/camera_head.py): pose head · Estimates camera parameters and pose-related outputs. · `page-4d/vggt/heads/camera_head.py`
- [ViT layers](https://github.com/vveicao/freeorbit4d/blob/main/page-4d/vggt/layers/vision_transformer.py): backbone layers · Transformer and attention layers used by the VGGT stack. · `page-4d/vggt/layers/vision_transformer.py`

### External stacks

Vendored or external components used downstream or as dependencies.

- [DiffSynth](https://github.com/vveicao/freeorbit4d/tree/main/DiffSynth-Studio): vendored external · Vendored external synthesis stack used for downstream generation. · `DiffSynth-Studio`
- [Gen models](https://github.com/vveicao/freeorbit4d/tree/main/generative-models): vendored external · Bundled generative video tooling for refinement or synthesis. · `generative-models`

### Support code

Shared config, camera, and trajectory utilities.

- [Config](https://github.com/vveicao/freeorbit4d/blob/main/utils/config.py): shared config · Loads and interprets scene and pipeline configuration. · `utils/config.py`
- [Camera utils](https://github.com/vveicao/freeorbit4d/blob/main/utils/camera.py): camera math · Camera and projection helpers shared across stages. · `utils/camera.py`
- [Trajectory utils](https://github.com/vveicao/freeorbit4d/blob/main/utils/trajectory.py): path utils · Helpers for camera trajectory representation and conversion. · `utils/trajectory.py`

## Connections

- Run pipeline → Full pipeline: dispatches · Entry point selects and launches the full pipeline.
- Run pipeline → Stage 0: dispatches · Entry point can invoke stage-specific execution.
- Run pipeline → Stage 1: dispatches · Entry point can invoke stage-specific execution.
- Run pipeline → Rendering stage: dispatches · Entry point can invoke stage-specific execution.
- Full pipeline → Stage 0: runs · Full pipeline begins with data preparation.
- Full pipeline → Stage 1: runs · Full pipeline proceeds into reconstruction.
- Full pipeline → Pointcloud stage: runs · Full pipeline includes point-cloud-centric processing.
- Full pipeline → Rendering stage: runs · Full pipeline includes rendering synthesis.
- Full pipeline → Stage 2: runs · Full pipeline can continue into refinement.
- Stage 0 → Mask prep: uses · Stage 0 depends on prepared masks and scene setup for custom videos.
- Stage 0 → Data proc: uses · Stage 0 prepares frame data and masks.
- Stage 0 → Multiview: uses · Stage 0 constructs multiview inputs.
- Stage 1 → VGGT model: uses · Reconstruction is driven by the learned VGGT model.
- Stage 1 → Track head: uses · Model predicts tracks as part of reconstruction.
- Stage 1 → Camera head: uses · Model estimates camera outputs for geometry recovery.
- Stage 1 → ViT layers: uses · Transformer backbone underpins the model stack.
- Stage 1 → Alignment: feeds · Raw model outputs are aligned into a coherent scene.
- Pointcloud stage → Point cloud: updates · Point-cloud stage manages the scene proxy representation.
- Pointcloud stage → Alignment: feeds · Alignment consolidates foreground and background geometry.
- Rendering stage → Core render: uses · Rendering stage synthesizes output views from reconstructed data.
- Camera traj → Trajectory utils: uses · Interactive editor produces camera path data.
- Camera traj → Config: uses · Trajectory authoring is scene-config driven.
- Render run → Core render: uses · Rendering script calls shared synthesis logic.
- Render run → Camera utils: uses · Rendering consumes camera trajectory and projection helpers.
- Core render → Point cloud: reads · Renderer consumes the fused scene proxy.
- Alignment → Point cloud: produces · Alignment fuses estimates into the point-cloud representation.
- Data proc → Camera utils: uses · Scene preparation relies on camera and projection utilities.
- VGGT model → Track head: contains · VGGT bundles tracking outputs.
- VGGT model → Camera head: contains · VGGT bundles pose and camera estimation outputs.
- VGGT model → ViT layers: built on · VGGT is implemented on transformer backbone layers.
- Stage 2 → Gen models: uses · Final refinement relies on bundled generative tooling.
- Stage 2 → DiffSynth: uses · Downstream synthesis may call into the vendored external stack.
