Skip to content

Commit 1e9daaa

Browse files
committed
Add mesh merge function.
1 parent ac1646e commit 1e9daaa

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/mesh.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ impl Mesh {
4646
})
4747
}
4848

49+
/// Merge the vertices and faces from a mesh into this one.
50+
pub fn merge(&mut self, mut other: Mesh) {
51+
let offset = self.vertices.len() as u32;
52+
53+
// Vertices from the second mesh are tacked on to the end of the vertex
54+
// buffer.
55+
self.vertices.append(&mut other.vertices);
56+
57+
// Indices from the second mesh must be offset to point to the new
58+
// vertex locations in the combined mesh.
59+
self.faces
60+
.extend(other.faces.into_iter().map(|f| f.map(|f| f + offset)));
61+
}
62+
4963
/// Transform such that the mesh is centered and on the range (-1, 1) along
5064
/// the longest extent.
5165
pub fn normalization_transform(&self) -> Matrix4<f64> {

0 commit comments

Comments
 (0)