Blender V5.3
bmesh_py_types.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2012 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_array_utils.hh"
10#include "BLI_math_geom_c.hh"
11#include "BLI_math_matrix_c.hh"
12#include "BLI_math_vector_c.hh"
13#include "BLI_sort.hh"
14#include "BLI_string_utils.hh"
15
16#include "DNA_material_types.h"
17#include "DNA_mesh_types.h"
18#include "DNA_object_types.h"
19#include "DNA_scene_types.h"
20
21#include "BKE_customdata.hh"
22#include "BKE_global.hh"
23#include "BKE_lib_id.hh"
24#include "BKE_mesh.h"
25#include "BKE_mesh_runtime.hh"
26#include "BKE_mesh_types.hh"
27#include "BKE_object.hh"
28
29#include "DEG_depsgraph.hh"
31
32#include "bmesh.hh"
33
34#include <Python.h>
35
36#include "../generic/python_compat.hh" /* IWYU pragma: keep. */
37
39
42
43#include "bmesh_py_types.hh" /* own include */
47
48namespace blender {
49
50static void bm_dealloc_editmode_warn(BPy_BMesh *self);
51
52/* Common Flags
53 * ************ */
54
55/* scene does not use BM_* flags. */
57 {1, "VERT"},
58 {2, "EDGE"},
59 {4, "FACE"},
60 {0, nullptr},
61};
62
64 {BM_VERT, "VERT"},
65 {BM_EDGE, "EDGE"},
66 {BM_FACE, "FACE"},
67 {0, nullptr},
68};
69
71 {BM_VERT, "VERT"},
72 {BM_LOOP, "EDGE"},
73 {BM_FACE, "FACE"},
74 {BM_LOOP, "LOOP"},
75 {0, nullptr},
76};
77
79#define BPY_BM_HTYPE_NOLOOP "'VERT', 'EDGE', 'FACE'"
80
82#define BPY_BM_HFLAG_ALL_STR "'SELECT', 'HIDE', 'SEAM', 'SMOOTH', 'TAG'"
83
85 {BM_ELEM_SELECT, "SELECT"},
86 {BM_ELEM_HIDDEN, "HIDE"},
87 {BM_ELEM_SEAM, "SEAM"},
88 {BM_ELEM_SMOOTH, "SMOOTH"},
89 {BM_ELEM_TAG, "TAG"},
90 {0, nullptr},
91};
92
93/* This could/should be shared with `scene.toolsettings.uv_sticky_select_mode`.
94 * however it relies on using the RNA API. */
96 {UV_STICKY_LOCATION, "SHARED_LOCATION"},
97 {UV_STICKY_DISABLE, "DISABLED"},
98 {UV_STICKY_VERT, "SHARED_VERTEX"},
99 {0, nullptr},
100};
101
102/* py-type definitions
103 * ******************* */
104
105/* getseters
106 * ========= */
107
108/* bmesh elems
109 * ----------- */
110
112 /* Wrap. */
113 bpy_bm_elem_select_doc,
114 "Selected state of this element.\n"
115 "\n"
116 ":type: bool\n");
118 /* Wrap. */
119 bpy_bm_elem_hide_doc,
120 "Hidden state of this element.\n"
121 "\n"
122 ":type: bool\n");
124 /* Wrap. */
125 bpy_bm_elem_tag_doc,
126 "Generic attribute scripts can use for own logic\n"
127 "\n"
128 ":type: bool\n");
130 /* Wrap. */
131 bpy_bm_elem_smooth_doc,
132 "Smooth state of this element.\n"
133 "\n"
134 ":type: bool\n");
136 /* Wrap. */
137 bpy_bm_elem_seam_doc,
138 "Seam for UV unwrapping.\n"
139 "\n"
140 ":type: bool\n");
142 /* Wrap. */
143 bpy_bm_elem_uv_select_doc,
144 "UV selected state of this element.\n"
145 "\n"
146 ":type: bool\n");
148 /* Wrap. */
149 bpy_bm_elem_uv_select_vert_doc,
150 "UV vertex selected state of this loop.\n"
151 "\n"
152 ":type: bool\n");
154 /* Wrap. */
155 bpy_bm_elem_uv_select_edge_doc,
156 "UV edge selected state of this loop.\n"
157 "\n"
158 ":type: bool\n");
159
160static PyObject *bpy_bm_elem_hflag_get(BPy_BMElem *self, void *flag)
161{
162 const char hflag = char(POINTER_AS_INT(flag));
163
164 BPY_BM_CHECK_OBJ(self);
165
166 return PyBool_FromLong(BM_elem_flag_test(self->ele, hflag));
167}
168
169static int bpy_bm_elem_hflag_set(BPy_BMElem *self, PyObject *value, void *flag)
170{
171 const char hflag = char(POINTER_AS_INT(flag));
172 int param;
173
174 BPY_BM_CHECK_INT(self);
175
176 if ((param = PyC_Long_AsBool(value)) == -1) {
177 return -1;
178 }
179
180 if (hflag == BM_ELEM_SELECT) {
181 BM_elem_select_set(self->bm, self->ele, param);
182 }
183 else {
184 BM_elem_flag_set(self->ele, hflag, param);
185 }
186 return 0;
187}
188
190 /* Wrap. */
191 bpy_bm_elem_index_doc,
192 "Index of this element.\n"
193 "\n"
194 ":type: int\n"
195 "\n"
196 ".. note::\n"
197 "\n"
198 " This value is not necessarily valid, while editing the mesh it can become *dirty*.\n"
199 "\n"
200 " It's also possible to assign any number to this attribute for a scripts internal logic.\n"
201 "\n"
202 " To ensure the value is up to date - see :meth:`bmesh.types.BMElemSeq.index_update`.\n");
203static PyObject *bpy_bm_elem_index_get(BPy_BMElem *self, void * /*flag*/)
204{
205 BPY_BM_CHECK_OBJ(self);
206
207 return PyLong_FromLong(BM_elem_index_get(self->ele));
208}
209
210static int bpy_bm_elem_index_set(BPy_BMElem *self, PyObject *value, void * /*flag*/)
211{
212 int param;
213
214 BPY_BM_CHECK_INT(self);
215
216 if (((param = PyC_Long_AsI32(value)) == -1) && PyErr_Occurred()) {
217 /* error is set */
218 return -1;
219 }
220
221 BM_elem_index_set(self->ele, param); /* set_dirty! */
222
223 /* when setting the index assume its set invalid */
224 self->bm->elem_index_dirty |= self->ele->head.htype;
225
226 return 0;
227}
228
229/* type specific get/sets
230 * ---------------------- */
231
232/* Mesh
233 * ^^^^ */
234
235/* Docstrings for all uses of this function. */
236
238 /* Wrap. */
239 bpy_bmvertseq_doc,
240 "This mesh's vert sequence (read-only).\n"
241 "\n"
242 ":type: :class:`bmesh.types.BMVertSeq`\n");
243static PyObject *bpy_bmvertseq_get(BPy_BMesh *self, void * /*closure*/)
244{
245 BPY_BM_CHECK_OBJ(self);
246 return BPy_BMVertSeq_CreatePyObject(self->bm);
247}
248
250 /* Wrap. */
251 bpy_bmedgeseq_doc,
252 "This mesh's edge sequence (read-only).\n"
253 "\n"
254 ":type: :class:`bmesh.types.BMEdgeSeq`\n");
255static PyObject *bpy_bmedgeseq_get(BPy_BMesh *self, void * /*closure*/)
256{
257 BPY_BM_CHECK_OBJ(self);
258 return BPy_BMEdgeSeq_CreatePyObject(self->bm);
259}
260
262 /* Wrap. */
263 bpy_bmfaceseq_doc,
264 "This mesh's face sequence (read-only).\n"
265 "\n"
266 ":type: :class:`bmesh.types.BMFaceSeq`\n");
267static PyObject *bpy_bmfaceseq_get(BPy_BMesh *self, void * /*closure*/)
268{
269 BPY_BM_CHECK_OBJ(self);
270 return BPy_BMFaceSeq_CreatePyObject(self->bm);
271}
272
274 /* Wrap. */
275 bpy_bmloopseq_doc,
276 "This mesh's loops (read-only).\n"
277 "\n"
278 ":type: :class:`bmesh.types.BMLoopSeq`\n"
279 "\n"
280 ".. note::\n"
281 "\n"
282 " Loops must be accessed via faces, this is only exposed for layer access.\n");
283static PyObject *bpy_bmloopseq_get(BPy_BMesh *self, void * /*closure*/)
284{
285 BPY_BM_CHECK_OBJ(self);
286 return BPy_BMLoopSeq_CreatePyObject(self->bm);
287}
288
289/* vert */
291 /* Wrap. */
292 bpy_bmvert_link_edges_doc,
293 "Edges connected to this vertex (read-only).\n"
294 "\n"
295 ":type: :class:`bmesh.types.BMElemSeq`\\ [:class:`bmesh.types.BMEdge`]\n");
297 /* Wrap. */
298 bpy_bmvert_link_faces_doc,
299 "Faces connected to this vertex (read-only).\n"
300 "\n"
301 ":type: :class:`bmesh.types.BMElemSeq`\\ [:class:`bmesh.types.BMFace`]\n");
303 /* Wrap. */
304 bpy_bmvert_link_loops_doc,
305 "Loops that use this vertex (read-only).\n"
306 "\n"
307 ":type: :class:`bmesh.types.BMElemSeq`\\ [:class:`bmesh.types.BMLoop`]\n");
308/* edge */
310 /* Wrap. */
311 bpy_bmedge_verts_doc,
312 "Verts this edge uses (always 2), (read-only).\n"
313 "\n"
314 ":type: :class:`bmesh.types.BMElemSeq`\\ [:class:`bmesh.types.BMVert`]\n");
316 /* Wrap. */
317 bpy_bmedge_link_faces_doc,
318 "Faces connected to this edge, (read-only).\n"
319 "\n"
320 ":type: :class:`bmesh.types.BMElemSeq`\\ [:class:`bmesh.types.BMFace`]\n");
322 /* Wrap. */
323 bpy_bmedge_link_loops_doc,
324 "Loops connected to this edge, (read-only).\n"
325 "\n"
326 ":type: :class:`bmesh.types.BMElemSeq`\\ [:class:`bmesh.types.BMLoop`]\n");
327/* face */
329 /* Wrap. */
330 bpy_bmface_verts_doc,
331 "Verts of this face, (read-only).\n"
332 "\n"
333 ":type: :class:`bmesh.types.BMElemSeq`\\ [:class:`bmesh.types.BMVert`]\n");
335 /* Wrap. */
336 bpy_bmface_edges_doc,
337 "Edges of this face, (read-only).\n"
338 "\n"
339 ":type: :class:`bmesh.types.BMElemSeq`\\ [:class:`bmesh.types.BMEdge`]\n");
341 /* Wrap. */
342 bpy_bmface_loops_doc,
343 "Loops of this face, (read-only).\n"
344 "\n"
345 ":type: :class:`bmesh.types.BMElemSeq`\\ [:class:`bmesh.types.BMLoop`]\n");
346/* loop */
348 /* Wrap. */
349 bpy_bmloops_link_loops_doc,
350 "Loops connected to this loop, (read-only).\n"
351 "\n"
352 ":type: :class:`bmesh.types.BMElemSeq`\\ [:class:`bmesh.types.BMLoop`]\n");
353
354static PyObject *bpy_bmelemseq_elem_get(BPy_BMElem *self, void *itype)
355{
356 BPY_BM_CHECK_OBJ(self);
358}
359
361 /* Wrap. */
362 bpy_bm_is_valid_doc,
363 "True when this element is valid (hasn't been freed or removed).\n"
364 "\n"
365 ":type: bool\n");
366static PyObject *bpy_bm_is_valid_get(BPy_BMGeneric *self, void * /*closure*/)
367{
368 return PyBool_FromLong(BPY_BM_IS_VALID(self));
369}
370
372 /* Wrap. */
373 bpy_bmesh_is_wrapped_doc,
374 "True when this mesh is owned by blender (typically the editmode BMesh).\n"
375 "\n"
376 ":type: bool\n");
377static PyObject *bpy_bmesh_is_wrapped_get(BPy_BMesh *self, void * /*closure*/)
378{
379 BPY_BM_CHECK_OBJ(self);
380
381 return PyBool_FromLong(self->flag & BPY_BMFLAG_IS_WRAPPED);
382}
383
385 /* Wrap. */
386 bpy_bmesh_select_mode_doc,
387 "The selection mode, cannot be assigned an empty set.\n"
388 "\n"
389 ":type: set[Literal[" BPY_BM_HTYPE_NOLOOP "]]\n");
390static PyObject *bpy_bmesh_select_mode_get(BPy_BMesh *self, void * /*closure*/)
391{
392 BPY_BM_CHECK_OBJ(self);
393
395}
396
397static int bpy_bmesh_select_mode_set(BPy_BMesh *self, PyObject *value, void * /*closure*/)
398{
399 int flag = 0;
400 BPY_BM_CHECK_INT(self);
401
402 if (PyC_FlagSet_ToBitfield(bpy_bm_scene_vert_edge_face_flags, value, &flag, "bm.select_mode") ==
403 -1)
404 {
405 return -1;
406 }
407 if (flag == 0) {
408 PyErr_SetString(PyExc_TypeError, "bm.select_mode: cannot assign an empty value");
409 return -1;
410 }
411
412 self->bm->selectmode = flag;
413 return 0;
414}
415
417 /* Wrap. */
418 bpy_bmesh_select_history_doc,
419 "Sequence of selected items (the last is displayed as active).\n"
420 "\n"
421 ":type: "
422 ":class:`bmesh.types.BMEditSelSeq`\n");
423static PyObject *bpy_bmesh_select_history_get(BPy_BMesh *self, void * /*closure*/)
424{
425 BPY_BM_CHECK_OBJ(self);
426
427 return BPy_BMEditSel_CreatePyObject(self->bm);
428}
429
430static int bpy_bmesh_select_history_set(BPy_BMesh *self, PyObject *value, void * /*closure*/)
431{
432 BPY_BM_CHECK_INT(self);
433
434 return BPy_BMEditSel_Assign(self, value);
435}
436
438 /* Wrap. */
439 bpy_bmesh_uv_select_sync_valid_doc,
440 "When true, the UV selection has been synchronized. "
441 "Setting to False means the UV selection will be ignored. "
442 "While setting to true is supported it is up to the script author to "
443 "ensure a correct selection state before doing so.\n"
444 "\n"
445 ":type: bool\n");
446static PyObject *bpy_bmesh_uv_select_sync_valid_get(BPy_BMesh *self, void * /*closure*/)
447{
448 BPY_BM_CHECK_OBJ(self);
449
450 return PyBool_FromLong(self->bm->uv_select_sync_valid);
451}
452
453static int bpy_bmesh_uv_select_sync_valid_set(BPy_BMesh *self, PyObject *value, void * /*closure*/)
454{
455 BPY_BM_CHECK_INT(self);
456
457 int param;
458 if ((param = PyC_Long_AsBool(value)) == -1) {
459 return -1;
460 }
461 self->bm->uv_select_sync_valid = param;
462 return 0;
463}
464
465/* Vert
466 * ^^^^ */
467
469 /* Wrap. */
470 bpy_bmvert_co_doc,
471 "The coordinates for this vertex as a 3D, wrapped vector.\n"
472 "\n"
473 ":type: "
474 ":class:`mathutils.Vector`\n");
475static PyObject *bpy_bmvert_co_get(BPy_BMVert *self, void * /*closure*/)
476{
477 BPY_BM_CHECK_OBJ(self);
478 return Vector_CreatePyObject_wrap(self->v->co, 3, nullptr);
479}
480
481static int bpy_bmvert_co_set(BPy_BMVert *self, PyObject *value, void * /*closure*/)
482{
483 BPY_BM_CHECK_INT(self);
484
485 if (mathutils_array_parse(self->v->co, 3, 3, value, "BMVert.co") != -1) {
486 return 0;
487 }
488
489 return -1;
490}
491
493 /* Wrap. */
494 bpy_bmvert_normal_doc,
495 "The normal for this vertex as a 3D, wrapped vector.\n"
496 "\n"
497 ":type: :class:`mathutils.Vector`\n");
498static PyObject *bpy_bmvert_normal_get(BPy_BMVert *self, void * /*closure*/)
499{
500 BPY_BM_CHECK_OBJ(self);
501 return Vector_CreatePyObject_wrap(self->v->no, 3, nullptr);
502}
503
504static int bpy_bmvert_normal_set(BPy_BMVert *self, PyObject *value, void * /*closure*/)
505{
506 BPY_BM_CHECK_INT(self);
507
508 if (mathutils_array_parse(self->v->no, 3, 3, value, "BMVert.normal") != -1) {
509 return 0;
510 }
511
512 return -1;
513}
514
516 /* Wrap. */
517 bpy_bmvert_is_manifold_doc,
518 "True when this vertex is manifold (read-only).\n"
519 "\n"
520 ":type: bool\n");
521static PyObject *bpy_bmvert_is_manifold_get(BPy_BMVert *self, void * /*closure*/)
522{
523 BPY_BM_CHECK_OBJ(self);
524 return PyBool_FromLong(BM_vert_is_manifold(self->v));
525}
526
528 /* Wrap. */
529 bpy_bmvert_is_wire_doc,
530 "True when this vertex is not connected to any faces (read-only).\n"
531 "\n"
532 ":type: bool\n");
533static PyObject *bpy_bmvert_is_wire_get(BPy_BMVert *self, void * /*closure*/)
534{
535 BPY_BM_CHECK_OBJ(self);
536 return PyBool_FromLong(BM_vert_is_wire(self->v));
537}
538
540 /* Wrap. */
541 bpy_bmvert_is_boundary_doc,
542 "True when this vertex is connected to boundary edges (read-only).\n"
543 "\n"
544 ":type: bool\n");
545static PyObject *bpy_bmvert_is_boundary_get(BPy_BMVert *self, void * /*closure*/)
546{
547 BPY_BM_CHECK_OBJ(self);
548 return PyBool_FromLong(BM_vert_is_boundary(self->v));
549}
550
551/* Edge
552 * ^^^^ */
553
555 /* Wrap. */
556 bpy_bmedge_is_manifold_doc,
557 "True when this edge is manifold (read-only).\n"
558 "\n"
559 ":type: bool\n");
560static PyObject *bpy_bmedge_is_manifold_get(BPy_BMEdge *self, void * /*closure*/)
561{
562 BPY_BM_CHECK_OBJ(self);
563 return PyBool_FromLong(BM_edge_is_manifold(self->e));
564}
565
567 /* Wrap. */
568 bpy_bmedge_is_contiguous_doc,
569 "True when this edge is manifold, between two faces with the same winding "
570 "(read-only).\n"
571 "\n"
572 ":type: bool\n");
573static PyObject *bpy_bmedge_is_contiguous_get(BPy_BMEdge *self, void * /*closure*/)
574{
575 BPY_BM_CHECK_OBJ(self);
576 return PyBool_FromLong(BM_edge_is_contiguous(self->e));
577}
578
580 /* Wrap. */
581 bpy_bmedge_is_convex_doc,
582 "True when this edge joins two convex faces, depends on a valid face normal (read-only).\n"
583 "\n"
584 ":type: bool\n");
585static PyObject *bpy_bmedge_is_convex_get(BPy_BMEdge *self, void * /*closure*/)
586{
587 BPY_BM_CHECK_OBJ(self);
588 return PyBool_FromLong(BM_edge_is_convex(self->e));
589}
590
592 /* Wrap. */
593 bpy_bmedge_is_wire_doc,
594 "True when this edge is not connected to any faces (read-only).\n"
595 "\n"
596 ":type: bool\n");
597static PyObject *bpy_bmedge_is_wire_get(BPy_BMEdge *self, void * /*closure*/)
598{
599 BPY_BM_CHECK_OBJ(self);
600 return PyBool_FromLong(BM_edge_is_wire(self->e));
601}
602
604 /* Wrap. */
605 bpy_bmedge_is_boundary_doc,
606 "True when this edge is at the boundary of a face (read-only).\n"
607 "\n"
608 ":type: bool\n");
609static PyObject *bpy_bmedge_is_boundary_get(BPy_BMEdge *self, void * /*closure*/)
610{
611 BPY_BM_CHECK_OBJ(self);
612 return PyBool_FromLong(BM_edge_is_boundary(self->e));
613}
614
615/* Face
616 * ^^^^ */
617
619 /* Wrap. */
620 bpy_bmface_normal_doc,
621 "The normal for this face as a 3D, wrapped vector.\n"
622 "\n"
623 ":type: :class:`mathutils.Vector`\n");
624static PyObject *bpy_bmface_normal_get(BPy_BMFace *self, void * /*closure*/)
625{
626 BPY_BM_CHECK_OBJ(self);
627 return Vector_CreatePyObject_wrap(self->f->no, 3, nullptr);
628}
629
630static int bpy_bmface_normal_set(BPy_BMFace *self, PyObject *value, void * /*closure*/)
631{
632 BPY_BM_CHECK_INT(self);
633
634 if (mathutils_array_parse(self->f->no, 3, 3, value, "BMFace.normal") != -1) {
635 return 0;
636 }
637
638 return -1;
639}
640
642 /* Wrap. */
643 bpy_bmface_material_index_doc,
644 "The face's material index.\n"
645 "\n"
646 ":type: int\n");
647static PyObject *bpy_bmface_material_index_get(BPy_BMFace *self, void * /*closure*/)
648{
649 BPY_BM_CHECK_OBJ(self);
650 return PyLong_FromLong(self->f->mat_nr);
651}
652
653static int bpy_bmface_material_index_set(BPy_BMFace *self, PyObject *value, void * /*closure*/)
654{
655 int param;
656
657 BPY_BM_CHECK_INT(self);
658
659 if (((param = PyC_Long_AsI32(value)) == -1) && PyErr_Occurred()) {
660 /* error is set */
661 return -1;
662 }
663
664 if ((param < 0) || (param > MAXMAT)) {
665 /* normally we clamp but in this case raise an error */
666 PyErr_SetString(PyExc_ValueError, "material index outside of usable range (0 - 32766)");
667 return -1;
668 }
669
670 self->f->mat_nr = short(param);
671 return 0;
672}
673
674/* Loop
675 * ^^^^ */
676
678 /* Wrap. */
679 bpy_bmloop_vert_doc,
680 "The loop's vertex (read-only).\n"
681 "\n"
682 ":type: :class:`bmesh.types.BMVert`\n");
683static PyObject *bpy_bmloop_vert_get(BPy_BMLoop *self, void * /*closure*/)
684{
685 BPY_BM_CHECK_OBJ(self);
686 return BPy_BMVert_CreatePyObject(self->bm, self->l->v);
687}
688
690 /* Wrap. */
691 bpy_bmloop_edge_doc,
692 "The loop's edge (between this loop and the next), (read-only).\n"
693 "\n"
694 ":type: :class:`bmesh.types.BMEdge`\n");
695static PyObject *bpy_bmloop_edge_get(BPy_BMLoop *self, void * /*closure*/)
696{
697 BPY_BM_CHECK_OBJ(self);
698 return BPy_BMEdge_CreatePyObject(self->bm, self->l->e);
699}
700
702 /* Wrap. */
703 bpy_bmloop_face_doc,
704 "The face this loop belongs to (read-only).\n"
705 "\n"
706 ":type: :class:`bmesh.types.BMFace`\n");
707static PyObject *bpy_bmloop_face_get(BPy_BMLoop *self, void * /*closure*/)
708{
709 BPY_BM_CHECK_OBJ(self);
710 return BPy_BMFace_CreatePyObject(self->bm, self->l->f);
711}
712
714 /* Wrap. */
715 bpy_bmloop_link_loop_next_doc,
716 "The next face corner (read-only).\n"
717 "\n"
718 ":type: :class:`bmesh.types.BMLoop`\n");
719static PyObject *bpy_bmloop_link_loop_next_get(BPy_BMLoop *self, void * /*closure*/)
720{
721 BPY_BM_CHECK_OBJ(self);
722 return BPy_BMLoop_CreatePyObject(self->bm, self->l->next);
723}
724
726 /* Wrap. */
727 bpy_bmloop_link_loop_prev_doc,
728 "The previous face corner (read-only).\n"
729 "\n"
730 ":type: :class:`bmesh.types.BMLoop`\n");
731static PyObject *bpy_bmloop_link_loop_prev_get(BPy_BMLoop *self, void * /*closure*/)
732{
733 BPY_BM_CHECK_OBJ(self);
734 return BPy_BMLoop_CreatePyObject(self->bm, self->l->prev);
735}
736
738 /* Wrap. */
739 bpy_bmloop_link_loop_radial_next_doc,
740 "The next loop around the edge (read-only).\n"
741 "\n"
742 ":type: :class:`bmesh.types.BMLoop`\n");
743static PyObject *bpy_bmloop_link_loop_radial_next_get(BPy_BMLoop *self, void * /*closure*/)
744{
745 BPY_BM_CHECK_OBJ(self);
746 return BPy_BMLoop_CreatePyObject(self->bm, self->l->radial_next);
747}
748
750 /* Wrap. */
751 bpy_bmloop_link_loop_radial_prev_doc,
752 "The previous loop around the edge (read-only).\n"
753 "\n"
754 ":type: :class:`bmesh.types.BMLoop`\n");
755static PyObject *bpy_bmloop_link_loop_radial_prev_get(BPy_BMLoop *self, void * /*closure*/)
756{
757 BPY_BM_CHECK_OBJ(self);
758 return BPy_BMLoop_CreatePyObject(self->bm, self->l->radial_prev);
759}
760
762 /* Wrap. */
763 bpy_bmloop_is_convex_doc,
764 "True when this loop is at the convex corner of a face, depends on a valid face "
765 "normal (read-only).\n"
766 "\n"
767 ":type: bool\n");
768static PyObject *bpy_bmloop_is_convex_get(BPy_BMLoop *self, void * /*closure*/)
769{
770 BPY_BM_CHECK_OBJ(self);
771 return PyBool_FromLong(BM_loop_is_convex(self->l));
772}
773
774/* ElemSeq
775 * ^^^^^^^ */
776
777/* NOTE: use for bmvert/edge/face/loop seq's use these, not bmelemseq directly. */
779 /* Wrap. */
780 bpy_bmelemseq_layers_vert_doc,
781 "custom-data layers (read-only).\n"
782 "\n"
783 ":type: :class:`bmesh.types.BMLayerAccessVert`\n");
785 /* Wrap. */
786 bpy_bmelemseq_layers_edge_doc,
787 "custom-data layers (read-only).\n"
788 "\n"
789 ":type: :class:`bmesh.types.BMLayerAccessEdge`\n");
791 /* Wrap. */
792 bpy_bmelemseq_layers_face_doc,
793 "custom-data layers (read-only).\n"
794 "\n"
795 ":type: :class:`bmesh.types.BMLayerAccessFace`\n");
797 /* Wrap. */
798 bpy_bmelemseq_layers_loop_doc,
799 "custom-data layers (read-only).\n"
800 "\n"
801 ":type: :class:`bmesh.types.BMLayerAccessLoop`\n");
802static PyObject *bpy_bmelemseq_layers_get(BPy_BMElemSeq *self, void *htype)
803{
804 BPY_BM_CHECK_OBJ(self);
805
807}
808
809/* FaceSeq
810 * ^^^^^^^ */
811
813 /* Wrap. */
814 bpy_bmfaceseq_active_doc,
815 "active face.\n"
816 "\n"
817 ":type: :class:`bmesh.types.BMFace` | None\n");
818static PyObject *bpy_bmfaceseq_active_get(BPy_BMElemSeq *self, void * /*closure*/)
819{
820 BMesh *bm = self->bm;
821 BPY_BM_CHECK_OBJ(self);
822
823 if (bm->act_face) {
824 return BPy_BMElem_CreatePyObject(bm, reinterpret_cast<BMHeader *>(bm->act_face));
825 }
826
827 Py_RETURN_NONE;
828}
829
830static int bpy_bmfaceseq_active_set(BPy_BMElem *self, PyObject *value, void * /*closure*/)
831{
832 const char *error_prefix = "faces.active = f";
833 BMesh *bm = self->bm;
834 if (value == Py_None) {
835 bm->act_face = nullptr;
836 return 0;
837 }
838 if (BPy_BMFace_Check(value)) {
839 BPY_BM_CHECK_SOURCE_INT(bm, error_prefix, value);
840
841 bm->act_face = (reinterpret_cast<BPy_BMFace *>(value))->f;
842 return 0;
843 }
844
845 PyErr_Format(PyExc_TypeError,
846 "%s: expected BMFace or None, not %.200s",
847 error_prefix,
848 Py_TYPE(value)->tp_name);
849 return -1;
850}
851
852static PyGetSetDef bpy_bmesh_getseters[] = {
853 {"verts",
854 reinterpret_cast<getter>(bpy_bmvertseq_get),
855 static_cast<setter>(nullptr),
856 bpy_bmvertseq_doc,
857 nullptr},
858 {"edges",
859 reinterpret_cast<getter>(bpy_bmedgeseq_get),
860 static_cast<setter>(nullptr),
861 bpy_bmedgeseq_doc,
862 nullptr},
863 {"faces",
864 reinterpret_cast<getter>(bpy_bmfaceseq_get),
865 static_cast<setter>(nullptr),
866 bpy_bmfaceseq_doc,
867 nullptr},
868 {"loops",
869 reinterpret_cast<getter>(bpy_bmloopseq_get),
870 static_cast<setter>(nullptr),
871 bpy_bmloopseq_doc,
872 nullptr},
873 {"select_mode",
874 reinterpret_cast<getter>(bpy_bmesh_select_mode_get),
875 reinterpret_cast<setter>(bpy_bmesh_select_mode_set),
876 bpy_bmesh_select_mode_doc,
877 nullptr},
878
879 {"select_history",
880 reinterpret_cast<getter>(bpy_bmesh_select_history_get),
881 reinterpret_cast<setter>(bpy_bmesh_select_history_set),
882 bpy_bmesh_select_history_doc,
883 nullptr},
884
885 {"uv_select_sync_valid",
886 reinterpret_cast<getter>(bpy_bmesh_uv_select_sync_valid_get),
887 reinterpret_cast<setter>(bpy_bmesh_uv_select_sync_valid_set),
888 bpy_bmesh_uv_select_sync_valid_doc,
889 nullptr},
890
891 /* readonly checks */
892 {"is_wrapped",
893 reinterpret_cast<getter>(bpy_bmesh_is_wrapped_get),
894 static_cast<setter>(nullptr),
895 bpy_bmesh_is_wrapped_doc,
896 nullptr}, /* as with mathutils */
897 {"is_valid",
898 reinterpret_cast<getter>(bpy_bm_is_valid_get),
899 static_cast<setter>(nullptr),
900 bpy_bm_is_valid_doc,
901 nullptr},
902
903 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
904};
905
906static PyGetSetDef bpy_bmvert_getseters[] = {
907 /* generic */
908 {"select",
909 reinterpret_cast<getter>(bpy_bm_elem_hflag_get),
910 reinterpret_cast<setter>(bpy_bm_elem_hflag_set),
911 bpy_bm_elem_select_doc,
912 reinterpret_cast<void *>(BM_ELEM_SELECT)},
913 {"hide",
914 reinterpret_cast<getter>(bpy_bm_elem_hflag_get),
915 reinterpret_cast<setter>(bpy_bm_elem_hflag_set),
916 bpy_bm_elem_hide_doc,
917 reinterpret_cast<void *>(BM_ELEM_HIDDEN)},
918 {"tag",
919 reinterpret_cast<getter>(bpy_bm_elem_hflag_get),
920 reinterpret_cast<setter>(bpy_bm_elem_hflag_set),
921 bpy_bm_elem_tag_doc,
922 reinterpret_cast<void *>(BM_ELEM_TAG)},
923 {"index",
924 reinterpret_cast<getter>(bpy_bm_elem_index_get),
925 reinterpret_cast<setter>(bpy_bm_elem_index_set),
926 bpy_bm_elem_index_doc,
927 nullptr},
928
929 {"co",
930 reinterpret_cast<getter>(bpy_bmvert_co_get),
931 reinterpret_cast<setter>(bpy_bmvert_co_set),
932 bpy_bmvert_co_doc,
933 nullptr},
934 {"normal",
935 reinterpret_cast<getter>(bpy_bmvert_normal_get),
936 reinterpret_cast<setter>(bpy_bmvert_normal_set),
937 bpy_bmvert_normal_doc,
938 nullptr},
939
940 /* connectivity data */
941 {"link_edges",
942 reinterpret_cast<getter>(bpy_bmelemseq_elem_get),
943 static_cast<setter>(nullptr),
944 bpy_bmvert_link_edges_doc,
945 reinterpret_cast<void *>(BM_EDGES_OF_VERT)},
946 {"link_faces",
947 reinterpret_cast<getter>(bpy_bmelemseq_elem_get),
948 static_cast<setter>(nullptr),
949 bpy_bmvert_link_faces_doc,
950 reinterpret_cast<void *>(BM_FACES_OF_VERT)},
951 {"link_loops",
952 reinterpret_cast<getter>(bpy_bmelemseq_elem_get),
953 static_cast<setter>(nullptr),
954 bpy_bmvert_link_loops_doc,
955 reinterpret_cast<void *>(BM_LOOPS_OF_VERT)},
956
957 /* readonly checks */
958 {"is_manifold",
959 reinterpret_cast<getter>(bpy_bmvert_is_manifold_get),
960 static_cast<setter>(nullptr),
961 bpy_bmvert_is_manifold_doc,
962 nullptr},
963 {"is_wire",
964 reinterpret_cast<getter>(bpy_bmvert_is_wire_get),
965 static_cast<setter>(nullptr),
966 bpy_bmvert_is_wire_doc,
967 nullptr},
968 {"is_boundary",
969 reinterpret_cast<getter>(bpy_bmvert_is_boundary_get),
970 static_cast<setter>(nullptr),
971 bpy_bmvert_is_boundary_doc,
972 nullptr},
973 {"is_valid",
974 reinterpret_cast<getter>(bpy_bm_is_valid_get),
975 static_cast<setter>(nullptr),
976 bpy_bm_is_valid_doc,
977 nullptr},
978
979 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
980};
981
982static PyGetSetDef bpy_bmedge_getseters[] = {
983 /* generic */
984 {"select",
985 reinterpret_cast<getter>(bpy_bm_elem_hflag_get),
986 reinterpret_cast<setter>(bpy_bm_elem_hflag_set),
987 bpy_bm_elem_select_doc,
988 reinterpret_cast<void *>(BM_ELEM_SELECT)},
989 {"hide",
990 reinterpret_cast<getter>(bpy_bm_elem_hflag_get),
991 reinterpret_cast<setter>(bpy_bm_elem_hflag_set),
992 bpy_bm_elem_hide_doc,
993 reinterpret_cast<void *>(BM_ELEM_HIDDEN)},
994 {"tag",
995 reinterpret_cast<getter>(bpy_bm_elem_hflag_get),
996 reinterpret_cast<setter>(bpy_bm_elem_hflag_set),
997 bpy_bm_elem_tag_doc,
998 reinterpret_cast<void *>(BM_ELEM_TAG)},
999 {"index",
1000 reinterpret_cast<getter>(bpy_bm_elem_index_get),
1001 reinterpret_cast<setter>(bpy_bm_elem_index_set),
1002 bpy_bm_elem_index_doc,
1003 nullptr},
1004
1005 {"smooth",
1006 reinterpret_cast<getter>(bpy_bm_elem_hflag_get),
1007 reinterpret_cast<setter>(bpy_bm_elem_hflag_set),
1008 bpy_bm_elem_smooth_doc,
1009 reinterpret_cast<void *>(BM_ELEM_SMOOTH)},
1010 {"seam",
1011 reinterpret_cast<getter>(bpy_bm_elem_hflag_get),
1012 reinterpret_cast<setter>(bpy_bm_elem_hflag_set),
1013 bpy_bm_elem_seam_doc,
1014 reinterpret_cast<void *>(BM_ELEM_SEAM)},
1015
1016 /* connectivity data */
1017 {"verts",
1018 reinterpret_cast<getter>(bpy_bmelemseq_elem_get),
1019 static_cast<setter>(nullptr),
1020 bpy_bmedge_verts_doc,
1021 reinterpret_cast<void *>(BM_VERTS_OF_EDGE)},
1022
1023 {"link_faces",
1024 reinterpret_cast<getter>(bpy_bmelemseq_elem_get),
1025 static_cast<setter>(nullptr),
1026 bpy_bmedge_link_faces_doc,
1027 reinterpret_cast<void *>(BM_FACES_OF_EDGE)},
1028 {"link_loops",
1029 reinterpret_cast<getter>(bpy_bmelemseq_elem_get),
1030 static_cast<setter>(nullptr),
1031 bpy_bmedge_link_loops_doc,
1032 reinterpret_cast<void *>(BM_LOOPS_OF_EDGE)},
1033
1034 /* readonly checks */
1035 {"is_manifold",
1036 reinterpret_cast<getter>(bpy_bmedge_is_manifold_get),
1037 static_cast<setter>(nullptr),
1038 bpy_bmedge_is_manifold_doc,
1039 nullptr},
1040 {"is_contiguous",
1041 reinterpret_cast<getter>(bpy_bmedge_is_contiguous_get),
1042 static_cast<setter>(nullptr),
1043 bpy_bmedge_is_contiguous_doc,
1044 nullptr},
1045 {"is_convex",
1046 reinterpret_cast<getter>(bpy_bmedge_is_convex_get),
1047 static_cast<setter>(nullptr),
1048 bpy_bmedge_is_convex_doc,
1049 nullptr},
1050 {"is_wire",
1051 reinterpret_cast<getter>(bpy_bmedge_is_wire_get),
1052 static_cast<setter>(nullptr),
1053 bpy_bmedge_is_wire_doc,
1054 nullptr},
1055 {"is_boundary",
1056 reinterpret_cast<getter>(bpy_bmedge_is_boundary_get),
1057 static_cast<setter>(nullptr),
1058 bpy_bmedge_is_boundary_doc,
1059 nullptr},
1060 {"is_valid",
1061 reinterpret_cast<getter>(bpy_bm_is_valid_get),
1062 static_cast<setter>(nullptr),
1063 bpy_bm_is_valid_doc,
1064 nullptr},
1065
1066 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
1067};
1068
1069static PyGetSetDef bpy_bmface_getseters[] = {
1070 /* generic */
1071 {"select",
1072 reinterpret_cast<getter>(bpy_bm_elem_hflag_get),
1073 reinterpret_cast<setter>(bpy_bm_elem_hflag_set),
1074 bpy_bm_elem_select_doc,
1075 reinterpret_cast<void *>(BM_ELEM_SELECT)},
1076 {"hide",
1077 reinterpret_cast<getter>(bpy_bm_elem_hflag_get),
1078 reinterpret_cast<setter>(bpy_bm_elem_hflag_set),
1079 bpy_bm_elem_hide_doc,
1080 reinterpret_cast<void *>(BM_ELEM_HIDDEN)},
1081 {"tag",
1082 reinterpret_cast<getter>(bpy_bm_elem_hflag_get),
1083 reinterpret_cast<setter>(bpy_bm_elem_hflag_set),
1084 bpy_bm_elem_tag_doc,
1085 reinterpret_cast<void *>(BM_ELEM_TAG)},
1086 {"uv_select",
1087 reinterpret_cast<getter>(bpy_bm_elem_hflag_get),
1088 reinterpret_cast<setter>(bpy_bm_elem_hflag_set),
1089 bpy_bm_elem_uv_select_doc,
1090 reinterpret_cast<void *>(BM_ELEM_SELECT_UV)},
1091 {"index",
1092 reinterpret_cast<getter>(bpy_bm_elem_index_get),
1093 reinterpret_cast<setter>(bpy_bm_elem_index_set),
1094 bpy_bm_elem_index_doc,
1095 nullptr},
1096
1097 {"smooth",
1098 reinterpret_cast<getter>(bpy_bm_elem_hflag_get),
1099 reinterpret_cast<setter>(bpy_bm_elem_hflag_set),
1100 bpy_bm_elem_smooth_doc,
1101 reinterpret_cast<void *>(BM_ELEM_SMOOTH)},
1102
1103 {"normal",
1104 reinterpret_cast<getter>(bpy_bmface_normal_get),
1105 reinterpret_cast<setter>(bpy_bmface_normal_set),
1106 bpy_bmface_normal_doc,
1107 nullptr},
1108
1109 {"material_index",
1110 reinterpret_cast<getter>(bpy_bmface_material_index_get),
1111 reinterpret_cast<setter>(bpy_bmface_material_index_set),
1112 bpy_bmface_material_index_doc,
1113 nullptr},
1114
1115 /* connectivity data */
1116 {"verts",
1117 reinterpret_cast<getter>(bpy_bmelemseq_elem_get),
1118 static_cast<setter>(nullptr),
1119 bpy_bmface_verts_doc,
1120 reinterpret_cast<void *>(BM_VERTS_OF_FACE)},
1121 {"edges",
1122 reinterpret_cast<getter>(bpy_bmelemseq_elem_get),
1123 static_cast<setter>(nullptr),
1124 bpy_bmface_edges_doc,
1125 reinterpret_cast<void *>(BM_EDGES_OF_FACE)},
1126 {"loops",
1127 reinterpret_cast<getter>(bpy_bmelemseq_elem_get),
1128 static_cast<setter>(nullptr),
1129 bpy_bmface_loops_doc,
1130 reinterpret_cast<void *>(BM_LOOPS_OF_FACE)},
1131
1132 /* readonly checks */
1133 {"is_valid",
1134 reinterpret_cast<getter>(bpy_bm_is_valid_get),
1135 static_cast<setter>(nullptr),
1136 bpy_bm_is_valid_doc,
1137 nullptr},
1138
1139 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
1140};
1141
1142static PyGetSetDef bpy_bmloop_getseters[] = {
1143/* generic */
1144/* flags are available but not used for loops. */
1145#if 0
1146 {"select",
1147 (getter)bpy_bm_elem_hflag_get,
1148 (setter)bpy_bm_elem_hflag_set,
1149 bpy_bm_elem_select_doc,
1150 (void *)BM_ELEM_SELECT},
1151 {"hide",
1152 (getter)bpy_bm_elem_hflag_get,
1153 (setter)bpy_bm_elem_hflag_set,
1154 bpy_bm_elem_hide_doc,
1155 (void *)BM_ELEM_HIDDEN},
1156#endif
1157 {"tag",
1158 reinterpret_cast<getter>(bpy_bm_elem_hflag_get),
1159 reinterpret_cast<setter>(bpy_bm_elem_hflag_set),
1160 bpy_bm_elem_tag_doc,
1161 reinterpret_cast<void *>(BM_ELEM_TAG)},
1162 {"uv_select_vert",
1163 reinterpret_cast<getter>(bpy_bm_elem_hflag_get),
1164 reinterpret_cast<setter>(bpy_bm_elem_hflag_set),
1165 bpy_bm_elem_uv_select_vert_doc,
1166 reinterpret_cast<void *>(BM_ELEM_SELECT_UV)},
1167 {"uv_select_edge",
1168 reinterpret_cast<getter>(bpy_bm_elem_hflag_get),
1169 reinterpret_cast<setter>(bpy_bm_elem_hflag_set),
1170 bpy_bm_elem_uv_select_edge_doc,
1171 reinterpret_cast<void *>(BM_ELEM_SELECT_UV_EDGE)},
1172 {"index",
1173 reinterpret_cast<getter>(bpy_bm_elem_index_get),
1174 reinterpret_cast<setter>(bpy_bm_elem_index_set),
1175 bpy_bm_elem_index_doc,
1176 nullptr},
1177
1178 {"vert",
1179 reinterpret_cast<getter>(bpy_bmloop_vert_get),
1180 static_cast<setter>(nullptr),
1181 bpy_bmloop_vert_doc,
1182 nullptr},
1183 {"edge",
1184 reinterpret_cast<getter>(bpy_bmloop_edge_get),
1185 static_cast<setter>(nullptr),
1186 bpy_bmloop_edge_doc,
1187 nullptr},
1188 {"face",
1189 reinterpret_cast<getter>(bpy_bmloop_face_get),
1190 static_cast<setter>(nullptr),
1191 bpy_bmloop_face_doc,
1192 nullptr},
1193
1194 /* connectivity data */
1195 {"link_loops",
1196 reinterpret_cast<getter>(bpy_bmelemseq_elem_get),
1197 static_cast<setter>(nullptr),
1198 bpy_bmloops_link_loops_doc,
1199 reinterpret_cast<void *>(BM_LOOPS_OF_LOOP)},
1200 {"link_loop_next",
1201 reinterpret_cast<getter>(bpy_bmloop_link_loop_next_get),
1202 static_cast<setter>(nullptr),
1203 bpy_bmloop_link_loop_next_doc,
1204 nullptr},
1205 {"link_loop_prev",
1206 reinterpret_cast<getter>(bpy_bmloop_link_loop_prev_get),
1207 static_cast<setter>(nullptr),
1208 bpy_bmloop_link_loop_prev_doc,
1209 nullptr},
1210 {"link_loop_radial_next",
1211 reinterpret_cast<getter>(bpy_bmloop_link_loop_radial_next_get),
1212 static_cast<setter>(nullptr),
1213 bpy_bmloop_link_loop_radial_next_doc,
1214 nullptr},
1215 {"link_loop_radial_prev",
1216 reinterpret_cast<getter>(bpy_bmloop_link_loop_radial_prev_get),
1217 static_cast<setter>(nullptr),
1218 bpy_bmloop_link_loop_radial_prev_doc,
1219 nullptr},
1220
1221 /* readonly checks */
1222 {"is_convex",
1223 reinterpret_cast<getter>(bpy_bmloop_is_convex_get),
1224 static_cast<setter>(nullptr),
1225 bpy_bmloop_is_convex_doc,
1226 nullptr},
1227 {"is_valid",
1228 reinterpret_cast<getter>(bpy_bm_is_valid_get),
1229 static_cast<setter>(nullptr),
1230 bpy_bm_is_valid_doc,
1231 nullptr},
1232
1233 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
1234};
1235
1236static PyGetSetDef bpy_bmvertseq_getseters[] = {
1237 {"layers",
1238 reinterpret_cast<getter>(bpy_bmelemseq_layers_get),
1239 static_cast<setter>(nullptr),
1240 bpy_bmelemseq_layers_vert_doc,
1241 reinterpret_cast<void *>(BM_VERT)},
1242 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
1243};
1244static PyGetSetDef bpy_bmedgeseq_getseters[] = {
1245 {"layers",
1246 reinterpret_cast<getter>(bpy_bmelemseq_layers_get),
1247 static_cast<setter>(nullptr),
1248 bpy_bmelemseq_layers_edge_doc,
1249 reinterpret_cast<void *>(BM_EDGE)},
1250 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
1251};
1252static PyGetSetDef bpy_bmfaceseq_getseters[] = {
1253 {"layers",
1254 reinterpret_cast<getter>(bpy_bmelemseq_layers_get),
1255 static_cast<setter>(nullptr),
1256 bpy_bmelemseq_layers_face_doc,
1257 reinterpret_cast<void *>(BM_FACE)},
1258 /* face only */
1259 {"active",
1260 reinterpret_cast<getter>(bpy_bmfaceseq_active_get),
1261 reinterpret_cast<setter>(bpy_bmfaceseq_active_set),
1262 bpy_bmfaceseq_active_doc,
1263 nullptr},
1264 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
1265};
1266static PyGetSetDef bpy_bmloopseq_getseters[] = {
1267 {"layers",
1268 reinterpret_cast<getter>(bpy_bmelemseq_layers_get),
1269 static_cast<setter>(nullptr),
1270 bpy_bmelemseq_layers_loop_doc,
1271 reinterpret_cast<void *>(BM_LOOP)},
1272 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
1273};
1274
1275/* Methods
1276 * ======= */
1277
1278/* Mesh
1279 * ---- */
1280
1282 /* Wrap. */
1283 bpy_bmesh_copy_doc,
1284 ".. method:: copy()\n"
1285 "\n"
1286 " :return: A copy of this BMesh.\n"
1287 " :rtype: :class:`bmesh.types.BMesh`\n");
1288static PyObject *bpy_bmesh_copy(BPy_BMesh *self)
1289{
1290 BPY_BM_CHECK_OBJ(self);
1291
1292 BMesh *bm = self->bm;
1293 BMesh *bm_copy = BM_mesh_copy(bm);
1294
1295 if (bm_copy) {
1297 }
1298
1299 PyErr_SetString(PyExc_SystemError, "Unable to copy BMesh, internal error");
1300 return nullptr;
1301}
1302
1304 /* Wrap. */
1305 bpy_bmesh_clear_doc,
1306 ".. method:: clear()\n"
1307 "\n"
1308 " Clear all mesh data.\n");
1309static PyObject *bpy_bmesh_clear(BPy_BMesh *self)
1310{
1311 BPY_BM_CHECK_OBJ(self);
1312
1313 BMesh *bm = self->bm;
1314
1316
1317 Py_RETURN_NONE;
1318}
1319
1321 /* Wrap. */
1322 bpy_bmesh_free_doc,
1323 ".. method:: free()\n"
1324 "\n"
1325 " Explicitly free the BMesh data from memory, causing exceptions on further access.\n"
1326 "\n"
1327 " .. note::\n"
1328 "\n"
1329 " The BMesh is freed automatically, typically when the script finishes executing.\n"
1330 " However in some cases it's hard to predict when this will be and it's useful to\n"
1331 " explicitly free the data.\n");
1332static PyObject *bpy_bmesh_free(BPy_BMesh *self)
1333{
1334 if (self->bm) {
1335 BMesh *bm = self->bm;
1336
1338
1339 if (self->flag & BPY_BMFLAG_IS_WRAPPED) {
1340 /* Ensure further access doesn't return this invalid object, see: #105715. */
1341 bm->py_handle = nullptr;
1342 }
1343 else {
1345 }
1346
1347 bpy_bm_generic_invalidate(reinterpret_cast<BPy_BMGeneric *>(self));
1348 }
1349
1350 Py_RETURN_NONE;
1351}
1352
1354 /* Wrap. */
1355 bpy_bmesh_to_mesh_doc,
1356 ".. method:: to_mesh(mesh)\n"
1357 "\n"
1358 " Writes this BMesh data into an existing Mesh data-block.\n"
1359 "\n"
1360 " :param mesh: The mesh data to write into.\n"
1361 " :type mesh: :class:`bpy.types.Mesh`\n");
1362static PyObject *bpy_bmesh_to_mesh(BPy_BMesh *self, PyObject *args)
1363{
1364 PyObject *py_mesh;
1365 Mesh *mesh;
1366
1367 BPY_BM_CHECK_OBJ(self);
1368
1369 if (!PyArg_ParseTuple(args,
1370 "O" /* `mesh` */
1371 ":to_mesh",
1372 &py_mesh) ||
1373 !(mesh = static_cast<Mesh *>(PyC_RNA_AsPointer(py_mesh, "Mesh"))))
1374 {
1375 return nullptr;
1376 }
1377
1378 /* we could allow this but its almost certainly _not_ what script authors want */
1379 if (mesh->runtime->edit_mesh) {
1380 PyErr_Format(PyExc_ValueError, "to_mesh(): Mesh '%s' is in editmode", mesh->id.name + 2);
1381 return nullptr;
1382 }
1383
1384 BMesh *bm = self->bm;
1385
1386 Main *bmain = nullptr;
1387 BMeshToMeshParams params{};
1388 params.update_shapekey_indices = true;
1389 if (mesh->id.tag & ID_TAG_NO_MAIN) {
1390 /* Mesh might be coming from a self-contained source like object.to_mesh(). No need to remap
1391 * anything in this case. */
1392 }
1393 else {
1395 bmain = G_MAIN; /* XXX UGLY! */
1396 params.calc_object_remap = true;
1397 }
1398
1399 BM_mesh_bm_to_me(bmain, bm, mesh, &params);
1400
1401 /* We could have the user do this but if they forget blender can easy crash
1402 * since the references arrays for the objects evaluated meshes are now invalid. */
1404
1405 Py_RETURN_NONE;
1406}
1407
1409 /* Wrap. */
1410 bpy_bmesh_from_object_doc,
1411 ".. method:: from_object(object, depsgraph, *, "
1412 "cage=False, face_normals=True, vertex_normals=True)\n"
1413 "\n"
1414 " Initialize this bmesh from existing object data-block (only meshes are currently "
1415 "supported).\n"
1416 "\n"
1417 " :param object: The object data to load.\n"
1418 " :type object: :class:`bpy.types.Object`\n"
1419 " :param depsgraph: The dependency graph for evaluated data.\n"
1420 " :type depsgraph: :class:`bpy.types.Depsgraph`\n"
1421 " :param cage: Get the mesh as a deformed cage.\n"
1422 " :type cage: bool\n"
1423 " :param face_normals: Calculate face normals.\n"
1424 " :type face_normals: bool\n"
1425 " :param vertex_normals: Calculate vertex normals.\n"
1426 " :type vertex_normals: bool\n");
1427static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject *kw)
1428{
1429 static const char *kwlist[] = {
1430 "object", "depsgraph", "cage", "face_normals", "vertex_normals", nullptr};
1431 PyObject *py_object;
1432 PyObject *py_depsgraph;
1433 Object *ob, *ob_eval;
1434 Depsgraph *depsgraph;
1435 Scene *scene_eval;
1436 const Mesh *mesh_eval;
1437 bool use_cage = false;
1438 bool use_fnorm = true;
1439 bool use_vert_normal = true;
1440 const CustomData_MeshMasks data_masks = CD_MASK_BMESH;
1441
1442 BPY_BM_CHECK_OBJ(self);
1443
1444 if (!PyArg_ParseTupleAndKeywords(args,
1445 kw,
1446 "O" /* `object` */
1447 "O" /* `depsgraph` */
1448 "|$" /* Optional, keyword only arguments. */
1449 "O&" /* `cage` */
1450 "O&" /* `face_normals` */
1451 "O&" /* `vertex_normals` */
1452 ":from_object",
1453 const_cast<char **>(kwlist),
1454 &py_object,
1455 &py_depsgraph,
1457 &use_cage,
1459 &use_fnorm,
1461 &use_vert_normal) ||
1462 !(ob = static_cast<Object *>(PyC_RNA_AsPointer(py_object, "Object"))) ||
1463 !(depsgraph = static_cast<Depsgraph *>(PyC_RNA_AsPointer(py_depsgraph, "Depsgraph"))))
1464 {
1465 return nullptr;
1466 }
1467
1468 if (ob->type != OB_MESH) {
1469 PyErr_SetString(PyExc_ValueError,
1470 "from_object(...): currently only mesh objects are supported");
1471 return nullptr;
1472 }
1473
1474 const bool use_render = DEG_get_mode(depsgraph) == DAG_EVAL_RENDER;
1475 scene_eval = DEG_get_evaluated_scene(depsgraph);
1476 ob_eval = DEG_get_evaluated(depsgraph, ob);
1477 bool need_free = false;
1478
1479 /* Write the display mesh into the dummy mesh */
1480 if (use_render) {
1481 if (use_cage) {
1482 PyErr_SetString(PyExc_ValueError,
1483 "from_object(...): cage arg is unsupported when dependency graph "
1484 "evaluation mode is RENDER");
1485 return nullptr;
1486 }
1487
1488 mesh_eval = BKE_mesh_new_from_object(depsgraph, ob_eval, true, false, true);
1489 need_free = true;
1490 }
1491 else {
1492 if (use_cage) {
1493 mesh_eval = bke::mesh_get_eval_deform(depsgraph, scene_eval, ob_eval, &data_masks);
1494 }
1495 else {
1496 mesh_eval = BKE_object_get_evaluated_mesh(ob_eval);
1497 }
1498 }
1499
1500 if (mesh_eval == nullptr) {
1501 PyErr_Format(PyExc_ValueError,
1502 "from_object(...): Object '%s' has no usable mesh data",
1503 ob->id.name + 2);
1504 return nullptr;
1505 }
1506
1507 BMesh *bm = self->bm;
1508
1509 BMeshFromMeshParams params{};
1510 params.calc_face_normal = use_fnorm;
1511 params.calc_vert_normal = use_vert_normal;
1512 BM_mesh_bm_from_me(bm, mesh_eval, &params);
1513
1514 if (need_free) {
1515 BKE_id_free(nullptr, const_cast<Mesh *>(mesh_eval));
1516 }
1517
1518 Py_RETURN_NONE;
1519}
1520
1522 /* Wrap. */
1523 bpy_bmesh_from_mesh_doc,
1524 ".. method:: from_mesh(mesh, *, "
1525 "face_normals=True, vertex_normals=True, use_shape_key=False, shape_key_index=0)\n"
1526 "\n"
1527 " Initialize this bmesh from existing mesh data-block.\n"
1528 "\n"
1529 " :param mesh: The mesh data to load.\n"
1530 " :type mesh: :class:`bpy.types.Mesh`\n"
1531 " :param face_normals: Calculate face normals.\n"
1532 " :type face_normals: bool\n"
1533 " :param vertex_normals: Calculate vertex normals.\n"
1534 " :type vertex_normals: bool\n"
1535 " :param use_shape_key: Use the locations from a shape key.\n"
1536 " :type use_shape_key: bool\n"
1537 " :param shape_key_index: The shape key index to use.\n"
1538 " :type shape_key_index: int\n"
1539 "\n"
1540 " .. note::\n"
1541 "\n"
1542 " Multiple calls can be used to join multiple meshes.\n"
1543 "\n"
1544 " Custom-data layers are only copied from ``mesh`` on initialization.\n"
1545 " Further calls will copy custom-data to matching layers, layers missing on the target "
1546 "mesh won't be added.\n");
1547static PyObject *bpy_bmesh_from_mesh(BPy_BMesh *self, PyObject *args, PyObject *kw)
1548{
1549 static const char *kwlist[] = {
1550 "mesh", "face_normals", "vertex_normals", "use_shape_key", "shape_key_index", nullptr};
1551 PyObject *py_mesh;
1552 Mesh *mesh;
1553 bool use_fnorm = true;
1554 bool use_vert_normal = true;
1555 bool use_shape_key = false;
1556 int shape_key_index = 0;
1557
1558 BPY_BM_CHECK_OBJ(self);
1559
1560 if (!PyArg_ParseTupleAndKeywords(args,
1561 kw,
1562 "O" /* `mesh` */
1563 "|$" /* Optional, keyword only arguments. */
1564 "O&" /* `face_normals` */
1565 "O&" /* `vertex_normals` */
1566 "O&" /* `use_shape_key` */
1567 "i" /* `shape_key_index` */
1568 ":from_mesh",
1569 const_cast<char **>(kwlist),
1570 &py_mesh,
1572 &use_fnorm,
1574 &use_vert_normal,
1576 &use_shape_key,
1577 &shape_key_index) ||
1578 !(mesh = static_cast<Mesh *>(PyC_RNA_AsPointer(py_mesh, "Mesh"))))
1579 {
1580 return nullptr;
1581 }
1582
1583 BMesh *bm = self->bm;
1584
1585 BMeshFromMeshParams params{};
1586 params.calc_face_normal = use_fnorm;
1587 params.calc_vert_normal = use_vert_normal;
1588 params.use_shapekey = use_shape_key;
1589 params.active_shapekey = shape_key_index + 1;
1590 BM_mesh_bm_from_me(bm, mesh, &params);
1591
1592 Py_RETURN_NONE;
1593}
1594
1596 /* Wrap. */
1597 bpy_bmesh_select_flush_mode_doc,
1598 ".. method:: select_flush_mode(*, flush_down=False)\n"
1599 "\n"
1600 " Flush selection based on the current mode "
1601 ":attr:`bmesh.types.BMesh.select_mode`.\n"
1602 "\n"
1603 " :param flush_down: Flush selection down from faces to edges & verts "
1604 "or from edges to verts. "
1605 "This option is ignored when vertex selection mode is enabled.\n"
1606 " :type flush_down: bool\n");
1607static PyObject *bpy_bmesh_select_flush_mode(BPy_BMesh *self, PyObject *args, PyObject *kw)
1608{
1609 BPY_BM_CHECK_OBJ(self);
1610
1611 bool flush_down = false;
1613
1614 static const char *kwlist[] = {
1615 "flush_down",
1616 nullptr,
1617 };
1618 if (!PyArg_ParseTupleAndKeywords(args,
1619 kw,
1620 "|$" /* Optional, keyword only arguments. */
1621 "O&" /* `flush_down` */
1622 ":select_flush_mode",
1623 const_cast<char **>(kwlist),
1625 &flush_down))
1626 {
1627 return nullptr;
1628 }
1629
1630 if (flush_down) {
1632 }
1633
1634 BM_mesh_select_mode_flush_ex(self->bm, self->bm->selectmode, flag);
1635
1636 Py_RETURN_NONE;
1637}
1638
1640 /* Wrap. */
1641 bpy_bmesh_select_flush_doc,
1642 ".. method:: select_flush(select)\n"
1643 "\n"
1644 " Flush selection from vertices, independent of the current selection mode.\n"
1645 "\n"
1646 " :param select: flush selection or de-selected elements.\n"
1647 " :type select: bool\n");
1648static PyObject *bpy_bmesh_select_flush(BPy_BMesh *self, PyObject *value)
1649{
1650 int param;
1651
1652 BPY_BM_CHECK_OBJ(self);
1653
1654 if ((param = PyC_Long_AsBool(value)) == -1) {
1655 return nullptr;
1656 }
1657 BM_mesh_select_flush_from_verts(self->bm, param);
1658 Py_RETURN_NONE;
1659}
1660
1661/* ---------------------------------------------------------------------- */
1664
1666 /* Wrap. */
1667 bpy_bmesh_uv_select_flush_mode_doc,
1668 ".. method:: uv_select_flush_mode(*, flush_down=False)\n"
1669 "\n"
1670 " Flush UV selection based on the current mode :attr:`bmesh.types.BMesh.select_mode`.\n"
1671 "\n"
1672 " :param flush_down: Flush selection down from faces to edges & verts "
1673 "or from edges to verts. "
1674 "This option is ignored when vertex selection mode is enabled.\n"
1675 " :type flush_down: bool\n");
1676static PyObject *bpy_bmesh_uv_select_flush_mode(BPy_BMesh *self, PyObject *args, PyObject *kw)
1677{
1678 BPY_BM_CHECK_OBJ(self);
1679 BMesh *bm = self->bm;
1680
1681 bool flush_down = false;
1682 static const char *kwlist[] = {
1683 "flush_down",
1684 nullptr,
1685 };
1686 if (!PyArg_ParseTupleAndKeywords(args,
1687 kw,
1688 "|$" /* Optional, keyword only arguments. */
1689 "O&" /* `flush_down` */
1690 ":uv_select_flush_mode",
1691 const_cast<char **>(kwlist),
1693 &flush_down))
1694 {
1695 return nullptr;
1696 }
1697
1699 Py_RETURN_NONE;
1700}
1701
1703 /* Wrap. */
1704 bpy_bmesh_uv_select_flush_doc,
1705 ".. method:: uv_select_flush(select)\n"
1706 "\n"
1707 " Flush selection from UV vertices to edges & faces independent of the selection mode.\n"
1708 "\n"
1709 " :param select: Flush selection or de-selected elements.\n"
1710 " :type select: bool\n"
1711 "\n"
1712 " .. note::\n"
1713 "\n"
1714 " - |UV_SELECT_SYNC_TO_MESH_NEEDED|\n");
1715static PyObject *bpy_bmesh_uv_select_flush(BPy_BMesh *self, PyObject *value)
1716{
1717 const char *error_prefix = "uv_select_flush(...)";
1718 int param;
1719
1720 BPY_BM_CHECK_OBJ(self);
1721
1722 if ((param = PyC_Long_AsBool(value)) == -1) {
1723 return nullptr;
1724 }
1725 BMesh *bm = self->bm;
1726 /* While sync doesn't need to be valid,
1727 * failing to make it valid causes selection functions to assert, so require it to be valid. */
1728 if (bpy_bm_check_uv_select_sync_valid(bm, error_prefix) == -1) {
1729 return nullptr;
1730 }
1732 Py_RETURN_NONE;
1733}
1734
1736 /* Wrap. */
1737 bpy_bmesh_uv_select_flush_shared_doc,
1738 ".. method:: uv_select_flush_shared(select)\n"
1739 "\n"
1740 " Flush selection from UV vertices to contiguous UV's independent of the selection mode.\n"
1741 "\n"
1742 " :param select: Flush selection or de-selected elements.\n"
1743 " :type select: bool\n"
1744 "\n"
1745 " .. note::\n"
1746 "\n"
1747 " - |UV_SELECT_SYNC_TO_MESH_NEEDED|\n");
1748static PyObject *bpy_bmesh_uv_select_flush_shared(BPy_BMesh *self, PyObject *value)
1749{
1750 const char *error_prefix = "uv_select_flush_shared(...)";
1751 int param;
1752
1753 BPY_BM_CHECK_OBJ(self);
1754
1755 if ((param = PyC_Long_AsBool(value)) == -1) {
1756 return nullptr;
1757 }
1758 BMesh *bm = self->bm;
1759 /* While sync doesn't need to be valid,
1760 * failing to make it valid causes selection functions to assert, so require it to be valid. */
1761 if (bpy_bm_check_uv_select_sync_valid(bm, error_prefix) == -1) {
1762 return nullptr;
1763 }
1764 if (param) {
1766 }
1767 else {
1769 }
1770 Py_RETURN_NONE;
1771}
1772
1774 /* Wrap. */
1775 bpy_bmesh_uv_select_sync_from_mesh_doc,
1776 ".. method:: uv_select_sync_from_mesh(*, "
1777 "sticky_select_mode='SHARED_LOCATION')\n"
1778 "\n"
1779 " Sync selection from mesh to UVs.\n"
1780 "\n"
1781 " :param sticky_select_mode: Behavior when flushing from the mesh to UV selection "
1782 "|UV_STICKY_SELECT_MODE_REF|. "
1783 "This should only be used when preparing to create a UV selection.\n"
1784 " :type sticky_select_mode: |UV_STICKY_SELECT_MODE_TYPE|\n"
1785 "\n"
1786 " .. note::\n"
1787 "\n"
1788 " - |UV_SELECT_SYNC_TO_MESH_NEEDED|\n");
1789static PyObject *bpy_bmesh_uv_select_sync_from_mesh(BPy_BMesh *self, PyObject *args, PyObject *kw)
1790{
1791 static const char *kwlist[] = {
1792 "sticky_select_mode",
1793 nullptr,
1794 };
1795
1796 BPY_BM_CHECK_OBJ(self);
1797
1799
1800 if (!PyArg_ParseTupleAndKeywords(args,
1801 kw,
1802 "|$" /* Optional, keyword only arguments. */
1803 "O&" /* `sticky_select_mode` */
1804 ":uv_select_sync_from_mesh",
1805 const_cast<char **>(kwlist),
1807 &uv_sticky_select_mode))
1808 {
1809 return nullptr;
1810 }
1811
1812 BMesh *bm = self->bm;
1813 switch (uv_sticky_select_mode.value_found) {
1814 case UV_STICKY_LOCATION: {
1815 const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_PROP_FLOAT2);
1816 if (cd_loop_uv_offset == -1) {
1817 PyErr_SetString(PyExc_ValueError, "sticky_select_mode='SHARED_LOCATION' requires UV's");
1818 return nullptr;
1819 }
1821 break;
1822 }
1823 case UV_STICKY_DISABLE: {
1825 break;
1826 }
1827 case UV_STICKY_VERT: {
1829 break;
1830 }
1831 }
1832
1833 Py_RETURN_NONE;
1834}
1835
1837 /* Wrap. */
1838 bpy_bmesh_uv_select_sync_to_mesh_doc,
1839 ".. method:: uv_select_sync_to_mesh()\n"
1840 "\n"
1841 " Sync selection from UVs to the mesh.\n");
1843{
1844 const char *error_prefix = "uv_select_sync_to_mesh(...)";
1845
1846 BPY_BM_CHECK_OBJ(self);
1847
1848 BMesh *bm = self->bm;
1849 if (bpy_bm_check_uv_select_sync_valid(bm, error_prefix) == -1) {
1850 return nullptr;
1851 }
1853 Py_RETURN_NONE;
1854}
1855
1857 /* Wrap. */
1858 bpy_bmesh_uv_select_foreach_set_doc,
1859 ".. method:: uv_select_foreach_set(select, /, *, "
1860 "loop_verts=(), loop_edges=(), faces=(), sticky_select_mode='SHARED_LOCATION')\n"
1861 "\n"
1862 " Set the UV selection state for loop-vertices, loop-edges & faces.\n"
1863 "\n"
1864 " This is a close equivalent to selecting in the UV editor.\n"
1865 "\n"
1866 " :param select: The selection state to set.\n"
1867 " :type select: bool\n"
1868 " :param loop_verts: Loop verts to operate on.\n"
1869 " :type loop_verts: Iterable[:class:`bmesh.types.BMLoop`]\n"
1870 " :param loop_edges: Loop edges to operate on.\n"
1871 " :type loop_edges: Iterable[:class:`bmesh.types.BMLoop`]\n"
1872 " :param faces: Faces to operate on.\n"
1873 " :type faces: Iterable[:class:`bmesh.types.BMFace`]\n"
1874 " :param sticky_select_mode: See |UV_STICKY_SELECT_MODE_REF|.\n"
1875 " :type sticky_select_mode: |UV_STICKY_SELECT_MODE_TYPE|\n"
1876 "\n"
1877 " .. note::\n"
1878 "\n"
1879 " - |UV_SELECT_FLUSH_MODE_NEEDED|\n"
1880 " - |UV_SELECT_SYNC_TO_MESH_NEEDED|\n");
1881static PyObject *bpy_bmesh_uv_select_foreach_set(BPy_BMesh *self, PyObject *args, PyObject *kw)
1882{
1883 const char *error_prefix = "uv_select_foreach_set(...)";
1884 static const char *kwlist[] = {
1885 "", /* `select` */
1886 "loop_verts",
1887 "loop_edges",
1888 "faces",
1889 "sticky_select_mode",
1890 nullptr,
1891 };
1892 BMesh *bm;
1893 bool use_select = false;
1894 PyObject *py_loop_verts = nullptr;
1895 PyObject *py_loop_edges = nullptr;
1896 PyObject *py_faces = nullptr;
1898
1899 BPY_BM_CHECK_OBJ(self);
1900
1901 if (!PyArg_ParseTupleAndKeywords(args,
1902 kw,
1903 "O&" /* `select` */
1904 "|$" /* Optional, keyword only arguments. */
1905 "O" /* `loop_verts` */
1906 "O" /* `loop_edges` */
1907 "O" /* `faces` */
1908 "O&" /* `sticky_select_mode` */
1909 ":uv_select_foreach_set",
1910 const_cast<char **>(kwlist),
1912 &use_select,
1913 &py_loop_verts,
1914 &py_loop_edges,
1915 &py_faces,
1917 &uv_sticky_select_mode))
1918 {
1919 return nullptr;
1920 }
1921
1922 bm = self->bm;
1923 if (bpy_bm_check_uv_select_sync_valid(bm, error_prefix) == -1) {
1924 return nullptr;
1925 }
1926 const bool shared = uv_sticky_select_mode.value_found == UV_STICKY_LOCATION;
1927 const int cd_loop_uv_offset = shared ? bpy_bm_uv_layer_offset_or_error(bm, error_prefix) : -1;
1928 if (shared && (cd_loop_uv_offset == -1)) {
1929 return nullptr;
1930 }
1931
1932 Py_ssize_t loop_vert_array_num = 0;
1933 Py_ssize_t loop_edge_array_num = 0;
1934 Py_ssize_t face_array_num = 0;
1935 BMLoop **loop_vert_array = nullptr;
1936 BMLoop **loop_edge_array = nullptr;
1937 BMFace **face_array = nullptr;
1938
1939 bool ok = true;
1940 if (ok && py_loop_verts) {
1941 BMesh *bm_test = nullptr;
1942 if (!(loop_vert_array = BPy_BMLoop_PySeq_As_Array(&bm_test,
1943 py_loop_verts,
1944 0,
1945 PY_SSIZE_T_MAX,
1946 &loop_vert_array_num,
1947 true,
1948 true,
1949 error_prefix)))
1950 {
1951 ok = false;
1952 }
1953 else if (bm_test && bpy_bm_check_bm_match_or_error(bm, bm_test, error_prefix) == -1) {
1954 ok = false;
1955 }
1956 }
1957 if (ok && py_loop_edges) {
1958 BMesh *bm_test = nullptr;
1959 if (!(loop_edge_array = BPy_BMLoop_PySeq_As_Array(&bm_test,
1960 py_loop_edges,
1961 0,
1962 PY_SSIZE_T_MAX,
1963 &loop_edge_array_num,
1964 true,
1965 true,
1966 error_prefix)))
1967 {
1968 ok = false;
1969 }
1970 else if (bm_test && bpy_bm_check_bm_match_or_error(bm, bm_test, error_prefix) == -1) {
1971 ok = false;
1972 }
1973 }
1974 if (ok && py_faces) {
1975 BMesh *bm_test = nullptr;
1976 if (!(face_array = BPy_BMFace_PySeq_As_Array(
1977 &bm_test, py_faces, 0, PY_SSIZE_T_MAX, &face_array_num, true, true, error_prefix)))
1978 {
1979 ok = false;
1980 }
1981 else if (bm_test && bpy_bm_check_bm_match_or_error(bm, bm_test, error_prefix) == -1) {
1982 ok = false;
1983 }
1984 }
1985
1986 /* TODO: support different "sticky" modes. */
1987 if (ok) {
1989 use_select,
1990 cd_loop_uv_offset,
1991 Span(loop_vert_array, loop_vert_array_num),
1992 Span(loop_edge_array, loop_edge_array_num),
1993 Span(face_array, face_array_num));
1994 }
1995
1996 PyMem_FREE(loop_vert_array);
1997 PyMem_FREE(loop_edge_array);
1998 PyMem_FREE(face_array);
1999
2000 if (ok == false) {
2001 /* The error has been raised. */
2002 return nullptr;
2003 }
2004 Py_RETURN_NONE;
2005}
2006
2008 /* Wrap. */
2009 bpy_bmesh_uv_select_foreach_set_from_mesh_doc,
2010 ".. method:: uv_select_foreach_set_from_mesh(select, /, *, "
2011 "verts=(), edges=(), faces=(), sticky_select_mode='SHARED_LOCATION')\n"
2012 "\n"
2013 " Select or de-select mesh elements, updating the UV selection.\n"
2014 "\n"
2015 " An equivalent to selecting from the 3D viewport "
2016 "for selection operations that support maintaining a synchronized UV selection.\n"
2017 "\n"
2018 " :param select: The selection state to set.\n"
2019 " :type select: bool\n"
2020 " :param verts: Verts to operate on.\n"
2021 " :type verts: Iterable[:class:`bmesh.types.BMVert`]\n"
2022 " :param edges: Edges to operate on.\n"
2023 " :type edges: Iterable[:class:`bmesh.types.BMEdge`]\n"
2024 " :param faces: Faces to operate on.\n"
2025 " :type faces: Iterable[:class:`bmesh.types.BMFace`]\n"
2026 " :param sticky_select_mode: See |UV_STICKY_SELECT_MODE_REF|.\n"
2027 " :type sticky_select_mode: |UV_STICKY_SELECT_MODE_TYPE|\n");
2029 PyObject *args,
2030 PyObject *kw)
2031{
2032 const char *error_prefix = "uv_select_foreach_set_from_mesh(...)";
2033 static const char *kwlist[] = {
2034 "", /* `select` */
2035 "verts",
2036 "edges",
2037 "faces",
2038 "sticky_select_mode",
2039 nullptr,
2040 };
2041 bool use_select = false;
2042 PyObject *py_verts = nullptr;
2043 PyObject *py_edges = nullptr;
2044 PyObject *py_faces = nullptr;
2046
2047 BPY_BM_CHECK_OBJ(self);
2048
2049 if (!PyArg_ParseTupleAndKeywords(args,
2050 kw,
2051 "O&" /* `select` */
2052 "|$" /* Optional, keyword only arguments. */
2053 "O" /* `verts` */
2054 "O" /* `edges` */
2055 "O" /* `faces` */
2056 "O&" /* `sticky_select_mode` */
2057 ":uv_select_foreach_set_from_mesh",
2058 const_cast<char **>(kwlist),
2060 &use_select,
2061 &py_verts,
2062 &py_edges,
2063 &py_faces,
2065 &uv_sticky_select_mode))
2066 {
2067 return nullptr;
2068 }
2069
2070 BMesh *bm = self->bm;
2071 if (bpy_bm_check_uv_select_sync_valid(bm, error_prefix) == -1) {
2072 return nullptr;
2073 }
2074 const bool shared = uv_sticky_select_mode.value_found == UV_STICKY_LOCATION;
2075 const int cd_loop_uv_offset = shared ? bpy_bm_uv_layer_offset_or_error(bm, error_prefix) : -1;
2076 if (shared && (cd_loop_uv_offset == -1)) {
2077 return nullptr;
2078 }
2079
2080 Py_ssize_t vert_array_num = 0;
2081 Py_ssize_t edge_array_num = 0;
2082 Py_ssize_t face_array_num = 0;
2083 BMVert **vert_array = nullptr;
2084 BMEdge **edge_array = nullptr;
2085 BMFace **face_array = nullptr;
2086
2087 bool ok = true;
2088 if (ok && py_verts) {
2089 BMesh *bm_test = nullptr;
2090 if (!(vert_array = BPy_BMVert_PySeq_As_Array(
2091 &bm_test, py_verts, 0, PY_SSIZE_T_MAX, &vert_array_num, true, true, error_prefix)))
2092 {
2093 ok = false;
2094 }
2095 else if (bm_test && bpy_bm_check_bm_match_or_error(bm, bm_test, error_prefix) == -1) {
2096 ok = false;
2097 }
2098 }
2099 if (ok && py_edges) {
2100 BMesh *bm_test = nullptr;
2101 if (!(edge_array = BPy_BMEdge_PySeq_As_Array(
2102 &bm_test, py_edges, 0, PY_SSIZE_T_MAX, &edge_array_num, true, true, error_prefix)))
2103 {
2104 ok = false;
2105 }
2106 else if (bm_test && bpy_bm_check_bm_match_or_error(bm, bm_test, error_prefix) == -1) {
2107 ok = false;
2108 }
2109 }
2110 if (ok && py_faces) {
2111 BMesh *bm_test = nullptr;
2112 if (!(face_array = BPy_BMFace_PySeq_As_Array(
2113 &bm_test, py_faces, 0, PY_SSIZE_T_MAX, &face_array_num, true, true, error_prefix)))
2114 {
2115 ok = false;
2116 }
2117 else if (bm_test && bpy_bm_check_bm_match_or_error(bm, bm_test, error_prefix) == -1) {
2118 ok = false;
2119 }
2120 }
2121
2122 if (ok) {
2123 const BMUVSelectPickParams uv_pick_params = {
2124 /*cd_loop_uv_offset*/ cd_loop_uv_offset,
2125 /*shared*/ shared,
2126 };
2128 use_select,
2129 uv_pick_params,
2130 Span(vert_array, vert_array_num),
2131 Span(edge_array, edge_array_num),
2132 Span(face_array, face_array_num));
2133 }
2134
2135 PyMem_FREE(vert_array);
2136 PyMem_FREE(edge_array);
2137 PyMem_FREE(face_array);
2138
2139 if (ok == false) {
2140 /* The error has been raised. */
2141 return nullptr;
2142 }
2143 Py_RETURN_NONE;
2144}
2145
2147
2149 /* Wrap. */
2150 bpy_bmesh_normal_update_doc,
2151 ".. method:: normal_update()\n"
2152 "\n"
2153 " Update normals of mesh faces and verts.\n"
2154 "\n"
2155 " .. note::\n"
2156 "\n"
2157 " The normal of any vertex where :attr:`is_wire` is True will be a zero vector.\n");
2158static PyObject *bpy_bmesh_normal_update(BPy_BMesh *self)
2159{
2160 BPY_BM_CHECK_OBJ(self);
2161
2163
2164 Py_RETURN_NONE;
2165}
2166
2168 /* Wrap. */
2169 bpy_bmesh_transform_doc,
2170 ".. method:: transform(matrix, *, filter=None)\n"
2171 "\n"
2172 " Transform the mesh (optionally filtering flagged data only).\n"
2173 "\n"
2174 " :param matrix: 4x4 transform matrix.\n"
2175 " :type matrix: :class:`mathutils.Matrix`\n"
2176 " :param filter: Flag to filter vertices.\n"
2177 " :type filter: set[Literal[" BPY_BM_HFLAG_ALL_STR "]] | None\n");
2178static PyObject *bpy_bmesh_transform(BPy_BMElem *self, PyObject *args, PyObject *kw)
2179{
2180 MatrixObject *mat;
2181 PyObject *filter = nullptr;
2182 PyC_TypeOrNone filter_or_none = {&PySet_Type, &filter};
2183 int filter_flags = 0;
2184
2185 BPY_BM_CHECK_OBJ(self);
2186
2187 static const char *_keywords[] = {"matrix", "filter", nullptr};
2188 static _PyArg_Parser _parser = {
2189 "O!" /* `matrix` */
2190 "|$" /* Optional, keyword only arguments. */
2191 "O&" /* `filter` */
2192 ":transform",
2193 _keywords,
2194 nullptr,
2195 };
2196 if (!_PyArg_ParseTupleAndKeywordsFast(
2197 args, kw, &_parser, &matrix_Type, &mat, PyC_ParseTypeOrNone, &filter_or_none))
2198 {
2199 return nullptr;
2200 }
2201
2202 BMVert *eve;
2203 BMIter iter;
2204 void *mat_ptr;
2205
2206 if (BaseMath_ReadCallback(mat) == -1) {
2207 return nullptr;
2208 }
2209 if (mat->col_num != 4 || mat->row_num != 4) {
2210 PyErr_SetString(PyExc_ValueError, "expected a 4x4 matrix");
2211 return nullptr;
2212 }
2213
2214 if (filter != nullptr &&
2215 PyC_FlagSet_ToBitfield(bpy_bm_hflag_all_flags, filter, &filter_flags, "bm.transform") == -1)
2216 {
2217 return nullptr;
2218 }
2219
2220 mat_ptr = mat->matrix;
2221
2222 if (!filter_flags) {
2223 BM_ITER_MESH (eve, &iter, self->bm, BM_VERTS_OF_MESH) {
2224 mul_m4_v3(static_cast<float (*)[4]>(mat_ptr), eve->co);
2225 }
2226 }
2227 else {
2228 const char filter_flags_ch = char(filter_flags);
2229 BM_ITER_MESH (eve, &iter, self->bm, BM_VERTS_OF_MESH) {
2230 if (BM_elem_flag_test(eve, filter_flags_ch)) {
2231 mul_m4_v3(static_cast<float (*)[4]>(mat_ptr), eve->co);
2232 }
2233 }
2234 }
2235
2236 Py_RETURN_NONE;
2237}
2238
2240 /* Wrap. */
2241 bpy_bmesh_calc_volume_doc,
2242 ".. method:: calc_volume(*, signed=False)\n"
2243 "\n"
2244 " Calculate mesh volume based on face normals.\n"
2245 "\n"
2246 " :param signed: when signed is true, negative values may be returned.\n"
2247 " :type signed: bool\n"
2248 " :return: The volume of the mesh.\n"
2249 " :rtype: float\n");
2250static PyObject *bpy_bmesh_calc_volume(BPy_BMElem *self, PyObject *args, PyObject *kw)
2251{
2252 static const char *kwlist[] = {"signed", nullptr};
2253 bool is_signed = false;
2254
2255 BPY_BM_CHECK_OBJ(self);
2256
2257 if (!PyArg_ParseTupleAndKeywords(args,
2258 kw,
2259 "|$" /* Optional, keyword only arguments. */
2260 "O&" /* `signed` */
2261 ":calc_volume",
2262 const_cast<char **>(kwlist),
2264 &is_signed))
2265 {
2266 return nullptr;
2267 }
2268
2269 return PyFloat_FromDouble(BM_mesh_calc_volume(self->bm, is_signed));
2270}
2271
2273 /* Wrap. */
2274 bpy_bmesh_calc_loop_triangles_doc,
2275 ".. method:: calc_loop_triangles()\n"
2276 "\n"
2277 " Calculate triangle tessellation from quads/ngons.\n"
2278 "\n"
2279 " :return: The triangulated faces.\n"
2280 " :rtype: list[tuple[:class:`bmesh.types.BMLoop`, "
2281 ":class:`bmesh.types.BMLoop`, "
2282 ":class:`bmesh.types.BMLoop`]]\n");
2284{
2285 int corner_tris_tot;
2286
2287 PyObject *ret;
2288
2289 BPY_BM_CHECK_OBJ(self);
2290
2291 BMesh *bm = self->bm;
2292
2293 corner_tris_tot = poly_to_tri_count(bm->totface, bm->totloop);
2294 Array<std::array<BMLoop *, 3>> corner_tris(corner_tris_tot);
2295 BM_mesh_calc_tessellation(bm, corner_tris);
2296
2297 ret = PyList_New(corner_tris_tot);
2298 for (int i = 0; i < corner_tris_tot; i++) {
2299 PyList_SET_ITEM(ret, i, BPy_BMLoop_Array_As_Tuple(bm, corner_tris[i].data(), 3));
2300 }
2301
2302 return ret;
2303}
2304
2305/* Elem
2306 * ---- */
2307
2309 /* Wrap. */
2310 bpy_bm_elem_select_set_doc,
2311 ".. method:: select_set(select)\n"
2312 "\n"
2313 " Set the selection.\n"
2314 " This is different from the *select* attribute because it updates the selection "
2315 "state of associated geometry.\n"
2316 "\n"
2317 " :param select: Select or de-select.\n"
2318 " :type select: bool\n"
2319 "\n"
2320 " .. note::\n"
2321 "\n"
2322 " This flushes selection down (e.g. selecting a face also selects its edges and "
2323 "vertices), but not up (e.g. de-selecting a vertex won't de-select faces that use it). "
2324 "Before finishing with a mesh, flushing is typically still needed.\n");
2325static PyObject *bpy_bm_elem_select_set(BPy_BMElem *self, PyObject *value)
2326{
2327 int param;
2328
2329 BPY_BM_CHECK_OBJ(self);
2330
2331 if ((param = PyC_Long_AsBool(value)) == -1) {
2332 return nullptr;
2333 }
2334
2335 BM_elem_select_set(self->bm, self->ele, param);
2336
2337 Py_RETURN_NONE;
2338}
2339
2341 /* Wrap. */
2342 bpy_bm_elem_hide_set_doc,
2343 ".. method:: hide_set(hide)\n"
2344 "\n"
2345 " Set the hide state.\n"
2346 " This is different from the *hide* attribute because it updates the selection and "
2347 "hide state of associated geometry.\n"
2348 "\n"
2349 " :param hide: Hidden or visible.\n"
2350 " :type hide: bool\n");
2351static PyObject *bpy_bm_elem_hide_set(BPy_BMElem *self, PyObject *value)
2352{
2353 int param;
2354
2355 BPY_BM_CHECK_OBJ(self);
2356
2357 if ((param = PyC_Long_AsBool(value)) == -1) {
2358 return nullptr;
2359 }
2360
2361 BM_elem_hide_set(self->bm, self->ele, param);
2362
2363 Py_RETURN_NONE;
2364}
2365
2367 /* Wrap. */
2368 bpy_bm_elem_copy_from_doc,
2369 ".. method:: copy_from(other)\n"
2370 "\n"
2371 " Copy values from another element of matching type.\n"
2372 "\n"
2373 " :param other: Another element of the same type to copy from.\n"
2374 " :type other: Self\n");
2375static PyObject *bpy_bm_elem_copy_from(BPy_BMElem *self, BPy_BMElem *value)
2376{
2377 BPY_BM_CHECK_OBJ(self);
2378
2379 if (Py_TYPE(self) != Py_TYPE(value)) {
2380 PyErr_Format(PyExc_TypeError,
2381 "expected element of type '%.200s' not '%.200s'",
2382 Py_TYPE(self)->tp_name,
2383 Py_TYPE(value)->tp_name);
2384 return nullptr;
2385 }
2386
2387 if (value->ele != self->ele) {
2388 switch (self->ele->head.htype) {
2389 case BM_VERT: {
2391 value->bm->vdata, self->bm->vdata, CD_MASK_BM_ELEM_PYPTR);
2392 BM_elem_attrs_copy(self->bm,
2393 cd_vert_map,
2394 reinterpret_cast<const BMVert *>(value->ele),
2395 reinterpret_cast<BMVert *>(self->ele));
2396 break;
2397 }
2398 case BM_EDGE: {
2400 value->bm->edata, self->bm->edata, CD_MASK_BM_ELEM_PYPTR);
2401 BM_elem_attrs_copy(self->bm,
2402 cd_edge_map,
2403 reinterpret_cast<const BMEdge *>(value->ele),
2404 reinterpret_cast<BMEdge *>(self->ele));
2405 break;
2406 }
2407 case BM_FACE: {
2409 value->bm->pdata, self->bm->pdata, CD_MASK_BM_ELEM_PYPTR);
2410 BM_elem_attrs_copy(self->bm,
2411 cd_face_map,
2412 reinterpret_cast<const BMFace *>(value->ele),
2413 reinterpret_cast<BMFace *>(self->ele));
2414 break;
2415 }
2416 case BM_LOOP: {
2418 value->bm->ldata, self->bm->ldata, CD_MASK_BM_ELEM_PYPTR);
2419 BM_elem_attrs_copy(self->bm,
2420 cd_loop_map,
2421 reinterpret_cast<const BMLoop *>(value->ele),
2422 reinterpret_cast<BMLoop *>(self->ele));
2423 break;
2424 }
2425 }
2426 }
2427
2428 Py_RETURN_NONE;
2429}
2430
2431/* Vert
2432 * ---- */
2433
2435 /* Wrap. */
2436 bpy_bmvert_copy_from_vert_interp_doc,
2437 ".. method:: copy_from_vert_interp(vert_pair, fac)\n"
2438 "\n"
2439 " Interpolate the customdata from a vert between 2 other verts.\n"
2440 "\n"
2441 " :param vert_pair: The verts between which to interpolate data from.\n"
2442 " :type vert_pair: Sequence[:class:`bmesh.types.BMVert`]\n"
2443 " :param fac: The interpolation factor.\n"
2444 " :type fac: float\n");
2445static PyObject *bpy_bmvert_copy_from_vert_interp(BPy_BMVert *self, PyObject *args)
2446{
2447 const char *error_prefix = "BMVert.copy_from_vert_interp(...)";
2448 PyObject *vert_seq;
2449 float fac;
2450
2451 BPY_BM_CHECK_OBJ(self);
2452
2453 if (!PyArg_ParseTuple(args,
2454 "O" /* `vert_pair` */
2455 "f" /* `fac` */
2456 ":BMVert.copy_from_vert_interp",
2457 &vert_seq,
2458 &fac))
2459 {
2460 return nullptr;
2461 }
2462
2463 BMesh *bm = self->bm;
2464
2465 Py_ssize_t vert_seq_num; /* Always 2. */
2466 BMVert **vert_array = BPy_BMVert_PySeq_As_Array(
2467 &bm, vert_seq, 2, 2, &vert_seq_num, true, true, error_prefix);
2468
2469 if (vert_array == nullptr) {
2470 return nullptr;
2471 }
2472
2473 BM_data_interp_from_verts(bm, vert_array[0], vert_array[1], self->v, clamp_f(fac, 0.0f, 1.0f));
2474
2475 PyMem_FREE(vert_array);
2476 Py_RETURN_NONE;
2477}
2478
2480 /* Wrap. */
2481 bpy_bmvert_copy_from_face_interp_doc,
2482 ".. method:: copy_from_face_interp(face)\n"
2483 "\n"
2484 " Interpolate the customdata from a face onto this vert (the vert should "
2485 "overlap the face).\n"
2486 "\n"
2487 " :param face: The face to interpolate data from.\n"
2488 " :type face: :class:`bmesh.types.BMFace`\n");
2489static PyObject *bpy_bmvert_copy_from_face_interp(BPy_BMVert *self, PyObject *args)
2490{
2491 const char *error_prefix = "copy_from_face_interp(...)";
2492 BPy_BMFace *py_face = nullptr;
2493
2494 BPY_BM_CHECK_OBJ(self);
2495
2496 if (!PyArg_ParseTuple(args,
2497 "O!" /* `face` */
2498 ":BMVert.copy_from_face_interp",
2500 &py_face))
2501 {
2502 return nullptr;
2503 }
2504
2505 BMesh *bm = self->bm;
2506
2507 BPY_BM_CHECK_SOURCE_OBJ(bm, error_prefix, py_face);
2508
2509 BM_vert_interp_from_face(bm, self->v, py_face->f);
2510
2511 Py_RETURN_NONE;
2512}
2513
2515 /* Wrap. */
2516 bpy_bmvert_calc_edge_angle_doc,
2517 ".. method:: calc_edge_angle(fallback=None)\n"
2518 "\n"
2519 " Return the angle between this vert's two connected edges.\n"
2520 "\n"
2521 " :param fallback: return this when the vert doesn't have 2 edges\n"
2522 " (instead of raising a :exc:`ValueError`).\n"
2523 " :type fallback: Any\n"
2524 " :return: Angle between edges in radians.\n"
2525 " :rtype: float\n");
2526static PyObject *bpy_bmvert_calc_edge_angle(BPy_BMVert *self, PyObject *args)
2527{
2528 const float angle_invalid = -1.0f;
2529 float angle;
2530 PyObject *fallback = nullptr;
2531
2532 BPY_BM_CHECK_OBJ(self);
2533
2534 if (!PyArg_ParseTuple(args,
2535 "|" /* Optional arguments. */
2536 "O" /* `fallback` */
2537 ":calc_edge_angle",
2538 &fallback))
2539 {
2540 return nullptr;
2541 }
2542
2543 angle = BM_vert_calc_edge_angle_ex(self->v, angle_invalid);
2544
2545 if (angle == angle_invalid) {
2546 /* avoid exception */
2547 if (fallback) {
2548 Py_INCREF(fallback);
2549 return fallback;
2550 }
2551
2552 PyErr_SetString(PyExc_ValueError,
2553 "BMVert.calc_edge_angle(): "
2554 "vert must connect to exactly 2 edges");
2555 return nullptr;
2556 }
2557
2558 return PyFloat_FromDouble(angle);
2559}
2560
2562 /* Wrap. */
2563 bpy_bmvert_calc_shell_factor_doc,
2564 ".. method:: calc_shell_factor()\n"
2565 "\n"
2566 " Return a multiplier calculated based on the sharpness of the vertex.\n"
2567 " Where a flat surface gives 1.0, and higher values sharper edges.\n"
2568 " This is used to maintain shell thickness when offsetting verts along their normals.\n"
2569 "\n"
2570 " :return: offset multiplier\n"
2571 " :rtype: float\n");
2573{
2574 BPY_BM_CHECK_OBJ(self);
2575 return PyFloat_FromDouble(BM_vert_calc_shell_factor(self->v));
2576}
2577
2579 /* Wrap. */
2580 bpy_bmvert_normal_update_doc,
2581 ".. method:: normal_update()\n"
2582 "\n"
2583 " Update vertex normal.\n"
2584 " This does not update the normals of adjoining faces.\n"
2585 "\n"
2586 " .. note::\n"
2587 "\n"
2588 " The vertex normal will be a zero vector if vertex :attr:`is_wire` is True.\n");
2590{
2591 BPY_BM_CHECK_OBJ(self);
2592
2593 BM_vert_normal_update(self->v);
2594
2595 Py_RETURN_NONE;
2596}
2597
2598/* Edge
2599 * ---- */
2600
2602 /* Wrap. */
2603 bpy_bmedge_calc_length_doc,
2604 ".. method:: calc_length()\n"
2605 "\n"
2606 " Return the length of the edge.\n"
2607 "\n"
2608 " :return: The length between both verts.\n"
2609 " :rtype: float\n");
2610static PyObject *bpy_bmedge_calc_length(BPy_BMEdge *self)
2611{
2612 BPY_BM_CHECK_OBJ(self);
2613 return PyFloat_FromDouble(len_v3v3(self->e->v1->co, self->e->v2->co));
2614}
2615
2617 /* Wrap. */
2618 bpy_bmedge_calc_face_angle_doc,
2619 ".. method:: calc_face_angle(fallback=None)\n"
2620 "\n"
2621 " Return the angle between this edge's two connected faces.\n"
2622 "\n"
2623 " :param fallback: return this when the edge doesn't have 2 faces\n"
2624 " (instead of raising a :exc:`ValueError`).\n"
2625 " :type fallback: Any\n"
2626 " :return: The angle between 2 connected faces in radians.\n"
2627 " :rtype: float\n");
2628static PyObject *bpy_bmedge_calc_face_angle(BPy_BMEdge *self, PyObject *args)
2629{
2630 const float angle_invalid = -1.0f;
2631 float angle;
2632 PyObject *fallback = nullptr;
2633
2634 BPY_BM_CHECK_OBJ(self);
2635
2636 if (!PyArg_ParseTuple(args,
2637 "|" /* Optional arguments. */
2638 "O" /* `fallback` */
2639 ":calc_face_angle",
2640 &fallback))
2641 {
2642 return nullptr;
2643 }
2644
2645 angle = BM_edge_calc_face_angle_ex(self->e, angle_invalid);
2646
2647 if (angle == angle_invalid) {
2648 /* avoid exception */
2649 if (fallback) {
2650 Py_INCREF(fallback);
2651 return fallback;
2652 }
2653
2654 PyErr_SetString(PyExc_ValueError,
2655 "BMEdge.calc_face_angle(): "
2656 "edge doesn't use 2 faces");
2657 return nullptr;
2658 }
2659
2660 return PyFloat_FromDouble(angle);
2661}
2662
2664 /* Wrap. */
2665 bpy_bmedge_calc_face_angle_signed_doc,
2666 ".. method:: calc_face_angle_signed(fallback=None)\n"
2667 "\n"
2668 " Return the signed angle between this edge's two connected faces.\n"
2669 "\n"
2670 " :param fallback: return this when the edge doesn't have 2 faces\n"
2671 " (instead of raising a :exc:`ValueError`).\n"
2672 " :type fallback: Any\n"
2673 " :return: The angle between 2 connected faces in radians (negative for concave join).\n"
2674 " :rtype: float\n");
2675static PyObject *bpy_bmedge_calc_face_angle_signed(BPy_BMEdge *self, PyObject *args)
2676{
2677 const float angle_invalid = -FLT_MAX;
2678 float angle;
2679 PyObject *fallback = nullptr;
2680
2681 BPY_BM_CHECK_OBJ(self);
2682
2683 if (!PyArg_ParseTuple(args,
2684 "|" /* Optional arguments. */
2685 "O" /* `fallback` */
2686 ":calc_face_angle_signed",
2687 &fallback))
2688 {
2689 return nullptr;
2690 }
2691
2692 angle = BM_edge_calc_face_angle_signed_ex(self->e, angle_invalid);
2693
2694 if (angle == angle_invalid) {
2695 /* avoid exception */
2696 if (fallback) {
2697 Py_INCREF(fallback);
2698 return fallback;
2699 }
2700
2701 PyErr_SetString(PyExc_ValueError,
2702 "BMEdge.calc_face_angle_signed(): "
2703 "edge doesn't use 2 faces");
2704 return nullptr;
2705 }
2706
2707 return PyFloat_FromDouble(angle);
2708}
2709
2711 /* Wrap. */
2712 bpy_bmedge_calc_tangent_doc,
2713 ".. method:: calc_tangent(loop)\n"
2714 "\n"
2715 " Return the tangent at this edge relative to a face (pointing inward into the face).\n"
2716 " This uses the face normal for calculation.\n"
2717 "\n"
2718 " :param loop: The loop used for tangent calculation.\n"
2719 " :type loop: :class:`bmesh.types.BMLoop`\n"
2720 " :return: a normalized vector.\n"
2721 " :rtype: :class:`mathutils.Vector`\n");
2722static PyObject *bpy_bmedge_calc_tangent(BPy_BMEdge *self, PyObject *args)
2723{
2724 BPy_BMLoop *py_loop;
2725 BPY_BM_CHECK_OBJ(self);
2726
2727 if (!PyArg_ParseTuple(args,
2728 "O!" /* `loop` */
2729 ":BMEdge.calc_tangent",
2731 &py_loop))
2732 {
2733 return nullptr;
2734 }
2735
2736 float vec[3];
2737 BPY_BM_CHECK_OBJ(py_loop);
2738 /* no need to check if they are from the same mesh or even connected */
2739 BM_edge_calc_face_tangent(self->e, py_loop->l, vec);
2740 return Vector_CreatePyObject(vec, 3, nullptr);
2741}
2742
2744 /* Wrap. */
2745 bpy_bmedge_other_vert_doc,
2746 ".. method:: other_vert(vert)\n"
2747 "\n"
2748 " Return the other vertex on this edge or None if the vertex is not used by this edge.\n"
2749 "\n"
2750 " :param vert: a vert in this edge.\n"
2751 " :type vert: :class:`bmesh.types.BMVert`\n"
2752 " :return: The edge's other vert.\n"
2753 " :rtype: :class:`bmesh.types.BMVert` | None\n");
2754static PyObject *bpy_bmedge_other_vert(BPy_BMEdge *self, BPy_BMVert *value)
2755{
2756 const char *error_prefix = "BMEdge.other_vert(...)";
2757 BMVert *other;
2758 BPY_BM_CHECK_OBJ(self);
2759
2760 if (!BPy_BMVert_Check(value)) {
2761 PyErr_Format(PyExc_TypeError,
2762 "%s: BMVert expected, not '%.200s'",
2763 error_prefix,
2764 Py_TYPE(value)->tp_name);
2765 return nullptr;
2766 }
2767
2768 BPY_BM_CHECK_SOURCE_OBJ(self->bm, error_prefix, value);
2769
2770 other = BM_edge_other_vert(self->e, value->v);
2771
2772 if (other) {
2773 return BPy_BMVert_CreatePyObject(self->bm, other);
2774 }
2775
2776 /* could raise an exception here */
2777 Py_RETURN_NONE;
2778}
2779
2781 /* Wrap. */
2782 bpy_bmedge_normal_update_doc,
2783 ".. method:: normal_update()\n"
2784 "\n"
2785 " Update normals of all connected faces and the edge verts.\n"
2786 "\n"
2787 " .. note::\n"
2788 "\n"
2789 " The normal of edge vertex will be a zero vector if vertex :attr:`is_wire` is True.\n");
2791{
2792 BPY_BM_CHECK_OBJ(self);
2793
2795
2796 Py_RETURN_NONE;
2797}
2798
2799/* Face
2800 * ---- */
2801
2803 /* Wrap. */
2804 bpy_bmface_copy_from_face_interp_doc,
2805 ".. method:: copy_from_face_interp(face, vert=True)\n"
2806 "\n"
2807 " Interpolate the customdata from another face onto this one (faces should overlap).\n"
2808 "\n"
2809 " :param face: The face to interpolate data from.\n"
2810 " :type face: :class:`bmesh.types.BMFace`\n"
2811 " :param vert: When True, also copy vertex data.\n"
2812 " :type vert: bool\n");
2813static PyObject *bpy_bmface_copy_from_face_interp(BPy_BMFace *self, PyObject *args)
2814{
2815 const char *error_prefix = "BMFace.copy_from_face_interp(...)";
2816 BPy_BMFace *py_face = nullptr;
2817 bool do_vertex = true;
2818
2819 BPY_BM_CHECK_OBJ(self);
2820
2821 if (!PyArg_ParseTuple(args,
2822 "O!" /* `face` */
2823 "|" /* Optional arguments. */
2824 "O&" /* `vert` */
2825 ":BMFace.copy_from_face_interp",
2827 &py_face,
2829 &do_vertex))
2830 {
2831 return nullptr;
2832 }
2833
2834 BMesh *bm = self->bm;
2835
2836 BPY_BM_CHECK_SOURCE_OBJ(bm, error_prefix, py_face);
2837
2838 BM_face_interp_from_face(bm, self->f, py_face->f, do_vertex);
2839
2840 Py_RETURN_NONE;
2841}
2842
2844 /* Wrap. */
2845 bpy_bmface_copy_doc,
2846 ".. method:: copy(*, verts=True, edges=True)\n"
2847 "\n"
2848 " Make a copy of this face.\n"
2849 "\n"
2850 " :param verts: When set, the faces verts will be duplicated too.\n"
2851 " :type verts: bool\n"
2852 " :param edges: When set, the faces edges will be duplicated too.\n"
2853 " :type edges: bool\n"
2854 " :return: The newly created face.\n"
2855 " :rtype: :class:`bmesh.types.BMFace`\n");
2856static PyObject *bpy_bmface_copy(BPy_BMFace *self, PyObject *args, PyObject *kw)
2857{
2858 static const char *kwlist[] = {"verts", "edges", nullptr};
2859
2860 BMesh *bm = self->bm;
2861 bool do_verts = true;
2862 bool do_edges = true;
2863
2864 BMFace *f_cpy;
2865 BPY_BM_CHECK_OBJ(self);
2866
2867 if (!PyArg_ParseTupleAndKeywords(args,
2868 kw,
2869 "|$" /* Optional, keyword only arguments. */
2870 "O&" /* `verts` */
2871 "O&" /* `edges` */
2872 ":BMFace.copy",
2873 const_cast<char **>(kwlist),
2875 &do_verts,
2877 &do_edges))
2878 {
2879 return nullptr;
2880 }
2881
2882 f_cpy = BM_face_copy(bm, self->f, do_verts, do_edges);
2883
2884 if (f_cpy) {
2885 return BPy_BMFace_CreatePyObject(bm, f_cpy);
2886 }
2887
2888 PyErr_SetString(PyExc_ValueError, "BMFace.copy(): couldn't create the new face, internal error");
2889 return nullptr;
2890}
2891
2893 /* Wrap. */
2894 bpy_bmface_uv_select_set_doc,
2895 ".. method:: uv_select_set(select)\n"
2896 "\n"
2897 " Set the UV face selection state.\n"
2898 "\n"
2899 " :param select: Select or de-select.\n"
2900 " :type select: bool\n"
2901 "\n"
2902 " .. note::\n"
2903 "\n"
2904 " This flushes selection down (selecting a face also selects its edges and "
2905 "vertices), but not up. Before finishing with a mesh, "
2906 "flushing with :meth:`bmesh.types.BMesh.uv_select_flush_mode` is still needed.\n");
2907static PyObject *bpy_bmface_uv_select_set(BPy_BMFace *self, PyObject *value)
2908{
2909 BMesh *bm = self->bm;
2910 BPY_BM_CHECK_OBJ(self);
2911 int param;
2912 if ((param = PyC_Long_AsBool(value)) == -1) {
2913 return nullptr;
2914 }
2915 BM_face_uvselect_set(bm, self->f, param);
2916 Py_RETURN_NONE;
2917}
2918
2920 /* Wrap. */
2921 bpy_bmface_calc_area_doc,
2922 ".. method:: calc_area()\n"
2923 "\n"
2924 " Return the area of the face.\n"
2925 "\n"
2926 " :return: The area of the face.\n"
2927 " :rtype: float\n");
2928static PyObject *bpy_bmface_calc_area(BPy_BMFace *self)
2929{
2930 BPY_BM_CHECK_OBJ(self);
2931 return PyFloat_FromDouble(BM_face_calc_area(self->f));
2932}
2933
2935 /* Wrap. */
2936 bpy_bmface_calc_perimeter_doc,
2937 ".. method:: calc_perimeter()\n"
2938 "\n"
2939 " Return the perimeter of the face.\n"
2940 "\n"
2941 " :return: The perimeter of the face.\n"
2942 " :rtype: float\n");
2944{
2945 BPY_BM_CHECK_OBJ(self);
2946 return PyFloat_FromDouble(BM_face_calc_perimeter(self->f));
2947}
2948
2950 /* Wrap. */
2951 bpy_bmface_calc_tangent_edge_doc,
2952 ".. method:: calc_tangent_edge()\n"
2953 "\n"
2954 " Return face tangent based on longest edge.\n"
2955 "\n"
2956 " :return: a normalized vector.\n"
2957 " :rtype: :class:`mathutils.Vector`\n");
2959{
2960 float tangent[3];
2961
2962 BPY_BM_CHECK_OBJ(self);
2963 BM_face_calc_tangent_from_edge(self->f, tangent);
2964 return Vector_CreatePyObject(tangent, 3, nullptr);
2965}
2966
2968 /* Wrap. */
2969 bpy_bmface_calc_tangent_edge_pair_doc,
2970 ".. method:: calc_tangent_edge_pair()\n"
2971 "\n"
2972 " Return face tangent based on the two longest disconnected edges.\n"
2973 "\n"
2974 " - Tris: Use the edge pair with the most similar lengths.\n"
2975 " - Quads: Use the longest edge pair.\n"
2976 " - NGons: Use the two longest disconnected edges.\n"
2977 "\n"
2978 " :return: a normalized vector.\n"
2979 " :rtype: :class:`mathutils.Vector`\n");
2981{
2982 float tangent[3];
2983
2984 BPY_BM_CHECK_OBJ(self);
2985 BM_face_calc_tangent_from_edge_pair(self->f, tangent);
2986 return Vector_CreatePyObject(tangent, 3, nullptr);
2987}
2988
2990 /* Wrap. */
2991 bpy_bmface_calc_tangent_edge_diagonal_doc,
2992 ".. method:: calc_tangent_edge_diagonal()\n"
2993 "\n"
2994 " Return face tangent based on the edge farthest from any vertex.\n"
2995 "\n"
2996 " :return: a normalized vector.\n"
2997 " :rtype: :class:`mathutils.Vector`\n");
2999{
3000 float tangent[3];
3001
3002 BPY_BM_CHECK_OBJ(self);
3004 return Vector_CreatePyObject(tangent, 3, nullptr);
3005}
3006
3008 /* Wrap. */
3009 bpy_bmface_calc_tangent_vert_diagonal_doc,
3010 ".. method:: calc_tangent_vert_diagonal()\n"
3011 "\n"
3012 " Return face tangent based on the two most distant vertices.\n"
3013 "\n"
3014 " :return: a normalized vector.\n"
3015 " :rtype: :class:`mathutils.Vector`\n");
3017{
3018 float tangent[3];
3019
3020 BPY_BM_CHECK_OBJ(self);
3022 return Vector_CreatePyObject(tangent, 3, nullptr);
3023}
3024
3026 /* Wrap. */
3027 bpy_bmface_calc_center_median_doc,
3028 ".. method:: calc_center_median()\n"
3029 "\n"
3030 " Return median center of the face.\n"
3031 "\n"
3032 " :return: a 3D vector.\n"
3033 " :rtype: :class:`mathutils.Vector`\n");
3035{
3036 float cent[3];
3037
3038 BPY_BM_CHECK_OBJ(self);
3039 BM_face_calc_center_median(self->f, cent);
3040 return Vector_CreatePyObject(cent, 3, nullptr);
3041}
3042
3044 /* Wrap. */
3045 bpy_bmface_calc_center_median_weighted_doc,
3046 ".. method:: calc_center_median_weighted()\n"
3047 "\n"
3048 " Return median center of the face weighted by edge lengths.\n"
3049 "\n"
3050 " :return: a 3D vector.\n"
3051 " :rtype: :class:`mathutils.Vector`\n");
3053{
3054 float cent[3];
3055
3056 BPY_BM_CHECK_OBJ(self);
3058 return Vector_CreatePyObject(cent, 3, nullptr);
3059}
3060
3062 /* Wrap. */
3063 bpy_bmface_calc_center_bounds_doc,
3064 ".. method:: calc_center_bounds()\n"
3065 "\n"
3066 " Return bounds center of the face.\n"
3067 "\n"
3068 " :return: a 3D vector.\n"
3069 " :rtype: :class:`mathutils.Vector`\n");
3071{
3072 float cent[3];
3073
3074 BPY_BM_CHECK_OBJ(self);
3075 BM_face_calc_center_bounds(self->f, cent);
3076 return Vector_CreatePyObject(cent, 3, nullptr);
3077}
3078
3080 /* Wrap. */
3081 bpy_bmface_normal_update_doc,
3082 ".. method:: normal_update()\n"
3083 "\n"
3084 " Update face normal based on the positions of the face verts.\n"
3085 " This does not update the normals of face verts.\n");
3087{
3088 BPY_BM_CHECK_OBJ(self);
3089
3090 BM_face_normal_update(self->f);
3091
3092 Py_RETURN_NONE;
3093}
3094
3096 /* Wrap. */
3097 bpy_bmface_normal_flip_doc,
3098 ".. method:: normal_flip()\n"
3099 "\n"
3100 " Reverses winding of a face, which flips its normal.\n");
3101static PyObject *bpy_bmface_normal_flip(BPy_BMFace *self)
3102{
3103 BPY_BM_CHECK_OBJ(self);
3104
3105 BM_face_normal_flip(self->bm, self->f);
3106
3107 Py_RETURN_NONE;
3108}
3109
3110/* Loop
3111 * ---- */
3112
3114 /* Wrap. */
3115 bpy_bmloop_copy_from_face_interp_doc,
3116 ".. method:: copy_from_face_interp(face, vert=True, multires=True)\n"
3117 "\n"
3118 " Interpolate the customdata from a face onto this loop (the loop's vert should "
3119 "overlap the face).\n"
3120 "\n"
3121 " :param face: The face to interpolate data from.\n"
3122 " :type face: :class:`bmesh.types.BMFace`\n"
3123 " :param vert: When enabled, interpolate the loop's vertex data (optional).\n"
3124 " :type vert: bool\n"
3125 " :param multires: When enabled, interpolate the loop's multires data (optional).\n"
3126 " :type multires: bool\n");
3127static PyObject *bpy_bmloop_copy_from_face_interp(BPy_BMLoop *self, PyObject *args)
3128{
3129 const char *error_prefix = "BMLoop.copy_from_face_interp(face)";
3130 BPy_BMFace *py_face = nullptr;
3131 bool do_vertex = true;
3132 bool do_multires = true;
3133
3134 BPY_BM_CHECK_OBJ(self);
3135
3136 if (!PyArg_ParseTuple(args,
3137 "O!" /* `face` */
3138 "|" /* Optional arguments. */
3139 "O&" /* `vert` */
3140 "O&" /* `multires` */
3141 ":BMLoop.copy_from_face_interp",
3143 &py_face,
3145 &do_vertex,
3147 &do_multires))
3148 {
3149 return nullptr;
3150 }
3151
3152 BMesh *bm = self->bm;
3153
3154 BPY_BM_CHECK_SOURCE_OBJ(bm, error_prefix, py_face);
3155
3156 BM_loop_interp_from_face(bm, self->l, py_face->f, do_vertex, do_multires);
3157
3158 Py_RETURN_NONE;
3159}
3160
3162 /* Wrap. */
3163 bpy_bmloop_uv_select_vert_set_doc,
3164 ".. method:: uv_select_vert_set(select)\n"
3165 "\n"
3166 " Set the UV vertex selection state.\n"
3167 "\n"
3168 " :param select: Select or de-select.\n"
3169 " :type select: bool\n"
3170 "\n"
3171 " .. note::\n"
3172 "\n"
3173 " This does not flush selection, so selecting a vertex won't "
3174 "select the edges & faces that use it. Before finishing with a mesh, "
3175 "flushing with :meth:`bmesh.types.BMesh.uv_select_flush_mode` is still needed.\n");
3176static PyObject *bpy_bmloop_uv_select_vert_set(BPy_BMLoop *self, PyObject *value)
3177{
3178 BMesh *bm = self->bm;
3179 BPY_BM_CHECK_OBJ(self);
3180 int param;
3181 if ((param = PyC_Long_AsBool(value)) == -1) {
3182 return nullptr;
3183 }
3184
3185 /* There is no flushing version of this function. */
3186 BM_loop_vert_uvselect_set_noflush(bm, self->l, param);
3187
3188 Py_RETURN_NONE;
3189}
3190
3192 /* Wrap. */
3193 bpy_bmloop_uv_select_edge_set_doc,
3194 ".. method:: uv_select_edge_set(select)\n"
3195 "\n"
3196 " Set the UV edge selection state.\n"
3197 "\n"
3198 " :param select: Select or de-select.\n"
3199 " :type select: bool\n"
3200 "\n"
3201 " .. note::\n"
3202 "\n"
3203 " This flushes selection down (selecting an edge also selects its "
3204 "vertices), but not up (de-selecting a vertex won't de-select the edges & faces "
3205 "that use it). Before finishing with a mesh, "
3206 "flushing with :meth:`bmesh.types.BMesh.uv_select_flush_mode` is still needed.\n");
3207static PyObject *bpy_bmloop_uv_select_edge_set(BPy_BMLoop *self, PyObject *value)
3208{
3209 BMesh *bm = self->bm;
3210 BPY_BM_CHECK_OBJ(self);
3211 int param;
3212 if ((param = PyC_Long_AsBool(value)) == -1) {
3213 return nullptr;
3214 }
3215 BM_loop_edge_uvselect_set(bm, self->l, param);
3216 Py_RETURN_NONE;
3217}
3218
3220 /* Wrap. */
3221 bpy_bmloop_calc_angle_doc,
3222 ".. method:: calc_angle()\n"
3223 "\n"
3224 " Return the angle at this loops corner of the face.\n"
3225 " This is calculated so sharper corners give lower angles.\n"
3226 "\n"
3227 " :return: The angle in radians.\n"
3228 " :rtype: float\n");
3229static PyObject *bpy_bmloop_calc_angle(BPy_BMLoop *self)
3230{
3231 BPY_BM_CHECK_OBJ(self);
3232 return PyFloat_FromDouble(BM_loop_calc_face_angle(self->l));
3233}
3234
3236 /* Wrap. */
3237 bpy_bmloop_calc_normal_doc,
3238 ".. method:: calc_normal()\n"
3239 "\n"
3240 " Return normal at this loops corner of the face.\n"
3241 " Falls back to the face normal for straight lines.\n"
3242 "\n"
3243 " :return: a normalized vector.\n"
3244 " :rtype: :class:`mathutils.Vector`\n");
3245static PyObject *bpy_bmloop_calc_normal(BPy_BMLoop *self)
3246{
3247 float vec[3];
3248 BPY_BM_CHECK_OBJ(self);
3249 BM_loop_calc_face_normal(self->l, vec);
3250 return Vector_CreatePyObject(vec, 3, nullptr);
3251}
3252
3254 /* Wrap. */
3255 bpy_bmloop_calc_tangent_doc,
3256 ".. method:: calc_tangent()\n"
3257 "\n"
3258 " Return the tangent at this loops corner of the face (pointing inward into the face).\n"
3259 " Falls back to the face normal for straight lines.\n"
3260 "\n"
3261 " :return: a normalized vector.\n"
3262 " :rtype: :class:`mathutils.Vector`\n");
3264{
3265 float vec[3];
3266 BPY_BM_CHECK_OBJ(self);
3267 BM_loop_calc_face_tangent(self->l, vec);
3268 return Vector_CreatePyObject(vec, 3, nullptr);
3269}
3270
3271/* Vert Seq
3272 * -------- */
3274 /* Wrap. */
3275 bpy_bmvertseq_new_doc,
3276 ".. method:: new(co=(0.0, 0.0, 0.0), source=None)\n"
3277 "\n"
3278 " Create a new vertex.\n"
3279 "\n"
3280 " :param co: The initial location of the vertex (optional argument).\n"
3281 " :type co: tuple[float, float, float] | Sequence[float]\n"
3282 " :param source: Existing vert to initialize settings.\n"
3283 " :type source: :class:`bmesh.types.BMVert` | None\n"
3284 " :return: The newly created vertex.\n"
3285 " :rtype: :class:`bmesh.types.BMVert`\n");
3286static PyObject *bpy_bmvertseq_new(BPy_BMElemSeq *self, PyObject *args, PyObject *kw)
3287{
3288 PyObject *py_co = nullptr;
3289 BPy_BMVert *py_vert_source = nullptr; /* optional */
3290 PyC_TypeOrNone py_vert_source_or_none = PyC_TYPE_OR_NONE_INIT(&BPy_BMVert_Type, &py_vert_source);
3291
3292 BPY_BM_CHECK_OBJ(self);
3293
3294 static const char *_keywords[] = {"", "source", nullptr};
3295 static _PyArg_Parser _parser = {
3296 "|" /* Optional arguments. */
3297 "O" /* `co` */
3298 "O&" /* `source` */
3299 ":verts.new",
3300 _keywords,
3301 nullptr,
3302 };
3303 if (!_PyArg_ParseTupleAndKeywordsFast(
3304 args, kw, &_parser, &py_co, PyC_ParseTypeOrNone, &py_vert_source_or_none))
3305 {
3306 return nullptr;
3307 }
3308
3309 BMesh *bm = self->bm;
3310 BMVert *v;
3311 float co[3] = {0.0f, 0.0f, 0.0f};
3312
3313 if (py_vert_source) {
3314 BPY_BM_CHECK_OBJ(py_vert_source);
3315 }
3316
3317 if (py_co && mathutils_array_parse(co, 3, 3, py_co, "verts.new(co)") == -1) {
3318 return nullptr;
3319 }
3320
3321 v = BM_vert_create(bm, co, nullptr, BM_CREATE_NOP);
3322
3323 if (v == nullptr) {
3324 PyErr_SetString(PyExc_ValueError,
3325 "verts.new(co): couldn't create the new vert, internal error");
3326 return nullptr;
3327 }
3328
3329 if (py_vert_source) {
3330 if (py_vert_source->bm == bm) {
3331 BM_elem_attrs_copy(bm, py_vert_source->v, v);
3332 }
3333 else {
3335 py_vert_source->bm->vdata, bm->vdata);
3336 BM_elem_attrs_copy(bm, cd_vert_map, py_vert_source->v, v);
3337 }
3338 }
3339
3341}
3342
3343/* Edge Seq
3344 * -------- */
3346 /* Wrap. */
3347 bpy_bmedgeseq_new_doc,
3348 ".. method:: new(verts, source=None)\n"
3349 "\n"
3350 " Create a new edge from a given pair of verts.\n"
3351 "\n"
3352 " :param verts: Vertex pair.\n"
3353 " :type verts: Sequence[:class:`bmesh.types.BMVert`]\n"
3354 " :param source: Existing edge to initialize settings (optional argument).\n"
3355 " :type source: :class:`bmesh.types.BMEdge` | None\n"
3356 " :return: The newly created edge.\n"
3357 " :rtype: :class:`bmesh.types.BMEdge`\n");
3358static PyObject *bpy_bmedgeseq_new(BPy_BMElemSeq *self, PyObject *args, PyObject *kw)
3359{
3360 const char *error_prefix = "edges.new(...)";
3361 PyObject *vert_seq;
3362 BPy_BMEdge *py_edge_source = nullptr; /* optional */
3363 PyC_TypeOrNone py_edge_source_or_none = PyC_TYPE_OR_NONE_INIT(&BPy_BMEdge_Type, &py_edge_source);
3364
3365 BPY_BM_CHECK_OBJ(self);
3366
3367 static const char *_keywords[] = {"", "source", nullptr};
3368 static _PyArg_Parser _parser = {
3369 "O" /* `verts` */
3370 "|" /* Optional arguments. */
3371 "O&" /* `source` */
3372 ":edges.new",
3373 _keywords,
3374 nullptr,
3375 };
3376 if (!_PyArg_ParseTupleAndKeywordsFast(
3377 args, kw, &_parser, &vert_seq, PyC_ParseTypeOrNone, &py_edge_source_or_none))
3378 {
3379 return nullptr;
3380 }
3381
3382 BMesh *bm = self->bm;
3383 BMEdge *e;
3384 PyObject *ret = nullptr;
3385
3386 if (py_edge_source) {
3387 BPY_BM_CHECK_OBJ(py_edge_source);
3388 }
3389
3390 Py_ssize_t vert_seq_num; /* Always 2. */
3391 BMVert **vert_array = BPy_BMVert_PySeq_As_Array(
3392 &bm, vert_seq, 2, 2, &vert_seq_num, true, true, error_prefix);
3393 if (vert_array == nullptr) {
3394 return nullptr;
3395 }
3396
3397 if (BM_edge_exists(vert_array[0], vert_array[1])) {
3398 PyErr_SetString(PyExc_ValueError, "edges.new(): this edge exists");
3399 goto cleanup;
3400 }
3401
3402 e = BM_edge_create(bm, vert_array[0], vert_array[1], nullptr, BM_CREATE_NOP);
3403
3404 if (e == nullptr) {
3405 PyErr_SetString(PyExc_ValueError,
3406 "edges.new(verts): couldn't create the new edge, internal error");
3407 goto cleanup;
3408 }
3409
3410 if (py_edge_source) {
3411 if (py_edge_source->bm == bm) {
3412 BM_elem_attrs_copy(bm, py_edge_source->e, e);
3413 }
3414 else {
3416 py_edge_source->bm->edata, bm->edata);
3417 BM_elem_attrs_copy(bm, cd_edge_map, py_edge_source->e, e);
3418 }
3419 }
3420
3422
3423cleanup:
3424 if (vert_array) {
3425 PyMem_FREE(vert_array);
3426 }
3427 return ret;
3428}
3429
3430/* Face Seq
3431 * -------- */
3433 /* Wrap. */
3434 bpy_bmfaceseq_new_doc,
3435 ".. method:: new(verts, source=None)\n"
3436 "\n"
3437 " Create a new face from a given set of verts.\n"
3438 "\n"
3439 " :param verts: Sequence of 3 or more verts.\n"
3440 " :type verts: Sequence[:class:`bmesh.types.BMVert`]\n"
3441 " :param source: Existing face to initialize settings (optional argument).\n"
3442 " :type source: :class:`bmesh.types.BMFace` | None\n"
3443 " :return: The newly created face.\n"
3444 " :rtype: :class:`bmesh.types.BMFace`\n");
3445static PyObject *bpy_bmfaceseq_new(BPy_BMElemSeq *self, PyObject *args, PyObject *kw)
3446{
3447 const char *error_prefix = "faces.new(...)";
3448 PyObject *vert_seq;
3449 BPy_BMFace *py_face_source = nullptr; /* optional */
3450 PyC_TypeOrNone py_face_source_or_none = PyC_TYPE_OR_NONE_INIT(&BPy_BMFace_Type, &py_face_source);
3451
3452 BPY_BM_CHECK_OBJ(self);
3453
3454 static const char *_keywords[] = {"", "source", nullptr};
3455 static _PyArg_Parser _parser = {
3456 "O" /* `verts` */
3457 "|" /* Optional arguments. */
3458 "O&" /* `source` */
3459 ":faces.new",
3460 _keywords,
3461 nullptr,
3462 };
3463 if (!_PyArg_ParseTupleAndKeywordsFast(
3464 args, kw, &_parser, &vert_seq, PyC_ParseTypeOrNone, &py_face_source_or_none))
3465 {
3466 return nullptr;
3467 }
3468
3469 BMesh *bm = self->bm;
3470
3471 PyObject *ret = nullptr;
3472
3473 BMFace *f_new;
3474
3475 if (py_face_source) {
3476 BPY_BM_CHECK_OBJ(py_face_source);
3477 }
3478
3479 Py_ssize_t vert_seq_num;
3480 BMVert **vert_array = BPy_BMVert_PySeq_As_Array(
3481 &bm, vert_seq, 3, PY_SSIZE_T_MAX, &vert_seq_num, true, true, error_prefix);
3482 if (vert_array == nullptr) {
3483 return nullptr;
3484 }
3485
3486 /* check if the face exists */
3487 if (BM_face_exists(vert_array, vert_seq_num) != nullptr) {
3488 PyErr_Format(PyExc_ValueError, "%s: face already exists", error_prefix);
3489 goto cleanup;
3490 }
3491
3492 /* Go ahead and make the face!
3493 * --------------------------- */
3494
3495 f_new = BM_face_create_verts(bm,
3496 vert_array,
3497 vert_seq_num,
3498 py_face_source ? py_face_source->f : nullptr,
3500 true);
3501
3502 if (f_new == nullptr) [[unlikely]] {
3503 PyErr_Format(
3504 PyExc_ValueError, "%s: couldn't create the new face, internal error", error_prefix);
3505 goto cleanup;
3506 }
3507
3509
3510/* pass through */
3511cleanup:
3512 if (vert_array) {
3513 PyMem_FREE(vert_array);
3514 }
3515 return ret;
3516}
3517
3518/* Elem Seq
3519 * -------- */
3520
3522 /* Wrap. */
3523 bpy_bmvertseq_remove_doc,
3524 ".. method:: remove(vert)\n"
3525 "\n"
3526 " Remove a vert.\n"
3527 "\n"
3528 " :param vert: The vert to remove.\n"
3529 " :type vert: :class:`bmesh.types.BMVert`\n");
3530static PyObject *bpy_bmvertseq_remove(BPy_BMElemSeq *self, BPy_BMVert *value)
3531{
3532 const char *error_prefix = "verts.remove(vert)";
3533 BPY_BM_CHECK_OBJ(self);
3534
3535 if (!BPy_BMVert_Check(value)) {
3536 return nullptr;
3537 }
3538
3539 BMesh *bm = self->bm;
3540
3541 BPY_BM_CHECK_SOURCE_OBJ(bm, error_prefix, value);
3542
3543 BM_vert_kill(bm, value->v);
3544 bpy_bm_generic_invalidate(reinterpret_cast<BPy_BMGeneric *>(value));
3545
3546 Py_RETURN_NONE;
3547}
3548
3550 /* Wrap. */
3551 bpy_bmedgeseq_remove_doc,
3552 ".. method:: remove(edge)\n"
3553 "\n"
3554 " Remove an edge.\n"
3555 "\n"
3556 " :param edge: The edge to remove.\n"
3557 " :type edge: :class:`bmesh.types.BMEdge`\n");
3558static PyObject *bpy_bmedgeseq_remove(BPy_BMElemSeq *self, BPy_BMEdge *value)
3559{
3560 const char *error_prefix = "edges.remove(...)";
3561 BPY_BM_CHECK_OBJ(self);
3562
3563 if (!BPy_BMEdge_Check(value)) {
3564 return nullptr;
3565 }
3566
3567 BMesh *bm = self->bm;
3568
3569 BPY_BM_CHECK_SOURCE_OBJ(bm, error_prefix, value);
3570
3571 BM_edge_kill(bm, value->e);
3572 bpy_bm_generic_invalidate(reinterpret_cast<BPy_BMGeneric *>(value));
3573
3574 Py_RETURN_NONE;
3575}
3576
3578 /* Wrap. */
3579 bpy_bmfaceseq_remove_doc,
3580 ".. method:: remove(face)\n"
3581 "\n"
3582 " Remove a face.\n"
3583 "\n"
3584 " :param face: The face to remove.\n"
3585 " :type face: :class:`bmesh.types.BMFace`\n");
3586static PyObject *bpy_bmfaceseq_remove(BPy_BMElemSeq *self, BPy_BMFace *value)
3587{
3588 const char *error_prefix = "faces.remove(...)";
3589 BPY_BM_CHECK_OBJ(self);
3590
3591 if (!BPy_BMFace_Check(value)) {
3592 return nullptr;
3593 }
3594
3595 BMesh *bm = self->bm;
3596
3597 BPY_BM_CHECK_SOURCE_OBJ(bm, error_prefix, value);
3598
3599 BM_face_kill(bm, value->f);
3600 bpy_bm_generic_invalidate(reinterpret_cast<BPy_BMGeneric *>(value));
3601
3602 Py_RETURN_NONE;
3603}
3604
3606 /* Wrap. */
3607 bpy_bmedgeseq_get__method_doc,
3608 ".. method:: get(verts, fallback=None)\n"
3609 "\n"
3610 " Return an edge which uses the **verts** passed.\n"
3611 "\n"
3612 " :param verts: Pair of verts (exactly 2).\n"
3613 " :type verts: Sequence[:class:`bmesh.types.BMVert`]\n"
3614 " :param fallback: Return this value if nothing is found.\n"
3615 " :type fallback: Any\n"
3616 " :return: The edge found or the fallback value.\n"
3617 " :rtype: :class:`bmesh.types.BMEdge` | None\n");
3618static PyObject *bpy_bmedgeseq_get__method(BPy_BMElemSeq *self, PyObject *args)
3619{
3620 const char *error_prefix = "edges.get(...)";
3621 PyObject *vert_seq;
3622 PyObject *fallback = Py_None; /* optional */
3623
3624 BPY_BM_CHECK_OBJ(self);
3625
3626 if (!PyArg_ParseTuple(args,
3627 "O" /* `verts` */
3628 "|" /* Optional arguments. */
3629 "O" /* `fallback` */
3630 ":edges.get",
3631 &vert_seq,
3632 &fallback))
3633 {
3634 return nullptr;
3635 }
3636
3637 BMesh *bm = self->bm;
3638 BMEdge *e;
3639 PyObject *ret = nullptr;
3640
3641 Py_ssize_t vert_seq_num; /* Always 2. */
3642 BMVert **vert_array = BPy_BMVert_PySeq_As_Array(
3643 &bm, vert_seq, 2, 2, &vert_seq_num, true, true, error_prefix);
3644
3645 if (vert_array == nullptr) {
3646 return nullptr;
3647 }
3648
3649 if ((e = BM_edge_exists(vert_array[0], vert_array[1]))) {
3651 }
3652 else {
3653 ret = fallback;
3654 Py_INCREF(ret);
3655 }
3656
3657 PyMem_FREE(vert_array);
3658 return ret;
3659}
3660
3662 /* Wrap. */
3663 bpy_bmfaceseq_get__method_doc,
3664 ".. method:: get(verts, fallback=None)\n"
3665 "\n"
3666 " Return a face which uses the **verts** passed.\n"
3667 "\n"
3668 " :param verts: Sequence of verts.\n"
3669 " :type verts: Sequence[:class:`bmesh.types.BMVert`]\n"
3670 " :param fallback: Return this value if nothing is found.\n"
3671 " :type fallback: Any\n"
3672 " :return: The face found or the fallback value.\n"
3673 " :rtype: :class:`bmesh.types.BMFace` | None\n");
3674static PyObject *bpy_bmfaceseq_get__method(BPy_BMElemSeq *self, PyObject *args)
3675{
3676 const char *error_prefix = "faces.get(...)";
3677 PyObject *vert_seq;
3678 PyObject *fallback = Py_None; /* optional */
3679
3680 BPY_BM_CHECK_OBJ(self);
3681
3682 if (!PyArg_ParseTuple(args,
3683 "O" /* `verts` */
3684 "|" /* Optional arguments. */
3685 "O" /* `fallback` */
3686 ":faces.get",
3687 &vert_seq,
3688 &fallback))
3689 {
3690 return nullptr;
3691 }
3692
3693 BMesh *bm = self->bm;
3694 BMFace *f = nullptr;
3695 PyObject *ret = nullptr;
3696
3697 Py_ssize_t vert_seq_num;
3698 BMVert **vert_array = BPy_BMVert_PySeq_As_Array(
3699 &bm, vert_seq, 1, PY_SSIZE_T_MAX, &vert_seq_num, true, true, error_prefix);
3700
3701 if (vert_array == nullptr) {
3702 return nullptr;
3703 }
3704
3705 f = BM_face_exists(vert_array, vert_seq_num);
3706 if (f != nullptr) {
3708 }
3709 else {
3710 ret = fallback;
3711 Py_INCREF(ret);
3712 }
3713
3714 PyMem_FREE(vert_array);
3715 return ret;
3716}
3717
3719 /* Wrap. */
3720 bpy_bmelemseq_index_update_doc,
3721 ".. method:: index_update()\n"
3722 "\n"
3723 " Initialize the index values of this sequence.\n"
3724 "\n"
3725 " This is the equivalent of looping over all elements and assigning the index values.\n"
3726 "\n"
3727 " .. code-block:: python\n"
3728 "\n"
3729 " for index, ele in enumerate(sequence):\n"
3730 " ele.index = index\n"
3731 "\n"
3732 " .. note::\n"
3733 "\n"
3734 " Running this on sequences besides "
3735 ":class:`bmesh.types.BMesh.verts`, "
3736 ":class:`bmesh.types.BMesh.edges`, "
3737 ":class:`bmesh.types.BMesh.faces`\n"
3738 " works but won't result in each element having a valid index, instead its order in the "
3739 "sequence will be set.\n");
3741{
3742 BMesh *bm = self->bm;
3743
3744 BPY_BM_CHECK_OBJ(self);
3745
3746 switch (BMIterType(self->itype)) {
3747 case BM_VERTS_OF_MESH:
3749 break;
3750 case BM_EDGES_OF_MESH:
3752 break;
3753 case BM_FACES_OF_MESH:
3755 break;
3756 default: {
3757 BMIter iter;
3758 BMElem *ele;
3759 int index = 0;
3760 const char htype = bm_iter_itype_htype_map[self->itype];
3761
3762 BM_ITER_BPY_BM_SEQ (ele, &iter, self) {
3763 BM_elem_index_set(ele, index); /* set_dirty! */
3764 index++;
3765 }
3766
3767 /* since this isn't the normal vert/edge/face loops,
3768 * we're setting dirty values here. so tag as dirty. */
3769 bm->elem_index_dirty |= htype;
3770
3771 break;
3772 }
3773 }
3774
3775 Py_RETURN_NONE;
3776}
3777
3779 /* Wrap. */
3780 bpy_bmelemseq_ensure_lookup_table_doc,
3781 ".. method:: ensure_lookup_table()\n"
3782 "\n"
3783 " Ensure internal data needed for int subscript access is initialized with "
3784 "verts/edges/faces, eg ``bm.verts[index]``.\n"
3785 "\n"
3786 " This needs to be called again after adding/removing data in this sequence.\n");
3788{
3789 BPY_BM_CHECK_OBJ(self);
3790
3792
3793 Py_RETURN_NONE;
3794}
3795
3797 /* Wrap. */
3798 bpy_bmelemseq_sort_doc,
3799 ".. method:: sort(*, key=None, reverse=False)\n"
3800 "\n"
3801 " Sort the elements of this sequence, using an optional custom sort key.\n"
3802 " Indices of elements are not changed, :meth:`bmesh.types.BMElemSeq.index_update` "
3803 "can be used for that.\n"
3804 "\n"
3805 " :param key: The key that sets the ordering of the elements.\n"
3806 " :type key: Callable[["
3807 ":class:`bmesh.types.BMVert` | "
3808 ":class:`bmesh.types.BMEdge` | "
3809 ":class:`bmesh.types.BMFace`], int] | None\n"
3810 " :param reverse: Reverse the order of the elements\n"
3811 " :type reverse: bool\n"
3812 "\n"
3813 " .. note::\n"
3814 "\n"
3815 " When the 'key' argument is not provided, the elements are reordered following their "
3816 "current index value.\n"
3817 " In particular this can be used by setting indices manually before calling this "
3818 "method.\n"
3819 "\n"
3820 " .. warning::\n"
3821 "\n"
3822 " Existing references to the N'th element, will continue to point the data at that "
3823 "index.\n");
3824
3825/* Use a static variable here because there is the need to sort some array
3826 * doing comparisons on elements of another array, qsort_r would have been
3827 * wonderful to use here, but unfortunately it is not standard and it's not
3828 * portable across different platforms.
3829 *
3830 * If a portable alternative to qsort_r becomes available, remove this static
3831 * var hack!
3832 *
3833 * NOTE: the functions below assumes the keys array has been allocated and it
3834 * has enough elements to complete the task.
3835 */
3836
3837static int bpy_bmelemseq_sort_cmp_by_keys_ascending(const void *index1_v,
3838 const void *index2_v,
3839 void *keys_v)
3840{
3841 const double *keys = static_cast<const double *>(keys_v);
3842 const int *index1 = static_cast<int *>(const_cast<void *>(index1_v));
3843 const int *index2 = static_cast<int *>(const_cast<void *>(index2_v));
3844
3845 if (keys[*index1] < keys[*index2]) {
3846 return -1;
3847 }
3848 if (keys[*index1] > keys[*index2]) {
3849 return 1;
3850 }
3851
3852 return 0;
3853}
3854
3855static int bpy_bmelemseq_sort_cmp_by_keys_descending(const void *index1_v,
3856 const void *index2_v,
3857 void *keys_v)
3858{
3859 return -bpy_bmelemseq_sort_cmp_by_keys_ascending(index1_v, index2_v, keys_v);
3860}
3861
3862static PyObject *bpy_bmelemseq_sort(BPy_BMElemSeq *self, PyObject *args, PyObject *kw)
3863{
3864 static const char *kwlist[] = {"key", "reverse", nullptr};
3865 PyObject *keyfunc = nullptr; /* optional */
3866 bool do_reverse = false; /* optional */
3867
3868 const char htype = bm_iter_itype_htype_map[self->itype];
3869 int n_elem;
3870
3871 BMIter iter;
3872 BMElem *ele;
3873
3874 double *keys;
3875 int *elem_idx;
3876 uint *elem_map_idx;
3877 int (*elem_idx_compare_by_keys)(const void *, const void *, void *);
3878
3879 uint *vert_idx = nullptr;
3880 uint *edge_idx = nullptr;
3881 uint *face_idx = nullptr;
3882 int i;
3883
3884 BMesh *bm = self->bm;
3885
3886 BPY_BM_CHECK_OBJ(self);
3887
3888 if (args != nullptr) {
3889 if (!PyArg_ParseTupleAndKeywords(args,
3890 kw,
3891 "|$" /* Optional, keyword only arguments. */
3892 "O" /* `key` */
3893 "O&" /* `reverse` */
3894 ":BMElemSeq.sort",
3895 const_cast<char **>(kwlist),
3896 &keyfunc,
3898 &do_reverse))
3899 {
3900 return nullptr;
3901 }
3902 if (keyfunc == Py_None) {
3903 keyfunc = nullptr;
3904 }
3905 }
3906
3907 if (keyfunc != nullptr && !PyCallable_Check(keyfunc)) {
3908 PyErr_SetString(PyExc_TypeError, "the 'key' argument is not a callable object");
3909 return nullptr;
3910 }
3911
3912 n_elem = BM_mesh_elem_count(bm, htype);
3913 if (n_elem <= 1) {
3914 /* 0 or 1 elements: sorted already */
3915 Py_RETURN_NONE;
3916 }
3917
3918 keys = static_cast<double *>(PyMem_MALLOC(sizeof(*keys) * n_elem));
3919 if (keys == nullptr) {
3920 PyErr_NoMemory();
3921 return nullptr;
3922 }
3923
3924 i = 0;
3925 BM_ITER_BPY_BM_SEQ (ele, &iter, self) {
3926 if (keyfunc != nullptr) {
3927 PyObject *py_elem;
3928 PyObject *index;
3929
3930 py_elem = BPy_BMElem_CreatePyObject(self->bm, reinterpret_cast<BMHeader *>(ele));
3931 index = PyObject_CallFunctionObjArgs(keyfunc, py_elem, nullptr);
3932 Py_DECREF(py_elem);
3933 if (index == nullptr) {
3934 /* No need to set the exception here,
3935 * PyObject_CallFunctionObjArgs() does that */
3936 PyMem_FREE(keys);
3937 return nullptr;
3938 }
3939
3940 if ((keys[i] = PyFloat_AsDouble(index)) == -1 && PyErr_Occurred()) {
3941 PyErr_SetString(PyExc_ValueError,
3942 "the value returned by the 'key' function is not a number");
3943 Py_DECREF(index);
3944 PyMem_FREE(keys);
3945 return nullptr;
3946 }
3947
3948 Py_DECREF(index);
3949 }
3950 else {
3951 /* If the 'key' function is not provided we sort
3952 * according to the current index values */
3953 keys[i] = ele->head.index;
3954 }
3955
3956 i++;
3957 }
3958
3959 elem_idx = static_cast<int *>(PyMem_MALLOC(sizeof(*elem_idx) * n_elem));
3960 if (elem_idx == nullptr) {
3961 PyErr_NoMemory();
3962 PyMem_FREE(keys);
3963 return nullptr;
3964 }
3965
3966 /* Initialize the element index array */
3967 array_utils::fill_index_range<int>({elem_idx, n_elem});
3968
3969 /* Sort the index array according to the order of the 'keys' array */
3970 if (do_reverse) {
3971 elem_idx_compare_by_keys = bpy_bmelemseq_sort_cmp_by_keys_descending;
3972 }
3973 else {
3974 elem_idx_compare_by_keys = bpy_bmelemseq_sort_cmp_by_keys_ascending;
3975 }
3976
3977 BLI_qsort_r(elem_idx, n_elem, sizeof(*elem_idx), elem_idx_compare_by_keys, keys);
3978
3979 elem_map_idx = static_cast<uint *>(PyMem_MALLOC(sizeof(*elem_map_idx) * n_elem));
3980 if (elem_map_idx == nullptr) {
3981 PyErr_NoMemory();
3982 PyMem_FREE(elem_idx);
3983 PyMem_FREE(keys);
3984 return nullptr;
3985 }
3986
3987 /* Initialize the map array
3988 *
3989 * We need to know the index such that if used as the new_index in
3990 * BM_mesh_remap() will give the order of the sorted keys like in
3991 * elem_idx */
3992 for (i = 0; i < n_elem; i++) {
3993 elem_map_idx[elem_idx[i]] = i;
3994 }
3995
3996 switch (BMIterType(self->itype)) {
3997 case BM_VERTS_OF_MESH:
3998 vert_idx = elem_map_idx;
3999 break;
4000 case BM_EDGES_OF_MESH:
4001 edge_idx = elem_map_idx;
4002 break;
4003 case BM_FACES_OF_MESH:
4004 face_idx = elem_map_idx;
4005 break;
4006 default:
4007 PyErr_Format(PyExc_TypeError, "element type %d not supported", self->itype);
4008 PyMem_FREE(elem_map_idx);
4009 PyMem_FREE(elem_idx);
4010 PyMem_FREE(keys);
4011 return nullptr;
4012 }
4013
4014 BM_mesh_remap(bm, vert_idx, edge_idx, face_idx);
4015
4016 PyMem_FREE(elem_map_idx);
4017 PyMem_FREE(elem_idx);
4018 PyMem_FREE(keys);
4019
4020 Py_RETURN_NONE;
4021}
4022
4023#ifdef __GNUC__
4024# ifdef __clang__
4025# pragma clang diagnostic push
4026# pragma clang diagnostic ignored "-Wcast-function-type"
4027# else
4028# pragma GCC diagnostic push
4029# pragma GCC diagnostic ignored "-Wcast-function-type"
4030# endif
4031#endif
4032
4033static PyMethodDef bpy_bmesh_methods[] = {
4034 /* utility */
4035 {"copy", reinterpret_cast<PyCFunction>(bpy_bmesh_copy), METH_NOARGS, bpy_bmesh_copy_doc},
4036 {"clear", reinterpret_cast<PyCFunction>(bpy_bmesh_clear), METH_NOARGS, bpy_bmesh_clear_doc},
4037 {"free", reinterpret_cast<PyCFunction>(bpy_bmesh_free), METH_NOARGS, bpy_bmesh_free_doc},
4038
4039 /* conversion */
4040 {"from_object",
4041 reinterpret_cast<PyCFunction>(bpy_bmesh_from_object),
4042 METH_VARARGS | METH_KEYWORDS,
4043 bpy_bmesh_from_object_doc},
4044 {"from_mesh",
4045 reinterpret_cast<PyCFunction>(bpy_bmesh_from_mesh),
4046 METH_VARARGS | METH_KEYWORDS,
4047 bpy_bmesh_from_mesh_doc},
4048 {"to_mesh",
4049 reinterpret_cast<PyCFunction>(bpy_bmesh_to_mesh),
4050 METH_VARARGS,
4051 bpy_bmesh_to_mesh_doc},
4052
4053 /* Mesh select methods. */
4054 {"select_flush_mode",
4055 reinterpret_cast<PyCFunction>(bpy_bmesh_select_flush_mode),
4056 METH_VARARGS | METH_KEYWORDS,
4057 bpy_bmesh_select_flush_mode_doc},
4058 {"select_flush",
4059 reinterpret_cast<PyCFunction>(bpy_bmesh_select_flush),
4060 METH_O,
4061 bpy_bmesh_select_flush_doc},
4062
4063 /* UV select methods. */
4064 {"uv_select_flush_mode",
4065 reinterpret_cast<PyCFunction>(bpy_bmesh_uv_select_flush_mode),
4066 METH_VARARGS | METH_KEYWORDS,
4067 bpy_bmesh_uv_select_flush_mode_doc},
4068 {"uv_select_flush",
4069 reinterpret_cast<PyCFunction>(bpy_bmesh_uv_select_flush),
4070 METH_O,
4071 bpy_bmesh_uv_select_flush_doc},
4072 {"uv_select_flush_shared",
4073 reinterpret_cast<PyCFunction>(bpy_bmesh_uv_select_flush_shared),
4074 METH_O,
4075 bpy_bmesh_uv_select_flush_shared_doc},
4076
4077 {"uv_select_sync_from_mesh",
4078 reinterpret_cast<PyCFunction>(bpy_bmesh_uv_select_sync_from_mesh),
4079 METH_VARARGS | METH_KEYWORDS,
4080 bpy_bmesh_uv_select_sync_from_mesh_doc},
4081 {"uv_select_sync_to_mesh",
4082 reinterpret_cast<PyCFunction>(bpy_bmesh_uv_select_sync_to_mesh),
4083 METH_NOARGS,
4084 bpy_bmesh_uv_select_sync_to_mesh_doc},
4085 {"uv_select_foreach_set",
4086 reinterpret_cast<PyCFunction>(bpy_bmesh_uv_select_foreach_set),
4087 METH_VARARGS | METH_KEYWORDS,
4088 bpy_bmesh_uv_select_foreach_set_doc},
4089 {"uv_select_foreach_set_from_mesh",
4090 reinterpret_cast<PyCFunction>(bpy_bmesh_uv_select_foreach_set_from_mesh),
4091 METH_VARARGS | METH_KEYWORDS,
4092 bpy_bmesh_uv_select_foreach_set_from_mesh_doc},
4093
4094 /* meshdata */
4095 {"normal_update",
4096 reinterpret_cast<PyCFunction>(bpy_bmesh_normal_update),
4097 METH_NOARGS,
4098 bpy_bmesh_normal_update_doc},
4099 {"transform",
4100 reinterpret_cast<PyCFunction>(bpy_bmesh_transform),
4101 METH_VARARGS | METH_KEYWORDS,
4102 bpy_bmesh_transform_doc},
4103
4104 /* calculations */
4105 {"calc_volume",
4106 reinterpret_cast<PyCFunction>(bpy_bmesh_calc_volume),
4107 METH_VARARGS | METH_KEYWORDS,
4108 bpy_bmesh_calc_volume_doc},
4109 {"calc_loop_triangles",
4110 reinterpret_cast<PyCFunction>(bpy_bmesh_calc_loop_triangles),
4111 METH_NOARGS,
4112 bpy_bmesh_calc_loop_triangles_doc},
4113 {nullptr, nullptr, 0, nullptr},
4114};
4115
4116static PyMethodDef bpy_bmvert_methods[] = {
4117 {"select_set",
4118 reinterpret_cast<PyCFunction>(bpy_bm_elem_select_set),
4119 METH_O,
4120 bpy_bm_elem_select_set_doc},
4121 {"hide_set",
4122 reinterpret_cast<PyCFunction>(bpy_bm_elem_hide_set),
4123 METH_O,
4124 bpy_bm_elem_hide_set_doc},
4125 {"copy_from",
4126 reinterpret_cast<PyCFunction>(bpy_bm_elem_copy_from),
4127 METH_O,
4128 bpy_bm_elem_copy_from_doc},
4129 {"copy_from_face_interp",
4130 reinterpret_cast<PyCFunction>(bpy_bmvert_copy_from_face_interp),
4131 METH_VARARGS,
4132 bpy_bmvert_copy_from_face_interp_doc},
4133 {"copy_from_vert_interp",
4134 reinterpret_cast<PyCFunction>(bpy_bmvert_copy_from_vert_interp),
4135 METH_VARARGS,
4136 bpy_bmvert_copy_from_vert_interp_doc},
4137
4138 {"calc_edge_angle",
4139 reinterpret_cast<PyCFunction>(bpy_bmvert_calc_edge_angle),
4140 METH_VARARGS,
4141 bpy_bmvert_calc_edge_angle_doc},
4142 {"calc_shell_factor",
4143 reinterpret_cast<PyCFunction>(bpy_bmvert_calc_shell_factor),
4144 METH_NOARGS,
4145 bpy_bmvert_calc_shell_factor_doc},
4146
4147 {"normal_update",
4148 reinterpret_cast<PyCFunction>(bpy_bmvert_normal_update),
4149 METH_NOARGS,
4150 bpy_bmvert_normal_update_doc},
4151
4152 {nullptr, nullptr, 0, nullptr},
4153};
4154
4155static PyMethodDef bpy_bmedge_methods[] = {
4156 {"select_set",
4157 reinterpret_cast<PyCFunction>(bpy_bm_elem_select_set),
4158 METH_O,
4159 bpy_bm_elem_select_set_doc},
4160 {"hide_set",
4161 reinterpret_cast<PyCFunction>(bpy_bm_elem_hide_set),
4162 METH_O,
4163 bpy_bm_elem_hide_set_doc},
4164 {"copy_from",
4165 reinterpret_cast<PyCFunction>(bpy_bm_elem_copy_from),
4166 METH_O,
4167 bpy_bm_elem_copy_from_doc},
4168
4169 {"other_vert",
4170 reinterpret_cast<PyCFunction>(bpy_bmedge_other_vert),
4171 METH_O,
4172 bpy_bmedge_other_vert_doc},
4173
4174 {"calc_length",
4175 reinterpret_cast<PyCFunction>(bpy_bmedge_calc_length),
4176 METH_NOARGS,
4177 bpy_bmedge_calc_length_doc},
4178 {"calc_face_angle",
4179 reinterpret_cast<PyCFunction>(bpy_bmedge_calc_face_angle),
4180 METH_VARARGS,
4181 bpy_bmedge_calc_face_angle_doc},
4182 {"calc_face_angle_signed",
4183 reinterpret_cast<PyCFunction>(bpy_bmedge_calc_face_angle_signed),
4184 METH_VARARGS,
4185 bpy_bmedge_calc_face_angle_signed_doc},
4186 {"calc_tangent",
4187 reinterpret_cast<PyCFunction>(bpy_bmedge_calc_tangent),
4188 METH_VARARGS,
4189 bpy_bmedge_calc_tangent_doc},
4190
4191 {"normal_update",
4192 reinterpret_cast<PyCFunction>(bpy_bmedge_normal_update),
4193 METH_NOARGS,
4194 bpy_bmedge_normal_update_doc},
4195
4196 {nullptr, nullptr, 0, nullptr},
4197};
4198
4199static PyMethodDef bpy_bmface_methods[] = {
4200 {"select_set",
4201 reinterpret_cast<PyCFunction>(bpy_bm_elem_select_set),
4202 METH_O,
4203 bpy_bm_elem_select_set_doc},
4204 {"hide_set",
4205 reinterpret_cast<PyCFunction>(bpy_bm_elem_hide_set),
4206 METH_O,
4207 bpy_bm_elem_hide_set_doc},
4208
4209 {"copy_from",
4210 reinterpret_cast<PyCFunction>(bpy_bm_elem_copy_from),
4211 METH_O,
4212 bpy_bm_elem_copy_from_doc},
4213 {"copy_from_face_interp",
4214 reinterpret_cast<PyCFunction>(bpy_bmface_copy_from_face_interp),
4215 METH_VARARGS,
4216 bpy_bmface_copy_from_face_interp_doc},
4217
4218 {"copy",
4219 reinterpret_cast<PyCFunction>(bpy_bmface_copy),
4220 METH_VARARGS | METH_KEYWORDS,
4221 bpy_bmface_copy_doc},
4222
4223 {"uv_select_set",
4224 reinterpret_cast<PyCFunction>(bpy_bmface_uv_select_set),
4225 METH_O,
4226 bpy_bmface_uv_select_set_doc},
4227
4228 {"calc_area",
4229 reinterpret_cast<PyCFunction>(bpy_bmface_calc_area),
4230 METH_NOARGS,
4231 bpy_bmface_calc_area_doc},
4232 {"calc_perimeter",
4233 reinterpret_cast<PyCFunction>(bpy_bmface_calc_perimeter),
4234 METH_NOARGS,
4235 bpy_bmface_calc_perimeter_doc},
4236 {"calc_tangent_edge",
4237 reinterpret_cast<PyCFunction>(bpy_bmface_calc_tangent_edge),
4238 METH_NOARGS,
4239 bpy_bmface_calc_tangent_edge_doc},
4240 {"calc_tangent_edge_pair",
4241 reinterpret_cast<PyCFunction>(bpy_bmface_calc_tangent_edge_pair),
4242 METH_NOARGS,
4243 bpy_bmface_calc_tangent_edge_pair_doc},
4244 {"calc_tangent_edge_diagonal",
4245 reinterpret_cast<PyCFunction>(bpy_bmface_calc_tangent_edge_diagonal),
4246 METH_NOARGS,
4247 bpy_bmface_calc_tangent_edge_diagonal_doc},
4248 {"calc_tangent_vert_diagonal",
4249 reinterpret_cast<PyCFunction>(bpy_bmface_calc_tangent_vert_diagonal),
4250 METH_NOARGS,
4251 bpy_bmface_calc_tangent_vert_diagonal_doc},
4252 {"calc_center_median",
4253 reinterpret_cast<PyCFunction>(bpy_bmface_calc_center_mean),
4254 METH_NOARGS,
4255 bpy_bmface_calc_center_median_doc},
4256 {"calc_center_median_weighted",
4257 reinterpret_cast<PyCFunction>(bpy_bmface_calc_center_median_weighted),
4258 METH_NOARGS,
4259 bpy_bmface_calc_center_median_weighted_doc},
4260 {"calc_center_bounds",
4261 reinterpret_cast<PyCFunction>(bpy_bmface_calc_center_bounds),
4262 METH_NOARGS,
4263 bpy_bmface_calc_center_bounds_doc},
4264
4265 {"normal_update",
4266 reinterpret_cast<PyCFunction>(bpy_bmface_normal_update),
4267 METH_NOARGS,
4268 bpy_bmface_normal_update_doc},
4269 {"normal_flip",
4270 reinterpret_cast<PyCFunction>(bpy_bmface_normal_flip),
4271 METH_NOARGS,
4272 bpy_bmface_normal_flip_doc},
4273
4274 {nullptr, nullptr, 0, nullptr},
4275};
4276
4277static PyMethodDef bpy_bmloop_methods[] = {
4278 {"copy_from",
4279 reinterpret_cast<PyCFunction>(bpy_bm_elem_copy_from),
4280 METH_O,
4281 bpy_bm_elem_copy_from_doc},
4282 {"copy_from_face_interp",
4283 reinterpret_cast<PyCFunction>(bpy_bmloop_copy_from_face_interp),
4284 METH_VARARGS,
4285 bpy_bmloop_copy_from_face_interp_doc},
4286
4287 {"uv_select_vert_set",
4288 reinterpret_cast<PyCFunction>(bpy_bmloop_uv_select_vert_set),
4289 METH_O,
4290 bpy_bmloop_uv_select_vert_set_doc},
4291 {"uv_select_edge_set",
4292 reinterpret_cast<PyCFunction>(bpy_bmloop_uv_select_edge_set),
4293 METH_O,
4294 bpy_bmloop_uv_select_edge_set_doc},
4295
4296 {"calc_angle",
4297 reinterpret_cast<PyCFunction>(bpy_bmloop_calc_angle),
4298 METH_NOARGS,
4299 bpy_bmloop_calc_angle_doc},
4300 {"calc_normal",
4301 reinterpret_cast<PyCFunction>(bpy_bmloop_calc_normal),
4302 METH_NOARGS,
4303 bpy_bmloop_calc_normal_doc},
4304 {"calc_tangent",
4305 reinterpret_cast<PyCFunction>(bpy_bmloop_calc_tangent),
4306 METH_NOARGS,
4307 bpy_bmloop_calc_tangent_doc},
4308 {nullptr, nullptr, 0, nullptr},
4309};
4310
4311static PyMethodDef bpy_bmelemseq_methods[] = {
4312 /* odd function, initializes index values */
4313 {"index_update",
4314 reinterpret_cast<PyCFunction>(bpy_bmelemseq_index_update),
4315 METH_NOARGS,
4316 bpy_bmelemseq_index_update_doc},
4317 {nullptr, nullptr, 0, nullptr},
4318};
4319
4320static PyMethodDef bpy_bmvertseq_methods[] = {
4321 {"new",
4322 reinterpret_cast<PyCFunction>(bpy_bmvertseq_new),
4323 METH_VARARGS | METH_KEYWORDS,
4324 bpy_bmvertseq_new_doc},
4325 {"remove",
4326 reinterpret_cast<PyCFunction>(bpy_bmvertseq_remove),
4327 METH_O,
4328 bpy_bmvertseq_remove_doc},
4329
4330 /* odd function, initializes index values */
4331 {"index_update",
4332 reinterpret_cast<PyCFunction>(bpy_bmelemseq_index_update),
4333 METH_NOARGS,
4334 bpy_bmelemseq_index_update_doc},
4335 {"ensure_lookup_table",
4336 reinterpret_cast<PyCFunction>(bpy_bmelemseq_ensure_lookup_table),
4337 METH_NOARGS,
4338 bpy_bmelemseq_ensure_lookup_table_doc},
4339 {"sort",
4340 reinterpret_cast<PyCFunction>(bpy_bmelemseq_sort),
4341 METH_VARARGS | METH_KEYWORDS,
4342 bpy_bmelemseq_sort_doc},
4343 {nullptr, nullptr, 0, nullptr},
4344};
4345
4346static PyMethodDef bpy_bmedgeseq_methods[] = {
4347 {"new",
4348 reinterpret_cast<PyCFunction>(bpy_bmedgeseq_new),
4349 METH_VARARGS | METH_KEYWORDS,
4350 bpy_bmedgeseq_new_doc},
4351 {"remove",
4352 reinterpret_cast<PyCFunction>(bpy_bmedgeseq_remove),
4353 METH_O,
4354 bpy_bmedgeseq_remove_doc},
4355 /* 'bpy_bmelemseq_get' for different purpose */
4356 {"get",
4357 reinterpret_cast<PyCFunction>(bpy_bmedgeseq_get__method),
4358 METH_VARARGS,
4359 bpy_bmedgeseq_get__method_doc},
4360
4361 /* odd function, initializes index values */
4362 {"index_update",
4363 reinterpret_cast<PyCFunction>(bpy_bmelemseq_index_update),
4364 METH_NOARGS,
4365 bpy_bmelemseq_index_update_doc},
4366 {"ensure_lookup_table",
4367 reinterpret_cast<PyCFunction>(bpy_bmelemseq_ensure_lookup_table),
4368 METH_NOARGS,
4369 bpy_bmelemseq_ensure_lookup_table_doc},
4370 {"sort",
4371 reinterpret_cast<PyCFunction>(bpy_bmelemseq_sort),
4372 METH_VARARGS | METH_KEYWORDS,
4373 bpy_bmelemseq_sort_doc},
4374 {nullptr, nullptr, 0, nullptr},
4375};
4376
4377static PyMethodDef bpy_bmfaceseq_methods[] = {
4378 {"new",
4379 reinterpret_cast<PyCFunction>(bpy_bmfaceseq_new),
4380 METH_VARARGS | METH_KEYWORDS,
4381 bpy_bmfaceseq_new_doc},
4382 {"remove",
4383 reinterpret_cast<PyCFunction>(bpy_bmfaceseq_remove),
4384 METH_O,
4385 bpy_bmfaceseq_remove_doc},
4386 /* 'bpy_bmelemseq_get' for different purpose */
4387 {"get",
4388 reinterpret_cast<PyCFunction>(bpy_bmfaceseq_get__method),
4389 METH_VARARGS,
4390 bpy_bmfaceseq_get__method_doc},
4391
4392 /* odd function, initializes index values */
4393 {"index_update",
4394 reinterpret_cast<PyCFunction>(bpy_bmelemseq_index_update),
4395 METH_NOARGS,
4396 bpy_bmelemseq_index_update_doc},
4397 {"ensure_lookup_table",
4398 reinterpret_cast<PyCFunction>(bpy_bmelemseq_ensure_lookup_table),
4399 METH_NOARGS,
4400 bpy_bmelemseq_ensure_lookup_table_doc},
4401 {"sort",
4402 reinterpret_cast<PyCFunction>(bpy_bmelemseq_sort),
4403 METH_VARARGS | METH_KEYWORDS,
4404 bpy_bmelemseq_sort_doc},
4405 {nullptr, nullptr, 0, nullptr},
4406};
4407
4408static PyMethodDef bpy_bmloopseq_methods[] = {
4409 /* odd function, initializes index values */
4410 /* no: index_update() function since we can't iterate over loops */
4411 /* no: sort() function since we can't iterate over loops */
4412 {nullptr, nullptr, 0, nullptr},
4413};
4414
4415#ifdef __GNUC__
4416# ifdef __clang__
4417# pragma clang diagnostic pop
4418# else
4419# pragma GCC diagnostic pop
4420# endif
4421#endif
4422
4423/* Sequences
4424 * ========= */
4425
4426/* BMElemSeq / Iter
4427 * ---------------- */
4428
4429static PyTypeObject *bpy_bm_itype_as_pytype(const char itype)
4430{
4431 /* should cover all types */
4432 switch (BMIterType(itype)) {
4433 case BM_VERTS_OF_MESH:
4434 case BM_VERTS_OF_FACE:
4435 case BM_VERTS_OF_EDGE:
4436 return &BPy_BMVert_Type;
4437
4438 case BM_EDGES_OF_MESH:
4439 case BM_EDGES_OF_FACE:
4440 case BM_EDGES_OF_VERT:
4441 return &BPy_BMEdge_Type;
4442
4443 case BM_FACES_OF_MESH:
4444 case BM_FACES_OF_EDGE:
4445 case BM_FACES_OF_VERT:
4446 return &BPy_BMFace_Type;
4447
4448 // case BM_ALL_LOOPS_OF_FACE:
4449 case BM_LOOPS_OF_FACE:
4450 case BM_LOOPS_OF_EDGE:
4451 case BM_LOOPS_OF_VERT:
4452 case BM_LOOPS_OF_LOOP:
4453 return &BPy_BMLoop_Type;
4454 }
4455
4456 return nullptr;
4457}
4458
4459static Py_ssize_t bpy_bmelemseq_length(BPy_BMElemSeq *self)
4460{
4461 BPY_BM_CHECK_INT(self);
4462
4463 /* first check if the size is known */
4464 switch (BMIterType(self->itype)) {
4465 /* main-types */
4466 case BM_VERTS_OF_MESH:
4467 return self->bm->totvert;
4468 case BM_EDGES_OF_MESH:
4469 return self->bm->totedge;
4470 case BM_FACES_OF_MESH:
4471 return self->bm->totface;
4472
4473 /* sub-types */
4474 case BM_VERTS_OF_FACE:
4475 case BM_EDGES_OF_FACE:
4476 case BM_LOOPS_OF_FACE:
4477 BPY_BM_CHECK_INT(self->py_ele);
4478 return (reinterpret_cast<BMFace *>(self->py_ele->ele))->len;
4479
4480 case BM_VERTS_OF_EDGE:
4481 return 2;
4482
4483 default:
4484 /* quiet compiler */
4485 break;
4486 }
4487
4488 /* loop over all items, avoid this if we can */
4489 {
4490 BMIter iter;
4491 BMHeader *ele;
4492 Py_ssize_t tot = 0;
4493
4494 BM_ITER_BPY_BM_SEQ (ele, &iter, self) {
4495 tot++;
4496 }
4497 return tot;
4498 }
4499}
4500
4501static PyObject *bpy_bmelemseq_subscript_int(BPy_BMElemSeq *self, Py_ssize_t keynum)
4502{
4503 BPY_BM_CHECK_OBJ(self);
4504
4505 if (keynum < 0) {
4506 /* only get length on negative value, may loop entire seq */
4507 keynum += bpy_bmelemseq_length(self);
4508 }
4509 if (keynum >= 0) {
4510 if (self->itype <= BM_FACES_OF_MESH) {
4511 if ((self->bm->elem_table_dirty & bm_iter_itype_htype_map[self->itype]) == 0) {
4512 BMHeader *ele = nullptr;
4513 switch (self->itype) {
4514 case BM_VERTS_OF_MESH:
4515 if (keynum < self->bm->totvert) {
4516 ele = reinterpret_cast<BMHeader *>(self->bm->vtable[keynum]);
4517 }
4518 break;
4519 case BM_EDGES_OF_MESH:
4520 if (keynum < self->bm->totedge) {
4521 ele = reinterpret_cast<BMHeader *>(self->bm->etable[keynum]);
4522 }
4523 break;
4524 case BM_FACES_OF_MESH:
4525 if (keynum < self->bm->totface) {
4526 ele = reinterpret_cast<BMHeader *>(self->bm->ftable[keynum]);
4527 }
4528 break;
4529 }
4530 if (ele) {
4531 return BPy_BMElem_CreatePyObject(self->bm, ele);
4532 }
4533 /* fall through to index error below */
4534 }
4535 else {
4536 PyErr_SetString(PyExc_IndexError,
4537 "BMElemSeq[index]: outdated internal index table, "
4538 "run ensure_lookup_table() first");
4539 return nullptr;
4540 }
4541 }
4542 else {
4543 BMHeader *ele = static_cast<BMHeader *>(BM_iter_at_index(
4544 self->bm, self->itype, self->py_ele ? self->py_ele->ele : nullptr, keynum));
4545 if (ele) {
4546 return BPy_BMElem_CreatePyObject(self->bm, ele);
4547 }
4548 }
4549 }
4550
4551 PyErr_Format(PyExc_IndexError, "BMElemSeq[index]: index %d out of range", keynum);
4552 return nullptr;
4553}
4554
4556 Py_ssize_t start,
4557 Py_ssize_t stop)
4558{
4559 BMIter iter;
4560 int count = 0;
4561 bool ok;
4562
4563 PyObject *list;
4564 BMHeader *ele;
4565
4566 BPY_BM_CHECK_OBJ(self);
4567
4568 list = PyList_New(0);
4569
4570 ok = BM_iter_init(&iter, self->bm, self->itype, self->py_ele ? self->py_ele->ele : nullptr);
4571
4572 BLI_assert(ok == true);
4573
4574 if (ok == false) [[unlikely]] {
4575 return list;
4576 }
4577
4578 /* first loop up-until the start */
4579 for (ok = true; ok; ok = (BM_iter_step(&iter) != nullptr)) {
4580 if (count == start) {
4581 break;
4582 }
4583 count++;
4584 }
4585
4586 /* add items until stop */
4587 while ((ele = static_cast<BMHeader *>(BM_iter_step(&iter)))) {
4588 PyList_APPEND(list, BPy_BMElem_CreatePyObject(self->bm, ele));
4589
4590 count++;
4591 if (count == stop) {
4592 break;
4593 }
4594 }
4595
4596 return list;
4597}
4598
4599static PyObject *bpy_bmelemseq_subscript(BPy_BMElemSeq *self, PyObject *key)
4600{
4601 /* don't need error check here */
4602 if (PyIndex_Check(key)) {
4603 const Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
4604 if (i == -1 && PyErr_Occurred()) {
4605 return nullptr;
4606 }
4607 return bpy_bmelemseq_subscript_int(self, i);
4608 }
4609 if (PySlice_Check(key)) {
4610 PySliceObject *key_slice = reinterpret_cast<PySliceObject *>(key);
4611 Py_ssize_t step = 1;
4612
4613 if (key_slice->step != Py_None && !_PyEval_SliceIndex(key_slice->step, &step)) {
4614 return nullptr;
4615 }
4616 if (step != 1) {
4617 PyErr_SetString(PyExc_TypeError, "BMElemSeq[slice]: slice steps not supported");
4618 return nullptr;
4619 }
4620 if (key_slice->start == Py_None && key_slice->stop == Py_None) {
4621 return bpy_bmelemseq_subscript_slice(self, 0, PY_SSIZE_T_MAX);
4622 }
4623
4624 Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX;
4625
4626 /* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */
4627 if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) {
4628 return nullptr;
4629 }
4630 if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) {
4631 return nullptr;
4632 }
4633
4634 if (start < 0 || stop < 0) {
4635 /* only get the length for negative values */
4636 const Py_ssize_t len = bpy_bmelemseq_length(self);
4637 if (start < 0) {
4638 start += len;
4639 CLAMP_MIN(start, 0);
4640 }
4641 if (stop < 0) {
4642 stop += len;
4643 CLAMP_MIN(stop, 0);
4644 }
4645 }
4646
4647 if (stop - start <= 0) {
4648 return PyList_New(0);
4649 }
4650
4651 return bpy_bmelemseq_subscript_slice(self, start, stop);
4652 }
4653
4654 PyErr_SetString(PyExc_AttributeError, "BMElemSeq[key]: invalid key, key must be an int");
4655 return nullptr;
4656}
4657
4658static int bpy_bmelemseq_contains(BPy_BMElemSeq *self, PyObject *value)
4659{
4660 BPY_BM_CHECK_INT(self);
4661
4662 if (Py_TYPE(value) == bpy_bm_itype_as_pytype(self->itype)) {
4663 BPy_BMElem *value_bm_ele = reinterpret_cast<BPy_BMElem *>(value);
4664 if (value_bm_ele->bm == self->bm) {
4665 BMElem *ele, *ele_test = value_bm_ele->ele;
4666 BMIter iter;
4667 BM_ITER_BPY_BM_SEQ (ele, &iter, self) {
4668 if (ele == ele_test) {
4669 return 1;
4670 }
4671 }
4672 }
4673 }
4674
4675 return 0;
4676}
4677
4678/* BMElem (customdata)
4679 * ------------------- */
4680
4682{
4683 BPY_BM_CHECK_OBJ(self);
4684
4685 return BPy_BMLayerItem_GetItem(self, key);
4686}
4687
4688static int bpy_bmelem_ass_subscript(BPy_BMElem *self, BPy_BMLayerItem *key, PyObject *value)
4689{
4690 BPY_BM_CHECK_INT(self);
4691
4692 return BPy_BMLayerItem_SetItem(self, key, value);
4693}
4694
4695static PySequenceMethods bpy_bmelemseq_as_sequence = {
4696 /*sq_length*/ reinterpret_cast<lenfunc>(bpy_bmelemseq_length),
4697 /*sq_concat*/ nullptr,
4698 /*sq_repeat*/ nullptr,
4699 /* Only set this so `PySequence_Check()` returns True. */
4700 /*sq_item*/ reinterpret_cast<ssizeargfunc>(bpy_bmelemseq_subscript_int),
4701 /*was_sq_slice*/ nullptr,
4702 /*sq_ass_item*/ nullptr,
4703 /*was_sq_ass_slice*/ nullptr,
4704 /*sq_contains*/ reinterpret_cast<objobjproc>(bpy_bmelemseq_contains),
4705 /*sq_inplace_concat*/ nullptr,
4706 /*sq_inplace_repeat*/ nullptr,
4707};
4708
4709static PyMappingMethods bpy_bmelemseq_as_mapping = {
4710 /*mp_length*/ reinterpret_cast<lenfunc>(bpy_bmelemseq_length),
4711 /*mp_subscript*/ reinterpret_cast<binaryfunc>(bpy_bmelemseq_subscript),
4712 /*mp_ass_subscript*/ static_cast<objobjargproc>(nullptr),
4713};
4714
4715/* for customdata access */
4716static PyMappingMethods bpy_bm_elem_as_mapping = {
4717 /*mp_length*/ static_cast<lenfunc>(
4718 nullptr), /* Keep this empty, messes up `if elem: ...` test. */
4719 /*mp_subscript*/ reinterpret_cast<binaryfunc>(bpy_bmelem_subscript),
4720 /*mp_ass_subscript*/ reinterpret_cast<objobjargproc>(bpy_bmelem_ass_subscript),
4721};
4722
4723/* Iterator
4724 * -------- */
4725
4726static PyObject *bpy_bmelemseq_iter(BPy_BMElemSeq *self)
4727{
4728 BPy_BMIter *py_iter;
4729
4730 BPY_BM_CHECK_OBJ(self);
4731 py_iter = reinterpret_cast<BPy_BMIter *>(BPy_BMIter_CreatePyObject(self->bm));
4733 &(py_iter->iter), self->bm, self->itype, self->py_ele ? self->py_ele->ele : nullptr);
4734 return reinterpret_cast<PyObject *>(py_iter);
4735}
4736
4737static PyObject *bpy_bmiter_next(BPy_BMIter *self)
4738{
4739 BMHeader *ele = static_cast<BMHeader *>(BM_iter_step(&self->iter));
4740 if (ele == nullptr) {
4741 PyErr_SetNone(PyExc_StopIteration);
4742 return nullptr;
4743 }
4744
4745 return BPy_BMElem_CreatePyObject(self->bm, ele);
4746}
4747
4748/* Deallocate Functions
4749 * ==================== */
4750
4752{
4753 BMesh *bm = self->bm;
4754
4755 /* The mesh has not been freed by #BMesh. */
4756 if (bm) {
4758
4761 }
4764 }
4767 }
4770 }
4771
4772 bm->py_handle = nullptr;
4773
4774 if ((self->flag & BPY_BMFLAG_IS_WRAPPED) == 0) {
4776 }
4777 }
4778
4779 PyObject_DEL(self);
4780}
4781
4783{
4784 BMesh *bm = self->bm;
4785 if (bm) {
4786 void **ptr = static_cast<void **>(
4788 if (ptr) {
4789 *ptr = nullptr;
4790 }
4791 }
4792 PyObject_DEL(self);
4793}
4794
4796{
4797 BMesh *bm = self->bm;
4798 if (bm) {
4799 void **ptr = static_cast<void **>(
4801 if (ptr) {
4802 *ptr = nullptr;
4803 }
4804 }
4805 PyObject_DEL(self);
4806}
4807
4809{
4810 BMesh *bm = self->bm;
4811 if (bm) {
4812 void **ptr = static_cast<void **>(
4814 if (ptr) {
4815 *ptr = nullptr;
4816 }
4817 }
4818 PyObject_DEL(self);
4819}
4820
4822{
4823 BMesh *bm = self->bm;
4824 if (bm) {
4825 void **ptr = static_cast<void **>(
4827 if (ptr) {
4828 *ptr = nullptr;
4829 }
4830 }
4831 PyObject_DEL(self);
4832}
4833
4835{
4836 Py_XDECREF(self->py_ele);
4837
4838 PyObject_DEL(self);
4839}
4840
4841/* not sure where this should go */
4842static Py_hash_t bpy_bm_elem_hash(PyObject *self)
4843{
4844 return Py_HashPointer((reinterpret_cast<BPy_BMElem *>(self))->ele);
4845}
4846
4847static Py_hash_t bpy_bm_hash(PyObject *self)
4848{
4849 return Py_HashPointer((reinterpret_cast<BPy_BMesh *>(self))->bm);
4850}
4851
4852/* Type Docstrings
4853 * =============== */
4854
4856 /* Wrap. */
4857 bpy_bmesh_doc,
4858 "The BMesh data structure\n");
4860 /* Wrap. */
4861 bpy_bmvert_doc,
4862 "The BMesh vertex type\n");
4864 /* Wrap. */
4865 bpy_bmedge_doc,
4866 "The BMesh edge connecting 2 verts\n");
4868 /* Wrap. */
4869 bpy_bmface_doc,
4870 "The BMesh face with 3 or more sides\n");
4872 /* Wrap. */
4873 bpy_bmloop_doc,
4874 "This is normally accessed from :class:`bmesh.types.BMFace.loops` where each face loop "
4875 "represents a corner of the face.\n");
4877 /* Wrap. */
4878 bpy_bmelemseq_doc,
4879 "General sequence type used for accessing any sequence of\n"
4880 ":class:`bmesh.types.BMVert`, "
4881 ":class:`bmesh.types.BMEdge`, "
4882 ":class:`bmesh.types.BMFace`, "
4883 ":class:`bmesh.types.BMLoop`.\n"
4884 "\n"
4885 "When accessed via "
4886 ":class:`bmesh.types.BMesh.verts`, "
4887 ":class:`bmesh.types.BMesh.edges`, "
4888 ":class:`bmesh.types.BMesh.faces`\n"
4889 "there are also functions to create/remove items.\n");
4891 /* Wrap. */
4892 bpy_bmiter_doc,
4893 "Internal BMesh type for looping over verts/faces/edges,\n"
4894 "used for iterating over :class:`bmesh.types.BMElemSeq` types.\n");
4895
4896static PyObject *bpy_bmesh_repr(BPy_BMesh *self)
4897{
4898 BMesh *bm = self->bm;
4899
4900 if (bm) {
4901 return PyUnicode_FromFormat("<BMesh(%p), totvert=%d, totedge=%d, totface=%d, totloop=%d>",
4902 bm,
4903 bm->totvert,
4904 bm->totedge,
4905 bm->totface,
4906 bm->totloop);
4907 }
4908
4909 return PyUnicode_FromFormat("<BMesh dead at %p>", self);
4910}
4911
4912static PyObject *bpy_bmvert_repr(BPy_BMVert *self)
4913{
4914 BMesh *bm = self->bm;
4915
4916 if (bm) {
4917 BMVert *v = self->v;
4918 return PyUnicode_FromFormat("<BMVert(%p), index=%d>", v, BM_elem_index_get(v));
4919 }
4920
4921 return PyUnicode_FromFormat("<BMVert dead at %p>", self);
4922}
4923
4924static PyObject *bpy_bmedge_repr(BPy_BMEdge *self)
4925{
4926 BMesh *bm = self->bm;
4927
4928 if (bm) {
4929 BMEdge *e = self->e;
4930 return PyUnicode_FromFormat("<BMEdge(%p), index=%d, verts=(%p/%d, %p/%d)>",
4931 e,
4933 e->v1,
4934 BM_elem_index_get(e->v1),
4935 e->v2,
4936 BM_elem_index_get(e->v2));
4937 }
4938
4939 return PyUnicode_FromFormat("<BMEdge dead at %p>", self);
4940}
4941
4942static PyObject *bpy_bmface_repr(BPy_BMFace *self)
4943{
4944 BMesh *bm = self->bm;
4945
4946 if (bm) {
4947 BMFace *f = self->f;
4948 return PyUnicode_FromFormat(
4949 "<BMFace(%p), index=%d, totverts=%d>", f, BM_elem_index_get(f), f->len);
4950 }
4951
4952 return PyUnicode_FromFormat("<BMFace dead at %p>", self);
4953}
4954
4955static PyObject *bpy_bmloop_repr(BPy_BMLoop *self)
4956{
4957 BMesh *bm = self->bm;
4958
4959 if (bm) {
4960 BMLoop *l = self->l;
4961 return PyUnicode_FromFormat("<BMLoop(%p), index=%d, vert=%p/%d, edge=%p/%d, face=%p/%d>",
4962 l,
4964 l->v,
4966 l->e,
4968 l->f,
4970 }
4971
4972 return PyUnicode_FromFormat("<BMLoop dead at %p>", self);
4973}
4974
4975/* Types
4976 * ===== */
4977
4978PyTypeObject BPy_BMesh_Type;
4979PyTypeObject BPy_BMVert_Type;
4980PyTypeObject BPy_BMEdge_Type;
4981PyTypeObject BPy_BMFace_Type;
4982PyTypeObject BPy_BMLoop_Type;
4988PyTypeObject BPy_BMIter_Type;
4989
4991{
4992 BPy_BMesh_Type.tp_basicsize = sizeof(BPy_BMesh);
4993 BPy_BMVert_Type.tp_basicsize = sizeof(BPy_BMVert);
4994 BPy_BMEdge_Type.tp_basicsize = sizeof(BPy_BMEdge);
4995 BPy_BMFace_Type.tp_basicsize = sizeof(BPy_BMFace);
4996 BPy_BMLoop_Type.tp_basicsize = sizeof(BPy_BMLoop);
4997 BPy_BMElemSeq_Type.tp_basicsize = sizeof(BPy_BMElemSeq);
4998 BPy_BMVertSeq_Type.tp_basicsize = sizeof(BPy_BMElemSeq);
4999 BPy_BMEdgeSeq_Type.tp_basicsize = sizeof(BPy_BMElemSeq);
5000 BPy_BMFaceSeq_Type.tp_basicsize = sizeof(BPy_BMElemSeq);
5001 BPy_BMLoopSeq_Type.tp_basicsize = sizeof(BPy_BMElemSeq);
5002 BPy_BMIter_Type.tp_basicsize = sizeof(BPy_BMIter);
5003
5004 BPy_BMesh_Type.tp_name = "BMesh";
5005 BPy_BMVert_Type.tp_name = "BMVert";
5006 BPy_BMEdge_Type.tp_name = "BMEdge";
5007 BPy_BMFace_Type.tp_name = "BMFace";
5008 BPy_BMLoop_Type.tp_name = "BMLoop";
5009 BPy_BMElemSeq_Type.tp_name = "BMElemSeq";
5010 BPy_BMVertSeq_Type.tp_name = "BMVertSeq";
5011 BPy_BMEdgeSeq_Type.tp_name = "BMEdgeSeq";
5012 BPy_BMFaceSeq_Type.tp_name = "BMFaceSeq";
5013 BPy_BMLoopSeq_Type.tp_name = "BMLoopSeq";
5014 BPy_BMIter_Type.tp_name = "BMIter";
5015
5016 BPy_BMesh_Type.tp_doc = bpy_bmesh_doc;
5017 BPy_BMVert_Type.tp_doc = bpy_bmvert_doc;
5018 BPy_BMEdge_Type.tp_doc = bpy_bmedge_doc;
5019 BPy_BMFace_Type.tp_doc = bpy_bmface_doc;
5020 BPy_BMLoop_Type.tp_doc = bpy_bmloop_doc;
5021 BPy_BMElemSeq_Type.tp_doc = bpy_bmelemseq_doc;
5022 BPy_BMVertSeq_Type.tp_doc = nullptr;
5023 BPy_BMEdgeSeq_Type.tp_doc = nullptr;
5024 BPy_BMFaceSeq_Type.tp_doc = nullptr;
5025 BPy_BMLoopSeq_Type.tp_doc = nullptr;
5026 BPy_BMIter_Type.tp_doc = bpy_bmiter_doc;
5027
5028 BPy_BMesh_Type.tp_repr = reinterpret_cast<reprfunc>(bpy_bmesh_repr);
5029 BPy_BMVert_Type.tp_repr = reinterpret_cast<reprfunc>(bpy_bmvert_repr);
5030 BPy_BMEdge_Type.tp_repr = reinterpret_cast<reprfunc>(bpy_bmedge_repr);
5031 BPy_BMFace_Type.tp_repr = reinterpret_cast<reprfunc>(bpy_bmface_repr);
5032 BPy_BMLoop_Type.tp_repr = reinterpret_cast<reprfunc>(bpy_bmloop_repr);
5033 BPy_BMElemSeq_Type.tp_repr = nullptr;
5034 BPy_BMVertSeq_Type.tp_repr = nullptr;
5035 BPy_BMEdgeSeq_Type.tp_repr = nullptr;
5036 BPy_BMFaceSeq_Type.tp_repr = nullptr;
5037 BPy_BMLoopSeq_Type.tp_repr = nullptr;
5038 BPy_BMIter_Type.tp_repr = nullptr;
5039
5045 BPy_BMElemSeq_Type.tp_getset = nullptr;
5050 BPy_BMIter_Type.tp_getset = nullptr;
5051
5052 BPy_BMesh_Type.tp_methods = bpy_bmesh_methods;
5062 BPy_BMIter_Type.tp_methods = nullptr;
5063
5064 /* #BPy_BMElem_Check() uses #bpy_bm_elem_hash() to check types.
5065 * if this changes update the macro. */
5066 BPy_BMesh_Type.tp_hash = bpy_bm_hash;
5071 BPy_BMElemSeq_Type.tp_hash = nullptr;
5072 BPy_BMVertSeq_Type.tp_hash = nullptr;
5073 BPy_BMEdgeSeq_Type.tp_hash = nullptr;
5074 BPy_BMFaceSeq_Type.tp_hash = nullptr;
5075 BPy_BMLoopSeq_Type.tp_hash = nullptr;
5076 BPy_BMIter_Type.tp_hash = nullptr;
5077
5082 BPy_BMLoopSeq_Type.tp_as_sequence =
5083 nullptr; /* this is not a seq really, only for layer access */
5084
5089 BPy_BMLoopSeq_Type.tp_as_mapping = nullptr; /* this is not a seq really, only for layer access */
5090
5091 /* layer access */
5092 BPy_BMVert_Type.tp_as_mapping = &bpy_bm_elem_as_mapping;
5093 BPy_BMEdge_Type.tp_as_mapping = &bpy_bm_elem_as_mapping;
5094 BPy_BMFace_Type.tp_as_mapping = &bpy_bm_elem_as_mapping;
5095 BPy_BMLoop_Type.tp_as_mapping = &bpy_bm_elem_as_mapping;
5096
5097 BPy_BMElemSeq_Type.tp_iter = reinterpret_cast<getiterfunc>(bpy_bmelemseq_iter);
5098 BPy_BMVertSeq_Type.tp_iter = reinterpret_cast<getiterfunc>(bpy_bmelemseq_iter);
5099 BPy_BMEdgeSeq_Type.tp_iter = reinterpret_cast<getiterfunc>(bpy_bmelemseq_iter);
5100 BPy_BMFaceSeq_Type.tp_iter = reinterpret_cast<getiterfunc>(bpy_bmelemseq_iter);
5101 BPy_BMLoopSeq_Type.tp_iter = nullptr; /* no mapping */
5102
5103 /* Only 1 iterator so far. */
5104 BPy_BMIter_Type.tp_iternext = reinterpret_cast<iternextfunc>(bpy_bmiter_next);
5105 BPy_BMIter_Type.tp_iter = PyObject_SelfIter;
5106
5107 BPy_BMesh_Type.tp_dealloc = reinterpret_cast<destructor>(bpy_bmesh_dealloc);
5108 BPy_BMVert_Type.tp_dealloc = reinterpret_cast<destructor>(bpy_bmvert_dealloc);
5109 BPy_BMEdge_Type.tp_dealloc = reinterpret_cast<destructor>(bpy_bmedge_dealloc);
5110 BPy_BMFace_Type.tp_dealloc = reinterpret_cast<destructor>(bpy_bmface_dealloc);
5111 BPy_BMLoop_Type.tp_dealloc = reinterpret_cast<destructor>(bpy_bmloop_dealloc);
5112 BPy_BMElemSeq_Type.tp_dealloc = reinterpret_cast<destructor>(bpy_bmelemseq_dealloc);
5113 BPy_BMVertSeq_Type.tp_dealloc = reinterpret_cast<destructor>(bpy_bmelemseq_dealloc);
5114 BPy_BMEdgeSeq_Type.tp_dealloc = reinterpret_cast<destructor>(bpy_bmelemseq_dealloc);
5115 BPy_BMFaceSeq_Type.tp_dealloc = reinterpret_cast<destructor>(bpy_bmelemseq_dealloc);
5116 BPy_BMLoopSeq_Type.tp_dealloc = reinterpret_cast<destructor>(bpy_bmelemseq_dealloc);
5117 BPy_BMIter_Type.tp_dealloc = nullptr;
5118
5119 BPy_BMesh_Type.tp_flags = Py_TPFLAGS_DEFAULT;
5120 BPy_BMVert_Type.tp_flags = Py_TPFLAGS_DEFAULT;
5121 BPy_BMEdge_Type.tp_flags = Py_TPFLAGS_DEFAULT;
5122 BPy_BMFace_Type.tp_flags = Py_TPFLAGS_DEFAULT;
5123 BPy_BMLoop_Type.tp_flags = Py_TPFLAGS_DEFAULT;
5124 BPy_BMElemSeq_Type.tp_flags = Py_TPFLAGS_DEFAULT;
5125 BPy_BMVertSeq_Type.tp_flags = Py_TPFLAGS_DEFAULT;
5126 BPy_BMEdgeSeq_Type.tp_flags = Py_TPFLAGS_DEFAULT;
5127 BPy_BMFaceSeq_Type.tp_flags = Py_TPFLAGS_DEFAULT;
5128 BPy_BMLoopSeq_Type.tp_flags = Py_TPFLAGS_DEFAULT;
5129 BPy_BMIter_Type.tp_flags = Py_TPFLAGS_DEFAULT;
5130
5131 PyType_Ready(&BPy_BMesh_Type);
5132 PyType_Ready(&BPy_BMVert_Type);
5133 PyType_Ready(&BPy_BMEdge_Type);
5134 PyType_Ready(&BPy_BMFace_Type);
5135 PyType_Ready(&BPy_BMLoop_Type);
5136 PyType_Ready(&BPy_BMElemSeq_Type);
5137 PyType_Ready(&BPy_BMVertSeq_Type);
5138 PyType_Ready(&BPy_BMEdgeSeq_Type);
5139 PyType_Ready(&BPy_BMFaceSeq_Type);
5140 PyType_Ready(&BPy_BMLoopSeq_Type);
5141 PyType_Ready(&BPy_BMIter_Type);
5142}
5143
5144/* bmesh.types submodule
5145 * ********************* */
5146
5147/* This exists to declare substitutions. */
5149 /* Wrap. */
5150 BPy_BM_types_module_doc,
5151 "\n"
5152 ".. |UV_STICKY_SELECT_MODE_REF| replace:: "
5153 "(:class:`bpy.types.ToolSettings.uv_sticky_select_mode` which may be passed in directly).\n"
5154 "\n"
5155 ".. |UV_STICKY_SELECT_MODE_TYPE| replace:: "
5156 "Literal['SHARED_LOCATION', 'DISABLED', 'SHARED_VERTEX']\n"
5157 "\n"
5158 ".. |UV_SELECT_FLUSH_MODE_NEEDED| replace:: "
5159 "This function is selection-mode independent, "
5160 "typically :meth:`bmesh.types.BMesh.uv_select_flush_mode` should be called afterwards.\n"
5161 "\n"
5162 ".. |UV_SELECT_SYNC_TO_MESH_NEEDED| replace:: "
5163 "This function doesn't flush the selection to the mesh, "
5164 "typically :meth:`bmesh.types.BMesh.uv_select_sync_to_mesh` should be called afterwards.\n");
5165static PyModuleDef BPy_BM_types_module_def = {
5166 /*m_base*/ PyModuleDef_HEAD_INIT,
5167 /*m_name*/ "bmesh.types",
5168 /*m_doc*/ BPy_BM_types_module_doc,
5169 /*m_size*/ 0,
5170 /*m_methods*/ nullptr,
5171 /*m_slots*/ nullptr,
5172 /*m_traverse*/ nullptr,
5173 /*m_clear*/ nullptr,
5174 /*m_free*/ nullptr,
5175};
5176
5178{
5179 PyObject *submodule;
5180
5181 submodule = PyModule_Create(&BPy_BM_types_module_def);
5182
5183 /* `bmesh_py_types.cc` */
5184 PyModule_AddType(submodule, &BPy_BMesh_Type);
5185 PyModule_AddType(submodule, &BPy_BMVert_Type);
5186 PyModule_AddType(submodule, &BPy_BMEdge_Type);
5187 PyModule_AddType(submodule, &BPy_BMFace_Type);
5188 PyModule_AddType(submodule, &BPy_BMLoop_Type);
5189 PyModule_AddType(submodule, &BPy_BMElemSeq_Type);
5190 PyModule_AddType(submodule, &BPy_BMVertSeq_Type);
5191 PyModule_AddType(submodule, &BPy_BMEdgeSeq_Type);
5192 PyModule_AddType(submodule, &BPy_BMFaceSeq_Type);
5193 PyModule_AddType(submodule, &BPy_BMLoopSeq_Type);
5194 PyModule_AddType(submodule, &BPy_BMIter_Type);
5195 /* `bmesh_py_types_select.cc` */
5196 PyModule_AddType(submodule, &BPy_BMEditSelSeq_Type);
5197 PyModule_AddType(submodule, &BPy_BMEditSelIter_Type);
5198 /* `bmesh_py_types_customdata.cc` */
5199 PyModule_AddType(submodule, &BPy_BMLayerAccessVert_Type);
5200 PyModule_AddType(submodule, &BPy_BMLayerAccessEdge_Type);
5201 PyModule_AddType(submodule, &BPy_BMLayerAccessFace_Type);
5202 PyModule_AddType(submodule, &BPy_BMLayerAccessLoop_Type);
5203 PyModule_AddType(submodule, &BPy_BMLayerCollection_Type);
5204 PyModule_AddType(submodule, &BPy_BMLayerItem_Type);
5205 /* `bmesh_py_types_meshdata.cc` */
5206 PyModule_AddType(submodule, &BPy_BMLoopUV_Type);
5207 PyModule_AddType(submodule, &BPy_BMVertSkin_Type);
5208 PyModule_AddType(submodule, &BPy_BMDeformVert_Type);
5209
5210 return submodule;
5211}
5212
5213/* Utility Functions
5214 * ***************** */
5215
5216PyObject *BPy_BMesh_CreatePyObject(BMesh *bm, int flag)
5217{
5218 BPy_BMesh *self;
5219
5220 if (bm->py_handle) {
5221 self = static_cast<BPy_BMesh *>(bm->py_handle);
5222 Py_INCREF(self);
5223 }
5224 else {
5225 self = PyObject_New(BPy_BMesh, &BPy_BMesh_Type);
5226 self->bm = bm;
5227 self->flag = flag;
5228
5229 bm->py_handle = self; /* point back */
5230
5231/* avoid allocating layers when we don't have to */
5232#if 0
5237#endif
5238 }
5239
5240 return reinterpret_cast<PyObject *>(self);
5241}
5242
5244{
5245 BPy_BMVert *self;
5246
5247 void **ptr = static_cast<void **>(
5249
5250 /* bmesh may free layers, ensure we have one to store ourself */
5251 if (ptr == nullptr) [[unlikely]] {
5253 ptr = static_cast<void **>(CustomData_bmesh_get(&bm->vdata, v->head.data, CD_BM_ELEM_PYPTR));
5254 }
5255
5256 if (*ptr != nullptr) {
5257 self = static_cast<BPy_BMVert *>(*ptr);
5258 Py_INCREF(self);
5259 }
5260 else {
5261 self = PyObject_New(BPy_BMVert, &BPy_BMVert_Type);
5262 BLI_assert(v != nullptr);
5263 self->bm = bm;
5264 self->v = v;
5265 *ptr = self;
5266 }
5267 return reinterpret_cast<PyObject *>(self);
5268}
5269
5271{
5272 BPy_BMEdge *self;
5273
5274 void **ptr = static_cast<void **>(
5276
5277 /* bmesh may free layers, ensure we have one to store ourself */
5278 if (ptr == nullptr) [[unlikely]] {
5280 ptr = static_cast<void **>(CustomData_bmesh_get(&bm->edata, e->head.data, CD_BM_ELEM_PYPTR));
5281 }
5282
5283 if (*ptr != nullptr) {
5284 self = static_cast<BPy_BMEdge *>(*ptr);
5285 Py_INCREF(self);
5286 }
5287 else {
5288 self = PyObject_New(BPy_BMEdge, &BPy_BMEdge_Type);
5289 BLI_assert(e != nullptr);
5290 self->bm = bm;
5291 self->e = e;
5292 *ptr = self;
5293 }
5294 return reinterpret_cast<PyObject *>(self);
5295}
5296
5298{
5299 BPy_BMFace *self;
5300
5301 void **ptr = static_cast<void **>(
5303
5304 /* bmesh may free layers, ensure we have one to store ourself */
5305 if (ptr == nullptr) [[unlikely]] {
5307 ptr = static_cast<void **>(CustomData_bmesh_get(&bm->pdata, f->head.data, CD_BM_ELEM_PYPTR));
5308 }
5309
5310 if (*ptr != nullptr) {
5311 self = static_cast<BPy_BMFace *>(*ptr);
5312 Py_INCREF(self);
5313 }
5314 else {
5315 self = PyObject_New(BPy_BMFace, &BPy_BMFace_Type);
5316 BLI_assert(f != nullptr);
5317 self->bm = bm;
5318 self->f = f;
5319 *ptr = self;
5320 }
5321 return reinterpret_cast<PyObject *>(self);
5322}
5323
5325{
5326 BPy_BMLoop *self;
5327
5328 void **ptr = static_cast<void **>(
5330
5331 /* bmesh may free layers, ensure we have one to store ourself */
5332 if (ptr == nullptr) [[unlikely]] {
5334 ptr = static_cast<void **>(CustomData_bmesh_get(&bm->ldata, l->head.data, CD_BM_ELEM_PYPTR));
5335 }
5336
5337 if (*ptr != nullptr) {
5338 self = static_cast<BPy_BMLoop *>(*ptr);
5339 Py_INCREF(self);
5340 }
5341 else {
5342 self = PyObject_New(BPy_BMLoop, &BPy_BMLoop_Type);
5343 BLI_assert(l != nullptr);
5344 self->bm = bm;
5345 self->l = l;
5346 *ptr = self;
5347 }
5348 return reinterpret_cast<PyObject *>(self);
5349}
5350
5351PyObject *BPy_BMElemSeq_CreatePyObject(BMesh *bm, BPy_BMElem *py_ele, const char itype)
5352{
5353 BPy_BMElemSeq *self = PyObject_New(BPy_BMElemSeq, &BPy_BMElemSeq_Type);
5354 self->bm = bm;
5355 self->py_ele = py_ele; /* can be nullptr */
5356 self->itype = itype;
5357 Py_XINCREF(py_ele);
5358 return reinterpret_cast<PyObject *>(self);
5359}
5360
5362{
5363 BPy_BMElemSeq *self = PyObject_New(BPy_BMElemSeq, &BPy_BMVertSeq_Type);
5364 self->bm = bm;
5365 self->py_ele = nullptr; /* unused */
5366 self->itype = BM_VERTS_OF_MESH;
5367 return reinterpret_cast<PyObject *>(self);
5368}
5369
5371{
5372 BPy_BMElemSeq *self = PyObject_New(BPy_BMElemSeq, &BPy_BMEdgeSeq_Type);
5373 self->bm = bm;
5374 self->py_ele = nullptr; /* unused */
5375 self->itype = BM_EDGES_OF_MESH;
5376 return reinterpret_cast<PyObject *>(self);
5377}
5378
5380{
5381 BPy_BMElemSeq *self = PyObject_New(BPy_BMElemSeq, &BPy_BMFaceSeq_Type);
5382 self->bm = bm;
5383 self->py_ele = nullptr; /* unused */
5384 self->itype = BM_FACES_OF_MESH;
5385 return reinterpret_cast<PyObject *>(self);
5386}
5387
5389{
5390 BPy_BMElemSeq *self = PyObject_New(BPy_BMElemSeq, &BPy_BMLoopSeq_Type);
5391 self->bm = bm;
5392 self->py_ele = nullptr; /* unused */
5393 self->itype = 0; /* should never be passed to the iterator function */
5394 return reinterpret_cast<PyObject *>(self);
5395}
5396
5398{
5399 BPy_BMIter *self = PyObject_New(BPy_BMIter, &BPy_BMIter_Type);
5400 self->bm = bm;
5401 /* caller must initialize 'iter' member */
5402 return reinterpret_cast<PyObject *>(self);
5403}
5404
5406{
5407 switch (ele->htype) {
5408 case BM_VERT:
5409 return BPy_BMVert_CreatePyObject(bm, reinterpret_cast<BMVert *>(ele));
5410 case BM_EDGE:
5411 return BPy_BMEdge_CreatePyObject(bm, reinterpret_cast<BMEdge *>(ele));
5412 case BM_FACE:
5413 return BPy_BMFace_CreatePyObject(bm, reinterpret_cast<BMFace *>(ele));
5414 case BM_LOOP:
5415 return BPy_BMLoop_CreatePyObject(bm, reinterpret_cast<BMLoop *>(ele));
5416 default:
5418 PyErr_SetString(PyExc_SystemError, "internal error");
5419 return nullptr;
5420 }
5421}
5422
5424{
5425 if (self->bm) [[likely]] {
5426
5427/* far too slow to enable by default but handy
5428 * to uncomment for debugging tricky errors,
5429 * note that this will throw error on entering a
5430 * function where the actual error will be caused by
5431 * the previous action. */
5432#if 0
5433 if (BM_mesh_is_valid(self->bm) == false) {
5434 PyErr_Format(
5435 PyExc_ReferenceError, "BMesh used by %.200s has become invalid", Py_TYPE(self)->tp_name);
5436 return -1;
5437 }
5438#endif
5439
5440 return 0;
5441 }
5442
5443 PyErr_Format(
5444 PyExc_ReferenceError, "BMesh data of type %.200s has been removed", Py_TYPE(self)->tp_name);
5445 return -1;
5446}
5447
5449 const char *error_prefix,
5450 void **args,
5451 uint args_tot)
5452{
5453 int ret = 0;
5454
5455 while (args_tot--) {
5456 BPy_BMGeneric *py_bm_elem = static_cast<BPy_BMGeneric *>(args[args_tot]);
5457 if (py_bm_elem) {
5458
5459 BLI_assert(BPy_BMesh_Check(py_bm_elem) || BPy_BMElem_Check(py_bm_elem));
5460
5461 ret = bpy_bm_generic_valid_check(py_bm_elem);
5462 if (ret == -1) [[unlikely]] {
5463 break;
5464 }
5465
5466 if (py_bm_elem->bm != bm_source) [[unlikely]] {
5467 /* could give more info here */
5468 PyErr_Format(PyExc_ValueError,
5469 "%.200s: BMesh data of type %.200s is from another mesh",
5470 error_prefix,
5471 Py_TYPE(py_bm_elem)->tp_name);
5472 ret = -1;
5473 break;
5474 }
5475 }
5476 }
5477
5478 return ret;
5479}
5480
5481int bpy_bm_check_uv_select_sync_valid(BMesh *bm, const char *error_prefix)
5482{
5483 int ret = 0;
5484 if (bm->uv_select_sync_valid == false) {
5485 PyErr_Format(PyExc_ValueError, "%s: bm.uv_select_sync_valid: must be true", error_prefix);
5486 ret = -1;
5487 }
5488 return ret;
5489}
5490
5491int bpy_bm_uv_layer_offset_or_error(BMesh *bm, const char *error_prefix)
5492{
5493 const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_PROP_FLOAT2);
5494 if (cd_loop_uv_offset == -1) {
5495 PyErr_Format(PyExc_ValueError, "%s: failed, no UV layer found", error_prefix);
5496 }
5497 return cd_loop_uv_offset;
5498}
5499
5500int bpy_bm_check_bm_match_or_error(BMesh *bm_a, BMesh *bm_b, const char *error_prefix)
5501{
5502 if (bm_a != bm_b) {
5503 PyErr_Format(PyExc_ValueError, "%s: elements must be from a singe BMesh", error_prefix);
5504 return -1;
5505 }
5506 return 0;
5507}
5508
5509void bpy_bm_generic_invalidate(BPy_BMGeneric *self)
5510{
5511 self->bm = nullptr;
5512}
5513
5515 PyObject *seq_fast,
5516 Py_ssize_t min,
5517 Py_ssize_t max,
5518 Py_ssize_t *r_seq_num,
5519 const char htype,
5520 const bool do_unique_check,
5521 const bool do_bm_check,
5522 const char *error_prefix)
5523{
5524 BMesh *bm = (r_bm && *r_bm) ? *r_bm : nullptr;
5525 PyObject **seq_fast_items = PySequence_Fast_ITEMS(seq_fast);
5526 const Py_ssize_t seq_num = PySequence_Fast_GET_SIZE(seq_fast);
5527 Py_ssize_t i, i_last_dirty = PY_SSIZE_T_MAX;
5528
5529 BPy_BMElem *item;
5530 BMElem **alloc;
5531
5532 *r_seq_num = 0;
5533
5534 if (seq_num < min || seq_num > max) {
5535 PyErr_Format(PyExc_TypeError,
5536 "%s: sequence incorrect size, expected [%d - %d], given %d",
5537 error_prefix,
5538 min,
5539 max,
5540 seq_num);
5541 return nullptr;
5542 }
5543
5544 /* from now on, use goto */
5545 alloc = static_cast<BMElem **>(PyMem_MALLOC(seq_num * sizeof(BPy_BMElem **)));
5546
5547 for (i = 0; i < seq_num; i++) {
5548 item = reinterpret_cast<BPy_BMElem *>(seq_fast_items[i]);
5549
5550 if (!BPy_BMElem_CheckHType(Py_TYPE(item), htype)) {
5551 PyErr_Format(PyExc_TypeError,
5552 "%s: expected %.200s, not '%.200s'",
5553 error_prefix,
5555 Py_TYPE(item)->tp_name);
5556 goto err_cleanup;
5557 }
5558 else if (!BPY_BM_IS_VALID(item)) {
5559 PyErr_Format(
5560 PyExc_TypeError, "%s: %d %s has been removed", error_prefix, i, Py_TYPE(item)->tp_name);
5561 goto err_cleanup;
5562 }
5563 /* trick so we can ensure all items have the same mesh,
5564 * and allows us to pass the 'bm' as nullptr. */
5565 else if (do_bm_check && (bm && bm != item->bm)) {
5566 PyErr_Format(PyExc_ValueError,
5567 "%s: %d %s is from another mesh",
5568 error_prefix,
5569 i,
5571 goto err_cleanup;
5572 }
5573
5574 if (bm == nullptr) {
5575 bm = item->bm;
5576 }
5577
5578 alloc[i] = item->ele;
5579
5580 if (do_unique_check) {
5582 i_last_dirty = i;
5583 }
5584 }
5585
5586 if (do_unique_check) {
5587 /* check for double verts! */
5588 bool ok = true;
5589 for (i = 0; i < seq_num; i++) {
5590 if (BM_elem_flag_test(alloc[i], BM_ELEM_INTERNAL_TAG) == false) [[unlikely]] {
5591 ok = false;
5592 }
5593
5594 /* ensure we don't leave this enabled */
5596 }
5597
5598 if (ok == false) {
5599 /* Cleared above. */
5600 i_last_dirty = PY_SSIZE_T_MAX;
5601 PyErr_Format(PyExc_ValueError,
5602 "%s: found the same %.200s used multiple times",
5603 error_prefix,
5605 goto err_cleanup;
5606 }
5607 }
5608
5609 *r_seq_num = seq_num;
5610 if (r_bm) {
5611 *r_bm = bm;
5612 }
5613 return alloc;
5614
5615err_cleanup:
5616 if (do_unique_check && (i_last_dirty != PY_SSIZE_T_MAX)) {
5617 for (i = 0; i <= i_last_dirty; i++) {
5619 }
5620 }
5621 PyMem_FREE(alloc);
5622 return nullptr;
5623}
5624
5626 PyObject *seq,
5627 Py_ssize_t min,
5628 Py_ssize_t max,
5629 Py_ssize_t *r_seq_num,
5630 const char htype,
5631 const bool do_unique_check,
5632 const bool do_bm_check,
5633 const char *error_prefix)
5634{
5635 PyObject *seq_fast;
5636 PyObject *ret;
5637
5638 if (!(seq_fast = PySequence_Fast(seq, error_prefix))) {
5639 return nullptr;
5640 }
5641
5642 ret = static_cast<PyObject *>(BPy_BMElem_PySeq_As_Array_FAST(
5643 r_bm, seq_fast, min, max, r_seq_num, htype, do_unique_check, do_bm_check, error_prefix));
5644
5645 Py_DECREF(seq_fast);
5646 return ret;
5647}
5648
5650 PyObject *seq,
5651 Py_ssize_t min,
5652 Py_ssize_t max,
5653 Py_ssize_t *r_seq_num,
5654 bool do_unique_check,
5655 bool do_bm_check,
5656 const char *error_prefix)
5657{
5658 return static_cast<BMVert **>(BPy_BMElem_PySeq_As_Array(
5659 r_bm, seq, min, max, r_seq_num, BM_VERT, do_unique_check, do_bm_check, error_prefix));
5660}
5662 PyObject *seq,
5663 Py_ssize_t min,
5664 Py_ssize_t max,
5665 Py_ssize_t *r_seq_num,
5666 bool do_unique_check,
5667 bool do_bm_check,
5668 const char *error_prefix)
5669{
5670 return static_cast<BMEdge **>(BPy_BMElem_PySeq_As_Array(
5671 r_bm, seq, min, max, r_seq_num, BM_EDGE, do_unique_check, do_bm_check, error_prefix));
5672}
5674 PyObject *seq,
5675 Py_ssize_t min,
5676 Py_ssize_t max,
5677 Py_ssize_t *r_seq_num,
5678 bool do_unique_check,
5679 bool do_bm_check,
5680 const char *error_prefix)
5681{
5682 return static_cast<BMFace **>(BPy_BMElem_PySeq_As_Array(
5683 r_bm, seq, min, max, r_seq_num, BM_FACE, do_unique_check, do_bm_check, error_prefix));
5684}
5686 PyObject *seq,
5687 Py_ssize_t min,
5688 Py_ssize_t max,
5689 Py_ssize_t *r_seq_num,
5690 bool do_unique_check,
5691 bool do_bm_check,
5692 const char *error_prefix)
5693{
5694 return static_cast<BMLoop **>(BPy_BMElem_PySeq_As_Array(
5695 r_bm, seq, min, max, r_seq_num, BM_LOOP, do_unique_check, do_bm_check, error_prefix));
5696}
5697
5698PyObject *BPy_BMElem_Array_As_Tuple(BMesh *bm, BMHeader **elem, Py_ssize_t elem_num)
5699{
5700 Py_ssize_t i;
5701 PyObject *ret = PyTuple_New(elem_num);
5702 for (i = 0; i < elem_num; i++) {
5703 PyTuple_SET_ITEM(ret, i, BPy_BMElem_CreatePyObject(bm, elem[i]));
5704 }
5705 return ret;
5706}
5707PyObject *BPy_BMVert_Array_As_Tuple(BMesh *bm, BMVert **elem, Py_ssize_t elem_num)
5708{
5709 Py_ssize_t i;
5710 PyObject *ret = PyTuple_New(elem_num);
5711 for (i = 0; i < elem_num; i++) {
5712 PyTuple_SET_ITEM(ret, i, BPy_BMVert_CreatePyObject(bm, elem[i]));
5713 }
5714 return ret;
5715}
5716PyObject *BPy_BMEdge_Array_As_Tuple(BMesh *bm, BMEdge **elem, Py_ssize_t elem_num)
5717{
5718 Py_ssize_t i;
5719 PyObject *ret = PyTuple_New(elem_num);
5720 for (i = 0; i < elem_num; i++) {
5721 PyTuple_SET_ITEM(ret, i, BPy_BMEdge_CreatePyObject(bm, elem[i]));
5722 }
5723
5724 return ret;
5725}
5726PyObject *BPy_BMFace_Array_As_Tuple(BMesh *bm, BMFace **elem, Py_ssize_t elem_num)
5727{
5728 Py_ssize_t i;
5729 PyObject *ret = PyTuple_New(elem_num);
5730 for (i = 0; i < elem_num; i++) {
5731 PyTuple_SET_ITEM(ret, i, BPy_BMFace_CreatePyObject(bm, elem[i]));
5732 }
5733
5734 return ret;
5735}
5736PyObject *BPy_BMLoop_Array_As_Tuple(BMesh *bm, BMLoop *const *elem, Py_ssize_t elem_num)
5737{
5738 Py_ssize_t i;
5739 PyObject *ret = PyTuple_New(elem_num);
5740 for (i = 0; i < elem_num; i++) {
5741 PyTuple_SET_ITEM(ret, i, BPy_BMLoop_CreatePyObject(bm, elem[i]));
5742 }
5743
5744 return ret;
5745}
5746
5747int BPy_BMElem_CheckHType(PyTypeObject *type, const char htype)
5748{
5749 return (((htype & BM_VERT) && (type == &BPy_BMVert_Type)) ||
5750 ((htype & BM_EDGE) && (type == &BPy_BMEdge_Type)) ||
5751 ((htype & BM_FACE) && (type == &BPy_BMFace_Type)) ||
5752 ((htype & BM_LOOP) && (type == &BPy_BMLoop_Type)));
5753}
5754
5755char *BPy_BMElem_StringFromHType_ex(const char htype, char ret[32])
5756{
5757 /* Zero to ensure string is always null terminated. */
5758 const char *ret_array[4];
5759 int i = 0;
5760 if (htype & BM_VERT) {
5761 ret_array[i++] = BPy_BMVert_Type.tp_name;
5762 }
5763 if (htype & BM_EDGE) {
5764 ret_array[i++] = BPy_BMEdge_Type.tp_name;
5765 }
5766 if (htype & BM_FACE) {
5767 ret_array[i++] = BPy_BMFace_Type.tp_name;
5768 }
5769 if (htype & BM_LOOP) {
5770 ret_array[i++] = BPy_BMLoop_Type.tp_name;
5771 }
5772 ret[0] = '(';
5773 int ret_ofs = BLI_string_join_array_by_sep_char(ret + 1, 30, '/', ret_array, i) + 1;
5774 ret[ret_ofs] = ')';
5775 ret[ret_ofs + 1] = '\0';
5776 return ret;
5777}
5778char *BPy_BMElem_StringFromHType(const char htype)
5779{
5780 /* Zero to ensure string is always null terminated. */
5781 static char ret[32];
5782 return BPy_BMElem_StringFromHType_ex(htype, ret);
5783}
5784
5785/* -------------------------------------------------------------------- */
5786/* keep at bottom */
5787
5788/* This function is called on free, it should stay quite fast */
5790{
5791 if (self->flag & BPY_BMFLAG_IS_WRAPPED) {
5792 /* Currently NOP - this works without warnings now. */
5793 }
5794}
5795
5796} // namespace blender
CustomData interface, see also DNA_customdata_types.h.
#define G_MAIN
General operations, lookup, etc. for blender objects.
#define MAXMAT
Object is a sort of wrapper for general info.
#define BLI_assert_unreachable()
#define POINTER_AS_INT(i)
#define CLAMP_MIN(a, b)
#define BM_ELEM_SELECT_UV_EDGE
#define BM_elem_index_get(ele)
#define BM_elem_flag_disable(ele, hflag)
#define BM_elem_flag_set(ele, hflag, val)
#define BM_elem_index_set(ele, index)
#define BM_elem_flag_test(ele, hflag)
#define BM_elem_flag_enable(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
#define BM_iter_init(iter, bm, itype, data)
#define BM_elem_hide_set(bm, ele, hide)
#define BMSelectFlushFlag_Default
#define CD_MASK_BM_ELEM_PYPTR
#define BPY_BM_HFLAG_ALL_STR
#define BPY_BM_HTYPE_NOLOOP
#define BPy_BMFace_Check(v)
#define BPY_BM_CHECK_OBJ(obj)
#define BPY_BM_CHECK_SOURCE_INT(bm, errmsg,...)
#define BPy_BMVert_Check(v)
#define BPy_BMElem_Check(v)
#define BPy_BMesh_Check(v)
#define BPy_BMEdge_Check(v)
#define BPY_BM_CHECK_SOURCE_OBJ(bm, errmsg,...)
#define BPY_BM_IS_VALID(obj)
#define BM_ITER_BPY_BM_SEQ(ele, iter, bpy_bmelemseq)
#define BPY_BM_CHECK_INT(obj)
btScalar max
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
constexpr Span()=default
#define FLT_MAX
#define shared
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
#define BaseMath_ReadCallback(_self)
Definition mathutils.hh:147
void fill_index_range(MutableSpan< T > span, const T start=0)
const Mesh * mesh_get_eval_deform(Depsgraph *depsgraph, const Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
BMesh Iterators.
static PyObject * bpy_bmedge_normal_update(BPy_BMEdge *self)
static PyMappingMethods bpy_bmelemseq_as_mapping
PyTypeObject BPy_BMLoopUV_Type
void BM_face_calc_center_median(const BMFace *f, float r_cent[3])
int CustomData_get_offset(const CustomData *data, eCustomDataType type)
BMFace * BM_face_copy(BMesh *bm_dst, const BMCustomDataCopyMap &cd_face_map, const BMCustomDataCopyMap &cd_loop_map, BMFace *f, const bool copy_verts, const bool copy_edges)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BM_edge_calc_face_tangent(const BMEdge *e, const BMLoop *e_loop, float r_tangent[3])
BMESH EDGE/FACE TANGENT.
int bpy_bm_uv_layer_offset_or_error(BMesh *bm, const char *error_prefix)
BMFace * BM_face_create_verts(BMesh *bm, BMVert **vert_arr, const int len, const BMFace *f_example, const eBMCreateFlag create_flag, const bool create_edges)
static PyMethodDef bpy_bmloopseq_methods[]
int PyC_FlagSet_ToBitfield(const PyC_FlagSet *items, PyObject *value, int *r_value, const char *error_prefix)
static PyObject * bpy_bmvertseq_get(BPy_BMesh *self, void *)
PyTypeObject BPy_BMLayerAccessVert_Type
static PyObject * bpy_bmface_calc_center_mean(BPy_BMFace *self)
void BM_mesh_uvselect_mode_flush_ex(BMesh *bm, const short selectmode, const bool flush_down)
static PyObject * bpy_bmloop_calc_tangent(BPy_BMLoop *self)
static PyGetSetDef bpy_bmedge_getseters[]
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
static PyGetSetDef bpy_bmfaceseq_getseters[]
void BM_data_layer_add(BMesh *bm, CustomData *data, int type)
void * BPy_BMElem_PySeq_As_Array_FAST(BMesh **r_bm, PyObject *seq_fast, Py_ssize_t min, Py_ssize_t max, Py_ssize_t *r_seq_num, const char htype, const bool do_unique_check, const bool do_bm_check, const char *error_prefix)
static PyObject * bpy_bm_is_valid_get(BPy_BMGeneric *self, void *)
static PyObject * bpy_bmvert_calc_shell_factor(BPy_BMVert *self)
static PyObject * bpy_bmloop_uv_select_vert_set(BPy_BMLoop *self, PyObject *value)
int bpy_bm_check_bm_match_or_error(BMesh *bm_a, BMesh *bm_b, const char *error_prefix)
BLI_INLINE bool BM_edge_is_wire(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void * CustomData_bmesh_get(const CustomData *data, void *block, eCustomDataType type)
static int bpy_bmvert_normal_set(BPy_BMVert *self, PyObject *value, void *)
PyTypeObject BPy_BMLoop_Type
static PyObject * bpy_bmface_copy_from_face_interp(BPy_BMFace *self, PyObject *args)
static PyObject * bpy_bmesh_uv_select_sync_valid_get(BPy_BMesh *self, void *)
int PyC_ParseBool(PyObject *o, void *p)
static PyObject * bpy_bmloopseq_get(BPy_BMesh *self, void *)
static int bpy_bmface_normal_set(BPy_BMFace *self, PyObject *value, void *)
void BM_mesh_free(BMesh *bm)
BMesh Free Mesh.
static int bpy_bm_elem_index_set(BPy_BMElem *self, PyObject *value, void *)
static PyModuleDef BPy_BM_types_module_def
void BM_face_normal_flip(BMesh *bm, BMFace *f)
static PyObject * bpy_bmvert_normal_get(BPy_BMVert *self, void *)
PyTypeObject BPy_BMVertSeq_Type
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)
unsigned int uint
Definition BKE_text.h:55
static PyObject * bpy_bm_elem_copy_from(BPy_BMElem *self, BPy_BMElem *value)
static PyObject * bpy_bmesh_normal_update(BPy_BMesh *self)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
PyTypeObject BPy_BMVert_Type
void BM_mesh_elem_table_ensure(BMesh *bm, const char htype)
void BM_vert_kill(BMesh *bm, BMVert *v)
float BM_edge_calc_face_angle_signed_ex(const BMEdge *e, const float fallback)
BMESH EDGE/FACE ANGLE.
static PyObject * bpy_bmvert_copy_from_vert_interp(BPy_BMVert *self, PyObject *args)
static PyMethodDef bpy_bmedge_methods[]
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
const char bm_iter_itype_htype_map[BM_ITYPE_MAX]
static PyObject * bpy_bmface_calc_center_median_weighted(BPy_BMFace *self)
static PyObject * bpy_bmelemseq_subscript_slice(BPy_BMElemSeq *self, Py_ssize_t start, Py_ssize_t stop)
bool BM_vert_is_wire(const BMVert *v)
static PyObject * bpy_bmesh_repr(BPy_BMesh *self)
BMVert ** BPy_BMVert_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)
PyTypeObject BPy_BMLayerAccessFace_Type
static PyObject * bpy_bmfaceseq_get__method(BPy_BMElemSeq *self, PyObject *args)
static PyObject * bpy_bmesh_select_history_get(BPy_BMesh *self, void *)
static int bpy_bmvert_co_set(BPy_BMVert *self, PyObject *value, void *)
static PyMethodDef bpy_bmelemseq_methods[]
static PyObject * bpy_bmvert_calc_edge_angle(BPy_BMVert *self, PyObject *args)
static PyGetSetDef bpy_bmvert_getseters[]
BMCustomDataCopyMap CustomData_bmesh_copy_map_calc(const CustomData &src, const CustomData &dst, eCustomDataMask mask_exclude=0)
PyObject * BPy_BMElem_Array_As_Tuple(BMesh *bm, BMHeader **elem, Py_ssize_t elem_num)
static PyObject * bpy_bmedgeseq_get(BPy_BMesh *self, void *)
static PyMethodDef bpy_bmvert_methods[]
static PyObject * bpy_bmface_calc_tangent_edge(BPy_BMFace *self)
static PyObject * bpy_bmface_calc_tangent_edge_diagonal(BPy_BMFace *self)
PyObject * BPy_BMLoop_CreatePyObject(BMesh *bm, BMLoop *l)
static int bpy_bmelemseq_sort_cmp_by_keys_descending(const void *index1_v, const void *index2_v, void *keys_v)
static PyObject * bpy_bmedgeseq_new(BPy_BMElemSeq *self, PyObject *args, PyObject *kw)
PyObject * Vector_CreatePyObject_wrap(float *vec, const int vec_num, PyTypeObject *base_type)
bool BM_edge_is_convex(const BMEdge *e)
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")
void BM_face_calc_tangent_from_edge_diagonal(const BMFace *f, float r_tangent[3])
static PyObject * bpy_bmvert_is_wire_get(BPy_BMVert *self, void *)
static PyObject * bpy_bmesh_uv_select_foreach_set(BPy_BMesh *self, PyObject *args, PyObject *kw)
PyObject * PyC_FlagSet_FromBitfield(PyC_FlagSet *items, int flag)
static void bpy_bmface_dealloc(BPy_BMElem *self)
PyObject * BPy_BMLoop_Array_As_Tuple(BMesh *bm, BMLoop *const *elem, Py_ssize_t elem_num)
static PyObject * bpy_bmelemseq_index_update(BPy_BMElemSeq *self)
static PyObject * bpy_bmesh_calc_volume(BPy_BMElem *self, PyObject *args, PyObject *kw)
static PyObject * bpy_bmloop_repr(BPy_BMLoop *self)
char * BPy_BMElem_StringFromHType(const char htype)
static PyObject * bpy_bmface_calc_tangent_edge_pair(BPy_BMFace *self)
static PyObject * bpy_bmesh_uv_select_flush(BPy_BMesh *self, PyObject *value)
int BPy_BMElem_CheckHType(PyTypeObject *type, const char htype)
static void bpy_bmvert_dealloc(BPy_BMElem *self)
static void bpy_bmesh_dealloc(BPy_BMesh *self)
static PyObject * bpy_bmedge_is_contiguous_get(BPy_BMEdge *self, void *)
static void bpy_bmelemseq_dealloc(BPy_BMElemSeq *self)
float BM_vert_calc_shell_factor(const BMVert *v)
static Py_hash_t bpy_bm_hash(PyObject *self)
static PyGetSetDef bpy_bmloop_getseters[]
PyObject * BPyInit_bmesh_types()
ATTR_WARN_UNUSED_RESULT const BMVert * v
static PyTypeObject * bpy_bm_itype_as_pytype(const char itype)
void BM_data_layer_free(BMesh *bm, CustomData *data, int type)
BMVert * BM_vert_create(BMesh *bm, const float co[3], const BMVert *v_example, const eBMCreateFlag create_flag)
Main function for creating a new vertex.
static int bpy_bmface_material_index_set(BPy_BMFace *self, PyObject *value, void *)
BLI_INLINE bool BM_edge_is_manifold(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static PyMethodDef bpy_bmface_methods[]
static PyObject * bpy_bmedge_calc_length(BPy_BMEdge *self)
static PyObject * bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject *kw)
static PyGetSetDef bpy_bmedgeseq_getseters[]
static int bpy_bmesh_select_history_set(BPy_BMesh *self, PyObject *value, void *)
void BM_mesh_uvselect_set_elem_shared(BMesh *bm, bool select, const int cd_loop_uv_offset, const Span< BMLoop * > loop_verts, const Span< BMLoop * > loop_edges, const Span< BMFace * > faces)
static PyObject * bpy_bmface_calc_center_bounds(BPy_BMFace *self)
static PyObject * bpy_bm_elem_index_get(BPy_BMElem *self, void *)
bool BM_mesh_is_valid(BMesh *bm)
static PyObject * bpy_bmelemseq_elem_get(BPy_BMElem *self, void *itype)
static PyObject * bpy_bmface_calc_tangent_vert_diagonal(BPy_BMFace *self)
PyTypeObject BPy_BMLoopSeq_Type
bool BM_vert_is_boundary(const BMVert *v)
static PyObject * bpy_bmelemseq_subscript_int(BPy_BMElemSeq *self, Py_ssize_t keynum)
BLI_INLINE BMVert * BM_edge_other_vert(BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static PyObject * bpy_bmloop_link_loop_radial_next_get(BPy_BMLoop *self, void *)
static PyMethodDef bpy_bmloop_methods[]
static PyMethodDef bpy_bmfaceseq_methods[]
void BM_loop_calc_face_tangent(const BMLoop *l, float r_tangent[3])
BM_loop_calc_face_tangent.
static PyObject * bpy_bmesh_select_mode_get(BPy_BMesh *self, void *)
static PyObject * bpy_bmelem_subscript(BPy_BMElem *self, BPy_BMLayerItem *key)
static void bpy_bmedge_dealloc(BPy_BMElem *self)
void BM_face_calc_center_bounds(const BMFace *f, float r_cent[3])
static PyObject * bpy_bmfaceseq_get(BPy_BMesh *self, void *)
void BM_vert_normal_update(BMVert *v)
void * BM_iter_at_index(BMesh *bm, const char itype, void *data, int index)
PyObject * BPy_BMLoopSeq_CreatePyObject(BMesh *bm)
PyObject * BPy_BMLayerAccess_CreatePyObject(BMesh *bm, const char htype)
PyObject * BPy_BMEditSel_CreatePyObject(BMesh *bm)
void BM_mesh_bm_from_me(BMesh *bm, const Mesh *mesh, const BMeshFromMeshParams *params)
Mesh -> BMesh.
static PyObject * bpy_bmesh_uv_select_sync_to_mesh(BPy_BMesh *self)
void mul_m4_v3(const float M[4][4], float r[3])
static PyObject * bpy_bmface_normal_update(BPy_BMFace *self)
PyTypeObject BPy_BMFace_Type
static PyObject * bpy_bmedge_is_wire_get(BPy_BMEdge *self, void *)
int bpy_bm_generic_valid_check(BPy_BMGeneric *self)
PyTypeObject BPy_BMesh_Type
float BM_loop_calc_face_normal(const BMLoop *l, float r_normal[3])
BM_loop_calc_face_normal.
PyC_FlagSet bpy_bm_htype_vert_edge_face_flags[]
static PyObject * bpy_bmelemseq_sort(BPy_BMElemSeq *self, PyObject *args, PyObject *kw)
double BM_mesh_calc_volume(BMesh *bm, bool is_signed)
BMesh const char itype
PyObject * Vector_CreatePyObject(const float *vec, const int vec_num, PyTypeObject *base_type)
PyObject * BPy_BMLayerItem_GetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer)
BMElem.__getitem__() / __setitem__()
PyC_FlagSet bpy_bm_htype_all_flags[]
PyTypeObject BPy_BMLayerCollection_Type
int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObject *py_value)
@ BM_CREATE_NOP
Definition bmesh_core.hh:34
float BM_face_calc_area(const BMFace *f)
static int bpy_bmesh_select_mode_set(BPy_BMesh *self, PyObject *value, void *)
static PyObject * bpy_bmloop_calc_normal(BPy_BMLoop *self)
void BM_face_normal_update(BMFace *f)
static PyObject * bpy_bmloop_is_convex_get(BPy_BMLoop *self, void *)
BMesh * BM_mesh_copy(BMesh *bm_old)
void BM_edge_kill(BMesh *bm, BMEdge *e)
void BM_mesh_uvselect_sync_from_mesh_sticky_disabled(BMesh *bm)
static PyObject * bpy_bm_elem_select_set(BPy_BMElem *self, PyObject *value)
void DEG_id_tag_update(ID *id, unsigned int flags)
static PyObject * bpy_bmvert_copy_from_face_interp(BPy_BMVert *self, PyObject *args)
PyTypeObject BPy_BMEditSelSeq_Type
static PyObject * bpy_bmloop_face_get(BPy_BMLoop *self, void *)
BMesh const char void * data
static PyObject * bpy_bmface_normal_get(BPy_BMFace *self, void *)
void BM_loop_vert_uvselect_set_noflush(BMesh *bm, BMLoop *l, bool select)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
static PyObject * bpy_bmesh_uv_select_flush_shared(BPy_BMesh *self, PyObject *value)
BLI_INLINE bool BM_edge_is_contiguous(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static PyObject * bpy_bmface_repr(BPy_BMFace *self)
static int bpy_bmfaceseq_active_set(BPy_BMElem *self, PyObject *value, void *)
static PyObject * bpy_bm_elem_hide_set(BPy_BMElem *self, PyObject *value)
static PyObject * bpy_bmesh_uv_select_foreach_set_from_mesh(BPy_BMesh *self, PyObject *args, PyObject *kw)
void BM_elem_select_set(BMesh *bm, BMElem *ele, const bool select)
void BM_mesh_uvselect_sync_from_mesh_sticky_location(BMesh *bm, const int cd_loop_uv_offset)
static PyObject * bpy_bmedge_calc_face_angle(BPy_BMEdge *self, PyObject *args)
static PyObject * bpy_bmesh_select_flush_mode(BPy_BMesh *self, PyObject *args, PyObject *kw)
static PyObject * bpy_bmloop_link_loop_next_get(BPy_BMLoop *self, void *)
float BM_edge_calc_face_angle_ex(const BMEdge *e, const float fallback)
BMESH EDGE/FACE ANGLE.
int BM_mesh_elem_count(BMesh *bm, const char htype)
PyTypeObject BPy_BMEdgeSeq_Type
const CustomData_MeshMasks CD_MASK_BMESH
static PyObject * bpy_bmvert_normal_update(BPy_BMVert *self)
static Py_ssize_t bpy_bmelemseq_length(BPy_BMElemSeq *self)
static void bpy_bmloop_dealloc(BPy_BMElem *self)
int mathutils_array_parse(float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
Definition mathutils.cc:97
static PyObject * bpy_bmvertseq_new(BPy_BMElemSeq *self, PyObject *args, PyObject *kw)
static PyObject * bpy_bmedge_is_manifold_get(BPy_BMEdge *self, void *)
static PyObject * bpy_bmedge_is_convex_get(BPy_BMEdge *self, void *)
static PyObject * bpy_bmesh_select_flush(BPy_BMesh *self, PyObject *value)
PyTypeObject BPy_BMFaceSeq_Type
static PyObject * bpy_bmesh_to_mesh(BPy_BMesh *self, PyObject *args)
static PyObject * bpy_bmedgeseq_get__method(BPy_BMElemSeq *self, PyObject *args)
PyTypeObject BPy_BMLayerItem_Type
static PyObject * bpy_bmedge_other_vert(BPy_BMEdge *self, BPy_BMVert *value)
void BM_mesh_clear(BMesh *bm)
BMesh Clear Mesh.
static PyObject * bpy_bmesh_free(BPy_BMesh *self)
static PyMethodDef bpy_bmvertseq_methods[]
PyTypeObject BPy_BMVertSkin_Type
PyObject * BPy_BMElem_CreatePyObject(BMesh *bm, BMHeader *ele)
BLI_INLINE bool BM_edge_is_boundary(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BM_face_calc_tangent_from_vert_diagonal(const BMFace *f, float r_tangent[3])
PyObject * BPy_BMVert_CreatePyObject(BMesh *bm, BMVert *v)
static int bpy_bmelemseq_sort_cmp_by_keys_ascending(const void *index1_v, const void *index2_v, void *keys_v)
PyTypeObject BPy_BMIter_Type
static PyObject * bpy_bm_elem_hflag_get(BPy_BMElem *self, void *flag)
PyTypeObject BPy_BMElemSeq_Type
static PyObject * bpy_bmloop_copy_from_face_interp(BPy_BMLoop *self, PyObject *args)
void BM_mesh_calc_tessellation(BMesh *bm, MutableSpan< std::array< BMLoop *, 3 > > looptris)
static PyObject * bpy_bmloop_vert_get(BPy_BMLoop *self, void *)
static PyObject * bpy_bmelemseq_ensure_lookup_table(BPy_BMElemSeq *self)
size_t BLI_string_join_array_by_sep_char(char *result, size_t result_maxncpy, char sep, const char *strings[], uint strings_num) ATTR_NONNULL()
void BM_edge_normals_update(BMEdge *e)
MINLINE int poly_to_tri_count(int poly_count, int corner_count)
static PyObject * bpy_bmesh_clear(BPy_BMesh *self)
void BKE_id_free(Main *bmain, void *idv)
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
static PyGetSetDef bpy_bmface_getseters[]
static PyObject * bpy_bmface_calc_area(BPy_BMFace *self)
float BM_vert_calc_edge_angle_ex(const BMVert *v, const float fallback)
BMESH VERT/EDGE ANGLE.
static PyObject * bpy_bmloop_uv_select_edge_set(BPy_BMLoop *self, PyObject *value)
PyObject * BPy_BMEdge_Array_As_Tuple(BMesh *bm, BMEdge **elem, Py_ssize_t elem_num)
float BM_face_calc_perimeter(const BMFace *f)
static PyObject * bpy_bmloop_link_loop_prev_get(BPy_BMLoop *self, void *)
void BPy_BM_init_types()
static PyObject * bpy_bmface_copy(BPy_BMFace *self, PyObject *args, PyObject *kw)
static PyObject * bpy_bmelemseq_subscript(BPy_BMElemSeq *self, PyObject *key)
float BM_loop_calc_face_angle(const BMLoop *l)
BMFace * BM_face_exists(BMVert *const *varr, int len)
PyTypeObject BPy_BMLayerAccessLoop_Type
int PyC_Long_AsBool(PyObject *value)
static PyObject * bpy_bmloop_edge_get(BPy_BMLoop *self, void *)
BMEdge * BM_edge_exists(BMVert *v_a, BMVert *v_b)
static PyObject * bpy_bmfaceseq_active_get(BPy_BMElemSeq *self, void *)
static PyMethodDef bpy_bmesh_methods[]
void BM_face_interp_from_face(BMesh *bm, BMFace *f_dst, const BMFace *f_src, const bool do_vertex)
static PyObject * bpy_bmvertseq_remove(BPy_BMElemSeq *self, BPy_BMVert *value)
void * PyC_RNA_AsPointer(PyObject *value, const char *type_name)
PyTypeObject matrix_Type
PyTypeObject BPy_BMLayerAccessEdge_Type
void BM_vert_interp_from_face(BMesh *bm, BMVert *v_dst, const BMFace *f_src)
PyC_FlagSet bpy_bm_hflag_all_flags[]
PyObject * BPy_BMFace_Array_As_Tuple(BMesh *bm, BMFace **elem, Py_ssize_t elem_num)
PyObject * BPy_BMFaceSeq_CreatePyObject(BMesh *bm)
static PyMappingMethods bpy_bm_elem_as_mapping
static PyObject * bpy_bmesh_is_wrapped_get(BPy_BMesh *self, void *)
static PyObject * bpy_bmfaceseq_remove(BPy_BMElemSeq *self, BPy_BMFace *value)
void BM_face_kill(BMesh *bm, BMFace *f)
static PyObject * bpy_bmloop_link_loop_radial_prev_get(BPy_BMLoop *self, void *)
void BLI_qsort_r(void *a, size_t n, size_t es, BLI_sort_cmp_t cmp, void *thunk)
Definition sort.cc:79
static int bpy_bm_elem_hflag_set(BPy_BMElem *self, PyObject *value, void *flag)
static PyObject * bpy_bmface_uv_select_set(BPy_BMFace *self, PyObject *value)
static PyGetSetDef bpy_bmvertseq_getseters[]
static PyObject * bpy_bmesh_calc_loop_triangles(BPy_BMElem *self)
static int bpy_bmelem_ass_subscript(BPy_BMElem *self, BPy_BMLayerItem *key, PyObject *value)
int bpy_bm_generic_valid_check_source(BMesh *bm_source, const char *error_prefix, void **args, uint args_tot)
@ ID_RECALC_GEOMETRY_ALL_MODES
Definition DNA_ID.h:1183
void BM_mesh_uvselect_flush_from_verts(BMesh *bm, const bool select)
static PyObject * bpy_bmedgeseq_remove(BPy_BMElemSeq *self, BPy_BMEdge *value)
PyObject * BPy_BMVertSeq_CreatePyObject(BMesh *bm)
@ ID_TAG_NO_MAIN
Definition DNA_ID.h:981
static PyObject * bpy_bmface_normal_flip(BPy_BMFace *self)
char * BPy_BMElem_StringFromHType_ex(const char htype, char ret[32])
static PyObject * bpy_bmelemseq_iter(BPy_BMElemSeq *self)
static PyObject * bpy_bmface_calc_perimeter(BPy_BMFace *self)
PyTypeObject BPy_BMDeformVert_Type
static int bpy_bmelemseq_contains(BPy_BMElemSeq *self, PyObject *value)
static PyObject * bpy_bmesh_uv_select_sync_from_mesh(BPy_BMesh *self, PyObject *args, PyObject *kw)
static PyObject * bpy_bmesh_transform(BPy_BMElem *self, PyObject *args, PyObject *kw)
void BM_mesh_uvselect_sync_from_mesh_sticky_vert(BMesh *bm)
PyObject * BPy_BMElemSeq_CreatePyObject(BMesh *bm, BPy_BMElem *py_ele, const char itype)
static void bm_dealloc_editmode_warn(BPy_BMesh *self)
Mesh * BKE_mesh_new_from_object(Depsgraph *depsgraph, Object *object, bool preserve_all_data_layers, bool preserve_origindex, bool ensure_subdivision)
PyObject * BPy_BMesh_CreatePyObject(BMesh *bm, int flag)
static PyGetSetDef bpy_bmesh_getseters[]
static PyObject * bpy_bmedge_calc_face_angle_signed(BPy_BMEdge *self, PyObject *args)
void BM_data_interp_from_verts(BMesh *bm, const BMVert *v_src_1, const BMVert *v_src_2, BMVert *v_dst, const float fac)
Data, Interpolate From Verts.
static Py_hash_t bpy_bm_elem_hash(PyObject *self)
void BM_face_calc_tangent_from_edge_pair(const BMFace *f, float r_tangent[3])
static PyObject * bpy_bmesh_from_mesh(BPy_BMesh *self, PyObject *args, PyObject *kw)
int BPy_BMEditSel_Assign(BPy_BMesh *self, PyObject *value)
void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *mesh, const BMeshToMeshParams *params)
static PyC_StringEnumItems bpy_bm_uv_select_sticky_items[]
static PyObject * bpy_bmvert_is_manifold_get(BPy_BMVert *self, void *)
static PyObject * bpy_bmface_material_index_get(BPy_BMFace *self, void *)
void BM_mesh_select_flush_from_verts(BMesh *bm, const bool select)
void BM_elem_attrs_copy(BMesh *bm, const BMCustomDataCopyMap &map, const BMVert *src, BMVert *dst)
PyObject * BPy_BMVert_Array_As_Tuple(BMesh *bm, BMVert **elem, Py_ssize_t elem_num)
static PyObject * bpy_bmvert_is_boundary_get(BPy_BMVert *self, void *)
int PyC_ParseStringEnum(PyObject *o, void *p)
int bpy_bm_check_uv_select_sync_valid(BMesh *bm, const char *error_prefix)
void * BPy_BMElem_PySeq_As_Array(BMesh **r_bm, PyObject *seq, Py_ssize_t min, Py_ssize_t max, Py_ssize_t *r_seq_num, const char htype, const bool do_unique_check, const bool do_bm_check, const char *error_prefix)
static PyObject * bpy_bmvert_co_get(BPy_BMVert *self, void *)
bool BM_vert_is_manifold(const BMVert *v)
static PyObject * bpy_bmedge_is_boundary_get(BPy_BMEdge *self, void *)
static PyObject * bpy_bmedge_calc_tangent(BPy_BMEdge *self, PyObject *args)
static int bpy_bmesh_uv_select_sync_valid_set(BPy_BMesh *self, PyObject *value, void *)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
static PyObject * bpy_bmvert_repr(BPy_BMVert *self)
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
static PyObject * bpy_bmesh_copy(BPy_BMesh *self)
void BM_mesh_uvselect_set_elem_from_mesh(BMesh *bm, const bool select, const BMUVSelectPickParams &params, const VectorList< BMVert * > &verts, const VectorList< BMEdge * > &edges, const VectorList< BMFace * > &faces)
PyObject * BPy_BMIter_CreatePyObject(BMesh *bm)
static PyObject * bpy_bmloop_calc_angle(BPy_BMLoop *self)
void BM_face_uvselect_set(BMesh *bm, BMFace *f, bool select)
PyTypeObject BPy_BMEdge_Type
PyObject * BPy_BMEdgeSeq_CreatePyObject(BMesh *bm)
bool BKE_id_is_in_global_main(ID *id)
Definition lib_id.cc:2759
static PyObject * bpy_bmfaceseq_new(BPy_BMElemSeq *self, PyObject *args, PyObject *kw)
static PyObject * bpy_bmiter_next(BPy_BMIter *self)
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)
@ BM_ELEM_SELECT_UV
@ BM_ELEM_INTERNAL_TAG
int PyC_ParseTypeOrNone(PyObject *o, void *p)
static PyObject * bpy_bmedge_repr(BPy_BMEdge *self)
BMEdge * BM_edge_create(BMesh *bm, BMVert *v1, BMVert *v2, const BMEdge *e_example, const eBMCreateFlag create_flag)
Main function for creating a new edge.
void BM_loop_edge_uvselect_set(BMesh *bm, BMLoop *l, bool select)
BMLoop ** BPy_BMLoop_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)
void bpy_bm_generic_invalidate(struct BPy_BMGeneric *)
static PyObject * bpy_bmelemseq_layers_get(BPy_BMElemSeq *self, void *htype)
void BM_mesh_uvselect_flush_shared_only_select(BMesh *bm, const int cd_loop_uv_offset)
void BM_mesh_uvselect_flush_shared_only_deselect(BMesh *bm, const int cd_loop_uv_offset)
static PySequenceMethods bpy_bmelemseq_as_sequence
static PyGetSetDef bpy_bmloopseq_getseters[]
void BM_face_calc_center_median_weighted(const BMFace *f, float r_cent[3])
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const uint *face_idx)
void BM_face_calc_tangent_from_edge(const BMFace *f, float r_tangent[3])
void BM_mesh_normals_update(BMesh *bm)
void BM_loop_interp_from_face(BMesh *bm, BMLoop *l_dst, const BMFace *f_src, const bool do_vertex, const bool do_multires)
void BM_mesh_uvselect_sync_to_mesh(BMesh *bm)
static PyObject * bpy_bmesh_uv_select_flush_mode(BPy_BMesh *self, PyObject *args, PyObject *kw)
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
Definition object.cc:4436
MINLINE float clamp_f(float value, float min, float max)
PyC_FlagSet bpy_bm_scene_vert_edge_face_flags[]
void BM_mesh_select_mode_flush_ex(BMesh *bm, const short selectmode, BMSelectFlushFlag flag)
Select Mode Flush.
@ BPY_BMFLAG_IS_WRAPPED
PyTypeObject BPy_BMEditSelIter_Type
static PyMethodDef bpy_bmedgeseq_methods[]
PyObject * BPy_BMEdge_CreatePyObject(BMesh *bm, BMEdge *e)
bool BM_loop_is_convex(const BMLoop *l)
PyObject * BPy_BMFace_CreatePyObject(BMesh *bm, BMFace *f)
#define PyC_TYPE_OR_NONE_INIT(py_type, value_p)
header-only compatibility defines.
#define Py_HashPointer
header-only utilities
#define min(a, b)
Definition sort.cc:38
PyObject_HEAD BMesh * bm
PyObject_HEAD BMesh * bm
PyObject_HEAD BMesh * bm
PyObject_HEAD BMesh * bm
PyObject_HEAD BMesh * bm
PyObject_HEAD BMesh * bm
PyObject_HEAD BMesh * bm
PyObject_HEAD BMesh * bm
PyObject_HEAD BMesh * bm
char name[258]
Definition DNA_ID.h:433
struct BMLoop * radial_next
struct BMLoop * radial_prev