Blender  V3.3
layer.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 /* Allow using deprecated functionality for .blend file I/O. */
8 #define DNA_DEPRECATED_ALLOW
9 
10 #include <string.h>
11 
12 #include "CLG_log.h"
13 
14 #include "BLI_listbase.h"
15 #include "BLI_mempool.h"
16 #include "BLI_string.h"
17 #include "BLI_string_utf8.h"
18 #include "BLI_string_utils.h"
19 #include "BLI_threads.h"
20 #include "BLT_translation.h"
21 
22 #include "BKE_animsys.h"
23 #include "BKE_collection.h"
24 #include "BKE_freestyle.h"
25 #include "BKE_idprop.h"
26 #include "BKE_layer.h"
27 #include "BKE_lib_id.h"
28 #include "BKE_main.h"
29 #include "BKE_node.h"
30 #include "BKE_object.h"
31 
32 #include "DNA_ID.h"
33 #include "DNA_collection_types.h"
34 #include "DNA_layer_types.h"
35 #include "DNA_node_types.h"
36 #include "DNA_object_types.h"
37 #include "DNA_scene_types.h"
38 #include "DNA_space_types.h"
39 #include "DNA_view3d_types.h"
41 #include "DNA_workspace_types.h"
42 #include "DNA_world_types.h"
43 
44 #include "DEG_depsgraph.h"
45 #include "DEG_depsgraph_debug.h"
46 #include "DEG_depsgraph_query.h"
47 
48 #include "DRW_engine.h"
49 
50 #include "RE_engine.h"
51 
52 #include "MEM_guardedalloc.h"
53 
54 #include "BLO_read_write.h"
55 
56 static CLG_LogRef LOG = {"bke.layercollection"};
57 
58 /* Set of flags which are dependent on a collection settings. */
63 
64 /* prototype */
65 static void object_bases_iterator_next(BLI_Iterator *iter, const int flag);
66 
67 /* -------------------------------------------------------------------- */
71 static LayerCollection *layer_collection_add(ListBase *lb_parent, Collection *collection)
72 {
73  LayerCollection *lc = MEM_callocN(sizeof(LayerCollection), "Collection Base");
74  lc->collection = collection;
75  lc->local_collections_bits = ~(0);
76  BLI_addtail(lb_parent, lc);
77 
78  return lc;
79 }
80 
81 static void layer_collection_free(ViewLayer *view_layer, LayerCollection *lc)
82 {
83  if (lc == view_layer->active_collection) {
84  view_layer->active_collection = NULL;
85  }
86 
88  layer_collection_free(view_layer, nlc);
89  }
90 
92 }
93 
95 {
96  Base *base = MEM_callocN(sizeof(Base), "Object Base");
97  base->object = ob;
98  base->local_view_bits = ~(0);
99  if (ob->base_flag & BASE_SELECTED) {
100  base->flag |= BASE_SELECTED;
101  }
102  return base;
103 }
104 
107 /* -------------------------------------------------------------------- */
111 /* RenderLayer */
112 
114 {
115  LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
116  if (!(view_layer->flag & VIEW_LAYER_RENDER)) {
117  return view_layer;
118  }
119  }
120 
122  return scene->view_layers.first;
123 }
124 
126 {
127  LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
128  if (view_layer->flag & VIEW_LAYER_RENDER) {
129  return view_layer;
130  }
131  }
132 
134  return scene->view_layers.first;
135 }
136 
137 ViewLayer *BKE_view_layer_find(const Scene *scene, const char *layer_name)
138 {
139  LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
140  if (STREQ(view_layer->name, layer_name)) {
141  return view_layer;
142  }
143  }
144 
145  return NULL;
146 }
147 
149 {
151  return scene->view_layers.first;
152 }
153 
154 static ViewLayer *view_layer_add(const char *name)
155 {
156  if (!name) {
157  name = DATA_("ViewLayer");
158  }
159 
160  ViewLayer *view_layer = MEM_callocN(sizeof(ViewLayer), "View Layer");
162 
163  BLI_strncpy_utf8(view_layer->name, name, sizeof(view_layer->name));
164 
165  /* Pure rendering pipeline settings. */
166  view_layer->layflag = SCE_LAY_FLAG_DEFAULT;
167  view_layer->passflag = SCE_PASS_COMBINED;
168  view_layer->pass_alpha_threshold = 0.5f;
169  view_layer->cryptomatte_levels = 6;
172 
173  return view_layer;
174 }
175 
176 static void layer_collection_exclude_all(LayerCollection *layer_collection)
177 {
178  LayerCollection *sub_collection = layer_collection->layer_collections.first;
179  for (; sub_collection != NULL; sub_collection = sub_collection->next) {
180  sub_collection->flag |= LAYER_COLLECTION_EXCLUDE;
181  layer_collection_exclude_all(sub_collection);
182  }
183 }
184 
186  const char *name,
187  ViewLayer *view_layer_source,
188  const int type)
189 {
190  ViewLayer *view_layer_new;
191 
192  if (view_layer_source) {
193  name = view_layer_source->name;
194  }
195 
196  switch (type) {
197  default:
198  case VIEWLAYER_ADD_NEW: {
199  view_layer_new = view_layer_add(name);
200  BLI_addtail(&scene->view_layers, view_layer_new);
201  BKE_layer_collection_sync(scene, view_layer_new);
202  break;
203  }
204  case VIEWLAYER_ADD_COPY: {
205  /* Allocate and copy view layer data */
206  view_layer_new = MEM_callocN(sizeof(ViewLayer), "View Layer");
207  *view_layer_new = *view_layer_source;
208  BKE_view_layer_copy_data(scene, scene, view_layer_new, view_layer_source, 0);
209  BLI_addtail(&scene->view_layers, view_layer_new);
210 
211  BLI_strncpy_utf8(view_layer_new->name, name, sizeof(view_layer_new->name));
212  break;
213  }
214  case VIEWLAYER_ADD_EMPTY: {
215  view_layer_new = view_layer_add(name);
216  BLI_addtail(&scene->view_layers, view_layer_new);
217 
218  /* Initialize layer-collections. */
219  BKE_layer_collection_sync(scene, view_layer_new);
221 
222  /* Update collections after changing visibility */
223  BKE_layer_collection_sync(scene, view_layer_new);
224  break;
225  }
226  }
227 
228  /* unique name */
230  view_layer_new,
231  DATA_("ViewLayer"),
232  '_',
233  offsetof(ViewLayer, name),
234  sizeof(view_layer_new->name));
235 
236  return view_layer_new;
237 }
238 
240 {
241  BKE_view_layer_free_ex(view_layer, true);
242 }
243 
244 void BKE_view_layer_free_ex(ViewLayer *view_layer, const bool do_id_user)
245 {
246  view_layer->basact = NULL;
247 
248  BLI_freelistN(&view_layer->object_bases);
249 
250  if (view_layer->object_bases_hash) {
251  BLI_ghash_free(view_layer->object_bases_hash, NULL, NULL);
252  }
253 
254  LISTBASE_FOREACH (LayerCollection *, lc, &view_layer->layer_collections) {
255  layer_collection_free(view_layer, lc);
256  }
257  BLI_freelistN(&view_layer->layer_collections);
258 
259  LISTBASE_FOREACH (ViewLayerEngineData *, sled, &view_layer->drawdata) {
260  if (sled->storage) {
261  if (sled->free) {
262  sled->free(sled->storage);
263  }
264  MEM_freeN(sled->storage);
265  }
266  }
267  BLI_freelistN(&view_layer->drawdata);
268  BLI_freelistN(&view_layer->aovs);
269  view_layer->active_aov = NULL;
270  BLI_freelistN(&view_layer->lightgroups);
271  view_layer->active_lightgroup = NULL;
272 
273  MEM_SAFE_FREE(view_layer->stats);
274 
275  BKE_freestyle_config_free(&view_layer->freestyle_config, do_id_user);
276 
277  if (view_layer->id_properties) {
278  IDP_FreeProperty_ex(view_layer->id_properties, do_id_user);
279  }
280 
281  MEM_SAFE_FREE(view_layer->object_bases_array);
282 
283  MEM_freeN(view_layer);
284 }
285 
286 void BKE_view_layer_selected_objects_tag(ViewLayer *view_layer, const int tag)
287 {
288  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
289  if ((base->flag & BASE_SELECTED) != 0) {
290  base->object->flag |= tag;
291  }
292  else {
293  base->object->flag &= ~tag;
294  }
295  }
296 }
297 
299 {
300  LISTBASE_FOREACH (LayerCollection *, lcn, lb) {
301  if (lcn == lc) {
302  return true;
303  }
304  if (find_scene_collection_in_scene_collections(&lcn->layer_collections, lc)) {
305  return true;
306  }
307  }
308  return false;
309 }
310 
312 {
313  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
314  if (base->object->type == OB_CAMERA) {
315  return base->object;
316  }
317  }
318 
319  return NULL;
320 }
321 
323 {
324  LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
325  if (find_scene_collection_in_scene_collections(&view_layer->layer_collections, lc)) {
326  return view_layer;
327  }
328  }
329 
330  return NULL;
331 }
332 
333 /* Base */
334 
335 static void view_layer_bases_hash_create(ViewLayer *view_layer, const bool do_base_duplicates_fix)
336 {
337  static ThreadMutex hash_lock = BLI_MUTEX_INITIALIZER;
338 
339  if (view_layer->object_bases_hash == NULL) {
340  BLI_mutex_lock(&hash_lock);
341 
342  if (view_layer->object_bases_hash == NULL) {
344 
345  LISTBASE_FOREACH_MUTABLE (Base *, base, &view_layer->object_bases) {
346  if (base->object) {
347  void **val_pp;
348  if (!BLI_ghash_ensure_p(hash, base->object, &val_pp)) {
349  *val_pp = base;
350  }
351  /* The same object has several bases.
352  *
353  * In normal cases this is a serious bug, but this is a common situation when remapping
354  * an object into another one already present in the same View Layer. While ideally we
355  * would process this case separately, for performances reasons it makes more sense to
356  * tackle it here. */
357  else if (do_base_duplicates_fix) {
358  if (view_layer->basact == base) {
359  view_layer->basact = NULL;
360  }
361  BLI_freelinkN(&view_layer->object_bases, base);
362  }
363  else {
364  CLOG_FATAL(&LOG,
365  "Object '%s' has more than one entry in view layer's object bases listbase",
366  base->object->id.name + 2);
367  }
368  }
369  }
370 
371  /* Assign pointer only after hash is complete. */
372  view_layer->object_bases_hash = hash;
373  }
374 
375  BLI_mutex_unlock(&hash_lock);
376  }
377 }
378 
380 {
381  if (!view_layer->object_bases_hash) {
382  view_layer_bases_hash_create(view_layer, false);
383  }
384 
385  return BLI_ghash_lookup(view_layer->object_bases_hash, ob);
386 }
387 
389 {
390  Base *base;
391 
392  for (base = view_layer->object_bases.first; base; base = base->next) {
393  base->flag &= ~BASE_SELECTED;
394  }
395 }
396 
397 void BKE_view_layer_base_select_and_set_active(struct ViewLayer *view_layer, Base *selbase)
398 {
399  view_layer->basact = selbase;
400  if ((selbase->flag & BASE_SELECTABLE) != 0) {
401  selbase->flag |= BASE_SELECTED;
402  }
403 }
404 
407 /* -------------------------------------------------------------------- */
411 static void layer_aov_copy_data(ViewLayer *view_layer_dst,
412  const ViewLayer *view_layer_src,
413  ListBase *aovs_dst,
414  const ListBase *aovs_src)
415 {
416  if (aovs_src != NULL) {
417  BLI_duplicatelist(aovs_dst, aovs_src);
418  }
419 
420  ViewLayerAOV *aov_dst = aovs_dst->first;
421  const ViewLayerAOV *aov_src = aovs_src->first;
422 
423  while (aov_dst != NULL) {
424  BLI_assert(aov_src);
425  if (aov_src == view_layer_src->active_aov) {
426  view_layer_dst->active_aov = aov_dst;
427  }
428 
429  aov_dst = aov_dst->next;
430  aov_src = aov_src->next;
431  }
432 }
433 
434 static void layer_lightgroup_copy_data(ViewLayer *view_layer_dst,
435  const ViewLayer *view_layer_src,
436  ListBase *lightgroups_dst,
437  const ListBase *lightgroups_src)
438 {
439  if (lightgroups_src != NULL) {
440  BLI_duplicatelist(lightgroups_dst, lightgroups_src);
441  }
442 
443  ViewLayerLightgroup *lightgroup_dst = lightgroups_dst->first;
444  const ViewLayerLightgroup *lightgroup_src = lightgroups_src->first;
445 
446  while (lightgroup_dst != NULL) {
447  BLI_assert(lightgroup_src);
448  if (lightgroup_src == view_layer_src->active_lightgroup) {
449  view_layer_dst->active_lightgroup = lightgroup_dst;
450  }
451 
452  lightgroup_dst = lightgroup_dst->next;
453  lightgroup_src = lightgroup_src->next;
454  }
455 }
456 
457 static void layer_collections_copy_data(ViewLayer *view_layer_dst,
458  const ViewLayer *view_layer_src,
459  ListBase *layer_collections_dst,
460  const ListBase *layer_collections_src)
461 {
462  BLI_duplicatelist(layer_collections_dst, layer_collections_src);
463 
464  LayerCollection *layer_collection_dst = layer_collections_dst->first;
465  const LayerCollection *layer_collection_src = layer_collections_src->first;
466 
467  while (layer_collection_dst != NULL) {
468  layer_collections_copy_data(view_layer_dst,
469  view_layer_src,
470  &layer_collection_dst->layer_collections,
471  &layer_collection_src->layer_collections);
472 
473  if (layer_collection_src == view_layer_src->active_collection) {
474  view_layer_dst->active_collection = layer_collection_dst;
475  }
476 
477  layer_collection_dst = layer_collection_dst->next;
478  layer_collection_src = layer_collection_src->next;
479  }
480 }
481 
483  const Scene *UNUSED(scene_src),
484  ViewLayer *view_layer_dst,
485  const ViewLayer *view_layer_src,
486  const int flag)
487 {
488  if (view_layer_dst->id_properties != NULL) {
489  view_layer_dst->id_properties = IDP_CopyProperty_ex(view_layer_dst->id_properties, flag);
490  }
492  &view_layer_dst->freestyle_config, &view_layer_src->freestyle_config, flag);
493 
494  view_layer_dst->stats = NULL;
495 
496  /* Clear temporary data. */
497  BLI_listbase_clear(&view_layer_dst->drawdata);
498  view_layer_dst->object_bases_array = NULL;
499  view_layer_dst->object_bases_hash = NULL;
500 
501  /* Copy layer collections and object bases. */
502  /* Inline 'BLI_duplicatelist' and update the active base. */
503  BLI_listbase_clear(&view_layer_dst->object_bases);
504  LISTBASE_FOREACH (Base *, base_src, &view_layer_src->object_bases) {
505  Base *base_dst = MEM_dupallocN(base_src);
506  BLI_addtail(&view_layer_dst->object_bases, base_dst);
507  if (view_layer_src->basact == base_src) {
508  view_layer_dst->basact = base_dst;
509  }
510  }
511 
512  view_layer_dst->active_collection = NULL;
513  layer_collections_copy_data(view_layer_dst,
514  view_layer_src,
515  &view_layer_dst->layer_collections,
516  &view_layer_src->layer_collections);
517 
518  LayerCollection *lc_scene_dst = view_layer_dst->layer_collections.first;
519  lc_scene_dst->collection = scene_dst->master_collection;
520 
521  BLI_listbase_clear(&view_layer_dst->aovs);
523  view_layer_dst, view_layer_src, &view_layer_dst->aovs, &view_layer_src->aovs);
524 
525  BLI_listbase_clear(&view_layer_dst->lightgroups);
527  view_layer_dst, view_layer_src, &view_layer_dst->lightgroups, &view_layer_src->lightgroups);
528 
529  if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
530  id_us_plus((ID *)view_layer_dst->mat_override);
531  }
532 }
533 
534 void BKE_view_layer_rename(Main *bmain, Scene *scene, ViewLayer *view_layer, const char *newname)
535 {
536  char oldname[sizeof(view_layer->name)];
537 
538  BLI_strncpy(oldname, view_layer->name, sizeof(view_layer->name));
539 
540  BLI_strncpy_utf8(view_layer->name, newname, sizeof(view_layer->name));
542  view_layer,
543  DATA_("ViewLayer"),
544  '.',
545  offsetof(ViewLayer, name),
546  sizeof(view_layer->name));
547 
548  if (scene->nodetree) {
549  bNode *node;
550  int index = BLI_findindex(&scene->view_layers, view_layer);
551 
552  for (node = scene->nodetree->nodes.first; node; node = node->next) {
553  if (node->type == CMP_NODE_R_LAYERS && node->id == NULL) {
554  if (node->custom1 == index) {
555  BLI_strncpy(node->name, view_layer->name, NODE_MAXSTR);
556  }
557  }
558  }
559  }
560 
561  /* Fix all the animation data and windows which may link to this. */
562  BKE_animdata_fix_paths_rename_all(NULL, "view_layers", oldname, view_layer->name);
563 
564  /* WM can be missing on startup. */
565  wmWindowManager *wm = bmain->wm.first;
566  if (wm) {
567  LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
568  if (win->scene == scene && STREQ(win->view_layer_name, oldname)) {
569  STRNCPY(win->view_layer_name, view_layer->name);
570  }
571  }
572  }
573 
574  /* Dependency graph uses view layer name based lookups. */
575  DEG_id_tag_update(&scene->id, 0);
576 }
577 
578 /* LayerCollection */
579 
583 static LayerCollection *collection_from_index(ListBase *lb, const int number, int *i)
584 {
585  LISTBASE_FOREACH (LayerCollection *, lc, lb) {
586  if (*i == number) {
587  return lc;
588  }
589 
590  (*i)++;
591  }
592 
593  LISTBASE_FOREACH (LayerCollection *, lc, lb) {
594  LayerCollection *lc_nested = collection_from_index(&lc->layer_collections, number, i);
595  if (lc_nested) {
596  return lc_nested;
597  }
598  }
599  return NULL;
600 }
601 
605 static bool layer_collection_hidden(ViewLayer *view_layer, LayerCollection *lc)
606 {
607  if (lc->flag & LAYER_COLLECTION_EXCLUDE) {
608  return true;
609  }
610 
611  /* Check visiblilty restriction flags */
613  return true;
614  }
615 
616  /* Restriction flags stay set, so we need to check parents */
617  CollectionParent *parent = lc->collection->parents.first;
618 
619  if (parent) {
621 
622  return lc && layer_collection_hidden(view_layer, lc);
623  }
624 
625  return false;
626 
627  return false;
628 }
629 
631 {
632  int i = 0;
633  return collection_from_index(&view_layer->layer_collections, index, &i);
634 }
635 
637 {
638  return view_layer->active_collection;
639 }
640 
642 {
643  if (lc->flag & LAYER_COLLECTION_EXCLUDE) {
644  return false;
645  }
646 
647  view_layer->active_collection = lc;
648  return true;
649 }
650 
652 {
653  CollectionParent *parent = lc->collection->parents.first;
654 
655  if (parent) {
657  }
658  else {
659  lc = NULL;
660  }
661 
662  /* Don't activate excluded or hidden collections to prevent creating objects in a hidden
663  * collection from the UI */
664  if (lc && layer_collection_hidden(view_layer, lc)) {
665  return BKE_layer_collection_activate_parent(view_layer, lc);
666  }
667 
668  if (!lc) {
669  lc = view_layer->layer_collections.first;
670  }
671 
672  view_layer->active_collection = lc;
673  return lc;
674 }
675 
679 static int collection_count(const ListBase *lb)
680 {
681  int i = 0;
682  LISTBASE_FOREACH (const LayerCollection *, lc, lb) {
683  i += collection_count(&lc->layer_collections) + 1;
684  }
685  return i;
686 }
687 
688 int BKE_layer_collection_count(const ViewLayer *view_layer)
689 {
690  return collection_count(&view_layer->layer_collections);
691 }
692 
696 static int index_from_collection(ListBase *lb, const LayerCollection *lc, int *i)
697 {
698  LISTBASE_FOREACH (LayerCollection *, lcol, lb) {
699  if (lcol == lc) {
700  return *i;
701  }
702 
703  (*i)++;
704  }
705 
706  LISTBASE_FOREACH (LayerCollection *, lcol, lb) {
707  int i_nested = index_from_collection(&lcol->layer_collections, lc, i);
708  if (i_nested != -1) {
709  return i_nested;
710  }
711  }
712  return -1;
713 }
714 
716 {
717  int i = 0;
718  return index_from_collection(&view_layer->layer_collections, lc, &i);
719 }
720 
723 /* -------------------------------------------------------------------- */
759 static bool no_resync = false;
760 
762 {
763  no_resync = true;
764 }
765 
767 {
768  no_resync = false;
769 }
770 
771 typedef struct LayerCollectionResync {
773 
774  /* Temp data used to generate a queue during valid layer search. See
775  * #layer_collection_resync_find. */
777 
778  /* LayerCollection and Collection wrapped by this data. */
781 
782  /* Hierarchical relationships in the old, existing ViewLayer state (except for newly created
783  * layers). */
786 
787  /* This layer still points to a valid collection. */
788  bool is_usable;
789  /* This layer is still valid as a parent, i.e. at least one of its original layer children is
790  * usable and matches one of its current children collections. */
792  /* This layer is still valid as a child, i.e. its original layer parent is usable and matches one
793  * of its current parents collections. */
795  /* This layer is still fully valid in the new collection hierarchy, i.e. itself and all of its
796  * parents fully match the current collection hierarchy.
797  * OR
798  * This layer has already been re-used to match the new collections hierarchy. */
799  bool is_used;
801 
804 {
805  LayerCollectionResync *layer_resync = BLI_mempool_calloc(mempool);
806 
807  layer_resync->layer = layer;
808  layer_resync->collection = layer->collection;
810  if (parent_layer_resync != NULL) {
812  }
813 
814  layer_resync->is_usable = (layer->collection != NULL);
815  layer_resync->is_valid_as_child =
816  layer_resync->is_usable && (parent_layer_resync == NULL ||
819  layer->collection,
820  offsetof(CollectionChild, collection)) != NULL));
821  if (layer_resync->is_valid_as_child) {
822  layer_resync->is_used = parent_layer_resync != NULL ? parent_layer_resync->is_used : true;
823  }
824  else {
825  layer_resync->is_used = false;
826  }
827 
829  layer_resync->is_valid_as_parent = layer_resync->is_usable;
830  }
831  else {
834  layer_resync, child_layer, mempool);
835  if (layer_resync->is_usable && child_layer_resync->is_valid_as_child) {
836  layer_resync->is_valid_as_parent = true;
837  }
838  }
839  }
840 
841  CLOG_INFO(&LOG,
842  4,
843  "Old LayerCollection for %s is...\n\tusable: %d\n\tvalid parent: %d\n\tvalid child: "
844  "%d\n\tused: %d\n",
845  layer_resync->collection ? layer_resync->collection->id.name : "<NONE>",
846  layer_resync->is_usable,
847  layer_resync->is_valid_as_parent,
848  layer_resync->is_valid_as_child,
849  layer_resync->is_used);
850 
851  return layer_resync;
852 }
853 
855  Collection *child_collection)
856 {
857  /* Given the given parent, valid layer collection, find in the old hierarchy the best possible
858  * unused layer matching the given child collection.
859  *
860  * This uses the following heuristics:
861  * - Prefer a layer descendant of the given parent one if possible.
862  * - Prefer a layer as closely related as possible from the given parent.
863  * - Do not used layers that are not head (highest possible ancestor) of a local valid hierarchy
864  * branch, since we can assume we could then re-use its ancestor instead.
865  *
866  * A queue is used to ensure this order of preferences.
867  */
868 
869  BLI_assert(layer_resync->collection != child_collection);
870  BLI_assert(child_collection != NULL);
871 
872  LayerCollectionResync *current_layer_resync = NULL;
873  LayerCollectionResync *root_layer_resync = layer_resync;
874 
875  LayerCollectionResync *queue_head = layer_resync, *queue_tail = layer_resync;
876  layer_resync->queue_next = NULL;
877 
878  while (queue_head != NULL) {
879  current_layer_resync = queue_head;
880  queue_head = current_layer_resync->queue_next;
881 
882  if (current_layer_resync->collection == child_collection &&
883  (current_layer_resync->parent_layer_resync == layer_resync ||
884  (!current_layer_resync->is_used && !current_layer_resync->is_valid_as_child))) {
885  /* This layer is a valid candidate, because its collection matches the seeked one, AND:
886  * - It is a direct child of the initial given parent ('unchanged hierarchy' case), OR
887  * - It is not currently used, and not part of a valid hierarchy (sub-)chain.
888  */
889  break;
890  }
891 
892  /* Else, add all its direct children for further searching. */
894  child_layer_resync,
895  &current_layer_resync->children_layer_resync) {
896  /* Add to tail of the queue. */
897  queue_tail->queue_next = child_layer_resync;
898  child_layer_resync->queue_next = NULL;
899  queue_tail = child_layer_resync;
900  if (queue_head == NULL) {
901  queue_head = queue_tail;
902  }
903  }
904 
905  /* If all descendants from current layer have been processed, go one step higher and
906  * process all of its other siblings. */
907  if (queue_head == NULL && root_layer_resync->parent_layer_resync != NULL) {
909  sibling_layer_resync,
910  &root_layer_resync->parent_layer_resync->children_layer_resync) {
911  if (sibling_layer_resync == root_layer_resync) {
912  continue;
913  }
914  /* Add to tail of the queue. */
915  queue_tail->queue_next = sibling_layer_resync;
916  sibling_layer_resync->queue_next = NULL;
917  queue_tail = sibling_layer_resync;
918  if (queue_head == NULL) {
919  queue_head = queue_tail;
920  }
921  }
922  root_layer_resync = root_layer_resync->parent_layer_resync;
923  }
924 
925  current_layer_resync = NULL;
926  }
927 
928  return current_layer_resync;
929 }
930 
932  LayerCollectionResync *layer_resync)
933 {
935  LayerCollectionResync *, child_layer_resync, &layer_resync->children_layer_resync) {
936  layer_collection_resync_unused_layers_free(view_layer, child_layer_resync);
937  }
938 
939  if (!layer_resync->is_used) {
940  CLOG_INFO(&LOG,
941  4,
942  "Freeing unused LayerCollection for %s",
943  layer_resync->collection != NULL ? layer_resync->collection->id.name :
944  "<Deleted Collection>");
945 
946  if (layer_resync->layer == view_layer->active_collection) {
947  view_layer->active_collection = NULL;
948  }
949 
950  /* We do not want to go recursive here, this is handled through the LayerCollectionResync data
951  * wrapper. */
952  MEM_freeN(layer_resync->layer);
953  layer_resync->layer = NULL;
954  layer_resync->collection = NULL;
955  layer_resync->is_usable = false;
956  }
957 }
958 
959 static void layer_collection_objects_sync(ViewLayer *view_layer,
961  ListBase *r_lb_new_object_bases,
962  const short collection_restrict,
963  const short layer_restrict,
964  const ushort local_collections_bits)
965 {
966  /* No need to sync objects if the collection is excluded. */
967  if ((layer->flag & LAYER_COLLECTION_EXCLUDE) != 0) {
968  return;
969  }
970 
972  if (cob->ob == NULL) {
973  continue;
974  }
975 
976  /* Tag linked object as a weak reference so we keep the object
977  * base pointer on file load and remember hidden state. */
978  id_lib_indirect_weak_link(&cob->ob->id);
979 
980  void **base_p;
981  Base *base;
982  if (BLI_ghash_ensure_p(view_layer->object_bases_hash, cob->ob, &base_p)) {
983  /* Move from old base list to new base list. Base might have already
984  * been moved to the new base list and the first/last test ensure that
985  * case also works. */
986  base = *base_p;
987  if (!ELEM(base, r_lb_new_object_bases->first, r_lb_new_object_bases->last)) {
988  BLI_remlink(&view_layer->object_bases, base);
989  BLI_addtail(r_lb_new_object_bases, base);
990  }
991  }
992  else {
993  /* Create new base. */
994  base = object_base_new(cob->ob);
995  base->local_collections_bits = local_collections_bits;
996  *base_p = base;
997  BLI_addtail(r_lb_new_object_bases, base);
998  }
999 
1000  if ((collection_restrict & COLLECTION_HIDE_VIEWPORT) == 0) {
1002  if ((layer_restrict & LAYER_COLLECTION_HIDE) == 0) {
1004  }
1005  if (((collection_restrict & COLLECTION_HIDE_SELECT) == 0)) {
1007  }
1008  }
1009 
1010  if ((collection_restrict & COLLECTION_HIDE_RENDER) == 0) {
1012  }
1013 
1014  /* Holdout and indirect only */
1015  if ((layer->flag & LAYER_COLLECTION_HOLDOUT)) {
1017  }
1020  }
1021 
1023  }
1024 }
1025 
1026 static void layer_collection_sync(ViewLayer *view_layer,
1027  LayerCollectionResync *layer_resync,
1028  BLI_mempool *layer_resync_mempool,
1029  ListBase *r_lb_new_object_bases,
1030  const short parent_layer_flag,
1031  const short parent_collection_restrict,
1032  const short parent_layer_restrict,
1033  const ushort parent_local_collections_bits)
1034 {
1035  /* This function assumes current 'parent' layer collection is already fully (re)synced and valid
1036  * regarding current Collection hierarchy.
1037  *
1038  * It will process all the children collections of the collection from the given 'parent' layer,
1039  * re-use or create layer collections for each of them, and ensure orders also match.
1040  *
1041  * Then it will ensure that the objects owned by the given parent collection have a proper base.
1042  *
1043  * NOTE: This process is recursive.
1044  */
1045 
1046  /* Temporary storage for all valid (new or reused) children layers. */
1047  ListBase new_lb_layer = {NULL, NULL};
1048 
1049  BLI_assert(layer_resync->is_used);
1050 
1051  LISTBASE_FOREACH (CollectionChild *, child, &layer_resync->collection->children) {
1052  Collection *child_collection = child->collection;
1053  LayerCollectionResync *child_layer_resync = layer_collection_resync_find(layer_resync,
1054  child_collection);
1055 
1056  if (child_layer_resync != NULL) {
1057  BLI_assert(child_layer_resync->collection != NULL);
1058  BLI_assert(child_layer_resync->layer != NULL);
1059  BLI_assert(child_layer_resync->is_usable);
1060 
1061  if (child_layer_resync->is_used) {
1062  CLOG_INFO(&LOG,
1063  4,
1064  "Found same existing LayerCollection for %s as child of %s",
1065  child_collection->id.name,
1066  layer_resync->collection->id.name);
1067  }
1068  else {
1069  CLOG_INFO(&LOG,
1070  4,
1071  "Found a valid unused LayerCollection for %s as child of %s, re-using it",
1072  child_collection->id.name,
1073  layer_resync->collection->id.name);
1074  }
1075 
1076  child_layer_resync->is_used = true;
1077 
1078  /* NOTE: Do not move the resync wrapper to match the new layer hierarchy, so that the old
1079  * parenting info remains available. In case a search for a valid layer in the children of
1080  * the current is required again, the old parenting hierarchy is needed as reference, not the
1081  * new one.
1082  */
1083  BLI_remlink(&child_layer_resync->parent_layer_resync->layer->layer_collections,
1084  child_layer_resync->layer);
1085  BLI_addtail(&new_lb_layer, child_layer_resync->layer);
1086  }
1087  else {
1088  CLOG_INFO(&LOG,
1089  4,
1090  "No available LayerCollection for %s as child of %s, creating a new one",
1091  child_collection->id.name,
1092  layer_resync->collection->id.name);
1093 
1094  LayerCollection *child_layer = layer_collection_add(&new_lb_layer, child_collection);
1095  child_layer->flag = parent_layer_flag;
1096 
1097  child_layer_resync = BLI_mempool_calloc(layer_resync_mempool);
1098  child_layer_resync->collection = child_collection;
1099  child_layer_resync->layer = child_layer;
1100  child_layer_resync->is_usable = true;
1101  child_layer_resync->is_used = true;
1102  child_layer_resync->is_valid_as_child = true;
1103  child_layer_resync->is_valid_as_parent = true;
1104  /* NOTE: Needs to be added to the layer_resync hierarchy so that the resync wrapper gets
1105  * freed at the end. */
1106  child_layer_resync->parent_layer_resync = layer_resync;
1107  BLI_addtail(&layer_resync->children_layer_resync, child_layer_resync);
1108  }
1109 
1110  LayerCollection *child_layer = child_layer_resync->layer;
1111 
1112  const ushort child_local_collections_bits = parent_local_collections_bits &
1113  child_layer->local_collections_bits;
1114 
1115  /* Tag linked collection as a weak reference so we keep the layer
1116  * collection pointer on file load and remember exclude state. */
1117  id_lib_indirect_weak_link(&child_collection->id);
1118 
1119  /* Collection restrict is inherited. */
1120  short child_collection_restrict = parent_collection_restrict;
1121  short child_layer_restrict = parent_layer_restrict;
1122  if (!(child_collection->flag & COLLECTION_IS_MASTER)) {
1123  child_collection_restrict |= child_collection->flag;
1124  child_layer_restrict |= child_layer->flag;
1125  }
1126 
1127  /* Sync child collections. */
1128  layer_collection_sync(view_layer,
1129  child_layer_resync,
1130  layer_resync_mempool,
1131  r_lb_new_object_bases,
1132  child_layer->flag,
1133  child_collection_restrict,
1134  child_layer_restrict,
1135  child_local_collections_bits);
1136 
1137  /* Layer collection exclude is not inherited. */
1138  child_layer->runtime_flag = 0;
1139  if (child_layer->flag & LAYER_COLLECTION_EXCLUDE) {
1140  continue;
1141  }
1142 
1143  /* We separate restrict viewport and visible view layer because a layer collection can be
1144  * hidden in the view layer yet (locally) visible in a viewport (if it is not restricted). */
1145  if (child_collection_restrict & COLLECTION_HIDE_VIEWPORT) {
1147  }
1148 
1149  if (((child_layer->runtime_flag & LAYER_COLLECTION_HIDE_VIEWPORT) == 0) &&
1150  ((child_layer_restrict & LAYER_COLLECTION_HIDE) == 0)) {
1152  }
1153  }
1154 
1155  /* Replace layer collection list with new one. */
1156  layer_resync->layer->layer_collections = new_lb_layer;
1157  BLI_assert(BLI_listbase_count(&layer_resync->collection->children) ==
1158  BLI_listbase_count(&new_lb_layer));
1159 
1160  /* Update bases etc. for objects. */
1161  layer_collection_objects_sync(view_layer,
1162  layer_resync->layer,
1163  r_lb_new_object_bases,
1164  parent_collection_restrict,
1165  parent_layer_restrict,
1166  parent_local_collections_bits);
1167 }
1168 
1169 #ifndef NDEBUG
1171 {
1172  bool is_valid = true;
1173 
1174  if (layer == NULL) {
1175  layer = view_layer->layer_collections.first;
1176  }
1177 
1178  /* Only check for a collection's objects if its layer is not excluded. */
1179  if ((layer->flag & LAYER_COLLECTION_EXCLUDE) == 0) {
1181  if (cob->ob == NULL) {
1182  continue;
1183  }
1184  if (BLI_ghash_lookup(view_layer->object_bases_hash, cob->ob) == NULL) {
1185  CLOG_FATAL(
1186  &LOG,
1187  "Object '%s' from collection '%s' has no entry in view layer's object bases cache",
1188  cob->ob->id.name + 2,
1189  layer->collection->id.name + 2);
1190  is_valid = false;
1191  break;
1192  }
1193  }
1194  }
1195 
1196  if (is_valid) {
1198  if (!view_layer_objects_base_cache_validate(view_layer, layer_child)) {
1199  is_valid = false;
1200  break;
1201  }
1202  }
1203  }
1204 
1205  return is_valid;
1206 }
1207 #else
1210 {
1211  return true;
1212 }
1213 #endif
1214 
1216 {
1217  LayerCollection *first_layer_collection = view_layer->layer_collections.first;
1218  if (BLI_listbase_count_at_most(&view_layer->layer_collections, 2) > 1 ||
1219  first_layer_collection->collection != scene->master_collection) {
1220  /* In some cases (from older files) we do have a master collection, but no matching layer,
1221  * instead all the children of the master collection have their layer collections in the
1222  * viewlayer's list. This is not a valid situation, add a layer for the master collection and
1223  * add all existing first-level layers as children of that new master layer. */
1224  ListBase layer_collections = view_layer->layer_collections;
1225  BLI_listbase_clear(&view_layer->layer_collections);
1226  LayerCollection *master_layer_collection = layer_collection_add(&view_layer->layer_collections,
1228  master_layer_collection->layer_collections = layer_collections;
1229  }
1230 }
1231 
1233 {
1234  if (no_resync) {
1235  return;
1236  }
1237 
1238  if (!scene->master_collection) {
1239  /* Happens for old files that don't have versioning applied yet. */
1240  return;
1241  }
1242 
1243  if (BLI_listbase_is_empty(&view_layer->layer_collections)) {
1244  /* In some cases (from older files, or when creating a new ViewLayer from
1245  * #BKE_view_layer_add), we do have a master collection, yet no matching layer. Create the
1246  * master one here, so that the rest of the code can work as expected. */
1248  }
1249 
1250 #ifndef NDEBUG
1251  {
1253  "ViewLayer's first level of children layer collections should always have "
1254  "exactly one item");
1255 
1256  LayerCollection *first_layer_collection = view_layer->layer_collections.first;
1257  BLI_assert_msg(first_layer_collection->collection == scene->master_collection,
1258  "ViewLayer's first layer collection should always be the one for the scene's "
1259  "master collection");
1260  }
1261 #endif
1262 
1263  /* Free cache. */
1264  MEM_SAFE_FREE(view_layer->object_bases_array);
1265 
1266  /* Create object to base hash if it does not exist yet. */
1267  if (!view_layer->object_bases_hash) {
1268  view_layer_bases_hash_create(view_layer, false);
1269  }
1270 
1271  /* Clear visible and selectable flags to be reset. */
1272  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
1273  base->flag &= ~g_base_collection_flags;
1274  base->flag_from_collection &= ~g_base_collection_flags;
1275  }
1276 
1277  /* Generate temporary data representing the old layers hierarchy, and how well it matches the
1278  * new collections hierarchy. */
1279  BLI_mempool *layer_resync_mempool = BLI_mempool_create(
1280  sizeof(LayerCollectionResync), 1024, 1024, BLI_MEMPOOL_NOP);
1282  NULL, view_layer->layer_collections.first, layer_resync_mempool);
1283 
1284  /* Generate new layer connections and object bases when collections changed. */
1285  ListBase new_object_bases = {.first = NULL, .last = NULL};
1286  const short parent_exclude = 0, parent_restrict = 0, parent_layer_restrict = 0;
1287  layer_collection_sync(view_layer,
1288  master_layer_resync,
1289  layer_resync_mempool,
1290  &new_object_bases,
1291  parent_exclude,
1292  parent_restrict,
1293  parent_layer_restrict,
1294  ~(0));
1295 
1296  layer_collection_resync_unused_layers_free(view_layer, master_layer_resync);
1297  BLI_mempool_destroy(layer_resync_mempool);
1298  master_layer_resync = NULL;
1299 
1300  /* Any remaining object bases are to be removed. */
1301  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
1302  if (view_layer->basact == base) {
1303  view_layer->basact = NULL;
1304  }
1305 
1306  if (base->object) {
1307  /* Those asserts are commented, since they are too expensive to perform even in debug, as
1308  * this layer resync function currently gets called way too often. */
1309 #if 0
1310  BLI_assert(BLI_findindex(&new_object_bases, base) == -1);
1311  BLI_assert(BLI_findptr(&new_object_bases, base->object, offsetof(Base, object)) == NULL);
1312 #endif
1313  BLI_ghash_remove(view_layer->object_bases_hash, base->object, NULL, NULL);
1314  }
1315  }
1316 
1317  BLI_freelistN(&view_layer->object_bases);
1318  view_layer->object_bases = new_object_bases;
1319 
1321 
1322  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
1323  BKE_base_eval_flags(base);
1324  }
1325 
1326  /* Always set a valid active collection. */
1327  LayerCollection *active = view_layer->active_collection;
1328  if (active && layer_collection_hidden(view_layer, active)) {
1330  }
1331  else if (active == NULL) {
1332  view_layer->active_collection = view_layer->layer_collections.first;
1333  }
1334 }
1335 
1337 {
1338  if (no_resync) {
1339  return;
1340  }
1341 
1342  LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
1343  BKE_layer_collection_sync(scene, view_layer);
1344  }
1345 }
1346 
1347 void BKE_main_collection_sync(const Main *bmain)
1348 {
1349  if (no_resync) {
1350  return;
1351  }
1352 
1353  /* TODO: if a single collection changed, figure out which
1354  * scenes it belongs to and only update those. */
1355 
1356  /* TODO: optimize for file load so only linked collections get checked? */
1357 
1358  for (const Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1360  }
1361 
1363 }
1364 
1366 {
1367  if (no_resync) {
1368  return;
1369  }
1370 
1371  /* On remapping of object or collection pointers free caches. */
1372  /* TODO: try to make this faster */
1373 
1374  for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1375  LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
1376  MEM_SAFE_FREE(view_layer->object_bases_array);
1377 
1378  if (view_layer->object_bases_hash) {
1379  BLI_ghash_free(view_layer->object_bases_hash, NULL, NULL);
1380  view_layer->object_bases_hash = NULL;
1381  }
1382 
1383  /* Directly re-create the mapping here, so that we can also deal with duplicates in
1384  * `view_layer->object_bases` list of bases properly. This is the only place where such
1385  * duplicates should be fixed, and not considered as a critical error. */
1386  view_layer_bases_hash_create(view_layer, true);
1387  }
1388 
1392  }
1393 
1398  }
1399 
1400  BKE_main_collection_sync(bmain);
1401 }
1402 
1405 /* -------------------------------------------------------------------- */
1410 {
1411  if (lc->collection->flag & COLLECTION_HIDE_SELECT) {
1412  return false;
1413  }
1414 
1415  bool changed = false;
1416 
1417  if (!(lc->flag & LAYER_COLLECTION_EXCLUDE)) {
1419  Base *base = BKE_view_layer_base_find(view_layer, cob->ob);
1420 
1421  if (base) {
1422  if (deselect) {
1423  if (base->flag & BASE_SELECTED) {
1424  base->flag &= ~BASE_SELECTED;
1425  changed = true;
1426  }
1427  }
1428  else {
1429  if ((base->flag & BASE_SELECTABLE) && !(base->flag & BASE_SELECTED)) {
1430  base->flag |= BASE_SELECTED;
1431  changed = true;
1432  }
1433  }
1434  }
1435  }
1436  }
1437 
1439  changed |= BKE_layer_collection_objects_select(view_layer, iter, deselect);
1440  }
1441 
1442  return changed;
1443 }
1444 
1446 {
1447  if (lc->collection->flag & COLLECTION_HIDE_SELECT) {
1448  return false;
1449  }
1450 
1451  if (!(lc->flag & LAYER_COLLECTION_EXCLUDE)) {
1453  Base *base = BKE_view_layer_base_find(view_layer, cob->ob);
1454 
1455  if (base && (base->flag & BASE_SELECTED) && (base->flag & BASE_VISIBLE_DEPSGRAPH)) {
1456  return true;
1457  }
1458  }
1459  }
1460 
1462  if (BKE_layer_collection_has_selected_objects(view_layer, iter)) {
1463  return true;
1464  }
1465  }
1466 
1467  return false;
1468 }
1469 
1471  LayerCollection *lc_child)
1472 {
1473  if (lc_parent == lc_child) {
1474  return true;
1475  }
1476 
1477  LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_parent->layer_collections) {
1478  if (BKE_layer_collection_has_layer_collection(lc_iter, lc_child)) {
1479  return true;
1480  }
1481  }
1482  return false;
1483 }
1484 
1487 /* -------------------------------------------------------------------- */
1491 void BKE_base_set_visible(Scene *scene, ViewLayer *view_layer, Base *base, bool extend)
1492 {
1493  if (!extend) {
1494  /* Make only one base visible. */
1495  LISTBASE_FOREACH (Base *, other, &view_layer->object_bases) {
1496  other->flag |= BASE_HIDDEN;
1497  }
1498 
1499  base->flag &= ~BASE_HIDDEN;
1500  }
1501  else {
1502  /* Toggle visibility of one base. */
1503  base->flag ^= BASE_HIDDEN;
1504  }
1505 
1506  BKE_layer_collection_sync(scene, view_layer);
1507 }
1508 
1509 bool BKE_base_is_visible(const View3D *v3d, const Base *base)
1510 {
1511  if ((base->flag & BASE_VISIBLE_DEPSGRAPH) == 0) {
1512  return false;
1513  }
1514 
1515  if (v3d == NULL) {
1516  return base->flag & BASE_VISIBLE_VIEWLAYER;
1517  }
1518 
1519  if ((v3d->localvd) && ((v3d->local_view_uuid & base->local_view_bits) == 0)) {
1520  return false;
1521  }
1522 
1523  if (((1 << (base->object->type)) & v3d->object_type_exclude_viewport) != 0) {
1524  return false;
1525  }
1526 
1527  if (v3d->flag & V3D_LOCAL_COLLECTIONS) {
1528  return (v3d->local_collections_uuid & base->local_collections_bits) != 0;
1529  }
1530 
1531  return base->flag & BASE_VISIBLE_VIEWLAYER;
1532 }
1533 
1534 bool BKE_object_is_visible_in_viewport(const View3D *v3d, const struct Object *ob)
1535 {
1536  BLI_assert(v3d != NULL);
1537 
1538  if (ob->visibility_flag & OB_HIDE_VIEWPORT) {
1539  return false;
1540  }
1541 
1542  if ((v3d->object_type_exclude_viewport & (1 << ob->type)) != 0) {
1543  return false;
1544  }
1545 
1546  if (v3d->localvd && ((v3d->local_view_uuid & ob->base_local_view_bits) == 0)) {
1547  return false;
1548  }
1549 
1550  if ((v3d->flag & V3D_LOCAL_COLLECTIONS) &&
1552  return false;
1553  }
1554 
1555  /* If not using local collection the object may still be in a hidden collection. */
1556  if ((v3d->flag & V3D_LOCAL_COLLECTIONS) == 0) {
1557  return (ob->base_flag & BASE_VISIBLE_VIEWLAYER) != 0;
1558  }
1559 
1560  return true;
1561 }
1562 
1565 /* -------------------------------------------------------------------- */
1570 {
1571  lc->flag |= flag;
1573  layer_collection_flag_set_recursive(lc_iter, flag);
1574  }
1575 }
1576 
1578 {
1579  lc->flag &= ~flag;
1582  }
1583 }
1584 
1586  ViewLayer *view_layer,
1587  LayerCollection *lc,
1588  bool extend)
1589 {
1590  LayerCollection *lc_master = view_layer->layer_collections.first;
1591  bool hide_it = extend && (lc->runtime_flag & LAYER_COLLECTION_VISIBLE_VIEW_LAYER);
1592 
1593  if (!extend) {
1594  /* Hide all collections. */
1595  LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_master->layer_collections) {
1597  }
1598  }
1599 
1600  /* Make all the direct parents visible. */
1601  if (hide_it) {
1602  lc->flag |= LAYER_COLLECTION_HIDE;
1603  }
1604  else {
1605  LayerCollection *lc_parent = lc;
1606  LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_master->layer_collections) {
1607  if (BKE_layer_collection_has_layer_collection(lc_iter, lc)) {
1608  lc_parent = lc_iter;
1609  break;
1610  }
1611  }
1612 
1613  while (lc_parent != lc) {
1614  lc_parent->flag &= ~LAYER_COLLECTION_HIDE;
1615 
1616  LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_parent->layer_collections) {
1617  if (BKE_layer_collection_has_layer_collection(lc_iter, lc)) {
1618  lc_parent = lc_iter;
1619  break;
1620  }
1621  }
1622  }
1623 
1624  /* Make all the children visible, but respect their disable state. */
1626 
1627  BKE_layer_collection_activate(view_layer, lc);
1628  }
1629 
1630  BKE_layer_collection_sync(scene, view_layer);
1631 }
1632 
1634  const int local_collections_uuid)
1635 {
1636  layer_collection->local_collections_bits |= local_collections_uuid;
1637  LISTBASE_FOREACH (LayerCollection *, child, &layer_collection->layer_collections) {
1638  layer_collection_local_visibility_set_recursive(child, local_collections_uuid);
1639  }
1640 }
1641 
1643  const int local_collections_uuid)
1644 {
1645  layer_collection->local_collections_bits &= ~local_collections_uuid;
1646  LISTBASE_FOREACH (LayerCollection *, child, &layer_collection->layer_collections) {
1647  layer_collection_local_visibility_unset_recursive(child, local_collections_uuid);
1648  }
1649 }
1650 
1651 static void layer_collection_local_sync(ViewLayer *view_layer,
1652  LayerCollection *layer_collection,
1653  const unsigned short local_collections_uuid,
1654  bool visible)
1655 {
1656  if ((layer_collection->local_collections_bits & local_collections_uuid) == 0) {
1657  visible = false;
1658  }
1659 
1660  if (visible) {
1661  LISTBASE_FOREACH (CollectionObject *, cob, &layer_collection->collection->gobject) {
1662  if (cob->ob == NULL) {
1663  continue;
1664  }
1665 
1666  Base *base = BKE_view_layer_base_find(view_layer, cob->ob);
1667  base->local_collections_bits |= local_collections_uuid;
1668  }
1669  }
1670 
1671  LISTBASE_FOREACH (LayerCollection *, child, &layer_collection->layer_collections) {
1672  if ((child->flag & LAYER_COLLECTION_EXCLUDE) == 0) {
1673  layer_collection_local_sync(view_layer, child, local_collections_uuid, visible);
1674  }
1675  }
1676 }
1677 
1678 void BKE_layer_collection_local_sync(ViewLayer *view_layer, const View3D *v3d)
1679 {
1680  if (no_resync) {
1681  return;
1682  }
1683 
1684  const unsigned short local_collections_uuid = v3d->local_collections_uuid;
1685 
1686  /* Reset flags and set the bases visible by default. */
1687  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
1688  base->local_collections_bits &= ~local_collections_uuid;
1689  }
1690 
1691  LISTBASE_FOREACH (LayerCollection *, layer_collection, &view_layer->layer_collections) {
1692  layer_collection_local_sync(view_layer, layer_collection, local_collections_uuid, true);
1693  }
1694 }
1695 
1697 {
1698  if (no_resync) {
1699  return;
1700  }
1701 
1702  LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
1703  LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
1704  LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
1705  LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
1706  if (area->spacetype != SPACE_VIEW3D) {
1707  continue;
1708  }
1709  View3D *v3d = area->spacedata.first;
1710  if (v3d->flag & V3D_LOCAL_COLLECTIONS) {
1711  BKE_layer_collection_local_sync(view_layer, v3d);
1712  }
1713  }
1714  }
1715  }
1716  }
1717 }
1718 
1720  const View3D *v3d,
1721  LayerCollection *lc,
1722  bool extend)
1723 {
1724  LayerCollection *lc_master = view_layer->layer_collections.first;
1725  bool hide_it = extend && ((v3d->local_collections_uuid & lc->local_collections_bits) != 0);
1726 
1727  if (!extend) {
1728  /* Hide all collections. */
1729  LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_master->layer_collections) {
1731  }
1732  }
1733 
1734  /* Make all the direct parents visible. */
1735  if (hide_it) {
1737  }
1738  else {
1739  LayerCollection *lc_parent = lc;
1740  LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_master->layer_collections) {
1741  if (BKE_layer_collection_has_layer_collection(lc_iter, lc)) {
1742  lc_parent = lc_iter;
1743  break;
1744  }
1745  }
1746 
1747  while (lc_parent != lc) {
1749 
1750  LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_parent->layer_collections) {
1751  if (BKE_layer_collection_has_layer_collection(lc_iter, lc)) {
1752  lc_parent = lc_iter;
1753  break;
1754  }
1755  }
1756  }
1757 
1758  /* Make all the children visible. */
1760  }
1761 
1762  BKE_layer_collection_local_sync(view_layer, v3d);
1763 }
1764 
1766 {
1767  if ((lc->flag & LAYER_COLLECTION_EXCLUDE) == 0) {
1769  Base *base = BKE_view_layer_base_find(view_layer, cob->ob);
1770  base->flag &= ~BASE_HIDDEN;
1771  }
1772  }
1774  layer_collection_bases_show_recursive(view_layer, lc_iter);
1775  }
1776 }
1777 
1779 {
1780  if ((lc->flag & LAYER_COLLECTION_EXCLUDE) == 0) {
1782  Base *base = BKE_view_layer_base_find(view_layer, cob->ob);
1783  base->flag |= BASE_HIDDEN;
1784  }
1785  }
1787  layer_collection_bases_hide_recursive(view_layer, lc_iter);
1788  }
1789 }
1790 
1792  LayerCollection *lc,
1793  const bool visible,
1794  const bool hierarchy)
1795 {
1796  if (hierarchy) {
1797  if (visible) {
1799  layer_collection_bases_show_recursive(view_layer, lc);
1800  }
1801  else {
1803  layer_collection_bases_hide_recursive(view_layer, lc);
1804  }
1805  }
1806  else {
1807  if (visible) {
1808  lc->flag &= ~LAYER_COLLECTION_HIDE;
1809  }
1810  else {
1811  lc->flag |= LAYER_COLLECTION_HIDE;
1812  }
1813  }
1814 }
1815 
1821  const int flag,
1822  const bool value,
1823  const bool restore_flag)
1824 {
1825  if (flag == LAYER_COLLECTION_EXCLUDE) {
1826  /* For exclude flag, we remember the state the children had before
1827  * excluding and restoring it when enabling the parent collection again. */
1828  if (value) {
1829  if (restore_flag) {
1832  }
1833  else {
1835  }
1836 
1837  lc->flag |= flag;
1838  }
1839  else {
1841  lc->flag &= ~flag;
1842  }
1843  }
1844  }
1845  else {
1846  SET_FLAG_FROM_TEST(lc->flag, value, flag);
1847  }
1848 
1850  layer_collection_flag_recursive_set(nlc, flag, value, true);
1851  }
1852 }
1853 
1854 void BKE_layer_collection_set_flag(LayerCollection *lc, const int flag, const bool value)
1855 {
1856  layer_collection_flag_recursive_set(lc, flag, value, false);
1857 }
1858 
1859 /* ---------------------------------------------------------------------- */
1860 
1862  const Collection *collection)
1863 {
1864  if (lc->collection == collection) {
1865  return lc;
1866  }
1867 
1870  if (found) {
1871  return found;
1872  }
1873  }
1874  return NULL;
1875 }
1876 
1878  const Collection *collection)
1879 {
1880  LISTBASE_FOREACH (LayerCollection *, layer_collection, &view_layer->layer_collections) {
1882  collection);
1883  if (found != NULL) {
1884  return found;
1885  }
1886  }
1887  return NULL;
1888 }
1889 
1891 {
1893 }
1894 
1896 {
1897  LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
1898  Base *base = BKE_view_layer_base_find(view_layer, ob);
1899  if (base) {
1900  return true;
1901  }
1902  }
1903  return false;
1904 }
1905 
1908 /* Iterators */
1909 
1910 /* -------------------------------------------------------------------- */
1915  const View3D *v3d;
1918 
1919 static bool object_bases_iterator_is_valid(const View3D *v3d, Base *base, const int flag)
1920 {
1921  BLI_assert((v3d == NULL) || (v3d->spacetype == SPACE_VIEW3D));
1922 
1923  /* Any flag satisfies the condition. */
1924  if (flag == ~0) {
1925  return (base->flag != 0);
1926  }
1927 
1928  /* Flags may be more than one flag, so we can't check != 0. */
1929  return BASE_VISIBLE(v3d, base) && ((base->flag & flag) == flag);
1930 }
1931 
1932 static void object_bases_iterator_begin(BLI_Iterator *iter, void *data_in_v, const int flag)
1933 {
1934  ObjectsVisibleIteratorData *data_in = data_in_v;
1935  ViewLayer *view_layer = data_in->view_layer;
1936  const View3D *v3d = data_in->v3d;
1937  Base *base = view_layer->object_bases.first;
1938 
1939  /* when there are no objects */
1940  if (base == NULL) {
1941  iter->data = NULL;
1942  iter->valid = false;
1943  return;
1944  }
1945 
1947  iter->data = data;
1948 
1949  data->v3d = v3d;
1950  data->base = base;
1951 
1952  if (object_bases_iterator_is_valid(v3d, base, flag) == false) {
1953  object_bases_iterator_next(iter, flag);
1954  }
1955  else {
1956  iter->current = base;
1957  }
1958 }
1959 
1960 static void object_bases_iterator_next(BLI_Iterator *iter, const int flag)
1961 {
1963  Base *base = data->base->next;
1964 
1965  while (base) {
1966  if (object_bases_iterator_is_valid(data->v3d, base, flag)) {
1967  iter->current = base;
1968  data->base = base;
1969  return;
1970  }
1971  base = base->next;
1972  }
1973 
1974  iter->valid = false;
1975 }
1976 
1978 {
1979  MEM_SAFE_FREE(iter->data);
1980 }
1981 
1982 static void objects_iterator_begin(BLI_Iterator *iter, void *data_in, const int flag)
1983 {
1984  object_bases_iterator_begin(iter, data_in, flag);
1985 
1986  if (iter->valid) {
1987  iter->current = ((Base *)iter->current)->object;
1988  }
1989 }
1990 
1991 static void objects_iterator_next(BLI_Iterator *iter, const int flag)
1992 {
1993  object_bases_iterator_next(iter, flag);
1994 
1995  if (iter->valid) {
1996  iter->current = ((Base *)iter->current)->object;
1997  }
1998 }
1999 
2001 {
2003 }
2004 
2007 /* -------------------------------------------------------------------- */
2013 {
2015 }
2016 
2018 {
2020 }
2021 
2023 {
2024  objects_iterator_end(iter);
2025 }
2026 
2029 /* -------------------------------------------------------------------- */
2034 {
2035  objects_iterator_begin(iter, data_in, 0);
2036 }
2037 
2039 {
2040  objects_iterator_next(iter, 0);
2041 }
2042 
2044 {
2045  objects_iterator_end(iter);
2046 }
2047 
2050 /* -------------------------------------------------------------------- */
2055 {
2057  if (iter->valid) {
2058  if (BKE_object_is_libdata((Object *)iter->current) == false) {
2059  /* First object is valid (selectable and not libdata) -> all good. */
2060  return;
2061  }
2062 
2063  /* Object is selectable but not editable -> search for another one. */
2065  }
2066 }
2067 
2069 {
2070  /* Search while there are objects and the one we have is not editable (editable = not libdata).
2071  */
2072  do {
2074  } while (iter->valid && BKE_object_is_libdata((Object *)iter->current) != false);
2075 }
2076 
2078 {
2079  objects_iterator_end(iter);
2080 }
2081 
2084 /* -------------------------------------------------------------------- */
2089 {
2091 }
2092 
2094 {
2096 }
2097 
2099 {
2101 }
2102 
2105 /* -------------------------------------------------------------------- */
2110 {
2111  object_bases_iterator_begin(iter, data_in, 0);
2112 }
2113 
2115 {
2116  object_bases_iterator_next(iter, 0);
2117 }
2118 
2120 {
2122 }
2123 
2126 /* -------------------------------------------------------------------- */
2131 {
2132  return (base->object->type == data->object_type) &&
2133  (base->object->mode & data->object_mode) != 0;
2134 }
2135 
2137 {
2138  struct ObjectsInModeIteratorData *data = data_in;
2139  Base *base = data->base_active;
2140 
2141  /* In this case the result will always be empty, the caller must check for no mode. */
2142  BLI_assert(data->object_mode != 0);
2143 
2144  /* when there are no objects */
2145  if (base == NULL) {
2146  iter->valid = false;
2147  return;
2148  }
2149  iter->data = data_in;
2150  iter->current = base;
2151 
2152  /* default type is active object type */
2153  if (data->object_type < 0) {
2154  data->object_type = base->object->type;
2155  }
2156 
2157  if (!(base_is_in_mode(data, base) && BKE_base_is_visible(data->v3d, base))) {
2159  }
2160 }
2161 
2163 {
2164  struct ObjectsInModeIteratorData *data = iter->data;
2165  Base *base = iter->current;
2166 
2167  if (base == data->base_active) {
2168  /* first step */
2169  base = data->view_layer->object_bases.first;
2170  if ((base == data->base_active) && BKE_base_is_visible(data->v3d, base)) {
2171  base = base->next;
2172  }
2173  }
2174  else {
2175  base = base->next;
2176  }
2177 
2178  while (base) {
2179  if ((base != data->base_active) && base_is_in_mode(data, base) &&
2180  BKE_base_is_visible(data->v3d, base)) {
2181  iter->current = base;
2182  return;
2183  }
2184  base = base->next;
2185  }
2186  iter->valid = false;
2187 }
2188 
2190 {
2191  /* do nothing */
2192 }
2193 
2196 /* -------------------------------------------------------------------- */
2201 {
2202  /* Apply collection flags. */
2203  base->flag &= ~g_base_collection_flags;
2205 
2206  /* Apply object restrictions. */
2207  const int object_restrict = base->object->visibility_flag;
2208  if (object_restrict & OB_HIDE_VIEWPORT) {
2209  base->flag &= ~BASE_ENABLED_VIEWPORT;
2210  }
2211  if (object_restrict & OB_HIDE_RENDER) {
2212  base->flag &= ~BASE_ENABLED_RENDER;
2213  }
2214  if (object_restrict & OB_HIDE_SELECT) {
2215  base->flag &= ~BASE_SELECTABLE;
2216  }
2217 
2218  /* Apply viewport visibility by default. The dependency graph for render
2219  * can change these again, but for tools we always want the viewport
2220  * visibility to be in sync regardless if depsgraph was evaluated. */
2221  if (!(base->flag & BASE_ENABLED_VIEWPORT) || (base->flag & BASE_HIDDEN)) {
2223  }
2224 
2225  /* Deselect unselectable objects. */
2226  if (!(base->flag & BASE_SELECTABLE)) {
2227  base->flag &= ~BASE_SELECTED;
2228  }
2229 }
2230 
2232  struct Scene *UNUSED(scene),
2234 {
2236 
2237  /* Create array of bases, for fast index-based lookup. */
2238  const int num_object_bases = BLI_listbase_count(&view_layer->object_bases);
2241  num_object_bases, sizeof(Base *), "view_layer->object_bases_array");
2242  int base_index = 0;
2244  view_layer->object_bases_array[base_index++] = base;
2245  }
2246 }
2247 
2249  struct Scene *scene,
2250  int view_layer_index)
2251 {
2252  BLI_assert(view_layer_index >= 0);
2253  ViewLayer *view_layer = BLI_findlink(&scene->view_layers, view_layer_index);
2256 }
2257 
2260 /* -------------------------------------------------------------------- */
2265 {
2266  LISTBASE_FOREACH (LayerCollection *, lc, lb) {
2267  BLO_write_struct(writer, LayerCollection, lc);
2268 
2269  write_layer_collections(writer, &lc->layer_collections);
2270  }
2271 }
2272 
2274 {
2277 
2278  if (view_layer->id_properties) {
2280  }
2281 
2284  }
2285 
2287  BLO_write_struct(writer, FreestyleLineSet, fls);
2288  }
2290  BLO_write_struct(writer, ViewLayerAOV, aov);
2291  }
2293  BLO_write_struct(writer, ViewLayerLightgroup, lightgroup);
2294  }
2296 }
2297 
2298 static void direct_link_layer_collections(BlendDataReader *reader, ListBase *lb, bool master)
2299 {
2300  BLO_read_list(reader, lb);
2301  LISTBASE_FOREACH (LayerCollection *, lc, lb) {
2302 #ifdef USE_COLLECTION_COMPAT_28
2303  BLO_read_data_address(reader, &lc->scene_collection);
2304 #endif
2305 
2306  /* Master collection is not a real data-block. */
2307  if (master) {
2308  BLO_read_data_address(reader, &lc->collection);
2309  }
2310 
2311  direct_link_layer_collections(reader, &lc->layer_collections, false);
2312  }
2313 }
2314 
2316 {
2317  view_layer->stats = NULL;
2320 
2323 
2326 
2329 
2330  BLO_read_list(reader, &view_layer->aovs);
2332 
2335 
2339 }
2340 
2342  Library *lib,
2343  LayerCollection *layer_collection,
2344  bool master)
2345 {
2346  /* Master collection is not a real data-block. */
2347  if (!master) {
2348  BLO_read_id_address(reader, lib, &layer_collection->collection);
2349  }
2350 
2352  LayerCollection *, layer_collection_nested, &layer_collection->layer_collections) {
2353  lib_link_layer_collection(reader, lib, layer_collection_nested, false);
2354  }
2355 }
2356 
2358 {
2360  BLO_read_id_address(reader, lib, &fmc->script);
2361  }
2362 
2364  BLO_read_id_address(reader, lib, &fls->linestyle);
2365  BLO_read_id_address(reader, lib, &fls->group);
2366  }
2367 
2369  /* we only bump the use count for the collection objects */
2370  BLO_read_id_address(reader, lib, &base->object);
2371 
2372  if (base->object == NULL) {
2373  /* Free in case linked object got lost. */
2375  if (view_layer->basact == base) {
2376  view_layer->basact = NULL;
2377  }
2378  }
2379  }
2380 
2382  lib_link_layer_collection(reader, lib, layer_collection, true);
2383  }
2384 
2386 
2388 }
2389 
2392 /* -------------------------------------------------------------------- */
2397 {
2399  if (aov == NULL) {
2400  return;
2401  }
2402 
2403  /* Don't allow dots, it's incompatible with OpenEXR convention to store channels
2404  * as "layer.pass.channel". */
2405  BLI_str_replace_char(aov->name, '.', '_');
2407  &view_layer->aovs, aov, DATA_("AOV"), '_', offsetof(ViewLayerAOV, name), sizeof(aov->name));
2408 }
2409 
2411 {
2412  if (aov != NULL) {
2413  BLI_assert(BLI_findindex(&view_layer->aovs, aov) != -1);
2414  view_layer->active_aov = aov;
2415  }
2416  else {
2418  }
2419 }
2420 
2421 struct ViewLayerAOV *BKE_view_layer_add_aov(struct ViewLayer *view_layer)
2422 {
2423  ViewLayerAOV *aov;
2424  aov = MEM_callocN(sizeof(ViewLayerAOV), __func__);
2425  aov->type = AOV_TYPE_COLOR;
2426  BLI_strncpy(aov->name, DATA_("AOV"), sizeof(aov->name));
2427  BLI_addtail(&view_layer->aovs, aov);
2428  viewlayer_aov_active_set(view_layer, aov);
2429  viewlayer_aov_make_name_unique(view_layer);
2430  return aov;
2431 }
2432 
2434 {
2435  BLI_assert(BLI_findindex(&view_layer->aovs, aov) != -1);
2436  BLI_assert(aov != NULL);
2437  if (view_layer->active_aov == aov) {
2438  if (aov->next) {
2439  viewlayer_aov_active_set(view_layer, aov->next);
2440  }
2441  else {
2442  viewlayer_aov_active_set(view_layer, aov->prev);
2443  }
2444  }
2445  BLI_freelinkN(&view_layer->aovs, aov);
2446 }
2447 
2449 {
2450  viewlayer_aov_active_set(view_layer, aov);
2451 }
2452 
2453 static void bke_view_layer_verify_aov_cb(void *userdata,
2454  Scene *UNUSED(scene),
2455  ViewLayer *UNUSED(view_layer),
2456  const char *name,
2457  int UNUSED(channels),
2458  const char *UNUSED(chanid),
2460 {
2461  GHash *name_count = userdata;
2462  void **value_p;
2463  void *key = BLI_strdup(name);
2464 
2465  if (!BLI_ghash_ensure_p(name_count, key, &value_p)) {
2466  *value_p = POINTER_FROM_INT(1);
2467  }
2468  else {
2469  int value = POINTER_AS_INT(*value_p);
2470  value++;
2471  *value_p = POINTER_FROM_INT(value);
2472  MEM_freeN(key);
2473  }
2474 }
2475 
2477  struct Scene *scene,
2478  struct ViewLayer *view_layer)
2479 {
2480  viewlayer_aov_make_name_unique(view_layer);
2481 
2482  GHash *name_count = BLI_ghash_str_new(__func__);
2484  engine, scene, view_layer, bke_view_layer_verify_aov_cb, name_count);
2485  LISTBASE_FOREACH (ViewLayerAOV *, aov, &view_layer->aovs) {
2486  void **value_p = BLI_ghash_lookup(name_count, aov->name);
2487  int count = POINTER_AS_INT(value_p);
2488  SET_FLAG_FROM_TEST(aov->flag, count > 1, AOV_CONFLICT);
2489  }
2490  BLI_ghash_free(name_count, MEM_freeN, NULL);
2491 }
2492 
2494 {
2495  LISTBASE_FOREACH (ViewLayerAOV *, aov, &view_layer->aovs) {
2496  if ((aov->flag & AOV_CONFLICT) == 0) {
2497  return true;
2498  }
2499  }
2500  return false;
2501 }
2502 
2504 {
2505  LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
2506  if (BLI_findindex(&view_layer->aovs, aov) != -1) {
2507  return view_layer;
2508  }
2509  }
2510  return NULL;
2511 }
2512 
2515 /* -------------------------------------------------------------------- */
2520  ViewLayerLightgroup *lightgroup)
2521 {
2522  /* Don't allow dots, it's incompatible with OpenEXR convention to store channels
2523  * as "layer.pass.channel". */
2524  BLI_str_replace_char(lightgroup->name, '.', '_');
2525  BLI_uniquename(&view_layer->lightgroups,
2526  lightgroup,
2527  DATA_("Lightgroup"),
2528  '_',
2529  offsetof(ViewLayerLightgroup, name),
2530  sizeof(lightgroup->name));
2531 }
2532 
2534 {
2535  if (lightgroup != NULL) {
2536  BLI_assert(BLI_findindex(&view_layer->lightgroups, lightgroup) != -1);
2537  view_layer->active_lightgroup = lightgroup;
2538  }
2539  else {
2540  view_layer->active_lightgroup = NULL;
2541  }
2542 }
2543 
2545  const char *name)
2546 {
2547  ViewLayerLightgroup *lightgroup;
2548  lightgroup = MEM_callocN(sizeof(ViewLayerLightgroup), __func__);
2549  if (name && name[0]) {
2550  BLI_strncpy(lightgroup->name, name, sizeof(lightgroup->name));
2551  }
2552  else {
2553  BLI_strncpy(lightgroup->name, DATA_("Lightgroup"), sizeof(lightgroup->name));
2554  }
2555  BLI_addtail(&view_layer->lightgroups, lightgroup);
2556  viewlayer_lightgroup_active_set(view_layer, lightgroup);
2557  viewlayer_lightgroup_make_name_unique(view_layer, lightgroup);
2558  return lightgroup;
2559 }
2560 
2562 {
2563  BLI_assert(BLI_findindex(&view_layer->lightgroups, lightgroup) != -1);
2564  BLI_assert(lightgroup != NULL);
2565  if (view_layer->active_lightgroup == lightgroup) {
2566  if (lightgroup->next) {
2567  viewlayer_lightgroup_active_set(view_layer, lightgroup->next);
2568  }
2569  else {
2570  viewlayer_lightgroup_active_set(view_layer, lightgroup->prev);
2571  }
2572  }
2573  BLI_freelinkN(&view_layer->lightgroups, lightgroup);
2574 }
2575 
2577 {
2578  viewlayer_lightgroup_active_set(view_layer, lightgroup);
2579 }
2580 
2582  struct ViewLayerLightgroup *lightgroup)
2583 {
2584  LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
2585  if (BLI_findindex(&view_layer->lightgroups, lightgroup) != -1) {
2586  return view_layer;
2587  }
2588  }
2589  return NULL;
2590 }
2591 
2593  ViewLayer *view_layer,
2594  ViewLayerLightgroup *lightgroup,
2595  const char *name)
2596 {
2597  char old_name[64];
2598  BLI_strncpy_utf8(old_name, lightgroup->name, sizeof(old_name));
2599  BLI_strncpy_utf8(lightgroup->name, name, sizeof(lightgroup->name));
2600  viewlayer_lightgroup_make_name_unique(view_layer, lightgroup);
2601 
2602  if (scene != NULL) {
2603  /* Update objects in the scene to refer to the new name instead. */
2605  if (!ID_IS_LINKED(ob) && ob->lightgroup != NULL) {
2606  LightgroupMembership *lgm = ob->lightgroup;
2607  if (STREQ(lgm->name, old_name)) {
2608  BLI_strncpy_utf8(lgm->name, lightgroup->name, sizeof(lgm->name));
2609  }
2610  }
2611  }
2613 
2614  /* Update the scene's world to refer to the new name instead. */
2615  if (scene->world != NULL && !ID_IS_LINKED(scene->world) && scene->world->lightgroup != NULL) {
2617  if (STREQ(lgm->name, old_name)) {
2618  BLI_strncpy_utf8(lgm->name, lightgroup->name, sizeof(lgm->name));
2619  }
2620  }
2621  }
2622 }
2623 
2625 {
2626  if (lgm != NULL) {
2627  BLI_strncpy(name, lgm->name, sizeof(lgm->name));
2628  }
2629  else {
2630  name[0] = '\0';
2631  }
2632 }
2633 
2635 {
2636  if (lgm != NULL) {
2637  return strlen(lgm->name);
2638  }
2639  return 0;
2640 }
2641 
2643 {
2644  if (name[0] != '\0') {
2645  if (*lgm == NULL) {
2646  *lgm = MEM_callocN(sizeof(LightgroupMembership), __func__);
2647  }
2648  BLI_strncpy((*lgm)->name, name, sizeof((*lgm)->name));
2649  }
2650  else {
2651  if (*lgm != NULL) {
2652  MEM_freeN(*lgm);
2653  *lgm = NULL;
2654  }
2655  }
2656 }
2657 
void BKE_animdata_fix_paths_rename_all(struct ID *ref_id, const char *prefix, const char *oldName, const char *newName)
Definition: anim_data.c:1287
#define FOREACH_SCENE_OBJECT_END
void BKE_collection_object_cache_free(struct Collection *collection)
Definition: collection.c:832
#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance)
void BKE_freestyle_config_copy(struct FreestyleConfig *new_config, const struct FreestyleConfig *config, int flag)
void BKE_freestyle_config_init(struct FreestyleConfig *config)
Definition: freestyle.c:27
void BKE_freestyle_config_free(struct FreestyleConfig *config, bool do_id_user)
Definition: freestyle.c:40
struct IDProperty * IDP_CopyProperty_ex(const struct IDProperty *prop, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void IDP_BlendWrite(struct BlendWriter *writer, const struct IDProperty *prop)
#define IDP_BlendDataRead(reader, prop)
Definition: BKE_idprop.h:321
void IDP_FreeProperty_ex(struct IDProperty *prop, bool do_id_user)
Definition: idprop.c:1087
void IDP_BlendReadLib(struct BlendLibReader *reader, struct Library *lib, struct IDProperty *prop)
Definition: idprop.c:1435
@ VIEWLAYER_ADD_NEW
Definition: BKE_layer.h:37
@ VIEWLAYER_ADD_EMPTY
Definition: BKE_layer.h:38
@ VIEWLAYER_ADD_COPY
Definition: BKE_layer.h:39
@ LIB_ID_CREATE_NO_USER_REFCOUNT
Definition: BKE_lib_id.h:126
void id_us_plus(struct ID *id)
Definition: lib_id.c:305
void id_lib_indirect_weak_link(struct ID *id)
Definition: lib_id.c:250
#define CMP_NODE_R_LAYERS
Definition: BKE_node.h:1216
General operations, lookup, etc. for blender objects.
bool BKE_object_is_libdata(const struct Object *ob)
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition: BLI_assert.h:53
unsigned int BLI_ghashutil_ptrhash(const void *key)
GHash * BLI_ghash_str_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
GHash * BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:689
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:734
bool BLI_ghashutil_ptrcmp(const void *a, const void *b)
bool BLI_ghash_remove(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:790
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:863
bool BLI_ghash_ensure_p(GHash *gh, void *key, void ***r_val) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:755
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:269
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
void BLI_freelinkN(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:239
void void void void void BLI_duplicatelist(struct ListBase *dst, const struct ListBase *src) ATTR_NONNULL(1
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
Definition: BLI_listbase.h:354
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
Definition: BLI_listbase.h:273
int BLI_listbase_count_at_most(const struct ListBase *listbase, int count_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:466
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:80
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:100
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_findptr(const struct ListBase *listbase, const void *ptr, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
@ BLI_MEMPOOL_NOP
Definition: BLI_mempool.h:99
BLI_mempool * BLI_mempool_create(unsigned int esize, unsigned int elem_num, unsigned int pchunk, unsigned int flag) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
Definition: BLI_mempool.c:253
void BLI_mempool_destroy(BLI_mempool *pool) ATTR_NONNULL(1)
Definition: BLI_mempool.c:707
void * BLI_mempool_calloc(BLI_mempool *pool) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1)
Definition: BLI_mempool.c:347
void BLI_str_replace_char(char *str, char src, char dst) ATTR_NONNULL()
Definition: string.c:503
#define STRNCPY(dst, src)
Definition: BLI_string.h:483
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:42
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL(1
bool BLI_uniquename(struct ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t name_len)
Definition: string_utils.c:309
unsigned short ushort
Definition: BLI_sys_types.h:68
#define BLI_MUTEX_INITIALIZER
Definition: BLI_threads.h:83
void BLI_mutex_lock(ThreadMutex *mutex)
Definition: threads.cc:373
void BLI_mutex_unlock(ThreadMutex *mutex)
Definition: threads.cc:378
pthread_mutex_t ThreadMutex
Definition: BLI_threads.h:82
#define POINTER_FROM_INT(i)
#define UNUSED(x)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define POINTER_AS_INT(i)
#define ELEM(...)
#define STREQ(a, b)
#define BLO_read_data_address(reader, ptr_p)
#define BLO_write_struct(writer, struct_name, data_ptr)
void BLO_read_list(BlendDataReader *reader, struct ListBase *list)
Definition: readfile.c:5172
#define BLO_read_id_address(reader, lib, id_ptr_p)
#define BLO_write_struct_list(writer, struct_name, list_ptr)
#define DATA_(msgid)
#define CLOG_INFO(clg_ref, level,...)
Definition: CLG_log.h:187
#define CLOG_FATAL(clg_ref,...)
Definition: CLG_log.h:191
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
void DEG_debug_print_eval(struct Depsgraph *depsgraph, const char *function_name, const char *object_name, const void *object_address)
void DEG_id_tag_update_ex(struct Main *bmain, struct ID *id, int flag)
void DEG_id_tag_update(struct ID *id, int flag)
ID and Library types, which are fundamental for sdna.
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:834
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:566
Object groups, one object can be in many groups at once.
@ COLLECTION_HIDE_RENDER
@ COLLECTION_HIDE_SELECT
@ COLLECTION_IS_MASTER
@ COLLECTION_HIDE_VIEWPORT
@ VIEW_LAYER_CRYPTOMATTE_ACCURATE
@ LAYER_COLLECTION_HIDE
@ LAYER_COLLECTION_EXCLUDE
@ LAYER_COLLECTION_INDIRECT_ONLY
@ LAYER_COLLECTION_PREVIOUSLY_EXCLUDED
@ LAYER_COLLECTION_HOLDOUT
@ BASE_HIDDEN
@ BASE_INDIRECT_ONLY
@ BASE_SELECTABLE
@ BASE_ENABLED_RENDER
@ BASE_HOLDOUT
@ BASE_VISIBLE_VIEWLAYER
@ BASE_VISIBLE_DEPSGRAPH
@ BASE_ENABLED_VIEWPORT
@ BASE_SELECTED
@ AOV_TYPE_COLOR
@ VIEW_LAYER_FREESTYLE
@ VIEW_LAYER_RENDER
@ LAYER_COLLECTION_VISIBLE_VIEW_LAYER
@ LAYER_COLLECTION_HIDE_VIEWPORT
@ LAYER_COLLECTION_HAS_OBJECTS
@ AOV_CONFLICT
#define NODE_MAXSTR
eNodeSocketDatatype
Object is a sort of wrapper for general info.
@ OB_HIDE_RENDER
@ OB_HIDE_SELECT
@ OB_HIDE_VIEWPORT
@ OB_CAMERA
#define SCE_LAY_FLAG_DEFAULT
@ SCE_PASS_COMBINED
#define BASE_VISIBLE(v3d, base)
@ SPACE_VIEW3D
#define V3D_LOCAL_COLLECTIONS
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a producing a negative Combine Generate a color from its and blue channels(Deprecated)") DefNode(ShaderNode
OperationNode * node
Scene scene
bool is_valid
const Depsgraph * depsgraph
DRWShaderLibrary * lib
void RE_engine_update_render_passes(struct RenderEngine *engine, struct Scene *scene, struct ViewLayer *view_layer, update_render_passes_cb_t callback, void *callback_data)
Definition: engine.c:1150
int count
Object * BKE_view_layer_camera_find(ViewLayer *view_layer)
Definition: layer.c:311
void BKE_view_layer_bases_in_mode_iterator_begin(BLI_Iterator *iter, void *data_in)
Definition: layer.c:2136
void BKE_view_layer_bases_in_mode_iterator_next(BLI_Iterator *iter)
Definition: layer.c:2162
void BKE_view_layer_rename_lightgroup(Scene *scene, ViewLayer *view_layer, ViewLayerLightgroup *lightgroup, const char *name)
Definition: layer.c:2592
static LayerCollectionResync * layer_collection_resync_create_recurse(LayerCollectionResync *parent_layer_resync, LayerCollection *layer, BLI_mempool *mempool)
Definition: layer.c:802
static void layer_collection_bases_hide_recursive(ViewLayer *view_layer, LayerCollection *lc)
Definition: layer.c:1778
static void layer_aov_copy_data(ViewLayer *view_layer_dst, const ViewLayer *view_layer_src, ListBase *aovs_dst, const ListBase *aovs_src)
Definition: layer.c:411
bool BKE_view_layer_has_collection(const ViewLayer *view_layer, const Collection *collection)
Definition: layer.c:1890
void BKE_view_layer_blend_read_data(BlendDataReader *reader, ViewLayer *view_layer)
Definition: layer.c:2315
void BKE_lightgroup_membership_set(struct LightgroupMembership **lgm, const char *name)
Definition: layer.c:2642
static bool layer_collection_hidden(ViewLayer *view_layer, LayerCollection *lc)
Definition: layer.c:605
struct LayerObjectBaseIteratorData LayerObjectBaseIteratorData
void BKE_view_layer_set_active_lightgroup(ViewLayer *view_layer, ViewLayerLightgroup *lightgroup)
Definition: layer.c:2576
static void layer_collection_local_visibility_unset_recursive(LayerCollection *layer_collection, const int local_collections_uuid)
Definition: layer.c:1642
static void layer_collection_free(ViewLayer *view_layer, LayerCollection *lc)
Definition: layer.c:81
static LayerCollection * find_layer_collection_by_scene_collection(LayerCollection *lc, const Collection *collection)
Definition: layer.c:1861
static void layer_collection_flag_set_recursive(LayerCollection *lc, const int flag)
Definition: layer.c:1569
bool BKE_view_layer_has_valid_aov(ViewLayer *view_layer)
Definition: layer.c:2493
static void object_bases_iterator_end(BLI_Iterator *iter)
Definition: layer.c:1977
void BKE_view_layer_bases_in_mode_iterator_end(BLI_Iterator *UNUSED(iter))
Definition: layer.c:2189
bool BKE_object_is_visible_in_viewport(const View3D *v3d, const struct Object *ob)
Definition: layer.c:1534
void BKE_view_layer_visible_bases_iterator_begin(BLI_Iterator *iter, void *data_in)
Definition: layer.c:2109
static void layer_collection_exclude_all(LayerCollection *layer_collection)
Definition: layer.c:176
void BKE_main_collection_sync_remap(const Main *bmain)
Definition: layer.c:1365
static void object_bases_iterator_begin(BLI_Iterator *iter, void *data_in_v, const int flag)
Definition: layer.c:1932
void BKE_layer_collection_set_visible(ViewLayer *view_layer, LayerCollection *lc, const bool visible, const bool hierarchy)
Definition: layer.c:1791
LayerCollection * BKE_layer_collection_from_index(ViewLayer *view_layer, const int index)
Definition: layer.c:630
static void viewlayer_lightgroup_active_set(ViewLayer *view_layer, ViewLayerLightgroup *lightgroup)
Definition: layer.c:2533
ViewLayer * BKE_view_layer_find_with_aov(struct Scene *scene, struct ViewLayerAOV *aov)
Definition: layer.c:2503
void BKE_view_layer_selected_editable_objects_iterator_begin(BLI_Iterator *iter, void *data_in)
Definition: layer.c:2054
static ViewLayer * view_layer_add(const char *name)
Definition: layer.c:154
static int index_from_collection(ListBase *lb, const LayerCollection *lc, int *i)
Definition: layer.c:696
void BKE_view_layer_set_active_aov(ViewLayer *view_layer, ViewLayerAOV *aov)
Definition: layer.c:2448
static void viewlayer_lightgroup_make_name_unique(ViewLayer *view_layer, ViewLayerLightgroup *lightgroup)
Definition: layer.c:2519
void BKE_view_layer_remove_aov(ViewLayer *view_layer, ViewLayerAOV *aov)
Definition: layer.c:2433
struct ViewLayerLightgroup * BKE_view_layer_add_lightgroup(struct ViewLayer *view_layer, const char *name)
Definition: layer.c:2544
void BKE_view_layer_remove_lightgroup(ViewLayer *view_layer, ViewLayerLightgroup *lightgroup)
Definition: layer.c:2561
void BKE_view_layer_selected_editable_objects_iterator_end(BLI_Iterator *iter)
Definition: layer.c:2077
static void viewlayer_aov_active_set(ViewLayer *view_layer, ViewLayerAOV *aov)
Definition: layer.c:2410
LayerCollection * BKE_layer_collection_activate_parent(ViewLayer *view_layer, LayerCollection *lc)
Definition: layer.c:651
void BKE_view_layer_selected_objects_iterator_begin(BLI_Iterator *iter, void *data_in)
Definition: layer.c:2012
static void layer_collection_flag_recursive_set(LayerCollection *lc, const int flag, const bool value, const bool restore_flag)
Definition: layer.c:1820
static bool find_scene_collection_in_scene_collections(ListBase *lb, const LayerCollection *lc)
Definition: layer.c:298
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
Definition: layer.c:379
void BKE_view_layer_visible_bases_iterator_end(BLI_Iterator *iter)
Definition: layer.c:2119
static void layer_lightgroup_copy_data(ViewLayer *view_layer_dst, const ViewLayer *view_layer_src, ListBase *lightgroups_dst, const ListBase *lightgroups_src)
Definition: layer.c:434
bool BKE_layer_collection_has_selected_objects(ViewLayer *view_layer, LayerCollection *lc)
Definition: layer.c:1445
static void layer_eval_view_layer(struct Depsgraph *depsgraph, struct Scene *UNUSED(scene), ViewLayer *view_layer)
Definition: layer.c:2231
void BKE_view_layer_selected_objects_iterator_end(BLI_Iterator *iter)
Definition: layer.c:2022
void BKE_layer_collection_set_flag(LayerCollection *lc, const int flag, const bool value)
Definition: layer.c:1854
void BKE_view_layer_selected_editable_objects_iterator_next(BLI_Iterator *iter)
Definition: layer.c:2068
void BKE_view_layer_blend_read_lib(BlendLibReader *reader, Library *lib, ViewLayer *view_layer)
Definition: layer.c:2357
static void layer_collection_objects_sync(ViewLayer *view_layer, LayerCollection *layer, ListBase *r_lb_new_object_bases, const short collection_restrict, const short layer_restrict, const ushort local_collections_bits)
Definition: layer.c:959
ViewLayer * BKE_view_layer_default_view(const Scene *scene)
Definition: layer.c:113
static int collection_count(const ListBase *lb)
Definition: layer.c:679
void BKE_view_layer_free_ex(ViewLayer *view_layer, const bool do_id_user)
Definition: layer.c:244
static void direct_link_layer_collections(BlendDataReader *reader, ListBase *lb, bool master)
Definition: layer.c:2298
static LayerCollection * layer_collection_add(ListBase *lb_parent, Collection *collection)
Definition: layer.c:71
void BKE_layer_collection_resync_allow(void)
Definition: layer.c:766
ViewLayer * BKE_view_layer_add(Scene *scene, const char *name, ViewLayer *view_layer_source, const int type)
Definition: layer.c:185
static const short g_base_collection_flags
Definition: layer.c:59
static void layer_collection_local_visibility_set_recursive(LayerCollection *layer_collection, const int local_collections_uuid)
Definition: layer.c:1633
static bool no_resync
Definition: layer.c:759
static void lib_link_layer_collection(BlendLibReader *reader, Library *lib, LayerCollection *layer_collection, bool master)
Definition: layer.c:2341
LayerCollection * BKE_layer_collection_get_active(ViewLayer *view_layer)
Definition: layer.c:636
void BKE_view_layer_selected_bases_iterator_next(BLI_Iterator *iter)
Definition: layer.c:2093
static void write_layer_collections(BlendWriter *writer, ListBase *lb)
Definition: layer.c:2264
ViewLayer * BKE_view_layer_default_render(const Scene *scene)
Definition: layer.c:125
static void layer_collection_sync(ViewLayer *view_layer, LayerCollectionResync *layer_resync, BLI_mempool *layer_resync_mempool, ListBase *r_lb_new_object_bases, const short parent_layer_flag, const short parent_collection_restrict, const short parent_layer_restrict, const ushort parent_local_collections_bits)
Definition: layer.c:1026
bool BKE_base_is_visible(const View3D *v3d, const Base *base)
Definition: layer.c:1509
void BKE_view_layer_verify_aov(struct RenderEngine *engine, struct Scene *scene, struct ViewLayer *view_layer)
Definition: layer.c:2476
void BKE_scene_collection_sync(const Scene *scene)
Definition: layer.c:1336
void BKE_view_layer_visible_objects_iterator_end(BLI_Iterator *iter)
Definition: layer.c:2043
ViewLayer * BKE_view_layer_find_with_lightgroup(struct Scene *scene, struct ViewLayerLightgroup *lightgroup)
Definition: layer.c:2581
void BKE_view_layer_selected_bases_iterator_end(BLI_Iterator *iter)
Definition: layer.c:2098
void BKE_view_layer_rename(Main *bmain, Scene *scene, ViewLayer *view_layer, const char *newname)
Definition: layer.c:534
void BKE_base_set_visible(Scene *scene, ViewLayer *view_layer, Base *base, bool extend)
Definition: layer.c:1491
static void objects_iterator_next(BLI_Iterator *iter, const int flag)
Definition: layer.c:1991
void BKE_layer_collection_local_sync(ViewLayer *view_layer, const View3D *v3d)
Definition: layer.c:1678
int BKE_layer_collection_count(const ViewLayer *view_layer)
Definition: layer.c:688
static void layer_collection_flag_unset_recursive(LayerCollection *lc, const int flag)
Definition: layer.c:1577
bool BKE_layer_collection_has_layer_collection(LayerCollection *lc_parent, LayerCollection *lc_child)
Definition: layer.c:1470
void BKE_layer_collection_isolate_global(Scene *scene, ViewLayer *view_layer, LayerCollection *lc, bool extend)
Definition: layer.c:1585
static void bke_view_layer_verify_aov_cb(void *userdata, Scene *UNUSED(scene), ViewLayer *UNUSED(view_layer), const char *name, int UNUSED(channels), const char *UNUSED(chanid), eNodeSocketDatatype UNUSED(type))
Definition: layer.c:2453
static LayerCollection * collection_from_index(ListBase *lb, const int number, int *i)
Definition: layer.c:583
static void layer_collection_bases_show_recursive(ViewLayer *view_layer, LayerCollection *lc)
Definition: layer.c:1765
void BKE_layer_eval_view_layer_indexed(struct Depsgraph *depsgraph, struct Scene *scene, int view_layer_index)
Definition: layer.c:2248
static void objects_iterator_end(BLI_Iterator *iter)
Definition: layer.c:2000
ViewLayer * BKE_view_layer_find(const Scene *scene, const char *layer_name)
Definition: layer.c:137
bool BKE_scene_has_object(Scene *scene, Object *ob)
Definition: layer.c:1895
void BKE_layer_collection_isolate_local(ViewLayer *view_layer, const View3D *v3d, LayerCollection *lc, bool extend)
Definition: layer.c:1719
void BKE_layer_collection_resync_forbid(void)
Definition: layer.c:761
void BKE_main_collection_sync(const Main *bmain)
Definition: layer.c:1347
void BKE_view_layer_free(ViewLayer *view_layer)
Definition: layer.c:239
static void layer_collection_resync_unused_layers_free(ViewLayer *view_layer, LayerCollectionResync *layer_resync)
Definition: layer.c:931
static void viewlayer_aov_make_name_unique(ViewLayer *view_layer)
Definition: layer.c:2396
void BKE_lightgroup_membership_get(struct LightgroupMembership *lgm, char *name)
Definition: layer.c:2624
void BKE_layer_collection_doversion_2_80(const Scene *scene, ViewLayer *view_layer)
Definition: layer.c:1215
void BKE_view_layer_visible_objects_iterator_begin(BLI_Iterator *iter, void *data_in)
Definition: layer.c:2033
static Base * object_base_new(Object *ob)
Definition: layer.c:94
static bool object_bases_iterator_is_valid(const View3D *v3d, Base *base, const int flag)
Definition: layer.c:1919
static LayerCollectionResync * layer_collection_resync_find(LayerCollectionResync *layer_resync, Collection *child_collection)
Definition: layer.c:854
void BKE_view_layer_selected_objects_tag(ViewLayer *view_layer, const int tag)
Definition: layer.c:286
ViewLayer * BKE_view_layer_find_from_collection(const Scene *scene, LayerCollection *lc)
Definition: layer.c:322
static void layer_collection_local_sync(ViewLayer *view_layer, LayerCollection *layer_collection, const unsigned short local_collections_uuid, bool visible)
Definition: layer.c:1651
void BKE_view_layer_base_select_and_set_active(struct ViewLayer *view_layer, Base *selbase)
Definition: layer.c:397
static CLG_LogRef LOG
Definition: layer.c:56
static void layer_collections_copy_data(ViewLayer *view_layer_dst, const ViewLayer *view_layer_src, ListBase *layer_collections_dst, const ListBase *layer_collections_src)
Definition: layer.c:457
void BKE_view_layer_base_deselect_all(ViewLayer *view_layer)
Definition: layer.c:388
void BKE_view_layer_selected_bases_iterator_begin(BLI_Iterator *iter, void *data_in)
Definition: layer.c:2088
LayerCollection * BKE_layer_collection_first_from_scene_collection(const ViewLayer *view_layer, const Collection *collection)
Definition: layer.c:1877
static void object_bases_iterator_next(BLI_Iterator *iter, const int flag)
Definition: layer.c:1960
static void objects_iterator_begin(BLI_Iterator *iter, void *data_in, const int flag)
Definition: layer.c:1982
bool BKE_layer_collection_objects_select(ViewLayer *view_layer, LayerCollection *lc, bool deselect)
Definition: layer.c:1409
void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer)
Definition: layer.c:1232
static bool view_layer_objects_base_cache_validate(ViewLayer *view_layer, LayerCollection *layer)
Definition: layer.c:1170
static void view_layer_bases_hash_create(ViewLayer *view_layer, const bool do_base_duplicates_fix)
Definition: layer.c:335
int BKE_layer_collection_findindex(ViewLayer *view_layer, const LayerCollection *lc)
Definition: layer.c:715
ViewLayer * BKE_view_layer_context_active_PLACEHOLDER(const Scene *scene)
Definition: layer.c:148
bool BKE_layer_collection_activate(ViewLayer *view_layer, LayerCollection *lc)
Definition: layer.c:641
struct LayerCollectionResync LayerCollectionResync
void BKE_base_eval_flags(Base *base)
Definition: layer.c:2200
void BKE_view_layer_copy_data(Scene *scene_dst, const Scene *UNUSED(scene_src), ViewLayer *view_layer_dst, const ViewLayer *view_layer_src, const int flag)
Definition: layer.c:482
void BKE_view_layer_visible_bases_iterator_next(BLI_Iterator *iter)
Definition: layer.c:2114
void BKE_layer_collection_local_sync_all(const Main *bmain)
Definition: layer.c:1696
struct ViewLayerAOV * BKE_view_layer_add_aov(struct ViewLayer *view_layer)
Definition: layer.c:2421
void BKE_view_layer_blend_write(BlendWriter *writer, ViewLayer *view_layer)
Definition: layer.c:2273
int BKE_lightgroup_membership_length(struct LightgroupMembership *lgm)
Definition: layer.c:2634
void BKE_view_layer_visible_objects_iterator_next(BLI_Iterator *iter)
Definition: layer.c:2038
static bool base_is_in_mode(struct ObjectsInModeIteratorData *data, Base *base)
Definition: layer.c:2130
void BKE_view_layer_selected_objects_iterator_next(BLI_Iterator *iter)
Definition: layer.c:2017
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
Definition: mallocn.c:34
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:28
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
static void area(int d1, int d2, int e1, int e2, float weights[2])
bool active
all scheduled work for the GPU.
#define hash
Definition: noise.c:153
void * current
Definition: BLI_iterator.h:14
short flag_from_collection
struct Base * next
short flag
struct Object * object
unsigned short local_view_bits
unsigned short local_collections_bits
struct Collection * collection
Definition: DNA_ID.h:368
void * next
Definition: DNA_ID.h:369
char name[66]
Definition: DNA_ID.h:378
LayerCollection * layer
Definition: layer.c:779
ListBase children_layer_resync
Definition: layer.c:785
struct LayerCollectionResync * prev
Definition: layer.c:772
struct LayerCollectionResync * next
Definition: layer.c:772
bool is_valid_as_child
Definition: layer.c:794
bool is_valid_as_parent
Definition: layer.c:791
Collection * collection
Definition: layer.c:780
struct LayerCollectionResync * queue_next
Definition: layer.c:776
struct LayerCollectionResync * parent_layer_resync
Definition: layer.c:784
struct LayerCollection * next
ListBase layer_collections
unsigned short local_collections_bits
struct Collection * collection
const View3D * v3d
Definition: layer.c:1915
void * last
Definition: DNA_listBase.h:31
void * first
Definition: DNA_listBase.h:31
Definition: BKE_main.h:121
ListBase scenes
Definition: BKE_main.h:168
ListBase wm
Definition: BKE_main.h:197
ListBase screens
Definition: BKE_main.h:183
ListBase collections
Definition: BKE_main.h:189
unsigned short local_collections_bits
short base_flag
Object_Runtime runtime
short visibility_flag
unsigned short base_local_view_bits
struct ViewLayer * view_layer
Definition: BKE_layer.h:286
const struct View3D * v3d
Definition: BKE_layer.h:268
struct ViewLayer * view_layer
Definition: BKE_layer.h:267
struct bNodeTree * nodetree
struct Collection * master_collection
ListBase view_layers
struct World * world
unsigned short local_view_uuid
struct View3D * localvd
char spacetype
unsigned short local_collections_uuid
int object_type_exclude_viewport
struct ViewLayerAOV * prev
struct ViewLayerAOV * next
struct ViewLayerLightgroup * prev
struct ViewLayerLightgroup * next
ListBase drawdata
struct FreestyleConfig freestyle_config
short cryptomatte_flag
ListBase lightgroups
struct IDProperty * id_properties
short cryptomatte_levels
ViewLayerLightgroup * active_lightgroup
ViewLayerAOV * active_aov
ListBase layer_collections
LayerCollection * active_collection
struct GHash * object_bases_hash
struct Base ** object_bases_array
struct Base * basact
struct SceneStats * stats
ListBase object_bases
float pass_alpha_threshold
ListBase aovs
struct Material * mat_override
char name[64]
struct LightgroupMembership * lightgroup
ListBase nodes