Blender V5.0
BKE_collection.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
11#include "BLI_ghash.h"
12#include "BLI_iterator.h"
13#include "BLI_sys_types.h"
14
15#include "DNA_listBase.h"
16#include "DNA_userdef_enums.h"
17
18/* Structs */
19
20struct BLI_Iterator;
21struct Base;
22struct BlendDataReader;
23struct BlendWriter;
24struct Collection;
25struct ID;
26struct CollectionChild;
27struct CollectionExport;
28struct GHash;
29struct Main;
30struct Object;
31struct Scene;
32struct ViewLayer;
33
35enum {
49};
50
51namespace blender::bke {
52
72
73} // namespace blender::bke
74
79
80/* Collections */
81
87 Collection *collection_parent,
88 const char *name_custom);
96 Scene *scene,
97 const Object *ob_src,
98 Collection *collection_dst);
106 Scene *scene,
107 Collection *collection_src,
108 Collection *collection_dst);
112void BKE_collection_free_data(Collection *collection);
113
117CollectionExport *BKE_collection_exporter_add(Collection *collection, char *idname, char *label);
118
123
127bool BKE_collection_exporter_move(Collection *collection, const int from, const int to);
128
134 const char *newname);
135
140
145bool BKE_collection_delete(Main *bmain, Collection *collection, bool hierarchy);
146
167 Collection *parent,
168 CollectionChild *child_old,
169 Collection *collection,
170 eDupli_ID_Flags duplicate_flags,
171 /*eLibIDDuplicateFlags*/ uint duplicate_options);
172
173/* Master Collection for Scene */
174
175#define BKE_SCENE_COLLECTION_NAME "Scene Collection"
177
184
185/* Collection Objects */
186
187bool BKE_collection_has_object(Collection *collection, const Object *ob);
195 Object *object_eval);
197 Scene *scene,
198 Collection *collection,
199 Object *ob);
200
202
203bool BKE_collection_is_empty(const Collection *collection);
204
209bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob);
210
218 const ViewLayer *view_layer,
219 Collection *collection,
220 Object *ob);
221
227bool BKE_collection_object_add_notest(Main *bmain, Collection *collection, Object *ob);
234void BKE_collection_object_add_from(Main *bmain, Scene *scene, Object *ob_src, Object *ob_dst);
238bool BKE_collection_object_remove(Main *bmain, Collection *collection, Object *ob, bool free_us);
243 Collection *collection,
244 Object *ob_old,
245 Object *ob_new);
246
253 Main *bmain, Scene *scene, Collection *collection_dst, Collection *collection_src, Object *ob);
254
258bool BKE_scene_collections_object_remove(Main *bmain, Scene *scene, Object *ob, bool free_us);
259
268
282 Collection *parent_collection,
283 Collection *child_collection);
284
285/* Dependencies. */
286
287bool BKE_collection_is_in_scene(Collection *collection);
289bool BKE_collection_object_cyclic_check(Main *bmain, Object *object, Collection *collection);
290
291/* Object list cache. */
292
304void BKE_collection_object_cache_free(const Main *bmain,
305 Collection *collection,
306 const int id_create_flag);
312
314 ViewLayer *view_layer,
315 Collection *collection);
316
317/* Editing. */
318
327 uint64_t session_uid,
328 Scene **r_scene = nullptr);
329
334 char r_name[/*MAX_ID_NAME - 2*/ 256]);
338const char *BKE_collection_ui_name_get(Collection *collection);
343bool BKE_collection_objects_select(const Scene *scene,
344 ViewLayer *view_layer,
345 Collection *collection,
346 bool deselect);
347
348/* Collection children */
349
350bool BKE_collection_child_add(Main *bmain, Collection *parent, Collection *child);
351
352bool BKE_collection_child_add_no_sync(Main *bmain, Collection *parent, Collection *child);
353
354bool BKE_collection_child_remove(Main *bmain, Collection *parent, Collection *child);
355
356bool BKE_collection_move(Main *bmain,
357 Collection *to_parent,
358 Collection *from_parent,
359 Collection *relative,
360 bool relative_after,
361 Collection *collection);
362
372bool BKE_collection_cycle_find(Collection *new_ancestor, Collection *collection);
379bool BKE_collection_cycles_fix(Main *bmain, Collection *collection);
380
381bool BKE_collection_has_collection(const Collection *parent, const Collection *collection);
382
387 Collection *collection);
398
403bool BKE_collection_validate(Collection *collection);
404
405/* .blend file I/O */
406
414
415/* Iteration callbacks. */
416
417using BKE_scene_objects_Cb = void (*)(Object *ob, void *data);
418using BKE_scene_collections_Cb = void (*)(Collection *ob, void *data);
419
420/* Iteration over objects in collection. */
421
422#define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN(_collection, _object, _mode) \
423 { \
424 int _base_flag = (_mode == DAG_EVAL_VIEWPORT) ? BASE_ENABLED_VIEWPORT : BASE_ENABLED_RENDER; \
425 int _object_visibility_flag = (_mode == DAG_EVAL_VIEWPORT) ? OB_HIDE_VIEWPORT : \
426 OB_HIDE_RENDER; \
427 int _base_id = 0; \
428 for (Base *_base = static_cast<Base *>(BKE_collection_object_cache_get(_collection).first); \
429 _base; \
430 _base = _base->next, _base_id++) \
431 { \
432 Object *_object = _base->object; \
433 if ((_base->flag & _base_flag) && \
434 (_object->visibility_flag & _object_visibility_flag) == 0) {
435
436#define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_END \
437 } \
438 } \
439 } \
440 ((void)0)
441
442#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object) \
443 for (Base *_base = static_cast<Base *>(BKE_collection_object_cache_get(_collection).first); \
444 _base; \
445 _base = _base->next) \
446 { \
447 Object *_object = _base->object; \
448 BLI_assert(_object != NULL);
449
450#define FOREACH_COLLECTION_OBJECT_RECURSIVE_END \
451 } \
452 ((void)0)
453
454/* Iteration over collections in scene. */
455
460void BKE_scene_collections_iterator_begin(BLI_Iterator *iter, void *data_in);
463
464void BKE_scene_objects_iterator_begin(BLI_Iterator *iter, void *data_in);
467
478
479void BKE_scene_objects_iterator_begin_ex(BLI_Iterator *iter, void *data_in);
482
490GSet *BKE_scene_objects_as_gset(Scene *scene, GSet *objects_gset);
491
492#define FOREACH_SCENE_COLLECTION_BEGIN(scene, _instance) \
493 ITER_BEGIN (BKE_scene_collections_iterator_begin, \
494 BKE_scene_collections_iterator_next, \
495 BKE_scene_collections_iterator_end, \
496 scene, \
497 Collection *, \
498 _instance)
499
500#define FOREACH_SCENE_COLLECTION_END ITER_END
501
502#define FOREACH_COLLECTION_BEGIN(_bmain, _scene, Type, _instance) \
503 { \
504 Type _instance; \
505 Collection *_instance_next; \
506 bool is_scene_collection = (_scene) != NULL; \
507\
508 if (_scene) { \
509 _instance_next = (_scene)->master_collection; \
510 } \
511 else { \
512 _instance_next = static_cast<Collection *>((_bmain)->collections.first); \
513 } \
514\
515 while ((_instance = _instance_next)) { \
516 if (is_scene_collection) { \
517 _instance_next = static_cast<Collection *>((_bmain)->collections.first); \
518 is_scene_collection = false; \
519 } \
520 else { \
521 _instance_next = static_cast<Collection *>(_instance->id.next); \
522 }
523
524#define FOREACH_COLLECTION_END \
525 } \
526 } \
527 ((void)0)
528
529#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance) \
530 ITER_BEGIN (BKE_scene_objects_iterator_begin, \
531 BKE_scene_objects_iterator_next, \
532 BKE_scene_objects_iterator_end, \
533 scene, \
534 Object *, \
535 _instance)
536
537#define FOREACH_SCENE_OBJECT_END ITER_END
bool BKE_collection_object_remove(Main *bmain, Collection *collection, Object *ob, bool free_us)
bool BKE_collection_has_object_recursive_instanced(Collection *collection, Object *ob)
void BKE_scene_objects_iterator_begin_ex(BLI_Iterator *iter, void *data_in)
void BKE_scene_objects_iterator_next_ex(BLI_Iterator *iter)
Collection * BKE_collection_master_add(Scene *scene)
void BKE_collection_exporter_remove(Collection *collection, CollectionExport *data)
void BKE_collection_object_cache_free(const Main *bmain, Collection *collection, const int id_create_flag)
bool BKE_collection_has_object_recursive(Collection *collection, Object *ob)
CollectionChild * BKE_collection_child_find(Collection *parent, Collection *collection)
void(*)(Collection *ob, void *data) BKE_scene_collections_Cb
void BKE_collection_add_from_collection(Main *bmain, Scene *scene, Collection *collection_src, Collection *collection_dst)
const char * BKE_collection_ui_name_get(Collection *collection)
void BKE_collection_exporter_free_data(CollectionExport *data)
bool BKE_scene_collections_object_remove(Main *bmain, Scene *scene, Object *ob, bool free_us)
bool BKE_collection_has_object_recursive_instanced_orig_id(Collection *collection_eval, Object *object_eval)
void BKE_collection_blend_write_nolib(BlendWriter *writer, Collection *collection)
bool BKE_collection_child_remove(Main *bmain, Collection *parent, Collection *child)
bool BKE_collection_viewlayer_object_add(Main *bmain, const ViewLayer *view_layer, Collection *collection, Object *ob)
void BKE_scene_collections_iterator_next(BLI_Iterator *iter)
Collection * BKE_collection_add(Main *bmain, Collection *collection_parent, const char *name_custom)
bool BKE_collection_has_object(Collection *collection, const Object *ob)
ListBase BKE_collection_object_cache_instanced_get(Collection *collection)
void BKE_collections_object_remove_invalids(Main *bmain)
Base * BKE_collection_or_layer_objects(const Scene *scene, ViewLayer *view_layer, Collection *collection)
void BKE_scene_objects_iterator_end(BLI_Iterator *iter)
bool BKE_collection_object_replace(Main *bmain, Collection *collection, Object *ob_old, Object *ob_new)
bool BKE_collection_is_empty(const Collection *collection)
Collection * BKE_collection_duplicate(Main *bmain, Collection *parent, CollectionChild *child_old, Collection *collection, eDupli_ID_Flags duplicate_flags, uint duplicate_options)
bool BKE_collection_move(Main *bmain, Collection *to_parent, Collection *from_parent, Collection *relative, bool relative_after, Collection *collection)
bool BKE_collection_is_in_scene(Collection *collection)
bool BKE_collection_child_add(Main *bmain, Collection *parent, Collection *child)
void BKE_collection_object_move(Main *bmain, Scene *scene, Collection *collection_dst, Collection *collection_src, Object *ob)
void BKE_collection_blend_write_prepare_nolib(BlendWriter *writer, Collection *collection)
Collection * BKE_collection_from_session_uid(Scene *scene, uint64_t session_uid)
void BKE_collection_add_from_object(Main *bmain, Scene *scene, const Object *ob_src, Collection *collection_dst)
bool BKE_collection_exporter_move(Collection *collection, const int from, const int to)
void BKE_collections_child_remove_nulls(Main *bmain, Collection *parent_collection, Collection *child_collection)
void BKE_collection_exporter_name_set(const ListBase *exporters, CollectionExport *data, const char *newname)
GSet * BKE_scene_objects_as_gset(Scene *scene, GSet *objects_gset)
bool BKE_collection_validate(Collection *collection)
CollectionExport * BKE_collection_exporter_add(Collection *collection, char *idname, char *label)
bool BKE_collection_child_add_no_sync(Main *bmain, Collection *parent, Collection *child)
void BKE_scene_collections_iterator_begin(BLI_Iterator *iter, void *data_in)
void BKE_collection_free_data(Collection *collection)
void(*)(Object *ob, void *data) BKE_scene_objects_Cb
bool BKE_collection_contains_geometry_recursive(const Collection *collection)
void BKE_main_collections_object_cache_free(const Main *bmain)
Collection * BKE_collection_object_find(Main *bmain, Scene *scene, Collection *collection, Object *ob)
void BKE_scene_collections_iterator_end(BLI_Iterator *iter)
bool BKE_collection_cycles_fix(Main *bmain, Collection *collection)
bool BKE_collection_object_add_notest(Main *bmain, Collection *collection, Object *ob)
void BKE_scene_objects_iterator_end_ex(BLI_Iterator *iter)
void BKE_collection_object_add_from(Main *bmain, Scene *scene, Object *ob_src, Object *ob_dst)
Collection * BKE_collection_parent_editable_find_recursive(const ViewLayer *view_layer, Collection *collection)
bool BKE_collection_delete(Main *bmain, Collection *collection, bool hierarchy)
bool BKE_collection_cycle_find(Collection *new_ancestor, Collection *collection)
bool BKE_collection_object_cyclic_check(Main *bmain, Object *object, Collection *collection)
void BKE_collections_after_lib_link(Main *bmain)
bool BKE_collection_has_collection(const Collection *parent, const Collection *collection)
ListBase BKE_collection_object_cache_get(Collection *collection)
void BKE_collection_blend_read_data(BlendDataReader *reader, Collection *collection, ID *owner_id)
void BKE_scene_objects_iterator_begin(BLI_Iterator *iter, void *data_in)
void BKE_collection_parent_relations_rebuild(Collection *collection)
bool BKE_collection_objects_select(const Scene *scene, ViewLayer *view_layer, Collection *collection, bool deselect)
void BKE_scene_objects_iterator_next(BLI_Iterator *iter)
void BKE_collection_new_name_get(Collection *collection_parent, char r_name[256])
void BKE_main_collections_parent_relations_rebuild(Main *bmain)
@ COLLECTION_TAG_COLLECTION_OBJECT_DIRTY
@ COLLECTION_TAG_RELATION_REBUILD
bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
struct GSet GSet
Definition BLI_ghash.h:337
unsigned int uint
These structs are the foundation for all linked lists in the library system.
eDupli_ID_Flags
BMesh const char void * data
unsigned long long int uint64_t
struct CollectionParent * prev
struct Collection * collection
struct CollectionParent * next
Definition DNA_ID.h:414