Fix duplicate triangles on chunk boundary in surface_nets
@@ -23,6 +23,8 @@ pub use height_map::*;
pub use quad::*;
pub use surface_nets::*;
+use std::convert::TryInto;
+
#[derive(Clone, Default)]
pub struct PosNormMesh {
pub positions: Vec<[f32; 3]>,
@@ -43,6 +45,15 @@ impl PosNormMesh {
self.indices.clear();
}
+ pub fn append(&mut self, other: &mut Self) {
+ let n: u32 = self.positions.len().try_into().unwrap();
+
+ self.positions.append(&mut other.positions);
+ self.normals.append(&mut other.normals);
+
+ self.indices.extend(other.indices.drain(..).map(|i| n + i));
+ }
+
/// Create a new mesh with equivalent triangles such that no vertex is shared by any two triangles.
///
/// Also computes a normal for each triangle using the cross product. The pre-existing normals are not used.
