Fix T70670: Hidden collections are still rendered by Cycles in the Viewport

Now local collections are fully working with cycles preview, while the
collection visibility bug is fixed.

Local collections were not working with cycles viewport even before the recent
commit to allow users to show collections that are hidden in the view layer.

It just got worse with said commit (0812949bbc).

Differential Revision: https://developer.blender.org/D6034
This commit is contained in:
Dalai Felinto 2019-10-09 19:02:56 -03:00
parent af5cc8cbd4
commit 280d6b03a7
Notes: blender-bot 2023-02-14 00:32:40 +01:00
Referenced by issue #70838, [Segfault<>BKE_object_is_visible_in_viewport] when rendering the default cube in cycles, despite viewport rendering works fine.
Referenced by issue #70670, Hidden collections are still rendered by Cycles in the Viewport
4 changed files with 45 additions and 3 deletions

View File

@ -541,7 +541,6 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
const bool show_lights = BlenderViewportParameters(b_v3d).use_scene_lights;
BL::ViewLayer b_view_layer = b_depsgraph.view_layer_eval();
const bool has_local_view = b_v3d && b_v3d.local_view();
BL::Depsgraph::object_instances_iterator b_instance_iter;
for (b_depsgraph.object_instances.begin(b_instance_iter);
@ -555,10 +554,10 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
/* test if object needs to be hidden */
const bool show_self = b_instance.show_self();
const bool show_local_view = !has_local_view || b_ob.local_view_get(b_v3d);
const bool show_particles = b_instance.show_particles();
const bool show_in_viewport = b_ob.visible_in_viewport_get(b_v3d);
if (show_local_view && (show_self || show_particles)) {
if (show_in_viewport && (show_self || show_particles)) {
/* object itself */
sync_object(b_depsgraph,
b_view_layer,

View File

@ -115,6 +115,7 @@ void BKE_base_set_visible(struct Scene *scene,
struct Base *base,
bool extend);
bool BKE_base_is_visible(const struct View3D *v3d, const struct Base *base);
bool BKE_object_is_visible_in_viewport(const struct View3D *v3d, const struct Object *ob);
void BKE_layer_collection_isolate_global(struct Scene *scene,
struct ViewLayer *view_layer,
struct LayerCollection *lc,

View File

@ -1059,6 +1059,33 @@ bool BKE_base_is_visible(const View3D *v3d, const Base *base)
return base->flag & BASE_VISIBLE_VIEWLAYER;
}
bool BKE_object_is_visible_in_viewport(const struct View3D *v3d, const struct Object *ob)
{
if (ob->restrictflag & OB_RESTRICT_VIEWPORT) {
return false;
}
if ((v3d->object_type_exclude_viewport & (1 << ob->type)) != 0) {
return false;
}
if (v3d->localvd && ((v3d->local_view_uuid & ob->base_local_view_bits) == 0)) {
return false;
}
if ((v3d->flag & V3D_LOCAL_COLLECTIONS) &&
((v3d->local_collections_uuid & ob->runtime.local_collections_bits) == 0)) {
return false;
}
/* If not using local view or local collection the object may still be in a hidden collection. */
if (((v3d->localvd) == NULL) && ((v3d->flag & V3D_LOCAL_COLLECTIONS) == 0)) {
return (ob->base_flag & BASE_VISIBLE_VIEWLAYER) != 0;
}
return true;
}
static void layer_collection_flag_set_recursive(LayerCollection *lc, const int flag)
{
lc->flag |= flag;

View File

@ -70,6 +70,7 @@ static const EnumPropertyItem space_items[] = {
# include "BKE_customdata.h"
# include "BKE_font.h"
# include "BKE_global.h"
# include "BKE_layer.h"
# include "BKE_main.h"
# include "BKE_mesh.h"
# include "BKE_mball.h"
@ -283,6 +284,11 @@ static void rna_Object_local_view_set(Object *ob,
}
}
static bool rna_Object_visible_in_viewport_get(Object *ob, View3D *v3d)
{
return BKE_object_is_visible_in_viewport(v3d, ob);
}
/* Convert a given matrix from a space to another (using the object and/or a bone as
* reference). */
static void rna_Object_mat_convert_space(Object *ob,
@ -825,6 +831,15 @@ void RNA_api_object(StructRNA *srna)
parm = RNA_def_boolean(func, "state", 0, "", "Local view state to define");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
/* Viewport */
func = RNA_def_function(srna, "visible_in_viewport_get", "rna_Object_visible_in_viewport_get");
RNA_def_function_ui_description(
func, "Check for local view and local collections for this viewport and object");
parm = RNA_def_pointer(func, "viewport", "SpaceView3D", "", "Viewport in local collections");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
parm = RNA_def_boolean(func, "result", 0, "", "Object viewport visibility");
RNA_def_function_return(func, parm);
/* Matrix space conversion */
func = RNA_def_function(srna, "convert_space", "rna_Object_mat_convert_space");
RNA_def_function_ui_description(