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

patch originally by mont29 with some edits.
This commit is contained in:
Campbell Barton 2013-12-06 21:13:11 +11:00
parent 72d950ba49
commit 75212f4677
7 changed files with 156 additions and 0 deletions

View File

@ -9,6 +9,7 @@ Submodules:
* :mod:`bmesh.ops`
* :mod:`bmesh.types`
* :mod:`bmesh.utils`
* :mod:`bmesh.geometry`
Intro

View File

@ -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",

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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__ */

View File

@ -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