void PresetInputs::resetMesh()
{
	assert ( x_mesh );
	assert ( y_mesh );
	assert ( rad_mesh );
	assert ( theta_mesh );

	copy_mesh(this->x_mesh, this->origx, gx, gy);
	copy_mesh(this->y_mesh, this->origy, gx, gy);
	copy_mesh(this->rad_mesh, this->origrad, gx, gy);
	copy_mesh(this->theta_mesh, this->origtheta, gx, gy);
}
示例#2
0
文件: mesh.c 项目: jinjoh/NOOR
void make_local_mesh(Mesh *me)
{
	Object *ob;
	Mesh *men;
	int local=0, lib=0;

	/* - only lib users: do nothing
	    * - only local users: set flag
	    * - mixed: make copy
	    */
	
	if(me->id.lib==0) return;
	if(me->id.us==1) {
		me->id.lib= 0;
		me->id.flag= LIB_LOCAL;
		new_id(0, (ID *)me, 0);
		
		if(me->mtface) make_local_tface(me);
		
		return;
	}
	
	ob= G.main->object.first;
	while(ob) {
		if( me==get_mesh(ob) ) {
			if(ob->id.lib) lib= 1;
			else local= 1;
		}
		ob= ob->id.next;
	}
	
	if(local && lib==0) {
		me->id.lib= 0;
		me->id.flag= LIB_LOCAL;
		new_id(0, (ID *)me, 0);
		
		if(me->mtface) make_local_tface(me);
		
	}
	else if(local && lib) {
		men= copy_mesh(me);
		men->id.us= 0;
		
		ob= G.main->object.first;
		while(ob) {
			if( me==get_mesh(ob) ) {				
				if(ob->id.lib==0) {
					set_mesh(ob, men);
				}
			}
			ob= ob->id.next;
		}
	}
}
示例#3
0
void make_local_mesh(Mesh *me)
{
	Main *bmain= G.main;
	Object *ob;
	int local=0, lib=0;

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

	if(me->id.lib==NULL) return;
	if(me->id.us==1) {
		me->id.lib= NULL;
		me->id.flag= LIB_LOCAL;

		new_id(&bmain->mesh, (ID *)me, NULL);
		expand_local_mesh(bmain, me);
		return;
	}

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

	if(local && lib==0) {
		me->id.lib= NULL;
		me->id.flag= LIB_LOCAL;

		new_id(&bmain->mesh, (ID *)me, NULL);
		expand_local_mesh(bmain, me);
	}
	else if(local && lib) {
		Mesh *men= copy_mesh(me);
		men->id.us= 0;

		for(ob= bmain->object.first; ob; ob= ob->id.next) {
			if(me == ob->data) {
				if(ob->id.lib==NULL) {
					set_mesh(ob, men);
				}
			}
		}
	}
}
示例#4
0
int id_copy(ID *id, ID **newid, int test)
{
	if(!test) *newid= NULL;

	/* conventions:
	 * - make shallow copy, only this ID block
	 * - id.us of the new ID is set to 1 */
	switch(GS(id->name)) {
		case ID_SCE:
			return 0; /* can't be copied from here */
		case ID_LI:
			return 0; /* can't be copied from here */
		case ID_OB:
			if(!test) *newid= (ID*)copy_object((Object*)id);
			return 1;
		case ID_ME:
			if(!test) *newid= (ID*)copy_mesh((Mesh*)id);
			return 1;
		case ID_CU:
			if(!test) *newid= (ID*)copy_curve((Curve*)id);
			return 1;
		case ID_MB:
			if(!test) *newid= (ID*)copy_mball((MetaBall*)id);
			return 1;
		case ID_MA:
			if(!test) *newid= (ID*)copy_material((Material*)id);
			return 1;
		case ID_TE:
			if(!test) *newid= (ID*)copy_texture((Tex*)id);
			return 1;
		case ID_IM:
			if(!test) *newid= (ID*)copy_image((Image*)id);
			return 1;
		case ID_LT:
			if(!test) *newid= (ID*)copy_lattice((Lattice*)id);
			return 1;
		case ID_LA:
			if(!test) *newid= (ID*)copy_lamp((Lamp*)id);
			return 1;
		case ID_SPK:
			if(!test) *newid= (ID*)copy_speaker((Speaker*)id);
			return 1;
		case ID_CA:
			if(!test) *newid= (ID*)copy_camera((Camera*)id);
			return 1;
		case ID_IP:
			return 0; /* deprecated */
		case ID_KE:
			if(!test) *newid= (ID*)copy_key((Key*)id);
			return 1;
		case ID_WO:
			if(!test) *newid= (ID*)copy_world((World*)id);
			return 1;
		case ID_SCR:
			return 0; /* can't be copied from here */
		case ID_VF:
			return 0; /* not implemented */
		case ID_TXT:
			if(!test) *newid= (ID*)copy_text((Text*)id);
			return 1;
		case ID_SCRIPT:
			return 0; /* deprecated */
		case ID_SO:
			return 0; /* not implemented */
		case ID_GR:
			if(!test) *newid= (ID*)copy_group((Group*)id);
			return 1;
		case ID_AR:
			if(!test) *newid= (ID*)copy_armature((bArmature*)id);
			return 1;
		case ID_AC:
			if(!test) *newid= (ID*)copy_action((bAction*)id);
			return 1;
		case ID_NT:
			if(!test) *newid= (ID*)ntreeCopyTree((bNodeTree*)id);
			return 1;
		case ID_BR:
			if(!test) *newid= (ID*)copy_brush((Brush*)id);
			return 1;
		case ID_PA:
			if(!test) *newid= (ID*)psys_copy_settings((ParticleSettings*)id);
			return 1;
		case ID_WM:
			return 0; /* can't be copied from here */
		case ID_GD:
			return 0; /* not implemented */
	}
	
	return 0;
}
示例#5
0
/* This function merges a mesh from the current scene into another main
 * it does not convert */
