Revision: 50103
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50103
Author:   redtriangle
Date:     2012-08-21 21:42:42 +0000 (Tue, 21 Aug 2012)
Log Message:
-----------
Bridge, add n-gon optimization
Bevel, fix error in calculating profile.

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/bmesh/operators/bmo_connect.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-21 21:01:07 UTC (rev 50102)
+++ branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_opdefines.c       
2012-08-21 21:42:42 UTC (rev 50103)
@@ -447,6 +447,7 @@
      {BMO_OP_SLOT_INT,  "segmentation"}, /* input segmentation param */
      {BMO_OP_SLOT_INT,  "interpolation"}, /* input interpolation param */
      {BMO_OP_SLOT_FLT,  "strenght"}, /* input strenght param */
+        {BMO_OP_SLOT_BOOL, "n_gon"},    /* flag N-gon optimization */
 
         {0, /* null-terminating sentinel */}},
        bmo_bridge_loops_exec,

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-21 21:01:07 UTC (rev 50102)
+++ branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_bevel.c  
2012-08-21 21:42:42 UTC (rev 50103)
@@ -66,10 +66,23 @@
        BMVert *v;
 } NewVertexItem;
 
+
+
+/* list of new vertices formed around v */
+typedef struct AdditionalVert{
+       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;
+
+
+
 /* Item in the list of additional vertices */
 typedef struct VertexItem{
        struct VertexItem *next, *prev;
-       BMVert *v;              /* parent vertex */
+       BMVert *v;
        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     */
@@ -77,26 +90,22 @@
        BMEdge *edge2;
        BMFace *f;
        float hv[3];    /* coordinate of support vertex */
-}VertexItem;
+       AdditionalVert *parent;
+} VertexItem;
 
