Blender V5.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
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#include "DNA_scene_types.h"
29
31
32#include "bmesh_py_api.hh" /* own include */
33
34namespace blender {
35
37 /* Wrap. */
38 bpy_bm_new_doc,
39 ".. function:: new(*, use_operators=True)\n"
40 "\n"
41 " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some "
42 "extra memory per vert/edge/face).\n"
43 " :type use_operators: bool\n"
44 " :return: Return a new, empty BMesh.\n"
45 " :rtype: :class:`bmesh.types.BMesh`\n");
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(args,
54 kw,
55 "|$" /* Optional, keyword only arguments. */
56 "O&" /* `use_operators` */
57 ":new",
58 const_cast<char **>(kwlist),
60 &use_operators))
61 {
62 return nullptr;
63 }
64
65 BMeshCreateParams params{};
66 params.use_toolflags = use_operators;
69
71}
72
74 /* Wrap. */
75 bpy_bm_from_edit_mesh_doc,
76 ".. function:: from_edit_mesh(mesh)\n"
77 "\n"
78 " Return a BMesh from this mesh, currently the mesh must already be in editmode.\n"
79 "\n"
80 " :param mesh: The editmode mesh.\n"
81 " :type mesh: :class:`bpy.types.Mesh`\n"
82 " :return: the BMesh associated with this mesh.\n"
83 " :rtype: :class:`bmesh.types.BMesh`\n");
84static PyObject *bpy_bm_from_edit_mesh(PyObject * /*self*/, PyObject *value)
85{
86 Mesh *mesh = static_cast<Mesh *>(PyC_RNA_AsPointer(value, "Mesh"));
87
88 if (mesh == nullptr) {
89 return nullptr;
90 }
91
92 if (mesh->runtime->edit_mesh == nullptr) {
93 PyErr_SetString(PyExc_ValueError, "The mesh must be in editmode");
94 return nullptr;
95 }
96
98
100}
101
102void EDBM_update_extern(Mesh *mesh, const bool do_tessface, const bool is_destructive);
103
105 /* Wrap. */
106 bpy_bm_update_edit_mesh_doc,
107 ".. function:: update_edit_mesh(mesh, *, loop_triangles=True, destructive=True)\n"
108 "\n"
109 " Update the mesh after changes to the BMesh in editmode,\n"
110 " optionally recalculating n-gon tessellation.\n"
111 "\n"
112 " :param mesh: The editmode mesh.\n"
113 " :type mesh: :class:`bpy.types.Mesh`\n"
114 " :param loop_triangles: Option to recalculate n-gon tessellation.\n"
115 " :type loop_triangles: bool\n"
116 " :param destructive: Use when geometry has been added or removed.\n"
117 " :type destructive: bool\n");
118static PyObject *bpy_bm_update_edit_mesh(PyObject * /*self*/, PyObject *args, PyObject *kw)
119{
120 static const char *kwlist[] = {"mesh", "loop_triangles", "destructive", nullptr};
121 PyObject *py_me;
122 Mesh *mesh;
123 bool do_loop_triangles = true;
124 bool is_destructive = true;
125
126 if (!PyArg_ParseTupleAndKeywords(args,
127 kw,
128 "O" /* `mesh` */
129 "|$" /* Optional, keyword only arguments. */
130 "O&" /* `loop_triangles` */
131 "O&" /* `destructive` */
132 ":update_edit_mesh",
133 const_cast<char **>(kwlist),
134 &py_me,
136 &do_loop_triangles,
138 &is_destructive))
139 {
140 return nullptr;
141 }
142
143 mesh = static_cast<Mesh *>(PyC_RNA_AsPointer(py_me, "Mesh"));
144
145 if (mesh == nullptr) {
146 return nullptr;
147 }
148
149 if (mesh->runtime->edit_mesh == nullptr) {
150 PyErr_SetString(PyExc_ValueError, "The mesh must be in editmode");
151 return nullptr;
152 }
153
154 {
155 EDBM_update_extern(mesh, do_loop_triangles, is_destructive);
156 }
157
158 Py_RETURN_NONE;
159}
160
161#ifdef __GNUC__
162# ifdef __clang__
163# pragma clang diagnostic push
164# pragma clang diagnostic ignored "-Wcast-function-type"
165# else
166# pragma GCC diagnostic push
167# pragma GCC diagnostic ignored "-Wcast-function-type"
168# endif
169#endif
170
171static PyMethodDef BPy_BM_methods[] = {
172 {"new",
173 reinterpret_cast<PyCFunction>(bpy_bm_new),
174 METH_VARARGS | METH_KEYWORDS,
175 bpy_bm_new_doc},
176 {"from_edit_mesh",
177 static_cast<PyCFunction>(bpy_bm_from_edit_mesh),
178 METH_O,
179 bpy_bm_from_edit_mesh_doc},
180 {"update_edit_mesh",
181 reinterpret_cast<PyCFunction>(bpy_bm_update_edit_mesh),
182 METH_VARARGS | METH_KEYWORDS,
183 bpy_bm_update_edit_mesh_doc},
184 {nullptr, nullptr, 0, nullptr},
185};
186
187#ifdef __GNUC__
188# ifdef __clang__
189# pragma clang diagnostic pop
190# else
191# pragma GCC diagnostic pop
192# endif
193#endif
194
196 /* Wrap. */
197 BPy_BM_doc,
198 "This module provides access to Blender's bmesh data structures.\n"
199 "\n"
200 ".. include:: include__bmesh.rst\n");
201static PyModuleDef BPy_BM_module_def = {
202 /*m_base*/ PyModuleDef_HEAD_INIT,
203 /*m_name*/ "bmesh",
204 /*m_doc*/ BPy_BM_doc,
205 /*m_size*/ 0,
206 /*m_methods*/ BPy_BM_methods,
207 /*m_slots*/ nullptr,
208 /*m_traverse*/ nullptr,
209 /*m_clear*/ nullptr,
210 /*m_free*/ nullptr,
211};
212
213PyObject *BPyInit_bmesh()
214{
215 PyObject *mod;
216 PyObject *submodule;
217 PyObject *sys_modules = PyImport_GetModuleDict();
218
223
224 mod = PyModule_Create(&BPy_BM_module_def);
225
226 /* bmesh.types */
227 PyModule_AddObject(mod, "types", (submodule = BPyInit_bmesh_types()));
228 PyC_Module_AddToSysModules(sys_modules, submodule);
229
230 /* bmesh.ops (not a real module, exposes module like access). */
231 PyModule_AddObject(mod, "ops", (submodule = BPyInit_bmesh_ops()));
232 PyC_Module_AddToSysModules(sys_modules, submodule);
233
234 PyModule_AddObject(mod, "utils", (submodule = BPyInit_bmesh_utils()));
235 PyC_Module_AddToSysModules(sys_modules, submodule);
236
237 PyModule_AddObject(mod, "geometry", (submodule = BPyInit_bmesh_geometry()));
238 PyC_Module_AddToSysModules(sys_modules, submodule);
239
240 return mod;
241}
242
243} // namespace blender
VecBase< float, D > constexpr mod(VecOp< float, D >, VecOp< float, D >) RET
BMesh Iterators.
int PyC_ParseBool(PyObject *o, void *p)
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
void BPy_BM_init_types_select()
PyObject * BPyInit_bmesh_ops()
static PyMethodDef BPy_BM_methods[]
PyObject * BPyInit_bmesh()
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
static PyObject * bpy_bm_from_edit_mesh(PyObject *, PyObject *value)
PyObject * BPyInit_bmesh_types()
static PyObject * bpy_bm_new(PyObject *, PyObject *args, PyObject *kw)
static PyObject * bpy_bm_update_edit_mesh(PyObject *, PyObject *args, PyObject *kw)
static PyModuleDef BPy_BM_module_def
const BMAllocTemplate bm_mesh_allocsize_default
Definition bmesh_mesh.cc:26
void BPy_BM_init_types()
void * PyC_RNA_AsPointer(PyObject *value, const char *type_name)
void EDBM_update_extern(Mesh *mesh, bool do_tessellation, bool is_destructive)
int PyC_Module_AddToSysModules(PyObject *sys_modules, PyObject *module)
PyObject * BPy_BMesh_CreatePyObject(BMesh *bm, int flag)
PyObject * BPyInit_bmesh_geometry()
BMesh * BM_mesh_create(const BMAllocTemplate *allocsize, const BMeshCreateParams *params)
BMesh Make Mesh.
void BPy_BM_init_types_meshdata()
@ BPY_BMFLAG_IS_WRAPPED
PyObject * BPyInit_bmesh_utils()