#geometry #parametric #3d #procedural #graphics

libfive

Tools for solid modeling, especially suited for parametric and procedural design

3 unstable releases

0.3.1 Feb 24, 2024
0.3.0 Feb 16, 2024
0.2.0 Feb 11, 2024
0.1.3 Jun 7, 2021

#98 in Math

Download history 105/week @ 2024-02-12 153/week @ 2024-02-19 92/week @ 2024-02-26 5/week @ 2024-03-04 1/week @ 2024-03-11 108/week @ 2024-04-01

110 downloads per month

MPL-2.0 license

1.5MB
10K SLoC

C++ 8K SLoC // 0.2% comments Rust 1.5K SLoC // 0.0% comments Python 340 SLoC // 0.4% comments

libfive libfive logo

A Rust wrapper for libfive.

Example

use libfive::*;

let f_rep_shape = Tree::sphere(1.0.into(), TreeVec3::default())
    .difference_multi(vec![
        Tree::sphere(0.6.into(), TreeVec3::default()),
        Tree::cylinder_z(
            0.6.into(),
            2.0.into(),
            TreeVec3::new(0.0, 0.0, -1.0),
        ),
        Tree::cylinder_z(
            0.6.into(),
            2.0.into(),
            TreeVec3::new(0.0, 0.0, -1.0),
        )
        .reflect_xz(),
        Tree::cylinder_z(
            0.6.into(),
            2.0.into(),
            TreeVec3::new(0.0, 0.0, -1.0),
        )
        .reflect_yz(),
    ]);

f_rep_shape.to_stl(
    "f_rep_shape.stl",
    &Region3::new(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0),
    // Resolution
    100.0,
)?;

This results in this STL mesh:

Generated f-rep. shape

Documentation

Build docs locally:

cargo doc -p libfive --no-deps --all-features --open

Features

  • ahash – On by default. Use AHashMap for hashing when resolving variable names. Disabling this will fall back to the slower HashMap.

  • stdlib – On by default. Add an extensive list of higher level operations – the libfive stdlib.

    To disable either/both of the above features unset default features in Cargo.toml:

    [dependencies.libfive]
    default-features = false
    
  • packed_opcodes - Tightly pack opcodes. This breaks compatibility with older saved f-rep files.

Dependencies

macOS

With homebrew installed, run:

brew install cmake pkg-config eigen libpng boost

Ubuntu/Debian

libfive should build out of the box on the latest Ubuntu LTS (currently 20.04). If you find that's not the case, please open an issue in the upstream repository!

Install the following dependencies with apt:

sudo apt-get install cmake pkg-config libeigen3-dev libpng-dev libboost-all-dev

Arch Linux

Install the following dependencies:

sudo pacman -S cmake pkgconf eigen libpng boost boost-libs

Windows (VS2019)

Install Git, choosing settings so that it can be invoked from a Windows Command Prompt (the defaults should be fine).

Install VS2019 (Community Edition), configured for Desktop development with C++.

You only need MSVC, Windows 10 SDK, and C++ CMake tools for Windows. Feel free to uncheck other optional packages in the right sidebar. Then run the installation!

Next, install dependencies using vcpkg.

⚠️ This step touches many files, so you may want to disable the Antimalware Service Executable, which will otherwise scan every single file and slow things down dramatically: in Windows SecurityVirus & threat protection settings, uncheck Real-time protection.

In a Windows Command Prompt:

git clone https://github.com/Microsoft/vcpkg.git
.\vcpkg\bootstrap-vcpkg.bat
.\vcpkg\vcpkg.exe install --triplet x64-windows eigen3 boost-container boost-bimap boost-interval boost-lockfree boost-functional boost-algorithm boost-math libpng

Go get some coffee or something – this will take a while.

Building

Just the usual.

cargo build

Dependencies

~1–3.5MB
~67K SLoC