[Bf-blender-cvs] [70966af5134] blender2.8: Workbench: option to change background

Jeroen Bakker noreply at git.blender.org
Fri Jul 27 15:28:18 CEST 2018


Commit: 70966af5134b0cf53273e3c6da19ad7d5857b0f2
Author: Jeroen Bakker
Date:   Fri Jul 27 15:05:46 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB70966af5134b0cf53273e3c6da19ad7d5857b0f2

Workbench: option to change background

Replaced the draw world option with a shading.background_type enum.
Where the user can select Theme, World or a Custom color.

World and theme colors do not always work in workbench. We needed to
have an option what the user could control locally (per viewport).
Especially when using linked data.

I removed the world background drawing from the draw_manager. It was never used as EEVEE and Workbench both override the logic.

Not 100% sure about the naming of Theme, World, Viewport.
In other parts of blender's codebase World is sometimes called Scene.
Will stick to the names that describes its location best.

{F3990139}

Reviewers: fclem, campbellbarton

Reviewed By: fclem

Subscribers: venomgfx

Tags: #bf_blender_2.8

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

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/blenkernel/intern/screen.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/draw/engines/workbench/workbench_data.c
M	source/blender/draw/intern/draw_view.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/makesrna/intern/rna_world.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 6874055a58f..e6d8b1ec2a7 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -3839,10 +3839,14 @@ class VIEW3D_PT_shading_color(Panel):
 
         shading = VIEW3D_PT_shading.get_shading(context)
 
-        layout.row().prop(shading, "color_type", expand=True)
-
+        layout.row().prop(shading, 'color_type', expand=True)
         if shading.color_type == 'SINGLE':
-            layout.row().prop(shading, "single_color", text="")
+            layout.row().prop(shading, 'single_color', text="")
+
+        layout.row().label("Background")
+        layout.row().prop(shading, 'background_type', expand=True)
+        if shading.background_type == 'VIEWPORT':
+            layout.row().prop(shading, "background_color", text="")
 
 
 class VIEW3D_PT_shading_options(Panel):
@@ -3912,10 +3916,6 @@ class VIEW3D_PT_shading_options(Panel):
         if not shading.light == 'MATCAP':
             col.prop(shading, "show_specular_highlight")
 
-        view = context.space_data
-        if view.type == 'VIEW_3D':
-            col.prop(view, "show_world")
-
 
 class VIEW3D_PT_shading_options_shadow(Panel):
     bl_label = "Shadow Settings"
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index f8d926a13ed..c107bb04e6e 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -869,6 +869,7 @@ void BKE_screen_view3d_shading_init(View3DShading *shading)
 	shading->cavity_valley_factor = 1.0f;
 	shading->cavity_ridge_factor = 1.0f;
 	copy_v3_fl(shading->single_color, 0.8f);
+	copy_v3_fl(shading->background_color, 0.05f);
 }
 
 /* magic zoom calculation, no idea what
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 068c12daa94..39ceb527209 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -1546,6 +1546,20 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
 			}
 		}
 
+		if (!DNA_struct_elem_find(fd->filesdna, "View3DShadeing", "short", "background_type")) {
+			for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
+				for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+					for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
+						if (sl->spacetype == SPACE_VIEW3D) {
+							View3D *v3d = (View3D *)sl;
+							v3d->shading.background_type = (v3d->flag3 & V3D_SHOW_WORLD)? V3D_SHADING_BACKGROUND_WORLD: V3D_SHADING_BACKGROUND_THEME;
+							copy_v3_fl(v3d->shading.background_color, 0.05f);
+						}
+					}
+				}
+			}
+		}
+
 		if (!DNA_struct_elem_find(fd->filesdna, "SceneEEVEE", "float", "gi_cubemap_draw_size")) {
 			for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 				scene->eevee.gi_irradiance_draw_size = 0.1f;
diff --git a/source/blender/draw/engines/workbench/workbench_data.c b/source/blender/draw/engines/workbench/workbench_data.c
index 5c3ab5f6688..24eb0f38a46 100644
--- a/source/blender/draw/engines/workbench/workbench_data.c
+++ b/source/blender/draw/engines/workbench/workbench_data.c
@@ -45,10 +45,16 @@ void workbench_private_data_init(WORKBENCH_PrivateData *wpd)
 	wd->matcap_orientation = (wpd->shading.flag & V3D_SHADING_MATCAP_FLIP_X) != 0;
 	wd->background_alpha = (v3d || scene->r.alphamode == R_ADDSKY) ? 1.0f : 0.0f;
 
-	if (!v3d || ((v3d->flag3 & V3D_SHOW_WORLD) && (scene->world != NULL))) {
+	if (!v3d || ((v3d->shading.background_type & V3D_SHADING_BACKGROUND_WORLD) &&
+	    (scene->world != NULL)))
+	{
 		copy_v3_v3(wd->background_color_low, &scene->world->horr);
 		copy_v3_v3(wd->background_color_high, &scene->world->horr);
 	}
+	else if (v3d->shading.background_type & V3D_SHADING_BACKGROUND_VIEWPORT) {
+		copy_v3_v3(wd->background_color_low, v3d->shading.background_color);
+		copy_v3_v3(wd->background_color_high, v3d->shading.background_color);
+	}
 	else if (v3d) {
 		UI_GetThemeColor3fv(UI_GetThemeValue(TH_SHOW_BACK_GRAD) ? TH_LOW_GRAD : TH_HIGH_GRAD, wd->background_color_low);
 		UI_GetThemeColor3fv(TH_HIGH_GRAD, wd->background_color_high);
diff --git a/source/blender/draw/intern/draw_view.c b/source/blender/draw/intern/draw_view.c
index 05aecea1d7a..95835a691a3 100644
--- a/source/blender/draw/intern/draw_view.c
+++ b/source/blender/draw/intern/draw_view.c
@@ -561,21 +561,12 @@ void DRW_draw_grid(void)
 
 void DRW_draw_background(void)
 {
-	const DRWContextState *draw_ctx = DRW_context_state_get();
-
 	/* Just to make sure */
 	glDepthMask(GL_TRUE);
 	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
 	glStencilMask(0xFF);
 
