diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-05-07 04:00:32 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-05-07 04:00:32 +0400 |
commit | 0ffde4fae3bd6a62302d829d319955b012a9b73a (patch) | |
tree | 007397ee204b0a9f2c1b16a4f9515091590c312c /source/blender/python/bmesh | |
parent | 424e8b69f1a008aa5e06ec05b67536bc76715695 (diff) |
expose bmesh volume calculation to python api (use for print toolbox addon).
Diffstat (limited to 'source/blender/python/bmesh')
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index 55a6f3c41c4..23837404b31 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -1171,6 +1171,35 @@ static PyObject *bpy_bmesh_transform(BPy_BMElem *self, PyObject *args, PyObject Py_RETURN_NONE; } +PyDoc_STRVAR(bpy_bmesh_calc_volume_doc, +".. method:: calc_volume(signed=False)\n" +"\n" +" Calculate mesh volume based on face normals.\n" +"\n" +" :arg signed: when signed is true, negative values may be returned.\n" +" :type signed: bool\n" +" :return: The volume of the mesh.\n" +" :rtype: float\n" +); +static PyObject *bpy_bmesh_calc_volume(BPy_BMElem *self, PyObject *args, PyObject *kw) +{ + static const char *kwlist[] = {"signed", NULL}; + PyObject *is_signed = Py_False; + + BPY_BM_CHECK_OBJ(self); + + if (!PyArg_ParseTupleAndKeywords(args, kw, + "|O!:calc_volume", + (char **)kwlist, + &PyBool_Type, &is_signed)) + { + return NULL; + } + else { + return PyFloat_FromDouble(BM_mesh_calc_volume(self->bm, is_signed != Py_False)); + } +} + /* Elem * ---- */ @@ -2454,6 +2483,9 @@ static struct PyMethodDef bpy_bmesh_methods[] = { {"select_flush", (PyCFunction)bpy_bmesh_select_flush, METH_O, bpy_bmesh_select_flush_doc}, {"normal_update", (PyCFunction)bpy_bmesh_normal_update, METH_NOARGS, bpy_bmesh_normal_update_doc}, {"transform", (PyCFunction)bpy_bmesh_transform, METH_VARARGS | METH_KEYWORDS, bpy_bmesh_transform_doc}, + + /* calculations */ + {"calc_volume", (PyCFunction)bpy_bmesh_calc_volume, METH_VARARGS | METH_KEYWORDS, bpy_bmesh_calc_volume_doc}, {NULL, NULL, 0, NULL} }; |