Fix T62388: object.visible_get() not affected by object.hide_viewport.

After recent changes BASE_VISIBLE was not always disabled properly when the
object is hidden. This refactors the code a bit to hopefully be more clear.
This commit is contained in:
Brecht Van Lommel 2019-03-12 18:24:33 +01:00
parent 834d3962b9
commit c427590c4e
Notes: blender-bot 2023-02-14 05:43:04 +01:00
Referenced by issue #62388, object visibilty using obj.hide_viewport not recognized by context.visible_objects and obj.visible_get()
Referenced by issue #62191, Blender 2.8 - Object Animation - animated hide_render and hide_viewport do not work as expected
2 changed files with 28 additions and 25 deletions

View File

@ -1443,23 +1443,35 @@ void BKE_view_layer_bases_in_mode_iterator_end(BLI_Iterator *UNUSED(iter))
/* Evaluation */
/* Applies object's restrict flags on top of flags coming from the collection
* and stores those in base->flag. */
* and stores those in base->flag. BASE_VISIBLE is based on viewport visibility. */
void BKE_base_eval_flags(Base *base)
{
const int object_restrict = base->object->restrictflag;
/* Apply collection flags. */
base->flag &= ~g_base_collection_flags;
base->flag |= (base->flag_from_collection & g_base_collection_flags);
/* Apply object restrictions. */
const int object_restrict = base->object->restrictflag;
if (object_restrict & OB_RESTRICT_VIEW) {
base->flag &= ~(BASE_ENABLED_VIEWPORT | BASE_SELECTABLE);
}
if (object_restrict & OB_RESTRICT_SELECT) {
base->flag &= ~BASE_SELECTABLE;
base->flag &= ~BASE_ENABLED_VIEWPORT;
}
if (object_restrict & OB_RESTRICT_RENDER) {
base->flag &= ~BASE_ENABLED_RENDER;
}
if (base->flag & BASE_HIDDEN) {
base->flag &= ~BASE_VISIBLE;
if (object_restrict & OB_RESTRICT_SELECT) {
base->flag &= ~BASE_SELECTABLE;
}
/* Apply viewport visibility by default. The dependency graph for render
* can change these again, but for tools we always want the viewport
* visibility to be in sync regardless if depsgraph was evaluated. */
if (!(base->flag & BASE_ENABLED_VIEWPORT) || (base->flag & BASE_HIDDEN)) {
base->flag &= ~(BASE_VISIBLE | BASE_SELECTABLE);
}
/* Deselect unselectable objects. */
if (!(base->flag & BASE_SELECTABLE)) {
base->flag &= ~BASE_SELECTED;
}
}

View File

@ -425,27 +425,18 @@ void BKE_object_eval_eval_base_flags(Depsgraph *depsgraph,
DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
/* Visibility based on depsgraph mode. */
const eEvaluationMode mode = DEG_get_mode(depsgraph);
const int base_enabled_flag = (mode == DAG_EVAL_VIEWPORT)
? BASE_ENABLED_VIEWPORT
: BASE_ENABLED_RENDER;
/* Set base flags based on collection and object restriction. */
BKE_base_eval_flags(base);
/* Compute visibility for depsgraph evaluation mode. */
if (base->flag & base_enabled_flag) {
/* When rendering, visibility is controlled by the enable/disable option. */
if (mode == DAG_EVAL_RENDER) {
/* For render, compute base visibility again since BKE_base_eval_flags
* assumed viewport visibility. Selectability does not matter here. */
if (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER) {
if (base->flag & BASE_ENABLED_RENDER) {
base->flag |= BASE_VISIBLE;
}
}
else {
base->flag &= ~(BASE_VISIBLE | BASE_SELECTABLE);
}
/* If base is not selectable, clear select. */
if ((base->flag & BASE_SELECTABLE) == 0) {
base->flag &= ~BASE_SELECTED;
else {
base->flag &= ~BASE_VISIBLE;
}
}
/* Copy flags and settings from base. */