Blender V4.3
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
11#include "BLI_compiler_compat.h"
12#include "BLI_ghash.h"
13#include "BLI_iterator.h"
14#include "BLI_sys_types.h"
15
16#include "DNA_listBase.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
76 CollectionExport *data,
77 const char *newname);
78
83
88bool BKE_collection_delete(Main *bmain, Collection *collection, bool hierarchy);
89
99 Collection *parent,
100 CollectionChild *child_old,
101 Collection *collection,
102 uint duplicate_flags,
103 uint duplicate_options);
104
105/* Master Collection for Scene */
106
107#define BKE_SCENE_COLLECTION_NAME "Scene Collection"
109
110/* Collection Objects */
111
112bool BKE_collection_has_object(Collection *collection, const Object *ob);
120 Object *object_eval);
122 Scene *scene,
123 Collection *collection,
124 Object *ob);
125
127
128bool BKE_collection_is_empty(const Collection *collection);
129
134bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob);
135
143 const ViewLayer *view_layer,
144 Collection *collection,
145 Object *ob);
146
152bool BKE_collection_object_add_notest(Main *bmain, Collection *collection, Object *ob);
159void BKE_collection_object_add_from(Main *bmain, Scene *scene, Object *ob_src, Object *ob_dst);
163bool BKE_collection_object_remove(Main *bmain, Collection *collection, Object *ob, bool free_us);
168 Collection *collection,
169 Object *ob_old,
170 Object *ob_new);
171
178 Main *bmain, Scene *scene, Collection *collection_dst, Collection *collection_src, Object *ob);
179
183bool BKE_scene_collections_object_remove(Main *bmain, Scene *scene, Object *ob, bool free_us);
184
193
207 Collection *parent_collection,
208 Collection *child_collection);
209
210/* Dependencies. */
211
212bool BKE_collection_is_in_scene(Collection *collection);
214bool BKE_collection_object_cyclic_check(Main *bmain, Object *object, Collection *collection);
215
216/* Object list cache. */
217
227void BKE_collection_object_cache_free(const Main *bmain,
228 Collection *collection,
229 const int id_create_flag);
235
237 ViewLayer *view_layer,
238 Collection *collection);
239
240/* Editing. */
241
247Collection *BKE_collection_from_index(Scene *scene, int index);
251void BKE_collection_new_name_get(Collection *collection_parent, char *rname);
255const char *BKE_collection_ui_name_get(Collection *collection);
260bool BKE_collection_objects_select(const Scene *scene,
261 ViewLayer *view_layer,
262 Collection *collection,
263 bool deselect);
264
265/* Collection children */
266
267bool BKE_collection_child_add(Main *bmain, Collection *parent, Collection *child);
268
269bool BKE_collection_child_add_no_sync(Main *bmain, Collection *parent, Collection *child);
270
271bool BKE_collection_child_remove(Main *bmain, Collection *parent, Collection *child);
272
273bool BKE_collection_move(Main *bmain,
274 Collection *to_parent,
275 Collection *from_parent,
276 Collection *relative,
277 bool relative_after,
278 Collection *collection);
279
289bool BKE_collection_cycle_find(Collection *new_ancestor, Collection *collection);
296bool BKE_collection_cycles_fix(Main *bmain, Collection *collection);
297
298bool BKE_collection_has_collection(const Collection *parent, const Collection *collection);
299
304 Collection *collection);
315
320bool BKE_collection_validate(Collection *collection);
321
322/* .blend file I/O */
323
331
332/* Iteration callbacks. */
333
334using BKE_scene_objects_Cb = void (*)(Object *ob, void *data);
335using BKE_scene_collections_Cb = void (*)(Collection *ob, void *data);
336
337/* Iteration over objects in collection. */
338
339#define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN(_collection, _object, _mode) \
340 { \
341 int _base_flag = (_mode == DAG_EVAL_VIEWPORT) ? BASE_ENABLED_VIEWPORT : BASE_ENABLED_RENDER; \
342 int _object_visibility_flag = (_mode == DAG_EVAL_VIEWPORT) ? OB_HIDE_VIEWPORT : \
343 OB_HIDE_RENDER; \
344 int _base_id = 0; \
345 for (Base *_base = static_cast<Base *>(BKE_collection_object_cache_get(_collection).first); \
346 _base; \
347 _base = _base->next, _base_id++) \
348 { \
349 Object *_object = _base->object; \
350 if ((_base->flag & _base_flag) && \
351 (_object->visibility_flag & _object_visibility_flag) == 0) {
352
353#define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_END \
354 } \
355 } \
356 } \
357 ((void)0)
358
359#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object) \
360 for (Base *_base = static_cast<Base *>(BKE_collection_object_cache_get(_collection).first); \
361 _base; \
362 _base = _base->next) \
363 { \
364 Object *_object = _base->object; \
365 BLI_assert(_object != NULL);
366
367#define FOREACH_COLLECTION_OBJECT_RECURSIVE_END \
368 } \
369 ((void)0)
370
371/* Iteration over collections in scene. */
372
377void BKE_scene_collections_iterator_begin(BLI_Iterator *iter, void *data_in);
380
381void BKE_scene_objects_iterator_begin(BLI_Iterator *iter, void *data_in);
384
395
396void BKE_scene_objects_iterator_begin_ex(BLI_Iterator *iter, void *data_in);
399
407GSet *BKE_scene_objects_as_gset(Scene *scene, GSet *objects_gset);
408
409#define FOREACH_SCENE_COLLECTION_BEGIN(scene, _instance) \
410 ITER_BEGIN (BKE_scene_collections_iterator_begin, \
411 BKE_scene_collections_iterator_next, \
412 BKE_scene_collections_iterator_end, \
413 scene, \
414 Collection *, \
415 _instance)
416
417#define FOREACH_SCENE_COLLECTION_END ITER_END
418
419#define FOREACH_COLLECTION_BEGIN(_bmain, _scene, Type, _instance) \
420 { \
421 Type _instance; \
422 Collection *_instance_next; \
423 bool is_scene_collection = (_scene) != NULL; \
424\
425 if (_scene) { \
426 _instance_next = _scene->master_collection; \
427 } \
428 else { \
429 _instance_next = static_cast<Collection *>((_bmain)->collections.first); \
430 } \
431\
432 while ((_instance = _instance_next)) { \
433 if (is_scene_collection) { \
434 _instance_next = static_cast<Collection *>((_bmain)->collections.first); \
435 is_scene_collection = false; \
436 } \
437 else { \
438 _instance_next = static_cast<Collection *>(_instance->id.next); \
439 }
440
441#define FOREACH_COLLECTION_END \
442 } \
443 } \
444 ((void)0)
445
446#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance) \
447 ITER_BEGIN (BKE_scene_objects_iterator_begin, \
448 BKE_scene_objects_iterator_next, \
449 BKE_scene_objects_iterator_end, \
450 scene, \
451 Object *, \
452 _instance)
453
454#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)
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)
Collection * BKE_collection_duplicate(Main *bmain, Collection *parent, CollectionChild *child_old, Collection *collection, uint duplicate_flags, uint duplicate_options)
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:341
unsigned int uint
These structs are the foundation for all linked lists in the library system.
struct CollectionParent * prev
struct Collection * collection
struct CollectionParent * next
Definition DNA_ID.h:413