3D View: add initial view.shading and view.overlay in RNA.

These are mostly empty still, many properties need to be renamed and moved there.
This commit is contained in:
Brecht Van Lommel 2018-04-29 09:44:57 +02:00
parent 03957b9487
commit e017876f78
Notes: blender-bot 2023-02-14 06:46:23 +01:00
Referenced by issue #54883, Crash when opening file left in sculpt mode
8 changed files with 118 additions and 55 deletions

View File

@ -586,11 +586,11 @@ kmi.properties.nr = 9
kmi = km.keymap_items.new('view3d.layers', 'ZERO', 'PRESS', any=True)
kmi.properties.nr = 10
kmi = km.keymap_items.new('wm.context_toggle_enum', 'F3', 'PRESS')
kmi.properties.data_path = 'space_data.viewport_shade'
kmi.properties.data_path = 'space_data.shading.type'
kmi.properties.value_1 = 'SOLID'
kmi.properties.value_2 = 'WIREFRAME'
kmi = km.keymap_items.new('wm.context_toggle_enum', 'Z', 'PRESS', alt=True)
kmi.properties.data_path = 'space_data.viewport_shade'
kmi.properties.data_path = 'space_data.shading.type'
kmi.properties.value_1 = 'SOLID'
kmi.properties.value_2 = 'TEXTURED'
kmi = km.keymap_items.new('view3d.select_or_deselect_all', 'SELECTMOUSE', 'CLICK')

View File

