[Bf-blender-cvs] [8ceb9956706] soc-2021-adaptive-cloth: adaptive_cloth: MeshIO: DNA Mesh: combine repeating UVs

ishbosamiya noreply at git.blender.org
Mon Jul 12 08:23:49 CEST 2021


Commit: 8ceb99567064de74a98559c1c332818e93b592e2
Author: ishbosamiya
Date:   Thu Jul 8 12:24:33 2021 +0530
Branches: soc-2021-adaptive-cloth
https://developer.blender.org/rB8ceb99567064de74a98559c1c332818e93b592e2

adaptive_cloth: MeshIO: DNA Mesh: combine repeating UVs

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

M	source/blender/blenkernel/BKE_cloth_remesh.hh
M	source/blender/blenkernel/tests/BKE_cloth_remesh_test.cc

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

diff --git a/source/blender/blenkernel/BKE_cloth_remesh.hh b/source/blender/blenkernel/BKE_cloth_remesh.hh
index 030a250cedd..8d92f149eb4 100644
--- a/source/blender/blenkernel/BKE_cloth_remesh.hh
+++ b/source/blender/blenkernel/BKE_cloth_remesh.hh
@@ -74,6 +74,7 @@ Mesh *BKE_cloth_remesh(struct Object *ob, struct ClothModifierData *clmd, struct
 #  include "BLI_float2.hh"
 #  include "BLI_float3.hh"
 #  include "BLI_generational_arena.hh"
+#  include "BLI_map.hh"
 #  include "BLI_vector.hh"
 
 namespace blender::bke::internal {
@@ -509,9 +510,17 @@ class MeshIO {
       normals.append(normal);
     }
 
-    for (auto i = 0; i < mesh->totloop; i++) {
-      uvs.append(mesh->mloopuv[i].uv);
-    }
+    /* A UV map is needed because the UVs stored the mesh are stored
+     * per loop which means there are UVs that repeat, this leads to
+     * having 2 or more unique edges per 1 true edge. The UV map is
+     * used to combine UVs and create the correct indexing for these.
+     *
+     * The map has a key as the tuple stores the mloop::v and uv
+     * coordinates. The map has the corresponding index stored.
+     */
+    using UVMapKey = std::pair<usize, float2>;
+    blender::Map<UVMapKey, usize> uv_map;
+    usize true_uv_index = 0;
 
     for (auto i = 0; i < mesh->totpoly; i++) {
       const auto &mp = mesh->mpoly[i];
@@ -521,9 +530,16 @@ class MeshIO {
       for (auto j = 0; j < mp.totloop; j++) {
         const auto &ml = mesh->mloop[mp.loopstart + j];
         usize pos_index = ml.v;
-        usize uv_index = mp.loopstart + j;
         usize normal_index = ml.v;
 
+        const UVMapKey key = {ml.v, mesh->mloopuv[mp.loopstart + j].uv};
+        if (uv_map.contains(key) == false) {
+          uvs.append(mesh->mloopuv[mp.loopstart + j].uv);
+          uv_map.add_new(key, true_uv_index);
+          true_uv_index++;
+        }
+        usize uv_index = uv_map.lookup(key);
+
         face.append(std::make_tuple(pos_index, uv_index, normal_index));
       }
 
diff --git a/source/blender/blenkernel/tests/BKE_cloth_remesh_test.cc b/source/blender/blenkernel/tests/BKE_cloth_remesh_test.cc
index 8bfd29a21bc..629df904971 100644
--- a/source/blender/blenkernel/tests/BKE_cloth_remesh_test.cc
+++ b/source/blender/blenkernel/tests/BKE_cloth_remesh_test.cc
@@ -319,26 +319,16 @@ TEST(cloth_remesh, MeshIO_ReadDNAMesh)
       "vt 0.625 0\n"
       "vt 0.625 0.25\n"
       "vt 0.375 0.25\n"
-      "vt 0.375 0.25\n"
-      "vt 0.625 0.25\n"
       "vt 0.625 0.5\n"
       "vt 0.375 0.5\n"
-      "vt 0.375 0.5\n"
-      "vt 0.625 0.5\n"
       "vt 0.625 0.75\n"
       "vt 0.375 0.75\n"
-      "vt 0.375 0.75\n"
-      "vt 0.625 0.75\n"
       "vt 0.625 1\n"
       "vt 0.375 1\n"
       "vt 0.125 0.5\n"
-      "vt 0.375 0.5\n"
-      "vt 0.375 0.75\n"
       "vt 0.125 0.75\n"
-      "vt 0.625 0.5\n"
       "vt 0.875 0.5\n"
       "vt 0.875 0.75\n"
-      "vt 0.625 0.75\n"
       "vn -0.577349 -0.577349 -0.577349\n"
       "vn -0.577349 -0.577349 0.577349\n"
       "vn -0.577349 0.577349 -0.577349\n"
@@ -348,11 +338,11 @@ TEST(cloth_remesh, MeshIO_ReadDNAMesh)
       "vn 0.577349 0.577349 -0.577349\n"
       "vn 0.577349 0.577349 0.577349\n"
       "f 1/1/1 2/2/2 4/3/4 3/4/3 \n"
-      "f 3/5/3 4/6/4 8/7/8 7/8/7 \n"
-      "f 7/9/7 8/10/8 6/11/6 5/12/5 \n"
-      "f 5/13/5 6/14/6 2/15/2 1/16/1 \n"
-      "f 3/17/3 7/18/7 5/19/5 1/20/1 \n"
-      "f 8/21/8 4/22/4 2/23/2 6/24/6 \n";
+      "f 3/4/3 4/3/4 8/5/8 7/6/7 \n"
+      "f 7/6/7 8/5/8 6/7/6 5/8/5 \n"
+      "f 5/8/5 6/7/6 2/9/2 1/10/1 \n"
+      "f 3/11/3 7/6/7 5/8/5 1/12/1 \n"
+      "f 8/5/8 4/13/4 2/14/2 6/7/6 \n";
 
   EXPECT_EQ(stream_out.str(), expected);
 }



More information about the Bf-blender-cvs mailing list