Change generate_outline_normals() not to if they equal regular normals.
This commit is contained in:
parent
19d193584a
commit
3dd9c4c367
14
src/lib.rs
14
src/lib.rs
|
@ -67,8 +67,12 @@ pub enum GenerateOutlineNormalsError {
|
|||
InvalidVertexAttributeFormat(&'static str, VertexFormat, VertexFormat),
|
||||
}
|
||||
|
||||
/// Extension methods for [`Mesh`].
|
||||
pub trait OutlineMeshExt {
|
||||
/// Generates outline normals for the mesh by normalising the sum of the regular normals.
|
||||
///
|
||||
/// This function will silently do nothing if the outline normals would be equal to the
|
||||
/// regular normals.
|
||||
fn generate_outline_normals(&mut self) -> Result<(), GenerateOutlineNormalsError>;
|
||||
}
|
||||
|
||||
|
@ -95,11 +99,18 @@ impl OutlineMeshExt for Mesh {
|
|||
)),
|
||||
}?;
|
||||
let mut map = HashMap::with_capacity(positions.len());
|
||||
let mut modified = false;
|
||||
for (p, n) in positions.iter().zip(normals.iter()) {
|
||||
let key = [FloatOrd(p[0]), FloatOrd(p[1]), FloatOrd(p[2])];
|
||||
let value = Vec3::from_array(*n);
|
||||
map.entry(key).and_modify(|e| *e += value).or_insert(value);
|
||||
map.entry(key)
|
||||
.and_modify(|e| {
|
||||
modified = true;
|
||||
*e += value
|
||||
})
|
||||
.or_insert(value);
|
||||
}
|
||||
if modified {
|
||||
let mut outlines = Vec::with_capacity(positions.len());
|
||||
for p in positions.iter() {
|
||||
let key = [FloatOrd(p[0]), FloatOrd(p[1]), FloatOrd(p[2])];
|
||||
|
@ -109,6 +120,7 @@ impl OutlineMeshExt for Mesh {
|
|||
ATTRIBUTE_OUTLINE_NORMAL,
|
||||
VertexAttributeValues::Float32x3(outlines),
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue