pub struct Manifold(/* private fields */);Expand description
Manifold rust wrapper for C++ manifold object.
Implementations§
Source§impl Manifold
impl Manifold
Sourcepub fn project(&self) -> Polygons
pub fn project(&self) -> Polygons
Project the manifold onto a plane and return the resulting polygons.
Sourcepub fn trim_by_plane(&self, x: f64, y: f64, z: f64, offset: f64) -> Self
pub fn trim_by_plane(&self, x: f64, y: f64, z: f64, offset: f64) -> Self
Trim by a plane.
Examples found in repository?
examples/write_stl.rs (line 91)
17fn main() -> std::io::Result<()> {
18 // Write sphere to an STL file
19 manifold_rs::Manifold::sphere(4.0, 128).write_stl_to_file("sphere.stl")?;
20
21 // Write cylinder to an STL file
22 {
23 let manifold = manifold_rs::Manifold::cylinder(1.0, 4.0, 3.0, 32);
24
25 // Convert the manifold to a mesh and back to a manifold, just for testing
26 let mesh = manifold.to_mesh();
27 let manifold = mesh.to_manifold();
28
29 manifold.write_stl_to_file("cylinder.stl")?;
30 }
31
32 // Generate torus with `revolve` and write resulting mesh to an STL file
33 {
34 // Generate circle with 32 vertices
35 let circle = generate_circle(2.0, (4.0, 0.0), 32);
36
37 // Revolve the circle 360° around the z-axis
38 let manifold = manifold_rs::Manifold::revolve(&[circle.as_slice()], 32, 360.0);
39
40 manifold.write_stl_to_file("torus.stl")?;
41 }
42
43 // Generate a tube via `extrude` and write resulting mesh to an STL file
44 {
45 // Generate circle with 32 vertices
46 let inner_circle = generate_circle(0.3, (0.0, 0.0), 32);
47 let outer_circle = generate_circle(1.0, (0.0, 0.0), 32);
48
49 // CCW winding order to create a hole in the tube
50 let inner_circle = inner_circle
51 .into_iter()
52 .enumerate()
53 .map(|(i, x)| if i % 2 == 0 { x } else { -x })
54 .collect::<Vec<_>>();
55
56 // Extrude the circle along the z-axis
57 let manifold = manifold_rs::Manifold::extrude(
58 &[outer_circle.as_slice(), inner_circle.as_slice()],
59 4.0,
60 16,
61 0.0,
62 1.0,
63 1.0,
64 );
65
66 manifold.write_stl_to_file("tube.stl")?;
67 }
68
69 // Convex hull of two circles
70 {
71 let left_circle = generate_circle(1.0, (-1.0, 0.0), 32);
72 let right_circle = generate_circle(1.0, (1.0, 0.0), 32);
73
74 // Extrude the circle along the z-axis
75 let manifold = manifold_rs::Manifold::extrude(
76 &[left_circle.as_slice(), right_circle.as_slice()],
77 4.0,
78 16,
79 0.0,
80 1.0,
81 1.0,
82 );
83 let manifold = manifold.hull();
84
85 manifold.write_stl_to_file("hull.stl")?;
86 }
87
88 // Trim a cylinder by a plane
89 {
90 let manifold = manifold_rs::Manifold::cylinder(1.0, 1.0, 3.0, 32);
91 let manifold = manifold.trim_by_plane(0.5, 0.5, 0.5, 0.0);
92
93 manifold.write_stl_to_file("cylinder_trimmed.stl")?;
94 }
95 Ok(())
96}Sourcepub fn hull(&self) -> Self
pub fn hull(&self) -> Self
Convex hull.
Examples found in repository?
examples/write_stl.rs (line 83)
17fn main() -> std::io::Result<()> {
18 // Write sphere to an STL file
19 manifold_rs::Manifold::sphere(4.0, 128).write_stl_to_file("sphere.stl")?;
20
21 // Write cylinder to an STL file
22 {
23 let manifold = manifold_rs::Manifold::cylinder(1.0, 4.0, 3.0, 32);
24
25 // Convert the manifold to a mesh and back to a manifold, just for testing
26 let mesh = manifold.to_mesh();
27 let manifold = mesh.to_manifold();
28
29 manifold.write_stl_to_file("cylinder.stl")?;
30 }
31
32 // Generate torus with `revolve` and write resulting mesh to an STL file
33 {
34 // Generate circle with 32 vertices
35 let circle = generate_circle(2.0, (4.0, 0.0), 32);
36
37 // Revolve the circle 360° around the z-axis
38 let manifold = manifold_rs::Manifold::revolve(&[circle.as_slice()], 32, 360.0);
39
40 manifold.write_stl_to_file("torus.stl")?;
41 }
42
43 // Generate a tube via `extrude` and write resulting mesh to an STL file
44 {
45 // Generate circle with 32 vertices
46 let inner_circle = generate_circle(0.3, (0.0, 0.0), 32);
47 let outer_circle = generate_circle(1.0, (0.0, 0.0), 32);
48
49 // CCW winding order to create a hole in the tube
50 let inner_circle = inner_circle
51 .into_iter()
52 .enumerate()
53 .map(|(i, x)| if i % 2 == 0 { x } else { -x })
54 .collect::<Vec<_>>();
55
56 // Extrude the circle along the z-axis
57 let manifold = manifold_rs::Manifold::extrude(
58 &[outer_circle.as_slice(), inner_circle.as_slice()],
59 4.0,
60 16,
61 0.0,
62 1.0,
63 1.0,
64 );
65
66 manifold.write_stl_to_file("tube.stl")?;
67 }
68
69 // Convex hull of two circles
70 {
71 let left_circle = generate_circle(1.0, (-1.0, 0.0), 32);
72 let right_circle = generate_circle(1.0, (1.0, 0.0), 32);
73
74 // Extrude the circle along the z-axis
75 let manifold = manifold_rs::Manifold::extrude(
76 &[left_circle.as_slice(), right_circle.as_slice()],
77 4.0,
78 16,
79 0.0,
80 1.0,
81 1.0,
82 );
83 let manifold = manifold.hull();
84
85 manifold.write_stl_to_file("hull.stl")?;
86 }
87
88 // Trim a cylinder by a plane
89 {
90 let manifold = manifold_rs::Manifold::cylinder(1.0, 1.0, 3.0, 32);
91 let manifold = manifold.trim_by_plane(0.5, 0.5, 0.5, 0.0);
92
93 manifold.write_stl_to_file("cylinder_trimmed.stl")?;
94 }
95 Ok(())
96}Sourcepub fn translate(&self, x: f64, y: f64, z: f64) -> Self
pub fn translate(&self, x: f64, y: f64, z: f64) -> Self
Translate the manifold.
Examples found in repository?
examples/bevy.rs (line 18)
8 fn setup(
9 mut commands: Commands,
10 mut meshes: ResMut<Assets<Mesh>>,
11 mut materials: ResMut<Assets<StandardMaterial>>,
12 ) {
13 let tube = Self::cylinder_manifold(1.0, 3.0)
14 .boolean_op(
15 &Self::cylinder_manifold(0.5, 4.0),
16 manifold_rs::BooleanOp::Difference,
17 )
18 .translate(-1.5, -1.5, 0.0);
19
20 Self::add_manifold(&mut commands, &mut meshes, &mut materials, tube);
21
22 let tube_with_normals = Self::cylinder_manifold(1.0, 3.0)
23 .boolean_op(
24 &Self::cylinder_manifold(0.5, 4.0),
25 manifold_rs::BooleanOp::Difference,
26 )
27 .calculate_normals(0, 50.0)
28 .translate(1.5, 1.5, 0.0);
29
30 Self::add_manifold(
31 &mut commands,
32 &mut meshes,
33 &mut materials,
34 tube_with_normals,
35 );
36 }More examples
examples/write_ply.rs (line 25)
6fn main() -> std::io::Result<()> {
7 // Generate a cube
8 {
9 let size = 10.0;
10 let manifold = Manifold::cube(size, size, size);
11 manifold.write_ply_to_file("cube.ply")?;
12 }
13
14 // Generate a cube with normals
15 {
16 let size = 10.0;
17 let manifold = Manifold::cube(size, size, size).calculate_normals(0, 30.0);
18 manifold.write_ply_to_file("cube_normals.ply")?;
19 }
20
21 // Generate a dice and smooth it
22 {
23 let size = 10.0;
24 let manifold = Manifold::cube(size, size, size)
25 .translate(-size / 2.0, -size / 2.0, -size / 2.0)
26 .intersection(&Manifold::sphere(size / 2.0_f64.sqrt(), 64));
27
28 let manifold = manifold
29 .calculate_normals(0, 40.0)
30 .refine_to_length(0.2)
31 .smooth_out(40.0, 1.0);
32
33 manifold.write_ply_to_file("dice.ply")?;
34 }
35
36 // Generate tube with normals
37 {
38 let inner_radius = 0.3;
39 let outer_radius = 1.0;
40 let height = 2.0;
41
42 let manifold = Manifold::cylinder(outer_radius, outer_radius, height, 32)
43 .difference(&Manifold::cylinder(inner_radius, inner_radius, height, 32));
44 let manifold = manifold.calculate_normals(0, 40.0);
45
46 manifold.write_ply_to_file("tube_normals.ply")?;
47 }
48
49 Ok(())
50}Sourcepub fn sphere(radius: f64, segments: u32) -> Self
pub fn sphere(radius: f64, segments: u32) -> Self
Create a sphere manifold.
Examples found in repository?
examples/write_ply.rs (line 26)
6fn main() -> std::io::Result<()> {
7 // Generate a cube
8 {
9 let size = 10.0;
10 let manifold = Manifold::cube(size, size, size);
11 manifold.write_ply_to_file("cube.ply")?;
12 }
13
14 // Generate a cube with normals
15 {
16 let size = 10.0;
17 let manifold = Manifold::cube(size, size, size).calculate_normals(0, 30.0);
18 manifold.write_ply_to_file("cube_normals.ply")?;
19 }
20
21 // Generate a dice and smooth it
22 {
23 let size = 10.0;
24 let manifold = Manifold::cube(size, size, size)
25 .translate(-size / 2.0, -size / 2.0, -size / 2.0)
26 .intersection(&Manifold::sphere(size / 2.0_f64.sqrt(), 64));
27
28 let manifold = manifold
29 .calculate_normals(0, 40.0)
30 .refine_to_length(0.2)
31 .smooth_out(40.0, 1.0);
32
33 manifold.write_ply_to_file("dice.ply")?;
34 }
35
36 // Generate tube with normals
37 {
38 let inner_radius = 0.3;
39 let outer_radius = 1.0;
40 let height = 2.0;
41
42 let manifold = Manifold::cylinder(outer_radius, outer_radius, height, 32)
43 .difference(&Manifold::cylinder(inner_radius, inner_radius, height, 32));
44 let manifold = manifold.calculate_normals(0, 40.0);
45
46 manifold.write_ply_to_file("tube_normals.ply")?;
47 }
48
49 Ok(())
50}More examples
examples/write_stl.rs (line 19)
17fn main() -> std::io::Result<()> {
18 // Write sphere to an STL file
19 manifold_rs::Manifold::sphere(4.0, 128).write_stl_to_file("sphere.stl")?;
20
21 // Write cylinder to an STL file
22 {
23 let manifold = manifold_rs::Manifold::cylinder(1.0, 4.0, 3.0, 32);
24
25 // Convert the manifold to a mesh and back to a manifold, just for testing
26 let mesh = manifold.to_mesh();
27 let manifold = mesh.to_manifold();
28
29 manifold.write_stl_to_file("cylinder.stl")?;
30 }
31
32 // Generate torus with `revolve` and write resulting mesh to an STL file
33 {
34 // Generate circle with 32 vertices
35 let circle = generate_circle(2.0, (4.0, 0.0), 32);
36
37 // Revolve the circle 360° around the z-axis
38 let manifold = manifold_rs::Manifold::revolve(&[circle.as_slice()], 32, 360.0);
39
40 manifold.write_stl_to_file("torus.stl")?;
41 }
42
43 // Generate a tube via `extrude` and write resulting mesh to an STL file
44 {
45 // Generate circle with 32 vertices
46 let inner_circle = generate_circle(0.3, (0.0, 0.0), 32);
47 let outer_circle = generate_circle(1.0, (0.0, 0.0), 32);
48
49 // CCW winding order to create a hole in the tube
50 let inner_circle = inner_circle
51 .into_iter()
52 .enumerate()
53 .map(|(i, x)| if i % 2 == 0 { x } else { -x })
54 .collect::<Vec<_>>();
55
56 // Extrude the circle along the z-axis
57 let manifold = manifold_rs::Manifold::extrude(
58 &[outer_circle.as_slice(), inner_circle.as_slice()],
59 4.0,
60 16,
61 0.0,
62 1.0,
63 1.0,
64 );
65
66 manifold.write_stl_to_file("tube.stl")?;
67 }
68
69 // Convex hull of two circles
70 {
71 let left_circle = generate_circle(1.0, (-1.0, 0.0), 32);
72 let right_circle = generate_circle(1.0, (1.0, 0.0), 32);
73
74 // Extrude the circle along the z-axis
75 let manifold = manifold_rs::Manifold::extrude(
76 &[left_circle.as_slice(), right_circle.as_slice()],
77 4.0,
78 16,
79 0.0,
80 1.0,
81 1.0,
82 );
83 let manifold = manifold.hull();
84
85 manifold.write_stl_to_file("hull.stl")?;
86 }
87
88 // Trim a cylinder by a plane
89 {
90 let manifold = manifold_rs::Manifold::cylinder(1.0, 1.0, 3.0, 32);
91 let manifold = manifold.trim_by_plane(0.5, 0.5, 0.5, 0.0);
92
93 manifold.write_stl_to_file("cylinder_trimmed.stl")?;
94 }
95 Ok(())
96}Sourcepub fn cube(x_size: f64, y_size: f64, z_size: f64) -> Self
pub fn cube(x_size: f64, y_size: f64, z_size: f64) -> Self
Create a cube manifold.
Examples found in repository?
examples/write_ply.rs (line 10)
6fn main() -> std::io::Result<()> {
7 // Generate a cube
8 {
9 let size = 10.0;
10 let manifold = Manifold::cube(size, size, size);
11 manifold.write_ply_to_file("cube.ply")?;
12 }
13
14 // Generate a cube with normals
15 {
16 let size = 10.0;
17 let manifold = Manifold::cube(size, size, size).calculate_normals(0, 30.0);
18 manifold.write_ply_to_file("cube_normals.ply")?;
19 }
20
21 // Generate a dice and smooth it
22 {
23 let size = 10.0;
24 let manifold = Manifold::cube(size, size, size)
25 .translate(-size / 2.0, -size / 2.0, -size / 2.0)
26 .intersection(&Manifold::sphere(size / 2.0_f64.sqrt(), 64));
27
28 let manifold = manifold
29 .calculate_normals(0, 40.0)
30 .refine_to_length(0.2)
31 .smooth_out(40.0, 1.0);
32
33 manifold.write_ply_to_file("dice.ply")?;
34 }
35
36 // Generate tube with normals
37 {
38 let inner_radius = 0.3;
39 let outer_radius = 1.0;
40 let height = 2.0;
41
42 let manifold = Manifold::cylinder(outer_radius, outer_radius, height, 32)
43 .difference(&Manifold::cylinder(inner_radius, inner_radius, height, 32));
44 let manifold = manifold.calculate_normals(0, 40.0);
45
46 manifold.write_ply_to_file("tube_normals.ply")?;
47 }
48
49 Ok(())
50}Sourcepub fn cylinder(
radius_low: f64,
radius_high: f64,
height: f64,
segments: u32,
) -> Self
pub fn cylinder( radius_low: f64, radius_high: f64, height: f64, segments: u32, ) -> Self
Create a cylinder manifold.
Examples found in repository?
More examples
examples/write_ply.rs (line 42)
6fn main() -> std::io::Result<()> {
7 // Generate a cube
8 {
9 let size = 10.0;
10 let manifold = Manifold::cube(size, size, size);
11 manifold.write_ply_to_file("cube.ply")?;
12 }
13
14 // Generate a cube with normals
15 {
16 let size = 10.0;
17 let manifold = Manifold::cube(size, size, size).calculate_normals(0, 30.0);
18 manifold.write_ply_to_file("cube_normals.ply")?;
19 }
20
21 // Generate a dice and smooth it
22 {
23 let size = 10.0;
24 let manifold = Manifold::cube(size, size, size)
25 .translate(-size / 2.0, -size / 2.0, -size / 2.0)
26 .intersection(&Manifold::sphere(size / 2.0_f64.sqrt(), 64));
27
28 let manifold = manifold
29 .calculate_normals(0, 40.0)
30 .refine_to_length(0.2)
31 .smooth_out(40.0, 1.0);
32
33 manifold.write_ply_to_file("dice.ply")?;
34 }
35
36 // Generate tube with normals
37 {
38 let inner_radius = 0.3;
39 let outer_radius = 1.0;
40 let height = 2.0;
41
42 let manifold = Manifold::cylinder(outer_radius, outer_radius, height, 32)
43 .difference(&Manifold::cylinder(inner_radius, inner_radius, height, 32));
44 let manifold = manifold.calculate_normals(0, 40.0);
45
46 manifold.write_ply_to_file("tube_normals.ply")?;
47 }
48
49 Ok(())
50}examples/write_stl.rs (line 23)
17fn main() -> std::io::Result<()> {
18 // Write sphere to an STL file
19 manifold_rs::Manifold::sphere(4.0, 128).write_stl_to_file("sphere.stl")?;
20
21 // Write cylinder to an STL file
22 {
23 let manifold = manifold_rs::Manifold::cylinder(1.0, 4.0, 3.0, 32);
24
25 // Convert the manifold to a mesh and back to a manifold, just for testing
26 let mesh = manifold.to_mesh();
27 let manifold = mesh.to_manifold();
28
29 manifold.write_stl_to_file("cylinder.stl")?;
30 }
31
32 // Generate torus with `revolve` and write resulting mesh to an STL file
33 {
34 // Generate circle with 32 vertices
35 let circle = generate_circle(2.0, (4.0, 0.0), 32);
36
37 // Revolve the circle 360° around the z-axis
38 let manifold = manifold_rs::Manifold::revolve(&[circle.as_slice()], 32, 360.0);
39
40 manifold.write_stl_to_file("torus.stl")?;
41 }
42
43 // Generate a tube via `extrude` and write resulting mesh to an STL file
44 {
45 // Generate circle with 32 vertices
46 let inner_circle = generate_circle(0.3, (0.0, 0.0), 32);
47 let outer_circle = generate_circle(1.0, (0.0, 0.0), 32);
48
49 // CCW winding order to create a hole in the tube
50 let inner_circle = inner_circle
51 .into_iter()
52 .enumerate()
53 .map(|(i, x)| if i % 2 == 0 { x } else { -x })
54 .collect::<Vec<_>>();
55
56 // Extrude the circle along the z-axis
57 let manifold = manifold_rs::Manifold::extrude(
58 &[outer_circle.as_slice(), inner_circle.as_slice()],
59 4.0,
60 16,
61 0.0,
62 1.0,
63 1.0,
64 );
65
66 manifold.write_stl_to_file("tube.stl")?;
67 }
68
69 // Convex hull of two circles
70 {
71 let left_circle = generate_circle(1.0, (-1.0, 0.0), 32);
72 let right_circle = generate_circle(1.0, (1.0, 0.0), 32);
73
74 // Extrude the circle along the z-axis
75 let manifold = manifold_rs::Manifold::extrude(
76 &[left_circle.as_slice(), right_circle.as_slice()],
77 4.0,
78 16,
79 0.0,
80 1.0,
81 1.0,
82 );
83 let manifold = manifold.hull();
84
85 manifold.write_stl_to_file("hull.stl")?;
86 }
87
88 // Trim a cylinder by a plane
89 {
90 let manifold = manifold_rs::Manifold::cylinder(1.0, 1.0, 3.0, 32);
91 let manifold = manifold.trim_by_plane(0.5, 0.5, 0.5, 0.0);
92
93 manifold.write_stl_to_file("cylinder_trimmed.stl")?;
94 }
95 Ok(())
96}Sourcepub fn intersection(&self, b: &Self) -> Self
pub fn intersection(&self, b: &Self) -> Self
Get the intersection of two manifolds.
Examples found in repository?
examples/write_ply.rs (line 26)
6fn main() -> std::io::Result<()> {
7 // Generate a cube
8 {
9 let size = 10.0;
10 let manifold = Manifold::cube(size, size, size);
11 manifold.write_ply_to_file("cube.ply")?;
12 }
13
14 // Generate a cube with normals
15 {
16 let size = 10.0;
17 let manifold = Manifold::cube(size, size, size).calculate_normals(0, 30.0);
18 manifold.write_ply_to_file("cube_normals.ply")?;
19 }
20
21 // Generate a dice and smooth it
22 {
23 let size = 10.0;
24 let manifold = Manifold::cube(size, size, size)
25 .translate(-size / 2.0, -size / 2.0, -size / 2.0)
26 .intersection(&Manifold::sphere(size / 2.0_f64.sqrt(), 64));
27
28 let manifold = manifold
29 .calculate_normals(0, 40.0)
30 .refine_to_length(0.2)
31 .smooth_out(40.0, 1.0);
32
33 manifold.write_ply_to_file("dice.ply")?;
34 }
35
36 // Generate tube with normals
37 {
38 let inner_radius = 0.3;
39 let outer_radius = 1.0;
40 let height = 2.0;
41
42 let manifold = Manifold::cylinder(outer_radius, outer_radius, height, 32)
43 .difference(&Manifold::cylinder(inner_radius, inner_radius, height, 32));
44 let manifold = manifold.calculate_normals(0, 40.0);
45
46 manifold.write_ply_to_file("tube_normals.ply")?;
47 }
48
49 Ok(())
50}Sourcepub fn difference(&self, b: &Self) -> Self
pub fn difference(&self, b: &Self) -> Self
Get the difference of two manifolds.
Examples found in repository?
examples/write_ply.rs (line 43)
6fn main() -> std::io::Result<()> {
7 // Generate a cube
8 {
9 let size = 10.0;
10 let manifold = Manifold::cube(size, size, size);
11 manifold.write_ply_to_file("cube.ply")?;
12 }
13
14 // Generate a cube with normals
15 {
16 let size = 10.0;
17 let manifold = Manifold::cube(size, size, size).calculate_normals(0, 30.0);
18 manifold.write_ply_to_file("cube_normals.ply")?;
19 }
20
21 // Generate a dice and smooth it
22 {
23 let size = 10.0;
24 let manifold = Manifold::cube(size, size, size)
25 .translate(-size / 2.0, -size / 2.0, -size / 2.0)
26 .intersection(&Manifold::sphere(size / 2.0_f64.sqrt(), 64));
27
28 let manifold = manifold
29 .calculate_normals(0, 40.0)
30 .refine_to_length(0.2)
31 .smooth_out(40.0, 1.0);
32
33 manifold.write_ply_to_file("dice.ply")?;
34 }
35
36 // Generate tube with normals
37 {
38 let inner_radius = 0.3;
39 let outer_radius = 1.0;
40 let height = 2.0;
41
42 let manifold = Manifold::cylinder(outer_radius, outer_radius, height, 32)
43 .difference(&Manifold::cylinder(inner_radius, inner_radius, height, 32));
44 let manifold = manifold.calculate_normals(0, 40.0);
45
46 manifold.write_ply_to_file("tube_normals.ply")?;
47 }
48
49 Ok(())
50}Sourcepub fn boolean_op(&self, b: &Self, op: BooleanOp) -> Self
pub fn boolean_op(&self, b: &Self, op: BooleanOp) -> Self
Boolean operation on manifolds.
Examples found in repository?
examples/bevy.rs (lines 14-17)
8 fn setup(
9 mut commands: Commands,
10 mut meshes: ResMut<Assets<Mesh>>,
11 mut materials: ResMut<Assets<StandardMaterial>>,
12 ) {
13 let tube = Self::cylinder_manifold(1.0, 3.0)
14 .boolean_op(
15 &Self::cylinder_manifold(0.5, 4.0),
16 manifold_rs::BooleanOp::Difference,
17 )
18 .translate(-1.5, -1.5, 0.0);
19
20 Self::add_manifold(&mut commands, &mut meshes, &mut materials, tube);
21
22 let tube_with_normals = Self::cylinder_manifold(1.0, 3.0)
23 .boolean_op(
24 &Self::cylinder_manifold(0.5, 4.0),
25 manifold_rs::BooleanOp::Difference,
26 )
27 .calculate_normals(0, 50.0)
28 .translate(1.5, 1.5, 0.0);
29
30 Self::add_manifold(
31 &mut commands,
32 &mut meshes,
33 &mut materials,
34 tube_with_normals,
35 );
36 }Sourcepub fn extrude(
multi_polygon_data: &[&[f64]],
height: f64,
n_divisions: u32,
twist_degrees: f64,
scale_top_x: f64,
scale_top_y: f64,
) -> Self
pub fn extrude( multi_polygon_data: &[&[f64]], height: f64, n_divisions: u32, twist_degrees: f64, scale_top_x: f64, scale_top_y: f64, ) -> Self
Extrude a polygon to create a manifold.
Examples found in repository?
examples/write_stl.rs (lines 57-64)
17fn main() -> std::io::Result<()> {
18 // Write sphere to an STL file
19 manifold_rs::Manifold::sphere(4.0, 128).write_stl_to_file("sphere.stl")?;
20
21 // Write cylinder to an STL file
22 {
23 let manifold = manifold_rs::Manifold::cylinder(1.0, 4.0, 3.0, 32);
24
25 // Convert the manifold to a mesh and back to a manifold, just for testing
26 let mesh = manifold.to_mesh();
27 let manifold = mesh.to_manifold();
28
29 manifold.write_stl_to_file("cylinder.stl")?;
30 }
31
32 // Generate torus with `revolve` and write resulting mesh to an STL file
33 {
34 // Generate circle with 32 vertices
35 let circle = generate_circle(2.0, (4.0, 0.0), 32);
36
37 // Revolve the circle 360° around the z-axis
38 let manifold = manifold_rs::Manifold::revolve(&[circle.as_slice()], 32, 360.0);
39
40 manifold.write_stl_to_file("torus.stl")?;
41 }
42
43 // Generate a tube via `extrude` and write resulting mesh to an STL file
44 {
45 // Generate circle with 32 vertices
46 let inner_circle = generate_circle(0.3, (0.0, 0.0), 32);
47 let outer_circle = generate_circle(1.0, (0.0, 0.0), 32);
48
49 // CCW winding order to create a hole in the tube
50 let inner_circle = inner_circle
51 .into_iter()
52 .enumerate()
53 .map(|(i, x)| if i % 2 == 0 { x } else { -x })
54 .collect::<Vec<_>>();
55
56 // Extrude the circle along the z-axis
57 let manifold = manifold_rs::Manifold::extrude(
58 &[outer_circle.as_slice(), inner_circle.as_slice()],
59 4.0,
60 16,
61 0.0,
62 1.0,
63 1.0,
64 );
65
66 manifold.write_stl_to_file("tube.stl")?;
67 }
68
69 // Convex hull of two circles
70 {
71 let left_circle = generate_circle(1.0, (-1.0, 0.0), 32);
72 let right_circle = generate_circle(1.0, (1.0, 0.0), 32);
73
74 // Extrude the circle along the z-axis
75 let manifold = manifold_rs::Manifold::extrude(
76 &[left_circle.as_slice(), right_circle.as_slice()],
77 4.0,
78 16,
79 0.0,
80 1.0,
81 1.0,
82 );
83 let manifold = manifold.hull();
84
85 manifold.write_stl_to_file("hull.stl")?;
86 }
87
88 // Trim a cylinder by a plane
89 {
90 let manifold = manifold_rs::Manifold::cylinder(1.0, 1.0, 3.0, 32);
91 let manifold = manifold.trim_by_plane(0.5, 0.5, 0.5, 0.0);
92
93 manifold.write_stl_to_file("cylinder_trimmed.stl")?;
94 }
95 Ok(())
96}Sourcepub fn revolve(
multi_polygon_data: &[&[f64]],
circular_segments: u32,
revolve_degrees: f64,
) -> Self
pub fn revolve( multi_polygon_data: &[&[f64]], circular_segments: u32, revolve_degrees: f64, ) -> Self
Revolve a polygon to create a manifold.
Examples found in repository?
examples/write_stl.rs (line 38)
17fn main() -> std::io::Result<()> {
18 // Write sphere to an STL file
19 manifold_rs::Manifold::sphere(4.0, 128).write_stl_to_file("sphere.stl")?;
20
21 // Write cylinder to an STL file
22 {
23 let manifold = manifold_rs::Manifold::cylinder(1.0, 4.0, 3.0, 32);
24
25 // Convert the manifold to a mesh and back to a manifold, just for testing
26 let mesh = manifold.to_mesh();
27 let manifold = mesh.to_manifold();
28
29 manifold.write_stl_to_file("cylinder.stl")?;
30 }
31
32 // Generate torus with `revolve` and write resulting mesh to an STL file
33 {
34 // Generate circle with 32 vertices
35 let circle = generate_circle(2.0, (4.0, 0.0), 32);
36
37 // Revolve the circle 360° around the z-axis
38 let manifold = manifold_rs::Manifold::revolve(&[circle.as_slice()], 32, 360.0);
39
40 manifold.write_stl_to_file("torus.stl")?;
41 }
42
43 // Generate a tube via `extrude` and write resulting mesh to an STL file
44 {
45 // Generate circle with 32 vertices
46 let inner_circle = generate_circle(0.3, (0.0, 0.0), 32);
47 let outer_circle = generate_circle(1.0, (0.0, 0.0), 32);
48
49 // CCW winding order to create a hole in the tube
50 let inner_circle = inner_circle
51 .into_iter()
52 .enumerate()
53 .map(|(i, x)| if i % 2 == 0 { x } else { -x })
54 .collect::<Vec<_>>();
55
56 // Extrude the circle along the z-axis
57 let manifold = manifold_rs::Manifold::extrude(
58 &[outer_circle.as_slice(), inner_circle.as_slice()],
59 4.0,
60 16,
61 0.0,
62 1.0,
63 1.0,
64 );
65
66 manifold.write_stl_to_file("tube.stl")?;
67 }
68
69 // Convex hull of two circles
70 {
71 let left_circle = generate_circle(1.0, (-1.0, 0.0), 32);
72 let right_circle = generate_circle(1.0, (1.0, 0.0), 32);
73
74 // Extrude the circle along the z-axis
75 let manifold = manifold_rs::Manifold::extrude(
76 &[left_circle.as_slice(), right_circle.as_slice()],
77 4.0,
78 16,
79 0.0,
80 1.0,
81 1.0,
82 );
83 let manifold = manifold.hull();
84
85 manifold.write_stl_to_file("hull.stl")?;
86 }
87
88 // Trim a cylinder by a plane
89 {
90 let manifold = manifold_rs::Manifold::cylinder(1.0, 1.0, 3.0, 32);
91 let manifold = manifold.trim_by_plane(0.5, 0.5, 0.5, 0.0);
92
93 manifold.write_stl_to_file("cylinder_trimmed.stl")?;
94 }
95 Ok(())
96}Sourcepub fn refine_to_length(self: &Manifold, t: f64) -> Self
pub fn refine_to_length(self: &Manifold, t: f64) -> Self
Refine manifold to Length.
Examples found in repository?
examples/write_ply.rs (line 30)
6fn main() -> std::io::Result<()> {
7 // Generate a cube
8 {
9 let size = 10.0;
10 let manifold = Manifold::cube(size, size, size);
11 manifold.write_ply_to_file("cube.ply")?;
12 }
13
14 // Generate a cube with normals
15 {
16 let size = 10.0;
17 let manifold = Manifold::cube(size, size, size).calculate_normals(0, 30.0);
18 manifold.write_ply_to_file("cube_normals.ply")?;
19 }
20
21 // Generate a dice and smooth it
22 {
23 let size = 10.0;
24 let manifold = Manifold::cube(size, size, size)
25 .translate(-size / 2.0, -size / 2.0, -size / 2.0)
26 .intersection(&Manifold::sphere(size / 2.0_f64.sqrt(), 64));
27
28 let manifold = manifold
29 .calculate_normals(0, 40.0)
30 .refine_to_length(0.2)
31 .smooth_out(40.0, 1.0);
32
33 manifold.write_ply_to_file("dice.ply")?;
34 }
35
36 // Generate tube with normals
37 {
38 let inner_radius = 0.3;
39 let outer_radius = 1.0;
40 let height = 2.0;
41
42 let manifold = Manifold::cylinder(outer_radius, outer_radius, height, 32)
43 .difference(&Manifold::cylinder(inner_radius, inner_radius, height, 32));
44 let manifold = manifold.calculate_normals(0, 40.0);
45
46 manifold.write_ply_to_file("tube_normals.ply")?;
47 }
48
49 Ok(())
50}Sourcepub fn refine_to_tolerance(self: &Manifold, t: f64) -> Self
pub fn refine_to_tolerance(self: &Manifold, t: f64) -> Self
Refine to tolerance.
Sourcepub fn smooth_by_normals(self: &Manifold, normal_idx: i32) -> Self
pub fn smooth_by_normals(self: &Manifold, normal_idx: i32) -> Self
Smooth by normals.
Sourcepub fn smooth_out(
self: &Manifold,
min_sharp_angle: f64,
min_smoothness: f64,
) -> Self
pub fn smooth_out( self: &Manifold, min_sharp_angle: f64, min_smoothness: f64, ) -> Self
Smooth out.
Examples found in repository?
examples/write_ply.rs (line 31)
6fn main() -> std::io::Result<()> {
7 // Generate a cube
8 {
9 let size = 10.0;
10 let manifold = Manifold::cube(size, size, size);
11 manifold.write_ply_to_file("cube.ply")?;
12 }
13
14 // Generate a cube with normals
15 {
16 let size = 10.0;
17 let manifold = Manifold::cube(size, size, size).calculate_normals(0, 30.0);
18 manifold.write_ply_to_file("cube_normals.ply")?;
19 }
20
21 // Generate a dice and smooth it
22 {
23 let size = 10.0;
24 let manifold = Manifold::cube(size, size, size)
25 .translate(-size / 2.0, -size / 2.0, -size / 2.0)
26 .intersection(&Manifold::sphere(size / 2.0_f64.sqrt(), 64));
27
28 let manifold = manifold
29 .calculate_normals(0, 40.0)
30 .refine_to_length(0.2)
31 .smooth_out(40.0, 1.0);
32
33 manifold.write_ply_to_file("dice.ply")?;
34 }
35
36 // Generate tube with normals
37 {
38 let inner_radius = 0.3;
39 let outer_radius = 1.0;
40 let height = 2.0;
41
42 let manifold = Manifold::cylinder(outer_radius, outer_radius, height, 32)
43 .difference(&Manifold::cylinder(inner_radius, inner_radius, height, 32));
44 let manifold = manifold.calculate_normals(0, 40.0);
45
46 manifold.write_ply_to_file("tube_normals.ply")?;
47 }
48
49 Ok(())
50}Sourcepub fn calculate_normals(
self: &Manifold,
normal_idx: i32,
min_sharp_angle: f64,
) -> Self
pub fn calculate_normals( self: &Manifold, normal_idx: i32, min_sharp_angle: f64, ) -> Self
Calculate normals for the manifold and return a new one.
Examples found in repository?
examples/bevy.rs (line 27)
8 fn setup(
9 mut commands: Commands,
10 mut meshes: ResMut<Assets<Mesh>>,
11 mut materials: ResMut<Assets<StandardMaterial>>,
12 ) {
13 let tube = Self::cylinder_manifold(1.0, 3.0)
14 .boolean_op(
15 &Self::cylinder_manifold(0.5, 4.0),
16 manifold_rs::BooleanOp::Difference,
17 )
18 .translate(-1.5, -1.5, 0.0);
19
20 Self::add_manifold(&mut commands, &mut meshes, &mut materials, tube);
21
22 let tube_with_normals = Self::cylinder_manifold(1.0, 3.0)
23 .boolean_op(
24 &Self::cylinder_manifold(0.5, 4.0),
25 manifold_rs::BooleanOp::Difference,
26 )
27 .calculate_normals(0, 50.0)
28 .translate(1.5, 1.5, 0.0);
29
30 Self::add_manifold(
31 &mut commands,
32 &mut meshes,
33 &mut materials,
34 tube_with_normals,
35 );
36 }More examples
examples/write_ply.rs (line 17)
6fn main() -> std::io::Result<()> {
7 // Generate a cube
8 {
9 let size = 10.0;
10 let manifold = Manifold::cube(size, size, size);
11 manifold.write_ply_to_file("cube.ply")?;
12 }
13
14 // Generate a cube with normals
15 {
16 let size = 10.0;
17 let manifold = Manifold::cube(size, size, size).calculate_normals(0, 30.0);
18 manifold.write_ply_to_file("cube_normals.ply")?;
19 }
20
21 // Generate a dice and smooth it
22 {
23 let size = 10.0;
24 let manifold = Manifold::cube(size, size, size)
25 .translate(-size / 2.0, -size / 2.0, -size / 2.0)
26 .intersection(&Manifold::sphere(size / 2.0_f64.sqrt(), 64));
27
28 let manifold = manifold
29 .calculate_normals(0, 40.0)
30 .refine_to_length(0.2)
31 .smooth_out(40.0, 1.0);
32
33 manifold.write_ply_to_file("dice.ply")?;
34 }
35
36 // Generate tube with normals
37 {
38 let inner_radius = 0.3;
39 let outer_radius = 1.0;
40 let height = 2.0;
41
42 let manifold = Manifold::cylinder(outer_radius, outer_radius, height, 32)
43 .difference(&Manifold::cylinder(inner_radius, inner_radius, height, 32));
44 let manifold = manifold.calculate_normals(0, 40.0);
45
46 manifold.write_ply_to_file("tube_normals.ply")?;
47 }
48
49 Ok(())
50}Sourcepub fn to_mesh(&self) -> Mesh
pub fn to_mesh(&self) -> Mesh
Get the mesh representation of the manifold.
Examples found in repository?
examples/bevy.rs (line 89)
88 fn manifold_to_bevy_mesh(manifold: manifold_rs::Manifold) -> Mesh {
89 let mesh = manifold.to_mesh();
90
91 let vertices = mesh.vertices();
92 let indices = mesh.indices();
93
94 match mesh.num_props() {
95 // Vertex without normals
96 3 => {
97 let vertices = vertices
98 .chunks(3)
99 .map(|c| -> [f32; 3] { c.try_into().expect("Chunk size should be 3") })
100 .collect::<Vec<[f32; 3]>>();
101
102 Mesh::new(
103 bevy::render::mesh::PrimitiveTopology::TriangleList,
104 bevy::asset::RenderAssetUsages::MAIN_WORLD
105 | bevy::asset::RenderAssetUsages::RENDER_WORLD,
106 )
107 .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, vertices)
108 .with_inserted_indices(bevy::render::mesh::Indices::U32(indices))
109 .with_duplicated_vertices()
110 .with_computed_flat_normals()
111 }
112 // Vertex with normals
113 6 => {
114 let normals = vertices
115 .chunks(6)
116 .map(|c| -> [f32; 3] { [c[3], c[4], c[5]] })
117 .collect::<Vec<[f32; 3]>>();
118
119 let vertices = vertices
120 .chunks(6)
121 .map(|c| -> [f32; 3] { [c[0], c[1], c[2]] })
122 .collect::<Vec<[f32; 3]>>();
123
124 Mesh::new(
125 bevy::render::mesh::PrimitiveTopology::TriangleList,
126 bevy::asset::RenderAssetUsages::MAIN_WORLD
127 | bevy::asset::RenderAssetUsages::RENDER_WORLD,
128 )
129 .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, vertices)
130 .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, normals)
131 .with_inserted_indices(bevy::render::mesh::Indices::U32(indices))
132 }
133 num_props => panic!("Invalid property count {num_props}"),
134 }
135 }More examples
examples/write_stl.rs (line 26)
17fn main() -> std::io::Result<()> {
18 // Write sphere to an STL file
19 manifold_rs::Manifold::sphere(4.0, 128).write_stl_to_file("sphere.stl")?;
20
21 // Write cylinder to an STL file
22 {
23 let manifold = manifold_rs::Manifold::cylinder(1.0, 4.0, 3.0, 32);
24
25 // Convert the manifold to a mesh and back to a manifold, just for testing
26 let mesh = manifold.to_mesh();
27 let manifold = mesh.to_manifold();
28
29 manifold.write_stl_to_file("cylinder.stl")?;
30 }
31
32 // Generate torus with `revolve` and write resulting mesh to an STL file
33 {
34 // Generate circle with 32 vertices
35 let circle = generate_circle(2.0, (4.0, 0.0), 32);
36
37 // Revolve the circle 360° around the z-axis
38 let manifold = manifold_rs::Manifold::revolve(&[circle.as_slice()], 32, 360.0);
39
40 manifold.write_stl_to_file("torus.stl")?;
41 }
42
43 // Generate a tube via `extrude` and write resulting mesh to an STL file
44 {
45 // Generate circle with 32 vertices
46 let inner_circle = generate_circle(0.3, (0.0, 0.0), 32);
47 let outer_circle = generate_circle(1.0, (0.0, 0.0), 32);
48
49 // CCW winding order to create a hole in the tube
50 let inner_circle = inner_circle
51 .into_iter()
52 .enumerate()
53 .map(|(i, x)| if i % 2 == 0 { x } else { -x })
54 .collect::<Vec<_>>();
55
56 // Extrude the circle along the z-axis
57 let manifold = manifold_rs::Manifold::extrude(
58 &[outer_circle.as_slice(), inner_circle.as_slice()],
59 4.0,
60 16,
61 0.0,
62 1.0,
63 1.0,
64 );
65
66 manifold.write_stl_to_file("tube.stl")?;
67 }
68
69 // Convex hull of two circles
70 {
71 let left_circle = generate_circle(1.0, (-1.0, 0.0), 32);
72 let right_circle = generate_circle(1.0, (1.0, 0.0), 32);
73
74 // Extrude the circle along the z-axis
75 let manifold = manifold_rs::Manifold::extrude(
76 &[left_circle.as_slice(), right_circle.as_slice()],
77 4.0,
78 16,
79 0.0,
80 1.0,
81 1.0,
82 );
83 let manifold = manifold.hull();
84
85 manifold.write_stl_to_file("hull.stl")?;
86 }
87
88 // Trim a cylinder by a plane
89 {
90 let manifold = manifold_rs::Manifold::cylinder(1.0, 1.0, 3.0, 32);
91 let manifold = manifold.trim_by_plane(0.5, 0.5, 0.5, 0.0);
92
93 manifold.write_stl_to_file("cylinder_trimmed.stl")?;
94 }
95 Ok(())
96}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Manifold
impl RefUnwindSafe for Manifold
impl !Send for Manifold
impl !Sync for Manifold
impl Unpin for Manifold
impl UnwindSafe for Manifold
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more