Commit: 57b624d85c5795cd7d3d05482e2d64391c8698f6
Author: Julian Eisel
Date:   Wed Jun 22 02:36:38 2016 +0200
Branches: soc-2016-layer_manager
https://developer.blender.org/rB57b624d85c5795cd7d3d05482e2d64391c8698f6

Wireframe/outline color from layer color-set

This commit makes wireframe/outline drawing of objects use the color-set of the 
highest layer in the hierarchy. This is an example of how a render engine 
(viewport in this case) can make use of the custom layer properties.
A local 3D View toggle allows quick toggling of the wireframe/outline colors.

On the general topic of custom wireframe colors: The layer based coloring makes 
it easy for users to assign colors that have meaning and are not just arbitrary 
choices. I discussed this with Ton, Sebastian König and others before, we all 
agreed that this is a pretty sane solution.
Also note that the colors are based on theme settings, which was a requirenment 
to avoid theme contrast issues.

Based on P158 by @campbellbarton.

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

M       release/scripts/startup/bl_ui/space_view3d.py
M       source/blender/blenkernel/BKE_object.h
M       source/blender/blenkernel/intern/object_layer.c
M       source/blender/editors/space_view3d/drawobject.c
M       source/blender/editors/space_view3d/view3d_draw.c
M       source/blender/editors/space_view3d/view3d_intern.h
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 b88b831..12fd776 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -3270,6 +3270,9 @@ class VIEW3D_PT_view3d_shading(Panel):
         if not scene.render.use_shading_nodes:
             col.prop(gs, "material_mode", text="")
 
+        if view.viewport_shade in {'BOUNDBOX', 'WIREFRAME', 'SOLID'}:
+            col.prop(view, "use_wire_color")
+
         if view.viewport_shade == 'SOLID':
             col.prop(view, "show_textured_solid")
             col.prop(view, "use_matcap")
diff --git a/source/blender/blenkernel/BKE_object.h 
b/source/blender/blenkernel/BKE_object.h
index 8ae9cc2..2553d5f 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -288,6 +288,7 @@ LayerTreeItem *BKE_objectlayer_add(
 void BKE_objectlayer_free(LayerTreeItem *litem);
 void BKE_objectlayer_base_assign(Base *base, LayerTreeItem *litem);
 void BKE_objectlayer_base_unassign(const Base *base, LayerTreeItem *litem);
+LayerTypeObject *BKE_objectlayer_from_base(LayerTree *ltree, const Base *base, 
const bool inverse);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenkernel/intern/object_layer.c 
b/source/blender/blenkernel/intern/object_layer.c
index 62829cd..cdb61b5 100644
--- a/source/blender/blenkernel/intern/object_layer.c
+++ b/source/blender/blenkernel/intern/object_layer.c
@@ -93,3 +93,31 @@ void BKE_objectlayer_base_unassign(const Base *base, 
LayerTreeItem *litem)
 
        objectlayer_array_resize(oblayer, oblayer->tot_bases - 1);
 }
