3 unstable releases
| 0.2.1 | Sep 22, 2025 |
|---|---|
| 0.2.0 | Sep 21, 2025 |
| 0.1.0 | Sep 17, 2025 |
#125 in Science
24 downloads per month
Used in objex
28KB
545 lines
matcat
A compact, procedural material catalog for simulations.
Instead of maintaining giant lookup tables of materials, matcat encodes every material as a 5-byte identifier (MatCatId), then procedurally derives its physical properties. This allows trillions of possible distinct materials — far more than you could ever hand-author — while still giving deterministic, repeatable results.
Features
-
Compact IDs
MatCatIdis only 5 bytes (u8category,u16variant,u16grade).
Each ID maps deterministically to a unique material. -
Procedural properties
props_for(id)derives a completeMatPropsstruct, covering mechanical, thermal, chemical, and electromagnetic properties. -
Distance metric
Compare materials in property-space with a Euclidean distance function. -
Search
find_closest_materiallets you match a target set of properties against a search space ofMatCatIds. -
Blazing fast
Property derivation (props_for) takes ~12ns; searching 1000 candidates takes ~17µs (see benches).
Example
use matcat::{MatCatId, props_for, find_closest_material};
fn main() {
let copper_id = MatCatId::new(1, 42, 0); // category=1 (Metal), variant=42, grade=0
let copper_props = props_for(&copper_id);
println!("Copper-like density: {} kg/m³", copper_props.density);
// Suppose we want the closest match to a target density
let target = matcat::materials::MatProps { density: 8000.0, ..Default::default() };
let candidates: Vec<_> = (0..1000).map(|v| MatCatId::new(1, v, 0)).collect();
if let Some((id, props)) = find_closest_material(&target, &candidates) {
println!("Closest material ID: {:?}, density={}", id, props.density);
}
}
Use cases
- Simulation engines that need consistent materials without manual authoring.
- ECS systems where materials are components.
- Procedural generation of worlds, objects, and environments.
- Approximate matching for “what’s the closest material to this set of properties?”
Performance
Benchmarked on a modern x86 CPU:
props_for: ~12 nsfind_closest_material(1000 candidates): ~17 µs
License
MIT
Dependencies
~465KB