Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-04-17 07:17:24 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-17 07:21:24 +0300
commite12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch)
tree8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/python/bmesh
parentb3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff)
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/python/bmesh')
-rw-r--r--source/blender/python/bmesh/CMakeLists.txt60
-rw-r--r--source/blender/python/bmesh/bmesh_py_api.c249
-rw-r--r--source/blender/python/bmesh/bmesh_py_geometry.c88
-rw-r--r--source/blender/python/bmesh/bmesh_py_ops.c533
-rw-r--r--source/blender/python/bmesh/bmesh_py_ops_call.c1476
-rw-r--r--source/blender/python/bmesh/bmesh_py_ops_call.h5
-rw-r--r--source/blender/python/bmesh/bmesh_py_types.c6227
-rw-r--r--source/blender/python/bmesh/bmesh_py_types.h194
-rw-r--r--source/blender/python/bmesh/bmesh_py_types_customdata.c1736
-rw-r--r--source/blender/python/bmesh/bmesh_py_types_customdata.h30
-rw-r--r--source/blender/python/bmesh/bmesh_py_types_meshdata.c766
-rw-r--r--source/blender/python/bmesh/bmesh_py_types_meshdata.h14
-rw-r--r--source/blender/python/bmesh/bmesh_py_types_select.c572
-rw-r--r--source/blender/python/bmesh/bmesh_py_types_select.h14
-rw-r--r--source/blender/python/bmesh/bmesh_py_utils.c1422
15 files changed, 6892 insertions, 6494 deletions
diff --git a/source/blender/python/bmesh/CMakeLists.txt b/source/blender/python/bmesh/CMakeLists.txt
index 23ecdf4aa75..14baa08abc1 100644
--- a/source/blender/python/bmesh/CMakeLists.txt
+++ b/source/blender/python/bmesh/CMakeLists.txt
@@ -16,49 +16,49 @@
# ***** END GPL LICENSE BLOCK *****
set(INC
- .
- ../../bmesh
- ../../blenkernel
- ../../blenlib
- ../../depsgraph
- ../../makesdna
- ../../../../intern/guardedalloc
+ .
+ ../../bmesh
+ ../../blenkernel
+ ../../blenlib
+ ../../depsgraph
+ ../../makesdna
+ ../../../../intern/guardedalloc
)
set(INC_SYS
- ${PYTHON_INCLUDE_DIRS}
+ ${PYTHON_INCLUDE_DIRS}
)
set(SRC
- bmesh_py_api.c
- bmesh_py_geometry.c
- bmesh_py_ops.c
- bmesh_py_ops_call.c
- bmesh_py_types.c
- bmesh_py_types_customdata.c
- bmesh_py_types_meshdata.c
- bmesh_py_types_select.c
- bmesh_py_utils.c
+ bmesh_py_api.c
+ bmesh_py_geometry.c
+ bmesh_py_ops.c
+ bmesh_py_ops_call.c
+ bmesh_py_types.c
+ bmesh_py_types_customdata.c
+ bmesh_py_types_meshdata.c
+ bmesh_py_types_select.c
+ bmesh_py_utils.c
- bmesh_py_api.h
- bmesh_py_geometry.h
- bmesh_py_ops.h
- bmesh_py_ops_call.h
- bmesh_py_types.h
- bmesh_py_types_customdata.h
- bmesh_py_types_meshdata.h
- bmesh_py_types_select.h
- bmesh_py_utils.h
+ bmesh_py_api.h
+ bmesh_py_geometry.h
+ bmesh_py_ops.h
+ bmesh_py_ops_call.h
+ bmesh_py_types.h
+ bmesh_py_types_customdata.h
+ bmesh_py_types_meshdata.h
+ bmesh_py_types_select.h
+ bmesh_py_utils.h
)
set(LIB
- bf_blenkernel
- bf_blenlib
- bf_python_mathutils
+ bf_blenkernel
+ bf_blenlib
+ bf_python_mathutils
)
if(WITH_FREESTYLE)
- add_definitions(-DWITH_FREESTYLE)
+ add_definitions(-DWITH_FREESTYLE)
endif()
blender_add_lib(bf_python_bmesh "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/python/bmesh/bmesh_py_api.c b/source/blender/python/bmesh/bmesh_py_api.c
index ef3e72bfbad..8ab5e7adea7 100644
--- a/source/blender/python/bmesh/bmesh_py_api.c
+++ b/source/blender/python/bmesh/bmesh_py_api.c
@@ -47,167 +47,168 @@
#include "bmesh_py_api.h" /* own include */
PyDoc_STRVAR(bpy_bm_new_doc,
-".. method:: new(use_operators=True)\n"
-"\n"
-" :arg 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"
-);
+ ".. method:: new(use_operators=True)\n"
+ "\n"
+ " :arg use_operators: Support calling operators in :mod:`bmesh.ops` (uses some "
+ "extra memory per vert/edge/face).\n"
+ " :type use_operators: bool\n"
+ " :return: Return a new, empty BMesh.\n"
+ " :rtype: :class:`bmesh.types.BMesh`\n");
static PyObject *bpy_bm_new(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
- static const char *kwlist[] = {"use_operators", NULL};
- BMesh *bm;
+ static const char *kwlist[] = {"use_operators", NULL};
+ BMesh *bm;
- bool use_operators = true;
+ bool use_operators = true;
- if (!PyArg_ParseTupleAndKeywords(
- args, kw, "|$O&:new", (char **)kwlist,
- PyC_ParseBool, &use_operators))
- {
- return NULL;
- }
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kw, "|$O&:new", (char **)kwlist, PyC_ParseBool, &use_operators)) {
+ return NULL;
+ }
- bm = BM_mesh_create(
- &bm_mesh_allocsize_default,
- &((struct BMeshCreateParams){.use_toolflags = use_operators,}));
+ bm = BM_mesh_create(&bm_mesh_allocsize_default,
+ &((struct BMeshCreateParams){
+ .use_toolflags = use_operators,
+ }));
- return BPy_BMesh_CreatePyObject(bm, BPY_BMFLAG_NOP);
+ return BPy_BMesh_CreatePyObject(bm, BPY_BMFLAG_NOP);
}
PyDoc_STRVAR(bpy_bm_from_edit_mesh_doc,
-".. method:: from_edit_mesh(mesh)\n"
-"\n"
-" Return a BMesh from this mesh, currently the mesh must already be in editmode.\n"
-"\n"
-" :arg mesh: The editmode mesh.\n"
-" :type mesh: :class:`bpy.types.Mesh`\n"
-" :return: the BMesh associated with this mesh.\n"
-" :rtype: :class:`bmesh.types.BMesh`\n"
-);
+ ".. method:: from_edit_mesh(mesh)\n"
+ "\n"
+ " Return a BMesh from this mesh, currently the mesh must already be in editmode.\n"
+ "\n"
+ " :arg mesh: The editmode mesh.\n"
+ " :type mesh: :class:`bpy.types.Mesh`\n"
+ " :return: the BMesh associated with this mesh.\n"
+ " :rtype: :class:`bmesh.types.BMesh`\n");
static PyObject *bpy_bm_from_edit_mesh(PyObject *UNUSED(self), PyObject *value)
{
- BMesh *bm;
- Mesh *me = PyC_RNA_AsPointer(value, "Mesh");
+ BMesh *bm;
+ Mesh *me = PyC_RNA_AsPointer(value, "Mesh");
- if (me == NULL) {
- return NULL;
- }
+ if (me == NULL) {
+ return NULL;
+ }
- if (me->edit_mesh == NULL) {
- PyErr_SetString(PyExc_ValueError,
- "The mesh must be in editmode");
- return NULL;
- }
+ if (me->edit_mesh == NULL) {
+ PyErr_SetString(PyExc_ValueError, "The mesh must be in editmode");
+ return NULL;
+ }
- bm = me->edit_mesh->bm;
+ bm = me->edit_mesh->bm;
- return BPy_BMesh_CreatePyObject(bm, BPY_BMFLAG_IS_WRAPPED);
+ return BPy_BMesh_CreatePyObject(bm, BPY_BMFLAG_IS_WRAPPED);
}
PyDoc_STRVAR(bpy_bm_update_edit_mesh_doc,
-".. method:: update_edit_mesh(mesh, loop_triangles=True, destructive=True)\n"
-"\n"
-" Update the mesh after changes to the BMesh in editmode,\n"
-" optionally recalculating n-gon tessellation.\n"
-"\n"
-" :arg mesh: The editmode mesh.\n"
-" :type mesh: :class:`bpy.types.Mesh`\n"
-" :arg loop_triangles: Option to recalculate n-gon tessellation.\n"
-" :type loop_triangles: boolean\n"
-" :arg destructive: Use when geometry has been added or removed.\n"
-" :type destructive: boolean\n"
-);
+ ".. method:: update_edit_mesh(mesh, loop_triangles=True, destructive=True)\n"
+ "\n"
+ " Update the mesh after changes to the BMesh in editmode,\n"
+ " optionally recalculating n-gon tessellation.\n"
+ "\n"
+ " :arg mesh: The editmode mesh.\n"
+ " :type mesh: :class:`bpy.types.Mesh`\n"
+ " :arg loop_triangles: Option to recalculate n-gon tessellation.\n"
+ " :type loop_triangles: boolean\n"
+ " :arg destructive: Use when geometry has been added or removed.\n"
+ " :type destructive: boolean\n");
static PyObject *bpy_bm_update_edit_mesh(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
- static const char *kwlist[] = {"mesh", "loop_triangles", "destructive", NULL};
- PyObject *py_me;
- Mesh *me;
- bool do_loop_triangles = true;
- bool is_destructive = true;
-
- if (!PyArg_ParseTupleAndKeywords(
- args, kw, "O|O&O&:update_edit_mesh", (char **)kwlist,
- &py_me,
- PyC_ParseBool, &do_loop_triangles,
- PyC_ParseBool, &is_destructive))
- {
- return NULL;
- }
-
- me = PyC_RNA_AsPointer(py_me, "Mesh");
-
- if (me == NULL) {
- return NULL;
- }
-
- if (me->edit_mesh == NULL) {
- PyErr_SetString(PyExc_ValueError,
- "The mesh must be in editmode");
- return NULL;
- }
-
- {
- extern void EDBM_update_generic(BMEditMesh *em, const bool do_tessface, const bool is_destructive);
-
- EDBM_update_generic(me->edit_mesh, do_loop_triangles, is_destructive);
- }
-
- Py_RETURN_NONE;
+ static const char *kwlist[] = {"mesh", "loop_triangles", "destructive", NULL};
+ PyObject *py_me;
+ Mesh *me;
+ bool do_loop_triangles = true;
+ bool is_destructive = true;
+
+ if (!PyArg_ParseTupleAndKeywords(args,
+ kw,
+ "O|O&O&:update_edit_mesh",
+ (char **)kwlist,
+ &py_me,
+ PyC_ParseBool,
+ &do_loop_triangles,
+ PyC_ParseBool,
+ &is_destructive)) {
+ return NULL;
+ }
+
+ me = PyC_RNA_AsPointer(py_me, "Mesh");
+
+ if (me == NULL) {
+ return NULL;
+ }
+
+ if (me->edit_mesh == NULL) {
+ PyErr_SetString(PyExc_ValueError, "The mesh must be in editmode");
+ return NULL;
+ }
+
+ {
+ extern void EDBM_update_generic(
+ BMEditMesh * em, const bool do_tessface, const bool is_destructive);
+
+ EDBM_update_generic(me->edit_mesh, do_loop_triangles, is_destructive);
+ }
+
+ Py_RETURN_NONE;
}
static struct PyMethodDef BPy_BM_methods[] = {
- {"new", (PyCFunction)bpy_bm_new, METH_VARARGS | METH_KEYWORDS, bpy_bm_new_doc},
- {"from_edit_mesh", (PyCFunction)bpy_bm_from_edit_mesh, METH_O, bpy_bm_from_edit_mesh_doc},
- {"update_edit_mesh", (PyCFunction)bpy_bm_update_edit_mesh, METH_VARARGS | METH_KEYWORDS, bpy_bm_update_edit_mesh_doc},
- {NULL, NULL, 0, NULL},
+ {"new", (PyCFunction)bpy_bm_new, METH_VARARGS | METH_KEYWORDS, bpy_bm_new_doc},
+ {"from_edit_mesh", (PyCFunction)bpy_bm_from_edit_mesh, METH_O, bpy_bm_from_edit_mesh_doc},
+ {"update_edit_mesh",
+ (PyCFunction)bpy_bm_update_edit_mesh,
+ METH_VARARGS | METH_KEYWORDS,
+ bpy_bm_update_edit_mesh_doc},
+ {NULL, NULL, 0, NULL},
};
PyDoc_STRVAR(BPy_BM_doc,
-"This module provides access to blenders bmesh data structures.\n"
-"\n"
-".. include:: include__bmesh.rst\n"
-);
+ "This module provides access to blenders bmesh data structures.\n"
+ "\n"
+ ".. include:: include__bmesh.rst\n");
static struct PyModuleDef BPy_BM_module_def = {
- PyModuleDef_HEAD_INIT,
- "bmesh", /* m_name */
- BPy_BM_doc, /* m_doc */
- 0, /* m_size */
- BPy_BM_methods, /* m_methods */
- NULL, /* m_reload */
- NULL, /* m_traverse */
- NULL, /* m_clear */
- NULL, /* m_free */
+ PyModuleDef_HEAD_INIT,
+ "bmesh", /* m_name */
+ BPy_BM_doc, /* m_doc */
+ 0, /* m_size */
+ BPy_BM_methods, /* m_methods */
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL, /* m_free */
};
PyObject *BPyInit_bmesh(void)
{
- PyObject *mod;
- PyObject *submodule;
- PyObject *sys_modules = PyImport_GetModuleDict();
+ PyObject *mod;
+ PyObject *submodule;
+ PyObject *sys_modules = PyImport_GetModuleDict();
- BPy_BM_init_types();
- BPy_BM_init_types_select();
- BPy_BM_init_types_customdata();
- BPy_BM_init_types_meshdata();
+ BPy_BM_init_types();
+ BPy_BM_init_types_select();
+ BPy_BM_init_types_customdata();
+ BPy_BM_init_types_meshdata();
- mod = PyModule_Create(&BPy_BM_module_def);
+ mod = PyModule_Create(&BPy_BM_module_def);
- /* bmesh.types */
- PyModule_AddObject(mod, "types", (submodule = BPyInit_bmesh_types()));
- PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
+ /* bmesh.types */
+ PyModule_AddObject(mod, "types", (submodule = BPyInit_bmesh_types()));
+ PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
- /* bmesh.ops (not a real module, exposes module like access). */
- PyModule_AddObject(mod, "ops", (submodule = BPyInit_bmesh_ops()));
- /* PyDict_SetItemString(sys_modules, PyModule_GetNameObject(submodule), submodule); */
- PyDict_SetItemString(sys_modules, "bmesh.ops", submodule); /* fake module */
+ /* bmesh.ops (not a real module, exposes module like access). */
+ PyModule_AddObject(mod, "ops", (submodule = BPyInit_bmesh_ops()));
+ /* PyDict_SetItemString(sys_modules, PyModule_GetNameObject(submodule), submodule); */
+ PyDict_SetItemString(sys_modules, "bmesh.ops", submodule); /* fake module */
- PyModule_AddObject(mod, "utils", (submodule = BPyInit_bmesh_utils()));
- PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
+ PyModule_AddObject(mod, "utils", (submodule = BPyInit_bmesh_utils()));
+ PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
- PyModule_AddObject(mod, "geometry", (submodule = BPyInit_bmesh_geometry()));
- PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
+ PyModule_AddObject(mod, "geometry", (submodule = BPyInit_bmesh_geometry()));
+ PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
- return mod;
+ return mod;
}
diff --git a/source/blender/python/bmesh/bmesh_py_geometry.c b/source/blender/python/bmesh/bmesh_py_geometry.c
index 30265af1e9f..2429d2a4888 100644
--- a/source/blender/python/bmesh/bmesh_py_geometry.c
+++ b/source/blender/python/bmesh/bmesh_py_geometry.c
@@ -35,70 +35,64 @@
#include "bmesh_py_geometry.h" /* own include */
PyDoc_STRVAR(bpy_bm_geometry_intersect_face_point_doc,
-".. method:: intersect_face_point(face, point)\n"
-"\n"
-" Tests if the projection of a point is inside a face (using the face's normal).\n"
-"\n"
-" :arg face: The face to test.\n"
-" :type face: :class:`bmesh.types.BMFace`\n"
-" :arg point: The point to test.\n"
-" :type point: float triplet\n"
-" :return: True when the projection of the point is in the face.\n"
-" :rtype: bool\n"
-);
+ ".. method:: intersect_face_point(face, point)\n"
+ "\n"
+ " Tests if the projection of a point is inside a face (using the face's normal).\n"
+ "\n"
+ " :arg face: The face to test.\n"
+ " :type face: :class:`bmesh.types.BMFace`\n"
+ " :arg point: The point to test.\n"
+ " :type point: float triplet\n"
+ " :return: True when the projection of the point is in the face.\n"
+ " :rtype: bool\n");
static PyObject *bpy_bm_geometry_intersect_face_point(BPy_BMFace *UNUSED(self), PyObject *args)
{
- BPy_BMFace *py_face;
- PyObject *py_point;
- float point[3];
- bool ret;
+ BPy_BMFace *py_face;
+ PyObject *py_point;
+ float point[3];
+ bool ret;
- if (!PyArg_ParseTuple(args,
- "O!O:intersect_face_point",
- &BPy_BMFace_Type, &py_face,
- &py_point))
- {
- return NULL;
- }
+ if (!PyArg_ParseTuple(args, "O!O:intersect_face_point", &BPy_BMFace_Type, &py_face, &py_point)) {
+ return NULL;
+ }
- BPY_BM_CHECK_OBJ(py_face);
- if (mathutils_array_parse(point, 3, 3, py_point, "intersect_face_point") == -1) {
- return NULL;
- }
+ BPY_BM_CHECK_OBJ(py_face);
+ if (mathutils_array_parse(point, 3, 3, py_point, "intersect_face_point") == -1) {
+ return NULL;
+ }
- ret = BM_face_point_inside_test(py_face->f, point);
+ ret = BM_face_point_inside_test(py_face->f, point);
- return PyBool_FromLong(ret);
+ return PyBool_FromLong(ret);
}
-
static struct PyMethodDef BPy_BM_geometry_methods[] = {
- {"intersect_face_point", (PyCFunction)bpy_bm_geometry_intersect_face_point, METH_VARARGS, bpy_bm_geometry_intersect_face_point_doc},
- {NULL, NULL, 0, NULL},
+ {"intersect_face_point",
+ (PyCFunction)bpy_bm_geometry_intersect_face_point,
+ METH_VARARGS,
+ bpy_bm_geometry_intersect_face_point_doc},
+ {NULL, NULL, 0, NULL},
};
-
PyDoc_STRVAR(BPy_BM_utils_doc,
-"This module provides access to bmesh geometry evaluation functions."
-);
+ "This module provides access to bmesh geometry evaluation functions.");
static struct PyModuleDef BPy_BM_geometry_module_def = {
- PyModuleDef_HEAD_INIT,
- "bmesh.geometry", /* m_name */
- BPy_BM_utils_doc, /* m_doc */
- 0, /* m_size */
- BPy_BM_geometry_methods, /* m_methods */
- NULL, /* m_reload */
- NULL, /* m_traverse */
- NULL, /* m_clear */
- NULL, /* m_free */
+ PyModuleDef_HEAD_INIT,
+ "bmesh.geometry", /* m_name */
+ BPy_BM_utils_doc, /* m_doc */
+ 0, /* m_size */
+ BPy_BM_geometry_methods, /* m_methods */
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL, /* m_free */
};
-
PyObject *BPyInit_bmesh_geometry(void)
{
- PyObject *submodule;
+ PyObject *submodule;
- submodule = PyModule_Create(&BPy_BM_geometry_module_def);
+ submodule = PyModule_Create(&BPy_BM_geometry_module_def);
- return submodule;
+ return submodule;
}
diff --git a/source/blender/python/bmesh/bmesh_py_ops.c b/source/blender/python/bmesh/bmesh_py_ops.c
index fe82f22ec8c..fd37c8521c1 100644
--- a/source/blender/python/bmesh/bmesh_py_ops.c
+++ b/source/blender/python/bmesh/bmesh_py_ops.c
@@ -31,11 +31,10 @@
#include "MEM_guardedalloc.h"
-
#include "bmesh.h"
#include "bmesh_py_ops_call.h"
-#include "bmesh_py_ops.h" /* own include */
+#include "bmesh_py_ops.h" /* own include */
/* bmesh operator 'bmesh.ops.*' callable types
* ******************************************* */
@@ -43,327 +42,337 @@ static PyTypeObject bmesh_op_Type;
static PyObject *bpy_bmesh_op_CreatePyObject(const char *opname)
{
- BPy_BMeshOpFunc *self = PyObject_New(BPy_BMeshOpFunc, &bmesh_op_Type);
+ BPy_BMeshOpFunc *self = PyObject_New(BPy_BMeshOpFunc, &bmesh_op_Type);
- self->opname = opname;
+ self->opname = opname;
- return (PyObject *)self;
+ return (PyObject *)self;
}
static PyObject *bpy_bmesh_op_repr(BPy_BMeshOpFunc *self)
{
- return PyUnicode_FromFormat("<%.200s bmesh.ops.%.200s()>",
- Py_TYPE(self)->tp_name,
- self->opname);
+ return PyUnicode_FromFormat("<%.200s bmesh.ops.%.200s()>", Py_TYPE(self)->tp_name, self->opname);
}
-
/* methods
* ======= */
-
/* __doc__
* ------- */
static char *bmp_slots_as_args(const BMOSlotType slot_types[BMO_OP_MAX_SLOTS], const bool is_out)
{
- DynStr *dyn_str = BLI_dynstr_new();
- char *ret;
- bool quoted;
- bool set;
-
- int i = 0;
-
- while (*slot_types[i].name) {
- quoted = false;
- set = false;
- /* cut off '.out' by using a string size arg */
- const int name_len = is_out ?
- (strchr(slot_types[i].name, '.') - slot_types[i].name) :
- sizeof(slot_types[i].name);
- const char *value = "<Unknown>";
- switch (slot_types[i].type) {
- case BMO_OP_SLOT_BOOL: value = "False"; break;
- case BMO_OP_SLOT_INT:
- if (slot_types[i].subtype.intg == BMO_OP_SLOT_SUBTYPE_INT_ENUM) {
- value = slot_types[i].enum_flags[0].identifier;
- quoted = true;
- }
- else if (slot_types[i].subtype.intg == BMO_OP_SLOT_SUBTYPE_INT_FLAG) {
- value = "";
- set = true;
- }
- else {
- value = "0";
- }
- break;
- case BMO_OP_SLOT_FLT: value = "0.0"; break;
- case BMO_OP_SLOT_PTR: value = "None"; break;
- case BMO_OP_SLOT_MAT: value = "Matrix()"; break;
- case BMO_OP_SLOT_VEC: value = "Vector()"; break;
- case BMO_OP_SLOT_ELEMENT_BUF: value =
- (slot_types[i].subtype.elem & BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE) ? "None" : "[]"; break;
- case BMO_OP_SLOT_MAPPING: value = "{}"; break;
- }
- BLI_dynstr_appendf(
- dyn_str, i ? ", %.*s=%s%s%s%s%s" : "%.*s=%s%s%s%s%s",
- name_len, slot_types[i].name,
- set ? "{" : "", quoted ? "'" : "",
- value,
- quoted ? "'" : "", set ? "}" : "");
- i++;
- }
-
- ret = BLI_dynstr_get_cstring(dyn_str);
- BLI_dynstr_free(dyn_str);
- return ret;
+ DynStr *dyn_str = BLI_dynstr_new();
+ char *ret;
+ bool quoted;
+ bool set;
+
+ int i = 0;
+
+ while (*slot_types[i].name) {
+ quoted = false;
+ set = false;
+ /* cut off '.out' by using a string size arg */
+ const int name_len = is_out ? (strchr(slot_types[i].name, '.') - slot_types[i].name) :
+ sizeof(slot_types[i].name);
+ const char *value = "<Unknown>";
+ switch (slot_types[i].type) {
+ case BMO_OP_SLOT_BOOL:
+ value = "False";
+ break;
+ case BMO_OP_SLOT_INT:
+ if (slot_types[i].subtype.intg == BMO_OP_SLOT_SUBTYPE_INT_ENUM) {
+ value = slot_types[i].enum_flags[0].identifier;
+ quoted = true;
+ }
+ else if (slot_types[i].subtype.intg == BMO_OP_SLOT_SUBTYPE_INT_FLAG) {
+ value = "";
+ set = true;
+ }
+ else {
+ value = "0";
+ }
+ break;
+ case BMO_OP_SLOT_FLT:
+ value = "0.0";
+ break;
+ case BMO_OP_SLOT_PTR:
+ value = "None";
+ break;
+ case BMO_OP_SLOT_MAT:
+ value = "Matrix()";
+ break;
+ case BMO_OP_SLOT_VEC:
+ value = "Vector()";
+ break;
+ case BMO_OP_SLOT_ELEMENT_BUF:
+ value = (slot_types[i].subtype.elem & BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE) ? "None" : "[]";
+ break;
+ case BMO_OP_SLOT_MAPPING:
+ value = "{}";
+ break;
+ }
+ BLI_dynstr_appendf(dyn_str,
+ i ? ", %.*s=%s%s%s%s%s" : "%.*s=%s%s%s%s%s",
+ name_len,
+ slot_types[i].name,
+ set ? "{" : "",
+ quoted ? "'" : "",
+ value,
+ quoted ? "'" : "",
+ set ? "}" : "");
+ i++;
+ }
+
+ ret = BLI_dynstr_get_cstring(dyn_str);
+ BLI_dynstr_free(dyn_str);
+ return ret;
}
static PyObject *bpy_bmesh_op_doc_get(BPy_BMeshOpFunc *self, void *UNUSED(closure))
{
- PyObject *ret;
- char *slot_in;
- char *slot_out;
- int i;
+ PyObject *ret;
+ char *slot_in;
+ char *slot_out;
+ int i;
- i = BMO_opcode_from_opname(self->opname);
+ i = BMO_opcode_from_opname(self->opname);
- slot_in = bmp_slots_as_args(bmo_opdefines[i]->slot_types_in, false);
- slot_out = bmp_slots_as_args(bmo_opdefines[i]->slot_types_out, true);
+ slot_in = bmp_slots_as_args(bmo_opdefines[i]->slot_types_in, false);
+ slot_out = bmp_slots_as_args(bmo_opdefines[i]->slot_types_out, true);
- ret = PyUnicode_FromFormat("%.200s bmesh.ops.%.200s(bmesh, %s)\n -> dict(%s)",
- Py_TYPE(self)->tp_name,
- self->opname, slot_in, slot_out);
+ ret = PyUnicode_FromFormat("%.200s bmesh.ops.%.200s(bmesh, %s)\n -> dict(%s)",
+ Py_TYPE(self)->tp_name,
+ self->opname,
+ slot_in,
+ slot_out);
- MEM_freeN(slot_in);
- MEM_freeN(slot_out);
+ MEM_freeN(slot_in);
+ MEM_freeN(slot_out);
- return ret;
+ return ret;
}
static PyGetSetDef bpy_bmesh_op_getseters[] = {
- {(char *)"__doc__", (getter)bpy_bmesh_op_doc_get, (setter)NULL, NULL, NULL},
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ {(char *)"__doc__", (getter)bpy_bmesh_op_doc_get, (setter)NULL, NULL, NULL},
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
-
/* Types
* ===== */
static PyTypeObject bmesh_op_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BMeshOpFunc", /* tp_name */
- sizeof(BPy_BMeshOpFunc), /* tp_basicsize */
- 0, /* tp_itemsize */
- /* methods */
- NULL, /* tp_dealloc */
- NULL, /* printfunc tp_print; */
- NULL, /* getattrfunc tp_getattr; */
- NULL, /* setattrfunc tp_setattr; */
- NULL, /* tp_compare */ /* DEPRECATED in python 3.0! */
- (reprfunc) bpy_bmesh_op_repr, /* tp_repr */
-
- /* Method suites for standard classes */
-
- NULL, /* PyNumberMethods *tp_as_number; */
- NULL, /* PySequenceMethods *tp_as_sequence; */
- NULL, /* PyMappingMethods *tp_as_mapping; */
-
- /* More standard operations (here for binary compatibility) */
-
- NULL, /* hashfunc tp_hash; */
- (ternaryfunc)BPy_BMO_call, /* ternaryfunc tp_call; */
- NULL, /* reprfunc tp_str; */
-
- /* will only use these if this is a subtype of a py class */
- NULL, /* getattrofunc tp_getattro; */
- NULL, /* setattrofunc tp_setattro; */
-
- /* Functions to access object as input/output buffer */
- NULL, /* PyBufferProcs *tp_as_buffer; */
-
- /*** Flags to define presence of optional/expanded features ***/
- Py_TPFLAGS_DEFAULT, /* long tp_flags; */
-
- NULL, /* char *tp_doc; Documentation string */
- /*** Assigned meaning in release 2.0 ***/
- /* call function for all accessible objects */
- NULL, /* traverseproc tp_traverse; */
-
- /* delete references to contained objects */
- NULL, /* inquiry tp_clear; */
-
- /*** Assigned meaning in release 2.1 ***/
- /*** rich comparisons ***/
- NULL, /* richcmpfunc tp_richcompare; */
-
- /*** weak reference enabler ***/
- 0,
- /*** Added in release 2.2 ***/
- /* Iterators */
- NULL, /* getiterfunc tp_iter; */
- NULL, /* iternextfunc tp_iternext; */
-
- /*** Attribute descriptor and subclassing stuff ***/
- NULL, /* struct PyMethodDef *tp_methods; */
- NULL, /* struct PyMemberDef *tp_members; */
- bpy_bmesh_op_getseters, /* struct PyGetSetDef *tp_getset; */
- NULL, /* struct _typeobject *tp_base; */
- NULL, /* PyObject *tp_dict; */
- NULL, /* descrgetfunc tp_descr_get; */
- NULL, /* descrsetfunc tp_descr_set; */
- 0, /* long tp_dictoffset; */
- NULL, /* initproc tp_init; */
- NULL, /* allocfunc tp_alloc; */
- NULL, /* newfunc tp_new; */
- /* Low-level free-memory routine */
- NULL, /* freefunc tp_free; */
- /* For PyObject_IS_GC */
- NULL, /* inquiry tp_is_gc; */
- NULL, /* PyObject *tp_bases; */
- /* method resolution order */
- NULL, /* PyObject *tp_mro; */
- NULL, /* PyObject *tp_cache; */
- NULL, /* PyObject *tp_subclasses; */
- NULL, /* PyObject *tp_weaklist; */
- NULL,
+ PyVarObject_HEAD_INIT(NULL, 0) "BMeshOpFunc", /* tp_name */
+ sizeof(BPy_BMeshOpFunc), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ /* methods */
+ NULL, /* tp_dealloc */
+ NULL, /* printfunc tp_print; */
+ NULL, /* getattrfunc tp_getattr; */
+ NULL, /* setattrfunc tp_setattr; */
+ NULL,
+ /* tp_compare */ /* DEPRECATED in python 3.0! */
+ (reprfunc)bpy_bmesh_op_repr, /* tp_repr */
+
+ /* Method suites for standard classes */
+
+ NULL, /* PyNumberMethods *tp_as_number; */
+ NULL, /* PySequenceMethods *tp_as_sequence; */
+ NULL, /* PyMappingMethods *tp_as_mapping; */
+
+ /* More standard operations (here for binary compatibility) */
+
+ NULL, /* hashfunc tp_hash; */
+ (ternaryfunc)BPy_BMO_call, /* ternaryfunc tp_call; */
+ NULL, /* reprfunc tp_str; */
+
+ /* will only use these if this is a subtype of a py class */
+ NULL, /* getattrofunc tp_getattro; */
+ NULL, /* setattrofunc tp_setattro; */
+
+ /* Functions to access object as input/output buffer */
+ NULL, /* PyBufferProcs *tp_as_buffer; */
+
+ /*** Flags to define presence of optional/expanded features ***/
+ Py_TPFLAGS_DEFAULT, /* long tp_flags; */
+
+ NULL, /* char *tp_doc; Documentation string */
+ /*** Assigned meaning in release 2.0 ***/
+ /* call function for all accessible objects */
+ NULL, /* traverseproc tp_traverse; */
+
+ /* delete references to contained objects */
+ NULL, /* inquiry tp_clear; */
+
+ /*** Assigned meaning in release 2.1 ***/
+ /*** rich comparisons ***/
+ NULL, /* richcmpfunc tp_richcompare; */
+
+ /*** weak reference enabler ***/
+ 0,
+ /*** Added in release 2.2 ***/
+ /* Iterators */
+ NULL, /* getiterfunc tp_iter; */
+ NULL, /* iternextfunc tp_iternext; */
+
+ /*** Attribute descriptor and subclassing stuff ***/
+ NULL, /* struct PyMethodDef *tp_methods; */
+ NULL, /* struct PyMemberDef *tp_members; */
+ bpy_bmesh_op_getseters, /* struct PyGetSetDef *tp_getset; */
+ NULL, /* struct _typeobject *tp_base; */
+ NULL, /* PyObject *tp_dict; */
+ NULL, /* descrgetfunc tp_descr_get; */
+ NULL, /* descrsetfunc tp_descr_set; */
+ 0, /* long tp_dictoffset; */
+ NULL, /* initproc tp_init; */
+ NULL, /* allocfunc tp_alloc; */
+ NULL, /* newfunc tp_new; */
+ /* Low-level free-memory routine */
+ NULL, /* freefunc tp_free; */
+ /* For PyObject_IS_GC */
+ NULL, /* inquiry tp_is_gc; */
+ NULL, /* PyObject *tp_bases; */
+ /* method resolution order */
+ NULL, /* PyObject *tp_mro; */
+ NULL, /* PyObject *tp_cache; */
+ NULL, /* PyObject *tp_subclasses; */
+ NULL, /* PyObject *tp_weaklist; */
+ NULL,
};
-
/* bmesh fake module 'bmesh.ops'
* ***************************** */
static PyObject *bpy_bmesh_ops_fakemod_getattro(PyObject *UNUSED(self), PyObject *pyname)
{
- const char *opname = _PyUnicode_AsString(pyname);
-
- if (BMO_opcode_from_opname(opname) != -1) {
- return bpy_bmesh_op_CreatePyObject(opname);
- }
- else {
- PyErr_Format(PyExc_AttributeError,
- "BMeshOpsModule: operator \"%.200s\" doesn't exist",
- opname);
- return NULL;
- }
+ const char *opname = _PyUnicode_AsString(pyname);
+
+ if (BMO_opcode_from_opname(opname) != -1) {
+ return bpy_bmesh_op_CreatePyObject(opname);
+ }
+ else {
+ PyErr_Format(
+ PyExc_AttributeError, "BMeshOpsModule: operator \"%.200s\" doesn't exist", opname);
+ return NULL;
+ }
}
static PyObject *bpy_bmesh_ops_fakemod_dir(PyObject *UNUSED(self))
{
- const unsigned int tot = bmo_opdefines_total;
- unsigned int i;
- PyObject *ret;
+ const unsigned int tot = bmo_opdefines_total;
+ unsigned int i;
+ PyObject *ret;
- ret = PyList_New(bmo_opdefines_total);
+ ret = PyList_New(bmo_opdefines_total);
- for (i = 0; i < tot; i++) {
- PyList_SET_ITEM(ret, i, PyUnicode_FromString(bmo_opdefines[i]->opname));
- }
+ for (i = 0; i < tot; i++) {
+ PyList_SET_ITEM(ret, i, PyUnicode_FromString(bmo_opdefines[i]->opname));
+ }
- return ret;
+ return ret;
}
static struct PyMethodDef bpy_bmesh_ops_fakemod_methods[] = {
- {"__dir__", (PyCFunction)bpy_bmesh_ops_fakemod_dir, METH_NOARGS, NULL},
- {NULL, NULL, 0, NULL},
+ {"__dir__", (PyCFunction)bpy_bmesh_ops_fakemod_dir, METH_NOARGS, NULL},
+ {NULL, NULL, 0, NULL},
};
static PyTypeObject bmesh_ops_fakemod_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BMeshOpsModule", /* tp_name */
- 0, /* tp_basicsize */
- 0, /* tp_itemsize */
- /* methods */
- NULL, /* tp_dealloc */
- NULL, /* printfunc tp_print; */
- NULL, /* getattrfunc tp_getattr; */
- NULL, /* setattrfunc tp_setattr; */
- NULL, /* tp_compare */ /* DEPRECATED in python 3.0! */
- NULL, /* tp_repr */
-
- /* Method suites for standard classes */
-
- NULL, /* PyNumberMethods *tp_as_number; */
- NULL, /* PySequenceMethods *tp_as_sequence; */
- NULL, /* PyMappingMethods *tp_as_mapping; */
-
- /* More standard operations (here for binary compatibility) */
-
- NULL, /* hashfunc tp_hash; */
- NULL, /* ternaryfunc tp_call; */
- NULL, /* reprfunc tp_str; */
-
- /* will only use these if this is a subtype of a py class */
- bpy_bmesh_ops_fakemod_getattro, /* getattrofunc tp_getattro; */
- NULL, /* setattrofunc tp_setattro; */
-
- /* Functions to access object as input/output buffer */
- NULL, /* PyBufferProcs *tp_as_buffer; */
-
- /*** Flags to define presence of optional/expanded features ***/
- Py_TPFLAGS_DEFAULT, /* long tp_flags; */
-
- NULL, /* char *tp_doc; Documentation string */
- /*** Assigned meaning in release 2.0 ***/
- /* call function for all accessible objects */
- NULL, /* traverseproc tp_traverse; */
-
- /* delete references to contained objects */
- NULL, /* inquiry tp_clear; */
-
- /*** Assigned meaning in release 2.1 ***/
- /*** rich comparisons (subclassed) ***/
- NULL, /* richcmpfunc tp_richcompare; */
-
- /*** weak reference enabler ***/
- 0,
- /*** Added in release 2.2 ***/
- /* Iterators */
- NULL, /* getiterfunc tp_iter; */
- NULL, /* iternextfunc tp_iternext; */
-
- /*** Attribute descriptor and subclassing stuff ***/
- bpy_bmesh_ops_fakemod_methods, /* struct PyMethodDef *tp_methods; */
- NULL, /* struct PyMemberDef *tp_members; */
- NULL, /* struct PyGetSetDef *tp_getset; */
- NULL, /* struct _typeobject *tp_base; */
- NULL, /* PyObject *tp_dict; */
- NULL, /* descrgetfunc tp_descr_get; */
- NULL, /* descrsetfunc tp_descr_set; */
- 0, /* long tp_dictoffset; */
- NULL, /* initproc tp_init; */
- NULL, /* allocfunc tp_alloc; */
- NULL, /* newfunc tp_new; */
- /* Low-level free-memory routine */
- NULL, /* freefunc tp_free; */
- /* For PyObject_IS_GC */
- NULL, /* inquiry tp_is_gc; */
- NULL, /* PyObject *tp_bases; */
- /* method resolution order */
- NULL, /* PyObject *tp_mro; */
- NULL, /* PyObject *tp_cache; */
- NULL, /* PyObject *tp_subclasses; */
- NULL, /* PyObject *tp_weaklist; */
- NULL,
+ PyVarObject_HEAD_INIT(NULL, 0) "BMeshOpsModule", /* tp_name */
+ 0, /* tp_basicsize */
+ 0, /* tp_itemsize */
+ /* methods */
+ NULL, /* tp_dealloc */
+ NULL, /* printfunc tp_print; */
+ NULL, /* getattrfunc tp_getattr; */
+ NULL, /* setattrfunc tp_setattr; */
+ NULL,
+ /* tp_compare */ /* DEPRECATED in python 3.0! */
+ NULL, /* tp_repr */
+
+ /* Method suites for standard classes */
+
+ NULL, /* PyNumberMethods *tp_as_number; */
+ NULL, /* PySequenceMethods *tp_as_sequence; */
+ NULL, /* PyMappingMethods *tp_as_mapping; */
+
+ /* More standard operations (here for binary compatibility) */
+
+ NULL, /* hashfunc tp_hash; */
+ NULL, /* ternaryfunc tp_call; */
+ NULL, /* reprfunc tp_str; */
+
+ /* will only use these if this is a subtype of a py class */
+ bpy_bmesh_ops_fakemod_getattro, /* getattrofunc tp_getattro; */
+ NULL, /* setattrofunc tp_setattro; */
+
+ /* Functions to access object as input/output buffer */
+ NULL, /* PyBufferProcs *tp_as_buffer; */
+
+ /*** Flags to define presence of optional/expanded features ***/
+ Py_TPFLAGS_DEFAULT, /* long tp_flags; */
+
+ NULL, /* char *tp_doc; Documentation string */
+ /*** Assigned meaning in release 2.0 ***/
+ /* call function for all accessible objects */
+ NULL, /* traverseproc tp_traverse; */
+
+ /* delete references to contained objects */
+ NULL, /* inquiry tp_clear; */
+
+ /*** Assigned meaning in release 2.1 ***/
+ /*** rich comparisons (subclassed) ***/
+ NULL, /* richcmpfunc tp_richcompare; */
+
+ /*** weak reference enabler ***/
+ 0,
+ /*** Added in release 2.2 ***/
+ /* Iterators */
+ NULL, /* getiterfunc tp_iter; */
+ NULL, /* iternextfunc tp_iternext; */
+
+ /*** Attribute descriptor and subclassing stuff ***/
+ bpy_bmesh_ops_fakemod_methods, /* struct PyMethodDef *tp_methods; */
+ NULL, /* struct PyMemberDef *tp_members; */
+ NULL, /* struct PyGetSetDef *tp_getset; */
+ NULL, /* struct _typeobject *tp_base; */
+ NULL, /* PyObject *tp_dict; */
+ NULL, /* descrgetfunc tp_descr_get; */
+ NULL, /* descrsetfunc tp_descr_set; */
+ 0, /* long tp_dictoffset; */
+ NULL, /* initproc tp_init; */
+ NULL, /* allocfunc tp_alloc; */
+ NULL, /* newfunc tp_new; */
+ /* Low-level free-memory routine */
+ NULL, /* freefunc tp_free; */
+ /* For PyObject_IS_GC */
+ NULL, /* inquiry tp_is_gc; */
+ NULL, /* PyObject *tp_bases; */
+ /* method resolution order */
+ NULL, /* PyObject *tp_mro; */
+ NULL, /* PyObject *tp_cache; */
+ NULL, /* PyObject *tp_subclasses; */
+ NULL, /* PyObject *tp_weaklist; */
+ NULL,
};
PyObject *BPyInit_bmesh_ops(void)
{
- PyObject *submodule;
+ PyObject *submodule;
- if (PyType_Ready(&bmesh_ops_fakemod_Type) < 0) {
- return NULL;
- }
+ if (PyType_Ready(&bmesh_ops_fakemod_Type) < 0) {
+ return NULL;
+ }
- if (PyType_Ready(&bmesh_op_Type) < 0) {
- return NULL;
- }
+ if (PyType_Ready(&bmesh_op_Type) < 0) {
+ return NULL;
+ }
- submodule = PyObject_New(PyObject, &bmesh_ops_fakemod_Type);
+ submodule = PyObject_New(PyObject, &bmesh_ops_fakemod_Type);
- /* prevent further creation of instances */
- bmesh_ops_fakemod_Type.tp_init = NULL;
- bmesh_ops_fakemod_Type.tp_new = NULL;
+ /* prevent further creation of instances */
+ bmesh_ops_fakemod_Type.tp_init = NULL;
+ bmesh_ops_fakemod_Type.tp_new = NULL;
- return submodule;
+ return submodule;
}
diff --git a/source/blender/python/bmesh/bmesh_py_ops_call.c b/source/blender/python/bmesh/bmesh_py_ops_call.c
index b9d506c4c41..401dded5188 100644
--- a/source/blender/python/bmesh/bmesh_py_ops_call.c
+++ b/source/blender/python/bmesh/bmesh_py_ops_call.c
@@ -33,7 +33,7 @@
#include "bmesh.h"
-#include "bmesh_py_ops_call.h" /* own include */
+#include "bmesh_py_ops_call.h" /* own include */
#include "bmesh_py_types.h"
@@ -44,18 +44,16 @@ BLI_STATIC_ASSERT(sizeof(PyC_FlagSet) == sizeof(BMO_FlagSet), "size mismatch");
static int bpy_bm_op_as_py_error(BMesh *bm)
{
- if (BMO_error_occurred(bm)) {
- /* note: we could have multiple errors */
- const char *errmsg;
- if (BMO_error_get(bm, &errmsg, NULL)) {
- PyErr_Format(PyExc_RuntimeError,
- "bmesh operator: %.200s",
- errmsg);
- BMO_error_clear(bm);
- return -1;
- }
- }
- return 0;
+ if (BMO_error_occurred(bm)) {
+ /* note: we could have multiple errors */
+ const char *errmsg;
+ if (BMO_error_get(bm, &errmsg, NULL)) {
+ PyErr_Format(PyExc_RuntimeError, "bmesh operator: %.200s", errmsg);
+ BMO_error_clear(bm);
+ return -1;
+ }
+ }
+ return 0;
}
/**
@@ -66,34 +64,41 @@ static int bpy_bm_op_as_py_error(BMesh *bm)
* \param htype: Test \a value matches this type.
* \param descr: Description text.
*/
-static int bpy_slot_from_py_elem_check(
- BPy_BMElem *value, BMesh *bm, const char htype,
- /* for error messages */
- const char *opname, const char *slot_name, const char *descr)
+static int bpy_slot_from_py_elem_check(BPy_BMElem *value,
+ BMesh *bm,
+ const char htype,
+ /* for error messages */
+ const char *opname,
+ const char *slot_name,
+ const char *descr)
{
- if (!BPy_BMElem_Check(value) ||
- !(value->ele->head.htype & htype))
- {
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" %.200s, expected a %.200s not *.200s",
- opname, slot_name, descr,
- BPy_BMElem_StringFromHType(htype),
- Py_TYPE(value)->tp_name);
- return -1;
- }
- else if (value->bm == NULL) {
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" %.200s invalidated element",
- opname, slot_name, descr);
- return -1;
- }
- else if (value->bm != bm) { /* we may want to make this check optional by setting 'bm' to NULL */
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" %.200s invalidated element",
- opname, slot_name, descr);
- return -1;
- }
- return 0;
+ if (!BPy_BMElem_Check(value) || !(value->ele->head.htype & htype)) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" %.200s, expected a %.200s not *.200s",
+ opname,
+ slot_name,
+ descr,
+ BPy_BMElem_StringFromHType(htype),
+ Py_TYPE(value)->tp_name);
+ return -1;
+ }
+ else if (value->bm == NULL) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" %.200s invalidated element",
+ opname,
+ slot_name,
+ descr);
+ return -1;
+ }
+ else if (value->bm != bm) { /* we may want to make this check optional by setting 'bm' to NULL */
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" %.200s invalidated element",
+ opname,
+ slot_name,
+ descr);
+ return -1;
+ }
+ return 0;
}
/**
@@ -105,434 +110,493 @@ static int bpy_slot_from_py_elem_check(
* \param htype_bmo: The type(s) supported by the target slot.
* \param descr: Description text.
*/
-static int bpy_slot_from_py_elemseq_check(
- BPy_BMGeneric *value, BMesh *bm,
- const char htype_py, const char htype_bmo,
- /* for error messages */
- const char *opname, const char *slot_name, const char *descr)
+static int bpy_slot_from_py_elemseq_check(BPy_BMGeneric *value,
+ BMesh *bm,
+ const char htype_py,
+ const char htype_bmo,
+ /* for error messages */
+ const char *opname,
+ const char *slot_name,
+ const char *descr)
{
- if (value->bm == NULL) {
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" %.200s, invalidated sequence",
- opname, slot_name, descr);
- return -1;
- }
- else if (value->bm != bm) { /* we may want to make this check optional by setting 'bm' to NULL */
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" %.200s, invalidated sequence",
- opname, slot_name, descr);
- return -1;
- }
- else if ((htype_py & htype_bmo) == 0) {
- char str_bmo[32];
- char str_py[32];
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" %.200s, expected "
- "a sequence of %.200s not %.200s",
- opname, slot_name, descr,
- BPy_BMElem_StringFromHType_ex(htype_bmo, str_bmo),
- BPy_BMElem_StringFromHType_ex(htype_py, str_py));
- return -1;
- }
-
- return 0;
+ if (value->bm == NULL) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" %.200s, invalidated sequence",
+ opname,
+ slot_name,
+ descr);
+ return -1;
+ }
+ else if (value->bm != bm) { /* we may want to make this check optional by setting 'bm' to NULL */
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" %.200s, invalidated sequence",
+ opname,
+ slot_name,
+ descr);
+ return -1;
+ }
+ else if ((htype_py & htype_bmo) == 0) {
+ char str_bmo[32];
+ char str_py[32];
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" %.200s, expected "
+ "a sequence of %.200s not %.200s",
+ opname,
+ slot_name,
+ descr,
+ BPy_BMElem_StringFromHType_ex(htype_bmo, str_bmo),
+ BPy_BMElem_StringFromHType_ex(htype_py, str_py));
+ return -1;
+ }
+
+ return 0;
}
/**
* Use for giving py args to an operator.
*/
-static int bpy_slot_from_py(
- BMesh *bm, BMOperator *bmop, BMOpSlot *slot, PyObject *value,
- /* the are just for exception messages */
- const char *opname, const char *slot_name)
+static int bpy_slot_from_py(BMesh *bm,
+ BMOperator *bmop,
+ BMOpSlot *slot,
+ PyObject *value,
+ /* the are just for exception messages */
+ const char *opname,
+ const char *slot_name)
{
- switch (slot->slot_type) {
- case BMO_OP_SLOT_BOOL:
- {
- const int param = PyC_Long_AsBool(value);
-
- if (param == -1) {
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" expected True/False or 0/1, not %.200s",
- opname, slot_name, Py_TYPE(value)->tp_name);
- return -1;
- }
- else {
- BMO_SLOT_AS_BOOL(slot) = param;
- }
-
- break;
- }
- case BMO_OP_SLOT_INT:
- {
- if (slot->slot_subtype.intg == BMO_OP_SLOT_SUBTYPE_INT_ENUM) {
- int enum_val = -1;
- PyC_FlagSet *items = (PyC_FlagSet *)slot->data.enum_data.flags;
- const char *enum_str = _PyUnicode_AsString(value);
-
- if (enum_str == NULL) {
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" expected a string, not %.200s",
- opname, slot_name, Py_TYPE(value)->tp_name);
- return -1;
- }
-
- if (PyC_FlagSet_ValueFromID(items, enum_str, &enum_val, slot_name) == -1) {
- return -1;
- }
-
- BMO_SLOT_AS_INT(slot) = enum_val;
- }
- else if (slot->slot_subtype.intg == BMO_OP_SLOT_SUBTYPE_INT_FLAG) {
- int flag = 0;
- PyC_FlagSet *items = (PyC_FlagSet *)slot->data.enum_data.flags;
-
- if (PyC_FlagSet_ToBitfield(items, value, &flag, slot_name) == -1) {
- return -1;
- }
-
- BMO_SLOT_AS_INT(slot) = flag;
- }
- else {
- const int param = PyC_Long_AsI32(value);
-
- if (param == -1 && PyErr_Occurred()) {
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" expected an int, not %.200s",
- opname, slot_name, Py_TYPE(value)->tp_name);
- return -1;
- }
- else {
- BMO_SLOT_AS_INT(slot) = param;
- }
- }
- break;
- }
- case BMO_OP_SLOT_FLT:
- {
- float param = PyFloat_AsDouble(value);
- if (param == -1 && PyErr_Occurred()) {
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" expected a float, not %.200s",
- opname, slot_name, Py_TYPE(value)->tp_name);
- return -1;
- }
- else {
- BMO_SLOT_AS_FLOAT(slot) = param;
- }
- break;
- }
- case BMO_OP_SLOT_MAT:
- {
- /* XXX - BMesh operator design is crappy here, operator slot should define matrix size,
- * not the caller! */
- MatrixObject *pymat;
- if (!Matrix_ParseAny(value, &pymat)) {
- return -1;
- }
- const ushort size = pymat->num_col;
- if ((size != pymat->num_row) || (!ELEM(size, 3, 4))) {
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" expected a 3x3 or 4x4 matrix Matrix",
- opname, slot_name);
- return -1;
- }
-
- BMO_slot_mat_set(bmop, bmop->slots_in, slot_name, pymat->matrix, size);
- break;
- }
- case BMO_OP_SLOT_VEC:
- {
- /* passing slot name here is a bit non-descriptive */
- if (mathutils_array_parse(BMO_SLOT_AS_VECTOR(slot), 3, 3, value, slot_name) == -1) {
- return -1;
- }
- break;
- }
- case BMO_OP_SLOT_ELEMENT_BUF:
- {
- if (slot->slot_subtype.elem & BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE) {
- if (bpy_slot_from_py_elem_check((BPy_BMElem *)value, bm, (slot->slot_subtype.elem & BM_ALL_NOLOOP),
- opname, slot_name, "single element") == -1)
- {
- return -1; /* error is set in bpy_slot_from_py_elem_check() */
- }
-
- BMO_slot_buffer_from_single(bmop, slot, &((BPy_BMElem *)value)->ele->head);
- }
- else {
- /* there are many ways we could interpret arguments, for now...
- * - verts/edges/faces from the mesh direct,
- * this way the operator takes every item.
- * - `TODO` a plain python sequence (list) of elements.
- * - `TODO` an iterator. eg.
- * face.verts
- * - `TODO` (type, flag) pair, eg.
- * ('VERT', {'TAG'})
- */
-
- if (BPy_BMVertSeq_Check(value)) {
- if (bpy_slot_from_py_elemseq_check((BPy_BMGeneric *)value, bm,
- BM_VERT, (slot->slot_subtype.elem & BM_ALL_NOLOOP),
- opname, slot_name, "element buffer") == -1)
- {
- return -1; /* error is set in bpy_slot_from_py_elem_check() */
- }
-
- BMO_slot_buffer_from_all(bm, bmop, bmop->slots_in, slot_name, BM_VERT);
- }
- else if (BPy_BMEdgeSeq_Check(value)) {
- if (bpy_slot_from_py_elemseq_check((BPy_BMGeneric *)value, bm,
- BM_EDGE, (slot->slot_subtype.elem & BM_ALL_NOLOOP),
- opname, slot_name, "element buffer") == -1)
- {
- return -1; /* error is set in bpy_slot_from_py_elem_check() */
- }
-
- BMO_slot_buffer_from_all(bm, bmop, bmop->slots_in, slot_name, BM_EDGE);
- }
- else if (BPy_BMFaceSeq_Check(value)) {
- if (bpy_slot_from_py_elemseq_check((BPy_BMGeneric *)value, bm,
- BM_FACE, (slot->slot_subtype.elem & BM_ALL_NOLOOP),
- opname, slot_name, "element buffer") == -1)
- {
- return -1; /* error is set in bpy_slot_from_py_elem_check() */
- }
- BMO_slot_buffer_from_all(bm, bmop, bmop->slots_in, slot_name, BM_FACE);
- }
-
- else if (BPy_BMElemSeq_Check(value)) {
- BMIter iter;
- BMHeader *ele;
- int tot;
- unsigned int i;
-
- if (bpy_slot_from_py_elemseq_check((BPy_BMGeneric *)value, bm,
- bm_iter_itype_htype_map[((BPy_BMElemSeq *)value)->itype],
- (slot->slot_subtype.elem & BM_ALL_NOLOOP),
- opname, slot_name, "element buffer") == -1)
- {
- return -1; /* error is set in bpy_slot_from_py_elem_check() */
- }
-
- /* this will loop over all elements which is a shame but
- * we need to know this before alloc */
- /* calls bpy_bmelemseq_length() */
- tot = Py_TYPE(value)->tp_as_sequence->sq_length(value);
-
- BMO_slot_buffer_alloc(bmop, bmop->slots_in, slot_name, tot);
-
- i = 0;
- BM_ITER_BPY_BM_SEQ (ele, &iter, ((BPy_BMElemSeq *)value)) {
- slot->data.buf[i] = ele;
- i++;
- }
- }
- /* keep this last */
- else if (PySequence_Check(value)) {
- BMElem **elem_array = NULL;
- Py_ssize_t elem_array_len;
-
- elem_array = BPy_BMElem_PySeq_As_Array(&bm, value, 0, PY_SSIZE_T_MAX,
- &elem_array_len, (slot->slot_subtype.elem & BM_ALL_NOLOOP),
- true, true, slot_name);
-
- /* error is set above */
- if (elem_array == NULL) {
- return -1;
- }
-
- BMO_slot_buffer_alloc(bmop, bmop->slots_in, slot_name, elem_array_len);
- memcpy(slot->data.buf, elem_array, sizeof(void *) * elem_array_len);
- PyMem_FREE(elem_array);
- }
- else {
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" expected "
- "a bmesh sequence, list, (htype, flag) pair, not %.200s",
- opname, slot_name, Py_TYPE(value)->tp_name);
- return -1;
- }
- }
- break;
- }
- case BMO_OP_SLOT_MAPPING:
- {
- /* first check types */
- if (slot->slot_subtype.map != BMO_OP_SLOT_SUBTYPE_MAP_EMPTY) {
- if (!PyDict_Check(value)) {
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" expected "
- "a dict, not %.200s",
- opname, slot_name, Py_TYPE(value)->tp_name);
- return -1;
- }
- }
- else {
- if (!PySet_Check(value)) {
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" expected "
- "a set, not %.200s",
- opname, slot_name, Py_TYPE(value)->tp_name);
- return -1;
- }
- }
-
- switch (slot->slot_subtype.map) {
- case BMO_OP_SLOT_SUBTYPE_MAP_ELEM:
- {
- if (PyDict_Size(value) > 0) {
- PyObject *arg_key, *arg_value;
- Py_ssize_t arg_pos = 0;
- while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
- if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key, bm, BM_ALL_NOLOOP,
- opname, slot_name, "invalid key in dict") == -1)
- {
- return -1; /* error is set in bpy_slot_from_py_elem_check() */
- }
-
- if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_value, bm, BM_ALL_NOLOOP,
- opname, slot_name, "invalid value in dict") == -1)
- {
- return -1; /* error is set in bpy_slot_from_py_elem_check() */
- }
-
- BMO_slot_map_elem_insert(bmop, slot,
- ((BPy_BMElem *)arg_key)->ele, ((BPy_BMElem *)arg_value)->ele);
- }
- }
- break;
- }
- case BMO_OP_SLOT_SUBTYPE_MAP_FLT:
- {
- if (PyDict_Size(value) > 0) {
- PyObject *arg_key, *arg_value;
- Py_ssize_t arg_pos = 0;
- while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
- float value_f;
-
- if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key, bm, BM_ALL_NOLOOP,
- opname, slot_name, "invalid key in dict") == -1)
- {
- return -1; /* error is set in bpy_slot_from_py_elem_check() */
- }
-
- value_f = PyFloat_AsDouble(arg_value);
-
- if (value_f == -1.0f && PyErr_Occurred()) {
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" expected "
- "a dict with float values, not %.200s",
- opname, slot_name, Py_TYPE(arg_value)->tp_name);
- return -1;
- }
-
- BMO_slot_map_float_insert(bmop, slot,
- ((BPy_BMElem *)arg_key)->ele, value_f);
- }
- }
- break;
- }
- case BMO_OP_SLOT_SUBTYPE_MAP_INT:
- {
- if (PyDict_Size(value) > 0) {
- PyObject *arg_key, *arg_value;
- Py_ssize_t arg_pos = 0;
- while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
- int value_i;
-
- if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key, bm, BM_ALL_NOLOOP,
- opname, slot_name, "invalid key in dict") == -1)
- {
- return -1; /* error is set in bpy_slot_from_py_elem_check() */
- }
-
- value_i = PyC_Long_AsI32(arg_value);
-
- if (value_i == -1 && PyErr_Occurred()) {
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" expected "
- "a dict with int values, not %.200s",
- opname, slot_name, Py_TYPE(arg_value)->tp_name);
- return -1;
- }
-
- BMO_slot_map_int_insert(bmop, slot,
- ((BPy_BMElem *)arg_key)->ele, value_i);
- }
- }
- break;
- }
- case BMO_OP_SLOT_SUBTYPE_MAP_BOOL:
- {
- if (PyDict_Size(value) > 0) {
- PyObject *arg_key, *arg_value;
- Py_ssize_t arg_pos = 0;
- while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
- int value_i;
-
- if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key, bm, BM_ALL_NOLOOP,
- opname, slot_name, "invalid key in dict") == -1)
- {
- return -1; /* error is set in bpy_slot_from_py_elem_check() */
- }
-
- value_i = PyC_Long_AsI32(arg_value);
-
- if (value_i == -1 && PyErr_Occurred()) {
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" expected "
- "a dict with bool values, not %.200s",
- opname, slot_name, Py_TYPE(arg_value)->tp_name);
- return -1;
- }
-
- BMO_slot_map_bool_insert(bmop, slot,
- ((BPy_BMElem *)arg_key)->ele, value_i != 0);
- }
- }
- break;
- }
- case BMO_OP_SLOT_SUBTYPE_MAP_EMPTY:
- {
- if (PySet_Size(value) > 0) {
- PyObject *arg_key;
- Py_ssize_t arg_pos = 0;
- Py_ssize_t arg_hash = 0;
- while (_PySet_NextEntry(value, &arg_pos, &arg_key, &arg_hash)) {
-
- if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key, bm, BM_ALL_NOLOOP,
- opname, slot_name, "invalid key in set") == -1)
- {
- return -1; /* error is set in bpy_slot_from_py_elem_check() */
- }
-
- BMO_slot_map_empty_insert(bmop, slot,
- ((BPy_BMElem *)arg_key)->ele);
- }
- }
- break;
- }
- case BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL:
- {
- /* can't convert from these */
- PyErr_Format(PyExc_NotImplementedError,
- "This arguments mapping subtype %d is not supported", slot->slot_subtype.map);
- return -1;
- }
- }
- break;
- }
- default:
- /* TODO --- many others */
- PyErr_Format(PyExc_NotImplementedError,
- "%.200s: keyword \"%.200s\" type %d not working yet!",
- opname, slot_name, slot->slot_type);
- return -1;
- }
-
- /* all is well */
- return 0;
+ switch (slot->slot_type) {
+ case BMO_OP_SLOT_BOOL: {
+ const int param = PyC_Long_AsBool(value);
+
+ if (param == -1) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected True/False or 0/1, not %.200s",
+ opname,
+ slot_name,
+ Py_TYPE(value)->tp_name);
+ return -1;
+ }
+ else {
+ BMO_SLOT_AS_BOOL(slot) = param;
+ }
+
+ break;
+ }
+ case BMO_OP_SLOT_INT: {
+ if (slot->slot_subtype.intg == BMO_OP_SLOT_SUBTYPE_INT_ENUM) {
+ int enum_val = -1;
+ PyC_FlagSet *items = (PyC_FlagSet *)slot->data.enum_data.flags;
+ const char *enum_str = _PyUnicode_AsString(value);
+
+ if (enum_str == NULL) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected a string, not %.200s",
+ opname,
+ slot_name,
+ Py_TYPE(value)->tp_name);
+ return -1;
+ }
+
+ if (PyC_FlagSet_ValueFromID(items, enum_str, &enum_val, slot_name) == -1) {
+ return -1;
+ }
+
+ BMO_SLOT_AS_INT(slot) = enum_val;
+ }
+ else if (slot->slot_subtype.intg == BMO_OP_SLOT_SUBTYPE_INT_FLAG) {
+ int flag = 0;
+ PyC_FlagSet *items = (PyC_FlagSet *)slot->data.enum_data.flags;
+
+ if (PyC_FlagSet_ToBitfield(items, value, &flag, slot_name) == -1) {
+ return -1;
+ }
+
+ BMO_SLOT_AS_INT(slot) = flag;
+ }
+ else {
+ const int param = PyC_Long_AsI32(value);
+
+ if (param == -1 && PyErr_Occurred()) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected an int, not %.200s",
+ opname,
+ slot_name,
+ Py_TYPE(value)->tp_name);
+ return -1;
+ }
+ else {
+ BMO_SLOT_AS_INT(slot) = param;
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_FLT: {
+ float param = PyFloat_AsDouble(value);
+ if (param == -1 && PyErr_Occurred()) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected a float, not %.200s",
+ opname,
+ slot_name,
+ Py_TYPE(value)->tp_name);
+ return -1;
+ }
+ else {
+ BMO_SLOT_AS_FLOAT(slot) = param;
+ }
+ break;
+ }
+ case BMO_OP_SLOT_MAT: {
+ /* XXX - BMesh operator design is crappy here, operator slot should define matrix size,
+ * not the caller! */
+ MatrixObject *pymat;
+ if (!Matrix_ParseAny(value, &pymat)) {
+ return -1;
+ }
+ const ushort size = pymat->num_col;
+ if ((size != pymat->num_row) || (!ELEM(size, 3, 4))) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected a 3x3 or 4x4 matrix Matrix",
+ opname,
+ slot_name);
+ return -1;
+ }
+
+ BMO_slot_mat_set(bmop, bmop->slots_in, slot_name, pymat->matrix, size);
+ break;
+ }
+ case BMO_OP_SLOT_VEC: {
+ /* passing slot name here is a bit non-descriptive */
+ if (mathutils_array_parse(BMO_SLOT_AS_VECTOR(slot), 3, 3, value, slot_name) == -1) {
+ return -1;
+ }
+ break;
+ }
+ case BMO_OP_SLOT_ELEMENT_BUF: {
+ if (slot->slot_subtype.elem & BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE) {
+ if (bpy_slot_from_py_elem_check((BPy_BMElem *)value,
+ bm,
+ (slot->slot_subtype.elem & BM_ALL_NOLOOP),
+ opname,
+ slot_name,
+ "single element") == -1) {
+ return -1; /* error is set in bpy_slot_from_py_elem_check() */
+ }
+
+ BMO_slot_buffer_from_single(bmop, slot, &((BPy_BMElem *)value)->ele->head);
+ }
+ else {
+ /* there are many ways we could interpret arguments, for now...
+ * - verts/edges/faces from the mesh direct,
+ * this way the operator takes every item.
+ * - `TODO` a plain python sequence (list) of elements.
+ * - `TODO` an iterator. eg.
+ * face.verts
+ * - `TODO` (type, flag) pair, eg.
+ * ('VERT', {'TAG'})
+ */
+
+ if (BPy_BMVertSeq_Check(value)) {
+ if (bpy_slot_from_py_elemseq_check((BPy_BMGeneric *)value,
+ bm,
+ BM_VERT,
+ (slot->slot_subtype.elem & BM_ALL_NOLOOP),
+ opname,
+ slot_name,
+ "element buffer") == -1) {
+ return -1; /* error is set in bpy_slot_from_py_elem_check() */
+ }
+
+ BMO_slot_buffer_from_all(bm, bmop, bmop->slots_in, slot_name, BM_VERT);
+ }
+ else if (BPy_BMEdgeSeq_Check(value)) {
+ if (bpy_slot_from_py_elemseq_check((BPy_BMGeneric *)value,
+ bm,
+ BM_EDGE,
+ (slot->slot_subtype.elem & BM_ALL_NOLOOP),
+ opname,
+ slot_name,
+ "element buffer") == -1) {
+ return -1; /* error is set in bpy_slot_from_py_elem_check() */
+ }
+
+ BMO_slot_buffer_from_all(bm, bmop, bmop->slots_in, slot_name, BM_EDGE);
+ }
+ else if (BPy_BMFaceSeq_Check(value)) {
+ if (bpy_slot_from_py_elemseq_check((BPy_BMGeneric *)value,
+ bm,
+ BM_FACE,
+ (slot->slot_subtype.elem & BM_ALL_NOLOOP),
+ opname,
+ slot_name,
+ "element buffer") == -1) {
+ return -1; /* error is set in bpy_slot_from_py_elem_check() */
+ }
+ BMO_slot_buffer_from_all(bm, bmop, bmop->slots_in, slot_name, BM_FACE);
+ }
+
+ else if (BPy_BMElemSeq_Check(value)) {
+ BMIter iter;
+ BMHeader *ele;
+ int tot;
+ unsigned int i;
+
+ if (bpy_slot_from_py_elemseq_check(
+ (BPy_BMGeneric *)value,
+ bm,
+ bm_iter_itype_htype_map[((BPy_BMElemSeq *)value)->itype],
+ (slot->slot_subtype.elem & BM_ALL_NOLOOP),
+ opname,
+ slot_name,
+ "element buffer") == -1) {
+ return -1; /* error is set in bpy_slot_from_py_elem_check() */
+ }
+
+ /* this will loop over all elements which is a shame but
+ * we need to know this before alloc */
+ /* calls bpy_bmelemseq_length() */
+ tot = Py_TYPE(value)->tp_as_sequence->sq_length(value);
+
+ BMO_slot_buffer_alloc(bmop, bmop->slots_in, slot_name, tot);
+
+ i = 0;
+ BM_ITER_BPY_BM_SEQ(ele, &iter, ((BPy_BMElemSeq *)value))
+ {
+ slot->data.buf[i] = ele;
+ i++;
+ }
+ }
+ /* keep this last */
+ else if (PySequence_Check(value)) {
+ BMElem **elem_array = NULL;
+ Py_ssize_t elem_array_len;
+
+ elem_array = BPy_BMElem_PySeq_As_Array(&bm,
+ value,
+ 0,
+ PY_SSIZE_T_MAX,
+ &elem_array_len,
+ (slot->slot_subtype.elem & BM_ALL_NOLOOP),
+ true,
+ true,
+ slot_name);
+
+ /* error is set above */
+ if (elem_array == NULL) {
+ return -1;
+ }
+
+ BMO_slot_buffer_alloc(bmop, bmop->slots_in, slot_name, elem_array_len);
+ memcpy(slot->data.buf, elem_array, sizeof(void *) * elem_array_len);
+ PyMem_FREE(elem_array);
+ }
+ else {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected "
+ "a bmesh sequence, list, (htype, flag) pair, not %.200s",
+ opname,
+ slot_name,
+ Py_TYPE(value)->tp_name);
+ return -1;
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_MAPPING: {
+ /* first check types */
+ if (slot->slot_subtype.map != BMO_OP_SLOT_SUBTYPE_MAP_EMPTY) {
+ if (!PyDict_Check(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected "
+ "a dict, not %.200s",
+ opname,
+ slot_name,
+ Py_TYPE(value)->tp_name);
+ return -1;
+ }
+ }
+ else {
+ if (!PySet_Check(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected "
+ "a set, not %.200s",
+ opname,
+ slot_name,
+ Py_TYPE(value)->tp_name);
+ return -1;
+ }
+ }
+
+ switch (slot->slot_subtype.map) {
+ case BMO_OP_SLOT_SUBTYPE_MAP_ELEM: {
+ if (PyDict_Size(value) > 0) {
+ PyObject *arg_key, *arg_value;
+ Py_ssize_t arg_pos = 0;
+ while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
+ if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key,
+ bm,
+ BM_ALL_NOLOOP,
+ opname,
+ slot_name,
+ "invalid key in dict") == -1) {
+ return -1; /* error is set in bpy_slot_from_py_elem_check() */
+ }
+
+ if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_value,
+ bm,
+ BM_ALL_NOLOOP,
+ opname,
+ slot_name,
+ "invalid value in dict") == -1) {
+ return -1; /* error is set in bpy_slot_from_py_elem_check() */
+ }
+
+ BMO_slot_map_elem_insert(
+ bmop, slot, ((BPy_BMElem *)arg_key)->ele, ((BPy_BMElem *)arg_value)->ele);
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_SUBTYPE_MAP_FLT: {
+ if (PyDict_Size(value) > 0) {
+ PyObject *arg_key, *arg_value;
+ Py_ssize_t arg_pos = 0;
+ while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
+ float value_f;
+
+ if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key,
+ bm,
+ BM_ALL_NOLOOP,
+ opname,
+ slot_name,
+ "invalid key in dict") == -1) {
+ return -1; /* error is set in bpy_slot_from_py_elem_check() */
+ }
+
+ value_f = PyFloat_AsDouble(arg_value);
+
+ if (value_f == -1.0f && PyErr_Occurred()) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected "
+ "a dict with float values, not %.200s",
+ opname,
+ slot_name,
+ Py_TYPE(arg_value)->tp_name);
+ return -1;
+ }
+
+ BMO_slot_map_float_insert(bmop, slot, ((BPy_BMElem *)arg_key)->ele, value_f);
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_SUBTYPE_MAP_INT: {
+ if (PyDict_Size(value) > 0) {
+ PyObject *arg_key, *arg_value;
+ Py_ssize_t arg_pos = 0;
+ while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
+ int value_i;
+
+ if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key,
+ bm,
+ BM_ALL_NOLOOP,
+ opname,
+ slot_name,
+ "invalid key in dict") == -1) {
+ return -1; /* error is set in bpy_slot_from_py_elem_check() */
+ }
+
+ value_i = PyC_Long_AsI32(arg_value);
+
+ if (value_i == -1 && PyErr_Occurred()) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected "
+ "a dict with int values, not %.200s",
+ opname,
+ slot_name,
+ Py_TYPE(arg_value)->tp_name);
+ return -1;
+ }
+
+ BMO_slot_map_int_insert(bmop, slot, ((BPy_BMElem *)arg_key)->ele, value_i);
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_SUBTYPE_MAP_BOOL: {
+ if (PyDict_Size(value) > 0) {
+ PyObject *arg_key, *arg_value;
+ Py_ssize_t arg_pos = 0;
+ while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
+ int value_i;
+
+ if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key,
+ bm,
+ BM_ALL_NOLOOP,
+ opname,
+ slot_name,
+ "invalid key in dict") == -1) {
+ return -1; /* error is set in bpy_slot_from_py_elem_check() */
+ }
+
+ value_i = PyC_Long_AsI32(arg_value);
+
+ if (value_i == -1 && PyErr_Occurred()) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected "
+ "a dict with bool values, not %.200s",
+ opname,
+ slot_name,
+ Py_TYPE(arg_value)->tp_name);
+ return -1;
+ }
+
+ BMO_slot_map_bool_insert(bmop, slot, ((BPy_BMElem *)arg_key)->ele, value_i != 0);
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_SUBTYPE_MAP_EMPTY: {
+ if (PySet_Size(value) > 0) {
+ PyObject *arg_key;
+ Py_ssize_t arg_pos = 0;
+ Py_ssize_t arg_hash = 0;
+ while (_PySet_NextEntry(value, &arg_pos, &arg_key, &arg_hash)) {
+
+ if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key,
+ bm,
+ BM_ALL_NOLOOP,
+ opname,
+ slot_name,
+ "invalid key in set") == -1) {
+ return -1; /* error is set in bpy_slot_from_py_elem_check() */
+ }
+
+ BMO_slot_map_empty_insert(bmop, slot, ((BPy_BMElem *)arg_key)->ele);
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL: {
+ /* can't convert from these */
+ PyErr_Format(PyExc_NotImplementedError,
+ "This arguments mapping subtype %d is not supported",
+ slot->slot_subtype.map);
+ return -1;
+ }
+ }
+ break;
+ }
+ default:
+ /* TODO --- many others */
+ PyErr_Format(PyExc_NotImplementedError,
+ "%.200s: keyword \"%.200s\" type %d not working yet!",
+ opname,
+ slot_name,
+ slot->slot_type);
+ return -1;
+ }
+
+ /* all is well */
+ return 0;
}
/**
@@ -542,153 +606,146 @@ static int bpy_slot_from_py(
*/
static PyObject *bpy_slot_to_py(BMesh *bm, BMOpSlot *slot)
{
- PyObject *item = NULL;
-
- /* keep switch in same order as above */
- switch (slot->slot_type) {
- case BMO_OP_SLOT_BOOL:
- item = PyBool_FromLong((BMO_SLOT_AS_BOOL(slot)));
- break;
- case BMO_OP_SLOT_INT:
- item = PyLong_FromLong(BMO_SLOT_AS_INT(slot));
- break;
- case BMO_OP_SLOT_FLT:
- item = PyFloat_FromDouble((double)BMO_SLOT_AS_FLOAT(slot));
- break;
- case BMO_OP_SLOT_MAT:
- item = Matrix_CreatePyObject((float *)BMO_SLOT_AS_MATRIX(slot), 4, 4, NULL);
- break;
- case BMO_OP_SLOT_VEC:
- item = Vector_CreatePyObject(BMO_SLOT_AS_VECTOR(slot), slot->len, NULL);
- break;
- case BMO_OP_SLOT_PTR:
- BLI_assert(0); /* currently we don't have any pointer return values in use */
- item = Py_INCREF_RET(Py_None);
- break;
- case BMO_OP_SLOT_ELEMENT_BUF:
- {
- if (slot->slot_subtype.elem & BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE) {
- BMHeader *ele = BMO_slot_buffer_get_single(slot);
- item = ele ? BPy_BMElem_CreatePyObject(bm, ele) : Py_INCREF_RET(Py_None);
- }
- else {
- const int size = slot->len;
- void **buffer = BMO_SLOT_AS_BUFFER(slot);
- int j;
-
- item = PyList_New(size);
- for (j = 0; j < size; j++) {
- BMHeader *ele = buffer[j];
- PyList_SET_ITEM(item, j, BPy_BMElem_CreatePyObject(bm, ele));
- }
- }
- break;
- }
- case BMO_OP_SLOT_MAPPING:
- {
- GHash *slot_hash = BMO_SLOT_AS_GHASH(slot);
- GHashIterator hash_iter;
-
- switch (slot->slot_subtype.map) {
- case BMO_OP_SLOT_SUBTYPE_MAP_ELEM:
- {
- item = _PyDict_NewPresized(slot_hash ? BLI_ghash_len(slot_hash) : 0);
- if (slot_hash) {
- GHASH_ITER (hash_iter, slot_hash) {
- BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter);
- void *ele_val = BLI_ghashIterator_getValue(&hash_iter);
-
- PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key);
- PyObject *py_val = BPy_BMElem_CreatePyObject(bm, ele_val);
-
- PyDict_SetItem(item, py_key, py_val);
- Py_DECREF(py_key);
- Py_DECREF(py_val);
- }
- }
- break;
- }
- case BMO_OP_SLOT_SUBTYPE_MAP_FLT:
- {
- item = _PyDict_NewPresized(slot_hash ? BLI_ghash_len(slot_hash) : 0);
- if (slot_hash) {
- GHASH_ITER (hash_iter, slot_hash) {
- BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter);
- void *ele_val = BLI_ghashIterator_getValue(&hash_iter);
-
- PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key);
- PyObject *py_val = PyFloat_FromDouble(*(float *)&ele_val);
-
- PyDict_SetItem(item, py_key, py_val);
- Py_DECREF(py_key);
- Py_DECREF(py_val);
- }
- }
- break;
- }
- case BMO_OP_SLOT_SUBTYPE_MAP_INT:
- {
- item = _PyDict_NewPresized(slot_hash ? BLI_ghash_len(slot_hash) : 0);
- if (slot_hash) {
- GHASH_ITER (hash_iter, slot_hash) {
- BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter);
- void *ele_val = BLI_ghashIterator_getValue(&hash_iter);
-
- PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key);
- PyObject *py_val = PyLong_FromLong(*(int *)&ele_val);
-
- PyDict_SetItem(item, py_key, py_val);
- Py_DECREF(py_key);
- Py_DECREF(py_val);
- }
- }
- break;
- }
- case BMO_OP_SLOT_SUBTYPE_MAP_BOOL:
- {
- item = _PyDict_NewPresized(slot_hash ? BLI_ghash_len(slot_hash) : 0);
- if (slot_hash) {
- GHASH_ITER (hash_iter, slot_hash) {
- BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter);
- void *ele_val = BLI_ghashIterator_getValue(&hash_iter);
-
- PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key);
- PyObject *py_val = PyBool_FromLong(*(bool *)&ele_val);
-
- PyDict_SetItem(item, py_key, py_val);
- Py_DECREF(py_key);
- Py_DECREF(py_val);
- }
- }
- break;
- }
- case BMO_OP_SLOT_SUBTYPE_MAP_EMPTY:
- {
- item = PySet_New(NULL);
- if (slot_hash) {
- GHASH_ITER (hash_iter, slot_hash) {
- BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter);
-
- PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key);
-
- PySet_Add(item, py_key);
-
- Py_DECREF(py_key);
- }
- }
- break;
- }
- case BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL:
- /* can't convert from these */
- item = Py_INCREF_RET(Py_None);
- break;
- }
- break;
- }
- }
- BLI_assert(item != NULL);
-
- return item;
+ PyObject *item = NULL;
+
+ /* keep switch in same order as above */
+ switch (slot->slot_type) {
+ case BMO_OP_SLOT_BOOL:
+ item = PyBool_FromLong((BMO_SLOT_AS_BOOL(slot)));
+ break;
+ case BMO_OP_SLOT_INT:
+ item = PyLong_FromLong(BMO_SLOT_AS_INT(slot));
+ break;
+ case BMO_OP_SLOT_FLT:
+ item = PyFloat_FromDouble((double)BMO_SLOT_AS_FLOAT(slot));
+ break;
+ case BMO_OP_SLOT_MAT:
+ item = Matrix_CreatePyObject((float *)BMO_SLOT_AS_MATRIX(slot), 4, 4, NULL);
+ break;
+ case BMO_OP_SLOT_VEC:
+ item = Vector_CreatePyObject(BMO_SLOT_AS_VECTOR(slot), slot->len, NULL);
+ break;
+ case BMO_OP_SLOT_PTR:
+ BLI_assert(0); /* currently we don't have any pointer return values in use */
+ item = Py_INCREF_RET(Py_None);
+ break;
+ case BMO_OP_SLOT_ELEMENT_BUF: {
+ if (slot->slot_subtype.elem & BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE) {
+ BMHeader *ele = BMO_slot_buffer_get_single(slot);
+ item = ele ? BPy_BMElem_CreatePyObject(bm, ele) : Py_INCREF_RET(Py_None);
+ }
+ else {
+ const int size = slot->len;
+ void **buffer = BMO_SLOT_AS_BUFFER(slot);
+ int j;
+
+ item = PyList_New(size);
+ for (j = 0; j < size; j++) {
+ BMHeader *ele = buffer[j];
+ PyList_SET_ITEM(item, j, BPy_BMElem_CreatePyObject(bm, ele));
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_MAPPING: {
+ GHash *slot_hash = BMO_SLOT_AS_GHASH(slot);
+ GHashIterator hash_iter;
+
+ switch (slot->slot_subtype.map) {
+ case BMO_OP_SLOT_SUBTYPE_MAP_ELEM: {
+ item = _PyDict_NewPresized(slot_hash ? BLI_ghash_len(slot_hash) : 0);
+ if (slot_hash) {
+ GHASH_ITER (hash_iter, slot_hash) {
+ BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter);
+ void *ele_val = BLI_ghashIterator_getValue(&hash_iter);
+
+ PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key);
+ PyObject *py_val = BPy_BMElem_CreatePyObject(bm, ele_val);
+
+ PyDict_SetItem(item, py_key, py_val);
+ Py_DECREF(py_key);
+ Py_DECREF(py_val);
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_SUBTYPE_MAP_FLT: {
+ item = _PyDict_NewPresized(slot_hash ? BLI_ghash_len(slot_hash) : 0);
+ if (slot_hash) {
+ GHASH_ITER (hash_iter, slot_hash) {
+ BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter);
+ void *ele_val = BLI_ghashIterator_getValue(&hash_iter);
+
+ PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key);
+ PyObject *py_val = PyFloat_FromDouble(*(float *)&ele_val);
+
+ PyDict_SetItem(item, py_key, py_val);
+ Py_DECREF(py_key);
+ Py_DECREF(py_val);
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_SUBTYPE_MAP_INT: {
+ item = _PyDict_NewPresized(slot_hash ? BLI_ghash_len(slot_hash) : 0);
+ if (slot_hash) {
+ GHASH_ITER (hash_iter, slot_hash) {
+ BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter);
+ void *ele_val = BLI_ghashIterator_getValue(&hash_iter);
+
+ PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key);
+ PyObject *py_val = PyLong_FromLong(*(int *)&ele_val);
+
+ PyDict_SetItem(item, py_key, py_val);
+ Py_DECREF(py_key);
+ Py_DECREF(py_val);
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_SUBTYPE_MAP_BOOL: {
+ item = _PyDict_NewPresized(slot_hash ? BLI_ghash_len(slot_hash) : 0);
+ if (slot_hash) {
+ GHASH_ITER (hash_iter, slot_hash) {
+ BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter);
+ void *ele_val = BLI_ghashIterator_getValue(&hash_iter);
+
+ PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key);
+ PyObject *py_val = PyBool_FromLong(*(bool *)&ele_val);
+
+ PyDict_SetItem(item, py_key, py_val);
+ Py_DECREF(py_key);
+ Py_DECREF(py_val);
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_SUBTYPE_MAP_EMPTY: {
+ item = PySet_New(NULL);
+ if (slot_hash) {
+ GHASH_ITER (hash_iter, slot_hash) {
+ BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter);
+
+ PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key);
+
+ PySet_Add(item, py_key);
+
+ Py_DECREF(py_key);
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL:
+ /* can't convert from these */
+ item = Py_INCREF_RET(Py_None);
+ break;
+ }
+ break;
+ }
+ }
+ BLI_assert(item != NULL);
+
+ return item;
}
/**
@@ -696,112 +753,109 @@ static PyObject *bpy_slot_to_py(BMesh *bm, BMOpSlot *slot)
*/
PyObject *BPy_BMO_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *kw)
{
- PyObject *ret;
- BPy_BMesh *py_bm;
- BMesh *bm;
-
- BMOperator bmop;
-
- if ((PyTuple_GET_SIZE(args) == 1) &&
- (py_bm = (BPy_BMesh *)PyTuple_GET_ITEM(args, 0)) &&
- (BPy_BMesh_Check(py_bm)))
- {
- BPY_BM_CHECK_OBJ(py_bm);
- bm = py_bm->bm;
-
- if (bm->use_toolflags == false) {
- PyErr_SetString(PyExc_ValueError,
- "bmesh created with 'use_operators=False'");
- return NULL;
- }
-
- /* could complain about entering with exceptions... */
- BMO_error_clear(bm);
- }
- else {
- PyErr_SetString(PyExc_TypeError,
- "bmesh operators expect a single BMesh positional argument, all other args must be keywords");
- return NULL;
- }
-
- /* TODO - error check this!, though we do the error check on attribute access */
- /* TODO - make flags optional */
- BMO_op_init(bm, &bmop, BMO_FLAG_DEFAULTS, self->opname);
-
- if (kw && PyDict_Size(kw) > 0) {
- /* setup properties, see bpy_rna.c: pyrna_py_to_prop()
- * which shares this logic for parsing properties */
-
- PyObject *key, *value;
- Py_ssize_t pos = 0;
- while (PyDict_Next(kw, &pos, &key, &value)) {
- const char *slot_name = _PyUnicode_AsString(key);
- BMOpSlot *slot;
-
- if (!BMO_slot_exists(bmop.slots_in, slot_name)) {
- PyErr_Format(PyExc_TypeError,
- "%.200s: keyword \"%.200s\" is invalid for this operator",
- self->opname, slot_name);
- BMO_op_finish(bm, &bmop);
- return NULL;
- }
-
- slot = BMO_slot_get(bmop.slots_in, slot_name);
-
- /* now assign the value */
- if (bpy_slot_from_py(bm, &bmop, slot, value,
- self->opname, slot_name) == -1)
- {
- BMO_op_finish(bm, &bmop);
- return NULL;
- }
- }
- }
-
- BMO_op_exec(bm, &bmop);
-
- /* from here until the end of the function, no returns, just set 'ret' */
- if (UNLIKELY(bpy_bm_op_as_py_error(bm) == -1)) {
- ret = NULL; /* exception raised above */
- }
- else if (bmop.slots_out[0].slot_name == NULL) {
- ret = Py_INCREF_RET(Py_None);
- }
- else {
- /* build return value */
- int i;
- ret = PyDict_New();
-
- for (i = 0; bmop.slots_out[i].slot_name; i++) {
- // BMOpDefine *op_def = opdefines[bmop.type];
- // BMOSlotType *slot_type = op_def->slot_types_out[i];
- BMOpSlot *slot = &bmop.slots_out[i];
- PyObject *item;
-
- /* this function doesn't throw exceptions */
- item = bpy_slot_to_py(bm, slot);
- if (item == NULL) {
- item = Py_INCREF_RET(Py_None);
- }
+ PyObject *ret;
+ BPy_BMesh *py_bm;
+ BMesh *bm;
+
+ BMOperator bmop;
+
+ if ((PyTuple_GET_SIZE(args) == 1) && (py_bm = (BPy_BMesh *)PyTuple_GET_ITEM(args, 0)) &&
+ (BPy_BMesh_Check(py_bm))) {
+ BPY_BM_CHECK_OBJ(py_bm);
+ bm = py_bm->bm;
+
+ if (bm->use_toolflags == false) {
+ PyErr_SetString(PyExc_ValueError, "bmesh created with 'use_operators=False'");
+ return NULL;
+ }
+
+ /* could complain about entering with exceptions... */
+ BMO_error_clear(bm);
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError,
+ "bmesh operators expect a single BMesh positional argument, all other args "
+ "must be keywords");
+ return NULL;
+ }
+
+ /* TODO - error check this!, though we do the error check on attribute access */
+ /* TODO - make flags optional */
+ BMO_op_init(bm, &bmop, BMO_FLAG_DEFAULTS, self->opname);
+
+ if (kw && PyDict_Size(kw) > 0) {
+ /* setup properties, see bpy_rna.c: pyrna_py_to_prop()
+ * which shares this logic for parsing properties */
+
+ PyObject *key, *value;
+ Py_ssize_t pos = 0;
+ while (PyDict_Next(kw, &pos, &key, &value)) {
+ const char *slot_name = _PyUnicode_AsString(key);
+ BMOpSlot *slot;
+
+ if (!BMO_slot_exists(bmop.slots_in, slot_name)) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" is invalid for this operator",
+ self->opname,
+ slot_name);
+ BMO_op_finish(bm, &bmop);
+ return NULL;
+ }
+
+ slot = BMO_slot_get(bmop.slots_in, slot_name);
+
+ /* now assign the value */
+ if (bpy_slot_from_py(bm, &bmop, slot, value, self->opname, slot_name) == -1) {
+ BMO_op_finish(bm, &bmop);
+ return NULL;
+ }
+ }
+ }
+
+ BMO_op_exec(bm, &bmop);
+
+ /* from here until the end of the function, no returns, just set 'ret' */
+ if (UNLIKELY(bpy_bm_op_as_py_error(bm) == -1)) {
+ ret = NULL; /* exception raised above */
+ }
+ else if (bmop.slots_out[0].slot_name == NULL) {
+ ret = Py_INCREF_RET(Py_None);
+ }
+ else {
+ /* build return value */
+ int i;
+ ret = PyDict_New();
+
+ for (i = 0; bmop.slots_out[i].slot_name; i++) {
+ // BMOpDefine *op_def = opdefines[bmop.type];
+ // BMOSlotType *slot_type = op_def->slot_types_out[i];
+ BMOpSlot *slot = &bmop.slots_out[i];
+ PyObject *item;
+
+ /* this function doesn't throw exceptions */
+ item = bpy_slot_to_py(bm, slot);
+ if (item == NULL) {
+ item = Py_INCREF_RET(Py_None);
+ }
#if 1
- /* temp code, strip off '.out' while we keep this convention */
- {
- char slot_name_strip[MAX_SLOTNAME];
- const char *ch = strchr(slot->slot_name, '.'); /* can't fail! */
- int tot = ch - slot->slot_name;
- BLI_assert(ch != NULL);
- memcpy(slot_name_strip, slot->slot_name, tot);
- slot_name_strip[tot] = '\0';
- PyDict_SetItemString(ret, slot_name_strip, item);
- }
+ /* temp code, strip off '.out' while we keep this convention */
+ {
+ char slot_name_strip[MAX_SLOTNAME];
+ const char *ch = strchr(slot->slot_name, '.'); /* can't fail! */
+ int tot = ch - slot->slot_name;
+ BLI_assert(ch != NULL);
+ memcpy(slot_name_strip, slot->slot_name, tot);
+ slot_name_strip[tot] = '\0';
+ PyDict_SetItemString(ret, slot_name_strip, item);
+ }
#else
- PyDict_SetItemString(ret, slot->slot_name, item);
+ PyDict_SetItemString(ret, slot->slot_name, item);
#endif
- Py_DECREF(item);
- }
- }
+ Py_DECREF(item);
+ }
+ }
- BMO_op_finish(bm, &bmop);
- return ret;
+ BMO_op_finish(bm, &bmop);
+ return ret;
}
diff --git a/source/blender/python/bmesh/bmesh_py_ops_call.h b/source/blender/python/bmesh/bmesh_py_ops_call.h
index 986c4e3e296..7b6611cd61d 100644
--- a/source/blender/python/bmesh/bmesh_py_ops_call.h
+++ b/source/blender/python/bmesh/bmesh_py_ops_call.h
@@ -25,11 +25,10 @@
#define __BMESH_PY_OPS_CALL_H__
typedef struct {
- PyObject_HEAD /* required python macro */
- const char *opname;
+ PyObject_HEAD /* required python macro */
+ const char *opname;
} BPy_BMeshOpFunc;
-
PyObject *BPy_BMO_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *kw);
#endif /* __BMESH_PY_OPS_CALL_H__ */
diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c
index 366f0b4b3f7..522927f56e2 100644
--- a/source/blender/python/bmesh/bmesh_py_types.c
+++ b/source/blender/python/bmesh/bmesh_py_types.c
@@ -57,36 +57,36 @@ static void bm_dealloc_editmode_warn(BPy_BMesh *self);
/* scene does not use BM_* flags. */
PyC_FlagSet bpy_bm_scene_vert_edge_face_flags[] = {
- {1, "VERT"},
- {2, "EDGE"},
- {4, "FACE"},
- {0, NULL},
+ {1, "VERT"},
+ {2, "EDGE"},
+ {4, "FACE"},
+ {0, NULL},
};
PyC_FlagSet bpy_bm_htype_vert_edge_face_flags[] = {
- {BM_VERT, "VERT"},
- {BM_EDGE, "EDGE"},
- {BM_FACE, "FACE"},
- {0, NULL},
+ {BM_VERT, "VERT"},
+ {BM_EDGE, "EDGE"},
+ {BM_FACE, "FACE"},
+ {0, NULL},
};
PyC_FlagSet bpy_bm_htype_all_flags[] = {
- {BM_VERT, "VERT"},
- {BM_LOOP, "EDGE"},
- {BM_FACE, "FACE"},
- {BM_LOOP, "LOOP"},
- {0, NULL},
+ {BM_VERT, "VERT"},
+ {BM_LOOP, "EDGE"},
+ {BM_FACE, "FACE"},
+ {BM_LOOP, "LOOP"},
+ {0, NULL},
};
#define BPY_BM_HFLAG_ALL_STR "('SELECT', 'HIDE', 'SEAM', 'SMOOTH', 'TAG')"
PyC_FlagSet bpy_bm_hflag_all_flags[] = {
- {BM_ELEM_SELECT, "SELECT"},
- {BM_ELEM_HIDDEN, "HIDE"},
- {BM_ELEM_SEAM, "SEAM"},
- {BM_ELEM_SMOOTH, "SMOOTH"},
- {BM_ELEM_TAG, "TAG"},
- {0, NULL},
+ {BM_ELEM_SELECT, "SELECT"},
+ {BM_ELEM_HIDDEN, "HIDE"},
+ {BM_ELEM_SEAM, "SEAM"},
+ {BM_ELEM_SMOOTH, "SMOOTH"},
+ {BM_ELEM_TAG, "TAG"},
+ {0, NULL},
};
/* py-type definitions
@@ -95,498 +95,463 @@ PyC_FlagSet bpy_bm_hflag_all_flags[] = {
/* getseters
* ========= */
-
/* bmesh elems
* ----------- */
-PyDoc_STRVAR(bpy_bm_elem_select_doc, "Selected state of this element.\n\n:type: boolean");
-PyDoc_STRVAR(bpy_bm_elem_hide_doc, "Hidden state of this element.\n\n:type: boolean");
-PyDoc_STRVAR(bpy_bm_elem_tag_doc, "Generic attribute scripts can use for own logic\n\n:type: boolean");
-PyDoc_STRVAR(bpy_bm_elem_smooth_doc, "Smooth state of this element.\n\n:type: boolean");
-PyDoc_STRVAR(bpy_bm_elem_seam_doc, "Seam for UV unwrapping.\n\n:type: boolean");
-
+PyDoc_STRVAR(bpy_bm_elem_select_doc, "Selected state of this element.\n\n:type: boolean");
+PyDoc_STRVAR(bpy_bm_elem_hide_doc, "Hidden state of this element.\n\n:type: boolean");
+PyDoc_STRVAR(bpy_bm_elem_tag_doc,
+ "Generic attribute scripts can use for own logic\n\n:type: boolean");
+PyDoc_STRVAR(bpy_bm_elem_smooth_doc, "Smooth state of this element.\n\n:type: boolean");
+PyDoc_STRVAR(bpy_bm_elem_seam_doc, "Seam for UV unwrapping.\n\n:type: boolean");
static PyObject *bpy_bm_elem_hflag_get(BPy_BMElem *self, void *flag)
{
- const char hflag = (char)POINTER_AS_INT(flag);
+ const char hflag = (char)POINTER_AS_INT(flag);
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- return PyBool_FromLong(BM_elem_flag_test(self->ele, hflag));
+ return PyBool_FromLong(BM_elem_flag_test(self->ele, hflag));
}
static int bpy_bm_elem_hflag_set(BPy_BMElem *self, PyObject *value, void *flag)
{
- const char hflag = (char)POINTER_AS_INT(flag);
- int param;
-
- BPY_BM_CHECK_INT(self);
-
- if ((param = PyC_Long_AsBool(value)) == -1) {
- return -1;
- }
-
- if (hflag == BM_ELEM_SELECT) {
- BM_elem_select_set(self->bm, self->ele, param);
- }
- else {
- BM_elem_flag_set(self->ele, hflag, param);
- }
- return 0;
-}
-
-PyDoc_STRVAR(bpy_bm_elem_index_doc,
-"Index of this element.\n"
-"\n"
-":type: int\n"
-"\n"
-".. note::\n"
-"\n"
-" This value is not necessarily valid, while editing the mesh it can become *dirty*.\n"
-"\n"
-" It's also possible to assign any number to this attribute for a scripts internal logic.\n"
-"\n"
-" To ensure the value is up to date - see :class:`BMElemSeq.index_update`.\n"
-);
+ const char hflag = (char)POINTER_AS_INT(flag);
+ int param;
+
+ BPY_BM_CHECK_INT(self);
+
+ if ((param = PyC_Long_AsBool(value)) == -1) {
+ return -1;
+ }
+
+ if (hflag == BM_ELEM_SELECT) {
+ BM_elem_select_set(self->bm, self->ele, param);
+ }
+ else {
+ BM_elem_flag_set(self->ele, hflag, param);
+ }
+ return 0;
+}
+
+PyDoc_STRVAR(
+ bpy_bm_elem_index_doc,
+ "Index of this element.\n"
+ "\n"
+ ":type: int\n"
+ "\n"
+ ".. note::\n"
+ "\n"
+ " This value is not necessarily valid, while editing the mesh it can become *dirty*.\n"
+ "\n"
+ " It's also possible to assign any number to this attribute for a scripts internal logic.\n"
+ "\n"
+ " To ensure the value is up to date - see :class:`BMElemSeq.index_update`.\n");
static PyObject *bpy_bm_elem_index_get(BPy_BMElem *self, void *UNUSED(flag))
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- return PyLong_FromLong(BM_elem_index_get(self->ele));
+ return PyLong_FromLong(BM_elem_index_get(self->ele));
}
static int bpy_bm_elem_index_set(BPy_BMElem *self, PyObject *value, void *UNUSED(flag))
{
- int param;
+ int param;
- BPY_BM_CHECK_INT(self);
+ BPY_BM_CHECK_INT(self);
- if (((param = PyC_Long_AsI32(value)) == -1) && PyErr_Occurred()) {
- /* error is set */
- return -1;
- }
+ if (((param = PyC_Long_AsI32(value)) == -1) && PyErr_Occurred()) {
+ /* error is set */
+ return -1;
+ }
- BM_elem_index_set(self->ele, param); /* set_dirty! */
+ BM_elem_index_set(self->ele, param); /* set_dirty! */
- /* when setting the index assume its set invalid */
- self->bm->elem_index_dirty |= self->ele->head.htype;
+ /* when setting the index assume its set invalid */
+ self->bm->elem_index_dirty |= self->ele->head.htype;
- return 0;
+ return 0;
}
/* type specific get/sets
* ---------------------- */
-
/* Mesh
* ^^^^ */
/* doc-strings for all uses of this function */
PyDoc_STRVAR(bpy_bmvertseq_doc,
-"This meshes vert sequence (read-only).\n\n:type: :class:`BMVertSeq`"
-);
+ "This meshes vert sequence (read-only).\n\n:type: :class:`BMVertSeq`");
static PyObject *bpy_bmvertseq_get(BPy_BMesh *self, void *UNUSED(closure))
{
- BPY_BM_CHECK_OBJ(self);
- return BPy_BMVertSeq_CreatePyObject(self->bm);
+ BPY_BM_CHECK_OBJ(self);
+ return BPy_BMVertSeq_CreatePyObject(self->bm);
}
PyDoc_STRVAR(bpy_bmedgeseq_doc,
-"This meshes edge sequence (read-only).\n\n:type: :class:`BMEdgeSeq`"
-);
+ "This meshes edge sequence (read-only).\n\n:type: :class:`BMEdgeSeq`");
static PyObject *bpy_bmedgeseq_get(BPy_BMesh *self, void *UNUSED(closure))
{
- BPY_BM_CHECK_OBJ(self);
- return BPy_BMEdgeSeq_CreatePyObject(self->bm);
+ BPY_BM_CHECK_OBJ(self);
+ return BPy_BMEdgeSeq_CreatePyObject(self->bm);
}
PyDoc_STRVAR(bpy_bmfaceseq_doc,
-"This meshes face sequence (read-only).\n\n:type: :class:`BMFaceSeq`"
-);
+ "This meshes face sequence (read-only).\n\n:type: :class:`BMFaceSeq`");
static PyObject *bpy_bmfaceseq_get(BPy_BMesh *self, void *UNUSED(closure))
{
- BPY_BM_CHECK_OBJ(self);
- return BPy_BMFaceSeq_CreatePyObject(self->bm);
+ BPY_BM_CHECK_OBJ(self);
+ return BPy_BMFaceSeq_CreatePyObject(self->bm);
}
PyDoc_STRVAR(bpy_bmloopseq_doc,
-"This meshes loops (read-only).\n\n:type: :class:`BMLoopSeq`\n"
-"\n"
-".. note::\n"
-"\n"
-" Loops must be accessed via faces, this is only exposed for layer access.\n"
-);
+ "This meshes loops (read-only).\n\n:type: :class:`BMLoopSeq`\n"
+ "\n"
+ ".. note::\n"
+ "\n"
+ " Loops must be accessed via faces, this is only exposed for layer access.\n");
static PyObject *bpy_bmloopseq_get(BPy_BMesh *self, void *UNUSED(closure))
{
- BPY_BM_CHECK_OBJ(self);
- return BPy_BMLoopSeq_CreatePyObject(self->bm);
+ BPY_BM_CHECK_OBJ(self);
+ return BPy_BMLoopSeq_CreatePyObject(self->bm);
}
/* vert */
-PyDoc_STRVAR(bpy_bmvert_link_edges_doc,
-"Edges connected to this vertex (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMEdge`"
-);
-PyDoc_STRVAR(bpy_bmvert_link_faces_doc,
-"Faces connected to this vertex (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMFace`"
-);
-PyDoc_STRVAR(bpy_bmvert_link_loops_doc,
-"Loops that use this vertex (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMLoop`"
-);
+PyDoc_STRVAR(
+ bpy_bmvert_link_edges_doc,
+ "Edges connected to this vertex (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMEdge`");
+PyDoc_STRVAR(
+ bpy_bmvert_link_faces_doc,
+ "Faces connected to this vertex (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMFace`");
+PyDoc_STRVAR(
+ bpy_bmvert_link_loops_doc,
+ "Loops that use this vertex (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMLoop`");
/* edge */
PyDoc_STRVAR(bpy_bmedge_verts_doc,
-"Verts this edge uses (always 2), (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMVert`"
-);
-PyDoc_STRVAR(bpy_bmedge_link_faces_doc,
-"Faces connected to this edge, (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMFace`"
-);
-PyDoc_STRVAR(bpy_bmedge_link_loops_doc,
-"Loops connected to this edge, (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMLoop`"
-);
+ "Verts this edge uses (always 2), (read-only).\n\n:type: :class:`BMElemSeq` of "
+ ":class:`BMVert`");
+PyDoc_STRVAR(
+ bpy_bmedge_link_faces_doc,
+ "Faces connected to this edge, (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMFace`");
+PyDoc_STRVAR(
+ bpy_bmedge_link_loops_doc,
+ "Loops connected to this edge, (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMLoop`");
/* face */
PyDoc_STRVAR(bpy_bmface_verts_doc,
-"Verts of this face, (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMVert`"
-);
+ "Verts of this face, (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMVert`");
PyDoc_STRVAR(bpy_bmface_edges_doc,
-"Edges of this face, (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMEdge`"
-);
+ "Edges of this face, (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMEdge`");
PyDoc_STRVAR(bpy_bmface_loops_doc,
-"Loops of this face, (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMLoop`"
-);
+ "Loops of this face, (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMLoop`");
/* loop */
-PyDoc_STRVAR(bpy_bmloops_link_loops_doc,
-"Loops connected to this loop, (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMLoop`"
-);
+PyDoc_STRVAR(
+ bpy_bmloops_link_loops_doc,
+ "Loops connected to this loop, (read-only).\n\n:type: :class:`BMElemSeq` of :class:`BMLoop`");
static PyObject *bpy_bmelemseq_elem_get(BPy_BMElem *self, void *itype)
{
- BPY_BM_CHECK_OBJ(self);
- return BPy_BMElemSeq_CreatePyObject(self->bm, self, POINTER_AS_INT(itype));
+ BPY_BM_CHECK_OBJ(self);
+ return BPy_BMElemSeq_CreatePyObject(self->bm, self, POINTER_AS_INT(itype));
}
-
PyDoc_STRVAR(bpy_bm_is_valid_doc,
-"True when this element is valid (hasn't been removed).\n\n:type: boolean"
-);
+ "True when this element is valid (hasn't been removed).\n\n:type: boolean");
static PyObject *bpy_bm_is_valid_get(BPy_BMGeneric *self)
{
- return PyBool_FromLong(BPY_BM_IS_VALID(self));
+ return PyBool_FromLong(BPY_BM_IS_VALID(self));
}
-PyDoc_STRVAR(bpy_bmesh_is_wrapped_doc,
-"True when this mesh is owned by blender (typically the editmode BMesh).\n\n:type: boolean"
-);
+PyDoc_STRVAR(
+ bpy_bmesh_is_wrapped_doc,
+ "True when this mesh is owned by blender (typically the editmode BMesh).\n\n:type: boolean");
static PyObject *bpy_bmesh_is_wrapped_get(BPy_BMesh *self)
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- return PyBool_FromLong(self->flag & BPY_BMFLAG_IS_WRAPPED);
+ return PyBool_FromLong(self->flag & BPY_BMFLAG_IS_WRAPPED);
}
PyDoc_STRVAR(bpy_bmesh_select_mode_doc,
-"The selection mode, values can be {'VERT', 'EDGE', 'FACE'}, can't be assigned an empty set.\n\n:type: set"
-);
+ "The selection mode, values can be {'VERT', 'EDGE', 'FACE'}, can't be assigned an "
+ "empty set.\n\n:type: set");
static PyObject *bpy_bmesh_select_mode_get(BPy_BMesh *self)
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- return PyC_FlagSet_FromBitfield(bpy_bm_scene_vert_edge_face_flags, self->bm->selectmode);
+ return PyC_FlagSet_FromBitfield(bpy_bm_scene_vert_edge_face_flags, self->bm->selectmode);
}
static int bpy_bmesh_select_mode_set(BPy_BMesh *self, PyObject *value)
{
- int flag = 0;
- BPY_BM_CHECK_INT(self);
+ int flag = 0;
+ BPY_BM_CHECK_INT(self);
- if (PyC_FlagSet_ToBitfield(bpy_bm_scene_vert_edge_face_flags, value, &flag, "bm.select_mode") == -1) {
- return -1;
- }
- else if (flag == 0) {
- PyErr_SetString(PyExc_TypeError,
- "bm.select_mode: cant assignt an empty value");
- return -1;
- }
- else {
- self->bm->selectmode = flag;
- return 0;
- }
+ if (PyC_FlagSet_ToBitfield(bpy_bm_scene_vert_edge_face_flags, value, &flag, "bm.select_mode") ==
+ -1) {
+ return -1;
+ }
+ else if (flag == 0) {
+ PyErr_SetString(PyExc_TypeError, "bm.select_mode: cant assignt an empty value");
+ return -1;
+ }
+ else {
+ self->bm->selectmode = flag;
+ return 0;
+ }
}
PyDoc_STRVAR(bpy_bmesh_select_history_doc,
-"Sequence of selected items (the last is displayed as active).\n\n:type: :class:`BMEditSelSeq`"
-);
+ "Sequence of selected items (the last is displayed as active).\n\n:type: "
+ ":class:`BMEditSelSeq`");
static PyObject *bpy_bmesh_select_history_get(BPy_BMesh *self)
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- return BPy_BMEditSel_CreatePyObject(self->bm);
+ return BPy_BMEditSel_CreatePyObject(self->bm);
}
static int bpy_bmesh_select_history_set(BPy_BMesh *self, PyObject *value)
{
- BPY_BM_CHECK_INT(self);
+ BPY_BM_CHECK_INT(self);
- return BPy_BMEditSel_Assign(self, value);
+ return BPy_BMEditSel_Assign(self, value);
}
/* Vert
* ^^^^ */
PyDoc_STRVAR(bpy_bmvert_co_doc,
-"The coordinates for this vertex as a 3D, wrapped vector.\n\n:type: :class:`mathutils.Vector`"
-);
+ "The coordinates for this vertex as a 3D, wrapped vector.\n\n:type: "
+ ":class:`mathutils.Vector`");
static PyObject *bpy_bmvert_co_get(BPy_BMVert *self)
{
- BPY_BM_CHECK_OBJ(self);
- return Vector_CreatePyObject_wrap(self->v->co, 3, NULL);
+ BPY_BM_CHECK_OBJ(self);
+ return Vector_CreatePyObject_wrap(self->v->co, 3, NULL);
}
static int bpy_bmvert_co_set(BPy_BMVert *self, PyObject *value)
{
- BPY_BM_CHECK_INT(self);
+ BPY_BM_CHECK_INT(self);
- if (mathutils_array_parse(self->v->co, 3, 3, value, "BMVert.co") != -1) {
- return 0;
- }
- else {
- return -1;
- }
+ if (mathutils_array_parse(self->v->co, 3, 3, value, "BMVert.co") != -1) {
+ return 0;
+ }
+ else {
+ return -1;
+ }
}
-
-PyDoc_STRVAR(bpy_bmvert_normal_doc,
-"The normal for this vertex as a 3D, wrapped vector.\n\n:type: :class:`mathutils.Vector`"
-);
+PyDoc_STRVAR(
+ bpy_bmvert_normal_doc,
+ "The normal for this vertex as a 3D, wrapped vector.\n\n:type: :class:`mathutils.Vector`");
static PyObject *bpy_bmvert_normal_get(BPy_BMVert *self)
{
- BPY_BM_CHECK_OBJ(self);
- return Vector_CreatePyObject_wrap(self->v->no, 3, NULL);
+ BPY_BM_CHECK_OBJ(self);
+ return Vector_CreatePyObject_wrap(self->v->no, 3, NULL);
}
static int bpy_bmvert_normal_set(BPy_BMVert *self, PyObject *value)
{
- BPY_BM_CHECK_INT(self);
+ BPY_BM_CHECK_INT(self);
- if (mathutils_array_parse(self->v->no, 3, 3, value, "BMVert.normal") != -1) {
- return 0;
- }
- else {
- return -1;
- }
+ if (mathutils_array_parse(self->v->no, 3, 3, value, "BMVert.normal") != -1) {
+ return 0;
+ }
+ else {
+ return -1;
+ }
}
-
PyDoc_STRVAR(bpy_bmvert_is_manifold_doc,
-"True when this vertex is manifold (read-only).\n\n:type: boolean"
-);
+ "True when this vertex is manifold (read-only).\n\n:type: boolean");
static PyObject *bpy_bmvert_is_manifold_get(BPy_BMVert *self)
{
- BPY_BM_CHECK_OBJ(self);
- return PyBool_FromLong(BM_vert_is_manifold(self->v));
+ BPY_BM_CHECK_OBJ(self);
+ return PyBool_FromLong(BM_vert_is_manifold(self->v));
}
-
PyDoc_STRVAR(bpy_bmvert_is_wire_doc,
-"True when this vertex is not connected to any faces (read-only).\n\n:type: boolean"
-);
+ "True when this vertex is not connected to any faces (read-only).\n\n:type: boolean");
static PyObject *bpy_bmvert_is_wire_get(BPy_BMVert *self)
{
- BPY_BM_CHECK_OBJ(self);
- return PyBool_FromLong(BM_vert_is_wire(self->v));
+ BPY_BM_CHECK_OBJ(self);
+ return PyBool_FromLong(BM_vert_is_wire(self->v));
}
-PyDoc_STRVAR(bpy_bmvert_is_boundary_doc,
-"True when this vertex is connected to boundary edges (read-only).\n\n:type: boolean"
-);
+PyDoc_STRVAR(
+ bpy_bmvert_is_boundary_doc,
+ "True when this vertex is connected to boundary edges (read-only).\n\n:type: boolean");
static PyObject *bpy_bmvert_is_boundary_get(BPy_BMVert *self)
{
- BPY_BM_CHECK_OBJ(self);
- return PyBool_FromLong(BM_vert_is_boundary(self->v));
+ BPY_BM_CHECK_OBJ(self);
+ return PyBool_FromLong(BM_vert_is_boundary(self->v));
}
-
/* Edge
* ^^^^ */
PyDoc_STRVAR(bpy_bmedge_is_manifold_doc,
-"True when this edge is manifold (read-only).\n\n:type: boolean"
-);
+ "True when this edge is manifold (read-only).\n\n:type: boolean");
static PyObject *bpy_bmedge_is_manifold_get(BPy_BMEdge *self)
{
- BPY_BM_CHECK_OBJ(self);
- return PyBool_FromLong(BM_edge_is_manifold(self->e));
+ BPY_BM_CHECK_OBJ(self);
+ return PyBool_FromLong(BM_edge_is_manifold(self->e));
}
PyDoc_STRVAR(bpy_bmedge_is_contiguous_doc,
-"True when this edge is manifold, between two faces with the same winding (read-only).\n\n:type: boolean"
-);
+ "True when this edge is manifold, between two faces with the same winding "
+ "(read-only).\n\n:type: boolean");
static PyObject *bpy_bmedge_is_contiguous_get(BPy_BMEdge *self)
{
- BPY_BM_CHECK_OBJ(self);
- return PyBool_FromLong(BM_edge_is_contiguous(self->e));
+ BPY_BM_CHECK_OBJ(self);
+ return PyBool_FromLong(BM_edge_is_contiguous(self->e));
}
PyDoc_STRVAR(bpy_bmedge_is_convex_doc,
-"True when this edge joins two convex faces, depends on a valid face normal (read-only).\n\n:type: boolean"
-);
+ "True when this edge joins two convex faces, depends on a valid face normal "
+ "(read-only).\n\n:type: boolean");
static PyObject *bpy_bmedge_is_convex_get(BPy_BMEdge *self)
{
- BPY_BM_CHECK_OBJ(self);
- return PyBool_FromLong(BM_edge_is_convex(self->e));
+ BPY_BM_CHECK_OBJ(self);
+ return PyBool_FromLong(BM_edge_is_convex(self->e));
}
PyDoc_STRVAR(bpy_bmedge_is_wire_doc,
-"True when this edge is not connected to any faces (read-only).\n\n:type: boolean"
-);
+ "True when this edge is not connected to any faces (read-only).\n\n:type: boolean");
static PyObject *bpy_bmedge_is_wire_get(BPy_BMEdge *self)
{
- BPY_BM_CHECK_OBJ(self);
- return PyBool_FromLong(BM_edge_is_wire(self->e));
+ BPY_BM_CHECK_OBJ(self);
+ return PyBool_FromLong(BM_edge_is_wire(self->e));
}
-
PyDoc_STRVAR(bpy_bmedge_is_boundary_doc,
-"True when this edge is at the boundary of a face (read-only).\n\n:type: boolean"
-);
+ "True when this edge is at the boundary of a face (read-only).\n\n:type: boolean");
static PyObject *bpy_bmedge_is_boundary_get(BPy_BMEdge *self)
{
- BPY_BM_CHECK_OBJ(self);
- return PyBool_FromLong(BM_edge_is_boundary(self->e));
+ BPY_BM_CHECK_OBJ(self);
+ return PyBool_FromLong(BM_edge_is_boundary(self->e));
}
-
/* Face
* ^^^^ */
-PyDoc_STRVAR(bpy_bmface_normal_doc,
-"The normal for this face as a 3D, wrapped vector.\n\n:type: :class:`mathutils.Vector`"
-);
+PyDoc_STRVAR(
+ bpy_bmface_normal_doc,
+ "The normal for this face as a 3D, wrapped vector.\n\n:type: :class:`mathutils.Vector`");
static PyObject *bpy_bmface_normal_get(BPy_BMFace *self)
{
- BPY_BM_CHECK_OBJ(self);
- return Vector_CreatePyObject_wrap(self->f->no, 3, NULL);
+ BPY_BM_CHECK_OBJ(self);
+ return Vector_CreatePyObject_wrap(self->f->no, 3, NULL);
}
static int bpy_bmface_normal_set(BPy_BMFace *self, PyObject *value)
{
- BPY_BM_CHECK_INT(self);
+ BPY_BM_CHECK_INT(self);
- if (mathutils_array_parse(self->f->no, 3, 3, value, "BMFace.normal") != -1) {
- return 0;
- }
- else {
- return -1;
- }
+ if (mathutils_array_parse(self->f->no, 3, 3, value, "BMFace.normal") != -1) {
+ return 0;
+ }
+ else {
+ return -1;
+ }
}
-PyDoc_STRVAR(bpy_bmface_material_index_doc,
-"The face's material index.\n\n:type: int"
-);
+PyDoc_STRVAR(bpy_bmface_material_index_doc, "The face's material index.\n\n:type: int");
static PyObject *bpy_bmface_material_index_get(BPy_BMFace *self)
{
- BPY_BM_CHECK_OBJ(self);
- return PyLong_FromLong(self->f->mat_nr);
+ BPY_BM_CHECK_OBJ(self);
+ return PyLong_FromLong(self->f->mat_nr);
}
static int bpy_bmface_material_index_set(BPy_BMFace *self, PyObject *value)
{
- int param;
+ int param;
- BPY_BM_CHECK_INT(self);
+ BPY_BM_CHECK_INT(self);
- if (((param = PyC_Long_AsI32(value)) == -1) && PyErr_Occurred()) {
- /* error is set */
- return -1;
- }
+ if (((param = PyC_Long_AsI32(value)) == -1) && PyErr_Occurred()) {
+ /* error is set */
+ return -1;
+ }
- if ((param < 0) || (param > MAXMAT)) {
- /* normally we clamp but in this case raise an error */
- PyErr_SetString(PyExc_ValueError,
- "material index outside of usable range (0 - 32766)");
- return -1;
- }
- else {
- self->f->mat_nr = (short)param;
- return 0;
- }
+ if ((param < 0) || (param > MAXMAT)) {
+ /* normally we clamp but in this case raise an error */
+ PyErr_SetString(PyExc_ValueError, "material index outside of usable range (0 - 32766)");
+ return -1;
+ }
+ else {
+ self->f->mat_nr = (short)param;
+ return 0;
+ }
}
-
/* Loop
* ^^^^ */
-PyDoc_STRVAR(bpy_bmloop_vert_doc,
-"The loop's vertex (read-only).\n\n:type: :class:`BMVert`"
-);
+PyDoc_STRVAR(bpy_bmloop_vert_doc, "The loop's vertex (read-only).\n\n:type: :class:`BMVert`");
static PyObject *bpy_bmloop_vert_get(BPy_BMLoop *self)
{
- BPY_BM_CHECK_OBJ(self);
- return BPy_BMVert_CreatePyObject(self->bm, self->l->v);
+ BPY_BM_CHECK_OBJ(self);
+ return BPy_BMVert_CreatePyObject(self->bm, self->l->v);
}
-
-PyDoc_STRVAR(bpy_bmloop_edge_doc,
-"The loop's edge (between this loop and the next), (read-only).\n\n:type: :class:`BMEdge`"
-);
+PyDoc_STRVAR(
+ bpy_bmloop_edge_doc,
+ "The loop's edge (between this loop and the next), (read-only).\n\n:type: :class:`BMEdge`");
static PyObject *bpy_bmloop_edge_get(BPy_BMLoop *self)
{
- BPY_BM_CHECK_OBJ(self);
- return BPy_BMEdge_CreatePyObject(self->bm, self->l->e);
+ BPY_BM_CHECK_OBJ(self);
+ return BPy_BMEdge_CreatePyObject(self->bm, self->l->e);
}
-
PyDoc_STRVAR(bpy_bmloop_face_doc,
-"The face this loop makes (read-only).\n\n:type: :class:`BMFace`"
-);
+ "The face this loop makes (read-only).\n\n:type: :class:`BMFace`");
static PyObject *bpy_bmloop_face_get(BPy_BMLoop *self)
{
- BPY_BM_CHECK_OBJ(self);
- return BPy_BMFace_CreatePyObject(self->bm, self->l->f);
+ BPY_BM_CHECK_OBJ(self);
+ return BPy_BMFace_CreatePyObject(self->bm, self->l->f);
}
PyDoc_STRVAR(bpy_bmloop_link_loop_next_doc,
-"The next face corner (read-only).\n\n:type: :class:`BMLoop`"
-);
+ "The next face corner (read-only).\n\n:type: :class:`BMLoop`");
static PyObject *bpy_bmloop_link_loop_next_get(BPy_BMLoop *self)
{
- BPY_BM_CHECK_OBJ(self);
- return BPy_BMLoop_CreatePyObject(self->bm, self->l->next);
+ BPY_BM_CHECK_OBJ(self);
+ return BPy_BMLoop_CreatePyObject(self->bm, self->l->next);
}
PyDoc_STRVAR(bpy_bmloop_link_loop_prev_doc,
-"The previous face corner (read-only).\n\n:type: :class:`BMLoop`"
-);
+ "The previous face corner (read-only).\n\n:type: :class:`BMLoop`");
static PyObject *bpy_bmloop_link_loop_prev_get(BPy_BMLoop *self)
{
- BPY_BM_CHECK_OBJ(self);
- return BPy_BMLoop_CreatePyObject(self->bm, self->l->prev);
+ BPY_BM_CHECK_OBJ(self);
+ return BPy_BMLoop_CreatePyObject(self->bm, self->l->prev);
}
PyDoc_STRVAR(bpy_bmloop_link_loop_radial_next_doc,
-"The next loop around the edge (read-only).\n\n:type: :class:`BMLoop`"
-);
+ "The next loop around the edge (read-only).\n\n:type: :class:`BMLoop`");
static PyObject *bpy_bmloop_link_loop_radial_next_get(BPy_BMLoop *self)
{
- BPY_BM_CHECK_OBJ(self);
- return BPy_BMLoop_CreatePyObject(self->bm, self->l->radial_next);
+ BPY_BM_CHECK_OBJ(self);
+ return BPy_BMLoop_CreatePyObject(self->bm, self->l->radial_next);
}
PyDoc_STRVAR(bpy_bmloop_link_loop_radial_prev_doc,
-"The previous loop around the edge (read-only).\n\n:type: :class:`BMLoop`"
-);
+ "The previous loop around the edge (read-only).\n\n:type: :class:`BMLoop`");
static PyObject *bpy_bmloop_link_loop_radial_prev_get(BPy_BMLoop *self)
{
- BPY_BM_CHECK_OBJ(self);
- return BPy_BMLoop_CreatePyObject(self->bm, self->l->radial_prev);
+ BPY_BM_CHECK_OBJ(self);
+ return BPy_BMLoop_CreatePyObject(self->bm, self->l->radial_prev);
}
PyDoc_STRVAR(bpy_bmloop_is_convex_doc,
-"True when this loop is at the convex corner of a face, depends on a valid face normal (read-only).\n\n:type: boolean"
-);
+ "True when this loop is at the convex corner of a face, depends on a valid face "
+ "normal (read-only).\n\n:type: boolean");
static PyObject *bpy_bmloop_is_convex_get(BPy_BMLoop *self)
{
- BPY_BM_CHECK_OBJ(self);
- return PyBool_FromLong(BM_loop_is_convex(self->l));
+ BPY_BM_CHECK_OBJ(self);
+ return PyBool_FromLong(BM_loop_is_convex(self->l));
}
/* ElemSeq
@@ -594,1935 +559,2096 @@ static PyObject *bpy_bmloop_is_convex_get(BPy_BMLoop *self)
/* note: use for bmvert/edge/face/loop seq's use these, not bmelemseq directly */
PyDoc_STRVAR(bpy_bmelemseq_layers_vert_doc,
-"custom-data layers (read-only).\n\n:type: :class:`BMLayerAccessVert`"
-);
+ "custom-data layers (read-only).\n\n:type: :class:`BMLayerAccessVert`");
PyDoc_STRVAR(bpy_bmelemseq_layers_edge_doc,
-"custom-data layers (read-only).\n\n:type: :class:`BMLayerAccessEdge`"
-);
+ "custom-data layers (read-only).\n\n:type: :class:`BMLayerAccessEdge`");
PyDoc_STRVAR(bpy_bmelemseq_layers_face_doc,
-"custom-data layers (read-only).\n\n:type: :class:`BMLayerAccessFace`"
-);
+ "custom-data layers (read-only).\n\n:type: :class:`BMLayerAccessFace`");
PyDoc_STRVAR(bpy_bmelemseq_layers_loop_doc,
-"custom-data layers (read-only).\n\n:type: :class:`BMLayerAccessLoop`"
-);
+ "custom-data layers (read-only).\n\n:type: :class:`BMLayerAccessLoop`");
static PyObject *bpy_bmelemseq_layers_get(BPy_BMElemSeq *self, void *htype)
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- return BPy_BMLayerAccess_CreatePyObject(self->bm, POINTER_AS_INT(htype));
+ return BPy_BMLayerAccess_CreatePyObject(self->bm, POINTER_AS_INT(htype));
}
/* FaceSeq
* ^^^^^^^ */
-PyDoc_STRVAR(bpy_bmfaceseq_active_doc,
-"active face.\n\n:type: :class:`BMFace` or None"
-);
+PyDoc_STRVAR(bpy_bmfaceseq_active_doc, "active face.\n\n:type: :class:`BMFace` or None");
static PyObject *bpy_bmfaceseq_active_get(BPy_BMElemSeq *self, void *UNUSED(closure))
{
- BMesh *bm = self->bm;
- BPY_BM_CHECK_OBJ(self);
+ BMesh *bm = self->bm;
+ BPY_BM_CHECK_OBJ(self);
- if (bm->act_face) {
- return BPy_BMElem_CreatePyObject(bm, (BMHeader *)bm->act_face);
- }
- else {
- Py_RETURN_NONE;
- }
+ if (bm->act_face) {
+ return BPy_BMElem_CreatePyObject(bm, (BMHeader *)bm->act_face);
+ }
+ else {
+ Py_RETURN_NONE;
+ }
}
static int bpy_bmfaceseq_active_set(BPy_BMElem *self, PyObject *value, void *UNUSED(closure))
{
- BMesh *bm = self->bm;
- if (value == Py_None) {
- bm->act_face = NULL;
- return 0;
- }
- else if (BPy_BMFace_Check(value)) {
- BPY_BM_CHECK_SOURCE_INT(bm, "faces.active = f", value);
-
- bm->act_face = ((BPy_BMFace *)value)->f;
- return 0;
- }
- else {
- PyErr_Format(PyExc_TypeError,
- "faces.active = f: expected BMFace or None, not %.200s",
- Py_TYPE(value)->tp_name);
- return -1;
- }
+ BMesh *bm = self->bm;
+ if (value == Py_None) {
+ bm->act_face = NULL;
+ return 0;
+ }
+ else if (BPy_BMFace_Check(value)) {
+ BPY_BM_CHECK_SOURCE_INT(bm, "faces.active = f", value);
+
+ bm->act_face = ((BPy_BMFace *)value)->f;
+ return 0;
+ }
+ else {
+ PyErr_Format(PyExc_TypeError,
+ "faces.active = f: expected BMFace or None, not %.200s",
+ Py_TYPE(value)->tp_name);
+ return -1;
+ }
}
static PyGetSetDef bpy_bmesh_getseters[] = {
- {(char *)"verts", (getter)bpy_bmvertseq_get, (setter)NULL, (char *)bpy_bmvertseq_doc, NULL},
- {(char *)"edges", (getter)bpy_bmedgeseq_get, (setter)NULL, (char *)bpy_bmedgeseq_doc, NULL},
- {(char *)"faces", (getter)bpy_bmfaceseq_get, (setter)NULL, (char *)bpy_bmfaceseq_doc, NULL},
- {(char *)"loops", (getter)bpy_bmloopseq_get, (setter)NULL, (char *)bpy_bmloopseq_doc, NULL},
- {(char *)"select_mode", (getter)bpy_bmesh_select_mode_get, (setter)bpy_bmesh_select_mode_set, (char *)bpy_bmesh_select_mode_doc, NULL},
-
- {(char *)"select_history", (getter)bpy_bmesh_select_history_get, (setter)bpy_bmesh_select_history_set, (char *)bpy_bmesh_select_history_doc, NULL},
-
- /* readonly checks */
- {(char *)"is_wrapped", (getter)bpy_bmesh_is_wrapped_get, (setter)NULL, (char *)bpy_bmesh_is_wrapped_doc, NULL}, /* as with mathutils */
- {(char *)"is_valid", (getter)bpy_bm_is_valid_get, (setter)NULL, (char *)bpy_bm_is_valid_doc, NULL},
-
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ {(char *)"verts", (getter)bpy_bmvertseq_get, (setter)NULL, (char *)bpy_bmvertseq_doc, NULL},
+ {(char *)"edges", (getter)bpy_bmedgeseq_get, (setter)NULL, (char *)bpy_bmedgeseq_doc, NULL},
+ {(char *)"faces", (getter)bpy_bmfaceseq_get, (setter)NULL, (char *)bpy_bmfaceseq_doc, NULL},
+ {(char *)"loops", (getter)bpy_bmloopseq_get, (setter)NULL, (char *)bpy_bmloopseq_doc, NULL},
+ {(char *)"select_mode",
+ (getter)bpy_bmesh_select_mode_get,
+ (setter)bpy_bmesh_select_mode_set,
+ (char *)bpy_bmesh_select_mode_doc,
+ NULL},
+
+ {(char *)"select_history",
+ (getter)bpy_bmesh_select_history_get,
+ (setter)bpy_bmesh_select_history_set,
+ (char *)bpy_bmesh_select_history_doc,
+ NULL},
+
+ /* readonly checks */
+ {(char *)"is_wrapped",
+ (getter)bpy_bmesh_is_wrapped_get,
+ (setter)NULL,
+ (char *)bpy_bmesh_is_wrapped_doc,
+ NULL}, /* as with mathutils */
+ {(char *)"is_valid",
+ (getter)bpy_bm_is_valid_get,
+ (setter)NULL,
+ (char *)bpy_bm_is_valid_doc,
+ NULL},
+
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyGetSetDef bpy_bmvert_getseters[] = {
- /* generic */
- {(char *)"select", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_select_doc, (void *)BM_ELEM_SELECT},
- {(char *)"hide", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_hide_doc, (void *)BM_ELEM_HIDDEN},
- {(char *)"tag", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_tag_doc, (void *)BM_ELEM_TAG},
- {(char *)"index", (getter)bpy_bm_elem_index_get, (setter)bpy_bm_elem_index_set, (char *)bpy_bm_elem_index_doc, NULL},
-
- {(char *)"co", (getter)bpy_bmvert_co_get, (setter)bpy_bmvert_co_set, (char *)bpy_bmvert_co_doc, NULL},
- {(char *)"normal", (getter)bpy_bmvert_normal_get, (setter)bpy_bmvert_normal_set, (char *)bpy_bmvert_normal_doc, NULL},
-
- /* connectivity data */
- {(char *)"link_edges", (getter)bpy_bmelemseq_elem_get, (setter)NULL, (char *)bpy_bmvert_link_edges_doc, (void *)BM_EDGES_OF_VERT},
- {(char *)"link_faces", (getter)bpy_bmelemseq_elem_get, (setter)NULL, (char *)bpy_bmvert_link_faces_doc, (void *)BM_FACES_OF_VERT},
- {(char *)"link_loops", (getter)bpy_bmelemseq_elem_get, (setter)NULL, (char *)bpy_bmvert_link_loops_doc, (void *)BM_LOOPS_OF_VERT},
-
- /* readonly checks */
- {(char *)"is_manifold", (getter)bpy_bmvert_is_manifold_get, (setter)NULL, (char *)bpy_bmvert_is_manifold_doc, NULL},
- {(char *)"is_wire", (getter)bpy_bmvert_is_wire_get, (setter)NULL, (char *)bpy_bmvert_is_wire_doc, NULL},
- {(char *)"is_boundary", (getter)bpy_bmvert_is_boundary_get, (setter)NULL, (char *)bpy_bmvert_is_boundary_doc, NULL},
- {(char *)"is_valid", (getter)bpy_bm_is_valid_get, (setter)NULL, (char *)bpy_bm_is_valid_doc, NULL},
-
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ /* generic */
+ {(char *)"select",
+ (getter)bpy_bm_elem_hflag_get,
+ (setter)bpy_bm_elem_hflag_set,
+ (char *)bpy_bm_elem_select_doc,
+ (void *)BM_ELEM_SELECT},
+ {(char *)"hide",
+ (getter)bpy_bm_elem_hflag_get,
+ (setter)bpy_bm_elem_hflag_set,
+ (char *)bpy_bm_elem_hide_doc,
+ (void *)BM_ELEM_HIDDEN},
+ {(char *)"tag",
+ (getter)bpy_bm_elem_hflag_get,
+ (setter)bpy_bm_elem_hflag_set,
+ (char *)bpy_bm_elem_tag_doc,
+ (void *)BM_ELEM_TAG},
+ {(char *)"index",
+ (getter)bpy_bm_elem_index_get,
+ (setter)bpy_bm_elem_index_set,
+ (char *)bpy_bm_elem_index_doc,
+ NULL},
+
+ {(char *)"co",
+ (getter)bpy_bmvert_co_get,
+ (setter)bpy_bmvert_co_set,
+ (char *)bpy_bmvert_co_doc,
+ NULL},
+ {(char *)"normal",
+ (getter)bpy_bmvert_normal_get,
+ (setter)bpy_bmvert_normal_set,
+ (char *)bpy_bmvert_normal_doc,
+ NULL},
+
+ /* connectivity data */
+ {(char *)"link_edges",
+ (getter)bpy_bmelemseq_elem_get,
+ (setter)NULL,
+ (char *)bpy_bmvert_link_edges_doc,
+ (void *)BM_EDGES_OF_VERT},
+ {(char *)"link_faces",
+ (getter)bpy_bmelemseq_elem_get,
+ (setter)NULL,
+ (char *)bpy_bmvert_link_faces_doc,
+ (void *)BM_FACES_OF_VERT},
+ {(char *)"link_loops",
+ (getter)bpy_bmelemseq_elem_get,
+ (setter)NULL,
+ (char *)bpy_bmvert_link_loops_doc,
+ (void *)BM_LOOPS_OF_VERT},
+
+ /* readonly checks */
+ {(char *)"is_manifold",
+ (getter)bpy_bmvert_is_manifold_get,
+ (setter)NULL,
+ (char *)bpy_bmvert_is_manifold_doc,
+ NULL},
+ {(char *)"is_wire",
+ (getter)bpy_bmvert_is_wire_get,
+ (setter)NULL,
+ (char *)bpy_bmvert_is_wire_doc,
+ NULL},
+ {(char *)"is_boundary",
+ (getter)bpy_bmvert_is_boundary_get,
+ (setter)NULL,
+ (char *)bpy_bmvert_is_boundary_doc,
+ NULL},
+ {(char *)"is_valid",
+ (getter)bpy_bm_is_valid_get,
+ (setter)NULL,
+ (char *)bpy_bm_is_valid_doc,
+ NULL},
+
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyGetSetDef bpy_bmedge_getseters[] = {
- /* generic */
- {(char *)"select", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_select_doc, (void *)BM_ELEM_SELECT},
- {(char *)"hide", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_hide_doc, (void *)BM_ELEM_HIDDEN},
- {(char *)"tag", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_tag_doc, (void *)BM_ELEM_TAG},
- {(char *)"index", (getter)bpy_bm_elem_index_get, (setter)bpy_bm_elem_index_set, (char *)bpy_bm_elem_index_doc, NULL},
-
- {(char *)"smooth", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_smooth_doc, (void *)BM_ELEM_SMOOTH},
- {(char *)"seam", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_seam_doc, (void *)BM_ELEM_SEAM},
-
- /* connectivity data */
- {(char *)"verts", (getter)bpy_bmelemseq_elem_get, (setter)NULL, (char *)bpy_bmedge_verts_doc, (void *)BM_VERTS_OF_EDGE},
-
- {(char *)"link_faces", (getter)bpy_bmelemseq_elem_get, (setter)NULL, (char *)bpy_bmedge_link_faces_doc, (void *)BM_FACES_OF_EDGE},
- {(char *)"link_loops", (getter)bpy_bmelemseq_elem_get, (setter)NULL, (char *)bpy_bmedge_link_loops_doc, (void *)BM_LOOPS_OF_EDGE},
-
- /* readonly checks */
- {(char *)"is_manifold", (getter)bpy_bmedge_is_manifold_get, (setter)NULL, (char *)bpy_bmedge_is_manifold_doc, NULL},
- {(char *)"is_contiguous", (getter)bpy_bmedge_is_contiguous_get, (setter)NULL, (char *)bpy_bmedge_is_contiguous_doc, NULL},
- {(char *)"is_convex", (getter)bpy_bmedge_is_convex_get, (setter)NULL, (char *)bpy_bmedge_is_convex_doc, NULL},
- {(char *)"is_wire", (getter)bpy_bmedge_is_wire_get, (setter)NULL, (char *)bpy_bmedge_is_wire_doc, NULL},
- {(char *)"is_boundary", (getter)bpy_bmedge_is_boundary_get, (setter)NULL, (char *)bpy_bmedge_is_boundary_doc, NULL},
- {(char *)"is_valid", (getter)bpy_bm_is_valid_get, (setter)NULL, (char *)bpy_bm_is_valid_doc, NULL},
-
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ /* generic */
+ {(char *)"select",
+ (getter)bpy_bm_elem_hflag_get,
+ (setter)bpy_bm_elem_hflag_set,
+ (char *)bpy_bm_elem_select_doc,
+ (void *)BM_ELEM_SELECT},
+ {(char *)"hide",
+ (getter)bpy_bm_elem_hflag_get,
+ (setter)bpy_bm_elem_hflag_set,
+ (char *)bpy_bm_elem_hide_doc,
+ (void *)BM_ELEM_HIDDEN},
+ {(char *)"tag",
+ (getter)bpy_bm_elem_hflag_get,
+ (setter)bpy_bm_elem_hflag_set,
+ (char *)bpy_bm_elem_tag_doc,
+ (void *)BM_ELEM_TAG},
+ {(char *)"index",
+ (getter)bpy_bm_elem_index_get,
+ (setter)bpy_bm_elem_index_set,
+ (char *)bpy_bm_elem_index_doc,
+ NULL},
+
+ {(char *)"smooth",
+ (getter)bpy_bm_elem_hflag_get,
+ (setter)bpy_bm_elem_hflag_set,
+ (char *)bpy_bm_elem_smooth_doc,
+ (void *)BM_ELEM_SMOOTH},
+ {(char *)"seam",
+ (getter)bpy_bm_elem_hflag_get,
+ (setter)bpy_bm_elem_hflag_set,
+ (char *)bpy_bm_elem_seam_doc,
+ (void *)BM_ELEM_SEAM},
+
+ /* connectivity data */
+ {(char *)"verts",
+ (getter)bpy_bmelemseq_elem_get,
+ (setter)NULL,
+ (char *)bpy_bmedge_verts_doc,
+ (void *)BM_VERTS_OF_EDGE},
+
+ {(char *)"link_faces",
+ (getter)bpy_bmelemseq_elem_get,
+ (setter)NULL,
+ (char *)bpy_bmedge_link_faces_doc,
+ (void *)BM_FACES_OF_EDGE},
+ {(char *)"link_loops",
+ (getter)bpy_bmelemseq_elem_get,
+ (setter)NULL,
+ (char *)bpy_bmedge_link_loops_doc,
+ (void *)BM_LOOPS_OF_EDGE},
+
+ /* readonly checks */
+ {(char *)"is_manifold",
+ (getter)bpy_bmedge_is_manifold_get,
+ (setter)NULL,
+ (char *)bpy_bmedge_is_manifold_doc,
+ NULL},
+ {(char *)"is_contiguous",
+ (getter)bpy_bmedge_is_contiguous_get,
+ (setter)NULL,
+ (char *)bpy_bmedge_is_contiguous_doc,
+ NULL},
+ {(char *)"is_convex",
+ (getter)bpy_bmedge_is_convex_get,
+ (setter)NULL,
+ (char *)bpy_bmedge_is_convex_doc,
+ NULL},
+ {(char *)"is_wire",
+ (getter)bpy_bmedge_is_wire_get,
+ (setter)NULL,
+ (char *)bpy_bmedge_is_wire_doc,
+ NULL},
+ {(char *)"is_boundary",
+ (getter)bpy_bmedge_is_boundary_get,
+ (setter)NULL,
+ (char *)bpy_bmedge_is_boundary_doc,
+ NULL},
+ {(char *)"is_valid",
+ (getter)bpy_bm_is_valid_get,
+ (setter)NULL,
+ (char *)bpy_bm_is_valid_doc,
+ NULL},
+
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyGetSetDef bpy_bmface_getseters[] = {
- /* generic */
- {(char *)"select", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_select_doc, (void *)BM_ELEM_SELECT},
- {(char *)"hide", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_hide_doc, (void *)BM_ELEM_HIDDEN},
- {(char *)"tag", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_tag_doc, (void *)BM_ELEM_TAG},
- {(char *)"index", (getter)bpy_bm_elem_index_get, (setter)bpy_bm_elem_index_set, (char *)bpy_bm_elem_index_doc, NULL},
-
- {(char *)"smooth", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_smooth_doc, (void *)BM_ELEM_SMOOTH},
-
- {(char *)"normal", (getter)bpy_bmface_normal_get, (setter)bpy_bmface_normal_set, (char *)bpy_bmface_normal_doc, NULL},
-
- {(char *)"material_index", (getter)bpy_bmface_material_index_get, (setter)bpy_bmface_material_index_set, (char *)bpy_bmface_material_index_doc, NULL},
-
- /* connectivity data */
- {(char *)"verts", (getter)bpy_bmelemseq_elem_get, (setter)NULL, (char *)bpy_bmface_verts_doc, (void *)BM_VERTS_OF_FACE},
- {(char *)"edges", (getter)bpy_bmelemseq_elem_get, (setter)NULL, (char *)bpy_bmface_edges_doc, (void *)BM_EDGES_OF_FACE},
- {(char *)"loops", (getter)bpy_bmelemseq_elem_get, (setter)NULL, (char *)bpy_bmface_loops_doc, (void *)BM_LOOPS_OF_FACE},
-
- /* readonly checks */
- {(char *)"is_valid", (getter)bpy_bm_is_valid_get, (setter)NULL, (char *)bpy_bm_is_valid_doc, NULL},
-
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ /* generic */
+ {(char *)"select",
+ (getter)bpy_bm_elem_hflag_get,
+ (setter)bpy_bm_elem_hflag_set,
+ (char *)bpy_bm_elem_select_doc,
+ (void *)BM_ELEM_SELECT},
+ {(char *)"hide",
+ (getter)bpy_bm_elem_hflag_get,
+ (setter)bpy_bm_elem_hflag_set,
+ (char *)bpy_bm_elem_hide_doc,
+ (void *)BM_ELEM_HIDDEN},
+ {(char *)"tag",
+ (getter)bpy_bm_elem_hflag_get,
+ (setter)bpy_bm_elem_hflag_set,
+ (char *)bpy_bm_elem_tag_doc,
+ (void *)BM_ELEM_TAG},
+ {(char *)"index",
+ (getter)bpy_bm_elem_index_get,
+ (setter)bpy_bm_elem_index_set,
+ (char *)bpy_bm_elem_index_doc,
+ NULL},
+
+ {(char *)"smooth",
+ (getter)bpy_bm_elem_hflag_get,
+ (setter)bpy_bm_elem_hflag_set,
+ (char *)bpy_bm_elem_smooth_doc,
+ (void *)BM_ELEM_SMOOTH},
+
+ {(char *)"normal",
+ (getter)bpy_bmface_normal_get,
+ (setter)bpy_bmface_normal_set,
+ (char *)bpy_bmface_normal_doc,
+ NULL},
+
+ {(char *)"material_index",
+ (getter)bpy_bmface_material_index_get,
+ (setter)bpy_bmface_material_index_set,
+ (char *)bpy_bmface_material_index_doc,
+ NULL},
+
+ /* connectivity data */
+ {(char *)"verts",
+ (getter)bpy_bmelemseq_elem_get,
+ (setter)NULL,
+ (char *)bpy_bmface_verts_doc,
+ (void *)BM_VERTS_OF_FACE},
+ {(char *)"edges",
+ (getter)bpy_bmelemseq_elem_get,
+ (setter)NULL,
+ (char *)bpy_bmface_edges_doc,
+ (void *)BM_EDGES_OF_FACE},
+ {(char *)"loops",
+ (getter)bpy_bmelemseq_elem_get,
+ (setter)NULL,
+ (char *)bpy_bmface_loops_doc,
+ (void *)BM_LOOPS_OF_FACE},
+
+ /* readonly checks */
+ {(char *)"is_valid",
+ (getter)bpy_bm_is_valid_get,
+ (setter)NULL,
+ (char *)bpy_bm_is_valid_doc,
+ NULL},
+
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyGetSetDef bpy_bmloop_getseters[] = {
- /* generic */
- /* flags are available but not used for loops. */
- // {(char *)"select", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_select_doc, (void *)BM_ELEM_SELECT},
- // {(char *)"hide", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_hide_doc, (void *)BM_ELEM_HIDDEN},
- {(char *)"tag", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_tag_doc, (void *)BM_ELEM_TAG},
- {(char *)"index", (getter)bpy_bm_elem_index_get, (setter)bpy_bm_elem_index_set, (char *)bpy_bm_elem_index_doc, NULL},
-
- {(char *)"vert", (getter)bpy_bmloop_vert_get, (setter)NULL, (char *)bpy_bmloop_vert_doc, NULL},
- {(char *)"edge", (getter)bpy_bmloop_edge_get, (setter)NULL, (char *)bpy_bmloop_edge_doc, NULL},
- {(char *)"face", (getter)bpy_bmloop_face_get, (setter)NULL, (char *)bpy_bmloop_face_doc, NULL},
-
- /* connectivity data */
- {(char *)"link_loops", (getter)bpy_bmelemseq_elem_get, (setter)NULL, (char *)bpy_bmloops_link_loops_doc, (void *)BM_LOOPS_OF_LOOP},
- {(char *)"link_loop_next", (getter)bpy_bmloop_link_loop_next_get, (setter)NULL, (char *)bpy_bmloop_link_loop_next_doc, NULL},
- {(char *)"link_loop_prev", (getter)bpy_bmloop_link_loop_prev_get, (setter)NULL, (char *)bpy_bmloop_link_loop_prev_doc, NULL},
- {(char *)"link_loop_radial_next", (getter)bpy_bmloop_link_loop_radial_next_get, (setter)NULL, (char *)bpy_bmloop_link_loop_radial_next_doc, NULL},
- {(char *)"link_loop_radial_prev", (getter)bpy_bmloop_link_loop_radial_prev_get, (setter)NULL, (char *)bpy_bmloop_link_loop_radial_prev_doc, NULL},
-
- /* readonly checks */
- {(char *)"is_convex", (getter)bpy_bmloop_is_convex_get, (setter)NULL, (char *)bpy_bmloop_is_convex_doc, NULL},
- {(char *)"is_valid", (getter)bpy_bm_is_valid_get, (setter)NULL, (char *)bpy_bm_is_valid_doc, NULL},
-
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ /* generic */
+ /* flags are available but not used for loops. */
+ // {(char *)"select", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_select_doc, (void *)BM_ELEM_SELECT},
+ // {(char *)"hide", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_hide_doc, (void *)BM_ELEM_HIDDEN},
+ {(char *)"tag",
+ (getter)bpy_bm_elem_hflag_get,
+ (setter)bpy_bm_elem_hflag_set,
+ (char *)bpy_bm_elem_tag_doc,
+ (void *)BM_ELEM_TAG},
+ {(char *)"index",
+ (getter)bpy_bm_elem_index_get,
+ (setter)bpy_bm_elem_index_set,
+ (char *)bpy_bm_elem_index_doc,
+ NULL},
+
+ {(char *)"vert", (getter)bpy_bmloop_vert_get, (setter)NULL, (char *)bpy_bmloop_vert_doc, NULL},
+ {(char *)"edge", (getter)bpy_bmloop_edge_get, (setter)NULL, (char *)bpy_bmloop_edge_doc, NULL},
+ {(char *)"face", (getter)bpy_bmloop_face_get, (setter)NULL, (char *)bpy_bmloop_face_doc, NULL},
+
+ /* connectivity data */
+ {(char *)"link_loops",
+ (getter)bpy_bmelemseq_elem_get,
+ (setter)NULL,
+ (char *)bpy_bmloops_link_loops_doc,
+ (void *)BM_LOOPS_OF_LOOP},
+ {(char *)"link_loop_next",
+ (getter)bpy_bmloop_link_loop_next_get,
+ (setter)NULL,
+ (char *)bpy_bmloop_link_loop_next_doc,
+ NULL},
+ {(char *)"link_loop_prev",
+ (getter)bpy_bmloop_link_loop_prev_get,
+ (setter)NULL,
+ (char *)bpy_bmloop_link_loop_prev_doc,
+ NULL},
+ {(char *)"link_loop_radial_next",
+ (getter)bpy_bmloop_link_loop_radial_next_get,
+ (setter)NULL,
+ (char *)bpy_bmloop_link_loop_radial_next_doc,
+ NULL},
+ {(char *)"link_loop_radial_prev",
+ (getter)bpy_bmloop_link_loop_radial_prev_get,
+ (setter)NULL,
+ (char *)bpy_bmloop_link_loop_radial_prev_doc,
+ NULL},
+
+ /* readonly checks */
+ {(char *)"is_convex",
+ (getter)bpy_bmloop_is_convex_get,
+ (setter)NULL,
+ (char *)bpy_bmloop_is_convex_doc,
+ NULL},
+ {(char *)"is_valid",
+ (getter)bpy_bm_is_valid_get,
+ (setter)NULL,
+ (char *)bpy_bm_is_valid_doc,
+ NULL},
+
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyGetSetDef bpy_bmvertseq_getseters[] = {
- {(char *)"layers", (getter)bpy_bmelemseq_layers_get, (setter)NULL, (char *)bpy_bmelemseq_layers_vert_doc, (void *)BM_VERT},
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ {(char *)"layers",
+ (getter)bpy_bmelemseq_layers_get,
+ (setter)NULL,
+ (char *)bpy_bmelemseq_layers_vert_doc,
+ (void *)BM_VERT},
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyGetSetDef bpy_bmedgeseq_getseters[] = {
- {(char *)"layers", (getter)bpy_bmelemseq_layers_get, (setter)NULL, (char *)bpy_bmelemseq_layers_edge_doc, (void *)BM_EDGE},
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ {(char *)"layers",
+ (getter)bpy_bmelemseq_layers_get,
+ (setter)NULL,
+ (char *)bpy_bmelemseq_layers_edge_doc,
+ (void *)BM_EDGE},
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyGetSetDef bpy_bmfaceseq_getseters[] = {
- {(char *)"layers", (getter)bpy_bmelemseq_layers_get, (setter)NULL, (char *)bpy_bmelemseq_layers_face_doc, (void *)BM_FACE},
- /* face only */
- {(char *)"active", (getter)bpy_bmfaceseq_active_get, (setter)bpy_bmfaceseq_active_set, (char *)bpy_bmfaceseq_active_doc, NULL},
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ {(char *)"layers",
+ (getter)bpy_bmelemseq_layers_get,
+ (setter)NULL,
+ (char *)bpy_bmelemseq_layers_face_doc,
+ (void *)BM_FACE},
+ /* face only */
+ {(char *)"active",
+ (getter)bpy_bmfaceseq_active_get,
+ (setter)bpy_bmfaceseq_active_set,
+ (char *)bpy_bmfaceseq_active_doc,
+ NULL},
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyGetSetDef bpy_bmloopseq_getseters[] = {
- {(char *)"layers", (getter)bpy_bmelemseq_layers_get, (setter)NULL, (char *)bpy_bmelemseq_layers_loop_doc, (void *)BM_LOOP},
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ {(char *)"layers",
+ (getter)bpy_bmelemseq_layers_get,
+ (setter)NULL,
+ (char *)bpy_bmelemseq_layers_loop_doc,
+ (void *)BM_LOOP},
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
-
/* Methods
* ======= */
-
/* Mesh
* ---- */
PyDoc_STRVAR(bpy_bmesh_copy_doc,
-".. method:: copy()\n"
-"\n"
-" :return: A copy of this BMesh.\n"
-" :rtype: :class:`BMesh`\n"
-);
+ ".. method:: copy()\n"
+ "\n"
+ " :return: A copy of this BMesh.\n"
+ " :rtype: :class:`BMesh`\n");
static PyObject *bpy_bmesh_copy(BPy_BMesh *self)
{
- BMesh *bm;
- BMesh *bm_copy;
+ BMesh *bm;
+ BMesh *bm_copy;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- bm = self->bm;
+ bm = self->bm;
- bm_copy = BM_mesh_copy(bm);
+ bm_copy = BM_mesh_copy(bm);
- if (bm_copy) {
- return BPy_BMesh_CreatePyObject(bm_copy, BPY_BMFLAG_NOP);
- }
- else {
- PyErr_SetString(PyExc_SystemError, "Unable to copy BMesh, internal error");
- return NULL;
- }
+ if (bm_copy) {
+ return BPy_BMesh_CreatePyObject(bm_copy, BPY_BMFLAG_NOP);
+ }
+ else {
+ PyErr_SetString(PyExc_SystemError, "Unable to copy BMesh, internal error");
+ return NULL;
+ }
}
PyDoc_STRVAR(bpy_bmesh_clear_doc,
-".. method:: clear()\n"
-"\n"
-" Clear all mesh data.\n"
-);
+ ".. method:: clear()\n"
+ "\n"
+ " Clear all mesh data.\n");
static PyObject *bpy_bmesh_clear(BPy_BMesh *self)
{
- BMesh *bm;
+ BMesh *bm;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- bm = self->bm;
+ bm = self->bm;
- BM_mesh_clear(bm);
+ BM_mesh_clear(bm);
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
-PyDoc_STRVAR(bpy_bmesh_free_doc,
-".. method:: free()\n"
-"\n"
-" Explicitly free the BMesh data from memory, causing exceptions on further access.\n"
-"\n"
-" .. note::\n"
-"\n"
-" The BMesh is freed automatically, typically when the script finishes executing.\n"
-" However in some cases its hard to predict when this will be and its useful to\n"
-" explicitly free the data.\n"
-);
+PyDoc_STRVAR(
+ bpy_bmesh_free_doc,
+ ".. method:: free()\n"
+ "\n"
+ " Explicitly free the BMesh data from memory, causing exceptions on further access.\n"
+ "\n"
+ " .. note::\n"
+ "\n"
+ " The BMesh is freed automatically, typically when the script finishes executing.\n"
+ " However in some cases its hard to predict when this will be and its useful to\n"
+ " explicitly free the data.\n");
static PyObject *bpy_bmesh_free(BPy_BMesh *self)
{
- if (self->bm) {
- BMesh *bm = self->bm;
+ if (self->bm) {
+ BMesh *bm = self->bm;
- bm_dealloc_editmode_warn(self);
+ bm_dealloc_editmode_warn(self);
- if ((self->flag & BPY_BMFLAG_IS_WRAPPED) == 0) {
- BM_mesh_free(bm);
- }
+ if ((self->flag & BPY_BMFLAG_IS_WRAPPED) == 0) {
+ BM_mesh_free(bm);
+ }
- bpy_bm_generic_invalidate((BPy_BMGeneric *)self);
- }
+ bpy_bm_generic_invalidate((BPy_BMGeneric *)self);
+ }
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(bpy_bmesh_to_mesh_doc,
-".. method:: to_mesh(mesh)\n"
-"\n"
-" Writes this BMesh data into an existing Mesh datablock.\n"
-"\n"
-" :arg mesh: The mesh data to write into.\n"
-" :type mesh: :class:`Mesh`\n"
-);
+ ".. method:: to_mesh(mesh)\n"
+ "\n"
+ " Writes this BMesh data into an existing Mesh datablock.\n"
+ "\n"
+ " :arg mesh: The mesh data to write into.\n"
+ " :type mesh: :class:`Mesh`\n");
static PyObject *bpy_bmesh_to_mesh(BPy_BMesh *self, PyObject *args)
{
- PyObject *py_mesh;
- Mesh *me;
- BMesh *bm;
-
- BPY_BM_CHECK_OBJ(self);
-
- if (!PyArg_ParseTuple(args, "O:to_mesh", &py_mesh) ||
- !(me = PyC_RNA_AsPointer(py_mesh, "Mesh")))
- {
- return NULL;
- }
-
- /* we could allow this but its almost certainly _not_ what script authors want */
- if (me->edit_mesh) {
- PyErr_Format(PyExc_ValueError,
- "to_mesh(): Mesh '%s' is in editmode", me->id.name + 2);
- return NULL;
- }
-
- bm = self->bm;
-
- BLI_assert(BKE_id_is_in_global_main(&me->id));
- BM_mesh_bm_to_me(
- G_MAIN, /* XXX UGLY! */
- bm, me,
- (&(struct BMeshToMeshParams){
- .calc_object_remap = true,
- }));
-
- /* we could have the user do this but if they forget blender can easy crash
- * since the references arrays for the objects derived meshes are now invalid */
- DEG_id_tag_update(&me->id, ID_RECALC_GEOMETRY);
-
- Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(bpy_bmesh_from_object_doc,
-".. method:: from_object(object, depsgraph, deform=True, cage=False, face_normals=True)\n"
-"\n"
-" Initialize this bmesh from existing object datablock (currently only meshes are supported).\n"
-"\n"
-" :arg object: The object data to load.\n"
-" :type object: :class:`Object`\n"
-" :arg deform: Apply deformation modifiers.\n"
-" :type deform: boolean\n"
-" :arg cage: Get the mesh as a deformed cage.\n"
-" :type cage: boolean\n"
-" :arg face_normals: Calculate face normals.\n"
-" :type face_normals: boolean\n"
-);
+ PyObject *py_mesh;
+ Mesh *me;
+ BMesh *bm;
+
+ BPY_BM_CHECK_OBJ(self);
+
+ if (!PyArg_ParseTuple(args, "O:to_mesh", &py_mesh) ||
+ !(me = PyC_RNA_AsPointer(py_mesh, "Mesh"))) {
+ return NULL;
+ }
+
+ /* we could allow this but its almost certainly _not_ what script authors want */
+ if (me->edit_mesh) {
+ PyErr_Format(PyExc_ValueError, "to_mesh(): Mesh '%s' is in editmode", me->id.name + 2);
+ return NULL;
+ }
+
+ bm = self->bm;
+
+ BLI_assert(BKE_id_is_in_global_main(&me->id));
+ BM_mesh_bm_to_me(G_MAIN, /* XXX UGLY! */
+ bm,
+ me,
+ (&(struct BMeshToMeshParams){
+ .calc_object_remap = true,
+ }));
+
+ /* we could have the user do this but if they forget blender can easy crash
+ * since the references arrays for the objects derived meshes are now invalid */
+ DEG_id_tag_update(&me->id, ID_RECALC_GEOMETRY);
+
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(
+ bpy_bmesh_from_object_doc,
+ ".. method:: from_object(object, depsgraph, deform=True, cage=False, face_normals=True)\n"
+ "\n"
+ " Initialize this bmesh from existing object datablock (currently only meshes are "
+ "supported).\n"
+ "\n"
+ " :arg object: The object data to load.\n"
+ " :type object: :class:`Object`\n"
+ " :arg deform: Apply deformation modifiers.\n"
+ " :type deform: boolean\n"
+ " :arg cage: Get the mesh as a deformed cage.\n"
+ " :type cage: boolean\n"
+ " :arg face_normals: Calculate face normals.\n"
+ " :type face_normals: boolean\n");
static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject *kw)
{
- static const char *kwlist[] = {"object", "depsgraph", "deform", "cage", "face_normals", NULL};
- PyObject *py_object;
- PyObject *py_depsgraph;
- Object *ob, *ob_eval;
- struct Depsgraph *depsgraph;
- struct Scene *scene_eval;
- Mesh *me_eval;
- BMesh *bm;
- bool use_deform = true;
- bool use_cage = false;
- bool use_fnorm = true;
- CustomData_MeshMasks data_masks = CD_MASK_BMESH;
-
- BPY_BM_CHECK_OBJ(self);
-
- if (!PyArg_ParseTupleAndKeywords(
- args, kw, "OO|O&O&O&:from_object", (char **)kwlist,
- &py_object, &py_depsgraph,
- PyC_ParseBool, &use_deform,
- PyC_ParseBool, &use_cage,
- PyC_ParseBool, &use_fnorm) ||
- !(ob = PyC_RNA_AsPointer(py_object, "Object")) ||
- !(depsgraph = PyC_RNA_AsPointer(py_depsgraph, "Depsgraph")))
- {
- return NULL;
- }
-
- if (ob->type != OB_MESH) {
- PyErr_SetString(PyExc_ValueError,
- "from_object(...): currently only mesh objects are supported");
- return NULL;
- }
-
- const bool use_render = DEG_get_mode(depsgraph) == DAG_EVAL_RENDER;
- scene_eval = DEG_get_evaluated_scene(depsgraph);
- ob_eval = DEG_get_evaluated_object(depsgraph, ob);
-
- /* Write the display mesh into the dummy mesh */
- if (use_deform) {
- if (use_render) {
- if (use_cage) {
- PyErr_SetString(PyExc_ValueError,
- "from_object(...): cage arg is unsupported when dependency graph evaluation mode is RENDER");
- return NULL;
- }
- else {
- me_eval = mesh_create_eval_final_render(depsgraph, scene_eval, ob_eval, &data_masks);
- }
- }
- else {
- if (use_cage) {
- me_eval = mesh_get_eval_deform(depsgraph, scene_eval, ob_eval, &data_masks);
- }
- else {
- me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &data_masks);
- }
- }
- }
- else {
- /* !use_deform */
- if (use_cage) {
- PyErr_SetString(PyExc_ValueError,
- "from_object(...): cage arg is unsupported when deform=False");
- return NULL;
- }
- else if (use_render) {
- me_eval = mesh_create_eval_no_deform_render(depsgraph, scene_eval, ob, &data_masks);
- }
- else {
- me_eval = mesh_create_eval_no_deform(depsgraph, scene_eval, ob, &data_masks);
- }
- }
-
- if (me_eval == NULL) {
- PyErr_Format(PyExc_ValueError,
- "from_object(...): Object '%s' has no usable mesh data", ob->id.name + 2);
- return NULL;
- }
-
- bm = self->bm;
-
- BM_mesh_bm_from_me(
- bm, me_eval, (&(struct BMeshFromMeshParams){
- .calc_face_normal = use_fnorm,
- }));
-
- Py_RETURN_NONE;
-}
-
-
-PyDoc_STRVAR(bpy_bmesh_from_mesh_doc,
-".. method:: from_mesh(mesh, face_normals=True, use_shape_key=False, shape_key_index=0)\n"
-"\n"
-" Initialize this bmesh from existing mesh datablock.\n"
-"\n"
-" :arg mesh: The mesh data to load.\n"
-" :type mesh: :class:`Mesh`\n"
-" :arg use_shape_key: Use the locations from a shape key.\n"
-" :type use_shape_key: boolean\n"
-" :arg shape_key_index: The shape key index to use.\n"
-" :type shape_key_index: int\n"
-"\n"
-" .. note::\n"
-"\n"
-" Multiple calls can be used to join multiple meshes.\n"
-"\n"
-" Custom-data layers are only copied from ``mesh`` on initialization.\n"
-" Further calls will copy custom-data to matching layers, layers missing on the target mesh wont be added.\n"
-);
+ static const char *kwlist[] = {"object", "depsgraph", "deform", "cage", "face_normals", NULL};
+ PyObject *py_object;
+ PyObject *py_depsgraph;
+ Object *ob, *ob_eval;
+ struct Depsgraph *depsgraph;
+ struct Scene *scene_eval;
+ Mesh *me_eval;
+ BMesh *bm;
+ bool use_deform = true;
+ bool use_cage = false;
+ bool use_fnorm = true;
+ CustomData_MeshMasks data_masks = CD_MASK_BMESH;
+
+ BPY_BM_CHECK_OBJ(self);
+
+ if (!PyArg_ParseTupleAndKeywords(args,
+ kw,
+ "OO|O&O&O&:from_object",
+ (char **)kwlist,
+ &py_object,
+ &py_depsgraph,
+ PyC_ParseBool,
+ &use_deform,
+ PyC_ParseBool,
+ &use_cage,
+ PyC_ParseBool,
+ &use_fnorm) ||
+ !(ob = PyC_RNA_AsPointer(py_object, "Object")) ||
+ !(depsgraph = PyC_RNA_AsPointer(py_depsgraph, "Depsgraph"))) {
+ return NULL;
+ }
+
+ if (ob->type != OB_MESH) {
+ PyErr_SetString(PyExc_ValueError,
+ "from_object(...): currently only mesh objects are supported");
+ return NULL;
+ }
+
+ const bool use_render = DEG_get_mode(depsgraph) == DAG_EVAL_RENDER;
+ scene_eval = DEG_get_evaluated_scene(depsgraph);
+ ob_eval = DEG_get_evaluated_object(depsgraph, ob);
+
+ /* Write the display mesh into the dummy mesh */
+ if (use_deform) {
+ if (use_render) {
+ if (use_cage) {
+ PyErr_SetString(PyExc_ValueError,
+ "from_object(...): cage arg is unsupported when dependency graph "
+ "evaluation mode is RENDER");
+ return NULL;
+ }
+ else {
+ me_eval = mesh_create_eval_final_render(depsgraph, scene_eval, ob_eval, &data_masks);
+ }
+ }
+ else {
+ if (use_cage) {
+ me_eval = mesh_get_eval_deform(depsgraph, scene_eval, ob_eval, &data_masks);
+ }
+ else {
+ me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &data_masks);
+ }
+ }
+ }
+ else {
+ /* !use_deform */
+ if (use_cage) {
+ PyErr_SetString(PyExc_ValueError,
+ "from_object(...): cage arg is unsupported when deform=False");
+ return NULL;
+ }
+ else if (use_render) {
+ me_eval = mesh_create_eval_no_deform_render(depsgraph, scene_eval, ob, &data_masks);
+ }
+ else {
+ me_eval = mesh_create_eval_no_deform(depsgraph, scene_eval, ob, &data_masks);
+ }
+ }
+
+ if (me_eval == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "from_object(...): Object '%s' has no usable mesh data",
+ ob->id.name + 2);
+ return NULL;
+ }
+
+ bm = self->bm;
+
+ BM_mesh_bm_from_me(bm,
+ me_eval,
+ (&(struct BMeshFromMeshParams){
+ .calc_face_normal = use_fnorm,
+ }));
+
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(
+ bpy_bmesh_from_mesh_doc,
+ ".. method:: from_mesh(mesh, face_normals=True, use_shape_key=False, shape_key_index=0)\n"
+ "\n"
+ " Initialize this bmesh from existing mesh datablock.\n"
+ "\n"
+ " :arg mesh: The mesh data to load.\n"
+ " :type mesh: :class:`Mesh`\n"
+ " :arg use_shape_key: Use the locations from a shape key.\n"
+ " :type use_shape_key: boolean\n"
+ " :arg shape_key_index: The shape key index to use.\n"
+ " :type shape_key_index: int\n"
+ "\n"
+ " .. note::\n"
+ "\n"
+ " Multiple calls can be used to join multiple meshes.\n"
+ "\n"
+ " Custom-data layers are only copied from ``mesh`` on initialization.\n"
+ " Further calls will copy custom-data to matching layers, layers missing on the target "
+ "mesh wont be added.\n");
static PyObject *bpy_bmesh_from_mesh(BPy_BMesh *self, PyObject *args, PyObject *kw)
{
- static const char *kwlist[] = {"mesh", "face_normals", "use_shape_key", "shape_key_index", NULL};
- BMesh *bm;
- PyObject *py_mesh;
- Mesh *me;
- bool use_fnorm = true;
- bool use_shape_key = false;
- int shape_key_index = 0;
-
- BPY_BM_CHECK_OBJ(self);
-
- if (!PyArg_ParseTupleAndKeywords(
- args, kw, "O|O&O&i:from_mesh", (char **)kwlist,
- &py_mesh,
- PyC_ParseBool, &use_fnorm,
- PyC_ParseBool, &use_shape_key,
- &shape_key_index) ||
- !(me = PyC_RNA_AsPointer(py_mesh, "Mesh")))
- {
- return NULL;
- }
-
- bm = self->bm;
-
- BM_mesh_bm_from_me(
- bm, me, (&(struct BMeshFromMeshParams){
- .calc_face_normal = use_fnorm, .use_shapekey = use_shape_key, .active_shapekey = shape_key_index + 1,
- }));
-
- Py_RETURN_NONE;
+ static const char *kwlist[] = {"mesh", "face_normals", "use_shape_key", "shape_key_index", NULL};
+ BMesh *bm;
+ PyObject *py_mesh;
+ Mesh *me;
+ bool use_fnorm = true;
+ bool use_shape_key = false;
+ int shape_key_index = 0;
+
+ BPY_BM_CHECK_OBJ(self);
+
+ if (!PyArg_ParseTupleAndKeywords(args,
+ kw,
+ "O|O&O&i:from_mesh",
+ (char **)kwlist,
+ &py_mesh,
+ PyC_ParseBool,
+ &use_fnorm,
+ PyC_ParseBool,
+ &use_shape_key,
+ &shape_key_index) ||
+ !(me = PyC_RNA_AsPointer(py_mesh, "Mesh"))) {
+ return NULL;
+ }
+
+ bm = self->bm;
+
+ BM_mesh_bm_from_me(bm,
+ me,
+ (&(struct BMeshFromMeshParams){
+ .calc_face_normal = use_fnorm,
+ .use_shapekey = use_shape_key,
+ .active_shapekey = shape_key_index + 1,
+ }));
+
+ Py_RETURN_NONE;
}
-
PyDoc_STRVAR(bpy_bmesh_select_flush_mode_doc,
-".. method:: select_flush_mode()\n"
-"\n"
-" flush selection based on the current mode current :class:`BMesh.select_mode`.\n"
-);
+ ".. method:: select_flush_mode()\n"
+ "\n"
+ " flush selection based on the current mode current :class:`BMesh.select_mode`.\n");
static PyObject *bpy_bmesh_select_flush_mode(BPy_BMesh *self)
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- BM_mesh_select_mode_flush(self->bm);
+ BM_mesh_select_mode_flush(self->bm);
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
-
PyDoc_STRVAR(bpy_bmesh_select_flush_doc,
-".. method:: select_flush(select)\n"
-"\n"
-" Flush selection, independent of the current selection mode.\n"
-"\n"
-" :arg select: flush selection or de-selected elements.\n"
-" :type select: boolean\n"
-);
+ ".. method:: select_flush(select)\n"
+ "\n"
+ " Flush selection, independent of the current selection mode.\n"
+ "\n"
+ " :arg select: flush selection or de-selected elements.\n"
+ " :type select: boolean\n");
static PyObject *bpy_bmesh_select_flush(BPy_BMesh *self, PyObject *value)
{
- int param;
+ int param;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if ((param = PyC_Long_AsBool(value)) == -1) {
- return NULL;
- }
+ if ((param = PyC_Long_AsBool(value)) == -1) {
+ return NULL;
+ }
- if (param) {
- BM_mesh_select_flush(self->bm);
- }
- else {
- BM_mesh_deselect_flush(self->bm);
- }
+ if (param) {
+ BM_mesh_select_flush(self->bm);
+ }
+ else {
+ BM_mesh_deselect_flush(self->bm);
+ }
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
-
PyDoc_STRVAR(bpy_bmesh_normal_update_doc,
-".. method:: normal_update()\n"
-"\n"
-" Update mesh normals.\n"
-);
+ ".. method:: normal_update()\n"
+ "\n"
+ " Update mesh normals.\n");
static PyObject *bpy_bmesh_normal_update(BPy_BMesh *self)
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- BM_mesh_normals_update(self->bm);
+ BM_mesh_normals_update(self->bm);
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
-
PyDoc_STRVAR(bpy_bmesh_transform_doc,
-".. method:: transform(matrix, filter=None)\n"
-"\n"
-" Transform the mesh (optionally filtering flagged data only).\n"
-"\n"
-" :arg matrix: transform matrix.\n"
-" :type matrix: 4x4 :class:`mathutils.Matrix`\n"
-" :arg filter: set of values in " BPY_BM_HFLAG_ALL_STR ".\n"
-" :type filter: set\n"
-);
+ ".. method:: transform(matrix, filter=None)\n"
+ "\n"
+ " Transform the mesh (optionally filtering flagged data only).\n"
+ "\n"
+ " :arg matrix: transform matrix.\n"
+ " :type matrix: 4x4 :class:`mathutils.Matrix`\n"
+ " :arg filter: set of values in " BPY_BM_HFLAG_ALL_STR
+ ".\n"
+ " :type filter: set\n");
static PyObject *bpy_bmesh_transform(BPy_BMElem *self, PyObject *args, PyObject *kw)
{
- static const char *kwlist[] = {"matrix", "filter", NULL};
-
- MatrixObject *mat;
- PyObject *filter = NULL;
- int filter_flags = 0;
-
- BPY_BM_CHECK_OBJ(self);
-
- if (!PyArg_ParseTupleAndKeywords(args, kw,
- "O!|O!:transform",
- (char **)kwlist,
- &matrix_Type, &mat,
- &PySet_Type, &filter))
- {
- return NULL;
- }
- else {
- BMVert *eve;
- BMIter iter;
- void *mat_ptr;
-
- if (BaseMath_ReadCallback(mat) == -1) {
- return NULL;
- }
- else if (mat->num_col != 4 || mat->num_row != 4) {
- PyErr_SetString(PyExc_ValueError,
- "expected a 4x4 matrix");
- return NULL;
- }
-
- if (filter != NULL && PyC_FlagSet_ToBitfield(bpy_bm_hflag_all_flags, filter,
- &filter_flags, "bm.transform") == -1)
- {
- return NULL;
- }
-
- mat_ptr = mat->matrix;
-
- if (!filter_flags) {
- BM_ITER_MESH (eve, &iter, self->bm, BM_VERTS_OF_MESH) {
- mul_m4_v3((float (*)[4])mat_ptr, eve->co);
- }
- }
- else {
- char filter_flags_ch = (char)filter_flags;
- BM_ITER_MESH (eve, &iter, self->bm, BM_VERTS_OF_MESH) {
- if (BM_elem_flag_test(eve, filter_flags_ch)) {
- mul_m4_v3((float (*)[4])mat_ptr, eve->co);
- }
- }
- }
- }
-
- Py_RETURN_NONE;
+ static const char *kwlist[] = {"matrix", "filter", NULL};
+
+ MatrixObject *mat;
+ PyObject *filter = NULL;
+ int filter_flags = 0;
+
+ BPY_BM_CHECK_OBJ(self);
+
+ if (!PyArg_ParseTupleAndKeywords(args,
+ kw,
+ "O!|O!:transform",
+ (char **)kwlist,
+ &matrix_Type,
+ &mat,
+ &PySet_Type,
+ &filter)) {
+ return NULL;
+ }
+ else {
+ BMVert *eve;
+ BMIter iter;
+ void *mat_ptr;
+
+ if (BaseMath_ReadCallback(mat) == -1) {
+ return NULL;
+ }
+ else if (mat->num_col != 4 || mat->num_row != 4) {
+ PyErr_SetString(PyExc_ValueError, "expected a 4x4 matrix");
+ return NULL;
+ }
+
+ if (filter != NULL &&
+ PyC_FlagSet_ToBitfield(bpy_bm_hflag_all_flags, filter, &filter_flags, "bm.transform") ==
+ -1) {
+ return NULL;
+ }
+
+ mat_ptr = mat->matrix;
+
+ if (!filter_flags) {
+ BM_ITER_MESH (eve, &iter, self->bm, BM_VERTS_OF_MESH) {
+ mul_m4_v3((float(*)[4])mat_ptr, eve->co);
+ }
+ }
+ else {
+ char filter_flags_ch = (char)filter_flags;
+ BM_ITER_MESH (eve, &iter, self->bm, BM_VERTS_OF_MESH) {
+ if (BM_elem_flag_test(eve, filter_flags_ch)) {
+ mul_m4_v3((float(*)[4])mat_ptr, eve->co);
+ }
+ }
+ }
+ }
+
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(bpy_bmesh_calc_volume_doc,
-".. method:: calc_volume(signed=False)\n"
-"\n"
-" Calculate mesh volume based on face normals.\n"
-"\n"
-" :arg signed: when signed is true, negative values may be returned.\n"
-" :type signed: bool\n"
-" :return: The volume of the mesh.\n"
-" :rtype: float\n"
-);
+ ".. method:: calc_volume(signed=False)\n"
+ "\n"
+ " Calculate mesh volume based on face normals.\n"
+ "\n"
+ " :arg signed: when signed is true, negative values may be returned.\n"
+ " :type signed: bool\n"
+ " :return: The volume of the mesh.\n"
+ " :rtype: float\n");
static PyObject *bpy_bmesh_calc_volume(BPy_BMElem *self, PyObject *args, PyObject *kw)
{
- static const char *kwlist[] = {"signed", NULL};
- PyObject *is_signed = Py_False;
+ static const char *kwlist[] = {"signed", NULL};
+ PyObject *is_signed = Py_False;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if (!PyArg_ParseTupleAndKeywords(args, kw,
- "|O!:calc_volume",
- (char **)kwlist,
- &PyBool_Type, &is_signed))
- {
- return NULL;
- }
- else {
- return PyFloat_FromDouble(BM_mesh_calc_volume(self->bm, is_signed != Py_False));
- }
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kw, "|O!:calc_volume", (char **)kwlist, &PyBool_Type, &is_signed)) {
+ return NULL;
+ }
+ else {
+ return PyFloat_FromDouble(BM_mesh_calc_volume(self->bm, is_signed != Py_False));
+ }
}
PyDoc_STRVAR(bpy_bmesh_calc_loop_triangles_doc,
-".. method:: calc_loop_triangles()\n"
-"\n"
-" Calculate triangle tessellation from quads/ngons.\n"
-"\n"
-" :return: The triangulated faces.\n"
-" :rtype: list of :class:`BMLoop` tuples\n"
-);
+ ".. method:: calc_loop_triangles()\n"
+ "\n"
+ " Calculate triangle tessellation from quads/ngons.\n"
+ "\n"
+ " :return: The triangulated faces.\n"
+ " :rtype: list of :class:`BMLoop` tuples\n");
static PyObject *bpy_bmesh_calc_loop_triangles(BPy_BMElem *self)
{
- BMesh *bm;
+ BMesh *bm;
- int looptris_tot;
- int tottri;
- BMLoop *(*looptris)[3];
+ int looptris_tot;
+ int tottri;
+ BMLoop *(*looptris)[3];
- PyObject *ret;
- int i;
+ PyObject *ret;
+ int i;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- bm = self->bm;
+ bm = self->bm;
- looptris_tot = poly_to_tri_count(bm->totface, bm->totloop);
- looptris = PyMem_MALLOC(sizeof(*looptris) * looptris_tot);
+ looptris_tot = poly_to_tri_count(bm->totface, bm->totloop);
+ looptris = PyMem_MALLOC(sizeof(*looptris) * looptris_tot);
- BM_mesh_calc_tessellation(bm, looptris, &tottri);
+ BM_mesh_calc_tessellation(bm, looptris, &tottri);
- ret = PyList_New(tottri);
- for (i = 0; i < tottri; i++) {
- PyList_SET_ITEM(ret, i, BPy_BMLoop_Array_As_Tuple(bm, looptris[i], 3));
- }
+ ret = PyList_New(tottri);
+ for (i = 0; i < tottri; i++) {
+ PyList_SET_ITEM(ret, i, BPy_BMLoop_Array_As_Tuple(bm, looptris[i], 3));
+ }
- PyMem_FREE(looptris);
+ PyMem_FREE(looptris);
- return ret;
+ return ret;
}
-
/* Elem
* ---- */
PyDoc_STRVAR(bpy_bm_elem_select_set_doc,
-".. method:: select_set(select)\n"
-"\n"
-" Set the selection.\n"
-" This is different from the *select* attribute because it updates the selection state of associated geometry.\n"
-"\n"
-" :arg select: Select or de-select.\n"
-" :type select: boolean\n"
-"\n"
-" .. note::\n"
-"\n"
-" Currently this only flushes down, so selecting a face will select all its vertices but de-selecting a vertex "
-" won't de-select all the faces that use it, before finishing with a mesh typically flushing is still needed.\n"
-);
+ ".. method:: select_set(select)\n"
+ "\n"
+ " Set the selection.\n"
+ " This is different from the *select* attribute because it updates the selection "
+ "state of associated geometry.\n"
+ "\n"
+ " :arg select: Select or de-select.\n"
+ " :type select: boolean\n"
+ "\n"
+ " .. note::\n"
+ "\n"
+ " Currently this only flushes down, so selecting a face will select all its "
+ "vertices but de-selecting a vertex "
+ " won't de-select all the faces that use it, before finishing with a mesh "
+ "typically flushing is still needed.\n");
static PyObject *bpy_bm_elem_select_set(BPy_BMElem *self, PyObject *value)
{
- int param;
+ int param;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if ((param = PyC_Long_AsBool(value)) == -1) {
- return NULL;
- }
+ if ((param = PyC_Long_AsBool(value)) == -1) {
+ return NULL;
+ }
- BM_elem_select_set(self->bm, self->ele, param);
+ BM_elem_select_set(self->bm, self->ele, param);
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
-
PyDoc_STRVAR(bpy_bm_elem_hide_set_doc,
-".. method:: hide_set(hide)\n"
-"\n"
-" Set the hide state.\n"
-" This is different from the *hide* attribute because it updates the selection and hide state of associated geometry.\n"
-"\n"
-" :arg hide: Hidden or visible.\n"
-" :type hide: boolean\n"
-);
+ ".. method:: hide_set(hide)\n"
+ "\n"
+ " Set the hide state.\n"
+ " This is different from the *hide* attribute because it updates the selection and "
+ "hide state of associated geometry.\n"
+ "\n"
+ " :arg hide: Hidden or visible.\n"
+ " :type hide: boolean\n");
static PyObject *bpy_bm_elem_hide_set(BPy_BMElem *self, PyObject *value)
{
- int param;
+ int param;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if ((param = PyC_Long_AsBool(value)) == -1) {
- return NULL;
- }
+ if ((param = PyC_Long_AsBool(value)) == -1) {
+ return NULL;
+ }
- BM_elem_hide_set(self->bm, self->ele, param);
+ BM_elem_hide_set(self->bm, self->ele, param);
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
-
PyDoc_STRVAR(bpy_bm_elem_copy_from_doc,
-".. method:: copy_from(other)\n"
-"\n"
-" Copy values from another element of matching type.\n"
-);
+ ".. method:: copy_from(other)\n"
+ "\n"
+ " Copy values from another element of matching type.\n");
static PyObject *bpy_bm_elem_copy_from(BPy_BMElem *self, BPy_BMElem *value)
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if (Py_TYPE(self) != Py_TYPE(value)) {
- PyErr_Format(PyExc_TypeError,
- "expected element of type '%.200s' not '%.200s'",
- Py_TYPE(self)->tp_name, Py_TYPE(value)->tp_name);
- return NULL;
- }
+ if (Py_TYPE(self) != Py_TYPE(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "expected element of type '%.200s' not '%.200s'",
+ Py_TYPE(self)->tp_name,
+ Py_TYPE(value)->tp_name);
+ return NULL;
+ }
- if (value->ele != self->ele) {
- BM_elem_attrs_copy(value->bm, self->bm, value->ele, self->ele);
- }
+ if (value->ele != self->ele) {
+ BM_elem_attrs_copy(value->bm, self->bm, value->ele, self->ele);
+ }
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
-
/* Vert
* ---- */
-
PyDoc_STRVAR(bpy_bmvert_copy_from_vert_interp_doc,
-".. method:: copy_from_vert_interp(vert_pair, fac)\n"
-"\n"
-" Interpolate the customdata from a vert between 2 other verts.\n"
-"\n"
-" :arg vert_pair: The vert to interpolate data from.\n"
-" :type vert_pair: :class:`BMVert`\n"
-);
+ ".. method:: copy_from_vert_interp(vert_pair, fac)\n"
+ "\n"
+ " Interpolate the customdata from a vert between 2 other verts.\n"
+ "\n"
+ " :arg vert_pair: The vert to interpolate data from.\n"
+ " :type vert_pair: :class:`BMVert`\n");
static PyObject *bpy_bmvert_copy_from_vert_interp(BPy_BMVert *self, PyObject *args)
{
- PyObject *vert_seq;
- float fac;
+ PyObject *vert_seq;
+ float fac;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "Of:BMVert.copy_from_vert_interp",
- &vert_seq, &fac))
- {
- return NULL;
- }
- else {
- BMesh *bm = self->bm;
- BMVert **vert_array = NULL;
- Py_ssize_t vert_seq_len; /* always 2 */
+ if (!PyArg_ParseTuple(args, "Of:BMVert.copy_from_vert_interp", &vert_seq, &fac)) {
+ return NULL;
+ }
+ else {
+ BMesh *bm = self->bm;
+ BMVert **vert_array = NULL;
+ Py_ssize_t vert_seq_len; /* always 2 */
- vert_array = BPy_BMElem_PySeq_As_Array(&bm, vert_seq, 2, 2,
- &vert_seq_len, BM_VERT,
- true, true, "BMVert.copy_from_vert_interp(...)");
+ vert_array = BPy_BMElem_PySeq_As_Array(&bm,
+ vert_seq,
+ 2,
+ 2,
+ &vert_seq_len,
+ BM_VERT,
+ true,
+ true,
+ "BMVert.copy_from_vert_interp(...)");
- if (vert_array == NULL) {
- return NULL;
- }
+ if (vert_array == NULL) {
+ return NULL;
+ }
- BM_data_interp_from_verts(bm, vert_array[0], vert_array[1], self->v, clamp_f(fac, 0.0f, 1.0f));
+ BM_data_interp_from_verts(bm, vert_array[0], vert_array[1], self->v, clamp_f(fac, 0.0f, 1.0f));
- PyMem_FREE(vert_array);
- Py_RETURN_NONE;
- }
+ PyMem_FREE(vert_array);
+ Py_RETURN_NONE;
+ }
}
-
PyDoc_STRVAR(bpy_bmvert_copy_from_face_interp_doc,
-".. method:: copy_from_face_interp(face)\n"
-"\n"
-" Interpolate the customdata from a face onto this loop (the loops vert should overlap the face).\n"
-"\n"
-" :arg face: The face to interpolate data from.\n"
-" :type face: :class:`BMFace`\n"
-);
+ ".. method:: copy_from_face_interp(face)\n"
+ "\n"
+ " Interpolate the customdata from a face onto this loop (the loops vert should "
+ "overlap the face).\n"
+ "\n"
+ " :arg face: The face to interpolate data from.\n"
+ " :type face: :class:`BMFace`\n");
static PyObject *bpy_bmvert_copy_from_face_interp(BPy_BMVert *self, PyObject *args)
{
- BPy_BMFace *py_face = NULL;
+ BPy_BMFace *py_face = NULL;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "O!:BMVert.copy_from_face_interp",
- &BPy_BMFace_Type, &py_face))
- {
- return NULL;
- }
- else {
- BMesh *bm = self->bm;
+ if (!PyArg_ParseTuple(args, "O!:BMVert.copy_from_face_interp", &BPy_BMFace_Type, &py_face)) {
+ return NULL;
+ }
+ else {
+ BMesh *bm = self->bm;
- BPY_BM_CHECK_SOURCE_OBJ(bm, "copy_from_face_interp()", py_face);
+ BPY_BM_CHECK_SOURCE_OBJ(bm, "copy_from_face_interp()", py_face);
- BM_vert_interp_from_face(bm, self->v, py_face->f);
+ BM_vert_interp_from_face(bm, self->v, py_face->f);
- Py_RETURN_NONE;
- }
+ Py_RETURN_NONE;
+ }
}
-
PyDoc_STRVAR(bpy_bmvert_calc_edge_angle_doc,
-".. method:: calc_edge_angle(fallback=None)\n"
-"\n"
-" Return the angle between this vert's two connected edges.\n"
-"\n"
-" :arg fallback: return this when the vert doesn't have 2 edges\n"
-" (instead of raising a :exc:`ValueError`).\n"
-" :type fallback: any\n"
-" :return: Angle between edges in radians.\n"
-" :rtype: float\n"
-);
+ ".. method:: calc_edge_angle(fallback=None)\n"
+ "\n"
+ " Return the angle between this vert's two connected edges.\n"
+ "\n"
+ " :arg fallback: return this when the vert doesn't have 2 edges\n"
+ " (instead of raising a :exc:`ValueError`).\n"
+ " :type fallback: any\n"
+ " :return: Angle between edges in radians.\n"
+ " :rtype: float\n");
static PyObject *bpy_bmvert_calc_edge_angle(BPy_BMVert *self, PyObject *args)
{
- const float angle_invalid = -1.0f;
- float angle;
- PyObject *fallback = NULL;
-
- BPY_BM_CHECK_OBJ(self);
-
- if (!PyArg_ParseTuple(args, "|O:calc_edge_angle", &fallback)) {
- return NULL;
- }
-
- angle = BM_vert_calc_edge_angle_ex(self->v, angle_invalid);
-
- if (angle == angle_invalid) {
- /* avoid exception */
- if (fallback) {
- Py_INCREF(fallback);
- return fallback;
- }
- else {
- PyErr_SetString(PyExc_ValueError,
- "BMVert.calc_edge_angle(): "
- "vert must connect to exactly 2 edges");
- return NULL;
- }
- }
-
- return PyFloat_FromDouble(angle);
-}
-
-PyDoc_STRVAR(bpy_bmvert_calc_shell_factor_doc,
-".. method:: calc_shell_factor()\n"
-"\n"
-" Return a multiplier calculated based on the sharpness of the vertex.\n"
-" Where a flat surface gives 1.0, and higher values sharper edges.\n"
-" This is used to maintain shell thickness when offsetting verts along their normals.\n"
-"\n"
-" :return: offset multiplier\n"
-" :rtype: float\n"
-);
+ const float angle_invalid = -1.0f;
+ float angle;
+ PyObject *fallback = NULL;
+
+ BPY_BM_CHECK_OBJ(self);
+
+ if (!PyArg_ParseTuple(args, "|O:calc_edge_angle", &fallback)) {
+ return NULL;
+ }
+
+ angle = BM_vert_calc_edge_angle_ex(self->v, angle_invalid);
+
+ if (angle == angle_invalid) {
+ /* avoid exception */
+ if (fallback) {
+ Py_INCREF(fallback);
+ return fallback;
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "BMVert.calc_edge_angle(): "
+ "vert must connect to exactly 2 edges");
+ return NULL;
+ }
+ }
+
+ return PyFloat_FromDouble(angle);
+}
+
+PyDoc_STRVAR(
+ bpy_bmvert_calc_shell_factor_doc,
+ ".. method:: calc_shell_factor()\n"
+ "\n"
+ " Return a multiplier calculated based on the sharpness of the vertex.\n"
+ " Where a flat surface gives 1.0, and higher values sharper edges.\n"
+ " This is used to maintain shell thickness when offsetting verts along their normals.\n"
+ "\n"
+ " :return: offset multiplier\n"
+ " :rtype: float\n");
static PyObject *bpy_bmvert_calc_shell_factor(BPy_BMVert *self)
{
- BPY_BM_CHECK_OBJ(self);
- return PyFloat_FromDouble(BM_vert_calc_shell_factor(self->v));
+ BPY_BM_CHECK_OBJ(self);
+ return PyFloat_FromDouble(BM_vert_calc_shell_factor(self->v));
}
PyDoc_STRVAR(bpy_bmvert_normal_update_doc,
-".. method:: normal_update()\n"
-"\n"
-" Update vertex normal.\n"
-);
+ ".. method:: normal_update()\n"
+ "\n"
+ " Update vertex normal.\n");
static PyObject *bpy_bmvert_normal_update(BPy_BMVert *self)
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- BM_vert_normal_update(self->v);
+ BM_vert_normal_update(self->v);
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
-
/* Edge
* ---- */
PyDoc_STRVAR(bpy_bmedge_calc_length_doc,
-".. method:: calc_length()\n"
-"\n"
-" :return: The length between both verts.\n"
-" :rtype: float\n"
-);
+ ".. method:: calc_length()\n"
+ "\n"
+ " :return: The length between both verts.\n"
+ " :rtype: float\n");
static PyObject *bpy_bmedge_calc_length(BPy_BMEdge *self)
{
- BPY_BM_CHECK_OBJ(self);
- return PyFloat_FromDouble(len_v3v3(self->e->v1->co, self->e->v2->co));
+ BPY_BM_CHECK_OBJ(self);
+ return PyFloat_FromDouble(len_v3v3(self->e->v1->co, self->e->v2->co));
}
PyDoc_STRVAR(bpy_bmedge_calc_face_angle_doc,
-".. method:: calc_face_angle(fallback=None)\n"
-"\n"
-" :arg fallback: return this when the edge doesn't have 2 faces\n"
-" (instead of raising a :exc:`ValueError`).\n"
-" :type fallback: any\n"
-" :return: The angle between 2 connected faces in radians.\n"
-" :rtype: float\n"
-);
+ ".. method:: calc_face_angle(fallback=None)\n"
+ "\n"
+ " :arg fallback: return this when the edge doesn't have 2 faces\n"
+ " (instead of raising a :exc:`ValueError`).\n"
+ " :type fallback: any\n"
+ " :return: The angle between 2 connected faces in radians.\n"
+ " :rtype: float\n");
static PyObject *bpy_bmedge_calc_face_angle(BPy_BMEdge *self, PyObject *args)
{
- const float angle_invalid = -1.0f;
- float angle;
- PyObject *fallback = NULL;
-
- BPY_BM_CHECK_OBJ(self);
-
- if (!PyArg_ParseTuple(args, "|O:calc_face_angle", &fallback)) {
- return NULL;
- }
-
- angle = BM_edge_calc_face_angle_ex(self->e, angle_invalid);
-
- if (angle == angle_invalid) {
- /* avoid exception */
- if (fallback) {
- Py_INCREF(fallback);
- return fallback;
- }
- else {
- PyErr_SetString(PyExc_ValueError,
- "BMEdge.calc_face_angle(): "
- "edge doesn't use 2 faces");
- return NULL;
- }
- }
-
- return PyFloat_FromDouble(angle);
-}
-
-PyDoc_STRVAR(bpy_bmedge_calc_face_angle_signed_doc,
-".. method:: calc_face_angle_signed(fallback=None)\n"
-"\n"
-" :arg fallback: return this when the edge doesn't have 2 faces\n"
-" (instead of raising a :exc:`ValueError`).\n"
-" :type fallback: any\n"
-" :return: The angle between 2 connected faces in radians (negative for concave join).\n"
-" :rtype: float\n"
-);
+ const float angle_invalid = -1.0f;
+ float angle;
+ PyObject *fallback = NULL;
+
+ BPY_BM_CHECK_OBJ(self);
+
+ if (!PyArg_ParseTuple(args, "|O:calc_face_angle", &fallback)) {
+ return NULL;
+ }
+
+ angle = BM_edge_calc_face_angle_ex(self->e, angle_invalid);
+
+ if (angle == angle_invalid) {
+ /* avoid exception */
+ if (fallback) {
+ Py_INCREF(fallback);
+ return fallback;
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "BMEdge.calc_face_angle(): "
+ "edge doesn't use 2 faces");
+ return NULL;
+ }
+ }
+
+ return PyFloat_FromDouble(angle);
+}
+
+PyDoc_STRVAR(
+ bpy_bmedge_calc_face_angle_signed_doc,
+ ".. method:: calc_face_angle_signed(fallback=None)\n"
+ "\n"
+ " :arg fallback: return this when the edge doesn't have 2 faces\n"
+ " (instead of raising a :exc:`ValueError`).\n"
+ " :type fallback: any\n"
+ " :return: The angle between 2 connected faces in radians (negative for concave join).\n"
+ " :rtype: float\n");
static PyObject *bpy_bmedge_calc_face_angle_signed(BPy_BMEdge *self, PyObject *args)
{
- const float angle_invalid = -FLT_MAX;
- float angle;
- PyObject *fallback = NULL;
-
- BPY_BM_CHECK_OBJ(self);
-
- if (!PyArg_ParseTuple(args, "|O:calc_face_angle_signed", &fallback)) {
- return NULL;
- }
-
- angle = BM_edge_calc_face_angle_signed_ex(self->e, angle_invalid);
-
- if (angle == angle_invalid) {
- /* avoid exception */
- if (fallback) {
- Py_INCREF(fallback);
- return fallback;
- }
- else {
- PyErr_SetString(PyExc_ValueError,
- "BMEdge.calc_face_angle_signed(): "
- "edge doesn't use 2 faces");
- return NULL;
- }
- }
-
- return PyFloat_FromDouble(angle);
-}
-
-PyDoc_STRVAR(bpy_bmedge_calc_tangent_doc,
-".. method:: calc_tangent(loop)\n"
-"\n"
-" Return the tangent at this edge relative to a face (pointing inward into the face).\n"
-" This uses the face normal for calculation.\n"
-"\n"
-" :arg loop: The loop used for tangent calculation.\n"
-" :type loop: :class:`BMLoop`\n"
-" :return: a normalized vector.\n"
-" :rtype: :class:`mathutils.Vector`\n"
-);
+ const float angle_invalid = -FLT_MAX;
+ float angle;
+ PyObject *fallback = NULL;
+
+ BPY_BM_CHECK_OBJ(self);
+
+ if (!PyArg_ParseTuple(args, "|O:calc_face_angle_signed", &fallback)) {
+ return NULL;
+ }
+
+ angle = BM_edge_calc_face_angle_signed_ex(self->e, angle_invalid);
+
+ if (angle == angle_invalid) {
+ /* avoid exception */
+ if (fallback) {
+ Py_INCREF(fallback);
+ return fallback;
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "BMEdge.calc_face_angle_signed(): "
+ "edge doesn't use 2 faces");
+ return NULL;
+ }
+ }
+
+ return PyFloat_FromDouble(angle);
+}
+
+PyDoc_STRVAR(
+ bpy_bmedge_calc_tangent_doc,
+ ".. method:: calc_tangent(loop)\n"
+ "\n"
+ " Return the tangent at this edge relative to a face (pointing inward into the face).\n"
+ " This uses the face normal for calculation.\n"
+ "\n"
+ " :arg loop: The loop used for tangent calculation.\n"
+ " :type loop: :class:`BMLoop`\n"
+ " :return: a normalized vector.\n"
+ " :rtype: :class:`mathutils.Vector`\n");
static PyObject *bpy_bmedge_calc_tangent(BPy_BMEdge *self, PyObject *args)
{
- BPy_BMLoop *py_loop;
- BPY_BM_CHECK_OBJ(self);
-
- if (!PyArg_ParseTuple(args, "O!:BMEdge.calc_face_tangent",
- &BPy_BMLoop_Type, &py_loop))
- {
- return NULL;
- }
- else {
- float vec[3];
- BPY_BM_CHECK_OBJ(py_loop);
- /* no need to check if they are from the same mesh or even connected */
- BM_edge_calc_face_tangent(self->e, py_loop->l, vec);
- return Vector_CreatePyObject(vec, 3, NULL);
- }
-}
-
-
-PyDoc_STRVAR(bpy_bmedge_other_vert_doc,
-".. method:: other_vert(vert)\n"
-"\n"
-" Return the other vertex on this edge or None if the vertex is not used by this edge.\n"
-"\n"
-" :arg vert: a vert in this edge.\n"
-" :type vert: :class:`BMVert`\n"
-" :return: The edges other vert.\n"
-" :rtype: :class:`BMVert` or None\n"
-);
+ BPy_BMLoop *py_loop;
+ BPY_BM_CHECK_OBJ(self);
+
+ if (!PyArg_ParseTuple(args, "O!:BMEdge.calc_face_tangent", &BPy_BMLoop_Type, &py_loop)) {
+ return NULL;
+ }
+ else {
+ float vec[3];
+ BPY_BM_CHECK_OBJ(py_loop);
+ /* no need to check if they are from the same mesh or even connected */
+ BM_edge_calc_face_tangent(self->e, py_loop->l, vec);
+ return Vector_CreatePyObject(vec, 3, NULL);
+ }
+}
+
+PyDoc_STRVAR(
+ bpy_bmedge_other_vert_doc,
+ ".. method:: other_vert(vert)\n"
+ "\n"
+ " Return the other vertex on this edge or None if the vertex is not used by this edge.\n"
+ "\n"
+ " :arg vert: a vert in this edge.\n"
+ " :type vert: :class:`BMVert`\n"
+ " :return: The edges other vert.\n"
+ " :rtype: :class:`BMVert` or None\n");
static PyObject *bpy_bmedge_other_vert(BPy_BMEdge *self, BPy_BMVert *value)
{
- BMVert *other;
- BPY_BM_CHECK_OBJ(self);
+ BMVert *other;
+ BPY_BM_CHECK_OBJ(self);
- if (!BPy_BMVert_Check(value)) {
- PyErr_Format(PyExc_TypeError,
- "BMEdge.other_vert(vert): BMVert expected, not '%.200s'",
- Py_TYPE(value)->tp_name);
- return NULL;
- }
+ if (!BPy_BMVert_Check(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "BMEdge.other_vert(vert): BMVert expected, not '%.200s'",
+ Py_TYPE(value)->tp_name);
+ return NULL;
+ }
- BPY_BM_CHECK_SOURCE_OBJ(self->bm, "BMEdge.other_vert(vert)", value);
+ BPY_BM_CHECK_SOURCE_OBJ(self->bm, "BMEdge.other_vert(vert)", value);
- other = BM_edge_other_vert(self->e, value->v);
+ other = BM_edge_other_vert(self->e, value->v);
- if (other) {
- return BPy_BMVert_CreatePyObject(self->bm, other);
- }
- else {
- /* could raise an exception here */
- Py_RETURN_NONE;
- }
+ if (other) {
+ return BPy_BMVert_CreatePyObject(self->bm, other);
+ }
+ else {
+ /* could raise an exception here */
+ Py_RETURN_NONE;
+ }
}
-
PyDoc_STRVAR(bpy_bmedge_normal_update_doc,
-".. method:: normal_update()\n"
-"\n"
-" Update edges vertex normals.\n"
-);
+ ".. method:: normal_update()\n"
+ "\n"
+ " Update edges vertex normals.\n");
static PyObject *bpy_bmedge_normal_update(BPy_BMEdge *self)
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- BM_edge_normals_update(self->e);
+ BM_edge_normals_update(self->e);
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
-
/* Face
* ---- */
-PyDoc_STRVAR(bpy_bmface_copy_from_face_interp_doc,
-".. method:: copy_from_face_interp(face, vert=True)\n"
-"\n"
-" Interpolate the customdata from another face onto this one (faces should overlap).\n"
-"\n"
-" :arg face: The face to interpolate data from.\n"
-" :type face: :class:`BMFace`\n"
-" :arg vert: When True, also copy vertex data.\n"
-" :type vert: boolean\n"
-);
+PyDoc_STRVAR(
+ bpy_bmface_copy_from_face_interp_doc,
+ ".. method:: copy_from_face_interp(face, vert=True)\n"
+ "\n"
+ " Interpolate the customdata from another face onto this one (faces should overlap).\n"
+ "\n"
+ " :arg face: The face to interpolate data from.\n"
+ " :type face: :class:`BMFace`\n"
+ " :arg vert: When True, also copy vertex data.\n"
+ " :type vert: boolean\n");
static PyObject *bpy_bmface_copy_from_face_interp(BPy_BMFace *self, PyObject *args)
{
- BPy_BMFace *py_face = NULL;
- bool do_vertex = true;
+ BPy_BMFace *py_face = NULL;
+ bool do_vertex = true;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(
- args, "O!|O&:BMFace.copy_from_face_interp",
- &BPy_BMFace_Type, &py_face,
- PyC_ParseBool, &do_vertex))
- {
- return NULL;
- }
- else {
- BMesh *bm = self->bm;
+ if (!PyArg_ParseTuple(args,
+ "O!|O&:BMFace.copy_from_face_interp",
+ &BPy_BMFace_Type,
+ &py_face,
+ PyC_ParseBool,
+ &do_vertex)) {
+ return NULL;
+ }
+ else {
+ BMesh *bm = self->bm;
- BPY_BM_CHECK_SOURCE_OBJ(bm, "BMFace.copy_from_face_interp(face)", py_face);
+ BPY_BM_CHECK_SOURCE_OBJ(bm, "BMFace.copy_from_face_interp(face)", py_face);
- BM_face_interp_from_face(bm, self->f, py_face->f, do_vertex);
+ BM_face_interp_from_face(bm, self->f, py_face->f, do_vertex);
- Py_RETURN_NONE;
- }
+ Py_RETURN_NONE;
+ }
}
-
PyDoc_STRVAR(bpy_bmface_copy_doc,
-".. method:: copy(verts=True, edges=True)\n"
-"\n"
-" Make a copy of this face.\n"
-"\n"
-" :arg verts: When set, the faces verts will be duplicated too.\n"
-" :type verts: boolean\n"
-" :arg edges: When set, the faces edges will be duplicated too.\n"
-" :type edges: boolean\n"
-" :return: The newly created face.\n"
-" :rtype: :class:`BMFace`\n"
-);
+ ".. method:: copy(verts=True, edges=True)\n"
+ "\n"
+ " Make a copy of this face.\n"
+ "\n"
+ " :arg verts: When set, the faces verts will be duplicated too.\n"
+ " :type verts: boolean\n"
+ " :arg edges: When set, the faces edges will be duplicated too.\n"
+ " :type edges: boolean\n"
+ " :return: The newly created face.\n"
+ " :rtype: :class:`BMFace`\n");
static PyObject *bpy_bmface_copy(BPy_BMFace *self, PyObject *args, PyObject *kw)
{
- static const char *kwlist[] = {"verts", "edges", NULL};
+ static const char *kwlist[] = {"verts", "edges", NULL};
- BMesh *bm = self->bm;
- bool do_verts = true;
- bool do_edges = true;
+ BMesh *bm = self->bm;
+ bool do_verts = true;
+ bool do_edges = true;
- BMFace *f_cpy;
- BPY_BM_CHECK_OBJ(self);
+ BMFace *f_cpy;
+ BPY_BM_CHECK_OBJ(self);
- if (!PyArg_ParseTupleAndKeywords(
- args, kw,
- "|O&O&:BMFace.copy", (char **)kwlist,
- PyC_ParseBool, &do_verts,
- PyC_ParseBool, &do_edges))
- {
- return NULL;
- }
+ if (!PyArg_ParseTupleAndKeywords(args,
+ kw,
+ "|O&O&:BMFace.copy",
+ (char **)kwlist,
+ PyC_ParseBool,
+ &do_verts,
+ PyC_ParseBool,
+ &do_edges)) {
+ return NULL;
+ }
- f_cpy = BM_face_copy(bm, bm, self->f, do_verts, do_edges);
+ f_cpy = BM_face_copy(bm, bm, self->f, do_verts, do_edges);
- if (f_cpy) {
- return BPy_BMFace_CreatePyObject(bm, f_cpy);
- }
- else {
- PyErr_SetString(PyExc_ValueError,
- "BMFace.copy(): couldn't create the new face, internal error");
- return NULL;
- }
+ if (f_cpy) {
+ return BPy_BMFace_CreatePyObject(bm, f_cpy);
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "BMFace.copy(): couldn't create the new face, internal error");
+ return NULL;
+ }
}
-
PyDoc_STRVAR(bpy_bmface_calc_area_doc,
-".. method:: calc_area()\n"
-"\n"
-" Return the area of the face.\n"
-"\n"
-" :return: Return the area of the face.\n"
-" :rtype: float\n"
-);
+ ".. method:: calc_area()\n"
+ "\n"
+ " Return the area of the face.\n"
+ "\n"
+ " :return: Return the area of the face.\n"
+ " :rtype: float\n");
static PyObject *bpy_bmface_calc_area(BPy_BMFace *self)
{
- BPY_BM_CHECK_OBJ(self);
- return PyFloat_FromDouble(BM_face_calc_area(self->f));
+ BPY_BM_CHECK_OBJ(self);
+ return PyFloat_FromDouble(BM_face_calc_area(self->f));
}
-
PyDoc_STRVAR(bpy_bmface_calc_perimeter_doc,
-".. method:: calc_perimeter()\n"
-"\n"
-" Return the perimeter of the face.\n"
-"\n"
-" :return: Return the perimeter of the face.\n"
-" :rtype: float\n"
-);
+ ".. method:: calc_perimeter()\n"
+ "\n"
+ " Return the perimeter of the face.\n"
+ "\n"
+ " :return: Return the perimeter of the face.\n"
+ " :rtype: float\n");
static PyObject *bpy_bmface_calc_perimeter(BPy_BMFace *self)
{
- BPY_BM_CHECK_OBJ(self);
- return PyFloat_FromDouble(BM_face_calc_perimeter(self->f));
+ BPY_BM_CHECK_OBJ(self);
+ return PyFloat_FromDouble(BM_face_calc_perimeter(self->f));
}
-
PyDoc_STRVAR(bpy_bmface_calc_tangent_edge_doc,
-".. method:: calc_tangent_edge()\n"
-"\n"
-" Return face tangent based on longest edge.\n"
-"\n"
-" :return: a normalized vector.\n"
-" :rtype: :class:`mathutils.Vector`\n"
-);
+ ".. method:: calc_tangent_edge()\n"
+ "\n"
+ " Return face tangent based on longest edge.\n"
+ "\n"
+ " :return: a normalized vector.\n"
+ " :rtype: :class:`mathutils.Vector`\n");
static PyObject *bpy_bmface_calc_tangent_edge(BPy_BMFace *self)
{
- float tangent[3];
+ float tangent[3];
- BPY_BM_CHECK_OBJ(self);
- BM_face_calc_tangent_edge(self->f, tangent);
- return Vector_CreatePyObject(tangent, 3, NULL);
+ BPY_BM_CHECK_OBJ(self);
+ BM_face_calc_tangent_edge(self->f, tangent);
+ return Vector_CreatePyObject(tangent, 3, NULL);
}
-
PyDoc_STRVAR(bpy_bmface_calc_tangent_edge_pair_doc,
-".. method:: calc_tangent_edge_pair()\n"
-"\n"
-" Return face tangent based on the two longest disconnected edges.\n"
-"\n"
-" - Tris: Use the edge pair with the most similar lengths.\n"
-" - Quads: Use the longest edge pair.\n"
-" - NGons: Use the two longest disconnected edges.\n"
-"\n"
-" :return: a normalized vector.\n"
-" :rtype: :class:`mathutils.Vector`\n"
-);
+ ".. method:: calc_tangent_edge_pair()\n"
+ "\n"
+ " Return face tangent based on the two longest disconnected edges.\n"
+ "\n"
+ " - Tris: Use the edge pair with the most similar lengths.\n"
+ " - Quads: Use the longest edge pair.\n"
+ " - NGons: Use the two longest disconnected edges.\n"
+ "\n"
+ " :return: a normalized vector.\n"
+ " :rtype: :class:`mathutils.Vector`\n");
static PyObject *bpy_bmface_calc_tangent_edge_pair(BPy_BMFace *self)
{
- float tangent[3];
+ float tangent[3];
- BPY_BM_CHECK_OBJ(self);
- BM_face_calc_tangent_edge_pair(self->f, tangent);
- return Vector_CreatePyObject(tangent, 3, NULL);
+ BPY_BM_CHECK_OBJ(self);
+ BM_face_calc_tangent_edge_pair(self->f, tangent);
+ return Vector_CreatePyObject(tangent, 3, NULL);
}
-
PyDoc_STRVAR(bpy_bmface_calc_tangent_edge_diagonal_doc,
-".. method:: calc_tangent_edge_diagonal()\n"
-"\n"
-" Return face tangent based on the edge farthest from any vertex.\n"
-"\n"
-" :return: a normalized vector.\n"
-" :rtype: :class:`mathutils.Vector`\n"
-);
+ ".. method:: calc_tangent_edge_diagonal()\n"
+ "\n"
+ " Return face tangent based on the edge farthest from any vertex.\n"
+ "\n"
+ " :return: a normalized vector.\n"
+ " :rtype: :class:`mathutils.Vector`\n");
static PyObject *bpy_bmface_calc_tangent_edge_diagonal(BPy_BMFace *self)
{
- float tangent[3];
+ float tangent[3];
- BPY_BM_CHECK_OBJ(self);
- BM_face_calc_tangent_edge_diagonal(self->f, tangent);
- return Vector_CreatePyObject(tangent, 3, NULL);
+ BPY_BM_CHECK_OBJ(self);
+ BM_face_calc_tangent_edge_diagonal(self->f, tangent);
+ return Vector_CreatePyObject(tangent, 3, NULL);
}
-
PyDoc_STRVAR(bpy_bmface_calc_tangent_vert_diagonal_doc,
-".. method:: calc_tangent_vert_diagonal()\n"
-"\n"
-" Return face tangent based on the two most distent vertices.\n"
-"\n"
-" :return: a normalized vector.\n"
-" :rtype: :class:`mathutils.Vector`\n"
-);
+ ".. method:: calc_tangent_vert_diagonal()\n"
+ "\n"
+ " Return face tangent based on the two most distent vertices.\n"
+ "\n"
+ " :return: a normalized vector.\n"
+ " :rtype: :class:`mathutils.Vector`\n");
static PyObject *bpy_bmface_calc_tangent_vert_diagonal(BPy_BMFace *self)
{
- float tangent[3];
+ float tangent[3];
- BPY_BM_CHECK_OBJ(self);
- BM_face_calc_tangent_vert_diagonal(self->f, tangent);
- return Vector_CreatePyObject(tangent, 3, NULL);
+ BPY_BM_CHECK_OBJ(self);
+ BM_face_calc_tangent_vert_diagonal(self->f, tangent);
+ return Vector_CreatePyObject(tangent, 3, NULL);
}
-
PyDoc_STRVAR(bpy_bmface_calc_center_median_doc,
-".. method:: calc_center_median()\n"
-"\n"
-" Return median center of the face.\n"
-"\n"
-" :return: a 3D vector.\n"
-" :rtype: :class:`mathutils.Vector`\n"
-);
+ ".. method:: calc_center_median()\n"
+ "\n"
+ " Return median center of the face.\n"
+ "\n"
+ " :return: a 3D vector.\n"
+ " :rtype: :class:`mathutils.Vector`\n");
static PyObject *bpy_bmface_calc_center_mean(BPy_BMFace *self)
{
- float cent[3];
+ float cent[3];
- BPY_BM_CHECK_OBJ(self);
- BM_face_calc_center_median(self->f, cent);
- return Vector_CreatePyObject(cent, 3, NULL);
+ BPY_BM_CHECK_OBJ(self);
+ BM_face_calc_center_median(self->f, cent);
+ return Vector_CreatePyObject(cent, 3, NULL);
}
PyDoc_STRVAR(bpy_bmface_calc_center_median_weighted_doc,
-".. method:: calc_center_median_weighted()\n"
-"\n"
-" Return median center of the face weighted by edge lengths.\n"
-"\n"
-" :return: a 3D vector.\n"
-" :rtype: :class:`mathutils.Vector`\n"
-);
+ ".. method:: calc_center_median_weighted()\n"
+ "\n"
+ " Return median center of the face weighted by edge lengths.\n"
+ "\n"
+ " :return: a 3D vector.\n"
+ " :rtype: :class:`mathutils.Vector`\n");
static PyObject *bpy_bmface_calc_center_median_weighted(BPy_BMFace *self)
{
- float cent[3];
+ float cent[3];
- BPY_BM_CHECK_OBJ(self);
- BM_face_calc_center_median_weighted(self->f, cent);
- return Vector_CreatePyObject(cent, 3, NULL);
+ BPY_BM_CHECK_OBJ(self);
+ BM_face_calc_center_median_weighted(self->f, cent);
+ return Vector_CreatePyObject(cent, 3, NULL);
}
PyDoc_STRVAR(bpy_bmface_calc_center_bounds_doc,
-".. method:: calc_center_bounds()\n"
-"\n"
-" Return bounds center of the face.\n"
-"\n"
-" :return: a 3D vector.\n"
-" :rtype: :class:`mathutils.Vector`\n"
-);
+ ".. method:: calc_center_bounds()\n"
+ "\n"
+ " Return bounds center of the face.\n"
+ "\n"
+ " :return: a 3D vector.\n"
+ " :rtype: :class:`mathutils.Vector`\n");
static PyObject *bpy_bmface_calc_center_bounds(BPy_BMFace *self)
{
- float cent[3];
+ float cent[3];
- BPY_BM_CHECK_OBJ(self);
- BM_face_calc_center_bounds(self->f, cent);
- return Vector_CreatePyObject(cent, 3, NULL);
+ BPY_BM_CHECK_OBJ(self);
+ BM_face_calc_center_bounds(self->f, cent);
+ return Vector_CreatePyObject(cent, 3, NULL);
}
-
PyDoc_STRVAR(bpy_bmface_normal_update_doc,
-".. method:: normal_update()\n"
-"\n"
-" Update face's normal.\n"
-);
+ ".. method:: normal_update()\n"
+ "\n"
+ " Update face's normal.\n");
static PyObject *bpy_bmface_normal_update(BPy_BMFace *self)
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- BM_face_normal_update(self->f);
+ BM_face_normal_update(self->f);
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
-
PyDoc_STRVAR(bpy_bmface_normal_flip_doc,
-".. method:: normal_flip()\n"
-"\n"
-" Reverses winding of a face, which flips its normal.\n"
-);
+ ".. method:: normal_flip()\n"
+ "\n"
+ " Reverses winding of a face, which flips its normal.\n");
static PyObject *bpy_bmface_normal_flip(BPy_BMFace *self)
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- BM_face_normal_flip(self->bm, self->f);
+ BM_face_normal_flip(self->bm, self->f);
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
-
/* Loop
* ---- */
PyDoc_STRVAR(bpy_bmloop_copy_from_face_interp_doc,
-".. method:: copy_from_face_interp(face, vert=True, multires=True)\n"
-"\n"
-" Interpolate the customdata from a face onto this loop (the loops vert should overlap the face).\n"
-"\n"
-" :arg face: The face to interpolate data from.\n"
-" :type face: :class:`BMFace`\n"
-" :arg vert: When enabled, interpolate the loops vertex data (optional).\n"
-" :type vert: boolean\n"
-" :arg multires: When enabled, interpolate the loops multires data (optional).\n"
-" :type multires: boolean\n"
-);
+ ".. method:: copy_from_face_interp(face, vert=True, multires=True)\n"
+ "\n"
+ " Interpolate the customdata from a face onto this loop (the loops vert should "
+ "overlap the face).\n"
+ "\n"
+ " :arg face: The face to interpolate data from.\n"
+ " :type face: :class:`BMFace`\n"
+ " :arg vert: When enabled, interpolate the loops vertex data (optional).\n"
+ " :type vert: boolean\n"
+ " :arg multires: When enabled, interpolate the loops multires data (optional).\n"
+ " :type multires: boolean\n");
static PyObject *bpy_bmloop_copy_from_face_interp(BPy_BMLoop *self, PyObject *args)
{
- BPy_BMFace *py_face = NULL;
- bool do_vertex = true;
- bool do_multires = true;
+ BPy_BMFace *py_face = NULL;
+ bool do_vertex = true;
+ bool do_multires = true;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(
- args, "O!|O&O&:BMLoop.copy_from_face_interp",
- &BPy_BMFace_Type, &py_face,
- PyC_ParseBool, &do_vertex,
- PyC_ParseBool, &do_multires))
- {
- return NULL;
- }
- else {
- BMesh *bm = self->bm;
+ if (!PyArg_ParseTuple(args,
+ "O!|O&O&:BMLoop.copy_from_face_interp",
+ &BPy_BMFace_Type,
+ &py_face,
+ PyC_ParseBool,
+ &do_vertex,
+ PyC_ParseBool,
+ &do_multires)) {
+ return NULL;
+ }
+ else {
+ BMesh *bm = self->bm;
- BPY_BM_CHECK_SOURCE_OBJ(bm, "BMLoop.copy_from_face_interp(face)", py_face);
+ BPY_BM_CHECK_SOURCE_OBJ(bm, "BMLoop.copy_from_face_interp(face)", py_face);
- BM_loop_interp_from_face(bm, self->l, py_face->f, do_vertex, do_multires);
+ BM_loop_interp_from_face(bm, self->l, py_face->f, do_vertex, do_multires);
- Py_RETURN_NONE;
- }
+ Py_RETURN_NONE;
+ }
}
-
PyDoc_STRVAR(bpy_bmloop_calc_angle_doc,
-".. method:: calc_angle()\n"
-"\n"
-" Return the angle at this loops corner of the face.\n"
-" This is calculated so sharper corners give lower angles.\n"
-"\n"
-" :return: The angle in radians.\n"
-" :rtype: float\n"
-);
+ ".. method:: calc_angle()\n"
+ "\n"
+ " Return the angle at this loops corner of the face.\n"
+ " This is calculated so sharper corners give lower angles.\n"
+ "\n"
+ " :return: The angle in radians.\n"
+ " :rtype: float\n");
static PyObject *bpy_bmloop_calc_angle(BPy_BMLoop *self)
{
- BPY_BM_CHECK_OBJ(self);
- return PyFloat_FromDouble(BM_loop_calc_face_angle(self->l));
+ BPY_BM_CHECK_OBJ(self);
+ return PyFloat_FromDouble(BM_loop_calc_face_angle(self->l));
}
PyDoc_STRVAR(bpy_bmloop_calc_normal_doc,
-".. method:: calc_normal()\n"
-"\n"
-" Return normal at this loops corner of the face.\n"
-" Falls back to the face normal for straight lines.\n"
-"\n"
-" :return: a normalized vector.\n"
-" :rtype: :class:`mathutils.Vector`\n"
-);
+ ".. method:: calc_normal()\n"
+ "\n"
+ " Return normal at this loops corner of the face.\n"
+ " Falls back to the face normal for straight lines.\n"
+ "\n"
+ " :return: a normalized vector.\n"
+ " :rtype: :class:`mathutils.Vector`\n");
static PyObject *bpy_bmloop_calc_normal(BPy_BMLoop *self)
{
- float vec[3];
- BPY_BM_CHECK_OBJ(self);
- BM_loop_calc_face_normal(self->l, vec);
- return Vector_CreatePyObject(vec, 3, NULL);
-}
-
-PyDoc_STRVAR(bpy_bmloop_calc_tangent_doc,
-".. method:: calc_tangent()\n"
-"\n"
-" Return the tangent at this loops corner of the face (pointing inward into the face).\n"
-" Falls back to the face normal for straight lines.\n"
-"\n"
-" :return: a normalized vector.\n"
-" :rtype: :class:`mathutils.Vector`\n"
-);
+ float vec[3];
+ BPY_BM_CHECK_OBJ(self);
+ BM_loop_calc_face_normal(self->l, vec);
+ return Vector_CreatePyObject(vec, 3, NULL);
+}
+
+PyDoc_STRVAR(
+ bpy_bmloop_calc_tangent_doc,
+ ".. method:: calc_tangent()\n"
+ "\n"
+ " Return the tangent at this loops corner of the face (pointing inward into the face).\n"
+ " Falls back to the face normal for straight lines.\n"
+ "\n"
+ " :return: a normalized vector.\n"
+ " :rtype: :class:`mathutils.Vector`\n");
static PyObject *bpy_bmloop_calc_tangent(BPy_BMLoop *self)
{
- float vec[3];
- BPY_BM_CHECK_OBJ(self);
- BM_loop_calc_face_tangent(self->l, vec);
- return Vector_CreatePyObject(vec, 3, NULL);
+ float vec[3];
+ BPY_BM_CHECK_OBJ(self);
+ BM_loop_calc_face_tangent(self->l, vec);
+ return Vector_CreatePyObject(vec, 3, NULL);
}
/* Vert Seq
* -------- */
PyDoc_STRVAR(bpy_bmvertseq_new_doc,
-".. method:: new(co=(0.0, 0.0, 0.0), example=None)\n"
-"\n"
-" Create a new vertex.\n"
-"\n"
-" :arg co: The initial location of the vertex (optional argument).\n"
-" :type co: float triplet\n"
-" :arg example: Existing vert to initialize settings.\n"
-" :type example: :class:`BMVert`\n"
-" :return: The newly created edge.\n"
-" :rtype: :class:`BMVert`\n"
-);
+ ".. method:: new(co=(0.0, 0.0, 0.0), example=None)\n"
+ "\n"
+ " Create a new vertex.\n"
+ "\n"
+ " :arg co: The initial location of the vertex (optional argument).\n"
+ " :type co: float triplet\n"
+ " :arg example: Existing vert to initialize settings.\n"
+ " :type example: :class:`BMVert`\n"
+ " :return: The newly created edge.\n"
+ " :rtype: :class:`BMVert`\n");
static PyObject *bpy_bmvertseq_new(BPy_BMElemSeq *self, PyObject *args)
{
- PyObject *py_co = NULL;
- BPy_BMVert *py_vert_example = NULL; /* optional */
+ PyObject *py_co = NULL;
+ BPy_BMVert *py_vert_example = NULL; /* optional */
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "|OO!:verts.new",
- &py_co,
- &BPy_BMVert_Type, &py_vert_example))
- {
- return NULL;
- }
- else {
- BMesh *bm = self->bm;
- BMVert *v;
- float co[3] = {0.0f, 0.0f, 0.0f};
+ if (!PyArg_ParseTuple(args, "|OO!:verts.new", &py_co, &BPy_BMVert_Type, &py_vert_example)) {
+ return NULL;
+ }
+ else {
+ BMesh *bm = self->bm;
+ BMVert *v;
+ float co[3] = {0.0f, 0.0f, 0.0f};
- if (py_vert_example) {
- BPY_BM_CHECK_OBJ(py_vert_example);
- }
+ if (py_vert_example) {
+ BPY_BM_CHECK_OBJ(py_vert_example);
+ }
- if (py_co && mathutils_array_parse(co, 3, 3, py_co, "verts.new(co)") == -1) {
- return NULL;
- }
+ if (py_co && mathutils_array_parse(co, 3, 3, py_co, "verts.new(co)") == -1) {
+ return NULL;
+ }
- v = BM_vert_create(bm, co, NULL, BM_CREATE_NOP);
+ v = BM_vert_create(bm, co, NULL, BM_CREATE_NOP);
- if (v == NULL) {
- PyErr_SetString(PyExc_ValueError,
- "faces.new(verts): couldn't create the new face, internal error");
- return NULL;
- }
+ if (v == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "faces.new(verts): couldn't create the new face, internal error");
+ return NULL;
+ }
- if (py_vert_example) {
- BM_elem_attrs_copy(py_vert_example->bm, bm, py_vert_example->v, v);
- }
+ if (py_vert_example) {
+ BM_elem_attrs_copy(py_vert_example->bm, bm, py_vert_example->v, v);
+ }
- return BPy_BMVert_CreatePyObject(bm, v);
- }
+ return BPy_BMVert_CreatePyObject(bm, v);
+ }
}
-
/* Edge Seq
* -------- */
PyDoc_STRVAR(bpy_bmedgeseq_new_doc,
-".. method:: new(verts, example=None)\n"
-"\n"
-" Create a new edge from a given pair of verts.\n"
-"\n"
-" :arg verts: Vertex pair.\n"
-" :type verts: pair of :class:`BMVert`\n"
-" :arg example: Existing edge to initialize settings (optional argument).\n"
-" :type example: :class:`BMEdge`\n"
-" :return: The newly created edge.\n"
-" :rtype: :class:`BMEdge`\n"
-);
+ ".. method:: new(verts, example=None)\n"
+ "\n"
+ " Create a new edge from a given pair of verts.\n"
+ "\n"
+ " :arg verts: Vertex pair.\n"
+ " :type verts: pair of :class:`BMVert`\n"
+ " :arg example: Existing edge to initialize settings (optional argument).\n"
+ " :type example: :class:`BMEdge`\n"
+ " :return: The newly created edge.\n"
+ " :rtype: :class:`BMEdge`\n");
static PyObject *bpy_bmedgeseq_new(BPy_BMElemSeq *self, PyObject *args)
{
- PyObject *vert_seq;
- BPy_BMEdge *py_edge_example = NULL; /* optional */
+ PyObject *vert_seq;
+ BPy_BMEdge *py_edge_example = NULL; /* optional */
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "O|O!:edges.new",
- &vert_seq,
- &BPy_BMEdge_Type, &py_edge_example))
- {
- return NULL;
- }
- else {
- BMesh *bm = self->bm;
- BMEdge *e;
- BMVert **vert_array = NULL;
- Py_ssize_t vert_seq_len; /* always 2 */
- PyObject *ret = NULL;
+ if (!PyArg_ParseTuple(args, "O|O!:edges.new", &vert_seq, &BPy_BMEdge_Type, &py_edge_example)) {
+ return NULL;
+ }
+ else {
+ BMesh *bm = self->bm;
+ BMEdge *e;
+ BMVert **vert_array = NULL;
+ Py_ssize_t vert_seq_len; /* always 2 */
+ PyObject *ret = NULL;
- if (py_edge_example) {
- BPY_BM_CHECK_OBJ(py_edge_example);
- }
+ if (py_edge_example) {
+ BPY_BM_CHECK_OBJ(py_edge_example);
+ }
- vert_array = BPy_BMElem_PySeq_As_Array(&bm, vert_seq, 2, 2,
- &vert_seq_len, BM_VERT,
- true, true, "edges.new(...)");
+ vert_array = BPy_BMElem_PySeq_As_Array(
+ &bm, vert_seq, 2, 2, &vert_seq_len, BM_VERT, true, true, "edges.new(...)");
- if (vert_array == NULL) {
- return NULL;
- }
+ if (vert_array == NULL) {
+ return NULL;
+ }
- if (BM_edge_exists(vert_array[0], vert_array[1])) {
- PyErr_SetString(PyExc_ValueError,
- "edges.new(): this edge exists");
- goto cleanup;
- }
+ if (BM_edge_exists(vert_array[0], vert_array[1])) {
+ PyErr_SetString(PyExc_ValueError, "edges.new(): this edge exists");
+ goto cleanup;
+ }
- e = BM_edge_create(bm, vert_array[0], vert_array[1], NULL, BM_CREATE_NOP);
+ e = BM_edge_create(bm, vert_array[0], vert_array[1], NULL, BM_CREATE_NOP);
- if (e == NULL) {
- PyErr_SetString(PyExc_ValueError,
- "faces.new(verts): couldn't create the new face, internal error");
- goto cleanup;
- }
+ if (e == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "faces.new(verts): couldn't create the new face, internal error");
+ goto cleanup;
+ }
- if (py_edge_example) {
- BM_elem_attrs_copy(py_edge_example->bm, bm, py_edge_example->e, e);
- }
+ if (py_edge_example) {
+ BM_elem_attrs_copy(py_edge_example->bm, bm, py_edge_example->e, e);
+ }
- ret = BPy_BMEdge_CreatePyObject(bm, e);
+ ret = BPy_BMEdge_CreatePyObject(bm, e);
-cleanup:
- if (vert_array) {
- PyMem_FREE(vert_array);
- }
- return ret;
- }
+ cleanup:
+ if (vert_array) {
+ PyMem_FREE(vert_array);
+ }
+ return ret;
+ }
}
-
/* Face Seq
* -------- */
PyDoc_STRVAR(bpy_bmfaceseq_new_doc,
-".. method:: new(verts, example=None)\n"
-"\n"
-" Create a new face from a given set of verts.\n"
-"\n"
-" :arg verts: Sequence of 3 or more verts.\n"
-" :type verts: :class:`BMVert`\n"
-" :arg example: Existing face to initialize settings (optional argument).\n"
-" :type example: :class:`BMFace`\n"
-" :return: The newly created face.\n"
-" :rtype: :class:`BMFace`\n"
-);
+ ".. method:: new(verts, example=None)\n"
+ "\n"
+ " Create a new face from a given set of verts.\n"
+ "\n"
+ " :arg verts: Sequence of 3 or more verts.\n"
+ " :type verts: :class:`BMVert`\n"
+ " :arg example: Existing face to initialize settings (optional argument).\n"
+ " :type example: :class:`BMFace`\n"
+ " :return: The newly created face.\n"
+ " :rtype: :class:`BMFace`\n");
static PyObject *bpy_bmfaceseq_new(BPy_BMElemSeq *self, PyObject *args)
{
- PyObject *vert_seq;
- BPy_BMFace *py_face_example = NULL; /* optional */
+ PyObject *vert_seq;
+ BPy_BMFace *py_face_example = NULL; /* optional */
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "O|O!:faces.new",
- &vert_seq,
- &BPy_BMFace_Type, &py_face_example))
- {
- return NULL;
- }
- else {
- BMesh *bm = self->bm;
- Py_ssize_t vert_seq_len;
+ if (!PyArg_ParseTuple(args, "O|O!:faces.new", &vert_seq, &BPy_BMFace_Type, &py_face_example)) {
+ return NULL;
+ }
+ else {
+ BMesh *bm = self->bm;
+ Py_ssize_t vert_seq_len;
- BMVert **vert_array = NULL;
+ BMVert **vert_array = NULL;
- PyObject *ret = NULL;
+ PyObject *ret = NULL;
- BMFace *f_new;
+ BMFace *f_new;
- if (py_face_example) {
- BPY_BM_CHECK_OBJ(py_face_example);
- }
+ if (py_face_example) {
+ BPY_BM_CHECK_OBJ(py_face_example);
+ }
- vert_array = BPy_BMElem_PySeq_As_Array(&bm, vert_seq, 3, PY_SSIZE_T_MAX,
- &vert_seq_len, BM_VERT,
- true, true, "faces.new(...)");
+ vert_array = BPy_BMElem_PySeq_As_Array(
+ &bm, vert_seq, 3, PY_SSIZE_T_MAX, &vert_seq_len, BM_VERT, true, true, "faces.new(...)");
- if (vert_array == NULL) {
- return NULL;
- }
+ if (vert_array == NULL) {
+ return NULL;
+ }
- /* check if the face exists */
- if (BM_face_exists(vert_array, vert_seq_len) != NULL) {
- PyErr_SetString(PyExc_ValueError,
- "faces.new(verts): face already exists");
- goto cleanup;
- }
+ /* check if the face exists */
+ if (BM_face_exists(vert_array, vert_seq_len) != NULL) {
+ PyErr_SetString(PyExc_ValueError, "faces.new(verts): face already exists");
+ goto cleanup;
+ }
- /* Go ahead and make the face!
- * --------------------------- */
+ /* Go ahead and make the face!
+ * --------------------------- */
- f_new = BM_face_create_verts(bm, vert_array, vert_seq_len,
- py_face_example ? py_face_example->f : NULL, BM_CREATE_NOP, true);
+ f_new = BM_face_create_verts(bm,
+ vert_array,
+ vert_seq_len,
+ py_face_example ? py_face_example->f : NULL,
+ BM_CREATE_NOP,
+ true);
- if (UNLIKELY(f_new == NULL)) {
- PyErr_SetString(PyExc_ValueError,
- "faces.new(verts): couldn't create the new face, internal error");
- goto cleanup;
- }
+ if (UNLIKELY(f_new == NULL)) {
+ PyErr_SetString(PyExc_ValueError,
+ "faces.new(verts): couldn't create the new face, internal error");
+ goto cleanup;
+ }
- ret = BPy_BMFace_CreatePyObject(bm, f_new);
+ ret = BPy_BMFace_CreatePyObject(bm, f_new);
- /* pass through */
-cleanup:
- if (vert_array) {
- PyMem_FREE(vert_array);
- }
- return ret;
- }
+ /* pass through */
+ cleanup:
+ if (vert_array) {
+ PyMem_FREE(vert_array);
+ }
+ return ret;
+ }
}
/* Elem Seq
* -------- */
PyDoc_STRVAR(bpy_bmvertseq_remove_doc,
-".. method:: remove(vert)\n"
-"\n"
-" Remove a vert.\n"
-);
+ ".. method:: remove(vert)\n"
+ "\n"
+ " Remove a vert.\n");
static PyObject *bpy_bmvertseq_remove(BPy_BMElemSeq *self, BPy_BMVert *value)
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if (!BPy_BMVert_Check(value)) {
- return NULL;
- }
- else {
- BMesh *bm = self->bm;
+ if (!BPy_BMVert_Check(value)) {
+ return NULL;
+ }
+ else {
+ BMesh *bm = self->bm;
- BPY_BM_CHECK_SOURCE_OBJ(bm, "verts.remove(vert)", value);
+ BPY_BM_CHECK_SOURCE_OBJ(bm, "verts.remove(vert)", value);
- BM_vert_kill(bm, value->v);
- bpy_bm_generic_invalidate((BPy_BMGeneric *)value);
+ BM_vert_kill(bm, value->v);
+ bpy_bm_generic_invalidate((BPy_BMGeneric *)value);
- Py_RETURN_NONE;
- }
+ Py_RETURN_NONE;
+ }
}
PyDoc_STRVAR(bpy_bmedgeseq_remove_doc,
-".. method:: remove(edge)\n"
-"\n"
-" Remove an edge.\n"
-);
+ ".. method:: remove(edge)\n"
+ "\n"
+ " Remove an edge.\n");
static PyObject *bpy_bmedgeseq_remove(BPy_BMElemSeq *self, BPy_BMEdge *value)
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if (!BPy_BMEdge_Check(value)) {
- return NULL;
- }
- else {
- BMesh *bm = self->bm;
+ if (!BPy_BMEdge_Check(value)) {
+ return NULL;
+ }
+ else {
+ BMesh *bm = self->bm;
- BPY_BM_CHECK_SOURCE_OBJ(bm, "edges.remove(edges)", value);
+ BPY_BM_CHECK_SOURCE_OBJ(bm, "edges.remove(edges)", value);
- BM_edge_kill(bm, value->e);
- bpy_bm_generic_invalidate((BPy_BMGeneric *)value);
+ BM_edge_kill(bm, value->e);
+ bpy_bm_generic_invalidate((BPy_BMGeneric *)value);
- Py_RETURN_NONE;
- }
+ Py_RETURN_NONE;
+ }
}
PyDoc_STRVAR(bpy_bmfaceseq_remove_doc,
-".. method:: remove(face)\n"
-"\n"
-" Remove a face.\n"
-);
+ ".. method:: remove(face)\n"
+ "\n"
+ " Remove a face.\n");
static PyObject *bpy_bmfaceseq_remove(BPy_BMElemSeq *self, BPy_BMFace *value)
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if (!BPy_BMFace_Check(value)) {
- return NULL;
- }
- else {
- BMesh *bm = self->bm;
+ if (!BPy_BMFace_Check(value)) {
+ return NULL;
+ }
+ else {
+ BMesh *bm = self->bm;
- BPY_BM_CHECK_SOURCE_OBJ(bm, "faces.remove(face)", value);
+ BPY_BM_CHECK_SOURCE_OBJ(bm, "faces.remove(face)", value);
- BM_face_kill(bm, value->f);
- bpy_bm_generic_invalidate((BPy_BMGeneric *)value);
+ BM_face_kill(bm, value->f);
+ bpy_bm_generic_invalidate((BPy_BMGeneric *)value);
- Py_RETURN_NONE;
- }
+ Py_RETURN_NONE;
+ }
}
PyDoc_STRVAR(bpy_bmedgeseq_get__method_doc,
-".. method:: get(verts, fallback=None)\n"
-"\n"
-" Return an edge which uses the **verts** passed.\n"
-"\n"
-" :arg verts: Sequence of verts.\n"
-" :type verts: :class:`BMVert`\n"
-" :arg fallback: Return this value if nothing is found.\n"
-" :return: The edge found or None\n"
-" :rtype: :class:`BMEdge`\n"
-);
+ ".. method:: get(verts, fallback=None)\n"
+ "\n"
+ " Return an edge which uses the **verts** passed.\n"
+ "\n"
+ " :arg verts: Sequence of verts.\n"
+ " :type verts: :class:`BMVert`\n"
+ " :arg fallback: Return this value if nothing is found.\n"
+ " :return: The edge found or None\n"
+ " :rtype: :class:`BMEdge`\n");
static PyObject *bpy_bmedgeseq_get__method(BPy_BMElemSeq *self, PyObject *args)
{
- PyObject *vert_seq;
- PyObject *fallback = Py_None; /* optional */
-
- BPY_BM_CHECK_OBJ(self);
-
- if (!PyArg_ParseTuple(args, "O|O:edges.get",
- &vert_seq,
- &fallback))
- {
- return NULL;
- }
- else {
- BMesh *bm = self->bm;
- BMEdge *e;
- BMVert **vert_array = NULL;
- Py_ssize_t vert_seq_len; /* always 2 */
- PyObject *ret = NULL;
-
- vert_array = BPy_BMElem_PySeq_As_Array(&bm, vert_seq, 2, 2,
- &vert_seq_len, BM_VERT,
- true, true, "edges.get(...)");
-
- if (vert_array == NULL) {
- return NULL;
- }
-
- if ((e = BM_edge_exists(vert_array[0], vert_array[1]))) {
- ret = BPy_BMEdge_CreatePyObject(bm, e);
- }
- else {
- ret = fallback;
- Py_INCREF(ret);
- }
-
- PyMem_FREE(vert_array);
- return ret;
- }
+ PyObject *vert_seq;
+ PyObject *fallback = Py_None; /* optional */
+
+ BPY_BM_CHECK_OBJ(self);
+
+ if (!PyArg_ParseTuple(args, "O|O:edges.get", &vert_seq, &fallback)) {
+ return NULL;
+ }
+ else {
+ BMesh *bm = self->bm;
+ BMEdge *e;
+ BMVert **vert_array = NULL;
+ Py_ssize_t vert_seq_len; /* always 2 */
+ PyObject *ret = NULL;
+
+ vert_array = BPy_BMElem_PySeq_As_Array(
+ &bm, vert_seq, 2, 2, &vert_seq_len, BM_VERT, true, true, "edges.get(...)");
+
+ if (vert_array == NULL) {
+ return NULL;
+ }
+
+ if ((e = BM_edge_exists(vert_array[0], vert_array[1]))) {
+ ret = BPy_BMEdge_CreatePyObject(bm, e);
+ }
+ else {
+ ret = fallback;
+ Py_INCREF(ret);
+ }
+
+ PyMem_FREE(vert_array);
+ return ret;
+ }
}
PyDoc_STRVAR(bpy_bmfaceseq_get__method_doc,
-".. method:: get(verts, fallback=None)\n"
-"\n"
-" Return a face which uses the **verts** passed.\n"
-"\n"
-" :arg verts: Sequence of verts.\n"
-" :type verts: :class:`BMVert`\n"
-" :arg fallback: Return this value if nothing is found.\n"
-" :return: The face found or None\n"
-" :rtype: :class:`BMFace`\n"
-);
+ ".. method:: get(verts, fallback=None)\n"
+ "\n"
+ " Return a face which uses the **verts** passed.\n"
+ "\n"
+ " :arg verts: Sequence of verts.\n"
+ " :type verts: :class:`BMVert`\n"
+ " :arg fallback: Return this value if nothing is found.\n"
+ " :return: The face found or None\n"
+ " :rtype: :class:`BMFace`\n");
static PyObject *bpy_bmfaceseq_get__method(BPy_BMElemSeq *self, PyObject *args)
{
- PyObject *vert_seq;
- PyObject *fallback = Py_None; /* optional */
-
- BPY_BM_CHECK_OBJ(self);
-
- if (!PyArg_ParseTuple(args, "O|O:faces.get",
- &vert_seq,
- &fallback))
- {
- return NULL;
- }
- else {
- BMesh *bm = self->bm;
- BMFace *f = NULL;
- BMVert **vert_array = NULL;
- Py_ssize_t vert_seq_len;
- PyObject *ret = NULL;
-
- vert_array = BPy_BMElem_PySeq_As_Array(&bm, vert_seq, 1, PY_SSIZE_T_MAX,
- &vert_seq_len, BM_VERT,
- true, true, "faces.get(...)");
-
- if (vert_array == NULL) {
- return NULL;
- }
-
- f = BM_face_exists(vert_array, vert_seq_len);
- if (f != NULL) {
- ret = BPy_BMFace_CreatePyObject(bm, f);
- }
- else {
- ret = fallback;
- Py_INCREF(ret);
- }
-
- PyMem_FREE(vert_array);
- return ret;
- }
-}
-
-PyDoc_STRVAR(bpy_bmelemseq_index_update_doc,
-".. method:: index_update()\n"
-"\n"
-" Initialize the index values of this sequence.\n"
-"\n"
-" This is the equivalent of looping over all elements and assigning the index values.\n"
-"\n"
-" .. code-block:: python\n"
-"\n"
-" for index, ele in enumerate(sequence):\n"
-" ele.index = index\n"
-"\n"
-" .. note::\n"
-"\n"
-" Running this on sequences besides :class:`BMesh.verts`, :class:`BMesh.edges`, :class:`BMesh.faces`\n"
-" works but wont result in each element having a valid index, instead its order in the sequence will be set.\n"
-);
+ PyObject *vert_seq;
+ PyObject *fallback = Py_None; /* optional */
+
+ BPY_BM_CHECK_OBJ(self);
+
+ if (!PyArg_ParseTuple(args, "O|O:faces.get", &vert_seq, &fallback)) {
+ return NULL;
+ }
+ else {
+ BMesh *bm = self->bm;
+ BMFace *f = NULL;
+ BMVert **vert_array = NULL;
+ Py_ssize_t vert_seq_len;
+ PyObject *ret = NULL;
+
+ vert_array = BPy_BMElem_PySeq_As_Array(
+ &bm, vert_seq, 1, PY_SSIZE_T_MAX, &vert_seq_len, BM_VERT, true, true, "faces.get(...)");
+
+ if (vert_array == NULL) {
+ return NULL;
+ }
+
+ f = BM_face_exists(vert_array, vert_seq_len);
+ if (f != NULL) {
+ ret = BPy_BMFace_CreatePyObject(bm, f);
+ }
+ else {
+ ret = fallback;
+ Py_INCREF(ret);
+ }
+
+ PyMem_FREE(vert_array);
+ return ret;
+ }
+}
+
+PyDoc_STRVAR(
+ bpy_bmelemseq_index_update_doc,
+ ".. method:: index_update()\n"
+ "\n"
+ " Initialize the index values of this sequence.\n"
+ "\n"
+ " This is the equivalent of looping over all elements and assigning the index values.\n"
+ "\n"
+ " .. code-block:: python\n"
+ "\n"
+ " for index, ele in enumerate(sequence):\n"
+ " ele.index = index\n"
+ "\n"
+ " .. note::\n"
+ "\n"
+ " Running this on sequences besides :class:`BMesh.verts`, :class:`BMesh.edges`, "
+ ":class:`BMesh.faces`\n"
+ " works but wont result in each element having a valid index, instead its order in the "
+ "sequence will be set.\n");
static PyObject *bpy_bmelemseq_index_update(BPy_BMElemSeq *self)
{
- BMesh *bm = self->bm;
+ BMesh *bm = self->bm;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- switch ((BMIterType)self->itype) {
- case BM_VERTS_OF_MESH:
- BM_mesh_elem_index_ensure(self->bm, BM_VERT);
- break;
- case BM_EDGES_OF_MESH:
- BM_mesh_elem_index_ensure(self->bm, BM_EDGE);
- break;
- case BM_FACES_OF_MESH:
- BM_mesh_elem_index_ensure(self->bm, BM_FACE);
- break;
- default:
- {
- BMIter iter;
- BMElem *ele;
- int index = 0;
- const char htype = bm_iter_itype_htype_map[self->itype];
+ switch ((BMIterType)self->itype) {
+ case BM_VERTS_OF_MESH:
+ BM_mesh_elem_index_ensure(self->bm, BM_VERT);
+ break;
+ case BM_EDGES_OF_MESH:
+ BM_mesh_elem_index_ensure(self->bm, BM_EDGE);
+ break;
+ case BM_FACES_OF_MESH:
+ BM_mesh_elem_index_ensure(self->bm, BM_FACE);
+ break;
+ default: {
+ BMIter iter;
+ BMElem *ele;
+ int index = 0;
+ const char htype = bm_iter_itype_htype_map[self->itype];
- BM_ITER_BPY_BM_SEQ (ele, &iter, self) {
- BM_elem_index_set(ele, index); /* set_dirty! */
- index++;
- }
+ BM_ITER_BPY_BM_SEQ(ele, &iter, self)
+ {
+ BM_elem_index_set(ele, index); /* set_dirty! */
+ index++;
+ }
- /* since this isn't the normal vert/edge/face loops,
- * we're setting dirty values here. so tag as dirty. */
- bm->elem_index_dirty |= htype;
+ /* since this isn't the normal vert/edge/face loops,
+ * we're setting dirty values here. so tag as dirty. */
+ bm->elem_index_dirty |= htype;
- break;
- }
- }
+ break;
+ }
+ }
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(bpy_bmelemseq_ensure_lookup_table_doc,
-".. method:: ensure_lookup_table()\n"
-"\n"
-" Ensure internal data needed for int subscription is initialized with verts/edges/faces, eg ``bm.verts[index]``.\n"
-"\n"
-" This needs to be called again after adding/removing data in this sequence."
-);
+ ".. method:: ensure_lookup_table()\n"
+ "\n"
+ " Ensure internal data needed for int subscription is initialized with "
+ "verts/edges/faces, eg ``bm.verts[index]``.\n"
+ "\n"
+ " This needs to be called again after adding/removing data in this sequence.");
static PyObject *bpy_bmelemseq_ensure_lookup_table(BPy_BMElemSeq *self)
{
- BPY_BM_CHECK_OBJ(self);
-
- BM_mesh_elem_table_ensure(self->bm, bm_iter_itype_htype_map[self->itype]);
-
- Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(bpy_bmelemseq_sort_doc,
-".. method:: sort(key=None, reverse=False)\n"
-"\n"
-" Sort the elements of this sequence, using an optional custom sort key.\n"
-" Indices of elements are not changed, BMElemeSeq.index_update() can be used for that.\n"
-"\n"
-" :arg key: The key that sets the ordering of the elements.\n"
-" :type key: :function: returning a number\n"
-" :arg reverse: Reverse the order of the elements\n"
-" :type reverse: :boolean:\n"
-"\n"
-" .. note::\n"
-"\n"
-" When the 'key' argument is not provided, the elements are reordered following their current index value.\n"
-" In particular this can be used by setting indices manually before calling this method.\n"
-"\n"
-" .. warning::\n"
-"\n"
-" Existing references to the N'th element, will continue to point the data at that index.\n"
-);
+ BPY_BM_CHECK_OBJ(self);
+
+ BM_mesh_elem_table_ensure(self->bm, bm_iter_itype_htype_map[self->itype]);
+
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(
+ bpy_bmelemseq_sort_doc,
+ ".. method:: sort(key=None, reverse=False)\n"
+ "\n"
+ " Sort the elements of this sequence, using an optional custom sort key.\n"
+ " Indices of elements are not changed, BMElemeSeq.index_update() can be used for that.\n"
+ "\n"
+ " :arg key: The key that sets the ordering of the elements.\n"
+ " :type key: :function: returning a number\n"
+ " :arg reverse: Reverse the order of the elements\n"
+ " :type reverse: :boolean:\n"
+ "\n"
+ " .. note::\n"
+ "\n"
+ " When the 'key' argument is not provided, the elements are reordered following their "
+ "current index value.\n"
+ " In particular this can be used by setting indices manually before calling this "
+ "method.\n"
+ "\n"
+ " .. warning::\n"
+ "\n"
+ " Existing references to the N'th element, will continue to point the data at that "
+ "index.\n");
/* Use a static variable here because there is the need to sort some array
* doing comparisons on elements of another array, qsort_r would have been
@@ -2536,320 +2662,439 @@ PyDoc_STRVAR(bpy_bmelemseq_sort_doc,
* has enough elements to complete the task.
*/
-static int bpy_bmelemseq_sort_cmp_by_keys_ascending(const void *index1_v, const void *index2_v, void *keys_v)
+static int bpy_bmelemseq_sort_cmp_by_keys_ascending(const void *index1_v,
+ const void *index2_v,
+ void *keys_v)
{
- const double *keys = keys_v;
- const int *index1 = (int *)index1_v;
- const int *index2 = (int *)index2_v;
+ const double *keys = keys_v;
+ const int *index1 = (int *)index1_v;
+ const int *index2 = (int *)index2_v;
- if (keys[*index1] < keys[*index2]) {
- return -1;
- }
- else if (keys[*index1] > keys[*index2]) {
- return 1;
- }
- else {
- return 0;
- }
+ if (keys[*index1] < keys[*index2]) {
+ return -1;
+ }
+ else if (keys[*index1] > keys[*index2]) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
-static int bpy_bmelemseq_sort_cmp_by_keys_descending(const void *index1_v, const void *index2_v, void *keys_v)
+static int bpy_bmelemseq_sort_cmp_by_keys_descending(const void *index1_v,
+ const void *index2_v,
+ void *keys_v)
{
- return -bpy_bmelemseq_sort_cmp_by_keys_ascending(index1_v, index2_v, keys_v);
+ return -bpy_bmelemseq_sort_cmp_by_keys_ascending(index1_v, index2_v, keys_v);
}
static PyObject *bpy_bmelemseq_sort(BPy_BMElemSeq *self, PyObject *args, PyObject *kw)
{
- static const char *kwlist[] = {"key", "reverse", NULL};
- PyObject *keyfunc = NULL; /* optional */
- bool do_reverse = false; /* optional */
-
- const char htype = bm_iter_itype_htype_map[self->itype];
- int n_elem;
-
- BMIter iter;
- BMElem *ele;
-
- double *keys;
- int *elem_idx;
- unsigned int *elem_map_idx;
- int (*elem_idx_compare_by_keys)(const void *, const void *, void *);
-
- unsigned int *vert_idx = NULL;
- unsigned int *edge_idx = NULL;
- unsigned int *face_idx = NULL;
- int i;
-
- BMesh *bm = self->bm;
-
- BPY_BM_CHECK_OBJ(self);
-
- if (args != NULL) {
- if (!PyArg_ParseTupleAndKeywords(
- args, kw,
- "|OO&:BMElemSeq.sort", (char **)kwlist,
- &keyfunc,
- PyC_ParseBool, &do_reverse))
- {
- return NULL;
- }
- }
-
- if (keyfunc != NULL && !PyCallable_Check(keyfunc)) {
- PyErr_SetString(PyExc_TypeError,
- "the 'key' argument is not a callable object");
- return NULL;
- }
-
- n_elem = BM_mesh_elem_count(bm, htype);
- if (n_elem <= 1) {
- /* 0 or 1 elements: sorted already */
- Py_RETURN_NONE;
- }
-
- keys = PyMem_MALLOC(sizeof(*keys) * n_elem);
- if (keys == NULL) {
- PyErr_NoMemory();
- return NULL;
- }
-
- i = 0;
- BM_ITER_BPY_BM_SEQ (ele, &iter, self) {
- if (keyfunc != NULL) {
- PyObject *py_elem;
- PyObject *index;
-
- py_elem = BPy_BMElem_CreatePyObject(self->bm, (BMHeader *)ele);
- index = PyObject_CallFunctionObjArgs(keyfunc, py_elem, NULL);
- Py_DECREF(py_elem);
- if (index == NULL) {
- /* No need to set the exception here,
- * PyObject_CallFunctionObjArgs() does that */
- PyMem_FREE(keys);
- return NULL;
- }
-
- if ((keys[i] = PyFloat_AsDouble(index)) == -1 && PyErr_Occurred()) {
- PyErr_SetString(PyExc_ValueError,
- "the value returned by the 'key' function is not a number");
- Py_DECREF(index);
- PyMem_FREE(keys);
- return NULL;
- }
-
- Py_DECREF(index);
- }
- else {
- /* If the 'key' function is not provided we sort
- * according to the current index values */
- keys[i] = ele->head.index;
- }
-
- i++;
- }
-
- elem_idx = PyMem_MALLOC(sizeof(*elem_idx) * n_elem);
- if (elem_idx == NULL) {
- PyErr_NoMemory();
- PyMem_FREE(keys);
- return NULL;
- }
-
- /* Initialize the element index array */
- range_vn_i(elem_idx, n_elem, 0);
-
- /* Sort the index array according to the order of the 'keys' array */
- if (do_reverse) {
- elem_idx_compare_by_keys = bpy_bmelemseq_sort_cmp_by_keys_descending;
- }
- else {
- elem_idx_compare_by_keys = bpy_bmelemseq_sort_cmp_by_keys_ascending;
- }
-
- BLI_qsort_r(elem_idx, n_elem, sizeof(*elem_idx), elem_idx_compare_by_keys, keys);
-
- elem_map_idx = PyMem_MALLOC(sizeof(*elem_map_idx) * n_elem);
- if (elem_map_idx == NULL) {
- PyErr_NoMemory();
- PyMem_FREE(elem_idx);
- PyMem_FREE(keys);
- return NULL;
- }
-
- /* Initialize the map array
- *
- * We need to know the index such that if used as the new_index in
- * BM_mesh_remap() will give the order of the sorted keys like in
- * elem_idx */
- for (i = 0; i < n_elem; i++) {
- elem_map_idx[elem_idx[i]] = i;
- }
-
- switch ((BMIterType)self->itype) {
- case BM_VERTS_OF_MESH:
- vert_idx = elem_map_idx;
- break;
- case BM_EDGES_OF_MESH:
- edge_idx = elem_map_idx;
- break;
- case BM_FACES_OF_MESH:
- face_idx = elem_map_idx;
- break;
- default:
- PyErr_Format(PyExc_TypeError, "element type %d not supported", self->itype);
- PyMem_FREE(elem_map_idx);
- PyMem_FREE(elem_idx);
- PyMem_FREE(keys);
- return NULL;
- }
-
- BM_mesh_remap(bm, vert_idx, edge_idx, face_idx);
-
- PyMem_FREE(elem_map_idx);
- PyMem_FREE(elem_idx);
- PyMem_FREE(keys);
-
- Py_RETURN_NONE;
+ static const char *kwlist[] = {"key", "reverse", NULL};
+ PyObject *keyfunc = NULL; /* optional */
+ bool do_reverse = false; /* optional */
+
+ const char htype = bm_iter_itype_htype_map[self->itype];
+ int n_elem;
+
+ BMIter iter;
+ BMElem *ele;
+
+ double *keys;
+ int *elem_idx;
+ unsigned int *elem_map_idx;
+ int (*elem_idx_compare_by_keys)(const void *, const void *, void *);
+
+ unsigned int *vert_idx = NULL;
+ unsigned int *edge_idx = NULL;
+ unsigned int *face_idx = NULL;
+ int i;
+
+ BMesh *bm = self->bm;
+
+ BPY_BM_CHECK_OBJ(self);
+
+ if (args != NULL) {
+ if (!PyArg_ParseTupleAndKeywords(args,
+ kw,
+ "|OO&:BMElemSeq.sort",
+ (char **)kwlist,
+ &keyfunc,
+ PyC_ParseBool,
+ &do_reverse)) {
+ return NULL;
+ }
+ }
+
+ if (keyfunc != NULL && !PyCallable_Check(keyfunc)) {
+ PyErr_SetString(PyExc_TypeError, "the 'key' argument is not a callable object");
+ return NULL;
+ }
+
+ n_elem = BM_mesh_elem_count(bm, htype);
+ if (n_elem <= 1) {
+ /* 0 or 1 elements: sorted already */
+ Py_RETURN_NONE;
+ }
+
+ keys = PyMem_MALLOC(sizeof(*keys) * n_elem);
+ if (keys == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ i = 0;
+ BM_ITER_BPY_BM_SEQ(ele, &iter, self)
+ {
+ if (keyfunc != NULL) {
+ PyObject *py_elem;
+ PyObject *index;
+
+ py_elem = BPy_BMElem_CreatePyObject(self->bm, (BMHeader *)ele);
+ index = PyObject_CallFunctionObjArgs(keyfunc, py_elem, NULL);
+ Py_DECREF(py_elem);
+ if (index == NULL) {
+ /* No need to set the exception here,
+ * PyObject_CallFunctionObjArgs() does that */
+ PyMem_FREE(keys);
+ return NULL;
+ }
+
+ if ((keys[i] = PyFloat_AsDouble(index)) == -1 && PyErr_Occurred()) {
+ PyErr_SetString(PyExc_ValueError,
+ "the value returned by the 'key' function is not a number");
+ Py_DECREF(index);
+ PyMem_FREE(keys);
+ return NULL;
+ }
+
+ Py_DECREF(index);
+ }
+ else {
+ /* If the 'key' function is not provided we sort
+ * according to the current index values */
+ keys[i] = ele->head.index;
+ }
+
+ i++;
+ }
+
+ elem_idx = PyMem_MALLOC(sizeof(*elem_idx) * n_elem);
+ if (elem_idx == NULL) {
+ PyErr_NoMemory();
+ PyMem_FREE(keys);
+ return NULL;
+ }
+
+ /* Initialize the element index array */
+ range_vn_i(elem_idx, n_elem, 0);
+
+ /* Sort the index array according to the order of the 'keys' array */
+ if (do_reverse) {
+ elem_idx_compare_by_keys = bpy_bmelemseq_sort_cmp_by_keys_descending;
+ }
+ else {
+ elem_idx_compare_by_keys = bpy_bmelemseq_sort_cmp_by_keys_ascending;
+ }
+
+ BLI_qsort_r(elem_idx, n_elem, sizeof(*elem_idx), elem_idx_compare_by_keys, keys);
+
+ elem_map_idx = PyMem_MALLOC(sizeof(*elem_map_idx) * n_elem);
+ if (elem_map_idx == NULL) {
+ PyErr_NoMemory();
+ PyMem_FREE(elem_idx);
+ PyMem_FREE(keys);
+ return NULL;
+ }
+
+ /* Initialize the map array
+ *
+ * We need to know the index such that if used as the new_index in
+ * BM_mesh_remap() will give the order of the sorted keys like in
+ * elem_idx */
+ for (i = 0; i < n_elem; i++) {
+ elem_map_idx[elem_idx[i]] = i;
+ }
+
+ switch ((BMIterType)self->itype) {
+ case BM_VERTS_OF_MESH:
+ vert_idx = elem_map_idx;
+ break;
+ case BM_EDGES_OF_MESH:
+ edge_idx = elem_map_idx;
+ break;
+ case BM_FACES_OF_MESH:
+ face_idx = elem_map_idx;
+ break;
+ default:
+ PyErr_Format(PyExc_TypeError, "element type %d not supported", self->itype);
+ PyMem_FREE(elem_map_idx);
+ PyMem_FREE(elem_idx);
+ PyMem_FREE(keys);
+ return NULL;
+ }
+
+ BM_mesh_remap(bm, vert_idx, edge_idx, face_idx);
+
+ PyMem_FREE(elem_map_idx);
+ PyMem_FREE(elem_idx);
+ PyMem_FREE(keys);
+
+ Py_RETURN_NONE;
}
static struct PyMethodDef bpy_bmesh_methods[] = {
- /* utility */
- {"copy", (PyCFunction)bpy_bmesh_copy, METH_NOARGS, bpy_bmesh_copy_doc},
- {"clear", (PyCFunction)bpy_bmesh_clear, METH_NOARGS, bpy_bmesh_clear_doc},
- {"free", (PyCFunction)bpy_bmesh_free, METH_NOARGS, bpy_bmesh_free_doc},
-
- /* conversion */
- {"from_object", (PyCFunction)bpy_bmesh_from_object, METH_VARARGS | METH_KEYWORDS, bpy_bmesh_from_object_doc},
- {"from_mesh", (PyCFunction)bpy_bmesh_from_mesh, METH_VARARGS | METH_KEYWORDS, bpy_bmesh_from_mesh_doc},
- {"to_mesh", (PyCFunction)bpy_bmesh_to_mesh, METH_VARARGS, bpy_bmesh_to_mesh_doc},
-
- /* meshdata */
- {"select_flush_mode", (PyCFunction)bpy_bmesh_select_flush_mode, METH_NOARGS, bpy_bmesh_select_flush_mode_doc},
- {"select_flush", (PyCFunction)bpy_bmesh_select_flush, METH_O, bpy_bmesh_select_flush_doc},
- {"normal_update", (PyCFunction)bpy_bmesh_normal_update, METH_NOARGS, bpy_bmesh_normal_update_doc},
- {"transform", (PyCFunction)bpy_bmesh_transform, METH_VARARGS | METH_KEYWORDS, bpy_bmesh_transform_doc},
-
- /* calculations */
- {"calc_volume", (PyCFunction)bpy_bmesh_calc_volume, METH_VARARGS | METH_KEYWORDS, bpy_bmesh_calc_volume_doc},
- {"calc_loop_triangles", (PyCFunction)bpy_bmesh_calc_loop_triangles, METH_NOARGS, bpy_bmesh_calc_loop_triangles_doc},
- {NULL, NULL, 0, NULL},
+ /* utility */
+ {"copy", (PyCFunction)bpy_bmesh_copy, METH_NOARGS, bpy_bmesh_copy_doc},
+ {"clear", (PyCFunction)bpy_bmesh_clear, METH_NOARGS, bpy_bmesh_clear_doc},
+ {"free", (PyCFunction)bpy_bmesh_free, METH_NOARGS, bpy_bmesh_free_doc},
+
+ /* conversion */
+ {"from_object",
+ (PyCFunction)bpy_bmesh_from_object,
+ METH_VARARGS | METH_KEYWORDS,
+ bpy_bmesh_from_object_doc},
+ {"from_mesh",
+ (PyCFunction)bpy_bmesh_from_mesh,
+ METH_VARARGS | METH_KEYWORDS,
+ bpy_bmesh_from_mesh_doc},
+ {"to_mesh", (PyCFunction)bpy_bmesh_to_mesh, METH_VARARGS, bpy_bmesh_to_mesh_doc},
+
+ /* meshdata */
+ {"select_flush_mode",
+ (PyCFunction)bpy_bmesh_select_flush_mode,
+ METH_NOARGS,
+ bpy_bmesh_select_flush_mode_doc},
+ {"select_flush", (PyCFunction)bpy_bmesh_select_flush, METH_O, bpy_bmesh_select_flush_doc},
+ {"normal_update",
+ (PyCFunction)bpy_bmesh_normal_update,
+ METH_NOARGS,
+ bpy_bmesh_normal_update_doc},
+ {"transform",
+ (PyCFunction)bpy_bmesh_transform,
+ METH_VARARGS | METH_KEYWORDS,
+ bpy_bmesh_transform_doc},
+
+ /* calculations */
+ {"calc_volume",
+ (PyCFunction)bpy_bmesh_calc_volume,
+ METH_VARARGS | METH_KEYWORDS,
+ bpy_bmesh_calc_volume_doc},
+ {"calc_loop_triangles",
+ (PyCFunction)bpy_bmesh_calc_loop_triangles,
+ METH_NOARGS,
+ bpy_bmesh_calc_loop_triangles_doc},
+ {NULL, NULL, 0, NULL},
};
static struct PyMethodDef bpy_bmvert_methods[] = {
- {"select_set", (PyCFunction)bpy_bm_elem_select_set, METH_O, bpy_bm_elem_select_set_doc},
- {"hide_set", (PyCFunction)bpy_bm_elem_hide_set, METH_O, bpy_bm_elem_hide_set_doc},
- {"copy_from", (PyCFunction)bpy_bm_elem_copy_from, METH_O, bpy_bm_elem_copy_from_doc},
- {"copy_from_face_interp", (PyCFunction)bpy_bmvert_copy_from_face_interp, METH_VARARGS, bpy_bmvert_copy_from_face_interp_doc},
- {"copy_from_vert_interp", (PyCFunction)bpy_bmvert_copy_from_vert_interp, METH_VARARGS, bpy_bmvert_copy_from_vert_interp_doc},
-
- {"calc_edge_angle", (PyCFunction)bpy_bmvert_calc_edge_angle, METH_VARARGS, bpy_bmvert_calc_edge_angle_doc},
- {"calc_shell_factor", (PyCFunction)bpy_bmvert_calc_shell_factor, METH_NOARGS, bpy_bmvert_calc_shell_factor_doc},
-
- {"normal_update", (PyCFunction)bpy_bmvert_normal_update, METH_NOARGS, bpy_bmvert_normal_update_doc},
-
- {NULL, NULL, 0, NULL},
+ {"select_set", (PyCFunction)bpy_bm_elem_select_set, METH_O, bpy_bm_elem_select_set_doc},
+ {"hide_set", (PyCFunction)bpy_bm_elem_hide_set, METH_O, bpy_bm_elem_hide_set_doc},
+ {"copy_from", (PyCFunction)bpy_bm_elem_copy_from, METH_O, bpy_bm_elem_copy_from_doc},
+ {"copy_from_face_interp",
+ (PyCFunction)bpy_bmvert_copy_from_face_interp,
+ METH_VARARGS,
+ bpy_bmvert_copy_from_face_interp_doc},
+ {"copy_from_vert_interp",
+ (PyCFunction)bpy_bmvert_copy_from_vert_interp,
+ METH_VARARGS,
+ bpy_bmvert_copy_from_vert_interp_doc},
+
+ {"calc_edge_angle",
+ (PyCFunction)bpy_bmvert_calc_edge_angle,
+ METH_VARARGS,
+ bpy_bmvert_calc_edge_angle_doc},
+ {"calc_shell_factor",
+ (PyCFunction)bpy_bmvert_calc_shell_factor,
+ METH_NOARGS,
+ bpy_bmvert_calc_shell_factor_doc},
+
+ {"normal_update",
+ (PyCFunction)bpy_bmvert_normal_update,
+ METH_NOARGS,
+ bpy_bmvert_normal_update_doc},
+
+ {NULL, NULL, 0, NULL},
};
static struct PyMethodDef bpy_bmedge_methods[] = {
- {"select_set", (PyCFunction)bpy_bm_elem_select_set, METH_O, bpy_bm_elem_select_set_doc},
- {"hide_set", (PyCFunction)bpy_bm_elem_hide_set, METH_O, bpy_bm_elem_hide_set_doc},
- {"copy_from", (PyCFunction)bpy_bm_elem_copy_from, METH_O, bpy_bm_elem_copy_from_doc},
-
- {"other_vert", (PyCFunction)bpy_bmedge_other_vert, METH_O, bpy_bmedge_other_vert_doc},
-
- {"calc_length", (PyCFunction)bpy_bmedge_calc_length, METH_NOARGS, bpy_bmedge_calc_length_doc},
- {"calc_face_angle", (PyCFunction)bpy_bmedge_calc_face_angle, METH_VARARGS, bpy_bmedge_calc_face_angle_doc},
- {"calc_face_angle_signed", (PyCFunction)bpy_bmedge_calc_face_angle_signed, METH_VARARGS, bpy_bmedge_calc_face_angle_signed_doc},
- {"calc_tangent", (PyCFunction)bpy_bmedge_calc_tangent, METH_VARARGS, bpy_bmedge_calc_tangent_doc},
-
- {"normal_update", (PyCFunction)bpy_bmedge_normal_update, METH_NOARGS, bpy_bmedge_normal_update_doc},
-
- {NULL, NULL, 0, NULL},
+ {"select_set", (PyCFunction)bpy_bm_elem_select_set, METH_O, bpy_bm_elem_select_set_doc},
+ {"hide_set", (PyCFunction)bpy_bm_elem_hide_set, METH_O, bpy_bm_elem_hide_set_doc},
+ {"copy_from", (PyCFunction)bpy_bm_elem_copy_from, METH_O, bpy_bm_elem_copy_from_doc},
+
+ {"other_vert", (PyCFunction)bpy_bmedge_other_vert, METH_O, bpy_bmedge_other_vert_doc},
+
+ {"calc_length", (PyCFunction)bpy_bmedge_calc_length, METH_NOARGS, bpy_bmedge_calc_length_doc},
+ {"calc_face_angle",
+ (PyCFunction)bpy_bmedge_calc_face_angle,
+ METH_VARARGS,
+ bpy_bmedge_calc_face_angle_doc},
+ {"calc_face_angle_signed",
+ (PyCFunction)bpy_bmedge_calc_face_angle_signed,
+ METH_VARARGS,
+ bpy_bmedge_calc_face_angle_signed_doc},
+ {"calc_tangent",
+ (PyCFunction)bpy_bmedge_calc_tangent,
+ METH_VARARGS,
+ bpy_bmedge_calc_tangent_doc},
+
+ {"normal_update",
+ (PyCFunction)bpy_bmedge_normal_update,
+ METH_NOARGS,
+ bpy_bmedge_normal_update_doc},
+
+ {NULL, NULL, 0, NULL},
};
static struct PyMethodDef bpy_bmface_methods[] = {
- {"select_set", (PyCFunction)bpy_bm_elem_select_set, METH_O, bpy_bm_elem_select_set_doc},
- {"hide_set", (PyCFunction)bpy_bm_elem_hide_set, METH_O, bpy_bm_elem_hide_set_doc},
-
- {"copy_from", (PyCFunction)bpy_bm_elem_copy_from, METH_O, bpy_bm_elem_copy_from_doc},
- {"copy_from_face_interp", (PyCFunction)bpy_bmface_copy_from_face_interp, METH_O, bpy_bmface_copy_from_face_interp_doc},
-
- {"copy", (PyCFunction)bpy_bmface_copy, METH_VARARGS | METH_KEYWORDS, bpy_bmface_copy_doc},
-
- {"calc_area", (PyCFunction)bpy_bmface_calc_area, METH_NOARGS, bpy_bmface_calc_area_doc},
- {"calc_perimeter", (PyCFunction)bpy_bmface_calc_perimeter, METH_NOARGS, bpy_bmface_calc_perimeter_doc},
- {"calc_tangent_edge", (PyCFunction)bpy_bmface_calc_tangent_edge, METH_NOARGS, bpy_bmface_calc_tangent_edge_doc},
- {"calc_tangent_edge_pair", (PyCFunction)bpy_bmface_calc_tangent_edge_pair, METH_NOARGS, bpy_bmface_calc_tangent_edge_pair_doc},
- {"calc_tangent_edge_diagonal", (PyCFunction)bpy_bmface_calc_tangent_edge_diagonal, METH_NOARGS, bpy_bmface_calc_tangent_edge_diagonal_doc},
- {"calc_tangent_vert_diagonal", (PyCFunction)bpy_bmface_calc_tangent_vert_diagonal, METH_NOARGS, bpy_bmface_calc_tangent_vert_diagonal_doc},
- {"calc_center_median", (PyCFunction)bpy_bmface_calc_center_mean, METH_NOARGS, bpy_bmface_calc_center_median_doc},
- {"calc_center_median_weighted", (PyCFunction)bpy_bmface_calc_center_median_weighted, METH_NOARGS, bpy_bmface_calc_center_median_weighted_doc},
- {"calc_center_bounds", (PyCFunction)bpy_bmface_calc_center_bounds, METH_NOARGS, bpy_bmface_calc_center_bounds_doc},
-
- {"normal_update", (PyCFunction)bpy_bmface_normal_update, METH_NOARGS, bpy_bmface_normal_update_doc},
- {"normal_flip", (PyCFunction)bpy_bmface_normal_flip, METH_NOARGS, bpy_bmface_normal_flip_doc},
-
- {NULL, NULL, 0, NULL},
+ {"select_set", (PyCFunction)bpy_bm_elem_select_set, METH_O, bpy_bm_elem_select_set_doc},
+ {"hide_set", (PyCFunction)bpy_bm_elem_hide_set, METH_O, bpy_bm_elem_hide_set_doc},
+
+ {"copy_from", (PyCFunction)bpy_bm_elem_copy_from, METH_O, bpy_bm_elem_copy_from_doc},
+ {"copy_from_face_interp",
+ (PyCFunction)bpy_bmface_copy_from_face_interp,
+ METH_O,
+ bpy_bmface_copy_from_face_interp_doc},
+
+ {"copy", (PyCFunction)bpy_bmface_copy, METH_VARARGS | METH_KEYWORDS, bpy_bmface_copy_doc},
+
+ {"calc_area", (PyCFunction)bpy_bmface_calc_area, METH_NOARGS, bpy_bmface_calc_area_doc},
+ {"calc_perimeter",
+ (PyCFunction)bpy_bmface_calc_perimeter,
+ METH_NOARGS,
+ bpy_bmface_calc_perimeter_doc},
+ {"calc_tangent_edge",
+ (PyCFunction)bpy_bmface_calc_tangent_edge,
+ METH_NOARGS,
+ bpy_bmface_calc_tangent_edge_doc},
+ {"calc_tangent_edge_pair",
+ (PyCFunction)bpy_bmface_calc_tangent_edge_pair,
+ METH_NOARGS,
+ bpy_bmface_calc_tangent_edge_pair_doc},
+ {"calc_tangent_edge_diagonal",
+ (PyCFunction)bpy_bmface_calc_tangent_edge_diagonal,
+ METH_NOARGS,
+ bpy_bmface_calc_tangent_edge_diagonal_doc},
+ {"calc_tangent_vert_diagonal",
+ (PyCFunction)bpy_bmface_calc_tangent_vert_diagonal,
+ METH_NOARGS,
+ bpy_bmface_calc_tangent_vert_diagonal_doc},
+ {"calc_center_median",
+ (PyCFunction)bpy_bmface_calc_center_mean,
+ METH_NOARGS,
+ bpy_bmface_calc_center_median_doc},
+ {"calc_center_median_weighted",
+ (PyCFunction)bpy_bmface_calc_center_median_weighted,
+ METH_NOARGS,
+ bpy_bmface_calc_center_median_weighted_doc},
+ {"calc_center_bounds",
+ (PyCFunction)bpy_bmface_calc_center_bounds,
+ METH_NOARGS,
+ bpy_bmface_calc_center_bounds_doc},
+
+ {"normal_update",
+ (PyCFunction)bpy_bmface_normal_update,
+ METH_NOARGS,
+ bpy_bmface_normal_update_doc},
+ {"normal_flip", (PyCFunction)bpy_bmface_normal_flip, METH_NOARGS, bpy_bmface_normal_flip_doc},
+
+ {NULL, NULL, 0, NULL},
};
static struct PyMethodDef bpy_bmloop_methods[] = {
- {"copy_from", (PyCFunction)bpy_bm_elem_copy_from, METH_O, bpy_bm_elem_copy_from_doc},
- {"copy_from_face_interp", (PyCFunction)bpy_bmloop_copy_from_face_interp, METH_O, bpy_bmloop_copy_from_face_interp_doc},
-
- {"calc_angle", (PyCFunction)bpy_bmloop_calc_angle, METH_NOARGS, bpy_bmloop_calc_angle_doc},
- {"calc_normal", (PyCFunction)bpy_bmloop_calc_normal, METH_NOARGS, bpy_bmloop_calc_normal_doc},
- {"calc_tangent", (PyCFunction)bpy_bmloop_calc_tangent, METH_NOARGS, bpy_bmloop_calc_tangent_doc},
- {NULL, NULL, 0, NULL},
+ {"copy_from", (PyCFunction)bpy_bm_elem_copy_from, METH_O, bpy_bm_elem_copy_from_doc},
+ {"copy_from_face_interp",
+ (PyCFunction)bpy_bmloop_copy_from_face_interp,
+ METH_O,
+ bpy_bmloop_copy_from_face_interp_doc},
+
+ {"calc_angle", (PyCFunction)bpy_bmloop_calc_angle, METH_NOARGS, bpy_bmloop_calc_angle_doc},
+ {"calc_normal", (PyCFunction)bpy_bmloop_calc_normal, METH_NOARGS, bpy_bmloop_calc_normal_doc},
+ {"calc_tangent",
+ (PyCFunction)bpy_bmloop_calc_tangent,
+ METH_NOARGS,
+ bpy_bmloop_calc_tangent_doc},
+ {NULL, NULL, 0, NULL},
};
static struct PyMethodDef bpy_bmelemseq_methods[] = {
- /* odd function, initializes index values */
- {"index_update", (PyCFunction)bpy_bmelemseq_index_update, METH_NOARGS, bpy_bmelemseq_index_update_doc},
- {NULL, NULL, 0, NULL},
+ /* odd function, initializes index values */
+ {"index_update",
+ (PyCFunction)bpy_bmelemseq_index_update,
+ METH_NOARGS,
+ bpy_bmelemseq_index_update_doc},
+ {NULL, NULL, 0, NULL},
};
static struct PyMethodDef bpy_bmvertseq_methods[] = {
- {"new", (PyCFunction)bpy_bmvertseq_new, METH_VARARGS, bpy_bmvertseq_new_doc},
- {"remove", (PyCFunction)bpy_bmvertseq_remove, METH_O, bpy_bmvertseq_remove_doc},
-
- /* odd function, initializes index values */
- {"index_update", (PyCFunction)bpy_bmelemseq_index_update, METH_NOARGS, bpy_bmelemseq_index_update_doc},
- {"ensure_lookup_table", (PyCFunction)bpy_bmelemseq_ensure_lookup_table, METH_NOARGS, bpy_bmelemseq_ensure_lookup_table_doc},
- {"sort", (PyCFunction)bpy_bmelemseq_sort, METH_VARARGS | METH_KEYWORDS, bpy_bmelemseq_sort_doc},
- {NULL, NULL, 0, NULL},
+ {"new", (PyCFunction)bpy_bmvertseq_new, METH_VARARGS, bpy_bmvertseq_new_doc},
+ {"remove", (PyCFunction)bpy_bmvertseq_remove, METH_O, bpy_bmvertseq_remove_doc},
+
+ /* odd function, initializes index values */
+ {"index_update",
+ (PyCFunction)bpy_bmelemseq_index_update,
+ METH_NOARGS,
+ bpy_bmelemseq_index_update_doc},
+ {"ensure_lookup_table",
+ (PyCFunction)bpy_bmelemseq_ensure_lookup_table,
+ METH_NOARGS,
+ bpy_bmelemseq_ensure_lookup_table_doc},
+ {"sort",
+ (PyCFunction)bpy_bmelemseq_sort,
+ METH_VARARGS | METH_KEYWORDS,
+ bpy_bmelemseq_sort_doc},
+ {NULL, NULL, 0, NULL},
};
static struct PyMethodDef bpy_bmedgeseq_methods[] = {
- {"new", (PyCFunction)bpy_bmedgeseq_new, METH_VARARGS, bpy_bmedgeseq_new_doc},
- {"remove", (PyCFunction)bpy_bmedgeseq_remove, METH_O, bpy_bmedgeseq_remove_doc},
- /* 'bpy_bmelemseq_get' for different purpose */
- {"get", (PyCFunction)bpy_bmedgeseq_get__method, METH_VARARGS, bpy_bmedgeseq_get__method_doc},
-
- /* odd function, initializes index values */
- {"index_update", (PyCFunction)bpy_bmelemseq_index_update, METH_NOARGS, bpy_bmelemseq_index_update_doc},
- {"ensure_lookup_table", (PyCFunction)bpy_bmelemseq_ensure_lookup_table, METH_NOARGS, bpy_bmelemseq_ensure_lookup_table_doc},
- {"sort", (PyCFunction)bpy_bmelemseq_sort, METH_VARARGS | METH_KEYWORDS, bpy_bmelemseq_sort_doc},
- {NULL, NULL, 0, NULL},
+ {"new", (PyCFunction)bpy_bmedgeseq_new, METH_VARARGS, bpy_bmedgeseq_new_doc},
+ {"remove", (PyCFunction)bpy_bmedgeseq_remove, METH_O, bpy_bmedgeseq_remove_doc},
+ /* 'bpy_bmelemseq_get' for different purpose */
+ {"get", (PyCFunction)bpy_bmedgeseq_get__method, METH_VARARGS, bpy_bmedgeseq_get__method_doc},
+
+ /* odd function, initializes index values */
+ {"index_update",
+ (PyCFunction)bpy_bmelemseq_index_update,
+ METH_NOARGS,
+ bpy_bmelemseq_index_update_doc},
+ {"ensure_lookup_table",
+ (PyCFunction)bpy_bmelemseq_ensure_lookup_table,
+ METH_NOARGS,
+ bpy_bmelemseq_ensure_lookup_table_doc},
+ {"sort",
+ (PyCFunction)bpy_bmelemseq_sort,
+ METH_VARARGS | METH_KEYWORDS,
+ bpy_bmelemseq_sort_doc},
+ {NULL, NULL, 0, NULL},
};
static struct PyMethodDef bpy_bmfaceseq_methods[] = {
- {"new", (PyCFunction)bpy_bmfaceseq_new, METH_VARARGS, bpy_bmfaceseq_new_doc},
- {"remove", (PyCFunction)bpy_bmfaceseq_remove, METH_O, bpy_bmfaceseq_remove_doc},
- /* 'bpy_bmelemseq_get' for different purpose */
- {"get", (PyCFunction)bpy_bmfaceseq_get__method, METH_VARARGS, bpy_bmfaceseq_get__method_doc},
-
- /* odd function, initializes index values */
- {"index_update", (PyCFunction)bpy_bmelemseq_index_update, METH_NOARGS, bpy_bmelemseq_index_update_doc},
- {"ensure_lookup_table", (PyCFunction)bpy_bmelemseq_ensure_lookup_table, METH_NOARGS, bpy_bmelemseq_ensure_lookup_table_doc},
- {"sort", (PyCFunction)bpy_bmelemseq_sort, METH_VARARGS | METH_KEYWORDS, bpy_bmelemseq_sort_doc},
- {NULL, NULL, 0, NULL},
+ {"new", (PyCFunction)bpy_bmfaceseq_new, METH_VARARGS, bpy_bmfaceseq_new_doc},
+ {"remove", (PyCFunction)bpy_bmfaceseq_remove, METH_O, bpy_bmfaceseq_remove_doc},
+ /* 'bpy_bmelemseq_get' for different purpose */
+ {"get", (PyCFunction)bpy_bmfaceseq_get__method, METH_VARARGS, bpy_bmfaceseq_get__method_doc},
+
+ /* odd function, initializes index values */
+ {"index_update",
+ (PyCFunction)bpy_bmelemseq_index_update,
+ METH_NOARGS,
+ bpy_bmelemseq_index_update_doc},
+ {"ensure_lookup_table",
+ (PyCFunction)bpy_bmelemseq_ensure_lookup_table,
+ METH_NOARGS,
+ bpy_bmelemseq_ensure_lookup_table_doc},
+ {"sort",
+ (PyCFunction)bpy_bmelemseq_sort,
+ METH_VARARGS | METH_KEYWORDS,
+ bpy_bmelemseq_sort_doc},
+ {NULL, NULL, 0, NULL},
};
static struct PyMethodDef bpy_bmloopseq_methods[] = {
- /* odd function, initializes index values */
- /* no: index_update() function since we cant iterate over loops */
- /* no: sort() function since we cant iterate over loops */
- {NULL, NULL, 0, NULL},
+ /* odd function, initializes index values */
+ /* no: index_update() function since we cant iterate over loops */
+ /* no: sort() function since we cant iterate over loops */
+ {NULL, NULL, 0, NULL},
};
/* Sequences
@@ -2860,253 +3105,254 @@ static struct PyMethodDef bpy_bmloopseq_methods[] = {
static PyTypeObject *bpy_bm_itype_as_pytype(const char itype)
{
- /* should cover all types */
- switch ((BMIterType)itype) {
- case BM_VERTS_OF_MESH:
- case BM_VERTS_OF_FACE:
- case BM_VERTS_OF_EDGE:
- return &BPy_BMVert_Type;
+ /* should cover all types */
+ switch ((BMIterType)itype) {
+ case BM_VERTS_OF_MESH:
+ case BM_VERTS_OF_FACE:
+ case BM_VERTS_OF_EDGE:
+ return &BPy_BMVert_Type;
- case BM_EDGES_OF_MESH:
- case BM_EDGES_OF_FACE:
- case BM_EDGES_OF_VERT:
- return &BPy_BMEdge_Type;
+ case BM_EDGES_OF_MESH:
+ case BM_EDGES_OF_FACE:
+ case BM_EDGES_OF_VERT:
+ return &BPy_BMEdge_Type;
- case BM_FACES_OF_MESH:
- case BM_FACES_OF_EDGE:
- case BM_FACES_OF_VERT:
- return &BPy_BMFace_Type;
+ case BM_FACES_OF_MESH:
+ case BM_FACES_OF_EDGE:
+ case BM_FACES_OF_VERT:
+ return &BPy_BMFace_Type;
- // case BM_ALL_LOOPS_OF_FACE:
- case BM_LOOPS_OF_FACE:
- case BM_LOOPS_OF_EDGE:
- case BM_LOOPS_OF_VERT:
- case BM_LOOPS_OF_LOOP:
- return &BPy_BMLoop_Type;
- }
+ // case BM_ALL_LOOPS_OF_FACE:
+ case BM_LOOPS_OF_FACE:
+ case BM_LOOPS_OF_EDGE:
+ case BM_LOOPS_OF_VERT:
+ case BM_LOOPS_OF_LOOP:
+ return &BPy_BMLoop_Type;
+ }
- return NULL;
+ return NULL;
}
static Py_ssize_t bpy_bmelemseq_length(BPy_BMElemSeq *self)
{
- BPY_BM_CHECK_INT(self);
-
- /* first check if the size is known */
- switch ((BMIterType)self->itype) {
- /* main-types */
- case BM_VERTS_OF_MESH:
- return self->bm->totvert;
- case BM_EDGES_OF_MESH:
- return self->bm->totedge;
- case BM_FACES_OF_MESH:
- return self->bm->totface;
-
- /* sub-types */
- case BM_VERTS_OF_FACE:
- case BM_EDGES_OF_FACE:
- case BM_LOOPS_OF_FACE:
- BPY_BM_CHECK_INT(self->py_ele);
- return ((BMFace *)self->py_ele->ele)->len;
-
- case BM_VERTS_OF_EDGE:
- return 2;
-
- default:
- /* quiet compiler */
- break;
- }
-
-
- /* loop over all items, avoid this if we can */
- {
- BMIter iter;
- BMHeader *ele;
- Py_ssize_t tot = 0;
-
- BM_ITER_BPY_BM_SEQ (ele, &iter, self) {
- tot++;
- }
- return tot;
- }
+ BPY_BM_CHECK_INT(self);
+
+ /* first check if the size is known */
+ switch ((BMIterType)self->itype) {
+ /* main-types */
+ case BM_VERTS_OF_MESH:
+ return self->bm->totvert;
+ case BM_EDGES_OF_MESH:
+ return self->bm->totedge;
+ case BM_FACES_OF_MESH:
+ return self->bm->totface;
+
+ /* sub-types */
+ case BM_VERTS_OF_FACE:
+ case BM_EDGES_OF_FACE:
+ case BM_LOOPS_OF_FACE:
+ BPY_BM_CHECK_INT(self->py_ele);
+ return ((BMFace *)self->py_ele->ele)->len;
+
+ case BM_VERTS_OF_EDGE:
+ return 2;
+
+ default:
+ /* quiet compiler */
+ break;
+ }
+
+ /* loop over all items, avoid this if we can */
+ {
+ BMIter iter;
+ BMHeader *ele;
+ Py_ssize_t tot = 0;
+
+ BM_ITER_BPY_BM_SEQ(ele, &iter, self)
+ {
+ tot++;
+ }
+ return tot;
+ }
}
static PyObject *bpy_bmelemseq_subscript_int(BPy_BMElemSeq *self, int keynum)
{
- BPY_BM_CHECK_OBJ(self);
-
- if (keynum < 0) {
- /* only get length on negative value, may loop entire seq */
- keynum += bpy_bmelemseq_length(self);
- }
- if (keynum >= 0) {
- if (self->itype <= BM_FACES_OF_MESH) {
- if ((self->bm->elem_table_dirty & bm_iter_itype_htype_map[self->itype]) == 0) {
- BMHeader *ele = NULL;
- switch (self->itype) {
- case BM_VERTS_OF_MESH:
- if (keynum < self->bm->totvert) {
- ele = (BMHeader *)self->bm->vtable[keynum];
- }
- break;
- case BM_EDGES_OF_MESH:
- if (keynum < self->bm->totedge) {
- ele = (BMHeader *)self->bm->etable[keynum];
- }
- break;
- case BM_FACES_OF_MESH:
- if (keynum < self->bm->totface) {
- ele = (BMHeader *)self->bm->ftable[keynum];
- }
- break;
- }
- if (ele) {
- return BPy_BMElem_CreatePyObject(self->bm, ele);
- }
- /* fall through to index error below */
- }
- else {
- PyErr_SetString(PyExc_IndexError,
- "BMElemSeq[index]: outdated internal index table, "
- "run ensure_lookup_table() first");
- return NULL;
- }
- }
- else {
- BMHeader *ele = BM_iter_at_index(self->bm, self->itype, self->py_ele ? self->py_ele->ele : NULL, keynum);
- if (ele) {
- return BPy_BMElem_CreatePyObject(self->bm, ele);
- }
- }
- }
-
- PyErr_Format(PyExc_IndexError,
- "BMElemSeq[index]: index %d out of range", keynum);
- return NULL;
-}
-
-static PyObject *bpy_bmelemseq_subscript_slice(BPy_BMElemSeq *self, Py_ssize_t start, Py_ssize_t stop)
-{
- BMIter iter;
- int count = 0;
- bool ok;
-
- PyObject *list;
- BMHeader *ele;
-
- BPY_BM_CHECK_OBJ(self);
-
- list = PyList_New(0);
-
- ok = BM_iter_init(&iter, self->bm, self->itype, self->py_ele ? self->py_ele->ele : NULL);
-
- BLI_assert(ok == true);
-
- if (UNLIKELY(ok == false)) {
- return list;
- }
-
- /* first loop up-until the start */
- for (ok = true; ok; ok = (BM_iter_step(&iter) != NULL)) {
- if (count == start) {
- break;
- }
- count++;
- }
-
- /* add items until stop */
- while ((ele = BM_iter_step(&iter))) {
- PyList_APPEND(list, BPy_BMElem_CreatePyObject(self->bm, ele));
-
- count++;
- if (count == stop) {
- break;
- }
- }
-
- return list;
+ BPY_BM_CHECK_OBJ(self);
+
+ if (keynum < 0) {
+ /* only get length on negative value, may loop entire seq */
+ keynum += bpy_bmelemseq_length(self);
+ }
+ if (keynum >= 0) {
+ if (self->itype <= BM_FACES_OF_MESH) {
+ if ((self->bm->elem_table_dirty & bm_iter_itype_htype_map[self->itype]) == 0) {
+ BMHeader *ele = NULL;
+ switch (self->itype) {
+ case BM_VERTS_OF_MESH:
+ if (keynum < self->bm->totvert) {
+ ele = (BMHeader *)self->bm->vtable[keynum];
+ }
+ break;
+ case BM_EDGES_OF_MESH:
+ if (keynum < self->bm->totedge) {
+ ele = (BMHeader *)self->bm->etable[keynum];
+ }
+ break;
+ case BM_FACES_OF_MESH:
+ if (keynum < self->bm->totface) {
+ ele = (BMHeader *)self->bm->ftable[keynum];
+ }
+ break;
+ }
+ if (ele) {
+ return BPy_BMElem_CreatePyObject(self->bm, ele);
+ }
+ /* fall through to index error below */
+ }
+ else {
+ PyErr_SetString(PyExc_IndexError,
+ "BMElemSeq[index]: outdated internal index table, "
+ "run ensure_lookup_table() first");
+ return NULL;
+ }
+ }
+ else {
+ BMHeader *ele = BM_iter_at_index(
+ self->bm, self->itype, self->py_ele ? self->py_ele->ele : NULL, keynum);
+ if (ele) {
+ return BPy_BMElem_CreatePyObject(self->bm, ele);
+ }
+ }
+ }
+
+ PyErr_Format(PyExc_IndexError, "BMElemSeq[index]: index %d out of range", keynum);
+ return NULL;
+}
+
+static PyObject *bpy_bmelemseq_subscript_slice(BPy_BMElemSeq *self,
+ Py_ssize_t start,
+ Py_ssize_t stop)
+{
+ BMIter iter;
+ int count = 0;
+ bool ok;
+
+ PyObject *list;
+ BMHeader *ele;
+
+ BPY_BM_CHECK_OBJ(self);
+
+ list = PyList_New(0);
+
+ ok = BM_iter_init(&iter, self->bm, self->itype, self->py_ele ? self->py_ele->ele : NULL);
+
+ BLI_assert(ok == true);
+
+ if (UNLIKELY(ok == false)) {
+ return list;
+ }
+
+ /* first loop up-until the start */
+ for (ok = true; ok; ok = (BM_iter_step(&iter) != NULL)) {
+ if (count == start) {
+ break;
+ }
+ count++;
+ }
+
+ /* add items until stop */
+ while ((ele = BM_iter_step(&iter))) {
+ PyList_APPEND(list, BPy_BMElem_CreatePyObject(self->bm, ele));
+
+ count++;
+ if (count == stop) {
+ break;
+ }
+ }
+
+ return list;
}
static PyObject *bpy_bmelemseq_subscript(BPy_BMElemSeq *self, PyObject *key)
{
- /* don't need error check here */
- if (PyIndex_Check(key)) {
- Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred()) {
- return NULL;
- }
- return bpy_bmelemseq_subscript_int(self, i);
- }
- else if (PySlice_Check(key)) {
- PySliceObject *key_slice = (PySliceObject *)key;
- Py_ssize_t step = 1;
-
- if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) {
- return NULL;
- }
- else if (step != 1) {
- PyErr_SetString(PyExc_TypeError,
- "BMElemSeq[slice]: slice steps not supported");
- return NULL;
- }
- else if (key_slice->start == Py_None && key_slice->stop == Py_None) {
- return bpy_bmelemseq_subscript_slice(self, 0, PY_SSIZE_T_MAX);
- }
- else {
- Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX;
-
- /* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */
- if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) {
- return NULL;
- }
- if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) {
- return NULL;
- }
-
- if (start < 0 || stop < 0) {
- /* only get the length for negative values */
- Py_ssize_t len = bpy_bmelemseq_length(self);
- if (start < 0) {
- start += len;
- }
- if (stop < 0) {
- stop += len;
- }
- }
-
- if (stop - start <= 0) {
- return PyList_New(0);
- }
- else {
- return bpy_bmelemseq_subscript_slice(self, start, stop);
- }
- }
- }
- else {
- PyErr_SetString(PyExc_AttributeError,
- "BMElemSeq[key]: invalid key, key must be an int");
- return NULL;
- }
+ /* don't need error check here */
+ if (PyIndex_Check(key)) {
+ Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
+ if (i == -1 && PyErr_Occurred()) {
+ return NULL;
+ }
+ return bpy_bmelemseq_subscript_int(self, i);
+ }
+ else if (PySlice_Check(key)) {
+ PySliceObject *key_slice = (PySliceObject *)key;
+ Py_ssize_t step = 1;
+
+ if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) {
+ return NULL;
+ }
+ else if (step != 1) {
+ PyErr_SetString(PyExc_TypeError, "BMElemSeq[slice]: slice steps not supported");
+ return NULL;
+ }
+ else if (key_slice->start == Py_None && key_slice->stop == Py_None) {
+ return bpy_bmelemseq_subscript_slice(self, 0, PY_SSIZE_T_MAX);
+ }
+ else {
+ Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX;
+
+ /* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */
+ if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) {
+ return NULL;
+ }
+ if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) {
+ return NULL;
+ }
+
+ if (start < 0 || stop < 0) {
+ /* only get the length for negative values */
+ Py_ssize_t len = bpy_bmelemseq_length(self);
+ if (start < 0) {
+ start += len;
+ }
+ if (stop < 0) {
+ stop += len;
+ }
+ }
+
+ if (stop - start <= 0) {
+ return PyList_New(0);
+ }
+ else {
+ return bpy_bmelemseq_subscript_slice(self, start, stop);
+ }
+ }
+ }
+ else {
+ PyErr_SetString(PyExc_AttributeError, "BMElemSeq[key]: invalid key, key must be an int");
+ return NULL;
+ }
}
static int bpy_bmelemseq_contains(BPy_BMElemSeq *self, PyObject *value)
{
- BPY_BM_CHECK_INT(self);
+ BPY_BM_CHECK_INT(self);
- if (Py_TYPE(value) == bpy_bm_itype_as_pytype(self->itype)) {
- BPy_BMElem *value_bm_ele = (BPy_BMElem *)value;
- if (value_bm_ele->bm == self->bm) {
- BMElem *ele, *ele_test = value_bm_ele->ele;
- BMIter iter;
- BM_ITER_BPY_BM_SEQ (ele, &iter, self) {
- if (ele == ele_test) {
- return 1;
- }
- }
- }
- }
+ if (Py_TYPE(value) == bpy_bm_itype_as_pytype(self->itype)) {
+ BPy_BMElem *value_bm_ele = (BPy_BMElem *)value;
+ if (value_bm_ele->bm == self->bm) {
+ BMElem *ele, *ele_test = value_bm_ele->ele;
+ BMIter iter;
+ BM_ITER_BPY_BM_SEQ(ele, &iter, self)
+ {
+ if (ele == ele_test) {
+ return 1;
+ }
+ }
+ }
+ }
- return 0;
+ return 0;
}
/* BMElem (customdata)
@@ -3114,42 +3360,44 @@ static int bpy_bmelemseq_contains(BPy_BMElemSeq *self, PyObject *value)
static PyObject *bpy_bmelem_subscript(BPy_BMElem *self, BPy_BMLayerItem *key)
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- return BPy_BMLayerItem_GetItem(self, key);
+ return BPy_BMLayerItem_GetItem(self, key);
}
static int bpy_bmelem_ass_subscript(BPy_BMElem *self, BPy_BMLayerItem *key, PyObject *value)
{
- BPY_BM_CHECK_INT(self);
+ BPY_BM_CHECK_INT(self);
- return BPy_BMLayerItem_SetItem(self, key, value);
+ return BPy_BMLayerItem_SetItem(self, key, value);
}
static PySequenceMethods bpy_bmelemseq_as_sequence = {
- (lenfunc)bpy_bmelemseq_length, /* sq_length */
- NULL, /* sq_concat */
- NULL, /* sq_repeat */
- (ssizeargfunc)bpy_bmelemseq_subscript_int, /* sq_item */ /* Only set this so PySequence_Check() returns True */
- NULL, /* sq_slice */
- (ssizeobjargproc)NULL, /* sq_ass_item */
- NULL, /* *was* sq_ass_slice */
- (objobjproc)bpy_bmelemseq_contains, /* sq_contains */
- (binaryfunc) NULL, /* sq_inplace_concat */
- (ssizeargfunc) NULL, /* sq_inplace_repeat */
+ (lenfunc)bpy_bmelemseq_length, /* sq_length */
+ NULL, /* sq_concat */
+ NULL, /* sq_repeat */
+ (ssizeargfunc)bpy_bmelemseq_subscript_int,
+ /* sq_item */ /* Only set this so PySequence_Check() returns True */
+ NULL, /* sq_slice */
+ (ssizeobjargproc)NULL, /* sq_ass_item */
+ NULL, /* *was* sq_ass_slice */
+ (objobjproc)bpy_bmelemseq_contains, /* sq_contains */
+ (binaryfunc)NULL, /* sq_inplace_concat */
+ (ssizeargfunc)NULL, /* sq_inplace_repeat */
};
static PyMappingMethods bpy_bmelemseq_as_mapping = {
- (lenfunc)bpy_bmelemseq_length, /* mp_length */
- (binaryfunc)bpy_bmelemseq_subscript, /* mp_subscript */
- (objobjargproc)NULL, /* mp_ass_subscript */
+ (lenfunc)bpy_bmelemseq_length, /* mp_length */
+ (binaryfunc)bpy_bmelemseq_subscript, /* mp_subscript */
+ (objobjargproc)NULL, /* mp_ass_subscript */
};
/* for customdata access */
static PyMappingMethods bpy_bm_elem_as_mapping = {
- (lenfunc)NULL, /* mp_length */ /* keep this empty, messes up 'if elem: ...' test */
- (binaryfunc)bpy_bmelem_subscript, /* mp_subscript */
- (objobjargproc)bpy_bmelem_ass_subscript, /* mp_ass_subscript */
+ (lenfunc)NULL,
+ /* mp_length */ /* keep this empty, messes up 'if elem: ...' test */
+ (binaryfunc)bpy_bmelem_subscript, /* mp_subscript */
+ (objobjargproc)bpy_bmelem_ass_subscript, /* mp_ass_subscript */
};
/* Iterator
@@ -3157,230 +3405,228 @@ static PyMappingMethods bpy_bm_elem_as_mapping = {
static PyObject *bpy_bmelemseq_iter(BPy_BMElemSeq *self)
{
- BPy_BMIter *py_iter;
+ BPy_BMIter *py_iter;
- BPY_BM_CHECK_OBJ(self);
- py_iter = (BPy_BMIter *)BPy_BMIter_CreatePyObject(self->bm);
- BM_iter_init(&(py_iter->iter), self->bm, self->itype, self->py_ele ? self->py_ele->ele : NULL);
- return (PyObject *)py_iter;
+ BPY_BM_CHECK_OBJ(self);
+ py_iter = (BPy_BMIter *)BPy_BMIter_CreatePyObject(self->bm);
+ BM_iter_init(&(py_iter->iter), self->bm, self->itype, self->py_ele ? self->py_ele->ele : NULL);
+ return (PyObject *)py_iter;
}
static PyObject *bpy_bmiter_next(BPy_BMIter *self)
{
- BMHeader *ele = BM_iter_step(&self->iter);
- if (ele == NULL) {
- PyErr_SetNone(PyExc_StopIteration);
- return NULL;
- }
- else {
- return (PyObject *)BPy_BMElem_CreatePyObject(self->bm, ele);
- }
+ BMHeader *ele = BM_iter_step(&self->iter);
+ if (ele == NULL) {
+ PyErr_SetNone(PyExc_StopIteration);
+ return NULL;
+ }
+ else {
+ return (PyObject *)BPy_BMElem_CreatePyObject(self->bm, ele);
+ }
}
-
/* Dealloc Functions
* ================= */
static void bpy_bmesh_dealloc(BPy_BMesh *self)
{
- BMesh *bm = self->bm;
+ BMesh *bm = self->bm;
- /* have have been freed by bmesh */
- if (bm) {
- bm_dealloc_editmode_warn(self);
+ /* have have been freed by bmesh */
+ if (bm) {
+ bm_dealloc_editmode_warn(self);
- if (CustomData_has_layer(&bm->vdata, CD_BM_ELEM_PYPTR)) {
- BM_data_layer_free(bm, &bm->vdata, CD_BM_ELEM_PYPTR);
- }
- if (CustomData_has_layer(&bm->edata, CD_BM_ELEM_PYPTR)) {
- BM_data_layer_free(bm, &bm->edata, CD_BM_ELEM_PYPTR);
- }
- if (CustomData_has_layer(&bm->pdata, CD_BM_ELEM_PYPTR)) {
- BM_data_layer_free(bm, &bm->pdata, CD_BM_ELEM_PYPTR);
- }
- if (CustomData_has_layer(&bm->ldata, CD_BM_ELEM_PYPTR)) {
- BM_data_layer_free(bm, &bm->ldata, CD_BM_ELEM_PYPTR);
- }
+ if (CustomData_has_layer(&bm->vdata, CD_BM_ELEM_PYPTR)) {
+ BM_data_layer_free(bm, &bm->vdata, CD_BM_ELEM_PYPTR);
+ }
+ if (CustomData_has_layer(&bm->edata, CD_BM_ELEM_PYPTR)) {
+ BM_data_layer_free(bm, &bm->edata, CD_BM_ELEM_PYPTR);
+ }
+ if (CustomData_has_layer(&bm->pdata, CD_BM_ELEM_PYPTR)) {
+ BM_data_layer_free(bm, &bm->pdata, CD_BM_ELEM_PYPTR);
+ }
+ if (CustomData_has_layer(&bm->ldata, CD_BM_ELEM_PYPTR)) {
+ BM_data_layer_free(bm, &bm->ldata, CD_BM_ELEM_PYPTR);
+ }
- bm->py_handle = NULL;
+ bm->py_handle = NULL;
- if ((self->flag & BPY_BMFLAG_IS_WRAPPED) == 0) {
- BM_mesh_free(bm);
- }
- }
+ if ((self->flag & BPY_BMFLAG_IS_WRAPPED) == 0) {
+ BM_mesh_free(bm);
+ }
+ }
- PyObject_DEL(self);
+ PyObject_DEL(self);
}
static void bpy_bmvert_dealloc(BPy_BMElem *self)
{
- BMesh *bm = self->bm;
- if (bm) {
- void **ptr = CustomData_bmesh_get(&bm->vdata, self->ele->head.data, CD_BM_ELEM_PYPTR);
- if (ptr) {
- *ptr = NULL;
- }
- }
- PyObject_DEL(self);
+ BMesh *bm = self->bm;
+ if (bm) {
+ void **ptr = CustomData_bmesh_get(&bm->vdata, self->ele->head.data, CD_BM_ELEM_PYPTR);
+ if (ptr) {
+ *ptr = NULL;
+ }
+ }
+ PyObject_DEL(self);
}
static void bpy_bmedge_dealloc(BPy_BMElem *self)
{
- BMesh *bm = self->bm;
- if (bm) {
- void **ptr = CustomData_bmesh_get(&bm->edata, self->ele->head.data, CD_BM_ELEM_PYPTR);
- if (ptr) {
- *ptr = NULL;
- }
- }
- PyObject_DEL(self);
+ BMesh *bm = self->bm;
+ if (bm) {
+ void **ptr = CustomData_bmesh_get(&bm->edata, self->ele->head.data, CD_BM_ELEM_PYPTR);
+ if (ptr) {
+ *ptr = NULL;
+ }
+ }
+ PyObject_DEL(self);
}
static void bpy_bmface_dealloc(BPy_BMElem *self)
{
- BMesh *bm = self->bm;
- if (bm) {
- void **ptr = CustomData_bmesh_get(&bm->pdata, self->ele->head.data, CD_BM_ELEM_PYPTR);
- if (ptr) {
- *ptr = NULL;
- }
- }
- PyObject_DEL(self);
+ BMesh *bm = self->bm;
+ if (bm) {
+ void **ptr = CustomData_bmesh_get(&bm->pdata, self->ele->head.data, CD_BM_ELEM_PYPTR);
+ if (ptr) {
+ *ptr = NULL;
+ }
+ }
+ PyObject_DEL(self);
}
static void bpy_bmloop_dealloc(BPy_BMElem *self)
{
- BMesh *bm = self->bm;
- if (bm) {
- void **ptr = CustomData_bmesh_get(&bm->ldata, self->ele->head.data, CD_BM_ELEM_PYPTR);
- if (ptr) {
- *ptr = NULL;
- }
- }
- PyObject_DEL(self);
+ BMesh *bm = self->bm;
+ if (bm) {
+ void **ptr = CustomData_bmesh_get(&bm->ldata, self->ele->head.data, CD_BM_ELEM_PYPTR);
+ if (ptr) {
+ *ptr = NULL;
+ }
+ }
+ PyObject_DEL(self);
}
static void bpy_bmelemseq_dealloc(BPy_BMElemSeq *self)
{
- Py_XDECREF(self->py_ele);
+ Py_XDECREF(self->py_ele);
- PyObject_DEL(self);
+ PyObject_DEL(self);
}
/* not sure where this should go */
static Py_hash_t bpy_bm_elem_hash(PyObject *self)
{
- return _Py_HashPointer(((BPy_BMElem *)self)->ele);
+ return _Py_HashPointer(((BPy_BMElem *)self)->ele);
}
static Py_hash_t bpy_bm_hash(PyObject *self)
{
- return _Py_HashPointer(((BPy_BMesh *)self)->bm);
+ return _Py_HashPointer(((BPy_BMesh *)self)->bm);
}
/* Type Docstrings
* =============== */
-PyDoc_STRVAR(bpy_bmesh_doc,
-"The BMesh data structure\n"
-);
-PyDoc_STRVAR(bpy_bmvert_doc,
-"The BMesh vertex type\n"
-);
-PyDoc_STRVAR(bpy_bmedge_doc,
-"The BMesh edge connecting 2 verts\n"
-);
-PyDoc_STRVAR(bpy_bmface_doc,
-"The BMesh face with 3 or more sides\n"
-);
+PyDoc_STRVAR(bpy_bmesh_doc, "The BMesh data structure\n");
+PyDoc_STRVAR(bpy_bmvert_doc, "The BMesh vertex type\n");
+PyDoc_STRVAR(bpy_bmedge_doc, "The BMesh edge connecting 2 verts\n");
+PyDoc_STRVAR(bpy_bmface_doc, "The BMesh face with 3 or more sides\n");
PyDoc_STRVAR(bpy_bmloop_doc,
-"This is normally accessed from :class:`BMFace.loops` where each face loop represents a corner of the face.\n"
-);
+ "This is normally accessed from :class:`BMFace.loops` where each face loop "
+ "represents a corner of the face.\n");
PyDoc_STRVAR(bpy_bmelemseq_doc,
-"General sequence type used for accessing any sequence of\n"
-":class:`BMVert`, :class:`BMEdge`, :class:`BMFace`, :class:`BMLoop`.\n"
-"\n"
-"When accessed via :class:`BMesh.verts`, :class:`BMesh.edges`, :class:`BMesh.faces`\n"
-"there are also functions to create/remomove items.\n"
-);
+ "General sequence type used for accessing any sequence of\n"
+ ":class:`BMVert`, :class:`BMEdge`, :class:`BMFace`, :class:`BMLoop`.\n"
+ "\n"
+ "When accessed via :class:`BMesh.verts`, :class:`BMesh.edges`, :class:`BMesh.faces`\n"
+ "there are also functions to create/remomove items.\n");
PyDoc_STRVAR(bpy_bmiter_doc,
-"Internal BMesh type for looping over verts/faces/edges,\n"
-"used for iterating over :class:`BMElemSeq` types.\n"
-);
+ "Internal BMesh type for looping over verts/faces/edges,\n"
+ "used for iterating over :class:`BMElemSeq` types.\n");
static PyObject *bpy_bmesh_repr(BPy_BMesh *self)
{
- BMesh *bm = self->bm;
+ BMesh *bm = self->bm;
- if (bm) {
- return PyUnicode_FromFormat("<BMesh(%p), totvert=%d, totedge=%d, totface=%d, totloop=%d>",
- bm, bm->totvert, bm->totedge, bm->totface, bm->totloop);
- }
- else {
- return PyUnicode_FromFormat("<BMesh dead at %p>", self);
- }
+ if (bm) {
+ return PyUnicode_FromFormat("<BMesh(%p), totvert=%d, totedge=%d, totface=%d, totloop=%d>",
+ bm,
+ bm->totvert,
+ bm->totedge,
+ bm->totface,
+ bm->totloop);
+ }
+ else {
+ return PyUnicode_FromFormat("<BMesh dead at %p>", self);
+ }
}
static PyObject *bpy_bmvert_repr(BPy_BMVert *self)
{
- BMesh *bm = self->bm;
+ BMesh *bm = self->bm;
- if (bm) {
- BMVert *v = self->v;
- return PyUnicode_FromFormat("<BMVert(%p), index=%d>",
- v, BM_elem_index_get(v));
- }
- else {
- return PyUnicode_FromFormat("<BMVert dead at %p>", self);
- }
+ if (bm) {
+ BMVert *v = self->v;
+ return PyUnicode_FromFormat("<BMVert(%p), index=%d>", v, BM_elem_index_get(v));
+ }
+ else {
+ return PyUnicode_FromFormat("<BMVert dead at %p>", self);
+ }
}
static PyObject *bpy_bmedge_repr(BPy_BMEdge *self)
{
- BMesh *bm = self->bm;
+ BMesh *bm = self->bm;
- if (bm) {
- BMEdge *e = self->e;
- return PyUnicode_FromFormat("<BMEdge(%p), index=%d, verts=(%p/%d, %p/%d)>",
- e, BM_elem_index_get(e),
- e->v1, BM_elem_index_get(e->v1),
- e->v2, BM_elem_index_get(e->v2));
- }
- else {
- return PyUnicode_FromFormat("<BMEdge dead at %p>", self);
- }
+ if (bm) {
+ BMEdge *e = self->e;
+ return PyUnicode_FromFormat("<BMEdge(%p), index=%d, verts=(%p/%d, %p/%d)>",
+ e,
+ BM_elem_index_get(e),
+ e->v1,
+ BM_elem_index_get(e->v1),
+ e->v2,
+ BM_elem_index_get(e->v2));
+ }
+ else {
+ return PyUnicode_FromFormat("<BMEdge dead at %p>", self);
+ }
}
static PyObject *bpy_bmface_repr(BPy_BMFace *self)
{
- BMesh *bm = self->bm;
+ BMesh *bm = self->bm;
- if (bm) {
- BMFace *f = self->f;
- return PyUnicode_FromFormat("<BMFace(%p), index=%d, totverts=%d>",
- f, BM_elem_index_get(f),
- f->len);
- }
- else {
- return PyUnicode_FromFormat("<BMFace dead at %p>", self);
- }
+ if (bm) {
+ BMFace *f = self->f;
+ return PyUnicode_FromFormat(
+ "<BMFace(%p), index=%d, totverts=%d>", f, BM_elem_index_get(f), f->len);
+ }
+ else {
+ return PyUnicode_FromFormat("<BMFace dead at %p>", self);
+ }
}
static PyObject *bpy_bmloop_repr(BPy_BMLoop *self)
{
- BMesh *bm = self->bm;
-
- if (bm) {
- BMLoop *l = self->l;
- return PyUnicode_FromFormat("<BMLoop(%p), index=%d, vert=%p/%d, edge=%p/%d, face=%p/%d>",
- l, BM_elem_index_get(l),
- l->v, BM_elem_index_get(l->v),
- l->e, BM_elem_index_get(l->e),
- l->f, BM_elem_index_get(l->f));
- }
- else {
- return PyUnicode_FromFormat("<BMLoop dead at %p>", self);
- }
+ BMesh *bm = self->bm;
+
+ if (bm) {
+ BMLoop *l = self->l;
+ return PyUnicode_FromFormat("<BMLoop(%p), index=%d, vert=%p/%d, edge=%p/%d, face=%p/%d>",
+ l,
+ BM_elem_index_get(l),
+ l->v,
+ BM_elem_index_get(l->v),
+ l->e,
+ BM_elem_index_get(l->e),
+ l->f,
+ BM_elem_index_get(l->f));
+ }
+ else {
+ return PyUnicode_FromFormat("<BMLoop dead at %p>", self);
+ }
}
/* Types
@@ -3398,220 +3644,213 @@ PyTypeObject BPy_BMFaceSeq_Type;
PyTypeObject BPy_BMLoopSeq_Type;
PyTypeObject BPy_BMIter_Type;
-
-
void BPy_BM_init_types(void)
{
- BPy_BMesh_Type.tp_basicsize = sizeof(BPy_BMesh);
- BPy_BMVert_Type.tp_basicsize = sizeof(BPy_BMVert);
- BPy_BMEdge_Type.tp_basicsize = sizeof(BPy_BMEdge);
- BPy_BMFace_Type.tp_basicsize = sizeof(BPy_BMFace);
- BPy_BMLoop_Type.tp_basicsize = sizeof(BPy_BMLoop);
- BPy_BMElemSeq_Type.tp_basicsize = sizeof(BPy_BMElemSeq);
- BPy_BMVertSeq_Type.tp_basicsize = sizeof(BPy_BMElemSeq);
- BPy_BMEdgeSeq_Type.tp_basicsize = sizeof(BPy_BMElemSeq);
- BPy_BMFaceSeq_Type.tp_basicsize = sizeof(BPy_BMElemSeq);
- BPy_BMLoopSeq_Type.tp_basicsize = sizeof(BPy_BMElemSeq);
- BPy_BMIter_Type.tp_basicsize = sizeof(BPy_BMIter);
-
-
- BPy_BMesh_Type.tp_name = "BMesh";
- BPy_BMVert_Type.tp_name = "BMVert";
- BPy_BMEdge_Type.tp_name = "BMEdge";
- BPy_BMFace_Type.tp_name = "BMFace";
- BPy_BMLoop_Type.tp_name = "BMLoop";
- BPy_BMElemSeq_Type.tp_name = "BMElemSeq";
- BPy_BMVertSeq_Type.tp_name = "BMVertSeq";
- BPy_BMEdgeSeq_Type.tp_name = "BMEdgeSeq";
- BPy_BMFaceSeq_Type.tp_name = "BMFaceSeq";
- BPy_BMLoopSeq_Type.tp_name = "BMLoopSeq";
- BPy_BMIter_Type.tp_name = "BMIter";
-
-
- BPy_BMesh_Type.tp_doc = bpy_bmesh_doc;
- BPy_BMVert_Type.tp_doc = bpy_bmvert_doc;
- BPy_BMEdge_Type.tp_doc = bpy_bmedge_doc;
- BPy_BMFace_Type.tp_doc = bpy_bmface_doc;
- BPy_BMLoop_Type.tp_doc = bpy_bmloop_doc;
- BPy_BMElemSeq_Type.tp_doc = bpy_bmelemseq_doc;
- BPy_BMVertSeq_Type.tp_doc = NULL;
- BPy_BMEdgeSeq_Type.tp_doc = NULL;
- BPy_BMFaceSeq_Type.tp_doc = NULL;
- BPy_BMLoopSeq_Type.tp_doc = NULL;
- BPy_BMIter_Type.tp_doc = bpy_bmiter_doc;
-
-
- BPy_BMesh_Type.tp_repr = (reprfunc)bpy_bmesh_repr;
- BPy_BMVert_Type.tp_repr = (reprfunc)bpy_bmvert_repr;
- BPy_BMEdge_Type.tp_repr = (reprfunc)bpy_bmedge_repr;
- BPy_BMFace_Type.tp_repr = (reprfunc)bpy_bmface_repr;
- BPy_BMLoop_Type.tp_repr = (reprfunc)bpy_bmloop_repr;
- BPy_BMElemSeq_Type.tp_repr = NULL;
- BPy_BMVertSeq_Type.tp_repr = NULL;
- BPy_BMEdgeSeq_Type.tp_repr = NULL;
- BPy_BMFaceSeq_Type.tp_repr = NULL;
- BPy_BMLoopSeq_Type.tp_repr = NULL;
- BPy_BMIter_Type.tp_repr = NULL;
-
-
- BPy_BMesh_Type.tp_getset = bpy_bmesh_getseters;
- BPy_BMVert_Type.tp_getset = bpy_bmvert_getseters;
- BPy_BMEdge_Type.tp_getset = bpy_bmedge_getseters;
- BPy_BMFace_Type.tp_getset = bpy_bmface_getseters;
- BPy_BMLoop_Type.tp_getset = bpy_bmloop_getseters;
- BPy_BMElemSeq_Type.tp_getset = NULL;
- BPy_BMVertSeq_Type.tp_getset = bpy_bmvertseq_getseters;
- BPy_BMEdgeSeq_Type.tp_getset = bpy_bmedgeseq_getseters;
- BPy_BMFaceSeq_Type.tp_getset = bpy_bmfaceseq_getseters;
- BPy_BMLoopSeq_Type.tp_getset = bpy_bmloopseq_getseters;
- BPy_BMIter_Type.tp_getset = NULL;
-
-
- BPy_BMesh_Type.tp_methods = bpy_bmesh_methods;
- BPy_BMVert_Type.tp_methods = bpy_bmvert_methods;
- BPy_BMEdge_Type.tp_methods = bpy_bmedge_methods;
- BPy_BMFace_Type.tp_methods = bpy_bmface_methods;
- BPy_BMLoop_Type.tp_methods = bpy_bmloop_methods;
- BPy_BMElemSeq_Type.tp_methods = bpy_bmelemseq_methods;
- BPy_BMVertSeq_Type.tp_methods = bpy_bmvertseq_methods;
- BPy_BMEdgeSeq_Type.tp_methods = bpy_bmedgeseq_methods;
- BPy_BMFaceSeq_Type.tp_methods = bpy_bmfaceseq_methods;
- BPy_BMLoopSeq_Type.tp_methods = bpy_bmloopseq_methods;
- BPy_BMIter_Type.tp_methods = NULL;
-
- /*BPy_BMElem_Check() uses bpy_bm_elem_hash() to check types.
- * if this changes update the macro */
- BPy_BMesh_Type.tp_hash = bpy_bm_hash;
- BPy_BMVert_Type.tp_hash = bpy_bm_elem_hash;
- BPy_BMEdge_Type.tp_hash = bpy_bm_elem_hash;
- BPy_BMFace_Type.tp_hash = bpy_bm_elem_hash;
- BPy_BMLoop_Type.tp_hash = bpy_bm_elem_hash;
- BPy_BMElemSeq_Type.tp_hash = NULL;
- BPy_BMVertSeq_Type.tp_hash = NULL;
- BPy_BMEdgeSeq_Type.tp_hash = NULL;
- BPy_BMFaceSeq_Type.tp_hash = NULL;
- BPy_BMLoopSeq_Type.tp_hash = NULL;
- BPy_BMIter_Type.tp_hash = NULL;
-
- BPy_BMElemSeq_Type.tp_as_sequence = &bpy_bmelemseq_as_sequence;
- BPy_BMVertSeq_Type.tp_as_sequence = &bpy_bmelemseq_as_sequence;
- BPy_BMEdgeSeq_Type.tp_as_sequence = &bpy_bmelemseq_as_sequence;
- BPy_BMFaceSeq_Type.tp_as_sequence = &bpy_bmelemseq_as_sequence;
- BPy_BMLoopSeq_Type.tp_as_sequence = NULL; /* this is not a seq really, only for layer access */
-
- BPy_BMElemSeq_Type.tp_as_mapping = &bpy_bmelemseq_as_mapping;
- BPy_BMVertSeq_Type.tp_as_mapping = &bpy_bmelemseq_as_mapping;
- BPy_BMEdgeSeq_Type.tp_as_mapping = &bpy_bmelemseq_as_mapping;
- BPy_BMFaceSeq_Type.tp_as_mapping = &bpy_bmelemseq_as_mapping;
- BPy_BMLoopSeq_Type.tp_as_mapping = NULL; /* this is not a seq really, only for layer access */
-
- /* layer access */
- BPy_BMVert_Type.tp_as_mapping = &bpy_bm_elem_as_mapping;
- BPy_BMEdge_Type.tp_as_mapping = &bpy_bm_elem_as_mapping;
- BPy_BMFace_Type.tp_as_mapping = &bpy_bm_elem_as_mapping;
- BPy_BMLoop_Type.tp_as_mapping = &bpy_bm_elem_as_mapping;
-
- BPy_BMElemSeq_Type.tp_iter = (getiterfunc)bpy_bmelemseq_iter;
- BPy_BMVertSeq_Type.tp_iter = (getiterfunc)bpy_bmelemseq_iter;
- BPy_BMEdgeSeq_Type.tp_iter = (getiterfunc)bpy_bmelemseq_iter;
- BPy_BMFaceSeq_Type.tp_iter = (getiterfunc)bpy_bmelemseq_iter;
- BPy_BMLoopSeq_Type.tp_iter = NULL; /* no mapping */
-
- /* only 1 iteratir so far */
- BPy_BMIter_Type.tp_iternext = (iternextfunc)bpy_bmiter_next;
- BPy_BMIter_Type.tp_iter = PyObject_SelfIter;
-
- BPy_BMesh_Type.tp_dealloc = (destructor)bpy_bmesh_dealloc;
- BPy_BMVert_Type.tp_dealloc = (destructor)bpy_bmvert_dealloc;
- BPy_BMEdge_Type.tp_dealloc = (destructor)bpy_bmedge_dealloc;
- BPy_BMFace_Type.tp_dealloc = (destructor)bpy_bmface_dealloc;
- BPy_BMLoop_Type.tp_dealloc = (destructor)bpy_bmloop_dealloc;
- BPy_BMElemSeq_Type.tp_dealloc = (destructor)bpy_bmelemseq_dealloc;
- BPy_BMVertSeq_Type.tp_dealloc = (destructor)bpy_bmelemseq_dealloc;
- BPy_BMEdgeSeq_Type.tp_dealloc = (destructor)bpy_bmelemseq_dealloc;
- BPy_BMFaceSeq_Type.tp_dealloc = (destructor)bpy_bmelemseq_dealloc;
- BPy_BMLoopSeq_Type.tp_dealloc = (destructor)bpy_bmelemseq_dealloc;
- BPy_BMIter_Type.tp_dealloc = NULL;
-
- BPy_BMesh_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- BPy_BMVert_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- BPy_BMEdge_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- BPy_BMFace_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- BPy_BMLoop_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- BPy_BMElemSeq_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- BPy_BMVertSeq_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- BPy_BMEdgeSeq_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- BPy_BMFaceSeq_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- BPy_BMLoopSeq_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- BPy_BMIter_Type.tp_flags = Py_TPFLAGS_DEFAULT;
-
-
- PyType_Ready(&BPy_BMesh_Type);
- PyType_Ready(&BPy_BMVert_Type);
- PyType_Ready(&BPy_BMEdge_Type);
- PyType_Ready(&BPy_BMFace_Type);
- PyType_Ready(&BPy_BMLoop_Type);
- PyType_Ready(&BPy_BMElemSeq_Type);
- PyType_Ready(&BPy_BMVertSeq_Type);
- PyType_Ready(&BPy_BMEdgeSeq_Type);
- PyType_Ready(&BPy_BMFaceSeq_Type);
- PyType_Ready(&BPy_BMLoopSeq_Type);
- PyType_Ready(&BPy_BMIter_Type);
+ BPy_BMesh_Type.tp_basicsize = sizeof(BPy_BMesh);
+ BPy_BMVert_Type.tp_basicsize = sizeof(BPy_BMVert);
+ BPy_BMEdge_Type.tp_basicsize = sizeof(BPy_BMEdge);
+ BPy_BMFace_Type.tp_basicsize = sizeof(BPy_BMFace);
+ BPy_BMLoop_Type.tp_basicsize = sizeof(BPy_BMLoop);
+ BPy_BMElemSeq_Type.tp_basicsize = sizeof(BPy_BMElemSeq);
+ BPy_BMVertSeq_Type.tp_basicsize = sizeof(BPy_BMElemSeq);
+ BPy_BMEdgeSeq_Type.tp_basicsize = sizeof(BPy_BMElemSeq);
+ BPy_BMFaceSeq_Type.tp_basicsize = sizeof(BPy_BMElemSeq);
+ BPy_BMLoopSeq_Type.tp_basicsize = sizeof(BPy_BMElemSeq);
+ BPy_BMIter_Type.tp_basicsize = sizeof(BPy_BMIter);
+
+ BPy_BMesh_Type.tp_name = "BMesh";
+ BPy_BMVert_Type.tp_name = "BMVert";
+ BPy_BMEdge_Type.tp_name = "BMEdge";
+ BPy_BMFace_Type.tp_name = "BMFace";
+ BPy_BMLoop_Type.tp_name = "BMLoop";
+ BPy_BMElemSeq_Type.tp_name = "BMElemSeq";
+ BPy_BMVertSeq_Type.tp_name = "BMVertSeq";
+ BPy_BMEdgeSeq_Type.tp_name = "BMEdgeSeq";
+ BPy_BMFaceSeq_Type.tp_name = "BMFaceSeq";
+ BPy_BMLoopSeq_Type.tp_name = "BMLoopSeq";
+ BPy_BMIter_Type.tp_name = "BMIter";
+
+ BPy_BMesh_Type.tp_doc = bpy_bmesh_doc;
+ BPy_BMVert_Type.tp_doc = bpy_bmvert_doc;
+ BPy_BMEdge_Type.tp_doc = bpy_bmedge_doc;
+ BPy_BMFace_Type.tp_doc = bpy_bmface_doc;
+ BPy_BMLoop_Type.tp_doc = bpy_bmloop_doc;
+ BPy_BMElemSeq_Type.tp_doc = bpy_bmelemseq_doc;
+ BPy_BMVertSeq_Type.tp_doc = NULL;
+ BPy_BMEdgeSeq_Type.tp_doc = NULL;
+ BPy_BMFaceSeq_Type.tp_doc = NULL;
+ BPy_BMLoopSeq_Type.tp_doc = NULL;
+ BPy_BMIter_Type.tp_doc = bpy_bmiter_doc;
+
+ BPy_BMesh_Type.tp_repr = (reprfunc)bpy_bmesh_repr;
+ BPy_BMVert_Type.tp_repr = (reprfunc)bpy_bmvert_repr;
+ BPy_BMEdge_Type.tp_repr = (reprfunc)bpy_bmedge_repr;
+ BPy_BMFace_Type.tp_repr = (reprfunc)bpy_bmface_repr;
+ BPy_BMLoop_Type.tp_repr = (reprfunc)bpy_bmloop_repr;
+ BPy_BMElemSeq_Type.tp_repr = NULL;
+ BPy_BMVertSeq_Type.tp_repr = NULL;
+ BPy_BMEdgeSeq_Type.tp_repr = NULL;
+ BPy_BMFaceSeq_Type.tp_repr = NULL;
+ BPy_BMLoopSeq_Type.tp_repr = NULL;
+ BPy_BMIter_Type.tp_repr = NULL;
+
+ BPy_BMesh_Type.tp_getset = bpy_bmesh_getseters;
+ BPy_BMVert_Type.tp_getset = bpy_bmvert_getseters;
+ BPy_BMEdge_Type.tp_getset = bpy_bmedge_getseters;
+ BPy_BMFace_Type.tp_getset = bpy_bmface_getseters;
+ BPy_BMLoop_Type.tp_getset = bpy_bmloop_getseters;
+ BPy_BMElemSeq_Type.tp_getset = NULL;
+ BPy_BMVertSeq_Type.tp_getset = bpy_bmvertseq_getseters;
+ BPy_BMEdgeSeq_Type.tp_getset = bpy_bmedgeseq_getseters;
+ BPy_BMFaceSeq_Type.tp_getset = bpy_bmfaceseq_getseters;
+ BPy_BMLoopSeq_Type.tp_getset = bpy_bmloopseq_getseters;
+ BPy_BMIter_Type.tp_getset = NULL;
+
+ BPy_BMesh_Type.tp_methods = bpy_bmesh_methods;
+ BPy_BMVert_Type.tp_methods = bpy_bmvert_methods;
+ BPy_BMEdge_Type.tp_methods = bpy_bmedge_methods;
+ BPy_BMFace_Type.tp_methods = bpy_bmface_methods;
+ BPy_BMLoop_Type.tp_methods = bpy_bmloop_methods;
+ BPy_BMElemSeq_Type.tp_methods = bpy_bmelemseq_methods;
+ BPy_BMVertSeq_Type.tp_methods = bpy_bmvertseq_methods;
+ BPy_BMEdgeSeq_Type.tp_methods = bpy_bmedgeseq_methods;
+ BPy_BMFaceSeq_Type.tp_methods = bpy_bmfaceseq_methods;
+ BPy_BMLoopSeq_Type.tp_methods = bpy_bmloopseq_methods;
+ BPy_BMIter_Type.tp_methods = NULL;
+
+ /*BPy_BMElem_Check() uses bpy_bm_elem_hash() to check types.
+ * if this changes update the macro */
+ BPy_BMesh_Type.tp_hash = bpy_bm_hash;
+ BPy_BMVert_Type.tp_hash = bpy_bm_elem_hash;
+ BPy_BMEdge_Type.tp_hash = bpy_bm_elem_hash;
+ BPy_BMFace_Type.tp_hash = bpy_bm_elem_hash;
+ BPy_BMLoop_Type.tp_hash = bpy_bm_elem_hash;
+ BPy_BMElemSeq_Type.tp_hash = NULL;
+ BPy_BMVertSeq_Type.tp_hash = NULL;
+ BPy_BMEdgeSeq_Type.tp_hash = NULL;
+ BPy_BMFaceSeq_Type.tp_hash = NULL;
+ BPy_BMLoopSeq_Type.tp_hash = NULL;
+ BPy_BMIter_Type.tp_hash = NULL;
+
+ BPy_BMElemSeq_Type.tp_as_sequence = &bpy_bmelemseq_as_sequence;
+ BPy_BMVertSeq_Type.tp_as_sequence = &bpy_bmelemseq_as_sequence;
+ BPy_BMEdgeSeq_Type.tp_as_sequence = &bpy_bmelemseq_as_sequence;
+ BPy_BMFaceSeq_Type.tp_as_sequence = &bpy_bmelemseq_as_sequence;
+ BPy_BMLoopSeq_Type.tp_as_sequence = NULL; /* this is not a seq really, only for layer access */
+
+ BPy_BMElemSeq_Type.tp_as_mapping = &bpy_bmelemseq_as_mapping;
+ BPy_BMVertSeq_Type.tp_as_mapping = &bpy_bmelemseq_as_mapping;
+ BPy_BMEdgeSeq_Type.tp_as_mapping = &bpy_bmelemseq_as_mapping;
+ BPy_BMFaceSeq_Type.tp_as_mapping = &bpy_bmelemseq_as_mapping;
+ BPy_BMLoopSeq_Type.tp_as_mapping = NULL; /* this is not a seq really, only for layer access */
+
+ /* layer access */
+ BPy_BMVert_Type.tp_as_mapping = &bpy_bm_elem_as_mapping;
+ BPy_BMEdge_Type.tp_as_mapping = &bpy_bm_elem_as_mapping;
+ BPy_BMFace_Type.tp_as_mapping = &bpy_bm_elem_as_mapping;
+ BPy_BMLoop_Type.tp_as_mapping = &bpy_bm_elem_as_mapping;
+
+ BPy_BMElemSeq_Type.tp_iter = (getiterfunc)bpy_bmelemseq_iter;
+ BPy_BMVertSeq_Type.tp_iter = (getiterfunc)bpy_bmelemseq_iter;
+ BPy_BMEdgeSeq_Type.tp_iter = (getiterfunc)bpy_bmelemseq_iter;
+ BPy_BMFaceSeq_Type.tp_iter = (getiterfunc)bpy_bmelemseq_iter;
+ BPy_BMLoopSeq_Type.tp_iter = NULL; /* no mapping */
+
+ /* only 1 iteratir so far */
+ BPy_BMIter_Type.tp_iternext = (iternextfunc)bpy_bmiter_next;
+ BPy_BMIter_Type.tp_iter = PyObject_SelfIter;
+
+ BPy_BMesh_Type.tp_dealloc = (destructor)bpy_bmesh_dealloc;
+ BPy_BMVert_Type.tp_dealloc = (destructor)bpy_bmvert_dealloc;
+ BPy_BMEdge_Type.tp_dealloc = (destructor)bpy_bmedge_dealloc;
+ BPy_BMFace_Type.tp_dealloc = (destructor)bpy_bmface_dealloc;
+ BPy_BMLoop_Type.tp_dealloc = (destructor)bpy_bmloop_dealloc;
+ BPy_BMElemSeq_Type.tp_dealloc = (destructor)bpy_bmelemseq_dealloc;
+ BPy_BMVertSeq_Type.tp_dealloc = (destructor)bpy_bmelemseq_dealloc;
+ BPy_BMEdgeSeq_Type.tp_dealloc = (destructor)bpy_bmelemseq_dealloc;
+ BPy_BMFaceSeq_Type.tp_dealloc = (destructor)bpy_bmelemseq_dealloc;
+ BPy_BMLoopSeq_Type.tp_dealloc = (destructor)bpy_bmelemseq_dealloc;
+ BPy_BMIter_Type.tp_dealloc = NULL;
+
+ BPy_BMesh_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMVert_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMEdge_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMFace_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMLoop_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMElemSeq_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMVertSeq_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMEdgeSeq_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMFaceSeq_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMLoopSeq_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMIter_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+
+ PyType_Ready(&BPy_BMesh_Type);
+ PyType_Ready(&BPy_BMVert_Type);
+ PyType_Ready(&BPy_BMEdge_Type);
+ PyType_Ready(&BPy_BMFace_Type);
+ PyType_Ready(&BPy_BMLoop_Type);
+ PyType_Ready(&BPy_BMElemSeq_Type);
+ PyType_Ready(&BPy_BMVertSeq_Type);
+ PyType_Ready(&BPy_BMEdgeSeq_Type);
+ PyType_Ready(&BPy_BMFaceSeq_Type);
+ PyType_Ready(&BPy_BMLoopSeq_Type);
+ PyType_Ready(&BPy_BMIter_Type);
}
/* bmesh.types submodule
* ********************* */
static struct PyModuleDef BPy_BM_types_module_def = {
- PyModuleDef_HEAD_INIT,
- "bmesh.types", /* m_name */
- NULL, /* m_doc */
- 0, /* m_size */
- NULL, /* m_methods */
- NULL, /* m_reload */
- NULL, /* m_traverse */
- NULL, /* m_clear */
- NULL, /* m_free */
+ PyModuleDef_HEAD_INIT,
+ "bmesh.types", /* m_name */
+ NULL, /* m_doc */
+ 0, /* m_size */
+ NULL, /* m_methods */
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL, /* m_free */
};
PyObject *BPyInit_bmesh_types(void)
{
- PyObject *submodule;
+ PyObject *submodule;
- submodule = PyModule_Create(&BPy_BM_types_module_def);
+ submodule = PyModule_Create(&BPy_BM_types_module_def);
#define MODULE_TYPE_ADD(s, t) \
- PyModule_AddObject(s, t.tp_name, (PyObject *)&t); Py_INCREF((PyObject *)&t)
-
- /* bmesh_py_types.c */
- MODULE_TYPE_ADD(submodule, BPy_BMesh_Type);
- MODULE_TYPE_ADD(submodule, BPy_BMVert_Type);
- MODULE_TYPE_ADD(submodule, BPy_BMEdge_Type);
- MODULE_TYPE_ADD(submodule, BPy_BMFace_Type);
- MODULE_TYPE_ADD(submodule, BPy_BMLoop_Type);
- MODULE_TYPE_ADD(submodule, BPy_BMElemSeq_Type);
- MODULE_TYPE_ADD(submodule, BPy_BMVertSeq_Type);
- MODULE_TYPE_ADD(submodule, BPy_BMEdgeSeq_Type);
- MODULE_TYPE_ADD(submodule, BPy_BMFaceSeq_Type);
- MODULE_TYPE_ADD(submodule, BPy_BMLoopSeq_Type);
- MODULE_TYPE_ADD(submodule, BPy_BMIter_Type);
- /* bmesh_py_types_select.c */
- MODULE_TYPE_ADD(submodule, BPy_BMEditSelSeq_Type);
- MODULE_TYPE_ADD(submodule, BPy_BMEditSelIter_Type);
- /* bmesh_py_types_customdata.c */
- MODULE_TYPE_ADD(submodule, BPy_BMLayerAccessVert_Type);
- MODULE_TYPE_ADD(submodule, BPy_BMLayerAccessEdge_Type);
- MODULE_TYPE_ADD(submodule, BPy_BMLayerAccessFace_Type);
- MODULE_TYPE_ADD(submodule, BPy_BMLayerAccessLoop_Type);
- MODULE_TYPE_ADD(submodule, BPy_BMLayerCollection_Type);
- MODULE_TYPE_ADD(submodule, BPy_BMLayerItem_Type);
- /* bmesh_py_types_meshdata.c */
- MODULE_TYPE_ADD(submodule, BPy_BMLoopUV_Type);
- MODULE_TYPE_ADD(submodule, BPy_BMDeformVert_Type);
+ PyModule_AddObject(s, t.tp_name, (PyObject *)&t); \
+ Py_INCREF((PyObject *)&t)
+
+ /* bmesh_py_types.c */
+ MODULE_TYPE_ADD(submodule, BPy_BMesh_Type);
+ MODULE_TYPE_ADD(submodule, BPy_BMVert_Type);
+ MODULE_TYPE_ADD(submodule, BPy_BMEdge_Type);
+ MODULE_TYPE_ADD(submodule, BPy_BMFace_Type);
+ MODULE_TYPE_ADD(submodule, BPy_BMLoop_Type);
+ MODULE_TYPE_ADD(submodule, BPy_BMElemSeq_Type);
+ MODULE_TYPE_ADD(submodule, BPy_BMVertSeq_Type);
+ MODULE_TYPE_ADD(submodule, BPy_BMEdgeSeq_Type);
+ MODULE_TYPE_ADD(submodule, BPy_BMFaceSeq_Type);
+ MODULE_TYPE_ADD(submodule, BPy_BMLoopSeq_Type);
+ MODULE_TYPE_ADD(submodule, BPy_BMIter_Type);
+ /* bmesh_py_types_select.c */
+ MODULE_TYPE_ADD(submodule, BPy_BMEditSelSeq_Type);
+ MODULE_TYPE_ADD(submodule, BPy_BMEditSelIter_Type);
+ /* bmesh_py_types_customdata.c */
+ MODULE_TYPE_ADD(submodule, BPy_BMLayerAccessVert_Type);
+ MODULE_TYPE_ADD(submodule, BPy_BMLayerAccessEdge_Type);
+ MODULE_TYPE_ADD(submodule, BPy_BMLayerAccessFace_Type);
+ MODULE_TYPE_ADD(submodule, BPy_BMLayerAccessLoop_Type);
+ MODULE_TYPE_ADD(submodule, BPy_BMLayerCollection_Type);
+ MODULE_TYPE_ADD(submodule, BPy_BMLayerItem_Type);
+ /* bmesh_py_types_meshdata.c */
+ MODULE_TYPE_ADD(submodule, BPy_BMLoopUV_Type);
+ MODULE_TYPE_ADD(submodule, BPy_BMDeformVert_Type);
#undef MODULE_TYPE_ADD
- return submodule;
+ return submodule;
}
/* Utility Functions
@@ -3619,272 +3858,273 @@ PyObject *BPyInit_bmesh_types(void)
PyObject *BPy_BMesh_CreatePyObject(BMesh *bm, int flag)
{
- BPy_BMesh *self;
+ BPy_BMesh *self;
- if (bm->py_handle) {
- self = bm->py_handle;
- Py_INCREF(self);
- }
- else {
- self = PyObject_New(BPy_BMesh, &BPy_BMesh_Type);
- self->bm = bm;
- self->flag = flag;
+ if (bm->py_handle) {
+ self = bm->py_handle;
+ Py_INCREF(self);
+ }
+ else {
+ self = PyObject_New(BPy_BMesh, &BPy_BMesh_Type);
+ self->bm = bm;
+ self->flag = flag;
- bm->py_handle = self; /* point back */
+ bm->py_handle = self; /* point back */
- /* avoid allocating layers when we don't have to */
+ /* avoid allocating layers when we don't have to */
#if 0
- BM_data_layer_add(bm, &bm->vdata, CD_BM_ELEM_PYPTR);
- BM_data_layer_add(bm, &bm->edata, CD_BM_ELEM_PYPTR);
- BM_data_layer_add(bm, &bm->pdata, CD_BM_ELEM_PYPTR);
- BM_data_layer_add(bm, &bm->ldata, CD_BM_ELEM_PYPTR);
+ BM_data_layer_add(bm, &bm->vdata, CD_BM_ELEM_PYPTR);
+ BM_data_layer_add(bm, &bm->edata, CD_BM_ELEM_PYPTR);
+ BM_data_layer_add(bm, &bm->pdata, CD_BM_ELEM_PYPTR);
+ BM_data_layer_add(bm, &bm->ldata, CD_BM_ELEM_PYPTR);
#endif
- }
+ }
- return (PyObject *)self;
+ return (PyObject *)self;
}
-
-
PyObject *BPy_BMVert_CreatePyObject(BMesh *bm, BMVert *v)
{
- BPy_BMVert *self;
+ BPy_BMVert *self;
- void **ptr = CustomData_bmesh_get(&bm->vdata, v->head.data, CD_BM_ELEM_PYPTR);
+ void **ptr = CustomData_bmesh_get(&bm->vdata, v->head.data, CD_BM_ELEM_PYPTR);
- /* bmesh may free layers, ensure we have one to store ourself */
- if (UNLIKELY(ptr == NULL)) {
- BM_data_layer_add(bm, &bm->vdata, CD_BM_ELEM_PYPTR);
- ptr = CustomData_bmesh_get(&bm->vdata, v->head.data, CD_BM_ELEM_PYPTR);
- }
+ /* bmesh may free layers, ensure we have one to store ourself */
+ if (UNLIKELY(ptr == NULL)) {
+ BM_data_layer_add(bm, &bm->vdata, CD_BM_ELEM_PYPTR);
+ ptr = CustomData_bmesh_get(&bm->vdata, v->head.data, CD_BM_ELEM_PYPTR);
+ }
- if (*ptr != NULL) {
- self = *ptr;
- Py_INCREF(self);
- }
- else {
- self = PyObject_New(BPy_BMVert, &BPy_BMVert_Type);
- BLI_assert(v != NULL);
- self->bm = bm;
- self->v = v;
- *ptr = self;
- }
- return (PyObject *)self;
+ if (*ptr != NULL) {
+ self = *ptr;
+ Py_INCREF(self);
+ }
+ else {
+ self = PyObject_New(BPy_BMVert, &BPy_BMVert_Type);
+ BLI_assert(v != NULL);
+ self->bm = bm;
+ self->v = v;
+ *ptr = self;
+ }
+ return (PyObject *)self;
}
PyObject *BPy_BMEdge_CreatePyObject(BMesh *bm, BMEdge *e)
{
- BPy_BMEdge *self;
+ BPy_BMEdge *self;
- void **ptr = CustomData_bmesh_get(&bm->edata, e->head.data, CD_BM_ELEM_PYPTR);
+ void **ptr = CustomData_bmesh_get(&bm->edata, e->head.data, CD_BM_ELEM_PYPTR);
- /* bmesh may free layers, ensure we have one to store ourself */
- if (UNLIKELY(ptr == NULL)) {
- BM_data_layer_add(bm, &bm->edata, CD_BM_ELEM_PYPTR);
- ptr = CustomData_bmesh_get(&bm->edata, e->head.data, CD_BM_ELEM_PYPTR);
- }
+ /* bmesh may free layers, ensure we have one to store ourself */
+ if (UNLIKELY(ptr == NULL)) {
+ BM_data_layer_add(bm, &bm->edata, CD_BM_ELEM_PYPTR);
+ ptr = CustomData_bmesh_get(&bm->edata, e->head.data, CD_BM_ELEM_PYPTR);
+ }
- if (*ptr != NULL) {
- self = *ptr;
- Py_INCREF(self);
- }
- else {
- self = PyObject_New(BPy_BMEdge, &BPy_BMEdge_Type);
- BLI_assert(e != NULL);
- self->bm = bm;
- self->e = e;
- *ptr = self;
- }
- return (PyObject *)self;
+ if (*ptr != NULL) {
+ self = *ptr;
+ Py_INCREF(self);
+ }
+ else {
+ self = PyObject_New(BPy_BMEdge, &BPy_BMEdge_Type);
+ BLI_assert(e != NULL);
+ self->bm = bm;
+ self->e = e;
+ *ptr = self;
+ }
+ return (PyObject *)self;
}
PyObject *BPy_BMFace_CreatePyObject(BMesh *bm, BMFace *f)
{
- BPy_BMFace *self;
+ BPy_BMFace *self;
- void **ptr = CustomData_bmesh_get(&bm->pdata, f->head.data, CD_BM_ELEM_PYPTR);
+ void **ptr = CustomData_bmesh_get(&bm->pdata, f->head.data, CD_BM_ELEM_PYPTR);
- /* bmesh may free layers, ensure we have one to store ourself */
- if (UNLIKELY(ptr == NULL)) {
- BM_data_layer_add(bm, &bm->pdata, CD_BM_ELEM_PYPTR);
- ptr = CustomData_bmesh_get(&bm->pdata, f->head.data, CD_BM_ELEM_PYPTR);
- }
+ /* bmesh may free layers, ensure we have one to store ourself */
+ if (UNLIKELY(ptr == NULL)) {
+ BM_data_layer_add(bm, &bm->pdata, CD_BM_ELEM_PYPTR);
+ ptr = CustomData_bmesh_get(&bm->pdata, f->head.data, CD_BM_ELEM_PYPTR);
+ }
- if (*ptr != NULL) {
- self = *ptr;
- Py_INCREF(self);
- }
- else {
- self = PyObject_New(BPy_BMFace, &BPy_BMFace_Type);
- BLI_assert(f != NULL);
- self->bm = bm;
- self->f = f;
- *ptr = self;
- }
- return (PyObject *)self;
+ if (*ptr != NULL) {
+ self = *ptr;
+ Py_INCREF(self);
+ }
+ else {
+ self = PyObject_New(BPy_BMFace, &BPy_BMFace_Type);
+ BLI_assert(f != NULL);
+ self->bm = bm;
+ self->f = f;
+ *ptr = self;
+ }
+ return (PyObject *)self;
}
PyObject *BPy_BMLoop_CreatePyObject(BMesh *bm, BMLoop *l)
{
- BPy_BMLoop *self;
+ BPy_BMLoop *self;
- void **ptr = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_BM_ELEM_PYPTR);
+ void **ptr = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_BM_ELEM_PYPTR);
- /* bmesh may free layers, ensure we have one to store ourself */
- if (UNLIKELY(ptr == NULL)) {
- BM_data_layer_add(bm, &bm->ldata, CD_BM_ELEM_PYPTR);
- ptr = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_BM_ELEM_PYPTR);
- }
+ /* bmesh may free layers, ensure we have one to store ourself */
+ if (UNLIKELY(ptr == NULL)) {
+ BM_data_layer_add(bm, &bm->ldata, CD_BM_ELEM_PYPTR);
+ ptr = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_BM_ELEM_PYPTR);
+ }
- if (*ptr != NULL) {
- self = *ptr;
- Py_INCREF(self);
- }
- else {
- self = PyObject_New(BPy_BMLoop, &BPy_BMLoop_Type);
- BLI_assert(l != NULL);
- self->bm = bm;
- self->l = l;
- *ptr = self;
- }
- return (PyObject *)self;
+ if (*ptr != NULL) {
+ self = *ptr;
+ Py_INCREF(self);
+ }
+ else {
+ self = PyObject_New(BPy_BMLoop, &BPy_BMLoop_Type);
+ BLI_assert(l != NULL);
+ self->bm = bm;
+ self->l = l;
+ *ptr = self;
+ }
+ return (PyObject *)self;
}
PyObject *BPy_BMElemSeq_CreatePyObject(BMesh *bm, BPy_BMElem *py_ele, const char itype)
{
- BPy_BMElemSeq *self = PyObject_New(BPy_BMElemSeq, &BPy_BMElemSeq_Type);
- self->bm = bm;
- self->py_ele = py_ele; /* can be NULL */
- self->itype = itype;
- Py_XINCREF(py_ele);
- return (PyObject *)self;
+ BPy_BMElemSeq *self = PyObject_New(BPy_BMElemSeq, &BPy_BMElemSeq_Type);
+ self->bm = bm;
+ self->py_ele = py_ele; /* can be NULL */
+ self->itype = itype;
+ Py_XINCREF(py_ele);
+ return (PyObject *)self;
}
PyObject *BPy_BMVertSeq_CreatePyObject(BMesh *bm)
{
- BPy_BMElemSeq *self = PyObject_New(BPy_BMElemSeq, &BPy_BMVertSeq_Type);
- self->bm = bm;
- self->py_ele = NULL; /* unused */
- self->itype = BM_VERTS_OF_MESH;
- return (PyObject *)self;
+ BPy_BMElemSeq *self = PyObject_New(BPy_BMElemSeq, &BPy_BMVertSeq_Type);
+ self->bm = bm;
+ self->py_ele = NULL; /* unused */
+ self->itype = BM_VERTS_OF_MESH;
+ return (PyObject *)self;
}
PyObject *BPy_BMEdgeSeq_CreatePyObject(BMesh *bm)
{
- BPy_BMElemSeq *self = PyObject_New(BPy_BMElemSeq, &BPy_BMEdgeSeq_Type);
- self->bm = bm;
- self->py_ele = NULL; /* unused */
- self->itype = BM_EDGES_OF_MESH;
- return (PyObject *)self;
+ BPy_BMElemSeq *self = PyObject_New(BPy_BMElemSeq, &BPy_BMEdgeSeq_Type);
+ self->bm = bm;
+ self->py_ele = NULL; /* unused */
+ self->itype = BM_EDGES_OF_MESH;
+ return (PyObject *)self;
}
PyObject *BPy_BMFaceSeq_CreatePyObject(BMesh *bm)
{
- BPy_BMElemSeq *self = PyObject_New(BPy_BMElemSeq, &BPy_BMFaceSeq_Type);
- self->bm = bm;
- self->py_ele = NULL; /* unused */
- self->itype = BM_FACES_OF_MESH;
- return (PyObject *)self;
+ BPy_BMElemSeq *self = PyObject_New(BPy_BMElemSeq, &BPy_BMFaceSeq_Type);
+ self->bm = bm;
+ self->py_ele = NULL; /* unused */
+ self->itype = BM_FACES_OF_MESH;
+ return (PyObject *)self;
}
PyObject *BPy_BMLoopSeq_CreatePyObject(BMesh *bm)
{
- BPy_BMElemSeq *self = PyObject_New(BPy_BMElemSeq, &BPy_BMLoopSeq_Type);
- self->bm = bm;
- self->py_ele = NULL; /* unused */
- self->itype = 0; /* should never be passed to the iterator function */
- return (PyObject *)self;
+ BPy_BMElemSeq *self = PyObject_New(BPy_BMElemSeq, &BPy_BMLoopSeq_Type);
+ self->bm = bm;
+ self->py_ele = NULL; /* unused */
+ self->itype = 0; /* should never be passed to the iterator function */
+ return (PyObject *)self;
}
PyObject *BPy_BMIter_CreatePyObject(BMesh *bm)
{
- BPy_BMIter *self = PyObject_New(BPy_BMIter, &BPy_BMIter_Type);
- self->bm = bm;
- /* caller must initialize 'iter' member */
- return (PyObject *)self;
+ BPy_BMIter *self = PyObject_New(BPy_BMIter, &BPy_BMIter_Type);
+ self->bm = bm;
+ /* caller must initialize 'iter' member */
+ return (PyObject *)self;
}
/* this is just a helper func */
PyObject *BPy_BMElem_CreatePyObject(BMesh *bm, BMHeader *ele)
{
- switch (ele->htype) {
- case BM_VERT:
- return BPy_BMVert_CreatePyObject(bm, (BMVert *)ele);
- case BM_EDGE:
- return BPy_BMEdge_CreatePyObject(bm, (BMEdge *)ele);
- case BM_FACE:
- return BPy_BMFace_CreatePyObject(bm, (BMFace *)ele);
- case BM_LOOP:
- return BPy_BMLoop_CreatePyObject(bm, (BMLoop *)ele);
- default:
- BLI_assert(0);
- PyErr_SetString(PyExc_SystemError, "internal error");
- return NULL;
- }
+ switch (ele->htype) {
+ case BM_VERT:
+ return BPy_BMVert_CreatePyObject(bm, (BMVert *)ele);
+ case BM_EDGE:
+ return BPy_BMEdge_CreatePyObject(bm, (BMEdge *)ele);
+ case BM_FACE:
+ return BPy_BMFace_CreatePyObject(bm, (BMFace *)ele);
+ case BM_LOOP:
+ return BPy_BMLoop_CreatePyObject(bm, (BMLoop *)ele);
+ default:
+ BLI_assert(0);
+ PyErr_SetString(PyExc_SystemError, "internal error");
+ return NULL;
+ }
}
int bpy_bm_generic_valid_check(BPy_BMGeneric *self)
{
- if (LIKELY(self->bm)) {
+ if (LIKELY(self->bm)) {
- /* far too slow to enable by default but handy
- * to uncomment for debugging tricky errors,
- * note that this will throw error on entering a
- * function where the actual error will be caused by
- * the previous action. */
+ /* far too slow to enable by default but handy
+ * to uncomment for debugging tricky errors,
+ * note that this will throw error on entering a
+ * function where the actual error will be caused by
+ * the previous action. */
#if 0
- if (BM_mesh_validate(self->bm) == false) {
- PyErr_Format(PyExc_ReferenceError,
- "BMesh used by %.200s has become invalid",
- Py_TYPE(self)->tp_name);
- return -1;
- }
+ if (BM_mesh_validate(self->bm) == false) {
+ PyErr_Format(PyExc_ReferenceError,
+ "BMesh used by %.200s has become invalid",
+ Py_TYPE(self)->tp_name);
+ return -1;
+ }
#endif
- return 0;
- }
- else {
- PyErr_Format(PyExc_ReferenceError,
- "BMesh data of type %.200s has been removed",
- Py_TYPE(self)->tp_name);
- return -1;
- }
-}
-
-int bpy_bm_generic_valid_check_source(BMesh *bm_source, const char *error_prefix, void **args, unsigned int args_tot)
-{
- int ret = 0;
-
- while (args_tot--) {
- BPy_BMGeneric *py_bm_elem = args[args_tot];
- if (py_bm_elem) {
-
- BLI_assert(BPy_BMesh_Check(py_bm_elem) ||
- BPy_BMElem_Check(py_bm_elem));
-
- ret = bpy_bm_generic_valid_check(py_bm_elem);
- if (UNLIKELY(ret == -1)) {
- break;
- }
- else {
- if (UNLIKELY(py_bm_elem->bm != bm_source)) {
- /* could give more info here */
- PyErr_Format(PyExc_ValueError,
- "%.200s: BMesh data of type %.200s is from another mesh",
- error_prefix, Py_TYPE(py_bm_elem)->tp_name);
- ret = -1;
- break;
- }
- }
- }
- }
-
- return ret;
+ return 0;
+ }
+ else {
+ PyErr_Format(PyExc_ReferenceError,
+ "BMesh data of type %.200s has been removed",
+ Py_TYPE(self)->tp_name);
+ return -1;
+ }
+}
+
+int bpy_bm_generic_valid_check_source(BMesh *bm_source,
+ const char *error_prefix,
+ void **args,
+ unsigned int args_tot)
+{
+ int ret = 0;
+
+ while (args_tot--) {
+ BPy_BMGeneric *py_bm_elem = args[args_tot];
+ if (py_bm_elem) {
+
+ BLI_assert(BPy_BMesh_Check(py_bm_elem) || BPy_BMElem_Check(py_bm_elem));
+
+ ret = bpy_bm_generic_valid_check(py_bm_elem);
+ if (UNLIKELY(ret == -1)) {
+ break;
+ }
+ else {
+ if (UNLIKELY(py_bm_elem->bm != bm_source)) {
+ /* could give more info here */
+ PyErr_Format(PyExc_ValueError,
+ "%.200s: BMesh data of type %.200s is from another mesh",
+ error_prefix,
+ Py_TYPE(py_bm_elem)->tp_name);
+ ret = -1;
+ break;
+ }
+ }
+ }
+ }
+
+ return ret;
}
void bpy_bm_generic_invalidate(BPy_BMGeneric *self)
{
- self->bm = NULL;
+ self->bm = NULL;
}
/* generic python seq as BMVert/Edge/Face array,
@@ -3892,186 +4132,196 @@ void bpy_bm_generic_invalidate(BPy_BMGeneric *self)
*
* The 'bm_r' value is assigned when empty, and used when set.
*/
-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_size,
- const char htype,
- const bool do_unique_check, const bool do_bm_check,
- const char *error_prefix)
-{
- BMesh *bm = (r_bm && *r_bm) ? *r_bm : NULL;
- PyObject **seq_fast_items = PySequence_Fast_ITEMS(seq_fast);
- const Py_ssize_t seq_len = PySequence_Fast_GET_SIZE(seq_fast);
- Py_ssize_t i, i_last_dirty = PY_SSIZE_T_MAX;
-
- BPy_BMElem *item;
- BMElem **alloc;
-
- *r_size = 0;
-
- if (seq_len < min || seq_len > max) {
- PyErr_Format(PyExc_TypeError,
- "%s: sequence incorrect size, expected [%d - %d], given %d",
- error_prefix, min, max, seq_len);
- return NULL;
- }
-
- /* from now on, use goto */
- alloc = PyMem_MALLOC(seq_len * sizeof(BPy_BMElem **));
-
- for (i = 0; i < seq_len; i++) {
- item = (BPy_BMElem *)seq_fast_items[i];
-
- if (!BPy_BMElem_CheckHType(Py_TYPE(item), htype)) {
- PyErr_Format(PyExc_TypeError,
- "%s: expected %.200s, not '%.200s'",
- error_prefix, BPy_BMElem_StringFromHType(htype), Py_TYPE(item)->tp_name);
- goto err_cleanup;
- }
- else if (!BPY_BM_IS_VALID(item)) {
- PyErr_Format(PyExc_TypeError,
- "%s: %d %s has been removed",
- error_prefix, i, Py_TYPE(item)->tp_name);
- goto err_cleanup;
- }
- /* trick so we can ensure all items have the same mesh,
- * and allows us to pass the 'bm' as NULL. */
- else if (do_bm_check && (bm && bm != item->bm)) {
- PyErr_Format(PyExc_ValueError,
- "%s: %d %s is from another mesh",
- error_prefix, i, BPy_BMElem_StringFromHType(htype));
- goto err_cleanup;
- }
-
- if (bm == NULL) {
- bm = item->bm;
- }
-
- alloc[i] = item->ele;
-
- if (do_unique_check) {
- BM_elem_flag_enable(item->ele, BM_ELEM_INTERNAL_TAG);
- i_last_dirty = i;
- }
- }
-
- if (do_unique_check) {
- /* check for double verts! */
- bool ok = true;
- for (i = 0; i < seq_len; i++) {
- if (UNLIKELY(BM_elem_flag_test(alloc[i], BM_ELEM_INTERNAL_TAG) == false)) {
- ok = false;
- }
-
- /* ensure we don't leave this enabled */
- BM_elem_flag_disable(alloc[i], BM_ELEM_INTERNAL_TAG);
- }
-
- if (ok == false) {
- /* Cleared above. */
- i_last_dirty = PY_SSIZE_T_MAX;
- PyErr_Format(PyExc_ValueError,
- "%s: found the same %.200s used multiple times",
- error_prefix, BPy_BMElem_StringFromHType(htype));
- goto err_cleanup;
- }
- }
-
- *r_size = seq_len;
- if (r_bm) {
- *r_bm = bm;
- }
- return alloc;
+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_size,
+ const char htype,
+ const bool do_unique_check,
+ const bool do_bm_check,
+ const char *error_prefix)
+{
+ BMesh *bm = (r_bm && *r_bm) ? *r_bm : NULL;
+ PyObject **seq_fast_items = PySequence_Fast_ITEMS(seq_fast);
+ const Py_ssize_t seq_len = PySequence_Fast_GET_SIZE(seq_fast);
+ Py_ssize_t i, i_last_dirty = PY_SSIZE_T_MAX;
+
+ BPy_BMElem *item;
+ BMElem **alloc;
+
+ *r_size = 0;
+
+ if (seq_len < min || seq_len > max) {
+ PyErr_Format(PyExc_TypeError,
+ "%s: sequence incorrect size, expected [%d - %d], given %d",
+ error_prefix,
+ min,
+ max,
+ seq_len);
+ return NULL;
+ }
+
+ /* from now on, use goto */
+ alloc = PyMem_MALLOC(seq_len * sizeof(BPy_BMElem **));
+
+ for (i = 0; i < seq_len; i++) {
+ item = (BPy_BMElem *)seq_fast_items[i];
+
+ if (!BPy_BMElem_CheckHType(Py_TYPE(item), htype)) {
+ PyErr_Format(PyExc_TypeError,
+ "%s: expected %.200s, not '%.200s'",
+ error_prefix,
+ BPy_BMElem_StringFromHType(htype),
+ Py_TYPE(item)->tp_name);
+ goto err_cleanup;
+ }
+ else if (!BPY_BM_IS_VALID(item)) {
+ PyErr_Format(
+ PyExc_TypeError, "%s: %d %s has been removed", error_prefix, i, Py_TYPE(item)->tp_name);
+ goto err_cleanup;
+ }
+ /* trick so we can ensure all items have the same mesh,
+ * and allows us to pass the 'bm' as NULL. */
+ else if (do_bm_check && (bm && bm != item->bm)) {
+ PyErr_Format(PyExc_ValueError,
+ "%s: %d %s is from another mesh",
+ error_prefix,
+ i,
+ BPy_BMElem_StringFromHType(htype));
+ goto err_cleanup;
+ }
+
+ if (bm == NULL) {
+ bm = item->bm;
+ }
+
+ alloc[i] = item->ele;
+
+ if (do_unique_check) {
+ BM_elem_flag_enable(item->ele, BM_ELEM_INTERNAL_TAG);
+ i_last_dirty = i;
+ }
+ }
+
+ if (do_unique_check) {
+ /* check for double verts! */
+ bool ok = true;
+ for (i = 0; i < seq_len; i++) {
+ if (UNLIKELY(BM_elem_flag_test(alloc[i], BM_ELEM_INTERNAL_TAG) == false)) {
+ ok = false;
+ }
+
+ /* ensure we don't leave this enabled */
+ BM_elem_flag_disable(alloc[i], BM_ELEM_INTERNAL_TAG);
+ }
+
+ if (ok == false) {
+ /* Cleared above. */
+ i_last_dirty = PY_SSIZE_T_MAX;
+ PyErr_Format(PyExc_ValueError,
+ "%s: found the same %.200s used multiple times",
+ error_prefix,
+ BPy_BMElem_StringFromHType(htype));
+ goto err_cleanup;
+ }
+ }
+
+ *r_size = seq_len;
+ if (r_bm) {
+ *r_bm = bm;
+ }
+ return alloc;
err_cleanup:
- if (do_unique_check && (i_last_dirty != PY_SSIZE_T_MAX)) {
- for (i = 0; i <= i_last_dirty; i++) {
- BM_elem_flag_disable(alloc[i], BM_ELEM_INTERNAL_TAG);
- }
- }
- PyMem_FREE(alloc);
- return NULL;
-
+ if (do_unique_check && (i_last_dirty != PY_SSIZE_T_MAX)) {
+ for (i = 0; i <= i_last_dirty; i++) {
+ BM_elem_flag_disable(alloc[i], BM_ELEM_INTERNAL_TAG);
+ }
+ }
+ PyMem_FREE(alloc);
+ return NULL;
}
-void *BPy_BMElem_PySeq_As_Array(
- BMesh **r_bm, PyObject *seq, Py_ssize_t min, Py_ssize_t max, Py_ssize_t *r_size,
- const char htype,
- const bool do_unique_check, const bool do_bm_check,
- 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_size,
+ const char htype,
+ const bool do_unique_check,
+ const bool do_bm_check,
+ const char *error_prefix)
{
- PyObject *seq_fast;
- PyObject *ret;
+ PyObject *seq_fast;
+ PyObject *ret;
- if (!(seq_fast = PySequence_Fast(seq, error_prefix))) {
- return NULL;
- }
+ if (!(seq_fast = PySequence_Fast(seq, error_prefix))) {
+ return NULL;
+ }
- ret = BPy_BMElem_PySeq_As_Array_FAST(
- r_bm, seq_fast, min, max, r_size,
- htype,
- do_unique_check, do_bm_check,
- error_prefix);
+ ret = BPy_BMElem_PySeq_As_Array_FAST(
+ r_bm, seq_fast, min, max, r_size, htype, do_unique_check, do_bm_check, error_prefix);
- Py_DECREF(seq_fast);
- return ret;
+ Py_DECREF(seq_fast);
+ return ret;
}
-
PyObject *BPy_BMElem_Array_As_Tuple(BMesh *bm, BMHeader **elem, Py_ssize_t elem_len)
{
- Py_ssize_t i;
- PyObject *ret = PyTuple_New(elem_len);
- for (i = 0; i < elem_len; i++) {
- PyTuple_SET_ITEM(ret, i, BPy_BMElem_CreatePyObject(bm, elem[i]));
- }
- return ret;
+ Py_ssize_t i;
+ PyObject *ret = PyTuple_New(elem_len);
+ for (i = 0; i < elem_len; i++) {
+ PyTuple_SET_ITEM(ret, i, BPy_BMElem_CreatePyObject(bm, elem[i]));
+ }
+ return ret;
}
PyObject *BPy_BMVert_Array_As_Tuple(BMesh *bm, BMVert **elem, Py_ssize_t elem_len)
{
- Py_ssize_t i;
- PyObject *ret = PyTuple_New(elem_len);
- for (i = 0; i < elem_len; i++) {
- PyTuple_SET_ITEM(ret, i, BPy_BMVert_CreatePyObject(bm, elem[i]));
- }
- return ret;
+ Py_ssize_t i;
+ PyObject *ret = PyTuple_New(elem_len);
+ for (i = 0; i < elem_len; i++) {
+ PyTuple_SET_ITEM(ret, i, BPy_BMVert_CreatePyObject(bm, elem[i]));
+ }
+ return ret;
}
PyObject *BPy_BMEdge_Array_As_Tuple(BMesh *bm, BMEdge **elem, Py_ssize_t elem_len)
{
- Py_ssize_t i;
- PyObject *ret = PyTuple_New(elem_len);
- for (i = 0; i < elem_len; i++) {
- PyTuple_SET_ITEM(ret, i, BPy_BMEdge_CreatePyObject(bm, elem[i]));
- }
+ Py_ssize_t i;
+ PyObject *ret = PyTuple_New(elem_len);
+ for (i = 0; i < elem_len; i++) {
+ PyTuple_SET_ITEM(ret, i, BPy_BMEdge_CreatePyObject(bm, elem[i]));
+ }
- return ret;
+ return ret;
}
PyObject *BPy_BMFace_Array_As_Tuple(BMesh *bm, BMFace **elem, Py_ssize_t elem_len)
{
- Py_ssize_t i;
- PyObject *ret = PyTuple_New(elem_len);
- for (i = 0; i < elem_len; i++) {
- PyTuple_SET_ITEM(ret, i, BPy_BMFace_CreatePyObject(bm, elem[i]));
- }
+ Py_ssize_t i;
+ PyObject *ret = PyTuple_New(elem_len);
+ for (i = 0; i < elem_len; i++) {
+ PyTuple_SET_ITEM(ret, i, BPy_BMFace_CreatePyObject(bm, elem[i]));
+ }
- return ret;
+ return ret;
}
PyObject *BPy_BMLoop_Array_As_Tuple(BMesh *bm, BMLoop **elem, Py_ssize_t elem_len)
{
- Py_ssize_t i;
- PyObject *ret = PyTuple_New(elem_len);
- for (i = 0; i < elem_len; i++) {
- PyTuple_SET_ITEM(ret, i, BPy_BMLoop_CreatePyObject(bm, elem[i]));
- }
+ Py_ssize_t i;
+ PyObject *ret = PyTuple_New(elem_len);
+ for (i = 0; i < elem_len; i++) {
+ PyTuple_SET_ITEM(ret, i, BPy_BMLoop_CreatePyObject(bm, elem[i]));
+ }
- return ret;
+ return ret;
}
int BPy_BMElem_CheckHType(PyTypeObject *type, const char htype)
{
- return (((htype & BM_VERT) && (type == &BPy_BMVert_Type)) ||
- ((htype & BM_EDGE) && (type == &BPy_BMEdge_Type)) ||
- ((htype & BM_FACE) && (type == &BPy_BMFace_Type)) ||
- ((htype & BM_LOOP) && (type == &BPy_BMLoop_Type)));
+ return (((htype & BM_VERT) && (type == &BPy_BMVert_Type)) ||
+ ((htype & BM_EDGE) && (type == &BPy_BMEdge_Type)) ||
+ ((htype & BM_FACE) && (type == &BPy_BMFace_Type)) ||
+ ((htype & BM_LOOP) && (type == &BPy_BMLoop_Type)));
}
/**
@@ -4081,32 +4331,39 @@ int BPy_BMElem_CheckHType(PyTypeObject *type, const char htype)
*/
char *BPy_BMElem_StringFromHType_ex(const char htype, char ret[32])
{
- /* zero to ensure string is always NULL terminated */
- char *ret_ptr = ret;
- if (htype & BM_VERT) { ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMVert_Type.tp_name); }
- if (htype & BM_EDGE) { ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMEdge_Type.tp_name); }
- if (htype & BM_FACE) { ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMFace_Type.tp_name); }
- if (htype & BM_LOOP) { ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMLoop_Type.tp_name); }
- ret[0] = '(';
- *ret_ptr++ = ')';
- *ret_ptr = '\0';
- return ret;
+ /* zero to ensure string is always NULL terminated */
+ char *ret_ptr = ret;
+ if (htype & BM_VERT) {
+ ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMVert_Type.tp_name);
+ }
+ if (htype & BM_EDGE) {
+ ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMEdge_Type.tp_name);
+ }
+ if (htype & BM_FACE) {
+ ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMFace_Type.tp_name);
+ }
+ if (htype & BM_LOOP) {
+ ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMLoop_Type.tp_name);
+ }
+ ret[0] = '(';
+ *ret_ptr++ = ')';
+ *ret_ptr = '\0';
+ return ret;
}
char *BPy_BMElem_StringFromHType(const char htype)
{
- /* zero to ensure string is always NULL terminated */
- static char ret[32];
- return BPy_BMElem_StringFromHType_ex(htype, ret);
+ /* zero to ensure string is always NULL terminated */
+ static char ret[32];
+ return BPy_BMElem_StringFromHType_ex(htype, ret);
}
-
/* -------------------------------------------------------------------- */
/* keep at bottom */
/* this function is called on free, it should stay quite fast */
static void bm_dealloc_editmode_warn(BPy_BMesh *self)
{
- if (self->flag & BPY_BMFLAG_IS_WRAPPED) {
- /* currently nop - this works without warnings now */
- }
+ if (self->flag & BPY_BMFLAG_IS_WRAPPED) {
+ /* currently nop - this works without warnings now */
+ }
}
diff --git a/source/blender/python/bmesh/bmesh_py_types.h b/source/blender/python/bmesh/bmesh_py_types.h
index 80646b7eb16..460e7f82222 100644
--- a/source/blender/python/bmesh/bmesh_py_types.h
+++ b/source/blender/python/bmesh/bmesh_py_types.h
@@ -38,65 +38,57 @@ extern PyTypeObject BPy_BMLoopSeq_Type;
extern PyTypeObject BPy_BMIter_Type;
-#define BPy_BMesh_Check(v) (Py_TYPE(v) == &BPy_BMesh_Type)
-#define BPy_BMVert_Check(v) (Py_TYPE(v) == &BPy_BMVert_Type)
-#define BPy_BMEdge_Check(v) (Py_TYPE(v) == &BPy_BMEdge_Type)
-#define BPy_BMFace_Check(v) (Py_TYPE(v) == &BPy_BMFace_Type)
-#define BPy_BMLoop_Check(v) (Py_TYPE(v) == &BPy_BMLoop_Type)
-#define BPy_BMElemSeq_Check(v) (Py_TYPE(v) == &BPy_BMElemSeq_Type)
-#define BPy_BMVertSeq_Check(v) (Py_TYPE(v) == &BPy_BMVertSeq_Type)
-#define BPy_BMEdgeSeq_Check(v) (Py_TYPE(v) == &BPy_BMEdgeSeq_Type)
-#define BPy_BMFaceSeq_Check(v) (Py_TYPE(v) == &BPy_BMFaceSeq_Type)
-#define BPy_BMLoopSeq_Check(v) (Py_TYPE(v) == &BPy_BMLoopSeq_Type)
-#define BPy_BMIter_Check(v) (Py_TYPE(v) == &BPy_BMIter_Type)
+#define BPy_BMesh_Check(v) (Py_TYPE(v) == &BPy_BMesh_Type)
+#define BPy_BMVert_Check(v) (Py_TYPE(v) == &BPy_BMVert_Type)
+#define BPy_BMEdge_Check(v) (Py_TYPE(v) == &BPy_BMEdge_Type)
+#define BPy_BMFace_Check(v) (Py_TYPE(v) == &BPy_BMFace_Type)
+#define BPy_BMLoop_Check(v) (Py_TYPE(v) == &BPy_BMLoop_Type)
+#define BPy_BMElemSeq_Check(v) (Py_TYPE(v) == &BPy_BMElemSeq_Type)
+#define BPy_BMVertSeq_Check(v) (Py_TYPE(v) == &BPy_BMVertSeq_Type)
+#define BPy_BMEdgeSeq_Check(v) (Py_TYPE(v) == &BPy_BMEdgeSeq_Type)
+#define BPy_BMFaceSeq_Check(v) (Py_TYPE(v) == &BPy_BMFaceSeq_Type)
+#define BPy_BMLoopSeq_Check(v) (Py_TYPE(v) == &BPy_BMLoopSeq_Type)
+#define BPy_BMIter_Check(v) (Py_TYPE(v) == &BPy_BMIter_Type)
/* trick since we know they share a hash function */
-#define BPy_BMElem_Check(v) (Py_TYPE(v)->tp_hash == BPy_BMVert_Type.tp_hash)
+#define BPy_BMElem_Check(v) (Py_TYPE(v)->tp_hash == BPy_BMVert_Type.tp_hash)
/* cast from _any_ bmesh type - they all have BMesh first */
typedef struct BPy_BMGeneric {
- PyObject_VAR_HEAD
- struct BMesh *bm; /* keep first */
+ PyObject_VAR_HEAD struct BMesh *bm; /* keep first */
} BPy_BMGeneric;
/* BPy_BMVert/BPy_BMEdge/BPy_BMFace/BPy_BMLoop can cast to this */
typedef struct BPy_BMElem {
- PyObject_VAR_HEAD
- struct BMesh *bm; /* keep first */
- struct BMElem *ele;
+ PyObject_VAR_HEAD struct BMesh *bm; /* keep first */
+ struct BMElem *ele;
} BPy_BMElem;
typedef struct BPy_BMesh {
- PyObject_VAR_HEAD
- struct BMesh *bm; /* keep first */
- int flag;
+ PyObject_VAR_HEAD struct BMesh *bm; /* keep first */
+ int flag;
} BPy_BMesh;
/* element types */
typedef struct BPy_BMVert {
- PyObject_VAR_HEAD
- struct BMesh *bm; /* keep first */
- struct BMVert *v;
+ PyObject_VAR_HEAD struct BMesh *bm; /* keep first */
+ struct BMVert *v;
} BPy_BMVert;
typedef struct BPy_BMEdge {
- PyObject_VAR_HEAD
- struct BMesh *bm; /* keep first */
- struct BMEdge *e;
+ PyObject_VAR_HEAD struct BMesh *bm; /* keep first */
+ struct BMEdge *e;
} BPy_BMEdge;
typedef struct BPy_BMFace {
- PyObject_VAR_HEAD
- struct BMesh *bm; /* keep first */
- struct BMFace *f;
+ PyObject_VAR_HEAD struct BMesh *bm; /* keep first */
+ struct BMFace *f;
} BPy_BMFace;
typedef struct BPy_BMLoop {
- PyObject_VAR_HEAD
- struct BMesh *bm; /* keep first */
- struct BMLoop *l;
+ PyObject_VAR_HEAD struct BMesh *bm; /* keep first */
+ struct BMLoop *l;
} BPy_BMLoop;
-
/* iterators */
/* used for ...
@@ -107,26 +99,24 @@ typedef struct BPy_BMLoop {
* - BPy_BMLoopSeq_Type
*/
typedef struct BPy_BMElemSeq {
- PyObject_VAR_HEAD
- struct BMesh *bm; /* keep first */
+ PyObject_VAR_HEAD struct BMesh *bm; /* keep first */
- /* if this is a sequence on an existing element,
- * loops of faces for eg.
- * If this variable is set, it will be used */
+ /* if this is a sequence on an existing element,
+ * loops of faces for eg.
+ * If this variable is set, it will be used */
- /* we hold a reference to this.
- * check in case the owner becomes invalid on access */
- /* TODO - make this a GC'd object!, will function OK without this though */
- BPy_BMElem *py_ele;
+ /* we hold a reference to this.
+ * check in case the owner becomes invalid on access */
+ /* TODO - make this a GC'd object!, will function OK without this though */
+ BPy_BMElem *py_ele;
- /* iterator type */
- short itype;
+ /* iterator type */
+ short itype;
} BPy_BMElemSeq;
typedef struct BPy_BMIter {
- PyObject_VAR_HEAD
- struct BMesh *bm; /* keep first */
- BMIter iter;
+ PyObject_VAR_HEAD struct BMesh *bm; /* keep first */
+ BMIter iter;
} BPy_BMIter;
void BPy_BM_init_types(void);
@@ -134,8 +124,8 @@ void BPy_BM_init_types(void);
PyObject *BPyInit_bmesh_types(void);
enum {
- BPY_BMFLAG_NOP = 0, /* do nothing */
- BPY_BMFLAG_IS_WRAPPED = 1, /* the mesh is owned by editmode */
+ BPY_BMFLAG_NOP = 0, /* do nothing */
+ BPY_BMFLAG_IS_WRAPPED = 1, /* the mesh is owned by editmode */
};
PyObject *BPy_BMesh_CreatePyObject(BMesh *bm, int flag);
@@ -150,18 +140,27 @@ PyObject *BPy_BMFaceSeq_CreatePyObject(BMesh *bm);
PyObject *BPy_BMLoopSeq_CreatePyObject(BMesh *bm);
PyObject *BPy_BMIter_CreatePyObject(BMesh *bm);
-PyObject *BPy_BMElem_CreatePyObject(BMesh *bm, BMHeader *ele); /* just checks type and creates v/e/f/l */
-
-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_size,
- const char htype,
- const bool do_unique_check, const bool do_bm_check,
- 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_size,
- const char htype,
- const bool do_unique_check, const bool do_bm_check,
- const char *error_prefix);
+PyObject *BPy_BMElem_CreatePyObject(BMesh *bm,
+ BMHeader *ele); /* just checks type and creates v/e/f/l */
+
+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_size,
+ const char htype,
+ const bool do_unique_check,
+ const bool do_bm_check,
+ 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_size,
+ const char htype,
+ const bool do_unique_check,
+ const bool do_bm_check,
+ const char *error_prefix);
PyObject *BPy_BMElem_Array_As_Tuple(BMesh *bm, BMHeader **elem, Py_ssize_t elem_len);
PyObject *BPy_BMVert_Array_As_Tuple(BMesh *bm, BMVert **elem, Py_ssize_t elem_len);
@@ -169,47 +168,58 @@ PyObject *BPy_BMEdge_Array_As_Tuple(BMesh *bm, BMEdge **elem, Py_ssize_t elem_le
PyObject *BPy_BMFace_Array_As_Tuple(BMesh *bm, BMFace **elem, Py_ssize_t elem_len);
PyObject *BPy_BMLoop_Array_As_Tuple(BMesh *bm, BMLoop **elem, Py_ssize_t elem_len);
-int BPy_BMElem_CheckHType(PyTypeObject *type, const char htype);
-char *BPy_BMElem_StringFromHType_ex(const char htype, char ret[32]);
-char *BPy_BMElem_StringFromHType(const char htype);
+int BPy_BMElem_CheckHType(PyTypeObject *type, const char htype);
+char *BPy_BMElem_StringFromHType_ex(const char htype, char ret[32]);
+char *BPy_BMElem_StringFromHType(const char htype);
// void bpy_bm_generic_invalidate(BPy_BMGeneric *self);
-int bpy_bm_generic_valid_check(BPy_BMGeneric *self);
-int bpy_bm_generic_valid_check_source(BMesh *bm_source, const char *error_prefix, void **args, unsigned int args_n) ATTR_NONNULL(1, 2);
+int bpy_bm_generic_valid_check(BPy_BMGeneric *self);
+int bpy_bm_generic_valid_check_source(BMesh *bm_source,
+ const char *error_prefix,
+ void **args,
+ unsigned int args_n) ATTR_NONNULL(1, 2);
#define BPY_BM_CHECK_OBJ(obj) \
- if (UNLIKELY(bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1)) { return NULL; } (void)0
+ if (UNLIKELY(bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1)) { \
+ return NULL; \
+ } \
+ (void)0
#define BPY_BM_CHECK_INT(obj) \
- if (UNLIKELY(bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1)) { return -1; } (void)0
+ if (UNLIKELY(bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1)) { \
+ return -1; \
+ } \
+ (void)0
/* macros like BPY_BM_CHECK_OBJ/BPY_BM_CHECK_INT that ensure we're from the right BMesh */
-#define BPY_BM_CHECK_SOURCE_OBJ(bm, errmsg, ...) { \
- void *_args[] = {__VA_ARGS__}; \
- if (UNLIKELY(bpy_bm_generic_valid_check_source(bm, errmsg, _args, ARRAY_SIZE(_args)) == -1)) { \
- return NULL; \
- } \
-} (void)0
-#define BPY_BM_CHECK_SOURCE_INT(bm, errmsg, ...) { \
- void *_args[] = {__VA_ARGS__}; \
- if (UNLIKELY(bpy_bm_generic_valid_check_source(bm, errmsg, _args, ARRAY_SIZE(_args)) == -1)) { \
- return -1; \
- } \
-} (void)0
+#define BPY_BM_CHECK_SOURCE_OBJ(bm, errmsg, ...) \
+ { \
+ void *_args[] = {__VA_ARGS__}; \
+ if (UNLIKELY(bpy_bm_generic_valid_check_source(bm, errmsg, _args, ARRAY_SIZE(_args)) == \
+ -1)) { \
+ return NULL; \
+ } \
+ } \
+ (void)0
+#define BPY_BM_CHECK_SOURCE_INT(bm, errmsg, ...) \
+ { \
+ void *_args[] = {__VA_ARGS__}; \
+ if (UNLIKELY(bpy_bm_generic_valid_check_source(bm, errmsg, _args, ARRAY_SIZE(_args)) == \
+ -1)) { \
+ return -1; \
+ } \
+ } \
+ (void)0
#define BPY_BM_IS_VALID(obj) (LIKELY((obj)->bm != NULL))
-#define BM_ITER_BPY_BM_SEQ(ele, iter, bpy_bmelemseq) \
- for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new( \
- iter, \
- (bpy_bmelemseq)->bm, \
- (bpy_bmelemseq)->itype, \
- (bpy_bmelemseq)->py_ele ? \
- ((BPy_BMElem *)(bpy_bmelemseq)->py_ele)->ele : \
- NULL \
- ); \
- ele; \
- BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_step(iter))
-
+#define BM_ITER_BPY_BM_SEQ(ele, iter, bpy_bmelemseq) \
+ for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new( \
+ iter, \
+ (bpy_bmelemseq)->bm, \
+ (bpy_bmelemseq)->itype, \
+ (bpy_bmelemseq)->py_ele ? ((BPy_BMElem *)(bpy_bmelemseq)->py_ele)->ele : NULL); \
+ ele; \
+ BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_step(iter))
#ifdef __PY_CAPI_UTILS_H__
struct PyC_FlagSet;
diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index abe146f2581..56c25edb7e4 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -45,29 +45,32 @@
static CustomData *bpy_bm_customdata_get(BMesh *bm, char htype)
{
- switch (htype) {
- case BM_VERT: return &bm->vdata;
- case BM_EDGE: return &bm->edata;
- case BM_FACE: return &bm->pdata;
- case BM_LOOP: return &bm->ldata;
- }
-
- BLI_assert(0);
- return NULL;
+ switch (htype) {
+ case BM_VERT:
+ return &bm->vdata;
+ case BM_EDGE:
+ return &bm->edata;
+ case BM_FACE:
+ return &bm->pdata;
+ case BM_LOOP:
+ return &bm->ldata;
+ }
+
+ BLI_assert(0);
+ return NULL;
}
static CustomDataLayer *bpy_bmlayeritem_get(BPy_BMLayerItem *self)
{
- CustomData *data = bpy_bm_customdata_get(self->bm, self->htype);
- const int index_absolute = CustomData_get_layer_index_n(data, self->type, self->index);
- if (index_absolute != -1) {
- return &data->layers[index_absolute];
- }
- else {
- PyErr_SetString(PyExc_RuntimeError,
- "layer has become invalid");
- return NULL;
- }
+ CustomData *data = bpy_bm_customdata_get(self->bm, self->htype);
+ const int index_absolute = CustomData_get_layer_index_n(data, self->type, self->index);
+ if (index_absolute != -1) {
+ return &data->layers[index_absolute];
+ }
+ else {
+ PyErr_SetString(PyExc_RuntimeError, "layer has become invalid");
+ return NULL;
+ }
}
/* py-type definitions
@@ -79,180 +82,273 @@ static CustomDataLayer *bpy_bmlayeritem_get(BPy_BMLayerItem *self)
/* used for many different types */
PyDoc_STRVAR(bpy_bmlayeraccess_collection__float_doc,
-"Generic float custom-data layer.\n\ntype: :class:`BMLayerCollection`"
-);
+ "Generic float custom-data layer.\n\ntype: :class:`BMLayerCollection`");
PyDoc_STRVAR(bpy_bmlayeraccess_collection__int_doc,
-"Generic int custom-data layer.\n\ntype: :class:`BMLayerCollection`"
-);
+ "Generic int custom-data layer.\n\ntype: :class:`BMLayerCollection`");
PyDoc_STRVAR(bpy_bmlayeraccess_collection__string_doc,
-"Generic string custom-data layer (exposed as bytes, 255 max length).\n\ntype: :class:`BMLayerCollection`"
-);
+ "Generic string custom-data layer (exposed as bytes, 255 max length).\n\ntype: "
+ ":class:`BMLayerCollection`");
PyDoc_STRVAR(bpy_bmlayeraccess_collection__deform_doc,
-"Vertex deform weight :class:`BMDeformVert` (TODO).\n\ntype: :class:`BMLayerCollection`" // TYPE DOESN'T EXIST YET
-);
-PyDoc_STRVAR(bpy_bmlayeraccess_collection__shape_doc,
-"Vertex shapekey absolute location (as a 3D Vector).\n\n:type: :class:`BMLayerCollection`"
+ "Vertex deform weight :class:`BMDeformVert` (TODO).\n\ntype: "
+ ":class:`BMLayerCollection`" // TYPE DOESN'T EXIST YET
);
+PyDoc_STRVAR(
+ bpy_bmlayeraccess_collection__shape_doc,
+ "Vertex shapekey absolute location (as a 3D Vector).\n\n:type: :class:`BMLayerCollection`");
PyDoc_STRVAR(bpy_bmlayeraccess_collection__bevel_weight_doc,
-"Bevel weight float in [0 - 1].\n\n:type: :class:`BMLayerCollection`"
-);
+ "Bevel weight float in [0 - 1].\n\n:type: :class:`BMLayerCollection`");
PyDoc_STRVAR(bpy_bmlayeraccess_collection__crease_doc,
-"Edge crease for subsurf - float in [0 - 1].\n\n:type: :class:`BMLayerCollection`"
-);
-PyDoc_STRVAR(bpy_bmlayeraccess_collection__uv_doc,
-"Accessor for :class:`BMLoopUV` UV (as a 2D Vector).\n\ntype: :class:`BMLayerCollection`"
-);
+ "Edge crease for subsurf - float in [0 - 1].\n\n:type: :class:`BMLayerCollection`");
+PyDoc_STRVAR(
+ bpy_bmlayeraccess_collection__uv_doc,
+ "Accessor for :class:`BMLoopUV` UV (as a 2D Vector).\n\ntype: :class:`BMLayerCollection`");
PyDoc_STRVAR(bpy_bmlayeraccess_collection__color_doc,
-"Accessor for vertex color layer.\n\ntype: :class:`BMLayerCollection`"
-);
+ "Accessor for vertex color layer.\n\ntype: :class:`BMLayerCollection`");
PyDoc_STRVAR(bpy_bmlayeraccess_collection__skin_doc,
-"Accessor for skin layer.\n\ntype: :class:`BMLayerCollection`"
-);
+ "Accessor for skin layer.\n\ntype: :class:`BMLayerCollection`");
PyDoc_STRVAR(bpy_bmlayeraccess_collection__paint_mask_doc,
-"Accessor for paint mask layer.\n\ntype: :class:`BMLayerCollection`"
-);
+ "Accessor for paint mask layer.\n\ntype: :class:`BMLayerCollection`");
PyDoc_STRVAR(bpy_bmlayeraccess_collection__face_map_doc,
-"FaceMap custom-data layer.\n\ntype: :class:`BMLayerCollection`"
-);
+ "FaceMap custom-data layer.\n\ntype: :class:`BMLayerCollection`");
#ifdef WITH_FREESTYLE
PyDoc_STRVAR(bpy_bmlayeraccess_collection__freestyle_edge_doc,
-"Accessor for Freestyle edge layer.\n\ntype: :class:`BMLayerCollection`"
-);
+ "Accessor for Freestyle edge layer.\n\ntype: :class:`BMLayerCollection`");
PyDoc_STRVAR(bpy_bmlayeraccess_collection__freestyle_face_doc,
-"Accessor for Freestyle face layer.\n\ntype: :class:`BMLayerCollection`"
-);
+ "Accessor for Freestyle face layer.\n\ntype: :class:`BMLayerCollection`");
#endif
static PyObject *bpy_bmlayeraccess_collection_get(BPy_BMLayerAccess *self, void *flag)
{
- const int type = (int)POINTER_AS_INT(flag);
+ const int type = (int)POINTER_AS_INT(flag);
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- return BPy_BMLayerCollection_CreatePyObject(self->bm, self->htype, type);
+ return BPy_BMLayerCollection_CreatePyObject(self->bm, self->htype, type);
}
-
PyDoc_STRVAR(bpy_bmlayercollection_active_doc,
-"The active layer of this type (read-only).\n\n:type: :class:`BMLayerItem`"
-);
+ "The active layer of this type (read-only).\n\n:type: :class:`BMLayerItem`");
static PyObject *bpy_bmlayercollection_active_get(BPy_BMLayerItem *self, void *UNUSED(flag))
{
- CustomData *data;
- int index;
+ CustomData *data;
+ int index;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- data = bpy_bm_customdata_get(self->bm, self->htype);
- index = CustomData_get_active_layer(data, self->type); /* type relative */
+ data = bpy_bm_customdata_get(self->bm, self->htype);
+ index = CustomData_get_active_layer(data, self->type); /* type relative */
- if (index != -1) {
- return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
- }
- else {
- Py_RETURN_NONE;
- }
+ if (index != -1) {
+ return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
+ }
+ else {
+ Py_RETURN_NONE;
+ }
}
-
-PyDoc_STRVAR(bpy_bmlayercollection_is_singleton_doc,
-"True if there can exists only one layer of this type (read-only).\n\n:type: boolean"
-);
+PyDoc_STRVAR(
+ bpy_bmlayercollection_is_singleton_doc,
+ "True if there can exists only one layer of this type (read-only).\n\n:type: boolean");
static PyObject *bpy_bmlayercollection_is_singleton_get(BPy_BMLayerItem *self, void *UNUSED(flag))
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- return PyBool_FromLong(CustomData_layertype_is_singleton(self->type));
+ return PyBool_FromLong(CustomData_layertype_is_singleton(self->type));
}
PyDoc_STRVAR(bpy_bmlayercollection_name_doc,
-"The layers unique name (read-only).\n\n:type: string"
-);
+ "The layers unique name (read-only).\n\n:type: string");
static PyObject *bpy_bmlayeritem_name_get(BPy_BMLayerItem *self, void *UNUSED(flag))
{
- CustomDataLayer *layer;
+ CustomDataLayer *layer;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- layer = bpy_bmlayeritem_get(self);
- if (layer) {
- return PyUnicode_FromString(layer->name);
- }
- else {
- return NULL;
- }
+ layer = bpy_bmlayeritem_get(self);
+ if (layer) {
+ return PyUnicode_FromString(layer->name);
+ }
+ else {
+ return NULL;
+ }
}
static PyGetSetDef bpy_bmlayeraccess_vert_getseters[] = {
- {(char *)"deform", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__deform_doc, (void *)CD_MDEFORMVERT},
-
- {(char *)"float", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__float_doc, (void *)CD_PROP_FLT},
- {(char *)"int", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__int_doc, (void *)CD_PROP_INT},
- {(char *)"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__string_doc, (void *)CD_PROP_STR},
-
- {(char *)"shape", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__shape_doc, (void *)CD_SHAPEKEY},
- {(char *)"bevel_weight", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__bevel_weight_doc, (void *)CD_BWEIGHT},
- {(char *)"skin", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__skin_doc, (void *)CD_MVERT_SKIN},
- {(char *)"paint_mask", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__paint_mask_doc, (void *)CD_PAINT_MASK},
-
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ {(char *)"deform",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__deform_doc,
+ (void *)CD_MDEFORMVERT},
+
+ {(char *)"float",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__float_doc,
+ (void *)CD_PROP_FLT},
+ {(char *)"int",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__int_doc,
+ (void *)CD_PROP_INT},
+ {(char *)"string",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__string_doc,
+ (void *)CD_PROP_STR},
+
+ {(char *)"shape",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__shape_doc,
+ (void *)CD_SHAPEKEY},
+ {(char *)"bevel_weight",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__bevel_weight_doc,
+ (void *)CD_BWEIGHT},
+ {(char *)"skin",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__skin_doc,
+ (void *)CD_MVERT_SKIN},
+ {(char *)"paint_mask",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__paint_mask_doc,
+ (void *)CD_PAINT_MASK},
+
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyGetSetDef bpy_bmlayeraccess_edge_getseters[] = {
- {(char *)"float", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__float_doc, (void *)CD_PROP_FLT},
- {(char *)"int", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__int_doc, (void *)CD_PROP_INT},
- {(char *)"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__string_doc, (void *)CD_PROP_STR},
-
- {(char *)"bevel_weight", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__bevel_weight_doc, (void *)CD_BWEIGHT},
- {(char *)"crease", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__crease_doc, (void *)CD_CREASE},
+ {(char *)"float",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__float_doc,
+ (void *)CD_PROP_FLT},
+ {(char *)"int",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__int_doc,
+ (void *)CD_PROP_INT},
+ {(char *)"string",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__string_doc,
+ (void *)CD_PROP_STR},
+
+ {(char *)"bevel_weight",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__bevel_weight_doc,
+ (void *)CD_BWEIGHT},
+ {(char *)"crease",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__crease_doc,
+ (void *)CD_CREASE},
#ifdef WITH_FREESTYLE
- {(char *)"freestyle", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__freestyle_edge_doc, (void *)CD_FREESTYLE_EDGE},
+ {(char *)"freestyle",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__freestyle_edge_doc,
+ (void *)CD_FREESTYLE_EDGE},
#endif
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyGetSetDef bpy_bmlayeraccess_face_getseters[] = {
- {(char *)"float", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__float_doc, (void *)CD_PROP_FLT},
- {(char *)"int", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__int_doc, (void *)CD_PROP_INT},
- {(char *)"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__string_doc, (void *)CD_PROP_STR},
- {(char *)"face_map", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__face_map_doc, (void *)CD_FACEMAP},
+ {(char *)"float",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__float_doc,
+ (void *)CD_PROP_FLT},
+ {(char *)"int",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__int_doc,
+ (void *)CD_PROP_INT},
+ {(char *)"string",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__string_doc,
+ (void *)CD_PROP_STR},
+ {(char *)"face_map",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__face_map_doc,
+ (void *)CD_FACEMAP},
#ifdef WITH_FREESTYLE
- {(char *)"freestyle", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__freestyle_face_doc, (void *)CD_FREESTYLE_FACE},
+ {(char *)"freestyle",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__freestyle_face_doc,
+ (void *)CD_FREESTYLE_FACE},
#endif
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyGetSetDef bpy_bmlayeraccess_loop_getseters[] = {
- {(char *)"float", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__float_doc, (void *)CD_PROP_FLT},
- {(char *)"int", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__int_doc, (void *)CD_PROP_INT},
- {(char *)"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__string_doc, (void *)CD_PROP_STR},
-
- {(char *)"uv", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__uv_doc, (void *)CD_MLOOPUV},
- {(char *)"color", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__color_doc, (void *)CD_MLOOPCOL},
-
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ {(char *)"float",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__float_doc,
+ (void *)CD_PROP_FLT},
+ {(char *)"int",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__int_doc,
+ (void *)CD_PROP_INT},
+ {(char *)"string",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__string_doc,
+ (void *)CD_PROP_STR},
+
+ {(char *)"uv",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__uv_doc,
+ (void *)CD_MLOOPUV},
+ {(char *)"color",
+ (getter)bpy_bmlayeraccess_collection_get,
+ (setter)NULL,
+ (char *)bpy_bmlayeraccess_collection__color_doc,
+ (void *)CD_MLOOPCOL},
+
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
-
static PyGetSetDef bpy_bmlayercollection_getseters[] = {
- /* BMESH_TODO, make writeable */
- {(char *)"active", (getter)bpy_bmlayercollection_active_get, (setter)NULL, (char *)bpy_bmlayercollection_active_doc, NULL},
- {(char *)"is_singleton", (getter)bpy_bmlayercollection_is_singleton_get, (setter)NULL, (char *)bpy_bmlayercollection_is_singleton_doc, NULL},
-
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ /* BMESH_TODO, make writeable */
+ {(char *)"active",
+ (getter)bpy_bmlayercollection_active_get,
+ (setter)NULL,
+ (char *)bpy_bmlayercollection_active_doc,
+ NULL},
+ {(char *)"is_singleton",
+ (getter)bpy_bmlayercollection_is_singleton_get,
+ (setter)NULL,
+ (char *)bpy_bmlayercollection_is_singleton_doc,
+ NULL},
+
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyGetSetDef bpy_bmlayeritem_getseters[] = {
- /* BMESH_TODO, make writeable */
- {(char *)"name", (getter)bpy_bmlayeritem_name_get, (setter)NULL, (char *)bpy_bmlayercollection_name_doc, NULL},
-
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ /* BMESH_TODO, make writeable */
+ {(char *)"name",
+ (getter)bpy_bmlayeritem_name_get,
+ (setter)NULL,
+ (char *)bpy_bmlayercollection_name_doc,
+ NULL},
+
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
-
/* Methods
* ======= */
@@ -260,318 +356,310 @@ static PyGetSetDef bpy_bmlayeritem_getseters[] = {
* ----------------- */
PyDoc_STRVAR(bpy_bmlayeritem_copy_from_doc,
-".. method:: copy_from(other)\n"
-"\n"
-" Return a copy of the layer\n"
-"\n"
-" :arg other: Another layer to copy from.\n"
-" :arg other: :class:`BMLayerItem`\n"
-);
+ ".. method:: copy_from(other)\n"
+ "\n"
+ " Return a copy of the layer\n"
+ "\n"
+ " :arg other: Another layer to copy from.\n"
+ " :arg other: :class:`BMLayerItem`\n");
static PyObject *bpy_bmlayeritem_copy_from(BPy_BMLayerItem *self, BPy_BMLayerItem *value)
{
- CustomData *data;
+ CustomData *data;
- if (!BPy_BMLayerItem_Check(value)) {
- PyErr_Format(PyExc_TypeError,
- "layer.copy_from(x): expected BMLayerItem, not '%.200s'",
- Py_TYPE(value)->tp_name);
- return NULL;
- }
+ if (!BPy_BMLayerItem_Check(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "layer.copy_from(x): expected BMLayerItem, not '%.200s'",
+ Py_TYPE(value)->tp_name);
+ return NULL;
+ }
- BPY_BM_CHECK_OBJ(self);
- BPY_BM_CHECK_SOURCE_OBJ(self->bm, "layer.copy_from()", value);
+ BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_SOURCE_OBJ(self->bm, "layer.copy_from()", value);
- if ((self->htype != value->htype) ||
- (self->type != value->type))
- {
- PyErr_SetString(PyExc_ValueError,
- "layer.copy_from(other): layer type mismatch");
- }
+ if ((self->htype != value->htype) || (self->type != value->type)) {
+ PyErr_SetString(PyExc_ValueError, "layer.copy_from(other): layer type mismatch");
+ }
- else if (self->index == value->index) {
- Py_RETURN_NONE;
- }
+ else if (self->index == value->index) {
+ Py_RETURN_NONE;
+ }
- data = bpy_bm_customdata_get(self->bm, self->htype);
+ data = bpy_bm_customdata_get(self->bm, self->htype);
- if ((bpy_bmlayeritem_get(self) == NULL) ||
- (bpy_bmlayeritem_get(value) == NULL))
- {
- return NULL;
- }
+ if ((bpy_bmlayeritem_get(self) == NULL) || (bpy_bmlayeritem_get(value) == NULL)) {
+ return NULL;
+ }
- BM_data_layer_copy(self->bm, data, self->type, value->index, self->index);
+ BM_data_layer_copy(self->bm, data, self->type, value->index, self->index);
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
/* similar to new(), but no name arg. */
PyDoc_STRVAR(bpy_bmlayercollection_verify_doc,
-".. method:: verify()\n"
-"\n"
-" Create a new layer or return an existing active layer\n"
-"\n"
-" :return: The newly verified layer.\n"
-" :rtype: :class:`BMLayerItem`\n"
-);
+ ".. method:: verify()\n"
+ "\n"
+ " Create a new layer or return an existing active layer\n"
+ "\n"
+ " :return: The newly verified layer.\n"
+ " :rtype: :class:`BMLayerItem`\n");
static PyObject *bpy_bmlayercollection_verify(BPy_BMLayerCollection *self)
{
- int index;
- CustomData *data;
+ int index;
+ CustomData *data;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- data = bpy_bm_customdata_get(self->bm, self->htype);
+ data = bpy_bm_customdata_get(self->bm, self->htype);
- index = CustomData_get_active_layer(data, self->type); /* type relative */
+ index = CustomData_get_active_layer(data, self->type); /* type relative */
- if (index == -1) {
- BM_data_layer_add(self->bm, data, self->type);
- index = 0;
- }
+ if (index == -1) {
+ BM_data_layer_add(self->bm, data, self->type);
+ index = 0;
+ }
- BLI_assert(index >= 0);
+ BLI_assert(index >= 0);
- return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
+ return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
}
PyDoc_STRVAR(bpy_bmlayercollection_new_doc,
-".. method:: new(name)\n"
-"\n"
-" Create a new layer\n"
-"\n"
-" :arg name: Optional name argument (will be made unique).\n"
-" :type name: string\n"
-" :return: The newly created layer.\n"
-" :rtype: :class:`BMLayerItem`\n"
-);
+ ".. method:: new(name)\n"
+ "\n"
+ " Create a new layer\n"
+ "\n"
+ " :arg name: Optional name argument (will be made unique).\n"
+ " :type name: string\n"
+ " :return: The newly created layer.\n"
+ " :rtype: :class:`BMLayerItem`\n");
static PyObject *bpy_bmlayercollection_new(BPy_BMLayerCollection *self, PyObject *args)
{
- const char *name = NULL;
- int index;
- CustomData *data;
+ const char *name = NULL;
+ int index;
+ CustomData *data;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "|s:new", &name)) {
- return NULL;
- }
+ if (!PyArg_ParseTuple(args, "|s:new", &name)) {
+ return NULL;
+ }
- data = bpy_bm_customdata_get(self->bm, self->htype);
+ data = bpy_bm_customdata_get(self->bm, self->htype);
- if (CustomData_layertype_is_singleton(self->type) &&
- CustomData_has_layer(data, self->type))
- {
- PyErr_SetString(PyExc_ValueError,
- "layers.new(): is a singleton, use verify() instead");
- return NULL;
- }
+ if (CustomData_layertype_is_singleton(self->type) && CustomData_has_layer(data, self->type)) {
+ PyErr_SetString(PyExc_ValueError, "layers.new(): is a singleton, use verify() instead");
+ return NULL;
+ }
- if (name) {
- BM_data_layer_add_named(self->bm, data, self->type, name);
- }
- else {
- BM_data_layer_add(self->bm, data, self->type);
- }
+ if (name) {
+ BM_data_layer_add_named(self->bm, data, self->type, name);
+ }
+ else {
+ BM_data_layer_add(self->bm, data, self->type);
+ }
- index = CustomData_number_of_layers(data, self->type) - 1;
- BLI_assert(index >= 0);
+ index = CustomData_number_of_layers(data, self->type) - 1;
+ BLI_assert(index >= 0);
- return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
+ return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
}
PyDoc_STRVAR(bpy_bmlayercollection_remove_doc,
-".. method:: remove(layer)\n"
-"\n"
-" Remove a layer\n"
-"\n"
-" :arg layer: The layer to remove.\n"
-" :type layer: :class:`BMLayerItem`\n"
-);
+ ".. method:: remove(layer)\n"
+ "\n"
+ " Remove a layer\n"
+ "\n"
+ " :arg layer: The layer to remove.\n"
+ " :type layer: :class:`BMLayerItem`\n");
static PyObject *bpy_bmlayercollection_remove(BPy_BMLayerCollection *self, BPy_BMLayerItem *value)
{
- CustomData *data;
+ CustomData *data;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if (!BPy_BMLayerItem_Check(value)) {
- PyErr_Format(PyExc_TypeError,
- "layers.remove(x): expected BMLayerItem, not '%.200s'",
- Py_TYPE(value)->tp_name);
- return NULL;
- }
+ if (!BPy_BMLayerItem_Check(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "layers.remove(x): expected BMLayerItem, not '%.200s'",
+ Py_TYPE(value)->tp_name);
+ return NULL;
+ }
- BPY_BM_CHECK_OBJ(value);
+ BPY_BM_CHECK_OBJ(value);
- if ((self->bm != value->bm) ||
- (self->type != value->type) ||
- (self->htype != value->htype))
- {
- PyErr_SetString(PyExc_ValueError,
- "layers.remove(x): x not in layers");
- }
+ if ((self->bm != value->bm) || (self->type != value->type) || (self->htype != value->htype)) {
+ PyErr_SetString(PyExc_ValueError, "layers.remove(x): x not in layers");
+ }
- data = bpy_bm_customdata_get(self->bm, self->htype);
- BM_data_layer_free_n(self->bm, data, self->type, value->index);
+ data = bpy_bm_customdata_get(self->bm, self->htype);
+ BM_data_layer_free_n(self->bm, data, self->type, value->index);
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
-
PyDoc_STRVAR(bpy_bmlayercollection_keys_doc,
-".. method:: keys()\n"
-"\n"
-" Return the identifiers of collection members\n"
-" (matching pythons dict.keys() functionality).\n"
-"\n"
-" :return: the identifiers for each member of this collection.\n"
-" :rtype: list of strings\n"
-);
+ ".. method:: keys()\n"
+ "\n"
+ " Return the identifiers of collection members\n"
+ " (matching pythons dict.keys() functionality).\n"
+ "\n"
+ " :return: the identifiers for each member of this collection.\n"
+ " :rtype: list of strings\n");
static PyObject *bpy_bmlayercollection_keys(BPy_BMLayerCollection *self)
{
- PyObject *ret;
- PyObject *item;
- int index;
- CustomData *data;
- int tot, i;
+ PyObject *ret;
+ PyObject *item;
+ int index;
+ CustomData *data;
+ int tot, i;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- data = bpy_bm_customdata_get(self->bm, self->htype);
- index = CustomData_get_layer_index(data, self->type); /* absolute, but no need to make relative */
- tot = (index != -1) ? CustomData_number_of_layers(data, self->type) : 0;
+ data = bpy_bm_customdata_get(self->bm, self->htype);
+ index = CustomData_get_layer_index(data,
+ self->type); /* absolute, but no need to make relative */
+ tot = (index != -1) ? CustomData_number_of_layers(data, self->type) : 0;
- ret = PyList_New(tot);
+ ret = PyList_New(tot);
- for (i = 0; tot-- > 0; index++) {
- item = PyUnicode_FromString(data->layers[index].name);
- PyList_SET_ITEM(ret, i++, item);
- }
+ for (i = 0; tot-- > 0; index++) {
+ item = PyUnicode_FromString(data->layers[index].name);
+ PyList_SET_ITEM(ret, i++, item);
+ }
- return ret;
+ return ret;
}
PyDoc_STRVAR(bpy_bmlayercollection_items_doc,
-".. method:: items()\n"
-"\n"
-" Return the identifiers of collection members\n"
-" (matching pythons dict.items() functionality).\n"
-"\n"
-" :return: (key, value) pairs for each member of this collection.\n"
-" :rtype: list of tuples\n"
-);
+ ".. method:: items()\n"
+ "\n"
+ " Return the identifiers of collection members\n"
+ " (matching pythons dict.items() functionality).\n"
+ "\n"
+ " :return: (key, value) pairs for each member of this collection.\n"
+ " :rtype: list of tuples\n");
static PyObject *bpy_bmlayercollection_items(BPy_BMLayerCollection *self)
{
- PyObject *ret;
- PyObject *item;
- int index;
- CustomData *data;
- int tot, i;
+ PyObject *ret;
+ PyObject *item;
+ int index;
+ CustomData *data;
+ int tot, i;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- data = bpy_bm_customdata_get(self->bm, self->htype);
- index = CustomData_get_layer_index(data, self->type);
- tot = (index != -1) ? CustomData_number_of_layers(data, self->type) : 0;
+ data = bpy_bm_customdata_get(self->bm, self->htype);
+ index = CustomData_get_layer_index(data, self->type);
+ tot = (index != -1) ? CustomData_number_of_layers(data, self->type) : 0;
- ret = PyList_New(tot);
+ ret = PyList_New(tot);
- for (i = 0; tot-- > 0; index++) {
- item = PyTuple_New(2);
- PyTuple_SET_ITEMS(item,
- PyUnicode_FromString(data->layers[index].name),
- BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, i));
- PyList_SET_ITEM(ret, i++, item);
- }
+ for (i = 0; tot-- > 0; index++) {
+ item = PyTuple_New(2);
+ PyTuple_SET_ITEMS(item,
+ PyUnicode_FromString(data->layers[index].name),
+ BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, i));
+ PyList_SET_ITEM(ret, i++, item);
+ }
- return ret;
+ return ret;
}
PyDoc_STRVAR(bpy_bmlayercollection_values_doc,
-".. method:: values()\n"
-"\n"
-" Return the values of collection\n"
-" (matching pythons dict.values() functionality).\n"
-"\n"
-" :return: the members of this collection.\n"
-" :rtype: list\n"
-);
+ ".. method:: values()\n"
+ "\n"
+ " Return the values of collection\n"
+ " (matching pythons dict.values() functionality).\n"
+ "\n"
+ " :return: the members of this collection.\n"
+ " :rtype: list\n");
static PyObject *bpy_bmlayercollection_values(BPy_BMLayerCollection *self)
{
- PyObject *ret;
- PyObject *item;
- int index;
- CustomData *data;
- int tot, i;
+ PyObject *ret;
+ PyObject *item;
+ int index;
+ CustomData *data;
+ int tot, i;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- data = bpy_bm_customdata_get(self->bm, self->htype);
- index = CustomData_get_layer_index(data, self->type);
- tot = (index != -1) ? CustomData_number_of_layers(data, self->type) : 0;
+ data = bpy_bm_customdata_get(self->bm, self->htype);
+ index = CustomData_get_layer_index(data, self->type);
+ tot = (index != -1) ? CustomData_number_of_layers(data, self->type) : 0;
- ret = PyList_New(tot);
+ ret = PyList_New(tot);
- for (i = 0; tot-- > 0; index++) {
- item = BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, i);
- PyList_SET_ITEM(ret, i++, item);
- }
+ for (i = 0; tot-- > 0; index++) {
+ item = BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, i);
+ PyList_SET_ITEM(ret, i++, item);
+ }
- return ret;
+ return ret;
}
PyDoc_STRVAR(bpy_bmlayercollection_get_doc,
-".. method:: get(key, default=None)\n"
-"\n"
-" Returns the value of the layer matching the key or default\n"
-" when not found (matches pythons dictionary function of the same name).\n"
-"\n"
-" :arg key: The key associated with the layer.\n"
-" :type key: string\n"
-" :arg default: Optional argument for the value to return if\n"
-" *key* is not found.\n"
-" :type default: Undefined\n"
-);
+ ".. method:: get(key, default=None)\n"
+ "\n"
+ " Returns the value of the layer matching the key or default\n"
+ " when not found (matches pythons dictionary function of the same name).\n"
+ "\n"
+ " :arg key: The key associated with the layer.\n"
+ " :type key: string\n"
+ " :arg default: Optional argument for the value to return if\n"
+ " *key* is not found.\n"
+ " :type default: Undefined\n");
static PyObject *bpy_bmlayercollection_get(BPy_BMLayerCollection *self, PyObject *args)
{
- const char *key;
- PyObject *def = Py_None;
+ const char *key;
+ PyObject *def = Py_None;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) {
- return NULL;
- }
- else {
- CustomData *data;
- int index;
+ if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) {
+ return NULL;
+ }
+ else {
+ CustomData *data;
+ int index;
- data = bpy_bm_customdata_get(self->bm, self->htype);
- index = CustomData_get_named_layer(data, self->type, key); /* type relative */
+ data = bpy_bm_customdata_get(self->bm, self->htype);
+ index = CustomData_get_named_layer(data, self->type, key); /* type relative */
- if (index != -1) {
- return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
- }
- }
+ if (index != -1) {
+ return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
+ }
+ }
- return Py_INCREF_RET(def);
+ return Py_INCREF_RET(def);
}
static struct PyMethodDef bpy_bmlayeritem_methods[] = {
- {"copy_from", (PyCFunction)bpy_bmlayeritem_copy_from, METH_O, bpy_bmlayeritem_copy_from_doc},
- {NULL, NULL, 0, NULL},
+ {"copy_from", (PyCFunction)bpy_bmlayeritem_copy_from, METH_O, bpy_bmlayeritem_copy_from_doc},
+ {NULL, NULL, 0, NULL},
};
static struct PyMethodDef bpy_bmelemseq_methods[] = {
- {"verify", (PyCFunction)bpy_bmlayercollection_verify, METH_NOARGS, bpy_bmlayercollection_verify_doc},
- {"new", (PyCFunction)bpy_bmlayercollection_new, METH_VARARGS, bpy_bmlayercollection_new_doc},
- {"remove", (PyCFunction)bpy_bmlayercollection_remove, METH_O, bpy_bmlayercollection_remove_doc},
-
- {"keys", (PyCFunction)bpy_bmlayercollection_keys, METH_NOARGS, bpy_bmlayercollection_keys_doc},
- {"values", (PyCFunction)bpy_bmlayercollection_values, METH_NOARGS, bpy_bmlayercollection_values_doc},
- {"items", (PyCFunction)bpy_bmlayercollection_items, METH_NOARGS, bpy_bmlayercollection_items_doc},
- {"get", (PyCFunction)bpy_bmlayercollection_get, METH_VARARGS, bpy_bmlayercollection_get_doc},
- {NULL, NULL, 0, NULL},
+ {"verify",
+ (PyCFunction)bpy_bmlayercollection_verify,
+ METH_NOARGS,
+ bpy_bmlayercollection_verify_doc},
+ {"new", (PyCFunction)bpy_bmlayercollection_new, METH_VARARGS, bpy_bmlayercollection_new_doc},
+ {"remove",
+ (PyCFunction)bpy_bmlayercollection_remove,
+ METH_O,
+ bpy_bmlayercollection_remove_doc},
+
+ {"keys", (PyCFunction)bpy_bmlayercollection_keys, METH_NOARGS, bpy_bmlayercollection_keys_doc},
+ {"values",
+ (PyCFunction)bpy_bmlayercollection_values,
+ METH_NOARGS,
+ bpy_bmlayercollection_values_doc},
+ {"items",
+ (PyCFunction)bpy_bmlayercollection_items,
+ METH_NOARGS,
+ bpy_bmlayercollection_items_doc},
+ {"get", (PyCFunction)bpy_bmlayercollection_get, METH_VARARGS, bpy_bmlayercollection_get_doc},
+ {NULL, NULL, 0, NULL},
};
/* Sequences
@@ -579,183 +667,185 @@ static struct PyMethodDef bpy_bmelemseq_methods[] = {
static Py_ssize_t bpy_bmlayercollection_length(BPy_BMLayerCollection *self)
{
- CustomData *data;
+ CustomData *data;
- BPY_BM_CHECK_INT(self);
+ BPY_BM_CHECK_INT(self);
- data = bpy_bm_customdata_get(self->bm, self->htype);
+ data = bpy_bm_customdata_get(self->bm, self->htype);
- return CustomData_number_of_layers(data, self->type);
+ return CustomData_number_of_layers(data, self->type);
}
-static PyObject *bpy_bmlayercollection_subscript_str(BPy_BMLayerCollection *self, const char *keyname)
+static PyObject *bpy_bmlayercollection_subscript_str(BPy_BMLayerCollection *self,
+ const char *keyname)
{
- CustomData *data;
- int index;
-
- BPY_BM_CHECK_OBJ(self);
-
- data = bpy_bm_customdata_get(self->bm, self->htype);
- index = CustomData_get_named_layer(data, self->type, keyname); /* type relative */
-
- if (index != -1) {
- return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
- }
- else {
- PyErr_Format(PyExc_KeyError,
- "BMLayerCollection[key]: key \"%.200s\" not found", keyname);
- return NULL;
- }
+ CustomData *data;
+ int index;
+
+ BPY_BM_CHECK_OBJ(self);
+
+ data = bpy_bm_customdata_get(self->bm, self->htype);
+ index = CustomData_get_named_layer(data, self->type, keyname); /* type relative */
+
+ if (index != -1) {
+ return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
+ }
+ else {
+ PyErr_Format(PyExc_KeyError, "BMLayerCollection[key]: key \"%.200s\" not found", keyname);
+ return NULL;
+ }
}
static PyObject *bpy_bmlayercollection_subscript_int(BPy_BMLayerCollection *self, int keynum)
{
- Py_ssize_t len;
- BPY_BM_CHECK_OBJ(self);
-
- len = bpy_bmlayercollection_length(self);
-
- if (keynum < 0) {
- keynum += len;
- }
- if (keynum >= 0) {
- if (keynum < len) {
- return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, keynum);
- }
- }
-
- PyErr_Format(PyExc_IndexError,
- "BMLayerCollection[index]: index %d out of range", keynum);
- return NULL;
+ Py_ssize_t len;
+ BPY_BM_CHECK_OBJ(self);
+
+ len = bpy_bmlayercollection_length(self);
+
+ if (keynum < 0) {
+ keynum += len;
+ }
+ if (keynum >= 0) {
+ if (keynum < len) {
+ return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, keynum);
+ }
+ }
+
+ PyErr_Format(PyExc_IndexError, "BMLayerCollection[index]: index %d out of range", keynum);
+ return NULL;
}
-static PyObject *bpy_bmlayercollection_subscript_slice(BPy_BMLayerCollection *self, Py_ssize_t start, Py_ssize_t stop)
+static PyObject *bpy_bmlayercollection_subscript_slice(BPy_BMLayerCollection *self,
+ Py_ssize_t start,
+ Py_ssize_t stop)
{
- Py_ssize_t len = bpy_bmlayercollection_length(self);
- int count = 0;
+ Py_ssize_t len = bpy_bmlayercollection_length(self);
+ int count = 0;
- PyObject *tuple;
+ PyObject *tuple;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if (start >= len) {
- start = len - 1;
- }
- if (stop >= len) {
- stop = len - 1;
- }
+ if (start >= len) {
+ start = len - 1;
+ }
+ if (stop >= len) {
+ stop = len - 1;
+ }
- tuple = PyTuple_New(stop - start);
+ tuple = PyTuple_New(stop - start);
- for (count = start; count < stop; count++) {
- PyTuple_SET_ITEM(tuple, count - start, BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, count));
- }
+ for (count = start; count < stop; count++) {
+ PyTuple_SET_ITEM(tuple,
+ count - start,
+ BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, count));
+ }
- return tuple;
+ return tuple;
}
static PyObject *bpy_bmlayercollection_subscript(BPy_BMLayerCollection *self, PyObject *key)
{
- /* don't need error check here */
- if (PyUnicode_Check(key)) {
- return bpy_bmlayercollection_subscript_str(self, _PyUnicode_AsString(key));
- }
- else if (PyIndex_Check(key)) {
- Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred()) {
- return NULL;
- }
- return bpy_bmlayercollection_subscript_int(self, i);
- }
- else if (PySlice_Check(key)) {
- PySliceObject *key_slice = (PySliceObject *)key;
- Py_ssize_t step = 1;
-
- if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) {
- return NULL;
- }
- else if (step != 1) {
- PyErr_SetString(PyExc_TypeError,
- "BMLayerCollection[slice]: slice steps not supported");
- return NULL;
- }
- else if (key_slice->start == Py_None && key_slice->stop == Py_None) {
- return bpy_bmlayercollection_subscript_slice(self, 0, PY_SSIZE_T_MAX);
- }
- else {
- Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX;
-
- /* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */
- if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) {
- return NULL;
- }
- if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) {
- return NULL;
- }
-
- if (start < 0 || stop < 0) {
- /* only get the length for negative values */
- Py_ssize_t len = bpy_bmlayercollection_length(self);
- if (start < 0) {
- start += len;
- }
- if (stop < 0) {
- stop += len;
- }
- }
-
- if (stop - start <= 0) {
- return PyTuple_New(0);
- }
- else {
- return bpy_bmlayercollection_subscript_slice(self, start, stop);
- }
- }
- }
- else {
- PyErr_SetString(PyExc_AttributeError,
- "BMLayerCollection[key]: invalid key, key must be an int");
- return NULL;
- }
+ /* don't need error check here */
+ if (PyUnicode_Check(key)) {
+ return bpy_bmlayercollection_subscript_str(self, _PyUnicode_AsString(key));
+ }
+ else if (PyIndex_Check(key)) {
+ Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
+ if (i == -1 && PyErr_Occurred()) {
+ return NULL;
+ }
+ return bpy_bmlayercollection_subscript_int(self, i);
+ }
+ else if (PySlice_Check(key)) {
+ PySliceObject *key_slice = (PySliceObject *)key;
+ Py_ssize_t step = 1;
+
+ if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) {
+ return NULL;
+ }
+ else if (step != 1) {
+ PyErr_SetString(PyExc_TypeError, "BMLayerCollection[slice]: slice steps not supported");
+ return NULL;
+ }
+ else if (key_slice->start == Py_None && key_slice->stop == Py_None) {
+ return bpy_bmlayercollection_subscript_slice(self, 0, PY_SSIZE_T_MAX);
+ }
+ else {
+ Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX;
+
+ /* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */
+ if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) {
+ return NULL;
+ }
+ if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) {
+ return NULL;
+ }
+
+ if (start < 0 || stop < 0) {
+ /* only get the length for negative values */
+ Py_ssize_t len = bpy_bmlayercollection_length(self);
+ if (start < 0) {
+ start += len;
+ }
+ if (stop < 0) {
+ stop += len;
+ }
+ }
+
+ if (stop - start <= 0) {
+ return PyTuple_New(0);
+ }
+ else {
+ return bpy_bmlayercollection_subscript_slice(self, start, stop);
+ }
+ }
+ }
+ else {
+ PyErr_SetString(PyExc_AttributeError,
+ "BMLayerCollection[key]: invalid key, key must be an int");
+ return NULL;
+ }
}
static int bpy_bmlayercollection_contains(BPy_BMLayerCollection *self, PyObject *value)
{
- const char *keyname = _PyUnicode_AsString(value);
- CustomData *data;
- int index;
+ const char *keyname = _PyUnicode_AsString(value);
+ CustomData *data;
+ int index;
- BPY_BM_CHECK_INT(self);
+ BPY_BM_CHECK_INT(self);
- if (keyname == NULL) {
- PyErr_SetString(PyExc_TypeError,
- "BMLayerCollection.__contains__: expected a string");
- return -1;
- }
+ if (keyname == NULL) {
+ PyErr_SetString(PyExc_TypeError, "BMLayerCollection.__contains__: expected a string");
+ return -1;
+ }
- data = bpy_bm_customdata_get(self->bm, self->htype);
- index = CustomData_get_named_layer_index(data, self->type, keyname);
+ data = bpy_bm_customdata_get(self->bm, self->htype);
+ index = CustomData_get_named_layer_index(data, self->type, keyname);
- return (index != -1) ? 1 : 0;
+ return (index != -1) ? 1 : 0;
}
static PySequenceMethods bpy_bmlayercollection_as_sequence = {
- (lenfunc)bpy_bmlayercollection_length, /* sq_length */
- NULL, /* sq_concat */
- NULL, /* sq_repeat */
- (ssizeargfunc)bpy_bmlayercollection_subscript_int, /* sq_item */ /* Only set this so PySequence_Check() returns True */
- NULL, /* sq_slice */
- (ssizeobjargproc)NULL, /* sq_ass_item */
- NULL, /* *was* sq_ass_slice */
- (objobjproc)bpy_bmlayercollection_contains, /* sq_contains */
- (binaryfunc) NULL, /* sq_inplace_concat */
- (ssizeargfunc) NULL, /* sq_inplace_repeat */
+ (lenfunc)bpy_bmlayercollection_length, /* sq_length */
+ NULL, /* sq_concat */
+ NULL, /* sq_repeat */
+ (ssizeargfunc)bpy_bmlayercollection_subscript_int,
+ /* sq_item */ /* Only set this so PySequence_Check() returns True */
+ NULL, /* sq_slice */
+ (ssizeobjargproc)NULL, /* sq_ass_item */
+ NULL, /* *was* sq_ass_slice */
+ (objobjproc)bpy_bmlayercollection_contains, /* sq_contains */
+ (binaryfunc)NULL, /* sq_inplace_concat */
+ (ssizeargfunc)NULL, /* sq_inplace_repeat */
};
static PyMappingMethods bpy_bmlayercollection_as_mapping = {
- (lenfunc)bpy_bmlayercollection_length, /* mp_length */
- (binaryfunc)bpy_bmlayercollection_subscript, /* mp_subscript */
- (objobjargproc)NULL, /* mp_ass_subscript */
+ (lenfunc)bpy_bmlayercollection_length, /* mp_length */
+ (binaryfunc)bpy_bmlayercollection_subscript, /* mp_subscript */
+ (objobjargproc)NULL, /* mp_ass_subscript */
};
/* Iterator
@@ -763,36 +853,33 @@ static PyMappingMethods bpy_bmlayercollection_as_mapping = {
static PyObject *bpy_bmlayercollection_iter(BPy_BMLayerCollection *self)
{
- /* fake it with a list iterator */
- PyObject *ret;
- PyObject *iter = NULL;
+ /* fake it with a list iterator */
+ PyObject *ret;
+ PyObject *iter = NULL;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- ret = bpy_bmlayercollection_subscript_slice(self, 0, PY_SSIZE_T_MIN);
+ ret = bpy_bmlayercollection_subscript_slice(self, 0, PY_SSIZE_T_MIN);
- if (ret) {
- iter = PyObject_GetIter(ret);
- Py_DECREF(ret);
- }
+ if (ret) {
+ iter = PyObject_GetIter(ret);
+ Py_DECREF(ret);
+ }
- return iter;
+ return iter;
}
-PyDoc_STRVAR(bpy_bmlayeraccess_type_doc,
-"Exposes custom-data layer attributes."
-);
+PyDoc_STRVAR(bpy_bmlayeraccess_type_doc, "Exposes custom-data layer attributes.");
PyDoc_STRVAR(bpy_bmlayercollection_type_doc,
-"Gives access to a collection of custom-data layers of the same type and behaves like python dictionaries, "
-"except for the ability to do list like index access."
-);
+ "Gives access to a collection of custom-data layers of the same type and behaves "
+ "like python dictionaries, "
+ "except for the ability to do list like index access.");
PyDoc_STRVAR(bpy_bmlayeritem_type_doc,
-"Exposes a single custom data layer, "
-"their main purpose is for use as item accessors to custom-data when used with vert/edge/face/loop data."
-);
-
+ "Exposes a single custom data layer, "
+ "their main purpose is for use as item accessors to custom-data when used with "
+ "vert/edge/face/loop data.");
PyTypeObject BPy_BMLayerAccessVert_Type; /* bm.verts.layers */
PyTypeObject BPy_BMLayerAccessEdge_Type; /* bm.edges.layers */
@@ -801,125 +888,126 @@ PyTypeObject BPy_BMLayerAccessLoop_Type; /* bm.loops.layers */
PyTypeObject BPy_BMLayerCollection_Type; /* bm.loops.layers.uv */
PyTypeObject BPy_BMLayerItem_Type; /* bm.loops.layers.uv["UVMap"] */
-
PyObject *BPy_BMLayerAccess_CreatePyObject(BMesh *bm, const char htype)
{
- BPy_BMLayerAccess *self;
- PyTypeObject *type;
-
- switch (htype) {
- case BM_VERT: type = &BPy_BMLayerAccessVert_Type; break;
- case BM_EDGE: type = &BPy_BMLayerAccessEdge_Type; break;
- case BM_FACE: type = &BPy_BMLayerAccessFace_Type; break;
- case BM_LOOP: type = &BPy_BMLayerAccessLoop_Type; break;
- default:
- {
- BLI_assert(0);
- type = NULL;
- break;
- }
- }
-
- self = PyObject_New(BPy_BMLayerAccess, type);
- self->bm = bm;
- self->htype = htype;
- return (PyObject *)self;
+ BPy_BMLayerAccess *self;
+ PyTypeObject *type;
+
+ switch (htype) {
+ case BM_VERT:
+ type = &BPy_BMLayerAccessVert_Type;
+ break;
+ case BM_EDGE:
+ type = &BPy_BMLayerAccessEdge_Type;
+ break;
+ case BM_FACE:
+ type = &BPy_BMLayerAccessFace_Type;
+ break;
+ case BM_LOOP:
+ type = &BPy_BMLayerAccessLoop_Type;
+ break;
+ default: {
+ BLI_assert(0);
+ type = NULL;
+ break;
+ }
+ }
+
+ self = PyObject_New(BPy_BMLayerAccess, type);
+ self->bm = bm;
+ self->htype = htype;
+ return (PyObject *)self;
}
PyObject *BPy_BMLayerCollection_CreatePyObject(BMesh *bm, const char htype, int type)
{
- BPy_BMLayerCollection *self = PyObject_New(BPy_BMLayerCollection, &BPy_BMLayerCollection_Type);
- self->bm = bm;
- self->htype = htype;
- self->type = type;
- return (PyObject *)self;
+ BPy_BMLayerCollection *self = PyObject_New(BPy_BMLayerCollection, &BPy_BMLayerCollection_Type);
+ self->bm = bm;
+ self->htype = htype;
+ self->type = type;
+ return (PyObject *)self;
}
PyObject *BPy_BMLayerItem_CreatePyObject(BMesh *bm, const char htype, int type, int index)
{
- BPy_BMLayerItem *self = PyObject_New(BPy_BMLayerItem, &BPy_BMLayerItem_Type);
- self->bm = bm;
- self->htype = htype;
- self->type = type;
- self->index = index;
- return (PyObject *)self;
+ BPy_BMLayerItem *self = PyObject_New(BPy_BMLayerItem, &BPy_BMLayerItem_Type);
+ self->bm = bm;
+ self->htype = htype;
+ self->type = type;
+ self->index = index;
+ return (PyObject *)self;
}
-
void BPy_BM_init_types_customdata(void)
{
- BPy_BMLayerAccessVert_Type.tp_basicsize = sizeof(BPy_BMLayerAccess);
- BPy_BMLayerAccessEdge_Type.tp_basicsize = sizeof(BPy_BMLayerAccess);
- BPy_BMLayerAccessFace_Type.tp_basicsize = sizeof(BPy_BMLayerAccess);
- BPy_BMLayerAccessLoop_Type.tp_basicsize = sizeof(BPy_BMLayerAccess);
- BPy_BMLayerCollection_Type.tp_basicsize = sizeof(BPy_BMLayerCollection);
- BPy_BMLayerItem_Type.tp_basicsize = sizeof(BPy_BMLayerItem);
-
- BPy_BMLayerAccessVert_Type.tp_name = "BMLayerAccessVert";
- BPy_BMLayerAccessEdge_Type.tp_name = "BMLayerAccessEdge";
- BPy_BMLayerAccessFace_Type.tp_name = "BMLayerAccessFace";
- BPy_BMLayerAccessLoop_Type.tp_name = "BMLayerAccessLoop";
- BPy_BMLayerCollection_Type.tp_name = "BMLayerCollection";
- BPy_BMLayerItem_Type.tp_name = "BMLayerItem";
-
- /* todo */
- BPy_BMLayerAccessVert_Type.tp_doc = bpy_bmlayeraccess_type_doc;
- BPy_BMLayerAccessEdge_Type.tp_doc = bpy_bmlayeraccess_type_doc;
- BPy_BMLayerAccessFace_Type.tp_doc = bpy_bmlayeraccess_type_doc;
- BPy_BMLayerAccessLoop_Type.tp_doc = bpy_bmlayeraccess_type_doc;
- BPy_BMLayerCollection_Type.tp_doc = bpy_bmlayercollection_type_doc;
- BPy_BMLayerItem_Type.tp_doc = bpy_bmlayeritem_type_doc;
-
- BPy_BMLayerAccessVert_Type.tp_repr = (reprfunc)NULL;
- BPy_BMLayerAccessEdge_Type.tp_repr = (reprfunc)NULL;
- BPy_BMLayerAccessFace_Type.tp_repr = (reprfunc)NULL;
- BPy_BMLayerAccessLoop_Type.tp_repr = (reprfunc)NULL;
- BPy_BMLayerCollection_Type.tp_repr = (reprfunc)NULL;
- BPy_BMLayerItem_Type.tp_repr = (reprfunc)NULL;
-
- BPy_BMLayerAccessVert_Type.tp_getset = bpy_bmlayeraccess_vert_getseters;
- BPy_BMLayerAccessEdge_Type.tp_getset = bpy_bmlayeraccess_edge_getseters;
- BPy_BMLayerAccessFace_Type.tp_getset = bpy_bmlayeraccess_face_getseters;
- BPy_BMLayerAccessLoop_Type.tp_getset = bpy_bmlayeraccess_loop_getseters;
- BPy_BMLayerCollection_Type.tp_getset = bpy_bmlayercollection_getseters;
- BPy_BMLayerItem_Type.tp_getset = bpy_bmlayeritem_getseters;
-
-
-// BPy_BMLayerAccess_Type.tp_methods = bpy_bmeditselseq_methods;
- BPy_BMLayerCollection_Type.tp_methods = bpy_bmelemseq_methods;
- BPy_BMLayerItem_Type.tp_methods = bpy_bmlayeritem_methods;
-
- BPy_BMLayerCollection_Type.tp_as_sequence = &bpy_bmlayercollection_as_sequence;
-
- BPy_BMLayerCollection_Type.tp_as_mapping = &bpy_bmlayercollection_as_mapping;
-
- BPy_BMLayerCollection_Type.tp_iter = (getiterfunc)bpy_bmlayercollection_iter;
-
- BPy_BMLayerAccessVert_Type.tp_dealloc = NULL;
- BPy_BMLayerAccessEdge_Type.tp_dealloc = NULL;
- BPy_BMLayerAccessFace_Type.tp_dealloc = NULL;
- BPy_BMLayerAccessLoop_Type.tp_dealloc = NULL;
- BPy_BMLayerCollection_Type.tp_dealloc = NULL;
- BPy_BMLayerItem_Type.tp_dealloc = NULL;
-
-
-
- BPy_BMLayerAccessVert_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- BPy_BMLayerAccessEdge_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- BPy_BMLayerAccessFace_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- BPy_BMLayerAccessLoop_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- BPy_BMLayerCollection_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- BPy_BMLayerItem_Type.tp_flags = Py_TPFLAGS_DEFAULT;
-
- PyType_Ready(&BPy_BMLayerAccessVert_Type);
- PyType_Ready(&BPy_BMLayerAccessEdge_Type);
- PyType_Ready(&BPy_BMLayerAccessFace_Type);
- PyType_Ready(&BPy_BMLayerAccessLoop_Type);
- PyType_Ready(&BPy_BMLayerCollection_Type);
- PyType_Ready(&BPy_BMLayerItem_Type);
+ BPy_BMLayerAccessVert_Type.tp_basicsize = sizeof(BPy_BMLayerAccess);
+ BPy_BMLayerAccessEdge_Type.tp_basicsize = sizeof(BPy_BMLayerAccess);
+ BPy_BMLayerAccessFace_Type.tp_basicsize = sizeof(BPy_BMLayerAccess);
+ BPy_BMLayerAccessLoop_Type.tp_basicsize = sizeof(BPy_BMLayerAccess);
+ BPy_BMLayerCollection_Type.tp_basicsize = sizeof(BPy_BMLayerCollection);
+ BPy_BMLayerItem_Type.tp_basicsize = sizeof(BPy_BMLayerItem);
+
+ BPy_BMLayerAccessVert_Type.tp_name = "BMLayerAccessVert";
+ BPy_BMLayerAccessEdge_Type.tp_name = "BMLayerAccessEdge";
+ BPy_BMLayerAccessFace_Type.tp_name = "BMLayerAccessFace";
+ BPy_BMLayerAccessLoop_Type.tp_name = "BMLayerAccessLoop";
+ BPy_BMLayerCollection_Type.tp_name = "BMLayerCollection";
+ BPy_BMLayerItem_Type.tp_name = "BMLayerItem";
+
+ /* todo */
+ BPy_BMLayerAccessVert_Type.tp_doc = bpy_bmlayeraccess_type_doc;
+ BPy_BMLayerAccessEdge_Type.tp_doc = bpy_bmlayeraccess_type_doc;
+ BPy_BMLayerAccessFace_Type.tp_doc = bpy_bmlayeraccess_type_doc;
+ BPy_BMLayerAccessLoop_Type.tp_doc = bpy_bmlayeraccess_type_doc;
+ BPy_BMLayerCollection_Type.tp_doc = bpy_bmlayercollection_type_doc;
+ BPy_BMLayerItem_Type.tp_doc = bpy_bmlayeritem_type_doc;
+
+ BPy_BMLayerAccessVert_Type.tp_repr = (reprfunc)NULL;
+ BPy_BMLayerAccessEdge_Type.tp_repr = (reprfunc)NULL;
+ BPy_BMLayerAccessFace_Type.tp_repr = (reprfunc)NULL;
+ BPy_BMLayerAccessLoop_Type.tp_repr = (reprfunc)NULL;
+ BPy_BMLayerCollection_Type.tp_repr = (reprfunc)NULL;
+ BPy_BMLayerItem_Type.tp_repr = (reprfunc)NULL;
+
+ BPy_BMLayerAccessVert_Type.tp_getset = bpy_bmlayeraccess_vert_getseters;
+ BPy_BMLayerAccessEdge_Type.tp_getset = bpy_bmlayeraccess_edge_getseters;
+ BPy_BMLayerAccessFace_Type.tp_getset = bpy_bmlayeraccess_face_getseters;
+ BPy_BMLayerAccessLoop_Type.tp_getset = bpy_bmlayeraccess_loop_getseters;
+ BPy_BMLayerCollection_Type.tp_getset = bpy_bmlayercollection_getseters;
+ BPy_BMLayerItem_Type.tp_getset = bpy_bmlayeritem_getseters;
+
+ // BPy_BMLayerAccess_Type.tp_methods = bpy_bmeditselseq_methods;
+ BPy_BMLayerCollection_Type.tp_methods = bpy_bmelemseq_methods;
+ BPy_BMLayerItem_Type.tp_methods = bpy_bmlayeritem_methods;
+
+ BPy_BMLayerCollection_Type.tp_as_sequence = &bpy_bmlayercollection_as_sequence;
+
+ BPy_BMLayerCollection_Type.tp_as_mapping = &bpy_bmlayercollection_as_mapping;
+
+ BPy_BMLayerCollection_Type.tp_iter = (getiterfunc)bpy_bmlayercollection_iter;
+
+ BPy_BMLayerAccessVert_Type.tp_dealloc = NULL;
+ BPy_BMLayerAccessEdge_Type.tp_dealloc = NULL;
+ BPy_BMLayerAccessFace_Type.tp_dealloc = NULL;
+ BPy_BMLayerAccessLoop_Type.tp_dealloc = NULL;
+ BPy_BMLayerCollection_Type.tp_dealloc = NULL;
+ BPy_BMLayerItem_Type.tp_dealloc = NULL;
+
+ BPy_BMLayerAccessVert_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMLayerAccessEdge_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMLayerAccessFace_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMLayerAccessLoop_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMLayerCollection_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMLayerItem_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+
+ PyType_Ready(&BPy_BMLayerAccessVert_Type);
+ PyType_Ready(&BPy_BMLayerAccessEdge_Type);
+ PyType_Ready(&BPy_BMLayerAccessFace_Type);
+ PyType_Ready(&BPy_BMLayerAccessLoop_Type);
+ PyType_Ready(&BPy_BMLayerCollection_Type);
+ PyType_Ready(&BPy_BMLayerItem_Type);
}
-
/* Per Element Get/Set
* ******************* */
@@ -928,46 +1016,42 @@ void BPy_BM_init_types_customdata(void)
*/
static void *bpy_bmlayeritem_ptr_get(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer)
{
- void *value;
- BMElem *ele = py_ele->ele;
- CustomData *data;
-
- /* error checking */
- if (UNLIKELY(!BPy_BMLayerItem_Check(py_layer))) {
- PyErr_SetString(PyExc_AttributeError,
- "BMElem[key]: invalid key, must be a BMLayerItem");
- return NULL;
- }
- else if (UNLIKELY(py_ele->bm != py_layer->bm)) {
- PyErr_SetString(PyExc_ValueError,
- "BMElem[layer]: layer is from another mesh");
- return NULL;
- }
- else if (UNLIKELY(ele->head.htype != py_layer->htype)) {
- char namestr_1[32], namestr_2[32];
- PyErr_Format(PyExc_ValueError,
- "Layer/Element type mismatch, expected %.200s got layer type %.200s",
- BPy_BMElem_StringFromHType_ex(ele->head.htype, namestr_1),
- BPy_BMElem_StringFromHType_ex(py_layer->htype, namestr_2));
- return NULL;
- }
-
- data = bpy_bm_customdata_get(py_layer->bm, py_layer->htype);
-
- value = CustomData_bmesh_get_n(data, ele->head.data, py_layer->type, py_layer->index);
-
- if (UNLIKELY(value == NULL)) {
- /* this should be fairly unlikely but possible if layers move about after we get them */
- PyErr_SetString(PyExc_KeyError,
- "BMElem[key]: layer not found");
- return NULL;
- }
- else {
- return value;
- }
+ void *value;
+ BMElem *ele = py_ele->ele;
+ CustomData *data;
+
+ /* error checking */
+ if (UNLIKELY(!BPy_BMLayerItem_Check(py_layer))) {
+ PyErr_SetString(PyExc_AttributeError, "BMElem[key]: invalid key, must be a BMLayerItem");
+ return NULL;
+ }
+ else if (UNLIKELY(py_ele->bm != py_layer->bm)) {
+ PyErr_SetString(PyExc_ValueError, "BMElem[layer]: layer is from another mesh");
+ return NULL;
+ }
+ else if (UNLIKELY(ele->head.htype != py_layer->htype)) {
+ char namestr_1[32], namestr_2[32];
+ PyErr_Format(PyExc_ValueError,
+ "Layer/Element type mismatch, expected %.200s got layer type %.200s",
+ BPy_BMElem_StringFromHType_ex(ele->head.htype, namestr_1),
+ BPy_BMElem_StringFromHType_ex(py_layer->htype, namestr_2));
+ return NULL;
+ }
+
+ data = bpy_bm_customdata_get(py_layer->bm, py_layer->htype);
+
+ value = CustomData_bmesh_get_n(data, ele->head.data, py_layer->type, py_layer->index);
+
+ if (UNLIKELY(value == NULL)) {
+ /* this should be fairly unlikely but possible if layers move about after we get them */
+ PyErr_SetString(PyExc_KeyError, "BMElem[key]: layer not found");
+ return NULL;
+ }
+ else {
+ return value;
+ }
}
-
/**
*\brief BMElem.__getitem__()
*
@@ -977,194 +1061,176 @@ static void *bpy_bmlayeritem_ptr_get(BPy_BMElem *py_ele, BPy_BMLayerItem *py_lay
*/
PyObject *BPy_BMLayerItem_GetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer)
{
- void *value = bpy_bmlayeritem_ptr_get(py_ele, py_layer);
- PyObject *ret;
-
- if (UNLIKELY(value == NULL)) {
- return NULL;
- }
-
- switch (py_layer->type) {
- case CD_MDEFORMVERT:
- {
- ret = BPy_BMDeformVert_CreatePyObject(value);
- break;
- }
- case CD_PROP_FLT:
- case CD_PAINT_MASK:
- {
- ret = PyFloat_FromDouble(*(float *)value);
- break;
- }
- case CD_PROP_INT:
- case CD_FACEMAP:
- {
- ret = PyLong_FromLong(*(int *)value);
- break;
- }
- case CD_PROP_STR:
- {
- MStringProperty *mstring = value;
- ret = PyBytes_FromStringAndSize(mstring->s, mstring->s_len);
- break;
- }
- case CD_MLOOPUV:
- {
- ret = BPy_BMLoopUV_CreatePyObject(value);
- break;
- }
- case CD_MLOOPCOL:
- {
- ret = BPy_BMLoopColor_CreatePyObject(value);
- break;
- }
- case CD_SHAPEKEY:
- {
- ret = Vector_CreatePyObject_wrap((float *)value, 3, NULL);
- break;
- }
- case CD_BWEIGHT:
- {
- ret = PyFloat_FromDouble(*(float *)value);
- break;
- }
- case CD_CREASE:
- {
- ret = PyFloat_FromDouble(*(float *)value);
- break;
- }
- case CD_MVERT_SKIN:
- {
- ret = BPy_BMVertSkin_CreatePyObject(value);
- break;
- }
- default:
- {
- ret = Py_NotImplemented; /* TODO */
- Py_INCREF(ret);
- break;
- }
- }
-
- return ret;
+ void *value = bpy_bmlayeritem_ptr_get(py_ele, py_layer);
+ PyObject *ret;
+
+ if (UNLIKELY(value == NULL)) {
+ return NULL;
+ }
+
+ switch (py_layer->type) {
+ case CD_MDEFORMVERT: {
+ ret = BPy_BMDeformVert_CreatePyObject(value);
+ break;
+ }
+ case CD_PROP_FLT:
+ case CD_PAINT_MASK: {
+ ret = PyFloat_FromDouble(*(float *)value);
+ break;
+ }
+ case CD_PROP_INT:
+ case CD_FACEMAP: {
+ ret = PyLong_FromLong(*(int *)value);
+ break;
+ }
+ case CD_PROP_STR: {
+ MStringProperty *mstring = value;
+ ret = PyBytes_FromStringAndSize(mstring->s, mstring->s_len);
+ break;
+ }
+ case CD_MLOOPUV: {
+ ret = BPy_BMLoopUV_CreatePyObject(value);
+ break;
+ }
+ case CD_MLOOPCOL: {
+ ret = BPy_BMLoopColor_CreatePyObject(value);
+ break;
+ }
+ case CD_SHAPEKEY: {
+ ret = Vector_CreatePyObject_wrap((float *)value, 3, NULL);
+ break;
+ }
+ case CD_BWEIGHT: {
+ ret = PyFloat_FromDouble(*(float *)value);
+ break;
+ }
+ case CD_CREASE: {
+ ret = PyFloat_FromDouble(*(float *)value);
+ break;
+ }
+ case CD_MVERT_SKIN: {
+ ret = BPy_BMVertSkin_CreatePyObject(value);
+ break;
+ }
+ default: {
+ ret = Py_NotImplemented; /* TODO */
+ Py_INCREF(ret);
+ break;
+ }
+ }
+
+ return ret;
}
int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObject *py_value)
{
- int ret = 0;
- void *value = bpy_bmlayeritem_ptr_get(py_ele, py_layer);
-
- if (UNLIKELY(value == NULL)) {
- return -1;
- }
-
- switch (py_layer->type) {
- case CD_MDEFORMVERT:
- {
- ret = BPy_BMDeformVert_AssignPyObject(value, py_value);
- break;
- }
- case CD_PROP_FLT:
- case CD_PAINT_MASK:
- {
- float tmp_val = PyFloat_AsDouble(py_value);
- if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
- PyErr_Format(PyExc_TypeError, "expected a float, not a %.200s", Py_TYPE(py_value)->tp_name);
- ret = -1;
- }
- else {
- *(float *)value = tmp_val;
- }
- break;
- }
- case CD_PROP_INT:
- case CD_FACEMAP:
- {
- int tmp_val = PyC_Long_AsI32(py_value);
- if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
- /* error is set */
- ret = -1;
- }
- else {
- *(int *)value = tmp_val;
- }
- break;
- }
- case CD_PROP_STR:
- {
- MStringProperty *mstring = value;
- char *tmp_val;
- Py_ssize_t tmp_val_len;
- if (UNLIKELY(PyBytes_AsStringAndSize(py_value, &tmp_val, &tmp_val_len) == -1)) {
- PyErr_Format(PyExc_TypeError, "expected bytes, not a %.200s", Py_TYPE(py_value)->tp_name);
- ret = -1;
- }
- else {
- if (tmp_val_len > sizeof(mstring->s)) {
- tmp_val_len = sizeof(mstring->s);
- }
- memcpy(mstring->s, tmp_val, tmp_val_len);
- mstring->s_len = tmp_val_len;
- }
- break;
- }
- case CD_MLOOPUV:
- {
- ret = BPy_BMLoopUV_AssignPyObject(value, py_value);
- break;
- }
- case CD_MLOOPCOL:
- {
- ret = BPy_BMLoopColor_AssignPyObject(value, py_value);
- break;
- }
- case CD_SHAPEKEY:
- {
- float tmp_val[3];
- if (UNLIKELY(mathutils_array_parse(tmp_val, 3, 3, py_value, "BMVert[shape] = value") == -1)) {
- ret = -1;
- }
- else {
- copy_v3_v3((float *)value, tmp_val);
- }
- break;
- }
- case CD_BWEIGHT:
- {
- float tmp_val = PyFloat_AsDouble(py_value);
- if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
- PyErr_Format(PyExc_TypeError, "expected a float, not a %.200s", Py_TYPE(py_value)->tp_name);
- ret = -1;
- }
- else {
- *(float *)value = clamp_f(tmp_val, 0.0f, 1.0f);
- }
- break;
- }
- case CD_CREASE:
- {
- float tmp_val = PyFloat_AsDouble(py_value);
- if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
- PyErr_Format(PyExc_TypeError, "expected a float, not a %.200s", Py_TYPE(py_value)->tp_name);
- ret = -1;
- }
- else {
- *(float *)value = clamp_f(tmp_val, 0.0f, 1.0f);
- }
- break;
- }
- case CD_MVERT_SKIN:
- {
- ret = BPy_BMVertSkin_AssignPyObject(value, py_value);
- break;
- }
- default:
- {
- PyErr_SetString(PyExc_AttributeError, "readonly / unsupported type");
- ret = -1;
- break;
- }
- }
-
- return ret;
+ int ret = 0;
+ void *value = bpy_bmlayeritem_ptr_get(py_ele, py_layer);
+
+ if (UNLIKELY(value == NULL)) {
+ return -1;
+ }
+
+ switch (py_layer->type) {
+ case CD_MDEFORMVERT: {
+ ret = BPy_BMDeformVert_AssignPyObject(value, py_value);
+ break;
+ }
+ case CD_PROP_FLT:
+ case CD_PAINT_MASK: {
+ float tmp_val = PyFloat_AsDouble(py_value);
+ if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
+ PyErr_Format(
+ PyExc_TypeError, "expected a float, not a %.200s", Py_TYPE(py_value)->tp_name);
+ ret = -1;
+ }
+ else {
+ *(float *)value = tmp_val;
+ }
+ break;
+ }
+ case CD_PROP_INT:
+ case CD_FACEMAP: {
+ int tmp_val = PyC_Long_AsI32(py_value);
+ if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
+ /* error is set */
+ ret = -1;
+ }
+ else {
+ *(int *)value = tmp_val;
+ }
+ break;
+ }
+ case CD_PROP_STR: {
+ MStringProperty *mstring = value;
+ char *tmp_val;
+ Py_ssize_t tmp_val_len;
+ if (UNLIKELY(PyBytes_AsStringAndSize(py_value, &tmp_val, &tmp_val_len) == -1)) {
+ PyErr_Format(PyExc_TypeError, "expected bytes, not a %.200s", Py_TYPE(py_value)->tp_name);
+ ret = -1;
+ }
+ else {
+ if (tmp_val_len > sizeof(mstring->s)) {
+ tmp_val_len = sizeof(mstring->s);
+ }
+ memcpy(mstring->s, tmp_val, tmp_val_len);
+ mstring->s_len = tmp_val_len;
+ }
+ break;
+ }
+ case CD_MLOOPUV: {
+ ret = BPy_BMLoopUV_AssignPyObject(value, py_value);
+ break;
+ }
+ case CD_MLOOPCOL: {
+ ret = BPy_BMLoopColor_AssignPyObject(value, py_value);
+ break;
+ }
+ case CD_SHAPEKEY: {
+ float tmp_val[3];
+ if (UNLIKELY(mathutils_array_parse(tmp_val, 3, 3, py_value, "BMVert[shape] = value") ==
+ -1)) {
+ ret = -1;
+ }
+ else {
+ copy_v3_v3((float *)value, tmp_val);
+ }
+ break;
+ }
+ case CD_BWEIGHT: {
+ float tmp_val = PyFloat_AsDouble(py_value);
+ if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
+ PyErr_Format(
+ PyExc_TypeError, "expected a float, not a %.200s", Py_TYPE(py_value)->tp_name);
+ ret = -1;
+ }
+ else {
+ *(float *)value = clamp_f(tmp_val, 0.0f, 1.0f);
+ }
+ break;
+ }
+ case CD_CREASE: {
+ float tmp_val = PyFloat_AsDouble(py_value);
+ if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
+ PyErr_Format(
+ PyExc_TypeError, "expected a float, not a %.200s", Py_TYPE(py_value)->tp_name);
+ ret = -1;
+ }
+ else {
+ *(float *)value = clamp_f(tmp_val, 0.0f, 1.0f);
+ }
+ break;
+ }
+ case CD_MVERT_SKIN: {
+ ret = BPy_BMVertSkin_AssignPyObject(value, py_value);
+ break;
+ }
+ default: {
+ PyErr_SetString(PyExc_AttributeError, "readonly / unsupported type");
+ ret = -1;
+ break;
+ }
+ }
+
+ return ret;
}
diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.h b/source/blender/python/bmesh/bmesh_py_types_customdata.h
index 39cac7885cd..95836707e3d 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.h
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.h
@@ -33,32 +33,29 @@ extern PyTypeObject BPy_BMLayerAccessLoop_Type;
extern PyTypeObject BPy_BMLayerCollection_Type;
extern PyTypeObject BPy_BMLayerItem_Type;
-#define BPy_BMLayerAccess_Check(v) (Py_TYPE(v) == &BPy_BMLayerAccess_Type)
-#define BPy_BMLayerCollection_Check(v) (Py_TYPE(v) == &BPy_BMLayerCollection_Type)
-#define BPy_BMLayerItem_Check(v) (Py_TYPE(v) == &BPy_BMLayerItem_Type)
+#define BPy_BMLayerAccess_Check(v) (Py_TYPE(v) == &BPy_BMLayerAccess_Type)
+#define BPy_BMLayerCollection_Check(v) (Py_TYPE(v) == &BPy_BMLayerCollection_Type)
+#define BPy_BMLayerItem_Check(v) (Py_TYPE(v) == &BPy_BMLayerItem_Type)
/* all layers for vert/edge/face/loop */
typedef struct BPy_BMLayerAccess {
- PyObject_VAR_HEAD
- struct BMesh *bm; /* keep first */
- char htype;
+ PyObject_VAR_HEAD struct BMesh *bm; /* keep first */
+ char htype;
} BPy_BMLayerAccess;
/* access different layer types deform/uv/vertexcolor */
typedef struct BPy_BMLayerCollection {
- PyObject_VAR_HEAD
- struct BMesh *bm; /* keep first */
- char htype;
- int type; /* customdata type - CD_XXX */
+ PyObject_VAR_HEAD struct BMesh *bm; /* keep first */
+ char htype;
+ int type; /* customdata type - CD_XXX */
} BPy_BMLayerCollection;
/* access a specific layer directly */
typedef struct BPy_BMLayerItem {
- PyObject_VAR_HEAD
- struct BMesh *bm; /* keep first */
- char htype;
- int type; /* customdata type - CD_XXX */
- int index; /* index of this layer type */
+ PyObject_VAR_HEAD struct BMesh *bm; /* keep first */
+ char htype;
+ int type; /* customdata type - CD_XXX */
+ int index; /* index of this layer type */
} BPy_BMLayerItem;
PyObject *BPy_BMLayerAccess_CreatePyObject(BMesh *bm, const char htype);
@@ -69,7 +66,6 @@ void BPy_BM_init_types_customdata(void);
/* __getitem__ / __setitem__ */
PyObject *BPy_BMLayerItem_GetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer);
-int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObject *value);
-
+int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObject *value);
#endif /* __BMESH_PY_TYPES_CUSTOMDATA_H__ */
diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
index 604b55de6e6..34a4ec3b1ed 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
@@ -45,111 +45,118 @@
/* Mesh Loop UV
* ************ */
-#define BPy_BMLoopUV_Check(v) (Py_TYPE(v) == &BPy_BMLoopUV_Type)
+#define BPy_BMLoopUV_Check(v) (Py_TYPE(v) == &BPy_BMLoopUV_Type)
typedef struct BPy_BMLoopUV {
- PyObject_VAR_HEAD
- MLoopUV *data;
+ PyObject_VAR_HEAD MLoopUV *data;
} BPy_BMLoopUV;
PyDoc_STRVAR(bpy_bmloopuv_uv_doc,
-"Loops UV (as a 2D Vector).\n\n:type: :class:`mathutils.Vector`"
-);
+ "Loops UV (as a 2D Vector).\n\n:type: :class:`mathutils.Vector`");
static PyObject *bpy_bmloopuv_uv_get(BPy_BMLoopUV *self, void *UNUSED(closure))
{
- return Vector_CreatePyObject_wrap(self->data->uv, 2, NULL);
+ return Vector_CreatePyObject_wrap(self->data->uv, 2, NULL);
}
static int bpy_bmloopuv_uv_set(BPy_BMLoopUV *self, PyObject *value, void *UNUSED(closure))
{
- float tvec[2];
- if (mathutils_array_parse(tvec, 2, 2, value, "BMLoopUV.uv") != -1) {
- copy_v2_v2(self->data->uv, tvec);
- return 0;
- }
- else {
- return -1;
- }
+ float tvec[2];
+ if (mathutils_array_parse(tvec, 2, 2, value, "BMLoopUV.uv") != -1) {
+ copy_v2_v2(self->data->uv, tvec);
+ return 0;
+ }
+ else {
+ return -1;
+ }
}
-PyDoc_STRVAR(bpy_bmloopuv_flag__pin_uv_doc,
-"UV pin state.\n\n:type: boolean"
-);
-PyDoc_STRVAR(bpy_bmloopuv_flag__select_doc,
-"UV select state.\n\n:type: boolean"
-);
-PyDoc_STRVAR(bpy_bmloopuv_flag__select_edge_doc,
-"UV edge select state.\n\n:type: boolean"
-);
-
+PyDoc_STRVAR(bpy_bmloopuv_flag__pin_uv_doc, "UV pin state.\n\n:type: boolean");
+PyDoc_STRVAR(bpy_bmloopuv_flag__select_doc, "UV select state.\n\n:type: boolean");
+PyDoc_STRVAR(bpy_bmloopuv_flag__select_edge_doc, "UV edge select state.\n\n:type: boolean");
static PyObject *bpy_bmloopuv_flag_get(BPy_BMLoopUV *self, void *flag_p)
{
- const int flag = POINTER_AS_INT(flag_p);
- return PyBool_FromLong(self->data->flag & flag);
+ const int flag = POINTER_AS_INT(flag_p);
+ return PyBool_FromLong(self->data->flag & flag);
}
static int bpy_bmloopuv_flag_set(BPy_BMLoopUV *self, PyObject *value, void *flag_p)
{
- const int flag = POINTER_AS_INT(flag_p);
+ const int flag = POINTER_AS_INT(flag_p);
- switch (PyC_Long_AsBool(value)) {
- case true:
- self->data->flag |= flag;
- return 0;
- case false:
- self->data->flag &= ~flag;
- return 0;
- default:
- /* error is set */
- return -1;
- }
+ switch (PyC_Long_AsBool(value)) {
+ case true:
+ self->data->flag |= flag;
+ return 0;
+ case false:
+ self->data->flag &= ~flag;
+ return 0;
+ default:
+ /* error is set */
+ return -1;
+ }
}
static PyGetSetDef bpy_bmloopuv_getseters[] = {
- /* attributes match rna_def_mloopuv */
- {(char *)"uv", (getter)bpy_bmloopuv_uv_get, (setter)bpy_bmloopuv_uv_set, (char *)bpy_bmloopuv_uv_doc, NULL},
- {(char *)"pin_uv", (getter)bpy_bmloopuv_flag_get, (setter)bpy_bmloopuv_flag_set, (char *)bpy_bmloopuv_flag__pin_uv_doc, (void *)MLOOPUV_PINNED},
- {(char *)"select", (getter)bpy_bmloopuv_flag_get, (setter)bpy_bmloopuv_flag_set, (char *)bpy_bmloopuv_flag__select_doc, (void *)MLOOPUV_VERTSEL},
- {(char *)"select_edge", (getter)bpy_bmloopuv_flag_get, (setter)bpy_bmloopuv_flag_set, (char *)bpy_bmloopuv_flag__select_edge_doc, (void *)MLOOPUV_EDGESEL},
-
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ /* attributes match rna_def_mloopuv */
+ {(char *)"uv",
+ (getter)bpy_bmloopuv_uv_get,
+ (setter)bpy_bmloopuv_uv_set,
+ (char *)bpy_bmloopuv_uv_doc,
+ NULL},
+ {(char *)"pin_uv",
+ (getter)bpy_bmloopuv_flag_get,
+ (setter)bpy_bmloopuv_flag_set,
+ (char *)bpy_bmloopuv_flag__pin_uv_doc,
+ (void *)MLOOPUV_PINNED},
+ {(char *)"select",
+ (getter)bpy_bmloopuv_flag_get,
+ (setter)bpy_bmloopuv_flag_set,
+ (char *)bpy_bmloopuv_flag__select_doc,
+ (void *)MLOOPUV_VERTSEL},
+ {(char *)"select_edge",
+ (getter)bpy_bmloopuv_flag_get,
+ (setter)bpy_bmloopuv_flag_set,
+ (char *)bpy_bmloopuv_flag__select_edge_doc,
+ (void *)MLOOPUV_EDGESEL},
+
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
PyTypeObject BPy_BMLoopUV_Type; /* bm.loops.layers.uv.active */
static void bm_init_types_bmloopuv(void)
{
- BPy_BMLoopUV_Type.tp_basicsize = sizeof(BPy_BMLoopUV);
+ BPy_BMLoopUV_Type.tp_basicsize = sizeof(BPy_BMLoopUV);
- BPy_BMLoopUV_Type.tp_name = "BMLoopUV";
+ BPy_BMLoopUV_Type.tp_name = "BMLoopUV";
- BPy_BMLoopUV_Type.tp_doc = NULL; // todo
+ BPy_BMLoopUV_Type.tp_doc = NULL; // todo
- BPy_BMLoopUV_Type.tp_getset = bpy_bmloopuv_getseters;
+ BPy_BMLoopUV_Type.tp_getset = bpy_bmloopuv_getseters;
- BPy_BMLoopUV_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMLoopUV_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- PyType_Ready(&BPy_BMLoopUV_Type);
+ PyType_Ready(&BPy_BMLoopUV_Type);
}
int BPy_BMLoopUV_AssignPyObject(struct MLoopUV *mloopuv, PyObject *value)
{
- if (UNLIKELY(!BPy_BMLoopUV_Check(value))) {
- PyErr_Format(PyExc_TypeError, "expected BMLoopUV, not a %.200s", Py_TYPE(value)->tp_name);
- return -1;
- }
- else {
- *((MLoopUV *)mloopuv) = *(((BPy_BMLoopUV *)value)->data);
- return 0;
- }
+ if (UNLIKELY(!BPy_BMLoopUV_Check(value))) {
+ PyErr_Format(PyExc_TypeError, "expected BMLoopUV, not a %.200s", Py_TYPE(value)->tp_name);
+ return -1;
+ }
+ else {
+ *((MLoopUV *)mloopuv) = *(((BPy_BMLoopUV *)value)->data);
+ return 0;
+ }
}
PyObject *BPy_BMLoopUV_CreatePyObject(struct MLoopUV *mloopuv)
{
- BPy_BMLoopUV *self = PyObject_New(BPy_BMLoopUV, &BPy_BMLoopUV_Type);
- self->data = mloopuv;
- return (PyObject *)self;
+ BPy_BMLoopUV *self = PyObject_New(BPy_BMLoopUV, &BPy_BMLoopUV_Type);
+ self->data = mloopuv;
+ return (PyObject *)self;
}
/* --- End Mesh Loop UV --- */
@@ -157,106 +164,114 @@ PyObject *BPy_BMLoopUV_CreatePyObject(struct MLoopUV *mloopuv)
/* Mesh Vert Skin
* ************ */
-#define BPy_BMVertSkin_Check(v) (Py_TYPE(v) == &BPy_BMVertSkin_Type)
+#define BPy_BMVertSkin_Check(v) (Py_TYPE(v) == &BPy_BMVertSkin_Type)
typedef struct BPy_BMVertSkin {
- PyObject_VAR_HEAD
- MVertSkin *data;
+ PyObject_VAR_HEAD MVertSkin *data;
} BPy_BMVertSkin;
PyDoc_STRVAR(bpy_bmvertskin_radius_doc,
-"Vert skin radii (as a 2D Vector).\n\n:type: :class:`mathutils.Vector`"
-);
+ "Vert skin radii (as a 2D Vector).\n\n:type: :class:`mathutils.Vector`");
static PyObject *bpy_bmvertskin_radius_get(BPy_BMVertSkin *self, void *UNUSED(closure))
{
- return Vector_CreatePyObject_wrap(self->data->radius, 2, NULL);
+ return Vector_CreatePyObject_wrap(self->data->radius, 2, NULL);
}
static int bpy_bmvertskin_radius_set(BPy_BMVertSkin *self, PyObject *value, void *UNUSED(closure))
{
- float tvec[2];
- if (mathutils_array_parse(tvec, 2, 2, value, "BMVertSkin.radius") != -1) {
- copy_v2_v2(self->data->radius, tvec);
- return 0;
- }
- else {
- return -1;
- }
+ float tvec[2];
+ if (mathutils_array_parse(tvec, 2, 2, value, "BMVertSkin.radius") != -1) {
+ copy_v2_v2(self->data->radius, tvec);
+ return 0;
+ }
+ else {
+ return -1;
+ }
}
PyDoc_STRVAR(bpy_bmvertskin_flag__use_root_doc,
-"Use as root vertex. Setting this flag does not clear other roots in the same mesh island.\n\n:type: boolean"
-);
-PyDoc_STRVAR(bpy_bmvertskin_flag__use_loose_doc,
-"Use loose vertex.\n\n:type: boolean"
-);
+ "Use as root vertex. Setting this flag does not clear other roots in the same mesh "
+ "island.\n\n:type: boolean");
+PyDoc_STRVAR(bpy_bmvertskin_flag__use_loose_doc, "Use loose vertex.\n\n:type: boolean");
static PyObject *bpy_bmvertskin_flag_get(BPy_BMVertSkin *self, void *flag_p)
{
- const int flag = POINTER_AS_INT(flag_p);
- return PyBool_FromLong(self->data->flag & flag);
+ const int flag = POINTER_AS_INT(flag_p);
+ return PyBool_FromLong(self->data->flag & flag);
}
static int bpy_bmvertskin_flag_set(BPy_BMVertSkin *self, PyObject *value, void *flag_p)
{
- const int flag = POINTER_AS_INT(flag_p);
+ const int flag = POINTER_AS_INT(flag_p);
- switch (PyC_Long_AsBool(value)) {
- case true:
- self->data->flag |= flag;
- return 0;
- case false:
- self->data->flag &= ~flag;
- return 0;
- default:
- /* error is set */
- return -1;
- }
+ switch (PyC_Long_AsBool(value)) {
+ case true:
+ self->data->flag |= flag;
+ return 0;
+ case false:
+ self->data->flag &= ~flag;
+ return 0;
+ default:
+ /* error is set */
+ return -1;
+ }
}
static PyGetSetDef bpy_bmvertskin_getseters[] = {
- /* attributes match rna_mesh_gen */
- {(char *)"radius", (getter)bpy_bmvertskin_radius_get, (setter)bpy_bmvertskin_radius_set, (char *)bpy_bmvertskin_radius_doc, NULL},
- {(char *)"use_root", (getter)bpy_bmvertskin_flag_get, (setter)bpy_bmvertskin_flag_set, (char *)bpy_bmvertskin_flag__use_root_doc, (void *)MVERT_SKIN_ROOT},
- {(char *)"use_loose", (getter)bpy_bmvertskin_flag_get, (setter)bpy_bmvertskin_flag_set, (char *)bpy_bmvertskin_flag__use_loose_doc, (void *)MVERT_SKIN_LOOSE},
-
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ /* attributes match rna_mesh_gen */
+ {(char *)"radius",
+ (getter)bpy_bmvertskin_radius_get,
+ (setter)bpy_bmvertskin_radius_set,
+ (char *)bpy_bmvertskin_radius_doc,
+ NULL},
+ {(char *)"use_root",
+ (getter)bpy_bmvertskin_flag_get,
+ (setter)bpy_bmvertskin_flag_set,
+ (char *)bpy_bmvertskin_flag__use_root_doc,
+ (void *)MVERT_SKIN_ROOT},
+ {(char *)"use_loose",
+ (getter)bpy_bmvertskin_flag_get,
+ (setter)bpy_bmvertskin_flag_set,
+ (char *)bpy_bmvertskin_flag__use_loose_doc,
+ (void *)MVERT_SKIN_LOOSE},
+
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyTypeObject BPy_BMVertSkin_Type; /* bm.loops.layers.skin.active */
static void bm_init_types_bmvertskin(void)
{
- BPy_BMVertSkin_Type.tp_basicsize = sizeof(BPy_BMVertSkin);
+ BPy_BMVertSkin_Type.tp_basicsize = sizeof(BPy_BMVertSkin);
- BPy_BMVertSkin_Type.tp_name = "BMVertSkin";
+ BPy_BMVertSkin_Type.tp_name = "BMVertSkin";
- BPy_BMVertSkin_Type.tp_doc = NULL; // todo
+ BPy_BMVertSkin_Type.tp_doc = NULL; // todo
- BPy_BMVertSkin_Type.tp_getset = bpy_bmvertskin_getseters;
+ BPy_BMVertSkin_Type.tp_getset = bpy_bmvertskin_getseters;
- BPy_BMVertSkin_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMVertSkin_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- PyType_Ready(&BPy_BMVertSkin_Type);
+ PyType_Ready(&BPy_BMVertSkin_Type);
}
int BPy_BMVertSkin_AssignPyObject(struct MVertSkin *mvertskin, PyObject *value)
{
- if (UNLIKELY(!BPy_BMVertSkin_Check(value))) {
- PyErr_Format(PyExc_TypeError, "expected BMVertSkin, not a %.200s", Py_TYPE(value)->tp_name);
- return -1;
- }
- else {
- *((MVertSkin *)mvertskin) = *(((BPy_BMVertSkin *)value)->data);
- return 0;
- }
+ if (UNLIKELY(!BPy_BMVertSkin_Check(value))) {
+ PyErr_Format(PyExc_TypeError, "expected BMVertSkin, not a %.200s", Py_TYPE(value)->tp_name);
+ return -1;
+ }
+ else {
+ *((MVertSkin *)mvertskin) = *(((BPy_BMVertSkin *)value)->data);
+ return 0;
+ }
}
PyObject *BPy_BMVertSkin_CreatePyObject(struct MVertSkin *mvertskin)
{
- BPy_BMVertSkin *self = PyObject_New(BPy_BMVertSkin, &BPy_BMVertSkin_Type);
- self->data = mvertskin;
- return (PyObject *)self;
+ BPy_BMVertSkin *self = PyObject_New(BPy_BMVertSkin, &BPy_BMVertSkin_Type);
+ self->data = mvertskin;
+ return (PyObject *)self;
}
/* --- End Mesh Vert Skin --- */
@@ -268,101 +283,100 @@ PyObject *BPy_BMVertSkin_CreatePyObject(struct MVertSkin *mvertskin)
* color which uses mathutils callbacks for mathutils.Color
*/
-#define MLOOPCOL_FROM_CAPSULE(color_capsule) \
- ((MLoopCol *)PyCapsule_GetPointer(color_capsule, NULL))
+#define MLOOPCOL_FROM_CAPSULE(color_capsule) \
+ ((MLoopCol *)PyCapsule_GetPointer(color_capsule, NULL))
static void mloopcol_to_float(const MLoopCol *mloopcol, float r_col[3])
{
- rgba_uchar_to_float(r_col, (const unsigned char *)&mloopcol->r);
+ rgba_uchar_to_float(r_col, (const unsigned char *)&mloopcol->r);
}
static void mloopcol_from_float(MLoopCol *mloopcol, const float col[3])
{
- rgba_float_to_uchar((unsigned char *)&mloopcol->r, col);
+ rgba_float_to_uchar((unsigned char *)&mloopcol->r, col);
}
static unsigned char mathutils_bmloopcol_cb_index = -1;
static int mathutils_bmloopcol_check(BaseMathObject *UNUSED(bmo))
{
- /* always ok */
- return 0;
+ /* always ok */
+ return 0;
}
static int mathutils_bmloopcol_get(BaseMathObject *bmo, int UNUSED(subtype))
{
- MLoopCol *mloopcol = MLOOPCOL_FROM_CAPSULE(bmo->cb_user);
- mloopcol_to_float(mloopcol, bmo->data);
- return 0;
+ MLoopCol *mloopcol = MLOOPCOL_FROM_CAPSULE(bmo->cb_user);
+ mloopcol_to_float(mloopcol, bmo->data);
+ return 0;
}
static int mathutils_bmloopcol_set(BaseMathObject *bmo, int UNUSED(subtype))
{
- MLoopCol *mloopcol = MLOOPCOL_FROM_CAPSULE(bmo->cb_user);
- mloopcol_from_float(mloopcol, bmo->data);
- return 0;
+ MLoopCol *mloopcol = MLOOPCOL_FROM_CAPSULE(bmo->cb_user);
+ mloopcol_from_float(mloopcol, bmo->data);
+ return 0;
}
static int mathutils_bmloopcol_get_index(BaseMathObject *bmo, int subtype, int UNUSED(index))
{
- /* lazy, avoid repeteing the case statement */
- if (mathutils_bmloopcol_get(bmo, subtype) == -1) {
- return -1;
- }
- return 0;
+ /* lazy, avoid repeteing the case statement */
+ if (mathutils_bmloopcol_get(bmo, subtype) == -1) {
+ return -1;
+ }
+ return 0;
}
static int mathutils_bmloopcol_set_index(BaseMathObject *bmo, int subtype, int index)
{
- const float f = bmo->data[index];
+ const float f = bmo->data[index];
- /* lazy, avoid repeteing the case statement */
- if (mathutils_bmloopcol_get(bmo, subtype) == -1) {
- return -1;
- }
+ /* lazy, avoid repeteing the case statement */
+ if (mathutils_bmloopcol_get(bmo, subtype) == -1) {
+ return -1;
+ }
- bmo->data[index] = f;
- return mathutils_bmloopcol_set(bmo, subtype);
+ bmo->data[index] = f;
+ return mathutils_bmloopcol_set(bmo, subtype);
}
static Mathutils_Callback mathutils_bmloopcol_cb = {
- mathutils_bmloopcol_check,
- mathutils_bmloopcol_get,
- mathutils_bmloopcol_set,
- mathutils_bmloopcol_get_index,
- mathutils_bmloopcol_set_index,
+ mathutils_bmloopcol_check,
+ mathutils_bmloopcol_get,
+ mathutils_bmloopcol_set,
+ mathutils_bmloopcol_get_index,
+ mathutils_bmloopcol_set_index,
};
static void bm_init_types_bmloopcol(void)
{
- /* pass */
- mathutils_bmloopcol_cb_index = Mathutils_RegisterCallback(&mathutils_bmloopcol_cb);
+ /* pass */
+ mathutils_bmloopcol_cb_index = Mathutils_RegisterCallback(&mathutils_bmloopcol_cb);
}
int BPy_BMLoopColor_AssignPyObject(struct MLoopCol *mloopcol, PyObject *value)
{
- float tvec[4];
- if (mathutils_array_parse(tvec, 4, 4, value, "BMLoopCol") != -1) {
- mloopcol_from_float(mloopcol, tvec);
- return 0;
- }
- else {
- return -1;
- }
+ float tvec[4];
+ if (mathutils_array_parse(tvec, 4, 4, value, "BMLoopCol") != -1) {
+ mloopcol_from_float(mloopcol, tvec);
+ return 0;
+ }
+ else {
+ return -1;
+ }
}
PyObject *BPy_BMLoopColor_CreatePyObject(struct MLoopCol *data)
{
- PyObject *color_capsule;
- color_capsule = PyCapsule_New(data, NULL, NULL);
- return Vector_CreatePyObject_cb(color_capsule, 4, mathutils_bmloopcol_cb_index, 0);
+ PyObject *color_capsule;
+ color_capsule = PyCapsule_New(data, NULL, NULL);
+ return Vector_CreatePyObject_cb(color_capsule, 4, mathutils_bmloopcol_cb_index, 0);
}
#undef MLOOPCOL_FROM_CAPSULE
/* --- End Mesh Loop Color --- */
-
/* Mesh Deform Vert
* **************** */
@@ -388,322 +402,310 @@ PyObject *BPy_BMLoopColor_CreatePyObject(struct MLoopCol *data)
* only expose as mapping, not a sequence.
*/
-#define BPy_BMDeformVert_Check(v) (Py_TYPE(v) == &BPy_BMDeformVert_Type)
+#define BPy_BMDeformVert_Check(v) (Py_TYPE(v) == &BPy_BMDeformVert_Type)
typedef struct BPy_BMDeformVert {
- PyObject_VAR_HEAD
- MDeformVert *data;
+ PyObject_VAR_HEAD MDeformVert *data;
} BPy_BMDeformVert;
-
/* Mapping Protocols
* ================= */
static int bpy_bmdeformvert_len(BPy_BMDeformVert *self)
{
- return self->data->totweight;
+ return self->data->totweight;
}
static PyObject *bpy_bmdeformvert_subscript(BPy_BMDeformVert *self, PyObject *key)
{
- if (PyIndex_Check(key)) {
- int i;
- i = PyNumber_AsSsize_t(key, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred()) {
- return NULL;
- }
- else {
- MDeformWeight *dw = defvert_find_index(self->data, i);
-
- if (dw == NULL) {
- PyErr_SetString(PyExc_KeyError, "BMDeformVert[key] = x: "
- "key not found");
- return NULL;
- }
- else {
- return PyFloat_FromDouble(dw->weight);
- }
- }
- }
- else {
- PyErr_Format(PyExc_TypeError,
- "BMDeformVert keys must be integers, not %.200s",
- Py_TYPE(key)->tp_name);
- return NULL;
- }
+ if (PyIndex_Check(key)) {
+ int i;
+ i = PyNumber_AsSsize_t(key, PyExc_IndexError);
+ if (i == -1 && PyErr_Occurred()) {
+ return NULL;
+ }
+ else {
+ MDeformWeight *dw = defvert_find_index(self->data, i);
+
+ if (dw == NULL) {
+ PyErr_SetString(PyExc_KeyError,
+ "BMDeformVert[key] = x: "
+ "key not found");
+ return NULL;
+ }
+ else {
+ return PyFloat_FromDouble(dw->weight);
+ }
+ }
+ }
+ else {
+ PyErr_Format(
+ PyExc_TypeError, "BMDeformVert keys must be integers, not %.200s", Py_TYPE(key)->tp_name);
+ return NULL;
+ }
}
static int bpy_bmdeformvert_ass_subscript(BPy_BMDeformVert *self, PyObject *key, PyObject *value)
{
- if (PyIndex_Check(key)) {
- int i;
-
- i = PyNumber_AsSsize_t(key, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred()) {
- return -1;
- }
-
- if (value) {
- /* dvert[group_index] = 0.5 */
- if (i < 0) {
- PyErr_SetString(PyExc_KeyError, "BMDeformVert[key] = x: "
- "weight keys can't be negative");
- return -1;
- }
- else {
- MDeformWeight *dw = defvert_verify_index(self->data, i);
- const float f = PyFloat_AsDouble(value);
- if (f == -1 && PyErr_Occurred()) { // parsed key not a number
- PyErr_SetString(PyExc_TypeError,
- "BMDeformVert[key] = x: "
- "assigned value not a number");
- return -1;
- }
-
- dw->weight = clamp_f(f, 0.0f, 1.0f);
- }
- }
- else {
- /* del dvert[group_index] */
- MDeformWeight *dw = defvert_find_index(self->data, i);
-
- if (dw == NULL) {
- PyErr_SetString(PyExc_KeyError, "del BMDeformVert[key]: "
- "key not found");
- }
- defvert_remove_group(self->data, dw);
- }
-
- return 0;
-
- }
- else {
- PyErr_Format(PyExc_TypeError,
- "BMDeformVert keys must be integers, not %.200s",
- Py_TYPE(key)->tp_name);
- return -1;
- }
+ if (PyIndex_Check(key)) {
+ int i;
+
+ i = PyNumber_AsSsize_t(key, PyExc_IndexError);
+ if (i == -1 && PyErr_Occurred()) {
+ return -1;
+ }
+
+ if (value) {
+ /* dvert[group_index] = 0.5 */
+ if (i < 0) {
+ PyErr_SetString(PyExc_KeyError,
+ "BMDeformVert[key] = x: "
+ "weight keys can't be negative");
+ return -1;
+ }
+ else {
+ MDeformWeight *dw = defvert_verify_index(self->data, i);
+ const float f = PyFloat_AsDouble(value);
+ if (f == -1 && PyErr_Occurred()) { // parsed key not a number
+ PyErr_SetString(PyExc_TypeError,
+ "BMDeformVert[key] = x: "
+ "assigned value not a number");
+ return -1;
+ }
+
+ dw->weight = clamp_f(f, 0.0f, 1.0f);
+ }
+ }
+ else {
+ /* del dvert[group_index] */
+ MDeformWeight *dw = defvert_find_index(self->data, i);
+
+ if (dw == NULL) {
+ PyErr_SetString(PyExc_KeyError,
+ "del BMDeformVert[key]: "
+ "key not found");
+ }
+ defvert_remove_group(self->data, dw);
+ }
+
+ return 0;
+ }
+ else {
+ PyErr_Format(
+ PyExc_TypeError, "BMDeformVert keys must be integers, not %.200s", Py_TYPE(key)->tp_name);
+ return -1;
+ }
}
static int bpy_bmdeformvert_contains(BPy_BMDeformVert *self, PyObject *value)
{
- const int key = PyLong_AsSsize_t(value);
+ const int key = PyLong_AsSsize_t(value);
- if (key == -1 && PyErr_Occurred()) {
- PyErr_SetString(PyExc_TypeError,
- "BMDeformVert.__contains__: expected an int");
- return -1;
- }
+ if (key == -1 && PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError, "BMDeformVert.__contains__: expected an int");
+ return -1;
+ }
- return (defvert_find_index(self->data, key) != NULL) ? 1 : 0;
+ return (defvert_find_index(self->data, key) != NULL) ? 1 : 0;
}
/* only defined for __contains__ */
static PySequenceMethods bpy_bmdeformvert_as_sequence = {
- (lenfunc)bpy_bmdeformvert_len, /* sq_length */
- NULL, /* sq_concat */
- NULL, /* sq_repeat */
-
- /* note: if this is set PySequence_Check() returns True,
- * but in this case we dont want to be treated as a seq */
- NULL, /* sq_item */
-
- NULL, /* sq_slice */
- NULL, /* sq_ass_item */
- NULL, /* *was* sq_ass_slice */
- (objobjproc)bpy_bmdeformvert_contains, /* sq_contains */
- (binaryfunc) NULL, /* sq_inplace_concat */
- (ssizeargfunc) NULL, /* sq_inplace_repeat */
+ (lenfunc)bpy_bmdeformvert_len, /* sq_length */
+ NULL, /* sq_concat */
+ NULL, /* sq_repeat */
+
+ /* note: if this is set PySequence_Check() returns True,
+ * but in this case we dont want to be treated as a seq */
+ NULL, /* sq_item */
+
+ NULL, /* sq_slice */
+ NULL, /* sq_ass_item */
+ NULL, /* *was* sq_ass_slice */
+ (objobjproc)bpy_bmdeformvert_contains, /* sq_contains */
+ (binaryfunc)NULL, /* sq_inplace_concat */
+ (ssizeargfunc)NULL, /* sq_inplace_repeat */
};
static PyMappingMethods bpy_bmdeformvert_as_mapping = {
- (lenfunc)bpy_bmdeformvert_len,
- (binaryfunc)bpy_bmdeformvert_subscript,
- (objobjargproc)bpy_bmdeformvert_ass_subscript,
+ (lenfunc)bpy_bmdeformvert_len,
+ (binaryfunc)bpy_bmdeformvert_subscript,
+ (objobjargproc)bpy_bmdeformvert_ass_subscript,
};
/* Methods
* ======= */
PyDoc_STRVAR(bpy_bmdeformvert_keys_doc,
-".. method:: keys()\n"
-"\n"
-" Return the group indices used by this vertex\n"
-" (matching pythons dict.keys() functionality).\n"
-"\n"
-" :return: the deform group this vertex uses\n"
-" :rtype: list of ints\n"
-);
+ ".. method:: keys()\n"
+ "\n"
+ " Return the group indices used by this vertex\n"
+ " (matching pythons dict.keys() functionality).\n"
+ "\n"
+ " :return: the deform group this vertex uses\n"
+ " :rtype: list of ints\n");
static PyObject *bpy_bmdeformvert_keys(BPy_BMDeformVert *self)
{
- PyObject *ret;
- int i;
- MDeformWeight *dw = self->data->dw;
+ PyObject *ret;
+ int i;
+ MDeformWeight *dw = self->data->dw;
- ret = PyList_New(self->data->totweight);
- for (i = 0; i < self->data->totweight; i++, dw++) {
- PyList_SET_ITEM(ret, i, PyLong_FromLong(dw->def_nr));
- }
+ ret = PyList_New(self->data->totweight);
+ for (i = 0; i < self->data->totweight; i++, dw++) {
+ PyList_SET_ITEM(ret, i, PyLong_FromLong(dw->def_nr));
+ }
- return ret;
+ return ret;
}
PyDoc_STRVAR(bpy_bmdeformvert_values_doc,
-".. method:: values()\n"
-"\n"
-" Return the weights of the deform vertex\n"
-" (matching pythons dict.values() functionality).\n"
-"\n"
-" :return: The weights that influence this vertex\n"
-" :rtype: list of floats\n"
-);
+ ".. method:: values()\n"
+ "\n"
+ " Return the weights of the deform vertex\n"
+ " (matching pythons dict.values() functionality).\n"
+ "\n"
+ " :return: The weights that influence this vertex\n"
+ " :rtype: list of floats\n");
static PyObject *bpy_bmdeformvert_values(BPy_BMDeformVert *self)
{
- PyObject *ret;
- int i;
- MDeformWeight *dw = self->data->dw;
+ PyObject *ret;
+ int i;
+ MDeformWeight *dw = self->data->dw;
- ret = PyList_New(self->data->totweight);
- for (i = 0; i < self->data->totweight; i++, dw++) {
- PyList_SET_ITEM(ret, i, PyFloat_FromDouble(dw->weight));
- }
+ ret = PyList_New(self->data->totweight);
+ for (i = 0; i < self->data->totweight; i++, dw++) {
+ PyList_SET_ITEM(ret, i, PyFloat_FromDouble(dw->weight));
+ }
- return ret;
+ return ret;
}
PyDoc_STRVAR(bpy_bmdeformvert_items_doc,
-".. method:: items()\n"
-"\n"
-" Return (group, weight) pairs for this vertex\n"
-" (matching pythons dict.items() functionality).\n"
-"\n"
-" :return: (key, value) pairs for each deform weight of this vertex.\n"
-" :rtype: list of tuples\n"
-);
+ ".. method:: items()\n"
+ "\n"
+ " Return (group, weight) pairs for this vertex\n"
+ " (matching pythons dict.items() functionality).\n"
+ "\n"
+ " :return: (key, value) pairs for each deform weight of this vertex.\n"
+ " :rtype: list of tuples\n");
static PyObject *bpy_bmdeformvert_items(BPy_BMDeformVert *self)
{
- PyObject *ret;
- PyObject *item;
- int i;
- MDeformWeight *dw = self->data->dw;
+ PyObject *ret;
+ PyObject *item;
+ int i;
+ MDeformWeight *dw = self->data->dw;
- ret = PyList_New(self->data->totweight);
- for (i = 0; i < self->data->totweight; i++, dw++) {
- item = PyTuple_New(2);
- PyTuple_SET_ITEMS(item,
- PyLong_FromLong(dw->def_nr),
- PyFloat_FromDouble(dw->weight));
- PyList_SET_ITEM(ret, i, item);
- }
+ ret = PyList_New(self->data->totweight);
+ for (i = 0; i < self->data->totweight; i++, dw++) {
+ item = PyTuple_New(2);
+ PyTuple_SET_ITEMS(item, PyLong_FromLong(dw->def_nr), PyFloat_FromDouble(dw->weight));
+ PyList_SET_ITEM(ret, i, item);
+ }
- return ret;
+ return ret;
}
PyDoc_STRVAR(bpy_bmdeformvert_get_doc,
-".. method:: get(key, default=None)\n"
-"\n"
-" Returns the deform weight matching the key or default\n"
-" when not found (matches pythons dictionary function of the same name).\n"
-"\n"
-" :arg key: The key associated with deform weight.\n"
-" :type key: int\n"
-" :arg default: Optional argument for the value to return if\n"
-" *key* is not found.\n"
-" :type default: Undefined\n"
-);
+ ".. method:: get(key, default=None)\n"
+ "\n"
+ " Returns the deform weight matching the key or default\n"
+ " when not found (matches pythons dictionary function of the same name).\n"
+ "\n"
+ " :arg key: The key associated with deform weight.\n"
+ " :type key: int\n"
+ " :arg default: Optional argument for the value to return if\n"
+ " *key* is not found.\n"
+ " :type default: Undefined\n");
static PyObject *bpy_bmdeformvert_get(BPy_BMDeformVert *self, PyObject *args)
{
- int key;
- PyObject *def = Py_None;
+ int key;
+ PyObject *def = Py_None;
- if (!PyArg_ParseTuple(args, "i|O:get", &key, &def)) {
- return NULL;
- }
- else {
- MDeformWeight *dw = defvert_find_index(self->data, key);
+ if (!PyArg_ParseTuple(args, "i|O:get", &key, &def)) {
+ return NULL;
+ }
+ else {
+ MDeformWeight *dw = defvert_find_index(self->data, key);
- if (dw) {
- return PyFloat_FromDouble(dw->weight);
- }
- else {
- return Py_INCREF_RET(def);
- }
- }
+ if (dw) {
+ return PyFloat_FromDouble(dw->weight);
+ }
+ else {
+ return Py_INCREF_RET(def);
+ }
+ }
}
-
PyDoc_STRVAR(bpy_bmdeformvert_clear_doc,
-".. method:: clear()\n"
-"\n"
-" Clears all weights.\n"
-);
+ ".. method:: clear()\n"
+ "\n"
+ " Clears all weights.\n");
static PyObject *bpy_bmdeformvert_clear(BPy_BMDeformVert *self)
{
- defvert_clear(self->data);
+ defvert_clear(self->data);
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
static struct PyMethodDef bpy_bmdeformvert_methods[] = {
- {"keys", (PyCFunction)bpy_bmdeformvert_keys, METH_NOARGS, bpy_bmdeformvert_keys_doc},
- {"values", (PyCFunction)bpy_bmdeformvert_values, METH_NOARGS, bpy_bmdeformvert_values_doc},
- {"items", (PyCFunction)bpy_bmdeformvert_items, METH_NOARGS, bpy_bmdeformvert_items_doc},
- {"get", (PyCFunction)bpy_bmdeformvert_get, METH_VARARGS, bpy_bmdeformvert_get_doc},
- /* BMESH_TODO pop, popitem, update */
- {"clear", (PyCFunction)bpy_bmdeformvert_clear, METH_NOARGS, bpy_bmdeformvert_clear_doc},
- {NULL, NULL, 0, NULL},
+ {"keys", (PyCFunction)bpy_bmdeformvert_keys, METH_NOARGS, bpy_bmdeformvert_keys_doc},
+ {"values", (PyCFunction)bpy_bmdeformvert_values, METH_NOARGS, bpy_bmdeformvert_values_doc},
+ {"items", (PyCFunction)bpy_bmdeformvert_items, METH_NOARGS, bpy_bmdeformvert_items_doc},
+ {"get", (PyCFunction)bpy_bmdeformvert_get, METH_VARARGS, bpy_bmdeformvert_get_doc},
+ /* BMESH_TODO pop, popitem, update */
+ {"clear", (PyCFunction)bpy_bmdeformvert_clear, METH_NOARGS, bpy_bmdeformvert_clear_doc},
+ {NULL, NULL, 0, NULL},
};
PyTypeObject BPy_BMDeformVert_Type; /* bm.loops.layers.uv.active */
static void bm_init_types_bmdvert(void)
{
- BPy_BMDeformVert_Type.tp_basicsize = sizeof(BPy_BMDeformVert);
+ BPy_BMDeformVert_Type.tp_basicsize = sizeof(BPy_BMDeformVert);
- BPy_BMDeformVert_Type.tp_name = "BMDeformVert";
+ BPy_BMDeformVert_Type.tp_name = "BMDeformVert";
- BPy_BMDeformVert_Type.tp_doc = NULL; // todo
+ BPy_BMDeformVert_Type.tp_doc = NULL; // todo
- BPy_BMDeformVert_Type.tp_as_sequence = &bpy_bmdeformvert_as_sequence;
- BPy_BMDeformVert_Type.tp_as_mapping = &bpy_bmdeformvert_as_mapping;
+ BPy_BMDeformVert_Type.tp_as_sequence = &bpy_bmdeformvert_as_sequence;
+ BPy_BMDeformVert_Type.tp_as_mapping = &bpy_bmdeformvert_as_mapping;
- BPy_BMDeformVert_Type.tp_methods = bpy_bmdeformvert_methods;
+ BPy_BMDeformVert_Type.tp_methods = bpy_bmdeformvert_methods;
- BPy_BMDeformVert_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMDeformVert_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- PyType_Ready(&BPy_BMDeformVert_Type);
+ PyType_Ready(&BPy_BMDeformVert_Type);
}
int BPy_BMDeformVert_AssignPyObject(struct MDeformVert *dvert, PyObject *value)
{
- if (UNLIKELY(!BPy_BMDeformVert_Check(value))) {
- PyErr_Format(PyExc_TypeError, "expected BMDeformVert, not a %.200s", Py_TYPE(value)->tp_name);
- return -1;
- }
- else {
- MDeformVert *dvert_src = ((BPy_BMDeformVert *)value)->data;
- if (LIKELY(dvert != dvert_src)) {
- defvert_copy(dvert, dvert_src);
- }
- return 0;
- }
+ if (UNLIKELY(!BPy_BMDeformVert_Check(value))) {
+ PyErr_Format(PyExc_TypeError, "expected BMDeformVert, not a %.200s", Py_TYPE(value)->tp_name);
+ return -1;
+ }
+ else {
+ MDeformVert *dvert_src = ((BPy_BMDeformVert *)value)->data;
+ if (LIKELY(dvert != dvert_src)) {
+ defvert_copy(dvert, dvert_src);
+ }
+ return 0;
+ }
}
PyObject *BPy_BMDeformVert_CreatePyObject(struct MDeformVert *dvert)
{
- BPy_BMDeformVert *self = PyObject_New(BPy_BMDeformVert, &BPy_BMDeformVert_Type);
- self->data = dvert;
- return (PyObject *)self;
+ BPy_BMDeformVert *self = PyObject_New(BPy_BMDeformVert, &BPy_BMDeformVert_Type);
+ self->data = dvert;
+ return (PyObject *)self;
}
/* --- End Mesh Deform Vert --- */
-
/* call to init all types */
void BPy_BM_init_types_meshdata(void)
{
- bm_init_types_bmloopuv();
- bm_init_types_bmloopcol();
- bm_init_types_bmdvert();
- bm_init_types_bmvertskin();
+ bm_init_types_bmloopuv();
+ bm_init_types_bmloopcol();
+ bm_init_types_bmdvert();
+ bm_init_types_bmvertskin();
}
diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.h b/source/blender/python/bmesh/bmesh_py_types_meshdata.h
index 66cdb9c119d..5211c30ec7e 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.h
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.h
@@ -27,11 +27,10 @@
extern PyTypeObject BPy_BMLoopUV_Type;
extern PyTypeObject BPy_BMDeformVert_Type;
-#define BPy_BMLoopUV_Check(v) (Py_TYPE(v) == &BPy_BMLoopUV_Type)
+#define BPy_BMLoopUV_Check(v) (Py_TYPE(v) == &BPy_BMLoopUV_Type)
typedef struct BPy_BMGenericMeshData {
- PyObject_VAR_HEAD
- void *data;
+ PyObject_VAR_HEAD void *data;
} BPy_BMGenericMeshData;
struct MDeformVert;
@@ -39,19 +38,18 @@ struct MLoopCol;
struct MLoopUV;
struct MVertSkin;
-int BPy_BMLoopUV_AssignPyObject(struct MLoopUV *data, PyObject *value);
+int BPy_BMLoopUV_AssignPyObject(struct MLoopUV *data, PyObject *value);
PyObject *BPy_BMLoopUV_CreatePyObject(struct MLoopUV *data);
-int BPy_BMVertSkin_AssignPyObject(struct MVertSkin *data, PyObject *value);
+int BPy_BMVertSkin_AssignPyObject(struct MVertSkin *data, PyObject *value);
PyObject *BPy_BMVertSkin_CreatePyObject(struct MVertSkin *data);
-int BPy_BMLoopColor_AssignPyObject(struct MLoopCol *data, PyObject *value);
+int BPy_BMLoopColor_AssignPyObject(struct MLoopCol *data, PyObject *value);
PyObject *BPy_BMLoopColor_CreatePyObject(struct MLoopCol *data);
-int BPy_BMDeformVert_AssignPyObject(struct MDeformVert *dvert, PyObject *value);
+int BPy_BMDeformVert_AssignPyObject(struct MDeformVert *dvert, PyObject *value);
PyObject *BPy_BMDeformVert_CreatePyObject(struct MDeformVert *dvert);
-
void BPy_BM_init_types_meshdata(void);
#endif /* __BMESH_PY_TYPES_MESHDATA_H__ */
diff --git a/source/blender/python/bmesh/bmesh_py_types_select.c b/source/blender/python/bmesh/bmesh_py_types_select.c
index e257c1bff4b..228874a86e3 100644
--- a/source/blender/python/bmesh/bmesh_py_types_select.c
+++ b/source/blender/python/bmesh/bmesh_py_types_select.c
@@ -41,397 +41,387 @@
#include "../generic/python_utildefines.h"
PyDoc_STRVAR(bpy_bmeditselseq_active_doc,
-"The last selected element or None (read-only).\n\n:type: :class:`BMVert`, :class:`BMEdge` or :class:`BMFace`"
-);
+ "The last selected element or None (read-only).\n\n:type: :class:`BMVert`, "
+ ":class:`BMEdge` or :class:`BMFace`");
static PyObject *bpy_bmeditselseq_active_get(BPy_BMEditSelSeq *self, void *UNUSED(closure))
{
- BMEditSelection *ese;
- BPY_BM_CHECK_OBJ(self);
-
- if ((ese = self->bm->selected.last)) {
- return BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head);
- }
- else {
- Py_RETURN_NONE;
- }
+ BMEditSelection *ese;
+ BPY_BM_CHECK_OBJ(self);
+
+ if ((ese = self->bm->selected.last)) {
+ return BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head);
+ }
+ else {
+ Py_RETURN_NONE;
+ }
}
static PyGetSetDef bpy_bmeditselseq_getseters[] = {
- {(char *)"active", (getter)bpy_bmeditselseq_active_get, (setter)NULL, (char *)bpy_bmeditselseq_active_doc, NULL},
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+ {(char *)"active",
+ (getter)bpy_bmeditselseq_active_get,
+ (setter)NULL,
+ (char *)bpy_bmeditselseq_active_doc,
+ NULL},
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
PyDoc_STRVAR(bpy_bmeditselseq_validate_doc,
-".. method:: validate()\n"
-"\n"
-" Ensures all elements in the selection history are selected.\n"
-);
+ ".. method:: validate()\n"
+ "\n"
+ " Ensures all elements in the selection history are selected.\n");
static PyObject *bpy_bmeditselseq_validate(BPy_BMEditSelSeq *self)
{
- BPY_BM_CHECK_OBJ(self);
- BM_select_history_validate(self->bm);
- Py_RETURN_NONE;
+ BPY_BM_CHECK_OBJ(self);
+ BM_select_history_validate(self->bm);
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(bpy_bmeditselseq_clear_doc,
-".. method:: clear()\n"
-"\n"
-" Empties the selection history.\n"
-);
+ ".. method:: clear()\n"
+ "\n"
+ " Empties the selection history.\n");
static PyObject *bpy_bmeditselseq_clear(BPy_BMEditSelSeq *self)
{
- BPY_BM_CHECK_OBJ(self);
- BM_select_history_clear(self->bm);
- Py_RETURN_NONE;
+ BPY_BM_CHECK_OBJ(self);
+ BM_select_history_clear(self->bm);
+ Py_RETURN_NONE;
}
-PyDoc_STRVAR(bpy_bmeditselseq_add_doc,
-".. method:: add(element)\n"
-"\n"
-" Add an element to the selection history (no action taken if its already added).\n"
-);
+PyDoc_STRVAR(
+ bpy_bmeditselseq_add_doc,
+ ".. method:: add(element)\n"
+ "\n"
+ " Add an element to the selection history (no action taken if its already added).\n");
static PyObject *bpy_bmeditselseq_add(BPy_BMEditSelSeq *self, BPy_BMElem *value)
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if ((BPy_BMVert_Check(value) ||
- BPy_BMEdge_Check(value) ||
- BPy_BMFace_Check(value)) == false)
- {
- PyErr_Format(PyExc_TypeError,
- "Expected a BMVert/BMedge/BMFace not a %.200s", Py_TYPE(value)->tp_name);
- return NULL;
- }
+ if ((BPy_BMVert_Check(value) || BPy_BMEdge_Check(value) || BPy_BMFace_Check(value)) == false) {
+ PyErr_Format(
+ PyExc_TypeError, "Expected a BMVert/BMedge/BMFace not a %.200s", Py_TYPE(value)->tp_name);
+ return NULL;
+ }
- BPY_BM_CHECK_SOURCE_OBJ(self->bm, "select_history.add()", value);
+ BPY_BM_CHECK_SOURCE_OBJ(self->bm, "select_history.add()", value);
- BM_select_history_store(self->bm, value->ele);
+ BM_select_history_store(self->bm, value->ele);
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(bpy_bmeditselseq_remove_doc,
-".. method:: remove(element)\n"
-"\n"
-" Remove an element from the selection history.\n"
-);
+ ".. method:: remove(element)\n"
+ "\n"
+ " Remove an element from the selection history.\n");
static PyObject *bpy_bmeditselseq_remove(BPy_BMEditSelSeq *self, BPy_BMElem *value)
{
- BPY_BM_CHECK_OBJ(self);
-
- if ((BPy_BMVert_Check(value) ||
- BPy_BMEdge_Check(value) ||
- BPy_BMFace_Check(value)) == false)
- {
- PyErr_Format(PyExc_TypeError,
- "Expected a BMVert/BMedge/BMFace not a %.200s", Py_TYPE(value)->tp_name);
- return NULL;
- }
-
- BPY_BM_CHECK_SOURCE_OBJ(self->bm, "select_history.remove()", value);
-
- if (BM_select_history_remove(self->bm, value->ele) == false) {
- PyErr_SetString(PyExc_ValueError,
- "Element not found in selection history");
- return NULL;
- }
-
- Py_RETURN_NONE;
+ BPY_BM_CHECK_OBJ(self);
+
+ if ((BPy_BMVert_Check(value) || BPy_BMEdge_Check(value) || BPy_BMFace_Check(value)) == false) {
+ PyErr_Format(
+ PyExc_TypeError, "Expected a BMVert/BMedge/BMFace not a %.200s", Py_TYPE(value)->tp_name);
+ return NULL;
+ }
+
+ BPY_BM_CHECK_SOURCE_OBJ(self->bm, "select_history.remove()", value);
+
+ if (BM_select_history_remove(self->bm, value->ele) == false) {
+ PyErr_SetString(PyExc_ValueError, "Element not found in selection history");
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
}
-PyDoc_STRVAR(bpy_bmeditselseq_discard_doc,
-".. method:: discard(element)\n"
-"\n"
-" Discard an element from the selection history.\n"
-"\n"
-" Like remove but doesn't raise an error when the elements not in the selection list.\n"
-);
+PyDoc_STRVAR(
+ bpy_bmeditselseq_discard_doc,
+ ".. method:: discard(element)\n"
+ "\n"
+ " Discard an element from the selection history.\n"
+ "\n"
+ " Like remove but doesn't raise an error when the elements not in the selection list.\n");
static PyObject *bpy_bmeditselseq_discard(BPy_BMEditSelSeq *self, BPy_BMElem *value)
{
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- if ((BPy_BMVert_Check(value) ||
- BPy_BMEdge_Check(value) ||
- BPy_BMFace_Check(value)) == false)
- {
- PyErr_Format(PyExc_TypeError,
- "Expected a BMVert/BMedge/BMFace not a %.200s", Py_TYPE(value)->tp_name);
- return NULL;
- }
+ if ((BPy_BMVert_Check(value) || BPy_BMEdge_Check(value) || BPy_BMFace_Check(value)) == false) {
+ PyErr_Format(
+ PyExc_TypeError, "Expected a BMVert/BMedge/BMFace not a %.200s", Py_TYPE(value)->tp_name);
+ return NULL;
+ }
- BPY_BM_CHECK_SOURCE_OBJ(self->bm, "select_history.discard()", value);
+ BPY_BM_CHECK_SOURCE_OBJ(self->bm, "select_history.discard()", value);
- BM_select_history_remove(self->bm, value->ele);
+ BM_select_history_remove(self->bm, value->ele);
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
static struct PyMethodDef bpy_bmeditselseq_methods[] = {
- {"validate", (PyCFunction)bpy_bmeditselseq_validate, METH_NOARGS, bpy_bmeditselseq_validate_doc},
- {"clear", (PyCFunction)bpy_bmeditselseq_clear, METH_NOARGS, bpy_bmeditselseq_clear_doc},
-
- {"add", (PyCFunction)bpy_bmeditselseq_add, METH_O, bpy_bmeditselseq_add_doc},
- {"remove", (PyCFunction)bpy_bmeditselseq_remove, METH_O, bpy_bmeditselseq_remove_doc},
- {"discard", (PyCFunction)bpy_bmeditselseq_discard, METH_O, bpy_bmeditselseq_discard_doc},
- {NULL, NULL, 0, NULL},
+ {"validate",
+ (PyCFunction)bpy_bmeditselseq_validate,
+ METH_NOARGS,
+ bpy_bmeditselseq_validate_doc},
+ {"clear", (PyCFunction)bpy_bmeditselseq_clear, METH_NOARGS, bpy_bmeditselseq_clear_doc},
+
+ {"add", (PyCFunction)bpy_bmeditselseq_add, METH_O, bpy_bmeditselseq_add_doc},
+ {"remove", (PyCFunction)bpy_bmeditselseq_remove, METH_O, bpy_bmeditselseq_remove_doc},
+ {"discard", (PyCFunction)bpy_bmeditselseq_discard, METH_O, bpy_bmeditselseq_discard_doc},
+ {NULL, NULL, 0, NULL},
};
-
/* Sequences
* ========= */
static Py_ssize_t bpy_bmeditselseq_length(BPy_BMEditSelSeq *self)
{
- BPY_BM_CHECK_INT(self);
+ BPY_BM_CHECK_INT(self);
- return BLI_listbase_count(&self->bm->selected);
+ return BLI_listbase_count(&self->bm->selected);
}
static PyObject *bpy_bmeditselseq_subscript_int(BPy_BMEditSelSeq *self, int keynum)
{
- BMEditSelection *ese;
-
- BPY_BM_CHECK_OBJ(self);
-
- if (keynum < 0) {
- ese = BLI_rfindlink(&self->bm->selected, -1 - keynum);
- }
- else {
- ese = BLI_findlink(&self->bm->selected, keynum);
- }
-
- if (ese) {
- return BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head);
- }
- else {
- PyErr_Format(PyExc_IndexError,
- "BMElemSeq[index]: index %d out of range", keynum);
- return NULL;
- }
+ BMEditSelection *ese;
+
+ BPY_BM_CHECK_OBJ(self);
+
+ if (keynum < 0) {
+ ese = BLI_rfindlink(&self->bm->selected, -1 - keynum);
+ }
+ else {
+ ese = BLI_findlink(&self->bm->selected, keynum);
+ }
+
+ if (ese) {
+ return BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head);
+ }
+ else {
+ PyErr_Format(PyExc_IndexError, "BMElemSeq[index]: index %d out of range", keynum);
+ return NULL;
+ }
}
-static PyObject *bpy_bmeditselseq_subscript_slice(BPy_BMEditSelSeq *self, Py_ssize_t start, Py_ssize_t stop)
+static PyObject *bpy_bmeditselseq_subscript_slice(BPy_BMEditSelSeq *self,
+ Py_ssize_t start,
+ Py_ssize_t stop)
{
- int count = 0;
- bool ok;
+ int count = 0;
+ bool ok;
- PyObject *list;
- BMEditSelection *ese;
+ PyObject *list;
+ BMEditSelection *ese;
- BPY_BM_CHECK_OBJ(self);
+ BPY_BM_CHECK_OBJ(self);
- list = PyList_New(0);
+ list = PyList_New(0);
- ese = self->bm->selected.first;
+ ese = self->bm->selected.first;
- ok = (ese != NULL);
+ ok = (ese != NULL);
- if (UNLIKELY(ok == false)) {
- return list;
- }
+ if (UNLIKELY(ok == false)) {
+ return list;
+ }
- /* first loop up-until the start */
- for (ok = true; ok; ok = ((ese = ese->next) != NULL)) {
- if (count == start) {
- break;
- }
- count++;
- }
+ /* first loop up-until the start */
+ for (ok = true; ok; ok = ((ese = ese->next) != NULL)) {
+ if (count == start) {
+ break;
+ }
+ count++;
+ }
- /* add items until stop */
- do {
- PyList_APPEND(list, BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head));
- count++;
- if (count == stop) {
- break;
- }
- } while ((ese = ese->next));
+ /* add items until stop */
+ do {
+ PyList_APPEND(list, BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head));
+ count++;
+ if (count == stop) {
+ break;
+ }
+ } while ((ese = ese->next));
- return list;
+ return list;
}
static PyObject *bpy_bmeditselseq_subscript(BPy_BMEditSelSeq *self, PyObject *key)
{
- /* don't need error check here */
- if (PyIndex_Check(key)) {
- Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred()) {
- return NULL;
- }
- return bpy_bmeditselseq_subscript_int(self, i);
- }
- else if (PySlice_Check(key)) {
- PySliceObject *key_slice = (PySliceObject *)key;
- Py_ssize_t step = 1;
-
- if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) {
- return NULL;
- }
- else if (step != 1) {
- PyErr_SetString(PyExc_TypeError,
- "BMElemSeq[slice]: slice steps not supported");
- return NULL;
- }
- else if (key_slice->start == Py_None && key_slice->stop == Py_None) {
- return bpy_bmeditselseq_subscript_slice(self, 0, PY_SSIZE_T_MAX);
- }
- else {
- Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX;
-
- /* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */
- if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) {
- return NULL;
- }
- if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) {
- return NULL;
- }
-
- if (start < 0 || stop < 0) {
- /* only get the length for negative values */
- Py_ssize_t len = bpy_bmeditselseq_length(self);
- if (start < 0) {
- start += len;
- }
- if (stop < 0) {
- stop += len;
- }
- }
-
- if (stop - start <= 0) {
- return PyList_New(0);
- }
- else {
- return bpy_bmeditselseq_subscript_slice(self, start, stop);
- }
- }
- }
- else {
- PyErr_SetString(PyExc_AttributeError,
- "BMElemSeq[key]: invalid key, key must be an int");
- return NULL;
- }
+ /* don't need error check here */
+ if (PyIndex_Check(key)) {
+ Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
+ if (i == -1 && PyErr_Occurred()) {
+ return NULL;
+ }
+ return bpy_bmeditselseq_subscript_int(self, i);
+ }
+ else if (PySlice_Check(key)) {
+ PySliceObject *key_slice = (PySliceObject *)key;
+ Py_ssize_t step = 1;
+
+ if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) {
+ return NULL;
+ }
+ else if (step != 1) {
+ PyErr_SetString(PyExc_TypeError, "BMElemSeq[slice]: slice steps not supported");
+ return NULL;
+ }
+ else if (key_slice->start == Py_None && key_slice->stop == Py_None) {
+ return bpy_bmeditselseq_subscript_slice(self, 0, PY_SSIZE_T_MAX);
+ }
+ else {
+ Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX;
+
+ /* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */
+ if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) {
+ return NULL;
+ }
+ if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) {
+ return NULL;
+ }
+
+ if (start < 0 || stop < 0) {
+ /* only get the length for negative values */
+ Py_ssize_t len = bpy_bmeditselseq_length(self);
+ if (start < 0) {
+ start += len;
+ }
+ if (stop < 0) {
+ stop += len;
+ }
+ }
+
+ if (stop - start <= 0) {
+ return PyList_New(0);
+ }
+ else {
+ return bpy_bmeditselseq_subscript_slice(self, start, stop);
+ }
+ }
+ }
+ else {
+ PyErr_SetString(PyExc_AttributeError, "BMElemSeq[key]: invalid key, key must be an int");
+ return NULL;
+ }
}
static int bpy_bmeditselseq_contains(BPy_BMEditSelSeq *self, PyObject *value)
{
- BPy_BMElem *value_bm_ele;
+ BPy_BMElem *value_bm_ele;
- BPY_BM_CHECK_INT(self);
+ BPY_BM_CHECK_INT(self);
- value_bm_ele = (BPy_BMElem *)value;
- if (value_bm_ele->bm == self->bm) {
- return BM_select_history_check(self->bm, value_bm_ele->ele);
- }
+ value_bm_ele = (BPy_BMElem *)value;
+ if (value_bm_ele->bm == self->bm) {
+ return BM_select_history_check(self->bm, value_bm_ele->ele);
+ }
- return 0;
+ return 0;
}
static PySequenceMethods bpy_bmeditselseq_as_sequence = {
- (lenfunc)bpy_bmeditselseq_length, /* sq_length */
- NULL, /* sq_concat */
- NULL, /* sq_repeat */
- (ssizeargfunc)bpy_bmeditselseq_subscript_int,/* sq_item */ /* Only set this so PySequence_Check() returns True */
- NULL, /* sq_slice */
- (ssizeobjargproc)NULL, /* sq_ass_item */
- NULL, /* *was* sq_ass_slice */
- (objobjproc)bpy_bmeditselseq_contains, /* sq_contains */
- (binaryfunc) NULL, /* sq_inplace_concat */
- (ssizeargfunc) NULL, /* sq_inplace_repeat */
+ (lenfunc)bpy_bmeditselseq_length, /* sq_length */
+ NULL, /* sq_concat */
+ NULL, /* sq_repeat */
+ (ssizeargfunc)bpy_bmeditselseq_subscript_int,
+ /* sq_item */ /* Only set this so PySequence_Check() returns True */
+ NULL, /* sq_slice */
+ (ssizeobjargproc)NULL, /* sq_ass_item */
+ NULL, /* *was* sq_ass_slice */
+ (objobjproc)bpy_bmeditselseq_contains, /* sq_contains */
+ (binaryfunc)NULL, /* sq_inplace_concat */
+ (ssizeargfunc)NULL, /* sq_inplace_repeat */
};
static PyMappingMethods bpy_bmeditselseq_as_mapping = {
- (lenfunc)bpy_bmeditselseq_length, /* mp_length */
- (binaryfunc)bpy_bmeditselseq_subscript, /* mp_subscript */
- (objobjargproc)NULL, /* mp_ass_subscript */
+ (lenfunc)bpy_bmeditselseq_length, /* mp_length */
+ (binaryfunc)bpy_bmeditselseq_subscript, /* mp_subscript */
+ (objobjargproc)NULL, /* mp_ass_subscript */
};
-
/* Iterator
* -------- */
static PyObject *bpy_bmeditselseq_iter(BPy_BMEditSelSeq *self)
{
- BPy_BMEditSelIter *py_iter;
+ BPy_BMEditSelIter *py_iter;
- BPY_BM_CHECK_OBJ(self);
- py_iter = (BPy_BMEditSelIter *)BPy_BMEditSelIter_CreatePyObject(self->bm);
- py_iter->ese = self->bm->selected.first;
- return (PyObject *)py_iter;
+ BPY_BM_CHECK_OBJ(self);
+ py_iter = (BPy_BMEditSelIter *)BPy_BMEditSelIter_CreatePyObject(self->bm);
+ py_iter->ese = self->bm->selected.first;
+ return (PyObject *)py_iter;
}
static PyObject *bpy_bmeditseliter_next(BPy_BMEditSelIter *self)
{
- BMEditSelection *ese = self->ese;
- if (ese == NULL) {
- PyErr_SetNone(PyExc_StopIteration);
- return NULL;
- }
- else {
- self->ese = ese->next;
- return (PyObject *)BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head);
- }
+ BMEditSelection *ese = self->ese;
+ if (ese == NULL) {
+ PyErr_SetNone(PyExc_StopIteration);
+ return NULL;
+ }
+ else {
+ self->ese = ese->next;
+ return (PyObject *)BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head);
+ }
}
PyTypeObject BPy_BMEditSelSeq_Type;
PyTypeObject BPy_BMEditSelIter_Type;
-
PyObject *BPy_BMEditSel_CreatePyObject(BMesh *bm)
{
- BPy_BMEditSelSeq *self = PyObject_New(BPy_BMEditSelSeq, &BPy_BMEditSelSeq_Type);
- self->bm = bm;
- /* caller must initialize 'iter' member */
- return (PyObject *)self;
+ BPy_BMEditSelSeq *self = PyObject_New(BPy_BMEditSelSeq, &BPy_BMEditSelSeq_Type);
+ self->bm = bm;
+ /* caller must initialize 'iter' member */
+ return (PyObject *)self;
}
PyObject *BPy_BMEditSelIter_CreatePyObject(BMesh *bm)
{
- BPy_BMEditSelIter *self = PyObject_New(BPy_BMEditSelIter, &BPy_BMEditSelIter_Type);
- self->bm = bm;
- /* caller must initialize 'iter' member */
- return (PyObject *)self;
+ BPy_BMEditSelIter *self = PyObject_New(BPy_BMEditSelIter, &BPy_BMEditSelIter_Type);
+ self->bm = bm;
+ /* caller must initialize 'iter' member */
+ return (PyObject *)self;
}
void BPy_BM_init_types_select(void)
{
- BPy_BMEditSelSeq_Type.tp_basicsize = sizeof(BPy_BMEditSelSeq);
- BPy_BMEditSelIter_Type.tp_basicsize = sizeof(BPy_BMEditSelIter);
+ BPy_BMEditSelSeq_Type.tp_basicsize = sizeof(BPy_BMEditSelSeq);
+ BPy_BMEditSelIter_Type.tp_basicsize = sizeof(BPy_BMEditSelIter);
- BPy_BMEditSelSeq_Type.tp_name = "BMEditSelSeq";
- BPy_BMEditSelIter_Type.tp_name = "BMEditSelIter";
+ BPy_BMEditSelSeq_Type.tp_name = "BMEditSelSeq";
+ BPy_BMEditSelIter_Type.tp_name = "BMEditSelIter";
- BPy_BMEditSelSeq_Type.tp_doc = NULL; /* todo */
- BPy_BMEditSelIter_Type.tp_doc = NULL;
+ BPy_BMEditSelSeq_Type.tp_doc = NULL; /* todo */
+ BPy_BMEditSelIter_Type.tp_doc = NULL;
- BPy_BMEditSelSeq_Type.tp_repr = (reprfunc)NULL;
- BPy_BMEditSelIter_Type.tp_repr = (reprfunc)NULL;
+ BPy_BMEditSelSeq_Type.tp_repr = (reprfunc)NULL;
+ BPy_BMEditSelIter_Type.tp_repr = (reprfunc)NULL;
- BPy_BMEditSelSeq_Type.tp_getset = bpy_bmeditselseq_getseters;
- BPy_BMEditSelIter_Type.tp_getset = NULL;
+ BPy_BMEditSelSeq_Type.tp_getset = bpy_bmeditselseq_getseters;
+ BPy_BMEditSelIter_Type.tp_getset = NULL;
- BPy_BMEditSelSeq_Type.tp_methods = bpy_bmeditselseq_methods;
- BPy_BMEditSelIter_Type.tp_methods = NULL;
+ BPy_BMEditSelSeq_Type.tp_methods = bpy_bmeditselseq_methods;
+ BPy_BMEditSelIter_Type.tp_methods = NULL;
- BPy_BMEditSelSeq_Type.tp_as_sequence = &bpy_bmeditselseq_as_sequence;
+ BPy_BMEditSelSeq_Type.tp_as_sequence = &bpy_bmeditselseq_as_sequence;
- BPy_BMEditSelSeq_Type.tp_as_mapping = &bpy_bmeditselseq_as_mapping;
+ BPy_BMEditSelSeq_Type.tp_as_mapping = &bpy_bmeditselseq_as_mapping;
- BPy_BMEditSelSeq_Type.tp_iter = (getiterfunc)bpy_bmeditselseq_iter;
+ BPy_BMEditSelSeq_Type.tp_iter = (getiterfunc)bpy_bmeditselseq_iter;
- /* only 1 iteratir so far */
- BPy_BMEditSelIter_Type.tp_iternext = (iternextfunc)bpy_bmeditseliter_next;
+ /* only 1 iteratir so far */
+ BPy_BMEditSelIter_Type.tp_iternext = (iternextfunc)bpy_bmeditseliter_next;
- BPy_BMEditSelSeq_Type.tp_dealloc = NULL; //(destructor)bpy_bmeditselseq_dealloc;
- BPy_BMEditSelIter_Type.tp_dealloc = NULL; //(destructor)bpy_bmvert_dealloc;
+ BPy_BMEditSelSeq_Type.tp_dealloc = NULL; //(destructor)bpy_bmeditselseq_dealloc;
+ BPy_BMEditSelIter_Type.tp_dealloc = NULL; //(destructor)bpy_bmvert_dealloc;
- BPy_BMEditSelSeq_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- BPy_BMEditSelIter_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMEditSelSeq_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_BMEditSelIter_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- PyType_Ready(&BPy_BMEditSelSeq_Type);
- PyType_Ready(&BPy_BMEditSelIter_Type);
+ PyType_Ready(&BPy_BMEditSelSeq_Type);
+ PyType_Ready(&BPy_BMEditSelIter_Type);
}
-
/* utility function */
/**
@@ -439,29 +429,35 @@ void BPy_BM_init_types_select(void)
*/
int BPy_BMEditSel_Assign(BPy_BMesh *self, PyObject *value)
{
- BMesh *bm;
- Py_ssize_t value_len;
- Py_ssize_t i;
- BMElem **value_array = NULL;
+ BMesh *bm;
+ Py_ssize_t value_len;
+ Py_ssize_t i;
+ BMElem **value_array = NULL;
- BPY_BM_CHECK_INT(self);
+ BPY_BM_CHECK_INT(self);
- bm = self->bm;
+ bm = self->bm;
- value_array = BPy_BMElem_PySeq_As_Array(&bm, value, 0, PY_SSIZE_T_MAX,
- &value_len, BM_VERT | BM_EDGE | BM_FACE,
- true, true, "BMesh.select_history = value");
+ value_array = BPy_BMElem_PySeq_As_Array(&bm,
+ value,
+ 0,
+ PY_SSIZE_T_MAX,
+ &value_len,
+ BM_VERT | BM_EDGE | BM_FACE,
+ true,
+ true,
+ "BMesh.select_history = value");
- if (value_array == NULL) {
- return -1;
- }
+ if (value_array == NULL) {
+ return -1;
+ }
- BM_select_history_clear(bm);
+ BM_select_history_clear(bm);
- for (i = 0; i < value_len; i++) {
- BM_select_history_store_notest(bm, value_array[i]);
- }
+ for (i = 0; i < value_len; i++) {
+ BM_select_history_store_notest(bm, value_array[i]);
+ }
- PyMem_FREE(value_array);
- return 0;
+ PyMem_FREE(value_array);
+ return 0;
}
diff --git a/source/blender/python/bmesh/bmesh_py_types_select.h b/source/blender/python/bmesh/bmesh_py_types_select.h
index 2bf2214d7f9..593857a5083 100644
--- a/source/blender/python/bmesh/bmesh_py_types_select.h
+++ b/source/blender/python/bmesh/bmesh_py_types_select.h
@@ -29,24 +29,22 @@ struct BPy_BMesh;
extern PyTypeObject BPy_BMEditSelSeq_Type;
extern PyTypeObject BPy_BMEditSelIter_Type;
-#define BPy_BMSelectHistory_Check(v) (Py_TYPE(v) == &BPy_BMEditSelSeq_Type)
-#define BPy_BMSelectHistoryIter_Check(v) (Py_TYPE(v) == &BPy_BMEditSelIter_Type)
+#define BPy_BMSelectHistory_Check(v) (Py_TYPE(v) == &BPy_BMEditSelSeq_Type)
+#define BPy_BMSelectHistoryIter_Check(v) (Py_TYPE(v) == &BPy_BMEditSelIter_Type)
typedef struct BPy_BMEditSelSeq {
- PyObject_VAR_HEAD
- struct BMesh *bm; /* keep first */
+ PyObject_VAR_HEAD struct BMesh *bm; /* keep first */
} BPy_BMEditSelSeq;
typedef struct BPy_BMEditSelIter {
- PyObject_VAR_HEAD
- struct BMesh *bm; /* keep first */
- struct BMEditSelection *ese;
+ PyObject_VAR_HEAD struct BMesh *bm; /* keep first */
+ struct BMEditSelection *ese;
} BPy_BMEditSelIter;
void BPy_BM_init_types_select(void);
PyObject *BPy_BMEditSel_CreatePyObject(BMesh *bm);
PyObject *BPy_BMEditSelIter_CreatePyObject(BMesh *bm);
-int BPy_BMEditSel_Assign(struct BPy_BMesh *self, PyObject *value);
+int BPy_BMEditSel_Assign(struct BPy_BMesh *self, PyObject *value);
#endif /* __BMESH_PY_SELECT_H__ */
diff --git a/source/blender/python/bmesh/bmesh_py_utils.c b/source/blender/python/bmesh/bmesh_py_utils.c
index 8b8dcb518b9..01f6cdf6e26 100644
--- a/source/blender/python/bmesh/bmesh_py_utils.c
+++ b/source/blender/python/bmesh/bmesh_py_utils.c
@@ -40,803 +40,821 @@
#include "../generic/py_capi_utils.h"
#include "../generic/python_utildefines.h"
-
PyDoc_STRVAR(bpy_bm_utils_vert_collapse_edge_doc,
-".. method:: vert_collapse_edge(vert, edge)\n"
-"\n"
-" Collapse a vertex into an edge.\n"
-"\n"
-" :arg vert: The vert that will be collapsed.\n"
-" :type vert: :class:`bmesh.types.BMVert`\n"
-" :arg edge: The edge to collapse into.\n"
-" :type edge: :class:`bmesh.types.BMEdge`\n"
-" :return: The resulting edge from the collapse operation.\n"
-" :rtype: :class:`bmesh.types.BMEdge`\n"
-);
+ ".. method:: vert_collapse_edge(vert, edge)\n"
+ "\n"
+ " Collapse a vertex into an edge.\n"
+ "\n"
+ " :arg vert: The vert that will be collapsed.\n"
+ " :type vert: :class:`bmesh.types.BMVert`\n"
+ " :arg edge: The edge to collapse into.\n"
+ " :type edge: :class:`bmesh.types.BMEdge`\n"
+ " :return: The resulting edge from the collapse operation.\n"
+ " :rtype: :class:`bmesh.types.BMEdge`\n");
static PyObject *bpy_bm_utils_vert_collapse_edge(PyObject *UNUSED(self), PyObject *args)
{
- BPy_BMEdge *py_edge;
- BPy_BMVert *py_vert;
-
- BMesh *bm;
- BMEdge *e_new = NULL;
-
- if (!PyArg_ParseTuple(args, "O!O!:vert_collapse_edge",
- &BPy_BMVert_Type, &py_vert,
- &BPy_BMEdge_Type, &py_edge))
- {
- return NULL;
- }
-
- BPY_BM_CHECK_OBJ(py_edge);
- BPY_BM_CHECK_OBJ(py_vert);
-
- /* this doubles for checking that the verts are in the same mesh */
- if (!(py_edge->e->v1 == py_vert->v ||
- py_edge->e->v2 == py_vert->v))
- {
- PyErr_SetString(PyExc_ValueError,
- "vert_collapse_edge(vert, edge): the vertex is not found in the edge");
- return NULL;
- }
-
- if (BM_vert_edge_count_is_over(py_vert->v, 2)) {
- PyErr_SetString(PyExc_ValueError,
- "vert_collapse_edge(vert, edge): vert has more than 2 connected edges");
- return NULL;
- }
-
- bm = py_edge->bm;
-
- e_new = BM_vert_collapse_edge(bm, py_edge->e, py_vert->v, true, true);
-
- if (e_new) {
- return BPy_BMEdge_CreatePyObject(bm, e_new);
- }
- else {
- PyErr_SetString(PyExc_ValueError,
- "vert_collapse_edge(vert, edge): no new edge created, internal error");
- return NULL;
- }
+ BPy_BMEdge *py_edge;
+ BPy_BMVert *py_vert;
+
+ BMesh *bm;
+ BMEdge *e_new = NULL;
+
+ if (!PyArg_ParseTuple(args,
+ "O!O!:vert_collapse_edge",
+ &BPy_BMVert_Type,
+ &py_vert,
+ &BPy_BMEdge_Type,
+ &py_edge)) {
+ return NULL;
+ }
+
+ BPY_BM_CHECK_OBJ(py_edge);
+ BPY_BM_CHECK_OBJ(py_vert);
+
+ /* this doubles for checking that the verts are in the same mesh */
+ if (!(py_edge->e->v1 == py_vert->v || py_edge->e->v2 == py_vert->v)) {
+ PyErr_SetString(PyExc_ValueError,
+ "vert_collapse_edge(vert, edge): the vertex is not found in the edge");
+ return NULL;
+ }
+
+ if (BM_vert_edge_count_is_over(py_vert->v, 2)) {
+ PyErr_SetString(PyExc_ValueError,
+ "vert_collapse_edge(vert, edge): vert has more than 2 connected edges");
+ return NULL;
+ }
+
+ bm = py_edge->bm;
+
+ e_new = BM_vert_collapse_edge(bm, py_edge->e, py_vert->v, true, true);
+
+ if (e_new) {
+ return BPy_BMEdge_CreatePyObject(bm, e_new);
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "vert_collapse_edge(vert, edge): no new edge created, internal error");
+ return NULL;
+ }
}
-
PyDoc_STRVAR(bpy_bm_utils_vert_collapse_faces_doc,
-".. method:: vert_collapse_faces(vert, edge, fac, join_faces)\n"
-"\n"
-" Collapses a vertex that has only two manifold edges onto a vertex it shares an edge with.\n"
-"\n"
-" :arg vert: The vert that will be collapsed.\n"
-" :type vert: :class:`bmesh.types.BMVert`\n"
-" :arg edge: The edge to collapse into.\n"
-" :type edge: :class:`bmesh.types.BMEdge`\n"
-" :arg fac: The factor to use when merging customdata [0 - 1].\n"
-" :type fac: float\n"
-" :return: The resulting edge from the collapse operation.\n"
-" :rtype: :class:`bmesh.types.BMEdge`\n"
-);
+ ".. method:: vert_collapse_faces(vert, edge, fac, join_faces)\n"
+ "\n"
+ " Collapses a vertex that has only two manifold edges onto a vertex it shares an "
+ "edge with.\n"
+ "\n"
+ " :arg vert: The vert that will be collapsed.\n"
+ " :type vert: :class:`bmesh.types.BMVert`\n"
+ " :arg edge: The edge to collapse into.\n"
+ " :type edge: :class:`bmesh.types.BMEdge`\n"
+ " :arg fac: The factor to use when merging customdata [0 - 1].\n"
+ " :type fac: float\n"
+ " :return: The resulting edge from the collapse operation.\n"
+ " :rtype: :class:`bmesh.types.BMEdge`\n");
static PyObject *bpy_bm_utils_vert_collapse_faces(PyObject *UNUSED(self), PyObject *args)
{
- BPy_BMEdge *py_edge;
- BPy_BMVert *py_vert;
-
- float fac;
- int do_join_faces;
-
- BMesh *bm;
- BMEdge *e_new = NULL;
-
- if (!PyArg_ParseTuple(args, "O!O!fi:vert_collapse_faces",
- &BPy_BMVert_Type, &py_vert,
- &BPy_BMEdge_Type, &py_edge,
- &fac, &do_join_faces))
- {
- return NULL;
- }
-
- BPY_BM_CHECK_OBJ(py_edge);
- BPY_BM_CHECK_OBJ(py_vert);
-
- /* this doubles for checking that the verts are in the same mesh */
- if (!(py_edge->e->v1 == py_vert->v ||
- py_edge->e->v2 == py_vert->v))
- {
- PyErr_SetString(PyExc_ValueError,
- "vert_collapse_faces(vert, edge): the vertex is not found in the edge");
- return NULL;
- }
-
- if (BM_vert_edge_count_is_over(py_vert->v, 2)) {
- PyErr_SetString(PyExc_ValueError,
- "vert_collapse_faces(vert, edge): vert has more than 2 connected edges");
- return NULL;
- }
-
- bm = py_edge->bm;
-
- e_new = BM_vert_collapse_faces(bm, py_edge->e, py_vert->v, clamp_f(fac, 0.0f, 1.0f), true, do_join_faces, true);
-
- if (e_new) {
- return BPy_BMEdge_CreatePyObject(bm, e_new);
- }
- else {
- PyErr_SetString(PyExc_ValueError,
- "vert_collapse_faces(vert, edge): no new edge created, internal error");
- return NULL;
- }
+ BPy_BMEdge *py_edge;
+ BPy_BMVert *py_vert;
+
+ float fac;
+ int do_join_faces;
+
+ BMesh *bm;
+ BMEdge *e_new = NULL;
+
+ if (!PyArg_ParseTuple(args,
+ "O!O!fi:vert_collapse_faces",
+ &BPy_BMVert_Type,
+ &py_vert,
+ &BPy_BMEdge_Type,
+ &py_edge,
+ &fac,
+ &do_join_faces)) {
+ return NULL;
+ }
+
+ BPY_BM_CHECK_OBJ(py_edge);
+ BPY_BM_CHECK_OBJ(py_vert);
+
+ /* this doubles for checking that the verts are in the same mesh */
+ if (!(py_edge->e->v1 == py_vert->v || py_edge->e->v2 == py_vert->v)) {
+ PyErr_SetString(PyExc_ValueError,
+ "vert_collapse_faces(vert, edge): the vertex is not found in the edge");
+ return NULL;
+ }
+
+ if (BM_vert_edge_count_is_over(py_vert->v, 2)) {
+ PyErr_SetString(PyExc_ValueError,
+ "vert_collapse_faces(vert, edge): vert has more than 2 connected edges");
+ return NULL;
+ }
+
+ bm = py_edge->bm;
+
+ e_new = BM_vert_collapse_faces(
+ bm, py_edge->e, py_vert->v, clamp_f(fac, 0.0f, 1.0f), true, do_join_faces, true);
+
+ if (e_new) {
+ return BPy_BMEdge_CreatePyObject(bm, e_new);
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "vert_collapse_faces(vert, edge): no new edge created, internal error");
+ return NULL;
+ }
}
-
PyDoc_STRVAR(bpy_bm_utils_vert_dissolve_doc,
-".. method:: vert_dissolve(vert)\n"
-"\n"
-" Dissolve this vertex (will be removed).\n"
-"\n"
-" :arg vert: The vert to be dissolved.\n"
-" :type vert: :class:`bmesh.types.BMVert`\n"
-" :return: True when the vertex dissolve is successful.\n"
-" :rtype: boolean\n"
-);
+ ".. method:: vert_dissolve(vert)\n"
+ "\n"
+ " Dissolve this vertex (will be removed).\n"
+ "\n"
+ " :arg vert: The vert to be dissolved.\n"
+ " :type vert: :class:`bmesh.types.BMVert`\n"
+ " :return: True when the vertex dissolve is successful.\n"
+ " :rtype: boolean\n");
static PyObject *bpy_bm_utils_vert_dissolve(PyObject *UNUSED(self), PyObject *args)
{
- BPy_BMVert *py_vert;
+ BPy_BMVert *py_vert;
- BMesh *bm;
+ BMesh *bm;
- if (!PyArg_ParseTuple(args, "O!:vert_dissolve",
- &BPy_BMVert_Type, &py_vert))
- {
- return NULL;
- }
+ if (!PyArg_ParseTuple(args, "O!:vert_dissolve", &BPy_BMVert_Type, &py_vert)) {
+ return NULL;
+ }
- BPY_BM_CHECK_OBJ(py_vert);
+ BPY_BM_CHECK_OBJ(py_vert);
- bm = py_vert->bm;
+ bm = py_vert->bm;
- return PyBool_FromLong((BM_vert_dissolve(bm, py_vert->v)));
+ return PyBool_FromLong((BM_vert_dissolve(bm, py_vert->v)));
}
PyDoc_STRVAR(bpy_bm_utils_vert_splice_doc,
-".. method:: vert_splice(vert, vert_target)\n"
-"\n"
-" Splice vert into vert_target.\n"
-"\n"
-" :arg vert: The vertex to be removed.\n"
-" :type vert: :class:`bmesh.types.BMVert`\n"
-" :arg vert_target: The vertex to use.\n"
-" :type vert_target: :class:`bmesh.types.BMVert`\n"
-"\n"
-" .. note:: The verts mustn't share an edge or face.\n"
-);
+ ".. method:: vert_splice(vert, vert_target)\n"
+ "\n"
+ " Splice vert into vert_target.\n"
+ "\n"
+ " :arg vert: The vertex to be removed.\n"
+ " :type vert: :class:`bmesh.types.BMVert`\n"
+ " :arg vert_target: The vertex to use.\n"
+ " :type vert_target: :class:`bmesh.types.BMVert`\n"
+ "\n"
+ " .. note:: The verts mustn't share an edge or face.\n");
static PyObject *bpy_bm_utils_vert_splice(PyObject *UNUSED(self), PyObject *args)
{
- BPy_BMVert *py_vert;
- BPy_BMVert *py_vert_target;
-
- BMesh *bm;
-
- bool ok;
-
- if (!PyArg_ParseTuple(args, "O!O!:vert_splice",
- &BPy_BMVert_Type, &py_vert,
- &BPy_BMVert_Type, &py_vert_target))
- {
- return NULL;
- }
-
- BPY_BM_CHECK_OBJ(py_vert);
- BPY_BM_CHECK_OBJ(py_vert_target);
-
- bm = py_vert->bm;
- BPY_BM_CHECK_SOURCE_OBJ(bm, "vert_splice", py_vert_target);
-
- if (py_vert->v == py_vert_target->v) {
- PyErr_SetString(PyExc_ValueError,
- "vert_splice(...): vert arguments match");
- return NULL;
- }
-
- if (BM_edge_exists(py_vert->v, py_vert_target->v)) {
- PyErr_SetString(PyExc_ValueError,
- "vert_splice(...): verts can't share an edge");
- return NULL;
- }
-
- if (BM_vert_pair_share_face_check(py_vert->v, py_vert_target->v)) {
- PyErr_SetString(PyExc_ValueError,
- "vert_splice(...): verts can't share a face");
- return NULL;
- }
-
- /* should always succeed */
- ok = BM_vert_splice(bm, py_vert_target->v, py_vert->v);
- BLI_assert(ok == true);
- UNUSED_VARS_NDEBUG(ok);
-
- Py_RETURN_NONE;
+ BPy_BMVert *py_vert;
+ BPy_BMVert *py_vert_target;
+
+ BMesh *bm;
+
+ bool ok;
+
+ if (!PyArg_ParseTuple(args,
+ "O!O!:vert_splice",
+ &BPy_BMVert_Type,
+ &py_vert,
+ &BPy_BMVert_Type,
+ &py_vert_target)) {
+ return NULL;
+ }
+
+ BPY_BM_CHECK_OBJ(py_vert);
+ BPY_BM_CHECK_OBJ(py_vert_target);
+
+ bm = py_vert->bm;
+ BPY_BM_CHECK_SOURCE_OBJ(bm, "vert_splice", py_vert_target);
+
+ if (py_vert->v == py_vert_target->v) {
+ PyErr_SetString(PyExc_ValueError, "vert_splice(...): vert arguments match");
+ return NULL;
+ }
+
+ if (BM_edge_exists(py_vert->v, py_vert_target->v)) {
+ PyErr_SetString(PyExc_ValueError, "vert_splice(...): verts can't share an edge");
+ return NULL;
+ }
+
+ if (BM_vert_pair_share_face_check(py_vert->v, py_vert_target->v)) {
+ PyErr_SetString(PyExc_ValueError, "vert_splice(...): verts can't share a face");
+ return NULL;
+ }
+
+ /* should always succeed */
+ ok = BM_vert_splice(bm, py_vert_target->v, py_vert->v);
+ BLI_assert(ok == true);
+ UNUSED_VARS_NDEBUG(ok);
+
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(bpy_bm_utils_vert_separate_doc,
-".. method:: vert_separate(vert, edges)\n"
-"\n"
-" Separate this vertex at every edge.\n"
-"\n"
-" :arg vert: The vert to be separated.\n"
-" :type vert: :class:`bmesh.types.BMVert`\n"
-" :arg edges: The edges to separated.\n"
-" :type edges: :class:`bmesh.types.BMEdge`\n"
-" :return: The newly separated verts (including the vertex passed).\n"
-" :rtype: tuple of :class:`bmesh.types.BMVert`\n"
-);
+ ".. method:: vert_separate(vert, edges)\n"
+ "\n"
+ " Separate this vertex at every edge.\n"
+ "\n"
+ " :arg vert: The vert to be separated.\n"
+ " :type vert: :class:`bmesh.types.BMVert`\n"
+ " :arg edges: The edges to separated.\n"
+ " :type edges: :class:`bmesh.types.BMEdge`\n"
+ " :return: The newly separated verts (including the vertex passed).\n"
+ " :rtype: tuple of :class:`bmesh.types.BMVert`\n");
static PyObject *bpy_bm_utils_vert_separate(PyObject *UNUSED(self), PyObject *args)
{
- BPy_BMVert *py_vert;
- PyObject *edge_seq;
+ BPy_BMVert *py_vert;
+ PyObject *edge_seq;
- BMesh *bm;
- BMVert **elem;
- int elem_len;
+ BMesh *bm;
+ BMVert **elem;
+ int elem_len;
- /* edges to split */
- BMEdge **edge_array;
- Py_ssize_t edge_array_len;
+ /* edges to split */
+ BMEdge **edge_array;
+ Py_ssize_t edge_array_len;
- PyObject *ret;
+ PyObject *ret;
+ if (!PyArg_ParseTuple(args, "O!O:vert_separate", &BPy_BMVert_Type, &py_vert, &edge_seq)) {
+ return NULL;
+ }
- if (!PyArg_ParseTuple(args, "O!O:vert_separate",
- &BPy_BMVert_Type, &py_vert,
- &edge_seq))
- {
- return NULL;
- }
+ BPY_BM_CHECK_OBJ(py_vert);
- BPY_BM_CHECK_OBJ(py_vert);
+ bm = py_vert->bm;
- bm = py_vert->bm;
+ edge_array = BPy_BMElem_PySeq_As_Array(&bm,
+ edge_seq,
+ 0,
+ PY_SSIZE_T_MAX,
+ &edge_array_len,
+ BM_EDGE,
+ true,
+ true,
+ "vert_separate(...)");
- edge_array = BPy_BMElem_PySeq_As_Array(&bm, edge_seq, 0, PY_SSIZE_T_MAX,
- &edge_array_len, BM_EDGE,
- true, true, "vert_separate(...)");
+ if (edge_array == NULL) {
+ return NULL;
+ }
- if (edge_array == NULL) {
- return NULL;
- }
+ BM_vert_separate(bm, py_vert->v, edge_array, edge_array_len, false, &elem, &elem_len);
+ /* return collected verts */
+ ret = BPy_BMVert_Array_As_Tuple(bm, elem, elem_len);
+ MEM_freeN(elem);
- BM_vert_separate(bm, py_vert->v, edge_array, edge_array_len, false, &elem, &elem_len);
- /* return collected verts */
- ret = BPy_BMVert_Array_As_Tuple(bm, elem, elem_len);
- MEM_freeN(elem);
+ PyMem_FREE(edge_array);
- PyMem_FREE(edge_array);
-
- return ret;
+ return ret;
}
-
PyDoc_STRVAR(bpy_bm_utils_edge_split_doc,
-".. method:: edge_split(edge, vert, fac)\n"
-"\n"
-" Split an edge, return the newly created data.\n"
-"\n"
-" :arg edge: The edge to split.\n"
-" :type edge: :class:`bmesh.types.BMEdge`\n"
-" :arg vert: One of the verts on the edge, defines the split direction.\n"
-" :type vert: :class:`bmesh.types.BMVert`\n"
-" :arg fac: The point on the edge where the new vert will be created [0 - 1].\n"
-" :type fac: float\n"
-" :return: The newly created (edge, vert) pair.\n"
-" :rtype: tuple\n"
-);
+ ".. method:: edge_split(edge, vert, fac)\n"
+ "\n"
+ " Split an edge, return the newly created data.\n"
+ "\n"
+ " :arg edge: The edge to split.\n"
+ " :type edge: :class:`bmesh.types.BMEdge`\n"
+ " :arg vert: One of the verts on the edge, defines the split direction.\n"
+ " :type vert: :class:`bmesh.types.BMVert`\n"
+ " :arg fac: The point on the edge where the new vert will be created [0 - 1].\n"
+ " :type fac: float\n"
+ " :return: The newly created (edge, vert) pair.\n"
+ " :rtype: tuple\n");
static PyObject *bpy_bm_utils_edge_split(PyObject *UNUSED(self), PyObject *args)
{
- BPy_BMEdge *py_edge;
- BPy_BMVert *py_vert;
- float fac;
-
- BMesh *bm;
- BMVert *v_new = NULL;
- BMEdge *e_new = NULL;
-
- if (!PyArg_ParseTuple(args, "O!O!f:edge_split",
- &BPy_BMEdge_Type, &py_edge,
- &BPy_BMVert_Type, &py_vert,
- &fac))
- {
- return NULL;
- }
-
- BPY_BM_CHECK_OBJ(py_edge);
- BPY_BM_CHECK_OBJ(py_vert);
-
- /* this doubles for checking that the verts are in the same mesh */
- if (!(py_edge->e->v1 == py_vert->v ||
- py_edge->e->v2 == py_vert->v))
- {
- PyErr_SetString(PyExc_ValueError,
- "edge_split(edge, vert): the vertex is not found in the edge");
- return NULL;
- }
-
- bm = py_edge->bm;
-
- v_new = BM_edge_split(bm, py_edge->e, py_vert->v, &e_new, clamp_f(fac, 0.0f, 1.0f));
-
- if (v_new && e_new) {
- PyObject *ret = PyTuple_New(2);
- PyTuple_SET_ITEMS(ret,
- BPy_BMEdge_CreatePyObject(bm, e_new),
- BPy_BMVert_CreatePyObject(bm, v_new));
- return ret;
- }
- else {
- PyErr_SetString(PyExc_ValueError,
- "edge_split(edge, vert): couldn't split the edge, internal error");
- return NULL;
- }
+ BPy_BMEdge *py_edge;
+ BPy_BMVert *py_vert;
+ float fac;
+
+ BMesh *bm;
+ BMVert *v_new = NULL;
+ BMEdge *e_new = NULL;
+
+ if (!PyArg_ParseTuple(args,
+ "O!O!f:edge_split",
+ &BPy_BMEdge_Type,
+ &py_edge,
+ &BPy_BMVert_Type,
+ &py_vert,
+ &fac)) {
+ return NULL;
+ }
+
+ BPY_BM_CHECK_OBJ(py_edge);
+ BPY_BM_CHECK_OBJ(py_vert);
+
+ /* this doubles for checking that the verts are in the same mesh */
+ if (!(py_edge->e->v1 == py_vert->v || py_edge->e->v2 == py_vert->v)) {
+ PyErr_SetString(PyExc_ValueError,
+ "edge_split(edge, vert): the vertex is not found in the edge");
+ return NULL;
+ }
+
+ bm = py_edge->bm;
+
+ v_new = BM_edge_split(bm, py_edge->e, py_vert->v, &e_new, clamp_f(fac, 0.0f, 1.0f));
+
+ if (v_new && e_new) {
+ PyObject *ret = PyTuple_New(2);
+ PyTuple_SET_ITEMS(
+ ret, BPy_BMEdge_CreatePyObject(bm, e_new), BPy_BMVert_CreatePyObject(bm, v_new));
+ return ret;
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "edge_split(edge, vert): couldn't split the edge, internal error");
+ return NULL;
+ }
}
-
PyDoc_STRVAR(bpy_bm_utils_edge_rotate_doc,
-".. method:: edge_rotate(edge, ccw=False)\n"
-"\n"
-" Rotate the edge and return the newly created edge.\n"
-" If rotating the edge fails, None will be returned.\n"
-"\n"
-" :arg edge: The edge to rotate.\n"
-" :type edge: :class:`bmesh.types.BMEdge`\n"
-" :arg ccw: When True the edge will be rotated counter clockwise.\n"
-" :type ccw: boolean\n"
-" :return: The newly rotated edge.\n"
-" :rtype: :class:`bmesh.types.BMEdge`\n"
-);
+ ".. method:: edge_rotate(edge, ccw=False)\n"
+ "\n"
+ " Rotate the edge and return the newly created edge.\n"
+ " If rotating the edge fails, None will be returned.\n"
+ "\n"
+ " :arg edge: The edge to rotate.\n"
+ " :type edge: :class:`bmesh.types.BMEdge`\n"
+ " :arg ccw: When True the edge will be rotated counter clockwise.\n"
+ " :type ccw: boolean\n"
+ " :return: The newly rotated edge.\n"
+ " :rtype: :class:`bmesh.types.BMEdge`\n");
static PyObject *bpy_bm_utils_edge_rotate(PyObject *UNUSED(self), PyObject *args)
{
- BPy_BMEdge *py_edge;
- bool do_ccw = false;
+ BPy_BMEdge *py_edge;
+ bool do_ccw = false;
- BMesh *bm;
- BMEdge *e_new = NULL;
+ BMesh *bm;
+ BMEdge *e_new = NULL;
- if (!PyArg_ParseTuple(
- args, "O!|O&:edge_rotate",
- &BPy_BMEdge_Type, &py_edge,
- PyC_ParseBool, &do_ccw))
- {
- return NULL;
- }
+ if (!PyArg_ParseTuple(
+ args, "O!|O&:edge_rotate", &BPy_BMEdge_Type, &py_edge, PyC_ParseBool, &do_ccw)) {
+ return NULL;
+ }
- BPY_BM_CHECK_OBJ(py_edge);
+ BPY_BM_CHECK_OBJ(py_edge);
- bm = py_edge->bm;
+ bm = py_edge->bm;
- e_new = BM_edge_rotate(bm, py_edge->e, do_ccw, 0);
+ e_new = BM_edge_rotate(bm, py_edge->e, do_ccw, 0);
- if (e_new) {
- return BPy_BMEdge_CreatePyObject(bm, e_new);
- }
- else {
- Py_RETURN_NONE;
- }
+ if (e_new) {
+ return BPy_BMEdge_CreatePyObject(bm, e_new);
+ }
+ else {
+ Py_RETURN_NONE;
+ }
}
-
-PyDoc_STRVAR(bpy_bm_utils_face_split_doc,
-".. method:: face_split(face, vert_a, vert_b, coords=(), use_exist=True, example=None)\n"
-"\n"
-" Face split with optional intermediate points.\n"
-"\n"
-" :arg face: The face to cut.\n"
-" :type face: :class:`bmesh.types.BMFace`\n"
-" :arg vert_a: First vertex to cut in the face (face must contain the vert).\n"
-" :type vert_a: :class:`bmesh.types.BMVert`\n"
-" :arg vert_b: Second vertex to cut in the face (face must contain the vert).\n"
-" :type vert_b: :class:`bmesh.types.BMVert`\n"
-" :arg coords: Optional argument to define points in between *vert_a* and *vert_b*.\n"
-" :type coords: sequence of float triplets\n"
-" :arg use_exist: .Use an existing edge if it exists (Only used when *coords* argument is empty or omitted)\n"
-" :type use_exist: boolean\n"
-" :arg example: Newly created edge will copy settings from this one.\n"
-" :type example: :class:`bmesh.types.BMEdge`\n"
-" :return: The newly created face or None on failure.\n"
-" :rtype: (:class:`bmesh.types.BMFace`, :class:`bmesh.types.BMLoop`) pair\n"
-);
+PyDoc_STRVAR(
+ bpy_bm_utils_face_split_doc,
+ ".. method:: face_split(face, vert_a, vert_b, coords=(), use_exist=True, example=None)\n"
+ "\n"
+ " Face split with optional intermediate points.\n"
+ "\n"
+ " :arg face: The face to cut.\n"
+ " :type face: :class:`bmesh.types.BMFace`\n"
+ " :arg vert_a: First vertex to cut in the face (face must contain the vert).\n"
+ " :type vert_a: :class:`bmesh.types.BMVert`\n"
+ " :arg vert_b: Second vertex to cut in the face (face must contain the vert).\n"
+ " :type vert_b: :class:`bmesh.types.BMVert`\n"
+ " :arg coords: Optional argument to define points in between *vert_a* and *vert_b*.\n"
+ " :type coords: sequence of float triplets\n"
+ " :arg use_exist: .Use an existing edge if it exists (Only used when *coords* argument is "
+ "empty or omitted)\n"
+ " :type use_exist: boolean\n"
+ " :arg example: Newly created edge will copy settings from this one.\n"
+ " :type example: :class:`bmesh.types.BMEdge`\n"
+ " :return: The newly created face or None on failure.\n"
+ " :rtype: (:class:`bmesh.types.BMFace`, :class:`bmesh.types.BMLoop`) pair\n");
static PyObject *bpy_bm_utils_face_split(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
- static const char *kwlist[] = {"face", "vert_a", "vert_b",
- "coords", "use_exist", "example", NULL};
-
- BPy_BMFace *py_face;
- BPy_BMVert *py_vert_a;
- BPy_BMVert *py_vert_b;
-
- /* optional */
- PyObject *py_coords = NULL;
- bool edge_exists = true;
- BPy_BMEdge *py_edge_example = NULL;
-
- float *coords;
- int ncoords = 0;
-
- BMesh *bm;
- BMFace *f_new = NULL;
- BMLoop *l_new = NULL;
- BMLoop *l_a, *l_b;
-
- if (!PyArg_ParseTupleAndKeywords(
- args, kw,
- "O!O!O!|OO&O!:face_split", (char **)kwlist,
- &BPy_BMFace_Type, &py_face,
- &BPy_BMVert_Type, &py_vert_a,
- &BPy_BMVert_Type, &py_vert_b,
- &py_coords,
- PyC_ParseBool, &edge_exists,
- &BPy_BMEdge_Type, &py_edge_example))
- {
- return NULL;
- }
-
- BPY_BM_CHECK_OBJ(py_face);
- BPY_BM_CHECK_OBJ(py_vert_a);
- BPY_BM_CHECK_OBJ(py_vert_b);
-
- if (py_edge_example) {
- BPY_BM_CHECK_OBJ(py_edge_example);
- }
-
- /* this doubles for checking that the verts are in the same mesh */
- if ((l_a = BM_face_vert_share_loop(py_face->f, py_vert_a->v)) &&
- (l_b = BM_face_vert_share_loop(py_face->f, py_vert_b->v)))
- {
- /* pass */
- }
- else {
- PyErr_SetString(PyExc_ValueError,
- "face_split(...): one of the verts passed is not found in the face");
- return NULL;
- }
-
- if (py_vert_a->v == py_vert_b->v) {
- PyErr_SetString(PyExc_ValueError,
- "face_split(...): vert arguments must differ");
- return NULL;
- }
-
- if (py_coords) {
- ncoords = mathutils_array_parse_alloc_v(&coords, 3, py_coords, "face_split(...): ");
- if (ncoords == -1) {
- return NULL;
- }
- }
- else {
- if (BM_loop_is_adjacent(l_a, l_b)) {
- PyErr_SetString(PyExc_ValueError,
- "face_split(...): verts are adjacent in the face");
- return NULL;
- }
- }
-
- /* --- main function body --- */
- bm = py_face->bm;
-
- if (ncoords) {
- f_new = BM_face_split_n(bm, py_face->f,
- l_a, l_b,
- (float (*)[3])coords, ncoords,
- &l_new, py_edge_example ? py_edge_example->e : NULL);
- PyMem_Free(coords);
- }
- else {
- f_new = BM_face_split(bm, py_face->f,
- l_a, l_b,
- &l_new, py_edge_example ? py_edge_example->e : NULL, edge_exists);
- }
-
- if (f_new && l_new) {
- PyObject *ret = PyTuple_New(2);
- PyTuple_SET_ITEMS(ret,
- BPy_BMFace_CreatePyObject(bm, f_new),
- BPy_BMLoop_CreatePyObject(bm, l_new));
- return ret;
- }
- else {
- PyErr_SetString(PyExc_ValueError,
- "face_split(...): couldn't split the face, internal error");
- return NULL;
- }
+ static const char *kwlist[] = {
+ "face", "vert_a", "vert_b", "coords", "use_exist", "example", NULL};
+
+ BPy_BMFace *py_face;
+ BPy_BMVert *py_vert_a;
+ BPy_BMVert *py_vert_b;
+
+ /* optional */
+ PyObject *py_coords = NULL;
+ bool edge_exists = true;
+ BPy_BMEdge *py_edge_example = NULL;
+
+ float *coords;
+ int ncoords = 0;
+
+ BMesh *bm;
+ BMFace *f_new = NULL;
+ BMLoop *l_new = NULL;
+ BMLoop *l_a, *l_b;
+
+ if (!PyArg_ParseTupleAndKeywords(args,
+ kw,
+ "O!O!O!|OO&O!:face_split",
+ (char **)kwlist,
+ &BPy_BMFace_Type,
+ &py_face,
+ &BPy_BMVert_Type,
+ &py_vert_a,
+ &BPy_BMVert_Type,
+ &py_vert_b,
+ &py_coords,
+ PyC_ParseBool,
+ &edge_exists,
+ &BPy_BMEdge_Type,
+ &py_edge_example)) {
+ return NULL;
+ }
+
+ BPY_BM_CHECK_OBJ(py_face);
+ BPY_BM_CHECK_OBJ(py_vert_a);
+ BPY_BM_CHECK_OBJ(py_vert_b);
+
+ if (py_edge_example) {
+ BPY_BM_CHECK_OBJ(py_edge_example);
+ }
+
+ /* this doubles for checking that the verts are in the same mesh */
+ if ((l_a = BM_face_vert_share_loop(py_face->f, py_vert_a->v)) &&
+ (l_b = BM_face_vert_share_loop(py_face->f, py_vert_b->v))) {
+ /* pass */
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "face_split(...): one of the verts passed is not found in the face");
+ return NULL;
+ }
+
+ if (py_vert_a->v == py_vert_b->v) {
+ PyErr_SetString(PyExc_ValueError, "face_split(...): vert arguments must differ");
+ return NULL;
+ }
+
+ if (py_coords) {
+ ncoords = mathutils_array_parse_alloc_v(&coords, 3, py_coords, "face_split(...): ");
+ if (ncoords == -1) {
+ return NULL;
+ }
+ }
+ else {
+ if (BM_loop_is_adjacent(l_a, l_b)) {
+ PyErr_SetString(PyExc_ValueError, "face_split(...): verts are adjacent in the face");
+ return NULL;
+ }
+ }
+
+ /* --- main function body --- */
+ bm = py_face->bm;
+
+ if (ncoords) {
+ f_new = BM_face_split_n(bm,
+ py_face->f,
+ l_a,
+ l_b,
+ (float(*)[3])coords,
+ ncoords,
+ &l_new,
+ py_edge_example ? py_edge_example->e : NULL);
+ PyMem_Free(coords);
+ }
+ else {
+ f_new = BM_face_split(bm,
+ py_face->f,
+ l_a,
+ l_b,
+ &l_new,
+ py_edge_example ? py_edge_example->e : NULL,
+ edge_exists);
+ }
+
+ if (f_new && l_new) {
+ PyObject *ret = PyTuple_New(2);
+ PyTuple_SET_ITEMS(
+ ret, BPy_BMFace_CreatePyObject(bm, f_new), BPy_BMLoop_CreatePyObject(bm, l_new));
+ return ret;
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError, "face_split(...): couldn't split the face, internal error");
+ return NULL;
+ }
}
-
PyDoc_STRVAR(bpy_bm_utils_face_split_edgenet_doc,
-".. method:: face_split_edgenet(face, edgenet)\n"
-"\n"
-" Splits a face into any number of regions defined by an edgenet.\n"
-"\n"
-" :arg face: The face to split.\n"
-" :type face: :class:`bmesh.types.BMFace`\n"
-" :arg face: The face to split.\n"
-" :type face: :class:`bmesh.types.BMFace`\n"
-" :arg edgenet: Sequence of edges.\n"
-" :type edgenet: :class:`bmesh.types.BMEdge`\n"
-" :return: The newly created faces.\n"
-" :rtype: tuple of (:class:`bmesh.types.BMFace`)\n"
-"\n"
-" .. note::\n"
-"\n"
-" Regions defined by edges need to connect to the face, otherwise they're ignored as loose edges.\n"
-);
-static PyObject *bpy_bm_utils_face_split_edgenet(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
+ ".. method:: face_split_edgenet(face, edgenet)\n"
+ "\n"
+ " Splits a face into any number of regions defined by an edgenet.\n"
+ "\n"
+ " :arg face: The face to split.\n"
+ " :type face: :class:`bmesh.types.BMFace`\n"
+ " :arg face: The face to split.\n"
+ " :type face: :class:`bmesh.types.BMFace`\n"
+ " :arg edgenet: Sequence of edges.\n"
+ " :type edgenet: :class:`bmesh.types.BMEdge`\n"
+ " :return: The newly created faces.\n"
+ " :rtype: tuple of (:class:`bmesh.types.BMFace`)\n"
+ "\n"
+ " .. note::\n"
+ "\n"
+ " Regions defined by edges need to connect to the face, otherwise they're "
+ "ignored as loose edges.\n");
+static PyObject *bpy_bm_utils_face_split_edgenet(PyObject *UNUSED(self),
+ PyObject *args,
+ PyObject *kw)
{
- static const char *kwlist[] = {"face", "edgenet", NULL};
-
- BPy_BMFace *py_face;
- PyObject *edge_seq;
-
- BMEdge **edge_array;
- Py_ssize_t edge_array_len;
-
- BMesh *bm;
-
- BMFace **face_arr;
- int face_arr_len;
- bool ok;
-
-
- if (!PyArg_ParseTupleAndKeywords(args, kw, "O!O:face_split_edgenet", (char **)kwlist,
- &BPy_BMFace_Type, &py_face,
- &edge_seq))
- {
- return NULL;
- }
-
- BPY_BM_CHECK_OBJ(py_face);
-
- bm = py_face->bm;
-
- edge_array = BPy_BMElem_PySeq_As_Array(&bm, edge_seq, 1, PY_SSIZE_T_MAX,
- &edge_array_len, BM_EDGE,
- true, true, "face_split_edgenet(...)");
-
- if (edge_array == NULL) {
- return NULL;
- }
-
- /* --- main function body --- */
-
- ok = BM_face_split_edgenet(bm, py_face->f, edge_array, edge_array_len,
- &face_arr, &face_arr_len);
-
- PyMem_FREE(edge_array);
-
- if (ok) {
- PyObject *ret = BPy_BMFace_Array_As_Tuple(bm, face_arr, face_arr_len);
- if (face_arr) {
- MEM_freeN(face_arr);
- }
- return ret;
- }
- else {
- PyErr_SetString(PyExc_ValueError,
- "face_split_edgenet(...): couldn't split the face, internal error");
- return NULL;
- }
+ static const char *kwlist[] = {"face", "edgenet", NULL};
+
+ BPy_BMFace *py_face;
+ PyObject *edge_seq;
+
+ BMEdge **edge_array;
+ Py_ssize_t edge_array_len;
+
+ BMesh *bm;
+
+ BMFace **face_arr;
+ int face_arr_len;
+ bool ok;
+
+ if (!PyArg_ParseTupleAndKeywords(args,
+ kw,
+ "O!O:face_split_edgenet",
+ (char **)kwlist,
+ &BPy_BMFace_Type,
+ &py_face,
+ &edge_seq)) {
+ return NULL;
+ }
+
+ BPY_BM_CHECK_OBJ(py_face);
+
+ bm = py_face->bm;
+
+ edge_array = BPy_BMElem_PySeq_As_Array(&bm,
+ edge_seq,
+ 1,
+ PY_SSIZE_T_MAX,
+ &edge_array_len,
+ BM_EDGE,
+ true,
+ true,
+ "face_split_edgenet(...)");
+
+ if (edge_array == NULL) {
+ return NULL;
+ }
+
+ /* --- main function body --- */
+
+ ok = BM_face_split_edgenet(bm, py_face->f, edge_array, edge_array_len, &face_arr, &face_arr_len);
+
+ PyMem_FREE(edge_array);
+
+ if (ok) {
+ PyObject *ret = BPy_BMFace_Array_As_Tuple(bm, face_arr, face_arr_len);
+ if (face_arr) {
+ MEM_freeN(face_arr);
+ }
+ return ret;
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "face_split_edgenet(...): couldn't split the face, internal error");
+ return NULL;
+ }
}
-
PyDoc_STRVAR(bpy_bm_utils_face_join_doc,
-".. method:: face_join(faces, remove=True)\n"
-"\n"
-" Joins a sequence of faces.\n"
-"\n"
-" :arg faces: Sequence of faces.\n"
-" :type faces: :class:`bmesh.types.BMFace`\n"
-" :arg remove: Remove the edges and vertices between the faces.\n"
-" :type remove: boolean\n"
-" :return: The newly created face or None on failure.\n"
-" :rtype: :class:`bmesh.types.BMFace`\n"
-);
+ ".. method:: face_join(faces, remove=True)\n"
+ "\n"
+ " Joins a sequence of faces.\n"
+ "\n"
+ " :arg faces: Sequence of faces.\n"
+ " :type faces: :class:`bmesh.types.BMFace`\n"
+ " :arg remove: Remove the edges and vertices between the faces.\n"
+ " :type remove: boolean\n"
+ " :return: The newly created face or None on failure.\n"
+ " :rtype: :class:`bmesh.types.BMFace`\n");
static PyObject *bpy_bm_utils_face_join(PyObject *UNUSED(self), PyObject *args)
{
- BMesh *bm = NULL;
- PyObject *py_face_array;
- BMFace **face_array;
- Py_ssize_t face_seq_len = 0;
- BMFace *f_new;
- bool do_remove = true;
-
- if (!PyArg_ParseTuple(
- args, "O|O&:face_join",
- &py_face_array,
- PyC_ParseBool, &do_remove))
- {
- return NULL;
- }
-
- face_array = BPy_BMElem_PySeq_As_Array(&bm, py_face_array, 2, PY_SSIZE_T_MAX,
- &face_seq_len, BM_FACE,
- true, true, "face_join(...)");
-
- if (face_array == NULL) {
- return NULL; /* error will be set */
- }
-
- /* Go ahead and join the face!
- * --------------------------- */
- f_new = BM_faces_join(bm, face_array, (int)face_seq_len, do_remove);
-
- PyMem_FREE(face_array);
-
- if (f_new) {
- return BPy_BMFace_CreatePyObject(bm, f_new);
- }
- else {
- Py_RETURN_NONE;
- }
+ BMesh *bm = NULL;
+ PyObject *py_face_array;
+ BMFace **face_array;
+ Py_ssize_t face_seq_len = 0;
+ BMFace *f_new;
+ bool do_remove = true;
+
+ if (!PyArg_ParseTuple(args, "O|O&:face_join", &py_face_array, PyC_ParseBool, &do_remove)) {
+ return NULL;
+ }
+
+ face_array = BPy_BMElem_PySeq_As_Array(
+ &bm, py_face_array, 2, PY_SSIZE_T_MAX, &face_seq_len, BM_FACE, true, true, "face_join(...)");
+
+ if (face_array == NULL) {
+ return NULL; /* error will be set */
+ }
+
+ /* Go ahead and join the face!
+ * --------------------------- */
+ f_new = BM_faces_join(bm, face_array, (int)face_seq_len, do_remove);
+
+ PyMem_FREE(face_array);
+
+ if (f_new) {
+ return BPy_BMFace_CreatePyObject(bm, f_new);
+ }
+ else {
+ Py_RETURN_NONE;
+ }
}
-
-PyDoc_STRVAR(bpy_bm_utils_face_vert_separate_doc,
-".. method:: face_vert_separate(face, vert)\n"
-"\n"
-" Rip a vertex in a face away and add a new vertex.\n"
-"\n"
-" :arg face: The face to separate.\n"
-" :type face: :class:`bmesh.types.BMFace`\n"
-" :arg vert: A vertex in the face to separate.\n"
-" :type vert: :class:`bmesh.types.BMVert`\n"
-" :return vert: The newly created vertex or None on failure.\n"
-" :rtype vert: :class:`bmesh.types.BMVert`\n"
-"\n"
-" .. note::\n"
-"\n"
-" This is the same as loop_separate, and has only been added for convenience.\n"
-);
+PyDoc_STRVAR(
+ bpy_bm_utils_face_vert_separate_doc,
+ ".. method:: face_vert_separate(face, vert)\n"
+ "\n"
+ " Rip a vertex in a face away and add a new vertex.\n"
+ "\n"
+ " :arg face: The face to separate.\n"
+ " :type face: :class:`bmesh.types.BMFace`\n"
+ " :arg vert: A vertex in the face to separate.\n"
+ " :type vert: :class:`bmesh.types.BMVert`\n"
+ " :return vert: The newly created vertex or None on failure.\n"
+ " :rtype vert: :class:`bmesh.types.BMVert`\n"
+ "\n"
+ " .. note::\n"
+ "\n"
+ " This is the same as loop_separate, and has only been added for convenience.\n");
static PyObject *bpy_bm_utils_face_vert_separate(PyObject *UNUSED(self), PyObject *args)
{
- BPy_BMFace *py_face;
- BPy_BMVert *py_vert;
-
- BMesh *bm;
- BMLoop *l;
- BMVert *v_old, *v_new;
-
- if (!PyArg_ParseTuple(args, "O!O!:face_vert_separate",
- &BPy_BMFace_Type, &py_face,
- &BPy_BMVert_Type, &py_vert))
- {
- return NULL;
- }
-
- bm = py_face->bm;
-
- BPY_BM_CHECK_OBJ(py_face);
- BPY_BM_CHECK_SOURCE_OBJ(bm, "face_vert_separate()", py_vert);
-
- l = BM_face_vert_share_loop(py_face->f, py_vert->v);
-
- if (l == NULL) {
- PyErr_SetString(PyExc_ValueError,
- "vertex not found in face");
- return NULL;
- }
-
- v_old = l->v;
- v_new = BM_face_loop_separate(bm, l);
-
- if (v_new != v_old) {
- return BPy_BMVert_CreatePyObject(bm, v_new);
- }
- else {
- Py_RETURN_NONE;
- }
+ BPy_BMFace *py_face;
+ BPy_BMVert *py_vert;
+
+ BMesh *bm;
+ BMLoop *l;
+ BMVert *v_old, *v_new;
+
+ if (!PyArg_ParseTuple(args,
+ "O!O!:face_vert_separate",
+ &BPy_BMFace_Type,
+ &py_face,
+ &BPy_BMVert_Type,
+ &py_vert)) {
+ return NULL;
+ }
+
+ bm = py_face->bm;
+
+ BPY_BM_CHECK_OBJ(py_face);
+ BPY_BM_CHECK_SOURCE_OBJ(bm, "face_vert_separate()", py_vert);
+
+ l = BM_face_vert_share_loop(py_face->f, py_vert->v);
+
+ if (l == NULL) {
+ PyErr_SetString(PyExc_ValueError, "vertex not found in face");
+ return NULL;
+ }
+
+ v_old = l->v;
+ v_new = BM_face_loop_separate(bm, l);
+
+ if (v_new != v_old) {
+ return BPy_BMVert_CreatePyObject(bm, v_new);
+ }
+ else {
+ Py_RETURN_NONE;
+ }
}
-
PyDoc_STRVAR(bpy_bm_utils_face_flip_doc,
-".. method:: face_flip(faces)\n"
-"\n"
-" Flip the faces direction.\n"
-"\n"
-" :arg face: Face to flip.\n"
-" :type face: :class:`bmesh.types.BMFace`\n"
-);
+ ".. method:: face_flip(faces)\n"
+ "\n"
+ " Flip the faces direction.\n"
+ "\n"
+ " :arg face: Face to flip.\n"
+ " :type face: :class:`bmesh.types.BMFace`\n");
static PyObject *bpy_bm_utils_face_flip(PyObject *UNUSED(self), BPy_BMFace *value)
{
- if (!BPy_BMFace_Check(value)) {
- PyErr_Format(PyExc_TypeError,
- "face_flip(face): BMFace expected, not '%.200s'",
- Py_TYPE(value)->tp_name);
- return NULL;
- }
+ if (!BPy_BMFace_Check(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "face_flip(face): BMFace expected, not '%.200s'",
+ Py_TYPE(value)->tp_name);
+ return NULL;
+ }
- BPY_BM_CHECK_OBJ(value);
+ BPY_BM_CHECK_OBJ(value);
- BM_face_normal_flip(value->bm, value->f);
+ BM_face_normal_flip(value->bm, value->f);
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
-
-
PyDoc_STRVAR(bpy_bm_utils_loop_separate_doc,
-".. method:: loop_separate(loop)\n"
-"\n"
-" Rip a vertex in a face away and add a new vertex.\n"
-"\n"
-" :arg loop: The loop to separate.\n"
-" :type loop: :class:`bmesh.types.BMLoop`\n"
-" :return vert: The newly created vertex or None on failure.\n"
-" :rtype vert: :class:`bmesh.types.BMVert`\n"
-);
+ ".. method:: loop_separate(loop)\n"
+ "\n"
+ " Rip a vertex in a face away and add a new vertex.\n"
+ "\n"
+ " :arg loop: The loop to separate.\n"
+ " :type loop: :class:`bmesh.types.BMLoop`\n"
+ " :return vert: The newly created vertex or None on failure.\n"
+ " :rtype vert: :class:`bmesh.types.BMVert`\n");
static PyObject *bpy_bm_utils_loop_separate(PyObject *UNUSED(self), BPy_BMLoop *value)
{
- BMesh *bm;
- BMLoop *l;
- BMVert *v_old, *v_new;
-
- if (!BPy_BMLoop_Check(value)) {
- PyErr_Format(PyExc_TypeError,
- "loop_separate(loop): BMLoop expected, not '%.200s'",
- Py_TYPE(value)->tp_name);
- return NULL;
- }
-
- BPY_BM_CHECK_OBJ(value);
-
- bm = value->bm;
- l = value->l;
-
- v_old = l->v;
- v_new = BM_face_loop_separate(bm, l);
-
- if (v_new != v_old) {
- return BPy_BMVert_CreatePyObject(bm, v_new);
- }
- else {
- Py_RETURN_NONE;
- }
+ BMesh *bm;
+ BMLoop *l;
+ BMVert *v_old, *v_new;
+
+ if (!BPy_BMLoop_Check(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "loop_separate(loop): BMLoop expected, not '%.200s'",
+ Py_TYPE(value)->tp_name);
+ return NULL;
+ }
+
+ BPY_BM_CHECK_OBJ(value);
+
+ bm = value->bm;
+ l = value->l;
+
+ v_old = l->v;
+ v_new = BM_face_loop_separate(bm, l);
+
+ if (v_new != v_old) {
+ return BPy_BMVert_CreatePyObject(bm, v_new);
+ }
+ else {
+ Py_RETURN_NONE;
+ }
}
-
static struct PyMethodDef BPy_BM_utils_methods[] = {
- {"vert_collapse_edge", (PyCFunction)bpy_bm_utils_vert_collapse_edge, METH_VARARGS, bpy_bm_utils_vert_collapse_edge_doc},
- {"vert_collapse_faces", (PyCFunction)bpy_bm_utils_vert_collapse_faces, METH_VARARGS, bpy_bm_utils_vert_collapse_faces_doc},
- {"vert_dissolve", (PyCFunction)bpy_bm_utils_vert_dissolve, METH_VARARGS, bpy_bm_utils_vert_dissolve_doc}, /* could use METH_O */
- {"vert_splice", (PyCFunction)bpy_bm_utils_vert_splice, METH_VARARGS, bpy_bm_utils_vert_splice_doc},
- {"vert_separate", (PyCFunction)bpy_bm_utils_vert_separate, METH_VARARGS, bpy_bm_utils_vert_separate_doc},
- {"edge_split", (PyCFunction)bpy_bm_utils_edge_split, METH_VARARGS, bpy_bm_utils_edge_split_doc},
- {"edge_rotate", (PyCFunction)bpy_bm_utils_edge_rotate, METH_VARARGS, bpy_bm_utils_edge_rotate_doc},
- {"face_split", (PyCFunction)bpy_bm_utils_face_split, METH_VARARGS | METH_KEYWORDS, bpy_bm_utils_face_split_doc},
- {"face_split_edgenet", (PyCFunction)bpy_bm_utils_face_split_edgenet, METH_VARARGS | METH_KEYWORDS, bpy_bm_utils_face_split_edgenet_doc},
- {"face_join", (PyCFunction)bpy_bm_utils_face_join, METH_VARARGS, bpy_bm_utils_face_join_doc},
- {"face_vert_separate", (PyCFunction)bpy_bm_utils_face_vert_separate, METH_VARARGS, bpy_bm_utils_face_vert_separate_doc},
- {"face_flip", (PyCFunction)bpy_bm_utils_face_flip, METH_O, bpy_bm_utils_face_flip_doc},
- {"loop_separate", (PyCFunction)bpy_bm_utils_loop_separate, METH_O, bpy_bm_utils_loop_separate_doc},
- {NULL, NULL, 0, NULL},
+ {"vert_collapse_edge",
+ (PyCFunction)bpy_bm_utils_vert_collapse_edge,
+ METH_VARARGS,
+ bpy_bm_utils_vert_collapse_edge_doc},
+ {"vert_collapse_faces",
+ (PyCFunction)bpy_bm_utils_vert_collapse_faces,
+ METH_VARARGS,
+ bpy_bm_utils_vert_collapse_faces_doc},
+ {"vert_dissolve",
+ (PyCFunction)bpy_bm_utils_vert_dissolve,
+ METH_VARARGS,
+ bpy_bm_utils_vert_dissolve_doc}, /* could use METH_O */
+ {"vert_splice",
+ (PyCFunction)bpy_bm_utils_vert_splice,
+ METH_VARARGS,
+ bpy_bm_utils_vert_splice_doc},
+ {"vert_separate",
+ (PyCFunction)bpy_bm_utils_vert_separate,
+ METH_VARARGS,
+ bpy_bm_utils_vert_separate_doc},
+ {"edge_split",
+ (PyCFunction)bpy_bm_utils_edge_split,
+ METH_VARARGS,
+ bpy_bm_utils_edge_split_doc},
+ {"edge_rotate",
+ (PyCFunction)bpy_bm_utils_edge_rotate,
+ METH_VARARGS,
+ bpy_bm_utils_edge_rotate_doc},
+ {"face_split",
+ (PyCFunction)bpy_bm_utils_face_split,
+ METH_VARARGS | METH_KEYWORDS,
+ bpy_bm_utils_face_split_doc},
+ {"face_split_edgenet",
+ (PyCFunction)bpy_bm_utils_face_split_edgenet,
+ METH_VARARGS | METH_KEYWORDS,
+ bpy_bm_utils_face_split_edgenet_doc},
+ {"face_join", (PyCFunction)bpy_bm_utils_face_join, METH_VARARGS, bpy_bm_utils_face_join_doc},
+ {"face_vert_separate",
+ (PyCFunction)bpy_bm_utils_face_vert_separate,
+ METH_VARARGS,
+ bpy_bm_utils_face_vert_separate_doc},
+ {"face_flip", (PyCFunction)bpy_bm_utils_face_flip, METH_O, bpy_bm_utils_face_flip_doc},
+ {"loop_separate",
+ (PyCFunction)bpy_bm_utils_loop_separate,
+ METH_O,
+ bpy_bm_utils_loop_separate_doc},
+ {NULL, NULL, 0, NULL},
};
-
-PyDoc_STRVAR(BPy_BM_utils_doc,
-"This module provides access to blenders bmesh data structures."
-);
+PyDoc_STRVAR(BPy_BM_utils_doc, "This module provides access to blenders bmesh data structures.");
static struct PyModuleDef BPy_BM_utils_module_def = {
- PyModuleDef_HEAD_INIT,
- "bmesh.utils", /* m_name */
- BPy_BM_utils_doc, /* m_doc */
- 0, /* m_size */
- BPy_BM_utils_methods, /* m_methods */
- NULL, /* m_reload */
- NULL, /* m_traverse */
- NULL, /* m_clear */
- NULL, /* m_free */
+ PyModuleDef_HEAD_INIT,
+ "bmesh.utils", /* m_name */
+ BPy_BM_utils_doc, /* m_doc */
+ 0, /* m_size */
+ BPy_BM_utils_methods, /* m_methods */
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL, /* m_free */
};
-
PyObject *BPyInit_bmesh_utils(void)
{
- PyObject *submodule;
+ PyObject *submodule;
- submodule = PyModule_Create(&BPy_BM_utils_module_def);
+ submodule = PyModule_Create(&BPy_BM_utils_module_def);
- return submodule;
+ return submodule;
}