Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-02-23 07:39:39 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-02-23 07:39:39 +0400
commit30c62d96992a02a0e74aca1331f971a30a913c21 (patch)
tree33158af2052f1f9a612d88b2244d90b8d16a0097
parent190f5d17871a714bb864e271985ea6e4c5d6b3d0 (diff)
bmesh py api: functions for getting the area/angle/center of BMesh elements.
-rw-r--r--source/blender/bmesh/bmesh_queries.h2
-rw-r--r--source/blender/bmesh/intern/bmesh_queries.c17
-rw-r--r--source/blender/python/bmesh/bmesh_py_types.c95
3 files changed, 114 insertions, 0 deletions
diff --git a/source/blender/bmesh/bmesh_queries.h b/source/blender/bmesh/bmesh_queries.h
index 1ae469eb663..39e1d9eaa7a 100644
--- a/source/blender/bmesh/bmesh_queries.h
+++ b/source/blender/bmesh/bmesh_queries.h
@@ -83,6 +83,8 @@ int BM_edge_is_manifold(struct BMesh *bm, struct BMEdge *e);
/* returns true if e is a boundary edge, e.g. has only 1 face bordering it. */
int BM_edge_is_boundry(struct BMEdge *e);
+/* returns the face corner angle */
+float BM_loop_face_angle(struct BMesh *bm, struct BMLoop *l);
/* returns angle of two faces surrounding an edge. note there must be
* exactly two faces sharing the edge.*/
diff --git a/source/blender/bmesh/intern/bmesh_queries.c b/source/blender/bmesh/intern/bmesh_queries.c
index 089bc79e25d..dd5e6ecc826 100644
--- a/source/blender/bmesh/intern/bmesh_queries.c
+++ b/source/blender/bmesh/intern/bmesh_queries.c
@@ -537,6 +537,23 @@ void BM_edge_ordered_verts(BMEdge *edge, BMVert **r_v1, BMVert **r_v2)
}
/*
+ * BMESH LOOP ANGLE
+ *
+ * Calculates the angle between the previous and next loops
+ * (angle at this loops face corner).
+ *
+ * Returns -
+ * Float.
+ */
+
+float BM_loop_face_angle(BMesh *UNUSED(bm), BMLoop *l)
+{
+ return angle_v3v3v3(l->prev->v->co,
+ l->v->co,
+ l->next->v->co);
+}
+
+/*
* BMESH FACE ANGLE
*
* Calculates the angle between two faces.
diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c
index 8350166c2d0..040fcdd5a68 100644
--- a/source/blender/python/bmesh/bmesh_py_types.c
+++ b/source/blender/python/bmesh/bmesh_py_types.c
@@ -631,6 +631,91 @@ static PyObject *bpy_bm_elem_copy_from(BPy_BMElem *self, BPy_BMElem *value)
Py_RETURN_NONE;
}
+
+/* Vert
+ * ---- */
+
+PyDoc_STRVAR(bpy_bmvert_calc_edge_angle_doc,
+ ".. method:: calc_edge_angle()\n"
+ "\n"
+ " Return the angle between 2 connected edges.\n"
+ );
+static PyObject *bpy_bmvert_calc_edge_angle(BPy_BMVert *self)
+{
+ BPY_BM_CHECK_OBJ(self);
+ return PyFloat_FromDouble(BM_vert_edge_angle(self->bm, self->v));
+}
+
+/* Edge
+ * ---- */
+
+PyDoc_STRVAR(bpy_bmedge_calc_face_angle_doc,
+ ".. method:: calc_face_angle()\n"
+ "\n"
+ " Return the angle between 2 connected faces.\n"
+ );
+static PyObject *bpy_bmedge_calc_face_angle(BPy_BMEdge *self)
+{
+ BPY_BM_CHECK_OBJ(self);
+ return PyFloat_FromDouble(BM_edge_face_angle(self->bm, self->e));
+}
+
+/* Face
+ * ---- */
+
+PyDoc_STRVAR(bpy_bmface_calc_area_doc,
+ ".. method:: calc_area()\n"
+ "\n"
+ " Return the area of the face.\n"
+ );
+static PyObject *bpy_bmface_calc_area(BPy_BMFace *self)
+{
+ BPY_BM_CHECK_OBJ(self);
+ return PyFloat_FromDouble(BM_face_area_calc(self->bm, self->f));
+}
+
+PyDoc_STRVAR(bpy_bmface_calc_center_mean_doc,
+ ".. method:: calc_center_median()\n"
+ "\n"
+ " Return median center of the face.\n"
+ );
+static PyObject *bpy_bmface_calc_center_mean(BPy_BMFace *self)
+{
+ float cent[3];
+
+ BPY_BM_CHECK_OBJ(self);
+ BM_face_center_mean_calc(self->bm, self->f, cent);
+ return Vector_CreatePyObject(cent, 3, Py_NEW, NULL);
+}
+
+PyDoc_STRVAR(bpy_bmface_calc_center_bounds_doc,
+ ".. method:: calc_center_bounds()\n"
+ "\n"
+ " Return bounds center of the face.\n"
+ );
+static PyObject *bpy_bmface_calc_center_bounds(BPy_BMFace *self)
+{
+ float cent[3];
+
+ BPY_BM_CHECK_OBJ(self);
+ BM_face_center_bounds_calc(self->bm, self->f, cent);
+ return Vector_CreatePyObject(cent, 3, Py_NEW, NULL);
+}
+
+/* Loop
+ * ---- */
+
+PyDoc_STRVAR(bpy_bmloop_calc_face_angle_doc,
+ ".. method:: calc_face_angle()\n"
+ "\n"
+ " Return angle at this loops corner of the face.\n"
+ );
+static PyObject *bpy_bmloop_calc_face_angle(BPy_BMLoop *self)
+{
+ BPY_BM_CHECK_OBJ(self);
+ return PyFloat_FromDouble(BM_loop_face_angle(self->bm, self->l));
+}
+
/* Vert Seq
* -------- */
@@ -945,23 +1030,33 @@ static struct PyMethodDef bpy_bmesh_methods[] = {
static struct PyMethodDef bpy_bmvert_methods[] = {
{"select_set", (PyCFunction)bpy_bm_elem_select_set, METH_O, bpy_bm_elem_select_set_doc},
{"copy_from", (PyCFunction)bpy_bm_elem_copy_from, METH_O, bpy_bm_elem_copy_from_doc},
+
+ {"calc_vert_angle", (PyCFunction)bpy_bmvert_calc_edge_angle, METH_NOARGS, bpy_bmvert_calc_edge_angle_doc},
{NULL, NULL, 0, NULL}
};
static struct PyMethodDef bpy_bmedge_methods[] = {
{"select_set", (PyCFunction)bpy_bm_elem_select_set, METH_O, bpy_bm_elem_select_set_doc},
{"copy_from", (PyCFunction)bpy_bm_elem_copy_from, METH_O, bpy_bm_elem_copy_from_doc},
+
+ {"calc_face_angle", (PyCFunction)bpy_bmedge_calc_face_angle, METH_NOARGS, bpy_bmedge_calc_face_angle_doc},
{NULL, NULL, 0, NULL}
};
static struct PyMethodDef bpy_bmface_methods[] = {
{"select_set", (PyCFunction)bpy_bm_elem_select_set, METH_O, bpy_bm_elem_select_set_doc},
{"copy_from", (PyCFunction)bpy_bm_elem_copy_from, METH_O, bpy_bm_elem_copy_from_doc},
+
+ {"calc_area", (PyCFunction)bpy_bmface_calc_area, METH_NOARGS, bpy_bmface_calc_area_doc},
+ {"calc_center_median", (PyCFunction)bpy_bmface_calc_center_mean, METH_NOARGS, bpy_bmface_calc_center_mean_doc},
+ {"calc_center_bounds", (PyCFunction)bpy_bmface_calc_center_bounds, METH_NOARGS, bpy_bmface_calc_center_bounds_doc},
{NULL, NULL, 0, NULL}
};
static struct PyMethodDef bpy_bmloop_methods[] = {
{"copy_from", (PyCFunction)bpy_bm_elem_copy_from, METH_O, bpy_bm_elem_copy_from_doc},
+
+ {"calc_angle", (PyCFunction)bpy_bmloop_calc_face_angle, METH_NOARGS, bpy_bmloop_calc_face_angle_doc},
{NULL, NULL, 0, NULL}
};