Blender V4.3
collection.cc File Reference
#include "CLG_log.h"
#include <cstring>
#include <optional>
#include "BLI_blenlib.h"
#include "BLI_iterator.h"
#include "BLI_listbase.h"
#include "BLI_math_base.h"
#include "BLI_string_utils.hh"
#include "BLI_threads.h"
#include "BLT_translation.hh"
#include "BKE_anim_data.hh"
#include "BKE_collection.hh"
#include "BKE_idprop.hh"
#include "BKE_idtype.hh"
#include "BKE_layer.hh"
#include "BKE_lib_id.hh"
#include "BKE_lib_query.hh"
#include "BKE_lib_remap.hh"
#include "BKE_main.hh"
#include "BKE_object.hh"
#include "BKE_preview_image.hh"
#include "BKE_report.hh"
#include "BKE_rigidbody.h"
#include "BKE_scene.hh"
#include "DNA_defaults.h"
#include "DNA_ID.h"
#include "DNA_collection_types.h"
#include "DNA_layer_types.h"
#include "DNA_object_types.h"
#include "DNA_rigidbody_types.h"
#include "DNA_scene_types.h"
#include "DEG_depsgraph.hh"
#include "DEG_depsgraph_query.hh"
#include "MEM_guardedalloc.h"
#include "BLO_read_write.hh"

Go to the source code of this file.

Classes

struct  CollectionsIteratorData
 
struct  SceneObjectsIteratorData
 

Macros

#define DNA_DEPRECATED_ALLOW
 

Functions

Prototypes

Extra asserts that #Collection.gobject_hash is valid which are too slow even for debug mode.

static bool collection_child_add (Main *bmain, Collection *parent, Collection *collection, const CollectionLightLinking *light_linking, const int id_create_flag, const bool add_us)
 
static bool collection_child_remove (Main *bmain, Collection *parent, Collection *collection, const int id_create_flag)
 
static bool collection_object_add (Main *bmain, Collection *collection, Object *ob, CollectionLightLinking *light_linking, const int id_create_flag, const bool add_us)
 
static void collection_object_remove_no_gobject_hash (Main *bmain, Collection *collection, CollectionObject *cob, const int id_create_flag, const bool free_us)
 
static bool collection_object_remove (Main *bmain, Collection *collection, Object *ob, const int id_create_flag, const bool free_us)
 
static CollectionParentcollection_find_parent (Collection *child, Collection *collection)
 
static bool collection_find_child_recursive (const Collection *parent, const Collection *collection)
 
static void collection_object_cache_free (const Main *bmain, Collection *collection, const int id_create_flag, const uint id_recalc_flag)
 
static void collection_gobject_hash_ensure (Collection *collection)
 
static void collection_gobject_hash_update_object (Collection *collection, Object *ob_old, CollectionObject *cob)
 
static void collection_exporter_copy (Collection *collection, CollectionExport *data)
 
Add Collection
static Collectioncollection_add (Main *bmain, Collection *collection_parent, const char *name_custom)
 
CollectionBKE_collection_add (Main *bmain, Collection *collection_parent, const char *name_custom)
 
void BKE_collection_add_from_object (Main *bmain, Scene *scene, const Object *ob_src, Collection *collection_dst)
 
void BKE_collection_add_from_collection (Main *bmain, Scene *scene, Collection *collection_src, Collection *collection_dst)
 
Free and Delete Collection
void BKE_collection_free_data (Collection *collection)
 
void BKE_collection_exporter_name_set (const ListBase *exporters, CollectionExport *data, const char *newname)
 
void BKE_collection_exporter_free_data (CollectionExport *data)
 
bool BKE_collection_delete (Main *bmain, Collection *collection, bool hierarchy)
 
Collection Copy
static Collectioncollection_duplicate_recursive (Main *bmain, Collection *parent, Collection *collection_old, CollectionChild *child_old, const int id_create_flag, const eDupli_ID_Flags duplicate_flags, const eLibIDDuplicateFlags duplicate_options)
 
CollectionBKE_collection_duplicate (Main *bmain, Collection *parent, CollectionChild *child_old, Collection *collection, uint duplicate_flags, uint duplicate_options)
 
Collection Naming
void BKE_collection_new_name_get (Collection *collection_parent, char *rname)
 
const char * BKE_collection_ui_name_get (Collection *collection)
 
Object List Cache
static void collection_object_cache_fill (ListBase *lb, Collection *collection, int parent_restrict, bool with_instances)
 
ListBase BKE_collection_object_cache_get (Collection *collection)
 
ListBase BKE_collection_object_cache_instanced_get (Collection *collection)
 
static void collection_object_cache_free_parent_recursive (const Main *bmain, Collection *collection, const int id_create_flag, const uint id_recalc_flag)
 
