#3d #csg #solid #geometry #rays

crater-rs

A library for N-dimensional arbitrary geometries

13 releases (6 breaking)

Uses new Rust 2024

new 0.7.0 Apr 30, 2025
0.6.0 Mar 6, 2025
0.5.0 Feb 7, 2025
0.4.1 Jan 17, 2025
0.1.4 Oct 3, 2024

#347 in Math

Download history 243/week @ 2025-01-12 47/week @ 2025-01-19 153/week @ 2025-02-02 23/week @ 2025-02-09 4/week @ 2025-02-16 1/week @ 2025-02-23 136/week @ 2025-03-02 22/week @ 2025-03-09 8/week @ 2025-03-16 8/week @ 2025-03-23 1/week @ 2025-03-30 2/week @ 2025-04-13 5/week @ 2025-04-20 114/week @ 2025-04-27

121 downloads per month

MIT and AGPL-3.0-only

4.5MB
4.5K SLoC

logo

This is Crater, the official mascot of crater.rs!

⚠️ WARNING ⚠️

crater.rs is still in early development. Until version 1.0.0, consider the public API mutable! I appreciate your patience as crater.rs matures 😅

Purpose

crater.rs is a library for N-D geometric modeling and analysis. It is built upon the Burn machine learning framework, allowing clients to leverage whatever backend (CPU, GPU, etc.) they wish.

Example: Ray Casting

Here's something you may create using crater.rs (see the aabb_raycast example). This is a little animation of crater.rs's built-in raycasting library, which supports batched ray-isosurface intersection that is offloaded to the device of the users choosing.

M1 Macbook completes these 100,000 rays in a little under 2 seconds.

raycast gif

I can push my Macbook to its memory limits and solve for 3 million rays and hit a peak ray throughput of about 130,000 rays/s.

Features

  • N-D Constructive Solid Geometry (CSG):
    • Batched, offloaded operations on fields via Burn Tensors
    • Define your geometry entirely in terms of an N-variant closure, f(x1, x2, ..., xN) <= 0.
    • Compose primitive closures together using differentiable, set-theoretic operations (e.g., f1(x1, x2, ..., xN) <= 0 OR f2(x1, x2, ..., xN) <= 0)
    • Arbitrarily transform regions through covariant operations on the N-D basis (e.g., f(x1, x2, ..., xN) -> f(g_1(x1), g_2(x2), ... g_N(xN)) for some transformation g_i(xi)).
    • Ray-casting against field isosurfaces on device (Axis-Aligned Bounding Box implementation for acceleration when the number of rays is high)
  • For N=3:
    • Invoke the (offloaded) Marching Cubes algorithm to convert CSGs to triangular meshes
    • Interact with crater.rs's MeshCollection and TriangleMesh types. Use this to export to common rendering formats (e.g., .stl, .vtk) Use Paraview as a drag and drop visualizer for these outputs.
  • N-D Region analysis:
    • Surface normals, gradients, curvature, etc.
    • Closed and open region volume calculations
  • Refer to the examples for various implemented use cases of crater.rs

Quick Start

crater.rs is distributed as a library crate for use as a dependency in your project(s).

> cargo add crater-rs
... adds `crater-rs` as a dependency of your crate

crater.rs Users in the Wild!

  • phlux.rs Monte Carlo Neutron Transport for the performant calculation of nuclear reactor physics
    • phlux.rs uses crater.rs's ray casting module for particle tracking against reactor geometries

Theory

crater.rs leverages a wealth of abstract mathematical and computing techniques. Rather than detail all aspects of the underlying theory in the README.md, check out the API documentation! There are numerous examples and explanations written inline.

Citations

  1. A. Ricci. "A constructive geometry for computer graphics" (1973)
  2. Vadim Shapiro. "Theory of R-Functions: A Primer" (1988)
  3. P.A. Fayolle and A. Pasko "An Evolutionary Approach to the Extraction of Object Construction Trees from 3D Point Clouds"
  4. A. Pasko, et. al. "Function Representation in Geometric Modeling: Concepts, Implementation and Applications"
  5. P. Bourke. "Polygonising a scalar field" (1994)
  6. N. Matsakis "Rayon Data Parallelism in Rust"

Dependencies

~65–105MB
~2M SLoC