UI: expose the 3D views active object, even when hidden

The previous behavior meant that changing an objects visibility
effectively changed the current mode - which missed necessary
updates for the tool-system (for example).

There was already a check for edit-mode, now expected to all modes.

This makes the test-case described in T83013 work as expected.
This commit is contained in:
Campbell Barton 2021-02-12 17:09:34 +11:00
parent 631cc5d56e
commit c10ad8e9ea
Notes: blender-bot 2023-02-14 11:35:46 +01:00
Referenced by commit 0c58ad8a34, Cleanup: remove unused common_restrict_check function
Referenced by issue #85532, Proposal to change behavior when the active object is hidden
1 changed files with 16 additions and 2 deletions

View File

@ -1591,7 +1591,8 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes
if (view_layer->basact) {
Object *ob = view_layer->basact->object;
/* if hidden but in edit mode, we still display, can happen with animation */
if ((view_layer->basact->flag & BASE_VISIBLE_DEPSGRAPH) != 0 || (ob->mode & OB_MODE_EDIT)) {
if ((view_layer->basact->flag & BASE_VISIBLE_DEPSGRAPH) != 0 ||
(ob->mode != OB_MODE_OBJECT)) {
CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, view_layer->basact);
}
}
@ -1599,12 +1600,25 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes
return 1;
}
else if (CTX_data_equals(member, "active_object")) {
/* In most cases the active object is the `view_layer->basact->object`.
* For the 3D view however it can be NULL when hidden.
*
* This is ignored in the case the object is in any mode (besides object-mode),
* since the object's mode impacts the current tool, cursor, gizmos etc.
* If we didn't have this exception, changing visibility would need to perform
* many of the the same updates as changing the objects mode.
*
* Further, there are multiple ways to hide objects - by collection, by object type, etc.
* it's simplest if all these methods behave consistently - respecting the object-mode
* without showing the object.
*
* See T85532 for alternatives that were considered. */
ViewLayer *view_layer = CTX_data_view_layer(C);
if (view_layer->basact) {
Object *ob = view_layer->basact->object;
/* if hidden but in edit mode, we still display, can happen with animation */
if ((view_layer->basact->flag & BASE_VISIBLE_DEPSGRAPH) != 0 ||
(ob->mode & OB_MODE_EDIT) != 0) {
(ob->mode != OB_MODE_OBJECT)) {
CTX_data_id_pointer_set(result, &ob->id);
}
}