[Bf-blender-cvs] [77a8f89a500] modifier-panels-ui: UV: support changing the opacity of the UV overlay

Campbell Barton noreply at git.blender.org
Thu Apr 16 21:30:28 CEST 2020


Commit: 77a8f89a5001e7886bb0cdc416e05f6f1e2dcbe5
Author: Campbell Barton
Date:   Thu Apr 16 18:10:21 2020 +1000
Branches: modifier-panels-ui
https://developer.blender.org/rB77a8f89a5001e7886bb0cdc416e05f6f1e2dcbe5

UV: support changing the opacity of the UV overlay

Add this option as it's useful to adjust how much UV's
cover the image when UV mapping.

D5348 by @EitanSomething with edits

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

M	release/scripts/startup/bl_ui/space_image.py
M	source/blender/blenloader/CMakeLists.txt
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/readfile.h
A	source/blender/blenloader/intern/versioning_290.c
M	source/blender/editors/space_image/space_image.c
M	source/blender/editors/uvedit/uvedit_draw.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 4506307067e..05924600db7 100644
--- a/release/scripts/startup/bl_ui/space_image.py
+++ b/release/scripts/startup/bl_ui/space_image.py
@@ -955,6 +955,7 @@ class IMAGE_PT_view_display_uv_edit_overlays(Panel):
         col = layout.column()
         col.prop(uvedit, "show_smooth_edges", text="Smooth")
         col.prop(uvedit, "show_modified_edges", text="Modified")
+        col.prop(uvedit, "uv_opacity")
 
 
 class IMAGE_PT_view_display_uv_edit_overlays_stretch(Panel):
diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt
index 450d3fc2371..1555b9231ed 100644
--- a/source/blender/blenloader/CMakeLists.txt
+++ b/source/blender/blenloader/CMakeLists.txt
@@ -53,6 +53,7 @@ set(SRC
   intern/versioning_260.c
   intern/versioning_270.c
   intern/versioning_280.c
+  intern/versioning_290.c
   intern/versioning_cycles.c
   intern/versioning_defaults.c
   intern/versioning_dna.c
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 9ff5ab3a648..cf68caebc65 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -9911,6 +9911,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
   blo_do_versions_260(fd, lib, main);
   blo_do_versions_270(fd, lib, main);
   blo_do_versions_280(fd, lib, main);
+  blo_do_versions_290(fd, lib, main);
   blo_do_versions_cycles(fd, lib, main);
 
   /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index 80f8bfc3f07..55abbe703de 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -199,6 +199,7 @@ void blo_do_versions_250(struct FileData *fd, struct Library *lib, struct Main *
 void blo_do_versions_260(struct FileData *fd, struct Library *lib, struct Main *bmain);
 void blo_do_versions_270(struct FileData *fd, struct Library *lib, struct Main *bmain);
 void blo_do_versions_280(struct FileData *fd, struct Library *lib, struct Main *bmain);
+void blo_do_versions_290(struct FileData *fd, struct Library *lib, struct Main *bmain);
 void blo_do_versions_cycles(struct FileData *fd, struct Library *lib, struct Main *bmain);
 
 void do_versions_after_linking_250(struct Main *bmain);
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
new file mode 100644
index 00000000000..c6adbb5c7d2
--- /dev/null
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -0,0 +1,63 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup blenloader
+ */
+/* allow readfile to use deprecated functionality */
+#define DNA_DEPRECATED_ALLOW
+
+#include "BLI_listbase.h"
+#include "BLI_utildefines.h"
+
+#include "DNA_screen_types.h"
+
+#include "BKE_collection.h"
+#include "BKE_main.h"
+
+#include "BLO_readfile.h"
+#include "readfile.h"
+
+/* Make preferences read-only, use versioning_userdef.c. */
+#define U (*((const UserDef *)&U))
+
+void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
+{
+  UNUSED_VARS(fd);
+  /**
+   * Versioning code until next subversion bump goes here.
+   *
+   * \note Be sure to check when bumping the version:
+   * - "versioning_userdef.c", #BLO_version_defaults_userpref_blend
+   * - "versioning_userdef.c", #do_versions_theme
+   *
+   * \note Keep this message at the bottom of the function.
+   */
+  {
+    /* Keep this block, even when empty. */
+
+    for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
+      LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+        LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
+          if (sl->spacetype == SPACE_IMAGE) {
+            SpaceImage *sima = (SpaceImage *)sl;
+            sima->uv_opacity = 1.0f;
+          }
+        }
+      }
+    }
+  }
+}
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index 5c146a99efd..ed14593ed2d 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -127,6 +127,7 @@ static SpaceLink *image_new(const ScrArea *UNUSED(area), const Scene *UNUSED(sce
   simage->zoom = 1.0f;
   simage->lock = true;
   simage->flag = SI_SHOW_GPENCIL | SI_USE_ALPHA | SI_COORDFLOATS;
+  simage->uv_opacity = 1.0f;
 
   BKE_imageuser_default(&simage->iuser);
   simage->iuser.flag = IMA_SHOW_STEREO | IMA_ANIM_ALWAYS;
diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c
index 6ea1bbbcc10..0fd3005ac41 100644
--- a/source/blender/editors/uvedit/uvedit_draw.c
+++ b/source/blender/editors/uvedit/uvedit_draw.c
@@ -306,6 +306,7 @@ static void draw_uvs(SpaceImage *sima,
   Object *ob_eval = batch->ob_eval;
   const ToolSettings *ts = scene->toolsettings;
   float col1[4], col2[4], col3[4], transparent[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+  const float overlay_alpha = sima->uv_opacity;
 
   if (sima->flag & SI_DRAWSHADOW) {
     bool is_cage_like_final_meshes = false;
@@ -347,6 +348,11 @@ static void draw_uvs(SpaceImage *sima,
       UI_GetThemeColor4fv(TH_FACE_SELECT, col2);
       UI_GetThemeColor4fv(TH_EDITMESH_ACTIVE, col3);
       col3[3] *= 0.2; /* Simulate dithering */
+
+      col1[3] *= overlay_alpha;
+      col2[3] *= overlay_alpha;
+      col3[3] *= overlay_alpha;
+
       GPU_batch_uniform_4fv(batch->faces, "faceColor", col1);
       GPU_batch_uniform_4fv(batch->faces, "selectColor", col2);
       GPU_batch_uniform_4fv(batch->faces, "activeColor", col3);
@@ -372,9 +378,16 @@ static void draw_uvs(SpaceImage *sima,
       GPU_line_smooth(true);
       GPU_blend(true);
     }
+    else if (overlay_alpha < 1.0f) {
+      GPU_blend(true);
+    }
+
     switch (sima->dt_uv) {
       case SI_UVDT_DASH: {
-        float dash_colors[2][4] = {{0.56f, 0.56f, 0.56f, 1.0f}, {0.07f, 0.07f, 0.07f, 1.0f}};
+        float dash_colors[2][4] = {
+            {0.56f, 0.56f, 0.56f, overlay_alpha},
+            {0.07f, 0.07f, 0.07f, overlay_alpha},
+        };
         float viewport_size[4];
         GPU_viewport_size_get_f(viewport_size);
 
@@ -398,7 +411,8 @@ static void draw_uvs(SpaceImage *sima,
          * instead of modifying the provoking vert. */
         glProvokingVertex(GL_FIRST_VERTEX_CONVENTION);
 
-        UI_GetThemeColor4fv(TH_EDGE_SELECT, col2);
+        UI_GetThemeColor3fv(TH_EDGE_SELECT, col2);
+        col2[3] = overlay_alpha;
 
         GPU_batch_program_set_builtin(
             batch->edges, (interpedges) ? GPU_SHADER_2D_UV_EDGES_SMOOTH : GPU_SHADER_2D_UV_EDGES);
@@ -406,18 +420,19 @@ static void draw_uvs(SpaceImage *sima,
         if (sima->dt_uv == SI_UVDT_OUTLINE) {
           /* Black Outline. */
           GPU_line_width(3.0f);
-          GPU_batch_uniform_4f(batch->edges, "edgeColor", 0.0f, 0.0f, 0.0f, 1.0f);
-          GPU_batch_uniform_4f(batch->edges, "selectColor", 0.0f, 0.0f, 0.0f, 1.0f);
+          GPU_batch_uniform_4f(batch->edges, "edgeColor", 0.0f, 0.0f, 0.0f, overlay_alpha);
+          GPU_batch_uniform_4f(batch->edges, "selectColor", 0.0f, 0.0f, 0.0f, overlay_alpha);
           GPU_batch_draw(batch->edges);
 
-          UI_GetThemeColor4fv(TH_WIRE_EDIT, col1);
+          UI_GetThemeColor3fv(TH_WIRE_EDIT, col1);
         }
         else if (sima->dt_uv == SI_UVDT_WHITE) {
-          copy_v4_fl4(col1, 1.0f, 1.0f, 1.0f, 1.0f);
+          copy_v3_fl3(col1, 1.0f, 1.0f, 1.0f);
         }
         else {
-          copy_v4_fl4(col1, 0.0f, 0.0f, 0.0f, 1.0f);
+          copy_v3_fl3(col1, 0.0f, 0.0f, 0.0f);
         }
+        col1[3] = overlay_alpha;
 
         /* Inner Line. Use depth test to insure selection is drawn on top. */
         GPU_depth_test(true);
@@ -435,6 +450,9 @@ static void draw_uvs(SpaceImage *sima,
       GPU_line_smooth(false);
       GPU_blend(false);
     }
+    else if (overlay_alpha < 1.0f) {
+      GPU_blend(false);
+    }
   }
   if (batch->verts || batch->facedots) {
     UI_GetThemeColor4fv(TH_VERTEX_SELECT, col2);
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 648d35c9a2d..90af60447fe 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -1075,7 +1075,9 @@ typedef struct SpaceImage {
   int flag;
 
   char pixel_snap_mode;
-  char _pad2[3];
+  char _pad2[7];
+
+  float uv_opacity;
 
   int tile_grid_shape[2];
 
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 1f072d2eb26..f6a7c74484a 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -2935,6 +2935,12 @@ 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, "uv_opacity", PROP_FLOAT, PROP_FACTOR);
+  RNA_def_property_float_sdna(prop, NULL, "uv_opacity");
+  RNA_def_property_range(prop, 0.2f, 1.0f);
+  RNA_def_property_ui_text(prop, "UV Opacity", "Opacity of UV overlays");
+  RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, NULL);
+
   /* todo: move edge and face drawing options here from G.f */
 
   prop = RNA_def_property(srna, "pix

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list