Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/layer.cc
- This file was moved from source/blender/blenkernel/intern/layer.c.
| Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
| static void object_bases_iterator_next(BLI_Iterator *iter, const int flag); | static void object_bases_iterator_next(BLI_Iterator *iter, const int flag); | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Layer Collections and Bases | /** \name Layer Collections and Bases | ||||
| * \{ */ | * \{ */ | ||||
| static LayerCollection *layer_collection_add(ListBase *lb_parent, Collection *collection) | static LayerCollection *layer_collection_add(ListBase *lb_parent, Collection *collection) | ||||
| { | { | ||||
| LayerCollection *lc = MEM_callocN(sizeof(LayerCollection), "Collection Base"); | LayerCollection *lc = MEM_cnew<LayerCollection>("Collection Base"); | ||||
| lc->collection = collection; | lc->collection = collection; | ||||
| lc->local_collections_bits = ~(0); | lc->local_collections_bits = ~(0); | ||||
| BLI_addtail(lb_parent, lc); | BLI_addtail(lb_parent, lc); | ||||
| return lc; | return lc; | ||||
| } | } | ||||
| static void layer_collection_free(ViewLayer *view_layer, LayerCollection *lc) | static void layer_collection_free(ViewLayer *view_layer, LayerCollection *lc) | ||||
| { | { | ||||
| if (lc == view_layer->active_collection) { | if (lc == view_layer->active_collection) { | ||||
| view_layer->active_collection = NULL; | view_layer->active_collection = NULL; | ||||
| } | } | ||||
| LISTBASE_FOREACH (LayerCollection *, nlc, &lc->layer_collections) { | LISTBASE_FOREACH (LayerCollection *, nlc, &lc->layer_collections) { | ||||
| layer_collection_free(view_layer, nlc); | layer_collection_free(view_layer, nlc); | ||||
| } | } | ||||
| BLI_freelistN(&lc->layer_collections); | BLI_freelistN(&lc->layer_collections); | ||||
| } | } | ||||
| static Base *object_base_new(Object *ob) | static Base *object_base_new(Object *ob) | ||||
| { | { | ||||
| Base *base = MEM_callocN(sizeof(Base), "Object Base"); | Base *base = MEM_cnew<Base>("Object Base"); | ||||
| base->object = ob; | base->object = ob; | ||||
| base->local_view_bits = ~(0); | base->local_view_bits = ~(0); | ||||
| if (ob->base_flag & BASE_SELECTED) { | if (ob->base_flag & BASE_SELECTED) { | ||||
| base->flag |= BASE_SELECTED; | base->flag |= BASE_SELECTED; | ||||
| } | } | ||||
| return base; | return base; | ||||
| } | } | ||||
| Show All 9 Lines | |||||
| { | { | ||||
| LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { | LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { | ||||
| if (!(view_layer->flag & VIEW_LAYER_RENDER)) { | if (!(view_layer->flag & VIEW_LAYER_RENDER)) { | ||||
| return view_layer; | return view_layer; | ||||
| } | } | ||||
| } | } | ||||
| BLI_assert(scene->view_layers.first); | BLI_assert(scene->view_layers.first); | ||||
| return scene->view_layers.first; | return static_cast<ViewLayer *>(scene->view_layers.first); | ||||
| } | } | ||||
| ViewLayer *BKE_view_layer_default_render(const Scene *scene) | ViewLayer *BKE_view_layer_default_render(const Scene *scene) | ||||
| { | { | ||||
| LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { | LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { | ||||
| if (view_layer->flag & VIEW_LAYER_RENDER) { | if (view_layer->flag & VIEW_LAYER_RENDER) { | ||||
| return view_layer; | return view_layer; | ||||
| } | } | ||||
| } | } | ||||
| BLI_assert(scene->view_layers.first); | BLI_assert(scene->view_layers.first); | ||||
| return scene->view_layers.first; | return static_cast<ViewLayer *>(scene->view_layers.first); | ||||
| } | } | ||||
| ViewLayer *BKE_view_layer_find(const Scene *scene, const char *layer_name) | ViewLayer *BKE_view_layer_find(const Scene *scene, const char *layer_name) | ||||
| { | { | ||||
| LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { | LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { | ||||
| if (STREQ(view_layer->name, layer_name)) { | if (STREQ(view_layer->name, layer_name)) { | ||||
| return view_layer; | return view_layer; | ||||
| } | } | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| ViewLayer *BKE_view_layer_context_active_PLACEHOLDER(const Scene *scene) | ViewLayer *BKE_view_layer_context_active_PLACEHOLDER(const Scene *scene) | ||||
| { | { | ||||
| BLI_assert(scene->view_layers.first); | BLI_assert(scene->view_layers.first); | ||||
| return scene->view_layers.first; | return static_cast<ViewLayer *>(scene->view_layers.first); | ||||
| } | } | ||||
| static ViewLayer *view_layer_add(const char *name) | static ViewLayer *view_layer_add(const char *name) | ||||
| { | { | ||||
| if (!name) { | if (!name) { | ||||
| name = DATA_("ViewLayer"); | name = DATA_("ViewLayer"); | ||||
| } | } | ||||
| ViewLayer *view_layer = MEM_callocN(sizeof(ViewLayer), "View Layer"); | ViewLayer *view_layer = MEM_cnew<ViewLayer>("View Layer"); | ||||
| view_layer->flag = VIEW_LAYER_RENDER | VIEW_LAYER_FREESTYLE; | view_layer->flag = VIEW_LAYER_RENDER | VIEW_LAYER_FREESTYLE; | ||||
| BLI_strncpy_utf8(view_layer->name, name, sizeof(view_layer->name)); | BLI_strncpy_utf8(view_layer->name, name, sizeof(view_layer->name)); | ||||
| /* Pure rendering pipeline settings. */ | /* Pure rendering pipeline settings. */ | ||||
| view_layer->layflag = SCE_LAY_FLAG_DEFAULT; | view_layer->layflag = SCE_LAY_FLAG_DEFAULT; | ||||
| view_layer->passflag = SCE_PASS_COMBINED; | view_layer->passflag = SCE_PASS_COMBINED; | ||||
| view_layer->pass_alpha_threshold = 0.5f; | view_layer->pass_alpha_threshold = 0.5f; | ||||
| view_layer->cryptomatte_levels = 6; | view_layer->cryptomatte_levels = 6; | ||||
| view_layer->cryptomatte_flag = VIEW_LAYER_CRYPTOMATTE_ACCURATE; | view_layer->cryptomatte_flag = VIEW_LAYER_CRYPTOMATTE_ACCURATE; | ||||
| BKE_freestyle_config_init(&view_layer->freestyle_config); | BKE_freestyle_config_init(&view_layer->freestyle_config); | ||||
| return view_layer; | return view_layer; | ||||
| } | } | ||||
| static void layer_collection_exclude_all(LayerCollection *layer_collection) | static void layer_collection_exclude_all(LayerCollection *layer_collection) | ||||
| { | { | ||||
| LayerCollection *sub_collection = layer_collection->layer_collections.first; | LayerCollection *sub_collection = static_cast<LayerCollection *>( | ||||
| layer_collection->layer_collections.first); | |||||
| for (; sub_collection != NULL; sub_collection = sub_collection->next) { | for (; sub_collection != NULL; sub_collection = sub_collection->next) { | ||||
| sub_collection->flag |= LAYER_COLLECTION_EXCLUDE; | sub_collection->flag |= LAYER_COLLECTION_EXCLUDE; | ||||
| layer_collection_exclude_all(sub_collection); | layer_collection_exclude_all(sub_collection); | ||||
| } | } | ||||
| } | } | ||||
| ViewLayer *BKE_view_layer_add(Scene *scene, | ViewLayer *BKE_view_layer_add(Scene *scene, | ||||
| const char *name, | const char *name, | ||||
| Show All 11 Lines | switch (type) { | ||||
| case VIEWLAYER_ADD_NEW: { | case VIEWLAYER_ADD_NEW: { | ||||
| view_layer_new = view_layer_add(name); | view_layer_new = view_layer_add(name); | ||||
| BLI_addtail(&scene->view_layers, view_layer_new); | BLI_addtail(&scene->view_layers, view_layer_new); | ||||
| BKE_layer_collection_sync(scene, view_layer_new); | BKE_layer_collection_sync(scene, view_layer_new); | ||||
| break; | break; | ||||
| } | } | ||||
| case VIEWLAYER_ADD_COPY: { | case VIEWLAYER_ADD_COPY: { | ||||
| /* Allocate and copy view layer data */ | /* Allocate and copy view layer data */ | ||||
| view_layer_new = MEM_callocN(sizeof(ViewLayer), "View Layer"); | view_layer_new = MEM_cnew<ViewLayer>("View Layer"); | ||||
| *view_layer_new = *view_layer_source; | *view_layer_new = *view_layer_source; | ||||
| BKE_view_layer_copy_data(scene, scene, view_layer_new, view_layer_source, 0); | BKE_view_layer_copy_data(scene, scene, view_layer_new, view_layer_source, 0); | ||||
| BLI_addtail(&scene->view_layers, view_layer_new); | BLI_addtail(&scene->view_layers, view_layer_new); | ||||
| BLI_strncpy_utf8(view_layer_new->name, name, sizeof(view_layer_new->name)); | BLI_strncpy_utf8(view_layer_new->name, name, sizeof(view_layer_new->name)); | ||||
| break; | break; | ||||
| } | } | ||||
| case VIEWLAYER_ADD_EMPTY: { | case VIEWLAYER_ADD_EMPTY: { | ||||
| view_layer_new = view_layer_add(name); | view_layer_new = view_layer_add(name); | ||||
| BLI_addtail(&scene->view_layers, view_layer_new); | BLI_addtail(&scene->view_layers, view_layer_new); | ||||
| /* Initialize layer-collections. */ | /* Initialize layer-collections. */ | ||||
| BKE_layer_collection_sync(scene, view_layer_new); | BKE_layer_collection_sync(scene, view_layer_new); | ||||
| layer_collection_exclude_all(view_layer_new->layer_collections.first); | layer_collection_exclude_all( | ||||
| static_cast<LayerCollection *>(view_layer_new->layer_collections.first)); | |||||
| /* Update collections after changing visibility */ | /* Update collections after changing visibility */ | ||||
| BKE_layer_collection_sync(scene, view_layer_new); | BKE_layer_collection_sync(scene, view_layer_new); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| /* unique name */ | /* unique name */ | ||||
| ▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | |||||
| Base *BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob) | Base *BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob) | ||||
| { | { | ||||
| BLI_assert_msg((view_layer->flag & VIEW_LAYER_OUT_OF_SYNC) == 0, | BLI_assert_msg((view_layer->flag & VIEW_LAYER_OUT_OF_SYNC) == 0, | ||||
| "View layer out of sync, invoke BKE_view_layer_synced_ensure."); | "View layer out of sync, invoke BKE_view_layer_synced_ensure."); | ||||
| if (!view_layer->object_bases_hash) { | if (!view_layer->object_bases_hash) { | ||||
| view_layer_bases_hash_create(view_layer, false); | view_layer_bases_hash_create(view_layer, false); | ||||
| } | } | ||||
| return BLI_ghash_lookup(view_layer->object_bases_hash, ob); | return static_cast<Base *>(BLI_ghash_lookup(view_layer->object_bases_hash, ob)); | ||||
| } | } | ||||
| void BKE_view_layer_base_deselect_all(const Scene *scene, ViewLayer *view_layer) | void BKE_view_layer_base_deselect_all(const Scene *scene, ViewLayer *view_layer) | ||||
| { | { | ||||
| BKE_view_layer_synced_ensure(scene, view_layer); | BKE_view_layer_synced_ensure(scene, view_layer); | ||||
| LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) { | LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) { | ||||
| base->flag &= ~BASE_SELECTED; | base->flag &= ~BASE_SELECTED; | ||||
| } | } | ||||
| Show All 17 Lines | static void layer_aov_copy_data(ViewLayer *view_layer_dst, | ||||
| const ViewLayer *view_layer_src, | const ViewLayer *view_layer_src, | ||||
| ListBase *aovs_dst, | ListBase *aovs_dst, | ||||
| const ListBase *aovs_src) | const ListBase *aovs_src) | ||||
| { | { | ||||
| if (aovs_src != NULL) { | if (aovs_src != NULL) { | ||||
| BLI_duplicatelist(aovs_dst, aovs_src); | BLI_duplicatelist(aovs_dst, aovs_src); | ||||
| } | } | ||||
| ViewLayerAOV *aov_dst = aovs_dst->first; | ViewLayerAOV *aov_dst = static_cast<ViewLayerAOV *>(aovs_dst->first); | ||||
| const ViewLayerAOV *aov_src = aovs_src->first; | const ViewLayerAOV *aov_src = static_cast<const ViewLayerAOV *>(aovs_src->first); | ||||
| while (aov_dst != NULL) { | while (aov_dst != NULL) { | ||||
| BLI_assert(aov_src); | BLI_assert(aov_src); | ||||
| if (aov_src == view_layer_src->active_aov) { | if (aov_src == view_layer_src->active_aov) { | ||||
| view_layer_dst->active_aov = aov_dst; | view_layer_dst->active_aov = aov_dst; | ||||
| } | } | ||||
| aov_dst = aov_dst->next; | aov_dst = aov_dst->next; | ||||
| aov_src = aov_src->next; | aov_src = aov_src->next; | ||||
| } | } | ||||
| } | } | ||||
| static void layer_lightgroup_copy_data(ViewLayer *view_layer_dst, | static void layer_lightgroup_copy_data(ViewLayer *view_layer_dst, | ||||
| const ViewLayer *view_layer_src, | const ViewLayer *view_layer_src, | ||||
| ListBase *lightgroups_dst, | ListBase *lightgroups_dst, | ||||
| const ListBase *lightgroups_src) | const ListBase *lightgroups_src) | ||||
| { | { | ||||
| if (lightgroups_src != NULL) { | if (lightgroups_src != NULL) { | ||||
| BLI_duplicatelist(lightgroups_dst, lightgroups_src); | BLI_duplicatelist(lightgroups_dst, lightgroups_src); | ||||
| } | } | ||||
| ViewLayerLightgroup *lightgroup_dst = lightgroups_dst->first; | ViewLayerLightgroup *lightgroup_dst = static_cast<ViewLayerLightgroup *>(lightgroups_dst->first); | ||||
| const ViewLayerLightgroup *lightgroup_src = lightgroups_src->first; | const ViewLayerLightgroup *lightgroup_src = static_cast<const ViewLayerLightgroup *>( | ||||
| lightgroups_src->first); | |||||
| while (lightgroup_dst != NULL) { | while (lightgroup_dst != NULL) { | ||||
| BLI_assert(lightgroup_src); | BLI_assert(lightgroup_src); | ||||
| if (lightgroup_src == view_layer_src->active_lightgroup) { | if (lightgroup_src == view_layer_src->active_lightgroup) { | ||||
| view_layer_dst->active_lightgroup = lightgroup_dst; | view_layer_dst->active_lightgroup = lightgroup_dst; | ||||
| } | } | ||||
| lightgroup_dst = lightgroup_dst->next; | lightgroup_dst = lightgroup_dst->next; | ||||
| lightgroup_src = lightgroup_src->next; | lightgroup_src = lightgroup_src->next; | ||||
| } | } | ||||
| } | } | ||||
| static void layer_collections_copy_data(ViewLayer *view_layer_dst, | static void layer_collections_copy_data(ViewLayer *view_layer_dst, | ||||
| const ViewLayer *view_layer_src, | const ViewLayer *view_layer_src, | ||||
| ListBase *layer_collections_dst, | ListBase *layer_collections_dst, | ||||
| const ListBase *layer_collections_src) | const ListBase *layer_collections_src) | ||||
| { | { | ||||
| BLI_duplicatelist(layer_collections_dst, layer_collections_src); | BLI_duplicatelist(layer_collections_dst, layer_collections_src); | ||||
| LayerCollection *layer_collection_dst = layer_collections_dst->first; | LayerCollection *layer_collection_dst = static_cast<LayerCollection *>( | ||||
| const LayerCollection *layer_collection_src = layer_collections_src->first; | layer_collections_dst->first); | ||||
| const LayerCollection *layer_collection_src = static_cast<const LayerCollection *>( | |||||
| layer_collections_src->first); | |||||
| while (layer_collection_dst != NULL) { | while (layer_collection_dst != NULL) { | ||||
| layer_collections_copy_data(view_layer_dst, | layer_collections_copy_data(view_layer_dst, | ||||
| view_layer_src, | view_layer_src, | ||||
| &layer_collection_dst->layer_collections, | &layer_collection_dst->layer_collections, | ||||
| &layer_collection_src->layer_collections); | &layer_collection_src->layer_collections); | ||||
| if (layer_collection_src == view_layer_src->active_collection) { | if (layer_collection_src == view_layer_src->active_collection) { | ||||
| Show All 25 Lines | void BKE_view_layer_copy_data(Scene *scene_dst, | ||||
| view_layer_dst->object_bases_hash = NULL; | view_layer_dst->object_bases_hash = NULL; | ||||
| /* Copy layer collections and object bases. */ | /* Copy layer collections and object bases. */ | ||||
| /* Inline 'BLI_duplicatelist' and update the active base. */ | /* Inline 'BLI_duplicatelist' and update the active base. */ | ||||
| BLI_listbase_clear(&view_layer_dst->object_bases); | BLI_listbase_clear(&view_layer_dst->object_bases); | ||||
| BLI_assert_msg((view_layer_src->flag & VIEW_LAYER_OUT_OF_SYNC) == 0, | BLI_assert_msg((view_layer_src->flag & VIEW_LAYER_OUT_OF_SYNC) == 0, | ||||
| "View Layer Object Base out of sync, invoke BKE_view_layer_synced_ensure."); | "View Layer Object Base out of sync, invoke BKE_view_layer_synced_ensure."); | ||||
| LISTBASE_FOREACH (const Base *, base_src, &view_layer_src->object_bases) { | LISTBASE_FOREACH (const Base *, base_src, &view_layer_src->object_bases) { | ||||
| Base *base_dst = MEM_dupallocN(base_src); | Base *base_dst = static_cast<Base *>(MEM_dupallocN(base_src)); | ||||
| BLI_addtail(&view_layer_dst->object_bases, base_dst); | BLI_addtail(&view_layer_dst->object_bases, base_dst); | ||||
| if (view_layer_src->basact == base_src) { | if (view_layer_src->basact == base_src) { | ||||
| view_layer_dst->basact = base_dst; | view_layer_dst->basact = base_dst; | ||||
| } | } | ||||
| } | } | ||||
| view_layer_dst->active_collection = NULL; | view_layer_dst->active_collection = NULL; | ||||
| layer_collections_copy_data(view_layer_dst, | layer_collections_copy_data(view_layer_dst, | ||||
| view_layer_src, | view_layer_src, | ||||
| &view_layer_dst->layer_collections, | &view_layer_dst->layer_collections, | ||||
| &view_layer_src->layer_collections); | &view_layer_src->layer_collections); | ||||
| LayerCollection *lc_scene_dst = view_layer_dst->layer_collections.first; | LayerCollection *lc_scene_dst = static_cast<LayerCollection *>( | ||||
| view_layer_dst->layer_collections.first); | |||||
| lc_scene_dst->collection = scene_dst->master_collection; | lc_scene_dst->collection = scene_dst->master_collection; | ||||
| BLI_listbase_clear(&view_layer_dst->aovs); | BLI_listbase_clear(&view_layer_dst->aovs); | ||||
| layer_aov_copy_data( | layer_aov_copy_data( | ||||
| view_layer_dst, view_layer_src, &view_layer_dst->aovs, &view_layer_src->aovs); | view_layer_dst, view_layer_src, &view_layer_dst->aovs, &view_layer_src->aovs); | ||||
| BLI_listbase_clear(&view_layer_dst->lightgroups); | BLI_listbase_clear(&view_layer_dst->lightgroups); | ||||
| layer_lightgroup_copy_data( | layer_lightgroup_copy_data( | ||||
| Show All 17 Lines | BLI_uniquename(&scene->view_layers, | ||||
| '.', | '.', | ||||
| offsetof(ViewLayer, name), | offsetof(ViewLayer, name), | ||||
| sizeof(view_layer->name)); | sizeof(view_layer->name)); | ||||
| if (scene->nodetree) { | if (scene->nodetree) { | ||||
| bNode *node; | bNode *node; | ||||
| int index = BLI_findindex(&scene->view_layers, view_layer); | int index = BLI_findindex(&scene->view_layers, view_layer); | ||||
| for (node = scene->nodetree->nodes.first; node; node = node->next) { | for (node = static_cast<bNode *>(scene->nodetree->nodes.first); node; node = node->next) { | ||||
| if (node->type == CMP_NODE_R_LAYERS && node->id == NULL) { | if (node->type == CMP_NODE_R_LAYERS && node->id == NULL) { | ||||
| if (node->custom1 == index) { | if (node->custom1 == index) { | ||||
| BLI_strncpy(node->name, view_layer->name, NODE_MAXSTR); | BLI_strncpy(node->name, view_layer->name, NODE_MAXSTR); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Fix all the animation data and windows which may link to this. */ | /* Fix all the animation data and windows which may link to this. */ | ||||
| BKE_animdata_fix_paths_rename_all(NULL, "view_layers", oldname, view_layer->name); | BKE_animdata_fix_paths_rename_all(NULL, "view_layers", oldname, view_layer->name); | ||||
| /* WM can be missing on startup. */ | /* WM can be missing on startup. */ | ||||
| wmWindowManager *wm = bmain->wm.first; | wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first); | ||||
| if (wm) { | if (wm) { | ||||
| LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { | LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { | ||||
| if (win->scene == scene && STREQ(win->view_layer_name, oldname)) { | if (win->scene == scene && STREQ(win->view_layer_name, oldname)) { | ||||
| STRNCPY(win->view_layer_name, view_layer->name); | STRNCPY(win->view_layer_name, view_layer->name); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 35 Lines | static bool layer_collection_hidden(ViewLayer *view_layer, LayerCollection *lc) | ||||
| } | } | ||||
| /* Check visibility restriction flags */ | /* Check visibility restriction flags */ | ||||
| if (lc->flag & LAYER_COLLECTION_HIDE || lc->collection->flag & COLLECTION_HIDE_VIEWPORT) { | if (lc->flag & LAYER_COLLECTION_HIDE || lc->collection->flag & COLLECTION_HIDE_VIEWPORT) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| /* Restriction flags stay set, so we need to check parents */ | /* Restriction flags stay set, so we need to check parents */ | ||||
| CollectionParent *parent = lc->collection->parents.first; | CollectionParent *parent = static_cast<CollectionParent *>(lc->collection->parents.first); | ||||
| if (parent) { | if (parent) { | ||||
| lc = BKE_layer_collection_first_from_scene_collection(view_layer, parent->collection); | lc = BKE_layer_collection_first_from_scene_collection(view_layer, parent->collection); | ||||
| return lc && layer_collection_hidden(view_layer, lc); | return lc && layer_collection_hidden(view_layer, lc); | ||||
| } | } | ||||
| return false; | return false; | ||||
| Show All 19 Lines | bool BKE_layer_collection_activate(ViewLayer *view_layer, LayerCollection *lc) | ||||
| } | } | ||||
| view_layer->active_collection = lc; | view_layer->active_collection = lc; | ||||
| return true; | return true; | ||||
| } | } | ||||
| LayerCollection *BKE_layer_collection_activate_parent(ViewLayer *view_layer, LayerCollection *lc) | LayerCollection *BKE_layer_collection_activate_parent(ViewLayer *view_layer, LayerCollection *lc) | ||||
| { | { | ||||
| CollectionParent *parent = lc->collection->parents.first; | CollectionParent *parent = static_cast<CollectionParent *>(lc->collection->parents.first); | ||||
| if (parent) { | if (parent) { | ||||
| lc = BKE_layer_collection_first_from_scene_collection(view_layer, parent->collection); | lc = BKE_layer_collection_first_from_scene_collection(view_layer, parent->collection); | ||||
| } | } | ||||
| else { | else { | ||||
| lc = NULL; | lc = NULL; | ||||
| } | } | ||||
| /* Don't activate excluded or hidden collections to prevent creating objects in a hidden | /* Don't activate excluded or hidden collections to prevent creating objects in a hidden | ||||
| * collection from the UI */ | * collection from the UI */ | ||||
| if (lc && layer_collection_hidden(view_layer, lc)) { | if (lc && layer_collection_hidden(view_layer, lc)) { | ||||
| return BKE_layer_collection_activate_parent(view_layer, lc); | return BKE_layer_collection_activate_parent(view_layer, lc); | ||||
| } | } | ||||
| if (!lc) { | if (!lc) { | ||||
| lc = view_layer->layer_collections.first; | lc = static_cast<LayerCollection *>(view_layer->layer_collections.first); | ||||
| } | } | ||||
| view_layer->active_collection = lc; | view_layer->active_collection = lc; | ||||
| return lc; | return lc; | ||||
| } | } | ||||
| /** | /** | ||||
| * Recursively get the count of collections | * Recursively get the count of collections | ||||
| ▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | typedef struct LayerCollectionResync { | ||||
| * OR | * OR | ||||
| * This layer has already been re-used to match the new collections hierarchy. */ | * This layer has already been re-used to match the new collections hierarchy. */ | ||||
| bool is_used; | bool is_used; | ||||
| } LayerCollectionResync; | } LayerCollectionResync; | ||||
| static LayerCollectionResync *layer_collection_resync_create_recurse( | static LayerCollectionResync *layer_collection_resync_create_recurse( | ||||
| LayerCollectionResync *parent_layer_resync, LayerCollection *layer, BLI_mempool *mempool) | LayerCollectionResync *parent_layer_resync, LayerCollection *layer, BLI_mempool *mempool) | ||||
| { | { | ||||
| LayerCollectionResync *layer_resync = BLI_mempool_calloc(mempool); | LayerCollectionResync *layer_resync = static_cast<LayerCollectionResync *>( | ||||
| BLI_mempool_calloc(mempool)); | |||||
| layer_resync->layer = layer; | layer_resync->layer = layer; | ||||
| layer_resync->collection = layer->collection; | layer_resync->collection = layer->collection; | ||||
| layer_resync->parent_layer_resync = parent_layer_resync; | layer_resync->parent_layer_resync = parent_layer_resync; | ||||
| if (parent_layer_resync != NULL) { | if (parent_layer_resync != NULL) { | ||||
| BLI_addtail(&parent_layer_resync->children_layer_resync, layer_resync); | BLI_addtail(&parent_layer_resync->children_layer_resync, layer_resync); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { | LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { | ||||
| BKE_view_layer_synced_ensure(scene, view_layer); | BKE_view_layer_synced_ensure(scene, view_layer); | ||||
| } | } | ||||
| } | } | ||||
| void BKE_main_view_layers_synced_ensure(const Main *bmain) | void BKE_main_view_layers_synced_ensure(const Main *bmain) | ||||
| { | { | ||||
| for (const Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { | for (const Scene *scene = static_cast<const Scene *>(bmain->scenes.first); scene; | ||||
| scene = static_cast<const Scene *>(scene->id.next)) { | |||||
| BKE_scene_view_layers_synced_ensure(scene); | BKE_scene_view_layers_synced_ensure(scene); | ||||
| } | } | ||||
| /* NOTE: This is not (yet?) covered by the dirty tag and differed re-sync system */ | /* NOTE: This is not (yet?) covered by the dirty tag and differed re-sync system */ | ||||
| BKE_layer_collection_local_sync_all(bmain); | BKE_layer_collection_local_sync_all(bmain); | ||||
| } | } | ||||
| static void layer_collection_objects_sync(ViewLayer *view_layer, | static void layer_collection_objects_sync(ViewLayer *view_layer, | ||||
| Show All 18 Lines | LISTBASE_FOREACH (CollectionObject *, cob, &layer->collection->gobject) { | ||||
| id_lib_indirect_weak_link(&cob->ob->id); | id_lib_indirect_weak_link(&cob->ob->id); | ||||
| void **base_p; | void **base_p; | ||||
| Base *base; | Base *base; | ||||
| if (BLI_ghash_ensure_p(view_layer->object_bases_hash, cob->ob, &base_p)) { | if (BLI_ghash_ensure_p(view_layer->object_bases_hash, cob->ob, &base_p)) { | ||||
| /* Move from old base list to new base list. Base might have already | /* Move from old base list to new base list. Base might have already | ||||
| * been moved to the new base list and the first/last test ensure that | * been moved to the new base list and the first/last test ensure that | ||||
| * case also works. */ | * case also works. */ | ||||
| base = *base_p; | base = static_cast<Base *>(*base_p); | ||||
| if (!ELEM(base, r_lb_new_object_bases->first, r_lb_new_object_bases->last)) { | if (!ELEM(base, r_lb_new_object_bases->first, r_lb_new_object_bases->last)) { | ||||
| BLI_remlink(&view_layer->object_bases, base); | BLI_remlink(&view_layer->object_bases, base); | ||||
| BLI_addtail(r_lb_new_object_bases, base); | BLI_addtail(r_lb_new_object_bases, base); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Create new base. */ | /* Create new base. */ | ||||
| base = object_base_new(cob->ob); | base = object_base_new(cob->ob); | ||||
| ▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | else { | ||||
| 4, | 4, | ||||
| "No available LayerCollection for %s as child of %s, creating a new one", | "No available LayerCollection for %s as child of %s, creating a new one", | ||||
| child_collection->id.name, | child_collection->id.name, | ||||
| layer_resync->collection->id.name); | layer_resync->collection->id.name); | ||||
| LayerCollection *child_layer = layer_collection_add(&new_lb_layer, child_collection); | LayerCollection *child_layer = layer_collection_add(&new_lb_layer, child_collection); | ||||
| child_layer->flag = parent_layer_flag; | child_layer->flag = parent_layer_flag; | ||||
| child_layer_resync = BLI_mempool_calloc(layer_resync_mempool); | child_layer_resync = static_cast<LayerCollectionResync *>( | ||||
| BLI_mempool_calloc(layer_resync_mempool)); | |||||
| child_layer_resync->collection = child_collection; | child_layer_resync->collection = child_collection; | ||||
| child_layer_resync->layer = child_layer; | child_layer_resync->layer = child_layer; | ||||
| child_layer_resync->is_usable = true; | child_layer_resync->is_usable = true; | ||||
| child_layer_resync->is_used = true; | child_layer_resync->is_used = true; | ||||
| child_layer_resync->is_valid_as_child = true; | child_layer_resync->is_valid_as_child = true; | ||||
| child_layer_resync->is_valid_as_parent = true; | child_layer_resync->is_valid_as_parent = true; | ||||
| /* NOTE: Needs to be added to the layer_resync hierarchy so that the resync wrapper gets | /* NOTE: Needs to be added to the layer_resync hierarchy so that the resync wrapper gets | ||||
| * freed at the end. */ | * freed at the end. */ | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| #ifndef NDEBUG | #ifndef NDEBUG | ||||
| static bool view_layer_objects_base_cache_validate(ViewLayer *view_layer, LayerCollection *layer) | static bool view_layer_objects_base_cache_validate(ViewLayer *view_layer, LayerCollection *layer) | ||||
| { | { | ||||
| bool is_valid = true; | bool is_valid = true; | ||||
| if (layer == NULL) { | if (layer == NULL) { | ||||
| layer = view_layer->layer_collections.first; | layer = static_cast<LayerCollection *>(view_layer->layer_collections.first); | ||||
| } | } | ||||
| /* Only check for a collection's objects if its layer is not excluded. */ | /* Only check for a collection's objects if its layer is not excluded. */ | ||||
| if ((layer->flag & LAYER_COLLECTION_EXCLUDE) == 0) { | if ((layer->flag & LAYER_COLLECTION_EXCLUDE) == 0) { | ||||
| LISTBASE_FOREACH (CollectionObject *, cob, &layer->collection->gobject) { | LISTBASE_FOREACH (CollectionObject *, cob, &layer->collection->gobject) { | ||||
| if (cob->ob == NULL) { | if (cob->ob == NULL) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| Show All 25 Lines | static bool view_layer_objects_base_cache_validate(ViewLayer *UNUSED(view_layer), | ||||
| LayerCollection *UNUSED(layer)) | LayerCollection *UNUSED(layer)) | ||||
| { | { | ||||
| return true; | return true; | ||||
| } | } | ||||
| #endif | #endif | ||||
| void BKE_layer_collection_doversion_2_80(const Scene *scene, ViewLayer *view_layer) | void BKE_layer_collection_doversion_2_80(const Scene *scene, ViewLayer *view_layer) | ||||
| { | { | ||||
| LayerCollection *first_layer_collection = view_layer->layer_collections.first; | LayerCollection *first_layer_collection = static_cast<LayerCollection *>( | ||||
| view_layer->layer_collections.first); | |||||
| if (BLI_listbase_count_at_most(&view_layer->layer_collections, 2) > 1 || | if (BLI_listbase_count_at_most(&view_layer->layer_collections, 2) > 1 || | ||||
| first_layer_collection->collection != scene->master_collection) { | first_layer_collection->collection != scene->master_collection) { | ||||
| /* In some cases (from older files) we do have a master collection, but no matching layer, | /* In some cases (from older files) we do have a master collection, but no matching layer, | ||||
| * instead all the children of the master collection have their layer collections in the | * instead all the children of the master collection have their layer collections in the | ||||
| * viewlayer's list. This is not a valid situation, add a layer for the master collection and | * viewlayer's list. This is not a valid situation, add a layer for the master collection and | ||||
| * add all existing first-level layers as children of that new master layer. */ | * add all existing first-level layers as children of that new master layer. */ | ||||
| ListBase layer_collections = view_layer->layer_collections; | ListBase layer_collections = view_layer->layer_collections; | ||||
| BLI_listbase_clear(&view_layer->layer_collections); | BLI_listbase_clear(&view_layer->layer_collections); | ||||
| Show All 22 Lines | void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer) | ||||
| } | } | ||||
| #ifndef NDEBUG | #ifndef NDEBUG | ||||
| { | { | ||||
| BLI_assert_msg(BLI_listbase_count_at_most(&view_layer->layer_collections, 2) == 1, | BLI_assert_msg(BLI_listbase_count_at_most(&view_layer->layer_collections, 2) == 1, | ||||
| "ViewLayer's first level of children layer collections should always have " | "ViewLayer's first level of children layer collections should always have " | ||||
| "exactly one item"); | "exactly one item"); | ||||
| LayerCollection *first_layer_collection = view_layer->layer_collections.first; | LayerCollection *first_layer_collection = static_cast<LayerCollection *>( | ||||
| view_layer->layer_collections.first); | |||||
| BLI_assert_msg(first_layer_collection->collection == scene->master_collection, | BLI_assert_msg(first_layer_collection->collection == scene->master_collection, | ||||
| "ViewLayer's first layer collection should always be the one for the scene's " | "ViewLayer's first layer collection should always be the one for the scene's " | ||||
| "master collection"); | "master collection"); | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* Free cache. */ | /* Free cache. */ | ||||
| MEM_SAFE_FREE(view_layer->object_bases_array); | MEM_SAFE_FREE(view_layer->object_bases_array); | ||||
| Show All 9 Lines | LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { | ||||
| base->flag_from_collection &= ~g_base_collection_flags; | base->flag_from_collection &= ~g_base_collection_flags; | ||||
| } | } | ||||
| /* Generate temporary data representing the old layers hierarchy, and how well it matches the | /* Generate temporary data representing the old layers hierarchy, and how well it matches the | ||||
| * new collections hierarchy. */ | * new collections hierarchy. */ | ||||
| BLI_mempool *layer_resync_mempool = BLI_mempool_create( | BLI_mempool *layer_resync_mempool = BLI_mempool_create( | ||||
| sizeof(LayerCollectionResync), 1024, 1024, BLI_MEMPOOL_NOP); | sizeof(LayerCollectionResync), 1024, 1024, BLI_MEMPOOL_NOP); | ||||
| LayerCollectionResync *master_layer_resync = layer_collection_resync_create_recurse( | LayerCollectionResync *master_layer_resync = layer_collection_resync_create_recurse( | ||||
| NULL, view_layer->layer_collections.first, layer_resync_mempool); | NULL, | ||||
| static_cast<LayerCollection *>(view_layer->layer_collections.first), | |||||
| layer_resync_mempool); | |||||
| /* Generate new layer connections and object bases when collections changed. */ | /* Generate new layer connections and object bases when collections changed. */ | ||||
| ListBase new_object_bases = {.first = NULL, .last = NULL}; | ListBase new_object_bases{}; | ||||
| const short parent_exclude = 0, parent_restrict = 0, parent_layer_restrict = 0; | const short parent_exclude = 0, parent_restrict = 0, parent_layer_restrict = 0; | ||||
| layer_collection_sync(view_layer, | layer_collection_sync(view_layer, | ||||
| master_layer_resync, | master_layer_resync, | ||||
| layer_resync_mempool, | layer_resync_mempool, | ||||
| &new_object_bases, | &new_object_bases, | ||||
| parent_exclude, | parent_exclude, | ||||
| parent_restrict, | parent_restrict, | ||||
| parent_layer_restrict, | parent_layer_restrict, | ||||
| Show All 30 Lines | #endif | ||||
| } | } | ||||
| /* Always set a valid active collection. */ | /* Always set a valid active collection. */ | ||||
| LayerCollection *active = view_layer->active_collection; | LayerCollection *active = view_layer->active_collection; | ||||
| if (active && layer_collection_hidden(view_layer, active)) { | if (active && layer_collection_hidden(view_layer, active)) { | ||||
| BKE_layer_collection_activate_parent(view_layer, active); | BKE_layer_collection_activate_parent(view_layer, active); | ||||
| } | } | ||||
| else if (active == NULL) { | else if (active == NULL) { | ||||
| view_layer->active_collection = view_layer->layer_collections.first; | view_layer->active_collection = static_cast<LayerCollection *>( | ||||
| view_layer->layer_collections.first); | |||||
| } | } | ||||
| } | } | ||||
| void BKE_scene_collection_sync(const Scene *scene) | void BKE_scene_collection_sync(const Scene *scene) | ||||
| { | { | ||||
| if (no_resync) { | if (no_resync) { | ||||
| return; | return; | ||||
| } | } | ||||
| Show All 9 Lines | if (no_resync) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* TODO: if a single collection changed, figure out which | /* TODO: if a single collection changed, figure out which | ||||
| * scenes it belongs to and only update those. */ | * scenes it belongs to and only update those. */ | ||||
| /* TODO: optimize for file load so only linked collections get checked? */ | /* TODO: optimize for file load so only linked collections get checked? */ | ||||
| for (const Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { | for (const Scene *scene = static_cast<const Scene *>(bmain->scenes.first); scene; | ||||
| scene = static_cast<const Scene *>(scene->id.next)) { | |||||
| BKE_scene_collection_sync(scene); | BKE_scene_collection_sync(scene); | ||||
| } | } | ||||
| BKE_layer_collection_local_sync_all(bmain); | BKE_layer_collection_local_sync_all(bmain); | ||||
| } | } | ||||
| void BKE_main_collection_sync_remap(const Main *bmain) | void BKE_main_collection_sync_remap(const Main *bmain) | ||||
| { | { | ||||
| if (no_resync) { | if (no_resync) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* On remapping of object or collection pointers free caches. */ | /* On remapping of object or collection pointers free caches. */ | ||||
| /* TODO: try to make this faster */ | /* TODO: try to make this faster */ | ||||
| for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { | for (Scene *scene = static_cast<Scene *>(bmain->scenes.first); scene; | ||||
| scene = static_cast<Scene *>(scene->id.next)) { | |||||
| LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { | LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { | ||||
| MEM_SAFE_FREE(view_layer->object_bases_array); | MEM_SAFE_FREE(view_layer->object_bases_array); | ||||
| if (view_layer->object_bases_hash) { | if (view_layer->object_bases_hash) { | ||||
| BLI_ghash_free(view_layer->object_bases_hash, NULL, NULL); | BLI_ghash_free(view_layer->object_bases_hash, NULL, NULL); | ||||
| view_layer->object_bases_hash = NULL; | view_layer->object_bases_hash = NULL; | ||||
| } | } | ||||
| /* Directly re-create the mapping here, so that we can also deal with duplicates in | /* Directly re-create the mapping here, so that we can also deal with duplicates in | ||||
| * `view_layer->object_bases` list of bases properly. This is the only place where such | * `view_layer->object_bases` list of bases properly. This is the only place where such | ||||
| * duplicates should be fixed, and not considered as a critical error. */ | * duplicates should be fixed, and not considered as a critical error. */ | ||||
| view_layer_bases_hash_create(view_layer, true); | view_layer_bases_hash_create(view_layer, true); | ||||
| } | } | ||||
| BKE_collection_object_cache_free(scene->master_collection); | BKE_collection_object_cache_free(scene->master_collection); | ||||
| DEG_id_tag_update_ex((Main *)bmain, &scene->master_collection->id, ID_RECALC_COPY_ON_WRITE); | DEG_id_tag_update_ex((Main *)bmain, &scene->master_collection->id, ID_RECALC_COPY_ON_WRITE); | ||||
| DEG_id_tag_update_ex((Main *)bmain, &scene->id, ID_RECALC_COPY_ON_WRITE); | DEG_id_tag_update_ex((Main *)bmain, &scene->id, ID_RECALC_COPY_ON_WRITE); | ||||
| } | } | ||||
| for (Collection *collection = bmain->collections.first; collection; | for (Collection *collection = static_cast<Collection *>(bmain->collections.first); collection; | ||||
| collection = collection->id.next) { | collection = static_cast<Collection *>(collection->id.next)) { | ||||
| BKE_collection_object_cache_free(collection); | BKE_collection_object_cache_free(collection); | ||||
| DEG_id_tag_update_ex((Main *)bmain, &collection->id, ID_RECALC_COPY_ON_WRITE); | DEG_id_tag_update_ex((Main *)bmain, &collection->id, ID_RECALC_COPY_ON_WRITE); | ||||
| } | } | ||||
| BKE_main_collection_sync(bmain); | BKE_main_collection_sync(bmain); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| ▲ Show 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | static void layer_collection_flag_unset_recursive(LayerCollection *lc, const int flag) | ||||
| } | } | ||||
| } | } | ||||
| void BKE_layer_collection_isolate_global(Scene *UNUSED(scene), | void BKE_layer_collection_isolate_global(Scene *UNUSED(scene), | ||||
| ViewLayer *view_layer, | ViewLayer *view_layer, | ||||
| LayerCollection *lc, | LayerCollection *lc, | ||||
| bool extend) | bool extend) | ||||
| { | { | ||||
| LayerCollection *lc_master = view_layer->layer_collections.first; | LayerCollection *lc_master = static_cast<LayerCollection *>(view_layer->layer_collections.first); | ||||
| bool hide_it = extend && (lc->runtime_flag & LAYER_COLLECTION_VISIBLE_VIEW_LAYER); | bool hide_it = extend && (lc->runtime_flag & LAYER_COLLECTION_VISIBLE_VIEW_LAYER); | ||||
| if (!extend) { | if (!extend) { | ||||
| /* Hide all collections. */ | /* Hide all collections. */ | ||||
| LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_master->layer_collections) { | LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_master->layer_collections) { | ||||
| layer_collection_flag_set_recursive(lc_iter, LAYER_COLLECTION_HIDE); | layer_collection_flag_set_recursive(lc_iter, LAYER_COLLECTION_HIDE); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | void BKE_layer_collection_local_sync_all(const Main *bmain) | ||||
| LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { | LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { | ||||
| LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { | LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { | ||||
| LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { | LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { | ||||
| LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { | LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { | ||||
| if (area->spacetype != SPACE_VIEW3D) { | if (area->spacetype != SPACE_VIEW3D) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| View3D *v3d = area->spacedata.first; | View3D *v3d = static_cast<View3D *>(area->spacedata.first); | ||||
| if (v3d->flag & V3D_LOCAL_COLLECTIONS) { | if (v3d->flag & V3D_LOCAL_COLLECTIONS) { | ||||
| BKE_layer_collection_local_sync(scene, view_layer, v3d); | BKE_layer_collection_local_sync(scene, view_layer, v3d); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void BKE_layer_collection_isolate_local( | void BKE_layer_collection_isolate_local( | ||||
| const Scene *scene, ViewLayer *view_layer, const View3D *v3d, LayerCollection *lc, bool extend) | const Scene *scene, ViewLayer *view_layer, const View3D *v3d, LayerCollection *lc, bool extend) | ||||
| { | { | ||||
| LayerCollection *lc_master = view_layer->layer_collections.first; | LayerCollection *lc_master = static_cast<LayerCollection *>(view_layer->layer_collections.first); | ||||
| bool hide_it = extend && ((v3d->local_collections_uuid & lc->local_collections_bits) != 0); | bool hide_it = extend && ((v3d->local_collections_uuid & lc->local_collections_bits) != 0); | ||||
| if (!extend) { | if (!extend) { | ||||
| /* Hide all collections. */ | /* Hide all collections. */ | ||||
| LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_master->layer_collections) { | LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_master->layer_collections) { | ||||
| layer_collection_local_visibility_unset_recursive(lc_iter, v3d->local_collections_uuid); | layer_collection_local_visibility_unset_recursive(lc_iter, v3d->local_collections_uuid); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 201 Lines • ▼ Show 20 Lines | static bool object_bases_iterator_is_valid(const View3D *v3d, Base *base, const int flag) | ||||
| } | } | ||||
| /* Flags may be more than one flag, so we can't check != 0. */ | /* Flags may be more than one flag, so we can't check != 0. */ | ||||
| return BASE_VISIBLE(v3d, base) && ((base->flag & flag) == flag); | return BASE_VISIBLE(v3d, base) && ((base->flag & flag) == flag); | ||||
| } | } | ||||
| static void object_bases_iterator_begin(BLI_Iterator *iter, void *data_in_v, const int flag) | static void object_bases_iterator_begin(BLI_Iterator *iter, void *data_in_v, const int flag) | ||||
| { | { | ||||
| ObjectsVisibleIteratorData *data_in = data_in_v; | ObjectsVisibleIteratorData *data_in = static_cast<ObjectsVisibleIteratorData *>(data_in_v); | ||||
| ViewLayer *view_layer = data_in->view_layer; | ViewLayer *view_layer = data_in->view_layer; | ||||
| const View3D *v3d = data_in->v3d; | const View3D *v3d = data_in->v3d; | ||||
| Base *base = BKE_view_layer_object_bases_get(view_layer)->first; | Base *base = static_cast<Base *>(BKE_view_layer_object_bases_get(view_layer)->first); | ||||
| /* when there are no objects */ | /* when there are no objects */ | ||||
| if (base == NULL) { | if (base == NULL) { | ||||
| iter->data = NULL; | iter->data = NULL; | ||||
| iter->valid = false; | iter->valid = false; | ||||
| return; | return; | ||||
| } | } | ||||
| LayerObjectBaseIteratorData *data = MEM_callocN(sizeof(LayerObjectBaseIteratorData), __func__); | LayerObjectBaseIteratorData *data = MEM_cnew<LayerObjectBaseIteratorData>(__func__); | ||||
| iter->data = data; | iter->data = data; | ||||
| data->v3d = v3d; | data->v3d = v3d; | ||||
| data->base = base; | data->base = base; | ||||
| if (object_bases_iterator_is_valid(v3d, base, flag) == false) { | if (object_bases_iterator_is_valid(v3d, base, flag) == false) { | ||||
| object_bases_iterator_next(iter, flag); | object_bases_iterator_next(iter, flag); | ||||
| } | } | ||||
| else { | else { | ||||
| iter->current = base; | iter->current = base; | ||||
| } | } | ||||
| } | } | ||||
| static void object_bases_iterator_next(BLI_Iterator *iter, const int flag) | static void object_bases_iterator_next(BLI_Iterator *iter, const int flag) | ||||
| { | { | ||||
| LayerObjectBaseIteratorData *data = iter->data; | LayerObjectBaseIteratorData *data = static_cast<LayerObjectBaseIteratorData *>(iter->data); | ||||
| Base *base = data->base->next; | Base *base = data->base->next; | ||||
| while (base) { | while (base) { | ||||
| if (object_bases_iterator_is_valid(data->v3d, base, flag)) { | if (object_bases_iterator_is_valid(data->v3d, base, flag)) { | ||||
| iter->current = base; | iter->current = base; | ||||
| data->base = base; | data->base = base; | ||||
| return; | return; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Lines | |||||
| static bool base_is_in_mode(struct ObjectsInModeIteratorData *data, Base *base) | static bool base_is_in_mode(struct ObjectsInModeIteratorData *data, Base *base) | ||||
| { | { | ||||
| return (base->object->type == data->object_type) && | return (base->object->type == data->object_type) && | ||||
| (base->object->mode & data->object_mode) != 0; | (base->object->mode & data->object_mode) != 0; | ||||
| } | } | ||||
| void BKE_view_layer_bases_in_mode_iterator_begin(BLI_Iterator *iter, void *data_in) | void BKE_view_layer_bases_in_mode_iterator_begin(BLI_Iterator *iter, void *data_in) | ||||
| { | { | ||||
| struct ObjectsInModeIteratorData *data = data_in; | struct ObjectsInModeIteratorData *data = static_cast<ObjectsInModeIteratorData *>(data_in); | ||||
| Base *base = data->base_active; | Base *base = data->base_active; | ||||
| /* In this case the result will always be empty, the caller must check for no mode. */ | /* In this case the result will always be empty, the caller must check for no mode. */ | ||||
| BLI_assert(data->object_mode != 0); | BLI_assert(data->object_mode != 0); | ||||
| /* when there are no objects */ | /* when there are no objects */ | ||||
| if (base == NULL) { | if (base == NULL) { | ||||
| iter->valid = false; | iter->valid = false; | ||||
| Show All 9 Lines | void BKE_view_layer_bases_in_mode_iterator_begin(BLI_Iterator *iter, void *data_in) | ||||
| if (!(base_is_in_mode(data, base) && BKE_base_is_visible(data->v3d, base))) { | if (!(base_is_in_mode(data, base) && BKE_base_is_visible(data->v3d, base))) { | ||||
| BKE_view_layer_bases_in_mode_iterator_next(iter); | BKE_view_layer_bases_in_mode_iterator_next(iter); | ||||
| } | } | ||||
| } | } | ||||
| void BKE_view_layer_bases_in_mode_iterator_next(BLI_Iterator *iter) | void BKE_view_layer_bases_in_mode_iterator_next(BLI_Iterator *iter) | ||||
| { | { | ||||
| struct ObjectsInModeIteratorData *data = iter->data; | struct ObjectsInModeIteratorData *data = static_cast<ObjectsInModeIteratorData *>(iter->data); | ||||
| Base *base = iter->current; | Base *base = static_cast<Base *>(iter->current); | ||||
| if (base == data->base_active) { | if (base == data->base_active) { | ||||
| /* first step */ | /* first step */ | ||||
| base = data->view_layer->object_bases.first; | base = static_cast<Base *>(data->view_layer->object_bases.first); | ||||
| if ((base == data->base_active) && BKE_base_is_visible(data->v3d, base)) { | if ((base == data->base_active) && BKE_base_is_visible(data->v3d, base)) { | ||||
| base = base->next; | base = base->next; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| base = base->next; | base = base->next; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | static void layer_eval_view_layer(struct Depsgraph *depsgraph, | ||||
| ViewLayer *view_layer) | ViewLayer *view_layer) | ||||
| { | { | ||||
| DEG_debug_print_eval(depsgraph, __func__, view_layer->name, view_layer); | DEG_debug_print_eval(depsgraph, __func__, view_layer->name, view_layer); | ||||
| /* Create array of bases, for fast index-based lookup. */ | /* Create array of bases, for fast index-based lookup. */ | ||||
| BKE_view_layer_synced_ensure(scene, view_layer); | BKE_view_layer_synced_ensure(scene, view_layer); | ||||
| const int num_object_bases = BLI_listbase_count(BKE_view_layer_object_bases_get(view_layer)); | const int num_object_bases = BLI_listbase_count(BKE_view_layer_object_bases_get(view_layer)); | ||||
| MEM_SAFE_FREE(view_layer->object_bases_array); | MEM_SAFE_FREE(view_layer->object_bases_array); | ||||
| view_layer->object_bases_array = MEM_malloc_arrayN( | view_layer->object_bases_array = static_cast<Base **>( | ||||
| num_object_bases, sizeof(Base *), "view_layer->object_bases_array"); | MEM_malloc_arrayN(num_object_bases, sizeof(Base *), "view_layer->object_bases_array")); | ||||
| int base_index = 0; | int base_index = 0; | ||||
| LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) { | LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) { | ||||
| view_layer->object_bases_array[base_index++] = base; | view_layer->object_bases_array[base_index++] = base; | ||||
| } | } | ||||
| } | } | ||||
| void BKE_layer_eval_view_layer_indexed(struct Depsgraph *depsgraph, | void BKE_layer_eval_view_layer_indexed(struct Depsgraph *depsgraph, | ||||
| struct Scene *scene, | struct Scene *scene, | ||||
| int view_layer_index) | int view_layer_index) | ||||
| { | { | ||||
| BLI_assert(view_layer_index >= 0); | BLI_assert(view_layer_index >= 0); | ||||
| ViewLayer *view_layer = BLI_findlink(&scene->view_layers, view_layer_index); | ViewLayer *view_layer = static_cast<ViewLayer *>( | ||||
| BLI_findlink(&scene->view_layers, view_layer_index)); | |||||
| BLI_assert(view_layer != NULL); | BLI_assert(view_layer != NULL); | ||||
| layer_eval_view_layer(depsgraph, scene, view_layer); | layer_eval_view_layer(depsgraph, scene, view_layer); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Blend File I/O | /** \name Blend File I/O | ||||
| ▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | static void viewlayer_aov_active_set(ViewLayer *view_layer, ViewLayerAOV *aov) | ||||
| else { | else { | ||||
| view_layer->active_aov = NULL; | view_layer->active_aov = NULL; | ||||
| } | } | ||||
| } | } | ||||
| struct ViewLayerAOV *BKE_view_layer_add_aov(struct ViewLayer *view_layer) | struct ViewLayerAOV *BKE_view_layer_add_aov(struct ViewLayer *view_layer) | ||||
| { | { | ||||
| ViewLayerAOV *aov; | ViewLayerAOV *aov; | ||||
| aov = MEM_callocN(sizeof(ViewLayerAOV), __func__); | aov = MEM_cnew<ViewLayerAOV>(__func__); | ||||
| aov->type = AOV_TYPE_COLOR; | aov->type = AOV_TYPE_COLOR; | ||||
| BLI_strncpy(aov->name, DATA_("AOV"), sizeof(aov->name)); | BLI_strncpy(aov->name, DATA_("AOV"), sizeof(aov->name)); | ||||
| BLI_addtail(&view_layer->aovs, aov); | BLI_addtail(&view_layer->aovs, aov); | ||||
| viewlayer_aov_active_set(view_layer, aov); | viewlayer_aov_active_set(view_layer, aov); | ||||
| viewlayer_aov_make_name_unique(view_layer); | viewlayer_aov_make_name_unique(view_layer); | ||||
| return aov; | return aov; | ||||
| } | } | ||||
| Show All 20 Lines | |||||
| static void bke_view_layer_verify_aov_cb(void *userdata, | static void bke_view_layer_verify_aov_cb(void *userdata, | ||||
| Scene *UNUSED(scene), | Scene *UNUSED(scene), | ||||
| ViewLayer *UNUSED(view_layer), | ViewLayer *UNUSED(view_layer), | ||||
| const char *name, | const char *name, | ||||
| int UNUSED(channels), | int UNUSED(channels), | ||||
| const char *UNUSED(chanid), | const char *UNUSED(chanid), | ||||
| eNodeSocketDatatype UNUSED(type)) | eNodeSocketDatatype UNUSED(type)) | ||||
| { | { | ||||
| GHash *name_count = userdata; | GHash *name_count = static_cast<GHash *>(userdata); | ||||
| void **value_p; | void **value_p; | ||||
| void *key = BLI_strdup(name); | void *key = BLI_strdup(name); | ||||
| if (!BLI_ghash_ensure_p(name_count, key, &value_p)) { | if (!BLI_ghash_ensure_p(name_count, key, &value_p)) { | ||||
| *value_p = POINTER_FROM_INT(1); | *value_p = POINTER_FROM_INT(1); | ||||
| } | } | ||||
| else { | else { | ||||
| int value = POINTER_AS_INT(*value_p); | int value = POINTER_AS_INT(*value_p); | ||||
| value++; | value++; | ||||
| *value_p = POINTER_FROM_INT(value); | *value_p = POINTER_FROM_INT(value); | ||||
| MEM_freeN(key); | MEM_freeN(key); | ||||
| } | } | ||||
| } | } | ||||
| void BKE_view_layer_verify_aov(struct RenderEngine *engine, | void BKE_view_layer_verify_aov(struct RenderEngine *engine, | ||||
| struct Scene *scene, | struct Scene *scene, | ||||
| struct ViewLayer *view_layer) | struct ViewLayer *view_layer) | ||||
| { | { | ||||
| viewlayer_aov_make_name_unique(view_layer); | viewlayer_aov_make_name_unique(view_layer); | ||||
| GHash *name_count = BLI_ghash_str_new(__func__); | GHash *name_count = BLI_ghash_str_new(__func__); | ||||
| RE_engine_update_render_passes( | RE_engine_update_render_passes( | ||||
| engine, scene, view_layer, bke_view_layer_verify_aov_cb, name_count); | engine, scene, view_layer, bke_view_layer_verify_aov_cb, name_count); | ||||
| LISTBASE_FOREACH (ViewLayerAOV *, aov, &view_layer->aovs) { | LISTBASE_FOREACH (ViewLayerAOV *, aov, &view_layer->aovs) { | ||||
| void **value_p = BLI_ghash_lookup(name_count, aov->name); | void **value_p = static_cast<void **>(BLI_ghash_lookup(name_count, aov->name)); | ||||
| int count = POINTER_AS_INT(value_p); | int count = POINTER_AS_INT(value_p); | ||||
| SET_FLAG_FROM_TEST(aov->flag, count > 1, AOV_CONFLICT); | SET_FLAG_FROM_TEST(aov->flag, count > 1, AOV_CONFLICT); | ||||
| } | } | ||||
| BLI_ghash_free(name_count, MEM_freeN, NULL); | BLI_ghash_free(name_count, MEM_freeN, NULL); | ||||
| } | } | ||||
| bool BKE_view_layer_has_valid_aov(ViewLayer *view_layer) | bool BKE_view_layer_has_valid_aov(ViewLayer *view_layer) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | else { | ||||
| view_layer->active_lightgroup = NULL; | view_layer->active_lightgroup = NULL; | ||||
| } | } | ||||
| } | } | ||||
| struct ViewLayerLightgroup *BKE_view_layer_add_lightgroup(struct ViewLayer *view_layer, | struct ViewLayerLightgroup *BKE_view_layer_add_lightgroup(struct ViewLayer *view_layer, | ||||
| const char *name) | const char *name) | ||||
| { | { | ||||
| ViewLayerLightgroup *lightgroup; | ViewLayerLightgroup *lightgroup; | ||||
| lightgroup = MEM_callocN(sizeof(ViewLayerLightgroup), __func__); | lightgroup = MEM_cnew<ViewLayerLightgroup>(__func__); | ||||
| if (name && name[0]) { | if (name && name[0]) { | ||||
| BLI_strncpy(lightgroup->name, name, sizeof(lightgroup->name)); | BLI_strncpy(lightgroup->name, name, sizeof(lightgroup->name)); | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_strncpy(lightgroup->name, DATA_("Lightgroup"), sizeof(lightgroup->name)); | BLI_strncpy(lightgroup->name, DATA_("Lightgroup"), sizeof(lightgroup->name)); | ||||
| } | } | ||||
| BLI_addtail(&view_layer->lightgroups, lightgroup); | BLI_addtail(&view_layer->lightgroups, lightgroup); | ||||
| viewlayer_lightgroup_active_set(view_layer, lightgroup); | viewlayer_lightgroup_active_set(view_layer, lightgroup); | ||||
| ▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | int BKE_lightgroup_membership_length(struct LightgroupMembership *lgm) | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| void BKE_lightgroup_membership_set(struct LightgroupMembership **lgm, const char *name) | void BKE_lightgroup_membership_set(struct LightgroupMembership **lgm, const char *name) | ||||
| { | { | ||||
| if (name[0] != '\0') { | if (name[0] != '\0') { | ||||
| if (*lgm == NULL) { | if (*lgm == NULL) { | ||||
| *lgm = MEM_callocN(sizeof(LightgroupMembership), __func__); | *lgm = MEM_cnew<LightgroupMembership>(__func__); | ||||
| } | } | ||||
| BLI_strncpy((*lgm)->name, name, sizeof((*lgm)->name)); | BLI_strncpy((*lgm)->name, name, sizeof((*lgm)->name)); | ||||
| } | } | ||||
| else { | else { | ||||
| if (*lgm != NULL) { | if (*lgm != NULL) { | ||||
| MEM_freeN(*lgm); | MEM_freeN(*lgm); | ||||
| *lgm = NULL; | *lgm = NULL; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||