void BKE_collection_object_cache_free (const Main *bmain, Collection *collection, const int id_create_flag)
 
void BKE_main_collections_object_cache_free (const Main *bmain)
 
BaseBKE_collection_or_layer_objects (const Scene *scene, ViewLayer *view_layer, Collection *collection)
 
Scene Master Collection
CollectionBKE_collection_master_add (Scene *scene)
 
Cyclic Checks
static bool collection_object_cyclic_check_internal (Object *object, Collection *collection)
 
bool BKE_collection_object_cyclic_check (Main *bmain, Object *object, Collection *collection)
 
Collection Object Membership
bool BKE_collection_has_object (Collection *collection, const Object *ob)
 
bool BKE_collection_has_object_recursive (Collection *collection, Object *ob)
 
bool BKE_collection_has_object_recursive_instanced (Collection *collection, Object *ob)
 
bool BKE_collection_has_object_recursive_instanced_orig_id (Collection *collection_eval, Object *object_eval)
 
static Collectioncollection_next_find (Main *bmain, Scene *scene, Collection *collection)
 
CollectionBKE_collection_object_find (Main *bmain, Scene *scene, Collection *collection, Object *ob)
 
bool BKE_collection_is_empty (const Collection *collection)
 
Collection Objects
static void collection_gobject_assert_internal_consistency (Collection *collection, const bool do_extensive_check)
 
static GHashcollection_gobject_hash_alloc (const Collection *collection)
 
static void collection_gobject_hash_create (Collection *collection)
 
static void collection_gobject_hash_ensure_fix (Main *bmain, Collection *collection)
 
CollectionBKE_collection_parent_editable_find_recursive (const ViewLayer *view_layer, Collection *collection)
 
bool BKE_collection_object_add_notest (Main *bmain, Collection *collection, Object *ob)
 
bool BKE_collection_object_add (Main *bmain, Collection *collection, Object *ob)
 
bool BKE_collection_viewlayer_object_add (Main *bmain, const ViewLayer *view_layer, Collection *collection, Object *ob)
 
void BKE_collection_object_add_from (Main *bmain, Scene *scene, Object *ob_src, Object *ob_dst)
 
bool BKE_collection_object_remove (Main *bmain, Collection *collection, Object *ob, const bool free_us)
 
bool BKE_collection_object_replace (Main *bmain, Collection *collection, Object *ob_old, Object *ob_new)
 
static bool scene_collections_object_remove (Main *bmain, Scene *scene, Object *ob, const bool free_us, Collection *collection_skip)
 
bool BKE_scene_collections_object_remove (Main *bmain, Scene *scene, Object *ob, const bool free_us)
 
void BKE_collections_object_remove_invalids (Main *bmain)
 
static void collection_null_children_remove (Collection *collection)
 
static void collection_missing_parents_remove (Collection *collection)
 
void BKE_collections_child_remove_nulls (Main *bmain, Collection *parent_collection, Collection *child_collection)
 
void BKE_collection_object_move (Main *bmain, Scene *scene, Collection *collection_dst, Collection *collection_src, Object *ob)
 
Collection Scene Membership
bool BKE_collection_is_in_scene (Collection *collection)
 
void BKE_collections_after_lib_link (Main *bmain)
 
Collection Children
static bool collection_instance_find_recursive (Collection *collection, Collection *instance_collection)
 
bool BKE_collection_cycle_find (Collection *new_ancestor, Collection *collection)
 
static bool collection_instance_fix_recursive (Collection *parent_collection, Collection *collection)
 
static bool collection_cycle_fix_recursive (Main *bmain, Collection *parent_collection, Collection *collection)
 
bool BKE_collection_cycles_fix (Main *bmain, Collection *collection)
 
CollectionChildBKE_collection_child_find (Collection *parent, Collection *collection)
 
bool BKE_collection_has_collection (const Collection *parent, const Collection *collection)
 
bool BKE_collection_child_add (Main *bmain, Collection *parent, Collection *child)
 
bool BKE_collection_child_add_no_sync (Main *bmain, Collection *parent, Collection *child)
 
bool BKE_collection_child_remove (Main *bmain, Collection *parent, Collection *child)
 
void BKE_collection_parent_relations_rebuild (Collection *collection)
 
static void collection_parents_rebuild_recursive (Collection *collection)
 
void BKE_main_collections_parent_relations_rebuild (Main *bmain)
 
bool BKE_collection_validate (Collection *collection)
 
Collection Index
static Collectioncollection_from_index_recursive (Collection *collection, const int index, int *index_current)
 
CollectionBKE_collection_from_index (Scene *scene, const int index)
 
