Commit: 75212f4677f4e3f54168eaacdfcaad19289eca38
Author: Campbell Barton
Date:   Fri Dec 6 21:13:11 2013 +1100
http://developer.blender.org/rB75212f4677f4e3f54168eaacdfcaad19289eca38

BMesh Py API: add bmesh.geometry.intersect_face_point()

patch originally by mont29 with some edits.

===================================================================

M       doc/python_api/rst/include__bmesh.rst
M       doc/python_api/sphinx_doc_gen.py
M       source/blender/python/bmesh/CMakeLists.txt
M       source/blender/python/bmesh/bmesh_py_api.c
A       source/blender/python/bmesh/bmesh_py_geometry.c
A       source/blender/python/bmesh/bmesh_py_geometry.h
M       source/blender/python/intern/bpy_interface.c

===================================================================

diff --git a/doc/python_api/rst/include__bmesh.rst 
b/doc/python_api/rst/include__bmesh.rst
index ce7c09a..9dccd4e 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 ff3fe63..a812863 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 b15923a..c7b86ac 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 c7b10d0..bc14e1a 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 0000000..4cd0a39
--- /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 <Python.h>
+
+#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 0000000..c0c455f
--- /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 cc1dd36..7a3d56d 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

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to