[Bf-blender-cvs] [73720586496] master: Wireframe: Add object and random coloring option in wireframe mode

Clément Foucault noreply at git.blender.org
Fri Feb 22 16:09:14 CET 2019


Commit: 7372058649666c7b0425c2f4d1a688a65ad11e61
Author: Clément Foucault
Date:   Fri Feb 22 16:06:13 2019 +0100
Branches: master
https://developer.blender.org/rB7372058649666c7b0425c2f4d1a688a65ad11e61

Wireframe: Add object and random coloring option in wireframe mode

The option is separated from the solid mode color option.

Random color uses the same method as solid mode.

Selection state is indicated by a brighter color that is outside the
brightness range of the unselected state colors. The active state is
indicated by the outlines that is, now, still drawn in wireframe mode.

Coloring of the selection / active outline is not optimal because it
can look ugly in some cases of color combination. But the outline color
is using index range coloring so it's not trivial to change the color of
the outline per object. For now we use the same outline color used in solid
mode for consistency and also still add an emphasis on the selected objects.

The Single color option uses the theme color. Maybe it would be nice to
change the name of it in a latter commit to avoid confusion.

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/draw/modes/object_mode.c
M	source/blender/draw/modes/overlay_mode.c
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index f2ba6fe695d..29333ddb2d5 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -4583,7 +4583,9 @@ class VIEW3D_PT_shading_color(Panel):
 
     def draw(self, context):
         shading = VIEW3D_PT_shading.get_shading(context)
-        if shading.type != 'WIREFRAME':
+        if shading.type == 'WIREFRAME':
+            self.layout.row().prop(shading, "wireframe_color_type", expand=True)
+        else:
             self._draw_color_type(context)
             self.layout.separator()
         self._draw_background_color(context)
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 07fae75974f..5234efdce03 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -2807,5 +2807,19 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
 
 	{
 		/* Versioning code until next subversion bump goes here. */
+
+		/* Add wireframe color. */
+		if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "char", "wire_color_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.wire_color_type = V3D_SHADING_SINGLE_COLOR;
+						}
+					}
+				}
+			}
+		}
 	}
 }
diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index 7439bd3255d..c0c290e1056 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -307,6 +307,7 @@ typedef struct OBJECT_PrivateData {
 	int id_ofs_prb_transform;
 
 	bool xray_enabled;
+	bool xray_enabled_and_not_wire;
 } OBJECT_PrivateData; /* Transient data */
 
 static struct {
@@ -995,7 +996,9 @@ static void OBJECT_cache_init(void *vedata)
 	}
 
 	g_data = stl->g_data;
-	g_data->xray_enabled = XRAY_ENABLED(draw_ctx->v3d) && (draw_ctx->v3d->shading.type < OB_MATERIAL);
+	g_data->xray_enabled = XRAY_ENABLED(draw_ctx->v3d) &&
+	                       (draw_ctx->v3d->shading.type < OB_MATERIAL);
+	g_data->xray_enabled_and_not_wire = g_data->xray_enabled && draw_ctx->v3d->shading.type > OB_WIRE;
 
 	{
 		DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_WIRE;
@@ -1003,7 +1006,7 @@ static void OBJECT_cache_init(void *vedata)
 
 		GPUShader *sh = sh_data->outline_prepass;
 
-		if (g_data->xray_enabled) {
+		if (g_data->xray_enabled_and_not_wire) {
 			sh = sh_data->outline_prepass_wire;
 		}
 
@@ -1050,7 +1053,7 @@ static void OBJECT_cache_init(void *vedata)
 
 		psl->outlines_search = DRW_pass_create("Outlines Detect Pass", state);
 
-		GPUShader *sh = (g_data->xray_enabled) ? sh_data->outline_detect_wire : sh_data->outline_detect;
+		GPUShader *sh = (g_data->xray_enabled_and_not_wire) ? sh_data->outline_detect_wire : sh_data->outline_detect;
 		DRWShadingGroup *grp = DRW_shgroup_create(sh, psl->outlines_search);
 		DRW_shgroup_uniform_texture_ref(grp, "outlineId", &e_data.outlines_id_tx);
 		DRW_shgroup_uniform_texture_ref(grp, "outlineDepth", &e_data.outlines_depth_tx);
@@ -2908,7 +2911,6 @@ static void OBJECT_cache_populate(void *vedata, Object *ob)
 
 	const bool do_outlines = (
 	        (draw_ctx->v3d->flag & V3D_SELECT_OUTLINE) && ((ob->base_flag & BASE_SELECTED) != 0) &&
-	        (draw_ctx->v3d->shading.type != OB_WIRE) &&
 	        ((DRW_object_is_renderable(ob) && (ob->dt > OB_WIRE)) || (ob->dt == OB_WIRE)));
 	const bool show_relations = ((draw_ctx->v3d->flag & V3D_HIDE_HELPLINES) == 0);
 	const bool hide_object_extra = (v3d->overlay.flag & V3D_OVERLAY_HIDE_OBJECT_XTRAS) != 0;
@@ -2926,7 +2928,7 @@ static void OBJECT_cache_populate(void *vedata, Object *ob)
 			        DRW_object_is_flat(ob, &flat_axis) &&
 			        DRW_object_axis_orthogonal_to_view(ob, flat_axis));
 
-			if (stl->g_data->xray_enabled || is_flat_object_viewed_from_side) {
+			if (stl->g_data->xray_enabled_and_not_wire || is_flat_object_viewed_from_side) {
 				geom = DRW_cache_object_edge_detection_get(ob, NULL);
 			}
 			else {
diff --git a/source/blender/draw/modes/overlay_mode.c b/source/blender/draw/modes/overlay_mode.c
index 30ea1bbeeaa..3cd9165abc4 100644
--- a/source/blender/draw/modes/overlay_mode.c
+++ b/source/blender/draw/modes/overlay_mode.c
@@ -29,6 +29,8 @@
 #include "BKE_object.h"
 #include "BKE_global.h"
 
+#include "BLI_hash.h"
+
 #include "GPU_shader.h"
 #include "DRW_render.h"
 
@@ -39,6 +41,7 @@
 #endif
 
 /* Structures */
+
 typedef struct OVERLAY_StorageList {
 	struct OVERLAY_PrivateData *g_data;
 } OVERLAY_StorageList;
@@ -59,6 +62,7 @@ typedef struct OVERLAY_Data {
 typedef struct OVERLAY_PrivateData {
 	DRWShadingGroup *face_orientation_shgrp;
 	DRWShadingGroup *face_wires_shgrp;
+	BLI_mempool *wire_color_mempool;
 	View3DOverlay overlay;
 	float wire_step_param;
 	bool ghost_stencil_test;
@@ -102,7 +106,7 @@ static void overlay_engine_init(void *vedata)
 
 	if (!stl->g_data) {
 		/* Alloc transient pointers */
-		stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+		stl->g_data = MEM_callocN(sizeof(*stl->g_data), __func__);
 	}
 	stl->g_data->ghost_stencil_test = false;
 
@@ -172,6 +176,13 @@ static void overlay_cache_init(void *vedata)
 	if (v3d->shading.type == OB_WIRE) {
 		g_data->overlay.flag |= V3D_OVERLAY_WIREFRAMES;
 		g_data->show_overlays = true;
+
+		if (ELEM(v3d->shading.wire_color_type,
+		         V3D_SHADING_OBJECT_COLOR,
+		         V3D_SHADING_RANDOM_COLOR))
+		{
+			g_data->wire_color_mempool = BLI_mempool_create(sizeof(float[3]), 0, 512, 0);
+		}
 	}
 
 	{
@@ -221,6 +232,92 @@ static void overlay_cache_init(void *vedata)
 	}
 }
 
+static void overlay_wire_color_get(
+        const View3D *v3d, const OVERLAY_PrivateData *pd, const Object *ob, const bool use_coloring,
+        float **rim_col, float **wire_col)
+{
+#ifndef NDEBUG
+	*rim_col = NULL;
+	*wire_col = NULL;
+#endif
+	const DRWContextState *draw_ctx = DRW_context_state_get();
+
+	if (UNLIKELY(ob->base_flag & BASE_FROM_SET)) {
+		*rim_col = G_draw.block.colorDupli;
+		*wire_col = G_draw.block.colorDupli;
+	}
+	else if (UNLIKELY(ob->base_flag & BASE_FROM_DUPLI)) {
+		if (ob->base_flag & BASE_SELECTED) {
+			if (G.moving & G_TRANSFORM_OBJ) {
+				*rim_col = G_draw.block.colorTransform;
+			}
+			else {
+				*rim_col = G_draw.block.colorDupliSelect;
+			}
+		}
+		else {
+			*rim_col = G_draw.block.colorDupli;
+		}
+		*wire_col = G_draw.block.colorDupli;
+	}
+	else if ((ob->base_flag & BASE_SELECTED) && use_coloring) {
+		if (G.moving & G_TRANSFORM_OBJ) {
+			*rim_col = G_draw.block.colorTransform;
+		}
+		else if (ob == draw_ctx->obact) {
+			*rim_col = G_draw.block.colorActive;
+		}
+		else {
+			*rim_col = G_draw.block.colorSelect;
+		}
+		*wire_col = G_draw.block.colorWire;
+	}
+	else {
+		*rim_col = G_draw.block.colorWire;
+		*wire_col = G_draw.block.colorWire;
+	}
+
+	if (v3d->shading.type == OB_WIRE) {
+		if (ELEM(v3d->shading.wire_color_type,
+		         V3D_SHADING_OBJECT_COLOR,
+		         V3D_SHADING_RANDOM_COLOR))
+		{
+			*wire_col = BLI_mempool_alloc(pd->wire_color_mempool);
+			*rim_col = BLI_mempool_alloc(pd->wire_color_mempool);
+
+			if (v3d->shading.wire_color_type == V3D_SHADING_OBJECT_COLOR) {
+				linearrgb_to_srgb_v3_v3(*wire_col, ob->color);
+				mul_v3_fl(*wire_col, 0.5f);
+				copy_v3_v3(*rim_col, *wire_col);
+			}
+			else {
+				uint hash = BLI_ghashutil_strhash_p_murmur(ob->id.name);
+				if (ob->id.lib) {
+					hash = (hash * 13) ^ BLI_ghashutil_strhash_p_murmur(ob->id.lib->name);
+				}
+
+				float hue = BLI_hash_int_01(hash);
+				float hsv[3] = {hue, 0.75f, 0.8f};
+				hsv_to_rgb_v(hsv, *wire_col);
+				copy_v3_v3(*rim_col, *wire_col);
+			}
+
+			if ((ob->base_flag & BASE_SELECTED) && use_coloring) {
+				/* "Normalize" color. */
+				add_v3_fl(*wire_col, 1e-4f);
+				float brightness = max_fff((*wire_col)[0], (*wire_col)[1], (*wire_col)[2]);
+				mul_v3_fl(*wire_col, (0.5f / brightness));
+				add_v3_fl(*rim_col, 0.75f);
+			}
+			else {
+				mul_v3_fl(*rim_col, 0.5f);
+				add_v3_fl(*wire_col, 0.5f);
+			}
+		}
+	}
+	BLI_assert(*rim_col && *wire_col);
+}
+
 static void overlay_cache_populate(void *vedata, Object *ob)
 {
 	OVERLAY_Data *data = vedata;
@@ -267,49 +364,12 @@ static void overlay_cache_populate(void *vedata, Object *ob)
 			const bool is_sculpt_mode = is_active && (draw_ctx->object_mode & OB_MODE_SCULPT) != 0;
 			const bool all_wires = (ob->dtx & OB_DRAW_ALL_EDGES);
 			const bool is_wire = (ob->dt < OB_SOLID);
+			const bool use_coloring = (!is_edit_mode && !is_sculpt_mode && !has_edit_mesh_cage);
 			const int stencil_mask = (ob->dtx & OB_DRAWXRAY) ? 0x00 : 0xFF;
+			float *rim_col, *wire_col;
 			DRWShadingGroup *shgrp = NULL;
 
-			const float *rim_col = NULL;
-			const float *wire_col = NULL;
-
-			if (UNLIKELY(ob->base_flag & BASE_FROM_SET)) {
-				rim_col = G_draw.block.colorDupli;
-				wire_col = G_draw.block.colorDupli;
-			}
-			else if (UNLIKELY(ob->base_flag & BASE_FROM_DUPLI)) {
-				if (ob->base_flag & BASE_SELECTED) {
-					if (G.moving & G_TRANSFORM_OBJ) {
-						rim_col = G_draw.block.colorTransform;
-					}
-					else {
-						rim_col = G_draw.block.colorDupliSelect;
-					}
-				}
-				else {
-					rim_col = G_draw.block.colorDupli;
-				}
-				wire_col = G_draw.block.colorDupli;
-			}
-			else if ((ob->base_flag & BASE_SELECTED) &&
-			         (!is_edit_mode && !is_sculpt_mode && !has_edit_mesh_cage))
-			{
-				if (G.moving & G_TRANSFORM_OBJ) {
-					rim_col = G_draw.block.colorTransform;
-				}
-				else if (ob == draw_ctx->obact) {
-					rim_col = G_draw.block.colorActive;
-				}
-				else {
-					rim_col = G_draw.block.colorSelect;
-				}
-				wire_col = G_draw.block.colorWire;
-			}
-			else {
-				rim_col = G_draw.block.colorWire;
-				wire_col = G_draw.block.colorWire;
-			}
-			BLI_assert(rim_col && wire_col);
+			overlay_wire_color_get(v3d, pd, ob,

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list