building_blocks/lib.rs
1//! [](https://crates.io/crates/building-blocks)
2//! [](https://docs.rs/building-blocks)
3//! [](./LICENSE)
4//! [](https://crates.io/crates/building-blocks)
5//! [](https://discord.gg/CnTNjwb)
6//!
7//! Building Blocks is a voxel library for real-time applications.
8//!
9//! 
10//!
11//! 
12//!
13//! 
15//!
16//! We focus on generally useful data structures and algorithms. Features include:
17//!
18//! - 2D and 3D data storage
19//! - structure-of-arrays (SoA) storage of multiple data channels per spatial dimension
20//! - a [`ChunkMap`](crate::storage::chunk::map) with generic chunk storage
21//! - chunk caching, compression, and serialization
22//! - [`OctreeSet`](crate::storage::octree::set) hierarchical bitset of voxel points
23//! - mesh generation
24//! - Surface Nets isosurface extraction
25//! - Minecraft-style greedy meshing
26//! - height maps
27//! - spatial queries
28//! - sparse traversal and search over octrees
29//! - ray casting and sphere casting against octrees with [`ncollide3d`](https://www.ncollide.org/)
30//! - Amanatides and Woo ray grid traversal
31//! - pathfinding
32//! - level of detail
33//! - `ChunkMap` can downsample chunks into lower resolutions within the same storage
34//! - dynamic 3D clipmap for keeping high detail close to a focal point
35//! - multiresolution Surface Nets (TODO)
36//! - procedural generation
37//! - sampling signed distance fields
38//! - constructive solid geometry with [`sdfu`](https://docs.rs/sdfu)
39//!
40//! # Short Code Example
41//!
42//! The code below samples a [signed distance field](https://en.wikipedia.org/wiki/Signed_distance_function) and generates a
43//! mesh from it.
44//!
45//! ```
46//! use building_blocks::{
47//! core::sdfu::{Sphere, SDF},
48//! prelude::*,
49//! mesh::{SurfaceNetsBuffer, surface_nets},
50//! };
51//!
52//! let center = Point3f::fill(25.0);
53//! let radius = 10.0;
54//! let sphere_sdf = Sphere::new(radius).translate(center);
55//!
56//! let extent = Extent3i::from_min_and_shape(Point3i::ZERO, Point3i::fill(50));
57//! let mut samples = Array3x1::fill_with(extent, |p| sphere_sdf.dist(Point3f::from(p)));
58//!
59//! let mut mesh_buffer = SurfaceNetsBuffer::default();
60//! let voxel_size = 2.0; // length of the edge of a voxel
61//! surface_nets(&samples, samples.extent(), voxel_size, &mut mesh_buffer);
62//! ```
63//!
64//! # Learning
65//!
66//! ## Design and Architecture
67//!
68//! There is a terse [design doc](https://github.com/bonsairobo/building-blocks/blob/main/DESIGN.md) that gives an overview of
69//! design decisions made concerning the current architecture. You might find this useful as a high-level summary of the most
70//! important pieces of code.
71//!
72//! ## Docs and Examples
73//!
74//! The current best way to learn about the library is to read the documentation and examples. For the latest stable docs, look
75//! [here](https://docs.rs/building_blocks/latest/building_blocks). For the latest unstable docs, clone the repo and run
76//!
77//! ```sh
78//! cargo doc --open
79//! ```
80//!
81//! There is plentiful documentation with examples. Take a look in the `examples/` directory to see how Building Blocks can be
82//! used in real applications.
83//!
84//! ### Getting Started
85//!
86//! This library is organized into several crates. The most fundamental are:
87//!
88//! - [**core**](crate::core): lattice point and extent data types
89//! - [**storage**](crate::storage): storage for lattice maps, i.e. functions defined on `Z^2` and `Z^3`
90//!
91//! Then you get extra bits of functionality from the others:
92//!
93//! - [**mesh**](crate::mesh): 3D mesh generation algorithms
94//! - [**search**](crate::search): search algorithms on lattice maps
95//!
96//! To learn the basics about lattice maps, start with these doc pages:
97//!
98//! - [point](https://docs.rs/building_blocks_core/latest/building_blocks_core/point/struct.PointN.html)
99//! - [extent](https://docs.rs/building_blocks_core/latest/building_blocks_core/extent/struct.ExtentN.html)
100//! - [array](https://docs.rs/building_blocks_storage/latest/building_blocks_storage/array/index.html)
101//! - [access traits](https://docs.rs/building_blocks_storage/latest/building_blocks_storage/access/index.html)
102//! - [chunk map](https://docs.rs/building_blocks_storage/latest/building_blocks_storage/chunk_map/index.html)
103//! - [transform map](https://docs.rs/building_blocks_storage/latest/building_blocks_storage/transform_map/index.html)
104//! - [fn map](https://docs.rs/building_blocks_storage/latest/building_blocks_storage/func/index.html)
105//! - [octrees](https://docs.rs/building_blocks_storage/latest/building_blocks_storage/octree/index.html)
106//!
107//! ## Benchmarks
108//!
109//! To run the benchmarks (using the "criterion" crate), go to the root of a crate and run `cargo bench`. As of version 0.5.0,
110//! all benchmark results are posted in the release notes.
111//!
112//! # Configuration
113//!
114//! ## LTO
115//!
116//! It is highly recommended that you enable link-time optimization when using building-blocks. It will improve the performance
117//! of critical algorithms like meshing by up to 2x. Just add this to your Cargo.toml:
118//!
119//! ```toml
120//! [profile.release]
121//! lto = true
122//! ```
123//!
124//! ## Cargo Features
125//!
126//! Building Blocks is organized into several crates, some of which are hidden behind features, and some have features
127//! themselves, which get re-exported by the top-level crate. Some features are enabled by default. You can avoid taking
128//! unnecessary dependencies by declaring `default-features = false` in your `Cargo.toml`:
129//!
130//! ```toml
131//! [dependencies.building-blocks]
132//! version = "0.6"
133//! default-features = false
134//! features = ["foo", "bar"]
135//! ```
136//!
137//! ### Math Type Conversions
138//!
139//! The `PointN` types have conversions to/from [`glam`](https://docs.rs/glam), [`nalgebra`](https://nalgebra.org/), and
140//! [`mint`](https://docs.rs/mint) types by enabling the corresponding feature.
141//!
142//! ### Compression Backends and WASM
143//!
144//! Chunk compression supports two backends out of the box: `Lz4` and `Snappy`. They are enabled with the "lz4" and "snappy"
145//! features. "lz4" is the default, but it relies on a C++ library, so it's not compatible with WASM. But Snappy is pure Rust,
146//! so it can! Just use `default-features = false` and add "snappy" to you `features` list.
147//!
148//! ### VOX Files
149//!
150//! ".VOX" files are supported via the [`dot_vox`](https://docs.rs/dot_vox/) crate. Enable the `dot_vox` feature to expose the
151//! generic `encode_vox` function and `Array3x1::decode_vox` constructor.
152//!
153//! ### Images
154//!
155//! Arrays can be converted to `ImageBuffer`s and constructed from `GenericImageView`s from the [`image`](https://docs.rs/image)
156//! crate. Enable the `image` feature to expose the generic `encode_image` function and `From<Im> where Im: GenericImageView`
157//! impl.
158//!
159//! ### Signed Distance Field Utilities (sdfu)
160//!
161//! The [`sdfu`](https://docs.rs/sdfu) crate provides convenient APIs for constructive solid geometry operations. By enabling
162//! this feature, the `PointN` types will implement the `sdfu::mathtypes` traits in order to be used with these APIs. The `sdfu`
163//! crate also gets exported under `building_blocks::core::sdfu`.
164//!
165//! # Development
166//!
167//! We prioritize work according to the [project board](https://github.com/bonsairobo/building-blocks/projects/1).
168//!
169//! If you'd like to make a contribution, please first read the **[design
170//! philosophy](https://github.com/bonsairobo/building-blocks/blob/main/DESIGN.md)** and **[contribution
171//! guidelines](https://github.com/bonsairobo/building-blocks/blob/main/CONTRIBUTING.md)**.
172
173// TODO: when cargo-readme supports intra-doc links, replace URLs above
174
175pub use building_blocks_core as core;
176pub use building_blocks_storage as storage;
177
178pub mod prelude {
179 pub use super::core::prelude::*;
180 pub use super::storage::prelude::*;
181}
182
183#[cfg(feature = "mesh")]
184pub use building_blocks_mesh as mesh;
185#[cfg(feature = "search")]
186pub use building_blocks_search as search;