Wireframe color option for all shading modes #111502

Merged
Jeroen Bakker merged 2 commits from Gilberto.R/blender:temp-wirecolor1 into main 2023-08-28 11:04:48 +02:00
6 changed files with 31 additions and 51 deletions

View File

@ -6312,14 +6312,9 @@ class VIEW3D_PT_shading_lighting(Panel):
class VIEW3D_PT_shading_color(Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'HEADER'
bl_label = "Color"
bl_label = "Wire Color"
bl_parent_id = 'VIEW3D_PT_shading'
@classmethod
def poll(cls, context):
shading = VIEW3D_PT_shading.get_shading(context)
return shading.type in {'WIREFRAME', 'SOLID'}
def _draw_color_type(self, context):
layout = self.layout
Gilberto.R marked this conversation as resolved
Review

poll function can be removed as it is always true

poll function can be removed as it is always true
shading = VIEW3D_PT_shading.get_shading(context)
@ -6338,13 +6333,19 @@ class VIEW3D_PT_shading_color(Panel):
layout.row().prop(shading, "background_color", text="")
def draw(self, context):
layout = self.layout
shading = VIEW3D_PT_shading.get_shading(context)
if shading.type == 'WIREFRAME':
self.layout.row().prop(shading, "wireframe_color_type", expand=True)
else:
self.layout.row().prop(shading, "wireframe_color_type", expand=True)
self.layout.separator()
if shading.type == 'SOLID':
layout.row().label(text="Color")
self._draw_color_type(context)
self.layout.separator()
self._draw_background_color(context)
self._draw_background_color(context)
elif shading.type == 'WIREFRAME':
self._draw_background_color(context)
class VIEW3D_PT_shading_options(Panel):

View File

@ -60,10 +60,9 @@ void OVERLAY_wireframe_cache_init(OVERLAY_Data *vedata)
pd->shdata.wire_opacity = pd->overlay.wireframe_opacity;
bool is_wire_shmode = (shading->type == OB_WIRE);
bool is_material_shmode = (shading->type > OB_SOLID);
bool is_object_color = is_wire_shmode && (shading->wire_color_type == V3D_SHADING_OBJECT_COLOR);
bool is_random_color = is_wire_shmode && (shading->wire_color_type == V3D_SHADING_RANDOM_COLOR);
int color_type = shading->wire_color_type;
const bool use_select = (DRW_state_is_select() || DRW_state_is_depth());
GPUShader *wires_sh = use_select ? OVERLAY_shader_wireframe_select() :
@ -95,8 +94,7 @@ void OVERLAY_wireframe_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_float_copy(grp, "wireOpacity", pd->shdata.wire_opacity);
DRW_shgroup_uniform_bool_copy(grp, "useColoring", use_coloring);
DRW_shgroup_uniform_bool_copy(grp, "isTransform", (G.moving & G_TRANSFORM_OBJ) != 0);
DRW_shgroup_uniform_bool_copy(grp, "isObjectColor", is_object_color);
DRW_shgroup_uniform_bool_copy(grp, "isRandomColor", is_random_color);
DRW_shgroup_uniform_int_copy(grp, "colorType", color_type);
DRW_shgroup_uniform_bool_copy(grp, "isHair", false);
pd->wires_all_grp[xray][use_coloring] = grp = DRW_shgroup_create(wires_sh, pass);

View File

@ -15,8 +15,7 @@ GPU_SHADER_CREATE_INFO(overlay_wireframe)
.push_constant(Type::FLOAT, "wireOpacity")
.push_constant(Type::BOOL, "useColoring")
.push_constant(Type::BOOL, "isTransform")
.push_constant(Type::BOOL, "isObjectColor")
.push_constant(Type::BOOL, "isRandomColor")
.push_constant(Type::INT, "colorType")
.push_constant(Type::BOOL, "isHair")
.push_constant(Type::MAT4, "hairDupliMatrix")
/* Scene Depth texture copy for manual depth test. */

View File

@ -51,7 +51,7 @@ void wire_object_color_get(out vec3 rim_col, out vec3 wire_col)
int flag = int(abs(ObjectInfo.w));
bool is_selected = (flag & DRW_BASE_SELECTED) != 0;
if (isObjectColor) {
if (colorType == V3D_SHADING_OBJECT_COLOR) {
rim_col = wire_col = ObjectColor.rgb * 0.5;
}
else {
@ -113,7 +113,7 @@ void main()
edgePos = edgeStart;
vec3 rim_col, wire_col;
if (isObjectColor || isRandomColor) {
if (colorType == V3D_SHADING_OBJECT_COLOR || colorType == V3D_SHADING_RANDOM_COLOR) {
wire_object_color_get(rim_col, wire_col);
}
else {

View File

@ -294,6 +294,11 @@ float get_homogenous_z_offset(float vs_z, float hs_w, float vs_offset)
#define DRW_BASE_FROM_SET (1 << 3)
#define DRW_BASE_ACTIVE (1 << 4)
/* Wire Color Types, matching eV3DShadingColorType.*/
#define V3D_SHADING_SINGLE_COLOR 2
#define V3D_SHADING_OBJECT_COLOR 4
#define V3D_SHADING_RANDOM_COLOR 1
/* ---- Opengl Depth conversion ---- */
float linear_depth(bool is_persp, float z, float zf, float zn)

View File

@ -440,6 +440,13 @@ static const EnumPropertyItem rna_enum_shading_color_type_items[] = {
{0, nullptr, 0, nullptr, nullptr},
};
static const EnumPropertyItem rna_enum_shading_wire_color_type_items[] = {
{V3D_SHADING_SINGLE_COLOR, "THEME", 0, "Theme", "Show scene wireframes with the theme's wire color"},
{V3D_SHADING_OBJECT_COLOR, "OBJECT", 0, "Object", "Show object color on wireframe"},
{V3D_SHADING_RANDOM_COLOR, "RANDOM", 0, "Random", "Show random object color on wireframe"},
{0, nullptr, 0, nullptr, nullptr},
};
static const EnumPropertyItem rna_enum_studio_light_items[] = {
{0, "DEFAULT", 0, "Default", ""},
{0, nullptr, 0, nullptr, nullptr},
@ -1322,34 +1329,6 @@ static PointerRNA rna_View3DShading_selected_studio_light_get(PointerRNA *ptr)
}
/* shading.light */
static const EnumPropertyItem *rna_View3DShading_color_type_itemf(bContext * /*C*/,
PointerRNA *ptr,
PropertyRNA * /*prop*/,
bool *r_free)
{
View3DShading *shading = (View3DShading *)ptr->data;
int totitem = 0;
if (shading->type == OB_WIRE) {
EnumPropertyItem *item = nullptr;
RNA_enum_items_add_value(
&item, &totitem, rna_enum_shading_color_type_items, V3D_SHADING_SINGLE_COLOR);
RNA_enum_items_add_value(
&item, &totitem, rna_enum_shading_color_type_items, V3D_SHADING_OBJECT_COLOR);
RNA_enum_items_add_value(
&item, &totitem, rna_enum_shading_color_type_items, V3D_SHADING_RANDOM_COLOR);
RNA_enum_item_end(&item, &totitem);
*r_free = true;
return item;
}
else {
/* Solid mode, or lookdev mode for workbench engine. */
*r_free = false;
return rna_enum_shading_color_type_items;
}
}
static void rna_View3DShading_studio_light_get_storage(View3DShading *shading,
char **dna_storage,
int *flag)
@ -4193,7 +4172,6 @@ static void rna_def_space_view3d_shading(BlenderRNA *brna)
prop = RNA_def_property(srna, "color_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, nullptr, "color_type");
RNA_def_property_enum_items(prop, rna_enum_shading_color_type_items);
RNA_def_property_enum_funcs(prop, nullptr, nullptr, "rna_View3DShading_color_type_itemf");
RNA_def_property_ui_text(prop, "Color", "Color Type");
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_update(
@ -4201,9 +4179,8 @@ static void rna_def_space_view3d_shading(BlenderRNA *brna)
prop = RNA_def_property(srna, "wireframe_color_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, nullptr, "wire_color_type");
RNA_def_property_enum_items(prop, rna_enum_shading_color_type_items);
RNA_def_property_enum_funcs(prop, nullptr, nullptr, "rna_View3DShading_color_type_itemf");
RNA_def_property_ui_text(prop, "Color", "Color Type");
RNA_def_property_enum_items(prop, rna_enum_shading_wire_color_type_items);
RNA_def_property_ui_text(prop, "Wire Color", "Wire Color Type");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D | NS_VIEW3D_SHADING, nullptr);
prop = RNA_def_property(srna, "single_color", PROP_FLOAT, PROP_COLOR);