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.
Summary
Functions
Clear the mesh bounds cache.
Compute bounding geometry from a list of vertices.
Load mesh bounds from a file.
Load mesh bounds, raising on error.
Types
@type bounds() :: %{ aabb: {BB.Math.Vec3.t(), BB.Math.Vec3.t()}, bounding_sphere: {BB.Math.Vec3.t(), float()} }
Functions
@spec clear_cache() :: :ok
Clear the mesh bounds cache.
Compute bounding geometry from a list of vertices.
Each vertex should be a {x, y, z} tuple of floats.
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 mesh bounds, raising on error.