Beispiel #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;
}
Beispiel #2
0
Tex *copy_texture(Tex *tex)
{
	Tex *texn;
	
	texn= copy_libblock(tex);
	if(texn->type==TEX_IMAGE) id_us_plus((ID *)texn->ima);
	else texn->ima= NULL;
	
	if(texn->plugin) {
		texn->plugin= MEM_dupallocN(texn->plugin);
		open_plugin_tex(texn->plugin);
	}
	
	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(tex->preview) texn->preview = BKE_previewimg_copy(tex->preview);

	if(tex->nodetree) {
		ntreeEndExecTree(tex->nodetree);
		texn->nodetree= ntreeCopyTree(tex->nodetree); 
	}
	
	return texn;
}
Beispiel #3
0
Lamp *copy_lamp(Lamp *la)
{
	Lamp *lan;
	int a;
	
	lan= copy_libblock(&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;
}
Beispiel #4
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;
}
Beispiel #5
0
/** Duplicate preview image from \a id and clear icon_id, to be used by datablock copy functions. */
void BKE_previewimg_id_copy(ID *new_id, ID *old_id)
{
	PreviewImage **old_prv_p = BKE_previewimg_id_get_p(old_id);
	PreviewImage **new_prv_p = BKE_previewimg_id_get_p(new_id);

	if (old_prv_p && *old_prv_p) {
		BLI_assert(new_prv_p != NULL && ELEM(*new_prv_p, NULL, *old_prv_p));
//		const int new_icon_id = get_next_free_id();

//		if (new_icon_id == 0) {
//			return;  /* Failure. */
//		}
		*new_prv_p = BKE_previewimg_copy(*old_prv_p);
		new_id->icon_id = (*new_prv_p)->icon_id = 0;
	}
}
Beispiel #6
0
World *copy_world(World *wrld)
{
	World *wrldn;
	int a;
	
	wrldn= copy_libblock(wrld);
	
	for(a=0; a<MAX_MTEX; a++) {
		if(wrld->mtex[a]) {
			wrldn->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial");
			memcpy(wrldn->mtex[a], wrld->mtex[a], sizeof(MTex));
			id_us_plus((ID *)wrldn->mtex[a]->tex);
		}
	}
	
	if (wrld->preview) wrldn->preview = BKE_previewimg_copy(wrld->preview);

#if 0 // XXX old animation system
	id_us_plus((ID *)wrldn->ipo);
#endif // XXX old animation system
	
	return wrldn;
}
PreviewImage *UI_icon_to_preview(int icon_id)
{
	Icon *icon = BKE_icon_get(icon_id);
	
	if (icon) {
		DrawInfo *di = (DrawInfo *)icon->drawinfo;
		if (di) {
			if (di->type == ICON_TYPE_PREVIEW) {
				PreviewImage *prv = (icon->type != 0) ? BKE_previewimg_id_ensure((ID *)icon->obj) : icon->obj;

				if (prv) {
					return BKE_previewimg_copy(prv);
				}
			}
			else if (di->data.buffer.image) {
				ImBuf *bbuf;

				bbuf = IMB_ibImageFromMemory(di->data.buffer.image->datatoc_rect, di->data.buffer.image->datatoc_size,
				                             IB_rect, NULL, __func__);
				if (bbuf) {
					PreviewImage *prv = BKE_previewimg_create();

					prv->rect[0] = bbuf->rect;

					prv->w[0] = bbuf->x;
					prv->h[0] = bbuf->y;

					bbuf->rect = NULL;
					IMB_freeImBuf(bbuf);

					return prv;
				}
			}
		}
	}
	return NULL;
}
Beispiel #8
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;
}
Beispiel #9
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;
}