[Bf-blender-cvs] [6011bf549a1] temp-T97352-3d-texturing-seam-bleeding-b2: Commit before restructurizing.

Jeroen Bakker noreply at git.blender.org
Wed Jun 1 12:29:31 CEST 2022


Commit: 6011bf549a1eab9e753f217467584fc4ee7d07f3
Author: Jeroen Bakker
Date:   Tue May 31 14:01:41 2022 +0200
Branches: temp-T97352-3d-texturing-seam-bleeding-b2
https://developer.blender.org/rB6011bf549a1eab9e753f217467584fc4ee7d07f3

Commit before restructurizing.

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

M	source/blender/blenkernel/BKE_uv_islands.hh
M	source/blender/blenkernel/intern/pbvh_pixels.cc
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 cdb42d84883..f14e4ea2e77 100644
--- a/source/blender/blenkernel/BKE_uv_islands.hh
+++ b/source/blender/blenkernel/BKE_uv_islands.hh
@@ -156,7 +156,8 @@ struct UVIsland {
                      const short island_index,
                      const MLoopTri *looptris,
                      const int64_t looptri_len,
-                     const MLoop *mloop);
+                     const MLoop *mloop,
+                     const MVert *mvert);
 
  private:
   void append(const UVPrimitive &primitive)
@@ -230,6 +231,7 @@ struct UVIsland {
 
 /* Debug functions to export to a SVG file. */
 void svg_header(std::ostream &ss);
+void svg(std::ostream &ss, const UVIsland &islands, int step);
 void svg(std::ostream &ss, const UVIslands &islands, int step);
 void svg(std::ostream &ss, const UVPrimitive &primitive, int step);
 void svg(std::ostream &ss, const UVIslandsMask &mask, int step);
@@ -266,11 +268,12 @@ struct UVIslands {
   void extend_borders(const UVIslandsMask &islands_mask,
                       const MLoopTri *looptris,
                       const int64_t looptri_len,
-                      const MLoop *mloop)
+                      const MLoop *mloop,
+                      const MVert *mvert)
   {
     ushort index = 0;
     for (UVIsland &island : islands) {
-      island.extend_border(islands_mask, index++, looptris, looptri_len, mloop);
+      island.extend_border(islands_mask, index++, looptris, looptri_len, mloop, mvert);
     }
 
 #ifdef DEBUG_SVG
diff --git a/source/blender/blenkernel/intern/pbvh_pixels.cc b/source/blender/blenkernel/intern/pbvh_pixels.cc
index 1059f97e423..0dc5a5eb2d8 100644
--- a/source/blender/blenkernel/intern/pbvh_pixels.cc
+++ b/source/blender/blenkernel/intern/pbvh_pixels.cc
@@ -42,7 +42,7 @@ static uv_islands::UVIslands build_uv_islands(const PBVH &pbvh, const MLoopUV *m
   uv_masks.add(islands);
   uv_masks.dilate();
   islands.extract_borders(pbvh.mloop);
-  islands.extend_borders(uv_masks, pbvh.looptri, pbvh.totprim, pbvh.mloop);
+  islands.extend_borders(uv_masks, pbvh.looptri, pbvh.totprim, pbvh.mloop, pbvh.verts);
   return islands;
 }
 
diff --git a/source/blender/blenkernel/intern/uv_islands.cc b/source/blender/blenkernel/intern/uv_islands.cc
index f584c45369f..32f5b2753ae 100644
--- a/source/blender/blenkernel/intern/uv_islands.cc
+++ b/source/blender/blenkernel/intern/uv_islands.cc
@@ -104,11 +104,23 @@ struct Fan {
   Vector<FanTri> tris;
 };
 
+static void print(const Fan &fan, const MVert *mvert)
+{
+  for (const FanTri &tri : fan.tris) {
+    for (int i = 0; i < 3; i++) {
+      float3 co1 = mvert[tri.v[i]].co;
+      printf("%d(%f,%f,%f) ", tri.v[i], co1.x, co1.y, co1.z);
+    }
+    printf("\n");
+  }
+}
+
 static void extend_at_vert(UVIsland &island,
                            UVBorderVert &vert,
                            const MLoopTri *looptris,
                            const int64_t looptri_len,
-                           const MLoop *mloop)
+                           const MLoop *mloop,
+                           const MVert *mvert)
 {
   // get the mesh vert.
   int64_t v = vert.vert;
@@ -142,6 +154,27 @@ static void extend_at_vert(UVIsland &island,
     }
   }
 
+  // reorder fan that the segments connect.
+  print(fan, mvert);
+  for (int i = 0; i < fan.tris.size() - 1; i++) {
+    for (int j = i + 1; j < fan.tris.size(); j++) {
+      if (fan.tris[j].v[1] == fan.tris[i].v[2]) {
+        if (i + 1 != j) {
+          std::swap(fan.tris[j], fan.tris[i + 1]);
+        }
+        break;
+      }
+    }
+  }
+  print(fan, mvert);
+
+  // add all verts that arent connected to the given border vert to the UVIsland.
+  // tag them as being 'not fixed in uv space'. count them and determine a position in uv space.
+  // add UV primitives for them.
+  // recalc the border.
+
+
+
   // count fan-sections between border edges.
   // 0 : split in half.
 }
