1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//! Octree construction and meshing
//!
//! This module implements
//! [Manifold Dual Contouring](https://people.engr.tamu.edu/schaefer/research/dualsimp_tvcg.pdf),
//! to generate a triangle mesh from an implicit surface (or anything
//! implementing [`Shape`](fidget_core::shape::Shape)).
//!
//! The resulting meshes should be
//! - Manifold
//! - Watertight
//! - Preserving sharp features (corners / edges)
//!
//! However, they may contain self-intersections, and are not guaranteed to
//! catch thin features (below the sampling grid resolution).
//!
//! The resulting [`Mesh`] objects can be written out as STL files.
//!
//! Here's a full example, meshing a sphere:
//!
//! ```
//! use fidget_core::{
//! context::Tree,
//! vm::VmShape
//! };
//! use fidget_mesh::{Octree, Settings};
//!
//! let radius_squared = Tree::x().square()
//! + Tree::y().square()
//! + Tree::z().square();
//! let tree: Tree = radius_squared.sqrt() - 0.6;
//! let shape = VmShape::from(tree);
//! let bound_shape = shape.try_into().expect("no extra vars");
//! let settings = Settings {
//! depth: 4,
//! ..Default::default()
//! };
//! let o = Octree::build(&bound_shape, &settings).unwrap();
//! let mesh = o.walk_dual();
//!
//! // Open a file to write, e.g.
//! // let mut f = std::fs::File::create("out.stl")?;
//! # let mut f = vec![];
//! mesh.write_stl(&mut f)?;
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
use ;
// Re-export the main Octree type as public
pub use Octree;
////////////////////////////////////////////////////////////////////////////////
/// An indexed 3D mesh
/// Settings when building an octree and mesh