static bool collection_objects_select (const Scene *scene, ViewLayer *view_layer, Collection *collection, bool deselect)
 
bool BKE_collection_objects_select (const Scene *scene, ViewLayer *view_layer, Collection *collection, bool deselect)
 
Collection move (outliner drag & drop)
bool BKE_collection_move (Main *bmain, Collection *to_parent, Collection *from_parent, Collection *relative, bool relative_after, Collection *collection)
 
Iterators
static void scene_collection_callback (Collection *collection, BKE_scene_collections_Cb callback, void *data)
 
static void scene_collections_count (Collection *, void *data)
 
static void scene_collections_build_array (Collection *collection, void *data)
 
static void scene_collections_array (Scene *scene, Collection ***r_collections_array, int *r_collections_array_len)
 
void BKE_scene_collections_iterator_begin (BLI_Iterator *iter, void *data_in)
 
void BKE_scene_collections_iterator_next (BLI_Iterator *iter)
 
void BKE_scene_collections_iterator_end (BLI_Iterator *iter)
 
static void scene_objects_iterator_begin (BLI_Iterator *iter, Scene *scene, GSet *visited_objects)
 
void BKE_scene_objects_iterator_begin (BLI_Iterator *iter, void *data_in)
 
static void scene_objects_iterator_skip_invalid_flag (BLI_Iterator *iter)
 
void BKE_scene_objects_iterator_begin_ex (BLI_Iterator *iter, void *data_in)
 
void BKE_scene_objects_iterator_next_ex (BLI_Iterator *iter)
 
void BKE_scene_objects_iterator_end_ex (BLI_Iterator *iter)
 
static CollectionObjectobject_base_unique (GSet *gs, CollectionObject *cob)
 
void BKE_scene_objects_iterator_next (BLI_Iterator *iter)
 
void BKE_scene_objects_iterator_end (BLI_Iterator *iter)
 
GSetBKE_scene_objects_as_gset (Scene *scene, GSet *objects_gset)
 

Variables

static CLG_LogRef LOG = {"bke.collection"}
 

Collection Data-Block

IDTypeInfo IDType_ID_GR
 
static void collection_init_data (ID *id)
 
static void collection_copy_data (Main *bmain, std::optional< Library * >, ID *id_dst, const ID *id_src, const int flag)
 
static void collection_free_data (ID *id)
 
static void collection_foreach_id (ID *id, LibraryForeachIDData *data)
 
static ID ** collection_owner_pointer_get (ID *id, const bool debug_relationship_assert)
 
void BKE_collection_blend_write_prepare_nolib (BlendWriter *, Collection *collection)
 
void BKE_collection_blend_write_nolib (BlendWriter *writer, Collection *collection)
 
static void collection_blend_write (BlendWriter *writer, ID *id, const void *id_address)
 
void BKE_collection_blend_read_data (BlendDataReader *reader, Collection *collection, ID *owner_id)
 
static void collection_blend_read_data (BlendDataReader *reader, ID *id)
 
static void collection_blend_read_after_liblink (BlendLibReader *, ID *id)
 

Macro Definition Documentation

◆ DNA_DEPRECATED_ALLOW

#define DNA_DEPRECATED_ALLOW

Definition at line 10 of file collection.cc.

Function Documentation

◆ BKE_collection_add()

◆ 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 478 of file collection.cc.

References BKE_collection_child_find(), BKE_main_collection_sync(), collection_child_add(), FOREACH_SCENE_COLLECTION_BEGIN, FOREACH_SCENE_COLLECTION_END, ID_IS_EDITABLE, and ID_IS_OVERRIDE_LIBRARY.

Referenced by lib_override_library_create_post_process().

◆ BKE_collection_add_from_object()

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

Add collection_dst to all scene collections that reference object ob_src is in. Used to replace an instance object with a collection (library override operator).

Logic is very similar to BKE_collection_object_add_from().

Definition at line 454 of file collection.cc.

References BKE_collection_has_object(), BKE_main_collection_sync(), collection_child_add(), FOREACH_SCENE_COLLECTION_BEGIN, FOREACH_SCENE_COLLECTION_END, ID_IS_LINKED, and ID_IS_OVERRIDABLE_LIBRARY.

Referenced by lib_override_library_create_post_process().

◆ BKE_collection_blend_read_data()

◆ BKE_collection_blend_write_nolib()

void BKE_collection_blend_write_nolib ( BlendWriter * writer,
Collection * collection )

◆ BKE_collection_blend_write_prepare_nolib()

void BKE_collection_blend_write_prepare_nolib ( BlendWriter * writer,
Collection * collection )

Perform some pre-writing cleanup on the COllection data itself (not in any sub-data referenced by pointers). To be called before writing the Collection struct itself.

