2012-02-22 09:19:53 +00:00
|
|
|
/*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
2012-02-23 05:20:09 +00:00
|
|
|
* The Original Code is Copyright (C) 2012 Blender Foundation.
|
2012-02-22 09:19:53 +00:00
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup pybmesh
|
2012-02-22 09:19:53 +00:00
|
|
|
*
|
2012-02-23 05:20:09 +00:00
|
|
|
* This file defines the 'bmesh' module.
|
2012-02-22 09:19:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <Python.h>
|
|
|
|
|
|
2012-03-24 01:24:58 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2012-02-22 09:19:53 +00:00
|
|
|
#include "bmesh.h"
|
|
|
|
|
|
|
|
|
|
#include "bmesh_py_types.h"
|
2012-03-16 05:03:13 +00:00
|
|
|
#include "bmesh_py_types_customdata.h"
|
2012-03-17 06:40:44 +00:00
|
|
|
#include "bmesh_py_types_meshdata.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "bmesh_py_types_select.h"
|
2012-03-16 05:03:13 +00:00
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "bmesh_py_geometry.h"
|
2012-06-26 21:40:01 +00:00
|
|
|
#include "bmesh_py_ops.h"
|
2012-02-23 05:20:09 +00:00
|
|
|
#include "bmesh_py_utils.h"
|
2012-02-22 09:19:53 +00:00
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
#include "BKE_editmesh.h"
|
2012-02-22 09:19:53 +00:00
|
|
|
|
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
|
|
|
|
|
#include "../generic/py_capi_utils.h"
|
|
|
|
|
|
|
|
|
|
#include "bmesh_py_api.h" /* own include */
|
|
|
|
|
|
2012-03-10 20:41:19 +00:00
|
|
|
PyDoc_STRVAR(bpy_bm_new_doc,
|
2016-07-01 19:07:11 +10:00
|
|
|
".. method:: new(use_operators=True)\n"
|
2012-03-10 20:41:19 +00:00
|
|
|
"\n"
|
2016-07-01 19:07:11 +10:00
|
|
|
" :arg use_operators: Support calling operators in :mod:`bmesh.ops` (uses some "
|
|
|
|
|
"extra memory per vert/edge/face).\n"
|
|
|
|
|
" :type use_operators: bool\n"
|
2012-03-11 04:07:22 +00:00
|
|
|
" :return: Return a new, empty BMesh.\n"
|
|
|
|
|
" :rtype: :class:`bmesh.types.BMesh`\n");
|
2012-03-10 20:41:19 +00:00
|
|
|
|
2016-07-01 19:07:11 +10:00
|
|
|
static PyObject *bpy_bm_new(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
|
2012-03-10 20:41:19 +00:00
|
|
|
{
|
2016-07-01 19:07:11 +10:00
|
|
|
static const char *kwlist[] = {"use_operators", NULL};
|
2012-03-10 20:41:19 +00:00
|
|
|
BMesh *bm;
|
|
|
|
|
|
2016-07-01 19:07:11 +10:00
|
|
|
bool use_operators = true;
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
}));
|
2012-03-10 20:41:19 +00:00
|
|
|
|
2012-03-11 05:58:22 +00:00
|
|
|
return BPy_BMesh_CreatePyObject(bm, BPY_BMFLAG_NOP);
|
2012-03-10 20:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-11 02:45:27 +00:00
|
|
|
PyDoc_STRVAR(bpy_bm_from_edit_mesh_doc,
|
|
|
|
|
".. method:: from_edit_mesh(mesh)\n"
|
2012-02-22 09:19:53 +00:00
|
|
|
"\n"
|
2012-02-24 04:59:13 +00:00
|
|
|
" Return a BMesh from this mesh, currently the mesh must already be in editmode.\n"
|
|
|
|
|
"\n"
|
2012-11-29 05:02:06 +00:00
|
|
|
" :arg mesh: The editmode mesh.\n"
|
|
|
|
|
" :type mesh: :class:`bpy.types.Mesh`\n"
|
2012-07-04 15:04:38 +00:00
|
|
|
" :return: the BMesh associated with this mesh.\n"
|
2012-02-24 04:59:13 +00:00
|
|
|
" :rtype: :class:`bmesh.types.BMesh`\n");
|
2012-03-11 02:45:27 +00:00
|
|
|
static PyObject *bpy_bm_from_edit_mesh(PyObject *UNUSED(self), PyObject *value)
|
2012-02-22 09:19:53 +00:00
|
|
|
{
|
2012-03-10 20:41:19 +00:00
|
|
|
BMesh *bm;
|
2012-02-22 09:19:53 +00:00
|
|
|
Mesh *me = PyC_RNA_AsPointer(value, "Mesh");
|
|
|
|
|
|
2012-03-10 20:41:19 +00:00
|
|
|
if (me == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2012-03-04 11:10:11 +00:00
|
|
|
|
2019-02-17 18:05:18 +11:00
|
|
|
if (me->edit_mesh == NULL) {
|
2012-03-11 02:45:27 +00:00
|
|
|
PyErr_SetString(PyExc_ValueError, "The mesh must be in editmode");
|
2012-03-10 20:41:19 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-17 18:05:18 +11:00
|
|
|
bm = me->edit_mesh->bm;
|
2012-03-10 20:41:19 +00:00
|
|
|
|
2012-03-11 05:58:22 +00:00
|
|
|
return BPy_BMesh_CreatePyObject(bm, BPY_BMFLAG_IS_WRAPPED);
|
2012-02-22 09:19:53 +00:00
|
|
|
}
|
|
|
|
|
|
2012-11-29 05:02:06 +00:00
|
|
|
PyDoc_STRVAR(bpy_bm_update_edit_mesh_doc,
|
2018-09-06 14:28:14 +02:00
|
|
|
".. method:: update_edit_mesh(mesh, loop_triangles=True, destructive=True)\n"
|
2012-11-29 05:02:06 +00:00
|
|
|
"\n"
|
2018-11-14 09:04:24 +11:00
|
|
|
" Update the mesh after changes to the BMesh in editmode,\n"
|
2012-11-29 05:02:06 +00:00
|
|
|
" optionally recalculating n-gon tessellation.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" :arg mesh: The editmode mesh.\n"
|
|
|
|
|
" :type mesh: :class:`bpy.types.Mesh`\n"
|
2018-09-06 14:28:14 +02:00
|
|
|
" :arg loop_triangles: Option to recalculate n-gon tessellation.\n"
|
|
|
|
|
" :type loop_triangles: boolean\n"
|
2015-03-08 16:47:30 +09:00
|
|
|
" :arg destructive: Use when geometry has been added or removed.\n"
|
2012-12-12 06:57:41 +00:00
|
|
|
" :type destructive: boolean\n");
|
2012-12-27 07:27:28 +00:00
|
|
|
static PyObject *bpy_bm_update_edit_mesh(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
|
2012-11-29 05:02:06 +00:00
|
|
|
{
|
2018-09-06 14:28:14 +02:00
|
|
|
static const char *kwlist[] = {"mesh", "loop_triangles", "destructive", NULL};
|
2012-11-29 05:02:06 +00:00
|
|
|
PyObject *py_me;
|
|
|
|
|
Mesh *me;
|
2018-09-06 14:28:14 +02:00
|
|
|
bool do_loop_triangles = true;
|
2015-08-04 18:34:20 +10:00
|
|
|
bool is_destructive = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-08-04 18:34:20 +10:00
|
|
|
if (!PyArg_ParseTupleAndKeywords(args,
|
|
|
|
|
kw,
|
PyAPI: use keyword only arguments
Use keyword only arguments for the following functions.
- addon_utils.module_bl_info 2nd arg `info_basis`.
- addon_utils.modules 1st `module_cache`, 2nd arg `refresh`.
- addon_utils.modules_refresh 1st arg `module_cache`.
- bl_app_template_utils.activate 1nd arg `template_id`.
- bl_app_template_utils.import_from_id 2nd arg `ignore_not_found`.
- bl_app_template_utils.import_from_path 2nd arg `ignore_not_found`.
- bl_keymap_utils.keymap_from_toolbar.generate 2nd & 3rd args `use_fallback_keys` & `use_reset`.
- bl_keymap_utils.platform_helpers.keyconfig_data_oskey_from_ctrl 2nd arg `filter_fn`.
- bl_ui_utils.bug_report_url.url_prefill_from_blender 1st arg `addon_info`.
- bmesh.types.BMFace.copy 1st & 2nd args `verts`, `edges`.
- bmesh.types.BMesh.calc_volume 1st arg `signed`.
- bmesh.types.BMesh.from_mesh 2nd..4th args `face_normals`, `use_shape_key`, `shape_key_index`.
- bmesh.types.BMesh.from_object 3rd & 4th args `cage`, `face_normals`.
- bmesh.types.BMesh.transform 2nd arg `filter`.
- bmesh.types.BMesh.update_edit_mesh 2nd & 3rd args `loop_triangles`, `destructive`.
- bmesh.types.{BMVertSeq,BMEdgeSeq,BMFaceSeq}.sort 1st & 2nd arg `key`, `reverse`.
- bmesh.utils.face_split 4th..6th args `coords`, `use_exist`, `example`.
- bpy.data.libraries.load 2nd..4th args `link`, `relative`, `assets_only`.
- bpy.data.user_map 1st..3rd args `subset`, `key_types, `value_types`.
- bpy.msgbus.subscribe_rna 5th arg `options`.
- bpy.path.abspath 2nd & 3rd args `start` & `library`.
- bpy.path.clean_name 2nd arg `replace`.
- bpy.path.ensure_ext 3rd arg `case_sensitive`.
- bpy.path.module_names 2nd arg `recursive`.
- bpy.path.relpath 2nd arg `start`.
- bpy.types.EditBone.transform 2nd & 3rd arg `scale`, `roll`.
- bpy.types.Operator.as_keywords 1st arg `ignore`.
- bpy.types.Struct.{keyframe_insert,keyframe_delete} 2nd..5th args `index`, `frame`, `group`, `options`.
- bpy.types.WindowManager.popup_menu 2nd & 3rd arg `title`, `icon`.
- bpy.types.WindowManager.popup_menu_pie 3rd & 4th arg `title`, `icon`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.blend_paths 1st..3rd args `absolute`, `packed`, `local`.
- bpy.utils.execfile 2nd arg `mod`.
- bpy.utils.keyconfig_set 2nd arg `report`.
- bpy.utils.load_scripts 1st & 2nd `reload_scripts` & `refresh_scripts`.
- bpy.utils.preset_find 3rd & 4th args `display_name`, `ext`.
- bpy.utils.resource_path 2nd & 3rd arg `major`, `minor`.
- bpy.utils.script_paths 1st..4th args `subdir`, `user_pref`, `check_all`, `use_user`.
- bpy.utils.smpte_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.smpte_from_seconds 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.system_resource 2nd arg `subdir`.
- bpy.utils.time_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.time_to_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.units.to_string 4th..6th `precision`, `split_unit`, `compatible_unit`.
- bpy.utils.units.to_value 4th arg `str_ref_unit`.
- bpy.utils.user_resource 2nd & 3rd args `subdir`, `create`
- bpy_extras.view3d_utils.location_3d_to_region_2d 4th arg `default`.
- bpy_extras.view3d_utils.region_2d_to_origin_3d 4th arg `clamp`.
- gpu.offscreen.unbind 1st arg `restore`.
- gpu_extras.batch.batch_for_shader 4th arg `indices`.
- gpu_extras.batch.presets.draw_circle_2d 4th arg `segments`.
- gpu_extras.presets.draw_circle_2d 4th arg `segments`.
- imbuf.types.ImBuf.resize 2nd arg `resize`.
- imbuf.write 2nd arg `filepath`.
- mathutils.kdtree.KDTree.find 2nd arg `filter`.
- nodeitems_utils.NodeCategory 3rd & 4th arg `descriptions`, `items`.
- nodeitems_utils.NodeItem 2nd..4th args `label`, `settings`, `poll`.
- nodeitems_utils.NodeItemCustom 1st & 2nd arg `poll`, `draw`.
- rna_prop_ui.draw 5th arg `use_edit`.
- rna_prop_ui.rna_idprop_ui_get 2nd arg `create`.
- rna_prop_ui.rna_idprop_ui_prop_clear 3rd arg `remove`.
- rna_prop_ui.rna_idprop_ui_prop_get 3rd arg `create`.
- rna_xml.xml2rna 2nd arg `root_rna`.
- rna_xml.xml_file_write 4th arg `skip_typemap`.
2021-06-08 18:03:14 +10:00
|
|
|
"O|$O&O&:update_edit_mesh",
|
2015-08-04 18:34:20 +10:00
|
|
|
(char **)kwlist,
|
|
|
|
|
&py_me,
|
2018-09-06 14:28:14 +02:00
|
|
|
PyC_ParseBool,
|
|
|
|
|
&do_loop_triangles,
|
2015-08-04 18:34:20 +10:00
|
|
|
PyC_ParseBool,
|
|
|
|
|
&is_destructive)) {
|
2012-11-29 05:02:06 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-29 05:02:06 +00:00
|
|
|
me = PyC_RNA_AsPointer(py_me, "Mesh");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-29 05:02:06 +00:00
|
|
|
if (me == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-17 18:05:18 +11:00
|
|
|
if (me->edit_mesh == NULL) {
|
2012-11-29 05:02:06 +00:00
|
|
|
PyErr_SetString(PyExc_ValueError, "The mesh must be in editmode");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-29 05:02:06 +00:00
|
|
|
{
|
2021-06-14 22:56:01 +10:00
|
|
|
extern void EDBM_update_extern(
|
2020-01-07 22:11:19 +11:00
|
|
|
struct Mesh * me, const bool do_tessface, const bool is_destructive);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-14 22:56:01 +10:00
|
|
|
EDBM_update_extern(me, do_loop_triangles, is_destructive);
|
2012-11-29 05:02:06 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-29 05:02:06 +00:00
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-22 09:19:53 +00:00
|
|
|
static struct PyMethodDef BPy_BM_methods[] = {
|
2016-07-01 19:07:11 +10:00
|
|
|
{"new", (PyCFunction)bpy_bm_new, METH_VARARGS | METH_KEYWORDS, bpy_bm_new_doc},
|
2012-08-26 11:35:43 +00:00
|
|
|
{"from_edit_mesh", (PyCFunction)bpy_bm_from_edit_mesh, METH_O, bpy_bm_from_edit_mesh_doc},
|
2012-12-27 07:27:28 +00:00
|
|
|
{"update_edit_mesh",
|
|
|
|
|
(PyCFunction)bpy_bm_update_edit_mesh,
|
|
|
|
|
METH_VARARGS | METH_KEYWORDS,
|
|
|
|
|
bpy_bm_update_edit_mesh_doc},
|
2019-02-03 14:01:45 +11:00
|
|
|
{NULL, NULL, 0, NULL},
|
2012-02-22 09:19:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PyDoc_STRVAR(BPy_BM_doc,
|
2012-03-09 21:23:15 +00:00
|
|
|
"This module provides access to blenders bmesh data structures.\n"
|
|
|
|
|
"\n"
|
2012-03-13 06:22:43 +00:00
|
|
|
".. include:: include__bmesh.rst\n");
|
2012-02-22 09:19:53 +00:00
|
|
|
static struct PyModuleDef BPy_BM_module_def = {
|
|
|
|
|
PyModuleDef_HEAD_INIT,
|
2012-02-22 10:41:07 +00:00
|
|
|
"bmesh", /* m_name */
|
2012-02-22 09:19:53 +00:00
|
|
|
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)
|
|
|
|
|
{
|
2012-02-24 04:59:13 +00:00
|
|
|
PyObject *mod;
|
2012-02-22 09:19:53 +00:00
|
|
|
PyObject *submodule;
|
2018-09-13 17:06:07 +10:00
|
|
|
PyObject *sys_modules = PyImport_GetModuleDict();
|
2012-02-22 09:19:53 +00:00
|
|
|
|
|
|
|
|
BPy_BM_init_types();
|
2012-03-16 05:03:13 +00:00
|
|
|
BPy_BM_init_types_select();
|
|
|
|
|
BPy_BM_init_types_customdata();
|
2012-03-17 06:40:44 +00:00
|
|
|
BPy_BM_init_types_meshdata();
|
2012-02-29 14:05:03 +00:00
|
|
|
|
2012-02-24 04:59:13 +00:00
|
|
|
mod = PyModule_Create(&BPy_BM_module_def);
|
2012-02-22 09:19:53 +00:00
|
|
|
|
2012-02-23 05:20:09 +00:00
|
|
|
/* bmesh.types */
|
2012-03-16 21:39:56 +00:00
|
|
|
PyModule_AddObject(mod, "types", (submodule = BPyInit_bmesh_types()));
|
2016-07-14 15:51:56 +10:00
|
|
|
PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
|
2012-02-24 04:59:13 +00:00
|
|
|
|
2016-07-14 15:51:56 +10:00
|
|
|
/* bmesh.ops (not a real module, exposes module like access). */
|
2012-06-26 21:40:01 +00:00
|
|
|
PyModule_AddObject(mod, "ops", (submodule = BPyInit_bmesh_ops()));
|
2020-10-09 11:17:13 +11:00
|
|
|
PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
|
2012-06-26 21:40:01 +00:00
|
|
|
|
2012-03-16 21:39:56 +00:00
|
|
|
PyModule_AddObject(mod, "utils", (submodule = BPyInit_bmesh_utils()));
|
2016-07-14 15:51:56 +10:00
|
|
|
PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
|
2012-02-23 05:20:09 +00:00
|
|
|
|
2013-12-06 21:13:11 +11:00
|
|
|
PyModule_AddObject(mod, "geometry", (submodule = BPyInit_bmesh_geometry()));
|
2016-07-14 15:51:56 +10:00
|
|
|
PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
|
2013-12-06 21:13:11 +11:00
|
|
|
|
2012-02-24 04:59:13 +00:00
|
|
|
return mod;
|
2012-02-22 09:19:53 +00:00
|
|
|
}
|