baby_shark

Crates.iobaby_shark
lib.rsbaby_shark
version0.3.12
created_at2023-03-12 11:17:09.114797+00
updated_at2025-09-14 10:46:40.036939+00
descriptionGeometry processing library
homepagehttps://github.com/dima634/baby_shark
repositoryhttps://github.com/dima634/baby_shark
max_upload_size
id807965
size734,144
(dima634)

documentation

README

Geometry processing library in pure Rust

Crates.io License

Features

IO

Reading and writing mesh files

The library supports reading and writing mesh files in multiple formats with automatic format detection based on file extension:

  • STL (binary only) - Widely used for 3D printing and CAD
  • OBJ - Common format for graphics applications
  • PLY (ASCII and binary) - Stanford Polygon Format, commonly used for research and 3D scanning

The read_from_file and write_to_file functions automatically detect the format from the file extension and use the appropriate reader/writer.

Example

use std::path::Path;
use baby_shark::{
    io::{read_from_file, write_to_file}, 
    mesh::corner_table::prelude::CornerTableF
};

fn main() {
    // Read mesh - format automatically detected from extension
    let mesh: CornerTableF = read_from_file(Path::new("./input.stl"))
        .expect("Failed to read mesh file");

    // Write mesh - format automatically detected from extension  
    write_to_file(&mesh, Path::new("./output.obj"))
        .expect("Failed to write mesh file");
}

Advanced usage with specific readers/writers

For more control, you can use format-specific readers and writers directly:

use baby_shark::io::{StlReader, StlWriter, ObjReader};

// Using specific readers
let mut stl_reader = StlReader::default();
let mesh = stl_reader.read_from_file(Path::new("./mesh.stl"))?;

let mut obj_reader = ObjReader::default(); 
let mesh = obj_reader.read_from_file(Path::new("./mesh.obj"))?;

// Using specific writers
let stl_writer = StlWriter::default();
stl_writer.write_to_file(&mesh, Path::new("./output.stl"))?;

Implicit modeling

Boolean operations

Boolean operations are a set of operations that can be performed on volumes to combine or modify their shapes. The supported boolean operations in this library are:

  • Union - combines two volumes into a single volume, resulting in a shape that includes the combined volume of both models.
  • Subtract - removes the volume from another, resulting in a shape that is the difference between the two models.
  • Intersect - returns the volume that is common to both models, resulting in a shape that includes only the overlapping region.

These boolean operations can be useful in various applications, such as creating complex shapes by combining simpler shapes, removing unwanted parts from a volume, or finding the intersection between two volumes.

Example

Subtract Union
boolean_subtract boolean_union

Volume offset

The volume offsetting allows for the expansion or contraction of a model shape, serving various applications like CNC machining, collision detection, and rapid prototyping. It's a vital tool in model generation and toolpath creation. Inwards and outwards offsets are supported.

Example

image

Voxel remeshing

Voxel remeshing is a computational process used in computer graphics to reconstruct or optimize the topology of a three-dimensional (3D) model. Voxels are volumetric pixels that make up the 3D space, and remeshing involves reorganizing these voxels to create a more uniform and well-defined mesh structure. Also, it comes with the benefit of removing overlapping geometry, a valuable asset in sculpting applications.

Example

image

Explicit modeling

Isotropic remeshing

This algorithm incrementally performs simple operations such as edge splits, edge collapses, edge flips, and Laplacian smoothing. All the vertices of the remeshed patch are reprojected to the original surface to keep a good approximation of the input. Any of those operations can be turned off using appropriate method (with_<operation>(false)).

image

Example

Mesh simplification (decimation)

This library implements incremental edge decimation algorithm. On each iteration edge with lowest collapse cost is collapsed. Several stop condition are supported:

  • Max error - algorithm stops when collapse lowest cost is bigger than given value
  • Min faces count - algorithm stops when faces count drops below given value
  • Bounding sphere - adaptive error algorithm based upon distance from a point. Useful for LOD mesh decimation.
image

Example

Bounded Sphere Example

Mesh deformation

Mesh deformation is a technique for smoothly modifying the shape of 3D meshes by specifying target positions for certain vertices while maintaining the overall structure and quality of the mesh. This library implements a robust deformation system that uses handle regions (vertices with known target positions) and regions of interest (vertices that should be deformed) to create natural-looking deformations.

The deformation algorithm works by:

  • Defining handle vertices - points with known target positions that act as constraints
  • Specifying a region of interest - the area of the mesh that should be deformed
  • Computing smooth deformations that satisfy the handle constraints while preserving mesh quality

This is particularly useful for applications like shape morphing, interactive modeling, and mesh editing where you need to maintain surface smoothness while achieving specific shape changes.

image

Example

Commit count: 222

cargo fmt