[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45776] trunk/blender/source/blender: bmesh api function: BM_edge_face_tangent()
Campbell Barton
ideasman42 at gmail.com
Thu Apr 19 13:25:05 CEST 2012
Revision: 45776
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45776
Author: campbellbarton
Date: 2012-04-19 11:25:05 +0000 (Thu, 19 Apr 2012)
Log Message:
-----------
bmesh api function: BM_edge_face_tangent()
was used by inset but make into an api function since scripts can use this too.
Modified Paths:
--------------
trunk/blender/source/blender/bmesh/intern/bmesh_queries.c
trunk/blender/source/blender/bmesh/intern/bmesh_queries.h
trunk/blender/source/blender/bmesh/operators/bmo_inset.c
trunk/blender/source/blender/python/bmesh/bmesh_py_types.c
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_queries.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_queries.c 2012-04-19 10:49:45 UTC (rev 45775)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_queries.c 2012-04-19 11:25:05 UTC (rev 45776)
@@ -813,6 +813,31 @@
}
/**
+ * \brief BMESH EDGE/FACE TANGENT
+ *
+ * Calculate the tangent at this loop corner or fallback to the face normal on straignt lines.
+ * This vector always points inward into the face.
+ *
+ * \brief BM_edge_face_tangent
+ * \param e
+ * \param e_loop The loop to calculate the tangent at,
+ * used to get the face and winding direction.
+ */
+
+void BM_edge_face_tangent(BMEdge *e, BMLoop *e_loop, float r_tangent[3])
+{
+ float tvec[3];
+ BMVert *v1, *v2;
+ BM_edge_ordered_verts_ex(e, &v1, &v2, e_loop);
+
+ sub_v3_v3v3(tvec, v1->co, v2->co); /* use for temp storage */
+ /* note, we could average the tangents of both loops,
+ * for non flat ngons it will give a better direction */
+ cross_v3_v3v3(r_tangent, tvec, e_loop->f->no);
+ normalize_v3(r_tangent);
+}
+
+/**
* \brief BMESH VERT/EDGE ANGLE
*
* Calculates the angle a verts 2 edges.
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_queries.h
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_queries.h 2012-04-19 10:49:45 UTC (rev 45775)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_queries.h 2012-04-19 11:25:05 UTC (rev 45776)
@@ -62,6 +62,8 @@
void BM_loop_face_tangent(BMLoop *l, float r_tangent[3]);
float BM_edge_face_angle(BMEdge *e);
+void BM_edge_face_tangent(BMEdge *e, BMLoop *e_loop, float r_tangent[3]);
+
float BM_vert_edge_angle(BMVert *v);
BMEdge *BM_edge_exists(BMVert *v1, BMVert *v2);
Modified: trunk/blender/source/blender/bmesh/operators/bmo_inset.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_inset.c 2012-04-19 10:49:45 UTC (rev 45775)
+++ trunk/blender/source/blender/bmesh/operators/bmo_inset.c 2012-04-19 11:25:05 UTC (rev 45776)
@@ -42,17 +42,6 @@
BMLoop *l;
} SplitEdgeInfo;
-static void edge_loop_tangent(BMEdge *e, BMLoop *e_loop, float r_no[3])
-{
- float tvec[3];
- BMVert *v1, *v2;
- BM_edge_ordered_verts_ex(e, &v1, &v2, e_loop);
-
- sub_v3_v3v3(tvec, v1->co, v2->co); /* use for temp storage */
- cross_v3_v3v3(r_no, tvec, e_loop->f->no);
- normalize_v3(r_no);
-}
-
/**
* return the tag loop where there is...
* - only 1 tagged face attached to this edge.
@@ -188,7 +177,7 @@
/* calc edge-split info */
es->e_new = es->l->e;
- edge_loop_tangent(es->e_new, es->l, es->no);
+ BM_edge_face_tangent(es->e_new, es->l, es->no);
if (es->e_new == es->e_old) { /* happens on boundary edges */
/* take care here, we're creating this double edge which _must_ have its verts replaced later on */
Modified: trunk/blender/source/blender/python/bmesh/bmesh_py_types.c
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_types.c 2012-04-19 10:49:45 UTC (rev 45775)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_types.c 2012-04-19 11:25:05 UTC (rev 45776)
@@ -1243,7 +1243,37 @@
return PyFloat_FromDouble(BM_edge_face_angle(self->e));
}
+PyDoc_STRVAR(bpy_bmedge_calc_tangent_doc,
+".. method:: calc_tangent(loop)\n"
+"\n"
+" Return the tangent at this edge relative to a face (pointing inward into the face).\n"
+" This uses the face normal for calculation.\n"
+"\n"
+" :arg loop: The loop used for tangent calculation.\n"
+" :type loop: :class:`BMLoop`\n"
+" :return: a normalized vector.\n"
+" :rtype: :class:`mathutils.Vector`\n"
+);
+static PyObject *bpy_bmedge_calc_tangent(BPy_BMEdge *self, PyObject *args)
+{
+ BPy_BMLoop *py_loop;
+ BPY_BM_CHECK_OBJ(self);
+ if (!PyArg_ParseTuple(args, "O!:BMEdge.calc_face_tangent",
+ &BPy_BMLoop_Type, &py_loop))
+ {
+ return NULL;
+ }
+ else {
+ float vec[3];
+ BPY_BM_CHECK_OBJ(py_loop);
+ /* no need to check if they are from the same mesh or even connected */
+ BM_edge_face_tangent(self->e, py_loop->l, vec);
+ return Vector_CreatePyObject(vec, 3, Py_NEW, NULL);
+ }
+}
+
+
PyDoc_STRVAR(bpy_bmedge_other_vert_doc,
".. method:: other_vert(vert)\n"
"\n"
@@ -2078,8 +2108,9 @@
{"other_vert", (PyCFunction)bpy_bmedge_other_vert, METH_O, bpy_bmedge_other_vert_doc},
- {"calc_length", (PyCFunction)bpy_bmedge_calc_length, METH_NOARGS, bpy_bmedge_calc_length_doc},
- {"calc_face_angle", (PyCFunction)bpy_bmedge_calc_face_angle, METH_NOARGS, bpy_bmedge_calc_face_angle_doc},
+ {"calc_length", (PyCFunction)bpy_bmedge_calc_length, METH_NOARGS, bpy_bmedge_calc_length_doc},
+ {"calc_face_angle", (PyCFunction)bpy_bmedge_calc_face_angle, METH_NOARGS, bpy_bmedge_calc_face_angle_doc},
+ {"calc_tangent", (PyCFunction)bpy_bmedge_calc_tangent, METH_VARARGS, bpy_bmedge_calc_tangent_doc},
{"normal_update", (PyCFunction)bpy_bmedge_normal_update, METH_NOARGS, bpy_bmedge_normal_update_doc},
More information about the Bf-blender-cvs
mailing list