Exemple #1
0
/* converts a cddm to a BMEditMesh.  if existing is non-NULL, the
 * new geometry will be put in there.*/
BMEditMesh *DM_to_editbmesh(DerivedMesh *dm, BMEditMesh *existing, const bool do_tessellate)
{
	BMEditMesh *em = existing;
	BMesh *bm;

	if (em) {
		bm = em->bm;
	}
	else {
		bm = BM_mesh_create(&bm_mesh_allocsize_default);
	}

	DM_to_bmesh_ex(dm, bm, do_tessellate);

	if (!em) {
		em = BKE_editmesh_create(bm, do_tessellate);
	}
	else {
		if (do_tessellate) {
			BKE_editmesh_tessface_calc(em);
		}
	}

	return em;
}
Exemple #2
0
BMEditMesh *BKE_editmesh_create(BMesh *bm, const bool do_tessellate)
{
	BMEditMesh *em = MEM_callocN(sizeof(BMEditMesh), __func__);

	em->bm = bm;
	if (do_tessellate) {
		BKE_editmesh_tessface_calc(em);
	}

	return em;
}
Exemple #3
0
void EDBM_redo_state_restore(BMBackup backup, BMEditMesh *em, int recalctess)
{
	BMesh *tmpbm;
	if (!em || !backup.bmcopy) {
		return;
	}

	BM_mesh_data_free(em->bm);
	tmpbm = BM_mesh_copy(backup.bmcopy);
	*em->bm = *tmpbm;
	MEM_freeN(tmpbm);
	tmpbm = NULL;

	if (recalctess) {
		BKE_editmesh_tessface_calc(em);
	}
}
Exemple #4
0
void EDBM_redo_state_free(BMBackup *backup, BMEditMesh *em, int recalctess)
{
	if (em && backup->bmcopy) {
		BM_mesh_data_free(em->bm);
		*em->bm = *backup->bmcopy;
	}
	else if (backup->bmcopy) {
		BM_mesh_data_free(backup->bmcopy);
	}

	if (backup->bmcopy) {
		MEM_freeN(backup->bmcopy);
	}
	backup->bmcopy = NULL;

	if (recalctess && em) {
		BKE_editmesh_tessface_calc(em);
	}
}
Exemple #5
0
/* returns 0 on error, 1 on success.  executes and finishes a bmesh operator */
bool EDBM_op_finish(BMEditMesh *em, BMOperator *bmop, wmOperator *op, const bool do_report)
{
	const char *errmsg;

	BMO_op_finish(em->bm, bmop);

	if (BMO_error_get(em->bm, &errmsg, NULL)) {
		BMEditMesh *emcopy = em->emcopy;

		if (do_report) {
			BKE_report(op->reports, RPT_ERROR, errmsg);
		}

		EDBM_mesh_free(em);
		*em = *emcopy;

		MEM_freeN(emcopy);
		em->emcopyusers = 0;
		em->emcopy = NULL;

		/* when copying, tessellation isn't to for faster copying,
		 * but means we need to re-tessellate here */
		if (em->looptris == NULL) {
			BKE_editmesh_tessface_calc(em);
		}

		return false;
	}
	else {
		em->emcopyusers--;
		if (em->emcopyusers < 0) {
			printf("warning: em->emcopyusers was less than zero.\n");
		}

		if (em->emcopyusers <= 0) {
			BKE_editmesh_free(em->emcopy);
			MEM_freeN(em->emcopy);
			em->emcopy = NULL;
		}

		return true;
	}
}