From 75212f4677f4e3f54168eaacdfcaad19289eca38 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 6 Dec 2013 21:13:11 +1100 Subject: [PATCH] BMesh Py API: add bmesh.geometry.intersect_face_point() patch originally by mont29 with some edits. --- doc/python_api/rst/include__bmesh.rst | 1 + doc/python_api/sphinx_doc_gen.py | 2 + source/blender/python/bmesh/CMakeLists.txt | 2 + source/blender/python/bmesh/bmesh_py_api.c | 5 + .../blender/python/bmesh/bmesh_py_geometry.c | 110 ++++++++++++++++++ .../blender/python/bmesh/bmesh_py_geometry.h | 35 ++++++ source/blender/python/intern/bpy_interface.c | 1 + 7 files changed, 156 insertions(+) create mode 100644 source/blender/python/bmesh/bmesh_py_geometry.c create mode 100644 source/blender/python/bmesh/bmesh_py_geometry.h diff --git a/doc/python_api/rst/include__bmesh.rst b/doc/python_api/rst/include__bmesh.rst index ce7c09ad3a1..9dccd4e72ae 100644 --- a/doc/python_api/rst/include__bmesh.rst +++ b/doc/python_api/rst/include__bmesh.rst @@ -9,6 +9,7 @@ Submodules: * :mod:`bmesh.ops` * :mod:`bmesh.types` * :mod:`bmesh.utils` +* :mod:`bmesh.geometry` Intro diff --git a/doc/python_api/sphinx_doc_gen.py b/doc/python_api/sphinx_doc_gen.py index ff3fe6377c2..a8128633569 100644 --- a/doc/python_api/sphinx_doc_gen.py +++ b/doc/python_api/sphinx_doc_gen.py @@ -256,6 +256,7 @@ else: "bmesh.ops", "bmesh.types", "bmesh.utils", + "bmesh.geometry", "bpy.app", "bpy.app.handlers", "bpy.app.translations", @@ -1768,6 +1769,7 @@ def write_rst_importable_modules(basepath): "bmesh" : "BMesh Module", "bmesh.types" : "BMesh Types", "bmesh.utils" : "BMesh Utilities", + "bmesh.geometry" : "BMesh Geometry Utilities", "bpy.app" : "Application Data", "bpy.app.handlers" : "Application Handlers", "bpy.app.translations" : "Application Translations", diff --git a/source/blender/python/bmesh/CMakeLists.txt b/source/blender/python/bmesh/CMakeLists.txt index b15923a87d2..c7b86acc8f9 100644 --- a/source/blender/python/bmesh/CMakeLists.txt +++ b/source/blender/python/bmesh/CMakeLists.txt @@ -33,6 +33,7 @@ set(INC_SYS set(SRC bmesh_py_api.c + bmesh_py_geometry.c bmesh_py_ops.c bmesh_py_ops_call.c bmesh_py_types.c @@ -42,6 +43,7 @@ set(SRC 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 diff --git a/source/blender/python/bmesh/bmesh_py_api.c b/source/blender/python/bmesh/bmesh_py_api.c index c7b10d0aa4b..bc14e1ac3a6 100644 --- a/source/blender/python/bmesh/bmesh_py_api.c +++ b/source/blender/python/bmesh/bmesh_py_api.c @@ -42,6 +42,7 @@ #include "bmesh_py_ops.h" #include "bmesh_py_utils.h" +#include "bmesh_py_geometry.h" #include "BKE_editmesh.h" @@ -201,5 +202,9 @@ PyObject *BPyInit_bmesh(void) PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); Py_INCREF(submodule); + PyModule_AddObject(mod, "geometry", (submodule = BPyInit_bmesh_geometry())); + PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); + Py_INCREF(submodule); + return mod; } diff --git a/source/blender/python/bmesh/bmesh_py_geometry.c b/source/blender/python/bmesh/bmesh_py_geometry.c new file mode 100644 index 00000000000..4cd0a3951b3 --- /dev/null +++ b/source/blender/python/bmesh/bmesh_py_geometry.c @@ -0,0 +1,110 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * Contributor(s): Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/bmesh/bmesh_py_geometry.c + * \ingroup pybmesh + * + * This file defines the 'bmesh.geometry' module. + * Utility functions for operating on 'bmesh.types' + */ + +#include + +#include "BLI_utildefines.h" + +#include "../mathutils/mathutils.h" + +#include "bmesh.h" +#include "bmesh_py_types.h" +#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 a point is inside a face (using the faces 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 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; + + 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; + } + + ret = BM_face_point_inside_test(py_face->f, point); + + 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} +}; + + +PyDoc_STRVAR(BPy_BM_utils_doc, +"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 */ +}; + + +PyObject *BPyInit_bmesh_geometry(void) +{ + PyObject *submodule; + + submodule = PyModule_Create(&BPy_BM_geometry_module_def); + + return submodule; +} diff --git a/source/blender/python/bmesh/bmesh_py_geometry.h b/source/blender/python/bmesh/bmesh_py_geometry.h new file mode 100644 index 00000000000..c0c455f79cd --- /dev/null +++ b/source/blender/python/bmesh/bmesh_py_geometry.h @@ -0,0 +1,35 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * The Original Code is Copyright (C) 2012 Blender Foundation. + * All rights reserved. + * + * Contributor(s): Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/bmesh/bmesh_py_geometry.h + * \ingroup pybmesh + */ + +#ifndef __BMESH_PY_GEOMETRY_H__ +#define __BMESH_PY_GEOMETRY_H__ + +PyObject *BPyInit_bmesh_geometry(void); + +#endif /* __BMESH_PY_GEOMETRY_H__ */ diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index cc1dd369f8b..7a3d56dc56d 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -219,6 +219,7 @@ static struct _inittab bpy_internal_modules[] = { {(char *)"bmesh", BPyInit_bmesh}, // {(char *)"bmesh.types", BPyInit_bmesh_types}, // {(char *)"bmesh.utils", BPyInit_bmesh_utils}, + // {(char *)"bmesh.utils", BPyInit_bmesh_geometry}, #ifdef WITH_AUDASPACE {(char *)"aud", AUD_initPython}, #endif