3D View: add object color drawing option
authorCampbell Barton <ideasman42@gmail.com>
Fri, 21 Dec 2018 00:40:47 +0000 (11:40 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 21 Dec 2018 00:45:01 +0000 (11:45 +1100)
Has some advantages over existing options.

- Using material links color to rendering with no way to vary colors
  if objects share a material.
- Random gives no control, objects may randomly have the same color,
  duplicating an object often changes it's color.

release/scripts/startup/bl_ui/space_view3d.py
source/blender/draw/engines/workbench/workbench_deferred.c
source/blender/draw/engines/workbench/workbench_forward.c
source/blender/draw/engines/workbench/workbench_materials.c
source/blender/makesdna/DNA_view3d_types.h
source/blender/makesrna/intern/rna_space.c

index 85c43e78e0a20fed91a0e8b73229ce2d2ecce8e8..c1b4849ddad6f66287e507e287f28c1383977ba8 100644 (file)
@@ -4378,7 +4378,7 @@ class VIEW3D_PT_shading(Panel):
     bl_space_type = 'VIEW_3D'
     bl_region_type = 'HEADER'
     bl_label = "Shading"
-    bl_ui_units_x = 11
+    bl_ui_units_x = 12
 
     @classmethod
     def get_shading(cls, context):
index 99c33697617be08dbc981d48d842e8b0ddf06eec..c3b469674d37a233a95d1939301c94d804d595ee 100644 (file)
@@ -832,7 +832,8 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
                                DRW_shgroup_call_object_add(material->shgrp, geom_array[i], ob);
                        }
                }
-               else if (ELEM(wpd->shading.color_type, V3D_SHADING_SINGLE_COLOR, V3D_SHADING_RANDOM_COLOR)) {
+               else if (ELEM(wpd->shading.color_type,
+                             V3D_SHADING_SINGLE_COLOR, V3D_SHADING_OBJECT_COLOR, V3D_SHADING_RANDOM_COLOR)) {
                        /* Draw solid color */
                        material = get_or_create_material_data(vedata, ob, NULL, NULL, wpd->shading.color_type);
                        if (is_sculpt_mode) {
index 7a0a5e2086473173b1b475dc2dd447dbaf4daac2..ca02cc2b5ea2fafb2d84c84ab14e94274b76f9ec 100644 (file)
@@ -528,7 +528,9 @@ void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob)
 
                /* Fallback from not drawn OB_TEXTURE mode or just OB_SOLID mode */
                if (!is_drawn) {
-                       if (ELEM(wpd->shading.color_type, V3D_SHADING_SINGLE_COLOR, V3D_SHADING_RANDOM_COLOR)) {
+                       if (ELEM(wpd->shading.color_type,
+                                V3D_SHADING_SINGLE_COLOR, V3D_SHADING_OBJECT_COLOR, V3D_SHADING_RANDOM_COLOR))
+                       {
                                /* No material split needed */
                                struct GPUBatch *geom = DRW_cache_object_surface_get(ob);
                                if (geom) {
index 5360cf3683b5cfacf02b4507971178e58ddc7fd4..faca4b401dcc871072a4a30a7eabc08335b6b834 100644 (file)
@@ -37,6 +37,10 @@ void workbench_material_update_data(WORKBENCH_PrivateData *wpd, Object *ob, Mate
                hsv_to_rgb_v(hsv, data->diffuse_color);
                copy_v3_v3(data->base_color, data->diffuse_color);
        }
+       else if (color_type == V3D_SHADING_OBJECT_COLOR) {
+               copy_v3_v3(data->diffuse_color, ob->col);
+               copy_v3_v3(data->base_color, data->diffuse_color);
+       }
        else {
                /* V3D_SHADING_MATERIAL_COLOR */
                if (mat) {
index 336dbec214b70334ba24520adabd297914467aad..72c9be2c12cf14dca0708cc319633b8a4fa9b454 100644 (file)
@@ -405,6 +405,7 @@ enum {
        V3D_SHADING_RANDOM_COLOR   = 1,
        V3D_SHADING_SINGLE_COLOR   = 2,
        V3D_SHADING_TEXTURE_COLOR  = 3,
+       V3D_SHADING_OBJECT_COLOR   = 4,
 };
 
 /* View3DShading->background_type */
index b77eed67d21fe3ff41f86d882e3647781e2b29e1..ef1b60272f3baa4f875e898fb421102f01dc9a23 100644 (file)
@@ -284,6 +284,7 @@ static const EnumPropertyItem rna_enum_viewport_lighting_items[] = {
 static const EnumPropertyItem rna_enum_shading_color_type_items[] = {
        {V3D_SHADING_SINGLE_COLOR,   "SINGLE",   0, "Single",   "Show scene in a single color"},
        {V3D_SHADING_MATERIAL_COLOR, "MATERIAL", 0, "Material", "Show material color"},
+       {V3D_SHADING_OBJECT_COLOR,   "OBJECT", 0, "Object",     "Show object color"},
        {V3D_SHADING_RANDOM_COLOR,   "RANDOM",   0, "Random",   "Show random object color"},
        {V3D_SHADING_TEXTURE_COLOR,  "TEXTURE",  0, "Texture",  "Show texture"},
        {0, NULL, 0, NULL, NULL}
@@ -819,6 +820,7 @@ static const EnumPropertyItem *rna_View3DShading_color_type_itemf(
        if (shading->type == OB_SOLID) {
                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_MATERIAL_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);
                if (shading->light != V3D_LIGHTING_MATCAP) {
                        RNA_enum_items_add_value(&item, &totitem, rna_enum_shading_color_type_items, V3D_SHADING_TEXTURE_COLOR);