@ -987,11 +987,11 @@ kmi = km.keymap_items.new('view3d.view_orbit', 'WHEELDOWNMOUSE', 'PRESS', shift=
kmi.properties.type = 'ORBITDOWN'
kmi = km.keymap_items.new('view3d.localview', 'I', 'PRESS', shift=True)
kmi = km.keymap_items.new('wm.context_toggle_enum', 'FOUR', 'PRESS')
kmi.properties.data_path = 'space_data.viewport_shade'
kmi.properties.data_path = 'space_data.shading.type'
kmi.properties.value_1 = 'WIREFRAME'
kmi.properties.value_2 = 'WIREFRAME'
kmi = km.keymap_items.new('wm.context_toggle_enum', 'FIVE', 'PRESS')
kmi.properties.data_path = 'space_data.viewport_shade'
kmi.properties.data_path = 'space_data.shading.type'
kmi.properties.value_1 = 'TEXTURED'
kmi.properties.value_2 = 'SOLID'
kmi = km.keymap_items.new('view3d.select_or_deselect_all', 'SELECTMOUSE', 'CLICK')
@ -1080,7 +1080,7 @@ kmi.properties.rotate = True
kmi = km.keymap_items.new('view3d.enable_manipulator', 'R', 'PRESS')
kmi.properties.scale = True
kmi = km.keymap_items.new('wm.context_toggle_enum', 'SIX', 'PRESS')
kmi.properties.data_path = 'space_data.viewport_shade'
kmi.properties.data_path = 'space_data.shading.type'
kmi.properties.value_1 = 'TEXTURED'
kmi.properties.value_2 = 'TEXTURED'
kmi = km.keymap_items.new('wm.context_set_enum', 'X', 'PRESS')

View File

@ -34,6 +34,7 @@ class VIEW3D_HT_header(Header):
layout = self.layout
view = context.space_data
shading = view.shading
# mode_string = context.mode
obj = context.active_object
toolsettings = context.tool_settings
@ -46,7 +47,7 @@ class VIEW3D_HT_header(Header):
# Contains buttons like Mode, Pivot, Manipulator, Layer, Mesh Select Mode...
row = layout
row.popover(space_type='VIEW_3D', region_type='UI', panel_type="VIEW3D_PT_shading", text="Shading")
row.popover(space_type='VIEW_3D', region_type='UI', panel_type="VIEW3D_PT_overlays", text="Overlay")
row.popover(space_type='VIEW_3D', region_type='UI', panel_type="VIEW3D_PT_overlay", text="Overlay")
layout.template_header_3D()
@ -57,7 +58,7 @@ class VIEW3D_HT_header(Header):
row.prop(toolsettings.particle_edit, "select_mode", text="", expand=True)
# Occlude geometry
if ((view.viewport_shade not in {'BOUNDBOX', 'WIREFRAME'} and (mode == 'PARTICLE_EDIT' or (mode == 'EDIT' and obj.type == 'MESH'))) or
if ((shading.type not in {'BOUNDBOX', 'WIREFRAME'} and (mode == 'PARTICLE_EDIT' or (mode == 'EDIT' and obj.type == 'MESH'))) or
(mode in {'WEIGHT_PAINT', 'VERTEX_PAINT'})):
row.prop(view, "use_occlude_geometry", text="")
@ -3529,15 +3530,16 @@ class VIEW3D_PT_shading(Panel):
layout = self.layout
view = context.space_data
shading = view.shading
col = layout.column()
col.prop(view, "viewport_shade", expand=True)
col.prop(shading, "type", expand=True)
if view.viewport_shade == 'SOLID':
if shading.type == 'SOLID':
col.separator()
col.row().prop(view, "viewport_lighting", expand=True)
col.row().prop(shading, "light", expand=True)
if view.viewport_lighting == 'STUDIO':
if shading.light == 'STUDIO':
# TODO: don't store these settings in the scene
scene = context.scene
props = scene.layer_properties['BLENDER_WORKBENCH']
@ -3576,15 +3578,17 @@ class VIEW3D_PT_overlay(Panel):
layout = self.layout
view = context.space_data
overlay = view.overlay
shading = view.shading
scene = context.scene
col = layout.column()
col.prop(view, "show_only_render", text="Show Overlays")
col.prop(overlay, "show_overlays")
col.separator()
col.prop(view, "show_world")
if view.viewport_shade == "SOLID":
if shading.type == "SOLID":
col.prop(view, "show_random_object_colors")
col.prop(view, "show_object_overlap")
@ -3592,7 +3596,7 @@ class VIEW3D_PT_overlay(Panel):
col.prop(view, "show_mode_shade_override")
col = layout.column()
display_all = not view.show_only_render
display_all = overlay.show_overlays
col.active = display_all
col.prop(view, "show_outline_selected")
col.prop(view, "show_all_objects_origin")
@ -4059,7 +4063,7 @@ classes = (
VIEW3D_PT_view3d_meshstatvis,
VIEW3D_PT_view3d_curvedisplay,
VIEW3D_PT_shading,
VIEW3D_PT_overlays,
VIEW3D_PT_overlay,
VIEW3D_PT_transform_orientations,
VIEW3D_PT_context_properties,
)

View File

@ -404,12 +404,12 @@ void view3d_keymap(wmKeyConfig *keyconf)
/* drawtype */
kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", ZKEY, KM_PRESS, 0, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.viewport_shade");
RNA_string_set(kmi->ptr, "data_path", "space_data.shading.type");
RNA_string_set(kmi->ptr, "value_1", "SOLID");
RNA_string_set(kmi->ptr, "value_2", "WIREFRAME");
kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", ZKEY, KM_PRESS, KM_ALT, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.viewport_shade");
RNA_string_set(kmi->ptr, "data_path", "space_data.shading.type");
RNA_string_set(kmi->ptr, "value_1", "SOLID");
RNA_string_set(kmi->ptr, "value_2", "TEXTURED");

View File

@ -165,7 +165,7 @@ extern const EnumPropertyItem rna_enum_property_type_items[];
extern const EnumPropertyItem rna_enum_property_subtype_items[];
extern const EnumPropertyItem rna_enum_property_unit_items[];
extern const EnumPropertyItem rna_enum_viewport_shade_items[];
extern const EnumPropertyItem rna_enum_shading_type_items[];
extern const EnumPropertyItem rna_enum_navigation_mode_items[];

