Blender V5.3
bmesh_py_types_meshdata.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
19
20#include <Python.h>
21
23
24#include "DNA_meshdata_types.h"
25
26#include "BKE_customdata.hh"
27
28#include "BLI_math_base_c.hh"
29#include "BLI_math_color_c.hh"
30#include "BLI_math_vector_c.hh"
32#include "BLI_utildefines.hh"
33
34#include "BKE_deform.hh"
35
36#include "bmesh.hh"
38
41
42namespace blender {
43
44/* Mesh Loop UV
45 * ************ */
46
47#define BPy_BMLoopUV_Check(v) (Py_TYPE(v) == &BPy_BMLoopUV_Type)
48
50 PyObject_HEAD
51 float *uv;
61 bool *pin;
63};
64
66 /* Wrap. */
67 bpy_bmloopuv_uv_doc,
68 "Loop UV (as a 2D Vector).\n"
69 "\n"
70 ":type: :class:`mathutils.Vector`\n");
71static PyObject *bpy_bmloopuv_uv_get(BPy_BMLoopUV *self, void * /*closure*/)
72{
73 return Vector_CreatePyObject_wrap(self->uv, 2, nullptr);
74}
75
76static int bpy_bmloopuv_uv_set(BPy_BMLoopUV *self, PyObject *value, void * /*closure*/)
77{
78 float tvec[2];
79 if (mathutils_array_parse(tvec, 2, 2, value, "BMLoopUV.uv") != -1) {
80 copy_v2_v2(self->uv, tvec);
81 return 0;
82 }
83
84 return -1;
85}
86
88{
89 if (self->pin == nullptr) {
90 PyErr_SetString(PyExc_RuntimeError,
91 "active uv layer has no associated pin layer. This is a bug!");
92 return false;
93 }
94 return true;
95}
96
98 /* Wrap. */
99 bpy_bmloopuv_pin_uv_doc,
100 "UV pin state.\n"
101 "\n"
102 ":type: bool\n");
103
104static PyObject *bpy_bmloopuv_pin_uv_get(BPy_BMLoopUV *self, void * /*closure*/)
105{
106 /* A non existing pin layer means nothing is currently pinned. */
107 if (!bpy_bmloopuv_pin_uv_ok_or_error(self)) [[unlikely]] {
108 return nullptr;
109 }
110 return PyBool_FromLong(*self->pin);
111}
112
113static int bpy_bmloopuv_pin_uv_set(BPy_BMLoopUV *self, PyObject *value, void * /*closure*/)
114{
115 /* TODO: if we add lazy allocation of the associated uv map bool layers to BMesh we need
116 * to add a pin layer and update self->pin in the case of self->pin being nullptr.
117 * This isn't easy to do currently as adding CustomData layers to a BMesh invalidates
118 * existing python objects. So for now lazy allocation isn't done and self->pin should
119 * never be nullptr. */
120 BLI_assert(self->pin);
121 if (!bpy_bmloopuv_pin_uv_ok_or_error(self)) [[unlikely]] {
122 return -1;
123 }
124 *self->pin = PyC_Long_AsBool(value);
125 return 0;
126}
127
128static PyGetSetDef bpy_bmloopuv_getseters[] = {
129 /* attributes match rna_def_mloopuv. */
130 {"uv",
131 reinterpret_cast<getter>(bpy_bmloopuv_uv_get),
132 reinterpret_cast<setter>(bpy_bmloopuv_uv_set),
133 bpy_bmloopuv_uv_doc,
134 nullptr},
135 {"pin_uv",
136 reinterpret_cast<getter>(bpy_bmloopuv_pin_uv_get),
137 reinterpret_cast<setter>(bpy_bmloopuv_pin_uv_set),
138 bpy_bmloopuv_pin_uv_doc,
139 nullptr},
140 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
141};
142
143PyTypeObject BPy_BMLoopUV_Type; /* bm.loops.layers.uv.active */
144
146{
147 BPy_BMLoopUV_Type.tp_basicsize = sizeof(BPy_BMLoopUV);
148
149 BPy_BMLoopUV_Type.tp_name = "BMLoopUV";
150
151 BPy_BMLoopUV_Type.tp_doc = nullptr; /* todo */
152
154
155 BPy_BMLoopUV_Type.tp_flags = Py_TPFLAGS_DEFAULT;
156
157 PyType_Ready(&BPy_BMLoopUV_Type);
158}
159
160int BPy_BMLoopUV_AssignPyObject(BMesh *bm, BMLoop *loop, PyObject *value)
161{
162 if (!BPy_BMLoopUV_Check(value)) [[unlikely]] {
163 PyErr_Format(PyExc_TypeError, "expected BMLoopUV, not a %.200s", Py_TYPE(value)->tp_name);
164 return -1;
165 }
166
167 BPy_BMLoopUV *src = reinterpret_cast<BPy_BMLoopUV *>(value);
168 const BMUVOffsets offsets = BM_uv_map_offsets_get(bm);
169
170 float *luv = BM_ELEM_CD_GET_FLOAT_P(loop, offsets.uv);
171 copy_v2_v2(luv, src->uv);
172 if (src->pin) {
173 BM_ELEM_CD_SET_BOOL(loop, offsets.pin, *src->pin);
174 }
175 return 0;
176}
177
179{
180 BPy_BMLoopUV *self = PyObject_New(BPy_BMLoopUV, &BPy_BMLoopUV_Type);
181
183
184 self->uv = BM_ELEM_CD_GET_FLOAT_P(loop, offsets.uv);
185 self->pin = offsets.pin >= 0 ? BM_ELEM_CD_GET_BOOL_P(loop, offsets.pin) : nullptr;
186
187 return reinterpret_cast<PyObject *>(self);
188}
189
190/* --- End Mesh Loop UV --- */
191
192/* Mesh Vert Skin
193 * ************
194 *
195 * The Skin modifier's per-vertex data used to be a single #MVertSkin struct combining the radius
196 * and root/loose flags, but now consists of a float2 "skin_modifier_radius" attribute and two
197 * boolean attributes: "skin_modifier_root" and "skin_modifier_loose". For backwards
198 * compatibility, the original combined struct is emulated as #BPy_BMVertSkin, compositing the
199 * three correlated attributes, similar to how #BPy_BMLoopUV emulates the old #MLoopUV struct. */
200
201#define BPy_BMVertSkin_Check(v) (Py_TYPE(v) == &BPy_BMVertSkin_Type)
202
204 PyObject_HEAD
207 bool *root;
209 bool *loose;
210};
211
213 /* Wrap. */
214 bpy_bmvertskin_radius_doc,
215 "Vert skin radii (as a 2D Vector).\n"
216 "\n"
217 ":type: :class:`mathutils.Vector`\n");
218static PyObject *bpy_bmvertskin_radius_get(BPy_BMVertSkin *self, void * /*closure*/)
219{
220 return Vector_CreatePyObject_wrap(*self->radius, 2, nullptr);
221}
222
223static int bpy_bmvertskin_radius_set(BPy_BMVertSkin *self, PyObject *value, void * /*closure*/)
224{
225 float tvec[2];
226 if (mathutils_array_parse(tvec, 2, 2, value, "BMVertSkin.radius") != -1) {
227 copy_v2_v2(*self->radius, tvec);
228 return 0;
229 }
230
231 return -1;
232}
233
234static bool bpy_bmvertskin_flag_ok_or_error(const bool *flag)
235{
236 if (flag == nullptr) {
237 PyErr_SetString(PyExc_RuntimeError, "skin layer has no associated root/loose layer.");
238 return false;
239 }
240 return true;
241}
242
244 /* Wrap. */
245 bpy_bmvertskin_flag__use_root_doc,
246 "Use as root vertex. Setting this flag does not clear other roots in the same mesh island.\n"
247 "\n"
248 ":type: bool\n");
249static PyObject *bpy_bmvertskin_use_root_get(BPy_BMVertSkin *self, void * /*closure*/)
250{
251 if (!bpy_bmvertskin_flag_ok_or_error(self->root)) [[unlikely]] {
252 return nullptr;
253 }
254 return PyBool_FromLong(*self->root);
255}
256
257static int bpy_bmvertskin_use_root_set(BPy_BMVertSkin *self, PyObject *value, void * /*closure*/)
258{
259 if (!bpy_bmvertskin_flag_ok_or_error(self->root)) [[unlikely]] {
260 return -1;
261 }
262 const int tmp_val = PyC_Long_AsBool(value);
263 if (tmp_val == -1) [[unlikely]] {
264 return -1;
265 }
266 *self->root = tmp_val;
267 return 0;
268}
269
271 /* Wrap. */
272 bpy_bmvertskin_flag__use_loose_doc,
273 "Use loose vertex.\n"
274 "\n"
275 ":type: bool\n");
276static PyObject *bpy_bmvertskin_use_loose_get(BPy_BMVertSkin *self, void * /*closure*/)
277{
278 if (!bpy_bmvertskin_flag_ok_or_error(self->loose)) [[unlikely]] {
279 return nullptr;
280 }
281 return PyBool_FromLong(*self->loose);
282}
283
284static int bpy_bmvertskin_use_loose_set(BPy_BMVertSkin *self, PyObject *value, void * /*closure*/)
285{
286 if (!bpy_bmvertskin_flag_ok_or_error(self->loose)) [[unlikely]] {
287 return -1;
288 }
289 const int tmp_val = PyC_Long_AsBool(value);
290 if (tmp_val == -1) [[unlikely]] {
291 return -1;
292 }
293 *self->loose = tmp_val;
294 return 0;
295}
296
297static PyGetSetDef bpy_bmvertskin_getseters[] = {
298 /* attributes match rna_mesh_gen. */
299 {"radius",
300 reinterpret_cast<getter>(bpy_bmvertskin_radius_get),
301 reinterpret_cast<setter>(bpy_bmvertskin_radius_set),
302 bpy_bmvertskin_radius_doc,
303 nullptr},
304 {"use_root",
305 reinterpret_cast<getter>(bpy_bmvertskin_use_root_get),
306 reinterpret_cast<setter>(bpy_bmvertskin_use_root_set),
307 bpy_bmvertskin_flag__use_root_doc,
308 nullptr},
309 {"use_loose",
310 reinterpret_cast<getter>(bpy_bmvertskin_use_loose_get),
311 reinterpret_cast<setter>(bpy_bmvertskin_use_loose_set),
312 bpy_bmvertskin_flag__use_loose_doc,
313 nullptr},
314
315 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
316};
317
318PyTypeObject BPy_BMVertSkin_Type; /* bm.verts.layers.skin.active */
319
321{
322 BPy_BMVertSkin_Type.tp_basicsize = sizeof(BPy_BMVertSkin);
323
324 BPy_BMVertSkin_Type.tp_name = "BMVertSkin";
325
326 BPy_BMVertSkin_Type.tp_doc = "Skin vertex data for the skin modifier.";
327
329
330 BPy_BMVertSkin_Type.tp_flags = Py_TPFLAGS_DEFAULT;
331
332 PyType_Ready(&BPy_BMVertSkin_Type);
333}
334
335int BPy_BMVertSkin_AssignPyObject(BMesh *bm, BMVert *vert, PyObject *value)
336{
337 if (!BPy_BMVertSkin_Check(value)) [[unlikely]] {
338 PyErr_Format(PyExc_TypeError, "expected BMVertSkin, not a %.200s", Py_TYPE(value)->tp_name);
339 return -1;
340 }
341
342 BPy_BMVertSkin *src = reinterpret_cast<BPy_BMVertSkin *>(value);
343
344 const int cd_radius_offset = CustomData_get_offset_named(
345 &bm->vdata, CD_PROP_FLOAT2, "skin_modifier_radius");
346 *static_cast<float2 *>(BM_ELEM_CD_GET_VOID_P(vert, cd_radius_offset)) = *src->radius;
347
348 if (src->root) {
349 const int cd_root_offset = CustomData_get_offset_named(
350 &bm->vdata, CD_PROP_BOOL, "skin_modifier_root");
351 if (cd_root_offset != -1) {
352 BM_ELEM_CD_SET_BOOL(vert, cd_root_offset, *src->root);
353 }
354 }
355 if (src->loose) {
356 const int cd_loose_offset = CustomData_get_offset_named(
357 &bm->vdata, CD_PROP_BOOL, "skin_modifier_loose");
358 if (cd_loose_offset != -1) {
359 BM_ELEM_CD_SET_BOOL(vert, cd_loose_offset, *src->loose);
360 }
361 }
362
363 return 0;
364}
365
367{
368 BPy_BMVertSkin *self = PyObject_New(BPy_BMVertSkin, &BPy_BMVertSkin_Type);
369
370 const int cd_radius_offset = CustomData_get_offset_named(
371 &bm->vdata, CD_PROP_FLOAT2, "skin_modifier_radius");
372 const int cd_root_offset = CustomData_get_offset_named(
373 &bm->vdata, CD_PROP_BOOL, "skin_modifier_root");
374 const int cd_loose_offset = CustomData_get_offset_named(
375 &bm->vdata, CD_PROP_BOOL, "skin_modifier_loose");
376
377 self->radius = static_cast<float2 *>(BM_ELEM_CD_GET_VOID_P(vert, cd_radius_offset));
378 self->root = cd_root_offset != -1 ?
379 static_cast<bool *>(BM_ELEM_CD_GET_VOID_P(vert, cd_root_offset)) :
380 nullptr;
381 self->loose = cd_loose_offset != -1 ?
382 static_cast<bool *>(BM_ELEM_CD_GET_VOID_P(vert, cd_loose_offset)) :
383 nullptr;
384
385 return reinterpret_cast<PyObject *>(self);
386}
387
388/* --- End Mesh Vert Skin --- */
389
390/* Mesh Loop Color
391 * *************** */
392
393/* This simply provides a color wrapper for
394 * color which uses mathutils callbacks for mathutils.Color
395 */
396
397#define MLOOPCOL_FROM_CAPSULE(color_capsule) \
398 ((MLoopCol *)PyCapsule_GetPointer(color_capsule, nullptr))
399
400static void mloopcol_to_float(const MLoopCol *mloopcol, float r_col[4])
401{
402 rgba_uchar_to_float(r_col, static_cast<const uchar *>(&mloopcol->r));
403}
404
405static void mloopcol_from_float(MLoopCol *mloopcol, const float col[4])
406{
407 rgba_float_to_uchar(static_cast<uchar *>(&mloopcol->r), col);
408}
409
411
413{
414 /* always ok */
415 return 0;
416}
417
418static int mathutils_bmloopcol_get(BaseMathObject *bmo, int /*subtype*/)
419{
420 MLoopCol *mloopcol = MLOOPCOL_FROM_CAPSULE(bmo->cb_user);
421 mloopcol_to_float(mloopcol, bmo->data);
422 return 0;
423}
424
425static int mathutils_bmloopcol_set(BaseMathObject *bmo, int /*subtype*/)
426{
427 MLoopCol *mloopcol = MLOOPCOL_FROM_CAPSULE(bmo->cb_user);
428 mloopcol_from_float(mloopcol, bmo->data);
429 return 0;
430}
431
432static int mathutils_bmloopcol_get_index(BaseMathObject *bmo, int subtype, int /*index*/)
433{
434 /* Lazy, avoid repeating the case statement. */
435 if (mathutils_bmloopcol_get(bmo, subtype) == -1) {
436 return -1;
437 }
438 return 0;
439}
440
441static int mathutils_bmloopcol_set_index(BaseMathObject *bmo, int subtype, int index)
442{
443 const float f = bmo->data[index];
444
445 /* Lazy, avoid repeating the case statement. */
446 if (mathutils_bmloopcol_get(bmo, subtype) == -1) {
447 return -1;
448 }
449
450 bmo->data[index] = f;
451 return mathutils_bmloopcol_set(bmo, subtype);
452}
453
461
467
468int BPy_BMLoopColor_AssignPyObject(MLoopCol *mloopcol, PyObject *value)
469{
470 float tvec[4];
471 if (mathutils_array_parse(tvec, 4, 4, value, "BMLoopCol") != -1) {
472 mloopcol_from_float(mloopcol, tvec);
473 return 0;
474 }
475
476 return -1;
477}
478
480{
481 PyObject *color_capsule = PyCapsule_New(mloopcol, nullptr, nullptr);
482 PyObject *ret = Vector_CreatePyObject_cb(color_capsule, 4, mathutils_bmloopcol_cb_index, 0);
483 Py_DECREF(color_capsule);
484 return ret;
485}
486
487#undef MLOOPCOL_FROM_CAPSULE
488
489/* --- End Mesh Loop Color --- */
490
491/* Mesh Deform Vert
492 * **************** */
493
517
518#define BPy_BMDeformVert_Check(v) (Py_TYPE(v) == &BPy_BMDeformVert_Type)
519
521 PyObject_HEAD
523};
524
525/* Mapping Protocols
526 * ================= */
527
529{
530 return self->data->totweight;
531}
532
533static PyObject *bpy_bmdeformvert_subscript(BPy_BMDeformVert *self, PyObject *key)
534{
535 if (PyIndex_Check(key)) {
536 int i;
537 i = PyNumber_AsSsize_t(key, PyExc_IndexError);
538 if (i == -1 && PyErr_Occurred()) {
539 return nullptr;
540 }
541
543
544 if (dw == nullptr) {
545 PyErr_SetString(PyExc_KeyError,
546 "BMDeformVert[key] = x: "
547 "key not found");
548 return nullptr;
549 }
550
551 return PyFloat_FromDouble(dw->weight);
552 }
553
554 PyErr_Format(
555 PyExc_TypeError, "BMDeformVert keys must be integers, not %.200s", Py_TYPE(key)->tp_name);
556 return nullptr;
557}
558
559static int bpy_bmdeformvert_ass_subscript(BPy_BMDeformVert *self, PyObject *key, PyObject *value)
560{
561 if (PyIndex_Check(key)) {
562 int i;
563
564 i = PyNumber_AsSsize_t(key, PyExc_IndexError);
565 if (i == -1 && PyErr_Occurred()) {
566 return -1;
567 }
568
569 if (value) {
570 /* Handle `dvert[group_index] = 0.5`. */
571 if (i < 0) {
572 PyErr_SetString(PyExc_KeyError,
573 "BMDeformVert[key] = x: "
574 "weight keys cannot be negative");
575 return -1;
576 }
577
578 const float f = PyFloat_AsDouble(value);
579 if (f == -1 && PyErr_Occurred()) { /* Assigned value not a number. */
580 PyErr_SetString(PyExc_TypeError,
581 "BMDeformVert[key] = x: "
582 "assigned value not a number");
583 return -1;
584 }
585
587 dw->weight = clamp_f(f, 0.0f, 1.0f);
588 }
589 else {
590 /* Handle `del dvert[group_index]`. */
592
593 if (dw == nullptr) {
594 PyErr_SetString(PyExc_KeyError,
595 "del BMDeformVert[key]: "
596 "key not found");
597 return -1;
598 }
600 }
601
602 return 0;
603 }
604
605 PyErr_Format(
606 PyExc_TypeError, "BMDeformVert keys must be integers, not %.200s", Py_TYPE(key)->tp_name);
607 return -1;
608}
609
610static int bpy_bmdeformvert_contains(BPy_BMDeformVert *self, PyObject *value)
611{
612 const int key = PyLong_AsSsize_t(value);
613
614 if (key == -1 && PyErr_Occurred()) {
615 PyErr_SetString(PyExc_TypeError, "BMDeformVert.__contains__: expected an int");
616 return -1;
617 }
618
619 return (BKE_defvert_find_index(self->data, key) != nullptr) ? 1 : 0;
620}
621
622/* only defined for __contains__ */
623static PySequenceMethods bpy_bmdeformvert_as_sequence = {
624 /*sq_length*/ reinterpret_cast<lenfunc>(bpy_bmdeformvert_len),
625 /*sq_concat*/ nullptr,
626 /*sq_repeat*/ nullptr,
627 /* NOTE: if this is set #PySequence_Check() returns True,
628 * but in this case we don't want to be treated as a seq. */
629 /*sq_item*/ nullptr,
630 /*was_sq_slice*/ nullptr, /* DEPRECATED. */
631 /*sq_ass_item*/ nullptr,
632 /*was_sq_ass_slice*/ nullptr, /* DEPRECATED. */
633 /*sq_contains*/ reinterpret_cast<objobjproc>(bpy_bmdeformvert_contains),
634 /*sq_inplace_concat*/ nullptr,
635 /*sq_inplace_repeat*/ nullptr,
636};
637
638static PyMappingMethods bpy_bmdeformvert_as_mapping = {
639 /*mp_length*/ reinterpret_cast<lenfunc>(bpy_bmdeformvert_len),
640 /*mp_subscript*/ reinterpret_cast<binaryfunc>(bpy_bmdeformvert_subscript),
641 /*mp_ass_subscript*/ reinterpret_cast<objobjargproc>(bpy_bmdeformvert_ass_subscript),
642};
643
644/* Methods
645 * ======= */
646
648 /* Wrap. */
649 bpy_bmdeformvert_keys_doc,
650 ".. method:: keys()\n"
651 "\n"
652 " Return the group indices used by this vertex\n"
653 " (matching Python's dict.keys() functionality).\n"
654 "\n"
655 " :return: The deform group indices this vertex uses.\n"
656 " :rtype: list[int]\n");
658{
659 PyObject *ret;
660 int i;
661 MDeformWeight *dw = self->data->dw;
662
663 ret = PyList_New(self->data->totweight);
664 for (i = 0; i < self->data->totweight; i++, dw++) {
665 PyList_SET_ITEM(ret, i, PyLong_FromLong(dw->def_nr));
666 }
667
668 return ret;
669}
670
672 /* Wrap. */
673 bpy_bmdeformvert_values_doc,
674 ".. method:: values()\n"
675 "\n"
676 " Return the weights of the deform vertex\n"
677 " (matching Python's dict.values() functionality).\n"
678 "\n"
679 " :return: The weights that influence this vertex\n"
680 " :rtype: list[float]\n");
682{
683 PyObject *ret;
684 int i;
685 MDeformWeight *dw = self->data->dw;
686
687 ret = PyList_New(self->data->totweight);
688 for (i = 0; i < self->data->totweight; i++, dw++) {
689 PyList_SET_ITEM(ret, i, PyFloat_FromDouble(dw->weight));
690 }
691
692 return ret;
693}
694
696 /* Wrap. */
697 bpy_bmdeformvert_items_doc,
698 ".. method:: items()\n"
699 "\n"
700 " Return (group, weight) pairs for this vertex\n"
701 " (matching Python's dict.items() functionality).\n"
702 "\n"
703 " :return: (key, value) pairs for each deform weight of this vertex.\n"
704 " :rtype: list[tuple[int, float]]\n");
706{
707 PyObject *ret;
708 PyObject *item;
709 int i;
710 MDeformWeight *dw = self->data->dw;
711
712 ret = PyList_New(self->data->totweight);
713 for (i = 0; i < self->data->totweight; i++, dw++) {
714 item = PyTuple_New(2);
715 PyTuple_SET_ITEMS(item, PyLong_FromLong(dw->def_nr), PyFloat_FromDouble(dw->weight));
716 PyList_SET_ITEM(ret, i, item);
717 }
718
719 return ret;
720}
721
723 /* Wrap. */
724 bpy_bmdeformvert_get_doc,
725 ".. method:: get(key, default=None)\n"
726 "\n"
727 " Returns the deform weight matching the key or default\n"
728 " when not found (matches Python's dictionary function of the same name).\n"
729 "\n"
730 " :param key: The vertex group index.\n"
731 " :type key: int\n"
732 " :param default: Optional argument for the value to return if\n"
733 " *key* is not found.\n"
734 " :type default: Any\n"
735 " :return: The deform weight or the default when not found.\n"
736 " :rtype: float | Any\n");
737static PyObject *bpy_bmdeformvert_get(BPy_BMDeformVert *self, PyObject *args)
738{
739 int key;
740 PyObject *def = Py_None;
741
742 if (!PyArg_ParseTuple(args,
743 "i" /* `key` */
744 "|" /* Optional arguments. */
745 "O" /* `default` */
746 ":get",
747 &key,
748 &def))
749 {
750 return nullptr;
751 }
752
753 MDeformWeight *dw = BKE_defvert_find_index(self->data, key);
754
755 if (dw) {
756 return PyFloat_FromDouble(dw->weight);
757 }
758
759 return Py_NewRef(def);
760}
761
763 /* Wrap. */
764 bpy_bmdeformvert_clear_doc,
765 ".. method:: clear()\n"
766 "\n"
767 " Clears all weights.\n");
769{
770 BKE_defvert_clear(self->data);
771
772 Py_RETURN_NONE;
773}
774
775#ifdef __GNUC__
776# ifdef __clang__
777# pragma clang diagnostic push
778# pragma clang diagnostic ignored "-Wcast-function-type"
779# else
780# pragma GCC diagnostic push
781# pragma GCC diagnostic ignored "-Wcast-function-type"
782# endif
783#endif
784
785static PyMethodDef bpy_bmdeformvert_methods[] = {
786 {"keys",
787 reinterpret_cast<PyCFunction>(bpy_bmdeformvert_keys),
788 METH_NOARGS,
789 bpy_bmdeformvert_keys_doc},
790 {"values",
791 reinterpret_cast<PyCFunction>(bpy_bmdeformvert_values),
792 METH_NOARGS,
793 bpy_bmdeformvert_values_doc},
794 {"items",
795 reinterpret_cast<PyCFunction>(bpy_bmdeformvert_items),
796 METH_NOARGS,
797 bpy_bmdeformvert_items_doc},
798 {"get",
799 reinterpret_cast<PyCFunction>(bpy_bmdeformvert_get),
800 METH_VARARGS,
801 bpy_bmdeformvert_get_doc},
802 /* BMESH_TODO `pop`, `popitem`, `update`. */
803 {"clear",
804 reinterpret_cast<PyCFunction>(bpy_bmdeformvert_clear),
805 METH_NOARGS,
806 bpy_bmdeformvert_clear_doc},
807 {nullptr, nullptr, 0, nullptr},
808};
809
810#ifdef __GNUC__
811# ifdef __clang__
812# pragma clang diagnostic pop
813# else
814# pragma GCC diagnostic pop
815# endif
816#endif
817
818PyTypeObject BPy_BMDeformVert_Type; /* bm.loops.layers.uv.active */
819
821{
822 BPy_BMDeformVert_Type.tp_basicsize = sizeof(BPy_BMDeformVert);
823
824 BPy_BMDeformVert_Type.tp_name = "BMDeformVert";
825
826 BPy_BMDeformVert_Type.tp_doc = nullptr; /* todo */
827
830
832
833 BPy_BMDeformVert_Type.tp_flags = Py_TPFLAGS_DEFAULT;
834
835 PyType_Ready(&BPy_BMDeformVert_Type);
836}
837
839{
840 if (!BPy_BMDeformVert_Check(value)) [[unlikely]] {
841 PyErr_Format(PyExc_TypeError, "expected BMDeformVert, not a %.200s", Py_TYPE(value)->tp_name);
842 return -1;
843 }
844
845 MDeformVert *dvert_src = (reinterpret_cast<BPy_BMDeformVert *>(value))->data;
846 if (dvert != dvert_src) [[likely]] {
847 BKE_defvert_copy(dvert, dvert_src);
848 }
849 return 0;
850}
851
853{
855 self->data = dvert;
856 return reinterpret_cast<PyObject *>(self);
857}
858
859/* --- End Mesh Deform Vert --- */
860
868
869} // namespace blender
CustomData interface, see also DNA_customdata_types.h.
support for deformation groups and hooks.
#define BM_ELEM_CD_GET_FLOAT_P(ele, offset)
#define BM_ELEM_CD_SET_BOOL(ele, offset, f)
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
#define BM_ELEM_CD_GET_BOOL_P(ele, offset)
#define MLOOPCOL_FROM_CAPSULE(color_capsule)
#define BPy_BMVertSkin_Check(v)
#define BPy_BMDeformVert_Check(v)
#define BPy_BMLoopUV_Check(v)
#define layer
BMesh Iterators.
PyTypeObject BPy_BMLoopUV_Type
static PyMethodDef bpy_bmdeformvert_methods[]
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static PyObject * bpy_bmdeformvert_items(BPy_BMDeformVert *self)
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
static PyObject * bpy_bmdeformvert_clear(BPy_BMDeformVert *self)
static int mathutils_bmloopcol_set_index(BaseMathObject *bmo, int subtype, int index)
static Py_ssize_t bpy_bmdeformvert_len(BPy_BMDeformVert *self)
static int bpy_bmvertskin_use_loose_set(BPy_BMVertSkin *self, PyObject *value, void *)
PyObject * BPy_BMDeformVert_CreatePyObject(MDeformVert *dvert)
MINLINE void copy_v2_v2(float r[2], const float a[2])
static void bm_init_types_bmdvert()
static int mathutils_bmloopcol_set(BaseMathObject *bmo, int)
static PyObject * bpy_bmdeformvert_keys(BPy_BMDeformVert *self)
PyObject * Vector_CreatePyObject_wrap(float *vec, const int vec_num, PyTypeObject *base_type)
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
static void bm_init_types_bmvertskin()
static bool bpy_bmloopuv_pin_uv_ok_or_error(const BPy_BMLoopUV *self)
PyObject * BPy_BMLoopColor_CreatePyObject(MLoopCol *mloopcol)
void BKE_defvert_clear(MDeformVert *dvert)
Definition deform.cc:918
PyObject * BPy_BMVertSkin_CreatePyObject(BMesh *bm, BMVert *vert)
static bool bpy_bmvertskin_flag_ok_or_error(const bool *flag)
static int bpy_bmdeformvert_contains(BPy_BMDeformVert *self, PyObject *value)
static PyObject * bpy_bmloopuv_uv_get(BPy_BMLoopUV *self, void *)
VecBase< float, 2 > float2
static void bm_init_types_bmloopcol()
unsigned char uchar
Definition BKE_text.h:58
static PyMappingMethods bpy_bmdeformvert_as_mapping
static PyObject * bpy_bmvertskin_use_loose_get(BPy_BMVertSkin *self, void *)
BMesh const char void * data
int BPy_BMLoopUV_AssignPyObject(BMesh *bm, BMLoop *loop, PyObject *value)
static PyObject * bpy_bmdeformvert_values(BPy_BMDeformVert *self)
static uchar mathutils_bmloopcol_cb_index
int CustomData_get_offset_named(const CustomData *data, eCustomDataType type, StringRef name)
PyObject * Vector_CreatePyObject_cb(PyObject *cb_user, int vec_num, uchar cb_type, uchar cb_subtype)
static int bpy_bmloopuv_pin_uv_set(BPy_BMLoopUV *self, PyObject *value, void *)
static void mloopcol_from_float(MLoopCol *mloopcol, const float col[4])
static PyGetSetDef bpy_bmvertskin_getseters[]
int mathutils_array_parse(float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
Definition mathutils.cc:97
MDeformWeight * BKE_defvert_ensure_index(MDeformVert *dv, int defgroup)
Definition deform.cc:830
uchar Mathutils_RegisterCallback(Mathutils_Callback *cb)
Definition mathutils.cc:543
static PyObject * bpy_bmvertskin_use_root_get(BPy_BMVertSkin *self, void *)
PyTypeObject BPy_BMVertSkin_Type
static Mathutils_Callback mathutils_bmloopcol_cb
static void bm_init_types_bmloopuv()
static int bpy_bmvertskin_use_root_set(BPy_BMVertSkin *self, PyObject *value, void *)
static void mloopcol_to_float(const MLoopCol *mloopcol, float r_col[4])
BMUVOffsets BM_uv_map_offsets_from_layer(const BMesh *bm, const int layer)
static int bpy_bmvertskin_radius_set(BPy_BMVertSkin *self, PyObject *value, void *)
int PyC_Long_AsBool(PyObject *value)
static PyObject * bpy_bmvertskin_radius_get(BPy_BMVertSkin *self, void *)
static int mathutils_bmloopcol_check(BaseMathObject *)
int BPy_BMLoopColor_AssignPyObject(MLoopCol *mloopcol, PyObject *value)
static int bpy_bmdeformvert_ass_subscript(BPy_BMDeformVert *self, PyObject *key, PyObject *value)
static PyGetSetDef bpy_bmloopuv_getseters[]
static PySequenceMethods bpy_bmdeformvert_as_sequence
void BKE_defvert_copy(MDeformVert *dvert_dst, const MDeformVert *dvert_src)
Definition deform.cc:130
PyTypeObject BPy_BMDeformVert_Type
PyObject * BPy_BMLoopUV_CreatePyObject(BMesh *bm, BMLoop *loop, int layer)
static int bpy_bmloopuv_uv_set(BPy_BMLoopUV *self, PyObject *value, void *)
int BPy_BMDeformVert_AssignPyObject(MDeformVert *dvert, PyObject *value)
static PyObject * bpy_bmdeformvert_subscript(BPy_BMDeformVert *self, PyObject *key)
static int mathutils_bmloopcol_get_index(BaseMathObject *bmo, int subtype, int)
static PyObject * bpy_bmdeformvert_get(BPy_BMDeformVert *self, PyObject *args)
static PyObject * bpy_bmloopuv_pin_uv_get(BPy_BMLoopUV *self, void *)
BMUVOffsets BM_uv_map_offsets_get(const BMesh *bm)
int BPy_BMVertSkin_AssignPyObject(BMesh *bm, BMVert *vert, PyObject *value)
void BKE_defvert_remove_group(MDeformVert *dvert, MDeformWeight *dw)
Definition deform.cc:885
void BPy_BM_init_types_meshdata()
MINLINE void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
MDeformWeight * BKE_defvert_find_index(const MDeformVert *dv, int defgroup)
Definition deform.cc:811
static int mathutils_bmloopcol_get(BaseMathObject *bmo, int)
MINLINE float clamp_f(float value, float min, float max)
header-only utilities
#define PyTuple_SET_ITEMS(op_arg,...)
PyObject_HEAD MDeformVert * data
struct MDeformWeight * dw