Crate imlet

Source
Expand description

§Imlet

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.

§Overview

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:

§Key Features

  • Functional Modeling: Create geometries by combining distance functions (e.g., spheres, toruses) and operations (e.g., intersections, unions).
  • Geometric Types: The engine includes the core geometric types, like Vec3, Plane, Mesh, and more.
  • Custom Distance Functions: Define distance functions mathematically or derive them from external triangle meshes.
  • Model Serialization: Save and load implicit models using the .json format for easy sharing and reuse.
  • Mesh Export/Import: Export results to .obj files or import external .obj files to create custom distance functions.
  • Iso-surfacing: Efficient iso-surface extraction from discretized scalar fields.
  • CLI Interface: Run saved models and show .obj files directly from the command line.
  • Built-in Viewer (optional): Visualize mesh outputs quickly using the viewer feature built on top of wgpu.

The main modules of the crate are types::geometry and types::computation, which together form the foundation for creating and manipulating implicit models. At the heart of Imlet is the ImplicitModel struct, which represents the computation graph used for modeling.

§Example: Creating a Simple Geometry

Here’s a basic example demonstrating how to use Imlet to combine a sphere and a gyroid using an intersection operation. The result is polygonized and saved as an .obj file:

use imlet::utils::io::write_obj_file;
use imlet::types::geometry::{Vec3, BoundingBox, Sphere};
use imlet::types::computation::{
    functions::Gyroid,
    operations::shape::BooleanIntersection,
};
use imlet::types::computation::model::ImplicitModel;

// Define the model parameters
let size = 10.0;
let cell_size = 0.1;
let model_space = BoundingBox::new(Vec3::origin(), Vec3::new(size, size, size));

// Create an implicit model
let mut model = ImplicitModel::with_bounds(model_space);

// 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_with_inputs(
        "Intersection",
        BooleanIntersection::new(),
        &[&sphere, &gyroid],
    )
    .unwrap();

// Generate the iso-surface and save it to an OBJ file
let mesh = model.generate_iso_surface(&intersection, cell_size).unwrap();
write_obj_file(&mesh, "output.obj").unwrap();

For detailed usage and API references, explore the module documentation.

Modules§

algorithms
Algorithms for iso-surface extraction.
types
Types for building and processing implicit models.
utils
Utility modules for file I/O, logging, and math operations.

Constants§

IMLET_VERSION
The current version of the Imlet library.