Blender  V2.93
Classes | Macros | Typedefs | Functions
BKE_collection.h File Reference
#include "BLI_compiler_compat.h"
#include "BLI_ghash.h"
#include "BLI_iterator.h"
#include "BLI_sys_types.h"
#include "DNA_listBase.h"

Go to the source code of this file.

Classes

struct  CollectionParent
 

Macros

#define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN(_collection, _object, _mode)
 
#define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_END
 
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object)
 
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_END
 
#define FOREACH_SCENE_COLLECTION_BEGIN(scene, _instance)
 
#define FOREACH_SCENE_COLLECTION_END   ITER_END
 
#define FOREACH_COLLECTION_BEGIN(_bmain, _scene, Type, _instance)
 
#define FOREACH_COLLECTION_END
 
#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance)
 
#define FOREACH_SCENE_OBJECT_END   ITER_END
 

Typedefs

typedef struct CollectionParent CollectionParent
 
typedef void(* BKE_scene_objects_Cb) (struct Object *ob, void *data)
 
typedef void(* BKE_scene_collections_Cb) (struct Collection *ob, void *data)
 

Functions

struct CollectionBKE_collection_add (struct Main *bmain, struct Collection *parent, const char *name)
 
void BKE_collection_add_from_object (struct Main *bmain, struct Scene *scene, const struct Object *ob_src, struct Collection *collection_dst)
 
void BKE_collection_add_from_collection (struct Main *bmain, struct Scene *scene, struct Collection *collection_src, struct Collection *collection_dst)
 
void BKE_collection_free (struct Collection *collection)
 
bool BKE_collection_delete (struct Main *bmain, struct Collection *collection, bool hierarchy)
 
struct CollectionBKE_collection_duplicate (struct Main *bmain, struct Collection *parent, struct Collection *collection, const uint duplicate_flags, const uint duplicate_options)
 
struct CollectionBKE_collection_master_add (void)
 
bool BKE_collection_has_object (struct Collection *collection, const struct Object *ob)
 
bool BKE_collection_has_object_recursive (struct Collection *collection, struct Object *ob)
 
bool BKE_collection_has_object_recursive_instanced (struct Collection *collection, struct Object *ob)
 
struct CollectionBKE_collection_object_find (struct Main *bmain, struct Scene *scene, struct Collection *collection, struct Object *ob)
 
bool BKE_collection_is_empty (const struct Collection *collection)
 
bool BKE_collection_object_add (struct Main *bmain, struct Collection *collection, struct Object *ob)
 
void BKE_collection_object_add_from (struct Main *bmain, struct Scene *scene, struct Object *ob_src, struct Object *ob_dst)
 
bool BKE_collection_object_remove (struct Main *bmain, struct Collection *collection, struct Object *object, const bool free_us)
 
void BKE_collection_object_move (struct Main *bmain, struct Scene *scene, struct Collection *collection_dst, struct Collection *collection_src, struct Object *ob)
 
bool BKE_scene_collections_object_remove (struct Main *bmain, struct Scene *scene, struct Object *object, const bool free_us)
 
void BKE_collections_object_remove_nulls (struct Main *bmain)
 
void BKE_collections_child_remove_nulls (struct Main *bmain, struct Collection *parent_collection, struct Collection *child_collection)
 
bool BKE_collection_is_in_scene (struct Collection *collection)
 
void BKE_collections_after_lib_link (struct Main *bmain)
 
bool BKE_collection_object_cyclic_check (struct Main *bmain, struct Object *object, struct Collection *collection)
 
struct ListBase BKE_collection_object_cache_get (struct Collection *collection)
 
ListBase BKE_collection_object_cache_instanced_get (struct Collection *collection)
 
void BKE_collection_object_cache_free (struct Collection *collection)
 
struct BaseBKE_collection_or_layer_objects (const struct ViewLayer *view_layer, struct Collection *collection)
 
struct CollectionBKE_collection_from_index (struct Scene *scene, const int index)
 
void BKE_collection_new_name_get (struct Collection *collection_parent, char *rname)
 
