Skip to content

Commit e17e98f

Browse files
committed
Better documentation
1 parent 4844abe commit e17e98f

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/mikktspace.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ fn generate_tangent_space<I: Geometry<O>, O: Ops>(
124124
struct TangentSpace<O: Ops> {
125125
/// [`RawTangentSpace`] value this [`TangentSpace`] contains.
126126
value: RawTangentSpace<O>,
127-
is_averaged: bool,
127+
/// Indicates this value has already been [combined](RawTangentSpace::combine)
128+
/// with another.
129+
/// This only occurs with quads, where each triangle's tangent values
130+
/// will be combined to produce the final result.
131+
is_combined: bool,
128132
orientation_preserving: bool,
129133
}
130134

@@ -157,16 +161,24 @@ impl<O: Ops> From<TangentSpace<O>> for crate::TangentSpace {
157161
struct TriangleInfo<O: Ops> {
158162
/// Stores the index of each neighboring triangle to this one, if any.
159163
/// Indices correspond to _edges_ of this triangle, rather than _vertices_.
164+
///
165+
/// In other words, `face_neighbors[n] = a` implies the nth edge is shared with
166+
/// a [triangle](TriangleInfo) with index `a`.
160167
face_neighbors: [Option<usize>; 3],
161-
162168
/// Stores which [`Group`] each vertex on this triangle is a member of, if any.
169+
///
170+
/// In other words, `assigned_group[n] = a` implies the nth vertex is a part
171+
/// of the [`Group`] indexed by `a`.
163172
assigned_group: [Option<usize>; 3],
164-
173+
/// First-order tangent and bi-tangent value for this triangle.
165174
tangent: RawTangentSpace<O>,
166-
167175
/// Determines if the current and the next triangle are a quad.
168176
original_face_index: usize,
169-
177+
/// Index into a list of [`TangentSpace`] values.
178+
/// As each [`TangentSpace`] value corresponds to a vertex on this triangle,
179+
/// [`tangent_spaces_offset`](TriangleInfo::tangent_spaces_offset) corresponds
180+
/// to the 0th vertex, `tangent_spaces_offset + 1` to the 1st, and likewise
181+
/// `tangent_spaces_offset + 2` to the 2nd.
170182
tangent_spaces_offset: usize,
171183
/// Indicates which vertex this triangle does not contain from its original face.
172184
/// For triangles, this will be [`None`].
@@ -178,6 +190,10 @@ struct TriangleInfo<O: Ops> {
178190
/// Indicates this triangle is a member of a quad where one of the triangles
179191
/// is degenerate, but the other is not.
180192
quad_with_one_degenerate_triangle: bool,
193+
/// Indicates that this triangle can be [grouped](Group) with any of its
194+
/// neighbors, regardless of typical merging rules.
195+
/// This typically happens when a triangle is poorly defined and must rely on
196+
/// a neighbor for a meaningful tangent value.
181197
group_with_any: bool,
182198
orientation_preserving: bool,
183199
}
@@ -653,16 +669,16 @@ fn generate_tangent_spaces<I: Geometry<O>, O: Ops>(
653669
debug_assert!(a.orientation_preserving == group.orientation_preserving);
654670

655671
if let Some(tangent_space) = tangent_space {
656-
debug_assert!(!tangent_space.is_averaged);
672+
debug_assert!(!tangent_space.is_combined);
657673
*tangent_space = TangentSpace {
658674
value: tangent_space.value.combine(sub_group_tangent_spaces[l]),
659-
is_averaged: true,
675+
is_combined: true,
660676
orientation_preserving: group.orientation_preserving,
661677
};
662678
} else {
663679
*tangent_space = Some(TangentSpace {
664680
value: sub_group_tangent_spaces[l],
665-
is_averaged: false,
681+
is_combined: false,
666682
orientation_preserving: group.orientation_preserving,
667683
});
668684
}

0 commit comments

Comments
 (0)