RAS_MeshObject *KX_BlenderSceneConverter::ConvertMeshSpecial(KX_Scene* kx_scene, Main *maggie, const char *name)
{
	/* Find a mesh in the current main */
	ID *me= static_cast<ID *>(BLI_findstring(&m_maggie->mesh, name, offsetof(ID, name) + 2));
	
	if(me==NULL) {
		printf("Could not be found \"%s\"\n", name);
		return NULL;
	}
	
	/* Watch this!, if its used in the original scene can cause big troubles */
	if(me->us > 0) {
		printf("Mesh has a user \"%s\"\n", name);
		me = (ID*)copy_mesh((Mesh*)me);
		me->us--;
	}
	BLI_remlink(&m_maggie->mesh, me); /* even if we made the copy it needs to be removed */
	BLI_addtail(&maggie->mesh, me);

	
	/* Must copy the materials this uses else we cant free them */
	{
		Mesh *mesh= (Mesh *)me;
		
		/* ensure all materials are tagged */
		for(int i=0; i<mesh->totcol; i++)
			if(mesh->mat[i])
				mesh->mat[i]->id.flag &= ~LIB_DOIT;
		
		for(int i=0; i<mesh->totcol; i++)
		{
			Material *mat_old= mesh->mat[i];
			
			/* if its tagged its a replaced material */
			if(mat_old && (mat_old->id.flag & LIB_DOIT)==0)
			{
				Material *mat_old= mesh->mat[i];
				Material *mat_new= copy_material( mat_old );
				
				mat_new->id.flag |= LIB_DOIT;
				mat_old->id.us--;
				
				BLI_remlink(&m_maggie->mat, mat_new);
				BLI_addtail(&maggie->mat, mat_new);
				
				mesh->mat[i]= mat_new;
				
				/* the same material may be used twice */
				for(int j=i+1; j<mesh->totcol; j++)
				{
					if(mesh->mat[j]==mat_old)
					{
						mesh->mat[j]= mat_new;
						mat_new->id.us++;
						mat_old->id.us--;
					}
				}
			}
		}
	}
	
	RAS_MeshObject *meshobj = BL_ConvertMesh((Mesh *)me, NULL, kx_scene, this);
	kx_scene->GetLogicManager()->RegisterMeshName(meshobj->GetName(),meshobj);
	m_map_mesh_to_gamemesh.clear(); /* This is at runtime so no need to keep this, BL_ConvertMesh adds */
	return meshobj;
}
示例#6
0
/* settings: 0 - preview, 1 - render */
Mesh *rna_Object_to_mesh(Object *ob, ReportList *reports, Scene *sce, int apply_modifiers, int settings)
{
	Mesh *tmpmesh;
	Curve *tmpcu = NULL;
	Object *tmpobj = NULL;
	int render = settings == eModifierMode_Render, i;
	int cage = !apply_modifiers;

	/* perform the mesh extraction based on type */
	switch (ob->type) {
	case OB_FONT:
	case OB_CURVE:
	case OB_SURF:

		/* copies object and modifiers (but not the data) */
		tmpobj= copy_object(ob);
		tmpcu = (Curve *)tmpobj->data;
		tmpcu->id.us--;

		/* if getting the original caged mesh, delete object modifiers */
		if( cage )
			object_free_modifiers(tmpobj);

		/* copies the data */
		tmpobj->data = copy_curve( (Curve *) ob->data );

#if 0
		/* copy_curve() sets disp.first null, so currently not need */
		{
			Curve *cu;
			cu = (Curve *)tmpobj->data;
			if( cu->disp.first )
				MEM_freeN( cu->disp.first );
			cu->disp.first = NULL;
		}
	
#endif

		/* get updated display list, and convert to a mesh */
		makeDispListCurveTypes( sce, tmpobj, 0 );
		nurbs_to_mesh( tmpobj );
		
		/* nurbs_to_mesh changes the type to a mesh, check it worked */
		if (tmpobj->type != OB_MESH) {
			free_libblock_us( &(G.main->object), tmpobj );
			BKE_report(reports, RPT_ERROR, "cant convert curve to mesh. Does the curve have any segments?");
			return NULL;
		}
		tmpmesh = tmpobj->data;
		free_libblock_us( &G.main->object, tmpobj );
		break;

	case OB_MBALL: {
		/* metaballs don't have modifiers, so just convert to mesh */
		Object *basis_ob = find_basis_mball(sce, ob);
		/* todo, re-generatre for render-res */
		/* metaball_polygonize(scene, ob) */

		if(ob != basis_ob)
			return NULL; /* only do basis metaball */

		tmpmesh = add_mesh("Mesh");
			
		if(render) {
			ListBase disp = {NULL, NULL};
			makeDispListMBall_forRender(sce, ob, &disp);
			mball_to_mesh(&disp, tmpmesh);
			freedisplist(&disp);
		}
		else
			mball_to_mesh(&ob->disp, tmpmesh);
		break;

	}
	case OB_MESH:
		/* copies object and modifiers (but not the data) */
		if (cage) {
			/* copies the data */
			tmpmesh = copy_mesh( ob->data );
		/* if not getting the original caged mesh, get final derived mesh */
		} else {
			/* Make a dummy mesh, saves copying */
			DerivedMesh *dm;
			/* CustomDataMask mask = CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL; */
			CustomDataMask mask = CD_MASK_MESH; /* this seems more suitable, exporter,
												   for example, needs CD_MASK_MDEFORMVERT */
			
			/* Write the display mesh into the dummy mesh */
			if (render)
				dm = mesh_create_derived_render( sce, ob, mask );
			else
				dm = mesh_create_derived_view( sce, ob, mask );
			
			tmpmesh = add_mesh( "Mesh" );
			DM_to_mesh( dm, tmpmesh );
			dm->release( dm );
		}
		
		break;
	default:
		BKE_report(reports, RPT_ERROR, "Object does not have geometry data");
		return NULL;
	}

	/* Copy materials to new mesh */
	switch (ob->type) {
	case OB_SURF:
	case OB_FONT:
	case OB_CURVE:
		tmpmesh->totcol = tmpcu->totcol;		
		
		/* free old material list (if it exists) and adjust user counts */
		if( tmpcu->mat ) {
			for( i = tmpcu->totcol; i-- > 0; ) {
				/* are we an object material or data based? */

				tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : tmpcu->mat[i];

				if (tmpmesh->mat[i]) {
					tmpmesh->mat[i]->id.us++;
				}
			}
		}
		break;

#if 0
	/* Crashes when assigning the new material, not sure why */
	case OB_MBALL:
		tmpmb = (MetaBall *)ob->data;
		tmpmesh->totcol = tmpmb->totcol;
		
		/* free old material list (if it exists) and adjust user counts */
		if( tmpmb->mat ) {
			for( i = tmpmb->totcol; i-- > 0; ) {
				tmpmesh->mat[i] = tmpmb->mat[i]; /* CRASH HERE ??? */
				if (tmpmesh->mat[i]) {
					tmpmb->mat[i]->id.us++;
				}
			}
		}
		break;
#endif

	case OB_MESH:
		if (!cage) {
			Mesh *origmesh= ob->data;
			tmpmesh->flag= origmesh->flag;
			tmpmesh->mat = MEM_dupallocN(origmesh->mat);
			tmpmesh->totcol = origmesh->totcol;
			tmpmesh->smoothresh= origmesh->smoothresh;
			if( origmesh->mat ) {
				for( i = origmesh->totcol; i-- > 0; ) {
					/* are we an object material or data based? */
					tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : origmesh->mat[i];

					if (tmpmesh->mat[i]) {
						tmpmesh->mat[i]->id.us++;
					}
				}
			}
		}
		break;
	} /* end copy materials */

	/* we don't assign it to anything */
	tmpmesh->id.us--;
	
	/* make sure materials get updated in objects */
	test_object_materials( ( ID * ) tmpmesh );

	return tmpmesh;
}