# sesamepaste233/starfieldmeshconverter architecture

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

- Interactive diagram: https://gitdiagram.com/sesamepaste233/starfieldmeshconverter
- Repository: https://github.com/sesamepaste233/starfieldmeshconverter

## Overview

##### Project Type and Purpose
- The project is a Blender plugin – designed to export models, morph targets, geometry, and physics data from Blender to be used with Starfield.
- Its purpose is to provide a single-click solution that integrates with Blender (versions 3.5/3.6 only) to convert and export data in multiple formats, including physics information.
- The README also notes a community aspect and open-source nature along with integration concerns (reverse-engineering and appropriate usage in mods).

##### Analysis of the File Structure
- Top-Level Structure:
– Files such as MeshConverter.sln, MeshConverter.vcxproj indicate a Visual Studio C++ solution.
– The “include” and “src” directories contain the core C++ source code.
– “scripts” include several Python-based tools grouped into subdirectories:
- tool_batch_process – for batch operations using Python.
- tool_export_mesh – handling mesh export with several specialized modules (BoneRegions, Material conversion, etc.).
- tool_physics_editor – a set of Python tools for editing, visualizing, and managing physics data.
– The “dist” directory packages these tools into deliverable zip archives.
– “SFGBDocs” holds the documentation files, which further suggest the plugin supports complex features (cloth physics, etc.).
- Architectural Patterns:
– The project is modular: different tools for mesh conversion, batch processing, and physics editing indicate multiple entry points or microservice-like components within the plugin ecosystem.

##### Key Components
a. Frontend / Integration (Blender Plugin Interface):
– The plugin UI and possibly event handlers within Blender (via Python scripts).
b. Core Engine (C++ Backend):
– “Main Application” or “MeshConverter Core” that includes entry point (Main.cpp) and core libraries such as:
- Mesh IO, Morph IO, Nif IO modules.
- Physics modules (handling cloth data, physics state, constraints; evident from hcl* and hknp* files).
- Utility libraries (Common.cpp, Utils.cpp).
c. Tools and Extensions (Python Tools):
- Batch Processing Tool (tool_batch_process)
- Mesh Export Tool (tool_export_mesh)
- Physics Editor Tool (tool_physics_editor)
– These represent additional UI components or scripts triggered by the plugin to perform specific tasks.
d. External Dependencies:
– Nodes for the JSON library, DirectXMesh, Eigen, and Miniball showing how these external libraries are integrated into the core engine.
e. Data Files and Resources:
– Indicate the presence of configuration and binary data files (such as physics_data.bin, profiler data files) that are consumed or produced.

##### Relationships and Interactions
- Data Flow:
– The plugin front end interacts with the Python scripts, which in turn communicate with the C++ backend modules.
– The C++ engine’s modules interact with each other (e.g., MeshIO module calls on Geometry and Physics modules) and use external libraries for processing.
- Dependencies:
– There is a clear dependency relationship from the backend core to the external libraries (for JSON parsing, geometry processing, etc.).
– Similarly, the Python tools (e.g., the physics editor) likely rely on the C++ libraries either through bindings or file-based data exchange.
- Integration:
– Tools in “scripts” may also have their own internal MVC-like separation between logic (operators), data (model files), and presentation (panels/forms).

##### Specific Elements
– “MeshConverter Core” for the C++ engine.
– “Blender Plugin Interface” for the integration with Blender.
– “Mesh Export Tool”, “Batch Processing Tool”, “Physics Editor” for the Python scripts.
– From the Blender UI into the Python tools.
– From Python tools into the core engine.
- Dependency elements for external libraries:
– For example, illustrate that the MeshConverter core calls out to JSON, DirectXMesh, Eigen, and Miniball.
– For distinguishing between C++ modules, Python scripts, and external dependencies.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Layer: Blender Plugin
    A["Blender Plugin Interface (Python)"]:::python

    %% Python Tools Layer
    subgraph "Python Tools"
        B["Batch Processing Tool (Python)"]:::python
        C["Mesh Export Tool (Python)"]:::python
        D["Physics Editor Tool (Python)"]:::python
    end

    %% C++ Core Engine Layer with Internal Modules
    subgraph "MeshConverter Core (C++)"
        X["Core Engine"]:::cpp
        E["MeshIO Module"]:::cpp
        F["MorphIO Module"]:::cpp
        G["NifIO Module"]:::cpp
        H["Physics Converter"]:::cpp
        I["Utility Library"]:::cpp
        X --> E
        X --> F
        X --> G
        X --> H
        X --> I
        %% Internal communication between modules
        E -->|"transfersData"| H
    end

    %% External Dependencies Layer
    J["nlohmann/json"]:::external
    K["DirectXMesh"]:::external
    L["Eigen"]:::external
    M["Miniball"]:::external

    %% Relationships from Blender Plugin to Python Tools
    A -->|"invokes"| B
    A -->|"invokes"| C
    A -->|"invokes"| D

    %% Relationships from Python Tools to C++ Core Engine
    B -->|"callsCore"| X
    C -->|"callsCore"| X
    D -->|"callsCore"| X

    %% Relationship from Core Engine to External Dependencies
    X -->|"uses"| J
    X -->|"uses"| K
    X -->|"uses"| L
    X -->|"uses"| M

    %% Click Events for Component Mappings
    click A "https://github.com/sesamepaste233/starfieldmeshconverter/blob/master/scripts/tool_export_mesh/MeshConverter.py"
    click X "https://github.com/sesamepaste233/starfieldmeshconverter/blob/master/src/Main.cpp"
    click X "https://github.com/sesamepaste233/starfieldmeshconverter/blob/master/include/MeshConverter.h"
    click B "https://github.com/sesamepaste233/starfieldmeshconverter/tree/master/scripts/tool_batch_process"
    click C "https://github.com/sesamepaste233/starfieldmeshconverter/tree/master/scripts/tool_export_mesh"
    click D "https://github.com/sesamepaste233/starfieldmeshconverter/tree/master/scripts/tool_physics_editor"

    %% Styles for Color Coding
    classDef python fill:#C8E6C9,stroke:#388E3C,stroke-width:2px,color:#000;
    classDef cpp fill:#FFE082,stroke:#F57F17,stroke-width:2px,color:#000;
    classDef external fill:#FFCDD2,stroke:#C62828,stroke-width:2px,color:#000;
```
