[Bf-blender-cvs] [c38dae0fabf] temp-T97352-3d-texturing-seam-bleeding-b2: Commit before continuing.

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


Commit: c38dae0fabfe2894f7c5908d1ba7e12a12d77500
Author: Jeroen Bakker
Date:   Wed Jun 1 12:29:26 2022 +0200
Branches: temp-T97352-3d-texturing-seam-bleeding-b2
https://developer.blender.org/rBc38dae0fabfe2894f7c5908d1ba7e12a12d77500

Commit before continuing.

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

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 6a66ee0ae49..df4eb93abdc 100644
--- a/source/blender/blenkernel/BKE_uv_islands.hh
+++ b/source/blender/blenkernel/BKE_uv_islands.hh
@@ -28,8 +28,9 @@ struct UVIslandsMask;
 struct UVBorder;
 
 struct UVVertex {
-  /* Loop index of the vertex in the original mesh. */
+  /* Loop index of the loop vertex in the original mesh. */
   uint64_t loop;
+  uint64_t v;
   /* Position in uv space. */
   float2 uv;
 };
@@ -57,7 +58,14 @@ struct UVPrimitive {
   uint64_t index;
   UVEdge edges[3];
 
-  explicit UVPrimitive(uint64_t prim_index, const MLoopTri &tri, const MLoopUV *mloopuv)
+  explicit UVPrimitive(uint64_t prim_index) : index(prim_index)
+  {
+  }
+
+  explicit UVPrimitive(uint64_t prim_index,
+                       const MLoopTri &tri,
+                       const MLoop *mloop,
+                       const MLoopUV *mloopuv)
       : index(prim_index)
   {
     for (int i = 0; i < 3; i++) {
@@ -65,6 +73,8 @@ struct UVPrimitive {
       edges[i].vertices[1].uv = mloopuv[tri.tri[(i + 1) % 3]].uv;
       edges[i].vertices[0].loop = tri.tri[i];
       edges[i].vertices[1].loop = tri.tri[(i + 1) % 3];
+      edges[i].vertices[0].v = mloop[tri.tri[i]].v;
+      edges[i].vertices[1].v = mloop[tri.tri[(i + 1) % 3]].v;
     }
   }
 
@@ -106,6 +116,9 @@ struct UVBorderVert {
   int64_t next_index;
   int64_t border_index;
 
+  /** Index of the uv primitive (UVIsland) */
+  int64_t uv_primitive_index;
+
   struct {
     /** Should this vertex still be checked when performing extension. */
     bool extendable : 1;
@@ -120,8 +133,10 @@ struct UVBorderVert {
 struct UVBorderEdge {
   UVEdge *edge;
   bool tag = false;
+  int64_t uv_prim_index;
 
-  explicit UVBorderEdge(UVEdge *edge) : edge(edge)
+  explicit UVBorderEdge(UVEdge *edge, int64_t uv_prim_index)
+      : edge(edge), uv_prim_index(uv_prim_index)
   {
   }
 };
@@ -241,6 +256,7 @@ struct UVIsland {
 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);
 void svg(std::ostream &ss, const UVPrimitive &primitive, int step);
 void svg(std::ostream &ss, const UVIslandsMask &mask, int step);
 void svg(std::ostream &ss, const UVBorder &border);
@@ -249,10 +265,13 @@ void svg_footer(std::ostream &ss);
 struct UVIslands {
   Vector<UVIsland> islands;
 
-  explicit UVIslands(const MLoopTri *primitives, uint64_t primitives_len, const MLoopUV *mloopuv)
+  explicit UVIslands(const MLoopTri *primitives,
+                     uint64_t primitives_len,
+                     const MLoop *mloop,
+                     const MLoopUV *mloopuv)
   {
     for (int prim = 0; prim < primitives_len; prim++) {
-      UVPrimitive primitive(prim, primitives[prim], mloopuv);
+      UVPrimitive primitive(prim, primitives[prim], mloop, mloopuv);
       add(primitive);
     }
 
diff --git a/source/blender/blenkernel/intern/pbvh_pixels.cc b/source/blender/blenkernel/intern/pbvh_pixels.cc
index 0dc5a5eb2d8..aba9b129ec0 100644
--- a/source/blender/blenkernel/intern/pbvh_pixels.cc
+++ b/source/blender/blenkernel/intern/pbvh_pixels.cc
@@ -37,7 +37,7 @@ constexpr bool USE_WATERTIGHT_CHECK = true;
 /** Build UV islands from PBVH primitives. */
 static uv_islands::UVIslands build_uv_islands(const PBVH &pbvh, const MLoopUV *mloopuv)
 {
-  uv_islands::UVIslands islands(pbvh.looptri, pbvh.totprim, mloopuv);
+  uv_islands::UVIslands islands(pbvh.looptri, pbvh.totprim, pbvh.mloop, mloopuv);
   uv_islands::UVIslandsMask uv_masks(float2(0.0, 0.0), ushort2(256, 256));
   uv_masks.add(islands);
   uv_masks.dilate();
diff --git a/source/blender/blenkernel/intern/uv_islands.cc b/source/blender/blenkernel/intern/uv_islands.cc
index c92d5b39540..506decdcc0f 100644
--- a/source/blender/blenkernel/intern/uv_islands.cc
+++ b/source/blender/blenkernel/intern/uv_islands.cc
@@ -11,11 +11,11 @@ namespace blender::bke::uv_islands {
 void UVIsland::extract_border(const MLoop *mloop)
 {
   Vector<UVBorderEdge> edges;
-
-  for (UVPrimitive &primitive : primitives) {
-    for (UVEdge &edge : primitive.edges) {
+  for (int64_t prim_index = 0; prim_index < primitives.size(); prim_index++) {
+    UVPrimitive &prim = primitives[prim_index];
+    for (UVEdge &edge : prim.edges) {
       if (edge.is_border_edge()) {
-        edges.append(UVBorderEdge(&edge));
+        edges.append(UVBorderEdge(&edge, prim_index));
       }
     }
   }
@@ -99,9 +99,12 @@ static UVBorderVert *sharpest_border_vert(UVIsland &island)
 struct FanTri {
   int64_t v[3];
   float2 uvs[3];
+  /* Index of the primitive in the original mesh. */
+  int64_t prim_index;
 
   struct {
     bool found : 1;
+    bool should_be_added : 1;
   } flags;
 };
 
@@ -121,7 +124,7 @@ static void print(const Fan &fan, const MVert *mvert)
 }
 
 static void extend_at_vert(UVIsland &island,
-                           const UVBorderVert &vert,
+                           UVBorderVert &vert,
                            const MLoopTri *looptris,
                            const int64_t looptri_len,
                            const MLoop *mloop,
@@ -136,6 +139,7 @@ static void extend_at_vert(UVIsland &island,
     for (int i = 0; i < 3; i++) {
       if (mloop[tri.tri[i]].v == v) {
         FanTri fantri;
+        fantri.prim_index = tri_index;
         fantri.flags.found = false;
         fantri.v[0] = mloop[tri.tri[0]].v;
         fantri.v[1] = mloop[tri.tri[1]].v;
@@ -145,6 +149,7 @@ static void extend_at_vert(UVIsland &island,
       }
     }
   }
+  print(fan, mvert);
 
   // Make sure the first vert points to the center of the fan.
   for (FanTri &tri : fan.tris) {
@@ -176,6 +181,7 @@ static void extend_at_vert(UVIsland &island,
   /* update the known uv coordinates. */
   for (FanTri &tri : fan.tris) {
     tri.flags.found = false;
+    tri.flags.should_be_added = false;
     int2 test_edge(tri.v[0], tri.v[1]);
     for (UVPrimitive &prim : island.primitives) {
       for (UVEdge &edge : prim.edges) {
@@ -184,7 +190,7 @@ static void extend_at_vert(UVIsland &island,
             (test_edge.x == o.y && test_edge.y == o.x)) {
           tri.uvs[0] = vert.uv;
           for (int i = 0; i < 2; i++) {
-            if (edge.vertices[0].uv == vert.uv) {
+            if (edge.vertices[i].uv == vert.uv) {
               tri.uvs[1] = edge.vertices[1 - i].uv;
               break;
             }
@@ -225,14 +231,89 @@ static void extend_at_vert(UVIsland &island,
     }
   }
   printf("Found %d new edges to add\n", num_to_add);
-  float angle = island.borders[vert.border_index].outside_angle(vert);
-  printf("Angle %f\n", angle);
 
-  switch (num_to_add) {
-    case 1:
-      break;
-    default:
-      break;
+  if (num_to_add > 0) {
+    UVBorder &border = island.borders[vert.border_index];
+    int i = 0;
+
+    {
+      UVPrimitive test(0);
+      test.edges[0].vertices[0].uv = border.verts[vert.index].uv;
+      test.edges[0].vertices[1].uv = border.verts[vert.next_index].uv;
+      test.edges[1].vertices[0].uv = border.verts[vert.next_index].uv;
+      test.edges[1].vertices[1].uv = border.verts[vert.prev_index].uv;
+      test.edges[2].vertices[0].uv = border.verts[vert.prev_index].uv;
+      test.edges[2].vertices[1].uv = border.verts[vert.index].uv;
+      // island.primitives.append(test);
+      // return;
+    }
+    FanTri *prev_tri = &fan.tris.last();
+    for (int tri_index = 0; tri_index < fan.tris.size(); tri_index++) {
+      FanTri &tri = fan.tris[tri_index];
+      if (tri.flags.found) {
+        prev_tri = &tri;
+        continue;
+      }
+      float factor = float(i + 1) / float(num_to_add + 1);
+      float2 new_pos;
+      interp_v2_v2v2(
+          new_pos, border.verts[vert.prev_index].uv, border.verts[vert.next_index].uv, factor);
+      print_v2_id(new_pos);
+      // TODO change length of edge.
+
+      tri.uvs[1] = new_pos;
+      prev_tri->uvs[2] = new_pos;
+      tri.flags.should_be_added = true;
+      prev_tri->flags.should_be_added = true;
+
+      i++;
+      prev_tri = &tri;
+    }
+    print(fan, mvert);
+
+    for (FanTri &tri : fan.tris) {
+      if (!tri.flags.should_be_added) {
+        continue;
+      }
+      UVPrimitive prim(tri.prim_index);
+      prim.edges[0].vertices[0].uv = tri.uvs[0];
+      prim.edges[0].vertices[1].uv = tri.uvs[1];
+      prim.edges[1].vertices[0].uv = tri.uvs[1];
+      prim.edges[1].vertices[1].uv = tri.uvs[2];
+      prim.edges[2].vertices[0].uv = tri.uvs[2];
+      prim.edges[2].vertices[1].uv = tri.uvs[0];
+
+      // prim.edges[0].adjacent_uv_primitive = prev_tri.uv_prim_index;
+      // prim.edges[1].adjacent_uv_primitive = next_tri.uv_prim_index;
+      island.primitives.append(prim);
+    }
+  }
+  else {
+    // TODO duplicate tris or fill tri.
+    // Currently we only do the duplication.
+    UVBorder &border = island.borders[vert.border_index];
+
+    float2 center_uv = (border.verts[vert.next_index].uv + border.verts[vert.prev_index].uv) /
+                       2.0f;
+    UVPrimitive prim1(0);
+    prim1.edges[0].vertices[0].uv = border.verts[vert.index].uv;
+    prim1.edges[0].vertices[1].uv = border.verts[vert.prev_index].uv;
+    prim1.edges[1].vertices[0].uv = border.verts[vert.prev_index].uv;
+    prim1.edges[1].vertices[1].uv = center_uv;
+    prim1.edges[2].vertices[0].uv = center_uv;
+    prim1.edges[2].vertices[1].uv = border.verts[vert.index].uv;
+    island.primitives.append(prim1);
+
+    UVPrimitive prim2(0);
+    prim2.edges[0].vertices[0].uv = border.verts[vert.index].uv;
+    prim2.edges[0].vertices[1].uv = center_uv;
+    prim2.edges[1].vertices[0].uv = center_uv;
+    prim2.edges[1].vertices[1].uv = border.verts[vert.next_index].uv;
+    prim2.edges[2].vertices[0].uv = border.verts[vert.next_index].uv;
+    prim2.edges[2].vertices[1].uv = border.verts[vert.index].uv;
+    island.primitives.append(prim2);
+
+    vert.uv = center_uv;
   }
 
   // count fan-sections between border edges.
@@ -253,9 +334,11 @@ void UVIsland::extend_border(const UVIslandsMask &mask,
   std::ofstream of;
   of.open("/tmp/extend.svg");
   svg_header(of);
+  svg(of, *thi

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list