Blender V4.5
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 Main;
29struct Object;
30struct Scene;
31struct ViewLayer;
32
37
38/* Collections */
39
45 Collection *collection_parent,
46 const char *name_custom);
54 Scene *scene,
55 const Object *ob_src,
56 Collection *collection_dst);
64 Scene *scene,
65 Collection *collection_src,
66 Collection *collection_dst);
70void BKE_collection_free_data(Collection *collection);
71
77 const char *newname);
78
83
88bool BKE_collection_delete(Main *bmain, Collection *collection, bool hierarchy);
89
110 Collection *parent,
111 CollectionChild *child_old,
112 Collection *collection,
113 eDupli_ID_Flags duplicate_flags,
114 /*eLibIDDuplicateFlags*/ uint duplicate_options);
115
116/* Master Collection for Scene */
117
118#define BKE_SCENE_COLLECTION_NAME "Scene Collection"
120
121/* Collection Objects */
122
123bool BKE_collection_has_object(Collection *collection, const Object *ob);
131 Object *object_eval);
133 Scene *scene,
134 Collection *collection,
135 Object *ob);
136
138
139bool BKE_collection_is_empty(const Collection *collection);
140
145bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob);
146
154 const ViewLayer *view_layer,
155 Collection *collection,
156 Object *ob);
157
163bool BKE_collection_object_add_notest(Main *bmain, Collection *collection, Object *ob);
170void BKE_collection_object_add_from(Main *bmain, Scene *scene, Object *ob_src, Object *ob_dst);
174bool BKE_collection_object_remove(Main *bmain, Collection *collection, Object *ob, bool free_us);
179 Collection *collection,
180 Object *ob_old,
181 Object *ob_new);
182
189 Main *bmain, Scene *scene, Collection *collection_dst, Collection *collection_src, Object *ob);
190
194bool BKE_scene_collections_object_remove(Main *bmain, Scene *scene, Object *ob, bool free_us);
195
204
218 Collection *parent_collection,
219 Collection *child_collection);
220
221/* Dependencies. */
222
223bool BKE_collection_is_in_scene(Collection *collection);
225bool BKE_collection_object_cyclic_check(Main *bmain, Object *object, Collection *collection);
226
227/* Object list cache. */
228
240void BKE_collection_object_cache_free(const Main *bmain,
241 Collection *collection,
242 const int id_create_flag);
248
250 ViewLayer *view_layer,
251 Collection *collection);
252
253/* Editing. */
254
260Collection *BKE_collection_from_index(Scene *scene, int index);
264void BKE_collection_new_name_get(Collection *collection_parent, char *rname);
268const char *BKE_collection_ui_name_get(Collection *collection);
273bool BKE_collection_objects_select(const Scene *scene,
274 ViewLayer *view_layer,
275 Collection *collection,
276 bool deselect);
277
278/* Collection children */
279
280bool BKE_collection_child_add(Main *bmain, Collection *parent, Collection *child);
281
282bool BKE_collection_child_add_no_sync(Main *bmain, Collection *parent, Collection *child);
283
284bool BKE_collection_child_remove(Main *bmain, Collection *parent, Collection *child);
285
286bool BKE_collection_move(Main *bmain,
287 Collection *to_parent,
288 Collection *from_parent,
289 Collection *relative,
290 bool relative_after,
291 Collection *collection);
292
302bool BKE_collection_cycle_find(Collection *new_ancestor, Collection *collection);
309bool BKE_collection_cycles_fix(Main *bmain, Collection *collection);
310
311bool BKE_collection_has_collection(const Collection *parent, const Collection *collection);
312
317 Collection *collection);
328
333bool BKE_collection_validate(Collection *collection);
334
335/* .blend file I/O */
336
344
345/* Iteration callbacks. */
346
347using BKE_scene_objects_Cb = void (*)(Object *ob, void *data);
348using BKE_scene_collections_Cb = void (*)(Collection *ob, void *data);
349
350/* Iteration over objects in collection. */
351
352#define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN(_collection, _object, _mode) \
353 { \
354 int _base_flag = (_mode == DAG_EVAL_VIEWPORT) ? BASE_ENABLED_VIEWPORT : BASE_ENABLED_RENDER; \
355 int _object_visibility_flag = (_mode == DAG_EVAL_VIEWPORT) ? OB_HIDE_VIEWPORT : \
356 OB_HIDE_RENDER; \
357 int _base_id = 0; \
358 for (Base *_base = static_cast<Base *>(BKE_collection_object_cache_get(_collection).first); \
359 _base; \
360 _base = _base->next, _base_id++) \
361 { \
362 Object *_object = _base->object; \
363 if ((_base->flag & _base_flag) && \
364 (_object->visibility_flag & _object_visibility_flag) == 0) {
365
366#define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_END \
367 } \
368 } \
369 } \
370 ((void)0)
371
372#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object) \
373 for (Base *_base = static_cast<Base *>(BKE_collection_object_cache_get(_collection).first); \
374 _base; \
375 _base = _base->next) \
376 { \
377 Object *_object = _base->object; \
378 BLI_assert(_object != NULL);
379
380#define FOREACH_COLLECTION_OBJECT_RECURSIVE_END \
381 } \
382 ((void)0)
383
384/* Iteration over collections in scene. */
385
390void BKE_scene_collections_iterator_begin(BLI_Iterator *iter, void *data_in);
393
394void BKE_scene_objects_iterator_begin(BLI_Iterator *iter, void *data_in);
397
408
409void BKE_scene_objects_iterator_begin_ex(BLI_Iterator *iter, void *data_in);
412
420GSet *BKE_scene_objects_as_gset(Scene *scene, GSet *objects_gset);
421
422#define FOREACH_SCENE_COLLECTION_BEGIN(scene, _instance) \
423 ITER_BEGIN (BKE_scene_collections_iterator_begin, \
424 BKE_scene_collections_iterator_next, \
425 BKE_scene_collections_iterator_end, \
426 scene, \
427 Collection *, \
428 _instance)
429
430#define FOREACH_SCENE_COLLECTION_END ITER_END
431
432#define FOREACH_COLLECTION_BEGIN(_bmain, _scene, Type, _instance) \
433 { \
434 Type _instance; \
435 Collection *_instance_next; \
436 bool is_scene_collection = (_scene) != NULL; \
437\
438 if (_scene) { \
439 _instance_next = (_scene)->master_collection; \
440 } \
441 else { \
442 _instance_next = static_cast<Collection *>((_bmain)->collections.first); \
443 } \
444\
445 while ((_instance = _instance_next)) { \
446 if (is_scene_collection) { \
447 _instance_next = static_cast<Collection *>((_bmain)->collections.first); \
448 is_scene_collection = false; \
449 } \
450 else { \
451 _instance_next = static_cast<Collection *>(_instance->id.next); \
452 }
453
454#define FOREACH_COLLECTION_END \
455 } \
456 } \
457 ((void)0)
458
459#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance) \
460 ITER_BEGIN (BKE_scene_objects_iterator_begin, \
461 BKE_scene_objects_iterator_next, \
462 BKE_scene_objects_iterator_end, \
463 scene, \
464 Object *, \
465 _instance)
466
467#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)
Collection * BKE_collection_from_index(Scene *scene, int index)
void BKE_scene_objects_iterator_next_ex(BLI_Iterator *iter)
Collection * BKE_collection_master_add(Scene *scene)
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)
void BKE_collection_add_from_object(Main *bmain, Scene *scene, const Object *ob_src, Collection *collection_dst)
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)
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_new_name_get(Collection *collection_parent, char *rname)
void BKE_collection_free_data(Collection *collection)
void(*)(Object *ob, void *data) BKE_scene_objects_Cb
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_main_collections_parent_relations_rebuild(Main *bmain)
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
struct CollectionParent * prev
struct Collection * collection
struct CollectionParent * next
Definition DNA_ID.h:404