density_mesh_core/mesh/
settings.rs

1use crate::{mesh::points_separation::PointsSeparation, Scalar};
2use serde::{Deserialize, Serialize};
3
4/// Settings of density mesh generation.
5#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6pub struct GenerateDensityMeshSettings {
7    /// Minimal points separation.
8    #[serde(default = "GenerateDensityMeshSettings::default_points_separation")]
9    pub points_separation: PointsSeparation,
10    /// Minimal visibility treshold.
11    #[serde(default = "GenerateDensityMeshSettings::default_visibility_threshold")]
12    pub visibility_threshold: Scalar,
13    /// Minimal steepness treshold.
14    #[serde(default = "GenerateDensityMeshSettings::default_steepness_threshold")]
15    pub steepness_threshold: Scalar,
16    /// Limit of iterations when cannot find next available point.
17    #[serde(default = "GenerateDensityMeshSettings::default_max_iterations")]
18    pub max_iterations: usize,
19    /// Optional extrude size.
20    #[serde(default)]
21    pub extrude_size: Option<Scalar>,
22    /// Keep invisible triangles.
23    #[serde(default)]
24    pub keep_invisible_triangles: bool,
25}
26
27impl Default for GenerateDensityMeshSettings {
28    fn default() -> Self {
29        Self {
30            points_separation: Self::default_points_separation(),
31            visibility_threshold: Self::default_visibility_threshold(),
32            steepness_threshold: Self::default_steepness_threshold(),
33            max_iterations: Self::default_max_iterations(),
34            extrude_size: None,
35            keep_invisible_triangles: false,
36        }
37    }
38}
39
40impl GenerateDensityMeshSettings {
41    fn default_points_separation() -> PointsSeparation {
42        PointsSeparation::Constant(10.0)
43    }
44
45    fn default_visibility_threshold() -> Scalar {
46        0.01
47    }
48
49    fn default_steepness_threshold() -> Scalar {
50        0.01
51    }
52
53    fn default_max_iterations() -> usize {
54        32
55    }
56}