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

Martijn Versteegh noreply at git.blender.org
Fri Jan 6 15:58:59 CET 2023


Commit: 1f2ebcc4df1f304e3519e5b89068d78c59ae5ca9
Author: Martijn Versteegh
Date:   Fri Jan 6 15:36:07 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB1f2ebcc4df1f304e3519e5b89068d78c59ae5ca9

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

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



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

diff --cc source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 471eb280ed4,0f8830a4521..97e5cb7dcfa
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@@ -2731,31 -2749,98 +2727,98 @@@ static void uv_map_mirror(BMFace *efa
    BMLoop *l;
    BMIter liter;
    float **uvs = BLI_array_alloca(uvs, efa->len);
-   float dx;
-   int i, mi;
- 
-   const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_PROP_FLOAT2);
- 
-   BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
+   int j;
+   BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, j) {
 -    MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
 -    uvs[j] = luv->uv;
 -    if (luv->uv[0] >= 1.0f) {
 -      luv->uv[0] -= 1.0f;
 +    float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
-     uvs[i] = luv;
++    uvs[j] = luv;
++    if (luv[0] >= 1.0f) {
++      luv[0] -= 1.0f;
+     }
 -    right_u = max_ff(right_u, luv->uv[0]);
++    right_u = max_ff(right_u, luv[0]);
    }
  
-   mi = 0;
-   for (i = 1; i < efa->len; i++) {
-     if (uvs[i][0] > uvs[mi][0]) {
-       mi = i;
+   float left_u = 1.0e30f;
+   BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
 -    MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
 -    if (right_u <= luv->uv[0] + 0.5f) {
 -      left_u = min_ff(left_u, luv->uv[0]);
++    float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
++    if (right_u <= luv[0] + 0.5f) {
++      left_u = min_ff(left_u, luv[0]);
      }
    }
  
-   for (i = 0; i < efa->len; i++) {
-     if (i != mi) {
-       dx = uvs[mi][0] - uvs[i][0];
-       if (dx > 0.5f) {
-         uvs[i][0] += 1.0f;
+   BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
 -    MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
 -    if (luv->uv[0] + 0.5f < right_u) {
 -      if (2 * luv->uv[0] + 1.0f < left_u + right_u) {
 -        luv->uv[0] += 1.0f;
++    float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
++    if (luv[0] + 0.5f < right_u) {
++      if (2 * luv[0] + 1.0f < left_u + right_u) {
++        luv[0] += 1.0f;
        }
      }
    }
+   if (!fan) {
+     return;
+   }
+ 
+   /* Another heuristic, this time, we attempt to "fan"
+    * the UVs of faces which pass through one of the poles
+    * of the unwrapping. */
+ 
+   /* Need to recompute min and max. */
+   float minmax_u[2] = {1.0e30f, -1.0e30f};
+   int pole_count = 0;
+   for (int i = 0; i < efa->len; i++) {
+     if (regular[i]) {
+       minmax_u[0] = min_ff(minmax_u[0], uvs[i][0]);
+       minmax_u[1] = max_ff(minmax_u[1], uvs[i][0]);
+     }
+     else {
+       pole_count++;
+     }
+   }
+   if (pole_count == 0 || pole_count == efa->len) {
+     return;
+   }
+   for (int i = 0; i < efa->len; i++) {
+     if (regular[i]) {
+       continue;
+     }
+     float u = 0.0f;
+     float sum = 0.0f;
+     const int i_plus = (i + 1) % efa->len;
+     const int i_minus = (i + efa->len - 1) % efa->len;
+     if (regular[i_plus]) {
+       u += uvs[i_plus][0];
+       sum += 1.0f;
+     }
+     if (regular[i_minus]) {
+       u += uvs[i_minus][0];
+       sum += 1.0f;
+     }
+     if (sum == 0) {
+       u += minmax_u[0] + minmax_u[1];
+       sum += 2.0f;
+     }
+     uvs[i][0] = u / sum;
+   }
+ }
+ 
+ static void uv_sphere_project(BMFace *efa,
+                               const float center[3],
+                               const float rotmat[3][3],
+                               const bool fan,
+                               const int cd_loop_uv_offset)
+ {
+   bool *regular = BLI_array_alloca(regular, efa->len);
+   int i;
+   BMLoop *l;
+   BMIter iter;
+   BM_ITER_ELEM_INDEX (l, &iter, efa, BM_LOOPS_OF_FACE, i) {
 -    MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
++    float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
+     float pv[3];
+     sub_v3_v3v3(pv, l->v->co, center);
+     mul_m3_v3(rotmat, pv);
 -    regular[i] = map_to_sphere(&luv->uv[0], &luv->uv[1], pv[0], pv[1], pv[2]);
++    regular[i] = map_to_sphere(&luv[0], &luv[1], pv[0], pv[1], pv[2]);
+   }
+ 
+   uv_map_mirror(efa, regular, fan, cd_loop_uv_offset);
  }
  
  static int sphere_project_exec(bContext *C, wmOperator *op)
@@@ -2789,8 -2873,8 +2851,8 @@@
        continue;
      }
  
 -    const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
 +    const BMUVOffsets offsets = BM_uv_map_get_offsets(em->bm);
-     float center[3], rotmat[4][4];
+     float center[3], rotmat[3][3];
  
      uv_map_transform(C, op, rotmat);
      uv_map_transform_center(scene, v3d, obedit, em, center, NULL);
@@@ -2807,12 -2893,7 +2871,7 @@@
          }
        }
  
-       BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
-         float *luv = BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv);
-         uv_sphere_project(luv, l->v->co, center, rotmat);
-       }
- 
-       uv_map_mirror(em, efa);
 -      uv_sphere_project(efa, center, rotmat, fan, cd_loop_uv_offset);
++      uv_sphere_project(efa, center, rotmat, fan, offsets.uv);
      }
  
      const bool per_face_aspect = true;
