# rawiazam/unity_2d_spring_mesh architecture

> Architecture diagram of the GitHub repository rawiazam/unity_2d_spring_mesh, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rawiazam/unity_2d_spring_mesh
- Repository: https://github.com/rawiazam/unity_2d_spring_mesh

## Overview

This Unity project is a GPU-accelerated 2D spring-mesh visual simulation. Its principal workflow is to initialize a grid of points and neighbor/restoring springs, apply mouse-click impulses, execute spring simulation on the GPU, and render the resulting mesh. The README identifies SpatialMap as redundant and describes density-based rendering as a possible improvement; the tree contains related shader assets, but no source excerpts were available to verify their runtime wiring.

Main entry points: [`Assets/scripts/spring_mesh.cs`](https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/spring_mesh.cs) (SpringMesh), [`Assets/scripts/impulse.cs`](https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/impulse.cs) (Impulse), [`Assets/scripts/spring.compute`](https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/spring.compute) (Spring compute), [`Assets/scripts/mesh_point.cs`](https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/mesh_point.cs) (Mesh point)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_simulation["Mesh simulation"]
  node_springmesh["SpringMesh<br/>[spring_mesh.cs]"]
  node_point["Mesh point<br/>[mesh_point.cs]"]
  node_spatialmap["SpatialMap<br/>[SpatialMap.cs]"]
  node_springcompute["Spring compute<br/>[spring.compute]"]
end

subgraph group_interaction["User interaction"]
  node_impulse["Impulse<br/>[impulse.cs]"]
end

subgraph group_rendering["Rendering"]
  node_dynamicmesh["DynamicMesh<br/>[dynamic_mesh.cs]"]
  node_densitycompute["Density map compute<br/>[DensityMap.compute]"]
  node_densityview["Density view<br/>[densityView.cs]"]
  node_densshader["Density shader<br/>[Dens.shader]"]
  node_quadmaterial["Quad material setup<br/>[QuadSetMaterial.cs]"]
end

node_user(("User"))
node_sample["Sample scene<br/>[SampleScene.unity]"]

node_springmesh -->|"creates points"| node_point
node_springmesh -->|"executes simulation"| node_springcompute
node_user -->|"clicks"| node_impulse
node_impulse -->|"sets variables"| node_springcompute
node_springmesh -->|"updates mesh"| node_dynamicmesh

click node_springmesh "https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/spring_mesh.cs"
click node_point "https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/mesh_point.cs"
click node_spatialmap "https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/SpatialMap.cs"
click node_springcompute "https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/spring.compute"
click node_impulse "https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/impulse.cs"
click node_dynamicmesh "https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/dynamic_mesh.cs"
click node_densitycompute "https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/shader/DensityMap.compute"
click node_densityview "https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/shader/densityView.cs"
click node_densshader "https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/shader/Dens.shader"
click node_quadmaterial "https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/shader/QuadSetMaterial.cs"
click node_sample "https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/Scenes/SampleScene.unity"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_springmesh,node_point,node_spatialmap,node_springcompute,node_user toneBlue
class node_impulse toneAmber
class node_dynamicmesh,node_densitycompute,node_densityview,node_densshader,node_quadmaterial toneMint
class node_sample toneTeal
```

## Components

### Mesh simulation

- [SpringMesh](https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/spring_mesh.cs): `Assets/scripts/spring_mesh.cs`
- [Mesh point](https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/mesh_point.cs): `Assets/scripts/mesh_point.cs`
- [SpatialMap](https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/SpatialMap.cs): `Assets/scripts/SpatialMap.cs`
- [Spring compute](https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/spring.compute): `Assets/scripts/spring.compute`

### User interaction

- [Impulse](https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/impulse.cs): `Assets/scripts/impulse.cs`

### Rendering

- [DynamicMesh](https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/dynamic_mesh.cs): `Assets/scripts/dynamic_mesh.cs`
- [Density map compute](https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/shader/DensityMap.compute): `Assets/scripts/shader/DensityMap.compute`
- [Density view](https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/shader/densityView.cs): `Assets/scripts/shader/densityView.cs`
- [Density shader](https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/shader/Dens.shader): `Assets/scripts/shader/Dens.shader`
- [Quad material setup](https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/scripts/shader/QuadSetMaterial.cs): `Assets/scripts/shader/QuadSetMaterial.cs`

### Other components

- **User**
- [Sample scene](https://github.com/rawiazam/unity_2d_spring_mesh/blob/master/Assets/Scenes/SampleScene.unity): `Assets/Scenes/SampleScene.unity`

## Connections

- SpringMesh → Mesh point: creates points
- SpringMesh → Spring compute: executes simulation
- User → Impulse: clicks
- Impulse → Spring compute: sets variables
- SpringMesh → DynamicMesh: updates mesh
