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

Siddhartha Jejurkar noreply at git.blender.org
Wed Sep 29 09:53:57 CEST 2021


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 3ee668888f3..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 292ca726b6f..d8f4d01a2e9 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -3394,7 +3394,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
               SpaceImage *sima = (SpaceImage *)sl;
               sima->flag &= ~(SI_FLAG_UNUSED_0 | SI_FLAG_UNUSED_1 | SI_FLAG_UNUSED_3 |
                               SI_FLAG_UNUSED_6 | SI_FLAG_UNUSED_7 | SI_FLAG_UNUSED_8 |
-                              SI_FLAG_UNUSED_17 | SI_FLAG_UNUSED_18 | SI_FLAG_UNUSED_23 |
+                              SI_FLAG_UNUSED_17 | SI_CUSTOM_GRID | SI_FLAG_UNUSED_23 |
                               SI_FLAG_UNUSED_24);
               break;
             }
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index 3b51e40c218..ea368c0b3b1 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -1579,28 +1579,25 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
     }
   }
 
-  /**
-   * Versioning code until next subversion bump goes here.
-   *
-   * \note Be sure to check when bumping the version:
-   * - "versioning_userdef.c", #blo_do_versions_userdef
-   * - "versioning_userdef.c", #do_versions_theme
-   *
-   * \note Keep this message at the bottom of the function.
-   */
-  {
-    /* Keep this block, even when empty. */
-
+  if (!MAIN_VERSION_ATLEAST(bmain, 300, 29)) {
     LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
       LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
         LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
-          if (sl->spacetype == SPACE_SEQ) {
-            ListBase *regionbase = (sl == area->spacedata.first) ? &area->regionbase :
-                                                                   &sl->regionbase;
-            LISTBASE_FOREACH (ARegion *, region, regionbase) {
-              if (region->regiontype == RGN_TYPE_WINDOW) {
-                region->v2d.max[1] = MAXSEQ;
+          switch (sl->spacetype) {
+            case SPACE_SEQ: {
+              ListBase *regionbase = (sl == area->spacedata.first) ? &area->regionbase :
+                                                                     &sl->regionbase;
+              LISTBASE_FOREACH (ARegion *, region, regionbase) {
+                if (region->regiontype == RGN_TYPE_WINDOW) {
+                  region->v2d.max[1] = MAXSEQ;
+                }
               }
+              break;
+            }
+            case SPACE_IMAGE: {
+              SpaceImage *sima = (SpaceImage *)sl;
+              sima->custom_grid_subdiv = 10;
+              break;
             }
           }
         }
@@ -1613,4 +1610,17 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
       }
     }
   }
+
+  /**
+   * Versioning code until next subversion bump goes here.
+   *
+   * \note Be sure to check when bumping the version:
+   * - "versioning_userdef.c", #blo_do_versions_userdef
+   * - "versioning_userdef.c", #do_versions_theme
+   *
+   * \note Keep this message at the bottom of the function.
+   */
+  {
+    /* Keep this block, even when empty. */
+  }
 }
diff --git a/source/blender/draw/engines/overlay/overlay_grid.c b/source/blender/draw/engines/overlay/overlay_grid.c
index 60cda9f2d61..31c8ed9d664 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),
+  CUSTOM_GRID = (1 << 12),
 };
 
 void OVERLAY_grid_init(OVERLAY_Data *vedata)
@@ -61,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 = &draw_ctx->region->v2d;
     if (sima->mode == SI_MODE_UV || !ED_space_image_has_buffer(sima)) {
       shd->grid_flag = GRID_BACK | PLANE_IMAGE | SHOW_GRID;
     }
@@ -68,15 +71,21 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata)
       shd->grid_flag = 0;
     }
 
+    if (sima->flag & SI_CUSTOM_GRID) {
+      shd->grid_flag |= CUSTOM_GRID;
+    }
+
     shd->grid_distance = 1.0f;
     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);
-    }
+
+    const int grid_size = SI_GRID_STEPS_LEN;
+    shd->zoom_factor = ED_space_image_zoom_level(v2d, grid_size);
+    ED_space_image_grid_steps(sima, shd->grid_steps, grid_size);
+
     return;
   }
 
@@ -248,6 +257,7 @@ void OVERLAY_grid_cache_init(OVERLAY_Data *vedata)
 
   grp = DRW_shgroup_create(sh, psl->grid_ps);
   DRW_shgroup_uniform_int(grp, "gridFlag", &shd->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", &dtxl->depth);
diff --git a/source/blender/draw/engines/overlay/overlay_private.h b/source/blender/draw/engines/overlay/overlay_private.h
index 23df571e8de..def278f98df 100644
--- a/source/blender/draw/engines/overlay/overlay_private.h
+++ b/source/blender/draw/engines/overlay/overlay_private.h
@@ -139,9 +139,10 @@ typedef struct OVERLAY_ShadingData {
   /** Grid */
   float grid_axes[3], grid_distance;
   float zplane_axes[3], grid_size[3];
-  float grid_steps[8];
+  float grid_steps[SI_GRID_STEPS_LEN];
   float inv_viewport_size[2];
   float grid_line_size;
+  float zoom_factor; /* Only for UV 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 3220adbff36..9feca644bd3 100644
--- a/source/blender/draw/engines/overlay/shaders/grid_frag.glsl
+++ b/source/blender/draw/engines/overlay/shaders/grid_frag.glsl
@@ -15,8 +15,9 @@ uniform float lineKernel = 0.0;
 uniform sampler2D depthBuffer;
 
 uniform int gridFlag;
+uniform float zoomFactor;
 
-#define STEPS_LEN 8
+#define STEPS_LEN 8 /* Match: #SI_GRID_STEPS_LEN */
 uniform float gridSteps[STEPS_LEN] = float[](0.001, 0.01, 0.1, 1.0, 10.0, 100.0, 1000.0, 10000.0);
 
 #define AXIS_X (1 << 0)
@@ -28,6 +29,8 @@ uniform float gridSteps[STEPS_LEN] = float[](0.001, 0.01, 0.1, 1.0, 10.0, 100.0,
 #define PLANE_YZ (1 << 6)
 #define GRID_BACK (1 << 9)    /* grid is behind objects */
 #define GRID_CAMERA (1 << 10) /* In camera view */
+#define PLANE_IMAGE (1 << 11) /* UV/Image Image editor */
+#define CUSTOM_GRID (1 << 12) /* UV Editor only */
 
 #define M_1_SQRTPI 0.5641895835477563 /* 1/sqrt(pi) */
 
@@ -122,9 +125,17 @@ void main()
      * would be more accurate, but not really necessary. */
     float grid_res = dot(dFdxPos, screenVecs[0].xyz);
 
-    /* The gride begins to appear when it comprises 4 pixels */
+    /* The grid begins to appear when it comprises 4 pixels */
     grid_res *= 4;
 
+    /* For UV/Image editor use zoomFactor */
+    if ((gridFlag & PLANE_IMAGE) != 0 &&
+        /* Grid begins to appear when the length of one 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list