const char * BKE_collection_ui_name_get (struct Collection *collection)
 
bool BKE_collection_objects_select (struct ViewLayer *view_layer, struct Collection *collection, bool deselect)
 
bool BKE_collection_child_add (struct Main *bmain, struct Collection *parent, struct Collection *child)
 
bool BKE_collection_child_add_no_sync (struct Collection *parent, struct Collection *child)
 
bool BKE_collection_child_remove (struct Main *bmain, struct Collection *parent, struct Collection *child)
 
bool BKE_collection_move (struct Main *bmain, struct Collection *to_parent, struct Collection *from_parent, struct Collection *relative, bool relative_after, struct Collection *collection)
 
bool BKE_collection_cycle_find (struct Collection *new_ancestor, struct Collection *collection)
 
bool BKE_collection_cycles_fix (struct Main *bmain, struct Collection *collection)
 
bool BKE_collection_has_collection (struct Collection *parent, struct Collection *collection)
 
void BKE_collection_parent_relations_rebuild (struct Collection *collection)
 
void BKE_main_collections_parent_relations_rebuild (struct Main *bmain)
 
void BKE_collection_blend_write_nolib (struct BlendWriter *writer, struct Collection *collection)
 
void BKE_collection_blend_read_data (struct BlendDataReader *reader, struct Collection *collection)
 
void BKE_collection_blend_read_lib (struct BlendLibReader *reader, struct Collection *collection)
 
void BKE_collection_blend_read_expand (struct BlendExpander *expander, struct Collection *collection)
 
void BKE_collection_compat_blend_read_data (struct BlendDataReader *reader, struct SceneCollection *sc)
 
void BKE_collection_compat_blend_read_lib (struct BlendLibReader *reader, struct Library *lib, struct SceneCollection *sc)
 
void BKE_collection_compat_blend_read_expand (struct BlendExpander *expander, struct SceneCollection *sc)
 
void BKE_scene_collections_iterator_begin (struct BLI_Iterator *iter, void *data_in)
 
void BKE_scene_collections_iterator_next (struct BLI_Iterator *iter)
 
void BKE_scene_collections_iterator_end (struct BLI_Iterator *iter)
 
void BKE_scene_objects_iterator_begin (struct BLI_Iterator *iter, void *data_in)
 
void BKE_scene_objects_iterator_next (struct BLI_Iterator *iter)
 
void BKE_scene_objects_iterator_end (struct BLI_Iterator *iter)
 
struct GSetBKE_scene_objects_as_gset (struct Scene *scene, struct GSet *objects_gset)
 

Macro Definition Documentation

◆ FOREACH_COLLECTION_BEGIN

#define FOREACH_COLLECTION_BEGIN (   _bmain,
  _scene,
  Type,
  _instance 
)
Value:
{ \
Type _instance; \
Collection *_instance_next; \
bool is_scene_collection = (_scene) != NULL; \
if (_scene) { \
_instance_next = _scene->master_collection; \
} \
else { \
_instance_next = (_bmain)->collections.first; \
} \
\
while ((_instance = _instance_next)) { \
if (is_scene_collection) { \
_instance_next = (_bmain)->collections.first; \
is_scene_collection = false; \
} \
else { \
_instance_next = _instance->id.next; \
}

Definition at line 244 of file BKE_collection.h.

◆ FOREACH_COLLECTION_END

#define FOREACH_COLLECTION_END
Value:
} \
} \
((void)0)

Definition at line 266 of file BKE_collection.h.

◆ FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN

#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (   _collection,
  _object 
)
Value:
for (Base *_base = (Base *)BKE_collection_object_cache_get(_collection).first; _base; \
_base = _base->next) { \
Object *_object = _base->object; \
BLI_assert(_object != NULL);
struct ListBase BKE_collection_object_cache_get(struct Collection *collection)
Definition: collection.c:827

Definition at line 212 of file BKE_collection.h.

◆ FOREACH_COLLECTION_OBJECT_RECURSIVE_END

#define FOREACH_COLLECTION_OBJECT_RECURSIVE_END
Value:
} \
((void)0)

