[Bf-blender-cvs] [26acb7d5f48] refactor-mesh-uv-map-generic: Merge branch 'master' into refactor-mesh-uv-map-generic

Martijn Versteegh noreply at git.blender.org
Thu Nov 10 00:08:44 CET 2022


Commit: 26acb7d5f4878ba8c7bc1c95681d5890101c2e6c
Author: Martijn Versteegh
Date:   Tue Nov 8 23:18:55 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB26acb7d5f4878ba8c7bc1c95681d5890101c2e6c

Merge branch 'master' into refactor-mesh-uv-map-generic

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



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

diff --cc source/blender/editors/uvedit/uvedit_islands.cc
index 2c6a8a1a3a6,d8e10435146..c45fb8a2cbd
--- a/source/blender/editors/uvedit/uvedit_islands.cc
+++ b/source/blender/editors/uvedit/uvedit_islands.cc
@@@ -36,29 -36,48 +36,48 @@@
  
  #include "bmesh.h"
  
- /* -------------------------------------------------------------------- */
- /** \name UV Face Utilities
-  * \{ */
+ static void mul_v2_m2_add_v2v2(float r[2],
+                                const float mat[2][2],
+                                const float a[2],
+                                const float b[2])
+ {
+   /* Compute `r = mat * (a + b)` with high precision. */
+   const double x = static_cast<double>(a[0]) + static_cast<double>(b[0]);
+   const double y = static_cast<double>(a[1]) + static_cast<double>(b[1]);
+ 
+   r[0] = static_cast<float>(mat[0][0] * x + mat[1][0] * y);
+   r[1] = static_cast<float>(mat[0][1] * x + mat[1][1] * y);
+ }
  
- static void bm_face_uv_translate_and_scale_around_pivot(BMFace *f,
-                                                         const float offset[2],
-                                                         const float scale[2],
-                                                         const float pivot[2],
-                                                         const int cd_loop_uv_offset)
+ static void island_uv_transform(FaceIsland *island,
+                                 const float matrix[2][2],    /* Scale and rotation. */
+                                 const float pre_translate[2] /* (pre) Translation. */
+ )
  {
-   BMLoop *l_iter;
-   BMLoop *l_first;
-   l_iter = l_first = BM_FACE_FIRST_LOOP(f);
-   do {
-     float *luv = BM_ELEM_CD_GET_FLOAT_P(l_iter, cd_loop_uv_offset);
-     for (int i = 0; i < 2; i++) {
-       luv[i] = offset[i] + (((luv[i] - pivot[i]) * scale[i]) + pivot[i]);
+   /* Use a pre-transform to compute `A * (x+b)`
+    *
+    * \note Ordinarily, we'd use a post_transform like `A * x + b`
+    * In general, post-transforms are easier to work with when using homogenous co-ordinates.
+    *
+    * When UV mapping into the unit square, post-transforms can lose precision on small islands.
+    * Instead we're using a pre-transform to maintain precision.
+    *
+    * To convert post-transform to pre-transform, use `A * x + b == A * (x + c), c = A^-1 * b`
+    */
+ 
 -  const int cd_loop_uv_offset = island->cd_loop_uv_offset;
++  const int cd_loop_uv_offset = island->offsets.uv;
+   const int faces_len = island->faces_len;
+   for (int i = 0; i < faces_len; i++) {
+     BMFace *f = island->faces[i];
+     BMLoop *l;
+     BMIter iter;
+     BM_ITER_ELEM (l, &iter, f, BM_LOOPS_OF_FACE) {
 -      MLoopUV *luv = (MLoopUV *)BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
 -      mul_v2_m2_add_v2v2(luv->uv, matrix, luv->uv, pre_translate);
++      float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
++      mul_v2_m2_add_v2v2(luv, matrix, luv, pre_translate);
      }
-   } while ((l_iter = l_iter->next) != l_first);
+   }
  }
  
- /** \} */
- 
  /* -------------------------------------------------------------------- */
  /** \name UV Face Array Utilities
   * \{ */
diff --cc source/blender/editors/uvedit/uvedit_select.c
index aa87aa9e5e5,777cc1d97e4..faa7b0e9b73
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@@ -4679,9 -4703,9 +4679,9 @@@ static int uv_select_similar_vert_exec(
        continue;
      }
  
 -    const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
 +    const BMUVOffsets offsets = BM_uv_map_get_offsets(bm);
      float ob_m3[3][3];
-     copy_m3_m4(ob_m3, ob->obmat);
+     copy_m3_m4(ob_m3, ob->object_to_world);
  
      BMFace *face;
      BMIter iter;
@@@ -4715,10 -4740,9 +4715,10 @@@
      }
  
      bool changed = false;
 -    const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
 +
 +    const BMUVOffsets offsets = BM_uv_map_get_offsets(bm);
      float ob_m3[3][3];
