[Bf-blender-cvs] [aa355118cf1] temp-T97352-3d-texturing-seam-bleeding-b2: Removed loops from the UVVertex as it became to confusing.

Jeroen Bakker noreply at git.blender.org
Tue Jun 14 14:56:59 CEST 2022


Commit: aa355118cf1d10f650902fc04e9a9948bfbc05ff
Author: Jeroen Bakker
Date:   Tue Jun 14 08:21:27 2022 +0200
Branches: temp-T97352-3d-texturing-seam-bleeding-b2
https://developer.blender.org/rBaa355118cf1d10f650902fc04e9a9948bfbc05ff

Removed loops from the UVVertex as it became to confusing.

===================================================================

M	source/blender/blenkernel/BKE_uv_islands.hh
M	source/blender/blenkernel/intern/uv_islands.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_uv_islands.hh b/source/blender/blenkernel/BKE_uv_islands.hh
index 9b45fe23f2b..f81578b59c7 100644
--- a/source/blender/blenkernel/BKE_uv_islands.hh
+++ b/source/blender/blenkernel/BKE_uv_islands.hh
@@ -182,8 +182,6 @@ struct MeshData {
 };
 
 struct UVVertex {
-  /* Loop index of the loop vertex in the original mesh. */
-  uint64_t loop;
   MeshVertex *vertex;
   /* Position in uv space. */
   float2 uv;
@@ -195,7 +193,7 @@ struct UVVertex {
   {
   }
 
-  explicit UVVertex(const MeshUVVert &vert) : loop(vert.loop), vertex(vert.vertex), uv(vert.uv)
+  explicit UVVertex(const MeshUVVert &vert) : vertex(vert.vertex), uv(vert.uv)
   {
   }
 };
@@ -216,17 +214,17 @@ struct UVEdge {
            (vertices[0]->uv == v2.uv && vertices[1]->uv == v1.uv);
   }
 
-  bool has_shared_loop(const UVEdge &other) const
+  bool has_shared_edge(const UVEdge &other) const
   {
-    return ((vertices[0]->loop == other.vertices[0]->loop &&
-             vertices[1]->loop == other.vertices[1]->loop) ||
-            (vertices[0]->loop == other.vertices[1]->loop &&
-             vertices[1]->loop == other.vertices[0]->loop));
+    return has_shared_edge(*other.vertices[0], *other.vertices[1]);
   }
 
-  bool has_shared_edge(const UVEdge &other) const
+  bool has_same_uv_vertices(const UVEdge &other) const
   {
-    return has_shared_edge(*other.vertices[0], *other.vertices[1]);
+    return has_shared_edge(other) && ((vertices[0]->vertex == other.vertices[0]->vertex &&
+                                       vertices[1]->vertex == other.vertices[1]->vertex) ||
+                                      (vertices[0]->vertex == other.vertices[1]->vertex &&
+                                       vertices[1]->vertex == other.vertices[0]->vertex));
   }
 
   bool is_border_edge() const
@@ -453,9 +451,9 @@ struct UVIsland {
       const MeshUVVert &v1 = primitive.get_uv_vert(edge->vert1);
       const MeshUVVert &v2 = primitive.get_uv_vert(edge->vert2);
       UVEdge uv_edge_template;
-      uv_edge_template.vertices[0] = lookup_or_create(UVVertex(v1), false);
-      uv_edge_template.vertices[1] = lookup_or_create(UVVertex(v2), false);
-      UVEdge *uv_edge = lookup_or_create(uv_edge_template, true);
+      uv_edge_template.vertices[0] = lookup_or_create(UVVertex(v1));
+      uv_edge_template.vertices[1] = lookup_or_create(UVVertex(v2));
+      UVEdge *uv_edge = lookup_or_create(uv_edge_template);
       uv_primitive_ptr->edges.append(uv_edge);
       uv_edge->append_to_uv_vertices();
       uv_edge->uv_primitives.append(uv_primitive_ptr);
@@ -463,11 +461,10 @@ struct UVIsland {
     return uv_primitive_ptr;
   }
 
-  UVVertex *lookup_or_create(const UVVertex &vertex, const bool loop_check)
+  UVVertex *lookup_or_create(const UVVertex &vertex)
   {
     for (UVVertex &uv_vertex : uv_vertices) {
-      if (uv_vertex.uv == vertex.uv && uv_vertex.vertex == vertex.vertex &&
-          ((!loop_check) || ((uv_vertex.loop == vertex.loop)))) {
+      if (uv_vertex.uv == vertex.uv && uv_vertex.vertex == vertex.vertex) {
         return &uv_vertex;
       }
     }
@@ -478,10 +475,10 @@ struct UVIsland {
     return result;
   }
 
-  UVEdge *lookup_or_create(const UVEdge &edge, const bool loop_check)
+  UVEdge *lookup_or_create(const UVEdge &edge)
   {
     for (UVEdge &uv_edge : uv_edges) {
-      if (uv_edge.has_shared_edge(edge) && (!loop_check || uv_edge.has_shared_loop(edge))) {
+      if (uv_edge.has_same_uv_vertices(edge)) {
         return &uv_edge;
       }
     }
@@ -507,9 +504,9 @@ struct UVIsland {
     for (int i = 0; i < 3; i++) {
       UVEdge *other_edge = primitive.edges[i];
       UVEdge uv_edge_template;
-      uv_edge_template.vertices[0] = lookup_or_create(*other_edge->vertices[0], false);
-      uv_edge_template.vertices[1] = lookup_or_create(*other_edge->vertices[1], false);
-      new_prim_ptr->edges[i] = lookup_or_create(uv_edge_template, false);
+      uv_edge_template.vertices[0] = lookup_or_create(*other_edge->vertices[0]);
+      uv_edge_template.vertices[1] = lookup_or_create(*other_edge->vertices[1]);
+      new_prim_ptr->edges[i] = lookup_or_create(uv_edge_template);
       new_prim_ptr->edges[i]->append_to_uv_vertices();
       new_prim_ptr->edges[i]->uv_primitives.append(new_prim_ptr);
     }
diff --git a/source/blender/blenkernel/intern/uv_islands.cc b/source/blender/blenkernel/intern/uv_islands.cc
index 833c7dbdeca..4c50aa228ca 100644
--- a/source/blender/blenkernel/intern/uv_islands.cc
+++ b/source/blender/blenkernel/intern/uv_islands.cc
@@ -221,32 +221,29 @@ static void add_uv_primitive_shared_uv_edge(UVIsland &island,
                                                                connected_vert_2->vertex);
   UVVertex vert_template;
   vert_template.uv = uv_unconnected;
-  vert_template.loop = other_vert->loop;
   vert_template.vertex = other_vert->vertex;
-  UVVertex *vert_ptr = island.lookup_or_create(vert_template, true);
+  UVVertex *vert_ptr = island.lookup_or_create(vert_template);
 
   const MeshUVVert *mesh_vert_1 = &mesh_primitive->get_uv_vert(connected_vert_1->vertex);
   vert_template.uv = connected_vert_1->uv;
-  vert_template.loop = mesh_vert_1->loop;
   vert_template.vertex = mesh_vert_1->vertex;
-  UVVertex *vert_1_ptr = island.lookup_or_create(vert_template, true);
+  UVVertex *vert_1_ptr = island.lookup_or_create(vert_template);
 
   const MeshUVVert *mesh_vert_2 = &mesh_primitive->get_uv_vert(connected_vert_2->vertex);
   vert_template.uv = connected_vert_2->uv;
-  vert_template.loop = mesh_vert_2->loop;
   vert_template.vertex = mesh_vert_2->vertex;
-  UVVertex *vert_2_ptr = island.lookup_or_create(vert_template, true);
+  UVVertex *vert_2_ptr = island.lookup_or_create(vert_template);
 
   UVEdge edge_template;
   edge_template.vertices[0] = vert_1_ptr;
   edge_template.vertices[1] = vert_2_ptr;
-  prim1.edges.append(island.lookup_or_create(edge_template, true));
+  prim1.edges.append(island.lookup_or_create(edge_template));
   edge_template.vertices[0] = vert_2_ptr;
   edge_template.vertices[1] = vert_ptr;
-  prim1.edges.append(island.lookup_or_create(edge_template, true));
+  prim1.edges.append(island.lookup_or_create(edge_template));
   edge_template.vertices[0] = vert_ptr;
   edge_template.vertices[1] = vert_1_ptr;
-  prim1.edges.append(island.lookup_or_create(edge_template, true));
+  prim1.edges.append(island.lookup_or_create(edge_template));
   prim1.append_to_uv_edges();
   prim1.append_to_uv_vertices();
   island.uv_primitives.append(prim1);
@@ -268,19 +265,20 @@ static void extend_at_vert(UVIsland &island, UVBorderCorner &corner, const MeshD
   printf("Found %d new edges to add\n", num_to_add);
 
   if (num_to_add == 0) {
-    float2 center_uv = corner.uv(0.5f);
+    float2 center_uv_1 = corner.uv(0.5f);
     // no new triangles found. In this case we should extend the existing borders.
     printf(" - add new projection for {%lld}\n", corner.second->uv_primitive->primitive->index);
     add_uv_primitive_shared_uv_edge(island,
                                     corner.first->get_uv_vertex(1),
                                     corner.first->get_uv_vertex(0),
-                                    center_uv,
+                                    center_uv_1,
                                     corner.second->uv_primitive->primitive);
+    float2 center_uv_2 = corner.uv(0.5f);
     printf(" - add new projection for {%lld}\n", corner.first->uv_primitive->primitive->index);
     add_uv_primitive_shared_uv_edge(island,
                                     corner.second->get_uv_vertex(0),
                                     corner.second->get_uv_vertex(1),
-                                    center_uv,
+                                    center_uv_2,
                                     corner.first->uv_primitive->primitive);
 
     /* Update border after adding the new geometry. */
@@ -290,18 +288,18 @@ static void extend_at_vert(UVIsland &island, UVBorderCorner &corner, const MeshD
         UVBorderEdge *border_edge = corner.first;
         border_edge->uv_primitive = &new_prim;
         border_edge->edge = border_edge->uv_primitive->get_uv_edge(
-            corner.first->get_uv_vertex(0)->uv, center_uv);
-        border_edge->reverse_order = border_edge->edge->vertices[0]->uv == center_uv;
+            corner.first->get_uv_vertex(0)->uv, center_uv_1);
+        border_edge->reverse_order = border_edge->edge->vertices[0]->uv == center_uv_1;
       }
       {
         UVPrimitive &new_prim = island.uv_primitives[island.uv_primitives.size() - 1];
         UVBorderEdge *border_edge = corner.second;
         border_edge->uv_primitive = &new_prim;
         border_edge->edge = border_edge->uv_primitive->get_uv_edge(
-            corner.second->get_uv_vertex(1)->uv, center_uv);
-        border_edge->reverse_order = border_edge->edge->vertices[1]->uv == center_uv;
+            corner.second->get_uv_vertex(1)->uv, center_uv_2);
+        border_edge->reverse_order = border_edge->edge->vertices[1]->uv == center_uv_2;
       }
-      island.validate_border();
+      // island.validate_border();
     }
   }
   else {
@@ -344,7 +342,7 @@ void UVIsland::extend_border(const UVIslandsMask &mask,
 
   // Debug setting to reduce the extension to a number of iterations as long as not all corner
   // cases have been implemented.
-  int num_iterations = 5;
+  int num_iterations = 6;
   while (num_iterations) {
     if (num_iterations == 1) {
       printf("");
@@ -362,7 +360,7 @@ void UVIsland::extend_border(const UVIslandsMask &mask,
 
     // TODO: extend
     extend_at_vert(*this, *extension_corner, mesh_data);
-    validate_border();
+    // validate_border();
 
     /* Mark that the vert is extended. Unable to extend twice. */
     extension_corner->second->flags.extendable = false;



More information about the Bf-blender-cvs mailing list