33 bpy_bm_utils_vert_collapse_edge_doc,
34 ".. function:: vert_collapse_edge(vert, edge)\n"
36 " Collapse a vertex into an edge.\n"
38 " :param vert: The vert that will be collapsed.\n"
39 " :type vert: :class:`bmesh.types.BMVert`\n"
40 " :param edge: The edge to collapse into.\n"
41 " :type edge: :class:`bmesh.types.BMEdge`\n"
42 " :return: The resulting edge from the collapse operation.\n"
43 " :rtype: :class:`bmesh.types.BMEdge`\n");
52 if (!PyArg_ParseTuple(args,
55 ":vert_collapse_edge",
68 if (!(py_edge->
e->
v1 == py_vert->
v || py_edge->
e->
v2 == py_vert->
v)) {
69 PyErr_SetString(PyExc_ValueError,
70 "vert_collapse_edge(vert, edge): the vertex is not found in the edge");
75 PyErr_SetString(PyExc_ValueError,
76 "vert_collapse_edge(vert, edge): vert has more than 2 connected edges");
88 PyErr_SetString(PyExc_ValueError,
89 "vert_collapse_edge(vert, edge): no new edge created, internal error");
95 bpy_bm_utils_vert_collapse_faces_doc,
96 ".. function:: vert_collapse_faces(vert, edge, fac, join_faces)\n"
98 " Collapses a vertex that has only two manifold edges onto a vertex it shares an "
101 " :param vert: The vert that will be collapsed.\n"
102 " :type vert: :class:`bmesh.types.BMVert`\n"
103 " :param edge: The edge to collapse into.\n"
104 " :type edge: :class:`bmesh.types.BMEdge`\n"
105 " :param fac: The factor to use when merging customdata [0 - 1].\n"
106 " :type fac: float\n"
107 " :param join_faces: When true the faces around the vertex will be joined otherwise "
108 "collapse the vertex by merging the 2 edges this vertex connects to into one.\n"
109 " :type join_faces: bool\n"
110 " :return: The resulting edge from the collapse operation.\n"
111 " :rtype: :class:`bmesh.types.BMEdge`\n");
123 if (!PyArg_ParseTuple(args,
128 ":vert_collapse_faces",
143 if (!(py_edge->
e->
v1 == py_vert->
v || py_edge->
e->
v2 == py_vert->
v)) {
144 PyErr_SetString(PyExc_ValueError,
145 "vert_collapse_faces(vert, edge): the vertex is not found in the edge");
150 PyErr_SetString(PyExc_ValueError,
151 "vert_collapse_faces(vert, edge): vert has more than 2 connected edges");
158 bm, py_edge->
e, py_vert->
v,
clamp_f(fac, 0.0f, 1.0f),
true, do_join_faces,
true,
true);
164 PyErr_SetString(PyExc_ValueError,
165 "vert_collapse_faces(vert, edge): no new edge created, internal error");
171 bpy_bm_utils_vert_dissolve_doc,
172 ".. function:: vert_dissolve(vert)\n"
174 " Dissolve this vertex (will be removed).\n"
176 " :param vert: The vert to be dissolved.\n"
177 " :type vert: :class:`bmesh.types.BMVert`\n"
178 " :return: True when the vertex dissolve is successful.\n"
186 if (!PyArg_ParseTuple(args,
204 bpy_bm_utils_vert_splice_doc,
205 ".. function:: vert_splice(vert, vert_target)\n"
207 " Splice vert into vert_target, merging them.\n"
209 " :param vert: The vertex to be removed.\n"
210 " :type vert: :class:`bmesh.types.BMVert`\n"
211 " :param vert_target: The vertex to merge into.\n"
212 " :type vert_target: :class:`bmesh.types.BMVert`\n"
214 " .. note:: The verts mustn't share an edge or face.\n");
217 const char *error_prefix =
"vert_splice(...)";
225 if (!PyArg_ParseTuple(args,
243 if (py_vert->
v == py_vert_target->
v) {
244 PyErr_Format(PyExc_ValueError,
"%s: vert arguments match", error_prefix);
249 PyErr_Format(PyExc_ValueError,
"%s: verts cannot share an edge", error_prefix);
254 PyErr_Format(PyExc_ValueError,
"%s: verts cannot share a face", error_prefix);
268 bpy_bm_utils_vert_separate_doc,
269 ".. function:: vert_separate(vert, edges)\n"
271 " Separate this vertex at every edge.\n"
273 " :param vert: The vert to be separated.\n"
274 " :type vert: :class:`bmesh.types.BMVert`\n"
275 " :param edges: The edges to separate.\n"
276 " :type edges: Sequence[:class:`bmesh.types.BMEdge`]\n"
277 " :return: The newly separated verts (including the vertex passed).\n"
278 " :rtype: tuple[:class:`bmesh.types.BMVert`, ...]\n");
281 const char *error_prefix =
"vert_separate(...)";
291 if (!PyArg_ParseTuple(args,
307 Py_ssize_t edge_array_num;
309 &
bm, edge_seq, 0, PY_SSIZE_T_MAX, &edge_array_num,
true,
true, error_prefix);
311 if (edge_array ==
nullptr) {
320 PyMem_FREE(edge_array);
327 bpy_bm_utils_edge_split_doc,
328 ".. function:: edge_split(edge, vert, fac)\n"
330 " Split an edge, return the newly created data.\n"
332 " :param edge: The edge to split.\n"
333 " :type edge: :class:`bmesh.types.BMEdge`\n"
334 " :param vert: One of the verts on the edge, defines the split direction.\n"
335 " :type vert: :class:`bmesh.types.BMVert`\n"
336 " :param fac: The point on the edge where the new vert will be created [0 - 1].\n"
337 " :type fac: float\n"
338 " :return: The newly created (edge, vert) pair.\n"
339 " :rtype: tuple[:class:`bmesh.types.BMEdge`, :class:`bmesh.types.BMVert`]\n");
350 if (!PyArg_ParseTuple(args,
368 if (!(py_edge->
e->
v1 == py_vert->
v || py_edge->
e->
v2 == py_vert->
v)) {
369 PyErr_SetString(PyExc_ValueError,
370 "edge_split(edge, vert): the vertex is not found in the edge");
378 if (v_new && e_new) {
379 PyObject *
ret = PyTuple_New(2);
385 PyErr_SetString(PyExc_ValueError,
386 "edge_split(edge, vert): couldn't split the edge, internal error");
392 bpy_bm_utils_edge_rotate_doc,
393 ".. function:: edge_rotate(edge, ccw=False)\n"
395 " Rotate the edge and return the newly created edge.\n"
396 " If rotating the edge fails, None will be returned.\n"
398 " :param edge: The edge to rotate.\n"
399 " :type edge: :class:`bmesh.types.BMEdge`\n"
400 " :param ccw: When True the edge will be rotated counter clockwise.\n"
402 " :return: The newly rotated edge.\n"
403 " :rtype: :class:`bmesh.types.BMEdge` | None\n");
412 if (!PyArg_ParseTuple(args,
440 bpy_bm_utils_face_split_doc,
441 ".. function:: face_split(face, vert_a, vert_b, *, coords=(), use_exist=True, source=None)\n"
443 " Face split with optional intermediate points.\n"
445 " :param face: The face to cut.\n"
446 " :type face: :class:`bmesh.types.BMFace`\n"
447 " :param vert_a: First vertex to cut in the face (face must contain the vert).\n"
448 " :type vert_a: :class:`bmesh.types.BMVert`\n"
449 " :param vert_b: Second vertex to cut in the face (face must contain the vert).\n"
450 " :type vert_b: :class:`bmesh.types.BMVert`\n"
451 " :param coords: Optional sequence of 3D points in between *vert_a* and *vert_b*.\n"
452 " :type coords: Sequence[Sequence[float]]\n"
453 " :param use_exist: Use an existing edge if it exists (only used when *coords* argument is "
454 "empty or omitted)\n"
455 " :type use_exist: bool\n"
456 " :param source: Newly created edge will copy settings from this one.\n"
457 " :type source: :class:`bmesh.types.BMEdge` | None\n"
458 " :return: The newly created face and loop.\n"
459 " :rtype: tuple[:class:`bmesh.types.BMFace`, :class:`bmesh.types.BMLoop`]\n");
462 const char *error_prefix =
"face_split(...)";
469 PyObject *py_coords =
nullptr;
470 bool edge_exists =
true;
482 static const char *_keywords[] = {
483 "face",
"vert_a",
"vert_b",
"coords",
"use_exist",
"source",
nullptr};
484 static _PyArg_Parser _parser = {
496 if (!_PyArg_ParseTupleAndKeywordsFast(args,
509 &py_edge_source_or_none))
518 if (py_edge_source) {
532 PyExc_ValueError,
"%s: one of the verts passed is not found in the face", error_prefix);
536 if (py_vert_a->
v == py_vert_b->
v) {
537 PyErr_Format(PyExc_ValueError,
"%s: vert arguments must differ", error_prefix);
549 PyErr_Format(PyExc_ValueError,
"%s: verts are adjacent in the face", error_prefix);
562 (
float (*)[3])coords,
565 py_edge_source ? py_edge_source->
e :
nullptr);
574 py_edge_source ? py_edge_source->
e :
nullptr,
578 if (f_new && l_new) {
579 PyObject *
ret = PyTuple_New(2);
585 PyErr_Format(PyExc_ValueError,
"%s: couldn't split the face, internal error", error_prefix);
591 bpy_bm_utils_face_split_edgenet_doc,
592 ".. function:: face_split_edgenet(face, edgenet)\n"
594 " Splits a face into any number of regions defined by an edgenet.\n"
596 " :param face: The face to split.\n"
597 " :type face: :class:`bmesh.types.BMFace`\n"
598 " :param edgenet: Sequence of edges.\n"
599 " :type edgenet: Sequence[:class:`bmesh.types.BMEdge`]\n"
600 " :return: The newly created faces.\n"
601 " :rtype: tuple[:class:`bmesh.types.BMFace`, ...]\n"
605 " Regions defined by edges need to connect to the face, otherwise they're "
606 "ignored as loose edges.\n");
609 const char *error_prefix =
"face_split_edgenet(...)";
610 static const char *kwlist[] = {
"face",
"edgenet",
nullptr};
619 if (!PyArg_ParseTupleAndKeywords(args,
623 ":face_split_edgenet",
624 const_cast<char **
>(kwlist),
636 Py_ssize_t edge_array_num;
638 &
bm, edge_seq, 1, PY_SSIZE_T_MAX, &edge_array_num,
true,
true, error_prefix);
640 if (edge_array ==
nullptr) {
648 PyMem_FREE(edge_array);
655 PyErr_SetString(PyExc_ValueError,
656 "face_split_edgenet(...): couldn't split the face, internal error");
662 bpy_bm_utils_face_join_doc,
663 ".. function:: face_join(faces, remove=True)\n"
665 " Joins a sequence of faces.\n"
667 " :param faces: Sequence of faces.\n"
668 " :type faces: Sequence[:class:`bmesh.types.BMFace`]\n"
669 " :param remove: Remove the edges and vertices between the faces.\n"
670 " :type remove: bool\n"
671 " :return: The newly created face or None on failure.\n"
672 " :rtype: :class:`bmesh.types.BMFace` | None\n");
675 const char *error_prefix =
"face_join(...)";
677 PyObject *py_face_array;
679 bool do_remove =
true;
681 if (!PyArg_ParseTuple(args,
693 Py_ssize_t face_seq_len = 0;
695 &
bm, py_face_array, 2, PY_SSIZE_T_MAX, &face_seq_len,
true,
true, error_prefix);
696 if (face_array ==
nullptr) {
703 f_new =
BM_faces_join(
bm, face_array,
int(face_seq_len), do_remove, &f_double);
706 "Doubled face detected at " AT ". Resulting mesh may be corrupt.");
708 PyMem_FREE(face_array);
719 bpy_bm_utils_face_vert_separate_doc,
720 ".. function:: face_vert_separate(face, vert)\n"
722 " Rip a vertex in a face away and add a new vertex.\n"
724 " :param face: The face to separate.\n"
725 " :type face: :class:`bmesh.types.BMFace`\n"
726 " :param vert: A vertex in the face to separate.\n"
727 " :type vert: :class:`bmesh.types.BMVert`\n"
728 " :return: The newly created vertex or None on failure.\n"
729 " :rtype: :class:`bmesh.types.BMVert` | None\n"
733 " This is the same as loop_separate, and has only been added for convenience.\n");
736 const char *error_prefix =
"face_vert_separate()";
744 if (!PyArg_ParseTuple(args,
747 ":face_vert_separate",
764 PyErr_Format(PyExc_ValueError,
"%s: vertex not found in face", error_prefix);
771 if (v_new != v_old) {
780 bpy_bm_utils_face_flip_doc,
781 ".. function:: face_flip(face)\n"
783 " Flip the face's direction.\n"
785 " :param face: Face to flip.\n"
786 " :type face: :class:`bmesh.types.BMFace`\n");
790 PyErr_Format(PyExc_TypeError,
791 "face_flip(face): BMFace expected, not '%.200s'",
792 Py_TYPE(value)->tp_name);
805 bpy_bm_utils_loop_separate_doc,
806 ".. function:: loop_separate(loop)\n"
808 " Rip a vertex in a face away and add a new vertex.\n"
810 " :param loop: The loop to separate.\n"
811 " :type loop: :class:`bmesh.types.BMLoop`\n"
812 " :return: The newly created vertex or None on failure.\n"
813 " :rtype: :class:`bmesh.types.BMVert` | None\n");
821 PyErr_Format(PyExc_TypeError,
822 "loop_separate(loop): BMLoop expected, not '%.200s'",
823 Py_TYPE(value)->tp_name);
835 if (v_new != v_old) {
844 bpy_bm_utils_uv_select_check_doc,
845 ".. function:: uv_select_check(bm, /, *, sync=True, flush=False, contiguous=False)\n"
847 " Check UV selection state for consistency issues.\n"
849 " :param bm: The BMesh to check.\n"
850 " :type bm: :class:`bmesh.types.BMesh`\n"
851 " :param sync: Check the data is properly synchronized "
852 "between UV's and the underlying mesh. "
853 "Failure to synchronize with the mesh selection "
854 "may cause tools not to behave properly.\n"
855 " :type sync: bool\n"
856 " :param flush: Check the selection has been properly flushed between elements "
857 "(based on the current :attr:`bmesh.types.BMesh.select_mode`).\n"
858 " :type flush: bool\n"
859 " :param contiguous: Check connected UV's and edges have a matching selection state.\n"
860 " :type contiguous: bool\n"
861 " :return: An error dictionary or None when there are no errors found.\n"
862 " :rtype: dict[str, int] | None\n");
865 const char *error_prefix =
"uv_select_check(...)";
867 bool check_sync =
true;
868 bool check_contiguous =
false;
869 bool check_flush =
false;
871 static const char *_keywords[] = {
878 static _PyArg_Parser _parser = {
888 if (!_PyArg_ParseTupleAndKeywordsFast(args,
912 const int cd_loop_uv_offset = check_contiguous ?
915 if (check_contiguous) {
916 if (cd_loop_uv_offset == -1) {
917 PyErr_SetString(PyExc_ValueError,
"contiguous=True for a mesh without UV coordinates");
924 bm, cd_loop_uv_offset, check_sync, check_flush, check_contiguous, &info);
929 PyObject *
result = PyDict_New();
931#define DICT_ADD_INT_MEMBER(info_struct, member) \
933 PyObject *value = PyLong_FromLong(info_struct.member); \
934 PyDict_SetItemString(result, STRINGIFY(member), value); \
960 if (check_contiguous) {
966 if (check_flush && check_contiguous) {
973#undef DICT_ADD_INT_MEMBER
980# pragma clang diagnostic push
981# pragma clang diagnostic ignored "-Wcast-function-type"
983# pragma GCC diagnostic push
984# pragma GCC diagnostic ignored "-Wcast-function-type"
989 {
"vert_collapse_edge",
992 bpy_bm_utils_vert_collapse_edge_doc},
993 {
"vert_collapse_faces",
996 bpy_bm_utils_vert_collapse_faces_doc},
1000 bpy_bm_utils_vert_dissolve_doc},
1004 bpy_bm_utils_vert_splice_doc},
1008 bpy_bm_utils_vert_separate_doc},
1012 bpy_bm_utils_edge_split_doc},
1016 bpy_bm_utils_edge_rotate_doc},
1019 METH_VARARGS | METH_KEYWORDS,
1020 bpy_bm_utils_face_split_doc},
1021 {
"face_split_edgenet",
1023 METH_VARARGS | METH_KEYWORDS,
1024 bpy_bm_utils_face_split_edgenet_doc},
1028 bpy_bm_utils_face_join_doc},
1029 {
"face_vert_separate",
1032 bpy_bm_utils_face_vert_separate_doc},
1036 bpy_bm_utils_face_flip_doc},
1040 bpy_bm_utils_loop_separate_doc},
1043 METH_VARARGS | METH_KEYWORDS,
1044 bpy_bm_utils_uv_select_check_doc},
1045 {
nullptr,
nullptr, 0,
nullptr},
1050# pragma clang diagnostic pop
1052# pragma GCC diagnostic pop
1059 "This module provides bmesh utility functions for splitting, joining, "
1060 "and modifying mesh elements.");
1075 PyObject *submodule;
Read Blender memory allocation and freeing.
#define UNUSED_VARS_NDEBUG(...)
#define BLI_assert_msg(a, msg)
#define BPy_BMFace_Check(v)
#define BPY_BM_CHECK_OBJ(obj)
#define BPy_BMLoop_Check(v)
#define BPY_BM_CHECK_SOURCE_OBJ(bm, errmsg,...)
#define DICT_ADD_INT_MEMBER(info_struct, member)
#define BM_vert_edge_count_is_over(v, n)
int CustomData_get_offset(const CustomData *data, eCustomDataType type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static PyObject * bpy_bm_utils_face_flip(PyObject *, BPy_BMFace *value)
int PyC_ParseBool(PyObject *o, void *p)
static PyObject * bpy_bm_utils_face_join(PyObject *, PyObject *args)
void BM_face_normal_flip(BMesh *bm, BMFace *f)
BLI_INLINE bool BM_loop_is_adjacent(const BMLoop *l_a, const BMLoop *l_b) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
BMEdge ** BPy_BMEdge_PySeq_As_Array(BMesh **r_bm, PyObject *seq, Py_ssize_t min, Py_ssize_t max, Py_ssize_t *r_seq_num, bool do_unique_check, bool do_bm_check, const char *error_prefix)
bool BM_mesh_uvselect_is_valid(BMesh *bm, const int cd_loop_uv_offset, const bool check_sync, const bool check_flush, const bool check_contiguous, UVSelectValidateInfo *info_p)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
PyTypeObject BPy_BMVert_Type
PyObject * BPy_BMLoop_CreatePyObject(BMesh *bm, BMLoop *l)
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
static PyObject * bpy_bm_utils_vert_separate(PyObject *, PyObject *args)
static PyObject * bpy_bm_utils_vert_splice(PyObject *, PyObject *args)
BMFace * BM_faces_join(BMesh *bm, BMFace **faces, int totface, const bool do_del, BMFace **r_double)
Join Connected Faces.
void BM_vert_separate(BMesh *bm, BMVert *v, BMEdge **e_in, int e_in_len, const bool copy_select, BMVert ***r_vout, int *r_vout_len)
PyTypeObject BPy_BMFace_Type
PyTypeObject BPy_BMesh_Type
static PyObject * bpy_bm_utils_uv_select_check(PyObject *, PyObject *args, PyObject *kwds)
BMEdge * BM_edge_rotate(BMesh *bm, BMEdge *e, const bool ccw, const short check_flag)
Rotate Edge.
static PyObject * bpy_bm_utils_loop_separate(PyObject *, BPy_BMLoop *value)
static PyMethodDef BPy_BM_utils_methods[]
static PyModuleDef BPy_BM_utils_module_def
ATTR_WARN_UNUSED_RESULT const BMLoop * l_b
bool BM_vert_pair_share_face_check(BMVert *v_a, BMVert *v_b)
static PyObject * bpy_bm_utils_face_split_edgenet(PyObject *, PyObject *args, PyObject *kw)
bool BM_vert_splice(BMesh *bm, BMVert *v_dst, BMVert *v_src)
Splice Vert.
PyObject * BPy_BMVert_CreatePyObject(BMesh *bm, BMVert *v)
BMVert * BM_face_loop_separate(BMesh *bm, BMLoop *l_sep)
Rip a single face from a vertex fan.
BMFace * BM_face_split_n(BMesh *bm, BMFace *f, BMLoop *l_a, BMLoop *l_b, float cos[][3], int n, BMLoop **r_l, BMEdge *example)
Face Split with intermediate points.
static PyObject * bpy_bm_utils_vert_collapse_faces(PyObject *, PyObject *args)
BMEdge * BM_vert_collapse_edge(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, const bool do_del, const bool kill_degenerate_faces, const bool kill_duplicate_faces)
Vert Collapse Faces.
static PyObject * bpy_bm_utils_face_split(PyObject *, PyObject *args, PyObject *kw)
BMEdge * BM_edge_exists(BMVert *v_a, BMVert *v_b)
static PyObject * bpy_bm_utils_vert_dissolve(PyObject *, PyObject *args)
bool BM_vert_dissolve(BMesh *bm, BMVert *v)
Dissolve Vert.
BMVert * BM_edge_split(BMesh *bm, BMEdge *e, BMVert *v, BMEdge **r_e, float fac)
Edge Split.
PyObject * BPy_BMFace_Array_As_Tuple(BMesh *bm, BMFace **elem, Py_ssize_t elem_num)
BMEdge * BM_vert_collapse_faces(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, float fac, const bool do_del, const bool join_faces, const bool kill_degenerate_faces, const bool kill_duplicate_faces)
Vert Collapse Faces.
static PyObject * bpy_bm_utils_face_vert_separate(PyObject *, PyObject *args)
BMFace * BM_face_split(BMesh *bm, BMFace *f, BMLoop *l_a, BMLoop *l_b, BMLoop **r_l, BMEdge *example, const bool no_double)
Face Split.
bool BM_face_split_edgenet(BMesh *bm, BMFace *f, BMEdge **edge_net, const int edge_net_len, Vector< BMFace * > *r_face_arr)
static PyObject * bpy_bm_utils_edge_split(PyObject *, PyObject *args)
BMLoop * BM_face_vert_share_loop(BMFace *f, BMVert *v)
Return the Loop Shared by Face and Vertex.
PyObject * BPy_BMVert_Array_As_Tuple(BMesh *bm, BMVert **elem, Py_ssize_t elem_num)
static PyObject * bpy_bm_utils_edge_rotate(PyObject *, PyObject *args)
int bpy_bm_check_uv_select_sync_valid(BMesh *bm, const char *error_prefix)
PyTypeObject BPy_BMEdge_Type
BMFace ** BPy_BMFace_PySeq_As_Array(BMesh **r_bm, PyObject *seq, Py_ssize_t min, Py_ssize_t max, Py_ssize_t *r_seq_num, bool do_unique_check, bool do_bm_check, const char *error_prefix)
int PyC_ParseTypeOrNone(PyObject *o, void *p)
int mathutils_array_parse_alloc_v(float **array, int array_dim, PyObject *value, const char *error_prefix)
MINLINE float clamp_f(float value, float min, float max)
static PyObject * bpy_bm_utils_vert_collapse_edge(PyObject *, PyObject *args)
PyObject * BPyInit_bmesh_utils()
PyObject * BPy_BMEdge_CreatePyObject(BMesh *bm, BMEdge *e)
PyObject * BPy_BMFace_CreatePyObject(BMesh *bm, BMFace *f)
#define PyC_TYPE_OR_NONE_INIT(py_type, value_p)
header-only compatibility defines.
#define PyTuple_SET_ITEMS(op_arg,...)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
UVSelectValidateInfo_Contiguous contiguous
UVSelectValidateInfo_Sync sync
UVSelectValidateInfo_Flush flush
UVSelectValidateInfo_FlushAndContiguous flush_contiguous