mesh_shell/
lib.rs

1//! Shell generation around 3D meshes using SDF-based offset.
2//!
3//! This crate provides tools for generating printable shells around 3D meshes
4//! using signed distance field (SDF) based offset techniques.
5//!
6//! # Features
7//!
8//! - **SDF-based offset**: Robust offset that avoids self-intersections
9//! - **Variable offset**: Per-vertex offset values for complex shapes
10//! - **Shell generation**: Create watertight shells with walls
11//! - **Rim generation**: Clean boundary edges connecting inner and outer surfaces
12//! - **Builder API**: Fluent builder pattern for ergonomic configuration
13//!
14//! # Quick Start with ShellBuilder
15//!
16//! The recommended way to generate shells is using the [`ShellBuilder`]:
17//!
18//! ```no_run
19//! use mesh_repair::Mesh;
20//! use mesh_shell::ShellBuilder;
21//!
22//! let mesh = Mesh::load("scan.stl").unwrap();
23//!
24//! // Simple: generate shell with defaults
25//! let result = ShellBuilder::new(&mesh)
26//!     .offset(2.0)           // 2mm outward offset
27//!     .wall_thickness(2.5)   // 2.5mm walls
28//!     .build()
29//!     .unwrap();
30//!
31//! result.mesh.save("shell.3mf").unwrap();
32//! ```
33//!
34//! # Advanced Configuration
35//!
36//! ```no_run
37//! use mesh_repair::Mesh;
38//! use mesh_repair::progress::ProgressCallback;
39//! use mesh_shell::ShellBuilder;
40//!
41//! let mesh = Mesh::load("scan.stl").unwrap();
42//!
43//! let callback: ProgressCallback = Box::new(|progress| {
44//!     println!("{}%: {}", progress.percent(), progress.message);
45//!     true // continue
46//! });
47//!
48//! let result = ShellBuilder::new(&mesh)
49//!     .offset(3.0)
50//!     .wall_thickness(2.0)
51//!     .voxel_size(0.5)       // Fine resolution
52//!     .high_quality()         // SDF-based walls
53//!     .use_gpu(true)          // GPU acceleration
54//!     .with_progress(callback)
55//!     .build()
56//!     .unwrap();
57//! ```
58//!
59//! # Low-Level API
60//!
61//! For more control, use the low-level functions directly:
62//!
63//! ```no_run
64//! use mesh_repair::Mesh;
65//! use mesh_shell::{apply_sdf_offset, generate_shell, SdfOffsetParams, ShellParams};
66//!
67//! let mut mesh = Mesh::load("scan.stl").unwrap();
68//!
69//! // Set offset values on vertices
70//! for v in &mut mesh.vertices {
71//!     v.offset = Some(2.0);
72//! }
73//!
74//! // Apply SDF offset
75//! let params = SdfOffsetParams::default();
76//! let result = apply_sdf_offset(&mesh, &params).unwrap();
77//!
78//! // Generate shell with walls
79//! let shell_params = ShellParams::default();
80//! let (shell, stats) = generate_shell(&result.mesh, &shell_params);
81//!
82//! shell.save("shell.3mf").unwrap();
83//! ```
84
85mod builder;
86mod error;
87mod offset;
88mod shell;
89
90pub use error::{ShellError, ShellResult};
91
92// Builder API (recommended)
93pub use builder::{ShellBuildResult, ShellBuilder};
94
95// SDF offset
96pub use offset::{SdfOffsetParams, SdfOffsetResult, SdfOffsetStats, apply_sdf_offset};
97
98// Shell generation (rename to avoid conflict with error::ShellResult)
99pub use shell::{
100    ShellParams, ShellResult as ShellGenerationResult, WallGenerationMethod, generate_shell,
101    generate_shell_no_validation, generate_shell_with_progress,
102};
103
104// Shell validation and repair
105pub use shell::{
106    ShellIssue, ShellRepairResult, ShellValidationResult, repair_shell, validate_and_repair_shell,
107    validate_shell,
108};
109
110// Rim generation and boundary analysis
111pub use shell::{
112    BoundaryAnalysis, BoundaryLoop, RimResult, analyze_boundary, generate_rim,
113    generate_rim_advanced, generate_rim_for_sdf_shell, validate_boundary_for_rim,
114};