# aniketrajnish/4d-engine-unity architecture

> Architecture diagram of the GitHub repository aniketrajnish/4d-engine-unity, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aniketrajnish/4d-engine-unity
- Repository: https://github.com/aniketrajnish/4d-engine-unity

## Overview

##### Main Components
- Engine Framework: The Unity ecosystem where the project lives (including the Scene, Main Camera, and overall project settings).
- Raymarching Core: The central part of the engine comprising the Raymarcher, RaymarchRenderer, RaymarchCollision, and related helper scripts. These components connect to the Main Camera (which has the Raymarcher attached) and are responsible for executing the raymarching algorithm.
- Shaders: Your shader assets are housed in Assets/Shaders. They drive the rendering of the 4D raymarcher (e.g., ImageEffectRaymarcher, Skybox shaders, and shader helper include files). This component interacts directly with the Raymarcher component.
- Editor Tools & UI: Custom editor scripts (like PropertiesEditor under Assets/Editor) and scene view filters that enhance usability in Unity for setting up and previewing 4D scenes.
- Utility & Event System: Modules such as the Event Center and other utility scripts (under Assets/Scripts/Utils) that manage event handling, math utilities, and scene view filtering.

##### Relationships and Data Flows
- How the Main Camera incorporates the Raymarcher component, which sends its computed parameters to the shaders.
- That the Editor Tools (e.g., the PropertiesEditor script) facilitate changes in inspector values that affect the Raymarcher and RaymarchRenderer.

##### Architectural Patterns/Design Principles
- Use the Observer/Events pattern as implemented via the Event Center, which decouples components.
- Separation between data (ScriptableObjects for dimensions) and functionality (scripts that process and pass the data to the shader).
- Multi-layered approach where high-level scene management (via Unity’s Scene system) interacts with low-level rendering (via custom shaders and raymarching algorithms).

##### Incorporate the Relevant Technologies and Frameworks
- Unity Engine (including specific ProjectSettings and Package references, like Unity.Mathematics).
- Custom shader development (using CG/HLSL includes for raymarching and skybox effects).
- Scriptable Objects for data management.
- Custom editor extensions that enhance the default Unity editor behavior.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Unity Environment"
        EF("Engine Framework (Test Scene)"):::unity
        MC("Main Camera (with Raymarcher)"):::unity
    end

    subgraph "Core Functional Modules"
        RM("Raymarching Core<br/>(Renderer,Raymarcher,Collision,Helpers)"):::core
    end

    subgraph "4D Shape Management"
        SO("Scriptable Objects (4D Shapes)"):::data
        SD("ShapeDimensions.cs"):::data
    end

    subgraph "Shader System"
        RS("Raymarching Shaders"):::shader
        SS("Skybox Shaders"):::shader
    end

    subgraph "Editor & Utility Components"
        PE("PropertiesEditor"):::editor
        EC("Event Center"):::utils
        SVF("Scene View Filter"):::utils
        SMU("Shader Math Utils"):::utils
    end

    EF --> MC
    MC --> RM
    SO --> RM
    SD --> SO
    RM -->|"sendsParams"| RS
    RM -->|"updatesSkybox"| SS
    PE -->|"inspectorUpdates"| RM
    EC -->|"notifiesChanges"| RM
    EC -->|"updatesShapes"| SO
    EC --> SVF
    EC --> SMU

    click EF "https://github.com/aniketrajnish/4d-engine-unity/blob/main/4D Engine Unity/Assets/Scenes/Test.unity"
    click RM "https://github.com/aniketrajnish/4d-engine-unity/tree/main/4D Engine Unity/Assets/Scripts/Raymarching Engine"
    click SO "https://github.com/aniketrajnish/4d-engine-unity/tree/main/4D Engine Unity/Assets/ScriptableObjects"
    click SD "https://github.com/aniketrajnish/4d-engine-unity/blob/main/4D Engine Unity/Assets/Scripts/Scriptable Objects/ShapeDimensions.cs"
    click RS "https://github.com/aniketrajnish/4d-engine-unity/tree/main/4D Engine Unity/Assets/Shaders/Raymarcher"
    click SS "https://github.com/aniketrajnish/4d-engine-unity/tree/main/4D Engine Unity/Assets/Shaders/Skybox"
    click PE "https://github.com/aniketrajnish/4d-engine-unity/blob/main/4D Engine Unity/Assets/Editor/PropertiesEditor.cs"
    click EC "https://github.com/aniketrajnish/4d-engine-unity/tree/main/4D Engine Unity/Assets/Scripts/Utils/Event Center"
    click SVF "https://github.com/aniketrajnish/4d-engine-unity/blob/main/4D Engine Unity/Assets/Scripts/Utils/Scene View Filter/SceneViewFilter.cs"
    click SMU "https://github.com/aniketrajnish/4d-engine-unity/blob/main/4D Engine Unity/Assets/Scripts/Utils/Shader Math Utils/MakraMathUtils.cs"

    classDef unity fill:#f9c,stroke:#333,stroke-width:2px;
    classDef core fill:#bbf,stroke:#333,stroke-width:2px;
    classDef data fill:#dfd,stroke:#333,stroke-width:2px;
    classDef shader fill:#ffd,stroke:#333,stroke-width:2px;
    classDef editor fill:#cfc,stroke:#333,stroke-width:2px;
    classDef utils fill:#fcc,stroke:#333,stroke-width:2px;
```