-	if ((draw_ctx->v3d->flag3 & V3D_SHOW_WORLD) &&
-	    (draw_ctx->scene->world != NULL))
-	{
-		const World *world = draw_ctx->scene->world;
-		glClearColor(world->horr, world->horg, world->horb, 1.0f);
-		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
-	}
-	else if (UI_GetThemeValue(TH_SHOW_BACK_GRAD)) {
+	if (UI_GetThemeValue(TH_SHOW_BACK_GRAD)) {
 		float m[4][4];
 		unit_m4(m);
 
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 71bdd2e20c2..2577077002e 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -1406,7 +1406,7 @@ static void space_view3d_listener(
 			switch (wmn->data) {
 				case ND_WORLD_DRAW:
 				case ND_WORLD:
-					if (v3d->flag3 & V3D_SHOW_WORLD)
+					if (v3d->shading.background_type & V3D_SHADING_BACKGROUND_WORLD)
 						ED_area_tag_redraw_regiontype(sa, RGN_TYPE_WINDOW);
 					break;
 			}
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 552d84ebb39..941f9262694 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -1599,7 +1599,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
 		v3d.flag2 |= V3D_SOLID_TEX;
 	}
 
-	v3d.flag3 |= V3D_SHOW_WORLD;
+	v3d.shading.background_type = V3D_SHADING_BACKGROUND_WORLD;
 
 	if (draw_flags & V3D_OFSDRAW_USE_CAMERA_DOF) {
 		if (camera->type == OB_CAMERA) {
diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h
index fedc604f120..bbbaf8bb957 100644
--- a/source/blender/makesdna/DNA_view3d_types.h
+++ b/source/blender/makesdna/DNA_view3d_types.h
@@ -142,7 +142,9 @@ typedef struct View3DShading {
 	short color_type;
 
 	short light;
-	short pad[3];
+	short background_type;
+	short pad2[2];
+
 	char studio_light[256]; /* FILE_MAXFILE */
 	char matcap[256]; /* FILE_MAXFILE */
 
@@ -157,6 +159,10 @@ typedef struct View3DShading {
 
 	float cavity_valley_factor;
 	float cavity_ridge_factor;
+
+	float background_color[3];
+	int pad;
+
 } View3DShading;
 
 /* 3D Viewport Overlay setings */
@@ -349,7 +355,7 @@ typedef struct View3D {
 
 
 /* View3d->flag3 (short) */
-#define V3D_SHOW_WORLD			(1 << 0)
+#define V3D_SHOW_WORLD			(1 << 0) /* LEGACY replaced by V3D_SHADING_BACKGROUND_WORLD */
 
 /* View3DShading->light */
 enum {
@@ -378,6 +384,13 @@ enum {
 	V3D_SHADING_TEXTURE_COLOR  = 3,
 };
 
+/* View3DShading->background_type */
+enum {
+	V3D_SHADING_BACKGROUND_THEME    = 0,
+	V3D_SHADING_BACKGROUND_WORLD    = 1,
+	V3D_SHADING_BACKGROUND_VIEWPORT = 2,
+};
+
 /* View3DOverlay->flag */
 enum {
 	V3D_OVERLAY_FACE_ORIENTATION  = (1 << 0),
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index e670d3c31a5..2f009238851 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -2427,6 +2427,15 @@ static void rna_def_space_view3d_shading(BlenderRNA *brna)
 	StructRNA *srna;
 	PropertyRNA *prop;
 
+	static const EnumPropertyItem background_type_items[] = {
+		{V3D_SHADING_BACKGROUND_THEME,    "THEME",    0, "Theme",    "Use the theme for background color"},
+		{V3D_SHADING_BACKGROUND_WORLD,    "WORLD",    0, "World",    "Use the world for background color"},
+		{V3D_SHADING_BACKGROUND_VIEWPORT, "VIEWPORT", 0, "Viewport", "Use a custom color limited to this viewport only"},
+		{0, NULL, 0, NULL, NULL}
+	};
+	static const float default_background_color[] = {0.05f, 0.05f, 0.05f};
+
+
 	/* Note these settings are used for both 3D viewport and the OpenGL render
 	 * engine in the scene, so can't assume to always be part of a screen. */
 	srna = RNA_def_struct(brna, "View3DShading", NULL);
@@ -2514,6 +2523,18 @@ static void rna_def_space_view3d_shading(BlenderRNA *brna)
 	RNA_def_property_range(prop, 0.0f, 1.0f);
 	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 
+	prop = RNA_def_property(srna, "background_type", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_items(prop, background_type_items);
+	RNA_def_property_ui_text(prop, "Background", "Way to draw the background");
+	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+	prop = RNA_def_property(srna, "background_color", PROP_FLOAT, PROP_COLOR);
+	RNA_def_property_array(prop, 3);
+	RNA_def_property_float_array_default(prop, default_background_color);
+	RNA_def_property_ui_text(prop, "Background Color", "Color for custom background color");
+	RNA_def_property_range(prop, 0.0f, 1.0f);
+	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
 	prop = RNA_def_property(srna, "show_shadows", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_SHADING_SHADOW);
 	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
@@ -2957,11 +2978,6 @@ static void rna_def_space_view3d(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Lock Camera to View", "Enable view navigation within the camera view");
 	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 
-	prop = RNA_def_property(srna, "show_world", PROP_BOOLEAN, PROP_NONE);
-	RNA_def_property_boolean_sdna(prop, NULL, "flag3", V3D_SHOW_WORLD);
-	RNA_def_property_ui_text(prop, "World Background", "Display world colors in the background");
-	RNA_def_pr

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list