diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-04-19 15:25:05 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-04-19 15:25:05 +0400 |
commit | db2edfcfdec81fb03667a63e70f05ee832bf2586 (patch) | |
tree | 0420d0ad4380a67bf1e473174f3ca8f325bb5a13 /source | |
parent | 250560a423ea889ec491cdfde887571dea3c9e7c (diff) |
bmesh api function: BM_edge_face_tangent()
was used by inset but make into an api function since scripts can use this too.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_queries.c | 25 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_queries.h | 2 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_inset.c | 13 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types.c | 35 |
4 files changed, 61 insertions, 14 deletions
diff --git a/source/blender/bmesh/intern/bmesh_queries.c b/source/blender/bmesh/intern/bmesh_queries.c index 5efdd547ba9..b021fb4c320 100644 --- a/source/blender/bmesh/intern/bmesh_queries.c +++ b/source/blender/bmesh/intern/bmesh_queries.c @@ -813,6 +813,31 @@ float BM_edge_face_angle(BMEdge *e) } /** + * \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. diff --git a/source/blender/bmesh/intern/bmesh_queries.h b/source/blender/bmesh/intern/bmesh_queries.h index 567d60eeac6..280fe843b1c 100644 --- a/source/blender/bmesh/intern/bmesh_queries.h +++ b/source/blender/bmesh/intern/bmesh_queries.h @@ -62,6 +62,8 @@ void BM_loop_face_normal(BMLoop *l, float r_normal[3]); 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); diff --git a/source/blender/bmesh/operators/bmo_inset.c b/source/blender/bmesh/operators/bmo_inset.c index 3bfacb29197..1c823e7590c 100644 --- a/source/blender/bmesh/operators/bmo_inset.c +++ b/source/blender/bmesh/operators/bmo_inset.c @@ -42,17 +42,6 @@ typedef struct SplitEdgeInfo { 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 @@ void bmo_inset_exec(BMesh *bm, BMOperator *op) /* 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 */ diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index 5fcefc7533b..6b6fd8a0bd4 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -1243,6 +1243,36 @@ static PyObject *bpy_bmedge_calc_face_angle(BPy_BMEdge *self) 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" @@ -2078,8 +2108,9 @@ static struct PyMethodDef bpy_bmedge_methods[] = { {"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}, |