# ark-tik/proceduralmeshgenerator architecture

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

- Interactive diagram: https://gitdiagram.com/ark-tik/proceduralmeshgenerator
- Repository: https://github.com/ark-tik/proceduralmeshgenerator

## Overview

Based on your project’s file tree and README, ProceduralMeshGenerator is a C++-based tool designed to help 3D artists automatically generate multiple variations of a base humanoid model. It leverages several third-party libraries (Assimp for model importing, GLAD/GLFW for OpenGL context and windowing, GLM for mathematical operations, freetype for font handling) and even integrates an immediate-mode GUI via ImGui to possibly allow interactive vertex selection and model adjustments.

##### Project Type and Purpose
- This is a desktop procedural mesh generation tool with a focus on 3D model manipulation and rendering.
- The expected use-case involves processing 3D models, altering them procedurally (potentially at the level of mesh, body parts, and textures), and rendering these variants for a 3D artist’s review.
- The README and file structure indicate that while it is still a work in progress, the tool already has distinct components for model processing, real-time rendering via OpenGL (using GLFW and GLAD), shader management, camera control, and interaction hooks (like triangle picking for vertex selection).

##### Core Components
a. Application Core/Engine:
- Application Module: Likely housed in Application.cpp, acting as the entry point, handling the initialization and overall control flow.
- Renderer: Includes Renderer.cpp and Shader*.cpp files, managing the rendering pipeline, shader compilation, and rendering passes.
- Mesh, Model, and BodyPart Modules: Essential for building and manipulating the 3D models; Mesh.cpp, Model.cpp, and BodyPart.cpp represent the procedural generation logic.
- Camera: Manages the viewpoint and projection parameters (see Camera.cpp) for rendering the scene.
- Utility Modules: Including CheckGLErrors (for error handling) and TrianglePicking (for user interaction with 3D geometry).

b. Graphics and Rendering:
- Dependencies for OpenGL initialization: GLAD and GLFW ensure context management.
- Shader System: Represent the shader source files (both vertex and fragment shaders) as key parts of the graphics pipeline.
- Mathematical Library: GLM supplies math operations (vectors, matrices) that underpin transformations, lighting, and camera calculations.
- Image and Texture Loading: stb_image (embedded inside src/expat/stb_image) likely handles texture loading.

c. External and Auxiliary Dependencies:
- Assimp: For importing external 3D models (could be used to load the base humanoid model or parts of it).
- freetype: For handling text outputs (possibly for UI or debugging overlays).
- ImGui: Found under src/expat/imgui, enabling GUI interaction for manipulation and possibly debugging.
- Additional resources and shaders: The “res” and “src/shaders” directories house assets, materials, and shader programs.

##### Relationships and Interactions
- The Application module initializes the system and orchestrates interactions among the core engine components.
- The Renderer interacts with the Mesh/Model data structures and uses GLAD/GLFW to control the OpenGL rendering context.
- The Camera module sets up view and projection matrices that the Renderer passes to the shaders.
- User interactions (handled by the ImGui interface and TrianglePicking) provide inputs which modify the procedural generation logic—altering body parts and meshes.
- External libraries (Assimp, freetype, GLM) provide additional functionality that integrates directly within these components.

##### Architectural Patterns and Design Principles
- Layered Architecture: Separate the system into clear layers such as Input/UI, Core Processing & Procedural Generation, Render Engine, and External Library Integration.
- Modular Design: Each component (e.g., Mesh, Renderer, Camera) is encapsulated in its own module, which promotes maintainability and extensibility.
- Separation of Concerns: The use of dedicated shader sources, external dependency structures, and specialized utilities like error-checking fosters a robust design.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Engine/Initialization"
        A["Application Core/Engine"] 
    end

    subgraph "Core Procedural Mesh Ops"
        M["Mesh"]
        Mo["Model"]
        BP["BodyPart"]
        TP["TrianglePicking"]
        CG["CheckGLErrors"]
    end

    subgraph "Graphics/Rendering Pipeline"
        R["Renderer Module"]
        S["Shader System"]
        C["Camera"]
        G["GLAD"]
        Fw["GLFW"]
        TI["stb_image (Texture Loader)"]
    end

    subgraph "User Interface and Interaction"
        I["ImGui"]
    end

    subgraph "External Dependencies"
        As["Assimp"]
        Gm["GLM"]
        Ft["freetype"]
    end

    A -->|"initializes"| R
    A -->|"calls"| CG
    M -->|"sendsMeshData"| R
    Mo -->|"providesModelData"| R
    BP -->|"modifiesBodyParts"| R
    TP -->|"modifiesMesh"| M
    TP -->|"influencesModel"| Mo
    TP -->|"influencesBodyPart"| BP
    I -->|"triggers"| TP
    R -->|"compilesShaders"| S
    R -->|"receivesCameraInput"| C
    R -->|"utilizesGLAD"| G
    R -->|"utilizesGLFW"| Fw
    R -->|"loadsTextures"| TI
    CG -->|"checksForErrors"| R
    As -->|"importsModel"| Mo
    Gm -->|"calculatesView"| C
    Gm -->|"supportsTransforms"| R
    Ft -->|"rendersFonts"| I

    click A "https://github.com/ark-tik/proceduralmeshgenerator/blob/master/ProceduralMeshGenerator/src/Application.cpp"
    click R "https://github.com/ark-tik/proceduralmeshgenerator/blob/master/ProceduralMeshGenerator/src/Renderer.cpp"
    click S "https://github.com/ark-tik/proceduralmeshgenerator/blob/master/ProceduralMeshGenerator/src/Shader.cpp"
    click M "https://github.com/ark-tik/proceduralmeshgenerator/blob/master/ProceduralMeshGenerator/src/Mesh.cpp"
    click Mo "https://github.com/ark-tik/proceduralmeshgenerator/blob/master/ProceduralMeshGenerator/src/Model.cpp"
    click BP "https://github.com/ark-tik/proceduralmeshgenerator/blob/master/ProceduralMeshGenerator/src/BodyPart.cpp"
    click C "https://github.com/ark-tik/proceduralmeshgenerator/blob/master/ProceduralMeshGenerator/src/Camera.cpp"
    click CG "https://github.com/ark-tik/proceduralmeshgenerator/blob/master/ProceduralMeshGenerator/src/CheckGLErrors.cpp"
    click TP "https://github.com/ark-tik/proceduralmeshgenerator/blob/master/ProceduralMeshGenerator/src/TrianglePicking.cpp"
    click I "https://github.com/ark-tik/proceduralmeshgenerator/tree/master/ProceduralMeshGenerator/src/expat/imgui"
    click G "https://github.com/ark-tik/proceduralmeshgenerator/blob/master/ProceduralMeshGenerator/src/glad.c"
    click Fw "https://github.com/ark-tik/proceduralmeshgenerator/tree/master/Dependencies/GLFW"
    click As "https://github.com/ark-tik/proceduralmeshgenerator/tree/master/Dependencies/Assimp"
    click Gm "https://github.com/ark-tik/proceduralmeshgenerator/tree/master/Dependencies/GLM"
    click Ft "https://github.com/ark-tik/proceduralmeshgenerator/tree/master/Dependencies/freetype"
    click TI "https://github.com/ark-tik/proceduralmeshgenerator/tree/master/ProceduralMeshGenerator/src/expat/stb_image"

    classDef engine fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef core fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef rendering fill:#FFA500,stroke:#333,stroke-width:2px;
    classDef ui fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px;

    class A engine;
    class M,Mo,BP,TP,CG core;
    class R,S,C,G,Fw,TI rendering;
    class I ui;
    class As,Gm,Ft external;
```
