[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49903] branches/soc-2012-sushi/source/ blender: add round bevel
Alexander Mokhov
alexander.mokhov at gmail.com
Tue Aug 14 22:12:54 CEST 2012
Revision: 49903
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49903
Author: redtriangle
Date: 2012-08-14 20:12:53 +0000 (Tue, 14 Aug 2012)
Log Message:
-----------
add round bevel
Modified Paths:
--------------
branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_opdefines.c
branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_bevel.c
branches/soc-2012-sushi/source/blender/editors/mesh/editmesh_tools.c
Modified: branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_opdefines.c 2012-08-14 19:13:47 UTC (rev 49902)
+++ branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_opdefines.c 2012-08-14 20:12:53 UTC (rev 49903)
@@ -1069,6 +1069,9 @@
* modifier uses this. We could do this as another float setting */
{BMO_OP_SLOT_INT, "lengthlayer"}, /* which PROP_FLT layer to us */
{BMO_OP_SLOT_FLT, "percent"}, /* percentage to expand beveled edge */
+
+ {BMO_OP_SLOT_FLT, "amount"},
+ {BMO_OP_SLOT_INT, "segmentation"},
{0} /* null-terminating sentinel */},
bmo_bevel_exec,
BMO_OP_FLAG_UNTAN_MULTIRES
Modified: branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_bevel.c
===================================================================
--- branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_bevel.c 2012-08-14 19:13:47 UTC (rev 49902)
+++ branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_bevel.c 2012-08-14 20:12:53 UTC (rev 49903)
@@ -50,6 +50,8 @@
#define EDGE_SELECTED 256
+#define BEVEL_EPSILON 1e-6
+
typedef struct LoopTag {
BMVert *newv;
} LoopTag;
@@ -58,34 +60,60 @@
BMVert *newv1, *newv2;
} EdgeTag;
-// Item in the list of vertices
+/* this structure is item of new vertices list */
+typedef struct NewVertexItem {
+ struct NewVertexItem *next, *prev;
+ BMVert *v;
+} NewVertexItem;
+
+/* Item in the list of additional vertices */
typedef struct VertexItem{
- struct VertexItem *next, *prev;
- BMVert *v;
- int onEdge; // true if new vertex located on edge; edge1 = edge, edge2 = NULL
- // false, new vert located betwen edge1 and edge2
- BMEdge *edge1;
- BMEdge *edge2;
- BMFace *f;
+ struct VertexItem *next, *prev;
+ BMVert *v; /* parent vertex */
+ int onEdge; /* 1 if new vertex located on edge; edge1 = edge, edge2 = NULL
+ * 0 if new vert located betwen edge1 and edge2
+ 3 additional vert for rounding case */
+ BMEdge *edge1;
+ BMEdge *edge2;
+ BMFace *f;
+ float hv[3]; /* coordinate of support vertex */
}VertexItem;
/* list of new vertices formed around v */
typedef struct AdditionalVert{
- struct AdditionalVert *next, *prev;
- BMVert *v;
- ListBase vertices;
- int count;
+ struct AdditionalVert *next, *prev;
+ BMVert *v; /* parrent vertex */
+ ListBase vertices; /* List of auxiliary vertices */
+ int count; /* count input edges, alse count additioanl vertex */
+ int countSelect; /* count input selection edges */
} AdditionalVert;
/*
* struct with bevel parametrs
*/
typedef struct BevelParams{
- ListBase vertList; /* list additional vertex */
- float offset;
- int byPolygon; /* 1 - make bevel on each polygon, 0 - ignore internal polygon */
+ ListBase vertList; /* list additional vertex */
+ ListBase newVertList; /* list of creation vertices */
+ float offset;
+ int byPolygon; /* 1 - make bevel on each polygon, 0 - ignore internal polygon */
+ int seg; /* segmentation */
+
+ BMOperator *op;
} BevelParams;
+
+typedef struct SurfaceEdgeData {
+ BMEdge *e;
+ BMVert *a, *b;
+ BMVert *boundaryA, *boundaryB;
+ ListBase vertexList;
+ int count;
+ float h[3];
+
+} SurfaceEdgeData;
+
+BMVert* bevel_create_unic_vertex(BMesh *bm, BevelParams *bp, float co[3]);
+
static void calc_corner_co(BMLoop *l, const float fac, float r_co[3],
const short do_dist, const short do_even)
{
@@ -211,167 +239,304 @@
(etags[BM_elem_index_get((e))].newv2) \
)
-// build point on edge
-// todo rename function
-BMVert* bevel_calc_aditional_vert(BMesh *bm, BevelParams *bp, BMEdge* edge, BMVert* vert)
+/* build point on edge
+* sEdge - selectes edge */
+BMVert* bevel_calc_aditional_vert(BMesh *bm, BevelParams *bp, BMEdge *sEdge, BMEdge* edge, BMVert* v)
{
- // TODO добавить проверку на то что эдж содержит вершину
- float vect[3], normV[3];
+ BMVert *new_Vert = NULL;
+/* float vect[3], normV[3];
+ sub_v3_v3v3(vect, BM_edge_other_vert(edge, v)->co, v->co);
+ normalize_v3_v3(normV, vect);
+ mul_v3_fl(normV, bp->offset);
- BMVert *new_Vert = NULL;
+ add_v3_v3(normV, v->co);
- sub_v3_v3v3(vect, BM_edge_other_vert(edge, vert)->co, vert->co);
- normalize_v3_v3(normV, vect);
- mul_v3_fl(normV, bp->offset);
+ new_Vert = bevel_create_unic_vertex(bm, bp, normV);
+ return new_Vert;*/
- add_v3_v3(normV, vert->co);
+ float ve[3], sve[3], angle, lenght;
- new_Vert = BM_vert_create(bm, normV, NULL);
- return new_Vert;
+ sub_v3_v3v3(ve, BM_edge_other_vert(edge, v)->co, v->co);
+ sub_v3_v3v3(sve, BM_edge_other_vert(sEdge, v)->co, v->co);
+
+ angle = angle_v3v3(ve, sve);
+ lenght = bp->offset / sin(angle);
+ normalize_v3(ve);
+ mul_v3_fl(ve, lenght);
+ add_v3_v3(ve, v->co);
+
+ new_Vert = bevel_create_unic_vertex(bm, bp, ve);
+
+ return new_Vert;
}
-// build point between edges
-// rename
+BMVert* bevel_create_unic_vertex(BMesh *bm, BevelParams *bp, float co[3])
+{
+ float epsilon = 1e-6;
+ BMVert *v = NULL;
+ NewVertexItem *item;
+ for (item = bp->newVertList.first; item; item = item->next) {
+ if (compare_v3v3(item->v->co, co, epsilon))
+ v = item->v;
+ }
+ if (!v) {
+ item = (NewVertexItem*)MEM_callocN(sizeof(NewVertexItem), "VertexItem");
+ item->v = BM_vert_create(bm, co, NULL);
+ BLI_addtail(&bp->newVertList, item);
+ v = item->v;
+ }
+ return v;
+}
+
+/*
+* build point between edges
+*/
BMVert* bevel_middle_vert(BMesh *bm, BevelParams *bp, BMEdge *edge_a, BMEdge *edge_b, BMVert *vert)
{
- float offset, v_a[3], v_b[3], v_c[3], norm_a[3], norm_b[3],norm_c[3], angel;
- BMVert* new_vert = NULL;
- offset = bp->offset;
- // calc vectors
- // TODO: add chec parallel case
- sub_v3_v3v3(v_a, BM_edge_other_vert(edge_a, vert)->co, vert->co);
- sub_v3_v3v3(v_b, BM_edge_other_vert(edge_b, vert)->co, vert->co);
- normalize_v3_v3(norm_a, v_a);
- normalize_v3_v3(norm_b, v_b);
- add_v3_v3v3(v_c, norm_a, norm_b);
- mul_v3_fl(v_c, 0.5);
- normalize_v3_v3(norm_c, v_c);
+ float offset, v_a[3], v_b[3], v_c[3], norm_a[3], norm_b[3],norm_c[3], angel;
+ float co[3];
+ BMVert* new_vert = NULL;
+ offset = bp->offset;
+ /* calc vectors */
+ sub_v3_v3v3(v_a, BM_edge_other_vert(edge_a, vert)->co, vert->co);
+ sub_v3_v3v3(v_b, BM_edge_other_vert(edge_b, vert)->co, vert->co);
+ normalize_v3_v3(norm_a, v_a);
+ normalize_v3_v3(norm_b, v_b);
- // v_c ^ edge_a
- //cos = (v_c[0]*v_a[0] + v_c[1]*v_a[1] + v_c[2]*v_a[0]) / (len_v3(v_c)*len_v3(v_a));
- angel = angle_normalized_v3v3(norm_c, norm_a);
- //offset = offset / (sqrt(1-cos*cos));
- offset = offset / sin(angel);
+ add_v3_v3v3(v_c, norm_a, norm_b);
+ normalize_v3_v3(norm_c, v_c);
+ angel = angle_v3v3(norm_a, norm_b);
+ mul_v3_fl(norm_c, offset / sin(angel/2));
+ add_v3_v3(norm_c, vert->co);
+ /*
+ mul_v3_fl(v_c, 0.5);
+ normalize_v3_v3(norm_c, v_c);
- mul_v3_fl(norm_c, offset);
- add_v3_v3(norm_c, vert->co);
- new_vert = BM_vert_create(bm, norm_c, NULL);
- return new_vert;
+ // v_c ^ edge_a
+ //cos = (v_c[0]*v_a[0] + v_c[1]*v_a[1] + v_c[2]*v_a[0]) / (len_v3(v_c)*len_v3(v_a));
+ angel = angle_normalized_v3v3(norm_c, norm_a);
+ //offset = offset / (sqrt(1-cos*cos));
+ offset = offset / sin(angel);
+
+ mul_v3_fl(norm_c, offset);
+ add_v3_v3(norm_c, vert->co);
+ */
+
+ new_vert = BM_vert_create(bm, norm_c, NULL);
+
+ return new_vert;
}
-// rename
/*
- e - selected edge
- return other selected edge
+* looking neighboring unselected Edge at the face
*/
+BMEdge* find_non_selected_adjacent_edge(BMesh *bm, BMFace *f, BMEdge *e, BMVert *v){
+ BMEdge *oe = NULL;
+ BMLoop *l = f->l_first;
+ do {
+ if (!(BMO_elem_flag_test(bm, l->e, EDGE_SELECTED)) &&
+ (l->e != e) &&
+ ((l->e->v1 == v ) ||
+ BM_edge_other_vert(l->e, l->e->v1) == v )) {
+ oe = l->e;
+ }
+ l = l->next;
+ } while (l != f->l_first);
+ return oe;
+}
+
+/*
+* e - selected edge
+* return other selected edge
+*/
BMEdge* find_selected_edge_in_face(BMesh *bm, BMFace *f, BMEdge *e, BMVert *v)
{
- BMEdge *oe = NULL;
- BMLoop *l = f->l_first;
- do {
- if (BMO_elem_flag_test(bm, l->e, EDGE_SELECTED) &&
- (l->e != e) &&
- ((l->e->v1 == v ) ||
- BM_edge_other_vert(l->e, l->e->v1) == v )) {
- oe = l->e;
- }
- l = l->next;
- } while (l != f->l_first);
- return oe;
+ BMEdge *oe = NULL;
+ BMLoop *l = f->l_first;
+ do {
+ if (BMO_elem_flag_test(bm, l->e, EDGE_SELECTED) &&
+ (l->e != e) &&
+ ((l->e->v1 == v ) ||
+ BM_edge_other_vert(l->e, l->e->v1) == v )) {
+ oe = l->e;
+ }
+ l = l->next;
+ } while (l != f->l_first);
+ return oe;
}
+BMEdge* find_selected_edge_in_av(BMesh *bm, BevelParams *bp, AdditionalVert *av)
+{
+ BMEdge *result = NULL, *e;
+ BMOIter siter;
+ BMO_ITER (e, &siter, bm, bp->op, "geom", BM_EDGE) {
+ if ( (BMO_elem_flag_test(bm, e, EDGE_SELECTED)) &&
+ ((e->v1 == av->v) || (BM_edge_other_vert(e, e->v1) == av->v)))
+ result = e;
+ }
+
+ /*e = bmesh_disk_faceedge_find_first(ed, av->v);
+ do {
+ e = bmesh_disk_edge_next(e, av->v);
+ if (BMO_elem_flag_test(bm, e, EDGE_SELECTED))
+ result = e;
+ } while (e != ed);*/
+ return result;
+}
+
int check_dublicated_vertex_item(AdditionalVert *item, BMFace *f)
{
- VertexItem *vItem;
- int result = 0;
- for (vItem = item->vertices.first; vItem; vItem = vItem->next) {
- if (vItem->f == f)
- result = 1;
- }
- return result;
+ VertexItem *vItem;
+ int result = 0;
+ for (vItem = item->vertices.first; vItem; vItem = vItem->next) {
+ if (vItem->f == f)
+ result = 1;
+ }
+ return result;
+}
+VertexItem* calc_support_vertex(BevelParams* bp, BMEdge *e, BMVert *v)
+{
+ VertexItem *item;
+ float vect[3], normV[3];
+
+ item = (VertexItem*)MEM_callocN(sizeof(VertexItem), "VertexItem");
+ item->onEdge = 3;
+ item->edge1 = e;
+ item->edge2 = NULL;
+ item->f = NULL;
+ item->v = NULL;
+
+ sub_v3_v3v3(vect, BM_edge_other_vert(e, v)->co, v->co);
+ normalize_v3_v3(normV, vect);
+ mul_v3_fl(normV, bp->offset);
+ add_v3_v3(normV, v->co);
+
+ copy_v3_v3(item->hv, normV);
+ return item;
}
-/*
+int check_dublicated_vertex_item_by_edge(AdditionalVert *av, BMEdge* edge)
+{
+ VertexItem *vitem;
+ int result = 0;
+ for (vitem = av->vertices.first; vitem; vitem = vitem->next) {
+ if ((vitem->onEdge == 1) &&
+ (vitem->edge1 == edge))
+ result = 1;
+ }
+ return result;
+
+}/*
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list