Definition at line 218 of file BKE_collection.h.

◆ FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN

#define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN (   _collection,
  _object,
  _mode 
)
Value:
{ \
int _base_flag = (_mode == DAG_EVAL_VIEWPORT) ? BASE_ENABLED_VIEWPORT : BASE_ENABLED_RENDER; \
int _object_restrict_flag = (_mode == DAG_EVAL_VIEWPORT) ? OB_RESTRICT_VIEWPORT : \
int _base_id = 0; \
for (Base *_base = (Base *)BKE_collection_object_cache_get(_collection).first; _base; \
_base = _base->next, _base_id++) { \
Object *_object = _base->object; \
if ((_base->flag & _base_flag) && (_object->restrictflag & _object_restrict_flag) == 0) {
@ DAG_EVAL_VIEWPORT
Definition: DEG_depsgraph.h:61
@ BASE_ENABLED_RENDER
@ BASE_ENABLED_VIEWPORT
@ OB_RESTRICT_VIEWPORT
@ OB_RESTRICT_RENDER

Definition at line 195 of file BKE_collection.h.

◆ FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_END

#define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_END
Value:
} \
} \
} \
((void)0)

Definition at line 206 of file BKE_collection.h.

◆ FOREACH_SCENE_COLLECTION_BEGIN

#define FOREACH_SCENE_COLLECTION_BEGIN (   scene,
  _instance 
)
Value:
scene, \
_instance)
void BKE_scene_collections_iterator_begin(struct BLI_Iterator *iter, void *data_in)
Definition: collection.c:2048
void BKE_scene_collections_iterator_end(struct BLI_Iterator *iter)
Definition: collection.c:2077
void BKE_scene_collections_iterator_next(struct BLI_Iterator *iter)
Definition: collection.c:2065
#define ITER_BEGIN(callback_begin, callback_next, callback_end, _data_in, _type, _instance)
Definition: BLI_iterator.h:44
Scene scene

Definition at line 234 of file BKE_collection.h.

◆ FOREACH_SCENE_COLLECTION_END

#define FOREACH_SCENE_COLLECTION_END   ITER_END

Definition at line 242 of file BKE_collection.h.

◆ FOREACH_SCENE_OBJECT_BEGIN

#define FOREACH_SCENE_OBJECT_BEGIN (   scene,
  _instance 
)
Value:
scene, \
Object *, \
_instance)
void BKE_scene_objects_iterator_next(struct BLI_Iterator *iter)
Definition: collection.c:2145
void BKE_scene_objects_iterator_end(struct BLI_Iterator *iter)
Definition: collection.c:2177
void BKE_scene_objects_iterator_begin(struct BLI_Iterator *iter, void *data_in)
Definition: collection.c:2122

Definition at line 271 of file BKE_collection.h.

◆ FOREACH_SCENE_OBJECT_END

#define FOREACH_SCENE_OBJECT_END   ITER_END

Definition at line 279 of file BKE_collection.h.

Typedef Documentation

◆ BKE_scene_collections_Cb

typedef void(* BKE_scene_collections_Cb) (struct Collection *ob, void *data)

Definition at line 191 of file BKE_collection.h.

◆ BKE_scene_objects_Cb

typedef void(* BKE_scene_objects_Cb) (struct Object *ob, void *data)

Definition at line 190 of file BKE_collection.h.

◆ CollectionParent

Function Documentation

◆ BKE_collection_add()

struct Collection* BKE_collection_add ( Main bmain,
Collection collection_parent,
const char *  name_custom 
)

◆ BKE_collection_add_from_collection()

void BKE_collection_add_from_collection ( Main bmain,
Scene scene,
Collection collection_src,
Collection collection_dst 
)

Add collection_dst to all scene collections that reference collection collection_src is in.

Logic is very similar to BKE_collection_object_add_from().

Definition at line 476 of file collection.c.

References BKE_main_collection_sync(), collection_child_add(), collection_find_child(), FOREACH_SCENE_COLLECTION_BEGIN, FOREACH_SCENE_COLLECTION_END, ID_IS_LINKED, Scene::master_collection, and scene.

