Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/scene.c
| Show First 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | void BKE_scene_copy_data(Main *bmain, Scene *sce_dst, const Scene *sce_src, const int flag) | ||||
| SceneCollection *mc_src = BKE_collection_master(sce_src); | SceneCollection *mc_src = BKE_collection_master(sce_src); | ||||
| SceneCollection *mc_dst = BKE_collection_master(sce_dst); | SceneCollection *mc_dst = BKE_collection_master(sce_dst); | ||||
| /* recursively creates a new SceneCollection tree */ | /* recursively creates a new SceneCollection tree */ | ||||
| scene_collection_copy(mc_dst, mc_src, flag_subdata); | scene_collection_copy(mc_dst, mc_src, flag_subdata); | ||||
| IDPropertyTemplate val = {0}; | IDPropertyTemplate val = {0}; | ||||
| BLI_duplicatelist(&sce_dst->render_layers, &sce_src->render_layers); | BLI_duplicatelist(&sce_dst->render_layers, &sce_src->render_layers); | ||||
| for (SceneLayer *sl_src = sce_src->render_layers.first, *sl_dst = sce_dst->render_layers.first; | for (SceneLayer *scene_layer_src = sce_src->render_layers.first, *scene_layer_dst = sce_dst->render_layers.first; | ||||
| sl_src; | scene_layer_src; | ||||
| sl_src = sl_src->next, sl_dst = sl_dst->next) | scene_layer_src = scene_layer_src->next, scene_layer_dst = scene_layer_dst->next) | ||||
| { | { | ||||
| sl_dst->stats = NULL; | if (scene_layer_dst->id_properties != NULL) { | ||||
| sl_dst->properties_evaluated = NULL; | scene_layer_dst->id_properties = IDP_CopyProperty_ex(scene_layer_dst->id_properties, flag_subdata); | ||||
| sl_dst->properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | } | ||||
| IDP_MergeGroup_ex(sl_dst->properties, sl_src->properties, true, flag_subdata); | BKE_freestyle_config_copy(&scene_layer_dst->freestyleConfig, &scene_layer_src->freestyleConfig, flag_subdata); | ||||
| scene_layer_dst->stats = NULL; | |||||
| scene_layer_dst->properties_evaluated = NULL; | |||||
| scene_layer_dst->properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); | |||||
| IDP_MergeGroup_ex(scene_layer_dst->properties, scene_layer_src->properties, true, flag_subdata); | |||||
| /* we start fresh with no overrides and no visibility flags set | /* we start fresh with no overrides and no visibility flags set | ||||
| * instead of syncing both trees we simply unlink and relink the scene collection */ | * instead of syncing both trees we simply unlink and relink the scene collection */ | ||||
| BLI_listbase_clear(&sl_dst->layer_collections); | BLI_listbase_clear(&scene_layer_dst->layer_collections); | ||||
| BLI_listbase_clear(&sl_dst->object_bases); | BLI_listbase_clear(&scene_layer_dst->object_bases); | ||||
| BLI_listbase_clear(&sl_dst->drawdata); | BLI_listbase_clear(&scene_layer_dst->drawdata); | ||||
| layer_collections_recreate(sl_dst, &sl_src->layer_collections, mc_dst, mc_src); | layer_collections_recreate(scene_layer_dst, &scene_layer_src->layer_collections, mc_dst, mc_src); | ||||
| /* Now we handle the syncing for visibility, selectability, ... */ | /* Now we handle the syncing for visibility, selectability, ... */ | ||||
| layer_collections_sync_flags(&sl_dst->layer_collections, &sl_src->layer_collections); | layer_collections_sync_flags(&scene_layer_dst->layer_collections, &scene_layer_src->layer_collections); | ||||
| Object *active_ob = OBACT(sl_src); | Object *active_ob = OBACT(scene_layer_src); | ||||
| for (Base *base_src = sl_src->object_bases.first, *base_dst = sl_dst->object_bases.first; | for (Base *base_src = scene_layer_src->object_bases.first, *base_dst = scene_layer_dst->object_bases.first; | ||||
| base_src; | base_src; | ||||
| base_src = base_src->next, base_dst = base_dst->next) | base_src = base_src->next, base_dst = base_dst->next) | ||||
| { | { | ||||
| base_dst->flag = base_src->flag; | base_dst->flag = base_src->flag; | ||||
| base_dst->flag_legacy = base_src->flag_legacy; | base_dst->flag_legacy = base_src->flag_legacy; | ||||
| if (base_dst->object == active_ob) { | if (base_dst->object == active_ob) { | ||||
| sl_dst->basact = base_dst; | scene_layer_dst->basact = base_dst; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| 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) { | ||||
| IDP_MergeGroup_ex(sce_dst->layer_properties, sce_src->layer_properties, true, flag_subdata); | IDP_MergeGroup_ex(sce_dst->layer_properties, sce_src->layer_properties, true, flag_subdata); | ||||
| } | } | ||||
| BLI_duplicatelist(&(sce_dst->markers), &(sce_src->markers)); | BLI_duplicatelist(&(sce_dst->markers), &(sce_src->markers)); | ||||
| BLI_duplicatelist(&(sce_dst->r.layers), &(sce_src->r.layers)); | |||||
| BLI_duplicatelist(&(sce_dst->r.views), &(sce_src->r.views)); | BLI_duplicatelist(&(sce_dst->r.views), &(sce_src->r.views)); | ||||
| BKE_keyingsets_copy(&(sce_dst->keyingsets), &(sce_src->keyingsets)); | BKE_keyingsets_copy(&(sce_dst->keyingsets), &(sce_src->keyingsets)); | ||||
| if (sce_src->nodetree) { | if (sce_src->nodetree) { | ||||
| /* Note: nodetree is *not* in bmain, however this specific case is handled at lower level | /* Note: nodetree is *not* in bmain, however this specific case is handled at lower level | ||||
| * (see BKE_libblock_copy_ex()). */ | * (see BKE_libblock_copy_ex()). */ | ||||
| BKE_id_copy_ex(bmain, (ID *)sce_src->nodetree, (ID **)&sce_dst->nodetree, flag, false); | BKE_id_copy_ex(bmain, (ID *)sce_src->nodetree, (ID **)&sce_dst->nodetree, flag, false); | ||||
| BKE_libblock_relink_ex(bmain, sce_dst->nodetree, (void *)(&sce_src->id), &sce_dst->id, false); | BKE_libblock_relink_ex(bmain, sce_dst->nodetree, (void *)(&sce_src->id), &sce_dst->id, false); | ||||
| } | } | ||||
| if (sce_src->rigidbody_world) { | if (sce_src->rigidbody_world) { | ||||
| sce_dst->rigidbody_world = BKE_rigidbody_world_copy(sce_src->rigidbody_world, flag_subdata); | sce_dst->rigidbody_world = BKE_rigidbody_world_copy(sce_src->rigidbody_world, flag_subdata); | ||||
| } | } | ||||
| /* copy Freestyle settings */ | |||||
| for (SceneRenderLayer *srl_dst = sce_dst->r.layers.first, *srl_src = sce_src->r.layers.first; | |||||
| srl_src; | |||||
| srl_dst = srl_dst->next, srl_src = srl_src->next) | |||||
| { | |||||
| if (srl_dst->prop != NULL) { | |||||
| srl_dst->prop = IDP_CopyProperty_ex(srl_dst->prop, flag_subdata); | |||||
| } | |||||
| BKE_freestyle_config_copy(&srl_dst->freestyleConfig, &srl_src->freestyleConfig, flag_subdata); | |||||
| } | |||||
| /* copy color management settings */ | /* copy color management settings */ | ||||
| BKE_color_managed_display_settings_copy(&sce_dst->display_settings, &sce_src->display_settings); | BKE_color_managed_display_settings_copy(&sce_dst->display_settings, &sce_src->display_settings); | ||||
| BKE_color_managed_view_settings_copy(&sce_dst->view_settings, &sce_src->view_settings); | BKE_color_managed_view_settings_copy(&sce_dst->view_settings, &sce_src->view_settings); | ||||
| BKE_color_managed_colorspace_settings_copy(&sce_dst->sequencer_colorspace_settings, &sce_src->sequencer_colorspace_settings); | BKE_color_managed_colorspace_settings_copy(&sce_dst->sequencer_colorspace_settings, &sce_src->sequencer_colorspace_settings); | ||||
| BKE_color_managed_display_settings_copy(&sce_dst->r.im_format.display_settings, &sce_src->r.im_format.display_settings); | BKE_color_managed_display_settings_copy(&sce_dst->r.im_format.display_settings, &sce_src->r.im_format.display_settings); | ||||
| BKE_color_managed_view_settings_copy(&sce_dst->r.im_format.view_settings, &sce_src->r.im_format.view_settings); | BKE_color_managed_view_settings_copy(&sce_dst->r.im_format.view_settings, &sce_src->r.im_format.view_settings); | ||||
| ▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | |||||
| Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type) | Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type) | ||||
| { | { | ||||
| Scene *sce_copy; | Scene *sce_copy; | ||||
| /* TODO this should/could most likely be replaced by call to more generic code at some point... | /* TODO this should/could most likely be replaced by call to more generic code at some point... | ||||
| * But for now, let's keep it well isolated here. */ | * But for now, let's keep it well isolated here. */ | ||||
| if (type == SCE_COPY_EMPTY) { | if (type == SCE_COPY_EMPTY) { | ||||
| ToolSettings *ts; | ToolSettings *ts; | ||||
| ListBase rl, rv; | ListBase rv; | ||||
| sce_copy = BKE_scene_add(bmain, sce->id.name + 2); | sce_copy = BKE_scene_add(bmain, sce->id.name + 2); | ||||
| rl = sce_copy->r.layers; | |||||
| rv = sce_copy->r.views; | rv = sce_copy->r.views; | ||||
| curvemapping_free_data(&sce_copy->r.mblur_shutter_curve); | curvemapping_free_data(&sce_copy->r.mblur_shutter_curve); | ||||
| sce_copy->r = sce->r; | sce_copy->r = sce->r; | ||||
| sce_copy->r.layers = rl; | sce_copy->active_layer = 0; | ||||
| sce_copy->r.actlay = 0; | |||||
| sce_copy->r.views = rv; | sce_copy->r.views = rv; | ||||
| sce_copy->unit = sce->unit; | sce_copy->unit = sce->unit; | ||||
| sce_copy->physics_settings = sce->physics_settings; | sce_copy->physics_settings = sce->physics_settings; | ||||
| sce_copy->gm = sce->gm; | sce_copy->gm = sce->gm; | ||||
| sce_copy->audio = sce->audio; | sce_copy->audio = sce->audio; | ||||
| if (sce->id.properties) | if (sce->id.properties) | ||||
| sce_copy->id.properties = IDP_CopyProperty(sce->id.properties); | sce_copy->id.properties = IDP_CopyProperty(sce->id.properties); | ||||
| ▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | else { | ||||
| BKE_id_copy_ex(bmain, (ID *)sce, (ID **)&sce_copy, LIB_ID_COPY_ACTIONS, false); | BKE_id_copy_ex(bmain, (ID *)sce, (ID **)&sce_copy, LIB_ID_COPY_ACTIONS, false); | ||||
| id_us_min(&sce_copy->id); | id_us_min(&sce_copy->id); | ||||
| id_us_ensure_real(&sce_copy->id); | id_us_ensure_real(&sce_copy->id); | ||||
| /* Extra actions, most notably SCE_FULL_COPY also duplicates several 'children' datablocks... */ | /* Extra actions, most notably SCE_FULL_COPY also duplicates several 'children' datablocks... */ | ||||
| if (type == SCE_COPY_FULL) { | if (type == SCE_COPY_FULL) { | ||||
| /* Copy Freestyle LineStyle datablocks. */ | /* Copy Freestyle LineStyle datablocks. */ | ||||
| for (SceneRenderLayer *srl_dst = sce_copy->r.layers.first; srl_dst; srl_dst = srl_dst->next) { | for (SceneLayer *scene_layer_dst = sce_copy->render_layers.first; scene_layer_dst; scene_layer_dst = scene_layer_dst->next) { | ||||
| for (FreestyleLineSet *lineset = srl_dst->freestyleConfig.linesets.first; lineset; lineset = lineset->next) { | for (FreestyleLineSet *lineset = scene_layer_dst->freestyleConfig.linesets.first; lineset; lineset = lineset->next) { | ||||
| if (lineset->linestyle) { | if (lineset->linestyle) { | ||||
| /* XXX Not copying anim/actions here? */ | /* XXX Not copying anim/actions here? */ | ||||
| BKE_id_copy_ex(bmain, (ID *)lineset->linestyle, (ID **)&lineset->linestyle, 0, false); | BKE_id_copy_ex(bmain, (ID *)lineset->linestyle, (ID **)&lineset->linestyle, 0, false); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Full copy of world (included animations) */ | /* Full copy of world (included animations) */ | ||||
| Show All 37 Lines | void BKE_scene_make_local(Main *bmain, Scene *sce, const bool lib_local) | ||||
| /* For now should work, may need more work though to support all possible corner cases | /* For now should work, may need more work though to support all possible corner cases | ||||
| * (also scene_copy probably needs some love). */ | * (also scene_copy probably needs some love). */ | ||||
| BKE_id_make_local_generic(bmain, &sce->id, true, lib_local); | BKE_id_make_local_generic(bmain, &sce->id, true, lib_local); | ||||
| } | } | ||||
| /** Free (or release) any data used by this scene (does not free the scene itself). */ | /** Free (or release) any data used by this scene (does not free the scene itself). */ | ||||
| void BKE_scene_free_ex(Scene *sce, const bool do_id_user) | void BKE_scene_free_ex(Scene *sce, const bool do_id_user) | ||||
| { | { | ||||
| SceneRenderLayer *srl; | |||||
| BKE_animdata_free((ID *)sce, false); | BKE_animdata_free((ID *)sce, false); | ||||
| /* check all sequences */ | /* check all sequences */ | ||||
| BKE_sequencer_clear_scene_in_allseqs(G.main, sce); | BKE_sequencer_clear_scene_in_allseqs(G.main, sce); | ||||
| BKE_sequencer_editing_free(sce); | BKE_sequencer_editing_free(sce); | ||||
| BKE_keyingsets_free(&sce->keyingsets); | BKE_keyingsets_free(&sce->keyingsets); | ||||
| Show All 16 Lines | if (sce->r.avicodecdata) { | ||||
| sce->r.avicodecdata = NULL; | sce->r.avicodecdata = NULL; | ||||
| } | } | ||||
| if (sce->r.ffcodecdata.properties) { | if (sce->r.ffcodecdata.properties) { | ||||
| IDP_FreeProperty(sce->r.ffcodecdata.properties); | IDP_FreeProperty(sce->r.ffcodecdata.properties); | ||||
| MEM_freeN(sce->r.ffcodecdata.properties); | MEM_freeN(sce->r.ffcodecdata.properties); | ||||
| sce->r.ffcodecdata.properties = NULL; | sce->r.ffcodecdata.properties = NULL; | ||||
| } | } | ||||
| for (srl = sce->r.layers.first; srl; srl = srl->next) { | |||||
| if (srl->prop != NULL) { | |||||
| IDP_FreeProperty(srl->prop); | |||||
| MEM_freeN(srl->prop); | |||||
| } | |||||
| BKE_freestyle_config_free(&srl->freestyleConfig); | |||||
| } | |||||
| BLI_freelistN(&sce->markers); | BLI_freelistN(&sce->markers); | ||||
| BLI_freelistN(&sce->r.layers); | |||||
| BLI_freelistN(&sce->r.views); | BLI_freelistN(&sce->r.views); | ||||
| if (sce->toolsettings) { | if (sce->toolsettings) { | ||||
| if (sce->toolsettings->vpaint) { | if (sce->toolsettings->vpaint) { | ||||
| BKE_paint_free(&sce->toolsettings->vpaint->paint); | BKE_paint_free(&sce->toolsettings->vpaint->paint); | ||||
| MEM_freeN(sce->toolsettings->vpaint); | MEM_freeN(sce->toolsettings->vpaint); | ||||
| } | } | ||||
| if (sce->toolsettings->wpaint) { | if (sce->toolsettings->wpaint) { | ||||
| ▲ Show 20 Lines • Show All 275 Lines • ▼ Show 20 Lines | void BKE_scene_init(Scene *sce) | ||||
| sce->audio.volume = 1.0f; | sce->audio.volume = 1.0f; | ||||
| BLI_strncpy(sce->r.pic, U.renderdir, sizeof(sce->r.pic)); | BLI_strncpy(sce->r.pic, U.renderdir, sizeof(sce->r.pic)); | ||||
| BLI_rctf_init(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f); | BLI_rctf_init(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f); | ||||
| sce->r.osa = 8; | sce->r.osa = 8; | ||||
| /* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */ | /* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */ | ||||
| BKE_scene_add_render_layer(sce, NULL); | |||||
| /* multiview - stereo */ | /* multiview - stereo */ | ||||
| BKE_scene_add_render_view(sce, STEREO_LEFT_NAME); | BKE_scene_add_render_view(sce, STEREO_LEFT_NAME); | ||||
| srv = sce->r.views.first; | srv = sce->r.views.first; | ||||
| BLI_strncpy(srv->suffix, STEREO_LEFT_SUFFIX, sizeof(srv->suffix)); | BLI_strncpy(srv->suffix, STEREO_LEFT_SUFFIX, sizeof(srv->suffix)); | ||||
| BKE_scene_add_render_view(sce, STEREO_RIGHT_NAME); | BKE_scene_add_render_view(sce, STEREO_RIGHT_NAME); | ||||
| srv = sce->r.views.last; | srv = sce->r.views.last; | ||||
| ▲ Show 20 Lines • Show All 694 Lines • ▼ Show 20 Lines | #endif | ||||
| /* Notify editors and python about recalc. */ | /* Notify editors and python about recalc. */ | ||||
| BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_FRAME_CHANGE_POST); | BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_FRAME_CHANGE_POST); | ||||
| /* Inform editors about possible changes. */ | /* Inform editors about possible changes. */ | ||||
| DEG_ids_check_recalc(bmain, scene, true); | DEG_ids_check_recalc(bmain, scene, true); | ||||
| /* clear recalc flags */ | /* clear recalc flags */ | ||||
| DEG_ids_clear_recalc(bmain); | DEG_ids_clear_recalc(bmain); | ||||
| } | } | ||||
| /* return default layer, also used to patch old files */ | |||||
| SceneRenderLayer *BKE_scene_add_render_layer(Scene *sce, const char *name) | |||||
| { | |||||
| SceneRenderLayer *srl; | |||||
| if (!name) | |||||
| name = DATA_("RenderLayer"); | |||||
| srl = MEM_callocN(sizeof(SceneRenderLayer), "new render layer"); | |||||
| BLI_strncpy(srl->name, name, sizeof(srl->name)); | |||||
| BLI_uniquename(&sce->r.layers, srl, DATA_("RenderLayer"), '.', offsetof(SceneRenderLayer, name), sizeof(srl->name)); | |||||
| BLI_addtail(&sce->r.layers, srl); | |||||
| /* note, this is also in render, pipeline.c, to make layer when scenedata doesnt have it */ | |||||
| srl->lay = (1 << 20) - 1; | |||||
| srl->layflag = 0x7FFF; /* solid ztra halo edge strand */ | |||||
| srl->passflag = SCE_PASS_COMBINED | SCE_PASS_Z; | |||||
| srl->pass_alpha_threshold = 0.5f; | |||||
| BKE_freestyle_config_init(&srl->freestyleConfig); | |||||
| return srl; | |||||
| } | |||||
| bool BKE_scene_remove_render_layer(Main *bmain, Scene *scene, SceneRenderLayer *srl) | |||||
| { | |||||
| const int act = BLI_findindex(&scene->r.layers, srl); | |||||
| Scene *sce; | |||||
| if (act == -1) { | |||||
| return false; | |||||
| } | |||||
| else if ( (scene->r.layers.first == scene->r.layers.last) && | |||||
| (scene->r.layers.first == srl)) | |||||
| { | |||||
| /* ensure 1 layer is kept */ | |||||
| return false; | |||||
| } | |||||
| BKE_freestyle_config_free(&srl->freestyleConfig); | |||||
| if (srl->prop) { | |||||
| IDP_FreeProperty(srl->prop); | |||||
| MEM_freeN(srl->prop); | |||||
| } | |||||
| BLI_remlink(&scene->r.layers, srl); | |||||
| MEM_freeN(srl); | |||||
| scene->r.actlay = 0; | |||||
| for (sce = bmain->scene.first; sce; sce = sce->id.next) { | |||||
| if (sce->nodetree) { | |||||
| BKE_nodetree_remove_layer_n(sce->nodetree, scene, act); | |||||
| } | |||||
| } | |||||
| return true; | |||||
| } | |||||
| /* return default view */ | /* return default view */ | ||||
| SceneRenderView *BKE_scene_add_render_view(Scene *sce, const char *name) | SceneRenderView *BKE_scene_add_render_view(Scene *sce, const char *name) | ||||
| { | { | ||||
| SceneRenderView *srv; | SceneRenderView *srv; | ||||
| if (!name) | if (!name) | ||||
| name = DATA_("RenderView"); | name = DATA_("RenderView"); | ||||
| ▲ Show 20 Lines • Show All 731 Lines • Show Last 20 Lines | |||||