[Bf-blender-cvs] [41689bb3104] blender-v2.93-release: Fix: Incorrect coordinates used in BLI_rct*_isect_segment functions

2022-08-02 Thread Siddhartha Jejurkar
Commit: 41689bb310469d85d9eae59ca578f4a15dc0e80b
Author: Siddhartha Jejurkar
Date:   Tue Jul 12 19:27:48 2022 +1000
Branches: blender-v2.93-release
https://developer.blender.org/rB41689bb310469d85d9eae59ca578f4a15dc0e80b

Fix: Incorrect coordinates used in BLI_rct*_isect_segment functions

Ref D15330.

===

M   source/blender/blenlib/intern/rct.c

===

diff --git a/source/blender/blenlib/intern/rct.c 
b/source/blender/blenlib/intern/rct.c
index 35e24ecc785..8b6e6abc713 100644
--- a/source/blender/blenlib/intern/rct.c
+++ b/source/blender/blenlib/intern/rct.c
@@ -294,7 +294,7 @@ bool BLI_rcti_isect_segment(const rcti *rect, const int 
s1[2], const int s2[2])
   /* diagonal: [/] */
   tvec1[0] = rect->xmin;
   tvec1[1] = rect->ymin;
-  tvec2[0] = rect->xmin;
+  tvec2[0] = rect->xmax;
   tvec2[1] = rect->ymax;
   if (isect_segments_i(s1, s2, tvec1, tvec2)) {
 return true;
@@ -340,7 +340,7 @@ bool BLI_rctf_isect_segment(const rctf *rect, const float 
s1[2], const float s2[
   /* diagonal: [/] */
   tvec1[0] = rect->xmin;
   tvec1[1] = rect->ymin;
-  tvec2[0] = rect->xmin;
+  tvec2[0] = rect->xmax;
   tvec2[1] = rect->ymax;
   if (isect_segments_fl(s1, s2, tvec1, tvec2)) {
 return true;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [77257405437] master: UV: Edge support for select shortest path operator

2022-07-21 Thread Siddhartha Jejurkar
Commit: 77257405437336dbd91a481926013f8c747cacae
Author: Siddhartha Jejurkar
Date:   Fri Jul 22 10:47:28 2022 +1000
Branches: master
https://developer.blender.org/rB77257405437336dbd91a481926013f8c747cacae

UV: Edge support for select shortest path operator

Calculating shortest path selection in UV edge mode was done using vertex
path logic. Since the UV editor now supports proper edge selection [0],
this approach can sometimes give incorrect results.

This problem is now fixed by adding separate logic to calculate the
shortest path in UV edge mode.

Resolves T99344.

[0]: ffaaa0bcbf477c30cf3665b9330767397169

Reviewed By: campbellbarton

Ref D15511.

===

M   source/blender/bmesh/tools/bmesh_path_uv.c
M   source/blender/bmesh/tools/bmesh_path_uv.h
M   source/blender/editors/uvedit/uvedit_path.c

===

diff --git a/source/blender/bmesh/tools/bmesh_path_uv.c 
b/source/blender/bmesh/tools/bmesh_path_uv.c
index 76697f51ac7..3d736cdc3b8 100644
--- a/source/blender/bmesh/tools/bmesh_path_uv.c
+++ b/source/blender/bmesh/tools/bmesh_path_uv.c
@@ -47,9 +47,7 @@ static float step_cost_3_v2_ex(
   return cost * (1.0f + 0.5f * (2.0f - sqrtf(fabsf(dot_v2v2(d1, d2);
 }
 
-static float UNUSED_FUNCTION(step_cost_3_v2)(const float v1[2],
- const float v2[2],
- const float v3[2])
+static float step_cost_3_v2(const float v1[2], const float v2[2], const float 
v3[2])
 {
   return step_cost_3_v2_ex(v1, v2, v3, false, false);
 }
@@ -60,7 +58,7 @@ static float UNUSED_FUNCTION(step_cost_3_v2)(const float 
v1[2],
 /** \name BM_mesh_calc_path_uv_vert
  * \{ */
 
-static void looptag_add_adjacent_uv(HeapSimple *heap,
+static void verttag_add_adjacent_uv(HeapSimple *heap,
 BMLoop *l_a,
 BMLoop **loops_prev,
 float *cost,
@@ -162,7 +160,7 @@ struct LinkNode *BM_mesh_calc_path_uv_vert(BMesh *bm,
 if (!BM_elem_flag_test(l, BM_ELEM_TAG)) {
   /* Adjacent loops are tagged while stepping to avoid 2x loops. */
   BM_elem_flag_enable(l, BM_ELEM_TAG);
-  looptag_add_adjacent_uv(heap, l, loops_prev, cost, params);
+  verttag_add_adjacent_uv(heap, l, loops_prev, cost, params);
 }
   }
 
@@ -185,8 +183,199 @@ struct LinkNode *BM_mesh_calc_path_uv_vert(BMesh *bm,
 /** \name BM_mesh_calc_path_uv_edge
  * \{ */
 
-/* TODO(@sidd017): Setting this as todo, since we now support proper UV edge 
selection (D12028).
- * Till then, continue using vertex path to fake shortest path calculation for 
edges. */
+static float edgetag_cut_cost_vert_uv(
+BMLoop *l_e_a, BMLoop *l_e_b, BMLoop *l_v, const float aspect_y, const int 
cd_loop_uv_offset)
+{
+  BMLoop *l_v1 = (l_v->v == l_e_a->v) ? l_e_a->next : l_e_a;
+  BMLoop *l_v2 = (l_v->v == l_e_b->v) ? l_e_b->next : l_e_b;
+
+  MLoopUV *luv_v1 = BM_ELEM_CD_GET_VOID_P(l_v1, cd_loop_uv_offset);
+  MLoopUV *luv_v2 = BM_ELEM_CD_GET_VOID_P(l_v2, cd_loop_uv_offset);
+  MLoopUV *luv_v = BM_ELEM_CD_GET_VOID_P(l_v, cd_loop_uv_offset);
+
+  float uv_v1[2] = {luv_v1->uv[0], luv_v1->uv[1] / aspect_y};
+  float uv_v2[2] = {luv_v2->uv[0], luv_v2->uv[1] / aspect_y};
+  float uv_v[2] = {luv_v->uv[0], luv_v->uv[1] / aspect_y};
+
+  return step_cost_3_v2(uv_v1, uv_v, uv_v2);
+}
+
+static float edgetag_cut_cost_face_uv(
+BMLoop *l_e_a, BMLoop *l_e_b, BMFace *f, const float aspect_v2[2], const 
int cd_loop_uv_offset)
+{
+  float l_e_a_cent[2], l_e_b_cent[2], f_cent[2];
+  MLoopUV *luv_e_a = BM_ELEM_CD_GET_VOID_P(l_e_a, cd_loop_uv_offset);
+  MLoopUV *luv_e_b = BM_ELEM_CD_GET_VOID_P(l_e_b, cd_loop_uv_offset);
+
+  mid_v2_v2v2(l_e_a_cent, luv_e_a->uv, luv_e_a->uv);
+  mid_v2_v2v2(l_e_b_cent, luv_e_b->uv, luv_e_b->uv);
+
+  mul_v2_v2(l_e_a_cent, aspect_v2);
+  mul_v2_v2(l_e_b_cent, aspect_v2);
+
+  BM_face_uv_calc_center_median_weighted(f, aspect_v2, cd_loop_uv_offset, 
f_cent);
+
+  return step_cost_3_v2(l_e_a_cent, l_e_b_cent, f_cent);
+}
+
+static void edgetag_add_adjacent_uv(HeapSimple *heap,
+BMLoop *l_a,
+BMLoop **loops_prev,
+float *cost,
+const struct BMCalcPathUVParams *params)
+{
+  BLI_assert(params->aspect_y != 0.0f);
+  const uint cd_loop_uv_offset = params->cd_loop_uv_offset;
+  BMLoop *l_a_verts[2] = {l_a, l_a->next};
+  const int l_a_index = BM_elem_index_get(l_a);
+
+  if (params->use_step_face == false) {
+for (int i = 0; i < ARRAY_SIZE(l_a_verts); i++) {
+
+  /* Skip current UV vert if it is part of the previous UV edge in the 
path. */
+  if (loops_prev[l_a_index]) {
+BMLoop *l_prev = loops_prev[l_a_index];
+if (l

[Bf-blender-cvs] [c07e9e0828d] blender-v3.2-release: Fix: Incorrect coordinates used in BLI_rct*_isect_segment functions

2022-07-15 Thread Siddhartha Jejurkar
Commit: c07e9e0828d17cd1b060c9151532eb4467e1843c
Author: Siddhartha Jejurkar
Date:   Tue Jul 12 19:27:48 2022 +1000
Branches: blender-v3.2-release
https://developer.blender.org/rBc07e9e0828d17cd1b060c9151532eb4467e1843c

Fix: Incorrect coordinates used in BLI_rct*_isect_segment functions

Ref D15330.

===

M   source/blender/blenlib/intern/rct.c

===

diff --git a/source/blender/blenlib/intern/rct.c 
b/source/blender/blenlib/intern/rct.c
index 0bb606c288e..7248db5b718 100644
--- a/source/blender/blenlib/intern/rct.c
+++ b/source/blender/blenlib/intern/rct.c
@@ -265,7 +265,7 @@ bool BLI_rcti_isect_segment(const rcti *rect, const int 
s1[2], const int s2[2])
   /* diagonal: [/] */
   tvec1[0] = rect->xmin;
   tvec1[1] = rect->ymin;
-  tvec2[0] = rect->xmin;
+  tvec2[0] = rect->xmax;
   tvec2[1] = rect->ymax;
   if (isect_segments_i(s1, s2, tvec1, tvec2)) {
 return true;
@@ -311,7 +311,7 @@ bool BLI_rctf_isect_segment(const rctf *rect, const float 
s1[2], const float s2[
   /* diagonal: [/] */
   tvec1[0] = rect->xmin;
   tvec1[1] = rect->ymin;
-  tvec2[0] = rect->xmin;
+  tvec2[0] = rect->xmax;
   tvec2[1] = rect->ymax;
   if (isect_segments_fl(s1, s2, tvec1, tvec2)) {
 return true;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [52b7f2b0890] master: UV: Box and lasso selection for partially intersecting edges

2022-07-12 Thread Siddhartha Jejurkar
Commit: 52b7f2b089071a6d2281e369ab820c9406e06c4e
Author: Siddhartha Jejurkar
Date:   Tue Jul 12 19:39:57 2022 +1000
Branches: master
https://developer.blender.org/rB52b7f2b089071a6d2281e369ab820c9406e06c4e

UV: Box and lasso selection for partially intersecting edges

In UV edge mode, box and lasso selections allow edge selections only
when the entire edge is contained within the selection area. This
doesn't consider any edges that partially overlap with the selection
area.

This is  now fixed by adding a second pass, similar to how these
operators work for edit-mesh selections. Now if both operators are
unable to find any edges contained within the selection area, then
they will perform a second pass which checks for edges that partially
intersect with the selection area.

Now edge selection in the UV editor matches edit-mesh edge-selection
when drawing wire-frame.

Resolves T99443.

Ref D15362

===

M   source/blender/editors/include/UI_view2d.h
M   source/blender/editors/interface/view2d.cc
M   source/blender/editors/uvedit/uvedit_select.c

===

diff --git a/source/blender/editors/include/UI_view2d.h 
b/source/blender/editors/include/UI_view2d.h
index 5c4eb254462..e508c96b4f1 100644
--- a/source/blender/editors/include/UI_view2d.h
+++ b/source/blender/editors/include/UI_view2d.h
@@ -309,6 +309,12 @@ float UI_view2d_view_to_region_y(const struct View2D *v2d, 
float y);
 bool UI_view2d_view_to_region_clip(
 const struct View2D *v2d, float x, float y, int *r_region_x, int 
*r_region_y) ATTR_NONNULL();
 
+bool UI_view2d_view_to_region_segment_clip(const View2D *v2d,
+   const float xy_a[2],
+   const float xy_b[2],
+   int r_region_a[2],
+   int r_region_b[2]) ATTR_NONNULL();
+
 /**
  * Convert from 2d-view space to screen/region space
  *
diff --git a/source/blender/editors/interface/view2d.cc 
b/source/blender/editors/interface/view2d.cc
index ee4bfd351ae..1bf7e25b154 100644
--- a/source/blender/editors/interface/view2d.cc
+++ b/source/blender/editors/interface/view2d.cc
@@ -1695,6 +1695,41 @@ void UI_view2d_view_to_region_fl(
   *r_region_y = v2d->mask.ymin + (y * BLI_rcti_size_y(>mask));
 }
 
+bool UI_view2d_view_to_region_segment_clip(const View2D *v2d,
+   const float xy_a[2],
+   const float xy_b[2],
+   int r_region_a[2],
+   int r_region_b[2])
+{
+  rctf rect_unit;
+  rect_unit.xmin = rect_unit.ymin = 0.0f;
+  rect_unit.xmax = rect_unit.ymax = 1.0f;
+
+  /* Express given coordinates as proportional values. */
+  const float s_a[2] = {
+  (xy_a[0] - v2d->cur.xmin) / BLI_rctf_size_x(>cur),
+  (xy_a[1] - v2d->cur.ymin) / BLI_rctf_size_y(>cur),
+  };
+  const float s_b[2] = {
+  (xy_b[0] - v2d->cur.xmin) / BLI_rctf_size_x(>cur),
+  (xy_b[1] - v2d->cur.ymin) / BLI_rctf_size_y(>cur),
+  };
+
+  /* Set initial value in case coordinates lie outside bounds. */
+  r_region_a[0] = r_region_b[0] = r_region_a[1] = r_region_b[1] = 
V2D_IS_CLIPPED;
+
+  if (BLI_rctf_isect_segment(_unit, s_a, s_b)) {
+r_region_a[0] = (int)(v2d->mask.xmin + (s_a[0] * 
BLI_rcti_size_x(>mask)));
+r_region_a[1] = (int)(v2d->mask.ymin + (s_a[1] * 
BLI_rcti_size_y(>mask)));
+r_region_b[0] = (int)(v2d->mask.xmin + (s_b[0] * 
BLI_rcti_size_x(>mask)));
+r_region_b[1] = (int)(v2d->mask.ymin + (s_b[1] * 
BLI_rcti_size_y(>mask)));
+
+return true;
+  }
+
+  return false;
+}
+
 void UI_view2d_view_to_region_rcti(const View2D *v2d, const rctf *rect_src, 
rcti *rect_dst)
 {
   const float cur_size[2] = {BLI_rctf_size_x(>cur), 
BLI_rctf_size_y(>cur)};
diff --git a/source/blender/editors/uvedit/uvedit_select.c 
b/source/blender/editors/uvedit/uvedit_select.c
index db834f6a0fd..b5a564fd984 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -3582,6 +3582,7 @@ static int uv_box_select_exec(bContext *C, wmOperator *op)
   }
 }
 else if (use_edge && !pinned) {
+  bool do_second_pass = true;
   BM_ITER_MESH (efa, , em->bm, BM_FACES_OF_MESH) {
 if (!uvedit_face_visible_test(scene, efa)) {
   continue;
@@ -3596,11 +3597,35 @@ static int uv_box_select_exec(bContext *C, wmOperator 
*op)
 uvedit_edge_select_set_with_sticky(
 scene, em, l_prev, select, false, cd_loop_uv_offset);
 changed = true;
+do_second_pass = false;
   }
   l_prev = l;
   luv_prev = luv;
 }
   }
+  /* Do a second pass if no complete edges c

[Bf-blender-cvs] [bb3a5388439] master: Fix: Incorrect coordinates used in BLI_rct*_isect_segment functions

2022-07-12 Thread Siddhartha Jejurkar
Commit: bb3a53884394908ba34459c38d419e6c4abe6107
Author: Siddhartha Jejurkar
Date:   Tue Jul 12 19:27:48 2022 +1000
Branches: master
https://developer.blender.org/rBbb3a53884394908ba34459c38d419e6c4abe6107

Fix: Incorrect coordinates used in BLI_rct*_isect_segment functions

Ref D15330.

===

M   source/blender/blenlib/intern/rct.c

===

diff --git a/source/blender/blenlib/intern/rct.c 
b/source/blender/blenlib/intern/rct.c
index 0bb606c288e..7248db5b718 100644
--- a/source/blender/blenlib/intern/rct.c
+++ b/source/blender/blenlib/intern/rct.c
@@ -265,7 +265,7 @@ bool BLI_rcti_isect_segment(const rcti *rect, const int 
s1[2], const int s2[2])
   /* diagonal: [/] */
   tvec1[0] = rect->xmin;
   tvec1[1] = rect->ymin;
-  tvec2[0] = rect->xmin;
+  tvec2[0] = rect->xmax;
   tvec2[1] = rect->ymax;
   if (isect_segments_i(s1, s2, tvec1, tvec2)) {
 return true;
@@ -311,7 +311,7 @@ bool BLI_rctf_isect_segment(const rctf *rect, const float 
s1[2], const float s2[
   /* diagonal: [/] */
   tvec1[0] = rect->xmin;
   tvec1[1] = rect->ymin;
-  tvec2[0] = rect->xmin;
+  tvec2[0] = rect->xmax;
   tvec2[1] = rect->ymax;
   if (isect_segments_fl(s1, s2, tvec1, tvec2)) {
 return true;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [82fc8786ea1] master: Fix T99343: Missing RNA_def_property_update for show overlays in UV editor

2022-07-06 Thread Siddhartha Jejurkar
Commit: 82fc8786ea182f0cdc9c2eedea53cbf3a3656e4d
Author: Siddhartha Jejurkar
Date:   Mon Jul 4 11:49:07 2022 +0530
Branches: master
https://developer.blender.org/rB82fc8786ea182f0cdc9c2eedea53cbf3a3656e4d

Fix T99343: Missing RNA_def_property_update for show overlays in UV editor

Reviewed By: jbakker

Maniphest Tasks: T99343

Differential Revision: https://developer.blender.org/D15354

===

M   source/blender/makesrna/intern/rna_space.c

===

diff --git a/source/blender/makesrna/intern/rna_space.c 
b/source/blender/makesrna/intern/rna_space.c
index 745c7137cb2..969d1f2075e 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -5298,6 +5298,7 @@ static void rna_def_space_image_overlay(BlenderRNA *brna)
   prop = RNA_def_property(srna, "show_overlays", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_sdna(prop, NULL, "overlay.flag", 
SI_OVERLAY_SHOW_OVERLAYS);
   RNA_def_property_ui_text(prop, "Show Overlays", "Display overlays like UV 
Maps and Metadata");
+  RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, NULL);
 
   prop = RNA_def_property(srna, "show_grid_background", PROP_BOOLEAN, 
PROP_NONE);
   RNA_def_property_boolean_sdna(prop, NULL, "overlay.flag", 
SI_OVERLAY_SHOW_GRID_BACKGROUND);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [33be9c08856] master: Fix T98924: Skip saving selection properties for UV edge ring operator

2022-06-28 Thread Siddhartha Jejurkar
Commit: 33be9c08856fb0fbdafdc12843addc944ce4183b
Author: Siddhartha Jejurkar
Date:   Tue Jun 28 17:02:32 2022 +0530
Branches: master
https://developer.blender.org/rB33be9c08856fb0fbdafdc12843addc944ce4183b

Fix T98924: Skip saving selection properties for UV edge ring operator

Oversight in rB7724251af81f. Skip saving selection properties
for UV edge ring operator as it allows the operator to re-use
the value that was previously set using the key-map.

Reviewed By: campbellbarton

Maniphest Tasks: T98924

Differential Revision: https://developer.blender.org/D15214

===

M   source/blender/editors/uvedit/uvedit_select.c

===

diff --git a/source/blender/editors/uvedit/uvedit_select.c 
b/source/blender/editors/uvedit/uvedit_select.c
index 964ac5f650b..db834f6a0fd 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -2935,12 +2935,14 @@ void UV_OT_select_edge_ring(wmOperatorType *ot)
   ot->poll = ED_operator_uvedit; /* requires space image */
 
   /* properties */
-  RNA_def_boolean(ot->srna,
-  "extend",
-  0,
-  "Extend",
-  "Extend selection rather than clearing the existing 
selection");
-  RNA_def_float_vector(
+  PropertyRNA *prop;
+  prop = RNA_def_boolean(ot->srna,
+ "extend",
+ 0,
+ "Extend",
+ "Extend selection rather than clearing the existing 
selection");
+  RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+  prop = RNA_def_float_vector(
   ot->srna,
   "location",
   2,
@@ -2951,6 +2953,7 @@ void UV_OT_select_edge_ring(wmOperatorType *ot)
   "Mouse location in normalized coordinates, 0.0 to 1.0 is within the 
image bounds",
   -100.0f,
   100.0f);
+  RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 }
 
 /** \} */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ffaaa0bcbf4] master: UV: Edge selection support

2022-03-03 Thread Siddhartha Jejurkar
Commit: ffaaa0bcbf477c30cf3665b9330767397169
Author: Siddhartha Jejurkar
Date:   Thu Mar 3 17:32:07 2022 +0530
Branches: master
https://developer.blender.org/rBffaaa0bcbf477c30cf3665b9330767397169

UV: Edge selection support

This patch adds edge selection support for UV editing (refer T76545).
Developed as a part of GSoC 2021 project - UV Editor Improvements.

Previously, selections in the UV editor always flushed down to vertices
and this caused multiple issues such as T76343, T78757 and T26676.
This patch fixes that by adding edge selection support for all UV
operators and adding support for flushing selections between vertices
and edges. Updating UV select modes is now done using a separate
operator, which also handles select mode flushing and undo for UV
select modes. Drawing edges (in UV edge mode) is also updated to match
the edit-mesh display in the 3D viewport.

Notes on technical changes made with this patch:
* MLOOPUV_EDGESEL flag is restored (was removed in rB9fa29fe7652a).
* Support for flushing selection between vertices and edges.
* Restored the BMLoopUV.select_edge boolean in the Python API.
* New operator to update UV select modes and flushing.
* UV select mode is now part of editmesh undo.

TODOs added with this patch:
* Edge support for shortest path operator (currently uses vertex path logic).
* Change default theme color instead of reducing contrast with edge-select.
* Proper UV element selections for Reveal Hidden operator.

Reviewed By: campbellbarton

Differential Revision: https://developer.blender.org/D12028

===

M   release/scripts/presets/keyconfig/keymap_data/blender_default.py
M   
release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
M   release/scripts/startup/bl_ui/space_image.py
M   source/blender/bmesh/tools/bmesh_path_uv.c
M   source/blender/draw/engines/overlay/overlay_edit_uv.c
M   source/blender/draw/engines/overlay/overlay_private.h
M   source/blender/draw/engines/overlay/overlay_shader.c
M   source/blender/draw/engines/overlay/shaders/edit_uv_edges_frag.glsl
M   source/blender/draw/engines/overlay/shaders/edit_uv_edges_geom.glsl
M   source/blender/draw/engines/overlay/shaders/edit_uv_edges_vert.glsl
M   source/blender/editors/include/ED_uvedit.h
M   source/blender/editors/mesh/editmesh_undo.c
M   source/blender/editors/uvedit/uvedit_intern.h
M   source/blender/editors/uvedit/uvedit_ops.c
M   source/blender/editors/uvedit/uvedit_path.c
M   source/blender/editors/uvedit/uvedit_rip.c
M   source/blender/editors/uvedit/uvedit_select.c
M   source/blender/editors/uvedit/uvedit_smart_stitch.c
M   source/blender/editors/uvedit/uvedit_unwrap_ops.c
M   source/blender/makesdna/DNA_meshdata_types.h
M   source/blender/makesrna/intern/rna_mesh.c
M   source/blender/makesrna/intern/rna_scene.c
M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py 
b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 6f4f862a3b8..83946fbf68f 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -385,9 +385,9 @@ def _template_items_uv_select_mode(params):
 *_template_items_editmode_mesh_select_mode(params),
 # Hack to prevent fall-through, when sync select isn't enabled 
(and the island button isn't visible).
 ("mesh.select_mode", {"type": 'FOUR', "value": 'PRESS'}, None),
-*(("wm.context_set_enum", {"type": NUMBERS_1[i], "value": 'PRESS'},
-   {"properties": [("data_path", 'tool_settings.uv_select_mode'), 
("value", ty)]})
-  for i, ty in enumerate(('VERTEX', 'EDGE', 'FACE', 'ISLAND')))
+*(("uv.select_mode", {"type": k, "value": 'PRESS'},
+   {"properties": [("type", e)]})
+  for k, e in (('ONE', 'VERTEX'), ('TWO', 'EDGE'), ('THREE', 
'FACE'), ('FOUR', 'ISLAND')))
 ]
 
 
diff --git 
a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py 
b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
index e65ac32d088..8c303bc3f69 100644
--- a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
+++ b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
@@ -554,14 +554,14 @@ def km_uv_editor(params):
 ("wm.search_menu", {"type": 'TAB', "value": 'PRESS'}, None),
 # Selection modes.
 *_template_items_editmode_mesh_select_mode(params),
-("wm.context_set_enum",

[Bf-blender-cvs] [dbc41b30f88] soc-2021-uv-edge-select-support: Merge branch 'master' into soc-2021-uv-edge-select-support

2021-12-17 Thread Siddhartha Jejurkar
Commit: dbc41b30f88b96f7d8c6e995b17f5930eb55cc77
Author: Siddhartha Jejurkar
Date:   Fri Dec 17 18:31:32 2021 +0530
Branches: soc-2021-uv-edge-select-support
https://developer.blender.org/rBdbc41b30f88b96f7d8c6e995b17f5930eb55cc77

Merge branch 'master' into soc-2021-uv-edge-select-support

===



===

diff --cc source/blender/editors/uvedit/uvedit_intern.h
index 9bc8a165b1f,1fa96a932ed..0a0dd9a133b
--- a/source/blender/editors/uvedit/uvedit_intern.h
+++ b/source/blender/editors/uvedit/uvedit_intern.h
@@@ -92,9 -91,17 +92,18 @@@ bool uv_find_nearest_edge_multi(struct 
  struct Object **objects,
  const uint objects_len,
  const float co[2],
 +const float penalty,
  struct UvNearestHit *hit);
  
+ /**
+  * \param only_in_face: when true, only hit faces which `co` is inside.
+  * This gives users a result they might expect, especially when zoomed in.
+  *
+  * \note Concave faces can cause odd behavior, although in practice this 
isn't often an issue.
+  * The center can be outside the face, in this case the distance to the center
+  * could cause the face to be considered too far away.
+  * If this becomes an issue we could track the distance to the faces closest 
edge.
+  */
  bool uv_find_nearest_face_ex(struct Scene *scene,
   struct Object *obedit,
   const float co[2],

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [99a2af76d10] soc-2021-uv-edge-select-support: Merge branch 'master' into soc-2021-uv-edge-select-support

2021-11-19 Thread Siddhartha Jejurkar
Commit: 99a2af76d10e05a18987be5d554ada197b1ca086
Author: Siddhartha Jejurkar
Date:   Sat Nov 20 00:04:44 2021 +0530
Branches: soc-2021-uv-edge-select-support
https://developer.blender.org/rB99a2af76d10e05a18987be5d554ada197b1ca086

Merge branch 'master' into soc-2021-uv-edge-select-support

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [139606bd370] soc-2021-uv-edge-select-support: Code cleanup and minor fixes

2021-11-19 Thread Siddhartha Jejurkar
Commit: 139606bd370f96e0a8685547d515a2335591d5de
Author: Siddhartha Jejurkar
Date:   Fri Nov 19 23:54:27 2021 +0530
Branches: soc-2021-uv-edge-select-support
https://developer.blender.org/rB139606bd370f96e0a8685547d515a2335591d5de

Code cleanup and minor fixes

===

M   source/blender/editors/uvedit/uvedit_intern.h
M   source/blender/editors/uvedit/uvedit_select.c

===

diff --git a/source/blender/editors/uvedit/uvedit_intern.h 
b/source/blender/editors/uvedit/uvedit_intern.h
index 2d516e3f677..9bc8a165b1f 100644
--- a/source/blender/editors/uvedit/uvedit_intern.h
+++ b/source/blender/editors/uvedit/uvedit_intern.h
@@ -127,13 +127,13 @@ BMLoop *uv_find_nearest_loop_from_edge(struct Scene 
*scene,
 
 /* flush uv selection */
 void uv_flush_vert_to_edge(struct Scene *scene,
-   struct Object *obedit,
+   struct BMEditMesh *em,
const int cd_loop_uv_offset);
 void uv_flush_edge_to_vert(struct Scene *scene,
-   struct Object *obedit,
+   struct BMEditMesh *em,
const int cd_loop_uv_offset);
-void uv_flush_edge_to_vert_with_sticky_loc(Scene *scene,
-   Object *obedit,
+void uv_flush_edge_to_vert_with_sticky_loc(struct Scene *scene,
+   struct BMEditMesh *em,
const int cd_loop_uv_offset);
 
 /* utility tool functions */
diff --git a/source/blender/editors/uvedit/uvedit_select.c 
b/source/blender/editors/uvedit/uvedit_select.c
index 5b4a8d7393f..83e8259f693 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -93,9 +93,9 @@ static void uv_select_flush_from_tag_face(SpaceImage *sima,
   Scene *scene,
   Object *obedit,
   const bool select);
-static void uv_select_flush_from_tag_loop(SpaceImage *sima,
+static void uv_select_flush_from_tag_loop(const SpaceImage *sima,
   Scene *scene,
-  Object *obedit,
+  BMEditMesh *em,
   const bool select);
 static void uv_select_tag_update_for_object(Depsgraph *depsgraph,
 const ToolSettings *ts,
@@ -108,10 +108,6 @@ static bool uvedit_vert_is_any_other_face_selected(const 
Scene *scene,
BMLoop *l,
BMVert *v,
const int 
cd_loop_uv_offset);
-static bool uvedit_vert_is_any_other_not_face_selected(const Scene *scene,
-   BMLoop *l,
-   BMVert *v,
-   const int 
cd_loop_uv_offset);
 
 /*  */
 /** \name Active Selection Tracking
@@ -307,27 +303,25 @@ void uvedit_face_select_set_with_sticky(const SpaceImage 
*sima,
   if (uvedit_face_visible_test(scene, efa)) {
 /* Sticky location and vertex modes. */
 /* Fallback, in case sima->sticky is invalid */
-BMLoop *l_iter, *l_first;
-l_iter = l_first = BM_FACE_FIRST_LOOP(efa);
-do {
-  MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset);
+BMLoop *l;
+MLoopUV *luv;
+BMIter liter;
+
+BM_ITER_ELEM (l, , efa, BM_LOOPS_OF_FACE) {
+  luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
   if (select) {
-/* Set selection flag for only the internal edges of the face that 
is being selected */
 luv->flag |= MLOOPUV_EDGESEL;
-/* Select all shared vertices */
 uvedit_uv_select_shared_location(
-scene, em, l_iter, select, false, do_history, 
cd_loop_uv_offset);
+scene, em, l, select, false, do_history, cd_loop_uv_offset);
   }
   else {
 luv->flag &= ~MLOOPUV_EDGESEL;
-
-if (!uvedit_vert_is_any_other_face_selected(
-scene, l_iter, l_iter->v, cd_loop_uv_offset)) {
+if (!uvedit_vert_is_any_other_face_selected(scene, l, l->v, 
cd_loop_uv_offset)) {
   uvedit_uv_select_shared_location(
-  scene, em, l_iter, select, false, do_history, 
cd_loop_uv_offset);
+  scene, em, l, select, false, do_history, cd_loop_uv_offset);
 }
   }
-} while ((l_iter = l_ite

[Bf-blender-cvs] [4e6f73e5dfe] soc-2021-uv-edge-select-support: Merge branch 'master' into soc-2021-uv-edge-select-support

2021-11-03 Thread Siddhartha Jejurkar
Commit: 4e6f73e5dfe07ce87e7503fbb69c76922b94fe19
Author: Siddhartha Jejurkar
Date:   Wed Nov 3 17:16:00 2021 +0530
Branches: soc-2021-uv-edge-select-support
https://developer.blender.org/rB4e6f73e5dfe07ce87e7503fbb69c76922b94fe19

Merge branch 'master' into soc-2021-uv-edge-select-support

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [7f8f2ff1a89] soc-2021-uv-edge-select-support: Merge branch 'master' into soc-2021-uv-edge-select-support

2021-11-03 Thread Siddhartha Jejurkar
Commit: 7f8f2ff1a8926267113503813922d4556c8a4e4f
Author: Siddhartha Jejurkar
Date:   Mon Oct 4 16:37:02 2021 +0530
Branches: soc-2021-uv-edge-select-support
https://developer.blender.org/rB7f8f2ff1a8926267113503813922d4556c8a4e4f

Merge branch 'master' into soc-2021-uv-edge-select-support

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [52822b218df] soc-2021-uv-edge-select-support: Merge branch 'master' into soc-2021-uv-edge-select-support

2021-10-02 Thread Siddhartha Jejurkar
Commit: 52822b218dfdfe867f4da068655386673ba91236
Author: Siddhartha Jejurkar
Date:   Sat Oct 2 12:40:33 2021 +0530
Branches: soc-2021-uv-edge-select-support
https://developer.blender.org/rB52822b218dfdfe867f4da068655386673ba91236

Merge branch 'master' into soc-2021-uv-edge-select-support

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [a285299ebbf] master: UV: Pack to closest/active UDIM

2021-09-29 Thread Siddhartha Jejurkar
Commit: a285299ebbf9dcb6af5734d3933b4836d38c188f
Author: Siddhartha Jejurkar
Date:   Wed Sep 29 17:51:41 2021 +1000
Branches: master
https://developer.blender.org/rBa285299ebbf9dcb6af5734d3933b4836d38c188f

UV: Pack to closest/active UDIM

Implements T78397
Extends the functionality of pack islands operator to allow packing UVs
to either the closest or active UDIM tile.
This provides 2 new options for packing UVs :

* Closest UDIM: Selected UVs will be packed to the UDIM tile they were
  placed on. If not present on a valid UDIM tile, the UVs will be packed
  to the closest UDIM in UV space
* Active UDIM: Selected UVs will be packed to the active UDIM image tile
  In case, no image is present in the UV editor, then UVs will be packed
  to the tile on the UDIM grid where the 2D cursor is located.

Reviewed By: campbellbarton

Maniphest Tasks: T78397

Ref D12680

===

M   source/blender/editors/include/ED_uvedit.h
M   source/blender/editors/uvedit/uvedit_islands.c
M   source/blender/editors/uvedit/uvedit_unwrap_ops.c

===

diff --git a/source/blender/editors/include/ED_uvedit.h 
b/source/blender/editors/include/ED_uvedit.h
index ea3d921f2c5..516239a7176 100644
--- a/source/blender/editors/include/ED_uvedit.h
+++ b/source/blender/editors/include/ED_uvedit.h
@@ -246,9 +246,14 @@ struct UVPackIsland_Params {
   uint use_seams : 1;
   uint correct_aspect : 1;
 };
+
+bool uv_coords_isect_udim(const struct Image *image, const int udim_grid[2], 
float coords[2]);
 void ED_uvedit_pack_islands_multi(const struct Scene *scene,
+  const struct SpaceImage *sima,
   Object **objects,
   const uint objects_len,
+  const bool use_target_udim,
+  int target_udim,
   const struct UVPackIsland_Params *params);
 
 #ifdef __cplusplus
diff --git a/source/blender/editors/uvedit/uvedit_islands.c 
b/source/blender/editors/uvedit/uvedit_islands.c
index 56bcbc63de1..2aa09d7e731 100644
--- a/source/blender/editors/uvedit/uvedit_islands.c
+++ b/source/blender/editors/uvedit/uvedit_islands.c
@@ -29,6 +29,7 @@
 
 #include "DNA_meshdata_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_space_types.h"
 
 #include "BLI_boxpack_2d.h"
 #include "BLI_convexhull_2d.h"
@@ -38,6 +39,7 @@
 
 #include "BKE_customdata.h"
 #include "BKE_editmesh.h"
+#include "BKE_image.h"
 
 #include "DEG_depsgraph.h"
 
@@ -231,6 +233,99 @@ static void bm_face_array_uv_scale_y(BMFace **faces,
 
 /** \} */
 
+/*  */
+/** \name UDIM packing helper functions
+ * \{ */
+
+/* Returns true if UV coordinates lie on a valid tile in UDIM grid or tiled 
image. */
+bool uv_coords_isect_udim(const Image *image, const int udim_grid[2], float 
coords[2])
+{
+  const float coords_floor[2] = {floorf(coords[0]), floorf(coords[1])};
+  const bool is_tiled_image = image && (image->source == IMA_SRC_TILED);
+
+  if (coords[0] < udim_grid[0] && coords[0] > 0 && coords[1] < udim_grid[1] && 
coords[1] > 0) {
+return true;
+  }
+  /* Check if selection lies on a valid UDIM image tile. */
+  else if (is_tiled_image) {
+LISTBASE_FOREACH (const ImageTile *, tile, >tiles) {
+  const int tile_index = tile->tile_number - 1001;
+  const int target_x = (tile_index % 10);
+  const int target_y = (tile_index / 10);
+  if (coords_floor[0] == target_x && coords_floor[1] == target_y) {
+return true;
+  }
+}
+  }
+  /* Probably not required since UDIM grid checks for 1001. */
+  else if (image && !is_tiled_image) {
+if (is_zero_v2(coords_floor)) {
+  return true;
+}
+  }
+
+  return false;
+}
+
+/**
+ * Calculates distance to nearest UDIM image tile in UV space and its UDIM 
tile number.
+ */
+static float uv_nearest_image_tile_distance(const Image *image,
+float coords[2],
+float nearest_tile_co[2])
+{
+  int nearest_image_tile_index = BKE_image_find_nearest_tile(image, coords);
+  if (nearest_image_tile_index == -1) {
+nearest_image_tile_index = 1001;
+  }
+
+  nearest_tile_co[0] = (nearest_image_tile_index - 1001) % 10;
+  nearest_tile_co[1] = (nearest_image_tile_index - 1001) / 10;
+  /* Add 0.5 to get tile center coordinates. */
+  float nearest_tile_center_co[2] = {nearest_tile_co[0], nearest_tile_co[1]};
+  add_v2_fl(nearest_tile_center_co, 0.5f);
+
+  return len_squared_v2v2(coords, nearest_tile_center_co);
+}
+
+/**
+ * Calculates distance to nearest UDIM grid tile in UV space

[Bf-blender-cvs] [bf06f76be63] master: UV Editor: Grid and snapping improvements

2021-09-29 Thread Siddhartha Jejurkar
Commit: bf06f76be6316be92a4655a41391e163d2fb1221
Author: Siddhartha Jejurkar
Date:   Wed Sep 29 17:47:32 2021 +1000
Branches: master
https://developer.blender.org/rBbf06f76be6316be92a4655a41391e163d2fb1221

UV Editor: Grid and snapping improvements

Implements T89789, T89792, custom grid (described as dynamic grid in
T78389) and UV grid snapping (T78391)
Replaces the default UV editor grid with 2 new types of grid :

* Custom grid: Allows the user to create an NxN grid, where the value
  of N is specified by the user.
* Subdividing grid: Subdivides the UV editor grid when the user
  zooms in the viewport and vice versa when zooming out.

UV snapping improvements :
* Increment snapping: Increment values for snapping are calculated based
  on which grid type is being used in the UV editor
  (subdividing or custom). In general the increment value is equal to
  the distance between 2 visible grid lines.
* Absolute grid snap: New toggle added to increment snapping option in
  the UV editor, allows UV grid snapping during translation.

Reviewed By: campbellbarton

Ref D12684

===

M   release/scripts/startup/bl_ui/space_image.py
M   source/blender/blenkernel/BKE_blender_version.h
M   source/blender/blenloader/intern/versioning_280.c
M   source/blender/blenloader/intern/versioning_300.c
M   source/blender/draw/engines/overlay/overlay_grid.c
M   source/blender/draw/engines/overlay/overlay_private.h
M   source/blender/draw/engines/overlay/shaders/grid_frag.glsl
M   source/blender/editors/include/ED_image.h
M   source/blender/editors/space_image/image_draw.c
M   source/blender/editors/space_image/space_image.c
M   source/blender/editors/transform/transform.c
M   source/blender/editors/transform/transform_snap.c
M   source/blender/makesdna/DNA_scene_types.h
M   source/blender/makesdna/DNA_space_types.h
M   source/blender/makesrna/intern/rna_scene.c
M   source/blender/makesrna/intern/rna_space.c
M   source/blender/nodes/composite/nodes/node_composite_gamma.cc

===

diff --git a/release/scripts/startup/bl_ui/space_image.py 
b/release/scripts/startup/bl_ui/space_image.py
index 3ee66f3..797d0c62b72 100644
--- a/release/scripts/startup/bl_ui/space_image.py
+++ b/release/scripts/startup/bl_ui/space_image.py
@@ -934,6 +934,10 @@ class IMAGE_PT_snapping(Panel):
 row = col.row(align=True)
 row.prop(tool_settings, "snap_target", expand=True)
 
+col.separator()
+if 'INCREMENT' in tool_settings.snap_uv_element:
+col.prop(tool_settings, "use_snap_uv_grid_absolute")
+
 col.label(text="Affect")
 row = col.row(align=True)
 row.prop(tool_settings, "use_snap_translate", text="Move", toggle=True)
@@ -1467,6 +1471,33 @@ class IMAGE_PT_udim_grid(Panel):
 col = layout.column()
 col.prop(uvedit, "tile_grid_shape", text="Grid Shape")
 
+class IMAGE_PT_custom_grid(Panel):
+bl_space_type = 'IMAGE_EDITOR'
+bl_region_type = 'UI'
+bl_category = "View"
+bl_label = "Custom Grid"
+
+@classmethod
+def poll(cls, context):
+sima = context.space_data
+return sima.show_uvedit
+
+def draw_header(self, context):
+sima = context.space_data
+uvedit = sima.uv_editor
+self.layout.prop(uvedit, "use_custom_grid", text="")
+
+def draw(self, context):
+layout = self.layout
+
+sima = context.space_data
+uvedit = sima.uv_editor
+
+layout.use_property_split = True
+layout.use_property_decorate = False
+
+col = layout.column()
+col.prop(uvedit, "custom_grid_subdivisions", text="Subdivisions")
 
 class IMAGE_PT_overlay(Panel):
 bl_space_type = 'IMAGE_EDITOR'
@@ -1652,6 +1683,7 @@ classes = (
 IMAGE_PT_uv_cursor,
 IMAGE_PT_annotation,
 IMAGE_PT_udim_grid,
+IMAGE_PT_custom_grid,
 IMAGE_PT_overlay,
 IMAGE_PT_overlay_uv_edit,
 IMAGE_PT_overlay_uv_edit_geometry,
diff --git a/source/blender/blenkernel/BKE_blender_version.h 
b/source/blender/blenkernel/BKE_blender_version.h
index 5ef0459663b..65f9da3b852 100644
--- a/source/blender/blenkernel/BKE_blender_version.h
+++ b/source/blender/blenkernel/BKE_blender_version.h
@@ -39,7 +39,7 @@ extern "C" {
 
 /* Blender file format version. */
 #define BLENDER_FILE_VERSION BLENDER_VERSION
-#define BLENDER_FILE_SUBVERSION 28
+#define BLENDER_FILE_SUBVERSION 29
 
 /* Minimum Blender version that supports reading file written with the current
  * version. Older Blender versions will test this and show a warning if the 
file
diff --git a/source/blender/blenloader/intern/versioning_280.c 
b/source/blender/blenloader/intern/versioning_280.c
index 292

[Bf-blender-cvs] [560e015a5b3] soc-2021-uv-editor-improvements: Fix and cleanup: Pack to correct/Specified UDIM

2021-09-25 Thread Siddhartha Jejurkar
Commit: 560e015a5b36a953e160dd2dd3a9c32ab74637c1
Author: Siddhartha Jejurkar
Date:   Sun Sep 26 00:40:51 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB560e015a5b36a953e160dd2dd3a9c32ab74637c1

Fix and cleanup: Pack to correct/Specified UDIM

After recent changes made in master branch, it is now possible to display
UDIM grid and tiled images simultaneously in the UV Editor.
This commit updates the pack islands to correct/specified UDIM
implementation to work with the new behavior. Also includes some code
and comment cleanups.

===

M   source/blender/editors/include/ED_uvedit.h
M   source/blender/editors/uvedit/uvedit_islands.c
M   source/blender/editors/uvedit/uvedit_unwrap_ops.c
M   source/blender/makesdna/DNA_scene_types.h

===

diff --git a/source/blender/editors/include/ED_uvedit.h 
b/source/blender/editors/include/ED_uvedit.h
index 269590197ee..cd89620fe64 100644
--- a/source/blender/editors/include/ED_uvedit.h
+++ b/source/blender/editors/include/ED_uvedit.h
@@ -247,10 +247,11 @@ struct UVPackIsland_Params {
   uint correct_aspect : 1;
 };
 void ED_uvedit_pack_islands_multi(const struct Scene *scene,
+  const struct SpaceImage *sima,
   Object **objects,
   const uint objects_len,
-  const struct SpaceImage *sima,
-  bool use_target,
+  const bool use_target_udim,
+  int target_udim,
   const struct UVPackIsland_Params *params);
 
 bool ED_uvedit_pack_islands_to_area_multi(const struct Scene *scene,
diff --git a/source/blender/editors/uvedit/uvedit_islands.c 
b/source/blender/editors/uvedit/uvedit_islands.c
index ef990080ec1..370e0176298 100644
--- a/source/blender/editors/uvedit/uvedit_islands.c
+++ b/source/blender/editors/uvedit/uvedit_islands.c
@@ -359,10 +359,11 @@ static int bm_mesh_calc_uv_islands(const Scene *scene,
  * \{ */
 
 void ED_uvedit_pack_islands_multi(const Scene *scene,
+  const SpaceImage *sima,
   Object **objects,
   const uint objects_len,
-  const SpaceImage *sima,
-  bool use_target,
+  const bool use_target_udim,
+  int target_udim,
   const struct UVPackIsland_Params *params)
 {
   /* Align to the Y axis, could make this configurable. */
@@ -370,18 +371,6 @@ void ED_uvedit_pack_islands_multi(const Scene *scene,
   ListBase island_list = {NULL};
   int island_list_len = 0;
 
-  const Image *image;
-  bool is_tiled_image = false;
-  int udim_grid[2] = {1, 1};
-
-  /* To handle cases where sima=NULL - Smart UV project */
-  if (sima) {
-image = sima->image;
-is_tiled_image = image && (image->source == IMA_SRC_TILED);
-udim_grid[0] = sima->tile_grid_shape[0];
-udim_grid[1] = sima->tile_grid_shape[1];
-  }
-
   for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
 Object *obedit = objects[ob_index];
 BMEditMesh *em = BKE_editmesh_from_object(obedit);
@@ -423,26 +412,25 @@ void ED_uvedit_pack_islands_multi(const Scene *scene,
   BoxPack *boxarray = MEM_mallocN(sizeof(*boxarray) * island_list_len, 
__func__);
 
   int index;
-  /* Coordinates for the center of the all the selected islands */
-  float selection_center[2] = {0.0f, 0.0f};
-  float selection_min[2], selection_max[2];
-  INIT_MINMAX2(selection_min, selection_max);
+  float selection_min_co[2], selection_max_co[2];
+  INIT_MINMAX2(selection_min_co, selection_max_co);
 
   LISTBASE_FOREACH_INDEX (struct FaceIsland *, island, _list, index) {
 
-/* Calculate bounding box of all selected islands */
-float bounds_min[2], bounds_max[2];
-INIT_MINMAX2(bounds_min, bounds_max);
-for (int i = 0; i < island->faces_len; i++) {
-  BMFace *f = island->faces[i];
-  BM_face_uv_minmax(f, bounds_min, bounds_max, island->cd_loop_uv_offset);
-}
-
-selection_min[0] = MIN2(bounds_min[0], selection_min[0]);
-selection_min[1] = MIN2(bounds_min[1], selection_min[1]);
-selection_max[0] = MAX2(bounds_max[0], selection_max[0]);
-selection_max[1] = MAX2(bounds_max[1], selection_max[1]);
+/* Skip calculation if not using Specified UDIM option */
+if (!use_target_udim) {
+  float bounds_min[2], bounds_max[2];
+  INIT_MINMAX2(bounds_min, bounds_max);
+  for (int i = 0; i < island->faces_len; i++) {
+BMFace *f = island->faces[i];
+BM_face_uv_minmax(f, bounds_min, bounds_max, 
island->cd_loop_uv_offset);
+  }

[Bf-blender-cvs] [f87ed1547c2] soc-2021-uv-editor-improvements: UV grid: Resolve merge conflicts

2021-09-22 Thread Siddhartha Jejurkar
Commit: f87ed1547c22c4b120399e29a6729136618b08ae
Author: Siddhartha Jejurkar
Date:   Wed Sep 22 23:08:30 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rBf87ed1547c22c4b120399e29a6729136618b08ae

UV grid: Resolve merge conflicts

Resolves merge conflicts that broke the subdividing and dynamic grid
implementations

===

M   source/blender/draw/engines/overlay/overlay_grid.c

===

diff --git a/source/blender/draw/engines/overlay/overlay_grid.c 
b/source/blender/draw/engines/overlay/overlay_grid.c
index e3e3c23d347..cb691afc1d5 100644
--- a/source/blender/draw/engines/overlay/overlay_grid.c
+++ b/source/blender/draw/engines/overlay/overlay_grid.c
@@ -63,6 +63,7 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata)
 
   if (pd->space_type == SPACE_IMAGE) {
 SpaceImage *sima = (SpaceImage *)draw_ctx->space_data;
+View2D *v2d = _ctx->region->v2d;
 if (sima->mode == SI_MODE_UV || !ED_space_image_has_buffer(sima)) {
   shd->grid_flag = GRID_BACK | PLANE_IMAGE | SHOW_GRID;
 }
@@ -76,8 +77,22 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata)
   shd->grid_size[0] = (float)sima->tile_grid_shape[0];
   shd->grid_size[1] = (float)sima->tile_grid_shape[1];
 }
-for (int step = 0; step < 8; step++) {
-  shd->grid_steps[step] = powf(4, step) * (1.0f / 16.0f);
+/**
+ * Previously the UV/Image Editor grid was static :
+ * - 0-1 UV space divided into 4x4 divisions marked by thick grid lines (1 
grid unit = 0.25 UV
+ *   units)
+ * - 0-1 UV space divided into 16x16 divisions marked by thin grid lines 
(1 grid unit = 0.0625
+ *   UV units)
+ *
+ * The new UV/Image Editor grid now supports 2 grid types :
+ * - Subdividing grid : Similar to the 3D viewport grid (zooming in adds 
more divisions to the
+ *   grid) [T89789]
+ * - Dynamic grid : Users create a desired NxN grid by using options 
exposed in UI [T78389]
+ */
+if (sima->flag & SI_DYNAMIC_GRID) {
+  shd->grid_flag |= DYNAMIC_GRID;
+  /* Temporary fix : dynamic_grid_size is not using the default value (=1) 
assignd in RNA */
+  sima->dynamic_grid_size = (sima->dynamic_grid_size == 0) ? 1 : 
sima->dynamic_grid_size;
 }
 /* N denotes the grid dimension when zoomed out (NxN grid).
  * While zooming in, each grid division further subdivides into smaller 
NxN divisions

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [1b9dd08d028] soc-2021-uv-editor-improvements: Merge branch 'master' into soc-2021-uv-editor-improvements

2021-09-22 Thread Siddhartha Jejurkar
Commit: 1b9dd08d0281f00ba96b2e6b74c7c9b662663c1b
Author: Siddhartha Jejurkar
Date:   Wed Sep 22 21:07:15 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB1b9dd08d0281f00ba96b2e6b74c7c9b662663c1b

Merge branch 'master' into soc-2021-uv-editor-improvements

===



===

diff --cc source/blender/draw/engines/overlay/overlay_grid.c
index 9d0f03b0cfe,60cda9f2d61..e3e3c23d347
--- a/source/blender/draw/engines/overlay/overlay_grid.c
+++ b/source/blender/draw/engines/overlay/overlay_grid.c
@@@ -63,40 -61,22 +63,31 @@@ void OVERLAY_grid_init(OVERLAY_Data *ve
  
if (pd->space_type == SPACE_IMAGE) {
  SpaceImage *sima = (SpaceImage *)draw_ctx->space_data;
- View2D *v2d = _ctx->region->v2d;
+ if (sima->mode == SI_MODE_UV || !ED_space_image_has_buffer(sima)) {
+   shd->grid_flag = GRID_BACK | PLANE_IMAGE | SHOW_GRID;
+ }
+ else {
+   shd->grid_flag = 0;
+ }
  
- shd->grid_flag = ED_space_image_has_buffer(sima) ? 0 : PLANE_IMAGE | 
SHOW_GRID;
  shd->grid_distance = 1.0f;
- copy_v3_fl3(
- shd->grid_size, (float)sima->tile_grid_shape[0], 
(float)sima->tile_grid_shape[1], 1.0f);
- 
- /**
-  * Previously the UV/Image Editor grid was static :
-  * - 0-1 UV space divided into 4x4 divisions marked by thick grid lines 
(1 grid unit = 0.25 UV
-  *   units)
-  * - 0-1 UV space divided into 16x16 divisions marked by thin grid lines 
(1 grid unit = 0.0625
-  *   UV units)
-  *
-  * The new UV/Image Editor grid now supports 2 grid types :
-  * - Subdividing grid : Similar to the 3D viewport grid (zooming in adds 
more divisions to the
-  *   grid) [T89789]
-  * - Dynamic grid : Users create a desired NxN grid by using options 
exposed in UI [T78389]
-  */
- 
- if (sima->flag & SI_DYNAMIC_GRID) {
-   shd->grid_flag |= DYNAMIC_GRID;
-   /* Temporary fix : dynamic_grid_size is not using the default value 
(=1) assignd in RNA */
-   sima->dynamic_grid_size = (sima->dynamic_grid_size == 0) ? 1 : 
sima->dynamic_grid_size;
+ copy_v3_fl3(shd->grid_size, 1.0f, 1.0f, 1.0f);
+ if (sima->mode == SI_MODE_UV) {
+   shd->grid_size[0] = (float)sima->tile_grid_shape[0];
+   shd->grid_size[1] = (float)sima->tile_grid_shape[1];
+ }
+ for (int step = 0; step < 8; step++) {
+   shd->grid_steps[step] = powf(4, step) * (1.0f / 16.0f);
  }
 +/* N denotes the grid dimension when zoomed out (NxN grid).
 + * While zooming in, each grid division further subdivides into smaller 
NxN divisions
 + *
 + * If this value is changed, then also update the value in 
initSnapSpatial()
 + * TODO? : Probably best to move this value to SpaceImage/View2D struct */
 +int N = 8;
 +shd->zoom_factor = ED_space_image_zoom_level(v2d, N);
 +
 +ED_space_image_grid_steps(sima, shd->grid_steps, N);
  return;
}

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [90707ca72f8] soc-2021-uv-edge-select-support: Merge branch 'master' into soc-2021-uv-edge-select-support

2021-09-22 Thread Siddhartha Jejurkar
Commit: 90707ca72f84821b8797edefb2ae5f357564d7b3
Author: Siddhartha Jejurkar
Date:   Wed Sep 22 18:51:28 2021 +0530
Branches: soc-2021-uv-edge-select-support
https://developer.blender.org/rB90707ca72f84821b8797edefb2ae5f357564d7b3

Merge branch 'master' into soc-2021-uv-edge-select-support

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [29deaaee007] soc-2021-uv-edge-select-support: Fix: Deselecting edges in sticky vertex mode

2021-09-11 Thread Siddhartha Jejurkar
Commit: 29deaaee007faaa9a42a73d29dc1b15f330e745b
Author: Siddhartha Jejurkar
Date:   Sat Sep 11 15:25:40 2021 +0530
Branches: soc-2021-uv-edge-select-support
https://developer.blender.org/rB29deaaee007faaa9a42a73d29dc1b15f330e745b

Fix: Deselecting edges in sticky vertex mode

Fixes the bug where deselecting an UV edge in sticky vertex mode would
deselect the UV vertices as well.

===

M   source/blender/editors/uvedit/uvedit_select.c

===

diff --git a/source/blender/editors/uvedit/uvedit_select.c 
b/source/blender/editors/uvedit/uvedit_select.c
index 98fa6753b61..14480acff9f 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -457,12 +457,24 @@ void uvedit_edge_select_set_with_sticky(const struct 
SpaceImage *sima,
 if (uvedit_face_visible_test(scene, l_radial_iter->f)) {
   uvedit_edge_select_set(scene, em, l_radial_iter, select, do_history, 
cd_loop_uv_offset);
 
-  uvedit_uv_select_shared_location(
-  scene, em, l_radial_iter, select, false, do_history, 
cd_loop_uv_offset);
-  uvedit_uv_select_shared_location(
-  scene, em, l_radial_iter->next, select, false, do_history, 
cd_loop_uv_offset);
+  if (select) {
+uvedit_uv_select_shared_location(
+scene, em, l_radial_iter, select, false, do_history, 
cd_loop_uv_offset);
+uvedit_uv_select_shared_location(
+scene, em, l_radial_iter->next, select, false, do_history, 
cd_loop_uv_offset);
+  }
+  else {
+if (!uvedit_vert_is_any_other_edge_selected(scene, l_radial_iter, 
cd_loop_uv_offset)) {
+  uvedit_uv_select_shared_location(
+  scene, em, l_radial_iter, select, false, do_history, 
cd_loop_uv_offset);
+}
+if (!uvedit_vert_is_any_other_edge_selected(
+scene, l_radial_iter->next, cd_loop_uv_offset)) {
+  uvedit_uv_select_shared_location(
+  scene, em, l_radial_iter->next, select, false, do_history, 
cd_loop_uv_offset);
+}
+  }
 }
-
   } while ((l_radial_iter = l_radial_iter->radial_next) != l);
   break;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [fdc93183600] soc-2021-uv-edge-select-support: UV: Drawing selected edges

2021-09-10 Thread Siddhartha Jejurkar
Commit: fdc931836004b2d8df6870be470e4b8d4596c4ca
Author: Siddhartha Jejurkar
Date:   Fri Sep 10 14:55:02 2021 +0530
Branches: soc-2021-uv-edge-select-support
https://developer.blender.org/rBfdc931836004b2d8df6870be470e4b8d4596c4ca

UV: Drawing selected edges

* Changes vertex count for UV edge polygon from 4 to 6 in the geometry
  shader
* Edge center for a selected edge will not be highlighted if the edge is
  not selected. This new behavior provides a visual aid to the user that
  helps in identifying selected and unselected UV edges

===

M   source/blender/draw/engines/overlay/shaders/edit_uv_edges_geom.glsl
M   source/blender/draw/engines/overlay/shaders/edit_uv_edges_vert.glsl

===

diff --git 
a/source/blender/draw/engines/overlay/shaders/edit_uv_edges_geom.glsl 
b/source/blender/draw/engines/overlay/shaders/edit_uv_edges_geom.glsl
index 4f8d553a220..2b4ddaa52f3 100644
--- a/source/blender/draw/engines/overlay/shaders/edit_uv_edges_geom.glsl
+++ b/source/blender/draw/engines/overlay/shaders/edit_uv_edges_geom.glsl
@@ -2,9 +2,10 @@
 #pragma BLENDER_REQUIRE(common_overlay_lib.glsl)
 
 layout(lines) in;
-layout(triangle_strip, max_vertices = 4) out;
+layout(triangle_strip, max_vertices = 6) out;
 
 in float selectionFac[2];
+in float edgeSelectionFac[2];
 flat in vec2 stippleStart[2];
 noperspective in vec2 stipplePos[2];
 
@@ -35,6 +36,12 @@ void main()
   vec2 ss_pos[2];
   vec4 pos0 = gl_in[0].gl_Position;
   vec4 pos1 = gl_in[1].gl_Position;
+  /* TODO(verify): Calculating edge-center in clip space might cause errors 
due to precision loss?? */
+  vec4 edgeCenter = (pos0 + pos1) / 2.0;
+  bool is_edge_selected = edgeSelectionFac[0] == 1.0;
+  /* Depth value as specified in vertex shader */
+  edgeCenter.z = is_edge_selected ? 0.25 : 0.35;
+
   ss_pos[0] = pos0.xy / pos0.w;
   ss_pos[1] = pos1.xy / pos1.w;
 
@@ -54,8 +61,14 @@ void main()
   vec2 line_perp = vec2(-line_dir.y, line_dir.x);
   vec2 edge_ofs = line_perp * sizeViewportInv * ceil(half_size);
 
+  vec2 stippleStartCenter, stipplePosCenter;
+  /* TODO(stipple pattern): Probable incorrect implementation - used as 
specified in vertex shader */
+  stippleStartCenter = stipplePosCenter = 500.0 + 500.0 * (edgeCenter.xy / 
edgeCenter.w);
+
   do_vertex(pos0, selectionFac[0], stippleStart[0], stipplePos[0], half_size, 
edge_ofs.xy);
   do_vertex(pos0, selectionFac[0], stippleStart[0], stipplePos[0], -half_size, 
-edge_ofs.xy);
+  do_vertex(edgeCenter, edgeSelectionFac[0], stippleStartCenter, 
stipplePosCenter, half_size, edge_ofs.xy);
+  do_vertex(edgeCenter, edgeSelectionFac[0], stippleStartCenter, 
stipplePosCenter, -half_size, -edge_ofs.xy);
   do_vertex(pos1, selectionFac[1], stippleStart[1], stipplePos[1], half_size, 
edge_ofs.xy);
   do_vertex(pos1, selectionFac[1], stippleStart[1], stipplePos[1], -half_size, 
-edge_ofs.xy);
 
diff --git 
a/source/blender/draw/engines/overlay/shaders/edit_uv_edges_vert.glsl 
b/source/blender/draw/engines/overlay/shaders/edit_uv_edges_vert.glsl
index 7627a287a05..3b00fd7aafe 100644
--- a/source/blender/draw/engines/overlay/shaders/edit_uv_edges_vert.glsl
+++ b/source/blender/draw/engines/overlay/shaders/edit_uv_edges_vert.glsl
@@ -6,6 +6,7 @@ in vec2 au;
 in int flag;
 
 out float selectionFac;
+out float edgeSelectionFac;
 noperspective out vec2 stipplePos;
 flat out vec2 stippleStart;
 
@@ -20,7 +21,9 @@ void main()
half_pixel_offset;
 
   bool is_select = (flag & VERT_UV_SELECT) != 0;
+  bool is_edge_selected = (flag & EDGE_UV_SELECT) != 0;
   selectionFac = is_select ? 1.0 : 0.0;
+  edgeSelectionFac = is_edge_selected ? 1.0 : 0.0;
   /* Move selected edges to the top
* Vertices are between 0.0 and 0.2, Edges between 0.2 and 0.4
* actual pixels are at 0.75, 1.0 is used for the background. */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [64d640d196a] soc-2021-uv-edge-select-support: Merge branch 'master' into soc-2021-uv-edge-select-support

2021-08-26 Thread Siddhartha Jejurkar
Commit: 64d640d196a08546b123c7eb87f7f1e16a6a25e4
Author: Siddhartha Jejurkar
Date:   Fri Aug 27 09:18:46 2021 +0530
Branches: soc-2021-uv-edge-select-support
https://developer.blender.org/rB64d640d196a08546b123c7eb87f7f1e16a6a25e4

Merge branch 'master' into soc-2021-uv-edge-select-support

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [2766e00ecfc] soc-2021-uv-edge-select-support: Merge branch 'master' into soc-2021-uv-edge-select-support

2021-08-15 Thread Siddhartha Jejurkar
Commit: 2766e00ecfcca78d1a9fc2982cc3846b8e741e09
Author: Siddhartha Jejurkar
Date:   Mon Aug 16 10:38:50 2021 +0530
Branches: soc-2021-uv-edge-select-support
https://developer.blender.org/rB2766e00ecfcca78d1a9fc2982cc3846b8e741e09

Merge branch 'master' into soc-2021-uv-edge-select-support

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [0c2bc843f50] soc-2021-uv-editor-improvements: Merge branch 'master' into soc-2021-uv-editor-improvements

2021-08-15 Thread Siddhartha Jejurkar
Commit: 0c2bc843f500cc0bc9511b5ca68ab61a8922ce9b
Author: Siddhartha Jejurkar
Date:   Mon Aug 16 10:34:46 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB0c2bc843f500cc0bc9511b5ca68ab61a8922ce9b

Merge branch 'master' into soc-2021-uv-editor-improvements

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [98deceb5c19] soc-2021-uv-editor-improvements: Cleanup and fix: Dynamic grid and offset operator

2021-08-15 Thread Siddhartha Jejurkar
Commit: 98deceb5c195444e26d69f784471fc7e721080d5
Author: Siddhartha Jejurkar
Date:   Mon Aug 16 10:04:49 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB98deceb5c195444e26d69f784471fc7e721080d5

Cleanup and fix: Dynamic grid and offset operator

* Minor fix for dynamic grid
* Cleanup UV offset operator

===

M   source/blender/editors/space_image/image_draw.c
M   source/blender/editors/uvedit/uvedit_ops.c

===

diff --git a/source/blender/editors/space_image/image_draw.c 
b/source/blender/editors/space_image/image_draw.c
index 4cd891f7c34..1b40959cf4b 100644
--- a/source/blender/editors/space_image/image_draw.c
+++ b/source/blender/editors/space_image/image_draw.c
@@ -595,7 +595,7 @@ void ED_space_image_grid_steps(SpaceImage *sima, float 
grid_steps[8], const int
 {
   if (sima->flag & SI_DYNAMIC_GRID) {
 for (int step = 0; step < 8; step++) {
-  grid_steps[step] = powf(1, step) * (1.0f / ((float)grid_dimension));
+  grid_steps[step] = powf(1, step) * (1.0f / 
((float)sima->dynamic_grid_size));
 }
   }
   else {
diff --git a/source/blender/editors/uvedit/uvedit_ops.c 
b/source/blender/editors/uvedit/uvedit_ops.c
index 6f308d32d86..6a74c22c4f7 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -1342,7 +1342,8 @@ static void UV_OT_snap_selected(wmOperatorType *ot)
 /** \name UV offset Operator
  * \{ */
 
-/* Pixel offset (defined in T78405) is currently not implemented in the 
operator */
+/* Since pixel resolution is not implemented yet (refer T78405), pixel offset 
is not implemented in
+ * this operator */
 enum {
   UDIM_OFFSET_UP = 0,
   UDIM_OFFSET_DOWN,
@@ -1354,18 +1355,10 @@ enum {
   DYNAMIC_GRID_OFFSET_RIGHT,
 };
 
-static int uv_offset_exec(bContext *C, wmOperator *op)
+static void uv_calc_offset(const SpaceImage *sima, const int offset_direction, 
float uv_offset[2])
 {
-  Scene *scene = CTX_data_scene(C);
-  ViewLayer *view_layer = CTX_data_view_layer(C);
-  const SpaceImage *sima = CTX_wm_space_image(C);
-  const ToolSettings *ts = scene->toolsettings;
-  // const bool synced_selection = (ts->uv_flag & UV_SYNC_SELECTION) != 0;
-  int dynamic_grid_size = (sima->flag & SI_DYNAMIC_GRID) ? 
sima->dynamic_grid_size : 0;
-
-  const int offset_direction = RNA_enum_get(op->ptr, "offset_direction");
-  float uv_offset[2] = {0.0f, 0.0f};
-
+  const bool is_dynamic_grid = sima->flag & SI_DYNAMIC_GRID;
+  zero_v2(uv_offset);
   /* Assign offset based on the keymap input */
   switch (offset_direction) {
 case UDIM_OFFSET_UP: {
@@ -1385,46 +1378,48 @@ static int uv_offset_exec(bContext *C, wmOperator *op)
   break;
 }
 case DYNAMIC_GRID_OFFSET_UP: {
-  if (dynamic_grid_size) {
-uv_offset[1] = 1.0f / ((float)dynamic_grid_size);
-  }
-  else { /* Dynamic Grid not in use */
-return OPERATOR_CANCELLED;
+  if (is_dynamic_grid) {
+uv_offset[1] = 1.0f / ((float)sima->dynamic_grid_size);
   }
   break;
 }
 case DYNAMIC_GRID_OFFSET_DOWN: {
-  if (dynamic_grid_size) {
-uv_offset[1] = (-1.0f) / ((float)dynamic_grid_size);
-  }
-  else { /* Dynamic Grid not in use */
-return OPERATOR_CANCELLED;
+  if (is_dynamic_grid) {
+uv_offset[1] = (-1.0f) / ((float)sima->dynamic_grid_size);
   }
   break;
 }
 case DYNAMIC_GRID_OFFSET_RIGHT: {
-  if (dynamic_grid_size) {
-uv_offset[0] = 1.0f / ((float)dynamic_grid_size);
-  }
-  else { /* Dynamic Grid not in use */
-return OPERATOR_CANCELLED;
+  if (is_dynamic_grid) {
+uv_offset[0] = 1.0f / ((float)sima->dynamic_grid_size);
   }
   break;
 }
 case DYNAMIC_GRID_OFFSET_LEFT: {
-  if (dynamic_grid_size) {
-uv_offset[0] = (-1.0f) / ((float)dynamic_grid_size);
-  }
-  else { /* Dynamic Grid not in use */
-return OPERATOR_CANCELLED;
+  if (is_dynamic_grid) {
+uv_offset[0] = (-1.0f) / ((float)sima->dynamic_grid_size);
   }
   break;
 }
 default: {
-  /* No valid use case */
-  return OPERATOR_CANCELLED;
+  /* Pass */
 }
   }
+}
+
+static int uv_offset_exec(bContext *C, wmOperator *op)
+{
+  Scene *scene = CTX_data_scene(C);
+  ViewLayer *view_layer = CTX_data_view_layer(C);
+  const SpaceImage *sima = CTX_wm_space_image(C);
+  const ToolSettings *ts = scene->toolsettings;
+  const int offset_direction = RNA_enum_get(op->ptr, "offset_direction");
+  float uv_offset[2] = {0.0f, 0.0f};
+
+  uv_calc_offset(sima, offset_direction, uv_offset);
+  if (is_zero_v2(uv_offset)) {
+return OPERATOR_CANCELLED;
+  }
 
   BMFace *efa;
   BMLoop *l;
@@ -1438,6 +1433,7 @@ static int uv_offset_exec(bContext *C, wmOperator 

[Bf-blender-cvs] [da8963af2dd] soc-2021-uv-editor-improvements: Cleanup and fixes: UV grid types

2021-08-15 Thread Siddhartha Jejurkar
Commit: da8963af2dd49201fb214a6e91ea2e251a74257e
Author: Siddhartha Jejurkar
Date:   Mon Aug 16 06:44:00 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rBda8963af2dd49201fb214a6e91ea2e251a74257e

Cleanup and fixes: UV grid types

* Code and comment cleanup
* Refactor subdividing grid code to allow creating grid of different
  dimensions different from the previous 4x4 grid
* Change subdividing grid dimensions to start from 8x8
* Refactor code used to calculate increment snapping value for the UV
  editor

===

M   source/blender/draw/engines/overlay/overlay_grid.c
M   source/blender/draw/engines/overlay/overlay_private.h
M   source/blender/draw/engines/overlay/shaders/grid_frag.glsl
M   source/blender/editors/include/ED_image.h
M   source/blender/editors/space_image/image_draw.c
M   source/blender/editors/transform/transform.c
M   source/blender/makesdna/DNA_space_types.h

===

diff --git a/source/blender/draw/engines/overlay/overlay_grid.c 
b/source/blender/draw/engines/overlay/overlay_grid.c
index 3077ddd4ee3..9d0f03b0cfe 100644
--- a/source/blender/draw/engines/overlay/overlay_grid.c
+++ b/source/blender/draw/engines/overlay/overlay_grid.c
@@ -70,19 +70,33 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata)
 copy_v3_fl3(
 shd->grid_size, (float)sima->tile_grid_shape[0], 
(float)sima->tile_grid_shape[1], 1.0f);
 
-/* For a NxN grid. Keep insync with value in initSnapSpatial() inside 
transform.c */
-int N = 4;
-shd->zoom_factor = ED_space_image_zoom_level(v2d, N);
+/**
+ * Previously the UV/Image Editor grid was static :
+ * - 0-1 UV space divided into 4x4 divisions marked by thick grid lines (1 
grid unit = 0.25 UV
+ *   units)
+ * - 0-1 UV space divided into 16x16 divisions marked by thin grid lines 
(1 grid unit = 0.0625
+ *   UV units)
+ *
+ * The new UV/Image Editor grid now supports 2 grid types :
+ * - Subdividing grid : Similar to the 3D viewport grid (zooming in adds 
more divisions to the
+ *   grid) [T89789]
+ * - Dynamic grid : Users create a desired NxN grid by using options 
exposed in UI [T78389]
+ */
 
 if (sima->flag & SI_DYNAMIC_GRID) {
   shd->grid_flag |= DYNAMIC_GRID;
   /* Temporary fix : dynamic_grid_size is not using the default value (=1) 
assignd in RNA */
   sima->dynamic_grid_size = (sima->dynamic_grid_size == 0) ? 1 : 
sima->dynamic_grid_size;
-  ED_space_image_grid_steps(sima->dynamic_grid_size, shd->grid_steps, 
true);
-}
-else {
-  ED_space_image_grid_steps(N, shd->grid_steps, false);
 }
+/* N denotes the grid dimension when zoomed out (NxN grid).
+ * While zooming in, each grid division further subdivides into smaller 
NxN divisions
+ *
+ * If this value is changed, then also update the value in 
initSnapSpatial()
+ * TODO? : Probably best to move this value to SpaceImage/View2D struct */
+int N = 8;
+shd->zoom_factor = ED_space_image_zoom_level(v2d, N);
+
+ED_space_image_grid_steps(sima, shd->grid_steps, N);
 return;
   }
 
diff --git a/source/blender/draw/engines/overlay/overlay_private.h 
b/source/blender/draw/engines/overlay/overlay_private.h
index 873cbf088a4..6dea1984ff6 100644
--- a/source/blender/draw/engines/overlay/overlay_private.h
+++ b/source/blender/draw/engines/overlay/overlay_private.h
@@ -142,7 +142,7 @@ typedef struct OVERLAY_ShadingData {
   float grid_steps[8];
   float inv_viewport_size[2];
   float grid_line_size;
-  float zoom_factor; /* Length per pixel in the UV editor viewport */
+  float zoom_factor; /* Only for UV/Image editor */
   int grid_flag;
   int zpos_flag;
   int zneg_flag;
diff --git a/source/blender/draw/engines/overlay/shaders/grid_frag.glsl 
b/source/blender/draw/engines/overlay/shaders/grid_frag.glsl
index 81e3f341a4f..93fba194a4c 100644
--- a/source/blender/draw/engines/overlay/shaders/grid_frag.glsl
+++ b/source/blender/draw/engines/overlay/shaders/grid_frag.glsl
@@ -130,8 +130,7 @@ void main()
 
 /* For UV/Image editor use zoomFactor */
 if((gridFlag & PLANE_IMAGE) != 0 && (gridFlag & DYNAMIC_GRID) == 0)
-{/* grid begins to appear when the length of one grid unit is at least
-  * (N^2) pixels in the UV/Image editor.
+{/* Grid begins to appear when the length of one grid unit is at least 
256/N pixels (for NxN grid)
   * Value of N defined in overlay_grid.c */
   grid_res = zoomFactor;
 }
diff --git a/source/blender/editors/include/ED_image.h 
b/source/blender/editors/include/ED_image.h
index a0d64037ab9..368acecd8ef 100644
--- a/source/blender/editors/include/ED_image.h
+++ b/source/blender/editors/include/ED_image.h
@@ -45,10 +45,12 @@ struct View2D;
 
 /* image_draw.c (Utility functions - should probably 

[Bf-blender-cvs] [6f61cd90cc4] soc-2021-uv-edge-select-support: Cleanup: Use utility function

2021-08-14 Thread Siddhartha Jejurkar
Commit: 6f61cd90cc4cd96c7ecab242e69d62917ca76c68
Author: Siddhartha Jejurkar
Date:   Sat Aug 14 20:12:38 2021 +0530
Branches: soc-2021-uv-edge-select-support
https://developer.blender.org/rB6f61cd90cc4cd96c7ecab242e69d62917ca76c68

Cleanup: Use utility function

===

M   source/blender/editors/uvedit/uvedit_select.c

===

diff --git a/source/blender/editors/uvedit/uvedit_select.c 
b/source/blender/editors/uvedit/uvedit_select.c
index 45e0ebd796a..98fa6753b61 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -312,7 +312,7 @@ void uvedit_face_select_set_with_sticky(const SpaceImage 
*sima,
 do {
   MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset);
   if (select) {
-/* Set selection flag for the internal edges of the face that is 
being selected */
+/* Set selection flag for only the internal edges of the face that 
is being selected */
 luv->flag |= MLOOPUV_EDGESEL;
 /* Select all shared vertices */
 uvedit_uv_select_shared_location(
@@ -321,30 +321,8 @@ void uvedit_face_select_set_with_sticky(const SpaceImage 
*sima,
   else {
 luv->flag &= ~MLOOPUV_EDGESEL;
 
-bool do_vert_deselect = true;
-BMEdge *e_first = l_iter->e, *e_iter;
-e_iter = e_first;
-do {
-  /* If any surrounding UV face is selected then don't deselect 
the shared UV vertices
-   * Deselcting the shared UV vertices could deselect the 
surrounding UV faces as
-   * well*/
-  BMLoop *l_radial_iter = e_iter->l;
-  do {
-MLoopUV *luv_radial_other = 
BM_ELEM_CD_GET_VOID_P(l_radial_iter,
-  
cd_loop_uv_offset);
-if ((l_radial_iter->f != l_iter->f) &&
-uvedit_face_select_test(scene, l_radial_iter->f, 
cd_loop_uv_offset) &&
-equals_v2v2(luv->uv, luv_radial_other->uv)) {
-  do_vert_deselect = false;
-  break;
-}
-  } while ((l_radial_iter = l_radial_iter->radial_next) != 
e_iter->l);
-  if (!do_vert_deselect) {
-break;
-  }
-} while ((e_iter = BM_DISK_EDGE_NEXT(e_iter, l_iter->v)) != 
e_first);
-
-if (do_vert_deselect) {
+if (!uvedit_vert_is_any_other_face_selected(
+scene, l_iter, l_iter->v, cd_loop_uv_offset)) {
   uvedit_uv_select_shared_location(
   scene, em, l_iter, select, false, do_history, 
cd_loop_uv_offset);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [70824abc3f9] soc-2021-uv-editor-improvements-edge-selection: Merge branch 'master' into soc-2021-uv-editor-improvements-edge-selection

2021-08-08 Thread Siddhartha Jejurkar
Commit: 70824abc3f995b8cefd51637b3dff6e9866e8cbc
Author: Siddhartha Jejurkar
Date:   Mon Aug 9 07:05:27 2021 +0530
Branches: soc-2021-uv-editor-improvements-edge-selection
https://developer.blender.org/rB70824abc3f995b8cefd51637b3dff6e9866e8cbc

Merge branch 'master' into soc-2021-uv-editor-improvements-edge-selection

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [72ee3397100] soc-2021-uv-editor-improvements: Merge branch 'master' into soc-2021-uv-editor-improvements

2021-08-08 Thread Siddhartha Jejurkar
Commit: 72ee3397100d7f90139d5bafc7cac2b5ef453659
Author: Siddhartha Jejurkar
Date:   Mon Aug 9 06:31:32 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB72ee3397100d7f90139d5bafc7cac2b5ef453659

Merge branch 'master' into soc-2021-uv-editor-improvements

===



===

diff --cc source/blender/makesrna/intern/rna_texture_api.c
index c46b9acf986,83c1efd55bc..4edeed86ca8
--- a/source/blender/makesrna/intern/rna_texture_api.c
+++ b/source/blender/makesrna/intern/rna_texture_api.c
@@@ -59,19 -59,23 +59,22 @@@ void RNA_api_texture(StructRNA *srna
PropertyRNA *parm;
  
func = RNA_def_function(srna, "evaluate", "texture_evaluate");
-   RNA_def_function_ui_description(func, "Evaluate the texture at the 
coordinates given");
+   RNA_def_function_ui_description(
+   func, "Evaluate the texture at the a given coordinate and returns the 
result");
  
-   parm = RNA_def_float_vector(func,
-   "value",
-   3,
-   NULL,
-   -FLT_MAX,
-   FLT_MAX,
-   "The object coordinates (x,y,z) used to 
generate/map the texture",
-   "",
-   -1e4,
-   1e4);
+   parm = RNA_def_float_vector(
+   func,
+   "value",
+   3,
+   NULL,
+   -FLT_MAX,
+   FLT_MAX,
+   "The coordinates (x,y,z) of the texture, in case of a 3D texture, the z 
value is the slice "
+   "of the texture that is evaluated. For 2D textures such as images, the 
z value is ignored",
+   "",
+   -1e4,
+   1e4);
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
 -
/* return location and normal */
parm = RNA_def_float_vector(
func,

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [a7f24a8307c] soc-2021-uv-editor-improvements-edge-selection: Edge selection support for Edge ring and loop select operator

2021-08-08 Thread Siddhartha Jejurkar
Commit: a7f24a8307ce2fedbca27495344a9d7623c094f1
Author: Siddhartha Jejurkar
Date:   Mon Aug 9 03:00:27 2021 +0530
Branches: soc-2021-uv-editor-improvements-edge-selection
https://developer.blender.org/rBa7f24a8307ce2fedbca27495344a9d7623c094f1

Edge selection support for Edge ring and loop select operator

* Adds edge selection support for edge ring and edge loop select operator
* Selecting face loops in the UV editor is now done through the loop
  select operator

===

M   source/blender/editors/uvedit/uvedit_select.c

===

diff --git a/source/blender/editors/uvedit/uvedit_select.c 
b/source/blender/editors/uvedit/uvedit_select.c
index 2ba64bb7961..d7762775296 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -844,14 +844,10 @@ void uvedit_uv_select_disable(const Scene *scene,
   }
 }
 
-/* Returns a radial loop which shares the same UV edge and has a visible UV 
face.
- * If more than one such radial loops exist then return NULL */
 static BMLoop *uvedit_loop_find_other_radial_loop_with_visible_face(const 
Scene *scene,
 BMLoop 
*l_src,
 const int 
cd_loop_uv_offset)
 {
-  /* This function basically tells if the UV edge associated with this loop is 
a boundry edge or if
-   * it is shared with another UV face or not */
   BMLoop *l_other = NULL;
   BMLoop *l_iter = l_src->radial_next;
   if (l_iter != l_src) {
@@ -873,14 +869,11 @@ static BMLoop 
*uvedit_loop_find_other_radial_loop_with_visible_face(const Scene
   return l_other;
 }
 
-/* Finds the loop belonging to another face that is also a boundry loop (is at 
the boundry of UV)
- */
 static BMLoop *uvedit_loop_find_other_boundary_loop_with_visible_face(const 
Scene *scene,
   BMLoop 
*l_edge,
   BMVert 
*v_pivot,
   const 
int cd_loop_uv_offset)
 {
-  /* This function helps find another loop whose UV edge is also a boundry 
edge) */
   BLI_assert(uvedit_loop_find_other_radial_loop_with_visible_face(
  scene, l_edge, cd_loop_uv_offset) == NULL);
 
@@ -1645,7 +1638,7 @@ static int uv_select_edgeloop(
   const int cd_loop_uv_offset = CustomData_get_offset(>bm->ldata, 
CD_MLOOPUV);
 
   if (extend) {
-select = !(uvedit_uv_select_test(scene, hit->l, cd_loop_uv_offset));
+select = !(uvedit_edge_select_test(scene, hit->l, cd_loop_uv_offset));
   }
   else {
 select = true;
@@ -1712,6 +1705,70 @@ static int uv_select_edgeloop(
 
 /** \} */
 
+/*  */
+/** \name Face Loop Select
+ * \{ */
+
+static int uv_select_faceloop(
+const SpaceImage *sima, Scene *scene, Object *obedit, UvNearestHit *hit, 
const bool extend)
+{
+  BMEditMesh *em = BKE_editmesh_from_object(obedit);
+  bool select;
+
+  const int cd_loop_uv_offset = CustomData_get_offset(>bm->ldata, 
CD_MLOOPUV);
+
+  if (!extend) {
+uv_select_all_perform(scene, NULL, obedit, SEL_DESELECT);
+  }
+
+  BM_mesh_elem_hflag_disable_all(em->bm, BM_FACE, BM_ELEM_TAG, false);
+
+  if (extend) {
+select = !(uvedit_face_select_test(scene, hit->l->f, cd_loop_uv_offset));
+  }
+  else {
+select = true;
+  }
+
+  BMLoop *l_pair[2] = {
+  hit->l,
+  uvedit_loop_find_other_radial_loop_with_visible_face(scene, hit->l, 
cd_loop_uv_offset),
+  };
+
+  for (int side = 0; side < 2; side++) {
+BMLoop *l_step = l_pair[side];
+while (l_step) {
+  if (!uvedit_face_visible_test(scene, l_step->f)) {
+break;
+  }
+
+  uvedit_face_select_set_with_sticky(
+  sima, scene, em, l_step->f, select, false, cd_loop_uv_offset);
+
+  BM_elem_flag_enable(l_step->f, BM_ELEM_TAG);
+  if (l_step->f->len == 4) {
+BMLoop *l_step_opposite = l_step->next->next;
+l_step = uvedit_loop_find_other_radial_loop_with_visible_face(
+scene, l_step_opposite, cd_loop_uv_offset);
+  }
+  else {
+l_step = NULL;
+  }
+
+  /* Break iteration when l_step :
+   * - is the first loop where we started from
+   * - tagged using BM_ELEM_TAG(meaning this loop has been visited in this 
iteration) */
+  if (l_step && BM_elem_flag_test(l_step->f, BM_ELEM_TAG)) {
+break;
+  }
+}
+  }
+
+  return (select) ? 1 : -1;
+}
+
+/** \} */
+
 /*  */
 /** \name Edge Ring Select
  * \{ */
@@ -1724,6 +1781,9 @@ static int uv_select_edgering(
   const bool use_face_select = (ts-

[Bf-blender-cvs] [752c840f1e3] soc-2021-uv-editor-improvements-edge-selection: Cleanup and fix: UV Invert selection

2021-08-08 Thread Siddhartha Jejurkar
Commit: 752c840f1e3423a62f611e07f6f63b4d6d125036
Author: Siddhartha Jejurkar
Date:   Sat Aug 7 23:39:29 2021 +0530
Branches: soc-2021-uv-editor-improvements-edge-selection
https://developer.blender.org/rB752c840f1e3423a62f611e07f6f63b4d6d125036

Cleanup and fix: UV Invert selection

* Code and comment cleanup
* Fix: Make invert selection respect sticky modes when using edge select
  mode

===

M   source/blender/editors/uvedit/uvedit_select.c

===

diff --git a/source/blender/editors/uvedit/uvedit_select.c 
b/source/blender/editors/uvedit/uvedit_select.c
index 964ea5ac0d5..2ba64bb7961 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -2328,37 +2328,28 @@ static void uv_select_all_perform(Scene *scene, 
SpaceImage *sima, Object *obedit
   luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
 
   switch (ts->uv_selectmode) {
-/* Invert MLOOPUV_EDGESEL flag for all uv elements if in edge 
selection mode.
- * This will mark all edges that need to be selected */
-case UV_SELECT_EDGE: {
-  luv->flag ^= MLOOPUV_EDGESEL;
-  luv->flag &= ~MLOOPUV_VERTSEL;
-  break;
-}
+/* Invert MLOOPUV_EDGESEL flag state for all uv elements if in 
edge/face selection
+ * mode. This will mark all edges that need to be selected */
+case UV_SELECT_EDGE:
 case UV_SELECT_FACE: {
   luv->flag ^= MLOOPUV_EDGESEL;
   luv->flag &= ~MLOOPUV_VERTSEL;
   break;
 }
-/* Invert MLOOPUV_VERTSEL flag for all uv elements if in vertex 
selection mode
- * This will mark all vertices that need to be selected */
+/* Invert MLOOPUV_VERTSEL flag state for all uv elements if in 
vertex/island selection
+ * mode This will mark all vertices that need to be selected */
 case UV_SELECT_VERTEX:
-case UV_SELECT_ISLAND:
-/* TEMPORARY: Fallback to vertex selection mode logic */
+case UV_SELECT_ISLAND: /* Fallback to vertex selection mode logic 
*/
 default: {
-  /* Fallback */
   luv->flag ^= MLOOPUV_VERTSEL;
   break;
 }
   }
 }
   }
-  /* Now, Flush selection flags based on UV selection mode */
+  /* Flush based on selection flags and current UV selection mode */
   switch (ts->uv_selectmode) {
-case UV_SELECT_EDGE: {
-  uv_flush_edge_to_vert(scene, obedit, cd_loop_uv_offset);
-  break;
-}
+case UV_SELECT_EDGE:
 case UV_SELECT_FACE: {
   if (sima->sticky == SI_STICKY_DISABLE) {
 uv_flush_edge_to_vert(scene, obedit, cd_loop_uv_offset);
@@ -2369,8 +2360,7 @@ static void uv_select_all_perform(Scene *scene, 
SpaceImage *sima, Object *obedit
   break;
 }
 case UV_SELECT_VERTEX:
-case UV_SELECT_ISLAND:
-/* TEMPORARY: Fallback to vertex selection mode logic */
+case UV_SELECT_ISLAND: /* Fallback to vertex selection mode logic */
 default: {
   uv_flush_vert_to_edge(scene, obedit, cd_loop_uv_offset);
   break;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ddbbbf40f67] soc-2021-uv-editor-improvements-edge-selection: Fix: Check edge selection only for common vertex

2021-08-08 Thread Siddhartha Jejurkar
Commit: ddbbbf40f670689406ad2de676a0e9620f189bda
Author: Siddhartha Jejurkar
Date:   Sat Aug 7 20:38:18 2021 +0530
Branches: soc-2021-uv-editor-improvements-edge-selection
https://developer.blender.org/rBddbbbf40f670689406ad2de676a0e9620f189bda

Fix: Check edge selection only for common vertex

Allow edge selection test only for UV edges that share a common UV
vertex. Previous logic didn't check if the UV edges shared the same
UV vertex.

===

M   source/blender/editors/uvedit/uvedit_select.c

===

diff --git a/source/blender/editors/uvedit/uvedit_select.c 
b/source/blender/editors/uvedit/uvedit_select.c
index 3a23c55021b..964ea5ac0d5 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -1217,10 +1217,22 @@ static bool 
uvedit_vert_is_any_other_edge_selected(const Scene *scene,
   do {
 BMLoop *l_radial_iter = e_iter->l;
 do {
-  if ((l_radial_iter->f != l->f) && uvedit_face_visible_test(scene, 
l_radial_iter->f)) {
+  if (l_radial_iter->v == l->v) {
+if (BM_loop_uv_share_vert_check(l, l_radial_iter, cd_loop_uv_offset) &&
+uvedit_face_visible_test(scene, l_radial_iter->f)) {
 
-if (uvedit_edge_select_test(scene, l_radial_iter, cd_loop_uv_offset)) {
-  return true;
+  if (uvedit_edge_select_test(scene, l_radial_iter, 
cd_loop_uv_offset)) {
+return true;
+  }
+}
+  }
+  else {
+if (BM_loop_uv_share_vert_check(l, l_radial_iter->next, 
cd_loop_uv_offset) &&
+uvedit_face_visible_test(scene, l_radial_iter->f)) {
+
+  if (uvedit_edge_select_test(scene, l_radial_iter, 
cd_loop_uv_offset)) {
+return true;
+  }
 }
   }
 } while ((l_radial_iter = l_radial_iter->radial_next) != e_iter->l);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [a342ea1cf52] soc-2021-uv-editor-improvements-edge-selection: UV: Refactor UV select split operator

2021-08-08 Thread Siddhartha Jejurkar
Commit: a342ea1cf52be46e83186d427d9c770e0d78b35a
Author: Siddhartha Jejurkar
Date:   Sat Aug 7 13:39:40 2021 +0530
Branches: soc-2021-uv-editor-improvements-edge-selection
https://developer.blender.org/rBa342ea1cf52be46e83186d427d9c770e0d78b35a

UV: Refactor UV select split operator

Refactor UV select split operator to use MLOOPUV_EDGESEL flag

===

M   source/blender/editors/uvedit/uvedit_select.c

===

diff --git a/source/blender/editors/uvedit/uvedit_select.c 
b/source/blender/editors/uvedit/uvedit_select.c
index 8c2e38f8359..bcc6e4e1afe 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -844,10 +844,14 @@ void uvedit_uv_select_disable(const Scene *scene,
   }
 }
 
+/* Returns a radial loop which shares the same UV edge and has a visible UV 
face.
+ * If more than one such radial loops exist then return NULL */
 static BMLoop *uvedit_loop_find_other_radial_loop_with_visible_face(const 
Scene *scene,
 BMLoop 
*l_src,
 const int 
cd_loop_uv_offset)
 {
+  /* This function basically tells if the UV edge associated with this loop is 
a boundry edge or if
+   * it is shared with another UV face or not */
   BMLoop *l_other = NULL;
   BMLoop *l_iter = l_src->radial_next;
   if (l_iter != l_src) {
@@ -869,11 +873,14 @@ static BMLoop 
*uvedit_loop_find_other_radial_loop_with_visible_face(const Scene
   return l_other;
 }
 
+/* Finds the loop belonging to another face that is also a boundry loop (is at 
the boundry of UV)
+ */
 static BMLoop *uvedit_loop_find_other_boundary_loop_with_visible_face(const 
Scene *scene,
   BMLoop 
*l_edge,
   BMVert 
*v_pivot,
   const 
int cd_loop_uv_offset)
 {
+  /* This function helps find another loop whose UV edge is also a boundry 
edge) */
   BLI_assert(uvedit_loop_find_other_radial_loop_with_visible_face(
  scene, l_edge, cd_loop_uv_offset) == NULL);
 
@@ -3103,8 +3110,8 @@ static int uv_select_split_exec(bContext *C, wmOperator 
*op)
 const int cd_loop_uv_offset = CustomData_get_offset(>ldata, 
CD_MLOOPUV);
 
 BM_ITER_MESH (efa, , bm, BM_FACES_OF_MESH) {
-  bool is_sel = false;
-  bool is_unsel = false;
+  /* Assume UV face is selected */
+  bool uv_face_is_sel = true;
 
   if (!uvedit_face_visible_test(scene, efa)) {
 continue;
@@ -3114,23 +3121,20 @@ static int uv_select_split_exec(bContext *C, wmOperator 
*op)
   BM_ITER_ELEM (l, , efa, BM_LOOPS_OF_FACE) {
 luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
 
-if (luv->flag & MLOOPUV_VERTSEL) {
-  is_sel = true;
+if ((luv->flag & MLOOPUV_VERTSEL) && (luv->flag & MLOOPUV_EDGESEL)) {
+  continue;
 }
 else {
-  is_unsel = true;
-}
-
-/* we have mixed selection, bail out */
-if (is_sel && is_unsel) {
+  uv_face_is_sel = false;
   break;
 }
   }
 
-  if (is_sel && is_unsel) {
+  if (!uv_face_is_sel) {
 BM_ITER_ELEM (l, , efa, BM_LOOPS_OF_FACE) {
   luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
   luv->flag &= ~MLOOPUV_VERTSEL;
+  luv->flag &= ~MLOOPUV_EDGESEL;
 }
 
 changed = true;
@@ -4056,6 +4060,7 @@ static int uv_select_pinned_exec(bContext *C, wmOperator 
*UNUSED(op))
 luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
 
 if (luv->flag & MLOOPUV_PINNED) {
+  /* Handle cases for edge selection and face selection separately */
   uvedit_uv_select_enable(scene, em, l, false, cd_loop_uv_offset);
   changed = true;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [a4af0f530ca] soc-2021-uv-editor-improvements-edge-selection: UV: Edge selection for UV select pinned operator

2021-08-08 Thread Siddhartha Jejurkar
Commit: a4af0f530cad2f6fdc91478a9a32fcb653a5b1e4
Author: Siddhartha Jejurkar
Date:   Sat Aug 7 14:07:06 2021 +0530
Branches: soc-2021-uv-editor-improvements-edge-selection
https://developer.blender.org/rBa4af0f530cad2f6fdc91478a9a32fcb653a5b1e4

UV: Edge selection for UV select pinned operator

Ensure edge selection for UV select pinned operator by flushing the
selection upwards (verts to edge)

===

M   source/blender/editors/uvedit/uvedit_select.c

===

diff --git a/source/blender/editors/uvedit/uvedit_select.c 
b/source/blender/editors/uvedit/uvedit_select.c
index bcc6e4e1afe..3a23c55021b 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -4060,13 +4060,18 @@ static int uv_select_pinned_exec(bContext *C, 
wmOperator *UNUSED(op))
 luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
 
 if (luv->flag & MLOOPUV_PINNED) {
-  /* Handle cases for edge selection and face selection separately */
   uvedit_uv_select_enable(scene, em, l, false, cd_loop_uv_offset);
   changed = true;
 }
   }
 }
 
+/* Flush selection
+ * REASON : uvedit_uv_select_enable() allows edge selection only in vertex 
select mode */
+if (ts->uv_selectmode != UV_SELECT_VERTEX) {
+  uv_flush_vert_to_edge(scene, obedit, cd_loop_uv_offset);
+}
+
 if (changed) {
   uv_select_tag_update_for_object(depsgraph, ts, obedit);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [e88563e4722] soc-2021-uv-editor-improvements-edge-selection: Merge branch 'master' into soc-2021-uv-editor-improvements-edge-selection

2021-08-05 Thread Siddhartha Jejurkar
Commit: e88563e472218555ee709cb2bd32079f8a5ac23f
Author: Siddhartha Jejurkar
Date:   Thu Aug 5 16:42:53 2021 +0530
Branches: soc-2021-uv-editor-improvements-edge-selection
https://developer.blender.org/rBe88563e472218555ee709cb2bd32079f8a5ac23f

Merge branch 'master' into soc-2021-uv-editor-improvements-edge-selection

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [db821af1729] soc-2021-uv-editor-improvements-edge-selection: Fix: Invert selection and free unreleased memory

2021-08-05 Thread Siddhartha Jejurkar
Commit: db821af1729d2b1b1037fe9b4f72b8029452ff65
Author: Siddhartha Jejurkar
Date:   Tue Aug 3 17:02:11 2021 +0530
Branches: soc-2021-uv-editor-improvements-edge-selection
https://developer.blender.org/rBdb821af1729d2b1b1037fe9b4f72b8029452ff65

Fix: Invert selection and free unreleased memory

- Free unreleased memory from vertex map
- Select Invert operator now works with UV face select mode as well

===

M   source/blender/editors/uvedit/uvedit_intern.h
M   source/blender/editors/uvedit/uvedit_select.c

===

diff --git a/source/blender/editors/uvedit/uvedit_intern.h 
b/source/blender/editors/uvedit/uvedit_intern.h
index b0ab34b6b02..2d516e3f677 100644
--- a/source/blender/editors/uvedit/uvedit_intern.h
+++ b/source/blender/editors/uvedit/uvedit_intern.h
@@ -132,6 +132,9 @@ void uv_flush_vert_to_edge(struct Scene *scene,
 void uv_flush_edge_to_vert(struct Scene *scene,
struct Object *obedit,
const int cd_loop_uv_offset);
+void uv_flush_edge_to_vert_with_sticky_loc(Scene *scene,
+   Object *obedit,
+   const int cd_loop_uv_offset);
 
 /* utility tool functions */
 
diff --git a/source/blender/editors/uvedit/uvedit_select.c 
b/source/blender/editors/uvedit/uvedit_select.c
index 0e8022b0289..8c2e38f8359 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -70,14 +70,24 @@
 
 #include "uvedit_intern.h"
 
-static void uv_select_all_perform(Scene *scene, Object *obedit, int action);
+static void uv_select_all_perform(Scene *scene, SpaceImage *sima, Object 
*obedit, int action);
 
-static void uv_select_all_perform_multi_ex(
-Scene *scene, Object **objects, const uint objects_len, int action, const 
Object *ob_exclude);
-static void uv_select_all_perform_multi(Scene *scene,
-Object **objects,
-const uint objects_len,
-int action);
+static void uv_select_all_perform_multi_ex(Scene *scene,
+   SpaceImage *sima,
+   Object **objects,
+   const uint objects_len,
+   int action,
+   const Object *ob_exclude);
+static void uv_select_all_perform_multi(
+Scene *scene, SpaceImage *sima, Object **objects, const uint objects_len, 
int action);
+
+static void uv_select_flush_from_tag_sticky_loc_internal(Scene *scene,
+ BMEditMesh *em,
+ UvVertMap *vmap,
+ const uint efa_index,
+ BMLoop *l,
+ const bool select,
+ const int 
cd_loop_uv_offset);
 
 static void uv_select_flush_from_tag_face(SpaceImage *sima,
   Scene *scene,
@@ -1333,6 +1343,47 @@ void uv_flush_edge_to_vert(Scene *scene, Object *obedit, 
const int cd_loop_uv_of
   }
 }
 
+/**
+ * Select shared vertices (vertex selection with sticky location) for all 
edges that are marked
+ * using MLOOPUV_EDGESEL flag as a tag
+ */
+void uv_flush_edge_to_vert_with_sticky_loc(Scene *scene,
+   Object *obedit,
+   const int cd_loop_uv_offset)
+{
+  BMEditMesh *em = BKE_editmesh_from_object(obedit);
+  BMFace *efa;
+  BMLoop *l;
+  BMIter iter, liter;
+  struct UvVertMap *vmap;
+  uint efa_index;
+
+  vmap = BM_uv_vert_map_create(em->bm, false, false);
+  if (vmap == NULL) {
+return;
+  }
+
+  BM_ITER_MESH_INDEX (efa, , em->bm, BM_FACES_OF_MESH, efa_index) {
+if (!uvedit_face_visible_test(scene, efa)) {
+  continue;
+}
+
+BM_ITER_ELEM (l, , efa, BM_LOOPS_OF_FACE) {
+  MLoopUV *luv;
+  luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+
+  if (luv->flag & MLOOPUV_EDGESEL) {
+uv_select_flush_from_tag_sticky_loc_internal(
+scene, em, vmap, efa_index, l, true, cd_loop_uv_offset);
+uv_select_flush_from_tag_sticky_loc_internal(
+scene, em, vmap, efa_index, l->next, true, cd_loop_uv_offset);
+  }
+}
+  }
+
+  BM_uv_vert_map_free(vmap);
+}
+
 /** \} */
 
 /* NOTE : UV Selection mode flushing NOT implemented for now
@@ -1618,7 +1669,7 @@ static int uv_select_edgeloop(
 
   /* Apply the selection. */
   if (!extend) {
-uv_select_all_perform(scene, obedit, SEL_DESELECT);
+uv_sele

[Bf-blender-cvs] [d6e02d92e13] soc-2021-uv-editor-improvements-edge-selection: UV: Extend edge selection support

2021-08-05 Thread Siddhartha Jejurkar
Commit: d6e02d92e13383b73f305cd7cd2162143f647507
Author: Siddhartha Jejurkar
Date:   Mon Aug 2 09:50:50 2021 +0530
Branches: soc-2021-uv-editor-improvements-edge-selection
https://developer.blender.org/rBd6e02d92e13383b73f305cd7cd2162143f647507

UV: Extend edge selection support

- Add edge selection support for operators: mouse select, box select,
  circle select, lasso select, (de)select all, invert selection and
  select more/less
- Flush selections between UV verts and edges
- Fix: prevent deselection of neighbouring edges when deselecting an
  edge in sticky location + edge select mode

===

M   source/blender/editors/uvedit/uvedit_intern.h
M   source/blender/editors/uvedit/uvedit_select.c

===

diff --git a/source/blender/editors/uvedit/uvedit_intern.h 
b/source/blender/editors/uvedit/uvedit_intern.h
index ea72b859f7c..b0ab34b6b02 100644
--- a/source/blender/editors/uvedit/uvedit_intern.h
+++ b/source/blender/editors/uvedit/uvedit_intern.h
@@ -125,6 +125,14 @@ BMLoop *uv_find_nearest_loop_from_edge(struct Scene *scene,
struct BMEdge *e,
const float co[2]);
 
+/* flush uv selection */
+void uv_flush_vert_to_edge(struct Scene *scene,
+   struct Object *obedit,
+   const int cd_loop_uv_offset);
+void uv_flush_edge_to_vert(struct Scene *scene,
+   struct Object *obedit,
+   const int cd_loop_uv_offset);
+
 /* utility tool functions */
 
 void uvedit_live_unwrap_update(struct SpaceImage *sima,
diff --git a/source/blender/editors/uvedit/uvedit_select.c 
b/source/blender/editors/uvedit/uvedit_select.c
index fe505f865b6..0e8022b0289 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -91,6 +91,18 @@ static void uv_select_tag_update_for_object(Depsgraph 
*depsgraph,
 const ToolSettings *ts,
 Object *obedit);
 
+static bool uvedit_vert_is_any_other_edge_selected(const Scene *scene,
+   BMLoop *l,
+   const int 
cd_loop_uv_offset);
+static bool uvedit_vert_is_any_other_face_selected(const Scene *scene,
+   BMLoop *l,
+   BMVert *v,
+   const int 
cd_loop_uv_offset);
+static bool uvedit_vert_is_any_other_not_face_selected(const Scene *scene,
+   BMLoop *l,
+   BMVert *v,
+   const int 
cd_loop_uv_offset);
+
 /*  */
 /** \name Active Selection Tracking
  *
@@ -469,17 +481,37 @@ void uvedit_edge_select_set_with_sticky(const struct 
SpaceImage *sima,
 default: {
   /* SI_STICKY_LOC
* Fallback to SI_STICKY_LOC, in case sima->sticky is invalid */
-  uvedit_edge_select_shared_location(
-  scene, em, l, select, false, do_history, cd_loop_uv_offset);
-
-  /* NOTE (Design tradeoff): This is a case where we deviate from the 
logic of: "EDGE
-   * SELECTION MODE SHOULD IMPLY ONLY EDGES MUST BE SELECTED". The UV 
vertex selections done
-   * below are to avoid the cases of edge selections breaking away 
(/become separate
-   * entities) from the vertices/edges they were connected to */
-  uvedit_uv_select_shared_location(scene, em, l, select, false, 
do_history, cd_loop_uv_offset);
-  uvedit_uv_select_shared_location(
-  scene, em, l->next, select, false, do_history, cd_loop_uv_offset);
+  if (select) {
+uvedit_edge_select_shared_location(
+scene, em, l, select, false, do_history, cd_loop_uv_offset);
+
+/* NOTE (Design tradeoff): This is a case where we deviate from the 
logic of: "EDGE
+ * SELECTION MODE SHOULD IMPLY ONLY EDGES MUST BE SELECTED". The UV 
vertex selections done
+ * below are to avoid the cases of edge selections breaking away 
(/become separate
+ * entities) from the vertices/edges they were connected to */
+uvedit_uv_select_shared_location(
+scene, em, l, select, false, do_history, cd_loop_uv_offset);
+uvedit_uv_select_shared_location(
+scene, em, l->next, select, false, do_history, cd_loop_uv_offset);
+  }
+  else {
+BMLoop *l_radial_iter = l;
+do {
+  if (BM_loop_uv_share_edge_check(l, l_radial_iter, 
cd_loop_uv_offset)) {
+MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l_ra

[Bf-blender-cvs] [035fa7985d2] soc-2021-uv-editor-improvements-edge-selection: UV: Edge selection support - Initial

2021-08-05 Thread Siddhartha Jejurkar
Commit: 035fa7985d270fae197dfd155c7937b24e16e244
Author: Siddhartha Jejurkar
Date:   Mon Jul 26 09:22:32 2021 +0530
Branches: soc-2021-uv-editor-improvements-edge-selection
https://developer.blender.org/rB035fa7985d270fae197dfd155c7937b24e16e244

UV: Edge selection support - Initial

* Add UV edge selection flag - MLOOPUV_EDGESEL
* Refactor existing UV element selection functions to use the edge
  selection flag wherever required
* Refactor existing UV element check functions to ensure proper
  selection states using the edge selection flag
* Refactor UV select all operator to use edge selection flag
* New functions for selecting vertices or edges that share the same
  location, either on 3D mesh or in UV space.
* Add small penalty for finding the nearest UV edge. Ensures that UV edge
  selection will select other edges sharing the same location in
  successive selection attempts.
* Expose UV edge selection flag as boolean in Python

Differential Revision: https://developer.blender.org/D12028

===

M   source/blender/editors/include/ED_uvedit.h
M   source/blender/editors/uvedit/uvedit_intern.h
M   source/blender/editors/uvedit/uvedit_path.c
M   source/blender/editors/uvedit/uvedit_select.c
M   source/blender/editors/uvedit/uvedit_smart_stitch.c
M   source/blender/makesdna/DNA_meshdata_types.h
M   source/blender/makesrna/intern/rna_mesh.c
M   source/blender/python/bmesh/bmesh_py_types_meshdata.c

===

diff --git a/source/blender/editors/include/ED_uvedit.h 
b/source/blender/editors/include/ED_uvedit.h
index ea3d921f2c5..157fc450e70 100644
--- a/source/blender/editors/include/ED_uvedit.h
+++ b/source/blender/editors/include/ED_uvedit.h
@@ -145,6 +145,13 @@ void uvedit_edge_select_set_with_sticky(const struct 
SpaceImage *sima,
 const bool select,
 const bool do_history,
 const uint cd_loop_uv_offset);
+void uvedit_edge_select_shared_location(const struct Scene *scene,
+struct BMEditMesh *em,
+struct BMLoop *l,
+const bool select,
+const bool use_mesh_location,
+const bool do_history,
+const uint cd_loop_uv_offset);
 void uvedit_edge_select_set(const struct Scene *scene,
 struct BMEditMesh *em,
 struct BMLoop *l,
@@ -168,6 +175,13 @@ void uvedit_uv_select_set_with_sticky(const struct 
SpaceImage *sima,
   const bool select,
   const bool do_history,
   const uint cd_loop_uv_offset);
+void uvedit_uv_select_shared_location(const struct Scene *scene,
+  struct BMEditMesh *em,
+  struct BMLoop *l,
+  const bool select,
+  const bool use_mesh_location,
+  const bool do_history,
+  const uint cd_loop_uv_offset);
 void uvedit_uv_select_set(const struct Scene *scene,
   struct BMEditMesh *em,
   struct BMLoop *l,
diff --git a/source/blender/editors/uvedit/uvedit_intern.h 
b/source/blender/editors/uvedit/uvedit_intern.h
index cd8fbd00316..ea72b859f7c 100644
--- a/source/blender/editors/uvedit/uvedit_intern.h
+++ b/source/blender/editors/uvedit/uvedit_intern.h
@@ -86,11 +86,13 @@ bool uv_find_nearest_vert_multi(struct Scene *scene,
 bool uv_find_nearest_edge(struct Scene *scene,
   struct Object *obedit,
   const float co[2],
+  const float penalty,
   struct UvNearestHit *hit);
 bool uv_find_nearest_edge_multi(struct Scene *scene,
 struct Object **objects,
 const uint objects_len,
 const float co[2],
+const float penalty,
 struct UvNearestHit *hit);
 
 bool uv_find_nearest_face_ex(struct Scene *scene,
diff --git a/source/blender/editors/uvedit/uvedit_path.c 
b/source/blender/editors/uvedit/uvedit_path.c
index 2613c5b23a0..1f3ba206103 100644
--- a/source/blender/editors/uvedit/uvedit_path.c
+++ b/source/blender/editors/uvedit/uvedit_path.c
@@ -627,7 +627,7 @@ static int uv_shortest_path_pick_invoke(bContext *C, 
wmOperator *op, const wmEve
 
   else if (uv_selectmode & UV_SELECT_EDGE) {
 UvNearestHit hit = UV_NEAREST_HIT_INIT

[Bf-blender-cvs] [8b3b353cafd] soc-2021-uv-editor-improvements-edge-selection: Fix: Prevent deselection of surrounding UV faces

2021-08-05 Thread Siddhartha Jejurkar
Commit: 8b3b353cafd151fc6236fe8fab417fd446d5ec03
Author: Siddhartha Jejurkar
Date:   Thu Jul 29 20:02:29 2021 +0530
Branches: soc-2021-uv-editor-improvements-edge-selection
https://developer.blender.org/rB8b3b353cafd151fc6236fe8fab417fd446d5ec03

Fix: Prevent deselection of surrounding UV faces

With face + sticky loc/vertex mode, trying to deselect UV faces would
sometimes result in surrounding UV faces being deselected as well. This
commit fixes that allowing conditional deselection of shared UV
vertices based on the selection state of surrounding UV faces.

===

M   source/blender/editors/uvedit/uvedit_select.c

===

diff --git a/source/blender/editors/uvedit/uvedit_select.c 
b/source/blender/editors/uvedit/uvedit_select.c
index aac9b8a419d..fe505f865b6 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -282,19 +282,53 @@ void uvedit_face_select_set_with_sticky(const SpaceImage 
*sima,
 case SI_STICKY_LOC:
 case SI_STICKY_VERTEX:
 default: {
-  /* Sticky location and vertex modes. */
-  /* Fallback, in case sima->sticky is invalid */
-  BMLoop *l_iter, *l_first;
-  l_iter = l_first = BM_FACE_FIRST_LOOP(efa);
-  do {
-uvedit_edge_select_shared_location(
-scene, em, l_iter, select, false, do_history, cd_loop_uv_offset);
-
-uvedit_uv_select_shared_location(
-scene, em, l_iter, select, false, do_history, cd_loop_uv_offset);
-uvedit_uv_select_shared_location(
-scene, em, l_iter->next, select, false, do_history, 
cd_loop_uv_offset);
-  } while ((l_iter = l_iter->next) != l_first);
+  if (uvedit_face_visible_test(scene, efa)) {
+/* Sticky location and vertex modes. */
+/* Fallback, in case sima->sticky is invalid */
+BMLoop *l_iter, *l_first;
+l_iter = l_first = BM_FACE_FIRST_LOOP(efa);
+do {
+  MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset);
+  if (select) {
+/* Set selection flag for the internal edges of the face that is 
being selected */
+luv->flag |= MLOOPUV_EDGESEL;
+/* Select all shared vertices */
+uvedit_uv_select_shared_location(
+scene, em, l_iter, select, false, do_history, 
cd_loop_uv_offset);
+  }
+  else {
+luv->flag &= ~MLOOPUV_EDGESEL;
+
+bool do_vert_deselect = true;
+BMEdge *e_first = l_iter->e, *e_iter;
+e_iter = e_first;
+do {
+  /* If any surrounding UV face is selected then don't deselect 
the shared UV vertices
+   * Deselcting the shared UV vertices could deselect the 
surrounding UV faces as
+   * well*/
+  BMLoop *l_radial_iter = e_iter->l;
+  do {
+MLoopUV *luv_radial_other = 
BM_ELEM_CD_GET_VOID_P(l_radial_iter,
+  
cd_loop_uv_offset);
+if ((l_radial_iter->f != l_iter->f) &&
+uvedit_face_select_test(scene, l_radial_iter->f, 
cd_loop_uv_offset) &&
+equals_v2v2(luv->uv, luv_radial_other->uv)) {
+  do_vert_deselect = false;
+  break;
+}
+  } while ((l_radial_iter = l_radial_iter->radial_next) != 
e_iter->l);
+  if (!do_vert_deselect) {
+break;
+  }
+} while ((e_iter = BM_DISK_EDGE_NEXT(e_iter, l_iter->v)) != 
e_first);
+
+if (do_vert_deselect) {
+  uvedit_uv_select_shared_location(
+  scene, em, l_iter, select, false, do_history, 
cd_loop_uv_offset);
+}
+  }
+} while ((l_iter = l_iter->next) != l_first);
+  }
   break;
 }
   }
@@ -438,10 +472,10 @@ void uvedit_edge_select_set_with_sticky(const struct 
SpaceImage *sima,
   uvedit_edge_select_shared_location(
   scene, em, l, select, false, do_history, cd_loop_uv_offset);
 
-  /* NOTE: This is a case where we deviate from the logic of: "EDGE 
SELECTION MODE SHOULD
-   * IMPLY ONLY EDGES MUST BE SELECTED".
-   * The UV vertex selections done below are to avoid the cases of edge 
selections breaking
-   * away (/become separate entities) from the vertices/edges they were 
connected to */
+  /* NOTE (Design tradeoff): This is a case where we deviate from the 
logic of: "EDGE
+   * SELECTION MODE SHOULD IMPLY ONLY EDGES MUST BE SELECTED". The UV 
vertex selections done
+   * below are to avoid the cases of edge selections breaking away 
(/become separate
+   * entities) from the vertices/edges they were connected to */
   u

[Bf-blender-cvs] [d6ddacabc17] soc-2021-uv-editor-improvements: Cleanup: Allow early exit if operator cancelled

2021-08-04 Thread Siddhartha Jejurkar
Commit: d6ddacabc171cb38410cc3aa84239767bb0793f0
Author: Siddhartha Jejurkar
Date:   Wed Aug 4 22:48:41 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rBd6ddacabc171cb38410cc3aa84239767bb0793f0

Cleanup: Allow early exit if operator cancelled

Cancel the pack islands operator early, in case there are no UV
selections to pack

===

M   source/blender/editors/uvedit/uvedit_unwrap_ops.c

===

diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c 
b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index d017c435bc1..8387e09b7e8 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -1031,6 +1031,16 @@ static int pack_islands_exec(bContext *C, wmOperator *op)
   .correct_aspect = true,
   };
 
+  uint objects_len = 0;
+  Object **objects = 
BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
+  view_layer, CTX_wm_view3d(C), _len);
+
+  /* Early exit in case no UVs are selected */
+  if (!uvedit_have_selection_multi(scene, objects, objects_len, )) {
+MEM_freeN(objects);
+return OPERATOR_CANCELLED;
+  }
+
   bool rotate = RNA_boolean_get(op->ptr, "rotate");
 
   /* Check if specified UDIM is valid - specified tile exists in the udim grid 
or tiled image */
@@ -1080,15 +1090,6 @@ static int pack_islands_exec(bContext *C, wmOperator *op)
 use_target = false;
   }
 
-  uint objects_len = 0;
-  Object **objects = 
BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
-  view_layer, CTX_wm_view3d(C), _len);
-
-  if (!uvedit_have_selection_multi(scene, objects, objects_len, )) {
-MEM_freeN(objects);
-return OPERATOR_CANCELLED;
-  }
-
   if (RNA_struct_property_is_set(op->ptr, "margin")) {
 scene->toolsettings->uvcalc_margin = RNA_float_get(op->ptr, "margin");
   }
@@ -1123,7 +1124,7 @@ static void pack_islands_draw(bContext *C, wmOperator *op)
 
   col = uiLayoutColumn(layout, false);
 
-  /* Expose target UDIM prop only if packing target is specified UDIM */
+  /* Expose target UDIM property only if packing target is specified UDIM */
   uiItemR(col, op->ptr, "packTo", 0, NULL, 0);
   if (RNA_enum_get(op->ptr, "packTo") == SPECIFIED_UDIM) {
 uiItemR(col, op->ptr, "target_udim", 0, NULL, 0);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [9974edc8570] soc-2021-uv-editor-improvements: Merge branch 'master' into soc-2021-uv-editor-improvements

2021-08-03 Thread Siddhartha Jejurkar
Commit: 9974edc8570097141ceb94638771127d829e9787
Author: Siddhartha Jejurkar
Date:   Wed Aug 4 06:13:00 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB9974edc8570097141ceb94638771127d829e9787

Merge branch 'master' into soc-2021-uv-editor-improvements

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [7d5ed35602d] soc-2021-uv-editor-improvements: Merge branch 'master' into soc-2021-uv-editor-improvements

2021-07-17 Thread Siddhartha Jejurkar
Commit: 7d5ed35602d791d6c4e1f47bfd6718760e241851
Author: Siddhartha Jejurkar
Date:   Sat Jul 17 21:40:01 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB7d5ed35602d791d6c4e1f47bfd6718760e241851

Merge branch 'master' into soc-2021-uv-editor-improvements

===



===

diff --cc source/blender/editors/uvedit/uvedit_islands.c
index 9181699a283,56bcbc63de1..ef990080ec1
--- a/source/blender/editors/uvedit/uvedit_islands.c
+++ b/source/blender/editors/uvedit/uvedit_islands.c
@@@ -37,8 -36,8 +37,9 @@@
  #include "BLI_math.h"
  #include "BLI_rect.h"
  
+ #include "BKE_customdata.h"
  #include "BKE_editmesh.h"
 +#include "BKE_image.h"
  
  #include "DEG_depsgraph.h"

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [cd75125c488] soc-2021-uv-editor-improvements: UV: Keymaps for offsetting selected UVs

2021-07-17 Thread Siddhartha Jejurkar
Commit: cd75125c48859fc2dfb9891ce14d3a5ff9aeda7f
Author: Siddhartha Jejurkar
Date:   Sat Jul 17 21:26:51 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rBcd75125c48859fc2dfb9891ce14d3a5ff9aeda7f

UV: Keymaps for offsetting selected UVs

Adds keymaps to offset selected UVs by a fixed distance in a specified 
direction.
Refer T78405

===

M   release/scripts/presets/keyconfig/keymap_data/blender_default.py
M   source/blender/editors/uvedit/uvedit_ops.c

===

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py 
b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 4319e3a962b..0e76f0c7e18 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -941,6 +941,22 @@ def km_uv_editor(params):
 ("transform.translate", {"type": params.select_tweak, "value": 'ANY'}, 
None),
 ("transform.rotate", {"type": 'R', "value": 'PRESS'}, None),
 ("transform.resize", {"type": 'S', "value": 'PRESS'}, None),
+("uv.offset", {"type": 'UP_ARROW', "value": 'PRESS', "ctrl": True},
+ {"properties": [("offset_direction", 'UDIM_UP')]}),
+("uv.offset", {"type": 'DOWN_ARROW', "value": 'PRESS', "ctrl": True},
+ {"properties": [("offset_direction", 'UDIM_DOWN')]}),
+("uv.offset", {"type": 'LEFT_ARROW', "value": 'PRESS', "ctrl": True},
+ {"properties": [("offset_direction", 'UDIM_LEFT')]}),
+("uv.offset", {"type": 'RIGHT_ARROW', "value": 'PRESS', "ctrl": True},
+ {"properties": [("offset_direction", 'UDIM_RIGHT')]}),
+("uv.offset", {"type": 'UP_ARROW', "value": 'PRESS', "alt": True},
+ {"properties": [("offset_direction", 'DYNAMIC_GRID_UP')]}),
+("uv.offset", {"type": 'DOWN_ARROW', "value": 'PRESS', "alt": True},
+ {"properties": [("offset_direction", 'DYNAMIC_GRID_DOWN')]}),
+("uv.offset", {"type": 'LEFT_ARROW', "value": 'PRESS', "alt": True},
+ {"properties": [("offset_direction", 'DYNAMIC_GRID_LEFT')]}),
+("uv.offset", {"type": 'RIGHT_ARROW', "value": 'PRESS', "alt": True},
+ {"properties": [("offset_direction", 'DYNAMIC_GRID_RIGHT')]}),
 ("transform.shear", {"type": 'S', "value": 'PRESS', "shift": True, 
"ctrl": True, "alt": True}, None),
 ("transform.mirror", {"type": 'M', "value": 'PRESS', "ctrl": True}, 
None),
 ("wm.context_toggle", {"type": 'TAB', "value": 'PRESS', "shift": True},
diff --git a/source/blender/editors/uvedit/uvedit_ops.c 
b/source/blender/editors/uvedit/uvedit_ops.c
index ee1980e5908..6f308d32d86 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -1338,6 +1338,176 @@ static void UV_OT_snap_selected(wmOperatorType *ot)
 
 /** \} */
 
+/*  */
+/** \name UV offset Operator
+ * \{ */
+
+/* Pixel offset (defined in T78405) is currently not implemented in the 
operator */
+enum {
+  UDIM_OFFSET_UP = 0,
+  UDIM_OFFSET_DOWN,
+  UDIM_OFFSET_LEFT,
+  UDIM_OFFSET_RIGHT,
+  DYNAMIC_GRID_OFFSET_UP,
+  DYNAMIC_GRID_OFFSET_DOWN,
+  DYNAMIC_GRID_OFFSET_LEFT,
+  DYNAMIC_GRID_OFFSET_RIGHT,
+};
+
+static int uv_offset_exec(bContext *C, wmOperator *op)
+{
+  Scene *scene = CTX_data_scene(C);
+  ViewLayer *view_layer = CTX_data_view_layer(C);
+  const SpaceImage *sima = CTX_wm_space_image(C);
+  const ToolSettings *ts = scene->toolsettings;
+  // const bool synced_selection = (ts->uv_flag & UV_SYNC_SELECTION) != 0;
+  int dynamic_grid_size = (sima->flag & SI_DYNAMIC_GRID) ? 
sima->dynamic_grid_size : 0;
+
+  const int offset_direction = RNA_enum_get(op->ptr, "offset_direction");
+  float uv_offset[2] = {0.0f, 0.0f};
+
+  /* Assign offset based on the keymap input */
+  switch (offset_direction) {
+case UDIM_OFFSET_UP: {
+  uv_offset[1] = 1.0f;
+  break;
+}
+case UDIM_OFFSET_DOWN: {
+  uv_offset[1] = -1.0f;
+  break;
+}
+case UDIM_OFFSET_LEFT: {
+  uv_o

[Bf-blender-cvs] [e1abd5947ff] soc-2021-uv-editor-improvements: UV: Absolute grid snap for UV editor

2021-07-10 Thread Siddhartha Jejurkar
Commit: e1abd5947ff920ec322e52b708ae4fc54fa8dec1
Author: Siddhartha Jejurkar
Date:   Sat Jul 10 17:32:07 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rBe1abd5947ff920ec322e52b708ae4fc54fa8dec1

UV: Absolute grid snap for UV editor

Adds a UI toggle for absolute grid snap when using Increment snapping in
UV editor. This implementation mimics the behavior observed with the
same toggle in the 3D viewport.

===

M   release/scripts/startup/bl_ui/space_image.py
M   source/blender/editors/transform/transform_snap.c
M   source/blender/makesdna/DNA_scene_types.h
M   source/blender/makesrna/intern/rna_scene.c

===

diff --git a/release/scripts/startup/bl_ui/space_image.py 
b/release/scripts/startup/bl_ui/space_image.py
index 8451d337e92..e7616a4e5ed 100644
--- a/release/scripts/startup/bl_ui/space_image.py
+++ b/release/scripts/startup/bl_ui/space_image.py
@@ -941,6 +941,10 @@ class IMAGE_PT_snapping(Panel):
 col.label(text="Target")
 row = col.row(align=True)
 row.prop(tool_settings, "snap_target", expand=True)
+
+col.separator()
+if 'INCREMENT' in tool_settings.snap_uv_element:
+col.prop(tool_settings, "use_snap_uv_grid_absolute")
 
 col.label(text="Affect")
 row = col.row(align=True)
diff --git a/source/blender/editors/transform/transform_snap.c 
b/source/blender/editors/transform/transform_snap.c
index 2619fdf3403..a1f65dcc7c8 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -590,6 +590,12 @@ static void initSnappingMode(TransInfo *t)
 t->tsnap.project = 0;
 
 t->tsnap.mode = ts->snap_uv_mode;
+/* NOTE : For now, absolute grid snap only works with translation */
+if ((t->tsnap.mode & SCE_SNAP_MODE_INCREMENT) && (ts->snap_flag & 
SCE_SNAP_ABS_UV_GRID) &&
+(t->mode == TFM_TRANSLATION)) {
+  t->tsnap.mode &= ~SCE_SNAP_MODE_INCREMENT;
+  t->tsnap.mode |= SCE_SNAP_MODE_GRID;
+}
   }
   else if (t->spacetype == SPACE_SEQ) {
 t->tsnap.mode = SEQ_tool_settings_snap_mode_get(t->scene);
@@ -1539,7 +1545,8 @@ bool transform_snap_grid(TransInfo *t, float *val)
 return false;
   }
 
-  if (t->spacetype != SPACE_VIEW3D) {
+  /* Don't do grid snapping if not in 3D viewport or UV editor */
+  if (!((t->spacetype == SPACE_VIEW3D) || (t->spacetype == SPACE_IMAGE))) {
 return false;
   }
 
diff --git a/source/blender/makesdna/DNA_scene_types.h 
b/source/blender/makesdna/DNA_scene_types.h
index f110d8c998e..274c4b96ff6 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1460,14 +1460,12 @@ typedef struct ToolSettings {
 
   char edge_mode_live_unwrap;
 
-  char _pad1[1];
-
   /* Transform */
   char transform_pivot_point;
   char transform_flag;
   char snap_mode, snap_node_mode;
   char snap_uv_mode;
-  char snap_flag;
+  short snap_flag;
   char snap_target;
   char snap_transform_mode_flag;
 
@@ -2048,6 +2046,7 @@ enum {
 #define SCE_SNAP_ABS_GRID (1 << 5)
 #define SCE_SNAP_BACKFACE_CULLING (1 << 6)
 #define SCE_SNAP_SEQ (1 << 7)
+#define SCE_SNAP_ABS_UV_GRID (1 << 8)
 
 /** #ToolSettings.snap_target */
 #define SCE_SNAP_TARGET_CLOSEST 0
diff --git a/source/blender/makesrna/intern/rna_scene.c 
b/source/blender/makesrna/intern/rna_scene.c
index 0a91d5f01bc..57f26ae998c 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -3139,6 +3139,14 @@ static void rna_def_tool_settings(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Snap UV Element", "Type of element to snap 
to");
   RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); /* header 
redraw */
 
+  prop = RNA_def_property(srna, "use_snap_uv_grid_absolute", PROP_BOOLEAN, 
PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "snap_flag", SCE_SNAP_ABS_UV_GRID);
+  RNA_def_property_ui_text(
+  prop,
+  "Absolute Grid Snap",
+  "Absolute grid alignment while translating (based on the pivot center)");
+  RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); /* header 
redraw */
+
   prop = RNA_def_property(srna, "snap_target", PROP_ENUM, PROP_NONE);
   RNA_def_property_enum_sdna(prop, NULL, "snap_target");
   RNA_def_property_enum_items(prop, rna_enum_snap_target_items);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [8d642bbba64] soc-2021-uv-editor-improvements: Merge branch 'master' into soc-2021-uv-editor-improvements

2021-07-08 Thread Siddhartha Jejurkar
Commit: 8d642bbba6434af72db4d5c97c18d92343e18e48
Author: Siddhartha Jejurkar
Date:   Thu Jul 8 23:59:20 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB8d642bbba6434af72db4d5c97c18d92343e18e48

Merge branch 'master' into soc-2021-uv-editor-improvements

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [5777ec9af91] soc-2021-uv-editor-improvements: Merge branch 'master' into soc-2021-uv-editor-improvements

2021-07-08 Thread Siddhartha Jejurkar
Commit: 5777ec9af91356db6fdc20b50f171a86d3d82db4
Author: Siddhartha Jejurkar
Date:   Thu Jul 8 15:48:19 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB5777ec9af91356db6fdc20b50f171a86d3d82db4

Merge branch 'master' into soc-2021-uv-editor-improvements

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [86023928ba7] soc-2021-uv-editor-improvements: UV: Increment snapping based on new UV grid types

2021-07-04 Thread Siddhartha Jejurkar
Commit: 86023928ba794606f2372ce9f52c86c2b881041f
Author: Siddhartha Jejurkar
Date:   Sun Jul 4 22:51:34 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB86023928ba794606f2372ce9f52c86c2b881041f

UV: Increment snapping based on new UV grid types

Since the default UV editor grid has been replaced with a new
subdividing grid and dynamic grid (T78389) has also been implemented,
increment snapping value needs to change according to the grid
configuration in use.

This commit ensures that the increment snapping value is changed
according to the grid dimensions currently in use.
Example - For a NxN grid the increment value is set as 1/N

===

M   source/blender/editors/include/ED_image.h
M   source/blender/editors/space_image/image_draw.c
M   source/blender/editors/transform/transform.c

===

diff --git a/source/blender/editors/include/ED_image.h 
b/source/blender/editors/include/ED_image.h
index aa923bcf245..a0d64037ab9 100644
--- a/source/blender/editors/include/ED_image.h
+++ b/source/blender/editors/include/ED_image.h
@@ -43,11 +43,12 @@ struct wmOperator;
 struct wmWindowManager;
 struct View2D;
 
-/* image_draw.c */
+/* image_draw.c (Utility functions - should probably be moved to a BKE header) 
*/
 float ED_space_image_zoom_level(const struct View2D *v2d, const int 
grid_dimension);
 void ED_space_image_grid_steps(const int grid_dimension,
float grid_steps[8],
const bool is_dynamic_grid);
+float ED_space_image_increment_snap_value(const float grid_steps[8], const 
float zoom_factor);
 
 /* image_edit.c, exported for transform */
 struct Image *ED_space_image(struct SpaceImage *sima);
diff --git a/source/blender/editors/space_image/image_draw.c 
b/source/blender/editors/space_image/image_draw.c
index 5b5ec236890..88db49aaf49 100644
--- a/source/blender/editors/space_image/image_draw.c
+++ b/source/blender/editors/space_image/image_draw.c
@@ -1078,4 +1078,41 @@ void ED_space_image_grid_steps(const int grid_dimension,
   grid_steps[step] = powf(grid_dimension, step) * (1.0f / 
(powf(grid_dimension, 8)));
 }
   }
+}
+
+/* Calculate the increment snapping value for UV/image editor based on the 
zoom factor
+ * The code in here (except the offset part) is used in `grid_frag.glsl` (see 
`grid_res`) for
+ * drawing the grid overlay for the UV/Image editor */
+float ED_space_image_increment_snap_value(const float grid_steps[8], const 
float zoom_factor)
+{
+  /* Small offset on each grid_steps[] so that snapping value doesn't change 
until grid lines are
+   * significantly visible.
+   * Offset = 3/4 * (grid_steps[i] - grid_steps[i+1])
+   *
+   * Refer grid_frag.glsl to find out when grid lines actually start
+   * appearing */
+  if ((grid_steps[0] - ((9 * grid_steps[0]) / (4.0f * 4.0f))) > zoom_factor) {
+return grid_steps[0];
+  }
+  else if ((grid_steps[1] - ((9 * grid_steps[1]) / (4.0f * 4.0f))) > 
zoom_factor) {
+return grid_steps[1];
+  }
+  else if ((grid_steps[2] - ((9 * grid_steps[2]) / (4.0f * 4.0f))) > 
zoom_factor) {
+return grid_steps[2];
+  }
+  else if ((grid_steps[3] - ((9 * grid_steps[3]) / (4.0f * 4.0f))) > 
zoom_factor) {
+return grid_steps[3];
+  }
+  else if ((grid_steps[4] - ((9 * grid_steps[4]) / (4.0f * 4.0f))) > 
zoom_factor) {
+return grid_steps[4];
+  }
+  else if ((grid_steps[5] - ((9 * grid_steps[5]) / (4.0f * 4.0f))) > 
zoom_factor) {
+return grid_steps[5];
+  }
+  else if ((grid_steps[6] - ((9 * grid_steps[6]) / (4.0f * 4.0f))) > 
zoom_factor) {
+return grid_steps[6];
+  }
+  else {
+return grid_steps[7];
+  }
 }
\ No newline at end of file
diff --git a/source/blender/editors/transform/transform.c 
b/source/blender/editors/transform/transform.c
index 88f91d477b5..7072c06f364 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -28,6 +28,7 @@
 #include "DNA_gpencil_types.h"
 #include "DNA_mask_types.h"
 #include "DNA_mesh_types.h"
+#include "DNA_screen_types.h"
 
 #include "BLI_math.h"
 #include "BLI_rect.h"
@@ -1610,8 +1611,25 @@ static void initSnapSpatial(TransInfo *t, float 
r_snap[2])
 }
   }
   else if (t->spacetype == SPACE_IMAGE) {
-r_snap[0] = 0.0625f;
-r_snap[1] = 0.03125f;
+/* Change the default value of 0.0625 since the UV editor grid is now 
dynamically subdividing
+ */
+SpaceImage *sima = t->area->spacedata.first;
+View2D *v2d = >region->v2d;
+/* For a NxN grid. Keep in sync with value in overay_grid.c. Could be 
moved to View2D or
+ * SpaceImage to make it global indirectly */
+int N = 4;
+float zoom_factor = ED_space_image_zoom_level(v2d, N); /* Use a better 
name */
+float

[Bf-blender-cvs] [708f375f767] soc-2021-uv-editor-improvements: Cleanup: Refactor reusable code into functions

2021-07-04 Thread Siddhartha Jejurkar
Commit: 708f375f767f25ed2a0ada54b652d2c776e415ea
Author: Siddhartha Jejurkar
Date:   Sun Jul 4 20:19:58 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB708f375f767f25ed2a0ada54b652d2c776e415ea

Cleanup: Refactor reusable code into functions

New functions for :
* Calculating current zoom factor used for determining the grid
  resolution in UV/Image editor
* Calculating grid steps for determining the grid spacings in UV/Image
  editor

===

M   source/blender/draw/engines/overlay/overlay_grid.c
M   source/blender/editors/include/ED_image.h
M   source/blender/editors/space_image/image_draw.c

===

diff --git a/source/blender/draw/engines/overlay/overlay_grid.c 
b/source/blender/draw/engines/overlay/overlay_grid.c
index ca4065c72ad..3077ddd4ee3 100644
--- a/source/blender/draw/engines/overlay/overlay_grid.c
+++ b/source/blender/draw/engines/overlay/overlay_grid.c
@@ -70,29 +70,18 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata)
 copy_v3_fl3(
 shd->grid_size, (float)sima->tile_grid_shape[0], 
(float)sima->tile_grid_shape[1], 1.0f);
 
-/* For a NxN grid */
+/* For a NxN grid. Keep insync with value in initSnapSpatial() inside 
transform.c */
 int N = 4;
-float xzoom = (v2d->cur.xmax - v2d->cur.xmin) / ((float)(v2d->mask.xmax - 
v2d->mask.xmin));
-float yzoom = (v2d->cur.ymax - v2d->cur.ymin) / ((float)(v2d->mask.ymax - 
v2d->mask.ymin));
-/* Calculating average of xzoom and yzoom for accuracy. Using only xzoom 
or yzoom would have
- * been sufficient */
-shd->zoom_factor = (xzoom + yzoom) / 2.0f;
-/* grid begins to appear when the length of one grid unit is at least
- * (N^2) pixels in the UV/Image editor */
-shd->zoom_factor *= (N * N);
+shd->zoom_factor = ED_space_image_zoom_level(v2d, N);
 
 if (sima->flag & SI_DYNAMIC_GRID) {
   shd->grid_flag |= DYNAMIC_GRID;
-  for (int step = 0; step < 8; step++) {
-/* Temporary fix : dynamic_grid_size is not using the default value 
(=1) assignd in RNA */
-sima->dynamic_grid_size = (sima->dynamic_grid_size == 0) ? 1 : 
sima->dynamic_grid_size;
-shd->grid_steps[step] = powf(1, step) * (1.0f / 
((float)sima->dynamic_grid_size));
-  }
+  /* Temporary fix : dynamic_grid_size is not using the default value (=1) 
assignd in RNA */
+  sima->dynamic_grid_size = (sima->dynamic_grid_size == 0) ? 1 : 
sima->dynamic_grid_size;
+  ED_space_image_grid_steps(sima->dynamic_grid_size, shd->grid_steps, 
true);
 }
 else {
-  for (int step = 0; step < 8; step++) {
-shd->grid_steps[step] = powf(N, step) * (1.0f / (powf(N, 8)));
-  }
+  ED_space_image_grid_steps(N, shd->grid_steps, false);
 }
 return;
   }
diff --git a/source/blender/editors/include/ED_image.h 
b/source/blender/editors/include/ED_image.h
index ec525806b81..aa923bcf245 100644
--- a/source/blender/editors/include/ED_image.h
+++ b/source/blender/editors/include/ED_image.h
@@ -41,6 +41,13 @@ struct SpaceImage;
 struct bContext;
 struct wmOperator;
 struct wmWindowManager;
+struct View2D;
+
+/* image_draw.c */
+float ED_space_image_zoom_level(const struct View2D *v2d, const int 
grid_dimension);
+void ED_space_image_grid_steps(const int grid_dimension,
+   float grid_steps[8],
+   const bool is_dynamic_grid);
 
 /* image_edit.c, exported for transform */
 struct Image *ED_space_image(struct SpaceImage *sima);
diff --git a/source/blender/editors/space_image/image_draw.c 
b/source/blender/editors/space_image/image_draw.c
index dc693b25107..5b5ec236890 100644
--- a/source/blender/editors/space_image/image_draw.c
+++ b/source/blender/editors/space_image/image_draw.c
@@ -34,6 +34,7 @@
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
+#include "DNA_view2d_types.h"
 
 #include "PIL_time.h"
 
@@ -1049,3 +1050,32 @@ void draw_image_cache(const bContext *C, ARegion *region)
 ED_mask_draw_frames(mask, region, cfra, sfra, efra);
   }
 }
+
+float ED_space_image_zoom_level(const View2D *v2d, const int grid_dimension)
+{
+  float xzoom = (v2d->cur.xmax - v2d->cur.xmin) / ((float)(v2d->mask.xmax - 
v2d->mask.xmin));
+  float yzoom = (v2d->cur.ymax - v2d->cur.ymin) / ((float)(v2d->mask.ymax - 
v2d->mask.ymin));
+  /* Calculating average of xzoom and yzoom for accuracy. Using only xzoom or 
yzoom would have
+   * been sufficient */
+  float zoom_factor = (xzoom + yzoom) / 2.0f;
+  /* grid begins to appear when the length of one grid unit is at least (N^2) 
pixels in the
+   * UV/Image editor for a (NxN grid) */
+  zoom_factor *= (gr

[Bf-blender-cvs] [28c85e60cb9] soc-2021-uv-editor-improvements: Cleanup: Use struct pointer

2021-07-04 Thread Siddhartha Jejurkar
Commit: 28c85e60cb92b7a61acafd0492c0e9b9e4b36c27
Author: Siddhartha Jejurkar
Date:   Sun Jul 4 15:29:24 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB28c85e60cb92b7a61acafd0492c0e9b9e4b36c27

Cleanup: Use struct pointer

Replace struct variables to use pointers instead

===

M   source/blender/draw/engines/overlay/overlay_grid.c

===

diff --git a/source/blender/draw/engines/overlay/overlay_grid.c 
b/source/blender/draw/engines/overlay/overlay_grid.c
index 0431168700a..ca4065c72ad 100644
--- a/source/blender/draw/engines/overlay/overlay_grid.c
+++ b/source/blender/draw/engines/overlay/overlay_grid.c
@@ -63,7 +63,7 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata)
 
   if (pd->space_type == SPACE_IMAGE) {
 SpaceImage *sima = (SpaceImage *)draw_ctx->space_data;
-View2D v2d = draw_ctx->region->v2d;
+View2D *v2d = _ctx->region->v2d;
 
 shd->grid_flag = ED_space_image_has_buffer(sima) ? 0 : PLANE_IMAGE | 
SHOW_GRID;
 shd->grid_distance = 1.0f;
@@ -72,8 +72,8 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata)
 
 /* For a NxN grid */
 int N = 4;
-float xzoom = (v2d.cur.xmax - v2d.cur.xmin) / ((float)(v2d.mask.xmax - 
v2d.mask.xmin));
-float yzoom = (v2d.cur.ymax - v2d.cur.ymin) / ((float)(v2d.mask.ymax - 
v2d.mask.ymin));
+float xzoom = (v2d->cur.xmax - v2d->cur.xmin) / ((float)(v2d->mask.xmax - 
v2d->mask.xmin));
+float yzoom = (v2d->cur.ymax - v2d->cur.ymin) / ((float)(v2d->mask.ymax - 
v2d->mask.ymin));
 /* Calculating average of xzoom and yzoom for accuracy. Using only xzoom 
or yzoom would have
  * been sufficient */
 shd->zoom_factor = (xzoom + yzoom) / 2.0f;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [d615f4d65e4] soc-2021-uv-editor-improvements: Fix: Pack islands to area operator

2021-07-03 Thread Siddhartha Jejurkar
Commit: d615f4d65e44109d1843441e9b3c5f145901c3c7
Author: Siddhartha Jejurkar
Date:   Sat Jul 3 14:29:56 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rBd615f4d65e44109d1843441e9b3c5f145901c3c7

Fix: Pack islands to area operator

* Correct packing area coordinates for cases when user sets the maximum
  coordinates to be lower than the minimum coordinates
* Cancel operator when scale option is disabled and packing area is not
  big enough for selected islands. Also display warning message in UI
  when this happens

===

M   source/blender/blenlib/BLI_boxpack_2d.h
M   source/blender/blenlib/intern/boxpack_2d.c
M   source/blender/editors/include/ED_uvedit.h
M   source/blender/editors/uvedit/uvedit_islands.c
M   source/blender/editors/uvedit/uvedit_unwrap_ops.c

===

diff --git a/source/blender/blenlib/BLI_boxpack_2d.h 
b/source/blender/blenlib/BLI_boxpack_2d.h
index 5b70cd3f410..89339b66021 100644
--- a/source/blender/blenlib/BLI_boxpack_2d.h
+++ b/source/blender/blenlib/BLI_boxpack_2d.h
@@ -64,7 +64,7 @@ void BLI_box_pack_2d_fixedarea(struct ListBase *boxes,
int height,
struct ListBase *packed);
 
-void BLI_rect_pack_2d(BoxPack *boxarray,
+bool BLI_rect_pack_2d(BoxPack *boxarray,
   const uint len,
   const float rect_width,
   const float rect_height);
diff --git a/source/blender/blenlib/intern/boxpack_2d.c 
b/source/blender/blenlib/intern/boxpack_2d.c
index 1679da7fc13..bddb9878a36 100644
--- a/source/blender/blenlib/intern/boxpack_2d.c
+++ b/source/blender/blenlib/intern/boxpack_2d.c
@@ -786,14 +786,8 @@ void BLI_box_pack_2d_fixedarea(ListBase *boxes, int width, 
int height, ListBase
 }
 
 /* Similar implementation of BLI_box_pack_2d_fixedarea() that works with 
BoxPack array and float
- * variables.
- * A current problem with the algorithm is that boxes that do not fit are not 
packed (skipped), so
- * that finally causes those boxes to be placed at the bottom left position 
overlapping with other
- * boxes.
- * TODO : Fix this issue by setting a callback that cancels the operator (and 
possibly prints an
- * error message saying the area is too small for packing islands without 
scaling) when a
- * particular box does not fit any empty space */
-void BLI_rect_pack_2d(BoxPack *boxarray,
+ * variables */
+bool BLI_rect_pack_2d(BoxPack *boxarray,
   const uint len,
   const float rect_width,
   const float rect_height)
@@ -802,11 +796,19 @@ void BLI_rect_pack_2d(BoxPack *boxarray,
   RectSizeBoxPack *full_rect = MEM_callocN(sizeof(RectSizeBoxPack), __func__);
   full_rect->w = rect_width;
   full_rect->h = rect_height;
+  bool is_box_packed;
 
   BLI_addhead(, full_rect);
+  /* CHECK : Sorting is probably used incorrectly here */
   qsort(boxarray, (size_t)len, sizeof(BoxPack), box_areasort);
 
+  /* Rotating islands in uvedits_islands.c doesn't work well with this 
algorithm
+   * TODO : Implement heuristic for rotating islands - Rotate islands if they 
don't fit in any
+   * empty space, but can fit if they are rotated. A boolean might be needed 
per island to check if
+   * islands need to be rotated when they are translated in uvedit_islands.c */
+
   for (uint i = 0; i < len; i++) {
+is_box_packed = false;
 LISTBASE_FOREACH (RectSizeBoxPack *, space, ) {
   /* Skip this space if it's too small. */
   if (boxarray[i].w > space->w || boxarray[i].h > space->h) {
@@ -816,6 +818,7 @@ void BLI_rect_pack_2d(BoxPack *boxarray,
   /* Pack this box into this space. */
   boxarray[i].x = space->x;
   boxarray[i].y = space->y;
+  is_box_packed = true;
 
   if (boxarray[i].w == space->w && boxarray[i].h == space->h) {
 /* Box exactly fills space, so just remove the space. */
@@ -867,7 +870,14 @@ void BLI_rect_pack_2d(BoxPack *boxarray,
 
   break;
 }
+/* Packing area not big enough to pack all boxes */
+if (!is_box_packed) {
+  BLI_freelistN();
+  return false;
+}
   }
 
+  /* All boxes packed successfully */
   BLI_freelistN();
+  return true;
 }
\ No newline at end of file
diff --git a/source/blender/editors/include/ED_uvedit.h 
b/source/blender/editors/include/ED_uvedit.h
index 2dc9635a494..269590197ee 100644
--- a/source/blender/editors/include/ED_uvedit.h
+++ b/source/blender/editors/include/ED_uvedit.h
@@ -253,7 +253,7 @@ void ED_uvedit_pack_islands_multi(const struct Scene *scene,
   bool use_target,
   const struct UVPackIsland_Params *params);
 
-void ED_uvedit_pack_islands_to_area_multi(const struct Scene *scene,
+bool ED_uvedit_pack_island

[Bf-blender-cvs] [eb88ce51468] soc-2021-uv-editor-improvements: Merge branch 'master' into soc-2021-uv-editor-improvements

2021-07-01 Thread Siddhartha Jejurkar
Commit: eb88ce51468fad9e2cff07eaaef8bd06582d367c
Author: Siddhartha Jejurkar
Date:   Thu Jul 1 18:29:10 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rBeb88ce51468fad9e2cff07eaaef8bd06582d367c

Merge branch 'master' into soc-2021-uv-editor-improvements

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [1f65001caee] soc-2021-uv-editor-improvements: Change the max limit for Dynamic grid

2021-07-01 Thread Siddhartha Jejurkar
Commit: 1f65001caee2b6aa43995bc5d6354145a0cef033
Author: Siddhartha Jejurkar
Date:   Thu Jul 1 12:02:33 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB1f65001caee2b6aa43995bc5d6354145a0cef033

Change the max limit for Dynamic grid

The max limit for dynamic grid was set at 12. This commit changes that
to 5000

===

M   source/blender/makesrna/intern/rna_space.c

===

diff --git a/source/blender/makesrna/intern/rna_space.c 
b/source/blender/makesrna/intern/rna_space.c
index c78b6c9328c..e07f16bd194 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -3448,7 +3448,7 @@ static void rna_def_space_image_uv(BlenderRNA *brna)
   prop = RNA_def_property(srna, "dynamic_grid_size", PROP_INT, PROP_NONE);
   RNA_def_property_int_sdna(prop, NULL, "dynamic_grid_size");
   RNA_def_property_int_default(prop, 1);
-  RNA_def_property_range(prop, 1, 12);
+  RNA_def_property_range(prop, 1, 5000);
   RNA_def_property_ui_text(
   prop, "Dynamic Grid Size", "How many grid units in UV space make one UV 
Unit");
   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, NULL);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [8a57e48a8f5] soc-2021-uv-editor-improvements: Minor Cleanup

2021-06-30 Thread Siddhartha Jejurkar
Commit: 8a57e48a8f51de40ec5957fa974a320e005e7511
Author: Siddhartha Jejurkar
Date:   Wed Jun 30 21:20:18 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB8a57e48a8f51de40ec5957fa974a320e005e7511

Minor Cleanup

* Remove printf statements
* Use enums

===

M   source/blender/draw/engines/overlay/overlay_grid.c
M   source/blender/editors/uvedit/uvedit_unwrap_ops.c

===

diff --git a/source/blender/draw/engines/overlay/overlay_grid.c 
b/source/blender/draw/engines/overlay/overlay_grid.c
index ab2dcb160b0..0431168700a 100644
--- a/source/blender/draw/engines/overlay/overlay_grid.c
+++ b/source/blender/draw/engines/overlay/overlay_grid.c
@@ -81,9 +81,6 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata)
  * (N^2) pixels in the UV/Image editor */
 shd->zoom_factor *= (N * N);
 
-printf("xzoom = %f\n", xzoom);
-printf("zoom Factor = %f\n\n", shd->zoom_factor);
-
 if (sima->flag & SI_DYNAMIC_GRID) {
   shd->grid_flag |= DYNAMIC_GRID;
   for (int step = 0; step < 8; step++) {
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c 
b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 03a12c4dafb..745a242050f 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -1136,8 +1136,8 @@ static void pack_islands_draw(bContext *C, wmOperator *op)
 void UV_OT_pack_islands(wmOperatorType *ot)
 {
   static const EnumPropertyItem pack_to[] = {
-  {0, "CLOSEST_UDIM", 0, "Closest UDIM", "Pack islands to closest UDIM"},
-  {1, "SPECIFIED_UDIM", 0, "Specified UDIM", "Pack islands to specified 
UDIM"},
+  {CLOSEST_UDIM, "CLOSEST_UDIM", 0, "Closest UDIM", "Pack islands to 
closest UDIM"},
+  {SPECIFIED_UDIM, "SPECIFIED_UDIM", 0, "Specified UDIM", "Pack islands to 
specified UDIM"},
   {0, NULL, 0, NULL, NULL},
   };
   /* identifiers */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [be270d8c8a2] soc-2021-uv-editor-improvements: Merge branch 'master' into soc-2021-uv-editor-improvements

2021-06-30 Thread Siddhartha Jejurkar
Commit: be270d8c8a2f3b5333cff373e4a96748d919a2a7
Author: Siddhartha Jejurkar
Date:   Wed Jun 30 18:45:04 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rBbe270d8c8a2f3b5333cff373e4a96748d919a2a7

Merge branch 'master' into soc-2021-uv-editor-improvements

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [39aa0062605] soc-2021-uv-editor-improvements: UV: Replace default grid with subdividing grid

2021-06-30 Thread Siddhartha Jejurkar
Commit: 39aa0062605635be64d5422e54fad2a4ec08d708
Author: Siddhartha Jejurkar
Date:   Wed Jun 30 11:55:18 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB39aa0062605635be64d5422e54fad2a4ec08d708

UV: Replace default grid with subdividing grid

Replaces the default static grid with a dynamically subdividing grid.
This means that zooming in the UV editor will add more divisions to
the grid and vice versa when zooming out.

===

M   source/blender/draw/engines/overlay/overlay_grid.c
M   source/blender/draw/engines/overlay/overlay_private.h
M   source/blender/draw/engines/overlay/shaders/grid_frag.glsl

===

diff --git a/source/blender/draw/engines/overlay/overlay_grid.c 
b/source/blender/draw/engines/overlay/overlay_grid.c
index bd092062e9c..ab2dcb160b0 100644
--- a/source/blender/draw/engines/overlay/overlay_grid.c
+++ b/source/blender/draw/engines/overlay/overlay_grid.c
@@ -23,6 +23,7 @@
 #include "DRW_render.h"
 
 #include "DNA_camera_types.h"
+#include "DNA_screen_types.h"
 
 #include "DEG_depsgraph_query.h"
 
@@ -46,6 +47,7 @@ enum {
   GRID_BACK = (1 << 9),
   GRID_CAMERA = (1 << 10),
   PLANE_IMAGE = (1 << 11),
+  DYNAMIC_GRID = (1 << 12),
 };
 
 void OVERLAY_grid_init(OVERLAY_Data *vedata)
@@ -61,18 +63,38 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata)
 
   if (pd->space_type == SPACE_IMAGE) {
 SpaceImage *sima = (SpaceImage *)draw_ctx->space_data;
+View2D v2d = draw_ctx->region->v2d;
+
 shd->grid_flag = ED_space_image_has_buffer(sima) ? 0 : PLANE_IMAGE | 
SHOW_GRID;
 shd->grid_distance = 1.0f;
 copy_v3_fl3(
 shd->grid_size, (float)sima->tile_grid_shape[0], 
(float)sima->tile_grid_shape[1], 1.0f);
-for (int step = 0; step < 8; step++) {
-  if (sima->flag & SI_DYNAMIC_GRID) {
+
+/* For a NxN grid */
+int N = 4;
+float xzoom = (v2d.cur.xmax - v2d.cur.xmin) / ((float)(v2d.mask.xmax - 
v2d.mask.xmin));
+float yzoom = (v2d.cur.ymax - v2d.cur.ymin) / ((float)(v2d.mask.ymax - 
v2d.mask.ymin));
+/* Calculating average of xzoom and yzoom for accuracy. Using only xzoom 
or yzoom would have
+ * been sufficient */
+shd->zoom_factor = (xzoom + yzoom) / 2.0f;
+/* grid begins to appear when the length of one grid unit is at least
+ * (N^2) pixels in the UV/Image editor */
+shd->zoom_factor *= (N * N);
+
+printf("xzoom = %f\n", xzoom);
+printf("zoom Factor = %f\n\n", shd->zoom_factor);
+
+if (sima->flag & SI_DYNAMIC_GRID) {
+  shd->grid_flag |= DYNAMIC_GRID;
+  for (int step = 0; step < 8; step++) {
 /* Temporary fix : dynamic_grid_size is not using the default value 
(=1) assignd in RNA */
 sima->dynamic_grid_size = (sima->dynamic_grid_size == 0) ? 1 : 
sima->dynamic_grid_size;
 shd->grid_steps[step] = powf(1, step) * (1.0f / 
((float)sima->dynamic_grid_size));
   }
-  else {
-shd->grid_steps[step] = powf(4, step) * (1.0f / 16.0f);
+}
+else {
+  for (int step = 0; step < 8; step++) {
+shd->grid_steps[step] = powf(N, step) * (1.0f / (powf(N, 8)));
   }
 }
 return;
@@ -245,6 +267,7 @@ void OVERLAY_grid_cache_init(OVERLAY_Data *vedata)
 
   grp = DRW_shgroup_create(sh, psl->grid_ps);
   DRW_shgroup_uniform_int(grp, "gridFlag", >grid_flag, 1);
+  DRW_shgroup_uniform_float_copy(grp, "zoomFactor", shd->zoom_factor);
   DRW_shgroup_uniform_vec3(grp, "planeAxes", shd->grid_axes, 1);
   DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
   DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", >depth);
diff --git a/source/blender/draw/engines/overlay/overlay_private.h 
b/source/blender/draw/engines/overlay/overlay_private.h
index a48b46a61fc..8c5c8613585 100644
--- a/source/blender/draw/engines/overlay/overlay_private.h
+++ b/source/blender/draw/engines/overlay/overlay_private.h
@@ -142,6 +142,7 @@ typedef struct OVERLAY_ShadingData {
   float grid_steps[8];
   float inv_viewport_size[2];
   float grid_line_size;
+  float zoom_factor; /* Length per pixel in the UV editor viewport */
   int grid_flag;
   int zpos_flag;
   int zneg_flag;
diff --git a/source/blender/draw/engines/overlay/shaders/grid_frag.glsl 
b/source/blender/draw/engines/overlay/shaders/grid_frag.glsl
index 3220adbff36..81e3f341a4f 100644
--- a/source/blender/draw/engines/overlay/shaders/grid_frag.glsl
+++ b/source/blender/draw/engines/overlay/shaders/grid_frag.glsl
@@ -15,6 +15,7 @@ uniform float lineKernel = 0.0;
 uniform sampler2D depthBuffer;
 
 uniform int gridFlag;
+uniform float zoomFactor;
 
 #define STEPS_LEN 8
 uniform float gridSteps[STEPS_LEN] = float[](0.001,

[Bf-blender-cvs] [1965df11f44] soc-2021-uv-editor-improvements: UV: Dynamic Grid

2021-06-26 Thread Siddhartha Jejurkar
Commit: 1965df11f4435c8695f3b9711594729ee6073e67
Author: Siddhartha Jejurkar
Date:   Sat Jun 26 14:02:50 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB1965df11f4435c8695f3b9711594729ee6073e67

UV: Dynamic Grid

Adds the option to replace the default grid in the UV editor with a NxN
grid.

Refer T78389

===

M   release/scripts/startup/bl_ui/space_image.py
M   source/blender/draw/engines/overlay/overlay_grid.c
M   source/blender/makesdna/DNA_space_types.h
M   source/blender/makesrna/intern/rna_space.c

===

diff --git a/release/scripts/startup/bl_ui/space_image.py 
b/release/scripts/startup/bl_ui/space_image.py
index 54b7dab5d1b..e3947790ff3 100644
--- a/release/scripts/startup/bl_ui/space_image.py
+++ b/release/scripts/startup/bl_ui/space_image.py
@@ -1474,6 +1474,35 @@ class IMAGE_PT_udim_grid(Panel):
 col = layout.column()
 col.prop(uvedit, "tile_grid_shape", text="Grid Shape")
 
+class IMAGE_PT_dynamic_grid(Panel):
+bl_space_type = 'IMAGE_EDITOR'
+bl_region_type = 'UI'
+bl_category = "View"
+bl_label = "Dynamic Grid"
+
+@classmethod
+def poll(cls, context):
+sima = context.space_data
+#Grid becomes irrelevant once an image is loaded in the UV Editor
+return sima.show_uvedit and sima.image is None
+
+#Not exposed in the Image editor and disabled by default
+def draw_header(self, context):
+sima = context.space_data
+uvedit = sima.uv_editor
+self.layout.prop(uvedit, "use_dynamic_grid", text="")
+
+def draw(self, context):
+layout = self.layout
+
+sima = context.space_data
+uvedit = sima.uv_editor
+
+layout.use_property_split = True
+layout.use_property_decorate = False
+
+col = layout.column()
+col.prop(uvedit, "dynamic_grid_size", text="Grid Size")
 
 class IMAGE_PT_overlay(Panel):
 bl_space_type = 'IMAGE_EDITOR'
@@ -1659,6 +1688,7 @@ classes = (
 IMAGE_PT_uv_cursor,
 IMAGE_PT_annotation,
 IMAGE_PT_udim_grid,
+IMAGE_PT_dynamic_grid,
 IMAGE_PT_overlay,
 IMAGE_PT_overlay_uv_edit,
 IMAGE_PT_overlay_uv_edit_geometry,
diff --git a/source/blender/draw/engines/overlay/overlay_grid.c 
b/source/blender/draw/engines/overlay/overlay_grid.c
index 5bb157ed081..bd092062e9c 100644
--- a/source/blender/draw/engines/overlay/overlay_grid.c
+++ b/source/blender/draw/engines/overlay/overlay_grid.c
@@ -66,7 +66,14 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata)
 copy_v3_fl3(
 shd->grid_size, (float)sima->tile_grid_shape[0], 
(float)sima->tile_grid_shape[1], 1.0f);
 for (int step = 0; step < 8; step++) {
-  shd->grid_steps[step] = powf(4, step) * (1.0f / 16.0f);
+  if (sima->flag & SI_DYNAMIC_GRID) {
+/* Temporary fix : dynamic_grid_size is not using the default value 
(=1) assignd in RNA */
+sima->dynamic_grid_size = (sima->dynamic_grid_size == 0) ? 1 : 
sima->dynamic_grid_size;
+shd->grid_steps[step] = powf(1, step) * (1.0f / 
((float)sima->dynamic_grid_size));
+  }
+  else {
+shd->grid_steps[step] = powf(4, step) * (1.0f / 16.0f);
+  }
 }
 return;
   }
diff --git a/source/blender/makesdna/DNA_space_types.h 
b/source/blender/makesdna/DNA_space_types.h
index 2b9a4f7ba1d..7376e87236b 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -1263,6 +1263,8 @@ typedef struct SpaceImage {
   float uv_opacity;
 
   int tile_grid_shape[2];
+  int dynamic_grid_size; /* Dynamic grid size in UV editor */
+  char _pad3[4];
 
   MaskSpaceInfo mask_info;
   SpaceImageOverlay overlay;
@@ -1318,7 +1320,9 @@ typedef enum eSpaceImage_Flag {
   SI_FLAG_UNUSED_7 = (1 << 7), /* cleared */
   SI_FLAG_UNUSED_8 = (1 << 8), /* cleared */
   SI_COORDFLOATS = (1 << 9),
-  SI_FLAG_UNUSED_10 = (1 << 10),
+
+  /* Replacing SI_FLAG_UNUSED_10, unused in versioning code */
+  SI_DYNAMIC_GRID = (1 << 10),
   SI_LIVE_UNWRAP = (1 << 11),
   SI_USE_ALPHA = (1 << 12),
   SI_SHOW_ALPHA = (1 << 13),
diff --git a/source/blender/makesrna/intern/rna_space.c 
b/source/blender/makesrna/intern/rna_space.c
index 18878040128..7aa27767c49 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -3440,6 +3440,19 @@ static void rna_def_space_image_uv(BlenderRNA *brna)
   prop, "Tile Grid Shape", "How many tiles will be shown in the 
background");
   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, NULL);
 
+  prop = RNA_def_property(srna, "use_dynamic_grid", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop

[Bf-blender-cvs] [ad5983895a0] soc-2021-uv-editor-improvements: Merge branch 'master' into soc-2021-uv-editor-improvements

2021-06-25 Thread Siddhartha Jejurkar
Commit: ad5983895a072c293b062c92d2cc0689676b2160
Author: Siddhartha Jejurkar
Date:   Fri Jun 25 19:11:12 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rBad5983895a072c293b062c92d2cc0689676b2160

Merge branch 'master' into soc-2021-uv-editor-improvements

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [37e185980a9] soc-2021-uv-editor-improvements: UV: Display packing area coordinates

2021-06-23 Thread Siddhartha Jejurkar
Commit: 37e185980a94067d97964d2d9955975b75501ec7
Author: Siddhartha Jejurkar
Date:   Wed Jun 23 21:10:59 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB37e185980a94067d97964d2d9955975b75501ec7

UV: Display packing area coordinates

Adds properties for displaying packing area coordinates in the pack
islands to area operator.
Also fixes the issue of modified packing coordinates when the user zooms
in/out in the editor before redoing the operator from the properties
panel in UI.

===

M   source/blender/editors/uvedit/uvedit_unwrap_ops.c

===

diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c 
b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 47c543c4635..e7bbb182ddf 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -1184,14 +1184,34 @@ static int pack_islands_to_area_exec(bContext *C, 
wmOperator *op)
   Object **objects = 
BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
   view_layer, CTX_wm_view3d(C), _len);
 
-  /* User-defined area for packing */
-  rctf bounds;
-  WM_operator_properties_border_to_rctf(op, );
-  UI_view2d_region_to_view_rctf(>v2d, , );
-
-  /* Store the bounding coordinates for the user-defined area */
-  float min_co[2] = {bounds.xmin, bounds.ymin};
-  float max_co[2] = {bounds.xmax, bounds.ymax};
+  /* Packing area coordinates */
+  float min_co[2] = {0.0f, 0.0f};
+  float max_co[2] = {1.0f, 1.0f};
+
+  /* Fixes the issue of modified packing coordinates when user reuses the 
operator from the
+   * properties panel after zooming in/out in the UV editor */
+  if (RNA_struct_property_is_set(op->ptr, "box_min_co") ||
+  RNA_struct_property_is_set(op->ptr, "box_max_co") ||
+  RNA_struct_property_is_set(op->ptr, "rotate") ||
+  RNA_struct_property_is_set(op->ptr, "scale") ||
+  RNA_struct_property_is_set(op->ptr, "margin")) {
+RNA_float_get_array(op->ptr, "box_min_co", min_co);
+RNA_float_get_array(op->ptr, "box_max_co", max_co);
+  }
+  /* MISSING : Implement a way to clamp box coordinates properly so that 
invalid cases such as
+   * (max_co < min_co) are handled */
+  else {
+rctf bounds;
+WM_operator_properties_border_to_rctf(op, );
+UI_view2d_region_to_view_rctf(>v2d, , );
+/* Bounding coordinates for the user-defined area */
+min_co[0] = bounds.xmin;
+min_co[1] = bounds.ymin;
+max_co[0] = bounds.xmax;
+max_co[1] = bounds.ymax;
+RNA_float_set_array(op->ptr, "box_min_co", min_co);
+RNA_float_set_array(op->ptr, "box_max_co", max_co);
+  }
 
   /* Keeping a lower bound of 0.001 for user-defined space, smaller than that 
and the UVs won't be
* visible in the UV editor
@@ -1278,6 +1298,30 @@ void UV_OT_pack_islands_to_area(wmOperatorType *ot)
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
   /* RNA properties */
+  /* Max coordinates of the packing area */
+  static float default_max[2] = {1.0f, 1.0f};
+  RNA_def_float_vector(ot->srna,
+   "box_max_co",
+   2,
+   default_max,
+   -100.0f,
+   100.0f,
+   "Maximum",
+   "Maximum coordinates for the packing area",
+   -100.0f,
+   100.0f);
+  /* Min coordinates of packing area */
+  static float default_min[2] = {0.0f, 0.0f};
+  RNA_def_float_vector(ot->srna,
+   "box_min_co",
+   2,
+   default_min,
+   -100.0f,
+   100.0f,
+   "Minimum",
+   "Minimum coordinates for the packing area",
+   -100.0f,
+   100.0f);
   RNA_def_boolean(ot->srna, "rotate", true, "Rotate", "Rotate islands for best 
fit");
   RNA_def_boolean(ot->srna, "scale", true, "Scale", "Scale islands for best 
fit");
   RNA_def_float_factor(

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [7e1e4889c60] soc-2021-uv-editor-improvements: Fix: Release memory before cancelling operator

2021-06-23 Thread Siddhartha Jejurkar
Commit: 7e1e4889c603a853e39241bceaea0eee5e20d8d5
Author: Siddhartha Jejurkar
Date:   Wed Jun 23 20:58:07 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB7e1e4889c603a853e39241bceaea0eee5e20d8d5

Fix: Release memory before cancelling operator

===

M   source/blender/editors/uvedit/uvedit_unwrap_ops.c

===

diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c 
b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index ce7e905a412..47c543c4635 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -1197,6 +1197,7 @@ static int pack_islands_to_area_exec(bContext *C, 
wmOperator *op)
* visible in the UV editor
* NOTE : Could be removed/changed */
   if ((max_co[0] - min_co[0]) <= 0.001f || (max_co[1] - min_co[1]) <= 0.001f) {
+MEM_freeN(objects);
 return OPERATOR_CANCELLED;
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [62d2e8130f0] soc-2021-uv-editor-improvements: Cleanup : UV pack operators

2021-06-23 Thread Siddhartha Jejurkar
Commit: 62d2e8130f0baf2244e4d4e77c5a60164241883a
Author: Siddhartha Jejurkar
Date:   Wed Jun 23 20:30:07 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB62d2e8130f0baf2244e4d4e77c5a60164241883a

Cleanup : UV pack operators

* Remove printf statements
* Use float constants instead of double
* Cleanup comments
* enum to make code better readable

===

M   source/blender/editors/uvedit/uvedit_unwrap_ops.c

===

diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c 
b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 51634e9328a..ce7e905a412 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -1007,6 +1007,12 @@ static void uvedit_pack_islands_multi(const Scene *scene,
   }
 }
 
+/* Packing targets */
+enum {
+  CLOSEST_UDIM = 0,
+  SPECIFIED_UDIM = 1,
+};
+
 static int pack_islands_exec(bContext *C, wmOperator *op)
 {
   ViewLayer *view_layer = CTX_data_view_layer(C);
@@ -1028,7 +1034,7 @@ static int pack_islands_exec(bContext *C, wmOperator *op)
   bool rotate = RNA_boolean_get(op->ptr, "rotate");
 
   /* Check if specified UDIM is valid - specified tile exists in the udim grid 
or tiled image */
-  if (RNA_enum_get(op->ptr, "packTo") == 1) {
+  if (RNA_enum_get(op->ptr, "packTo") == SPECIFIED_UDIM) {
 if (RNA_struct_property_is_set(op->ptr, "target_udim")) {
   int target_udim = RNA_int_get(op->ptr, "target_udim");
 
@@ -1037,7 +1043,6 @@ static int pack_islands_exec(bContext *C, wmOperator *op)
 target_udim -= 1001;
 const int target_x = (target_udim % 10) + 1;
 const int target_y = (target_udim / 10) + 1;
-
 if (target_x <= sima->tile_grid_shape[0] && target_y <= 
sima->tile_grid_shape[1]) {
   scene->toolsettings->target_udim = RNA_int_get(op->ptr, 
"target_udim");
 }
@@ -1049,9 +1054,7 @@ static int pack_islands_exec(bContext *C, wmOperator *op)
   /* If tiled image present then check if target_udim is valid */
   else if (image && is_tiled_image) {
 RNA_int_set(op->ptr, "target_udim", scene->toolsettings->target_udim);
-
 LISTBASE_FOREACH (const ImageTile *, tile, >tiles) {
-
   if (target_udim == tile->tile_number) {
 scene->toolsettings->target_udim = target_udim;
 RNA_int_set(op->ptr, "target_udim", target_udim);
@@ -1067,7 +1070,6 @@ static int pack_islands_exec(bContext *C, wmOperator *op)
   }
 }
 
-/*  */
 else {
   scene->toolsettings->target_udim = RNA_int_get(op->ptr, "target_udim");
 }
@@ -1108,7 +1110,6 @@ static int pack_islands_exec(bContext *C, wmOperator *op)
});
 
   MEM_freeN(objects);
-
   return OPERATOR_FINISHED;
 }
 
@@ -1122,8 +1123,9 @@ static void pack_islands_draw(bContext *C, wmOperator *op)
 
   col = uiLayoutColumn(layout, false);
 
+  /* Expose target UDIM prop only if packing target is specified UDIM */
   uiItemR(col, op->ptr, "packTo", 0, NULL, 0);
-  if (RNA_enum_get(op->ptr, "packTo") == 1) {
+  if (RNA_enum_get(op->ptr, "packTo") == SPECIFIED_UDIM) {
 uiItemR(col, op->ptr, "target_udim", 0, NULL, 0);
   }
 
@@ -1151,7 +1153,7 @@ void UV_OT_pack_islands(wmOperatorType *ot)
   ot->ui = pack_islands_draw;
 
   /* properties */
-  RNA_def_enum(ot->srna, "packTo", pack_to, 0, "Pack to", "");
+  RNA_def_enum(ot->srna, "packTo", pack_to, CLOSEST_UDIM, "Pack to", "");
   RNA_def_boolean(ot->srna, "rotate", true, "Rotate", "Rotate islands for best 
fit");
   RNA_def_int(ot->srna,
   "target_udim",
@@ -1179,7 +1181,6 @@ static int pack_islands_to_area_exec(bContext *C, 
wmOperator *op)
   ARegion *region = CTX_wm_region(C);
 
   uint objects_len = 0;
-  /* Get reference to objects currently in edit mode */
   Object **objects = 
BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
   view_layer, CTX_wm_view3d(C), _len);
 
@@ -1195,14 +1196,10 @@ static int pack_islands_to_area_exec(bContext *C, 
wmOperator *op)
   /* Keeping a lower bound of 0.001 for user-defined space, smaller than that 
and the UVs won't be
* visible in the UV editor
* NOTE : Could be removed/changed */
-  if ((max_co[0] - min_co[0]) <= 0.001 || (max_co[1] - min_co[1]) <= 0.001) {
+  if ((max_co[0] - min_co[0]) <= 0.001f || (max_co[1] - min_co[1]) <= 0.001f) {
 return OPERATOR_CANCELLED;
   }
 
-  /* Check : packing area coordinates */
-  printf("Bottom-left coordinates : (%f,%f) \n", b

[Bf-blender-cvs] [2b37edebdff] soc-2021-uv-editor-improvements: Merge branch 'master' into soc-2021-uv-editor-improvements

2021-06-21 Thread Siddhartha Jejurkar
Commit: 2b37edebdfff71ec0ab10398b47da480e8fb27e6
Author: Siddhartha Jejurkar
Date:   Mon Jun 21 19:10:47 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB2b37edebdfff71ec0ab10398b47da480e8fb27e6

Merge branch 'master' into soc-2021-uv-editor-improvements

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [e5ab28d3921] soc-2021-uv-editor-improvements: UV : Pack islands to box area

2021-06-19 Thread Siddhartha Jejurkar
Commit: e5ab28d3921e77bac464c717610e2bf1b5c58b5c
Author: Siddhartha Jejurkar
Date:   Sat Jun 19 22:10:34 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rBe5ab28d3921e77bac464c717610e2bf1b5c58b5c

UV : Pack islands to box area

Adds a new operator to the UV editor - Pack islands to area
Allows the users to pack selected UV islands to a specified
area in the UV editor

Refer T78398

===

M   release/scripts/startup/bl_ui/space_image.py
M   source/blender/blenlib/BLI_boxpack_2d.h
M   source/blender/blenlib/intern/boxpack_2d.c
M   source/blender/editors/include/ED_uvedit.h
M   source/blender/editors/uvedit/uvedit_intern.h
M   source/blender/editors/uvedit/uvedit_islands.c
M   source/blender/editors/uvedit/uvedit_ops.c
M   source/blender/editors/uvedit/uvedit_unwrap_ops.c
M   source/blender/windowmanager/intern/wm_operators.c

===

diff --git a/release/scripts/startup/bl_ui/space_image.py 
b/release/scripts/startup/bl_ui/space_image.py
index 3fafa328289..54b7dab5d1b 100644
--- a/release/scripts/startup/bl_ui/space_image.py
+++ b/release/scripts/startup/bl_ui/space_image.py
@@ -436,6 +436,7 @@ class IMAGE_MT_uvs(Menu):
 layout.separator()
 
 layout.operator("uv.pack_islands")
+layout.operator("uv.pack_islands_to_area")
 layout.operator("uv.average_islands_scale")
 
 layout.separator()
diff --git a/source/blender/blenlib/BLI_boxpack_2d.h 
b/source/blender/blenlib/BLI_boxpack_2d.h
index 7e347d0b0d7..5b70cd3f410 100644
--- a/source/blender/blenlib/BLI_boxpack_2d.h
+++ b/source/blender/blenlib/BLI_boxpack_2d.h
@@ -52,11 +52,23 @@ typedef struct FixedSizeBoxPack {
   int w, h;
 } FixedSizeBoxPack;
 
+/* Similar to FixedSizeBoxPack. Uses float variables */
+typedef struct RectSizeBoxPack {
+  struct RectSizeBoxPack *next, *prev;
+  float x, y;
+  float w, h;
+} RectSizeBoxPack;
+
 void BLI_box_pack_2d_fixedarea(struct ListBase *boxes,
int width,
int height,
struct ListBase *packed);
 
+void BLI_rect_pack_2d(BoxPack *boxarray,
+  const uint len,
+  const float rect_width,
+  const float rect_height);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenlib/intern/boxpack_2d.c 
b/source/blender/blenlib/intern/boxpack_2d.c
index 84b3f728884..4f2d9747975 100644
--- a/source/blender/blenlib/intern/boxpack_2d.c
+++ b/source/blender/blenlib/intern/boxpack_2d.c
@@ -784,3 +784,90 @@ void BLI_box_pack_2d_fixedarea(ListBase *boxes, int width, 
int height, ListBase
 
   BLI_freelistN();
 }
+
+/* Similar implementation of BLI_box_pack_2d_fixedarea() that works with 
BoxPack array and float
+ * variables.
+ * A current problem with the algorithm is that boxes that do not fit are not 
packed (skipped), so
+ * that finally causes those boxes to be placed at the bottom left position 
overlapping with other
+ * boxes.
+ * TODO : Fix this issue by setting a callback that cancels the operator (and 
possibly prints an
+ * error message saying the area is too small for packing islands without 
scaling) when a
+ * particular box does not fit any empty space */
+void BLI_rect_pack_2d(BoxPack *boxarray,
+  const uint len,
+  const float rect_width,
+  const float rect_height)
+{
+  ListBase spaces = {NULL};
+  RectSizeBoxPack *full_rect = MEM_callocN(sizeof(RectSizeBoxPack), __func__);
+  full_rect->w = rect_width;
+  full_rect->h = rect_height;
+
+  BLI_addhead(, full_rect);
+  qsort(boxarray, (size_t)len, sizeof(BoxPack), box_areasort);
+
+  for (uint i = 0; i < len; i++) {
+LISTBASE_FOREACH (RectSizeBoxPack *, space, ) {
+  /* Skip this space if it's too small. */
+  if (boxarray[i].w > space->w || boxarray[i].h > space->h) {
+continue;
+  }
+
+  /* Pack this box into this space. */
+  boxarray[i].x = space->x;
+  boxarray[i].y = space->y;
+
+  if (boxarray[i].w == space->w && boxarray[i].h == space->h) {
+/* Box exactly fills space, so just remove the space. */
+BLI_remlink(, space);
+MEM_freeN(space);
+  }
+  else if (boxarray[i].w == space->w) {
+/* Box fills the entire width, so we can just contract the box
+ * to the upper part that remains. */
+space->y += boxarray[i].h;
+space->h -= boxarray[i].h;
+  }
+  else if (boxarray[i].h == space->h) {
+/* Box fills the entire height, so we can just contract the box
+ * to the right part that remains. */
+space->x += boxarray[i].w;
+space->w -= boxarray[i].w;
+  }
+  else {
+/* Split 

[Bf-blender-cvs] [2771b931b57] soc-2021-uv-editor-improvements: Merge branch 'master' into soc-2021-uv-editor-improvements

2021-06-17 Thread Siddhartha Jejurkar
Commit: 2771b931b57cb01a8652ee063b22ddb800f0b232
Author: Siddhartha Jejurkar
Date:   Thu Jun 17 14:12:33 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB2771b931b57cb01a8652ee063b22ddb800f0b232

Merge branch 'master' into soc-2021-uv-editor-improvements

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [f76eca3af22] soc-2021-uv-editor-improvements: Merge branch 'master' into soc-2021-uv-editor-improvements

2021-06-16 Thread Siddhartha Jejurkar
Commit: f76eca3af22108ae813804bdb437edd4b868d5fc
Author: Siddhartha Jejurkar
Date:   Mon Jun 14 17:14:18 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rBf76eca3af22108ae813804bdb437edd4b868d5fc

Merge branch 'master' into soc-2021-uv-editor-improvements

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [279a67ecc8f] soc-2021-uv-editor-improvements: Minor fix : Correct calculation of nearest UDIM

2021-06-11 Thread Siddhartha Jejurkar
Commit: 279a67ecc8f012adb8b0485472048e096024edcf
Author: Siddhartha Jejurkar
Date:   Fri Jun 11 20:50:38 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB279a67ecc8f012adb8b0485472048e096024edcf

Minor fix : Correct calculation of nearest UDIM

Corrects the logic for calculating the distance between selected UVs and
UDIM tiles

===

M   source/blender/blenkernel/intern/image.c

===

diff --git a/source/blender/blenkernel/intern/image.c 
b/source/blender/blenkernel/intern/image.c
index 2f7e2b41a73..6db4b7b1dd9 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -748,13 +748,15 @@ int BKE_image_find_nearest_tile(const Image *image, const 
float co[2])
   LISTBASE_FOREACH (const ImageTile *, tile, >tiles) {
 const int tile_index = tile->tile_number - 1001;
 /* Coordinates of the current tile. */
-const float tile_index_co[2] = {tile_index % 10, tile_index / 10};
+float tile_index_co[2] = {tile_index % 10, tile_index / 10};
 
 if (equals_v2v2(co_floor, tile_index_co)) {
   return tile->tile_number;
 }
 
-/* Distance between co[2] and UDIM tile. */
+/* Distance between co[2] and center of UDIM tile. */
+tile_index_co[0] += 0.5f;
+tile_index_co[1] += 0.5f;
 const float dist_sq = len_squared_v2v2(tile_index_co, co);
 
 if (dist_sq < dist_best_sq) {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [1a890011516] soc-2021-uv-editor-improvements: UV : Pack islands to correct/specified UDIM

2021-06-11 Thread Siddhartha Jejurkar
Commit: 1a890011516e14e57c4d1dd1b845158211a97e1a
Author: Siddhartha Jejurkar
Date:   Fri Jun 11 19:36:24 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB1a890011516e14e57c4d1dd1b845158211a97e1a

UV : Pack islands to correct/specified UDIM

Adds 2 features to the pack islands operator

 * Packing selected UVs to the closest UDIM
 * Packing selected UVs to user specified UDIM

===

M   source/blender/editors/include/ED_uvedit.h
M   source/blender/editors/uvedit/uvedit_islands.c
M   source/blender/editors/uvedit/uvedit_unwrap_ops.c
M   source/blender/makesdna/DNA_scene_defaults.h
M   source/blender/makesdna/DNA_scene_types.h

===

diff --git a/source/blender/editors/include/ED_uvedit.h 
b/source/blender/editors/include/ED_uvedit.h
index ea3d921f2c5..dd61768a312 100644
--- a/source/blender/editors/include/ED_uvedit.h
+++ b/source/blender/editors/include/ED_uvedit.h
@@ -249,6 +249,8 @@ struct UVPackIsland_Params {
 void ED_uvedit_pack_islands_multi(const struct Scene *scene,
   Object **objects,
   const uint objects_len,
+  const struct SpaceImage *sima,
+  bool use_target,
   const struct UVPackIsland_Params *params);
 
 #ifdef __cplusplus
diff --git a/source/blender/editors/uvedit/uvedit_islands.c 
b/source/blender/editors/uvedit/uvedit_islands.c
index 93948b5ae1b..a03b6670dae 100644
--- a/source/blender/editors/uvedit/uvedit_islands.c
+++ b/source/blender/editors/uvedit/uvedit_islands.c
@@ -29,6 +29,7 @@
 
 #include "DNA_meshdata_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_space_types.h"
 
 #include "BLI_boxpack_2d.h"
 #include "BLI_convexhull_2d.h"
@@ -37,6 +38,7 @@
 #include "BLI_rect.h"
 
 #include "BKE_editmesh.h"
+#include "BKE_image.h"
 
 #include "DEG_depsgraph.h"
 
@@ -358,6 +360,8 @@ static int bm_mesh_calc_uv_islands(const Scene *scene,
 void ED_uvedit_pack_islands_multi(const Scene *scene,
   Object **objects,
   const uint objects_len,
+  const SpaceImage *sima,
+  bool use_target,
   const struct UVPackIsland_Params *params)
 {
   /* Align to the Y axis, could make this configurable. */
@@ -365,6 +369,18 @@ void ED_uvedit_pack_islands_multi(const Scene *scene,
   ListBase island_list = {NULL};
   int island_list_len = 0;
 
+  const Image *image;
+  bool is_tiled_image = false;
+  int udim_grid[2] = {1, 1};
+
+  /* To handle cases where sima=NULL - Smart UV project */
+  if (sima) {
+image = sima->image;
+is_tiled_image = image && (image->source == IMA_SRC_TILED);
+udim_grid[0] = sima->tile_grid_shape[0];
+udim_grid[1] = sima->tile_grid_shape[1];
+  }
+
   for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
 Object *obedit = objects[ob_index];
 BMEditMesh *em = BKE_editmesh_from_object(obedit);
@@ -406,8 +422,26 @@ void ED_uvedit_pack_islands_multi(const Scene *scene,
   BoxPack *boxarray = MEM_mallocN(sizeof(*boxarray) * island_list_len, 
__func__);
 
   int index;
+  /* Coordinates for the center of the all the selected islands */
+  float selection_center[2] = {0.0f, 0.0f};
+  float selection_min[2], selection_max[2];
+  INIT_MINMAX2(selection_min, selection_max);
+
   LISTBASE_FOREACH_INDEX (struct FaceIsland *, island, _list, index) {
 
+/* Calculate bounding box of all selected islands */
+float bounds_min[2], bounds_max[2];
+INIT_MINMAX2(bounds_min, bounds_max);
+for (int i = 0; i < island->faces_len; i++) {
+  BMFace *f = island->faces[i];
+  BM_face_uv_minmax(f, bounds_min, bounds_max, island->cd_loop_uv_offset);
+}
+
+selection_min[0] = MIN2(bounds_min[0], selection_min[0]);
+selection_min[1] = MIN2(bounds_min[1], selection_min[1]);
+selection_max[0] = MAX2(bounds_max[0], selection_max[0]);
+selection_max[1] = MAX2(bounds_max[1], selection_max[1]);
+
 if (params->rotate) {
   if (island->aspect_y != 1.0f) {
 bm_face_array_uv_scale_y(
@@ -440,6 +474,10 @@ void ED_uvedit_pack_islands_multi(const Scene *scene,
 }
   }
 
+  /* Calculate the center of the bounding box */
+  selection_center[0] = (selection_min[0] + selection_max[0]) / 2.0f;
+  selection_center[1] = (selection_min[1] + selection_max[1]) / 2.0f;
+
   if (margin > 0.0f) {
 /* Logic matches behavior from #param_pack,
  * use area so multiply the margin by the area to give
@@ -463,6 +501,61 @@ void ED_uvedit_pack_islands_multi(const Scene *scene,
 
   const float scale[2] = {

[Bf-blender-cvs] [2126fc815dc] soc-2021-uv-editor-improvements: Merge branch 'master' into soc-2021-uv-editor-improvements

2021-06-11 Thread Siddhartha Jejurkar
Commit: 2126fc815dcfa4b33393d78aee61d757bcb52810
Author: Siddhartha Jejurkar
Date:   Thu Jun 10 15:45:47 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB2126fc815dcfa4b33393d78aee61d757bcb52810

Merge branch 'master' into soc-2021-uv-editor-improvements

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [790d11899ad] soc-2021-uv-editor-improvements: Merge branch 'master' into soc-2021-uv-editor-improvements

2021-06-08 Thread Siddhartha Jejurkar
Commit: 790d11899ad3b6df9a0cdb0c0a4962bbc1340ad5
Author: Siddhartha Jejurkar
Date:   Tue Jun 8 20:58:04 2021 +0530
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB790d11899ad3b6df9a0cdb0c0a4962bbc1340ad5

Merge branch 'master' into soc-2021-uv-editor-improvements

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [c1f7f18a8e6] blender-v2.93-release: Fix T81247: Constrain selected UVs to correct UDIM

2021-05-12 Thread Siddhartha Jejurkar
Commit: c1f7f18a8e6c82fddaa6ec06b7b78e3d2c64a1c8
Author: Siddhartha Jejurkar
Date:   Thu May 13 00:08:16 2021 +1000
Branches: blender-v2.93-release
https://developer.blender.org/rBc1f7f18a8e6c82fddaa6ec06b7b78e3d2c64a1c8

Fix T81247: Constrain selected UVs to correct UDIM

With Constrain to Image Bounds selected, UVs will be constrained to the
correct/closest UDIM if the image is tiled.
UVs will be constrained to the 0-1 UV space if the image is not tiled.
This will override the present behavior of always constraining selected
UVs to the 0-1 UV space (UDIM 1001).

Reviewed By: campbellbarton

Ref D11202

===

M   source/blender/blenkernel/BKE_image.h
M   source/blender/blenkernel/intern/image.c
M   source/blender/editors/transform/transform_convert.c

===

diff --git a/source/blender/blenkernel/BKE_image.h 
b/source/blender/blenkernel/BKE_image.h
index c51a5f7e5e1..d298e5dcf6d 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -325,6 +325,7 @@ int BKE_image_get_tile_from_pos(struct Image *ima,
 const float uv[2],
 float r_uv[2],
 float r_ofs[2]);
+int BKE_image_find_nearest_tile(const struct Image *image, const float co[2]);
 
 void BKE_image_get_size(struct Image *image, struct ImageUser *iuser, int 
*r_width, int *r_height);
 void BKE_image_get_size_fl(struct Image *image, struct ImageUser *iuser, float 
r_size[2]);
diff --git a/source/blender/blenkernel/intern/image.c 
b/source/blender/blenkernel/intern/image.c
index 368b1c2e66b..2f7e2b41a73 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -735,6 +735,37 @@ int BKE_image_get_tile_from_pos(struct Image *ima,
   return tile_number;
 }
 
+/**
+ * Return the tile_number for the closest UDIM tile.
+ */
+int BKE_image_find_nearest_tile(const Image *image, const float co[2])
+{
+  const float co_floor[2] = {floorf(co[0]), floorf(co[1])};
+  /* Distance to the closest UDIM tile. */
+  float dist_best_sq = FLT_MAX;
+  int tile_number_best = -1;
+
+  LISTBASE_FOREACH (const ImageTile *, tile, >tiles) {
+const int tile_index = tile->tile_number - 1001;
+/* Coordinates of the current tile. */
+const float tile_index_co[2] = {tile_index % 10, tile_index / 10};
+
+if (equals_v2v2(co_floor, tile_index_co)) {
+  return tile->tile_number;
+}
+
+/* Distance between co[2] and UDIM tile. */
+const float dist_sq = len_squared_v2v2(tile_index_co, co);
+
+if (dist_sq < dist_best_sq) {
+  dist_best_sq = dist_sq;
+  tile_number_best = tile->tile_number;
+}
+  }
+
+  return tile_number_best;
+}
+
 static void image_init_color_management(Image *ima)
 {
   ImBuf *ibuf;
diff --git a/source/blender/editors/transform/transform_convert.c 
b/source/blender/editors/transform/transform_convert.c
index c021c084a23..7239bed1eeb 100644
--- a/source/blender/editors/transform/transform_convert.c
+++ b/source/blender/editors/transform/transform_convert.c
@@ -37,6 +37,7 @@
 #include "BKE_context.h"
 #include "BKE_fcurve.h"
 #include "BKE_global.h"
+#include "BKE_image.h"
 #include "BKE_layer.h"
 #include "BKE_lib_id.h"
 #include "BKE_main.h"
@@ -505,9 +506,27 @@ bool clipUVTransform(TransInfo *t, float vec[2], const 
bool resize)
   bool clipx = true, clipy = true;
   float min[2], max[2];
 
-  min[0] = min[1] = 0.0f;
-  max[0] = t->aspect[0];
-  max[1] = t->aspect[1];
+  /* Check if the current image in UV editor is a tiled image or not. */
+  const SpaceImage *sima = t->area->spacedata.first;
+  const Image *image = sima->image;
+  const bool is_tiled_image = image && (image->source == IMA_SRC_TILED);
+  /* Stores the coordinates of the closest UDIM tile.
+   * Also acts as an offset to the tile from the origin of UV space. */
+  float base_offset[2] = {0.0f, 0.0f};
+
+  /* If tiled image then constrain to correct/closest UDIM tile, else 0-1 UV 
space. */
+  if (is_tiled_image) {
+int nearest_tile_index = BKE_image_find_nearest_tile(image, 
t->center_global);
+if (nearest_tile_index != -1) {
+  nearest_tile_index -= 1001;
+  /* Getting coordinates of nearest tile from the tile index. */
+  base_offset[0] = nearest_tile_index % 10;
+  base_offset[1] = nearest_tile_index / 10;
+}
+  }
+
+  min[0] = min[1] = FLT_MAX;
+  max[0] = max[1] = FLT_MIN;
 
   FOREACH_TRANS_DATA_CONTAINER (t, tc) {
 
@@ -520,42 +539,48 @@ bool clipUVTransform(TransInfo *t, float vec[2], const 
bool resize)
   }
 
   if (resize) {
-if (min[0] < 0.0f && t->center_global[0] > 0.0f && t->center_global[0] < 
t->aspect[0] * 0.5f) {
-  vec[0] *= t->cen

[Bf-blender-cvs] [9f3d41d4eee] master: Fix T86924: UV Sync selection breaks individual origin calculation

2021-03-26 Thread Siddhartha Jejurkar
Commit: 9f3d41d4eee6814fa4b6b89e75caeba1953ea6a7
Author: Siddhartha Jejurkar
Date:   Sat Mar 27 15:58:31 2021 +1100
Branches: master
https://developer.blender.org/rB9f3d41d4eee6814fa4b6b89e75caeba1953ea6a7

Fix T86924: UV Sync selection breaks individual origin calculation

Use uvedit_uv_select_test which accounts for UV Sync selection.

Ref D10830

===

M   source/blender/editors/mesh/editmesh_utils.c

===

diff --git a/source/blender/editors/mesh/editmesh_utils.c 
b/source/blender/editors/mesh/editmesh_utils.c
index 94f386e08d5..2e98f0558f3 100644
--- a/source/blender/editors/mesh/editmesh_utils.c
+++ b/source/blender/editors/mesh/editmesh_utils.c
@@ -785,7 +785,7 @@ UvElementMap *BM_uv_element_map_create(BMesh *bm,
   l = v->l;
   luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
   uv = luv->uv;
-  uv_vert_sel = luv->flag & MLOOPUV_VERTSEL;
+  uv_vert_sel = uvedit_uv_select_test(scene, l, cd_loop_uv_offset);
 
   lastv = NULL;
   iterv = vlist;
@@ -796,7 +796,7 @@ UvElementMap *BM_uv_element_map_create(BMesh *bm,
 l = iterv->l;
 luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
 uv2 = luv->uv;
-uv2_vert_sel = luv->flag & MLOOPUV_VERTSEL;
+uv2_vert_sel = uvedit_uv_select_test(scene, l, cd_loop_uv_offset);
 
 /* Check if the uv loops share the same selection state (if not, they 
are not connected as
  * they have been ripped or other edit commands have separated them). 
*/

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [350ad4bcb1b] master: Fix T86199: error when adding custom fluid diffusion preset

2021-03-11 Thread Siddhartha Jejurkar
Commit: 350ad4bcb1b38ed07f5198a7340ebbe9ab856bf3
Author: Siddhartha Jejurkar
Date:   Thu Mar 11 16:51:01 2021 +0100
Branches: master
https://developer.blender.org/rB350ad4bcb1b38ed07f5198a7340ebbe9ab856bf3

Fix T86199: error when adding custom fluid diffusion preset

Differential Revision: https://developer.blender.org/D10694

===

M   release/scripts/startup/bl_operators/presets.py

===

diff --git a/release/scripts/startup/bl_operators/presets.py 
b/release/scripts/startup/bl_operators/presets.py
index 5132b358f5e..cedbe542287 100644
--- a/release/scripts/startup/bl_operators/presets.py
+++ b/release/scripts/startup/bl_operators/presets.py
@@ -384,7 +384,7 @@ class AddPresetFluid(AddPresetBase, Operator):
 """Add or remove a Fluid Preset"""
 bl_idname = "fluid.preset_add"
 bl_label = "Add Fluid Preset"
-preset_menu = "FLUID_MT_presets"
+preset_menu = "FLUID_PT_presets"
 
 preset_defines = [
 "fluid = bpy.context.fluid"

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [122fefcc858] master: DNA: add defaults for UnifiedPaintSettings

2021-03-10 Thread Siddhartha Jejurkar
Commit: 122fefcc8589a09d4e89ed3045f29f07ec6564e9
Author: Siddhartha Jejurkar
Date:   Wed Mar 10 21:41:55 2021 +1100
Branches: master
https://developer.blender.org/rB122fefcc8589a09d4e89ed3045f29f07ec6564e9

DNA: add defaults for UnifiedPaintSettings

Newly created scenes had unified paint settings zeroed. see T80164

Ref D10658

===

M   source/blender/makesdna/DNA_scene_defaults.h
M   source/blender/makesdna/intern/dna_defaults.c
M   source/blender/makesrna/intern/rna_scene.c

===

diff --git a/source/blender/makesdna/DNA_scene_defaults.h 
b/source/blender/makesdna/DNA_scene_defaults.h
index 3e1b2ef56a1..1a2a8892e64 100644
--- a/source/blender/makesdna/DNA_scene_defaults.h
+++ b/source/blender/makesdna/DNA_scene_defaults.h
@@ -284,6 +284,15 @@
 .count = 10, \
   }
 
+#define _DNA_DEFAULTS_UnifiedPaintSettings \
+  { \
+.size = 50, \
+.unprojected_radius = 0.29, \
+.alpha = 0.5f, \
+.weight = 0.5f, \
+.flag = UNIFIED_PAINT_SIZE | UNIFIED_PAINT_ALPHA, \
+  }
+
 #define _DNA_DEFAULTS_ParticleEditSettings \
   { \
 .flag = PE_KEEP_LENGTHS | PE_LOCK_FIRST | PE_DEFLECT_EMITTER | 
PE_AUTO_VELOCITY, \
@@ -345,6 +354,8 @@
 .snap_transform_mode_flag = SCE_SNAP_TRANSFORM_MODE_TRANSLATE, \
  \
 .curve_paint_settings = _DNA_DEFAULTS_CurvePaintSettings, \
+ \
+.unified_paint_settings = _DNA_DEFAULTS_UnifiedPaintSettings, \
  \
 .statvis = _DNA_DEFAULTS_MeshStatVis, \
  \
diff --git a/source/blender/makesdna/intern/dna_defaults.c 
b/source/blender/makesdna/intern/dna_defaults.c
index 3e4d5d87fb0..7aca742a8e6 100644
--- a/source/blender/makesdna/intern/dna_defaults.c
+++ b/source/blender/makesdna/intern/dna_defaults.c
@@ -425,6 +425,7 @@ const void *DNA_default_table[SDNA_TYPE_MAX] = {
 SDNA_DEFAULT_DECL(ToolSettings),
 SDNA_DEFAULT_DECL_EX(CurvePaintSettings, 
ToolSettings.curve_paint_settings),
 SDNA_DEFAULT_DECL_EX(ImagePaintSettings, ToolSettings.imapaint),
+SDNA_DEFAULT_DECL_EX(UnifiedPaintSettings, 
ToolSettings.unified_paint_settings),
 SDNA_DEFAULT_DECL_EX(ParticleEditSettings, ToolSettings.particle),
 SDNA_DEFAULT_DECL_EX(ParticleBrushData, ToolSettings.particle.brush[0]),
 SDNA_DEFAULT_DECL_EX(MeshStatVis, ToolSettings.statvis),
diff --git a/source/blender/makesrna/intern/rna_scene.c 
b/source/blender/makesrna/intern/rna_scene.c
index 1ac224b27e4..4ff9e3006b4 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -3569,7 +3569,6 @@ static void rna_def_unified_paint_settings(BlenderRNA 
*brna)
   prop = RNA_def_property(srna, "strength", PROP_FLOAT, PROP_FACTOR);
   RNA_def_property_float_sdna(prop, NULL, "alpha");
   RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
-  RNA_def_property_float_default(prop, 0.5f);
   RNA_def_property_range(prop, 0.0f, 10.0f);
   RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.001, 3);
   RNA_def_property_ui_text(
@@ -3579,7 +3578,6 @@ static void rna_def_unified_paint_settings(BlenderRNA 
*brna)
   prop = RNA_def_property(srna, "weight", PROP_FLOAT, PROP_FACTOR);
   RNA_def_property_float_sdna(prop, NULL, "weight");
   RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
-  RNA_def_property_float_default(prop, 0.5f);
   RNA_def_property_range(prop, 0.0f, 1.0f);
   RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.001, 3);
   RNA_def_property_ui_text(prop, "Weight", "Weight to assign in vertex 
groups");

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs