# by-luckk/physgen3d architecture

> Architecture diagram of the GitHub repository by-luckk/physgen3d, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/by-luckk/physgen3d
- Repository: https://github.com/by-luckk/physgen3d

## Overview

##### Main Components and Their Roles
- Input & Data:
– "data" folder holds raw image data (under data/img) and HDR environment maps (data/hdr) used for lighting in rendering.
– "configs" contains configuration files (e.g., GroundingDINO, lama-prediction, mpm configurations) that control various stages.
- Perception Module:
– Executed via perception.py, this module processes a given input image (e.g., teddy.jpg), extracts depth information, object masks, and creates initial meshes. It outputs intermediate files (depth, inpainted images, masks, reconstructed meshes, etc.) into an organized “outputs” folder.
- Simulation Module:
– Managed by simulation.py (and supported by additional scripts such as ball_sim.py and mpm_sim.py), the simulation module reads configuration parameters (from the data/sim folder) to simulate physical behavior. This module applies the physics engine provided in the "engine" folder (which includes core solvers, mesh IO, voxelizers, etc.) and writes simulation results into its dedicated output folder.
- Rendering Module:
– Triggered by rendering.py. It takes the simulation results and perception outputs to produce final visuals. HDR backgrounds, camera settings, and rendering parameters are configured (from command-line arguments and external config files) to generate images and video outputs.
- Engine and Supporting Tools:
– The "engine" folder encapsulates the core physics and simulation functionalities (e.g., mpm_solver, particle_io, renderer) whereas additional modules like “my_instant_mesh.py” and “my_dust3r.py” support specialized tasks.
– The "inverse", "locate", and "mesh_utils.py" files assist in different stages of geometry and object registration.
– Submodules (e.g., instant_mesh, GroundingDINO, dust3r, lama) integrate external repositories and state-of-the-art models for mesh generation, superpoint matching, and transformer-based decoding.

##### Relationships and Data Flow
– Raw images and HDR data from the “data” directory.
– Configuration inputs from “configs.”
- Next, illustrate the Perception component:
– Show that perception.py receives the input image and text prompt.
– Indicate outputs (object masks, point clouds, inpainted images, meshes) being stored in a structured “outputs” directory.
– Simulation.py uses configuration data (from data/sim) and the outputs of the Perception module (e.g., initial meshes, detected geometries).
– Under this, include the core functionality from the “engine” folder that provides solvers and simulation routines.
- On the right-hand side, add the Rendering component:
– Connect the simulation results and perception outputs as inputs to rendering.py.
– Highlight that rendering employs HDR environments and produces final visuals (images and videos).
- Auxiliary components (e.g., "locate", "inverse") as supporting modules that feed into perception or simulation as needed.

##### Important Architectural Patterns and Technologies
- Modular Pipeline: Emphasize separation of concerns where perception, simulation, and rendering are distinct yet interconnected.
- Integration via Submodules: Note the architecture leverages external models and code (e.g., instant_mesh, GroundingDINO) which are integrated as submodules.
- Dependency Flow: Detail how configuration management and external dependencies (install scripts in env_install) facilitate the entire workflow.
- Use of TAICHI-Elements: The “engine” directory’s role in providing physics simulation routines based on taichi-elements is crucial.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input & Data
    subgraph "Input & Data"
        A1["Raw Image Data & HDR (data)"]:::input
        A2["Configuration Files (configs)"]:::input
    end

    %% Perception Module
    subgraph "Perception"
        P1["perception.py (Extracts depth, masks, meshes)"]:::perception
        P2["Outputs (object masks, point clouds, inpainted images, meshes)"]:::perception
    end

    %% Simulation Module
    subgraph "Simulation"
        S1["simulation.py (Handles physics simulation)"]:::simulation
        S2["Simulation Config (data/sim)"]:::simulation
        S3["Engine Core (engine)"]:::simulation
    end

    %% Rendering Module
    subgraph "Rendering"
        R1["rendering.py (Generates final visuals)"]:::rendering
    end

    %% Supporting Tools
    subgraph "Supporting Tools"
        ST1["Inverse Functions (inverse)"]:::engine
        ST2["Locate & Match (locate)"]:::engine
        ST3["Mesh Utility (mesh_utils.py)"]:::engine
        ST4["Specialized Mesh (my_instant_mesh.py)"]:::engine
        ST5["Specialized Dust (my_dust3r.py)"]:::engine
    end

    %% External Submodules
    subgraph "External Submodules"
        ES1["GroundingDINO (submodules)"]:::external
        ES2["Dust3r (submodules)"]:::external
        ES3["Instant Mesh (submodules)"]:::external
        ES4["Lama (submodules)"]:::external
    end

    %% Data Flow Connections
    A1 -->|"feeds"| P1
    A2 -->|"configures"| P1
    P1 -->|"generates"| P2
    P2 -->|"supplies"| S1
    S2 -->|"configures"| S1
    S1 -->|"executes"| S3
    S1 -->|"provides_results"| R1
    S3 -->|"sends_results"| R1

    %% Supporting Tools Integration
    ST1 -->|"supports"| P1
    ST2 -->|"supports"| S1
    ST3 -->|"assists"| S1
    ST4 -->|"enhances"| S1
    ST5 -->|"enhances"| S1

    %% External Submodules Integration
    ES1 -->|"integrated"| P1
    ES2 -->|"integrated"| S1
    ES3 -->|"integrated"| S1
    ES4 -->|"integrated"| S1

    %% Styles
    classDef input fill:#b3cde0,stroke:#1f78b4,stroke-width:2px;
    classDef perception fill:#a6cee3,stroke:#1f78b4,stroke-width:2px;
    classDef simulation fill:#b2df8a,stroke:#33a02c,stroke-width:2px;
    classDef rendering fill:#fdbf6f,stroke:#ff7f00,stroke-width:2px;
    classDef engine fill:#cab2d6,stroke:#6a3d9a,stroke-width:2px;
    classDef external fill:#fb9a99,stroke:#e31a1c,stroke-width:2px;

    %% Click Events
    click A1 "https://github.com/by-luckk/physgen3d/tree/main/data/"
    click A2 "https://github.com/by-luckk/physgen3d/tree/main/configs/"
    click P1 "https://github.com/by-luckk/physgen3d/blob/main/perception.py"
    click S1 "https://github.com/by-luckk/physgen3d/blob/main/simulation.py"
    click S2 "https://github.com/by-luckk/physgen3d/tree/main/data/sim/"
    click S3 "https://github.com/by-luckk/physgen3d/tree/main/engine/"
    click R1 "https://github.com/by-luckk/physgen3d/blob/main/rendering.py"
    click ST1 "https://github.com/by-luckk/physgen3d/tree/main/inverse/"
    click ST2 "https://github.com/by-luckk/physgen3d/tree/main/locate/"
    click ST3 "https://github.com/by-luckk/physgen3d/blob/main/mesh_utils.py"
    click ST4 "https://github.com/by-luckk/physgen3d/blob/main/my_instant_mesh.py"
    click ST5 "https://github.com/by-luckk/physgen3d/blob/main/my_dust3r.py"
    click ES1 "https://github.com/by-luckk/physgen3d/tree/main/submodules/GroundingDINO"
    click ES2 "https://github.com/by-luckk/physgen3d/tree/main/submodules/dust3r"
    click ES3 "https://github.com/by-luckk/physgen3d/tree/main/submodules/instant_mesh"
    click ES4 "https://github.com/by-luckk/physgen3d/tree/main/submodules/lama"
```