@@@ -2850,22 -2931,25 +2909,25 @@@ void UV_OT_sphere_project(wmOperatorTyp
  /** \name Cylinder UV Project Operator
   * \{ */
  
- static void uv_cylinder_project(float target[2],
-                                 const float source[3],
+ static void uv_cylinder_project(BMFace *efa,
                                  const float center[3],
-                                 const float rotmat[4][4])
+                                 const float rotmat[3][3],
+                                 const bool fan,
+                                 const int cd_loop_uv_offset)
  {
-   float pv[3];
- 
-   sub_v3_v3v3(pv, source, center);
-   mul_m4_v3(rotmat, pv);
- 
-   map_to_tube(&target[0], &target[1], pv[0], pv[1], pv[2]);
- 
-   /* split line is always zero */
-   if (target[0] >= 1.0f) {
-     target[0] -= 1.0f;
+   bool *regular = BLI_array_alloca(regular, efa->len);
+   int i;
+   BMLoop *l;
+   BMIter iter;
+   BM_ITER_ELEM_INDEX (l, &iter, efa, BM_LOOPS_OF_FACE, i) {
 -    MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
++    float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
+     float pv[3];
+     sub_v3_v3v3(pv, l->v->co, center);
+     mul_m3_v3(rotmat, pv);
 -    regular[i] = map_to_tube(&luv->uv[0], &luv->uv[1], pv[0], pv[1], pv[2]);
++    regular[i] = map_to_tube(&luv[0], &luv[1], pv[0], pv[1], pv[2]);
    }
+ 
+   uv_map_mirror(efa, regular, fan, cd_loop_uv_offset);
  }
  
  static int cylinder_project_exec(bContext *C, wmOperator *op)
@@@ -2899,8 -2982,8 +2960,8 @@@
        continue;
      }
  
 -    const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
 +    const BMUVOffsets offsets = BM_uv_map_get_offsets(em->bm);
-     float center[3], rotmat[4][4];
+     float center[3], rotmat[3][3];
  
      uv_map_transform(C, op, rotmat);
      uv_map_transform_center(scene, v3d, obedit, em, center, NULL);
@@@ -2915,12 -3000,7 +2978,7 @@@
          continue;
        }
  
-       BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
-         float *luv = BM_ELEM_CD_GET_VOID_P(l, offsets.uv);
-         uv_cylinder_project(luv, l->v->co, center, rotmat);
-       }
- 
-       uv_map_mirror(em, efa);
 -      uv_cylinder_project(efa, center, rotmat, fan, cd_loop_uv_offset);
++      uv_cylinder_project(efa, center, rotmat, fan, offsets.uv);
      }
  
      const bool per_face_aspect = true;



More information about the Bf-blender-cvs mailing list