Definition at line 269 of file collection.cc.

Referenced by collection_blend_write(), and scene_blend_write().

◆ BKE_collection_child_add()

◆ BKE_collection_child_add_no_sync()

bool BKE_collection_child_add_no_sync ( Main * bmain,
Collection * parent,
Collection * child )

◆ BKE_collection_child_find()

◆ BKE_collection_child_remove()

◆ 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 1750 of file collection.cc.

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

Referenced by BKE_collection_cycle_find(), BKE_collection_move(), BKE_collection_parent_relations_rebuild(), BKE_collection_validate(), blender::ed::object::collection_add_info_get_from_op(), collection_child_add(), collection_cycle_fix_recursive(), and blender::ed::outliner::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 1814 of file collection.cc.

References collection_cycle_fix_recursive(), and collection_instance_fix_recursive().

Referenced by do_versions_after_linking_290().

◆ BKE_collection_delete()

◆ BKE_collection_duplicate()

Collection * BKE_collection_duplicate ( Main * bmain,
Collection * parent,
CollectionChild * child_old,
Collection * collection,
uint duplicate_flags,
uint duplicate_options )

Make a deep copy (aka duplicate) of the given collection and all of its children, recursively.

Warning
This functions will clear all bmain #ID.idnew pointers, unless LIB_ID_DUPLICATE_IS_SUBPROCESS duplicate option is passed on, in which case caller is responsible to reconstruct collection dependencies information's (i.e. call BKE_main_collection_sync).

Definition at line 727 of file collection.cc.

References BKE_libblock_relink_to_newid(), BKE_main_collection_sync(), BKE_main_id_newptr_and_tag_clear(), BLI_assert, collection_duplicate_recursive(), FOREACH_MAIN_ID_BEGIN, FOREACH_MAIN_ID_END, Collection::id, ID_IS_LINKED, ID_TAG_NEW, ID_TAG_NO_MAIN, LIB_ID_CREATE_NO_MAIN, LIB_ID_DUPLICATE_IS_ROOT_ID, LIB_ID_DUPLICATE_IS_SUBPROCESS, ID::tag, and USER_DUP_LINKED_ID.

Referenced by BKE_scene_duplicate(), and blender::ed::outliner::collection_duplicate_exec().

◆ BKE_collection_exporter_free_data()

void BKE_collection_exporter_free_data ( CollectionExport * data)

Free all data owned by the collection exporter.

Definition at line 533 of file collection.cc.

References IDP_FreeProperty().

Referenced by blender::ed::object::collection_exporter_remove_exec(), and collection_free_data().

◆ BKE_collection_exporter_name_set()

void BKE_collection_exporter_name_set ( const ListBase * exporters,
CollectionExport * data,
const char * newname )

Assigns a unique name to the collection exporter.

Definition at line 519 of file collection.cc.

References BLI_listbase_from_link(), BLI_uniquename(), offsetof, and STRNCPY.

Referenced by blender::ed::object::collection_exporter_add_exec().

◆ BKE_collection_free_data()

void BKE_collection_free_data ( Collection * collection)

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

Definition at line 513 of file collection.cc.

References BKE_libblock_free_data(), and collection_free_data().

Referenced by scene_free_data().

◆ BKE_collection_from_index()

Collection * BKE_collection_from_index ( Scene * scene,
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 2087 of file collection.cc.

References collection_from_index_recursive().

Referenced by blender::ed::object::move_to_collection_exec(), and blender::ed::object::move_to_collection_invoke().

◆ BKE_collection_has_collection()

◆ BKE_collection_has_object()

◆ BKE_collection_has_object_recursive()

◆ BKE_collection_has_object_recursive_instanced()

bool BKE_collection_has_object_recursive_instanced ( Collection * collection,
Object * ob )

◆ BKE_collection_has_object_recursive_instanced_orig_id()

bool BKE_collection_has_object_recursive_instanced_orig_id ( Collection * collection_eval,
Object * object_eval )

Find whether an evaluated object's original ID is contained or instanced by any object in this collection. The collection is expected to be an evaluated data-block too.

Definition at line 1084 of file collection.cc.

References BKE_collection_object_cache_instanced_get(), BLI_assert, DEG_get_original_id(), Collection::id, Object::id, ID_TAG_COPIED_ON_EVAL, LISTBASE_FOREACH, and ID::tag.

Referenced by blender::nodes::node_geo_collection_info_cc::node_geo_exec().

◆ BKE_collection_is_empty()

bool BKE_collection_is_empty ( const Collection * collection)

◆ BKE_collection_is_in_scene()

◆ BKE_collection_master_add()

◆ BKE_collection_move()

◆ 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 )

