Esempio n. 1
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;
}
Esempio n. 2
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);
	
	if (la->id.lib) {
		BKE_id_lib_local_paths(G.main, la->id.lib, &lan->id);
	}

	return lan;
}
Esempio n. 3
0
// does copy_fcurve...
void BKE_action_make_local(bAction *act)
{
	tMakeLocalActionContext mlac = {act, NULL, false, false};
	Main *bmain = G.main;
	
	if (act->id.lib == NULL)
		return;
	
	/* XXX: double-check this; it used to be just single-user check, but that was when fake-users were still default */
	if ((act->id.flag & LIB_FAKEUSER) && (act->id.us <= 1)) {
		id_clear_lib_data(bmain, &act->id);
		return;
	}
	
	BKE_animdata_main_cb(bmain, make_localact_init_cb, &mlac);
	
	if (mlac.is_local && mlac.is_lib == false) {
		id_clear_lib_data(bmain, &act->id);
	}
	else if (mlac.is_local && mlac.is_lib) {
		mlac.act_new = BKE_action_copy(act);
		mlac.act_new->id.us = 0;

		BKE_id_lib_local_paths(bmain, act->id.lib, &mlac.act_new->id);

		BKE_animdata_main_cb(bmain, make_localact_apply_cb, &mlac);
	}
}
Esempio n. 4
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->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 */
	if (!(brushn->id.flag & LIB_FAKEUSER)) {
		brushn->id.flag |= LIB_FAKEUSER;
		brushn->id.us++;
	}
	
	if (brush->id.lib) {
		BKE_id_lib_local_paths(G.main, brush->id.lib, &brushn->id);
	}

	return brushn;
}
Esempio n. 5
0
/**
 * Pull an ID out of a library (make it local). Only call this for IDs that
 * don't have other library users.
 */
void id_clear_lib_data(Main *bmain, ID *id)
{
	bNodeTree *ntree = NULL;

	BKE_id_lib_local_paths(bmain, id->lib, id);

	if (id->flag & LIB_FAKEUSER) {
		id->us--;
		id->flag &= ~LIB_FAKEUSER;
	}

	id->lib = NULL;
	id->flag = LIB_LOCAL;
	new_id(which_libbase(bmain, GS(id->name)), id, NULL);

	/* internal bNodeTree blocks inside ID types below
	 * also stores id->lib, make sure this stays in sync.
	 */
	switch (GS(id->name)) {
		case ID_SCE:	ntree = ((Scene *)id)->nodetree;		break;
		case ID_MA:		ntree = ((Material *)id)->nodetree;		break;
		case ID_LA:		ntree = ((Lamp *)id)->nodetree;			break;
		case ID_WO:		ntree = ((World *)id)->nodetree;		break;
		case ID_TE:		ntree = ((Tex *)id)->nodetree;			break;
	}
	if (ntree)
		ntree->id.lib = NULL;
}
Esempio n. 6
0
/* Pull an ID out of a library (make it local). Only call this for IDs that
 * don't have other library users. */
