bmesh api function: BM_edge_face_tangent()

was used by inset but make into an api function since scripts can use this too.
This commit is contained in:
2012-04-19 11:25:05 +00:00
parent 250560a423
commit db2edfcfde
4 changed files with 61 additions and 14 deletions

View File

@@ -812,6 +812,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
*

View File

@@ -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);

View File

@@ -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 */

View File

@@ -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"
@@ -2080,6 +2110,7 @@ static struct PyMethodDef bpy_bmedge_methods[] = {
{"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},