Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/scene.c
| Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_cachefile.h" | #include "BKE_cachefile.h" | ||||
| #include "BKE_collection.h" | #include "BKE_collection.h" | ||||
| #include "BKE_colortools.h" | #include "BKE_colortools.h" | ||||
| #include "BKE_editmesh.h" | #include "BKE_editmesh.h" | ||||
| #include "BKE_fcurve.h" | #include "BKE_fcurve.h" | ||||
| #include "BKE_freestyle.h" | #include "BKE_freestyle.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| #include "BKE_group.h" | |||||
| #include "BKE_icons.h" | #include "BKE_icons.h" | ||||
| #include "BKE_idprop.h" | #include "BKE_idprop.h" | ||||
| #include "BKE_image.h" | #include "BKE_image.h" | ||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "BKE_library.h" | #include "BKE_library.h" | ||||
| #include "BKE_library_remap.h" | #include "BKE_library_remap.h" | ||||
| #include "BKE_linestyle.h" | #include "BKE_linestyle.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| ▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| /* We never handle usercount here for own data. */ | /* We never handle usercount here for own data. */ | ||||
| const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT; | const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT; | ||||
| sce_dst->ed = NULL; | sce_dst->ed = NULL; | ||||
| sce_dst->depsgraph_hash = NULL; | sce_dst->depsgraph_hash = NULL; | ||||
| sce_dst->fps_info = NULL; | sce_dst->fps_info = NULL; | ||||
| /* layers and collections */ | /* Master Collection */ | ||||
| sce_dst->collection = MEM_dupallocN(sce_src->collection); | if (sce_src->master_collection) { | ||||
| SceneCollection *mc_src = BKE_collection_master(&sce_src->id); | sce_dst->master_collection = BKE_collection_copy_master(bmain, sce_src->master_collection, flag); | ||||
| SceneCollection *mc_dst = BKE_collection_master(&sce_dst->id); | } | ||||
| /* Recursively creates a new SceneCollection tree. */ | |||||
| BKE_collection_copy_data(mc_dst, mc_src, flag_subdata); | |||||
| /* layers */ | |||||
| IDPropertyTemplate val = {0}; | IDPropertyTemplate val = {0}; | ||||
| BLI_duplicatelist(&sce_dst->view_layers, &sce_src->view_layers); | BLI_duplicatelist(&sce_dst->view_layers, &sce_src->view_layers); | ||||
| for (ViewLayer *view_layer_src = sce_src->view_layers.first, *view_layer_dst = sce_dst->view_layers.first; | for (ViewLayer *view_layer_src = sce_src->view_layers.first, *view_layer_dst = sce_dst->view_layers.first; | ||||
| view_layer_src; | view_layer_src; | ||||
| view_layer_src = view_layer_src->next, view_layer_dst = view_layer_dst->next) | view_layer_src = view_layer_src->next, view_layer_dst = view_layer_dst->next) | ||||
| { | { | ||||
| BKE_view_layer_copy_data(view_layer_dst, view_layer_src, mc_dst, mc_src, flag_subdata); | BKE_view_layer_copy_data(sce_dst, sce_src, view_layer_dst, view_layer_src, flag_subdata); | ||||
| } | } | ||||
| sce_dst->collection_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | sce_dst->collection_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | ||||
| if (sce_src->collection_properties) { | if (sce_src->collection_properties) { | ||||
| IDP_MergeGroup_ex(sce_dst->collection_properties, sce_src->collection_properties, true, flag_subdata); | IDP_MergeGroup_ex(sce_dst->collection_properties, sce_src->collection_properties, true, flag_subdata); | ||||
| } | } | ||||
| sce_dst->layer_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | sce_dst->layer_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | ||||
| if (sce_src->layer_properties) { | if (sce_src->layer_properties) { | ||||
| ▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | if (type == SCE_COPY_FULL) { | ||||
| } | } | ||||
| } | } | ||||
| /* Full copy of world (included animations) */ | /* Full copy of world (included animations) */ | ||||
| if (sce_copy->world) { | if (sce_copy->world) { | ||||
| BKE_id_copy_ex(bmain, (ID *)sce_copy->world, (ID **)&sce_copy->world, LIB_ID_COPY_ACTIONS, false); | BKE_id_copy_ex(bmain, (ID *)sce_copy->world, (ID **)&sce_copy->world, LIB_ID_COPY_ACTIONS, false); | ||||
| } | } | ||||
| /* Collections */ | |||||
| BKE_collection_copy_full(bmain, sce_copy->master_collection); | |||||
| /* Full copy of GreasePencil. */ | /* Full copy of GreasePencil. */ | ||||
| /* XXX Not copying anim/actions here? */ | /* XXX Not copying anim/actions here? */ | ||||
| if (sce_copy->gpd) { | if (sce_copy->gpd) { | ||||
| BKE_id_copy_ex(bmain, (ID *)sce_copy->gpd, (ID **)&sce_copy->gpd, 0, false); | BKE_id_copy_ex(bmain, (ID *)sce_copy->gpd, (ID **)&sce_copy->gpd, 0, false); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Remove sequencer if not full copy */ | /* Remove sequencer if not full copy */ | ||||
| ▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | void BKE_scene_free_ex(Scene *sce, const bool do_id_user) | ||||
| for (ViewLayer *view_layer = sce->view_layers.first, *view_layer_next; view_layer; view_layer = view_layer_next) { | for (ViewLayer *view_layer = sce->view_layers.first, *view_layer_next; view_layer; view_layer = view_layer_next) { | ||||
| view_layer_next = view_layer->next; | view_layer_next = view_layer->next; | ||||
| BLI_remlink(&sce->view_layers, view_layer); | BLI_remlink(&sce->view_layers, view_layer); | ||||
| BKE_view_layer_free_ex(view_layer, do_id_user); | BKE_view_layer_free_ex(view_layer, do_id_user); | ||||
| } | } | ||||
| /* Master Collection */ | /* Master Collection */ | ||||
| BKE_collection_master_free(&sce->id, do_id_user); | // TODO: what to do with do_id_user? it's also true when just | ||||
| MEM_freeN(sce->collection); | // closing the file which seems wrong? should decrement users | ||||
| sce->collection = NULL; | // for objects directly in the master collection? then other | ||||
| // collections in the scene need to do it too? | |||||
| if (sce->master_collection) { | |||||
| BKE_collection_free(sce->master_collection); | |||||
| MEM_freeN(sce->master_collection); | |||||
| sce->master_collection = NULL; | |||||
| } | |||||
| /* LayerCollection engine settings. */ | /* LayerCollection engine settings. */ | ||||
| if (sce->collection_properties) { | if (sce->collection_properties) { | ||||
| IDP_FreeProperty(sce->collection_properties); | IDP_FreeProperty(sce->collection_properties); | ||||
| MEM_freeN(sce->collection_properties); | MEM_freeN(sce->collection_properties); | ||||
| sce->collection_properties = NULL; | sce->collection_properties = NULL; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 275 Lines • ▼ Show 20 Lines | void BKE_scene_init(Scene *sce) | ||||
| sce->toolsettings->gpencil_v3d_align = GP_PROJECT_VIEWSPACE; | sce->toolsettings->gpencil_v3d_align = GP_PROJECT_VIEWSPACE; | ||||
| sce->toolsettings->gpencil_v2d_align = GP_PROJECT_VIEWSPACE; | sce->toolsettings->gpencil_v2d_align = GP_PROJECT_VIEWSPACE; | ||||
| sce->toolsettings->gpencil_seq_align = GP_PROJECT_VIEWSPACE; | sce->toolsettings->gpencil_seq_align = GP_PROJECT_VIEWSPACE; | ||||
| sce->toolsettings->gpencil_ima_align = GP_PROJECT_VIEWSPACE; | sce->toolsettings->gpencil_ima_align = GP_PROJECT_VIEWSPACE; | ||||
| sce->orientation_index_custom = -1; | sce->orientation_index_custom = -1; | ||||
| /* Master Collection */ | /* Master Collection */ | ||||
| sce->collection = MEM_callocN(sizeof(SceneCollection), "Master Collection"); | sce->master_collection = BKE_collection_master_add(); | ||||
| BLI_strncpy(sce->collection->name, "Master Collection", sizeof(sce->collection->name)); | |||||
| /* Engine settings */ | /* Engine settings */ | ||||
| IDPropertyTemplate val = {0}; | IDPropertyTemplate val = {0}; | ||||
| sce->collection_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | sce->collection_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | ||||
| BKE_layer_collection_engine_settings_create(sce->collection_properties); | BKE_layer_collection_engine_settings_create(sce->collection_properties); | ||||
| sce->layer_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | sce->layer_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | ||||
| BKE_view_layer_engine_settings_create(sce->layer_properties); | BKE_view_layer_engine_settings_create(sce->layer_properties); | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * Sets the active scene, mainly used when running in background mode (``--scene`` command line argument). | * Sets the active scene, mainly used when running in background mode (``--scene`` command line argument). | ||||
| * This is also called to set the scene directly, bypassing windowing code. | * This is also called to set the scene directly, bypassing windowing code. | ||||
| * Otherwise #WM_window_change_active_scene is used when changing scenes by the user. | * Otherwise #WM_window_change_active_scene is used when changing scenes by the user. | ||||
| */ | */ | ||||
| void BKE_scene_set_background(Main *bmain, Scene *scene) | void BKE_scene_set_background(Main *bmain, Scene *scene) | ||||
| { | { | ||||
| Object *ob; | Object *ob; | ||||
| Group *group; | |||||
| /* check for cyclic sets, for reading old files but also for definite security (py?) */ | /* check for cyclic sets, for reading old files but also for definite security (py?) */ | ||||
| BKE_scene_validate_setscene(bmain, scene); | BKE_scene_validate_setscene(bmain, scene); | ||||
| /* deselect objects (for dataselect) */ | /* deselect objects (for dataselect) */ | ||||
| for (ob = bmain->object.first; ob; ob = ob->id.next) | for (ob = bmain->object.first; ob; ob = ob->id.next) | ||||
| ob->flag &= ~(SELECT | OB_FROMGROUP); | ob->flag &= ~SELECT; | ||||
| /* group flags again */ | |||||
| for (group = bmain->group.first; group; group = group->id.next) { | |||||
| FOREACH_GROUP_OBJECT_BEGIN(group, object) | |||||
| { | |||||
| object->flag |= OB_FROMGROUP; | |||||
| } | |||||
| FOREACH_GROUP_OBJECT_END; | |||||
| } | |||||
| /* copy layers and flags from bases to objects */ | /* copy layers and flags from bases to objects */ | ||||
| for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) { | for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) { | ||||
| for (Base *base = view_layer->object_bases.first; base; base = base->next) { | for (Base *base = view_layer->object_bases.first; base; base = base->next) { | ||||
| ob = base->object; | ob = base->object; | ||||
| /* group patch... */ | /* collection patch... */ | ||||
| BKE_scene_object_base_flag_sync_from_base(base); | BKE_scene_object_base_flag_sync_from_base(base); | ||||
| } | } | ||||
| } | } | ||||
| /* no full animation update, this to enable render code to work (render code calls own animation updates) */ | /* no full animation update, this to enable render code to work (render code calls own animation updates) */ | ||||
| } | } | ||||
| /* called from creator_args.c */ | /* called from creator_args.c */ | ||||
| Scene *BKE_scene_set_name(Main *bmain, const char *name) | Scene *BKE_scene_set_name(Main *bmain, const char *name) | ||||
| ▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | while (run_again) { | ||||
| } | } | ||||
| if (*base == NULL) { | if (*base == NULL) { | ||||
| iter->phase = F_START; | iter->phase = F_START; | ||||
| } | } | ||||
| else { | else { | ||||
| if (iter->phase != F_DUPLI) { | if (iter->phase != F_DUPLI) { | ||||
| if (depsgraph && (*base)->object->transflag & OB_DUPLI) { | if (depsgraph && (*base)->object->transflag & OB_DUPLI) { | ||||
| /* groups cannot be duplicated for mballs yet, | /* collections cannot be duplicated for mballs yet, | ||||
| * this enters eternal loop because of | * this enters eternal loop because of | ||||
| * makeDispListMBall getting called inside of group_duplilist */ | * makeDispListMBall getting called inside of collection_duplilist */ | ||||
| if ((*base)->object->dup_group == NULL) { | if ((*base)->object->dup_group == NULL) { | ||||
| iter->duplilist = object_duplilist_ex(depsgraph, (*scene), (*base)->object, false); | iter->duplilist = object_duplilist_ex(depsgraph, (*scene), (*base)->object, false); | ||||
| iter->dupob = iter->duplilist->first; | iter->dupob = iter->duplilist->first; | ||||
| if (!iter->dupob) { | if (!iter->dupob) { | ||||
| free_object_duplilist(iter->duplilist); | free_object_duplilist(iter->duplilist); | ||||
| iter->duplilist = NULL; | iter->duplilist = NULL; | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | #if 0 | ||||
| if (ob && *ob) { | if (ob && *ob) { | ||||
| printf("Scene: '%s', '%s'\n", (*scene)->id.name + 2, (*ob)->id.name + 2); | printf("Scene: '%s', '%s'\n", (*scene)->id.name + 2, (*ob)->id.name + 2); | ||||
| } | } | ||||
| #endif | #endif | ||||
| return iter->phase; | return iter->phase; | ||||
| } | } | ||||
| Scene *BKE_scene_find_from_collection(const Main *bmain, const SceneCollection *scene_collection) | Scene *BKE_scene_find_from_collection(const Main *bmain, const Collection *collection) | ||||
| { | { | ||||
| for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { | for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { | ||||
| for (ViewLayer *layer = scene->view_layers.first; layer; layer = layer->next) { | for (ViewLayer *layer = scene->view_layers.first; layer; layer = layer->next) { | ||||
| if (BKE_view_layer_has_collection(layer, scene_collection)) { | if (BKE_view_layer_has_collection(layer, collection)) { | ||||
| return scene; | return scene; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 447 Lines • ▼ Show 20 Lines | while (base) { | ||||
| base = base->next; | base = base->next; | ||||
| } | } | ||||
| } | } | ||||
| void BKE_scene_object_base_flag_sync_from_base(Base *base) | void BKE_scene_object_base_flag_sync_from_base(Base *base) | ||||
| { | { | ||||
| Object *ob = base->object; | Object *ob = base->object; | ||||
| /* keep the object only flags untouched */ | |||||
| int flag = ob->flag & OB_FROMGROUP; | |||||
| ob->flag = base->flag; | ob->flag = base->flag; | ||||
| ob->flag |= flag; | |||||
| if ((base->flag & BASE_SELECTED) != 0) { | if ((base->flag & BASE_SELECTED) != 0) { | ||||
| ob->flag |= SELECT; | ob->flag |= SELECT; | ||||
| } | } | ||||
| else { | else { | ||||
| ob->flag &= ~SELECT; | ob->flag &= ~SELECT; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 523 Lines • Show Last 20 Lines | |||||