Referenced by lib_override_library_create_post_process().

◆ BKE_collection_add_from_object()

void BKE_collection_add_from_object ( struct Main bmain,
struct Scene scene,
const struct Object ob_src,
struct Collection collection_dst 
)

◆ BKE_collection_blend_read_data()

void BKE_collection_blend_read_data ( struct BlendDataReader reader,
struct Collection collection 
)

◆ BKE_collection_blend_read_expand()

void BKE_collection_blend_read_expand ( struct BlendExpander expander,
struct Collection collection 
)

◆ BKE_collection_blend_read_lib()

void BKE_collection_blend_read_lib ( struct BlendLibReader reader,
struct Collection collection 
)

◆ BKE_collection_blend_write_nolib()

void BKE_collection_blend_write_nolib ( struct BlendWriter writer,
struct Collection collection 
)

◆ BKE_collection_child_add()

bool BKE_collection_child_add ( struct Main bmain,
struct Collection parent,
struct Collection child 
)

◆ BKE_collection_child_add_no_sync()

bool BKE_collection_child_add_no_sync ( struct Collection parent,
struct Collection child 
)

Definition at line 1616 of file collection.c.

References collection_child_add().

Referenced by single_object_users_collection().

◆ BKE_collection_child_remove()

bool BKE_collection_child_remove ( struct Main bmain,
struct Collection parent,
struct Collection child 
)

◆ BKE_collection_compat_blend_read_data()

void BKE_collection_compat_blend_read_data ( struct BlendDataReader reader,
struct SceneCollection sc 
)

◆ BKE_collection_compat_blend_read_expand()

void BKE_collection_compat_blend_read_expand ( struct BlendExpander expander,
struct SceneCollection sc 
)

◆ BKE_collection_compat_blend_read_lib()

void BKE_collection_compat_blend_read_lib ( struct BlendLibReader reader,
struct Library lib,
struct SceneCollection sc 
)

◆ BKE_collection_cycle_find()

bool BKE_collection_cycle_find ( Collection new_ancestor,
Collection collection 
)

Find potential cycles in collections.

Parameters
new_ancestorthe potential new owner of given collection, or the collection to check if the later is NULL.
collectionthe collection we want to add to new_ancestor, may be NULL if we just want to ensure new_ancestor does not already have cycles.
Returns
true if a cycle is found.

Definition at line 1450 of file collection.c.

References BKE_collection_cycle_find(), collection_instance_find_recursive(), LISTBASE_FOREACH, NULL, and Collection::parents.

Referenced by BKE_collection_cycle_find(), BKE_collection_move(), BKE_collection_parent_relations_rebuild(), collection_child_add(), collection_cycle_fix_recursive(), collection_instance_add_exec(), and collection_instance_exec().

◆ BKE_collection_cycles_fix()

bool BKE_collection_cycles_fix ( Main bmain,
Collection collection 
)

Find and fix potential cycles in collections.

Parameters
collectionThe collection to check for existing cycles.
Returns
true if cycles are found and fixed.

Definition at line 1519 of file collection.c.

References collection_cycle_fix_recursive(), and collection_instance_fix_recursive().

Referenced by do_versions_after_linking_290().

◆ BKE_collection_delete()

bool BKE_collection_delete ( Main bmain,
Collection collection,
bool  hierarchy 
)

◆ BKE_collection_duplicate()

struct Collection* BKE_collection_duplicate ( struct Main bmain,
struct Collection parent,
struct Collection collection,
const uint  duplicate_flags,
const uint  duplicate_options 
)

◆ BKE_collection_free()

void BKE_collection_free ( Collection collection)

Free (or release) any data used by this collection (does not free the collection itself).

Definition at line 510 of file collection.c.

References BKE_libblock_free_data(), collection_free_data(), and Collection::id.

Referenced by scene_free_data().

◆ BKE_collection_from_index()

struct Collection* BKE_collection_from_index ( Scene scene,
const int  index 
)

Return Scene Collection for a given index.

The index is calculated from top to bottom counting the children before the siblings.