View File

@ -4823,7 +4823,6 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
srna = RNA_def_struct(brna, "RenderSettings", NULL);
RNA_def_struct_sdna(srna, "RenderData");
RNA_def_struct_nested(brna, srna, "Scene");
RNA_def_struct_path_func(srna, "rna_RenderSettings_path");
RNA_def_struct_ui_text(srna, "Render Data", "Rendering settings for a Scene data-block");
/* Render Data */
@ -5330,14 +5329,14 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
prop = RNA_def_property(srna, "sequencer_gl_preview", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "seq_prev_type");
RNA_def_property_enum_items(prop, rna_enum_viewport_shade_items);
RNA_def_property_enum_items(prop, rna_enum_shading_type_items);
RNA_def_property_ui_text(prop, "Sequencer Preview Shading", "Method to draw in the sequencer view");
RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SceneSequencer_update");
#if 0 /* UNUSED, see R_SEQ_GL_REND comment */
prop = RNA_def_property(srna, "sequencer_gl_render", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "seq_rend_type");
RNA_def_property_enum_items(prop, rna_enum_viewport_shade_items);
RNA_def_property_enum_items(prop, rna_enum_shading_type_items);
/* XXX Label and tooltips are obviously wrong! */
RNA_def_property_ui_text(prop, "Sequencer Preview Shading", "Method to draw in the sequencer view");
#endif

View File

