Workbench: don't change to workbench drawtype for files saved in 2.8.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Wed, 18 Apr 2018 09:51:20 +0000 (11:51 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Wed, 18 Apr 2018 14:35:38 +0000 (16:35 +0200)
Assume files saved in 2.8 were intended for Eevee and set them to material
viewport shading. In Eevee this is equal to rendered draw mode, in Cycles
this will draw with Eevee. This way Eevee demo files still show something
interesting when opened.

release/scripts/startup/bl_ui/space_view3d.py
source/blender/blenloader/intern/versioning_280.c
source/blender/draw/intern/draw_manager.c
source/blender/editors/space_view3d/view3d_header.c
source/blender/makesrna/intern/rna_space.c

index 5e022aee0ed5bdd914f2e8a09c8233050134ce46..af032a7e75db1505d5660fe1a54d338b74bf1742 100644 (file)
@@ -46,10 +46,6 @@ class VIEW3D_HT_header(Header):
         # Contains buttons like Mode, Pivot, Manipulator, Layer, Mesh Select Mode...
         row = layout
         layout.template_header_3D()
-        row.prop(view, "viewport_shade", text="", icon_only=True)
-
-        if view.viewport_shade == "SOLID":
-            row.prop(view, "viewport_shade_solid", text="")
 
         if obj:
             mode = obj.mode
index b3cd1a6a1b7f5a8eae01f1e7ab2d31ca572cfd97..490344d30fa3ee4b34b05dfcbee4c21cb5f3049e 100644 (file)
@@ -934,6 +934,12 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main)
                                                View3D *v3d = (View3D *)sl;
                                                v3d->drawtype_solid = OB_LIGHTING_STUDIO;
                                                v3d->drawtype_wireframe = OB_LIGHTING_STUDIO;
+
+                                               /* Assume (demo) files written with 2.8 want to show
+                                                * Eevee renders in the viewport. */
+                                               if (MAIN_VERSION_ATLEAST(main, 280, 0)) {
+                                                       v3d->drawtype = OB_MATERIAL;
+                                               }
                                        }
                                }
                        }
index a147aed308cf1a39ce61ee3a19ab0490eafc246d..2ab661aa5dd4d06e6eda698e0e23cc93eb4af4ba 100644 (file)
@@ -915,6 +915,11 @@ static void drw_engines_enable_from_engine(RenderEngineType *engine_type, int dr
                case OB_TEXTURE:
                        break;
 
+               case OB_MATERIAL:
+                       engine_type = RE_engines_find("BLENDER_EEVEE");
+                       use_drw_engine(engine_type->draw_engine);
+                       break;
+
                default:
                case OB_RENDER:
                        /* TODO layers */
index 1f47f44f2f6e9ceb06eb850f3b110337c263f68b..563ff188f0d48315726e64022906ff005c4317a1 100644 (file)
@@ -303,6 +303,12 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
        /* other buttons: */
        UI_block_emboss_set(block, UI_EMBOSS);
 
+       /* Draw type */
+       uiItemR(layout, &v3dptr, "viewport_shade", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
+       if (v3d->drawtype == OB_SOLID) {
+               uiItemR(layout, &v3dptr, "viewport_shade_solid", 0, "", ICON_NONE);
+       }
+
        row = uiLayoutRow(layout, true);
        uiItemR(row, &v3dptr, "pivot_point", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
        if (!ob || ELEM(ob->mode, OB_MODE_OBJECT, OB_MODE_POSE, OB_MODE_WEIGHT_PAINT)) {
index 601a8bffcfaee68a57718f62a9b4bb2a6845f381..2d7dc477fe30af254fc781e673d05c1f6207366b 100644 (file)
@@ -668,9 +668,23 @@ static void rna_RegionView3D_view_matrix_set(PointerRNA *ptr, const float *value
 
 static int rna_SpaceView3D_viewport_shade_get(PointerRNA *ptr)
 {
+       bScreen *screen = ptr->id.data;
+       Scene *scene = WM_windows_scene_get_from_screen(G.main->wm.first, screen);
+       RenderEngineType *type = RE_engines_find(scene->view_render.engine_id);
        View3D *v3d = (View3D *)ptr->data;
-       int drawtype = v3d->drawtype;
-       return drawtype;
+
+       if (BKE_scene_uses_blender_eevee(scene)) {
+               if (v3d->drawtype == OB_MATERIAL) {
+                       return OB_RENDER;
+               }
+       }
+       else if (v3d->drawtype == OB_RENDER) {
+               if (!(type && type->render_to_view)) {
+                       return OB_MATERIAL;
+               }
+       }
+
+       return v3d->drawtype;
 }
 
 static void rna_SpaceView3D_viewport_shade_set(PointerRNA *ptr, int value)
@@ -683,14 +697,27 @@ static void rna_SpaceView3D_viewport_shade_set(PointerRNA *ptr, int value)
 }
 
 static const EnumPropertyItem *rna_SpaceView3D_viewport_shade_itemf(
-        bContext *UNUSED(C), PointerRNA *UNUSED(ptr),
+        bContext *C, PointerRNA *UNUSED(ptr),
         PropertyRNA *UNUSED(prop), bool *r_free)
 {
+       wmWindow *win = CTX_wm_window(C);
+       Scene *scene = WM_window_get_active_scene(win);
+       RenderEngineType *type = RE_engines_find(scene->view_render.engine_id);
+
        EnumPropertyItem *item = NULL;
        int totitem = 0;
 
        RNA_enum_items_add_value(&item, &totitem, rna_enum_viewport_shade_items, OB_SOLID);
-       RNA_enum_items_add_value(&item, &totitem, rna_enum_viewport_shade_items, OB_RENDER);
+
+       if (BKE_scene_uses_blender_eevee(scene)) {
+               RNA_enum_items_add_value(&item, &totitem, rna_enum_viewport_shade_items, OB_RENDER);
+       }
+       else {
+               RNA_enum_items_add_value(&item, &totitem, rna_enum_viewport_shade_items, OB_MATERIAL);
+               if (type && type->render_to_view) {
+                       RNA_enum_items_add_value(&item, &totitem, rna_enum_viewport_shade_items, OB_RENDER);
+               }
+       }
 
        RNA_enum_item_end(&item, &totitem);
        *r_free = true;