void id_clear_lib_data(Main *bmain, ID *id)
{
    BKE_id_lib_local_paths(bmain, id->lib, id);

    id->lib = NULL;
    id->flag = LIB_LOCAL;
    new_id(which_libbase(bmain, GS(id->name)), id, NULL);
}
Esempio n. 7
0
void BKE_brush_make_local(Brush *brush)
{

	/* - only lib users: do nothing
	 * - only local users: set flag
	 * - mixed: make copy
	 */

	Main *bmain = G.main;
	Scene *scene;
	int is_local = FALSE, is_lib = FALSE;

	if (brush->id.lib == NULL) return;

	if (brush->clone.image) {
		/* special case: ima always local immediately. Clone image should only
		 * have one user anyway. */
		id_clear_lib_data(bmain, &brush->clone.image->id);
		extern_local_brush(brush);
	}

	for (scene = bmain->scene.first; scene && ELEM(0, is_lib, is_local); scene = scene->id.next) {
		if (BKE_paint_brush(&scene->toolsettings->imapaint.paint) == brush) {
			if (scene->id.lib) is_lib = TRUE;
			else is_local = TRUE;
		}
	}

	if (is_local && is_lib == FALSE) {
		id_clear_lib_data(bmain, &brush->id);
		extern_local_brush(brush);

		/* enable fake user by default */
		if (!(brush->id.flag & LIB_FAKEUSER)) {
			brush->id.flag |= LIB_FAKEUSER;
			brush->id.us++;
		}
	}
	else if (is_local && is_lib) {
		Brush *brush_new = BKE_brush_copy(brush);
		brush_new->id.us = 1; /* only keep fake user */
		brush_new->id.flag |= LIB_FAKEUSER;

		/* Remap paths of new ID using old library as base. */
		BKE_id_lib_local_paths(bmain, brush->id.lib, &brush_new->id);
		
		for (scene = bmain->scene.first; scene; scene = scene->id.next) {
			if (BKE_paint_brush(&scene->toolsettings->imapaint.paint) == brush) {
				if (scene->id.lib == NULL) {
					BKE_paint_brush_set(&scene->toolsettings->imapaint.paint, brush_new);
				}
			}
		}
	}
}
Esempio n. 8
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;
}
Esempio n. 9
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;
}
Esempio n. 10
0
void BKE_lamp_make_local(Lamp *la)
{
	Main *bmain = G.main;
	Object *ob;
	int is_local = FALSE, is_lib = FALSE;

	/* - only lib users: do nothing
	 * - only local users: set flag
	 * - mixed: make copy
	 */
	
	if (la->id.lib == NULL) return;
	if (la->id.us == 1) {
		id_clear_lib_data(bmain, &la->id);
		return;
	}
	
	ob = bmain->object.first;
	while (ob) {
		if (ob->data == la) {
			if (ob->id.lib) is_lib = TRUE;
			else is_local = TRUE;
		}
		ob = ob->id.next;
	}
	
	if (is_local && is_lib == FALSE) {
		id_clear_lib_data(bmain, &la->id);
	}
	else if (is_local && is_lib) {
		Lamp *la_new = BKE_lamp_copy(la);
		la_new->id.us = 0;

		/* Remap paths of new ID using old library as base. */
		BKE_id_lib_local_paths(bmain, la->id.lib, &la_new->id);

		ob = bmain->object.first;
		while (ob) {
			if (ob->data == la) {
				
				if (ob->id.lib == NULL) {
					ob->data = la_new;
					la_new->id.us++;
					la->id.us--;
				}
			}
			ob = ob->id.next;
		}
	}
}
Esempio n. 11
0
void BKE_speaker_make_local(Speaker *spk)
{
	Main *bmain = G.main;
	Object *ob;
	bool is_local = false, is_lib = false;

	/* - only lib users: do nothing
	 * - only local users: set flag
	 * - mixed: make copy
	 */

	if (spk->id.lib == NULL) return;
	if (spk->id.us == 1) {
		id_clear_lib_data(bmain, &spk->id);
		return;
	}

	ob = bmain->object.first;
	while (ob) {
		if (ob->data == spk) {
			if (ob->id.lib) is_lib = true;
			else is_local = true;
		}
		ob = ob->id.next;
	}

	if (is_local && is_lib == false) {
		id_clear_lib_data(bmain, &spk->id);
	}
	else if (is_local && is_lib) {
		Speaker *spk_new = BKE_speaker_copy(spk);
		spk_new->id.us = 0;

		/* Remap paths of new ID using old library as base. */
		BKE_id_lib_local_paths(bmain, spk->id.lib, &spk_new->id);

		ob = bmain->object.first;
		while (ob) {
			if (ob->data == spk) {

				if (ob->id.lib == NULL) {
					ob->data = spk_new;
					spk_new->id.us++;
					spk->id.us--;
				}
			}
			ob = ob->id.next;
		}
	}
}
Esempio n. 12
0
void BKE_mball_make_local(MetaBall *mb)
{
    Main *bmain = G.main;
    Object *ob;
    bool is_local = false, is_lib = false;

    /* - only lib users: do nothing
     * - only local users: set flag
     * - mixed: make copy
     */

    if (mb->id.lib == NULL) return;
    if (mb->id.us == 1) {
        id_clear_lib_data(bmain, &mb->id);
        extern_local_mball(mb);

        return;
    }

    for (ob = G.main->object.first; ob && ELEM(0, is_lib, is_local); ob = ob->id.next) {
        if (ob->data == mb) {
            if (ob->id.lib) is_lib = true;
            else is_local = true;
        }
    }

    if (is_local && is_lib == false) {
        id_clear_lib_data(bmain, &mb->id);
        extern_local_mball(mb);
    }
    else if (is_local && is_lib) {
        MetaBall *mb_new = BKE_mball_copy(mb);
        mb_new->id.us = 0;

        /* Remap paths of new ID using old library as base. */
        BKE_id_lib_local_paths(bmain, mb->id.lib, &mb_new->id);

        for (ob = G.main->object.first; ob; ob = ob->id.next) {
            if (ob->data == mb) {
                if (ob->id.lib == NULL) {
                    ob->data = mb_new;
                    mb_new->id.us++;
                    mb->id.us--;
                }
            }
        }
    }
}
Esempio n. 13
0
void BKE_mesh_make_local(Mesh *me)
{
	Main *bmain = G.main;
	Object *ob;
	int is_local = FALSE, is_lib = FALSE;

	/* - only lib users: do nothing
	 * - only local users: set flag
	 * - mixed: make copy
	 */

	if (me->id.lib == NULL) return;
	if (me->id.us == 1) {
		id_clear_lib_data(bmain, &me->id);
		expand_local_mesh(me);
		return;
	}

	for (ob = bmain->object.first; ob && ELEM(0, is_lib, is_local); ob = ob->id.next) {
		if (me == ob->data) {
			if (ob->id.lib) is_lib = TRUE;
			else is_local = TRUE;
		}
	}

	if (is_local && is_lib == FALSE) {
		id_clear_lib_data(bmain, &me->id);
		expand_local_mesh(me);
	}
	else if (is_local && is_lib) {
		Mesh *me_new = BKE_mesh_copy(me);
		me_new->id.us = 0;


		/* Remap paths of new ID using old library as base. */
		BKE_id_lib_local_paths(bmain, me->id.lib, &me_new->id);

		for (ob = bmain->object.first; ob; ob = ob->id.next) {
			if (me == ob->data) {
				if (ob->id.lib == NULL) {
					BKE_mesh_assign_object(ob, me_new);
				}
			}
		}
	}
}
Esempio n. 14
0
void make_local_camera(Camera *cam)
{
	Main *bmain= G.main;
	Object *ob;
	int is_local= FALSE, is_lib= FALSE;

	/* - only lib users: do nothing
	 * - only local users: set flag
	 * - mixed: make copy
	 */
	
	if (cam->id.lib==NULL) return;
	if (cam->id.us==1) {
		id_clear_lib_data(bmain, &cam->id);
		return;
	}
	
	for (ob= bmain->object.first; ob && ELEM(0, is_lib, is_local); ob= ob->id.next) {
		if (ob->data==cam) {
			if (ob->id.lib) is_lib= TRUE;
			else is_local= TRUE;
		}
	}
	
	if (is_local && is_lib == FALSE) {
		id_clear_lib_data(bmain, &cam->id);
	}
	else if (is_local && is_lib) {
		Camera *cam_new= copy_camera(cam);

		cam_new->id.us= 0;

		/* Remap paths of new ID using old library as base. */
		BKE_id_lib_local_paths(bmain, cam->id.lib, &cam_new->id);

		for (ob= bmain->object.first; ob; ob= ob->id.next) {
			if (ob->data == cam) {
				if (ob->id.lib==NULL) {
					ob->data= cam_new;
					cam_new->id.us++;
					cam->id.us--;
				}
			}
		}
	}
}
Esempio n. 15
0
void BKE_lattice_make_local(Lattice *lt)
{
	Main *bmain = G.main;
	Object *ob;
	int is_local = FALSE, is_lib = FALSE;

	/* - only lib users: do nothing
	 * - only local users: set flag
	 * - mixed: make copy
	 */
	
	if (lt->id.lib == NULL) return;
	if (lt->id.us == 1) {
		id_clear_lib_data(bmain, &lt->id);
		return;
	}
	
	for (ob = bmain->object.first; ob && ELEM(FALSE, is_lib, is_local); ob = ob->id.next) {
		if (ob->data == lt) {
			if (ob->id.lib) is_lib = TRUE;
			else is_local = TRUE;
		}
	}
	
	if (is_local && is_lib == FALSE) {
		id_clear_lib_data(bmain, &lt->id);
	}
	else if (is_local && is_lib) {
		Lattice *lt_new = BKE_lattice_copy(lt);
		lt_new->id.us = 0;

		/* Remap paths of new ID using old library as base. */
		BKE_id_lib_local_paths(bmain, lt->id.lib, &lt_new->id);

		for (ob = bmain->object.first; ob; ob = ob->id.next) {
			if (ob->data == lt) {
				if (ob->id.lib == NULL) {
					ob->data = lt_new;
					lt_new->id.us++;
					lt->id.us--;
				}
			}
		}
	}
}
Esempio n. 16
0
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--;
				}
			}
		}
	}
}
Esempio n. 17
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;
}
Esempio n. 18
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");
		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;
}
Esempio n. 19
0
void BKE_texture_make_local(Tex *tex)
{
	Main *bmain = G.main;
	Material *ma;
	World *wrld;
	Lamp *la;
	Brush *br;
	ParticleSettings *pa;
	int a, is_local = FALSE, is_lib = FALSE;

	/* - only lib users: do nothing
	 * - only local users: set flag
	 * - mixed: make copy
	 */
	
	if (tex->id.lib == NULL) return;

	if (tex->id.us == 1) {
		id_clear_lib_data(bmain, &tex->id);
		extern_local_texture(tex);
		return;
	}
	
	ma = bmain->mat.first;
	while (ma) {
		for (a = 0; a < MAX_MTEX; a++) {
			if (ma->mtex[a] && ma->mtex[a]->tex == tex) {
				if (ma->id.lib) is_lib = TRUE;
				else is_local = TRUE;
			}
		}
		ma = ma->id.next;
	}
	la = bmain->lamp.first;
	while (la) {
		for (a = 0; a < MAX_MTEX; a++) {
			if (la->mtex[a] && la->mtex[a]->tex == tex) {
				if (la->id.lib) is_lib = TRUE;
				else is_local = TRUE;
			}
		}
		la = la->id.next;
	}
	wrld = bmain->world.first;
	while (wrld) {
		for (a = 0; a < MAX_MTEX; a++) {
			if (wrld->mtex[a] && wrld->mtex[a]->tex == tex) {
				if (wrld->id.lib) is_lib = TRUE;
				else is_local = TRUE;
			}
		}
		wrld = wrld->id.next;
	}
	br = bmain->brush.first;
	while (br) {
		if (br->mtex.tex == tex) {
			if (br->id.lib) is_lib = TRUE;
			else is_local = TRUE;
		}
		if (br->mask_mtex.tex == tex) {
			if (br->id.lib) is_lib = TRUE;
			else is_local = TRUE;
		}
		br = br->id.next;
	}
	pa = bmain->particle.first;
	while (pa) {
		for (a = 0; a < MAX_MTEX; a++) {
			if (pa->mtex[a] && pa->mtex[a]->tex == tex) {
				if (pa->id.lib) is_lib = TRUE;
				else is_local = TRUE;
			}
		}
		pa = pa->id.next;
	}
	
	if (is_local && is_lib == FALSE) {
		id_clear_lib_data(bmain, &tex->id);
		extern_local_texture(tex);
	}
	else if (is_local && is_lib) {
		Tex *tex_new = BKE_texture_copy(tex);

		tex_new->id.us = 0;

		/* Remap paths of new ID using old library as base. */
		BKE_id_lib_local_paths(bmain, tex->id.lib, &tex_new->id);
		
		ma = bmain->mat.first;
		while (ma) {
			for (a = 0; a < MAX_MTEX; a++) {
				if (ma->mtex[a] && ma->mtex[a]->tex == tex) {
					if (ma->id.lib == NULL) {
						ma->mtex[a]->tex = tex_new;
						tex_new->id.us++;
						tex->id.us--;
					}
				}
			}
			ma = ma->id.next;
		}
		la = bmain->lamp.first;
		while (la) {
			for (a = 0; a < MAX_MTEX; a++) {
				if (la->mtex[a] && la->mtex[a]->tex == tex) {
					if (la->id.lib == NULL) {
						la->mtex[a]->tex = tex_new;
						tex_new->id.us++;
						tex->id.us--;
					}
				}
			}
			la = la->id.next;
		}
		wrld = bmain->world.first;
		while (wrld) {
			for (a = 0; a < MAX_MTEX; a++) {
				if (wrld->mtex[a] && wrld->mtex[a]->tex == tex) {
					if (wrld->id.lib == NULL) {
						wrld->mtex[a]->tex = tex_new;
						tex_new->id.us++;
						tex->id.us--;
					}
				}
			}
			wrld = wrld->id.next;
		}
		br = bmain->brush.first;
		while (br) {
			if (br->mtex.tex == tex) {
				if (br->id.lib == NULL) {
					br->mtex.tex = tex_new;
					tex_new->id.us++;
					tex->id.us--;
				}
			}
			if (br->mask_mtex.tex == tex) {
				if (br->id.lib == NULL) {
					br->mask_mtex.tex = tex_new;
					tex_new->id.us++;
					tex->id.us--;
				}
			}
			br = br->id.next;
		}
		pa = bmain->particle.first;
		while (pa) {
			for (a = 0; a < MAX_MTEX; a++) {
				if (pa->mtex[a] && pa->mtex[a]->tex == tex) {
					if (pa->id.lib == NULL) {
						pa->mtex[a]->tex = tex_new;
						tex_new->id.us++;
						tex->id.us--;
					}
				}
			}
			pa = pa->id.next;
		}
	}
}