/**
 * \note doesn't actually check selection.
 */
int BPy_BMEditSel_Assign(BPy_BMesh *self, PyObject *value)
{
	BMesh *bm;
	Py_ssize_t value_len;
	Py_ssize_t i;
	BMElem **value_array = NULL;

	BPY_BM_CHECK_INT(self);

	bm = self->bm;

	value_array = BPy_BMElem_PySeq_As_Array(&bm, value, 0, PY_SSIZE_T_MAX,
	                                        &value_len, BM_VERT | BM_EDGE | BM_FACE,
	                                        TRUE, TRUE, "BMesh.select_history = value");

	if (value_array == NULL) {
		return -1;
	}

	BM_select_history_clear(bm);

	for (i = 0; i < value_len; i++) {
		BM_select_history_store_notest(bm, value_array[i]);
	}

	PyMem_FREE(value_array);
	return 0;
}
Esempio n. 2
0
static PyObject *bpy_bm_utils_face_join(PyObject *UNUSED(self), PyObject *args)
{
	BMesh *bm = NULL;
	PyObject *py_face_array;
	BMFace **face_array;
	Py_ssize_t face_seq_len = 0;
	BMFace *f_new;
	int do_remove = TRUE;

	if (!PyArg_ParseTuple(args, "O|i:face_join", &py_face_array, &do_remove)) {
		return NULL;
	}

	face_array = BPy_BMElem_PySeq_As_Array(&bm, py_face_array, 2, PY_SSIZE_T_MAX,
	                                       &face_seq_len, BM_FACE,
	                                       TRUE, TRUE, "face_join(...)");

	if (face_array == NULL) {
		return NULL; /* error will be set */
	}

	/* Go ahead and join the face!
	 * --------------------------- */
	f_new = BM_faces_join(bm, face_array, (int)face_seq_len, do_remove);

	PyMem_FREE(face_array);

	if (f_new) {
		return BPy_BMFace_CreatePyObject(bm, f_new);
	}
	else {
		Py_RETURN_NONE;
	}
}
static PyObject *bpy_bm_utils_face_split_edgenet(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
	static const char *kwlist[] = {"face", "edgenet", NULL};

	BPy_BMFace *py_face;
	PyObject *edge_seq;

	BMEdge **edge_array;
	Py_ssize_t edge_array_len;

	BMesh *bm;

	BMFace **face_arr;
	int face_arr_len;
	bool ok;


	if (!PyArg_ParseTupleAndKeywords(args, kw, "O!O:face_split_edgenet", (char **)kwlist,
	                                 &BPy_BMFace_Type, &py_face,
	                                 &edge_seq))
	{
		return NULL;
	}

	BPY_BM_CHECK_OBJ(py_face);

	bm = py_face->bm;

	edge_array = BPy_BMElem_PySeq_As_Array(&bm, edge_seq, 1, PY_SSIZE_T_MAX,
	                                       &edge_array_len, BM_EDGE,
	                                       true, true, "face_split_edgenet(...)");

	if (edge_array == NULL) {
		return NULL;
	}

	/* --- main function body --- */

	ok = BM_face_split_edgenet(bm, py_face->f, edge_array, edge_array_len,
	                           &face_arr, &face_arr_len);

	PyMem_FREE(edge_array);

	if (ok) {
		PyObject *ret = BPy_BMFace_Array_As_Tuple(bm, face_arr, face_arr_len);
		if (face_arr) {
			MEM_freeN(face_arr);
		}
		return ret;
	}
	else {
		PyErr_SetString(PyExc_ValueError,
		                "face_split_edgenet(...): couldn't split the face, internal error");
		return NULL;
	}
}
Esempio n. 4
0
static PyObject *bpy_bm_utils_vert_separate(PyObject *UNUSED(self), PyObject *args)
{
	BPy_BMVert *py_vert;
	PyObject *edge_seq;

	BMesh *bm;
	BMVert **elem;
	int elem_len;

	/* edges to split */
	BMEdge **edge_array;
	Py_ssize_t edge_array_len;

	PyObject *ret;


	if (!PyArg_ParseTuple(args, "O!O:vert_separate",
	                      &BPy_BMVert_Type, &py_vert,
	                      &edge_seq))
	{
		return NULL;
	}

	BPY_BM_CHECK_OBJ(py_vert);

	bm = py_vert->bm;

	edge_array = BPy_BMElem_PySeq_As_Array(&bm, edge_seq, 0, PY_SSIZE_T_MAX,
	                                       &edge_array_len, BM_EDGE,
	                                       TRUE, TRUE, "vert_separate(...)");

	if (edge_array == NULL) {
		return NULL;
	}

	if (BM_vert_separate(bm, py_vert->v, &elem, &elem_len, edge_array, edge_array_len)) {
		/* return collected verts */
		ret = BPy_BMElem_Array_As_Tuple(bm, (BMHeader **)elem, elem_len);
		MEM_freeN(elem);
	}
	else {
		ret = PyTuple_New(0);
	}

	PyMem_FREE(edge_array);

	return ret;
}