Add object to given collection, ensuring this collection is 'editable' (i.e. local and not a liboverride), and finding a suitable parent one otherwise.

Definition at line 1468 of file collection.cc.

References BKE_collection_viewlayer_object_add().

Referenced by bc_add_object(), BKE_collection_object_move(), BKE_object_add_for_data(), blender::ed::object::collection_add_exec(), blender::ed::object::collection_create_exec(), blender::ed::outliner::collection_drop_invoke(), blender::ed::object::collection_link_exec(), blender::io::usd::USDStageReader::create_proto_collections(), ED_rigidbody_constraint_add(), blender::io::obj::geometry_to_blender_objects(), blender::io::usd::import_endjob(), import_endjob(), blender::io::ply::importer_main(), blender::io::stl::importer_main(), lib_override_library_create_post_process(), light_linking_collection_add_object(), loose_data_instantiate_object_base_instance_init(), blender::ed::object::make_links_data_exec(), blender::ed::object::make_links_scene_exec(), blender::ed::object::make_local_all__instance_indirect_unused(), blender::ed::object::move_to_collection_exec(), Freestyle::BlenderStrokeRenderer::NewMesh(), blender::ed::object::object_add_sync_base_collection(), blender::ed::object::object_add_sync_rigid_body(), object_preview_scene_create(), blender::ed::object::objects_add_active_exec(), blender::ed::outliner::scene_drop_invoke(), blender::bke::tests::WholeIDTestData::setup(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), and ui_template_id_liboverride_hierarchy_make().

◆ BKE_collection_object_add_from()

◆ BKE_collection_object_add_notest()

bool BKE_collection_object_add_notest ( Main * bmain,
Collection * collection,
Object * ob )

Same as BKE_collection_object_add, but unconditionally adds the object to the given collection.

NOTE: required in certain cases, like do-versioning or complex ID management tasks.

Definition at line 1443 of file collection.cc.

References BKE_collection_is_in_scene(), BKE_main_collection_sync(), BLI_assert, collection_object_add(), ID_TAG_NO_MAIN, and LIB_ID_CREATE_NO_MAIN.

Referenced by BKE_collection_viewlayer_object_add(), do_version_layers_to_collections(), and do_versions_after_linking_280().

◆ BKE_collection_object_cache_free()

void BKE_collection_object_cache_free ( const Main * bmain,
Collection * collection,
const int id_create_flag )

Free the object cache of given collection and all of its ancestors (recursively).

Parameters
bmainThe Main database owning the collection. May be nullptr, only used if doing depsgraph tagging.
id_create_flagFlags controlling ID creation, used here to enable or not depsgraph tagging of affected IDs (e.g. LIB_ID_CREATE_NO_DEG_TAG would prevent depsgraph tagging).

Definition at line 946 of file collection.cc.

References BLI_assert, collection_object_cache_free_parent_recursive(), ID_RECALC_GEOMETRY, and ID_RECALC_HIERARCHY.

Referenced by BKE_collection_move(), collection_child_add(), collection_child_remove(), collection_gobject_hash_ensure_fix(), collection_object_add(), collection_object_remove_no_gobject_hash(), and blender::deg::deg_graph_build_finalize().

◆ BKE_collection_object_cache_get()

◆ BKE_collection_object_cache_instanced_get()

◆ BKE_collection_object_cyclic_check()

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

◆ BKE_collection_object_find()

◆ 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 1674 of file collection.cc.

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

Referenced by blender::ed::outliner::collection_drop_invoke(), and blender::ed::object::move_to_collection_exec().

◆ BKE_collection_object_remove()

◆ BKE_collection_object_replace()

bool BKE_collection_object_replace ( Main * bmain,
Collection * collection,
Object * ob_old,
Object * ob_new )

◆ BKE_collection_objects_select()

