[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44352] trunk/blender/source/blender: bmesh py api: functions for getting the area/angle/ center of BMesh elements.

Campbell Barton ideasman42 at gmail.com
Thu Feb 23 04:39:48 CET 2012


Revision: 44352
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44352
Author:   campbellbarton
Date:     2012-02-23 03:39:39 +0000 (Thu, 23 Feb 2012)
Log Message:
-----------
bmesh py api: functions for getting the area/angle/center of BMesh elements.

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/bmesh_queries.h
    trunk/blender/source/blender/bmesh/intern/bmesh_queries.c
    trunk/blender/source/blender/python/bmesh/bmesh_py_types.c

Modified: trunk/blender/source/blender/bmesh/bmesh_queries.h
===================================================================
--- trunk/blender/source/blender/bmesh/bmesh_queries.h	2012-02-23 02:37:18 UTC (rev 44351)
+++ trunk/blender/source/blender/bmesh/bmesh_queries.h	2012-02-23 03:39:39 UTC (rev 44352)
@@ -83,6 +83,8 @@
 /* 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.*/

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_queries.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_queries.c	2012-02-23 02:37:18 UTC (rev 44351)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_queries.c	2012-02-23 03:39:39 UTC (rev 44352)
@@ -537,6 +537,23 @@
 }
 
 /*
+ *			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.

Modified: trunk/blender/source/blender/python/bmesh/bmesh_py_types.c
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_types.c	2012-02-23 02:37:18 UTC (rev 44351)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_types.c	2012-02-23 03:39:39 UTC (rev 44352)
@@ -631,6 +631,91 @@
 	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_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}
 };
 




More information about the Bf-blender-cvs mailing list