+
+/**
+ * Find the first layer that has \a base in it.
+ * \param inverse: Do inverse loockup to find last layer rather than first one.
+ */
+LayerTypeObject *BKE_objectlayer_from_base(LayerTree *ltree, const Base *base, 
const bool inverse)
+{
+       BLI_assert(ltree->type == LAYER_TREETYPE_OBJECT);
+
+       for (int i = inverse ? ltree->tot_items - 1 : 0;
+            inverse ? i >= 0 : i < ltree->tot_items;
+            inverse ? i-- : i++)
+       {
+               LayerTreeItem *litem = ltree->items_all[i];
+               if (litem->type->type == LAYER_ITEMTYPE_LAYER) {
+                       LayerTypeObject *oblayer = (LayerTypeObject *)litem;
+                       BKE_OBJECTLAYER_BASES_ITER_START(oblayer, j, iterbase)
+                       {
+                               if (iterbase == base) {
+                                       return oblayer;
+                               }
+                       }
+                       BKE_OBJECTLAYER_BASES_ITER_END;
+               }
+       }
+
+       return NULL;
+}
diff --git a/source/blender/editors/space_view3d/drawobject.c 
b/source/blender/editors/space_view3d/drawobject.c
index 07e8325..ee67850 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -7573,11 +7573,28 @@ void draw_object(Scene *scene, ARegion *ar, View3D 
*v3d, Base *base, const short
 
        /* which wire color */
        if ((dflag & DRAW_CONSTCOLOR) == 0) {
+               const bool is_wire_color = V3D_IS_WIRECOLOR(v3d);
+               bool use_wire_color = false;
 
                ED_view3d_project_base(ar, base);
 
-               draw_object_wire_color(scene, base, _ob_wire_col);
-               ob_wire_col = _ob_wire_col;
+               if (is_wire_color) {
+                       ThemeWireColor *wcol = 
view3d_layer_color_from_base(scene->object_layers, base);
+                       if (wcol) {
+                               if (base->flag & SELECT) {
+                                       ob_wire_col = (unsigned char 
*)(scene->basact == base ? wcol->active : wcol->select);
+                               }
+                               else {
+                                       ob_wire_col = (unsigned char 
*)wcol->solid;
+                               }
+                               use_wire_color = true;
+                       }
+               }
+               /* fallback to theme setting */
+               if (!use_wire_color) {
+                       draw_object_wire_color(scene, base, _ob_wire_col);
+                       ob_wire_col = _ob_wire_col;
+               }
 
                glColor3ubv(ob_wire_col);
        }
diff --git a/source/blender/editors/space_view3d/view3d_draw.c 
b/source/blender/editors/space_view3d/view3d_draw.c
index f292084..c41a435 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -92,6 +92,8 @@
 #include "ED_screen_types.h"
 #include "ED_transform.h"
 
+#include "RNA_access.h"
+
 #include "UI_interface.h"
 #include "UI_interface_icons.h"
 #include "UI_resources.h"
@@ -121,6 +123,15 @@ extern void bl_debug_draw_edge_add(const float v0[3], 
const float v1[3]);
 extern void bl_debug_color_set(const unsigned int col);
 #endif
 
+ThemeWireColor *view3d_layer_color_from_base(LayerTree *ltree, const Base 
*base)
+{
+       bTheme *btheme = UI_GetTheme();
+       LayerTypeObject *oblayer = BKE_objectlayer_from_base(ltree, base, true);
+       const int col_idx = oblayer ? RNA_enum_get(oblayer->litem.ptr, 
"color_set") : 0;
+
+       return (col_idx > 0) ? &btheme->tarm[col_idx - 1] : NULL;
+}
+
 void circf(float x, float y, float rad)
 {
        GLUquadricObj *qobj = gluNewQuadric(); 
@@ -2213,13 +2224,32 @@ static void draw_dupli_objects(Scene *scene, ARegion 
*ar, View3D *v3d, Base *bas
 {
        /* define the color here so draw_dupli_objects_color can be called
         * from the set loop */
+       const bool is_wire_color = V3D_IS_WIRECOLOR(v3d);
+       bool use_wire_color = false;
+       short dflag;
+       int color;
+
+       if (is_wire_color) {
+               ThemeWireColor *wcol = 
view3d_layer_color_from_base(scene->object_layers, base);
+               if (wcol) {
+                       glColor3ubv((unsigned char *)(base->flag & SELECT ? 
wcol->select : wcol->solid));
+
+                       color = TH_UNDEFINED;
+                       dflag = DRAW_CONSTCOLOR;
+                       use_wire_color = true;
+               }
+       }
+
+       /* fallback to theme setting */
+       if (!use_wire_color) {
+               color = (base->flag & SELECT) ? TH_SELECT : TH_WIRE;
+               /* debug */
+               if (base->object->dup_group && base->object->dup_group->id.us < 
1)
+                       color = TH_REDALERT;
+               dflag = 0;
+       }
        
-       int color = (base->flag & SELECT) ? TH_SELECT : TH_WIRE;
-       /* debug */
-       if (base->object->dup_group && base->object->dup_group->id.us < 1)
-               color = TH_REDALERT;
-       
-       draw_dupli_objects_color(scene, ar, v3d, base, 0, color);
+       draw_dupli_objects_color(scene, ar, v3d, base, dflag, color);
 }
 
 /* XXX warning, not using gpu offscreen here */
diff --git a/source/blender/editors/space_view3d/view3d_intern.h 
b/source/blender/editors/space_view3d/view3d_intern.h
index 6d831c6..88bddf1 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -192,6 +192,7 @@ void ED_view3d_draw_depth(Scene *scene, struct ARegion *ar, 
View3D *v3d, bool al
 void ED_view3d_draw_depth_gpencil(Scene *scene, ARegion *ar, View3D *v3d);
 void ED_view3d_after_add(ListBase *lb, Base *base, const short dflag);
 
+struct ThemeWireColor *view3d_layer_color_from_base(struct LayerTree *ltree, 
const Base *base);
 void circf(float x, float y, float rad);
 void circ(float x, float y, float rad);
 void view3d_update_depths_rect(struct ARegion *ar, struct ViewDepths *d, 
struct rcti *rect);
diff --git a/source/blender/makesdna/DNA_view3d_types.h 
b/source/blender/makesdna/DNA_view3d_types.h
index 5b533d1..b7a336a 100644
--- a/source/blender/makesdna/DNA_view3d_types.h
+++ b/source/blender/makesdna/DNA_view3d_types.h
@@ -301,6 +301,7 @@ typedef struct View3D {
        (((view) >= RV3D_VIEW_FRONT) && ((view) <= RV3D_VIEW_BOTTOM))
 
 /* View3d->flag2 (short) */
+#define V3D_WIRE_COLOR_NOCUSTOM (1 << 1)
 #define V3D_RENDER_OVERRIDE            (1 << 2)
 #define V3D_SOLID_TEX                  (1 << 3)
 #define V3D_SHOW_GPENCIL               (1 << 4)
@@ -388,6 +389,10 @@ enum {
 
 #define V3D_BGPIC_EXPANDED (V3D_BGPIC_EXPANDED | V3D_BGPIC_CAMERACLIP)
 
+#define V3D_IS_WIRECOLOR(v3d) \
+       (((v3d)->drawtype <= OB_SOLID) && \
+        (((v3d)->flag2 & V3D_WIRE_COLOR_NOCUSTOM) == 0))
+
 /* BGPic->source */
 /* may want to use 1 for select ?*/
 #define V3D_BGPIC_IMAGE                0
diff --git a/source/blender/makesrna/intern/rna_space.c 
b/source/blender/makesrna/intern/rna_space.c
index 77b55fa..741576e 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -2694,6 +2694,11 @@ static void rna_def_space_view3d(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Show 3D Marker Names", "Show names for 
reconstructed tracks objects");
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 
+       prop = RNA_def_property(srna, "use_wire_color", PROP_BOOLEAN, 
PROP_NONE);
+       RNA_def_property_boolean_negative_sdna(prop, NULL, "flag2", 
V3D_WIRE_COLOR_NOCUSTOM);
+       RNA_def_property_ui_text(prop, "Color Wire", "Draw wireframes using 
layer color");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
        prop = RNA_def_property(srna, "use_matcap", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag2", V3D_SOLID_MATCAP);
        RNA_def_property_ui_text(prop, "Matcap", "Active Objects draw images 
mapped on normals, enhancing Solid Draw Mode");

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to