opensubdiv_rs/sdc/options.rs
1//! Standard subdivision options (port of `opensubdiv/sdc/options.h`).
2
3/// Boundary interpolation rules for vertex (position) data
4/// (`Sdc::Options::VtxBoundaryInterpolation`).
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
6pub enum VtxBoundaryInterpolation {
7 /// Smooth boundaries: no boundary edge or vertex is sharpened, so
8 /// boundaries of the mesh "shrink" toward the interior. Note that
9 /// (matching OpenSubdiv) child vertices *are* still generated for
10 /// boundary components.
11 None,
12 /// Sharpen boundary edges only ("edge only"): boundaries behave as
13 /// creases; boundary corners are rounded.
14 #[default]
15 EdgeOnly,
16 /// Sharpen boundary edges *and* pin boundary corners (vertices incident
17 /// to exactly one face).
18 EdgeAndCorner,
19}
20
21/// Face-varying linear-interpolation rules
22/// (`Sdc::Options::FVarLinearInterpolation`).
23///
24/// These rules govern how face-varying channels (see
25/// [`FVarChannelDescriptor`](crate::far::FVarChannelDescriptor)) are refined
26/// and limited by
27/// [`PrimvarRefiner::interpolate_face_varying`](crate::far::PrimvarRefiner::interpolate_face_varying)
28/// and
29/// [`PrimvarRefiner::limit_face_varying`](crate::far::PrimvarRefiner::limit_face_varying).
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
31pub enum FVarLinearInterpolation {
32 /// Smooth everywhere the mesh is smooth.
33 None,
34 /// Linearly interpolate (sharpen) corners only.
35 #[default]
36 CornersOnly,
37 /// `CornersOnly` + sharpening of junctions of three or more edges.
38 CornersPlus1,
39 /// `CornersPlus1` + sharpening of darts and concave corners.
40 CornersPlus2,
41 /// Linear interpolation along all boundary edges and corners.
42 Boundaries,
43 /// Linear interpolation everywhere ("bilinear" face-varying).
44 All,
45}
46
47/// Method used to subdivide (semi-sharp) crease sharpness values
48/// (`Sdc::Options::CreasingMethod`).
49#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
50pub enum CreasingMethod {
51 /// Classic Catmull-Clark semi-sharp creasing: a child edge's sharpness is
52 /// its parent's sharpness reduced by one.
53 #[default]
54 Uniform,
55 /// Chaikin creasing: sharpness of child edges is additionally averaged
56 /// with the other sharp edges around the shared vertex, giving smoother
57 /// decay along a crease of varying sharpness.
58 Chaikin,
59}
60
61/// How triangular faces are subdivided by the Catmark scheme
62/// (`Sdc::Options::TriangleSubdivision`).
63#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
64pub enum TriangleSubdivision {
65 /// The standard Catmull-Clark weights.
66 #[default]
67 Catmark,
68 /// The "smooth triangle" weight adjustment of the original Catmull-Clark
69 /// paper (`TRI_SUB_SMOOTH`): the child vertex of an interior edge with a
70 /// triangle on either side takes more of its position from the incident
71 /// face points (0.470 per triangle instead of 1/4) and less from the
72 /// edge's end vertices, removing the pinching plain Catmark produces at
73 /// triangles inside a quad mesh. Face points and vertex points are not
74 /// affected, and the rule only acts at the base level: after one
75 /// refinement every face is a quad.
76 ///
77 /// This is USD's `triangleSubdivisionRule = "smooth"`.
78 Smooth,
79}
80
81/// All supported options applying to subdivision scheme rules
82/// (`Sdc::Options`).
83///
84/// Instances are lightweight and copyable; the default value of every field
85/// matches OpenSubdiv's defaults.
86#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
87pub struct Options {
88 /// How vertices and edges on a mesh boundary are interpolated.
89 pub vtx_boundary_interpolation: VtxBoundaryInterpolation,
90 /// How face-varying data is interpolated around seams and boundaries.
91 pub fvar_linear_interpolation: FVarLinearInterpolation,
92 /// How semi-sharp creases decay under subdivision.
93 pub creasing_method: CreasingMethod,
94 /// Which weights are used when subdividing triangles.
95 pub triangle_subdivision: TriangleSubdivision,
96}
97
98impl Options {
99 /// Options with every field set to its OpenSubdiv default.
100 pub fn new() -> Self {
101 Self::default()
102 }
103
104 /// Builder-style setter for [`VtxBoundaryInterpolation`].
105 pub fn with_vtx_boundary_interpolation(mut self, v: VtxBoundaryInterpolation) -> Self {
106 self.vtx_boundary_interpolation = v;
107 self
108 }
109
110 /// Builder-style setter for [`FVarLinearInterpolation`].
111 pub fn with_fvar_linear_interpolation(mut self, v: FVarLinearInterpolation) -> Self {
112 self.fvar_linear_interpolation = v;
113 self
114 }
115
116 /// Builder-style setter for [`CreasingMethod`].
117 pub fn with_creasing_method(mut self, v: CreasingMethod) -> Self {
118 self.creasing_method = v;
119 self
120 }
121
122 /// Builder-style setter for [`TriangleSubdivision`].
123 pub fn with_triangle_subdivision(mut self, v: TriangleSubdivision) -> Self {
124 self.triangle_subdivision = v;
125 self
126 }
127}