Exemple #1
0
static void extern_local_brush(Brush *brush)
{
	id_lib_extern((ID *)brush->mtex.tex);
	id_lib_extern((ID *)brush->mask_mtex.tex);
	id_lib_extern((ID *)brush->clone.image);
	id_lib_extern((ID *)brush->paint_curve);
}
Exemple #2
0
Mesh *BKE_mesh_copy_ex(Main *bmain, Mesh *me)
{
	Mesh *men;
	MTFace *tface;
	MTexPoly *txface;
	int a, i;
	const int do_tessface = ((me->totface != 0) && (me->totpoly == 0)); /* only do tessface if we have no polys */
	
	men = BKE_libblock_copy_ex(bmain, &me->id);
	
	men->mat = MEM_dupallocN(me->mat);
	for (a = 0; a < men->totcol; a++) {
		id_us_plus((ID *)men->mat[a]);
	}
	id_us_plus((ID *)men->texcomesh);

	CustomData_copy(&me->vdata, &men->vdata, CD_MASK_MESH, CD_DUPLICATE, men->totvert);
	CustomData_copy(&me->edata, &men->edata, CD_MASK_MESH, CD_DUPLICATE, men->totedge);
	CustomData_copy(&me->ldata, &men->ldata, CD_MASK_MESH, CD_DUPLICATE, men->totloop);
	CustomData_copy(&me->pdata, &men->pdata, CD_MASK_MESH, CD_DUPLICATE, men->totpoly);
	if (do_tessface) {
		CustomData_copy(&me->fdata, &men->fdata, CD_MASK_MESH, CD_DUPLICATE, men->totface);
	}
	else {
		mesh_tessface_clear_intern(men, FALSE);
	}

	BKE_mesh_update_customdata_pointers(men, do_tessface);

	/* ensure indirect linked data becomes lib-extern */
	for (i = 0; i < me->fdata.totlayer; i++) {
		if (me->fdata.layers[i].type == CD_MTFACE) {
			tface = (MTFace *)me->fdata.layers[i].data;

			for (a = 0; a < me->totface; a++, tface++)
				if (tface->tpage)
					id_lib_extern((ID *)tface->tpage);
		}
	}
	
	for (i = 0; i < me->pdata.totlayer; i++) {
		if (me->pdata.layers[i].type == CD_MTEXPOLY) {
			txface = (MTexPoly *)me->pdata.layers[i].data;

			for (a = 0; a < me->totpoly; a++, txface++)
				if (txface->tpage)
					id_lib_extern((ID *)txface->tpage);
		}
	}

	men->edit_btmesh = NULL;

	men->mselect = MEM_dupallocN(men->mselect);
	men->bb = MEM_dupallocN(men->bb);
	
	men->key = BKE_key_copy(me->key);
	if (men->key) men->key->from = (ID *)men;

	return men;
}
Exemple #3
0
/* for curve, mball, mesh types */
void extern_local_matarar(struct Material **matar, short totcol)
{
	short i;
	for(i= 0; i < totcol; i++) {
		id_lib_extern((ID *)matar[i]);
	}
}
Exemple #4
0
static void group_linkobs2scene_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te),
                                   TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
{
	Group *group = (Group *)tselem->id;
	GroupObject *gob;
	Base *base;
	
	for (gob = group->gobject.first; gob; gob = gob->next) {
		base = BKE_scene_base_find(scene, gob->ob);
		if (base) {
			base->object->flag |= SELECT;
			base->flag |= SELECT;
		}
		else {
			/* link to scene */
			base = MEM_callocN(sizeof(Base), "add_base");
			BLI_addhead(&scene->base, base);
			base->lay = gob->ob->lay;
			gob->ob->flag |= SELECT;
			base->flag = gob->ob->flag;
			base->object = gob->ob;
			id_lib_extern((ID *)gob->ob); /* in case these are from a linked group */
		}
	}
}
Exemple #5
0
static void extern_local_material(Material *ma)
{
	int i;
	for(i=0; i < MAX_MTEX; i++) {
		if(ma->mtex[i]) id_lib_extern((ID *)ma->mtex[i]->tex);
	}
}
Exemple #6
0
/* XXX keep synced with next function */
Material *copy_material(Material *ma)
{
	Material *man;
	int a;
	
	man= copy_libblock(ma);
	
	id_lib_extern((ID *)man->group);
	
	for(a=0; a<MAX_MTEX; a++) {
		if(ma->mtex[a]) {
			man->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial");
			memcpy(man->mtex[a], ma->mtex[a], sizeof(MTex));
			id_us_plus((ID *)man->mtex[a]->tex);
		}
	}
	
	if(ma->ramp_col) man->ramp_col= MEM_dupallocN(ma->ramp_col);
	if(ma->ramp_spec) man->ramp_spec= MEM_dupallocN(ma->ramp_spec);
	
	if (ma->preview) man->preview = BKE_previewimg_copy(ma->preview);

	if(ma->nodetree) {
		man->nodetree= ntreeCopyTree(ma->nodetree);	/* 0 == full new tree */
	}

	man->gpumaterial.first= man->gpumaterial.last= NULL;
	
	return man;
}
Exemple #7
0
static int group_instance_add_exec(bContext *C, wmOperator *op)
{
	Group *group= BLI_findlink(&CTX_data_main(C)->group, RNA_enum_get(op->ptr, "group"));

	int enter_editmode;
	unsigned int layer;
	float loc[3], rot[3];
	
	object_add_generic_invoke_options(C, op);
	if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer))
		return OPERATOR_CANCELLED;

	if(group) {
		Main *bmain= CTX_data_main(C);
		Scene *scene= CTX_data_scene(C);
		Object *ob= ED_object_add_type(C, OB_EMPTY, loc, rot, FALSE, layer);
		rename_id(&ob->id, group->id.name+2);
		ob->dup_group= group;
		ob->transflag |= OB_DUPLIGROUP;
		id_lib_extern(&group->id);

		/* works without this except if you try render right after, see: 22027 */
		DAG_scene_sort(bmain, scene);

		WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, CTX_data_scene(C));

		return OPERATOR_FINISHED;
	}

	return OPERATOR_CANCELLED;
}
Exemple #8
0
Camera *copy_camera(Camera *cam)
{
	Camera *camn;
	
	camn= copy_libblock(&cam->id);

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

	return camn;
}
Exemple #9
0
Camera *BKE_camera_copy(Camera *cam)
{
	Camera *camn;
	
	camn = BKE_libblock_copy(&cam->id);

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

	return camn;
}
Exemple #10
0
void TimelineMarker_camera_set(PointerRNA *ptr, PointerRNA value)
{
	TimeMarker *data= (TimeMarker*)(ptr->data);
	ID *id= ptr->id.data;
	if(id==value.data) return;

	if(value.data)
		id_lib_extern((ID*)value.data);

	data->camera= value.data;
}
Exemple #11
0
static void group_instance_cb(bContext *C, Scene *scene, TreeElement *UNUSED(te),
                              TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
{
	Group *group = (Group *)tselem->id;

	Object *ob = ED_object_add_type(C, OB_EMPTY, scene->cursor, NULL, FALSE, scene->layact);
	rename_id(&ob->id, group->id.name + 2);
	ob->dup_group = group;
	ob->transflag |= OB_DUPLIGROUP;
	id_lib_extern(&group->id);
}
Exemple #12
0
static void expand_local_mesh(Main *bmain, Mesh *me)
{
	id_lib_extern((ID *)me->texcomesh);

	if(me->mtface) {
		/* why is this an exception? - should not really make local when extern'ing - campbell */
		make_local_tface(bmain, me);
	}

	if(me->mat) {
		extern_local_matarar(me->mat, me->totcol);
	}
}
Exemple #13
0
static void expand_local_mesh(Mesh *me)
{
	id_lib_extern((ID *)me->texcomesh);

	if (me->mtface || me->mtpoly) {
		int a, i;

		for (i = 0; i < me->pdata.totlayer; i++) {
			if (me->pdata.layers[i].type == CD_MTEXPOLY) {
				MTexPoly *txface = (MTexPoly *)me->pdata.layers[i].data;

				for (a = 0; a < me->totpoly; a++, txface++) {
					/* special case: ima always local immediately */
					if (txface->tpage) {
						id_lib_extern((ID *)txface->tpage);
					}
				}
			}
		}

		for (i = 0; i < me->fdata.totlayer; i++) {
			if (me->fdata.layers[i].type == CD_MTFACE) {
				MTFace *tface = (MTFace *)me->fdata.layers[i].data;

				for (a = 0; a < me->totface; a++, tface++) {
					/* special case: ima always local immediately */
					if (tface->tpage) {
						id_lib_extern((ID *)tface->tpage);
					}
				}
			}
		}
	}

	if (me->mat) {
		extern_local_matarar(me->mat, me->totcol);
	}
}
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;
}
Exemple #15
0
static void lib_indirect_test_id(ID *id, Library *lib)
{
#define LIBTAG(a)   if (a && a->id.lib) { a->id.flag &= ~LIB_INDIRECT; a->id.flag |= LIB_EXTERN; } (void)0
	
	if (id->lib) {
		/* datablocks that were indirectly related are now direct links
		 * without this, appending data that has a link to other data will fail to write */
		if (lib && id->lib->parent == lib) {
			id_lib_extern(id);
		}
		return;
	}
	
	if (GS(id->name) == ID_OB) {
		Object *ob = (Object *)id;
		Mesh *me;

		int a;

#if 0   /* XXX OLD ANIMSYS, NLASTRIPS ARE NO LONGER USED */
		/* XXX old animation system! -------------------------------------- */
		{
			bActionStrip *strip;
			for (strip = ob->nlastrips.first; strip; strip = strip->next) {
				LIBTAG(strip->object);
				LIBTAG(strip->act);
				LIBTAG(strip->ipo);
			}
		}
		/* XXX: new animation system needs something like this? */
#endif

		for (a = 0; a < ob->totcol; a++) {
			LIBTAG(ob->mat[a]);
		}
	
		LIBTAG(ob->dup_group);
		LIBTAG(ob->proxy);
		
		me = ob->data;
		LIBTAG(me);
	}

#undef LIBTAG
}
Exemple #16
0
Mesh *copy_mesh(Mesh *me)
{
	Mesh *men;
	MTFace *tface;
	int a, i;
	
	men= copy_libblock(me);
	
	men->mat= MEM_dupallocN(me->mat);
	for(a=0; a<men->totcol; a++) {
		id_us_plus((ID *)men->mat[a]);
	}
	id_us_plus((ID *)men->texcomesh);

	CustomData_copy(&me->vdata, &men->vdata, CD_MASK_MESH, CD_DUPLICATE, men->totvert);
	CustomData_copy(&me->edata, &men->edata, CD_MASK_MESH, CD_DUPLICATE, men->totedge);
	CustomData_copy(&me->fdata, &men->fdata, CD_MASK_MESH, CD_DUPLICATE, men->totface);
	mesh_update_customdata_pointers(men);

	/* ensure indirect linked data becomes lib-extern */
	for(i=0; i<me->fdata.totlayer; i++) {
		if(me->fdata.layers[i].type == CD_MTFACE) {
			tface= (MTFace*)me->fdata.layers[i].data;

			for(a=0; a<me->totface; a++, tface++)
				if(tface->tpage)
					id_lib_extern((ID*)tface->tpage);
		}
	}
	
	men->mselect= NULL;
	men->edit_mesh= NULL;
	men->pv= NULL; /* looks like this is no-longer supported but NULL just incase */

	men->bb= MEM_dupallocN(men->bb);
	
	men->key= copy_key(me->key);
	if(men->key) men->key->from= (ID *)men;

	return men;
}
static int bpy_bmtexpoly_image_set(BPy_BMTexPoly *self, PyObject *value, void *UNUSED(closure))
{
	ID *id;

	if (value == Py_None) {
		id = NULL;
	}
	else if (pyrna_id_FromPyObject(value, &id) && id && GS(id->name) == ID_IM) {
		/* pass */
	}
	else {
		PyErr_Format(PyExc_KeyError, "BMTexPoly.image = x"
		             "expected an image or None, not '%.200s'",
		             Py_TYPE(value)->tp_name);
		return -1;
	}

	id_lib_extern(id);
	self->data->tpage = (struct Image *)id;

	return 0;
}
Exemple #18
0
static void lib_indirect_test_id(ID *id, Library *lib)
{
	
	if(id->lib) {
		/* datablocks that were indirectly related are now direct links
		 * without this, appending data that has a link to other data will fail to write */
		if(lib && id->lib->parent == lib) {
			id_lib_extern(id);
		}
		return;
	}
	
	if(GS(id->name)==ID_OB) {		
		Object *ob= (Object *)id;
		bActionStrip *strip;
		Mesh *me;

		int a;
	
		// XXX old animation system! --------------------------------------
		for (strip=ob->nlastrips.first; strip; strip=strip->next){
			LIBTAG(strip->object); 
			LIBTAG(strip->act);
			LIBTAG(strip->ipo);
		}
		// XXX: new animation system needs something like this?
	
		for(a=0; a<ob->totcol; a++) {
			LIBTAG(ob->mat[a]);
		}
	
		LIBTAG(ob->dup_group);
		LIBTAG(ob->proxy);
		
		me= ob->data;
		LIBTAG(me);
	}
}
Exemple #19
0
static void group_linkobs2scene_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
{
	Group *group= (Group *)tselem->id;
	GroupObject *gob;
	Base *base;
	
	for (gob=group->gobject.first; gob; gob=gob->next) {
		base= object_in_scene(gob->ob, scene);
		if (base) {
			base->object->flag |= SELECT;
			base->flag |= SELECT;
		}
		else {
			/* link to scene */
			base= MEM_callocN( sizeof(Base), "add_base");
			BLI_addhead(&scene->base, base);
			base->lay= (1<<20)-1; /*v3d->lay;*/ /* would be nice to use the 3d layer but the include's not here */
			gob->ob->flag |= SELECT;
			base->flag = gob->ob->flag;
			base->object= gob->ob;
			id_lib_extern((ID *)gob->ob); /* in case these are from a linked group */
		}
	}
}
Exemple #20
0
static void extern_local_brush(Brush *brush)
{
	id_lib_extern((ID *)brush->mtex.tex);
}
Exemple #21
0
static void extern_local_texture(Tex *tex)
{
	id_lib_extern((ID *)tex->ima);
}
Exemple #22
0
/* UNUSED, keep in case we want to copy functionality for use elsewhere */
static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event)
{
	Object *ob;
	Base *base;
	Curve *cu, *cu1;
	Nurb *nu;
	int do_scene_sort= 0;
	
	if (scene->id.lib) return;

	if (!(ob=OBACT)) return;
	
	if (scene->obedit) { // XXX get from context
		/* obedit_copymenu(); */
		return;
	}
	if (event==9) {
		copymenu_properties(scene, v3d, ob);
		return;
	}
	else if (event==10) {
		copymenu_logicbricks(scene, v3d, ob);
		return;
	}
	else if (event==24) {
		/* moved to object_link_modifiers */
		/* copymenu_modifiers(bmain, scene, v3d, ob); */
		return;
	}

	for (base= FIRSTBASE; base; base= base->next) {
		if (base != BASACT) {
			if (TESTBASELIB(v3d, base)) {
				base->object->recalc |= OB_RECALC_OB;
				
				if (event==1) {  /* loc */
					copy_v3_v3(base->object->loc, ob->loc);
					copy_v3_v3(base->object->dloc, ob->dloc);
				}
				else if (event==2) {  /* rot */
					copy_v3_v3(base->object->rot, ob->rot);
					copy_v3_v3(base->object->drot, ob->drot);

					copy_qt_qt(base->object->quat, ob->quat);
					copy_qt_qt(base->object->dquat, ob->dquat);
				}
				else if (event==3) {  /* size */
					copy_v3_v3(base->object->size, ob->size);
					copy_v3_v3(base->object->dscale, ob->dscale);
				}
				else if (event==4) {  /* drawtype */
					base->object->dt= ob->dt;
					base->object->dtx= ob->dtx;
					base->object->empty_drawtype= ob->empty_drawtype;
					base->object->empty_drawsize= ob->empty_drawsize;
				}
				else if (event==5) {  /* time offs */
					base->object->sf= ob->sf;
				}
				else if (event==6) {  /* dupli */
					base->object->dupon= ob->dupon;
					base->object->dupoff= ob->dupoff;
					base->object->dupsta= ob->dupsta;
					base->object->dupend= ob->dupend;
					
					base->object->transflag &= ~OB_DUPLI;
					base->object->transflag |= (ob->transflag & OB_DUPLI);

					base->object->dup_group= ob->dup_group;
					if (ob->dup_group)
						id_lib_extern(&ob->dup_group->id);
				}
				else if (event==7) {	/* mass */
					base->object->mass= ob->mass;
				}
				else if (event==8) {	/* damping */
					base->object->damping= ob->damping;
					base->object->rdamping= ob->rdamping;
				}
				else if (event==11) {	/* all physical attributes */
					base->object->gameflag = ob->gameflag;
					base->object->inertia = ob->inertia;
					base->object->formfactor = ob->formfactor;
					base->object->damping= ob->damping;
					base->object->rdamping= ob->rdamping;
					base->object->min_vel= ob->min_vel;
					base->object->max_vel= ob->max_vel;
					if (ob->gameflag & OB_BOUNDS) {
						base->object->collision_boundtype = ob->collision_boundtype;
					}
					base->object->margin= ob->margin;
					base->object->bsoft= copy_bulletsoftbody(ob->bsoft);

				}
				else if (event==17) {	/* tex space */
					copy_texture_space(base->object, ob);
				}
				else if (event==18) {	/* font settings */
					
					if (base->object->type==ob->type) {
						cu= ob->data;
						cu1= base->object->data;
						
						cu1->spacemode= cu->spacemode;
						cu1->spacing= cu->spacing;
						cu1->linedist= cu->linedist;
						cu1->shear= cu->shear;
						cu1->fsize= cu->fsize;
						cu1->xof= cu->xof;
						cu1->yof= cu->yof;
						cu1->textoncurve= cu->textoncurve;
						cu1->wordspace= cu->wordspace;
						cu1->ulpos= cu->ulpos;
						cu1->ulheight= cu->ulheight;
						if (cu1->vfont) cu1->vfont->id.us--;
						cu1->vfont= cu->vfont;
						id_us_plus((ID *)cu1->vfont);
						if (cu1->vfontb) cu1->vfontb->id.us--;
						cu1->vfontb= cu->vfontb;
						id_us_plus((ID *)cu1->vfontb);
						if (cu1->vfonti) cu1->vfonti->id.us--;
						cu1->vfonti= cu->vfonti;
						id_us_plus((ID *)cu1->vfonti);
						if (cu1->vfontbi) cu1->vfontbi->id.us--;
						cu1->vfontbi= cu->vfontbi;
						id_us_plus((ID *)cu1->vfontbi);						

						BKE_text_to_curve(bmain, scene, base->object, 0); /* needed? */

						
						BLI_strncpy(cu1->family, cu->family, sizeof(cu1->family));
						
						base->object->recalc |= OB_RECALC_DATA;
					}
				}
				else if (event==19) {	/* bevel settings */
					
					if (ELEM(base->object->type, OB_CURVE, OB_FONT)) {
						cu= ob->data;
						cu1= base->object->data;
						
						cu1->bevobj= cu->bevobj;
						cu1->taperobj= cu->taperobj;
						cu1->width= cu->width;
						cu1->bevresol= cu->bevresol;
						cu1->ext1= cu->ext1;
						cu1->ext2= cu->ext2;
						
						base->object->recalc |= OB_RECALC_DATA;
					}
				}
				else if (event==25) {	/* curve resolution */

					if (ELEM(base->object->type, OB_CURVE, OB_FONT)) {
						cu= ob->data;
						cu1= base->object->data;
						
						cu1->resolu= cu->resolu;
						cu1->resolu_ren= cu->resolu_ren;
						
						nu= cu1->nurb.first;
						
						while (nu) {
							nu->resolu= cu1->resolu;
							nu= nu->next;
						}
						
						base->object->recalc |= OB_RECALC_DATA;
					}
				}
				else if (event==21) {
					if (base->object->type==OB_MESH) {
						ModifierData *md = modifiers_findByType(ob, eModifierType_Subsurf);

						if (md) {
							ModifierData *tmd = modifiers_findByType(base->object, eModifierType_Subsurf);

							if (!tmd) {
								tmd = modifier_new(eModifierType_Subsurf);
								BLI_addtail(&base->object->modifiers, tmd);
							}

							modifier_copyData(md, tmd);
							base->object->recalc |= OB_RECALC_DATA;
						}
					}
				}
				else if (event==22) {
					/* Copy the constraint channels over */
					copy_constraints(&base->object->constraints, &ob->constraints, TRUE);
					
					do_scene_sort= 1;
				}
				else if (event==23) {
					base->object->softflag= ob->softflag;
					if (base->object->soft) sbFree(base->object->soft);
					
					base->object->soft= copy_softbody(ob->soft);

					if (!modifiers_findByType(base->object, eModifierType_Softbody)) {
						BLI_addhead(&base->object->modifiers, modifier_new(eModifierType_Softbody));
					}
				}
				else if (event==26) {
#if 0 // XXX old animation system
					copy_nlastrips(&base->object->nlastrips, &ob->nlastrips);
#endif // XXX old animation system
				}
				else if (event==27) {	/* autosmooth */
					if (base->object->type==OB_MESH) {
						Mesh *me= ob->data;
						Mesh *cme= base->object->data;
						cme->smoothresh= me->smoothresh;
						if (me->flag & ME_AUTOSMOOTH)
							cme->flag |= ME_AUTOSMOOTH;
						else
							cme->flag &= ~ME_AUTOSMOOTH;
					}
				}
				else if (event==28) { /* UV orco */
					if (ELEM(base->object->type, OB_CURVE, OB_SURF)) {
						cu= ob->data;
						cu1= base->object->data;
						
						if (cu->flag & CU_UV_ORCO)
							cu1->flag |= CU_UV_ORCO;
						else
							cu1->flag &= ~CU_UV_ORCO;
					}		
				}
				else if (event==29) { /* protected bits */
					base->object->protectflag= ob->protectflag;
				}
				else if (event==30) { /* index object */
					base->object->index= ob->index;
				}
				else if (event==31) { /* object color */
					copy_v4_v4(base->object->col, ob->col);
				}
			}
		}
	}
	
	if (do_scene_sort)
		DAG_scene_sort(bmain, scene);

	DAG_ids_flush_update(bmain, 0);
}