# ovi-lab/vicon-nexus-unity-stream architecture

> Architecture diagram of the GitHub repository ovi-lab/vicon-nexus-unity-stream, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ovi-lab/vicon-nexus-unity-stream
- Repository: https://github.com/ovi-lab/vicon-nexus-unity-stream

## Overview

##### And sketch the main components
- External Vicon Nexus Service:
- This is represented by the Vicon Nexus Unity Stream Python package (external to this Unity project) that streams motion capture data.
- Communication Layer:
- The WebSocket component (found under Assets/Scripts/WebSockets) handles the network communication between Vicon Nexus and the Unity runtime.
- Core Unity Module:
- ViconNexusUnityStream Package: Highlight the scripts responsible for processing streaming data; these include classes for managing stream data (ViconStreamData.cs), one-euro filter for smoothing (OneEuroFilter.cs), and hand properties (HandProperties.cs).
- XR Subsystem:
- Under the XRSubsystem directory there are implementations of ViconHandProvider.cs, ViconHandSubsystem.cs, ViconXRDevice.cs, ViconXRLoader.cs, and settings – this area handles the connection of the streaming data to Unity’s XR framework.
- Scene and Prefabs:
- The Prefabs in Assets/Prefabs (e.g., Vicon XR Origin and MainViconCamera) and relevant sample scenes (in Samples~) represent how the streamed data is used to render and drive the XR scene, including hand representations.
- Assets and Blender Models:
- The Meshes directory and the “source” folder with Blender files (LeftHand.blend, RightHand.blend) indicate the visual assets used for modeling the hands. The README also explains specific export settings required for the left hand model.
- Editor Tools:
- The Editor folder under Assets/Scripts/ViconNexusUnityStream contains custom inspectors and post-processors (e.g., ViconBuildPreProcessor.cs, HWDMergerEditor.cs, etc.) which are used to simplify configuration and asset import tasks.

##### Relationships and data flow between these components
- Next, connect the WebSocket layer to the “Core Unity Module (ViconNexusUnityStream)”—this component is responsible for receiving, filtering (e.g., OneEuroFilter), and pre-processing the incoming stream data.

##### Architectural patterns and design principles
- Separation of Concerns: Different parts of the system take care of separate responsibilities (networking, data processing, XR integration, editor configuration).
- Layered Architecture: Distinguish clearly between external data ingestion (Vicon Nexus service and WebSocket communication), internal data processing (ViconNexusUnityStream scripts), and rendering/integration (XR subsystem and scene prefabs).
- Extensibility: The presence of custom editor tools and modular XR subsystems (with clear interface separation found in distinct directories) enable developers to extend or modify parts of the system independently.

- That each component is as granular as needed—if helpful, break down the XR subsystem further into individual classes such as the hand provider and device loader.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["External Vicon Nexus Service"]:::external
    B["WebSocket Communication Layer"]:::communication

    subgraph "Core Unity Module (ViconNexusUnityStream)"
        C1["ViconStreamData.cs"]:::core
        C2["OneEuroFilter.cs"]:::core
        C3["HandProperties.cs"]:::core
        C1 -->|"uses"| C2
        C1 -->|"uses"| C3
    end

    subgraph "XR Subsystem"
        X1["ViconHandProvider.cs"]:::xr
        X2["ViconHandSubsystem.cs"]:::xr
        X3["ViconXRDevice.cs"]:::xr
        X4["ViconXRLoader.cs"]:::xr
        X5["ViconXRSettings & Constants"]:::xr
    end

    subgraph "Scene and Prefabs"
        S1["Assets/Prefabs"]:::scene
        S2["Samples~ Scenes"]:::scene
    end

    subgraph "Visual Assets"
        V1["Meshes (FBX hand models)"]:::asset
        V2["Blender Files"]:::asset
    end

    F["Editor Tools"]:::editor

    %% Data flow connections
    A -->|"streams"| B
    B -->|"sendsData"| C1
    C1 -->|"processes"| X1
    X1 -->|"drives"| S1
    X1 -->|"drives"| S2

    %% Editor Tools configuration connection (bi-directional)
    F <-->|"configures"| C1

    %% Visual assets used by Scene
    V1 -->|"providesModels"| S1
    V2 -->|"providesModels"| S1

    %% Click events
    click B "https://github.com/ovi-lab/vicon-nexus-unity-stream/tree/master/Assets/Scripts/WebSockets/WebSocket"
    click C1 "https://github.com/ovi-lab/vicon-nexus-unity-stream/blob/master/Assets/Scripts/ViconNexusUnityStream/ViconStreamData.cs"
    click C2 "https://github.com/ovi-lab/vicon-nexus-unity-stream/blob/master/Assets/Scripts/ViconNexusUnityStream/OneEuroFilter.cs"
    click C3 "https://github.com/ovi-lab/vicon-nexus-unity-stream/blob/master/Assets/Scripts/ViconNexusUnityStream/HandProperties.cs"
    click X1 "https://github.com/ovi-lab/vicon-nexus-unity-stream/blob/master/Assets/Scripts/ViconNexusUnityStream/XRSubsystem/ViconHandProvider.cs"
    click X2 "https://github.com/ovi-lab/vicon-nexus-unity-stream/blob/master/Assets/Scripts/ViconNexusUnityStream/XRSubsystem/ViconHandSubsystem.cs"
    click X3 "https://github.com/ovi-lab/vicon-nexus-unity-stream/blob/master/Assets/Scripts/ViconNexusUnityStream/XRSubsystem/ViconXRDevice.cs"
    click X4 "https://github.com/ovi-lab/vicon-nexus-unity-stream/blob/master/Assets/Scripts/ViconNexusUnityStream/XRSubsystem/ViconXRLoader.cs"
    click X5 "https://github.com/ovi-lab/vicon-nexus-unity-stream/blob/master/Assets/Scripts/ViconNexusUnityStream/XRSubsystem/ViconXRSettings.cs"
    click S1 "https://github.com/ovi-lab/vicon-nexus-unity-stream/tree/master/Assets/Prefabs"
    click S2 "https://github.com/ovi-lab/vicon-nexus-unity-stream/tree/master/Samples~"
    click V1 "https://github.com/ovi-lab/vicon-nexus-unity-stream/tree/master/Assets/Meshes"
    click V2 "https://github.com/ovi-lab/vicon-nexus-unity-stream/tree/master/source"
    click F "https://github.com/ovi-lab/vicon-nexus-unity-stream/tree/master/Assets/Scripts/ViconNexusUnityStream/Editor"

    %% Styles
    classDef external fill:#f9c74f,stroke:#000,stroke-width:2px;
    classDef communication fill:#90be6d,stroke:#000,stroke-width:2px;
    classDef core fill:#f94144,stroke:#000,stroke-width:2px;
    classDef xr fill:#577590,stroke:#fff,stroke-width:2px;
    classDef scene fill:#43aa8b,stroke:#000,stroke-width:2px;
    classDef asset fill:#f3722c,stroke:#000,stroke-width:2px;
    classDef editor fill:#277da1,stroke:#000,stroke-width:2px;
```