-/* list of new vertices formed around v */
-typedef struct AdditionalVert{
-       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{
+typedef struct BevelParams {
        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 */
+       int isMaxOffset;                /* flag for control offset 0 - offset < 
max, 1 - offset > max*/
+       float maxOffset;                /* maximum allowable offset */
 
        BMOperator *op;
 } BevelParams;
@@ -239,12 +248,37 @@
                (etags[BM_elem_index_get((e))].newv2)                           
      \
        )
 
+
+void recalculate_aditional_vert(BMesh* bm, BevelParams* bp, VertexItem *vi, 
BMEdge* sEdge)
+{
+       // берем минимальный отсуп
+       float ve[3], sve[3], angle, lenght, viLen, vie[3];
+       BMVert *v;
+       v = vi->parent->v;
+
+       sub_v3_v3v3(ve, BM_edge_other_vert(vi->edge1, 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);
+
+       sub_v3_v3v3(vie, v->co, vi->v->co);
+       viLen = len_v3(vie);
+
+       if (lenght < viLen){
+               normalize_v3(ve);
+               mul_v3_fl(ve, lenght);
+               add_v3_v3(ve, v->co);
+               vi->v = BM_vert_create(bm, ve, NULL);
+       }
+}
+
 /* build point on edge
 *  sEdge - selectes edge */
 BMVert* bevel_calc_aditional_vert(BMesh *bm, BevelParams *bp, BMEdge *sEdge, 
BMEdge* edge, BMVert* v)
 {
        BMVert *new_Vert = NULL;
-/*     float vect[3], normV[3];
+       /*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);
@@ -261,6 +295,10 @@
 
        angle = angle_v3v3(ve, sve);
        lenght = bp->offset / sin(angle);
+
+       //if (bp->maxOffset < lenght)
+       //      bp->maxOffset = lenght;
+
        normalize_v3(ve);
        mul_v3_fl(ve, lenght);
        add_v3_v3(ve, v->co);
@@ -294,7 +332,6 @@
 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;
-       float co[3];
        BMVert* new_vert = NULL;
        offset = bp->offset;
        /* calc vectors */
@@ -395,10 +432,45 @@
        return result;
 }
 
-VertexItem* calc_support_vertex(BevelParams* bp, BMEdge *e, BMVert *v)
+/*
+*      A-M-B
+*        |
+*      C-N-D
+*  A-B, C-D input line
+* return MN - distance
+*/
+float calc_len_between_line(float A[3], float B[3], float C[3], float D[3], 
float M[3], float N[3])
 {
+       float P1, P2, Q1, Q2, R1, R2, m, n;
+       float MN[3];
+
+       P1 = (B[0] - A[0]) * (B[0] - A[0]) + (B[1] - A[1]) * (B[1] - A[1]) + 
(B[2] - A[2]) * (B[2] - A[2]);
+       P2 = (B[0] - A[0]) * (D[0] - C[0]) + (B[1] - A[1]) * (D[1] - C[1]) + 
(B[2] - A[2]) * (D[2] - C[2]);
+       Q1 = -1 * P2;
+       Q2 = -1 * ((D[0]  - C[0]) * (D[0] - C[0]) + (D[1] - C[1]) * (D[1] - 
C[1]) + (D[2] - C[2]) * (D[2] - C[2]));
+       R1 = (C[0] - A[0]) * (B[0] - A[0]) + (C[1] - A[1]) * (B[1] - A[1]) + 
(C[2] - A[2]) * (B[2] - A[2]);
+       R2 = (C[0] - A[0]) * (D[0] - C[0]) + (C[1] - A[1]) * (D[1] - C[1]) + 
(C[2] - A[2]) * (D[2] - C[2]);
+
+       m = (Q2 * R1 - Q1 * R2) / (P1 * Q2 - P2 * Q1);
+       n = (P1 * R2 - P2 * R1) / (P1 * Q2 - P2 * Q1);
+
+       M[0] = A[0] + m * (B[0] - A[0]);
+       M[1] = A[1] + m * (B[1] - A[1]);
+       M[2] = A[2] + m * (B[2] - A[2]);
+
+       N[0] = C[0] + n * (D[0] - C[0]);
+       N[1] = C[1] + n * (D[1] - C[1]);
+       N[2] = C[2] + n * (D[2] - C[2]);
+
+       sub_v3_v3v3(MN, M, N);
+       return len_v3(MN);
+}
+
+VertexItem* calc_support_vertex(BMEdge *e, BMVert *v, VertexItem *itemA, 
VertexItem *itemB)
+{
        VertexItem *item;
-       float vect[3], normV[3];
+//     float vect[3], normV[3];
+       float M[3], N[3];
 
        item = (VertexItem*)MEM_callocN(sizeof(VertexItem), "VertexItem");
        item->onEdge = 3;
@@ -407,27 +479,68 @@
        item->f = NULL;
        item->v = NULL;
 
-       sub_v3_v3v3(vect, BM_edge_other_vert(e, v)->co, v->co);
+       /*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);
+       copy_v3_v3(item->hv, normV);*/
+
+       calc_len_between_line(v->co, BM_edge_other_vert(e, v)->co, 
itemA->v->co, itemB->v->co, M, N);
+       copy_v3_v3(item->hv, M);
+
        return item;
 }
 
-int check_dublicated_vertex_item_by_edge(AdditionalVert *av, BMEdge* edge)
+/*
+  return NULL if not dublicated
+       return dublicated item
+*/
+VertexItem* check_dublicated_vertex_item_by_edge(AdditionalVert *av, BMEdge* 
edge)
 {
-       VertexItem *vitem;
-       int result = 0;
+       VertexItem *vitem, *vi = NULL;
+//     int result = 0;
+
        for (vitem = av->vertices.first; vitem; vitem = vitem->next) {
                if  ((vitem->onEdge == 1) &&
                        (vitem->edge1 == edge))
-                       result = 1;
+                       vi = vitem;
        }
-       return result;
+       return vi;
 
-}/*
+}
+
+VertexItem* find_on_edge_vertex_item(AdditionalVert* av, BMEdge *e)
+{
+       VertexItem *item, *r = NULL;
+       for (item = av->vertices.first; item; item = item->next){
+               if ((item->onEdge == 1) && (item->edge1 == e))
+                       r = item;
+       }
+       return r;
+}
+
+
+VertexItem* find_between_vertex_item(AdditionalVert* av, BMEdge *e, VertexItem 
*exclI)
+{
+       VertexItem *item, *r = NULL;
+       for (item = av->vertices.first; item; item = item->next){
+               if (exclI != NULL){
+                       if ((item->onEdge == 0) &&
+                                       (item != exclI) &&
+                                       ((item->edge1 == e) || (item->edge2) == 
e))
+                               r = item;
+               }
+               else {
+                       if ((item->onEdge == 0) &&
+                               ((item->edge1 == e) || (item->edge2) == e))
+                       r = item;
+               }
+       }
+       return r;
+}
+
+/*
 * additional construction arround the vertex
 */
 void bevel_aditional_construction_by_vert(BMesh *bm, BevelParams *bp, 
BMOperator *op, BMVert *v)
@@ -436,7 +549,6 @@
        BMOIter siter;
        //BMIter iter;
        BMEdge *e, **edges = NULL;
-       int i;
        BLI_array_declare(edges);
 
        // calc count input selected edges
@@ -464,9 +576,10 @@
                        if (BMO_elem_flag_test(bm, e, EDGE_SELECTED)) {
                                BMFace *f;
                                BMIter iter;
+
                                av->countSelect++;
                                /* calc additional point,    calc support 
vertex on edge */
-                               BLI_addtail(&av->vertices, 
calc_support_vertex(bp, e, v));
+                               //BLI_addtail(&av->vertices, 
calc_support_vertex(bp, e, v));
 
                                /* point located beteween selecion edges*/
                                BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
@@ -477,6 +590,7 @@
                                                        if 
(!check_dublicated_vertex_item(av, f)) {
                                                                VertexItem 
*item;
                                                                item = 
(VertexItem*)MEM_callocN(sizeof(VertexItem), "VertexItem");
+                                                               item->parent = 
av;
                                                                item->onEdge = 
0; // false
                                                                item->edge1 = e;
                                                                item->edge2 = 
find_selected_edge_in_face(bm, f, e, v);
@@ -489,9 +603,10 @@
 
                                                adjacentE = 
find_non_selected_adjacent_edge(bm, f, e, v);
                                                if ((l->e == e) && (adjacentE 
!= NULL)){
-                                                       if 
(!check_dublicated_vertex_item_by_edge(av, adjacentE)){
+                                                       if 
(check_dublicated_vertex_item_by_edge(av, adjacentE) == NULL){
                                                                VertexItem 
*item;
                                                                item = 
(VertexItem*)MEM_callocN(sizeof(VertexItem), "VertexItem");
+                                                               item->parent = 
av;
                                                                item->onEdge = 
1; /* true */
                                                                item->edge1 = 
adjacentE;
                                                                item->edge2 = 
NULL;
@@ -500,6 +615,8 @@
 
                                                                
BLI_addtail(&av->vertices, item);
                                                                av->count ++;
+                                                       } else{
+                                                               
recalculate_aditional_vert(bm, bp, check_dublicated_vertex_item_by_edge(av, 
adjacentE), e);
                                                        }
                                                }
 
@@ -513,8 +630,8 @@
                        /*if (!BMO_elem_flag_test(bm, e, EDGE_SELECTED)){
                                VertexItem *item;
                                item = 
(VertexItem*)MEM_callocN(sizeof(VertexItem), "VertexItem");
-                               item->onEdge = 1; /* true */
-                               /*item->edge1 = e;
+                               item->onEdge = 1;
+                               item->edge1 = e;
                                item->edge2 = NULL;
                                item->f = NULL;
                                item->v = bevel_calc_aditional_vert(bm, bp, e, 
v);
@@ -522,14 +639,30 @@
                                av->count ++;
                        }*/
                } while (e != edges[0]);
+
+               /* calc additional point,    calc support vertex on edge */
+               e = bmesh_disk_faceedge_find_first(edges[0], v);
+               do {
+                       VertexItem *itemA, *itemB; /* pair of middle vertices */
+                       e = bmesh_disk_edge_next(e, v);
+                       if (BMO_elem_flag_test(bm, e, EDGE_SELECTED)) {
+                       itemA = find_between_vertex_item(av, e , NULL);
+                               if (itemA != NULL)
+                                       itemB = find_between_vertex_item(av, e 
, itemA);
+
+                               if ((itemA != NULL && itemB != NULL))
+                                       BLI_addtail(&av->vertices, 
calc_support_vertex(e, v, itemA, itemB));
+                       }
+               } while (e != edges[0]);
        }
+
        BLI_array_free(edges);
 }
 

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to