@@ -150,10 +183,18 @@ void UVIsland::extend_border(const UVIslandsMask &mask,
                              const short island_index,
                              const MLoopTri *looptris,
                              const int64_t looptri_len,
-                             const MLoop *mloop)
+                             const MLoop *mloop,
+                             const MVert *mvert)
 {
   // Find sharpest corner that still inside the island mask and can be extended.
   // exit when no corner could be found.
+#ifdef DEBUG_SVG
+  int step = 0;
+  std::ofstream of;
+  of.open("/tmp/extend.svg");
+  svg_header(of);
+#endif
+
   while (true) {
     UVBorderVert *extension_vert = sharpest_border_vert(*this);
     if (extension_vert == nullptr) {
@@ -167,12 +208,20 @@ void UVIsland::extend_border(const UVIslandsMask &mask,
     }
 
     // TODO: extend
-    extend_at_vert(*this, *extension_vert, looptris, looptri_len, mloop);
+    extend_at_vert(*this, *extension_vert, looptris, looptri_len, mloop, mvert);
 
     /* Mark that the vert is extended. Unable to extend twice. */
     extension_vert->flags.extendable = false;
+#ifdef DEBUG_SVG
+    svg(of, *this, step);
+    step++;
+#endif
     break;
   }
+#ifdef DEBUG_SVG
+  svg_footer(of);
+  of.close();
+#endif
 }
 
 /** \} */
@@ -337,6 +386,42 @@ void svg(std::ostream &ss, const UVEdge &edge)
      << edge.vertices[1].uv.y * 1024 << "\"/>\n";
 }
 
+void svg(std::ostream &ss, const UVIsland &island, int step)
+{
+  ss << "<g transform=\"translate(" << step * 1024 << " 0)\">\n";
+  ss << "  <g fill=\"yellow\">\n";
+
+  /* Inner edges */
+  ss << "    <g stroke=\"grey\" stroke-dasharray=\"5 5\">\n";
+  for (const UVPrimitive &primitive : island.primitives) {
+    for (int i = 0; i < 3; i++) {
+      const UVEdge &edge = primitive.edges[i];
+      if (edge.adjacent_uv_primitive == -1) {
+        continue;
+      }
+      svg(ss, edge);
+    }
+  }
+  ss << "     </g>\n";
+
+  /* Border */
+  ss << "    <g stroke=\"black\" stroke-width=\"2\">\n";
+  for (const UVPrimitive &primitive : island.primitives) {
+    for (int i = 0; i < 3; i++) {
+      const UVEdge &edge = primitive.edges[i];
+      if (edge.adjacent_uv_primitive != -1) {
+        continue;
+      }
+      svg(ss, edge);
+    }
+  }
+  ss << "     </g>\n";
+
+  ss << "   </g>\n";
+
+  ss << "</g>\n";
+}
+
 void svg(std::ostream &ss, const UVIslands &islands, int step)
 {
   ss << "<g transform=\"translate(" << step * 1024 << " 0)\">\n";



More information about the Bf-blender-cvs mailing list