Unverified Commit 5eb12946 authored by Max Slater's avatar Max Slater Committed by GitHub
Browse files

Update meshedit.cpp

parent 2e7b5053
...@@ -106,10 +106,11 @@ std::optional<Halfedge_Mesh::VertexRef> Halfedge_Mesh::split_edge(Halfedge_Mesh: ...@@ -106,10 +106,11 @@ std::optional<Halfedge_Mesh::VertexRef> Halfedge_Mesh::split_edge(Halfedge_Mesh:
bevel_face_positions come in: these functions are called repeatedly as you bevel_face_positions come in: these functions are called repeatedly as you
move your mouse, the position of which determins the normal and tangent offset move your mouse, the position of which determins the normal and tangent offset
parameters. These functions are also passed an array of the original vertex parameters. These functions are also passed an array of the original vertex
positions: for bevel_vertex, it has one element, the original vertex position, positions: for bevel_vertex, it has one element, the original vertex position,
for bevel_edge, two for the two vertices, and for bevel_face, it has the original for bevel_edge, two for the two vertices, and for bevel_face, it has the original
position of each vertex in halfedge order. You should use these positions, as well position of each vertex in order starting from face->halfedge. You should use these
as the normal and tangent offset fields to assign positions to the new vertices. positions, as well as the normal and tangent offset fields to assign positions to
the new vertices.
Finally, note that the normal and tangent offsets are not relative values - you Finally, note that the normal and tangent offsets are not relative values - you
should compute a particular new position from them, not a delta to apply. should compute a particular new position from them, not a delta to apply.
...@@ -118,8 +119,8 @@ std::optional<Halfedge_Mesh::VertexRef> Halfedge_Mesh::split_edge(Halfedge_Mesh: ...@@ -118,8 +119,8 @@ std::optional<Halfedge_Mesh::VertexRef> Halfedge_Mesh::split_edge(Halfedge_Mesh:
/* /*
This method should replace the vertex v with a face, corresponding to This method should replace the vertex v with a face, corresponding to
a bevel operation. It should return the new face. NOTE: This method is a bevel operation. It should return the new face. NOTE: This method is
responsible for updating the *connectivity* of the mesh only---it does not only responsible for updating the *connectivity* of the mesh---it does not
need to update the vertex positions. These positions will be updated in need to update the vertex positions. These positions will be updated in
Halfedge_Mesh::bevel_vertex_positions (which you also have to Halfedge_Mesh::bevel_vertex_positions (which you also have to
implement!) implement!)
*/ */
...@@ -136,7 +137,7 @@ std::optional<Halfedge_Mesh::FaceRef> Halfedge_Mesh::bevel_vertex(Halfedge_Mesh: ...@@ -136,7 +137,7 @@ std::optional<Halfedge_Mesh::FaceRef> Halfedge_Mesh::bevel_vertex(Halfedge_Mesh:
This method should replace the edge e with a face, corresponding to a This method should replace the edge e with a face, corresponding to a
bevel operation. It should return the new face. NOTE: This method is bevel operation. It should return the new face. NOTE: This method is
responsible for updating the *connectivity* of the mesh only---it does not responsible for updating the *connectivity* of the mesh only---it does not
need to update the vertex positions. These positions will be updated in need to update the vertex positions. These positions will be updated in
Halfedge_Mesh::bevel_edge_positions (which you also have to Halfedge_Mesh::bevel_edge_positions (which you also have to
implement!) implement!)
*/ */
...@@ -204,8 +205,8 @@ void Halfedge_Mesh::bevel_vertex_positions(const std::vector<Vec3>& start_positi ...@@ -204,8 +205,8 @@ void Halfedge_Mesh::bevel_vertex_positions(const std::vector<Vec3>& start_positi
(in the orig array) to compute an offset vertex position. (in the orig array) to compute an offset vertex position.
Note that there is a 1-to-1 correspondence between halfedges in Note that there is a 1-to-1 correspondence between halfedges in
newHalfedges and vertex positions newHalfedges and vertex positions in start_positions. So, you can write
in orig. So, you can write loops of the form loops of the form:
for(size_t i = 0; i < new_halfedges.size(); i++) for(size_t i = 0; i < new_halfedges.size(); i++)
{ {
...@@ -241,8 +242,8 @@ void Halfedge_Mesh::bevel_edge_positions(const std::vector<Vec3>& start_position ...@@ -241,8 +242,8 @@ void Halfedge_Mesh::bevel_edge_positions(const std::vector<Vec3>& start_position
position. position.
Note that there is a 1-to-1 correspondence between halfedges in Note that there is a 1-to-1 correspondence between halfedges in
new_halfedges and vertex positions new_halfedges and vertex positions in start_positions. So, you can write
in orig. So, you can write loops of the form loops of the form:
for(size_t i = 0; i < new_halfedges.size(); i++) for(size_t i = 0; i < new_halfedges.size(); i++)
{ {
...@@ -304,7 +305,7 @@ void Halfedge_Mesh::triangulate() { ...@@ -304,7 +305,7 @@ void Halfedge_Mesh::triangulate() {
Step II: Assign a unique index (starting at 0) to each vertex, edge, and Step II: Assign a unique index (starting at 0) to each vertex, edge, and
face in the original mesh. These indices will be the indices of the face in the original mesh. These indices will be the indices of the
vertices in the new (subdivided mesh). They do not have to be assigned vertices in the new (subdivided) mesh. They do not have to be assigned
in any particular order, so long as no index is shared by more than one in any particular order, so long as no index is shared by more than one
mesh element, and the total number of indices is equal to V+E+F, i.e., mesh element, and the total number of indices is equal to V+E+F, i.e.,
the total number of vertices plus edges plus faces in the original mesh. the total number of vertices plus edges plus faces in the original mesh.
...@@ -351,7 +352,7 @@ void Halfedge_Mesh::linear_subdivide_positions() { ...@@ -351,7 +352,7 @@ void Halfedge_Mesh::linear_subdivide_positions() {
into quads (by inserting a vertex at the face midpoint and each into quads (by inserting a vertex at the face midpoint and each
of the edge midpoints). The new vertex positions will be stored of the edge midpoints). The new vertex positions will be stored
in the members Vertex::new_pos, Edge::new_pos, and in the members Vertex::new_pos, Edge::new_pos, and
Face::new_pos. The values of the positions are based on Face::new_pos. The values of the positions are based on
the Catmull-Clark rules for subdivision. the Catmull-Clark rules for subdivision.
Note: this will only be called on meshes without boundary Note: this will only be called on meshes without boundary
...@@ -372,53 +373,39 @@ void Halfedge_Mesh::catmullclark_subdivide_positions() { ...@@ -372,53 +373,39 @@ void Halfedge_Mesh::catmullclark_subdivide_positions() {
} }
/* /*
This routine should increase the number of triangles in the mesh This routine should increase the number of triangles in the mesh
using Loop subdivision. Note: this is will only be called on triangle meshes. using Loop subdivision. Note: this is will only be called on triangle meshes.
*/ */
void Halfedge_Mesh::loop_subdivide() { void Halfedge_Mesh::loop_subdivide() {
// Compute new positions for all the vertices in the input mesh, using // Each vertex and edge of the original mesh can be associated with a
// the Loop subdivision rule, and store them in Vertex::new_pos. // vertex in the new (subdivided) mesh.
// -> At this point, we also want to mark each vertex as being a vertex of the
// original mesh. Use Vertex::is_new for this.
// -> Next, compute the updated vertex positions associated with edges, and
// store it in Edge::new_pos.
// -> Next, we're going to split every edge in the mesh, in any order. For
// future reference, we're also going to store some information about which
// subdivided edges come from splitting an edge in the original mesh, and
// which edges are new, by setting the flat Edge::is_new. Note that in this
// loop, we only want to iterate over edges of the original mesh.
// Otherwise, we'll end up splitting edges that we just split (and the
// loop will never end!)
// -> Now flip any new edge that connects an old and new vertex.
// -> Finally, copy the new vertex positions into final Vertex::pos.
// Each vertex and edge of the original surface can be associated with a
// vertex in the new (subdivided) surface.
// Therefore, our strategy for computing the subdivided vertex locations is to // Therefore, our strategy for computing the subdivided vertex locations is to
// *first* compute the new positions // *first* compute the new positions
// using the connectivity of the original (coarse) mesh; navigating this mesh // using the connectivity of the original (coarse) mesh. Navigating this mesh
// will be much easier than navigating // will be much easier than navigating
// the new subdivided (fine) mesh, which has more elements to traverse. We // the new subdivided (fine) mesh, which has more elements to traverse. We
// will then assign vertex positions in // will then assign vertex positions in
// the new mesh based on the values we computed for the original mesh. // the new mesh based on the values we computed for the original mesh.
// Compute updated positions for all the vertices in the original mesh, using // Compute new positions for all the vertices in the input mesh using
// the Loop subdivision rule. // the Loop subdivision rule and store them in Vertex::new_pos.
// At this point, we also want to mark each vertex as being a vertex of the
// Next, compute the updated vertex positions associated with edges. // original mesh. Use Vertex::is_new for this.
// Next, we're going to split every edge in the mesh, in any order. For // Next, compute the subdivided vertex positions associated with edges, and
// future reference, we're also going to store some information about which // store them in Edge::new_pos.
// subdivided edges come from splitting an edge in the original mesh, and
// which edges are new. // Next, we're going to split every edge in the mesh, in any order.
// In this loop, we only want to iterate over edges of the original // We're also going to distinguish subdivided edges that came from splitting
// mesh---otherwise, we'll end up splitting edges that we just split (and // an edge in the original mesh from new edges by setting the boolean Edge::is_new.
// the loop will never end!) // Note that in this loop, we only want to iterate over edges of the original mesh.
// Otherwise, we'll end up splitting edges that we just split (and the
// Finally, flip any new edge that connects an old and new vertex. // loop will never end!)
// Copy the updated vertex positions to the subdivided mesh. // Now flip any new edge that connects an old and new vertex.
// Finally, copy new vertex positions into the Vertex::pos.
} }
/* /*
...@@ -439,7 +426,7 @@ bool Halfedge_Mesh::isotropic_remesh() { ...@@ -439,7 +426,7 @@ bool Halfedge_Mesh::isotropic_remesh() {
// -> Finally, apply some tangential smoothing to the vertex positions // -> Finally, apply some tangential smoothing to the vertex positions
// Note: if you erase elements in a local operation, they will not be actually deleted // Note: if you erase elements in a local operation, they will not be actually deleted
// until do_erase or validate are called. This is to facilitate checking // until do_erase or validate is called. This is to facilitate checking
// for dangling references to elements that will be erased. // for dangling references to elements that will be erased.
// The rest of the codebase will automatically call validate() after each op, // The rest of the codebase will automatically call validate() after each op,
// but here simply calling collapse_edge() will not erase the elements. // but here simply calling collapse_edge() will not erase the elements.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment