53 if (index_absolute != -1) {
54 return &data->layers[index_absolute];
57 PyErr_SetString(PyExc_RuntimeError,
"layer has become invalid");
71 bpy_bmlayeraccess_collection__float_doc,
72 "Generic float custom-data layer.\n"
74 ":type: :class:`BMLayerCollection` of float");
77 bpy_bmlayeraccess_collection__int_doc,
78 "Generic int custom-data layer.\n"
80 ":type: :class:`BMLayerCollection` of int");
83 bpy_bmlayeraccess_collection__float_vector_doc,
84 "Generic 3D vector with float precision custom-data layer.\n"
87 ":class:`BMLayerCollection` of :class:`mathutils.Vector`");
90 bpy_bmlayeraccess_collection__float_color_doc,
91 "Generic RGBA color with float precision custom-data layer.\n"
94 ":class:`BMLayerCollection` of :class:`mathutils.Vector`");
97 bpy_bmlayeraccess_collection__color_doc,
98 "Generic RGBA color with 8-bit precision custom-data layer.\n"
101 ":class:`BMLayerCollection` of :class:`mathutils.Vector`");
104 bpy_bmlayeraccess_collection__string_doc,
105 "Generic string custom-data layer (exposed as bytes, 255 max length).\n"
108 ":class:`BMLayerCollection` of bytes");
111 bpy_bmlayeraccess_collection__deform_doc,
112 "Vertex deform weight :class:`BMDeformVert` (TODO).\n"
115 ":class:`BMLayerCollection` of :class:`bmesh.types.BMDeformVert`"
119 bpy_bmlayeraccess_collection__shape_doc,
120 "Vertex shapekey absolute location (as a 3D Vector).\n"
122 ":type: :class:`BMLayerCollection` of :class:`mathutils.Vector`");
125 bpy_bmlayeraccess_collection__uv_doc,
126 "Accessor for :class:`BMLoopUV` UV (as a 2D Vector).\n"
128 ":type: :class:`BMLayerCollection` of :class:`bmesh.types.BMLoopUV`");
131 bpy_bmlayeraccess_collection__skin_doc,
132 "Accessor for skin layer.\n"
134 ":type: :class:`BMLayerCollection` of :class:`bmesh.types.BMVertSkin`");
138 bpy_bmlayeraccess_collection__freestyle_edge_doc,
139 "Accessor for Freestyle edge layer.\n"
141 ":type: :class:`BMLayerCollection`");
144 bpy_bmlayeraccess_collection__freestyle_face_doc,
145 "Accessor for Freestyle face layer.\n"
147 ":type: :class:`BMLayerCollection`");
161 bpy_bmlayercollection_active_doc,
162 "The active layer of this type (read-only).\n"
164 ":type: :class:`BMLayerItem`");
183 "True if there can exists only one layer of this type (read-only).\n"
195 bpy_bmlayercollection_name_doc,
196 "The layers unique name (read-only).\n"
207 return PyUnicode_FromString(layer->name);
217 bpy_bmlayeraccess_collection__deform_doc,
223 bpy_bmlayeraccess_collection__float_doc,
228 bpy_bmlayeraccess_collection__int_doc,
233 bpy_bmlayeraccess_collection__float_vector_doc,
238 bpy_bmlayeraccess_collection__float_color_doc,
243 bpy_bmlayeraccess_collection__color_doc,
248 bpy_bmlayeraccess_collection__string_doc,
254 bpy_bmlayeraccess_collection__shape_doc,
259 bpy_bmlayeraccess_collection__skin_doc,
262 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr}
269 bpy_bmlayeraccess_collection__float_doc,
274 bpy_bmlayeraccess_collection__int_doc,
279 bpy_bmlayeraccess_collection__float_vector_doc,
284 bpy_bmlayeraccess_collection__float_color_doc,
289 bpy_bmlayeraccess_collection__color_doc,
294 bpy_bmlayeraccess_collection__string_doc,
300 bpy_bmlayeraccess_collection__freestyle_edge_doc,
303 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr}
310 bpy_bmlayeraccess_collection__float_doc,
315 bpy_bmlayeraccess_collection__int_doc,
320 bpy_bmlayeraccess_collection__float_vector_doc,
325 bpy_bmlayeraccess_collection__float_color_doc,
330 bpy_bmlayeraccess_collection__color_doc,
335 bpy_bmlayeraccess_collection__string_doc,
342 bpy_bmlayeraccess_collection__freestyle_face_doc,
346 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr}
353 bpy_bmlayeraccess_collection__float_doc,
358 bpy_bmlayeraccess_collection__int_doc,
363 bpy_bmlayeraccess_collection__float_vector_doc,
368 bpy_bmlayeraccess_collection__float_color_doc,
373 bpy_bmlayeraccess_collection__string_doc,
378 bpy_bmlayeraccess_collection__uv_doc,
383 bpy_bmlayeraccess_collection__color_doc,
386 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr}
394 bpy_bmlayercollection_active_doc,
399 bpy_bmlayercollection_is_singleton_doc,
402 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr}
410 bpy_bmlayercollection_name_doc,
413 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr}
424 bpy_bmlayeritem_copy_from_doc,
425 ".. method:: copy_from(other)\n"
427 " Return a copy of the layer\n"
429 " :arg other: Another layer to copy from.\n"
430 " :type other: :class:`BMLayerItem`\n");
436 PyErr_Format(PyExc_TypeError,
437 "layer.copy_from(x): expected BMLayerItem, not '%.200s'",
438 Py_TYPE(value)->tp_name);
445 if ((
self->htype != value->htype) || (
self->type != value->type)) {
446 PyErr_SetString(PyExc_ValueError,
"layer.copy_from(other): layer type mismatch");
449 else if (
self->index == value->index) {
467 bpy_bmlayercollection_verify_doc,
468 ".. method:: verify()\n"
470 " Create a new layer or return an existing active layer\n"
472 " :return: The newly verified layer.\n"
473 " :rtype: :class:`BMLayerItem`\n");
503 bpy_bmlayercollection_new_doc,
504 ".. method:: new(name)\n"
506 " Create a new layer\n"
508 " :arg name: Optional name argument (will be made unique).\n"
510 " :return: The newly created layer.\n"
511 " :rtype: :class:`BMLayerItem`\n");
514 const char *name =
nullptr;
520 if (!PyArg_ParseTuple(args,
"|s:new", &name)) {
529 PyErr_SetString(PyExc_ValueError,
"layers.new(): is a singleton, use verify() instead");
555 bpy_bmlayercollection_remove_doc,
556 ".. method:: remove(layer)\n"
560 " :arg layer: The layer to remove.\n"
561 " :type layer: :class:`BMLayerItem`\n");
569 PyErr_Format(PyExc_TypeError,
570 "layers.remove(x): expected BMLayerItem, not '%.200s'",
571 Py_TYPE(value)->tp_name);
577 if ((
self->bm != value->bm) || (
self->type != value->type) || (
self->htype != value->htype)) {
578 PyErr_SetString(PyExc_ValueError,
"layers.remove(x): x not in layers");
589 bpy_bmlayercollection_keys_doc,
590 ".. method:: keys()\n"
592 " Return the identifiers of collection members\n"
593 " (matching Python's dict.keys() functionality).\n"
595 " :return: the identifiers for each member of this collection.\n"
596 " :rtype: list[str]\n");
614 ret = PyList_New(tot);
616 for (i = 0; tot-- > 0; index++) {
617 item = PyUnicode_FromString(data->layers[index].name);
618 PyList_SET_ITEM(
ret, i++, item);
626 bpy_bmlayercollection_items_doc,
627 ".. method:: items()\n"
629 " Return the identifiers of collection members\n"
630 " (matching Python's dict.items() functionality).\n"
632 " :return: (key, value) pairs for each member of this collection.\n"
633 " :rtype: list[tuple[str, :class:`BMLayerItem`]]\n");
648 ret = PyList_New(tot);
650 for (i = 0; tot-- > 0; index++) {
651 item = PyTuple_New(2);
653 PyUnicode_FromString(data->layers[index].name),
655 PyList_SET_ITEM(
ret, i++, item);
663 bpy_bmlayercollection_values_doc,
664 ".. method:: values()\n"
666 " Return the values of collection\n"
667 " (matching Python's dict.values() functionality).\n"
669 " :return: the members of this collection.\n"
670 " :rtype: list[:class:`BMLayerItem`]\n");
685 ret = PyList_New(tot);
687 for (i = 0; tot-- > 0; index++) {
689 PyList_SET_ITEM(
ret, i++, item);
697 bpy_bmlayercollection_get_doc,
698 ".. method:: get(key, default=None)\n"
700 " Returns the value of the layer matching the key or default\n"
701 " when not found (matches Python's dictionary function of the same name).\n"
703 " :arg key: The key associated with the layer.\n"
705 " :arg default: Optional argument for the value to return if\n"
706 " *key* is not found.\n"
707 " :type default: Any\n");
711 PyObject *def = Py_None;
715 if (!PyArg_ParseTuple(args,
"s|O:get", &key, &def)) {
729 return Py_NewRef(def);
734 {
nullptr,
nullptr, 0,
nullptr},
737#if (defined(__GNUC__) && !defined(__clang__))
738# pragma GCC diagnostic push
739# pragma GCC diagnostic ignored "-Wcast-function-type"
746 bpy_bmlayercollection_verify_doc},
751 bpy_bmlayercollection_remove_doc},
757 bpy_bmlayercollection_values_doc},
761 bpy_bmlayercollection_items_doc},
763 {
nullptr,
nullptr, 0,
nullptr},
766#if (defined(__GNUC__) && !defined(__clang__))
767# pragma GCC diagnostic pop
800 PyErr_Format(PyExc_KeyError,
"BMLayerCollection[key]: key \"%.200s\" not found", keyname);
821 PyErr_Format(PyExc_IndexError,
"BMLayerCollection[index]: index %d out of range", keynum);
843 tuple = PyTuple_New(stop - start);
846 PyTuple_SET_ITEM(tuple,
857 if (PyUnicode_Check(key)) {
860 if (PyIndex_Check(key)) {
861 const Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
862 if (i == -1 && PyErr_Occurred()) {
867 if (PySlice_Check(key)) {
868 PySliceObject *key_slice = (PySliceObject *)key;
871 if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) {
875 PyErr_SetString(PyExc_TypeError,
"BMLayerCollection[slice]: slice steps not supported");
878 if (key_slice->start == Py_None && key_slice->stop == Py_None) {
882 Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX;
885 if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) {
888 if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) {
892 if (start < 0 || stop < 0) {
905 if (stop - start <= 0) {
906 return PyTuple_New(0);
912 PyErr_SetString(PyExc_AttributeError,
"BMLayerCollection[key]: invalid key, key must be an int");
918 const char *keyname = PyUnicode_AsUTF8(value);
924 if (keyname ==
nullptr) {
925 PyErr_SetString(PyExc_TypeError,
"BMLayerCollection.__contains__: expected a string");
932 return (index != -1) ? 1 : 0;
952 (objobjargproc)
nullptr,
962 PyObject *iter =
nullptr;
969 iter = PyObject_GetIter(
ret);
978 bpy_bmlayeraccess_type_doc,
979 "Exposes custom-data layer attributes.");
983 bpy_bmlayercollection_type_doc,
984 "Gives access to a collection of custom-data layers of the same type and behaves "
985 "like Python dictionaries, "
986 "except for the ability to do list like index access.");
990 bpy_bmlayeritem_type_doc,
991 "Exposes a single custom data layer, "
992 "their main purpose is for use as item accessors to custom-data when used with "
993 "vert/edge/face/loop data.");
1029 self->htype = htype;
1030 return (PyObject *)
self;
1037 self->htype = htype;
1039 return (PyObject *)
self;
1046 self->htype = htype;
1048 self->index = index;
1049 return (PyObject *)
self;
1136 PyErr_SetString(PyExc_AttributeError,
"BMElem[key]: invalid key, must be a BMLayerItem");
1140 PyErr_SetString(PyExc_ValueError,
"BMElem[layer]: layer is from another mesh");
1144 char namestr_1[32], namestr_2[32];
1145 PyErr_Format(PyExc_ValueError,
1146 "Layer/Element type mismatch, expected %.200s got layer type %.200s",
1159 PyErr_SetString(PyExc_KeyError,
"BMElem[key]: layer not found");
1175 switch (py_layer->
type) {
1181 ret = PyFloat_FromDouble(*(
float *)value);
1185 ret = PyLong_FromLong(*(
int *)value);
1198 ret = PyBytes_FromStringAndSize(mstring->
s, mstring->
s_len);
1203 PyErr_SetString(PyExc_ValueError,
"BMElem[layer]: layer is from another mesh");
1222 ret = Py_NotImplemented;
1240 switch (py_layer->
type) {
1246 const float tmp_val = PyFloat_AsDouble(py_value);
1247 if (
UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
1249 PyExc_TypeError,
"expected a float, not a %.200s", Py_TYPE(py_value)->tp_name);
1253 *(
float *)value = tmp_val;
1258 const int tmp_val = PyC_Long_AsI32(py_value);
1259 if (
UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
1264 *(
int *)value = tmp_val;
1283 Py_ssize_t tmp_val_len;
1284 if (
UNLIKELY(PyBytes_AsStringAndSize(py_value, &tmp_val, &tmp_val_len) == -1)) {
1285 PyErr_Format(PyExc_TypeError,
"expected bytes, not a %.200s", Py_TYPE(py_value)->tp_name);
1289 if (tmp_val_len >
sizeof(mstring->
s)) {
1290 tmp_val_len =
sizeof(mstring->
s);
1292 memcpy(mstring->
s, tmp_val, tmp_val_len);
1293 mstring->
s_len = tmp_val_len;
1299 PyErr_SetString(PyExc_ValueError,
"BMElem[layer]: layer is from another mesh");
1327 PyErr_SetString(PyExc_AttributeError,
"readonly / unsupported type");
CustomData interface, see also DNA_customdata_types.h.
int CustomData_get_layer_index_n(const CustomData *data, eCustomDataType type, int n)
int CustomData_get_named_layer(const CustomData *data, eCustomDataType type, blender::StringRef name)
void * CustomData_bmesh_get_n(const CustomData *data, void *block, eCustomDataType type, int n)
int CustomData_get_named_layer_index(const CustomData *data, eCustomDataType type, blender::StringRef name)
int CustomData_get_layer_index(const CustomData *data, eCustomDataType type)
int CustomData_get_active_layer(const CustomData *data, eCustomDataType type)
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
bool CustomData_layertype_is_singleton(eCustomDataType type)
int CustomData_number_of_layers(const CustomData *data, eCustomDataType type)
#define BLI_assert_unreachable()
MINLINE void copy_v3_v3(float r[3], const float a[3])
#define POINTER_AS_INT(i)
void BM_data_layer_free_n(BMesh *bm, CustomData *data, int type, int n)
void BM_data_layer_copy(BMesh *bm, CustomData *data, int type, int src_n, int dst_n)
void BM_data_layer_add(BMesh *bm, CustomData *data, int type)
void BM_data_layer_add_named(BMesh *bm, CustomData *data, int type, const char *name)
void BM_uv_map_ensure_select_and_pin_attrs(BMesh *bm)
ATTR_WARN_UNUSED_RESULT BMesh * bm
char * BPy_BMElem_StringFromHType_ex(const char htype, char ret[32])
#define BPY_BM_CHECK_OBJ(obj)
#define BPY_BM_CHECK_SOURCE_OBJ(bm, errmsg,...)
#define BPY_BM_CHECK_INT(obj)
PyObject * BPy_BMLayerItem_CreatePyObject(BMesh *bm, const char htype, int type, int index)
static PyGetSetDef bpy_bmlayeritem_getseters[]
PyTypeObject BPy_BMLayerCollection_Type
PyObject * BPy_BMLayerAccess_CreatePyObject(BMesh *bm, const char htype)
static PyObject * bpy_bmlayercollection_iter(BPy_BMLayerCollection *self)
static PyObject * bpy_bmlayercollection_subscript_slice(BPy_BMLayerCollection *self, Py_ssize_t start, Py_ssize_t stop)
PyTypeObject BPy_BMLayerItem_Type
static PyGetSetDef bpy_bmlayercollection_getseters[]
static PyObject * bpy_bmlayercollection_keys(BPy_BMLayerCollection *self)
static PySequenceMethods bpy_bmlayercollection_as_sequence
static PyObject * bpy_bmlayercollection_subscript(BPy_BMLayerCollection *self, PyObject *key)
PyTypeObject BPy_BMLayerAccessLoop_Type
PyTypeObject BPy_BMLayerAccessVert_Type
static PyObject * bpy_bmlayercollection_verify(BPy_BMLayerCollection *self)
static PyGetSetDef bpy_bmlayeraccess_loop_getseters[]
static void * bpy_bmlayeritem_ptr_get(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer)
static int bpy_bmlayercollection_contains(BPy_BMLayerCollection *self, PyObject *value)
static PyGetSetDef bpy_bmlayeraccess_edge_getseters[]
static PyObject * bpy_bmlayercollection_subscript_int(BPy_BMLayerCollection *self, Py_ssize_t keynum)
static PyMethodDef bpy_bmelemseq_methods[]
static Py_ssize_t bpy_bmlayercollection_length(BPy_BMLayerCollection *self)
int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObject *py_value)
static PyObject * bpy_bmlayeritem_copy_from(BPy_BMLayerItem *self, BPy_BMLayerItem *value)
PyTypeObject BPy_BMLayerAccessFace_Type
static PyObject * bpy_bmlayercollection_new(BPy_BMLayerCollection *self, PyObject *args)
static PyObject * bpy_bmlayercollection_is_singleton_get(BPy_BMLayerItem *self, void *)
static PyGetSetDef bpy_bmlayeraccess_face_getseters[]
static PyObject * bpy_bmlayercollection_items(BPy_BMLayerCollection *self)
static PyMappingMethods bpy_bmlayercollection_as_mapping
static PyObject * bpy_bmlayercollection_subscript_str(BPy_BMLayerCollection *self, const char *keyname)
PyTypeObject BPy_BMLayerAccessEdge_Type
static PyObject * bpy_bmlayeraccess_collection_get(BPy_BMLayerAccess *self, void *flag)
static PyObject * bpy_bmlayercollection_values(BPy_BMLayerCollection *self)
static CustomDataLayer * bpy_bmlayeritem_get(BPy_BMLayerItem *self)
static PyObject * bpy_bmlayercollection_get(BPy_BMLayerCollection *self, PyObject *args)
static PyObject * bpy_bmlayeritem_name_get(BPy_BMLayerItem *self, void *)
void BPy_BM_init_types_customdata()
static PyObject * bpy_bmlayercollection_remove(BPy_BMLayerCollection *self, BPy_BMLayerItem *value)
PyObject * BPy_BMLayerCollection_CreatePyObject(BMesh *bm, const char htype, int type)
static PyObject * bpy_bmlayercollection_active_get(BPy_BMLayerItem *self, void *)
PyDoc_STRVAR(bpy_bmlayeraccess_collection__float_doc, "Generic float custom-data layer.\n" "\n" ":type: :class:`BMLayerCollection` of float")
static PyMethodDef bpy_bmlayeritem_methods[]
PyObject * BPy_BMLayerItem_GetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer)
BMElem.__getitem__() / setitem()
static PyGetSetDef bpy_bmlayeraccess_vert_getseters[]
static CustomData * bpy_bm_customdata_get(BMesh *bm, char htype)
#define BPy_BMLayerItem_Check(v)
int BPy_BMVertSkin_AssignPyObject(MVertSkin *mvertskin, PyObject *value)
PyObject * BPy_BMDeformVert_CreatePyObject(MDeformVert *dvert)
int BPy_BMDeformVert_AssignPyObject(MDeformVert *dvert, PyObject *value)
PyObject * BPy_BMLoopColor_CreatePyObject(MLoopCol *mloopcol)
PyObject * BPy_BMLoopUV_CreatePyObject(BMesh *bm, BMLoop *loop, int layer)
int BPy_BMLoopColor_AssignPyObject(MLoopCol *mloopcol, PyObject *value)
int BPy_BMLoopUV_AssignPyObject(BMesh *bm, BMLoop *loop, PyObject *value)
PyObject * BPy_BMVertSkin_CreatePyObject(MVertSkin *mvertskin)
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
int mathutils_array_parse(float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
PyObject * Vector_CreatePyObject_wrap(float *vec, const int vec_num, PyTypeObject *base_type)
#define PyTuple_SET_ITEMS(op_arg,...)
PyObject_VAR_HEAD BMesh * bm
PyObject_VAR_HEAD BMesh * bm