コード例 #1
0
void set_current_material_texture(Material *ma, Tex *newtex)
{
	Tex *tex= NULL;
	bNode *node;
	
	if(ma && ma->use_nodes && ma->nodetree) {
		node= nodeGetActiveID(ma->nodetree, ID_TE);

		if(node) {
			tex= (Tex *)node->id;
			id_us_min(&tex->id);
			node->id= &newtex->id;
			id_us_plus(&newtex->id);
			ma= NULL;
		}
	}
	if(ma) {
		int act= (int)ma->texact;

		tex= (ma->mtex[act])? ma->mtex[act]->tex: NULL;
		id_us_min(&tex->id);

		if(newtex) {
			if(!ma->mtex[act])
				ma->mtex[act]= add_mtex();
			
			ma->mtex[act]->tex= newtex;
			id_us_plus(&newtex->id);
		}
		else if(ma->mtex[act]) {
			MEM_freeN(ma->mtex[act]);
			ma->mtex[act]= NULL;
		}
	}
}
コード例 #2
0
ファイル: sca.c プロジェクト: mgschwan/blensor
void free_actuator(bActuator *act)
{
	if (act->data) {
		switch (act->type) {
			case ACT_ACTION:
			case ACT_SHAPEACTION:
			{
				bActionActuator *aa = (bActionActuator *)act->data;
				if (aa->act)
					id_us_min((ID *)aa->act);
				break;
			}
			case ACT_SOUND:
			{
				bSoundActuator *sa = (bSoundActuator *) act->data;
				if (sa->sound)
					id_us_min((ID *)sa->sound);
				break;
			}
		}

		MEM_freeN(act->data);
	}
	MEM_freeN(act);
}
コード例 #3
0
bAction *rna_Main_actions_new(Main *UNUSED(bmain), const char *name)
{
	bAction *act= add_empty_action(name);
	id_us_min(&act->id);
	act->id.flag &= ~LIB_FAKEUSER;
	return act;
}
コード例 #4
0
Tex *rna_Main_textures_new(Main *UNUSED(bmain), const char *name, int type)
{
	Tex *tex= add_texture(name);
	tex_set_type(tex, type);
	id_us_min(&tex->id);
	return tex;
}
コード例 #5
0
Image *rna_Main_images_new(Main *UNUSED(bmain), const char *name, int width, int height, int alpha, int float_buffer)
{
	float color[4]= {0.0, 0.0, 0.0, 1.0};
	Image *image= BKE_add_image_size(width, height, name, alpha ? 32:24, float_buffer, 0, color);
	id_us_min(&image->id);
	return image;
}
コード例 #6
0
Lamp *rna_Main_lamps_new(Main *UNUSED(bmain), const char *name, int type)
{
	Lamp *lamp= add_lamp(name);
	lamp->type= type;
	id_us_min(&lamp->id);
	return lamp;
}
コード例 #7
0
struct bNodeTree *rna_Main_nodetree_new(Main *UNUSED(bmain), const char *name, int type)
{
	bNodeTree *tree = ntreeAddTree(name, type, NODE_GROUP);

	id_us_min(&tree->id);
	return tree;
}
コード例 #8
0
ファイル: brush.c プロジェクト: Rojuinex/Blender
/* not brush itself */
void BKE_brush_free(Brush *brush)
{
	id_us_min((ID *)brush->mtex.tex);
	id_us_min((ID *)brush->mask_mtex.tex);
	id_us_min((ID *)brush->paint_curve);

	if (brush->icon_imbuf)
		IMB_freeImBuf(brush->icon_imbuf);

	BKE_previewimg_free(&(brush->preview));

	curvemapping_free(brush->curve);

	if (brush->gradient)
		MEM_freeN(brush->gradient);
}
コード例 #9
0
ファイル: BL_ArmatureObject.cpp プロジェクト: diekev/blender
BL_ArmatureObject::BL_ArmatureObject(
				void* sgReplicationInfo, 
				SG_Callbacks callbacks, 
				Object *armature,
				Scene *scene,
				int vert_deform_type)

