void BKE_world_make_local(World *wrld) { Main *bmain = G.main; Scene *sce; int is_local = FALSE, is_lib = FALSE; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ if (wrld->id.lib == NULL) return; if (wrld->id.us == 1) { id_clear_lib_data(bmain, &wrld->id); return; } for (sce = bmain->scene.first; sce && ELEM(FALSE, is_lib, is_local); sce = sce->id.next) { if (sce->world == wrld) { if (sce->id.lib) is_lib = TRUE; else is_local = TRUE; } } if (is_local && is_lib == FALSE) { id_clear_lib_data(bmain, &wrld->id); } else if (is_local && is_lib) { World *wrld_new = BKE_world_copy(wrld); wrld_new->id.us = 0; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, wrld->id.lib, &wrld_new->id); for (sce = bmain->scene.first; sce; sce = sce->id.next) { if (sce->world == wrld) { if (sce->id.lib == NULL) { sce->world = wrld_new; wrld_new->id.us++; wrld->id.us--; } } } } }
int id_copy(ID *id, ID **newid, int test) { if (!test) *newid = NULL; /* conventions: * - make shallow copy, only this ID block * - id.us of the new ID is set to 1 */ switch (GS(id->name)) { case ID_SCE: return 0; /* can't be copied from here */ case ID_LI: return 0; /* can't be copied from here */ case ID_OB: if (!test) *newid = (ID *)BKE_object_copy((Object *)id); return 1; case ID_ME: if (!test) *newid = (ID *)BKE_mesh_copy((Mesh *)id); return 1; case ID_CU: if (!test) *newid = (ID *)BKE_curve_copy((Curve *)id); return 1; case ID_MB: if (!test) *newid = (ID *)BKE_mball_copy((MetaBall *)id); return 1; case ID_MA: if (!test) *newid = (ID *)BKE_material_copy((Material *)id); return 1; case ID_TE: if (!test) *newid = (ID *)BKE_texture_copy((Tex *)id); return 1; case ID_IM: if (!test) *newid = (ID *)BKE_image_copy((Image *)id); return 1; case ID_LT: if (!test) *newid = (ID *)BKE_lattice_copy((Lattice *)id); return 1; case ID_LA: if (!test) *newid = (ID *)BKE_lamp_copy((Lamp *)id); return 1; case ID_SPK: if (!test) *newid = (ID *)BKE_speaker_copy((Speaker *)id); return 1; case ID_CA: if (!test) *newid = (ID *)BKE_camera_copy((Camera *)id); return 1; case ID_IP: return 0; /* deprecated */ case ID_KE: if (!test) *newid = (ID *)BKE_key_copy((Key *)id); return 1; case ID_WO: if (!test) *newid = (ID *)BKE_world_copy((World *)id); return 1; case ID_SCR: return 0; /* can't be copied from here */ case ID_VF: return 0; /* not implemented */ case ID_TXT: if (!test) *newid = (ID *)BKE_text_copy((Text *)id); return 1; case ID_SCRIPT: return 0; /* deprecated */ case ID_SO: return 0; /* not implemented */ case ID_GR: if (!test) *newid = (ID *)BKE_group_copy((Group *)id); return 1; case ID_AR: if (!test) *newid = (ID *)BKE_armature_copy((bArmature *)id); return 1; case ID_AC: if (!test) *newid = (ID *)BKE_action_copy((bAction *)id); return 1; case ID_NT: if (!test) *newid = (ID *)ntreeCopyTree((bNodeTree *)id); return 1; case ID_BR: if (!test) *newid = (ID *)BKE_brush_copy((Brush *)id); return 1; case ID_PA: if (!test) *newid = (ID *)BKE_particlesettings_copy((ParticleSettings *)id); return 1; case ID_WM: return 0; /* can't be copied from here */ case ID_GD: return 0; /* not implemented */ } return 0; }
Scene *BKE_scene_copy(Scene *sce, int type) { Scene *scen; ToolSettings *ts; Base *base, *obase; if (type == SCE_COPY_EMPTY) { ListBase lb; /* XXX. main should become an arg */ scen = BKE_scene_add(G.main, sce->id.name + 2); lb = scen->r.layers; scen->r = sce->r; scen->r.layers = lb; scen->unit = sce->unit; scen->physics_settings = sce->physics_settings; scen->gm = sce->gm; scen->audio = sce->audio; MEM_freeN(scen->toolsettings); } else { scen = BKE_libblock_copy(&sce->id); BLI_duplicatelist(&(scen->base), &(sce->base)); clear_id_newpoins(); id_us_plus((ID *)scen->world); id_us_plus((ID *)scen->set); id_us_plus((ID *)scen->gm.dome.warptext); scen->ed = NULL; scen->theDag = NULL; scen->obedit = NULL; scen->stats = NULL; scen->fps_info = NULL; BLI_duplicatelist(&(scen->markers), &(sce->markers)); BLI_duplicatelist(&(scen->transform_spaces), &(sce->transform_spaces)); BLI_duplicatelist(&(scen->r.layers), &(sce->r.layers)); BKE_keyingsets_copy(&(scen->keyingsets), &(sce->keyingsets)); if (sce->nodetree) { /* ID's are managed on both copy and switch */ scen->nodetree = ntreeCopyTree(sce->nodetree); ntreeSwitchID(scen->nodetree, &sce->id, &scen->id); } obase = sce->base.first; base = scen->base.first; while (base) { id_us_plus(&base->object->id); if (obase == sce->basact) scen->basact = base; obase = obase->next; base = base->next; } /* copy color management settings */ BKE_color_managed_display_settings_copy(&scen->display_settings, &sce->display_settings); BKE_color_managed_view_settings_copy(&scen->view_settings, &sce->view_settings); BKE_color_managed_view_settings_copy(&scen->r.im_format.view_settings, &sce->r.im_format.view_settings); BLI_strncpy(scen->sequencer_colorspace_settings.name, sce->sequencer_colorspace_settings.name, sizeof(scen->sequencer_colorspace_settings.name)); /* remove animation used by sequencer */ if (type != SCE_COPY_FULL) remove_sequencer_fcurves(scen); } /* tool settings */ scen->toolsettings = MEM_dupallocN(sce->toolsettings); ts = scen->toolsettings; if (ts) { if (ts->vpaint) { ts->vpaint = MEM_dupallocN(ts->vpaint); ts->vpaint->paintcursor = NULL; ts->vpaint->vpaint_prev = NULL; ts->vpaint->wpaint_prev = NULL; BKE_paint_copy(&ts->vpaint->paint, &ts->vpaint->paint); } if (ts->wpaint) { ts->wpaint = MEM_dupallocN(ts->wpaint); ts->wpaint->paintcursor = NULL; ts->wpaint->vpaint_prev = NULL; ts->wpaint->wpaint_prev = NULL; BKE_paint_copy(&ts->wpaint->paint, &ts->wpaint->paint); } if (ts->sculpt) { ts->sculpt = MEM_dupallocN(ts->sculpt); BKE_paint_copy(&ts->sculpt->paint, &ts->sculpt->paint); } BKE_paint_copy(&ts->imapaint.paint, &ts->imapaint.paint); ts->imapaint.paintcursor = NULL; ts->particle.paintcursor = NULL; } /* make a private copy of the avicodecdata */ if (sce->r.avicodecdata) { scen->r.avicodecdata = MEM_dupallocN(sce->r.avicodecdata); scen->r.avicodecdata->lpFormat = MEM_dupallocN(scen->r.avicodecdata->lpFormat); scen->r.avicodecdata->lpParms = MEM_dupallocN(scen->r.avicodecdata->lpParms); } /* make a private copy of the qtcodecdata */ if (sce->r.qtcodecdata) { scen->r.qtcodecdata = MEM_dupallocN(sce->r.qtcodecdata); scen->r.qtcodecdata->cdParms = MEM_dupallocN(scen->r.qtcodecdata->cdParms); } if (sce->r.ffcodecdata.properties) { /* intentionally check scen not sce. */ scen->r.ffcodecdata.properties = IDP_CopyProperty(sce->r.ffcodecdata.properties); } /* NOTE: part of SCE_COPY_LINK_DATA and SCE_COPY_FULL operations * are done outside of blenkernel with ED_objects_single_users! */ /* camera */ if (type == SCE_COPY_LINK_DATA || type == SCE_COPY_FULL) { ID_NEW(scen->camera); } /* before scene copy */ sound_create_scene(scen); /* world */ if (type == SCE_COPY_FULL) { BKE_copy_animdata_id_action((ID *)scen); if (scen->world) { id_us_plus((ID *)scen->world); scen->world = BKE_world_copy(scen->world); BKE_copy_animdata_id_action((ID *)scen->world); } if (sce->ed) { scen->ed = MEM_callocN(sizeof(Editing), "addseq"); scen->ed->seqbasep = &scen->ed->seqbase; BKE_sequence_base_dupli_recursive(sce, scen, &scen->ed->seqbase, &sce->ed->seqbase, SEQ_DUPE_ALL); } } return scen; }