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