@ -175,7 +175,7 @@ static const EnumPropertyItem autosnap_items[] = {
};
#endif
const EnumPropertyItem rna_enum_viewport_shade_items[] = {
const EnumPropertyItem rna_enum_shading_type_items[] = {
{OB_WIRE, "WIREFRAME", ICON_WIRE, "Wireframe", "Display the object as wire edges"},
{OB_SOLID, "SOLID", ICON_SOLID, "Solid", "Display the object solid"},
{OB_TEXTURE, "TEXTURED", ICON_POTATO, "Texture", "Display the object solid, with a texture"},
@ -491,7 +491,7 @@ static void rna_SpaceView3D_layer_update(Main *bmain, Scene *UNUSED(scene), Poin
DEG_on_visible_update(bmain, false);
}
static void rna_SpaceView3D_viewport_shade_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
static void rna_3DViewShading_type_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
{
View3D *v3d = (View3D *)(ptr->data);
ScrArea *sa = rna_area_from_space(ptr);
@ -649,7 +649,7 @@ static void rna_RegionView3D_view_matrix_set(PointerRNA *ptr, const float *value
ED_view3d_from_m4(mat, rv3d->ofs, rv3d->viewquat, &rv3d->dist);
}
static int rna_SpaceView3D_viewport_shade_get(PointerRNA *ptr)
static int rna_3DViewShading_type_get(PointerRNA *ptr)
{
bScreen *screen = ptr->id.data;
Scene *scene = WM_windows_scene_get_from_screen(G.main->wm.first, screen);
@ -670,7 +670,7 @@ static int rna_SpaceView3D_viewport_shade_get(PointerRNA *ptr)
return v3d->drawtype;
}
static void rna_SpaceView3D_viewport_shade_set(PointerRNA *ptr, int value)
static void rna_3DViewShading_type_set(PointerRNA *ptr, int value)
{
View3D *v3d = (View3D *)ptr->data;
if (value != v3d->drawtype && value == OB_RENDER) {
@ -679,7 +679,7 @@ static void rna_SpaceView3D_viewport_shade_set(PointerRNA *ptr, int value)
v3d->drawtype = value;
}
static const EnumPropertyItem *rna_SpaceView3D_viewport_shade_itemf(
static const EnumPropertyItem *rna_3DViewShading_type_itemf(
bContext *C, PointerRNA *UNUSED(ptr),
PropertyRNA *UNUSED(prop), bool *r_free)
{
@ -690,15 +690,15 @@ static const EnumPropertyItem *rna_SpaceView3D_viewport_shade_itemf(
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_shading_type_items, OB_SOLID);
if (BKE_scene_uses_blender_eevee(scene)) {
RNA_enum_items_add_value(&item, &totitem, rna_enum_viewport_shade_items, OB_RENDER);
RNA_enum_items_add_value(&item, &totitem, rna_enum_shading_type_items, OB_RENDER);
}
else {
RNA_enum_items_add_value(&item, &totitem, rna_enum_viewport_shade_items, OB_MATERIAL);
RNA_enum_items_add_value(&item, &totitem, rna_enum_shading_type_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_items_add_value(&item, &totitem, rna_enum_shading_type_items, OB_RENDER);
}
}
@ -720,6 +720,26 @@ static const EnumPropertyItem *rna_SpaceView3D_stereo3d_camera_itemf(
return stereo3d_camera_items;
}
static PointerRNA rna_SpaceView3D_shading_get(PointerRNA *ptr)
{
return rna_pointer_inherit_refine(ptr, &RNA_View3DShading, ptr->data);
}
static char *rna_View3DShading_path(PointerRNA *UNUSED(ptr))
{
return BLI_sprintfN("shading");
}
static PointerRNA rna_SpaceView3D_overlay_get(PointerRNA *ptr)
{
return rna_pointer_inherit_refine(ptr, &RNA_View3DOverlay, ptr->data);
}
static char *rna_View3DOverlay_path(PointerRNA *UNUSED(ptr))
{
return BLI_sprintfN("overlay");
}
/* Space Image Editor */
static PointerRNA rna_SpaceImageEditor_uvedit_get(PointerRNA *ptr)
@ -2159,6 +2179,49 @@ static void rna_def_space_outliner(BlenderRNA *brna)
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
}
static void rna_def_space_view3d_shading(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "View3DShading", NULL);
RNA_def_struct_sdna(srna, "View3D");
RNA_def_struct_nested(brna, srna, "SpaceView3D");
RNA_def_struct_path_func(srna, "rna_View3DShading_path");
RNA_def_struct_ui_text(srna, "3D View Shading Settings", "Settings for shading in the 3D viewport");
prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "drawtype");
RNA_def_property_enum_items(prop, rna_enum_shading_type_items);
RNA_def_property_enum_funcs(prop, "rna_3DViewShading_type_get", "rna_3DViewShading_type_set",
"rna_3DViewShading_type_itemf");
RNA_def_property_ui_text(prop, "Viewport Shading", "Method to display/shade objects in the 3D View");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_3DViewShading_type_update");
prop = RNA_def_property(srna, "light", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "drawtype_lighting");
RNA_def_property_enum_items(prop, rna_enum_viewport_lighting_items);
RNA_def_property_ui_text(prop, "Lighting", "Lighting Method for Solid/Texture Viewport Shading");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_3DViewShading_type_update");
}
static void rna_def_space_view3d_overlay(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "View3DOverlay", NULL);
RNA_def_struct_sdna(srna, "View3D");
RNA_def_struct_nested(brna, srna, "SpaceView3D");
RNA_def_struct_path_func(srna, "rna_View3DOverlay_path");
RNA_def_struct_ui_text(srna, "3D View Overlay Settings", "Settings for display of overlays in the 3D viewport");
prop = RNA_def_property(srna, "show_overlays", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag2", V3D_RENDER_OVERRIDE);
RNA_def_property_ui_text(prop, "Show Overlays", "Display overlays like manipulators and outlines");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
}
static void rna_def_space_view3d(BlenderRNA *brna)
{
StructRNA *srna;
@ -2269,37 +2332,23 @@ static void rna_def_space_view3d(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Lock to Cursor", "3D View center is locked to the cursor's position");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "viewport_shade", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "drawtype");
RNA_def_property_enum_items(prop, rna_enum_viewport_shade_items);
RNA_def_property_enum_funcs(prop, "rna_SpaceView3D_viewport_shade_get", "rna_SpaceView3D_viewport_shade_set",
"rna_SpaceView3D_viewport_shade_itemf");
RNA_def_property_ui_text(prop, "Viewport Shading", "Method to display/shade objects in the 3D View");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_SpaceView3D_viewport_shade_update");
prop = RNA_def_property(srna, "viewport_lighting", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "drawtype_lighting");
RNA_def_property_enum_items(prop, rna_enum_viewport_lighting_items);
RNA_def_property_ui_text(prop, "Viewport Lighting", "Lighting Method for Solid/Texture Viewport Shading");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_SpaceView3D_viewport_shade_update");
prop = RNA_def_property(srna, "show_face_orientation_overlay", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "overlays", V3D_OVERLAY_FACE_ORIENTATION);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_ui_text(prop, "Face Orientation", "Show the Face Orientation Overlay");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_SpaceView3D_viewport_shade_update");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_3DViewShading_type_update");
prop = RNA_def_property(srna, "show_random_object_colors", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "drawtype_options", V3D_DRAWOPTION_RANDOMIZE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_ui_text(prop, "Random Colors", "Show random object colors");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_SpaceView3D_viewport_shade_update");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_3DViewShading_type_update");
prop = RNA_def_property(srna, "show_object_overlap", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "drawtype_options", V3D_DRAWOPTION_OBJECT_OVERLAP);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_ui_text(prop, "Object Overlap", "Show Object Overlap");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_SpaceView3D_viewport_shade_update");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_3DViewShading_type_update");
prop = RNA_def_property(srna, "local_view", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "localvd");
@ -2432,11 +2481,6 @@ static void rna_def_space_view3d(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Lock Camera to View", "Enable view navigation within the camera view");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "show_only_render", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag2", V3D_RENDER_OVERRIDE);
RNA_def_property_ui_text(prop, "Only Render", "Display only objects which will be rendered");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "show_world", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag3", V3D_SHOW_WORLD);
RNA_def_property_ui_text(prop, "World Background", "Display world colors in the background");
@ -2594,6 +2638,22 @@ static void rna_def_space_view3d(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Volume Alpha", "Opacity (alpha) of the cameras' frustum volume");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
/* Nested Structs */
prop = RNA_def_property(srna, "shading", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
RNA_def_property_struct_type(prop, "View3DShading");
RNA_def_property_pointer_funcs(prop, "rna_SpaceView3D_shading_get", NULL, NULL, NULL);
RNA_def_property_ui_text(prop, "Shading Settings", "Settings for shading in the 3D viewport");
prop = RNA_def_property(srna, "overlay", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
RNA_def_property_struct_type(prop, "View3DOverlay");
RNA_def_property_pointer_funcs(prop, "rna_SpaceView3D_overlay_get", NULL, NULL, NULL);
RNA_def_property_ui_text(prop, "Overlay Settings", "Settings for display of overlays in the 3D viewport");
rna_def_space_view3d_shading(brna);
rna_def_space_view3d_overlay(brna);
/* *** Animated *** */
RNA_define_animate_sdna(true);
/* region */

View File

@ -38,12 +38,12 @@ USE_QUICK_RENDER = False
def render_gl(context, filepath, shade):
def ctx_viewport_shade(context, shade):
def ctx_shading_type(context, shade):
for area in context.window.screen.areas:
if area.type == 'VIEW_3D':
space = area.spaces.active
# rv3d = space.region_3d
space.viewport_shade = shade
space.shading.type = shade
import bpy
scene = context.scene
@ -59,7 +59,7 @@ def render_gl(context, filepath, shade):
render.resolution_x = 512
render.resolution_y = 512
ctx_viewport_shade(context, shade)
ctx_shading_type(context, shade)
#~ # stop to inspect!
#~ if filepath == "test_cube_shell_solidify_subsurf_wp_wire":