Definition at line 1734 of file collection.c.

References collection_from_index_recursive(), Scene::master_collection, and scene.

Referenced by move_to_collection_exec(), and move_to_collection_invoke().

◆ BKE_collection_has_collection()

bool BKE_collection_has_collection ( struct Collection parent,
struct Collection collection 
)

Definition at line 1545 of file collection.c.

References collection_find_child_recursive().

Referenced by outliner_collection_is_isolated().

◆ BKE_collection_has_object()

bool BKE_collection_has_object ( struct Collection collection,
const struct Object ob 
)

◆ BKE_collection_has_object_recursive()

bool BKE_collection_has_object_recursive ( struct Collection collection,
struct Object ob 
)

◆ BKE_collection_has_object_recursive_instanced()

bool BKE_collection_has_object_recursive_instanced ( struct Collection collection,
struct Object ob 
)

◆ BKE_collection_is_empty()

bool BKE_collection_is_empty ( const struct Collection collection)

◆ BKE_collection_is_in_scene()

bool BKE_collection_is_in_scene ( struct Collection collection)

◆ BKE_collection_master_add()

struct Collection* BKE_collection_master_add ( void  )

◆ BKE_collection_move()

bool BKE_collection_move ( struct Main bmain,
struct Collection to_parent,
struct Collection from_parent,
struct Collection relative,
bool  relative_after,
struct Collection collection 
)

◆ BKE_collection_new_name_get()

void BKE_collection_new_name_get ( Collection collection_parent,
char *  rname 
)

◆ BKE_collection_object_add()

bool BKE_collection_object_add ( Main bmain,
Collection collection,
Object ob 
)

◆ BKE_collection_object_add_from()

void BKE_collection_object_add_from ( Main bmain,
Scene scene,
Object ob_src,
Object ob_dst 
)

◆ BKE_collection_object_cache_free()

void BKE_collection_object_cache_free ( struct Collection collection)

◆ BKE_collection_object_cache_get()

struct ListBase BKE_collection_object_cache_get ( struct Collection collection)

◆ BKE_collection_object_cache_instanced_get()

ListBase BKE_collection_object_cache_instanced_get ( struct Collection collection)

◆ BKE_collection_object_cyclic_check()

bool BKE_collection_object_cyclic_check ( struct Main bmain,
struct Object object,
struct Collection collection 
)

◆ BKE_collection_object_find()

struct Collection* BKE_collection_object_find ( struct Main bmain,
struct Scene scene,
struct Collection collection,
struct Object ob 
)

◆ BKE_collection_object_move()

void BKE_collection_object_move ( Main bmain,
Scene scene,
Collection collection_dst,
Collection collection_src,
Object ob 
)

Move object from a collection into another

If source collection is NULL move it from all the existing collections.

Definition at line 1367 of file collection.c.

References BKE_collection_object_add(), BKE_collection_object_remove(), NULL, scene, and scene_collections_object_remove().

Referenced by collection_drop_invoke(), and move_to_collection_exec().

◆ BKE_collection_object_remove()

bool BKE_collection_object_remove ( Main bmain,
Collection collection,
Object ob,
const bool  free_us 
)

◆ BKE_collection_objects_select()

bool BKE_collection_objects_select ( ViewLayer view_layer,
Collection collection,
bool  deselect 
)

Select all the objects in this Collection (and its nested collections) for this ViewLayer. Return true if any object was selected.

Definition at line 1781 of file collection.c.

References BKE_layer_collection_first_from_scene_collection(), BKE_layer_collection_objects_select(), collection_objects_select(), and NULL.

◆ BKE_collection_or_layer_objects()

struct Base* BKE_collection_or_layer_objects ( const struct ViewLayer view_layer,
struct Collection collection 
)

◆ BKE_collection_parent_relations_rebuild()

void BKE_collection_parent_relations_rebuild ( Collection collection)

Rebuild parent relationships from child ones, for all children of given collection.

Note
Given collection is assumed to already have valid parents.

Definition at line 1636 of file collection.c.

