diff options
Diffstat (limited to 'source/blender/editors/space_view3d')
15 files changed, 157 insertions, 62 deletions
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index c1c7147b3b1..3357e872af7 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -752,6 +752,7 @@ static void view3d_ob_drop_copy_external_asset(bContext *UNUSED(C), wmDrag *drag RNA_int_set(drop->ptr, "session_uuid", id->session_uuid); + BKE_view_layer_synced_ensure(scene, view_layer); Base *base = BKE_view_layer_base_find(view_layer, (Object *)id); if (base != NULL) { BKE_view_layer_base_select_and_set_active(view_layer, base); @@ -804,6 +805,7 @@ static void view3d_collection_drop_copy_external_asset(bContext *UNUSED(C), /* Make an object active, just use the first one in the collection. */ CollectionObject *cobject = collection->gobject.first; + BKE_view_layer_synced_ensure(scene, view_layer); Base *base = cobject ? BKE_view_layer_base_find(view_layer, cobject->ob) : NULL; if (base) { BLI_assert((base->flag & BASE_SELECTABLE) && (base->flag & BASE_ENABLED_VIEWPORT)); @@ -1404,7 +1406,9 @@ static void view3d_main_region_message_subscribe(const wmRegionMessageSubscribeP WM_msg_subscribe_rna_anon_type(mbus, SceneDisplay, &msg_sub_value_region_tag_redraw); WM_msg_subscribe_rna_anon_type(mbus, ObjectDisplay, &msg_sub_value_region_tag_redraw); + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(scene, view_layer); Object *obact = BKE_view_layer_active_object_get(view_layer); if (obact != NULL) { switch (obact->mode) { @@ -1439,7 +1443,9 @@ static void view3d_main_region_cursor(wmWindow *win, ScrArea *area, ARegion *reg return; } + Scene *scene = WM_window_get_active_scene(win); ViewLayer *view_layer = WM_window_get_active_view_layer(win); + BKE_view_layer_synced_ensure(scene, view_layer); Object *obedit = BKE_view_layer_edit_object_get(view_layer); if (obedit) { WM_cursor_set(win, WM_CURSOR_EDIT); @@ -1888,11 +1894,14 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes * without showing the object. * * See T85532 for alternatives that were considered. */ + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - if (view_layer->basact) { - Object *ob = view_layer->basact->object; + BKE_view_layer_synced_ensure(scene, view_layer); + Base *base = BKE_view_layer_active_base_get(view_layer); + if (base) { + Object *ob = base->object; /* if hidden but in edit mode, we still display, can happen with animation */ - if ((view_layer->basact->flag & BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT) != 0 || + if ((base->flag & BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT) != 0 || (ob->mode != OB_MODE_OBJECT)) { CTX_data_id_pointer_set(result, &ob->id); } diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c index fe7e3a797c9..04824097e05 100644 --- a/source/blender/editors/space_view3d/view3d_buttons.c +++ b/source/blender/editors/space_view3d/view3d_buttons.c @@ -1278,8 +1278,10 @@ static void do_view3d_vgroup_buttons(bContext *C, void *UNUSED(arg), int event) return; } + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = view_layer->basact->object; + BKE_view_layer_synced_ensure(scene, view_layer); + Object *ob = BKE_view_layer_active_object_get(view_layer); ED_vgroup_vert_active_mirror(ob, event - B_VGRP_PNL_EDIT_SINGLE); DEG_id_tag_update(ob->data, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); @@ -1287,7 +1289,9 @@ static void do_view3d_vgroup_buttons(bContext *C, void *UNUSED(arg), int event) static bool view3d_panel_vgroup_poll(const bContext *C, PanelType *UNUSED(pt)) { + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); if (ob && (BKE_object_is_in_editmode_vgroup(ob) || BKE_object_is_in_wpaint_select_vert(ob))) { MDeformVert *dvert_act = ED_mesh_active_dvert_get_only(ob); @@ -1304,7 +1308,8 @@ static void view3d_panel_vgroup(const bContext *C, Panel *panel) uiBlock *block = uiLayoutAbsoluteBlock(panel->layout); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = view_layer->basact->object; + BKE_view_layer_synced_ensure(scene, view_layer); + Object *ob = BKE_view_layer_active_object_get(view_layer); MDeformVert *dv; @@ -1686,8 +1691,10 @@ static void v3d_editmetaball_buts(uiLayout *layout, Object *ob) static void do_view3d_region_buttons(bContext *C, void *UNUSED(index), int event) { + Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); View3D *v3d = CTX_wm_view3d(C); + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); switch (event) { @@ -1715,15 +1722,19 @@ static void do_view3d_region_buttons(bContext *C, void *UNUSED(index), int event static bool view3d_panel_transform_poll(const bContext *C, PanelType *UNUSED(pt)) { + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - return (view_layer->basact != NULL); + BKE_view_layer_synced_ensure(scene, view_layer); + return (BKE_view_layer_active_base_get(view_layer) != NULL); } static void view3d_panel_transform(const bContext *C, Panel *panel) { uiBlock *block; + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = view_layer->basact->object; + BKE_view_layer_synced_ensure(scene, view_layer); + Object *ob = BKE_view_layer_active_object_get(view_layer); Object *obedit = OBEDIT_FROM_OBACT(ob); uiLayout *col; diff --git a/source/blender/editors/space_view3d/view3d_cursor_snap.c b/source/blender/editors/space_view3d/view3d_cursor_snap.c index 195806fbecc..72e1f6f46c7 100644 --- a/source/blender/editors/space_view3d/view3d_cursor_snap.c +++ b/source/blender/editors/space_view3d/view3d_cursor_snap.c @@ -692,6 +692,7 @@ static void v3d_cursor_snap_update(V3DSnapCursorState *state, } else { ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(CTX_data_scene(C), view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); const int orient_index = BKE_scene_orientation_get_index(scene, SCE_ORIENT_DEFAULT); const int pivot_point = scene->toolsettings->transform_pivot_point; diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index efc8b4a8502..e0939b714a0 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -1306,7 +1306,8 @@ static void draw_selected_name( s += sprintf(s, "(%d)", cfra); if ((ob == NULL) || (ob->mode == OB_MODE_OBJECT)) { - LayerCollection *layer_collection = view_layer->active_collection; + BKE_view_layer_synced_ensure(scene, view_layer); + LayerCollection *layer_collection = BKE_view_layer_active_collection_get(view_layer); s += sprintf(s, " %s%s", BKE_collection_ui_name_get(layer_collection->collection), @@ -1497,6 +1498,7 @@ void view3d_draw_region_info(const bContext *C, ARegion *region) } if (U.uiflag & USER_DRAWVIEWINFO) { + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); draw_selected_name(scene, view_layer, ob, xoffset, &yoffset); } @@ -2121,6 +2123,7 @@ bool ED_view3d_clipping_test(const RegionView3D *rv3d, const float co[3], const * \note Only use in object mode. */ static void validate_object_select_id(struct Depsgraph *depsgraph, + const Scene *scene, ViewLayer *view_layer, ARegion *region, View3D *v3d, @@ -2153,6 +2156,7 @@ static void validate_object_select_id(struct Depsgraph *depsgraph, } if (obact_eval && ((obact_eval->base_flag & BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT) != 0)) { + BKE_view_layer_synced_ensure(scene, view_layer); Base *base = BKE_view_layer_base_find(view_layer, obact); DRW_select_buffer_context_create(&base, 1, -1); } @@ -2188,7 +2192,8 @@ static void view3d_opengl_read_Z_pixels(GPUViewport *viewport, rcti *rect, void void ED_view3d_select_id_validate(ViewContext *vc) { - validate_object_select_id(vc->depsgraph, vc->view_layer, vc->region, vc->v3d, vc->obact); + validate_object_select_id( + vc->depsgraph, vc->scene, vc->view_layer, vc->region, vc->v3d, vc->obact); } int ED_view3d_backbuf_sample_size_clamp(ARegion *region, const float dist) diff --git a/source/blender/editors/space_view3d/view3d_gizmo_armature.c b/source/blender/editors/space_view3d/view3d_gizmo_armature.c index 89b46069df1..4f73e2fada2 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_armature.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_armature.c @@ -113,8 +113,10 @@ static bool WIDGETGROUP_armature_spline_poll(const bContext *C, wmGizmoGroupType return false; } + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Base *base = view_layer->basact; + BKE_view_layer_synced_ensure(scene, view_layer); + Base *base = BKE_view_layer_active_base_get(view_layer); if (base && BASE_SELECTABLE(v3d, base)) { Object *ob = BKE_object_pose_armature_get(base->object); if (ob) { @@ -132,7 +134,9 @@ static bool WIDGETGROUP_armature_spline_poll(const bContext *C, wmGizmoGroupType static void WIDGETGROUP_armature_spline_setup(const bContext *C, wmGizmoGroup *gzgroup) { + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_object_pose_armature_get(BKE_view_layer_active_object_get(view_layer)); bPoseChannel *pchan = BKE_pose_channel_active_if_layer_visible(ob); @@ -165,7 +169,9 @@ static void WIDGETGROUP_armature_spline_setup(const bContext *C, wmGizmoGroup *g static void WIDGETGROUP_armature_spline_refresh(const bContext *C, wmGizmoGroup *gzgroup) { + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_object_pose_armature_get(BKE_view_layer_active_object_get(view_layer)); if (!gzgroup->customdata) { diff --git a/source/blender/editors/space_view3d/view3d_gizmo_camera.c b/source/blender/editors/space_view3d/view3d_gizmo_camera.c index d4720d01d70..952ef56710b 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_camera.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_camera.c @@ -55,8 +55,10 @@ static bool WIDGETGROUP_camera_poll(const bContext *C, wmGizmoGroupType *UNUSED( return false; } + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Base *base = view_layer->basact; + BKE_view_layer_synced_ensure(scene, view_layer); + Base *base = BKE_view_layer_active_base_get(view_layer); if (base && BASE_SELECTABLE(v3d, base)) { Object *ob = base->object; if (ob->type == OB_CAMERA) { @@ -72,7 +74,9 @@ static bool WIDGETGROUP_camera_poll(const bContext *C, wmGizmoGroupType *UNUSED( static void WIDGETGROUP_camera_setup(const bContext *C, wmGizmoGroup *gzgroup) { + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); float dir[3]; @@ -124,7 +128,9 @@ static void WIDGETGROUP_camera_refresh(const bContext *C, wmGizmoGroup *gzgroup) struct CameraWidgetGroup *cagzgroup = gzgroup->customdata; View3D *v3d = CTX_wm_view3d(C); + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); Camera *ca = ob->data; PointerRNA camera_ptr; @@ -151,7 +157,6 @@ static void WIDGETGROUP_camera_refresh(const bContext *C, wmGizmoGroup *gzgroup) } /* TODO: make focal length/ortho ob_scale_inv widget optional. */ - const Scene *scene = CTX_data_scene(C); const float aspx = (float)scene->r.xsch * scene->r.xasp; const float aspy = (float)scene->r.ysch * scene->r.yasp; const bool is_ortho = (ca->type == CAM_ORTHO); @@ -241,7 +246,9 @@ static void WIDGETGROUP_camera_message_subscribe(const bContext *C, struct wmMsgBus *mbus) { ARegion *region = CTX_wm_region(C); + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); Camera *ca = ob->data; @@ -370,6 +377,7 @@ static bool WIDGETGROUP_camera_view_poll(const bContext *C, wmGizmoGroupType *UN * We could change the rules for when to show. */ { ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(scene, view_layer); if (scene->camera != BKE_view_layer_active_object_get(view_layer)) { return false; } diff --git a/source/blender/editors/space_view3d/view3d_gizmo_empty.c b/source/blender/editors/space_view3d/view3d_gizmo_empty.c index a7febe11672..41a763192ce 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_empty.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_empty.c @@ -99,8 +99,10 @@ static bool WIDGETGROUP_empty_image_poll(const bContext *C, wmGizmoGroupType *UN return false; } + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Base *base = view_layer->basact; + BKE_view_layer_synced_ensure(scene, view_layer); + Base *base = BKE_view_layer_active_base_get(view_layer); if (base && BASE_SELECTABLE(v3d, base)) { Object *ob = base->object; if (ob->type == OB_EMPTY) { @@ -132,7 +134,9 @@ static void WIDGETGROUP_empty_image_refresh(const bContext *C, wmGizmoGroup *gzg { struct EmptyImageWidgetGroup *igzgroup = gzgroup->customdata; wmGizmo *gz = igzgroup->gizmo; + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); copy_m4_m4(gz->matrix_basis, ob->obmat); diff --git a/source/blender/editors/space_view3d/view3d_gizmo_forcefield.c b/source/blender/editors/space_view3d/view3d_gizmo_forcefield.c index f2f9e9092fa..58b43301397 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_forcefield.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_forcefield.c @@ -42,8 +42,10 @@ static bool WIDGETGROUP_forcefield_poll(const bContext *C, wmGizmoGroupType *UNU return false; } + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Base *base = view_layer->basact; + BKE_view_layer_synced_ensure(scene, view_layer); + Base *base = BKE_view_layer_active_base_get(view_layer); if (base && BASE_SELECTABLE(v3d, base)) { Object *ob = base->object; if (ob->pd && ob->pd->forcefield) { @@ -73,7 +75,9 @@ static void WIDGETGROUP_forcefield_refresh(const bContext *C, wmGizmoGroup *gzgr { wmGizmoWrapper *wwrapper = gzgroup->customdata; wmGizmo *gz = wwrapper->gizmo; + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); PartDeflect *pd = ob->pd; diff --git a/source/blender/editors/space_view3d/view3d_gizmo_light.c b/source/blender/editors/space_view3d/view3d_gizmo_light.c index d0f58f43c2b..df653f9a6e5 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_light.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_light.c @@ -45,8 +45,10 @@ static bool WIDGETGROUP_light_spot_poll(const bContext *C, wmGizmoGroupType *UNU return false; } + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Base *base = view_layer->basact; + BKE_view_layer_synced_ensure(scene, view_layer); + Base *base = BKE_view_layer_active_base_get(view_layer); if (base && BASE_SELECTABLE(v3d, base)) { Object *ob = base->object; if (ob->type == OB_LAMP) { @@ -76,7 +78,9 @@ static void WIDGETGROUP_light_spot_refresh(const bContext *C, wmGizmoGroup *gzgr { wmGizmoWrapper *wwrapper = gzgroup->customdata; wmGizmo *gz = wwrapper->gizmo; + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); Light *la = ob->data; float dir[3]; @@ -156,8 +160,10 @@ static bool WIDGETGROUP_light_area_poll(const bContext *C, wmGizmoGroupType *UNU return false; } + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Base *base = view_layer->basact; + BKE_view_layer_synced_ensure(scene, view_layer); + Base *base = BKE_view_layer_active_base_get(view_layer); if (base && BASE_SELECTABLE(v3d, base)) { Object *ob = base->object; if (ob->type == OB_LAMP) { @@ -186,7 +192,9 @@ static void WIDGETGROUP_light_area_setup(const bContext *UNUSED(C), wmGizmoGroup static void WIDGETGROUP_light_area_refresh(const bContext *C, wmGizmoGroup *gzgroup) { wmGizmoWrapper *wwrapper = gzgroup->customdata; + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); Light *la = ob->data; wmGizmo *gz = wwrapper->gizmo; @@ -239,8 +247,10 @@ static bool WIDGETGROUP_light_target_poll(const bContext *C, wmGizmoGroupType *U return false; } + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Base *base = view_layer->basact; + BKE_view_layer_synced_ensure(scene, view_layer); + Base *base = BKE_view_layer_active_base_get(view_layer); if (base && BASE_SELECTABLE(v3d, base)) { Object *ob = base->object; if (ob->type == OB_LAMP) { @@ -280,7 +290,9 @@ static void WIDGETGROUP_light_target_setup(const bContext *UNUSED(C), wmGizmoGro static void WIDGETGROUP_light_target_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) { wmGizmoWrapper *wwrapper = gzgroup->customdata; + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); wmGizmo *gz = wwrapper->gizmo; diff --git a/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c b/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c index 15c19ab35ad..d0f6ca4c922 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c @@ -128,7 +128,9 @@ static int gizmo_preselect_elem_test_select(bContext *C, wmGizmo *gz, const int const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); View3D *v3d = CTX_wm_view3d(C); - if (((gz_ele->bases)) == NULL || (gz_ele->bases[0] != view_layer->basact)) { + BKE_view_layer_synced_ensure(scene, view_layer); + if (((gz_ele->bases)) == NULL || + (gz_ele->bases[0] != BKE_view_layer_active_base_get(view_layer))) { MEM_SAFE_FREE(gz_ele->bases); gz_ele->bases = BKE_view_layer_array_from_bases_in_edit_mode( scene, view_layer, v3d, &gz_ele->bases_len); @@ -355,7 +357,9 @@ static int gizmo_preselect_edgering_test_select(bContext *C, wmGizmo *gz, const const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); View3D *v3d = CTX_wm_view3d(C); - if (((gz_ring->bases)) == NULL || (gz_ring->bases[0] != view_layer->basact)) { + BKE_view_layer_synced_ensure(scene, view_layer); + if (((gz_ring->bases)) == NULL || + (gz_ring->bases[0] != BKE_view_layer_active_base_get(view_layer))) { MEM_SAFE_FREE(gz_ring->bases); gz_ring->bases = BKE_view_layer_array_from_bases_in_edit_mode( scene, view_layer, v3d, &gz_ring->bases_len); diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c index 41a0e137b03..d95d49dd982 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c @@ -421,6 +421,7 @@ static bool view3d_ruler_item_mousemove(const bContext *C, Scene *scene = DEG_get_input_scene(depsgraph); ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); RegionView3D *rv3d = ruler_info->region->regiondata; + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); Object *obedit = OBEDIT_FROM_OBACT(ob); diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 90d108c23cc..45f7a3a8fe9 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -125,7 +125,9 @@ void uiTemplateEditModeSelection(uiLayout *layout, struct bContext *C) static void uiTemplatePaintModeSelection(uiLayout *layout, struct bContext *C) { + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); /* Gizmos aren't used in paint modes */ @@ -147,7 +149,9 @@ static void uiTemplatePaintModeSelection(uiLayout *layout, struct bContext *C) void uiTemplateHeader3D_mode(uiLayout *layout, struct bContext *C) { + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); Object *obedit = CTX_data_edit_object(C); bGPdata *gpd = CTX_data_gpencil_data(C); diff --git a/source/blender/editors/space_view3d/view3d_navigate.c b/source/blender/editors/space_view3d/view3d_navigate.c index 728971472af..b27c65c42ef 100644 --- a/source/blender/editors/space_view3d/view3d_navigate.c +++ b/source/blender/editors/space_view3d/view3d_navigate.c @@ -164,8 +164,10 @@ bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3]) const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); + Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); View3D *v3d = CTX_wm_view3d(C); + BKE_view_layer_synced_ensure(scene_eval, view_layer_eval); Object *ob_act_eval = BKE_view_layer_active_object_get(view_layer_eval); Object *ob_act = DEG_get_original_object(ob_act_eval); @@ -207,7 +209,7 @@ bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3]) float select_center[3]; zero_v3(select_center); - LISTBASE_FOREACH (Base *, base_eval, &view_layer_eval->object_bases) { + LISTBASE_FOREACH (Base *, base_eval, BKE_view_layer_object_bases_get(view_layer_eval)) { if (BASE_SELECTED(v3d, base_eval)) { /* use the boundbox if we can */ Object *ob_eval = base_eval->object; @@ -751,8 +753,9 @@ static int view3d_all_exec(bContext *C, wmOperator *op) RegionView3D *rv3d = CTX_wm_region_view3d(C); Scene *scene = CTX_data_scene(C); Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); - Base *base_eval; + const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions"); const bool skip_camera = (ED_view3d_camera_lock_check(v3d, region->regiondata) || /* any one of the regions may be locked */ @@ -777,7 +780,8 @@ static int view3d_all_exec(bContext *C, wmOperator *op) INIT_MINMAX(min, max); } - for (base_eval = view_layer_eval->object_bases.first; base_eval; base_eval = base_eval->next) { + BKE_view_layer_synced_ensure(scene_eval, view_layer_eval); + LISTBASE_FOREACH (Base *, base_eval, BKE_view_layer_object_bases_get(view_layer_eval)) { if (BASE_VISIBLE(v3d, base_eval)) { bool only_center = false; Object *ob = DEG_get_original_object(base_eval->object); @@ -863,6 +867,7 @@ static int viewselected_exec(bContext *C, wmOperator *op) Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); const Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); + BKE_view_layer_synced_ensure(scene_eval, view_layer_eval); Object *ob_eval = BKE_view_layer_active_object_get(view_layer_eval); Object *obedit = CTX_data_edit_object(C); const bGPdata *gpd_eval = ob_eval && (ob_eval->type == OB_GPENCIL) ? ob_eval->data : NULL; @@ -887,7 +892,8 @@ static int viewselected_exec(bContext *C, wmOperator *op) /* this is weak code this way, we should make a generic * active/selection callback interface once... */ Base *base_eval; - for (base_eval = view_layer_eval->object_bases.first; base_eval; base_eval = base_eval->next) { + for (base_eval = BKE_view_layer_object_bases_get(view_layer_eval)->first; base_eval; + base_eval = base_eval->next) { if (BASE_SELECTED_EDITABLE(v3d, base_eval)) { if (base_eval->object->type == OB_ARMATURE) { if (base_eval->object->mode & OB_MODE_POSE) { @@ -964,7 +970,7 @@ static int viewselected_exec(bContext *C, wmOperator *op) ok_dist = 0; /* don't zoom */ } else { - LISTBASE_FOREACH (Base *, base_eval, &view_layer_eval->object_bases) { + LISTBASE_FOREACH (Base *, base_eval, BKE_view_layer_object_bases_get(view_layer_eval)) { if (BASE_SELECTED(v3d, base_eval)) { bool only_center = false; Object *ob = DEG_get_original_object(base_eval->object); @@ -1308,6 +1314,7 @@ static int view_camera_exec(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); if (rv3d->persp != RV3D_CAMOB) { + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); if (!rv3d->smooth_timer) { diff --git a/source/blender/editors/space_view3d/view3d_select.cc b/source/blender/editors/space_view3d/view3d_select.cc index 65631930d18..e76696f31cf 100644 --- a/source/blender/editors/space_view3d/view3d_select.cc +++ b/source/blender/editors/space_view3d/view3d_select.cc @@ -140,10 +140,11 @@ void ED_view3d_viewcontext_init_object(ViewContext *vc, Object *obact) /** \name Internal Object Utilities * \{ */ -static bool object_deselect_all_visible(ViewLayer *view_layer, View3D *v3d) +static bool object_deselect_all_visible(const Scene *scene, ViewLayer *view_layer, View3D *v3d) { bool changed = false; - LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { + BKE_view_layer_synced_ensure(scene, view_layer); + LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) { if (base->flag & BASE_SELECTED) { if (BASE_SELECTABLE(v3d, base)) { ED_object_base_select(base, BA_DESELECT); @@ -155,10 +156,11 @@ static bool object_deselect_all_visible(ViewLayer *view_layer, View3D *v3d) } /* deselect all except b */ -static bool object_deselect_all_except(ViewLayer *view_layer, Base *b) +static bool object_deselect_all_except(const Scene *scene, ViewLayer *view_layer, Base *b) { bool changed = false; - LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { + BKE_view_layer_synced_ensure(scene, view_layer); + LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) { if (base->flag & BASE_SELECTED) { if (b != base) { ED_object_base_select(base, BA_DESELECT); @@ -199,6 +201,7 @@ static void editselect_buf_cache_init(ViewContext *vc, short select_mode) else { /* Use for paint modes, currently only a single object at a time. */ if (vc->obact) { + BKE_view_layer_synced_ensure(vc->scene, vc->view_layer); Base *base = BKE_view_layer_base_find(vc->view_layer, vc->obact); DRW_select_buffer_context_create(&base, 1, select_mode); } @@ -559,14 +562,13 @@ static bool do_lasso_select_objects(ViewContext *vc, const eSelectOp sel_op) { View3D *v3d = vc->v3d; - Base *base; bool changed = false; if (SEL_OP_USE_PRE_DESELECT(sel_op)) { - changed |= object_deselect_all_visible(vc->view_layer, vc->v3d); + changed |= object_deselect_all_visible(vc->scene, vc->view_layer, vc->v3d); } - - for (base = static_cast<Base *>(vc->view_layer->object_bases.first); base; base = base->next) { + BKE_view_layer_synced_ensure(vc->scene, vc->view_layer); + LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(vc->view_layer)) { if (BASE_SELECTABLE(v3d, base)) { /* Use this to avoid unnecessary lasso look-ups. */ const bool is_select = base->flag & BASE_SELECTED; const bool is_inside = ((ED_view3d_project_base(vc->region, base) == V3D_PROJ_RET_OK) && @@ -1459,8 +1461,10 @@ static int object_select_menu_exec(bContext *C, wmOperator *op) const char *name = object_mouse_select_menu_data[name_index].idname; View3D *v3d = CTX_wm_view3d(C); + Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - const Base *oldbasact = view_layer->basact; + BKE_view_layer_synced_ensure(scene, view_layer); + const Base *oldbasact = BKE_view_layer_active_base_get(view_layer); Base *basact = nullptr; CTX_DATA_BEGIN (C, Base *, base, selectable_bases) { @@ -1500,7 +1504,7 @@ static int object_select_menu_exec(bContext *C, wmOperator *op) } } else { - object_deselect_all_except(view_layer, basact); + object_deselect_all_except(scene, view_layer, basact); ED_object_base_select(basact, BA_SELECT); changed = true; } @@ -1656,7 +1660,8 @@ static int bone_select_menu_exec(bContext *C, wmOperator *op) View3D *v3d = CTX_wm_view3d(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - const Base *oldbasact = view_layer->basact; + BKE_view_layer_synced_ensure(scene, view_layer); + const Base *oldbasact = BKE_view_layer_active_base_get(view_layer); Base *basact = object_mouse_select_menu_data[name_index].base_ptr; @@ -2101,6 +2106,7 @@ static Base *mouse_select_eval_buffer(ViewContext *vc, bool do_bones_get_priotity, int *r_select_id_subelem) { + Scene *scene = vc->scene; ViewLayer *view_layer = vc->view_layer; View3D *v3d = vc->v3d; int a; @@ -2164,8 +2170,10 @@ static Base *mouse_select_eval_buffer(ViewContext *vc, /* It's possible there are no hits (all objects contained bones). */ if (hits > 0) { /* Only exclude active object when it is selected. */ - if (view_layer->basact && (view_layer->basact->flag & BASE_SELECTED)) { - const int select_id_active = view_layer->basact->object->runtime.select_id; + BKE_view_layer_synced_ensure(scene, view_layer); + Base *base = BKE_view_layer_active_base_get(view_layer); + if (base && (base->flag & BASE_SELECTED)) { + const int select_id_active = base->object->runtime.select_id; for (int i_next = 0, i_prev = hits - 1; i_next < hits; i_prev = i_next++) { if ((select_id_active == (buffer[i_prev].id & 0xFFFF)) && (select_id_active != (buffer[i_next].id & 0xFFFF))) { @@ -2192,7 +2200,8 @@ static Base *mouse_select_eval_buffer(ViewContext *vc, Base *basact = nullptr; if (found) { - LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { + BKE_view_layer_synced_ensure(scene, view_layer); + LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) { if (has_bones ? BASE_VISIBLE(v3d, base) : BASE_SELECTABLE(v3d, base)) { if (base->object->runtime.select_id == select_id) { basact = base; @@ -2212,10 +2221,12 @@ static Base *mouse_select_eval_buffer(ViewContext *vc, static Base *mouse_select_object_center(ViewContext *vc, Base *startbase, const int mval[2]) { ARegion *region = vc->region; + Scene *scene = vc->scene; ViewLayer *view_layer = vc->view_layer; View3D *v3d = vc->v3d; - Base *oldbasact = view_layer->basact; + BKE_view_layer_synced_ensure(scene, view_layer); + Base *oldbasact = BKE_view_layer_active_base_get(view_layer); const float mval_fl[2] = {(float)mval[0], (float)mval[1]}; float dist = ED_view3d_select_dist_px() * 1.3333f; @@ -2243,7 +2254,7 @@ static Base *mouse_select_object_center(ViewContext *vc, Base *startbase, const base = base->next; if (base == nullptr) { - base = static_cast<Base *>(view_layer->object_bases.first); + base = static_cast<Base *>(BKE_view_layer_object_bases_get(view_layer)->first); } if (base == startbase) { break; @@ -2529,12 +2540,13 @@ static bool ed_object_select_pick(bContext *C, /* No menu, continue with selection. */ ViewLayer *view_layer = vc.view_layer; + BKE_view_layer_synced_ensure(scene, view_layer); /* Don't set when the context has no active object (hidden), see: T60807. */ - const Base *oldbasact = vc.obact ? view_layer->basact : nullptr; + const Base *oldbasact = vc.obact ? BKE_view_layer_active_base_get(view_layer) : nullptr; /* Always start list from `basact` when cycling the selection. */ Base *startbase = (oldbasact && oldbasact->next) ? oldbasact->next : - static_cast<Base *>(view_layer->object_bases.first); + static_cast<Base *>(BKE_view_layer_object_bases_get(view_layer)->first); /* The next object's base to make active. */ Base *basact = nullptr; @@ -2705,7 +2717,7 @@ static bool ed_object_select_pick(bContext *C, /* Ensure code above doesn't change the active base. This code is already fairly involved, * it's best if changing the active object is localized to a single place. */ - BLI_assert(oldbasact == (vc.obact ? view_layer->basact : nullptr)); + BLI_assert(oldbasact == (vc.obact ? BKE_view_layer_active_base_get(view_layer) : nullptr)); bool found = (basact != nullptr); if ((handled == false) && (vc.obedit == nullptr)) { @@ -2717,7 +2729,7 @@ static bool ed_object_select_pick(bContext *C, else if (found || params->deselect_all) { /* Deselect everything. */ /* `basact` may be nullptr. */ - if (object_deselect_all_except(view_layer, basact)) { + if (object_deselect_all_except(scene, view_layer, basact)) { changed_object = true; } } @@ -2729,7 +2741,7 @@ static bool ed_object_select_pick(bContext *C, if (vc.obedit) { /* Only do the select (use for setting vertex parents & hooks). * In edit-mode do not activate. */ - object_deselect_all_except(view_layer, basact); + object_deselect_all_except(scene, view_layer, basact); ED_object_base_select(basact, BA_SELECT); changed_object = true; @@ -2760,7 +2772,7 @@ static bool ed_object_select_pick(bContext *C, break; } case SEL_OP_SET: { - object_deselect_all_except(view_layer, basact); + object_deselect_all_except(scene, view_layer, basact); ED_object_base_select(basact, BA_SELECT); break; } @@ -3641,8 +3653,8 @@ static bool do_object_box_select(bContext *C, ViewContext *vc, rcti *rect, const vc->obact); const int hits = view3d_opengl_select( vc, buffer, (totobj + MAXPICKELEMS), rect, VIEW3D_SELECT_ALL, select_filter); - - LISTBASE_FOREACH (Base *, base, &vc->view_layer->object_bases) { + BKE_view_layer_synced_ensure(vc->scene, vc->view_layer); + LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(vc->view_layer)) { base->object->id.tag &= ~LIB_TAG_DOIT; } @@ -3650,14 +3662,15 @@ static bool do_object_box_select(bContext *C, ViewContext *vc, rcti *rect, const bool changed = false; if (SEL_OP_USE_PRE_DESELECT(sel_op)) { - changed |= object_deselect_all_visible(vc->view_layer, vc->v3d); + changed |= object_deselect_all_visible(vc->scene, vc->view_layer, vc->v3d); } + ListBase *object_bases = BKE_view_layer_object_bases_get(vc->view_layer); if ((hits == -1) && !SEL_OP_USE_OUTSIDE(sel_op)) { goto finally; } - LISTBASE_FOREACH (Base *, base, &vc->view_layer->object_bases) { + LISTBASE_FOREACH (Base *, base, object_bases) { if (BASE_SELECTABLE(v3d, base)) { if ((base->object->runtime.select_id & 0x0000FFFF) != 0) { bases.append(base); @@ -3678,8 +3691,7 @@ static bool do_object_box_select(bContext *C, ViewContext *vc, rcti *rect, const } } - for (Base *base = static_cast<Base *>(vc->view_layer->object_bases.first); base && hits; - base = base->next) { + for (Base *base = static_cast<Base *>(object_bases->first); base && hits; base = base->next) { if (BASE_SELECTABLE(v3d, base)) { const bool is_select = base->flag & BASE_SELECTED; const bool is_inside = base->object->id.tag & LIB_TAG_DOIT; @@ -4603,6 +4615,7 @@ static bool object_circle_select(ViewContext *vc, float rad) { BLI_assert(ELEM(sel_op, SEL_OP_SET, SEL_OP_ADD, SEL_OP_SUB)); + Scene *scene = vc->scene; ViewLayer *view_layer = vc->view_layer; View3D *v3d = vc->v3d; @@ -4611,12 +4624,12 @@ static bool object_circle_select(ViewContext *vc, bool changed = false; if (SEL_OP_USE_PRE_DESELECT(sel_op)) { - changed |= object_deselect_all_visible(vc->view_layer, vc->v3d); + changed |= object_deselect_all_visible(vc->scene, vc->view_layer, vc->v3d); } const bool select = (sel_op != SEL_OP_SUB); const int select_flag = select ? BASE_SELECTED : 0; - - LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { + BKE_view_layer_synced_ensure(scene, view_layer); + LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) { if (BASE_SELECTABLE(v3d, base) && ((base->flag & BASE_SELECTED) != select_flag)) { float screen_co[2]; if (ED_view3d_project_float_global( diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 7c98ca8df74..d0db4de0c47 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -553,6 +553,7 @@ int view3d_opengl_select_ex(ViewContext *vc, ARegion *region = vc->region; rcti rect; int hits = 0; + BKE_view_layer_synced_ensure(scene, vc->view_layer); const bool use_obedit_skip = (BKE_view_layer_edit_object_get(vc->view_layer) != NULL) && (vc->obedit == NULL); const bool is_pick_select = (U.gpu_flag & USER_GPU_FLAG_NO_DEPT_PICK) == 0; @@ -852,9 +853,11 @@ static bool view3d_localview_init(const Depsgraph *depsgraph, ok = false; } else { + BKE_view_layer_synced_ensure(scene, view_layer); Object *obedit = BKE_view_layer_edit_object_get(view_layer); if (obedit) { - LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { + BKE_view_layer_synced_ensure(scene, view_layer); + LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) { base->local_view_bits &= ~local_view_bit; } FOREACH_BASE_IN_EDIT_MODE_BEGIN (scene, view_layer, v3d, base_iter) { @@ -865,7 +868,8 @@ static bool view3d_localview_init(const Depsgraph *depsgraph, FOREACH_BASE_IN_EDIT_MODE_END; } else { - LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { + BKE_view_layer_synced_ensure(scene, view_layer); + LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) { if (BASE_SELECTED(v3d, base)) { BKE_object_minmax(base->object, min, max, false); base->local_view_bits |= local_view_bit; @@ -956,6 +960,7 @@ static bool view3d_localview_init(const Depsgraph *depsgraph, static void view3d_localview_exit(const Depsgraph *depsgraph, wmWindowManager *wm, wmWindow *win, + const Scene *scene, ViewLayer *view_layer, ScrArea *area, const bool frame_selected, @@ -966,8 +971,8 @@ static void view3d_localview_exit(const Depsgraph *depsgraph, if (v3d->localvd == NULL) { return; } - - LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { + BKE_view_layer_synced_ensure(scene, view_layer); + LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) { if (base->local_view_bits & v3d->local_view_uuid) { base->local_view_bits &= ~v3d->local_view_uuid; } @@ -1040,7 +1045,8 @@ static int localview_exec(bContext *C, wmOperator *op) bool changed; if (v3d->localvd) { - view3d_localview_exit(depsgraph, wm, win, view_layer, area, frame_selected, smooth_viewtx); + view3d_localview_exit( + depsgraph, wm, win, scene, view_layer, area, frame_selected, smooth_viewtx); changed = true; } else { @@ -1101,8 +1107,8 @@ static int localview_remove_from_exec(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); bool changed = false; - - LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { + BKE_view_layer_synced_ensure(scene, view_layer); + LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) { if (BASE_SELECTED(v3d, base)) { base->local_view_bits &= ~v3d->local_view_uuid; ED_object_base_select(base, BA_DESELECT); |