# hyphesus/teethsim architecture

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

- Interactive diagram: https://gitdiagram.com/hyphesus/teethsim
- Repository: https://github.com/hyphesus/teethsim

## Overview

##### Project type and purpose
- This is a Unity‐based real‐time 3D simulation tool (“Teeth Examination Simulator”) that integrates a Phantom-Omni haptic device via the HapticsDirect plugin. Its goal is to let dental students practice cavity cleaning/filling with accurate force feedback.

##### File structure
- Top-level:
- Assets/ – Unity content (3D models, materials, scenes, scripts, prefabs, plugin)
- Packages/ – Unity package manifest (TextMesh Pro, test tools)
- ProjectSettings/ – Unity project configuration
- README.md, LICENSE, .gitignore
- Under Assets:
- 3DSystems/HapticsDirect/ – HapticsDirect plugin (native .lib + C# wrapper + documentation + sample scenes)
- Movement&Interaction Scripts/ – camera and interaction scripts (ConstantRotation, LookAround etc.)
- Scenes/ – SampleScene.unity
- TextMesh Pro/ – UI text framework
- Models & Materials – dentures, stylus, environment objects with colliders and haptic materials
- Prefabs – reusable scene objects (TouchActor, TouchXActor)
- Key scripts:
- HapticCollider.cs, HapticPlugin.cs – core haptic interface
- DestroyOnInteraction.cs – removal of rotten particles
- SceneControl.cs – (future) scene management

##### Insights from README
- Lists hierarchy items as Unity GameObjects and their components
- Describes the haptic interaction loop: collision → K-key press → rotten part removal
- Advises how to set up the Phantom-Omni driver and HapticActor Device Identifier

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Hardware
    subgraph "External Hardware"
        Device["Phantom-Omni Device"]:::external
        Driver["Phantom-Omni Driver"]:::external
    end

    %% Haptics Plugin Layer
    subgraph "HapticsDirect Plugin"
        NativeLib["HapticDirect Native Lib (hdu.lib)"]:::plugin
        HapticPlugin["HapticPlugin.cs"]:::plugin
        HapticCollider["HapticCollider.cs"]:::plugin
        VirtualHaptic["VirtualHaptic.cs"]:::plugin
        HelpWindow["HelpWindow.cs"]:::ui
        SceneControl["SceneControl.cs"]:::logic
    end

    %% Unity Engine & Scene Graph
    subgraph "Unity Engine & Scene"
        SampleScene["SampleScene.unity"]:::scene
        Physics["Unity Physics Engine"]:::engine
        SceneGraph["GameObjects & MeshColliders & RigidBodies"]:::engine
    end

    %% Interaction Logic
    subgraph "Interaction Logic"
        RotDestroy["RotDestroy.cs"]:::logic
    end

    %% UI Layer
    subgraph "UI Layer"
        TextMeshPro["TextMesh Pro"]:::ui
    end

    %% Input Layer
    subgraph "Input Layer"
        LookAround["LookAround.cs"]:::input
        ConstantRotation["ConstantRotation.cs"]:::input
    end

    %% Assets & Prefabs
    subgraph "Assets & Resources"
        Models["Models & Materials"]:::assets
        Prefabs["TouchActor / TouchXActor Prefabs"]:::assets
    end

    %% Data Flows
    Device -->|Driver Interface| Driver
    Driver -->|loads| NativeLib
    NativeLib -->|C# Wrapper Calls| HapticPlugin
    HapticPlugin <-->|force feedback loop| HapticCollider
    HapticCollider -->|collision data| Physics
    Physics -->|updates| SceneGraph
    SceneGraph -->|collision event| RotDestroy
    RotDestroy -.->|removes objects| SceneGraph
    Physics -->|force feedback| HapticPlugin
    HapticPlugin -->|force output| Device
    SceneGraph -->|state updates| HelpWindow
    SceneGraph -->|state updates| TextMeshPro
    LookAround -->|controls| SceneGraph
    ConstantRotation -->|controls| SceneGraph
    SampleScene -->|loads assets| Models
    SampleScene -->|instantiates| Prefabs

    %% Click Events
    click SampleScene "https://github.com/hyphesus/teethsim/blob/main/Assets/Scenes/SampleScene.unity"
    click NativeLib "https://github.com/hyphesus/teethsim/blob/main/Assets/3DSystems/HapticsDirect/HapticPlugin/hdu.lib"
    click HapticPlugin "https://github.com/hyphesus/teethsim/blob/main/Assets/3DSystems/HapticsDirect/HapticScripts/HapticPlugin.cs"
    click HapticCollider "https://github.com/hyphesus/teethsim/blob/main/Assets/3DSystems/HapticsDirect/HapticScripts/HapticCollider.cs"
    click HelpWindow "https://github.com/hyphesus/teethsim/blob/main/Assets/3DSystems/HapticsDirect/HapticScripts/HelpWindow.cs"
    click SceneControl "https://github.com/hyphesus/teethsim/blob/main/Assets/3DSystems/HapticsDirect/HapticScripts/SceneControl.cs"
    click VirtualHaptic "https://github.com/hyphesus/teethsim/blob/main/Assets/3DSystems/HapticsDirect/HapticScripts/VirtualHaptic.cs"
    click RotDestroy "https://github.com/hyphesus/teethsim/blob/main/Assets/Movement&Interaction Scripts/RotDestroy.cs"
    click LookAround "https://github.com/hyphesus/teethsim/blob/main/Assets/Movement&Interaction Scripts/LookAround.cs"
    click ConstantRotation "https://github.com/hyphesus/teethsim/blob/main/Assets/Movement&Interaction Scripts/ConstantRotation.cs"
    click Prefabs "https://github.com/hyphesus/teethsim/blob/main/Assets/3DSystems/HapticsDirect/Prefabs/TouchActor.prefab"
    click Prefabs "https://github.com/hyphesus/teethsim/blob/main/Assets/3DSystems/HapticsDirect/Prefabs/TouchXActor.prefab"
    click Models "https://github.com/hyphesus/teethsim/blob/main/Assets/3DSystems/HapticsDirect/Resources/Models/dentures-teeth.obj"
    click Models "https://github.com/hyphesus/teethsim/blob/main/Assets/3DSystems/HapticsDirect/Resources/Models/dentalPick.obj"
    click Models "https://github.com/hyphesus/teethsim/blob/main/Assets/3DSystems/HapticsDirect/Resources/Models/Materials/MaterialStage.mat"
    click TextMeshPro "https://github.com/hyphesus/teethsim/tree/main/Assets/TextMesh Pro"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:1px;
    classDef plugin fill:#ffeb3b,stroke:#333,stroke-width:1px;
    classDef engine fill:#8bc34a,stroke:#333,stroke-width:1px;
    classDef logic fill:#03a9f4,stroke:#333,stroke-width:1px;
    classDef ui fill:#e91e63,stroke:#333,stroke-width:1px;
    classDef input fill:#9c27b0,stroke:#333,stroke-width:1px;
    classDef scene fill:#ffc107,stroke:#333,stroke-width:1px;
    classDef assets fill:#795548,stroke:#333,stroke-width:1px;
```
