Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/layer.c
| Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
| #include "DRW_engine.h" | #include "DRW_engine.h" | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH) printf | #define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH) printf | ||||
| /* prototype */ | /* prototype */ | ||||
| struct EngineSettingsCB_Type; | struct EngineSettingsCB_Type; | ||||
| static void layer_collection_free(SceneLayer *sl, LayerCollection *lc); | static void layer_collection_free(ViewLayer *sl, LayerCollection *lc); | ||||
| static void layer_collection_objects_populate(SceneLayer *sl, LayerCollection *lc, ListBase *objects); | static void layer_collection_objects_populate(ViewLayer *sl, LayerCollection *lc, ListBase *objects); | ||||
| static LayerCollection *layer_collection_add(SceneLayer *sl, LayerCollection *parent, SceneCollection *sc); | static LayerCollection *layer_collection_add(ViewLayer *sl, LayerCollection *parent, SceneCollection *sc); | ||||
| static LayerCollection *find_layer_collection_by_scene_collection(LayerCollection *lc, const SceneCollection *sc); | static LayerCollection *find_layer_collection_by_scene_collection(LayerCollection *lc, const SceneCollection *sc); | ||||
| static IDProperty *collection_engine_settings_create(struct EngineSettingsCB_Type *ces_type, const bool populate); | static IDProperty *collection_engine_settings_create(struct EngineSettingsCB_Type *ces_type, const bool populate); | ||||
| static IDProperty *collection_engine_get(IDProperty *root, const int type, const char *engine_name); | static IDProperty *collection_engine_get(IDProperty *root, const int type, const char *engine_name); | ||||
| static void collection_engine_settings_init(IDProperty *root, const bool populate); | static void collection_engine_settings_init(IDProperty *root, const bool populate); | ||||
| static void layer_engine_settings_init(IDProperty *root, const bool populate); | static void layer_engine_settings_init(IDProperty *root, const bool populate); | ||||
| static void object_bases_iterator_next(BLI_Iterator *iter, const int flag); | static void object_bases_iterator_next(BLI_Iterator *iter, const int flag); | ||||
| /* RenderLayer */ | /* RenderLayer */ | ||||
| /** | /** | ||||
| * Returns the SceneLayer to be used for rendering | * Returns the ViewLayer to be used for rendering | ||||
| * Most of the time BKE_scene_layer_from_workspace_get should be used instead | * Most of the time BKE_view_layer_from_workspace_get should be used instead | ||||
| */ | */ | ||||
| SceneLayer *BKE_scene_layer_from_scene_get(const Scene *scene) | ViewLayer *BKE_view_layer_from_scene_get(const Scene *scene) | ||||
| { | { | ||||
| SceneLayer *sl = BLI_findlink(&scene->render_layers, scene->active_layer); | ViewLayer *sl = BLI_findlink(&scene->view_layers, scene->active_view_layer); | ||||
| BLI_assert(sl); | BLI_assert(sl); | ||||
| return sl; | return sl; | ||||
| } | } | ||||
| /** | /** | ||||
| * Returns the SceneLayer to be used for drawing, outliner, and other context related areas. | * Returns the ViewLayer to be used for drawing, outliner, and other context related areas. | ||||
| */ | */ | ||||
| SceneLayer *BKE_scene_layer_from_workspace_get(const struct Scene *scene, const struct WorkSpace *workspace) | ViewLayer *BKE_view_layer_from_workspace_get(const struct Scene *scene, const struct WorkSpace *workspace) | ||||
| { | { | ||||
| if (BKE_workspace_use_scene_settings_get(workspace)) { | if (BKE_workspace_use_scene_settings_get(workspace)) { | ||||
| return BKE_scene_layer_from_scene_get(scene); | return BKE_view_layer_from_scene_get(scene); | ||||
| } | } | ||||
| else { | else { | ||||
| return BKE_workspace_render_layer_get(workspace); | return BKE_workspace_view_layer_get(workspace); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * This is a placeholder to know which areas of the code need to be addressed for the Workspace changes. | * This is a placeholder to know which areas of the code need to be addressed for the Workspace changes. | ||||
| * Never use this, you should either use BKE_scene_layer_workspace_active or get SceneLayer explicitly. | * Never use this, you should either use BKE_view_layer_workspace_active or get ViewLayer explicitly. | ||||
| */ | */ | ||||
| SceneLayer *BKE_scene_layer_context_active_PLACEHOLDER(const Scene *scene) | ViewLayer *BKE_view_layer_context_active_PLACEHOLDER(const Scene *scene) | ||||
| { | { | ||||
| return BKE_scene_layer_from_scene_get(scene); | return BKE_view_layer_from_scene_get(scene); | ||||
| } | } | ||||
| /** | /** | ||||
| * Add a new renderlayer | * Add a new renderlayer | ||||
| * by default, a renderlayer has the master collection | * by default, a renderlayer has the master collection | ||||
| */ | */ | ||||
| SceneLayer *BKE_scene_layer_add(Scene *scene, const char *name) | ViewLayer *BKE_view_layer_add(Scene *scene, const char *name) | ||||
| { | { | ||||
| if (!name) { | if (!name) { | ||||
| name = DATA_("Render Layer"); | name = DATA_("Render Layer"); | ||||
| } | } | ||||
| IDPropertyTemplate val = {0}; | IDPropertyTemplate val = {0}; | ||||
| SceneLayer *sl = MEM_callocN(sizeof(SceneLayer), "Scene Layer"); | ViewLayer *sl = MEM_callocN(sizeof(ViewLayer), "Scene Layer"); | ||||
| sl->flag = SCENE_LAYER_RENDER | SCENE_LAYER_FREESTYLE; | sl->flag = VIEW_LAYER_RENDER | VIEW_LAYER_FREESTYLE; | ||||
| sl->properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | sl->properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | ||||
| layer_engine_settings_init(sl->properties, false); | layer_engine_settings_init(sl->properties, false); | ||||
| BLI_addtail(&scene->render_layers, sl); | BLI_addtail(&scene->view_layers, sl); | ||||
| /* unique name */ | /* unique name */ | ||||
| BLI_strncpy_utf8(sl->name, name, sizeof(sl->name)); | BLI_strncpy_utf8(sl->name, name, sizeof(sl->name)); | ||||
| BLI_uniquename(&scene->render_layers, sl, DATA_("SceneLayer"), '.', offsetof(SceneLayer, name), sizeof(sl->name)); | BLI_uniquename(&scene->view_layers, sl, DATA_("ViewLayer"), '.', offsetof(ViewLayer, name), sizeof(sl->name)); | ||||
| SceneCollection *sc = BKE_collection_master(scene); | SceneCollection *sc = BKE_collection_master(scene); | ||||
| layer_collection_add(sl, NULL, sc); | layer_collection_add(sl, NULL, sc); | ||||
| /* Pure rendering pipeline settings. */ | /* Pure rendering pipeline settings. */ | ||||
| sl->layflag = 0x7FFF; /* solid ztra halo edge strand */ | sl->layflag = 0x7FFF; /* solid ztra halo edge strand */ | ||||
| sl->passflag = SCE_PASS_COMBINED | SCE_PASS_Z; | sl->passflag = SCE_PASS_COMBINED | SCE_PASS_Z; | ||||
| sl->pass_alpha_threshold = 0.5f; | sl->pass_alpha_threshold = 0.5f; | ||||
| BKE_freestyle_config_init(&sl->freestyle_config); | BKE_freestyle_config_init(&sl->freestyle_config); | ||||
| return sl; | return sl; | ||||
| } | } | ||||
| /** | /** | ||||
| * Free (or release) any data used by this SceneLayer. | * Free (or release) any data used by this ViewLayer. | ||||
| */ | */ | ||||
| void BKE_scene_layer_free(SceneLayer *sl) | void BKE_view_layer_free(ViewLayer *sl) | ||||
| { | { | ||||
| sl->basact = NULL; | sl->basact = NULL; | ||||
| for (Base *base = sl->object_bases.first; base; base = base->next) { | for (Base *base = sl->object_bases.first; base; base = base->next) { | ||||
| if (base->collection_properties) { | if (base->collection_properties) { | ||||
| IDP_FreeProperty(base->collection_properties); | IDP_FreeProperty(base->collection_properties); | ||||
| MEM_freeN(base->collection_properties); | MEM_freeN(base->collection_properties); | ||||
| } | } | ||||
| Show All 10 Lines | if (sl->properties) { | ||||
| MEM_freeN(sl->properties); | MEM_freeN(sl->properties); | ||||
| } | } | ||||
| if (sl->properties_evaluated) { | if (sl->properties_evaluated) { | ||||
| IDP_FreeProperty(sl->properties_evaluated); | IDP_FreeProperty(sl->properties_evaluated); | ||||
| MEM_freeN(sl->properties_evaluated); | MEM_freeN(sl->properties_evaluated); | ||||
| } | } | ||||
| for (SceneLayerEngineData *sled = sl->drawdata.first; sled; sled = sled->next) { | for (ViewLayerEngineData *sled = sl->drawdata.first; sled; sled = sled->next) { | ||||
| if (sled->storage) { | if (sled->storage) { | ||||
| if (sled->free) { | if (sled->free) { | ||||
| sled->free(sled->storage); | sled->free(sled->storage); | ||||
| } | } | ||||
| MEM_freeN(sled->storage); | MEM_freeN(sled->storage); | ||||
| } | } | ||||
| } | } | ||||
| BLI_freelistN(&sl->drawdata); | BLI_freelistN(&sl->drawdata); | ||||
| MEM_SAFE_FREE(sl->stats); | MEM_SAFE_FREE(sl->stats); | ||||
| BKE_freestyle_config_free(&sl->freestyle_config); | BKE_freestyle_config_free(&sl->freestyle_config); | ||||
| if (sl->id_properties) { | if (sl->id_properties) { | ||||
| IDP_FreeProperty(sl->id_properties); | IDP_FreeProperty(sl->id_properties); | ||||
| MEM_freeN(sl->id_properties); | MEM_freeN(sl->id_properties); | ||||
| } | } | ||||
| MEM_freeN(sl); | MEM_freeN(sl); | ||||
| } | } | ||||
| /** | /** | ||||
| * Tag all the selected objects of a renderlayer | * Tag all the selected objects of a renderlayer | ||||
| */ | */ | ||||
| void BKE_scene_layer_selected_objects_tag(SceneLayer *sl, const int tag) | void BKE_view_layer_selected_objects_tag(ViewLayer *sl, const int tag) | ||||
| { | { | ||||
| for (Base *base = sl->object_bases.first; base; base = base->next) { | for (Base *base = sl->object_bases.first; base; base = base->next) { | ||||
| if ((base->flag & BASE_SELECTED) != 0) { | if ((base->flag & BASE_SELECTED) != 0) { | ||||
| base->object->flag |= tag; | base->object->flag |= tag; | ||||
| } | } | ||||
| else { | else { | ||||
| base->object->flag &= ~tag; | base->object->flag &= ~tag; | ||||
| } | } | ||||
| Show All 11 Lines | for (LayerCollection *lcn = lb->first; lcn; lcn = lcn->next) { | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| /** | /** | ||||
| * Fallback for when a Scene has no camera to use | * Fallback for when a Scene has no camera to use | ||||
| * | * | ||||
| * \param scene_layer: in general you want to use the same SceneLayer that is used | * \param view_layer: in general you want to use the same ViewLayer that is used | ||||
| * for depsgraph. If rendering you pass the scene active layer, when viewing in the viewport | * for depsgraph. If rendering you pass the scene active layer, when viewing in the viewport | ||||
| * you want to get SceneLayer from context. | * you want to get ViewLayer from context. | ||||
| */ | */ | ||||
| Object *BKE_scene_layer_camera_find(SceneLayer *scene_layer) | Object *BKE_view_layer_camera_find(ViewLayer *view_layer) | ||||
| { | { | ||||
| for (Base *base = scene_layer->object_bases.first; base; base = base->next) { | for (Base *base = view_layer->object_bases.first; base; base = base->next) { | ||||
| if (base->object->type == OB_CAMERA) { | if (base->object->type == OB_CAMERA) { | ||||
| return base->object; | return base->object; | ||||
| } | } | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /** | /** | ||||
| * Find the SceneLayer a LayerCollection belongs to | * Find the ViewLayer a LayerCollection belongs to | ||||
| */ | */ | ||||
| SceneLayer *BKE_scene_layer_find_from_collection(const Scene *scene, LayerCollection *lc) | ViewLayer *BKE_view_layer_find_from_collection(const Scene *scene, LayerCollection *lc) | ||||
| { | { | ||||
| for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) { | for (ViewLayer *sl = scene->view_layers.first; sl; sl = sl->next) { | ||||
| if (find_scene_collection_in_scene_collections(&sl->layer_collections, lc)) { | if (find_scene_collection_in_scene_collections(&sl->layer_collections, lc)) { | ||||
| return sl; | return sl; | ||||
| } | } | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* Base */ | /* Base */ | ||||
| Base *BKE_scene_layer_base_find(SceneLayer *sl, Object *ob) | Base *BKE_view_layer_base_find(ViewLayer *sl, Object *ob) | ||||
| { | { | ||||
| return BLI_findptr(&sl->object_bases, ob, offsetof(Base, object)); | return BLI_findptr(&sl->object_bases, ob, offsetof(Base, object)); | ||||
| } | } | ||||
| void BKE_scene_layer_base_deselect_all(SceneLayer *sl) | void BKE_view_layer_base_deselect_all(ViewLayer *sl) | ||||
| { | { | ||||
| Base *base; | Base *base; | ||||
| for (base = sl->object_bases.first; base; base = base->next) { | for (base = sl->object_bases.first; base; base = base->next) { | ||||
| base->flag &= ~BASE_SELECTED; | base->flag &= ~BASE_SELECTED; | ||||
| } | } | ||||
| } | } | ||||
| void BKE_scene_layer_base_select(struct SceneLayer *sl, Base *selbase) | void BKE_view_layer_base_select(struct ViewLayer *sl, Base *selbase) | ||||
| { | { | ||||
| sl->basact = selbase; | sl->basact = selbase; | ||||
| if ((selbase->flag & BASE_SELECTABLED) != 0) { | if ((selbase->flag & BASE_SELECTABLED) != 0) { | ||||
| selbase->flag |= BASE_SELECTED; | selbase->flag |= BASE_SELECTED; | ||||
| } | } | ||||
| } | } | ||||
| static void scene_layer_object_base_unref(SceneLayer *sl, Base *base) | static void view_layer_object_base_unref(ViewLayer *sl, Base *base) | ||||
| { | { | ||||
| base->refcount--; | base->refcount--; | ||||
| /* It only exists in the RenderLayer */ | /* It only exists in the RenderLayer */ | ||||
| if (base->refcount == 0) { | if (base->refcount == 0) { | ||||
| if (sl->basact == base) { | if (sl->basact == base) { | ||||
| sl->basact = NULL; | sl->basact = NULL; | ||||
| } | } | ||||
| if (base->collection_properties) { | if (base->collection_properties) { | ||||
| IDP_FreeProperty(base->collection_properties); | IDP_FreeProperty(base->collection_properties); | ||||
| MEM_freeN(base->collection_properties); | MEM_freeN(base->collection_properties); | ||||
| } | } | ||||
| BLI_remlink(&sl->object_bases, base); | BLI_remlink(&sl->object_bases, base); | ||||
| MEM_freeN(base); | MEM_freeN(base); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Return the base if existent, or create it if necessary | * Return the base if existent, or create it if necessary | ||||
| * Always bump the refcount | * Always bump the refcount | ||||
| */ | */ | ||||
| static Base *object_base_add(SceneLayer *sl, Object *ob) | static Base *object_base_add(ViewLayer *sl, Object *ob) | ||||
| { | { | ||||
| Base *base; | Base *base; | ||||
| base = BKE_scene_layer_base_find(sl, ob); | base = BKE_view_layer_base_find(sl, ob); | ||||
| if (base == NULL) { | if (base == NULL) { | ||||
| base = MEM_callocN(sizeof(Base), "Object Base"); | base = MEM_callocN(sizeof(Base), "Object Base"); | ||||
| /* Do not bump user count, leave it for SceneCollections. */ | /* Do not bump user count, leave it for SceneCollections. */ | ||||
| base->object = ob; | base->object = ob; | ||||
| BLI_addtail(&sl->object_bases, base); | BLI_addtail(&sl->object_bases, base); | ||||
| IDPropertyTemplate val = {0}; | IDPropertyTemplate val = {0}; | ||||
| base->collection_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | base->collection_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | ||||
| } | } | ||||
| base->refcount++; | base->refcount++; | ||||
| return base; | return base; | ||||
| } | } | ||||
| /* LayerCollection */ | /* LayerCollection */ | ||||
| static void layer_collection_objects_unpopulate(SceneLayer *sl, LayerCollection *lc) | static void layer_collection_objects_unpopulate(ViewLayer *sl, LayerCollection *lc) | ||||
| { | { | ||||
| if (sl) { | if (sl) { | ||||
| for (LinkData *link = lc->object_bases.first; link; link = link->next) { | for (LinkData *link = lc->object_bases.first; link; link = link->next) { | ||||
| scene_layer_object_base_unref(sl, link->data); | view_layer_object_base_unref(sl, link->data); | ||||
| } | } | ||||
| } | } | ||||
| BLI_freelistN(&lc->object_bases); | BLI_freelistN(&lc->object_bases); | ||||
| } | } | ||||
| /** | /** | ||||
| * When freeing the entire SceneLayer at once we don't bother with unref | * When freeing the entire ViewLayer at once we don't bother with unref | ||||
| * otherwise SceneLayer is passed to keep the syncing of the LayerCollection tree | * otherwise ViewLayer is passed to keep the syncing of the LayerCollection tree | ||||
| */ | */ | ||||
| static void layer_collection_free(SceneLayer *sl, LayerCollection *lc) | static void layer_collection_free(ViewLayer *sl, LayerCollection *lc) | ||||
| { | { | ||||
| layer_collection_objects_unpopulate(sl, lc); | layer_collection_objects_unpopulate(sl, lc); | ||||
| BLI_freelistN(&lc->overrides); | BLI_freelistN(&lc->overrides); | ||||
| if (lc->properties) { | if (lc->properties) { | ||||
| IDP_FreeProperty(lc->properties); | IDP_FreeProperty(lc->properties); | ||||
| MEM_freeN(lc->properties); | MEM_freeN(lc->properties); | ||||
| } | } | ||||
| if (lc->properties_evaluated) { | if (lc->properties_evaluated) { | ||||
| IDP_FreeProperty(lc->properties_evaluated); | IDP_FreeProperty(lc->properties_evaluated); | ||||
| MEM_freeN(lc->properties_evaluated); | MEM_freeN(lc->properties_evaluated); | ||||
| } | } | ||||
| for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) { | for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) { | ||||
| layer_collection_free(sl, nlc); | layer_collection_free(sl, nlc); | ||||
| } | } | ||||
| BLI_freelistN(&lc->layer_collections); | BLI_freelistN(&lc->layer_collections); | ||||
| } | } | ||||
| /** | /** | ||||
| * Free (or release) LayerCollection from SceneLayer | * Free (or release) LayerCollection from ViewLayer | ||||
| * (does not free the LayerCollection itself). | * (does not free the LayerCollection itself). | ||||
| */ | */ | ||||
| void BKE_layer_collection_free(SceneLayer *sl, LayerCollection *lc) | void BKE_layer_collection_free(ViewLayer *sl, LayerCollection *lc) | ||||
| { | { | ||||
| layer_collection_free(sl, lc); | layer_collection_free(sl, lc); | ||||
| } | } | ||||
| /* LayerCollection */ | /* LayerCollection */ | ||||
| /** | /** | ||||
| * Recursively get the collection for a given index | * Recursively get the collection for a given index | ||||
| Show All 13 Lines | for (LayerCollection *lc = lb->first; lc; lc = lc->next) { | ||||
| } | } | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /** | /** | ||||
| * Get the collection for a given index | * Get the collection for a given index | ||||
| */ | */ | ||||
| LayerCollection *BKE_layer_collection_from_index(SceneLayer *sl, const int index) | LayerCollection *BKE_layer_collection_from_index(ViewLayer *sl, const int index) | ||||
| { | { | ||||
| int i = 0; | int i = 0; | ||||
| return collection_from_index(&sl->layer_collections, index, &i); | return collection_from_index(&sl->layer_collections, index, &i); | ||||
| } | } | ||||
| /** | /** | ||||
| * Get the active collection | * Get the active collection | ||||
| */ | */ | ||||
| LayerCollection *BKE_layer_collection_get_active(SceneLayer *sl) | LayerCollection *BKE_layer_collection_get_active(ViewLayer *sl) | ||||
| { | { | ||||
| int i = 0; | int i = 0; | ||||
| return collection_from_index(&sl->layer_collections, sl->active_collection, &i); | return collection_from_index(&sl->layer_collections, sl->active_collection, &i); | ||||
| } | } | ||||
| /** | /** | ||||
| * Return layer collection to add new object(s). | * Return layer collection to add new object(s). | ||||
| * Create one if none exists. | * Create one if none exists. | ||||
| */ | */ | ||||
| LayerCollection *BKE_layer_collection_get_active_ensure(Scene *scene, SceneLayer *sl) | LayerCollection *BKE_layer_collection_get_active_ensure(Scene *scene, ViewLayer *sl) | ||||
| { | { | ||||
| LayerCollection *lc = BKE_layer_collection_get_active(sl); | LayerCollection *lc = BKE_layer_collection_get_active(sl); | ||||
| if (lc == NULL) { | if (lc == NULL) { | ||||
| BLI_assert(BLI_listbase_is_empty(&sl->layer_collections)); | BLI_assert(BLI_listbase_is_empty(&sl->layer_collections)); | ||||
| /* When there is no collection linked to this SceneLayer, create one. */ | /* When there is no collection linked to this ViewLayer, create one. */ | ||||
| SceneCollection *sc = BKE_collection_add(scene, NULL, NULL); | SceneCollection *sc = BKE_collection_add(scene, NULL, NULL); | ||||
| lc = BKE_collection_link(sl, sc); | lc = BKE_collection_link(sl, sc); | ||||
| /* New collection has to be the active one. */ | /* New collection has to be the active one. */ | ||||
| BLI_assert(lc == BKE_layer_collection_get_active(sl)); | BLI_assert(lc == BKE_layer_collection_get_active(sl)); | ||||
| } | } | ||||
| return lc; | return lc; | ||||
| } | } | ||||
| Show All 9 Lines | static int collection_count(ListBase *lb) | ||||
| } | } | ||||
| return i; | return i; | ||||
| } | } | ||||
| /** | /** | ||||
| * Get the total number of collections | * Get the total number of collections | ||||
| * (including all the nested collections) | * (including all the nested collections) | ||||
| */ | */ | ||||
| int BKE_layer_collection_count(SceneLayer *sl) | int BKE_layer_collection_count(ViewLayer *sl) | ||||
| { | { | ||||
| return collection_count(&sl->layer_collections); | return collection_count(&sl->layer_collections); | ||||
| } | } | ||||
| /** | /** | ||||
| * Recursively get the index for a given collection | * Recursively get the index for a given collection | ||||
| */ | */ | ||||
| static int index_from_collection(ListBase *lb, const LayerCollection *lc, int *i) | static int index_from_collection(ListBase *lb, const LayerCollection *lc, int *i) | ||||
| Show All 11 Lines | for (LayerCollection *lcol = lb->first; lcol; lcol = lcol->next) { | ||||
| } | } | ||||
| } | } | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| /** | /** | ||||
| * Return -1 if not found | * Return -1 if not found | ||||
| */ | */ | ||||
| int BKE_layer_collection_findindex(SceneLayer *sl, const LayerCollection *lc) | int BKE_layer_collection_findindex(ViewLayer *sl, const LayerCollection *lc) | ||||
| { | { | ||||
| int i = 0; | int i = 0; | ||||
| return index_from_collection(&sl->layer_collections, lc, &i); | return index_from_collection(&sl->layer_collections, lc, &i); | ||||
| } | } | ||||
| /** | /** | ||||
| * Lookup the listbase that contains \a lc. | * Lookup the listbase that contains \a lc. | ||||
| */ | */ | ||||
| Show All 34 Lines | |||||
| } | } | ||||
| #endif | #endif | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| /* Outliner drag and drop */ | /* Outliner drag and drop */ | ||||
| /** | /** | ||||
| * Nest a LayerCollection into another one | * Nest a LayerCollection into another one | ||||
| * Both collections must be from the same SceneLayer, return true if succeded. | * Both collections must be from the same ViewLayer, return true if succeded. | ||||
| * | * | ||||
| * The LayerCollection will effectively be moved into the | * The LayerCollection will effectively be moved into the | ||||
| * new (nested) position. So all the settings, overrides, ... go with it, and | * new (nested) position. So all the settings, overrides, ... go with it, and | ||||
| * if the collection was directly linked to the SceneLayer it's then unlinked. | * if the collection was directly linked to the ViewLayer it's then unlinked. | ||||
| * | * | ||||
| * For the other SceneLayers we simply resync the tree, without changing directly | * For the other ViewLayers we simply resync the tree, without changing directly | ||||
| * linked collections (even if they link to the same SceneCollection) | * linked collections (even if they link to the same SceneCollection) | ||||
| * | * | ||||
| * \param lc_src LayerCollection to nest into \a lc_dst | * \param lc_src LayerCollection to nest into \a lc_dst | ||||
| * \param lc_dst LayerCollection to have \a lc_src inserted into | * \param lc_dst LayerCollection to have \a lc_src inserted into | ||||
| */ | */ | ||||
| static void layer_collection_swap( | static void layer_collection_swap( | ||||
| SceneLayer *sl, ListBase *lb_a, ListBase *lb_b, | ViewLayer *sl, ListBase *lb_a, ListBase *lb_b, | ||||
| LayerCollection *lc_a, LayerCollection *lc_b) | LayerCollection *lc_a, LayerCollection *lc_b) | ||||
| { | { | ||||
| if (lb_a == NULL) { | if (lb_a == NULL) { | ||||
| lb_a = layer_collection_listbase_find(&sl->layer_collections, lc_a); | lb_a = layer_collection_listbase_find(&sl->layer_collections, lc_a); | ||||
| } | } | ||||
| if (lb_b == NULL) { | if (lb_b == NULL) { | ||||
| lb_b = layer_collection_listbase_find(&sl->layer_collections, lc_b); | lb_b = layer_collection_listbase_find(&sl->layer_collections, lc_b); | ||||
| } | } | ||||
| BLI_assert(lb_a); | BLI_assert(lb_a); | ||||
| BLI_assert(lb_b); | BLI_assert(lb_b); | ||||
| BLI_listbases_swaplinks(lb_a, lb_b, lc_a, lc_b); | BLI_listbases_swaplinks(lb_a, lb_b, lc_a, lc_b); | ||||
| } | } | ||||
| /** | /** | ||||
| * Move \a lc_src into \a lc_dst. Both have to be stored in \a sl. | * Move \a lc_src into \a lc_dst. Both have to be stored in \a sl. | ||||
| * If \a lc_src is directly linked to the SceneLayer it's unlinked | * If \a lc_src is directly linked to the ViewLayer it's unlinked | ||||
| */ | */ | ||||
| bool BKE_layer_collection_move_into(const Scene *scene, LayerCollection *lc_dst, LayerCollection *lc_src) | bool BKE_layer_collection_move_into(const Scene *scene, LayerCollection *lc_dst, LayerCollection *lc_src) | ||||
| { | { | ||||
| SceneLayer *sl = BKE_scene_layer_find_from_collection(scene, lc_src); | ViewLayer *sl = BKE_view_layer_find_from_collection(scene, lc_src); | ||||
| bool is_directly_linked = false; | bool is_directly_linked = false; | ||||
| if ((!sl) || (sl != BKE_scene_layer_find_from_collection(scene, lc_dst))) { | if ((!sl) || (sl != BKE_view_layer_find_from_collection(scene, lc_dst))) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* We can't nest the collection into itself */ | /* We can't nest the collection into itself */ | ||||
| if (lc_src->scene_collection == lc_dst->scene_collection) { | if (lc_src->scene_collection == lc_dst->scene_collection) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if (BLI_findindex(&sl->layer_collections, lc_new) != -1) { | ||||
| BKE_collection_unlink(sl, lc_new); | BKE_collection_unlink(sl, lc_new); | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| /** | /** | ||||
| * Move \a lc_src above \a lc_dst. Both have to be stored in \a sl. | * Move \a lc_src above \a lc_dst. Both have to be stored in \a sl. | ||||
| * If \a lc_src is directly linked to the SceneLayer it's unlinked | * If \a lc_src is directly linked to the ViewLayer it's unlinked | ||||
| */ | */ | ||||
| bool BKE_layer_collection_move_above(const Scene *scene, LayerCollection *lc_dst, LayerCollection *lc_src) | bool BKE_layer_collection_move_above(const Scene *scene, LayerCollection *lc_dst, LayerCollection *lc_src) | ||||
| { | { | ||||
| SceneLayer *sl = BKE_scene_layer_find_from_collection(scene, lc_src); | ViewLayer *sl = BKE_view_layer_find_from_collection(scene, lc_src); | ||||
| const bool is_directly_linked_src = BLI_findindex(&sl->layer_collections, lc_src) != -1; | const bool is_directly_linked_src = BLI_findindex(&sl->layer_collections, lc_src) != -1; | ||||
| const bool is_directly_linked_dst = BLI_findindex(&sl->layer_collections, lc_dst) != -1; | const bool is_directly_linked_dst = BLI_findindex(&sl->layer_collections, lc_dst) != -1; | ||||
| if ((!sl) || (sl != BKE_scene_layer_find_from_collection(scene, lc_dst))) { | if ((!sl) || (sl != BKE_view_layer_find_from_collection(scene, lc_dst))) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* Collection is already where we wanted it to be */ | /* Collection is already where we wanted it to be */ | ||||
| if (lc_dst->prev == lc_src) { | if (lc_dst->prev == lc_src) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* Collection is already where we want it to be in the scene tree | /* Collection is already where we want it to be in the scene tree | ||||
| * but we want to swap it in the layer tree still */ | * but we want to swap it in the layer tree still */ | ||||
| if (lc_dst->prev && lc_dst->prev->scene_collection == lc_src->scene_collection) { | if (lc_dst->prev && lc_dst->prev->scene_collection == lc_src->scene_collection) { | ||||
| LayerCollection *lc_swap = lc_dst->prev; | LayerCollection *lc_swap = lc_dst->prev; | ||||
| layer_collection_swap(sl, NULL, NULL, lc_dst->prev, lc_src); | layer_collection_swap(sl, NULL, NULL, lc_dst->prev, lc_src); | ||||
| if (BLI_findindex(&sl->layer_collections, lc_swap) != -1) { | if (BLI_findindex(&sl->layer_collections, lc_swap) != -1) { | ||||
| BKE_collection_unlink(sl, lc_swap); | BKE_collection_unlink(sl, lc_swap); | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| /* We don't allow to move above/below a directly linked collection | /* We don't allow to move above/below a directly linked collection | ||||
| * unless the source collection is also directly linked */ | * unless the source collection is also directly linked */ | ||||
| else if (is_directly_linked_dst) { | else if (is_directly_linked_dst) { | ||||
| /* Both directly linked to the SceneLayer, just need to swap */ | /* Both directly linked to the ViewLayer, just need to swap */ | ||||
| if (is_directly_linked_src) { | if (is_directly_linked_src) { | ||||
| BLI_remlink(&sl->layer_collections, lc_src); | BLI_remlink(&sl->layer_collections, lc_src); | ||||
| BLI_insertlinkbefore(&sl->layer_collections, lc_dst, lc_src); | BLI_insertlinkbefore(&sl->layer_collections, lc_dst, lc_src); | ||||
| return true; | return true; | ||||
| } | } | ||||
| else { | else { | ||||
| return false; | return false; | ||||
| } | } | ||||
| Show All 27 Lines | if (BLI_findindex(&sl->layer_collections, lc_new) != -1) { | ||||
| BKE_collection_unlink(sl, lc_new); | BKE_collection_unlink(sl, lc_new); | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| /** | /** | ||||
| * Move \a lc_src below \a lc_dst. Both have to be stored in \a sl. | * Move \a lc_src below \a lc_dst. Both have to be stored in \a sl. | ||||
| * If \a lc_src is directly linked to the SceneLayer it's unlinked | * If \a lc_src is directly linked to the ViewLayer it's unlinked | ||||
| */ | */ | ||||
| bool BKE_layer_collection_move_below(const Scene *scene, LayerCollection *lc_dst, LayerCollection *lc_src) | bool BKE_layer_collection_move_below(const Scene *scene, LayerCollection *lc_dst, LayerCollection *lc_src) | ||||
| { | { | ||||
| SceneLayer *sl = BKE_scene_layer_find_from_collection(scene, lc_src); | ViewLayer *sl = BKE_view_layer_find_from_collection(scene, lc_src); | ||||
| const bool is_directly_linked_src = BLI_findindex(&sl->layer_collections, lc_src) != -1; | const bool is_directly_linked_src = BLI_findindex(&sl->layer_collections, lc_src) != -1; | ||||
| const bool is_directly_linked_dst = BLI_findindex(&sl->layer_collections, lc_dst) != -1; | const bool is_directly_linked_dst = BLI_findindex(&sl->layer_collections, lc_dst) != -1; | ||||
| if ((!sl) || (sl != BKE_scene_layer_find_from_collection(scene, lc_dst))) { | if ((!sl) || (sl != BKE_view_layer_find_from_collection(scene, lc_dst))) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* Collection is already where we wanted it to be */ | /* Collection is already where we wanted it to be */ | ||||
| if (lc_dst->next == lc_src) { | if (lc_dst->next == lc_src) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* Collection is already where we want it to be in the scene tree | /* Collection is already where we want it to be in the scene tree | ||||
| * but we want to swap it in the layer tree still */ | * but we want to swap it in the layer tree still */ | ||||
| if (lc_dst->next && lc_dst->next->scene_collection == lc_src->scene_collection) { | if (lc_dst->next && lc_dst->next->scene_collection == lc_src->scene_collection) { | ||||
| LayerCollection *lc_swap = lc_dst->next; | LayerCollection *lc_swap = lc_dst->next; | ||||
| layer_collection_swap(sl, NULL, NULL, lc_dst->next, lc_src); | layer_collection_swap(sl, NULL, NULL, lc_dst->next, lc_src); | ||||
| if (BLI_findindex(&sl->layer_collections, lc_swap) != -1) { | if (BLI_findindex(&sl->layer_collections, lc_swap) != -1) { | ||||
| BKE_collection_unlink(sl, lc_swap); | BKE_collection_unlink(sl, lc_swap); | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| /* We don't allow to move above/below a directly linked collection | /* We don't allow to move above/below a directly linked collection | ||||
| * unless the source collection is also directly linked */ | * unless the source collection is also directly linked */ | ||||
| else if (is_directly_linked_dst) { | else if (is_directly_linked_dst) { | ||||
| /* Both directly linked to the SceneLayer, just need to swap */ | /* Both directly linked to the ViewLayer, just need to swap */ | ||||
| if (is_directly_linked_src) { | if (is_directly_linked_src) { | ||||
| BLI_remlink(&sl->layer_collections, lc_src); | BLI_remlink(&sl->layer_collections, lc_src); | ||||
| BLI_insertlinkafter(&sl->layer_collections, lc_dst, lc_src); | BLI_insertlinkafter(&sl->layer_collections, lc_dst, lc_src); | ||||
| return true; | return true; | ||||
| } | } | ||||
| else { | else { | ||||
| return false; | return false; | ||||
| } | } | ||||
| Show All 25 Lines | bool BKE_layer_collection_move_below(const Scene *scene, LayerCollection *lc_dst, LayerCollection *lc_src) | ||||
| /* If it's directly linked, unlink it after the swap */ | /* If it's directly linked, unlink it after the swap */ | ||||
| if (BLI_findindex(&sl->layer_collections, lc_new) != -1) { | if (BLI_findindex(&sl->layer_collections, lc_new) != -1) { | ||||
| BKE_collection_unlink(sl, lc_new); | BKE_collection_unlink(sl, lc_new); | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| static bool layer_collection_resync(SceneLayer *sl, LayerCollection *lc, const SceneCollection *sc) | static bool layer_collection_resync(ViewLayer *sl, LayerCollection *lc, const SceneCollection *sc) | ||||
| { | { | ||||
| if (lc->scene_collection == sc) { | if (lc->scene_collection == sc) { | ||||
| ListBase collections = {NULL}; | ListBase collections = {NULL}; | ||||
| BLI_movelisttolist(&collections, &lc->layer_collections); | BLI_movelisttolist(&collections, &lc->layer_collections); | ||||
| for (SceneCollection *sc_nested = sc->scene_collections.first; sc_nested; sc_nested = sc_nested->next) { | for (SceneCollection *sc_nested = sc->scene_collections.first; sc_nested; sc_nested = sc_nested->next) { | ||||
| LayerCollection *lc_nested = BLI_findptr(&collections, sc_nested, offsetof(LayerCollection, scene_collection)); | LayerCollection *lc_nested = BLI_findptr(&collections, sc_nested, offsetof(LayerCollection, scene_collection)); | ||||
| if (lc_nested) { | if (lc_nested) { | ||||
| Show All 26 Lines | |||||
| } | } | ||||
| /** | /** | ||||
| * Update the scene layers so that any LayerCollection that points | * Update the scene layers so that any LayerCollection that points | ||||
| * to \a sc is re-synced again | * to \a sc is re-synced again | ||||
| */ | */ | ||||
| void BKE_layer_collection_resync(const Scene *scene, const SceneCollection *sc) | void BKE_layer_collection_resync(const Scene *scene, const SceneCollection *sc) | ||||
| { | { | ||||
| for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) { | for (ViewLayer *sl = scene->view_layers.first; sl; sl = sl->next) { | ||||
| for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) { | for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) { | ||||
| layer_collection_resync(sl, lc, sc); | layer_collection_resync(sl, lc, sc); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| /** | /** | ||||
| * Link a collection to a renderlayer | * Link a collection to a renderlayer | ||||
| * The collection needs to be created separately | * The collection needs to be created separately | ||||
| */ | */ | ||||
| LayerCollection *BKE_collection_link(SceneLayer *sl, SceneCollection *sc) | LayerCollection *BKE_collection_link(ViewLayer *sl, SceneCollection *sc) | ||||
| { | { | ||||
| LayerCollection *lc = layer_collection_add(sl, NULL, sc); | LayerCollection *lc = layer_collection_add(sl, NULL, sc); | ||||
| sl->active_collection = BKE_layer_collection_findindex(sl, lc); | sl->active_collection = BKE_layer_collection_findindex(sl, lc); | ||||
| return lc; | return lc; | ||||
| } | } | ||||
| /** | /** | ||||
| * Unlink a collection base from a renderlayer | * Unlink a collection base from a renderlayer | ||||
| * The corresponding collection is not removed from the master collection | * The corresponding collection is not removed from the master collection | ||||
| */ | */ | ||||
| void BKE_collection_unlink(SceneLayer *sl, LayerCollection *lc) | void BKE_collection_unlink(ViewLayer *sl, LayerCollection *lc) | ||||
| { | { | ||||
| BKE_layer_collection_free(sl, lc); | BKE_layer_collection_free(sl, lc); | ||||
| BLI_remlink(&sl->layer_collections, lc); | BLI_remlink(&sl->layer_collections, lc); | ||||
| MEM_freeN(lc); | MEM_freeN(lc); | ||||
| sl->active_collection = 0; | sl->active_collection = 0; | ||||
| } | } | ||||
| /** | /** | ||||
| * Recursively enable nested collections | * Recursively enable nested collections | ||||
| */ | */ | ||||
| static void layer_collection_enable(SceneLayer *sl, LayerCollection *lc) | static void layer_collection_enable(ViewLayer *sl, LayerCollection *lc) | ||||
| { | { | ||||
| layer_collection_objects_populate(sl, lc, &lc->scene_collection->objects); | layer_collection_objects_populate(sl, lc, &lc->scene_collection->objects); | ||||
| for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) { | for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) { | ||||
| layer_collection_enable(sl, nlc); | layer_collection_enable(sl, nlc); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Enable collection | * Enable collection | ||||
| * Add its objects bases to SceneLayer | * Add its objects bases to ViewLayer | ||||
| * Depsgraph needs to be rebuilt afterwards | * Depsgraph needs to be rebuilt afterwards | ||||
| */ | */ | ||||
| void BKE_collection_enable(SceneLayer *sl, LayerCollection *lc) | void BKE_collection_enable(ViewLayer *sl, LayerCollection *lc) | ||||
| { | { | ||||
| if ((lc->flag & COLLECTION_DISABLED) == 0) { | if ((lc->flag & COLLECTION_DISABLED) == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| lc->flag &= ~COLLECTION_DISABLED; | lc->flag &= ~COLLECTION_DISABLED; | ||||
| layer_collection_enable(sl, lc); | layer_collection_enable(sl, lc); | ||||
| } | } | ||||
| /** | /** | ||||
| * Recursively disable nested collections | * Recursively disable nested collections | ||||
| */ | */ | ||||
| static void layer_collection_disable(SceneLayer *sl, LayerCollection *lc) | static void layer_collection_disable(ViewLayer *sl, LayerCollection *lc) | ||||
| { | { | ||||
| layer_collection_objects_unpopulate(sl, lc); | layer_collection_objects_unpopulate(sl, lc); | ||||
| for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) { | for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) { | ||||
| layer_collection_disable(sl, nlc); | layer_collection_disable(sl, nlc); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Disable collection | * Disable collection | ||||
| * Remove all its object bases from SceneLayer | * Remove all its object bases from ViewLayer | ||||
| * Depsgraph needs to be rebuilt afterwards | * Depsgraph needs to be rebuilt afterwards | ||||
| */ | */ | ||||
| void BKE_collection_disable(SceneLayer *sl, LayerCollection *lc) | void BKE_collection_disable(ViewLayer *sl, LayerCollection *lc) | ||||
| { | { | ||||
| if ((lc->flag & COLLECTION_DISABLED) != 0) { | if ((lc->flag & COLLECTION_DISABLED) != 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| lc->flag |= COLLECTION_DISABLED; | lc->flag |= COLLECTION_DISABLED; | ||||
| layer_collection_disable(sl, lc); | layer_collection_disable(sl, lc); | ||||
| } | } | ||||
| static void layer_collection_object_add(SceneLayer *sl, LayerCollection *lc, Object *ob) | static void layer_collection_object_add(ViewLayer *sl, LayerCollection *lc, Object *ob) | ||||
| { | { | ||||
| Base *base = object_base_add(sl, ob); | Base *base = object_base_add(sl, ob); | ||||
| /* Only add an object once - prevent SceneCollection->objects and | /* Only add an object once - prevent SceneCollection->objects and | ||||
| * SceneCollection->filter_objects to add the same object. */ | * SceneCollection->filter_objects to add the same object. */ | ||||
| if (BLI_findptr(&lc->object_bases, base, offsetof(LinkData, data))) { | if (BLI_findptr(&lc->object_bases, base, offsetof(LinkData, data))) { | ||||
| return; | return; | ||||
| } | } | ||||
| bool is_visible = (lc->flag & COLLECTION_VISIBLE) != 0; | bool is_visible = (lc->flag & COLLECTION_VISIBLE) != 0; | ||||
| bool is_selectable = is_visible && ((lc->flag & COLLECTION_SELECTABLE) != 0); | bool is_selectable = is_visible && ((lc->flag & COLLECTION_SELECTABLE) != 0); | ||||
| if (is_visible) { | if (is_visible) { | ||||
| base->flag |= BASE_VISIBLED; | base->flag |= BASE_VISIBLED; | ||||
| } | } | ||||
| if (is_selectable) { | if (is_selectable) { | ||||
| base->flag |= BASE_SELECTABLED; | base->flag |= BASE_SELECTABLED; | ||||
| } | } | ||||
| BLI_addtail(&lc->object_bases, BLI_genericNodeN(base)); | BLI_addtail(&lc->object_bases, BLI_genericNodeN(base)); | ||||
| } | } | ||||
| static void layer_collection_object_remove(SceneLayer *sl, LayerCollection *lc, Object *ob) | static void layer_collection_object_remove(ViewLayer *sl, LayerCollection *lc, Object *ob) | ||||
| { | { | ||||
| Base *base; | Base *base; | ||||
| base = BKE_scene_layer_base_find(sl, ob); | base = BKE_view_layer_base_find(sl, ob); | ||||
| LinkData *link = BLI_findptr(&lc->object_bases, base, offsetof(LinkData, data)); | LinkData *link = BLI_findptr(&lc->object_bases, base, offsetof(LinkData, data)); | ||||
| BLI_remlink(&lc->object_bases, link); | BLI_remlink(&lc->object_bases, link); | ||||
| MEM_freeN(link); | MEM_freeN(link); | ||||
| scene_layer_object_base_unref(sl, base); | view_layer_object_base_unref(sl, base); | ||||
| } | } | ||||
| static void layer_collection_objects_populate(SceneLayer *sl, LayerCollection *lc, ListBase *objects) | static void layer_collection_objects_populate(ViewLayer *sl, LayerCollection *lc, ListBase *objects) | ||||
| { | { | ||||
| for (LinkData *link = objects->first; link; link = link->next) { | for (LinkData *link = objects->first; link; link = link->next) { | ||||
| layer_collection_object_add(sl, lc, link->data); | layer_collection_object_add(sl, lc, link->data); | ||||
| } | } | ||||
| } | } | ||||
| static void layer_collection_populate(SceneLayer *sl, LayerCollection *lc, SceneCollection *sc) | static void layer_collection_populate(ViewLayer *sl, LayerCollection *lc, SceneCollection *sc) | ||||
| { | { | ||||
| layer_collection_objects_populate(sl, lc, &sc->objects); | layer_collection_objects_populate(sl, lc, &sc->objects); | ||||
| layer_collection_objects_populate(sl, lc, &sc->filter_objects); | layer_collection_objects_populate(sl, lc, &sc->filter_objects); | ||||
| for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) { | for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) { | ||||
| layer_collection_add(sl, lc, nsc); | layer_collection_add(sl, lc, nsc); | ||||
| } | } | ||||
| } | } | ||||
| static LayerCollection *layer_collection_add(SceneLayer *sl, LayerCollection *parent, SceneCollection *sc) | static LayerCollection *layer_collection_add(ViewLayer *sl, LayerCollection *parent, SceneCollection *sc) | ||||
| { | { | ||||
| IDPropertyTemplate val = {0}; | IDPropertyTemplate val = {0}; | ||||
| LayerCollection *lc = MEM_callocN(sizeof(LayerCollection), "Collection Base"); | LayerCollection *lc = MEM_callocN(sizeof(LayerCollection), "Collection Base"); | ||||
| lc->scene_collection = sc; | lc->scene_collection = sc; | ||||
| lc->flag = COLLECTION_VISIBLE | COLLECTION_SELECTABLE; | lc->flag = COLLECTION_VISIBLE | COLLECTION_SELECTABLE; | ||||
| lc->properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | lc->properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | ||||
| Show All 11 Lines | static LayerCollection *layer_collection_add(ViewLayer *sl, LayerCollection *parent, SceneCollection *sc) | ||||
| return lc; | return lc; | ||||
| } | } | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| /** | /** | ||||
| * See if render layer has the scene collection linked directly, or indirectly (nested) | * See if render layer has the scene collection linked directly, or indirectly (nested) | ||||
| */ | */ | ||||
| bool BKE_scene_layer_has_collection(SceneLayer *sl, const SceneCollection *sc) | bool BKE_view_layer_has_collection(ViewLayer *sl, const SceneCollection *sc) | ||||
| { | { | ||||
| for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) { | for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) { | ||||
| if (find_layer_collection_by_scene_collection(lc, sc) != NULL) { | if (find_layer_collection_by_scene_collection(lc, sc) != NULL) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| /** | /** | ||||
| * See if the object is in any of the scene layers of the scene | * See if the object is in any of the scene layers of the scene | ||||
| */ | */ | ||||
| bool BKE_scene_has_object(Scene *scene, Object *ob) | bool BKE_scene_has_object(Scene *scene, Object *ob) | ||||
| { | { | ||||
| for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) { | for (ViewLayer *sl = scene->view_layers.first; sl; sl = sl->next) { | ||||
| Base *base = BKE_scene_layer_base_find(sl, ob); | Base *base = BKE_view_layer_base_find(sl, ob); | ||||
| if (base) { | if (base) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| Show All 11 Lines | for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) { | ||||
| if (found) { | if (found) { | ||||
| return found; | return found; | ||||
| } | } | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /** | /** | ||||
| * Add a new LayerCollection for all the SceneLayers that have sc_parent | * Add a new LayerCollection for all the ViewLayers that have sc_parent | ||||
| */ | */ | ||||
| void BKE_layer_sync_new_scene_collection(Scene *scene, const SceneCollection *sc_parent, SceneCollection *sc) | void BKE_layer_sync_new_scene_collection(Scene *scene, const SceneCollection *sc_parent, SceneCollection *sc) | ||||
| { | { | ||||
| for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) { | for (ViewLayer *sl = scene->view_layers.first; sl; sl = sl->next) { | ||||
| for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) { | for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) { | ||||
| LayerCollection *lc_parent = find_layer_collection_by_scene_collection(lc, sc_parent); | LayerCollection *lc_parent = find_layer_collection_by_scene_collection(lc, sc_parent); | ||||
| if (lc_parent) { | if (lc_parent) { | ||||
| layer_collection_add(sl, lc_parent, sc); | layer_collection_add(sl, lc_parent, sc); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Add a corresponding ObjectBase to all the equivalent LayerCollection | * Add a corresponding ObjectBase to all the equivalent LayerCollection | ||||
| */ | */ | ||||
| void BKE_layer_sync_object_link(const Scene *scene, SceneCollection *sc, Object *ob) | void BKE_layer_sync_object_link(const Scene *scene, SceneCollection *sc, Object *ob) | ||||
| { | { | ||||
| for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) { | for (ViewLayer *sl = scene->view_layers.first; sl; sl = sl->next) { | ||||
| for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) { | for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) { | ||||
| LayerCollection *found = find_layer_collection_by_scene_collection(lc, sc); | LayerCollection *found = find_layer_collection_by_scene_collection(lc, sc); | ||||
| if (found) { | if (found) { | ||||
| layer_collection_object_add(sl, found, ob); | layer_collection_object_add(sl, found, ob); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Remove the equivalent object base to all layers that have this collection | * Remove the equivalent object base to all layers that have this collection | ||||
| * also remove all reference to ob in the filter_objects | * also remove all reference to ob in the filter_objects | ||||
| */ | */ | ||||
| void BKE_layer_sync_object_unlink(const Scene *scene, SceneCollection *sc, Object *ob) | void BKE_layer_sync_object_unlink(const Scene *scene, SceneCollection *sc, Object *ob) | ||||
| { | { | ||||
| for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) { | for (ViewLayer *sl = scene->view_layers.first; sl; sl = sl->next) { | ||||
| for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) { | for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) { | ||||
| LayerCollection *found = find_layer_collection_by_scene_collection(lc, sc); | LayerCollection *found = find_layer_collection_by_scene_collection(lc, sc); | ||||
| if (found) { | if (found) { | ||||
| layer_collection_object_remove(sl, found, ob); | layer_collection_object_remove(sl, found, ob); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| /* Override */ | /* Override */ | ||||
| /** | /** | ||||
| * Add a new datablock override | * Add a new datablock override | ||||
| */ | */ | ||||
| void BKE_override_scene_layer_datablock_add(SceneLayer *scene_layer, int id_type, const char *data_path, const ID *id) | void BKE_override_view_layer_datablock_add(ViewLayer *view_layer, int id_type, const char *data_path, const ID *id) | ||||
| { | { | ||||
| UNUSED_VARS(scene_layer, id_type, data_path, id); | UNUSED_VARS(view_layer, id_type, data_path, id); | ||||
| TODO_LAYER_OVERRIDE; | TODO_LAYER_OVERRIDE; | ||||
| } | } | ||||
| /** | /** | ||||
| * Add a new int override | * Add a new int override | ||||
| */ | */ | ||||
| void BKE_override_scene_layer_int_add(SceneLayer *scene_layer, int id_type, const char *data_path, const int value) | void BKE_override_view_layer_int_add(ViewLayer *view_layer, int id_type, const char *data_path, const int value) | ||||
| { | { | ||||
| UNUSED_VARS(scene_layer, id_type, data_path, value); | UNUSED_VARS(view_layer, id_type, data_path, value); | ||||
| TODO_LAYER_OVERRIDE; | TODO_LAYER_OVERRIDE; | ||||
| } | } | ||||
| /** | /** | ||||
| * Add a new boolean override | * Add a new boolean override | ||||
| */ | */ | ||||
| void BKE_override_layer_collection_boolean_add(struct LayerCollection *layer_collection, int id_type, const char *data_path, const bool value) | void BKE_override_layer_collection_boolean_add(struct LayerCollection *layer_collection, int id_type, const char *data_path, const bool value) | ||||
| { | { | ||||
| UNUSED_VARS(layer_collection, id_type, data_path, value); | UNUSED_VARS(layer_collection, id_type, data_path, value); | ||||
| TODO_LAYER_OVERRIDE; | TODO_LAYER_OVERRIDE; | ||||
| } | } | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| /* Engine Settings */ | /* Engine Settings */ | ||||
| ListBase R_layer_collection_engines_settings_callbacks = {NULL, NULL}; | ListBase R_layer_collection_engines_settings_callbacks = {NULL, NULL}; | ||||
| ListBase R_scene_layer_engines_settings_callbacks = {NULL, NULL}; | ListBase R_view_layer_engines_settings_callbacks = {NULL, NULL}; | ||||
| typedef struct EngineSettingsCB_Type { | typedef struct EngineSettingsCB_Type { | ||||
| struct EngineSettingsCB_Type *next, *prev; | struct EngineSettingsCB_Type *next, *prev; | ||||
| char name[MAX_NAME]; /* engine name */ | char name[MAX_NAME]; /* engine name */ | ||||
| EngineSettingsCB callback; | EngineSettingsCB callback; | ||||
| Show All 9 Lines | static void create_engine_settings_scene(IDProperty *root, EngineSettingsCB_Type *es_type) | ||||
| IDP_AddToGroup(root, props); | IDP_AddToGroup(root, props); | ||||
| } | } | ||||
| static void create_layer_collection_engine_settings_scene(Scene *scene, EngineSettingsCB_Type *es_type) | static void create_layer_collection_engine_settings_scene(Scene *scene, EngineSettingsCB_Type *es_type) | ||||
| { | { | ||||
| create_engine_settings_scene(scene->collection_properties, es_type); | create_engine_settings_scene(scene->collection_properties, es_type); | ||||
| } | } | ||||
| static void create_scene_layer_engine_settings_scene(Scene *scene, EngineSettingsCB_Type *es_type) | static void create_view_layer_engine_settings_scene(Scene *scene, EngineSettingsCB_Type *es_type) | ||||
| { | { | ||||
| create_engine_settings_scene(scene->layer_properties, es_type); | create_engine_settings_scene(scene->layer_properties, es_type); | ||||
| } | } | ||||
| static void create_layer_collection_engine_settings_collection(LayerCollection *lc, EngineSettingsCB_Type *es_type) | static void create_layer_collection_engine_settings_collection(LayerCollection *lc, EngineSettingsCB_Type *es_type) | ||||
| { | { | ||||
| if (BKE_layer_collection_engine_collection_get(lc, COLLECTION_MODE_NONE, es_type->name)) { | if (BKE_layer_collection_engine_collection_get(lc, COLLECTION_MODE_NONE, es_type->name)) { | ||||
| return; | return; | ||||
| } | } | ||||
| IDProperty *props = collection_engine_settings_create(es_type, false); | IDProperty *props = collection_engine_settings_create(es_type, false); | ||||
| IDP_AddToGroup(lc->properties, props); | IDP_AddToGroup(lc->properties, props); | ||||
| for (LayerCollection *lcn = lc->layer_collections.first; lcn; lcn = lcn->next) { | for (LayerCollection *lcn = lc->layer_collections.first; lcn; lcn = lcn->next) { | ||||
| create_layer_collection_engine_settings_collection(lcn, es_type); | create_layer_collection_engine_settings_collection(lcn, es_type); | ||||
| } | } | ||||
| } | } | ||||
| static void create_layer_collection_engines_settings_scene(Scene *scene, EngineSettingsCB_Type *es_type) | static void create_layer_collection_engines_settings_scene(Scene *scene, EngineSettingsCB_Type *es_type) | ||||
| { | { | ||||
| /* Populate the scene with the new settings. */ | /* Populate the scene with the new settings. */ | ||||
| create_layer_collection_engine_settings_scene(scene, es_type); | create_layer_collection_engine_settings_scene(scene, es_type); | ||||
| for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) { | for (ViewLayer *sl = scene->view_layers.first; sl; sl = sl->next) { | ||||
| for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) { | for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) { | ||||
| create_layer_collection_engine_settings_collection(lc, es_type); | create_layer_collection_engine_settings_collection(lc, es_type); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void create_scene_layer_engines_settings_scene(Scene *scene, EngineSettingsCB_Type *es_type) | static void create_view_layer_engines_settings_scene(Scene *scene, EngineSettingsCB_Type *es_type) | ||||
| { | { | ||||
| /* Populate the scene with the new settings. */ | /* Populate the scene with the new settings. */ | ||||
| create_scene_layer_engine_settings_scene(scene, es_type); | create_view_layer_engine_settings_scene(scene, es_type); | ||||
| } | } | ||||
| static void create_scene_layer_engines_settings_layer(SceneLayer *sl, EngineSettingsCB_Type *es_type) | static void create_view_layer_engines_settings_layer(ViewLayer *sl, EngineSettingsCB_Type *es_type) | ||||
| { | { | ||||
| if (BKE_scene_layer_engine_layer_get(sl, COLLECTION_MODE_NONE, es_type->name)) { | if (BKE_view_layer_engine_layer_get(sl, COLLECTION_MODE_NONE, es_type->name)) { | ||||
| return; | return; | ||||
| } | } | ||||
| IDProperty *props = collection_engine_settings_create(es_type, false); | IDProperty *props = collection_engine_settings_create(es_type, false); | ||||
| IDP_AddToGroup(sl->properties, props); | IDP_AddToGroup(sl->properties, props); | ||||
| } | } | ||||
| static EngineSettingsCB_Type *engine_settings_callback_register(const char *engine_name, EngineSettingsCB func, ListBase *lb) | static EngineSettingsCB_Type *engine_settings_callback_register(const char *engine_name, EngineSettingsCB func, ListBase *lb) | ||||
| Show All 25 Lines | void BKE_layer_collection_engine_settings_callback_register( | ||||
| if (bmain) { | if (bmain) { | ||||
| /* Populate all of the collections of the scene with those settings. */ | /* Populate all of the collections of the scene with those settings. */ | ||||
| for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { | for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { | ||||
| create_layer_collection_engines_settings_scene(scene, es_type); | create_layer_collection_engines_settings_scene(scene, es_type); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void BKE_scene_layer_engine_settings_callback_register( | void BKE_view_layer_engine_settings_callback_register( | ||||
| Main *bmain, const char *engine_name, EngineSettingsCB func) | Main *bmain, const char *engine_name, EngineSettingsCB func) | ||||
| { | { | ||||
| EngineSettingsCB_Type *es_type = | EngineSettingsCB_Type *es_type = | ||||
| engine_settings_callback_register(engine_name, func, &R_scene_layer_engines_settings_callbacks); | engine_settings_callback_register(engine_name, func, &R_view_layer_engines_settings_callbacks); | ||||
| if (bmain) { | if (bmain) { | ||||
| /* Populate all of the collections of the scene with those settings. */ | /* Populate all of the collections of the scene with those settings. */ | ||||
| for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { | for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { | ||||
| create_scene_layer_engines_settings_scene(scene, es_type); | create_view_layer_engines_settings_scene(scene, es_type); | ||||
| for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) { | for (ViewLayer *sl = scene->view_layers.first; sl; sl = sl->next) { | ||||
| create_scene_layer_engines_settings_layer(sl, es_type); | create_view_layer_engines_settings_layer(sl, es_type); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void BKE_layer_collection_engine_settings_callback_free(void) | void BKE_layer_collection_engine_settings_callback_free(void) | ||||
| { | { | ||||
| BLI_freelistN(&R_layer_collection_engines_settings_callbacks); | BLI_freelistN(&R_layer_collection_engines_settings_callbacks); | ||||
| } | } | ||||
| void BKE_scene_layer_engine_settings_callback_free(void) | void BKE_view_layer_engine_settings_callback_free(void) | ||||
| { | { | ||||
| BLI_freelistN(&R_scene_layer_engines_settings_callbacks); | BLI_freelistN(&R_view_layer_engines_settings_callbacks); | ||||
| } | } | ||||
| /** | /** | ||||
| * Create a root IDProperty for this engine | * Create a root IDProperty for this engine | ||||
| * | * | ||||
| * \param populate whether we want to pre-fill the collection with the default properties | * \param populate whether we want to pre-fill the collection with the default properties | ||||
| */ | */ | ||||
| static IDProperty *collection_engine_settings_create(EngineSettingsCB_Type *es_type, const bool populate) | static IDProperty *collection_engine_settings_create(EngineSettingsCB_Type *es_type, const bool populate) | ||||
| ▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| EngineSettingsCB_Type *es_type; | EngineSettingsCB_Type *es_type; | ||||
| for (es_type = R_layer_collection_engines_settings_callbacks.first; es_type; es_type = es_type->next) { | for (es_type = R_layer_collection_engines_settings_callbacks.first; es_type; es_type = es_type->next) { | ||||
| IDProperty *props = collection_engine_settings_create(es_type, populate); | IDProperty *props = collection_engine_settings_create(es_type, populate); | ||||
| IDP_AddToGroup(root, props); | IDP_AddToGroup(root, props); | ||||
| } | } | ||||
| } | } | ||||
| static void scene_layer_create_render_settings(IDProperty *root, const bool populate) | static void view_layer_create_render_settings(IDProperty *root, const bool populate) | ||||
| { | { | ||||
| EngineSettingsCB_Type *es_type; | EngineSettingsCB_Type *es_type; | ||||
| for (es_type = R_scene_layer_engines_settings_callbacks.first; es_type; es_type = es_type->next) { | for (es_type = R_view_layer_engines_settings_callbacks.first; es_type; es_type = es_type->next) { | ||||
| IDProperty *props = collection_engine_settings_create(es_type, populate); | IDProperty *props = collection_engine_settings_create(es_type, populate); | ||||
| IDP_AddToGroup(root, props); | IDP_AddToGroup(root, props); | ||||
| } | } | ||||
| } | } | ||||
| static void collection_create_mode_settings(IDProperty *root, const bool populate) | static void collection_create_mode_settings(IDProperty *root, const bool populate) | ||||
| { | { | ||||
| /* XXX TODO: put all those engines in the R_engines_settings_callbacks | /* XXX TODO: put all those engines in the R_engines_settings_callbacks | ||||
| ▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | |||||
| IDProperty *BKE_layer_collection_engine_scene_get(Scene *scene, const int type, const char *engine_name) | IDProperty *BKE_layer_collection_engine_scene_get(Scene *scene, const int type, const char *engine_name) | ||||
| { | { | ||||
| return collection_engine_get(scene->collection_properties, type, engine_name); | return collection_engine_get(scene->collection_properties, type, engine_name); | ||||
| } | } | ||||
| /** | /** | ||||
| * Return scene layer engine settings for specified engine in the scene | * Return scene layer engine settings for specified engine in the scene | ||||
| */ | */ | ||||
| IDProperty *BKE_scene_layer_engine_scene_get(Scene *scene, const int type, const char *engine_name) | IDProperty *BKE_view_layer_engine_scene_get(Scene *scene, const int type, const char *engine_name) | ||||
| { | { | ||||
| return collection_engine_get(scene->layer_properties, type, engine_name); | return collection_engine_get(scene->layer_properties, type, engine_name); | ||||
| } | } | ||||
| /** | /** | ||||
| * Return scene layer engine settings for specified engine | * Return scene layer engine settings for specified engine | ||||
| */ | */ | ||||
| IDProperty *BKE_scene_layer_engine_layer_get(SceneLayer *sl, const int type, const char *engine_name) | IDProperty *BKE_view_layer_engine_layer_get(ViewLayer *sl, const int type, const char *engine_name) | ||||
| { | { | ||||
| return collection_engine_get(sl->properties, type, engine_name); | return collection_engine_get(sl->properties, type, engine_name); | ||||
| } | } | ||||
| /** | /** | ||||
| * Return scene layer evaluated engine settings for specified engine | * Return scene layer evaluated engine settings for specified engine | ||||
| */ | */ | ||||
| IDProperty *BKE_scene_layer_engine_evaluated_get(SceneLayer *sl, const int type, const char *engine_name) | IDProperty *BKE_view_layer_engine_evaluated_get(ViewLayer *sl, const int type, const char *engine_name) | ||||
| { | { | ||||
| return collection_engine_get(sl->properties_evaluated, type, engine_name); | return collection_engine_get(sl->properties_evaluated, type, engine_name); | ||||
| } | } | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| /* Engine Settings Properties */ | /* Engine Settings Properties */ | ||||
| void BKE_collection_engine_property_add_float(IDProperty *props, const char *name, float value) | void BKE_collection_engine_property_add_float(IDProperty *props, const char *name, float value) | ||||
| ▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | static void collection_engine_settings_init(IDProperty *root, const bool populate) | ||||
| /* mode engines */ | /* mode engines */ | ||||
| collection_create_mode_settings(root, populate); | collection_create_mode_settings(root, populate); | ||||
| } | } | ||||
| /* get all the default settings defined in scene and merge them here */ | /* get all the default settings defined in scene and merge them here */ | ||||
| static void layer_engine_settings_init(IDProperty *root, const bool populate) | static void layer_engine_settings_init(IDProperty *root, const bool populate) | ||||
| { | { | ||||
| /* render engines */ | /* render engines */ | ||||
| scene_layer_create_render_settings(root, populate); | view_layer_create_render_settings(root, populate); | ||||
| /* mode engines */ | /* mode engines */ | ||||
| layer_create_mode_settings(root, populate); | layer_create_mode_settings(root, populate); | ||||
| } | } | ||||
| /** | /** | ||||
| * Initialize the layer collection render setings | * Initialize the layer collection render setings | ||||
| * It's used mainly for scenes | * It's used mainly for scenes | ||||
| */ | */ | ||||
| void BKE_layer_collection_engine_settings_create(IDProperty *root) | void BKE_layer_collection_engine_settings_create(IDProperty *root) | ||||
| { | { | ||||
| collection_engine_settings_init(root, true); | collection_engine_settings_init(root, true); | ||||
| } | } | ||||
| /** | /** | ||||
| * Initialize the render setings | * Initialize the render setings | ||||
| * It's used mainly for scenes | * It's used mainly for scenes | ||||
| */ | */ | ||||
| void BKE_scene_layer_engine_settings_create(IDProperty *root) | void BKE_view_layer_engine_settings_create(IDProperty *root) | ||||
| { | { | ||||
| layer_engine_settings_init(root, true); | layer_engine_settings_init(root, true); | ||||
| } | } | ||||
| /** | /** | ||||
| * Reference of IDProperty group scene collection settings | * Reference of IDProperty group scene collection settings | ||||
| * Used when reading blendfiles, to see if there is any missing settings. | * Used when reading blendfiles, to see if there is any missing settings. | ||||
| */ | */ | ||||
| static struct { | static struct { | ||||
| struct { | struct { | ||||
| IDProperty *collection_properties; | IDProperty *collection_properties; | ||||
| IDProperty *render_settings; | IDProperty *render_settings; | ||||
| } scene; | } scene; | ||||
| IDProperty *scene_layer; | IDProperty *view_layer; | ||||
| IDProperty *layer_collection; | IDProperty *layer_collection; | ||||
| } root_reference = { | } root_reference = { | ||||
| .scene = {NULL, NULL}, | .scene = {NULL, NULL}, | ||||
| .scene_layer = NULL, | .view_layer = NULL, | ||||
| .layer_collection = NULL, | .layer_collection = NULL, | ||||
| }; | }; | ||||
| /** | /** | ||||
| * Free the reference scene collection settings IDProperty group. | * Free the reference scene collection settings IDProperty group. | ||||
| */ | */ | ||||
| static void engine_settings_validate_init(void) | static void engine_settings_validate_init(void) | ||||
| { | { | ||||
| Show All 11 Lines | static void engine_settings_validate_init(void) | ||||
| } | } | ||||
| /* Render engine setting. */ | /* Render engine setting. */ | ||||
| if (root_reference.scene.render_settings == NULL) { | if (root_reference.scene.render_settings == NULL) { | ||||
| root_reference.scene.render_settings = IDP_New(IDP_GROUP, &val, ROOT_PROP); | root_reference.scene.render_settings = IDP_New(IDP_GROUP, &val, ROOT_PROP); | ||||
| layer_engine_settings_init(root_reference.scene.render_settings, true); | layer_engine_settings_init(root_reference.scene.render_settings, true); | ||||
| } | } | ||||
| if (root_reference.scene_layer == NULL) { | if (root_reference.view_layer == NULL) { | ||||
| root_reference.scene_layer = IDP_New(IDP_GROUP, &val, ROOT_PROP); | root_reference.view_layer = IDP_New(IDP_GROUP, &val, ROOT_PROP); | ||||
| layer_engine_settings_init(root_reference.scene_layer, false); | layer_engine_settings_init(root_reference.view_layer, false); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Free the reference scene collection settings IDProperty group. | * Free the reference scene collection settings IDProperty group. | ||||
| */ | */ | ||||
| static void layer_collection_engine_settings_validate_free(void) | static void layer_collection_engine_settings_validate_free(void) | ||||
| { | { | ||||
| IDProperty *idprops[] = { | IDProperty *idprops[] = { | ||||
| root_reference.scene.render_settings, | root_reference.scene.render_settings, | ||||
| root_reference.scene.collection_properties, | root_reference.scene.collection_properties, | ||||
| root_reference.scene_layer, | root_reference.view_layer, | ||||
| root_reference.layer_collection, | root_reference.layer_collection, | ||||
| NULL, | NULL, | ||||
| }; | }; | ||||
| IDProperty **idprop = &idprops[0]; | IDProperty **idprop = &idprops[0]; | ||||
| while (*idprop) { | while (*idprop) { | ||||
| if (*idprop) { | if (*idprop) { | ||||
| IDP_FreeProperty(*idprop); | IDP_FreeProperty(*idprop); | ||||
| Show All 34 Lines | void BKE_layer_collection_engine_settings_validate_collection(LayerCollection *lc) | ||||
| BLI_assert(lc->properties != NULL); | BLI_assert(lc->properties != NULL); | ||||
| IDP_MergeGroup(lc->properties, root_reference.layer_collection, false); | IDP_MergeGroup(lc->properties, root_reference.layer_collection, false); | ||||
| } | } | ||||
| /** | /** | ||||
| * Make sure Scene has all required collection settings. | * Make sure Scene has all required collection settings. | ||||
| */ | */ | ||||
| void BKE_scene_layer_engine_settings_validate_scene(Scene *scene) | void BKE_view_layer_engine_settings_validate_scene(Scene *scene) | ||||
| { | { | ||||
| if (root_reference.scene.render_settings == NULL) { | if (root_reference.scene.render_settings == NULL) { | ||||
| engine_settings_validate_init(); | engine_settings_validate_init(); | ||||
| } | } | ||||
| if (scene->layer_properties == NULL) { | if (scene->layer_properties == NULL) { | ||||
| IDPropertyTemplate val = {0}; | IDPropertyTemplate val = {0}; | ||||
| scene->layer_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | scene->layer_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | ||||
| BKE_scene_layer_engine_settings_create(scene->layer_properties); | BKE_view_layer_engine_settings_create(scene->layer_properties); | ||||
| } | } | ||||
| else { | else { | ||||
| IDP_MergeGroup(scene->layer_properties, root_reference.scene.render_settings, false); | IDP_MergeGroup(scene->layer_properties, root_reference.scene.render_settings, false); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Make sure Scene has all required collection settings. | * Make sure Scene has all required collection settings. | ||||
| */ | */ | ||||
| void BKE_scene_layer_engine_settings_validate_layer(SceneLayer *sl) | void BKE_view_layer_engine_settings_validate_layer(ViewLayer *sl) | ||||
| { | { | ||||
| if (root_reference.scene_layer == NULL) { | if (root_reference.view_layer == NULL) { | ||||
| engine_settings_validate_init(); | engine_settings_validate_init(); | ||||
| } | } | ||||
| IDP_MergeGroup(sl->properties, root_reference.scene_layer, false); | IDP_MergeGroup(sl->properties, root_reference.view_layer, false); | ||||
| } | } | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| /* Iterators */ | /* Iterators */ | ||||
| static void object_bases_iterator_begin(BLI_Iterator *iter, void *data_in, const int flag) | static void object_bases_iterator_begin(BLI_Iterator *iter, void *data_in, const int flag) | ||||
| { | { | ||||
| SceneLayer *sl = data_in; | ViewLayer *sl = data_in; | ||||
| Base *base = sl->object_bases.first; | Base *base = sl->object_bases.first; | ||||
| /* when there are no objects */ | /* when there are no objects */ | ||||
| if (base == NULL) { | if (base == NULL) { | ||||
| iter->valid = false; | iter->valid = false; | ||||
| return; | return; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | void BKE_visible_bases_iterator_end(BLI_Iterator *UNUSED(iter)) | ||||
| /* do nothing */ | /* do nothing */ | ||||
| } | } | ||||
| void BKE_renderable_objects_iterator_begin(BLI_Iterator *iter, void *data_in) | void BKE_renderable_objects_iterator_begin(BLI_Iterator *iter, void *data_in) | ||||
| { | { | ||||
| ObjectsRenderableIteratorData *data = data_in; | ObjectsRenderableIteratorData *data = data_in; | ||||
| for (Scene *scene = data->scene; scene; scene = scene->set) { | for (Scene *scene = data->scene; scene; scene = scene->set) { | ||||
| for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) { | for (ViewLayer *sl = scene->view_layers.first; sl; sl = sl->next) { | ||||
| for (Base *base = sl->object_bases.first; base; base = base->next) { | for (Base *base = sl->object_bases.first; base; base = base->next) { | ||||
| base->object->id.flag |= LIB_TAG_DOIT; | base->object->id.flag |= LIB_TAG_DOIT; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| SceneLayer *scene_layer = data->scene->render_layers.first; | ViewLayer *view_layer = data->scene->view_layers.first; | ||||
| data->iter.scene_layer = scene_layer; | data->iter.view_layer = view_layer; | ||||
| Base base = {(Base *)scene_layer->object_bases.first, NULL}; | Base base = {(Base *)view_layer->object_bases.first, NULL}; | ||||
| data->iter.base = &base; | data->iter.base = &base; | ||||
| data->iter.set = NULL; | data->iter.set = NULL; | ||||
| iter->data = data_in; | iter->data = data_in; | ||||
| BKE_renderable_objects_iterator_next(iter); | BKE_renderable_objects_iterator_next(iter); | ||||
| } | } | ||||
| Show All 12 Lines | if (base != NULL) { | ||||
| if ((base->flag & BASE_VISIBLED) == 0) { | if ((base->flag & BASE_VISIBLED) == 0) { | ||||
| BKE_renderable_objects_iterator_next(iter); | BKE_renderable_objects_iterator_next(iter); | ||||
| } | } | ||||
| return; | return; | ||||
| } | } | ||||
| /* Time to go to the next scene layer. */ | /* Time to go to the next scene layer. */ | ||||
| if (data->iter.set == NULL) { | if (data->iter.set == NULL) { | ||||
| while ((data->iter.scene_layer = data->iter.scene_layer->next)) { | while ((data->iter.view_layer = data->iter.view_layer->next)) { | ||||
| SceneLayer *scene_layer = data->iter.scene_layer; | ViewLayer *view_layer = data->iter.view_layer; | ||||
| if (scene_layer->flag & SCENE_LAYER_RENDER) { | if (view_layer->flag & VIEW_LAYER_RENDER) { | ||||
| Base base_iter = {(Base *)scene_layer->object_bases.first, NULL}; | Base base_iter = {(Base *)view_layer->object_bases.first, NULL}; | ||||
| data->iter.base = &base_iter; | data->iter.base = &base_iter; | ||||
| BKE_renderable_objects_iterator_next(iter); | BKE_renderable_objects_iterator_next(iter); | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| /* Setup the "set" for the next iteration. */ | /* Setup the "set" for the next iteration. */ | ||||
| Scene scene = {.set = data->scene}; | Scene scene = {.set = data->scene}; | ||||
| data->iter.set = &scene; | data->iter.set = &scene; | ||||
| BKE_renderable_objects_iterator_next(iter); | BKE_renderable_objects_iterator_next(iter); | ||||
| return; | return; | ||||
| } | } | ||||
| /* Look for an object in the next set. */ | /* Look for an object in the next set. */ | ||||
| while ((data->iter.set = data->iter.set->set)) { | while ((data->iter.set = data->iter.set->set)) { | ||||
| SceneLayer *scene_layer = BKE_scene_layer_from_scene_get(data->iter.set); | ViewLayer *view_layer = BKE_view_layer_from_scene_get(data->iter.set); | ||||
| Base base_iter = {(Base *)scene_layer->object_bases.first, NULL}; | Base base_iter = {(Base *)view_layer->object_bases.first, NULL}; | ||||
| data->iter.base = &base_iter; | data->iter.base = &base_iter; | ||||
| BKE_renderable_objects_iterator_next(iter); | BKE_renderable_objects_iterator_next(iter); | ||||
| return; | return; | ||||
| } | } | ||||
| iter->valid = false; | iter->valid = false; | ||||
| } | } | ||||
| Show All 21 Lines | static void idproperty_reset(IDProperty **props, IDProperty *props_ref) | ||||
| *props = IDP_New(IDP_GROUP, &val, ROOT_PROP); | *props = IDP_New(IDP_GROUP, &val, ROOT_PROP); | ||||
| if (props_ref) { | if (props_ref) { | ||||
| IDP_MergeGroup(*props, props_ref, true); | IDP_MergeGroup(*props, props_ref, true); | ||||
| } | } | ||||
| } | } | ||||
| void BKE_layer_eval_layer_collection_pre(const struct EvaluationContext *UNUSED(eval_ctx), | void BKE_layer_eval_layer_collection_pre(const struct EvaluationContext *UNUSED(eval_ctx), | ||||
| Scene *scene, SceneLayer *scene_layer) | Scene *scene, ViewLayer *view_layer) | ||||
| { | { | ||||
| DEBUG_PRINT("%s on %s (%p)\n", __func__, scene_layer->name, scene_layer); | DEBUG_PRINT("%s on %s (%p)\n", __func__, view_layer->name, view_layer); | ||||
| for (Base *base = scene_layer->object_bases.first; base != NULL; base = base->next) { | for (Base *base = view_layer->object_bases.first; base != NULL; base = base->next) { | ||||
| base->flag &= ~(BASE_VISIBLED | BASE_SELECTABLED); | base->flag &= ~(BASE_VISIBLED | BASE_SELECTABLED); | ||||
| idproperty_reset(&base->collection_properties, scene->collection_properties); | idproperty_reset(&base->collection_properties, scene->collection_properties); | ||||
| } | } | ||||
| /* Sync properties from scene to scene layer. */ | /* Sync properties from scene to scene layer. */ | ||||
| idproperty_reset(&scene_layer->properties_evaluated, scene->layer_properties); | idproperty_reset(&view_layer->properties_evaluated, scene->layer_properties); | ||||
| IDP_MergeGroup(scene_layer->properties_evaluated, scene_layer->properties, true); | IDP_MergeGroup(view_layer->properties_evaluated, view_layer->properties, true); | ||||
| /* TODO(sergey): Is it always required? */ | /* TODO(sergey): Is it always required? */ | ||||
| scene_layer->flag |= SCENE_LAYER_ENGINE_DIRTY; | view_layer->flag |= VIEW_LAYER_ENGINE_DIRTY; | ||||
| } | } | ||||
| void BKE_layer_eval_layer_collection(const struct EvaluationContext *UNUSED(eval_ctx), | void BKE_layer_eval_layer_collection(const struct EvaluationContext *UNUSED(eval_ctx), | ||||
| LayerCollection *layer_collection, | LayerCollection *layer_collection, | ||||
| LayerCollection *parent_layer_collection) | LayerCollection *parent_layer_collection) | ||||
| { | { | ||||
| DEBUG_PRINT("%s on %s (%p), parent %s (%p)\n", | DEBUG_PRINT("%s on %s (%p), parent %s (%p)\n", | ||||
| __func__, | __func__, | ||||
| Show All 34 Lines | for (LinkData *link = layer_collection->object_bases.first; link != NULL; link = link->next) { | ||||
| if (is_selectable) { | if (is_selectable) { | ||||
| base->flag |= BASE_SELECTABLED; | base->flag |= BASE_SELECTABLED; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void BKE_layer_eval_layer_collection_post(const struct EvaluationContext *UNUSED(eval_ctx), | void BKE_layer_eval_layer_collection_post(const struct EvaluationContext *UNUSED(eval_ctx), | ||||
| SceneLayer *scene_layer) | ViewLayer *view_layer) | ||||
| { | { | ||||
| DEBUG_PRINT("%s on %s (%p)\n", __func__, scene_layer->name, scene_layer); | DEBUG_PRINT("%s on %s (%p)\n", __func__, view_layer->name, view_layer); | ||||
| /* if base is not selectabled, clear select */ | /* if base is not selectabled, clear select */ | ||||
| for (Base *base = scene_layer->object_bases.first; base; base = base->next) { | for (Base *base = view_layer->object_bases.first; base; base = base->next) { | ||||
| if ((base->flag & BASE_SELECTABLED) == 0) { | if ((base->flag & BASE_SELECTABLED) == 0) { | ||||
| base->flag &= ~BASE_SELECTED; | base->flag &= ~BASE_SELECTED; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Free any static allocated memory. | * Free any static allocated memory. | ||||
| */ | */ | ||||
| void BKE_layer_exit(void) | void BKE_layer_exit(void) | ||||
| { | { | ||||
| layer_collection_engine_settings_validate_free(); | layer_collection_engine_settings_validate_free(); | ||||
| } | } | ||||