Blender V5.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
10
11#include <string>
12
13#include "BLI_iterator.hh"
14#include "BLI_map.hh"
15#include "BLI_set.hh"
16#include "BLI_sys_types.hh"
17
19#include "DNA_listBase.h"
20#include "DNA_userdef_enums.h"
21
22namespace blender {
23
24/* Structs */
25
26struct BLI_Iterator;
27struct Base;
28struct BlendDataReader;
29struct BlendWriter;
30struct Collection;
31struct ID;
32struct CollectionChild;
33struct CollectionImport;
34struct CollectionExport;
35struct CollectionObject;
36struct Main;
37struct Object;
38struct Scene;
39struct ViewLayer;
40
42enum {
56};
57
59
64
65namespace bke {
66
73 ListBaseT<Base> object_cache = {};
74
76 ListBaseT<Base> object_cache_instanced = {};
77
79 ListBaseT<CollectionParent> parents = {};
80
83
85};
86
92
93} // namespace bke
94
95/* Collections */
96
102 Collection *collection_parent,
103 const char *name_custom);
111 Scene *scene,
112 const Object *ob_src,
113 Collection *collection_dst);
121 Scene *scene,
122 Collection *collection_src,
123 Collection *collection_dst);
127void BKE_collection_free_data(Collection *collection);
128
134 std::string *reason = nullptr);
135
139CollectionImport *BKE_collection_importer_add(Collection *collection, const char *idname);
140
144CollectionExport *BKE_collection_exporter_add(Collection *collection, char *idname, char *label);
145
150
154bool BKE_collection_exporter_move(Collection *collection, const int from, const int to);
155
159void BKE_collection_exporter_name_set(const ListBaseT<CollectionExport> *exporters,
161 const char *newname);
162
168
173bool BKE_collection_delete(Main *bmain, Collection *collection, bool hierarchy);
174
195 Collection *parent,
196 CollectionChild *child_old,
197 Collection *collection,
198 eDupli_ID_Flags duplicate_flags,
199 /*eLibIDDuplicateFlags*/ uint duplicate_options);
200
201/* Master Collection for Scene */
202
203#define BKE_SCENE_COLLECTION_NAME "Scene Collection"
204Collection *BKE_collection_master_add(Scene *scene);
205
211bool BKE_collection_contains_geometry_recursive(const Collection *collection);
212
213/* Collection Objects */
214
215bool BKE_collection_has_object(Collection *collection, const Object *ob);
216bool BKE_collection_has_object_recursive(Collection *collection, Object *ob);
217bool BKE_collection_has_object_recursive_instanced(Collection *collection, Object *ob);
222bool BKE_collection_has_object_recursive_instanced_orig_id(Collection *collection_eval,
223 Object *object_eval);
224Collection *BKE_collection_object_find(Main *bmain,
225 Scene *scene,
226 Collection *collection,
227 Object *ob);
228
229CollectionChild *BKE_collection_child_find(Collection *parent, Collection *collection);
230
231bool BKE_collection_is_empty(const Collection *collection);
232
237bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob);
238
246 const ViewLayer *view_layer,
247 Collection *collection,
248 Object *ob);
249
255bool BKE_collection_object_add_notest(Main *bmain, Collection *collection, Object *ob);
262void BKE_collection_object_add_from(Main *bmain, Scene *scene, Object *ob_src, Object *ob_dst);
266bool BKE_collection_object_remove(Main *bmain, Collection *collection, Object *ob, bool free_us);
270bool BKE_collection_object_replace(Main *bmain,
271 Collection *collection,
272 Object *ob_old,
273 Object *ob_new);
274
281 Main *bmain, Scene *scene, Collection *collection_dst, Collection *collection_src, Object *ob);
282
288CollectionObject *BKE_collection_object_find_in(const Collection &collection, const Object &ob);
289
294
303
307bool BKE_scene_collections_object_remove(Main *bmain, Scene *scene, Object *ob, bool free_us);
308
317
331 Collection *parent_collection,
332 Collection *child_collection);
333
334/* Dependencies. */
335
336bool BKE_collection_is_in_scene(Collection *collection);
337void BKE_collections_after_lib_link(Main *bmain);
338bool BKE_collection_object_cyclic_check(Main *bmain, Object *object, Collection *collection);
339
340/* Object list cache. */
341
342ListBaseT<Base> BKE_collection_object_cache_get(Collection *collection);
343ListBaseT<Base> BKE_collection_object_cache_instanced_get(Collection *collection);
353void BKE_collection_object_cache_free(const Main *bmain,
354 Collection *collection,
355 const int id_create_flag);
360void BKE_main_collections_object_cache_free(const Main *bmain);
361
362Base *BKE_collection_or_layer_objects(const Main &bmain,
363 const Scene *scene,
364 ViewLayer *view_layer,
365 Collection *collection);
366
367/* Editing. */
368
372Collection *BKE_collection_from_session_uid(Scene *scene, uint64_t session_uid);
376Collection *BKE_collection_from_session_uid(Main *bmain,
377 uint64_t session_uid,
378 Scene **r_scene = nullptr);
379
384 char r_name[/*MAX_ID_NAME - 2*/ 256]);
388const char *BKE_collection_ui_name_get(Collection *collection);
389
390/* Collection children */
391
392bool BKE_collection_child_add(Main *bmain, Collection *parent, Collection *child);
393
394bool BKE_collection_child_add_no_sync(Main *bmain, Collection *parent, Collection *child);
395
396bool BKE_collection_child_remove(Main *bmain, Collection *parent, Collection *child);
397
398bool BKE_collection_move(Main *bmain,
399 Collection *to_parent,
400 Collection *from_parent,
401 Collection *relative,
402 bool relative_after,
403 Collection *collection);
404
414bool BKE_collection_cycle_find(Collection *new_ancestor, Collection *collection);
421bool BKE_collection_cycles_fix(Main *bmain, Collection *collection);
422
423bool BKE_collection_has_collection(const Collection *parent, const Collection *collection);
424
429 Collection *collection);
440
446bool BKE_collection_validate(Collection *collection);
447
448/* .blend file I/O */
449
456void BKE_collection_blend_read_data(BlendDataReader *reader, Collection *collection, ID *owner_id);
457
458/* Iteration callbacks. */
459
460using BKE_scene_objects_Cb = void (*)(Object *ob, void *data);
461using BKE_scene_collections_Cb = void (*)(Collection *ob, void *data);
462
463/* Iteration over objects in collection. */
464
465#define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN(_collection, _object, _mode) \
466 { \
467 int _base_flag = (_mode == DAG_EVAL_VIEWPORT) ? BASE_ENABLED_VIEWPORT : BASE_ENABLED_RENDER; \
468 int _object_visibility_flag = (_mode == DAG_EVAL_VIEWPORT) ? OB_HIDE_VIEWPORT : \
469 OB_HIDE_RENDER; \
470 [[maybe_unused]] int _base_id = 0; \
471 for (Base *_base = BKE_collection_object_cache_get(_collection).first(); _base; \
472 _base = _base->next, _base_id++) \
473 { \
474 Object *_object = _base->object; \
475 if ((_base->flag & _base_flag) && \
476 (_object->visibility_flag & _object_visibility_flag) == 0) \
477 {
478
479#define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_END \
480 } \
481 } \
482 } \
483 ((void)0)
484
485#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object) \
486 for (Base *_base = BKE_collection_object_cache_get(_collection).first(); _base; \
487 _base = _base->next) \
488 { \
489 Object *_object = _base->object; \
490 BLI_assert(_object != NULL);
491
492#define FOREACH_COLLECTION_OBJECT_RECURSIVE_END \
493 } \
494 ((void)0)
495
496/* Iteration over collections in scene. */
497
502void BKE_scene_collections_iterator_begin(BLI_Iterator *iter, void *data_in);
503void BKE_scene_collections_iterator_next(BLI_Iterator *iter);
504void BKE_scene_collections_iterator_end(BLI_Iterator *iter);
505
506void BKE_scene_objects_iterator_begin(BLI_Iterator *iter, void *data_in);
507void BKE_scene_objects_iterator_next(BLI_Iterator *iter);
508void BKE_scene_objects_iterator_end(BLI_Iterator *iter);
509
521
522void BKE_scene_objects_iterator_begin_ex(BLI_Iterator *iter, void *data_in);
525
534
535#define FOREACH_SCENE_COLLECTION_BEGIN(scene, _instance) \
536 ITER_BEGIN (BKE_scene_collections_iterator_begin, \
537 BKE_scene_collections_iterator_next, \
538 BKE_scene_collections_iterator_end, \
539 scene, \
540 Collection *, \
541 _instance)
542
543#define FOREACH_SCENE_COLLECTION_END ITER_END
544
545#define FOREACH_COLLECTION_BEGIN(_bmain, _scene, Type, _instance) \
546 { \
547 Type _instance; \
548 Collection *_instance_next; \
549 bool is_scene_collection = (_scene) != NULL; \
550\
551 if (_scene) { \
552 _instance_next = (_scene)->master_collection; \
553 } \
554 else { \
555 _instance_next = (_bmain)->collections.first(); \
556 } \
557\
558 while ((_instance = _instance_next)) { \
559 if (is_scene_collection) { \
560 _instance_next = (_bmain)->collections.first(); \
561 is_scene_collection = false; \
562 } \
563 else { \
564 _instance_next = static_cast<Collection *>(_instance->id.next); \
565 }
566
567#define FOREACH_COLLECTION_END \
568 } \
569 } \
570 ((void)0)
571
572#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance) \
573 ITER_BEGIN (BKE_scene_objects_iterator_begin, \
574 BKE_scene_objects_iterator_next, \
575 BKE_scene_objects_iterator_end, \
576 scene, \
577 Object *, \
578 _instance)
579
580#define FOREACH_SCENE_OBJECT_END ITER_END
581
582} // namespace blender
Object groups, one object can be in many groups at once.
These structs are the foundation for all linked lists in the library system.
unsigned long long int uint64_t
Definition scene.h:133
BMesh Iterators.
@ COLLECTION_TAG_RELATION_REBUILD
@ COLLECTION_TAG_COLLECTION_OBJECT_DIRTY
bool BKE_collection_delete(Main *bmain, Collection *collection, bool hierarchy)
void BKE_scene_objects_iterator_end(BLI_Iterator *iter)
void BKE_scene_objects_iterator_begin(BLI_Iterator *iter, void *data_in)
bool BKE_collection_has_object_recursive_instanced(Collection *collection, Object *ob)
Collection * BKE_collection_duplicate(Main *bmain, Collection *parent, CollectionChild *child_old, Collection *collection, eDupli_ID_Flags duplicate_flags, uint duplicate_options)
bool BKE_collection_has_object_recursive_instanced_orig_id(Collection *collection_eval, Object *object_eval)
unsigned int uint
Definition BKE_text.h:55
const char * BKE_collection_ui_name_get(Collection *collection)
void BKE_collections_child_remove_nulls(Main *bmain, Collection *parent_collection, Collection *child_collection)
Collection * BKE_collection_from_session_uid(Scene *scene, uint64_t session_uid)
void BKE_collection_blend_write_prepare_nolib(BlendWriter *writer, Collection *collection)
bool BKE_collection_viewlayer_object_add(Main *bmain, const ViewLayer *view_layer, Collection *collection, Object *ob)
bool BKE_collection_child_add(Main *bmain, Collection *parent, Collection *child)
void(*)(Object *ob, void *data) BKE_scene_objects_Cb
CollectionObject * BKE_collection_object_find_in(const Collection &collection, const Object &ob)
void BKE_main_collections_parent_relations_rebuild(Main *bmain)
void BKE_main_collections_object_cache_free(const Main *bmain)
bool BKE_scene_collections_object_remove(Main *bmain, Scene *scene, Object *ob, bool free_us)
void BKE_scene_collections_iterator_next(BLI_Iterator *iter)
void BKE_collection_importer_free_data(CollectionImport *data)
void BKE_collection_object_parent_clear_sort_index_reset(Main &bmain, Object &ob)
CollectionImport * BKE_collection_importer_add(Collection *collection, const char *idname)
void BKE_collection_object_cache_free(const Main *bmain, Collection *collection, const int id_create_flag)
bool BKE_collection_cycles_fix(Main *bmain, Collection *collection)
bool BKE_collection_exporter_move(Collection *collection, const int from, const int to)
bool BKE_collection_has_object(Collection *collection, const Object *ob)
bool BKE_collection_object_add_notest(Main *bmain, Collection *collection, Object *ob)
Collection * BKE_collection_object_find(Main *bmain, Scene *scene, Collection *collection, Object *ob)
void BKE_collection_free_data(Collection *collection)
bool BKE_collection_validate(Collection *collection)
void BKE_collection_object_parented_sort_index_reset(Main &bmain, Object &ob)
BMesh const char void * data
bool BKE_collection_contains_geometry_recursive(const Collection *collection)
void BKE_collection_add_from_object(Main *bmain, Scene *scene, const Object *ob_src, Collection *collection_dst)
bool BKE_collection_move(Main *bmain, Collection *to_parent, Collection *from_parent, Collection *relative, bool relative_after, Collection *collection)
void BKE_collections_object_remove_invalids(Main *bmain)
bool BKE_collection_is_in_scene(Collection *collection)
bool BKE_collection_is_empty(const Collection *collection)
bool BKE_collection_object_cyclic_check(Main *bmain, Object *object, Collection *collection)
unsigned char uint8_t
Definition BKE_text.h:79
CollectionChild * BKE_collection_child_find(Collection *parent, Collection *collection)
Base * BKE_collection_or_layer_objects(const Main &bmain, const Scene *scene, ViewLayer *view_layer, Collection *collection)
void BKE_collection_add_from_collection(Main *bmain, Scene *scene, Collection *collection_src, Collection *collection_dst)
CollectionExport * BKE_collection_exporter_add(Collection *collection, char *idname, char *label)
void BKE_collection_blend_write_nolib(BlendWriter *writer, Collection *collection)
Collection * BKE_collection_parent_editable_find_recursive(const ViewLayer *view_layer, Collection *collection)
bool BKE_collection_child_remove(Main *bmain, Collection *parent, Collection *child)
void BKE_collections_after_lib_link(Main *bmain)
void BKE_collection_object_add_from(Main *bmain, Scene *scene, Object *ob_src, Object *ob_dst)
void BKE_collection_object_move(Main *bmain, Scene *scene, Collection *collection_dst, Collection *collection_src, Object *ob)
bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
void BKE_scene_collections_iterator_begin(BLI_Iterator *iter, void *data_in)
bool BKE_collection_has_collection(const Collection *parent, const Collection *collection)
ListBaseT< Base > BKE_collection_object_cache_instanced_get(Collection *collection)
void BKE_scene_collections_iterator_end(BLI_Iterator *iter)
ListBaseT< Base > BKE_collection_object_cache_get(Collection *collection)
void(*)(Collection *ob, void *data) BKE_scene_collections_Cb
void BKE_scene_objects_iterator_next(BLI_Iterator *iter)
bool BKE_collection_cycle_find(Collection *new_ancestor, Collection *collection)
bool BKE_collection_child_add_no_sync(Main *bmain, Collection *parent, Collection *child)
Set< Object * > * BKE_scene_objects_as_set(Scene *scene, Set< Object * > *objects_set)
void BKE_collection_parent_relations_rebuild(Collection *collection)
bool BKE_collection_is_content_editable(const Collection *collection, std::string *reason=nullptr)
void BKE_scene_objects_iterator_next_ex(BLI_Iterator *iter)
bool BKE_collection_object_remove(Main *bmain, Collection *collection, Object *ob, bool free_us)
void BKE_collection_exporter_remove(Collection *collection, CollectionExport *data)
bool BKE_collection_object_replace(Main *bmain, Collection *collection, Object *ob_old, Object *ob_new)
Collection * BKE_collection_master_add(Scene *scene)
void BKE_collection_exporter_name_set(const ListBaseT< CollectionExport > *exporters, CollectionExport *data, const char *newname)
void BKE_scene_objects_iterator_end_ex(BLI_Iterator *iter)
void BKE_collection_exporter_free_data(CollectionExport *data)
void BKE_scene_objects_iterator_begin_ex(BLI_Iterator *iter, void *data_in)
bool BKE_collection_has_object_recursive(Collection *collection, Object *ob)
Map< const Object *, CollectionObject * > CollectionObjectMap
void BKE_collection_new_name_get(Collection *collection_parent, char r_name[256])
void BKE_collection_blend_read_data(BlendDataReader *reader, Collection *collection, ID *owner_id)
Collection * BKE_collection_add(Main *bmain, Collection *collection_parent, const char *name_custom)
struct CollectionParent * next
struct CollectionParent * prev
struct Collection * collection
ListBaseT< Base > object_cache_instanced
ListBaseT< CollectionParent > parents
CollectionObjectMap * gobject_hash