Skip to content

Commit

Permalink
add resolve to faces to selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Bendzae committed Oct 3, 2024
1 parent c4e4759 commit 768b6f8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/smesh/edit_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,29 @@ use crate::{bail, prelude::*};

/// Edit operations
impl SMesh {
pub fn extrude(&mut self, face: FaceId) -> SMeshResult<FaceId> {
let vertices = face.vertices(self).collect_vec();
// Duplicate verts
let mut vertex_pairs = Vec::new();
for v in &vertices {
let position = v.position(self)?;
vertex_pairs.push((*v, self.add_vertex(position)));
}

assert_eq!(vertices.len(), vertex_pairs.len());

self.delete_only_face(face)?;
// Make faces
for ((old_0, new_0), (old_1, new_1)) in
vertex_pairs.iter().copied().circular_tuple_windows()
{
info!("{:?} {:?} {:?} {:?}", old_0, old_1, new_1, new_0);
self.make_quad(old_0, old_1, new_1, new_0)?;
}
let top_face = self.make_face(vertex_pairs.iter().map(|(_old, new)| *new).collect_vec())?;
Ok(top_face)
}

pub fn extrude_edge(&mut self, e0: HalfedgeId) -> SMeshResult<HalfedgeId> {
// Find boundary halfedge
let e0 = match e0.is_boundary(self) {
Expand Down Expand Up @@ -105,29 +128,6 @@ impl SMesh {
Ok(new_edges)
}

pub fn extrude(&mut self, face: FaceId) -> SMeshResult<FaceId> {
let vertices = face.vertices(self).collect_vec();
// Duplicate verts
let mut vertex_pairs = Vec::new();
for v in &vertices {
let position = v.position(self)?;
vertex_pairs.push((*v, self.add_vertex(position)));
}

assert_eq!(vertices.len(), vertex_pairs.len());

self.delete_only_face(face)?;
// Make faces
for ((old_0, new_0), (old_1, new_1)) in
vertex_pairs.iter().copied().circular_tuple_windows()
{
info!("{:?} {:?} {:?} {:?}", old_0, old_1, new_1, new_0);
self.make_quad(old_0, old_1, new_1, new_0)?;
}
let top_face = self.make_face(vertex_pairs.iter().map(|(_old, new)| *new).collect_vec())?;
Ok(top_face)
}

// Returns the normal of the face. The first three vertices are used to
// compute the normal. If the vertices of the face are not coplanar,
// the result will not be correct.
Expand Down
17 changes: 17 additions & 0 deletions src/smesh/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ impl MeshSelection {
}
Ok(vertices)
}

pub fn resolve_to_faces(&self, smesh: &SMesh) -> SMeshResult<HashSet<FaceId>> {
let mut faces = self.faces.clone();
for he in &self.halfedges {
faces.insert(he.face().run(smesh)?);
}
for v in &self.vertices {
for f in v.faces(smesh) {
if f.vertices(smesh)
.all(|face_v| self.vertices.contains(&face_v))
{
faces.insert(f);
}
}
}
Ok(faces)
}
}

impl From<VertexId> for MeshSelection {
Expand Down

0 comments on commit 768b6f8

Please sign in to comment.