References BKE_collection_cycle_find(), BLI_addtail(), BLI_freelinkN(), Collection::children, CollectionParent::collection, collection_find_child(), LISTBASE_FOREACH_MUTABLE, MEM_callocN, and NULL.

Referenced by collection_parents_rebuild_recursive().

◆ BKE_collection_ui_name_get()

const char* BKE_collection_ui_name_get ( struct Collection collection)

◆ BKE_collections_after_lib_link()

void BKE_collections_after_lib_link ( struct Main bmain)

Definition at line 1406 of file collection.c.

References BKE_main_collection_sync().

Referenced by blo_read_file_internal(), and library_link_end().

◆ BKE_collections_child_remove_nulls()

void BKE_collections_child_remove_nulls ( Main bmain,
Collection parent_collection,
Collection child_collection 
)

Remove all NULL children from parent collections of changed collection. This is used for library remapping, where these pointers have been set to NULL. Otherwise this should never happen.

Note
caller must ensure BKE_main_collection_sync_remap() is called afterwards!
Parameters
parent_collectionThe collection owning the pointers that were remapped. May be NULL, in which case whole bmain database of collections is checked.
child_collectionThe collection that was remapped to another pointer. May be NULL, in which case whole bmain database of collections is checked.

Definition at line 1318 of file collection.c.

References BLI_freelinkN(), collection_find_child(), collection_missing_parents_remove(), collection_null_children_remove(), Main::collections, ListBase::first, Collection::id, Scene::id, Scene::master_collection, ID::next, NULL, Collection::parents, scene, and Main::scenes.

Referenced by libblock_remap_data_postprocess_collection_update().

◆ BKE_collections_object_remove_nulls()

void BKE_collections_object_remove_nulls ( struct Main bmain)

◆ BKE_main_collections_parent_relations_rebuild()

void BKE_main_collections_parent_relations_rebuild ( Main bmain)

◆ BKE_scene_collections_iterator_begin()

void BKE_scene_collections_iterator_begin ( BLI_Iterator iter,
void *  data_in 
)

Only use this in non-performance critical situations (it iterates over all scene collections twice)

Definition at line 2048 of file collection.c.

References BLI_assert, BLI_ITERATOR_INIT, BLI_Iterator::current, BLI_Iterator::data, data, MEM_callocN, scene, and scene_collections_array().

Referenced by scene_objects_iterator_begin().

◆ BKE_scene_collections_iterator_end()

void BKE_scene_collections_iterator_end ( struct BLI_Iterator iter)

Definition at line 2077 of file collection.c.

References BLI_Iterator::data, data, MEM_freeN, and BLI_Iterator::valid.

Referenced by BKE_scene_objects_iterator_end().

◆ BKE_scene_collections_iterator_next()

void BKE_scene_collections_iterator_next ( struct BLI_Iterator iter)

◆ BKE_scene_collections_object_remove()

bool BKE_scene_collections_object_remove ( Main bmain,
Scene scene,
Object ob,
const bool  free_us 
)

◆ BKE_scene_objects_as_gset()

struct GSet* BKE_scene_objects_as_gset ( Scene scene,
GSet objects_gset 
)

Generate a new GSet (or extend given objects_gset if not NULL) with all objects referenced by all collections of given scene.

Note
: This will include objects without a base currently (because they would belong to excluded collections only e.g.).

Definition at line 2196 of file collection.c.

References BKE_scene_objects_iterator_end(), BKE_scene_objects_iterator_next(), BLI_Iterator::data, NULL, scene, scene_objects_iterator_begin(), and BLI_Iterator::valid.

Referenced by lib_override_library_create_post_process().

◆ BKE_scene_objects_iterator_begin()

void BKE_scene_objects_iterator_begin ( struct BLI_Iterator iter,
void *  data_in 
)

Definition at line 2122 of file collection.c.

References NULL, scene, and scene_objects_iterator_begin().

◆ BKE_scene_objects_iterator_end()

void BKE_scene_objects_iterator_end ( struct BLI_Iterator iter)

◆ BKE_scene_objects_iterator_next()

void BKE_scene_objects_iterator_next ( struct BLI_Iterator iter)