-     copy_m3_m4(ob_m3, ob->obmat);
+     copy_m3_m4(ob_m3, ob->object_to_world);
  
      BMFace *face;
      BMIter iter;
@@@ -4791,9 -4816,9 +4791,9 @@@ static int uv_select_similar_edge_exec(
        continue;
      }
  
 -    const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
 +    const BMUVOffsets offsets = BM_uv_map_get_offsets(bm);
      float ob_m3[3][3];
-     copy_m3_m4(ob_m3, ob->obmat);
+     copy_m3_m4(ob_m3, ob->object_to_world);
  
      BMFace *face;
      BMIter iter;
@@@ -4830,9 -4857,9 +4830,9 @@@
      }
  
      bool changed = false;
 -    const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
 +    const BMUVOffsets offsets = BM_uv_map_get_offsets(bm);
      float ob_m3[3][3];
-     copy_m3_m4(ob_m3, ob->obmat);
+     copy_m3_m4(ob_m3, ob->object_to_world);
  
      BMFace *face;
      BMIter iter;
@@@ -4898,9 -4927,9 +4898,9 @@@ static int uv_select_similar_face_exec(
      BMesh *bm = em->bm;
  
      float ob_m3[3][3];
-     copy_m3_m4(ob_m3, ob->obmat);
+     copy_m3_m4(ob_m3, ob->object_to_world);
  
 -    const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
 +    const BMUVOffsets offsets = BM_uv_map_get_offsets(bm);
  
      BMFace *face;
      BMIter iter;
@@@ -4931,10 -4960,10 +4931,10 @@@
      BMesh *bm = em->bm;
      bool changed = false;
      bool do_history = false;
 -    const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
 +    const BMUVOffsets offsets = BM_uv_map_get_offsets(bm);
  
      float ob_m3[3][3];
-     copy_m3_m4(ob_m3, ob->obmat);
+     copy_m3_m4(ob_m3, ob->object_to_world);
  
      BMFace *face;
      BMIter iter;
diff --cc source/blender/io/usd/intern/usd_writer_mesh.cc
index 04c86e57852,e7d79e888e4..8b47da4fc00
--- a/source/blender/io/usd/intern/usd_writer_mesh.cc
+++ b/source/blender/io/usd/intern/usd_writer_mesh.cc
@@@ -120,13 -122,13 +123,13 @@@ void USDGenericMeshWriter::write_uv_map
       * for texture coordinates by naming the UV Map as such, without having to guess which UV Map
       * is the "standard" one. */
      pxr::TfToken primvar_name(pxr::TfMakeValidIdentifier(layer->name));
-     pxr::UsdGeomPrimvar uv_coords_primvar = usd_mesh.CreatePrimvar(
+     pxr::UsdGeomPrimvar uv_coords_primvar = primvarsAPI.CreatePrimvar(
          primvar_name, pxr::SdfValueTypeNames->TexCoord2fArray, pxr::UsdGeomTokens->faceVarying);
  
 -    MLoopUV *mloopuv = static_cast<MLoopUV *>(layer->data);
 +    const float2 *mloopuv = static_cast<const float2 *>(layer->data);
      pxr::VtArray<pxr::GfVec2f> uv_coords;
      for (int loop_idx = 0; loop_idx < mesh->totloop; loop_idx++) {
 -      uv_coords.push_back(pxr::GfVec2f(mloopuv[loop_idx].uv));
 +      uv_coords.push_back(pxr::GfVec2f((const float *)(mloopuv[loop_idx])));
      }
  
      if (!uv_coords_primvar.HasValue()) {
diff --cc source/blender/makesdna/DNA_modifier_types.h
index c5d8fb267b6,c4180071352..5fca67321b1
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@@ -1936,11 -1932,10 +1936,11 @@@ typedef struct UVWarpModifierData 
    /** Optional name of bone target, MAX_ID_NAME-2. */
    char bone_dst[64];
  
-   /** Optional vertexgroup name, MAX_VGROUP_NAME. */
+   /** Optional vertex-group name, #MAX_VGROUP_NAME. */
    char vgroup_name[64];
    /** MAX_CUSTOMDATA_LAYER_NAME. */
 -  char uvlayer_name[64];
 +  char uvlayer_name[68];
 +  char _pad[4];
  } UVWarpModifierData;
  
  /** #UVWarpModifierData.flag */



More information about the Bf-blender-cvs mailing list