Skip to main content

opensubdiv_rs/sdc/
types.rs

1//! Basic scheme types and traits (port of `opensubdiv/sdc/types.h`).
2
3/// Enumerated type for all subdivision schemes supported by OpenSubdiv
4/// (`Sdc::SchemeType`).
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
6pub enum SchemeType {
7    /// Bilinear subdivision: faces are split into quads and primvar data is
8    /// interpolated linearly. The limit surface is the control mesh itself.
9    Bilinear,
10    /// Catmull-Clark subdivision — the industry standard for quad-dominant
11    /// meshes. Faces of any size are supported; all child faces are quads.
12    #[default]
13    Catmark,
14    /// Loop subdivision — for purely triangular meshes; all child faces are
15    /// triangles.
16    Loop,
17}
18
19/// Enumerated type for the topological split applied by a scheme
20/// (`Sdc::Split`).
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22pub enum Split {
23    /// Used by Catmark and Bilinear: an N-sided face is split into N quads.
24    ToQuads,
25    /// Used by Loop: a triangle is split into 4 triangles.
26    ToTris,
27    /// Not currently used (reserved, as in OpenSubdiv).
28    Hybrid,
29}
30
31impl SchemeType {
32    /// The topological split for this scheme
33    /// (`Sdc::SchemeTypeTraits::GetTopologicalSplitType()`).
34    pub fn topological_split_type(self) -> Split {
35        match self {
36            SchemeType::Bilinear | SchemeType::Catmark => Split::ToQuads,
37            SchemeType::Loop => Split::ToTris,
38        }
39    }
40
41    /// Number of vertices of a "regular" face for the scheme
42    /// (`Sdc::SchemeTypeTraits::GetRegularFaceSize()`).
43    pub fn regular_face_size(self) -> usize {
44        match self {
45            SchemeType::Bilinear | SchemeType::Catmark => 4,
46            SchemeType::Loop => 3,
47        }
48    }
49
50    /// Valence of a "regular" interior vertex for the scheme
51    /// (`Sdc::SchemeTypeTraits::GetRegularVertexValence()`).
52    pub fn regular_vertex_valence(self) -> usize {
53        match self {
54            SchemeType::Bilinear | SchemeType::Catmark => 4,
55            SchemeType::Loop => 6,
56        }
57    }
58
59    /// Whether local neighborhoods of the scheme's limit surface are purely
60    /// linear (true only for Bilinear).
61    pub fn is_linear(self) -> bool {
62        matches!(self, SchemeType::Bilinear)
63    }
64
65    /// The name of the scheme, as in `Sdc::SchemeTypeTraits::GetName()`.
66    pub fn name(self) -> &'static str {
67        match self {
68            SchemeType::Bilinear => "Bilinear",
69            SchemeType::Catmark => "Catmark",
70            SchemeType::Loop => "Loop",
71        }
72    }
73}