Depsgraph and collection enable/visibility
authorDalai Felinto <dfelinto@gmail.com>
Thu, 21 Sep 2017 10:55:14 +0000 (12:55 +0200)
committerDalai Felinto <dfelinto@gmail.com>
Thu, 21 Sep 2017 12:45:08 +0000 (14:45 +0200)
Iterate over invisible objects too, so lamps can still lit the scene.
Also, now you can use a collection to set an object to invisible, not
only to visible.

For example:
Scene > Master collection > bedroom > furniture
Scene > View Layer > bedroom    (visible)
                   > furniture  (invisible)

The View Layer has two linked collections, bedroom and furniture.
This setup will make the furniture collection invisible.

Note: Unlike what was suggested on D2849, this does not make collection
visibility influence camera visibility. I will keep this as a separate
patch.

Reviewers: sergey

Subscribers: sergey, brecht, fclem

Differential Revision: https://developer.blender.org/D2849

12 files changed:
intern/cycles/blender/blender_object.cpp
source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/layer.c
source/blender/blenkernel/intern/object.c
source/blender/depsgraph/intern/depsgraph_query.cc
source/blender/draw/engines/eevee/eevee_engine.c
source/blender/draw/engines/eevee/eevee_lightprobes.c
source/blender/draw/intern/draw_manager.c
source/blender/draw/modes/object_mode.c
source/blender/editors/space_view3d/drawobject.c
source/blender/makesrna/intern/rna_object.c
source/blender/makesrna/intern/rna_object_api.c

