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

Siddhartha Jejurkar noreply at git.blender.org
Sat Jun 26 10:37:19 CEST 2021


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, NULL, "flag", SI_DYNAMIC_GRID);
+  RNA_def_property_ui_text(prop, "Dynamic Grid", "Replace the default grid with a Dynamic grid");
+  RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, NULL);
+
+  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_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);
+
   prop = RNA_def_property(srna, "uv_opacity", PROP_FLOAT, PROP_FACTOR);
   RNA_def_property_float_sdna(prop, NULL, "uv_opacity");
   RNA_def_property_range(prop, 0.0f, 1.0f);



More information about the Bf-blender-cvs mailing list