:	KX_GameObject(sgReplicationInfo,callbacks),
	m_controlledConstraints(),
	m_poseChannels(),
	m_scene(scene), // maybe remove later. needed for BKE_pose_where_is
	m_lastframe(0.0),
	m_timestep(0.040),
	m_vert_deform_type(vert_deform_type),
	m_constraintNumber(0),
	m_channelNumber(0),
	m_lastapplyframe(0.0)
{
	m_origObjArma = armature; // Keep a copy of the original armature so we can fix drivers later
	m_objArma = BKE_object_copy(G.main, armature);
	m_objArma->data = BKE_armature_copy(G.main, (bArmature *)armature->data);
	// During object replication ob->data is increase, we decrease it now because we get a copy.
	id_us_min(&((bArmature *)m_origObjArma->data)->id);
	m_pose = m_objArma->pose;
	// need this to get iTaSC working ok in the BGE
	m_pose->flag |= POSE_GAME_ENGINE;
	memcpy(m_obmat, m_objArma->obmat, sizeof(m_obmat));

	// The side-effect of this method registers this object as "animatable" with the KX_Scene.
	GetActionManager();
}
コード例 #10
0
ファイル: lamp.c プロジェクト: DrangPo/blender
void BKE_lamp_free(Lamp *la)
{
	MTex *mtex;
	int a;

	for (a = 0; a < MAX_MTEX; a++) {
		mtex = la->mtex[a];
		if (mtex && mtex->tex)
			id_us_min(&mtex->tex->id);
		if (mtex)
			MEM_freeN(mtex);
	}
	
	BKE_animdata_free((ID *)la);

	curvemapping_free(la->curfalloff);

	/* is no lib link block, but lamp extension */
	if (la->nodetree) {
		ntreeFreeTree(la->nodetree);
		MEM_freeN(la->nodetree);
	}
	
	BKE_previewimg_free(&la->preview);
	BKE_icon_id_delete(&la->id);
	la->id.icon_id = 0;
}
コード例 #11
0
static void freeData(ModifierData *md)
{
	DisplaceModifierData *dmd = (DisplaceModifierData *) md;
	if (dmd->texture) {
		id_us_min(&dmd->texture->id);
	}
}
コード例 #12
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;
}
コード例 #13
0
ファイル: brush.c プロジェクト: UPBGE/blender
int BKE_brush_texture_delete(Brush *brush)
{
	if (brush->mtex.tex)
		id_us_min(&brush->mtex.tex->id);

	return 1;
}
コード例 #14
0
ファイル: node_templates.c プロジェクト: mgschwan/blensor
static void node_remove_linked(bNodeTree *ntree, bNode *rem_node)
{
	bNode *node, *next;
	bNodeSocket *sock;

	if (!rem_node)
		return;

	/* tag linked nodes to be removed */
	for (node = ntree->nodes.first; node; node = node->next)
		node->flag &= ~NODE_TEST;

	node_tag_recursive(rem_node);

	/* clear tags on nodes that are still used by other nodes */
	for (node = ntree->nodes.first; node; node = node->next)
		if (!(node->flag & NODE_TEST))
			for (sock = node->inputs.first; sock; sock = sock->next)
				if (sock->link && sock->link->fromnode != rem_node)
					node_clear_recursive(sock->link->fromnode);

	/* remove nodes */
	for (node = ntree->nodes.first; node; node = next) {
		next = node->next;

		if (node->flag & NODE_TEST) {
			if (node->id)
				id_us_min(node->id);
			nodeFreeNode(ntree, node);
		}
	}
}
コード例 #15
0
ファイル: collection.c プロジェクト: wangyxuan/blender
/* Add new collection, without view layer syncing. */
static Collection *collection_add(Main *bmain,
                                  Collection *collection_parent,
                                  const char *name_custom)
{
  /* Determine new collection name. */
  char name[MAX_NAME];

  if (name_custom) {
    STRNCPY(name, name_custom);
  }
  else {
    BKE_collection_new_name_get(collection_parent, name);
  }

  /* Create new collection. */
  Collection *collection = BKE_libblock_alloc(bmain, ID_GR, name, 0);

  /* We increase collection user count when linking to Collections. */
  id_us_min(&collection->id);

  /* Optionally add to parent collection. */
  if (collection_parent) {
    collection_child_add(collection_parent, collection, 0, true);
  }

  return collection;
}
コード例 #16
0
static void freeData(ModifierData *md)
{
	WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) md;
	if (wmd->mask_texture) {
		id_us_min(&wmd->mask_texture->id);
	}
}
コード例 #17
0
static void freeData(ModifierData *md)
{
	WaveModifierData *wmd = (WaveModifierData *) md;
	if (wmd->texture) {
		id_us_min(&wmd->texture->id);
	}
}
コード例 #18
0
ファイル: paint_ops.c プロジェクト: mgschwan/blensor
static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool,
                                  const size_t tool_offset, const int ob_mode,
                                  const char *tool_name, const bool create_missing,
                                  const bool toggle)
{
	Brush *brush, *brush_orig = BKE_paint_brush(paint);

	if (toggle)
		brush = brush_tool_toggle(bmain, brush_orig, tool, tool_offset, ob_mode);
	else
		brush = brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);

	if (!brush && brush_tool(brush_orig, tool_offset) != tool && create_missing) {
		brush = BKE_brush_add(bmain, tool_name, ob_mode);
		id_us_min(&brush->id);  /* fake user only */
		brush_tool_set(brush, tool_offset, tool);
		brush->toggle_brush = brush_orig;
	}

	if (brush) {
		BKE_paint_brush_set(paint, brush);
		BKE_paint_invalidate_overlay_all();

		WM_main_add_notifier(NC_BRUSH | NA_EDITED, brush);
		return OPERATOR_FINISHED;
	}
	else {
		return OPERATOR_CANCELLED;
	}
}
コード例 #19
0
ファイル: paint.c プロジェクト: vanangamudi/blender-main
void paint_brush_set(Paint *p, Brush *br)
{
	if (p) {
		id_us_min((ID *)p->brush);
		id_us_plus((ID *)br);
		p->brush = br;
	}
}
コード例 #20
0
static void freeData(ModifierData *md)
{
	MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *) md;

	if (mcmd->cache_file) {
		id_us_min(&mcmd->cache_file->id);
	}
}
コード例 #21
0
static void freeData(ModifierData *md)
{
	WeightVGEditModifierData *wmd = (WeightVGEditModifierData *) md;
	curvemapping_free(wmd->cmap_curve);

	if (wmd->mask_texture) {
		id_us_min(&wmd->mask_texture->id);
	}
}
コード例 #22
0
static void unlink_world_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *tsep, TreeStoreElem *tselem)
{
	Scene *parscene = (Scene *)tsep->id;
	World *wo = (World *)tselem->id;
	
	/* need to use parent scene not just scene, otherwise may end up getting wrong one */
	id_us_min(&wo->id);
	parscene->world = NULL;
}
コード例 #23
0
static void id_fake_user_clear_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
{
	ID *id = tselem->id;
	
	if ((id) && (id->flag & LIB_FAKEUSER)) {
		id->flag &= ~LIB_FAKEUSER;
		id_us_min(id);
	}
}
コード例 #24
0
ファイル: texture.c プロジェクト: mgschwan/blensor
void set_current_material_texture(Material *ma, Tex *newtex)
{
	Tex *tex = NULL;
	bNode *node;

	if ((ma->use_nodes && ma->nodetree) &&
	    (node = nodeGetActiveID(ma->nodetree, ID_TE)))
	{
		tex = (Tex *)node->id;
		id_us_min(&tex->id);
		if (newtex) {
			node->id = &newtex->id;
			id_us_plus(&newtex->id);
		}
		else {
			node->id = NULL;
		}
	}
	else {
		int act = (int)ma->texact;

		tex = (ma->mtex[act]) ? ma->mtex[act]->tex : NULL;
		id_us_min(&tex->id);

		if (newtex) {
			if (!ma->mtex[act]) {
				ma->mtex[act] = BKE_texture_mtex_add();
				/* Reset this slot's ON/OFF toggle, for materials, when slot was empty. */
				ma->septex &= ~(1 << act);
				/* For volumes the default UV texture coordinates are not available. */
				if (ma->material_type == MA_TYPE_VOLUME) {
					ma->mtex[act]->texco = TEXCO_ORCO;
				}
			}
			
			ma->mtex[act]->tex = newtex;
			id_us_plus(&newtex->id);
		}
		else if (ma->mtex[act]) {
			MEM_freeN(ma->mtex[act]);
			ma->mtex[act] = NULL;
		}
	}
}
コード例 #25
0
ファイル: brush.c プロジェクト: UPBGE/blender
int BKE_brush_clone_image_delete(Brush *brush)
{
	if (brush && brush->clone.image) {
		id_us_min(&brush->clone.image->id);
		brush->clone.image = NULL;
		return 1;
	}

	return 0;
}
コード例 #26
0
void set_current_brush_texture(Brush *br, Tex *newtex)
{
	if (br->mtex.tex)
		id_us_min(&br->mtex.tex->id);

	if (newtex) {
		br->mtex.tex = newtex;
		id_us_plus(&newtex->id);
	}
}
コード例 #27
0
void MovieClip_grease_pencil_set(PointerRNA *ptr, PointerRNA value)
{
	MovieClip *data = (MovieClip *)(ptr->data);

	if (data->gpd)
		id_us_min((ID *)data->gpd);
	if (value.data)
		id_us_plus((ID *)value.data);

	data->gpd = value.data;
}
コード例 #28
0
ファイル: rna_ID.c プロジェクト: pawkoz/dyplom
static ID *rna_ID_copy(ID *id)
{
	ID *newid;

	if (id_copy(id, &newid, false)) {
		if (newid) id_us_min(newid);
		return newid;
	}
	
	return NULL;
}
コード例 #29
0
ファイル: paint_toolslots.c プロジェクト: dfelinto/blender
void BKE_paint_toolslots_brush_update_ex(Paint *paint, Brush *brush)
{
  const uint tool_offset = paint->runtime.tool_offset;
  UNUSED_VARS_NDEBUG(tool_offset);
  BLI_assert(tool_offset != 0);
  const int slot_index = BKE_brush_tool_get(brush, paint);
  BKE_paint_toolslots_len_ensure(paint, slot_index + 1);
  PaintToolSlot *tslot = &paint->tool_slots[slot_index];
  id_us_plus(&brush->id);
  id_us_min(&tslot->brush->id);
  tslot->brush = brush;
}
コード例 #30
0
Object *rna_Main_objects_new(Main *UNUSED(bmain), ReportList *reports, const char *name, ID *data)
{
	Object *ob;
	int type= OB_EMPTY;
	if(data) {
		switch(GS(data->name)) {
			case ID_ME:
				type= OB_MESH;
				break;
			case ID_CU:
				type= curve_type((struct Curve *)data);
				break;
			case ID_MB:
				type= OB_MBALL;
				break;
			case ID_LA:
				type= OB_LAMP;
				break;
			case ID_SPK:
				type= OB_SPEAKER;
				break;
			case ID_CA:
				type= OB_CAMERA;
				break;
			case ID_LT:
				type= OB_LATTICE;
				break;
			case ID_AR:
				type= OB_ARMATURE;
				break;
			default:
			{
				const char *idname;
				if(RNA_enum_id_from_value(id_type_items, GS(data->name), &idname) == 0)
					idname= "UNKNOWN";

				BKE_reportf(reports, RPT_ERROR, "ID type '%s' is not valid for a object.", idname);
				return NULL;
			}
		}

		id_us_plus(data);
	}

	ob= add_only_object(type, name);
	id_us_min(&ob->id);

	ob->data= data;
	test_object_materials(ob->data);
	
	return ob;
}