index 991b834dcfad66a3dcc43a3b94b79232250bbd96..635f1d2eb46da2b465eccd46594387a65d8d2fe0 100644 (file)
@@ -519,6 +519,10 @@ void BlenderSync::sync_objects(float motion_time)
            ++b_dupli_iter)
        {
                BL::Object b_ob = b_dupli_iter->object();
+               if(!b_ob.is_visible()) {
+                       continue;
+               }
+
                progress.set_sync_status("Synchronizing object", b_ob.name());
 
                /* load per-object culling data */
index 35cde742ff06923245b4f51da04ba8bd3964b203..ce6a95c682b279f06b21b326e096a4ee34799e90 100644 (file)
@@ -83,6 +83,7 @@ bool BKE_object_exists_check(struct Object *obtest);
 bool BKE_object_is_in_editmode(struct Object *ob);
 bool BKE_object_is_in_editmode_vgroup(struct Object *ob);
 bool BKE_object_is_in_wpaint_select_vert(struct Object *ob);
+bool BKE_object_is_visible(struct Object *ob);
 
 void BKE_object_init(struct Object *ob);
 struct Object *BKE_object_add_only_object(
index 5d0cb6ae4308e0dd5328b84dda67313006849568..126a2b7bb6c71d1ea4aeea10f496aab6dc1e16b2 100644 (file)
@@ -1860,6 +1860,9 @@ void BKE_layer_eval_layer_collection(const struct EvaluationContext *UNUSED(eval
                        IDP_MergeGroup(base->collection_properties, layer_collection->properties_evaluated, true);
                        base->flag |= BASE_VISIBLED;
                }
+               else {
+                       base->flag &= ~BASE_VISIBLED;
+               }
 
                if (is_selectable) {
                        base->flag |= BASE_SELECTABLED;
index 9f48d8f6b110375fa9981a206ec7290383061e82..cfb6db3581032a81a51f7e90db1229000da7a877 100644 (file)
@@ -562,6 +562,15 @@ bool BKE_object_is_in_wpaint_select_vert(Object *ob)
        return false;
 }
 
+/**
+ * Return if the object is visible, as evaluated by depsgraph
+ * Keep in sync with rna_object.c (object.is_visible).
+ */
+bool BKE_object_is_visible(Object *ob)
+{
+       return (ob->base_flag & BASE_VISIBLED) != 0;
+}
+
 bool BKE_object_exists_check(Object *obtest)
 {
        Object *ob;
index 7d0ac47e6fda4aa6d38bbb4f3c55aa110b560f8c..0d06cc48b88e070b5b666cfe7d3798eb5bb19e1e 100644 (file)
@@ -211,33 +211,30 @@ void DEG_objects_iterator_next(BLI_Iterator *iter)
        }
 
        base = data->base->next;
-       while (base != NULL) {
-               if ((base->flag & BASE_VISIBLED) != 0) {
-                       // Object *ob = DEG_get_evaluated_object(data->graph, base->object);
-                       Object *ob = base->object;
-                       iter->current = ob;
-                       data->base = base;
-
-                       BLI_assert(DEG::deg_validate_copy_on_write_datablock(&ob->id));
-
-                       /* Make sure we have the base collection settings is already populated.
-                        * This will fail when BKE_layer_eval_layer_collection_pre hasn't run yet
-                        * Which usually means a missing call to DEG_id_tag_update(). */
-                       BLI_assert(!BLI_listbase_is_empty(&base->collection_properties->data.group));
-
-                       /* Flushing depsgraph data. */
-                       deg_flush_base_flags_and_settings(ob,
-                                                         base,
-                                                         data->base_flag);
-
-                       if ((data->flag & DEG_OBJECT_ITER_FLAG_DUPLI) && (ob->transflag & OB_DUPLI)) {
-                               data->dupli_parent = ob;
-                               data->dupli_list = object_duplilist(&data->eval_ctx, data->scene, ob);
-                               data->dupli_object_next = (DupliObject *)data->dupli_list->first;
-                       }
-                       return;
+       if (base != NULL) {
+               // Object *ob = DEG_get_evaluated_object(data->graph, base->object);
+               Object *ob = base->object;
+               iter->current = ob;
+               data->base = base;
+
+               BLI_assert(DEG::deg_validate_copy_on_write_datablock(&ob->id));
+
+               /* Make sure we have the base collection settings is already populated.
+                * This will fail when BKE_layer_eval_layer_collection_pre hasn't run yet
+                * Which usually means a missing call to DEG_id_tag_update(). */
+               BLI_assert(!BLI_listbase_is_empty(&base->collection_properties->data.group));
+
+               /* Flushing depsgraph data. */
+               deg_flush_base_flags_and_settings(ob,
+                                                                                 base,
+                                                                                 data->base_flag);
+
+               if ((data->flag & DEG_OBJECT_ITER_FLAG_DUPLI) && (ob->transflag & OB_DUPLI)) {
+                       data->dupli_parent = ob;
+                       data->dupli_list = object_duplilist(&data->eval_ctx, data->scene, ob);
+                       data->dupli_object_next = (DupliObject *)data->dupli_list->first;
                }
-               base = base->next;
+               return;
        }
 
        /* Look for an object in the next set. */
index e8821f236334d0b46dd6b4877d3cef17910ece16..f27b5236d7168fe1f971a1d98c30164e886b1be0 100644 (file)
@@ -29,6 +29,8 @@
 #include "BLI_dynstr.h"
 #include "BLI_rand.h"
 
+#include "BKE_object.h"
+
 #include "GPU_material.h"
 #include "GPU_glew.h"
 
@@ -93,6 +95,10 @@ static void EEVEE_cache_populate(void *vedata, Object *ob)
        }
 
        if (ELEM(ob->type, OB_MESH)) {
+               if (!BKE_object_is_visible(ob)) {
+                       return;
+               }
+
                EEVEE_materials_cache_populate(vedata, sldata, ob);
 
                const bool cast_shadow = true;
index 96db3164fe18561f605971ce88e99a154f1aa327..a37dc091aa8b9d4bd08a6ce8322027d070ef4a65 100644 (file)
@@ -590,7 +590,10 @@ static void EEVEE_planar_reflections_updates(EEVEE_SceneLayerData *sldata, EEVEE
                eplanar->attenuation_bias = max_dist * -eplanar->attenuation_scale;
 
                /* Debug Display */
-               if (DRW_state_draw_support() && (probe->flag & LIGHTPROBE_FLAG_SHOW_DATA)) {
+               if (BKE_object_is_visible(ob) &&
+                   DRW_state_draw_support() &&
+                   (probe->flag & LIGHTPROBE_FLAG_SHOW_DATA))
+               {
                        DRWShadingGroup *grp = DRW_shgroup_create(e_data.probe_planar_display_sh, psl->probe_display);
 
                        DRW_shgroup_uniform_int(grp, "probeIdx", &ped->probe_id, 1);
@@ -643,8 +646,12 @@ static void EEVEE_lightprobes_updates(EEVEE_SceneLayerData *sldata, EEVEE_PassLi
                invert_m4(eprobe->parallaxmat);
 
                /* Debug Display */
-               if (DRW_state_draw_support() && (probe->flag & LIGHTPROBE_FLAG_SHOW_DATA)) {
-                       DRW_shgroup_call_dynamic_add(stl->g_data->cube_display_shgrp, &ped->probe_id, ob->obmat[3], &probe->data_draw_size);
+               if (BKE_object_is_visible(ob) &&
+                       DRW_state_draw_support() &&
+                   (probe->flag & LIGHTPROBE_FLAG_SHOW_DATA))
+               {
+                       DRW_shgroup_call_dynamic_add(
+                                   stl->g_data->cube_display_shgrp, &ped->probe_id, ob->obmat[3], &probe->data_draw_size);
                }
        }
 
@@ -701,7 +708,10 @@ static void EEVEE_lightprobes_updates(EEVEE_SceneLayerData *sldata, EEVEE_PassLi
                copy_v3_v3_int(egrid->resolution, &probe->grid_resolution_x);
 
                /* Debug Display */
-               if (DRW_state_draw_support() && (probe->flag & LIGHTPROBE_FLAG_SHOW_DATA)) {
+               if (BKE_object_is_visible(ob) &&
+                   DRW_state_draw_support() &&
+                   (probe->flag & LIGHTPROBE_FLAG_SHOW_DATA))
+               {
                        struct Gwn_Batch *geom = DRW_cache_sphere_get();
                        DRWShadingGroup *grp = DRW_shgroup_instance_create(e_data.probe_grid_display_sh, psl->probe_display, geom);
                        DRW_shgroup_set_instance_count(grp, ped->num_cell);
index bd143e33d0930561f97db7728b53b653640dda2b..b20c9fe013b3325fb5c693df4a9532d487732b7b 100644 (file)
@@ -2164,6 +2164,10 @@ bool DRW_object_is_renderable(Object *ob)
        Scene *scene = DST.draw_ctx.scene;
        Object *obedit = scene->obedit;
 
+       if (!BKE_object_is_visible(ob)) {
+               return false;
+       }
+
        if (ob->type == OB_MESH) {
                if (ob == obedit) {
                        IDProperty *props = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_EDIT, "");
index 933f8a60b9f7f30d0323cc40f6be2eb9b557753a..22571808cbcf4632d2f9f707316f805b85900a08 100644 (file)
@@ -43,6 +43,7 @@
 #include "BKE_camera.h"
 #include "BKE_curve.h"
 #include "BKE_global.h"
+#include "BKE_object.h"
 #include "BKE_particle.h"
 #include "BKE_image.h"
 #include "BKE_texture.h"
@@ -1562,7 +1563,7 @@ static void DRW_shgroup_lightprobe(OBJECT_StorageList *stl, Object *ob, SceneLay
 
 static void DRW_shgroup_relationship_lines(OBJECT_StorageList *stl, Object *ob)
 {
-       if (ob->parent && ((ob->parent->base_flag & BASE_VISIBLED) != 0)) {
+       if (ob->parent && BKE_object_is_visible(ob->parent)) {
                DRW_shgroup_call_dynamic_add(stl->g_data->relationship_lines, ob->obmat[3]);
                DRW_shgroup_call_dynamic_add(stl->g_data->relationship_lines, ob->parent->obmat[3]);
        }
@@ -1677,6 +1678,10 @@ static void OBJECT_cache_populate(void *vedata, Object *ob)
        View3D *v3d = draw_ctx->v3d;
        int theme_id = TH_UNDEFINED;
 
+       if (!BKE_object_is_visible(ob)) {
+               return;
+       }
+
        //CollectionEngineSettings *ces_mode_ob = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_OBJECT, "");
 
        //bool do_wire = BKE_collection_engine_property_value_get_bool(ces_mode_ob, "show_wire");
index 2fce8783aa2f89123625333bad3255d7137e2459..4df7f6762bcc11383ebc6a72b712c67849309872 100644 (file)
@@ -9217,7 +9217,7 @@ afterdraw:
 
                /* help lines and so */
                if (ob != scene->obedit && ob->parent) {
-                       if ((ob->parent->base_flag & BASE_VISIBLED) != 0) {
+                       if (BKE_object_is_visible(ob->parent)) {
                                setlinestyle(3);
                                immBegin(GWN_PRIM_LINES, 2);
                                immVertex3fv(pos, ob->obmat[3]);
index 427ef5c307f485f4ac9a5221452782433cdf4da6..e57333fb8a77b01678965c573a2c530331ccc620 100644 (file)
@@ -2897,6 +2897,12 @@ static void rna_def_object(BlenderRNA *brna)
        RNA_def_property_ui_icon(prop, ICON_RESTRICT_RENDER_OFF, 1);
        RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_hide_update");
 
+       /* Keep it in sync with BKE_object_is_visible. */
+       prop = RNA_def_property(srna, "is_visible", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "base_flag", BASE_VISIBLED);
+       RNA_def_property_ui_text(prop, "Visible", "Visible to camera rays, set only on objects evaluated by depsgraph");
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
        prop = RNA_def_property(srna, "collection_properties", PROP_COLLECTION, PROP_NONE);
        RNA_def_property_collection_sdna(prop, NULL, "base_collection_properties->data.group", NULL);
        RNA_def_property_struct_type(prop, "LayerCollectionSettings");
index 7bf483ad2f023f1d18de5667083bad0094425c89..1234bd9f3677a3b025c04f325872d5e2f3ee9c8d 100644 (file)
@@ -329,11 +329,6 @@ static void rna_Object_shape_key_remove(
        RNA_POINTER_INVALIDATE(kb_ptr);
 }
 
-static int rna_Object_is_visible(Object *ob, Scene *sce)
-{
-       return !(ob->restrictflag & OB_RESTRICT_VIEW) && (ob->lay & sce->lay);
-}
-
 #if 0
 static void rna_Mesh_assign_verts_to_group(Object *ob, bDeformGroup *group, int *indices, int totindex,
                                            float weight, int assignmode)
@@ -754,12 +749,6 @@ void RNA_api_object(StructRNA *srna)
        RNA_def_function_output(func, parm);
 
        /* View */
-       func = RNA_def_function(srna, "is_visible", "rna_Object_is_visible");
-       RNA_def_function_ui_description(func, "Determine if object is visible in a given scene");
-       parm = RNA_def_pointer(func, "scene", "Scene", "", "");
-       RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
-       parm = RNA_def_boolean(func, "result", 0, "", "Object visibility");
-       RNA_def_function_return(func, parm);
 
        /* utility function for checking if the object is modified */
        func = RNA_def_function(srna, "is_modified", "rna_Object_is_modified");