bool BKE_collection_objects_select ( const Scene * scene,
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 2134 of file collection.cc.

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

◆ BKE_collection_or_layer_objects()

◆ BKE_collection_parent_editable_find_recursive()

◆ 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 1937 of file collection.cc.

References BKE_collection_child_find(), BKE_collection_cycle_find(), BLI_addtail(), BLI_assert, BLI_freelinkN(), CollectionParent::collection, collection_find_parent(), ID_TAG_COPIED_ON_EVAL, ID_TAG_NO_MAIN, LISTBASE_FOREACH_MUTABLE, and MEM_callocN.

Referenced by collection_parents_rebuild_recursive().

◆ BKE_collection_ui_name_get()

const char * BKE_collection_ui_name_get ( Collection * collection)

◆ BKE_collection_validate()

bool BKE_collection_validate ( Collection * collection)

Perform some validation on integrity of the data of this collection.

Returns
true if everything is OK, false if some errors are detected.

Definition at line 2020 of file collection.cc.

References BKE_collection_cycle_find(), BLI_gset_clear(), BLI_gset_ensure_p_ex(), BLI_gset_free(), BLI_gset_ptr_new(), BLI_listbase_validate(), and LISTBASE_FOREACH.

◆ BKE_collection_viewlayer_object_add()

bool BKE_collection_viewlayer_object_add ( Main * bmain,
const ViewLayer * view_layer,
Collection * collection,
Object * ob )

Add object to given collection, similar to BKE_collection_object_add.

However, it additionally ensures that the selected collection is also part of the given view_layer, if non-NULL. Otherwise, the object is not added to any collection.

Definition at line 1473 of file collection.cc.

References BKE_collection_object_add_notest(), and BKE_collection_parent_editable_find_recursive().

Referenced by BKE_collection_object_add(), and BKE_object_add().

◆ BKE_collections_after_lib_link()

void BKE_collections_after_lib_link ( Main * bmain)

Definition at line 1713 of file collection.cc.

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 1635 of file collection.cc.

References BKE_collection_child_find(), BLI_freelinkN(), collection_missing_parents_remove(), collection_null_children_remove(), Main::collections, LISTBASE_FOREACH, LISTBASE_FOREACH_MUTABLE, Collection_Runtime::parents, Collection::runtime, and Main::scenes.

Referenced by libblock_remap_data_postprocess_collection_update().

◆ BKE_collections_object_remove_invalids()

void BKE_collections_object_remove_invalids ( Main * bmain)

Check all collections in bmain (including embedded ones in scenes) for invalid CollectionObject (either with NULL object pointer, or duplicates), and remove them.

Note
In case of duplicates, the first CollectionObject in the list is kept, all others are removed.

Definition at line 1604 of file collection.cc.

References collection_gobject_hash_ensure_fix(), Main::collections, LISTBASE_FOREACH, and Main::scenes.

Referenced by libblock_remap_data_postprocess_object_update().

◆ BKE_main_collections_object_cache_free()

void BKE_main_collections_object_cache_free ( const Main * bmain)

Free the object cache of all collections in given bmain, including master collections of scenes.

Definition at line 955 of file collection.cc.

References collection_object_cache_free(), Main::collections, ListBase::first, ID_RECALC_GEOMETRY, ID_RECALC_HIERARCHY, and Main::scenes.

Referenced by BKE_main_collection_sync_remap().

◆ 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 2262 of file collection.cc.

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

Referenced by scene_objects_iterator_begin().

◆ BKE_scene_collections_iterator_end()

void BKE_scene_collections_iterator_end ( BLI_Iterator * iter)

Definition at line 2292 of file collection.cc.

References BLI_Iterator::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 ( BLI_Iterator * iter)

◆ BKE_scene_collections_object_remove()

◆ BKE_scene_objects_as_gset()

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 2467 of file collection.cc.

References BKE_scene_objects_iterator_end(), BKE_scene_objects_iterator_next(), BLI_Iterator::data, 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 ( BLI_Iterator * iter,
void * data_in )

Definition at line 2338 of file collection.cc.

References scene_objects_iterator_begin().

Referenced by BKE_scene_objects_iterator_begin_ex().

◆ BKE_scene_objects_iterator_begin_ex()

void BKE_scene_objects_iterator_begin_ex ( BLI_Iterator * iter,
void * data_in )

◆ BKE_scene_objects_iterator_end()

◆ BKE_scene_objects_iterator_end_ex()

void BKE_scene_objects_iterator_end_ex ( BLI_Iterator * iter)

Definition at line 2393 of file collection.cc.

References BKE_scene_objects_iterator_end(), BLI_Iterator::data, and data.

◆ BKE_scene_objects_iterator_next()

◆ BKE_scene_objects_iterator_next_ex()

void BKE_scene_objects_iterator_next_ex ( BLI_Iterator * iter)

◆ collection_add()

static Collection * collection_add ( Main * bmain,
Collection * collection_parent,
const char * name_custom )
static

◆ collection_blend_read_after_liblink()

static void collection_blend_read_after_liblink ( BlendLibReader * ,
ID * id )
static

Definition at line 363 of file collection.cc.

References BLI_assert, BLI_freelinkN(), and LISTBASE_FOREACH_MUTABLE.

◆ collection_blend_read_data()

static void collection_blend_read_data ( BlendDataReader * reader,
ID * id )
static

Definition at line 357 of file collection.cc.

References BKE_collection_blend_read_data().

◆ collection_blend_write()

static void collection_blend_write ( BlendWriter * writer,
ID * id,
const void * id_address )
static

◆ collection_child_add()

◆ collection_child_remove()

static bool collection_child_remove ( Main * bmain,
Collection * parent,
Collection * collection,
const int id_create_flag )
static

◆ collection_copy_data()

static void collection_copy_data ( Main * bmain,
std::optional< Library * > ,
ID * id_dst,
const ID * id_src,
const int flag )
static

◆ collection_cycle_fix_recursive()

static bool collection_cycle_fix_recursive ( Main * bmain,
Collection * parent_collection,
Collection * collection )
static

◆ collection_duplicate_recursive()

◆ collection_exporter_copy()

◆ collection_find_child_recursive()

static bool collection_find_child_recursive ( const Collection * parent,
const Collection * collection )
static

◆ collection_find_parent()

static CollectionParent * collection_find_parent ( Collection * child,
Collection * collection )
static

◆ collection_foreach_id()

◆ collection_free_data()

◆ collection_from_index_recursive()

static Collection * collection_from_index_recursive ( Collection * collection,
const int index,
int * index_current )
static

◆ collection_gobject_assert_internal_consistency()

static void collection_gobject_assert_internal_consistency ( Collection * collection,
const bool do_extensive_check )
static

Validate the integrity of the collection's CollectionObject list, and of its mapping.

Simple test is very fast, as it only checks that the 'dirty' tag for collection's objects is not set.

The extensive check is expensive. This should not be done from within loops over collections items, or from low-level operations that can be assumed safe (like adding or removing an object from a collection). It ensures that:

Definition at line 1290 of file collection.cc.

References BLI_assert, BLI_ghash_lookup(), collection_gobject_hash_create(), COLLECTION_TAG_COLLECTION_OBJECT_DIRTY, LISTBASE_FOREACH, and UNUSED_VARS_NDEBUG.

Referenced by collection_gobject_hash_ensure(), and collection_gobject_hash_ensure_fix().

◆ collection_gobject_hash_alloc()

static GHash * collection_gobject_hash_alloc ( const Collection * collection)
static

◆ collection_gobject_hash_create()

◆ collection_gobject_hash_ensure()

static void collection_gobject_hash_ensure ( Collection * collection)
static

◆ collection_gobject_hash_ensure_fix()

◆ collection_gobject_hash_update_object()

static void collection_gobject_hash_update_object ( Collection * collection,
Object * ob_old,
CollectionObject * cob )
static

Update the collections object hash, removing ob_old, inserting cob->ob as the new key.

Note
This function is called from IDTypeInfo::foreach_id callback, and a difference of Object pointers is only expected in case ID remapping is happening. This code is the only are in Blender allowed to (temporarily) leave the CollectionObject list in an inconsistent/invalid state (with nullptr object pointers, or duplicates of #CollectionObjects). If such invalid cases are encountered, it will tag the collection objects list as dirty.
Parameters
ob_oldThe existing key to cob in the hash, not removed when nullptr.
cobThe cob->ob is to be used as the new key, when nullptr it's not added back into the hash.

Definition at line 1244 of file collection.cc.

References BLI_ghash_ensure_p(), BLI_ghash_popkey(), COLLECTION_TAG_COLLECTION_OBJECT_DIRTY, and CollectionObject::ob.

Referenced by collection_foreach_id().

◆ collection_init_data()

static void collection_init_data ( ID * id)
static

◆ collection_instance_find_recursive()

static bool collection_instance_find_recursive ( Collection * collection,
Collection * instance_collection )
static

◆ collection_instance_fix_recursive()

static bool collection_instance_fix_recursive ( Collection * parent_collection,
Collection * collection )
static

◆ collection_missing_parents_remove()

static void collection_missing_parents_remove ( Collection * collection)
static

◆ collection_next_find()

static Collection * collection_next_find ( Main * bmain,
Scene * scene,
Collection * collection )
static

Definition at line 1098 of file collection.cc.

References Main::collections, and ListBase::first.

Referenced by BKE_collection_object_find().

◆ collection_null_children_remove()

static void collection_null_children_remove ( Collection * collection)
static

Definition at line 1615 of file collection.cc.

References BLI_freelinkN(), and LISTBASE_FOREACH_MUTABLE.

Referenced by BKE_collections_child_remove_nulls().

◆ collection_object_add()

◆ collection_object_cache_fill()

◆ collection_object_cache_free()

static void collection_object_cache_free ( const Main * bmain,
Collection * collection,
const int id_create_flag,
const uint id_recalc_flag )
static

◆ collection_object_cache_free_parent_recursive()

static void collection_object_cache_free_parent_recursive ( const Main * bmain,
Collection * collection,
const int id_create_flag,
const uint id_recalc_flag )
static

Utils to recursively tag the parent hierarchy of a collection, matching the

Definition at line 926 of file collection.cc.

References collection_object_cache_free(), collection_object_cache_free_parent_recursive(), and LISTBASE_FOREACH.

Referenced by BKE_collection_object_cache_free(), and collection_object_cache_free_parent_recursive().

◆ collection_object_cyclic_check_internal()

◆ collection_object_remove()

static bool collection_object_remove ( Main * bmain,
Collection * collection,
Object * ob,
const int id_create_flag,
const bool free_us )
static

◆ collection_object_remove_no_gobject_hash()

static void collection_object_remove_no_gobject_hash ( Main * bmain,
Collection * collection,
CollectionObject * cob,
const int id_create_flag,
const bool free_us )
static
Parameters
id_create_flagCreation/Copy ID management flags, e.g. LIB_ID_CREATE_NO_MAIN.

A version of collection_object_remove that does not handle collection->runtime.gobject_hash, Either the caller must have removed the object from the hash or the hash may be nullptr.

Definition at line 1396 of file collection.cc.

References BKE_collection_object_cache_free(), BKE_id_free_us(), BLI_freelinkN(), Object::id, id_us_min(), and CollectionObject::ob.

Referenced by BKE_collection_delete(), BKE_collection_object_replace(), and collection_object_remove().

◆ collection_objects_select()

static bool collection_objects_select ( const Scene * scene,
ViewLayer * view_layer,
Collection * collection,
bool deselect )
static

◆ collection_owner_pointer_get()

static ID ** collection_owner_pointer_get ( ID * id,
const bool debug_relationship_assert )
static

◆ collection_parents_rebuild_recursive()

◆ object_base_unique()

static CollectionObject * object_base_unique ( GSet * gs,
CollectionObject * cob )
static

Ensures we only get each object once, even when included in several collections.

Definition at line 2409 of file collection.cc.

References BLI_gset_ensure_p_ex(), CollectionObject::next, and CollectionObject::ob.

Referenced by BKE_scene_objects_iterator_next().

◆ scene_collection_callback()

static void scene_collection_callback ( Collection * collection,
BKE_scene_collections_Cb callback,
void * data )
static

◆ scene_collections_array()

static void scene_collections_array ( Scene * scene,
Collection *** r_collections_array,
int * r_collections_array_len )
static

◆ scene_collections_build_array()

static void scene_collections_build_array ( Collection * collection,
void * data )
static

Definition at line 2232 of file collection.cc.

References data.

Referenced by scene_collections_array().

◆ scene_collections_count()

static void scene_collections_count ( Collection * ,
void * data )
static

Definition at line 2226 of file collection.cc.

References data.

Referenced by scene_collections_array().

◆ scene_collections_object_remove()

static bool scene_collections_object_remove ( Main * bmain,
Scene * scene,
Object * ob,
const bool free_us,
Collection * collection_skip )
static

◆ scene_objects_iterator_begin()

static void scene_objects_iterator_begin ( BLI_Iterator * iter,
Scene * scene,
GSet * visited_objects )
static

◆ scene_objects_iterator_skip_invalid_flag()

static void scene_objects_iterator_skip_invalid_flag ( BLI_Iterator * iter)
static

Variable Documentation

◆ IDType_ID_GR

IDTypeInfo IDType_ID_GR
Initial value:
= {
sizeof(Collection),
"Collection",
N_("collections"),
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
}
@ IDTYPE_FLAGS_APPEND_IS_REUSABLE
Definition BKE_idtype.hh:39
@ IDTYPE_FLAGS_NO_ANIMDATA
Definition BKE_idtype.hh:41
#define BLT_I18NCONTEXT_ID_COLLECTION
#define FILTER_ID_OB
Definition DNA_ID.h:1181
#define FILTER_ID_GR
Definition DNA_ID.h:1170
@ INDEX_ID_GR
Definition DNA_ID.h:1308
@ ID_GR
struct Collection Collection
static ID ** collection_owner_pointer_get(ID *id, const bool debug_relationship_assert)
static void collection_copy_data(Main *bmain, std::optional< Library * >, ID *id_dst, const ID *id_src, const int flag)
static void collection_free_data(ID *id)
static void collection_blend_read_data(BlendDataReader *reader, ID *id)
static void collection_blend_write(BlendWriter *writer, ID *id, const void *id_address)
static void collection_init_data(ID *id)
static void collection_blend_read_after_liblink(BlendLibReader *, ID *id)
static void collection_foreach_id(ID *id, LibraryForeachIDData *data)
#define N_(msgid)

Definition at line 382 of file collection.cc.

◆ LOG

CLG_LogRef LOG = {"bke.collection"}
static

Definition at line 56 of file collection.cc.

Referenced by BKE_collection_blend_read_data().