From 392ac52ebb74cbd62857045930dca035f1a3971d Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Mon, 27 May 2024 18:16:04 +0200 Subject: [PATCH] UI: Toggle Camera Guides in Viewport Overlays Allow toggling camera composition guides in the 3DView Overlay popover. Pull Request: https://projects.blender.org/blender/blender/pulls/121923 --- scripts/startup/bl_ui/space_view3d.py | 2 ++ source/blender/blenkernel/BKE_blender_version.h | 2 +- source/blender/blenloader/intern/versioning_400.cc | 13 +++++++++++++ source/blender/editors/space_view3d/view3d_draw.cc | 2 +- source/blender/makesdna/DNA_view3d_defaults.h | 2 +- source/blender/makesdna/DNA_view3d_types.h | 1 + source/blender/makesrna/intern/rna_space.cc | 6 ++++++ 7 files changed, 25 insertions(+), 3 deletions(-) diff --git a/scripts/startup/bl_ui/space_view3d.py b/scripts/startup/bl_ui/space_view3d.py index c650f2c4b3f..468aa3eead9 100644 --- a/scripts/startup/bl_ui/space_view3d.py +++ b/scripts/startup/bl_ui/space_view3d.py @@ -7194,6 +7194,8 @@ class VIEW3D_PT_overlay_guides(Panel): sub = split.column() sub.prop(overlay, "show_text", text="Text Info") sub.prop(overlay, "show_stats", text="Statistics") + if view.region_3d.view_perspective == 'CAMERA': + sub.prop(overlay, "show_camera_guides", text="Camera Guides") sub = split.column() sub.prop(overlay, "show_cursor", text="3D Cursor") diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index 2d0c4065e9d..58cc474a772 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -29,7 +29,7 @@ extern "C" { /* Blender file format version. */ #define BLENDER_FILE_VERSION BLENDER_VERSION -#define BLENDER_FILE_SUBVERSION 44 +#define BLENDER_FILE_SUBVERSION 45 /* Minimum Blender version that supports reading file written with the current * version. Older Blender versions will test this and cancel loading the file, showing a warning to diff --git a/source/blender/blenloader/intern/versioning_400.cc b/source/blender/blenloader/intern/versioning_400.cc index 9a1c905046f..8bd9730dbc9 100644 --- a/source/blender/blenloader/intern/versioning_400.cc +++ b/source/blender/blenloader/intern/versioning_400.cc @@ -3650,6 +3650,19 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain) } } + if (!MAIN_VERSION_FILE_ATLEAST(bmain, 402, 45)) { + LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = static_cast(area->spacedata.first); + v3d->flag2 |= V3D_SHOW_CAMERA_GUIDES; + } + } + } + } + } + /** * Always bump subversion in BKE_blender_version.h when adding versioning * code here, and wrap it inside a MAIN_VERSION_FILE_ATLEAST check. diff --git a/source/blender/editors/space_view3d/view3d_draw.cc b/source/blender/editors/space_view3d/view3d_draw.cc index 9cd161d4a34..4e02ef8f60e 100644 --- a/source/blender/editors/space_view3d/view3d_draw.cc +++ b/source/blender/editors/space_view3d/view3d_draw.cc @@ -614,7 +614,7 @@ static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *region, } /* When overlays are disabled, only show camera outline & passepartout. */ - if (v3d->flag2 & V3D_HIDE_OVERLAYS) { + if (v3d->flag2 & V3D_HIDE_OVERLAYS || !(v3d->flag2 & V3D_SHOW_CAMERA_GUIDES)) { return; } diff --git a/source/blender/makesdna/DNA_view3d_defaults.h b/source/blender/makesdna/DNA_view3d_defaults.h index 1d97cd75d9b..ec6cfb3ec88 100644 --- a/source/blender/makesdna/DNA_view3d_defaults.h +++ b/source/blender/makesdna/DNA_view3d_defaults.h @@ -85,7 +85,7 @@ .gridflag = V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_FLOOR | V3D_SHOW_ORTHO_GRID, \ \ .flag = V3D_SELECT_OUTLINE, \ - .flag2 = V3D_SHOW_RECONSTRUCTION | V3D_SHOW_ANNOTATION | V3D_SHOW_VIEWER, \ + .flag2 = V3D_SHOW_RECONSTRUCTION | V3D_SHOW_ANNOTATION | V3D_SHOW_VIEWER | V3D_SHOW_CAMERA_GUIDES, \ \ .lens = 50.0f, \ .clip_start = 0.01f, \ diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index dfba5d3ebb2..ed453db8202 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -479,6 +479,7 @@ enum { V3D_FLAG2_UNUSED_15 = 1 << 15, /* cleared */ V3D_XR_SHOW_CONTROLLERS = 1 << 16, V3D_XR_SHOW_CUSTOM_OVERLAYS = 1 << 17, + V3D_SHOW_CAMERA_GUIDES = (1 << 18), }; /** #View3D::gp_flag (short) */ diff --git a/source/blender/makesrna/intern/rna_space.cc b/source/blender/makesrna/intern/rna_space.cc index 2e4c97ef1ed..b5dba4a9054 100644 --- a/source/blender/makesrna/intern/rna_space.cc +++ b/source/blender/makesrna/intern/rna_space.cc @@ -4546,6 +4546,12 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Show Statistics", "Display scene statistics overlay text"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, nullptr); + /* show camera composition guides */ + prop = RNA_def_property(srna, "show_camera_guides", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "flag2", V3D_SHOW_CAMERA_GUIDES); + RNA_def_property_ui_text(prop, "Show Camera Guides", "Show camera composition guides"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, nullptr); + prop = RNA_def_property(srna, "show_extras", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_negative_sdna( prop, nullptr, "overlay.flag", V3D_OVERLAY_HIDE_OBJECT_XTRAS);