mesh_graph/ops/
insert.rs

1use glam::Vec3;
2
3use crate::{Face, FaceId, Halfedge, HalfedgeId, MeshGraph, Vertex, VertexId};
4
5impl MeshGraph {
6    /// Inserts a vertex and it's position into the mesh graph.
7    /// It doesn't do any connections.
8    pub fn insert_vertex(&mut self, position: Vec3) -> VertexId {
9        let vertex = Vertex::default();
10        let vertex_id = self.vertices.insert(vertex);
11        self.positions.insert(vertex_id, position);
12
13        vertex_id
14    }
15
16    /// Inserts a halfedge into the mesh graph. It only connects the halfedge to the given end vertex but not the reverse.
17    /// It also doesn't do any other connections.
18    pub fn insert_halfedge(&mut self, end_vertex: VertexId) -> HalfedgeId {
19        let halfedge = Halfedge {
20            end_vertex,
21            next: None,
22            twin: None,
23            face: None,
24        };
25        self.halfedges.insert(halfedge)
26    }
27
28    /// Inserts a face into the mesh graph. It only connects the face to the given halfedge but not the reverse.
29    /// It also doesn't do any other connections.
30    pub fn insert_face(&mut self, halfedge: HalfedgeId) -> FaceId {
31        let face_id = self.faces.insert_with_key(|id| Face {
32            halfedge,
33            index: self.index_to_face_id.len(),
34            id,
35        });
36
37        self.index_to_face_id.push(face_id);
38
39        face_id
40    }
41}