# `BB.Collision.Mesh`
[🔗](https://github.com/beam-bots/bb/blob/main/lib/bb/collision/mesh.ex#L5)

Mesh loading and bounding geometry computation for collision detection.

This module provides basic mesh support for collision detection by computing
bounding primitives (spheres or AABBs) from mesh vertices. Triangle-level
collision detection is not supported - meshes are approximated by their
bounding geometry.

Currently supports:
- Binary STL files
- ASCII STL files

## Usage

    # Load mesh and compute bounds
    {:ok, bounds} = BB.Collision.Mesh.load_bounds("/path/to/model.stl")

    # bounds contains:
    %{
      aabb: {min_vec3, max_vec3},
      bounding_sphere: {centre_vec3, radius}
    }

## Caching

Mesh bounds are cached in an ETS table to avoid repeated file parsing.
The cache key includes the file path and modification time.

# `bounds`

```elixir
@type bounds() :: %{
  aabb: {BB.Math.Vec3.t(), BB.Math.Vec3.t()},
  bounding_sphere: {BB.Math.Vec3.t(), float()}
}
```

# `clear_cache`

```elixir
@spec clear_cache() :: :ok
```

Clear the mesh bounds cache.

# `compute_bounds`

```elixir
@spec compute_bounds([{float(), float(), float()}]) ::
  {:ok, bounds()} | {:error, :empty_mesh}
```

Compute bounding geometry from a list of vertices.

Each vertex should be a `{x, y, z}` tuple of floats.

# `load_bounds`

```elixir
@spec load_bounds(String.t()) :: {:ok, bounds()} | {:error, term()}
```

Load mesh bounds from a file.

Parses the mesh file, computes bounding geometry, and caches the result.
Subsequent calls with the same file (unchanged) return cached bounds.

Returns `{:ok, bounds}` or `{:error, reason}`.

# `load_bounds!`

```elixir
@spec load_bounds!(String.t()) :: bounds()
```

Load mesh bounds, raising on error.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
