Blender V4.3
bmesh_py_api.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2012 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11#include <Python.h>
12
13#include "BLI_utildefines.h"
14
15#include "bmesh.hh"
16
17#include "bmesh_py_types.hh"
21
22#include "bmesh_py_geometry.hh"
23#include "bmesh_py_ops.hh"
24#include "bmesh_py_utils.hh"
25
26#include "BKE_editmesh.hh"
27#include "BKE_mesh_types.hh"
28
29#include "DNA_mesh_types.h"
30
32
33#include "bmesh_py_api.hh" /* own include */
34
36 /* Wrap. */
37 bpy_bm_new_doc,
38 ".. method:: new(use_operators=True)\n"
39 "\n"
40 " :arg use_operators: Support calling operators in :mod:`bmesh.ops` (uses some "
41 "extra memory per vert/edge/face).\n"
42 " :type use_operators: bool\n"
43 " :return: Return a new, empty BMesh.\n"
44 " :rtype: :class:`bmesh.types.BMesh`\n");
45
46static PyObject *bpy_bm_new(PyObject * /*self*/, PyObject *args, PyObject *kw)
47{
48 static const char *kwlist[] = {"use_operators", nullptr};
49 BMesh *bm;
50
51 bool use_operators = true;
52
53 if (!PyArg_ParseTupleAndKeywords(
54 args, kw, "|$O&:new", (char **)kwlist, PyC_ParseBool, &use_operators))
55 {
56 return nullptr;
57 }
58
60 params.use_toolflags = use_operators;
62
64}
65
67 /* Wrap. */
68 bpy_bm_from_edit_mesh_doc,
69 ".. method:: from_edit_mesh(mesh)\n"
70 "\n"
71 " Return a BMesh from this mesh, currently the mesh must already be in editmode.\n"
72 "\n"
73 " :arg mesh: The editmode mesh.\n"
74 " :type mesh: :class:`bpy.types.Mesh`\n"
75 " :return: the BMesh associated with this mesh.\n"
76 " :rtype: :class:`bmesh.types.BMesh`\n");
77static PyObject *bpy_bm_from_edit_mesh(PyObject * /*self*/, PyObject *value)
78{
79 BMesh *bm;
80 Mesh *mesh = static_cast<Mesh *>(PyC_RNA_AsPointer(value, "Mesh"));
81
82 if (mesh == nullptr) {
83 return nullptr;
84 }
85
86 if (mesh->runtime->edit_mesh == nullptr) {
87 PyErr_SetString(PyExc_ValueError, "The mesh must be in editmode");
88 return nullptr;
89 }
90
91 bm = mesh->runtime->edit_mesh->bm;
92
94}
95
96void EDBM_update_extern(Mesh *mesh, const bool do_tessface, const bool is_destructive);
97
99 /* Wrap. */
100 bpy_bm_update_edit_mesh_doc,
101 ".. method:: update_edit_mesh(mesh, loop_triangles=True, destructive=True)\n"
102 "\n"
103 " Update the mesh after changes to the BMesh in editmode,\n"
104 " optionally recalculating n-gon tessellation.\n"
105 "\n"
106 " :arg mesh: The editmode mesh.\n"
107 " :type mesh: :class:`bpy.types.Mesh`\n"
108 " :arg loop_triangles: Option to recalculate n-gon tessellation.\n"
109 " :type loop_triangles: bool\n"
110 " :arg destructive: Use when geometry has been added or removed.\n"
111 " :type destructive: bool\n");
112static PyObject *bpy_bm_update_edit_mesh(PyObject * /*self*/, PyObject *args, PyObject *kw)
113{
114 static const char *kwlist[] = {"mesh", "loop_triangles", "destructive", nullptr};
115 PyObject *py_me;
116 Mesh *mesh;
117 bool do_loop_triangles = true;
118 bool is_destructive = true;
119
120 if (!PyArg_ParseTupleAndKeywords(args,
121 kw,
122 "O|$O&O&:update_edit_mesh",
123 (char **)kwlist,
124 &py_me,
126 &do_loop_triangles,
128 &is_destructive))
129 {
130 return nullptr;
131 }
132
133 mesh = static_cast<Mesh *>(PyC_RNA_AsPointer(py_me, "Mesh"));
134
135 if (mesh == nullptr) {
136 return nullptr;
137 }
138
139 if (mesh->runtime->edit_mesh == nullptr) {
140 PyErr_SetString(PyExc_ValueError, "The mesh must be in editmode");
141 return nullptr;
142 }
143
144 {
145 EDBM_update_extern(mesh, do_loop_triangles, is_destructive);
146 }
147
148 Py_RETURN_NONE;
149}
150
151#if (defined(__GNUC__) && !defined(__clang__))
152# pragma GCC diagnostic push
153# pragma GCC diagnostic ignored "-Wcast-function-type"
154#endif
155
156static PyMethodDef BPy_BM_methods[] = {
157 {"new", (PyCFunction)bpy_bm_new, METH_VARARGS | METH_KEYWORDS, bpy_bm_new_doc},
158 {"from_edit_mesh", (PyCFunction)bpy_bm_from_edit_mesh, METH_O, bpy_bm_from_edit_mesh_doc},
159 {"update_edit_mesh",
160 (PyCFunction)bpy_bm_update_edit_mesh,
161 METH_VARARGS | METH_KEYWORDS,
162 bpy_bm_update_edit_mesh_doc},
163 {nullptr, nullptr, 0, nullptr},
164};
165
166#if (defined(__GNUC__) && !defined(__clang__))
167# pragma GCC diagnostic pop
168#endif
169
171 /* Wrap. */
172 BPy_BM_doc,
173 "This module provides access to blenders bmesh data structures.\n"
174 "\n"
175 ".. include:: include__bmesh.rst\n");
176static PyModuleDef BPy_BM_module_def = {
177 /*m_base*/ PyModuleDef_HEAD_INIT,
178 /*m_name*/ "bmesh",
179 /*m_doc*/ BPy_BM_doc,
180 /*m_size*/ 0,
181 /*m_methods*/ BPy_BM_methods,
182 /*m_slots*/ nullptr,
183 /*m_traverse*/ nullptr,
184 /*m_clear*/ nullptr,
185 /*m_free*/ nullptr,
186};
187
188PyObject *BPyInit_bmesh()
189{
190 PyObject *mod;
191 PyObject *submodule;
192 PyObject *sys_modules = PyImport_GetModuleDict();
193
198
199 mod = PyModule_Create(&BPy_BM_module_def);
200
201 /* bmesh.types */
202 PyModule_AddObject(mod, "types", (submodule = BPyInit_bmesh_types()));
203 PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
204
205 /* bmesh.ops (not a real module, exposes module like access). */
206 PyModule_AddObject(mod, "ops", (submodule = BPyInit_bmesh_ops()));
207 PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
208
209 PyModule_AddObject(mod, "utils", (submodule = BPyInit_bmesh_utils()));
210 PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
211
212 PyModule_AddObject(mod, "geometry", (submodule = BPyInit_bmesh_geometry()));
213 PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
214
215 return mod;
216}
ATTR_WARN_UNUSED_RESULT BMesh * bm
const BMAllocTemplate bm_mesh_allocsize_default
Definition bmesh_mesh.cc:29
BMesh * BM_mesh_create(const BMAllocTemplate *allocsize, const BMeshCreateParams *params)
BMesh Make Mesh.
static PyObject * bpy_bm_from_edit_mesh(PyObject *, PyObject *value)
static PyMethodDef BPy_BM_methods[]
static PyObject * bpy_bm_update_edit_mesh(PyObject *, PyObject *args, PyObject *kw)
static PyObject * bpy_bm_new(PyObject *, PyObject *args, PyObject *kw)
static PyModuleDef BPy_BM_module_def
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")
PyObject * BPyInit_bmesh()
void EDBM_update_extern(Mesh *mesh, const bool do_tessface, const bool is_destructive)
PyObject * BPyInit_bmesh_geometry()
PyObject * BPyInit_bmesh_ops()
PyObject * BPy_BMesh_CreatePyObject(BMesh *bm, int flag)
void BPy_BM_init_types()
PyObject * BPyInit_bmesh_types()
@ BPY_BMFLAG_IS_WRAPPED
@ BPY_BMFLAG_NOP
void BPy_BM_init_types_customdata()
void BPy_BM_init_types_meshdata()
void BPy_BM_init_types_select()
PyObject * BPyInit_bmesh_utils()
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void * PyC_RNA_AsPointer(PyObject *value, const char *type_name)
int PyC_ParseBool(PyObject *o, void *p)
ccl_device_inline int mod(int x, int m)
Definition util/math.h:520