diff options
-rw-r--r-- | intern/cycles/blender/blender_object.cpp | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_layer.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/layer.c | 27 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_object_api.c | 15 |
4 files changed, 45 insertions, 3 deletions
diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp index 59509d20fb2..d3efc18a990 100644 --- a/intern/cycles/blender/blender_object.cpp +++ b/intern/cycles/blender/blender_object.cpp @@ -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, diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h index d2c869532c8..19eb40debe6 100644 --- a/source/blender/blenkernel/BKE_layer.h +++ b/source/blender/blenkernel/BKE_layer.h @@ -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, diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index 726ca9d705b..b915fddca18 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -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; diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index 56d25f5bebf..babf388bfc7 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -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( |