Imlet
(Implicit Modeling Lightweight Exploration Toolkit) is a lightweight and flexible engine for creating 3D geometries through implicit modeling, written in Rust.
It enables the construction of compound spatial functions that can be evaluated and polygonized to generate geometries.
Imlet
provides tools for defining and combining distance functions, extracting isosurfaces, and exporting the results. At its core, it offers a high-level interface for implicit modeling, including:
- Functional Modeling: Create geometries by combining distance functions (e.g., spheres, toruses) and operations (e.g., intersections, unions).
- Geometric Types: Provides core geometric types, like
Vec3
,Plane
,Mesh
, and more. - Custom Distance Functions: Define distance functions mathematically or derive them from external triangle meshes.
- Field Sampling: Both dense and sparse field sampling for handling large domains.
- Iso-surfacing: Efficient iso-surface extraction from discretized scalar fields using marching cubes.
- Mesh Export/Import: Export results to
.obj
files or import external.obj
files to create custom distance functions.
serde
: Save and load implicit models using the.json
format for easy sharing and reuse.viewer
: Visualize mesh outputs quickly using theviewer
feature built on top ofwgpu
.
For a more in-depth explanation of the library, see the docs
To run a basic example via the terminal and show the result, run the following.
cargo run --release --features viewer --example $example
where $example
is any of the examples in the example dir, like gyroid
, interpolation
or bunny
.
Add via cargo.
cargo add imlet
Below is an example of how to use Imlet to create a 3D model by combining a sphere and a gyroid using an intersection operation.
The model is then evaluated over a 3D space and saved as a mesh in an OBJ file.
// Define the model parameters
let size = 10.0;
let cell_size = 0.1;
let bounds = BoundingBox::new(Vec3::origin(), Vec3::new(size, size, size));
// Create an implicit model
let mut model = ImplicitModel::new();
// Add a sphere to the model
let sphere = model
.add_function(
"Sphere",
Sphere::new(Vec3::new(0.5 * size, 0.5 * size, 0.5 * size), 0.45 * size))
.unwrap();
// Add a gyroid function to the model
let gyroid = model
.add_function("Gyroid", Gyroid::with_equal_spacing(2.5, true))
.unwrap();
// Combine the sphere and gyroid using a Boolean intersection
let intersection = model
.add_operation(
"Intersection",
BooleanIntersection::new(),
Some(&[&sphere, &gyroid]))
.unwrap();
// Sample a sparse field and generate an iso-surface.
let config = SparseFieldConfig::default()
.set_cell_size(cell_size);
let mut sampler = SparseSampler::builder()
.with_bounds(bounds) // Set the bounds for the sampling.
.with_config(config) // Set the sparse field parameters.
.build()
.expect("Should be able to build the sampler.");
sampler
.sample_field(&model)
.expect("Sampling should work.");
let mesh = sampler
.iso_surface(0.0)
.expect("Extracting iso-surface should work.");
write_obj_file(&mesh, "interpolation_example").unwrap();
The project is still in the early phase of development, so expect breaking API changes as the library keeps developing. Below is a non-exhaustive list of improvements that are on my radar for the next steps.
- More flexible viewer using bevy.
- Python binding or other scripting interface to build and compute models. (For example using PyO3)
- GPU computation of models for faster processing. (For example using CubeCL)
- Develop a node editor for visual programming. (For example using snarl)
This project is licensed under either of the following:
Choose the one that best suits your needs.