Example #1
0
Brush *BKE_brush_copy(Main *bmain, Brush *brush)
{
	Brush *brushn;
	
	brushn = BKE_libblock_copy(bmain, &brush->id);

	if (brush->mtex.tex)
		id_us_plus((ID *)brush->mtex.tex);

	if (brush->mask_mtex.tex)
		id_us_plus((ID *)brush->mask_mtex.tex);

	if (brush->paint_curve)
		id_us_plus((ID *)brush->paint_curve);

	if (brush->icon_imbuf)
		brushn->icon_imbuf = IMB_dupImBuf(brush->icon_imbuf);

	brushn->preview = NULL;

	brushn->curve = curvemapping_copy(brush->curve);

	/* enable fake user by default */
	id_fake_user_set(&brush->id);

	BKE_id_copy_ensure_local(bmain, &brush->id, &brushn->id);

	return brushn;
}
Example #2
0
/* make a copy of a given gpencil datablock */
bGPdata *gpencil_data_duplicate(bGPdata *src, bool internal_copy)
{
    bGPDlayer *gpl, *gpld;
    bGPdata *dst;

    /* error checking */
    if (src == NULL)
        return NULL;

    /* make a copy of the base-data */
    if (internal_copy) {
        /* make a straight copy for undo buffers used during stroke drawing */
        dst = MEM_dupallocN(src);
    }
    else {
        /* make a copy when others use this */
        dst = BKE_libblock_copy(&src->id);
    }

    /* copy layers */
    BLI_listbase_clear(&dst->layers);
    for (gpl = src->layers.first; gpl; gpl = gpl->next) {
        /* make a copy of source layer and its data */
        gpld = gpencil_layer_duplicate(gpl);
        BLI_addtail(&dst->layers, gpld);
    }

    /* return new */
    return dst;
}
Example #3
0
World *BKE_world_copy(World *wrld)
{
	World *wrldn;
	int a;
	
	wrldn = BKE_libblock_copy(&wrld->id);
	
	for (a = 0; a < MAX_MTEX; a++) {
		if (wrld->mtex[a]) {
			wrldn->mtex[a] = MEM_mallocN(sizeof(MTex), "BKE_world_copy");
			memcpy(wrldn->mtex[a], wrld->mtex[a], sizeof(MTex));
			id_us_plus((ID *)wrldn->mtex[a]->tex);
		}
	}

	if (wrld->nodetree) {
		wrldn->nodetree = ntreeCopyTree(wrld->nodetree);
	}
	
	if (wrld->preview)
		wrldn->preview = BKE_previewimg_copy(wrld->preview);

	BLI_listbase_clear(&wrldn->gpumaterial);

	if (wrld->id.lib) {
		BKE_id_lib_local_paths(G.main, wrld->id.lib, &wrldn->id);
	}

	return wrldn;
}
Example #4
0
/* texture copy without adding to main dbase */
Tex *localize_texture(Tex *tex)
{
	Tex *texn;
	
	texn = BKE_libblock_copy(&tex->id);
	BLI_remlink(&G.main->tex, texn);
	
	/* image texture: BKE_texture_free also doesn't decrease */
	
	if (texn->coba) texn->coba = MEM_dupallocN(texn->coba);
	if (texn->env) {
		texn->env = BKE_copy_envmap(texn->env);
		id_us_min(&texn->env->ima->id);
	}
	if (texn->pd) texn->pd = BKE_copy_pointdensity(texn->pd);
	if (texn->vd) {
		texn->vd = MEM_dupallocN(texn->vd);
		if (texn->vd->dataset)
			texn->vd->dataset = MEM_dupallocN(texn->vd->dataset);
	}
	if (texn->ot) {
		texn->ot = BKE_copy_oceantex(tex->ot);
	}
	
	texn->preview = NULL;
	
	if (tex->nodetree) {
		texn->nodetree = ntreeLocalize(tex->nodetree);
	}
	
	return texn;
}
Example #5
0
Lamp *localize_lamp(Lamp *la)
{
	Lamp *lan;
	int a;
	
	lan = BKE_libblock_copy(&la->id);
	BLI_remlink(&G.main->lamp, lan);

	for (a = 0; a < MAX_MTEX; a++) {
		if (lan->mtex[a]) {
			lan->mtex[a] = MEM_mallocN(sizeof(MTex), "localize_lamp");
			memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex));
			/* free lamp decrements */
			id_us_plus((ID *)lan->mtex[a]->tex);
		}
	}
	
	lan->curfalloff = curvemapping_copy(la->curfalloff);

	if (la->nodetree)
		lan->nodetree = ntreeLocalize(la->nodetree);
	
	lan->preview = NULL;
	
	return lan;
}
Example #6
0
Brush *BKE_brush_copy(Brush *brush)
{
	Brush *brushn;
	
	brushn = BKE_libblock_copy(&brush->id);

	if (brush->mtex.tex)
		id_us_plus((ID *)brush->mtex.tex);

	if (brush->mask_mtex.tex)
		id_us_plus((ID *)brush->mask_mtex.tex);

	if (brush->icon_imbuf)
		brushn->icon_imbuf = IMB_dupImBuf(brush->icon_imbuf);

	brushn->preview = NULL;

	brushn->curve = curvemapping_copy(brush->curve);

	/* enable fake user by default */
	if (!(brushn->id.flag & LIB_FAKEUSER)) {
		brushn->id.flag |= LIB_FAKEUSER;
		brushn->id.us++;
	}
	
	return brushn;
}
Example #7
0
Lamp *BKE_lamp_copy(Lamp *la)
{
	Lamp *lan;
	int a;
	
	lan = BKE_libblock_copy(&la->id);

	for (a = 0; a < MAX_MTEX; a++) {
		if (lan->mtex[a]) {
			lan->mtex[a] = MEM_mallocN(sizeof(MTex), "copylamptex");
			memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex));
			id_us_plus((ID *)lan->mtex[a]->tex);
		}
	}
	
	lan->curfalloff = curvemapping_copy(la->curfalloff);

	if (la->nodetree)
		lan->nodetree = ntreeCopyTree(la->nodetree);
	
	if (la->preview)
		lan->preview = BKE_previewimg_copy(la->preview);
	
	return lan;
}
Example #8
0
Camera *BKE_camera_copy(Camera *cam)
{
	Camera *camn;
	
	camn = BKE_libblock_copy(&cam->id);

	id_lib_extern((ID *)camn->dof_ob);

	return camn;
}
Example #9
0
Speaker *BKE_speaker_copy(Speaker *spk)
{
	Speaker *spkn;

	spkn = BKE_libblock_copy(&spk->id);
	if (spkn->sound)
		spkn->sound->id.us++;

	return spkn;
}
Example #10
0
Speaker *BKE_speaker_copy(Speaker *spk)
{
	Speaker *spkn;

	spkn = BKE_libblock_copy(&spk->id);
	if (spkn->sound)
		spkn->sound->id.us++;

	if (spk->id.lib) {
		BKE_id_lib_local_paths(G.main, spk->id.lib, &spkn->id);
	}

	return spkn;
}
Example #11
0
Camera *BKE_camera_copy(Camera *cam)
{
	Camera *camn;
	
	camn = BKE_libblock_copy(&cam->id);

	id_lib_extern((ID *)camn->dof_ob);

	if (cam->id.lib) {
		BKE_id_lib_local_paths(G.main, cam->id.lib, &camn->id);
	}

	return camn;
}
Example #12
0
Lattice *BKE_lattice_copy(Lattice *lt)
{
	Lattice *ltn;

	ltn = BKE_libblock_copy(&lt->id);
	ltn->def = MEM_dupallocN(lt->def);

	ltn->key = BKE_key_copy(ltn->key);
	if (ltn->key) ltn->key->from = (ID *)ltn;
	
	if (lt->dvert) {
		int tot = lt->pntsu * lt->pntsv * lt->pntsw;
		ltn->dvert = MEM_mallocN(sizeof(MDeformVert) * tot, "Lattice MDeformVert");
		copy_dverts(ltn->dvert, lt->dvert, tot);
	}

	ltn->editlatt = NULL;

	return ltn;
}
Example #13
0
bAction *BKE_action_copy(Main *bmain, bAction *src)
{
	bAction *dst = NULL;
	bActionGroup *dgrp, *sgrp;
	FCurve *dfcu, *sfcu;
	
	if (src == NULL) 
		return NULL;
	dst = BKE_libblock_copy(bmain, &src->id);
	
	/* duplicate the lists of groups and markers */
	BLI_duplicatelist(&dst->groups, &src->groups);
	BLI_duplicatelist(&dst->markers, &src->markers);
	
	/* copy F-Curves, fixing up the links as we go */
	BLI_listbase_clear(&dst->curves);
	
	for (sfcu = src->curves.first; sfcu; sfcu = sfcu->next) {
		/* duplicate F-Curve */
		dfcu = copy_fcurve(sfcu);
		BLI_addtail(&dst->curves, dfcu);
		
		/* fix group links (kindof bad list-in-list search, but this is the most reliable way) */
		for (dgrp = dst->groups.first, sgrp = src->groups.first; dgrp && sgrp; dgrp = dgrp->next, sgrp = sgrp->next) {
			if (sfcu->grp == sgrp) {
				dfcu->grp = dgrp;
				
				if (dgrp->channels.first == sfcu)
					dgrp->channels.first = dfcu;
				if (dgrp->channels.last == sfcu)
					dgrp->channels.last = dfcu;
					
				break;
			}
		}
	}
	
	BKE_id_copy_ensure_local(bmain, &src->id, &dst->id);

	return dst;
}
Example #14
0
MetaBall *BKE_mball_copy(MetaBall *mb)
{
    MetaBall *mbn;
    int a;

    mbn = BKE_libblock_copy(&mb->id);

    BLI_duplicatelist(&mbn->elems, &mb->elems);

    mbn->mat = MEM_dupallocN(mb->mat);
    for (a = 0; a < mbn->totcol; a++) {
        id_us_plus((ID *)mbn->mat[a]);
    }

    mbn->editelems = NULL;
    mbn->lastelem = NULL;

    if (mb->id.lib) {
        BKE_id_lib_local_paths(G.main, mb->id.lib, &mbn->id);
    }

    return mbn;
}
Lattice *BKE_lattice_copy(Lattice *lt)
{
	Lattice *ltn;

	ltn = BKE_libblock_copy(&lt->id);
	ltn->def = MEM_dupallocN(lt->def);

	ltn->key = BKE_key_copy(ltn->key);
	if (ltn->key) ltn->key->from = (ID *)ltn;
	
	if (lt->dvert) {
		int tot = lt->pntsu * lt->pntsv * lt->pntsw;
		ltn->dvert = MEM_mallocN(sizeof(MDeformVert) * tot, "Lattice MDeformVert");
		BKE_defvert_array_copy(ltn->dvert, lt->dvert, tot);
	}

	ltn->editlatt = NULL;

	if (lt->id.lib) {
		BKE_id_lib_local_paths(G.main, lt->id.lib, &ltn->id);
	}

	return ltn;
}
Example #16
0
Tex *BKE_texture_copy(Tex *tex)
{
	Tex *texn;
	
	texn = BKE_libblock_copy(&tex->id);
	if (texn->type == TEX_IMAGE) id_us_plus((ID *)texn->ima);
	else texn->ima = NULL;
	
	if (texn->coba) texn->coba = MEM_dupallocN(texn->coba);
	if (texn->env) texn->env = BKE_copy_envmap(texn->env);
	if (texn->pd) texn->pd = BKE_copy_pointdensity(texn->pd);
	if (texn->vd) texn->vd = MEM_dupallocN(texn->vd);
	if (texn->ot) texn->ot = BKE_copy_oceantex(texn->ot);
	if (tex->preview) texn->preview = BKE_previewimg_copy(tex->preview);

	if (tex->nodetree) {
		if (tex->nodetree->execdata) {
			ntreeTexEndExecTree(tex->nodetree->execdata);
		}
		texn->nodetree = ntreeCopyTree(tex->nodetree);
	}
	
	return texn;
}
Example #17
0
World *BKE_world_copy(World *wrld)
{
	World *wrldn;
	int a;
	
	wrldn = BKE_libblock_copy(&wrld->id);
	
	for (a = 0; a < MAX_MTEX; a++) {
		if (wrld->mtex[a]) {
			wrldn->mtex[a] = MEM_mallocN(sizeof(MTex), "BKE_world_copy");
			memcpy(wrldn->mtex[a], wrld->mtex[a], sizeof(MTex));
			id_us_plus((ID *)wrldn->mtex[a]->tex);
		}
	}

	if (wrld->nodetree) {
		wrldn->nodetree = ntreeCopyTree(wrld->nodetree);
	}
	
	if (wrld->preview)
		wrldn->preview = BKE_previewimg_copy(wrld->preview);

	return wrldn;
}
Example #18
0
World *localize_world(World *wrld)
{
	World *wrldn;
	int a;
	
	wrldn = BKE_libblock_copy(&wrld->id);
	BLI_remlink(&G.main->world, wrldn);
	
	for (a = 0; a < MAX_MTEX; a++) {
		if (wrld->mtex[a]) {
			wrldn->mtex[a] = MEM_mallocN(sizeof(MTex), "localize_world");
			memcpy(wrldn->mtex[a], wrld->mtex[a], sizeof(MTex));
			/* free world decrements */
			id_us_plus((ID *)wrldn->mtex[a]->tex);
		}
	}

	if (wrld->nodetree)
		wrldn->nodetree = ntreeLocalize(wrld->nodetree);
	
	wrldn->preview = NULL;
	
	return wrldn;
}
Example #19
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;
}