[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48946] branches/soc-2012-sushi/source/ blender/bmesh/operators/bmo_bevel.c: implement linear shape of bevel

Alexander Mokhov alexander.mokhov at gmail.com
Sun Jul 15 20:24:16 CEST 2012


Revision: 48946
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48946
Author:   redtriangle
Date:     2012-07-15 18:24:16 +0000 (Sun, 15 Jul 2012)
Log Message:
-----------
implement linear shape of bevel

Modified Paths:
--------------
    branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_bevel.c

Modified: branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_bevel.c
===================================================================
--- branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_bevel.c	2012-07-15 16:57:21 UTC (rev 48945)
+++ branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_bevel.c	2012-07-15 18:24:16 UTC (rev 48946)
@@ -26,7 +26,6 @@
 
 #include "MEM_guardedalloc.h"
 
-//#include "BLI_heap.h"
 #include "BLI_listbase.h"
 #include "BLI_array.h"
 #include "BLI_math.h"
@@ -39,6 +38,7 @@
 #include "intern/bmesh_operators_private.h" /* own include */
 #include "intern/bmesh_private.h"
 
+
 #define BEVEL_FLAG	1
 #define BEVEL_DEL	2
 #define FACE_NEW	4
@@ -48,7 +48,7 @@
 #define FACE_SPAN	64
 #define FACE_HOLE	128
 
-#define EDGE_SELECTED 6
+#define EDGE_SELECTED 256
 
 typedef struct LoopTag {
 	BMVert *newv;
@@ -63,22 +63,27 @@
     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
+                // false, new vert located betwen edge1 and edge2
     BMEdge *edge1;
     BMEdge *edge2;
+    BMFace *f;
 }VertexItem;
 
-// list of new vertices formed around v
+/* list of new vertices formed around v */
 typedef struct AdditionalVert{
     struct AdditionalVert *next, *prev;
     BMVert *v;
     ListBase vertices;
+    int count;
 } AdditionalVert;
 
-
+/*
+* struct with bevel parametrs
+*/
 typedef struct BevelParams{
-    ListBase vertList;
+    ListBase vertList;  /* list additional vertex */
     float offset;
+    int byPolygon; /* 1 - make bevel on each polygon, 0 - ignore internal polygon */
 } BevelParams;
 
 static void calc_corner_co(BMLoop *l, const float fac, float r_co[3],
@@ -226,13 +231,14 @@
 }
 
 // build point between edges
+// rename
 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: ДОБАВИТЬ ПРОВЕРКУ НА ПАРАЛЕЛЬНОСТЬ
+    // 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);
@@ -253,15 +259,52 @@
     return new_vert;
 }
 
-// additional construction arround the vertex
+// rename
+/*
+  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;
+}
+
+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;
+
+}
+
+/*
+* additional construction arround the vertex
+*/
 void bevel_aditional_construction_by_vert(BMesh *bm, BevelParams *bp, BMOperator *op, BMVert *v)
 {
+    // TODO develop planar case
     BMOIter siter;
     BMIter iter;
     BMEdge *e, **edges = NULL;
+    int i;
     BLI_array_declare(edges);
 
-    // calc count input edges
+    // calc count input selected edges
     BMO_ITER (e, &siter, bm, op, "geom", BM_EDGE) {
         if ((e->v1 == v)|| (BM_edge_other_vert(e, e->v1) == v))
         {
@@ -269,77 +312,216 @@
             BLI_array_append(edges, e);
         }
     }
-
-    if (BLI_array_count(edges) == 1)
-    {
-    // TODO разработать плоский варинат
+    if (BLI_array_count(edges) > 0) {
+        BMEdge *prev_e;
         AdditionalVert *av;
         av = (AdditionalVert*)MEM_callocN(sizeof(AdditionalVert), "AdditionalVert");
         av->v = v;
+        av->count = 0;
         av->vertices.first = av->vertices.last = NULL;
         BLI_addtail(&bp->vertList, av);
+        e = bmesh_disk_faceedge_find_first(edges[0], v);
 
-        BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH)
-        {
-            if (e!= edges[0])
-            {
-                if ((e->v1 == v)||(BM_edge_other_vert(e, e->v1) == v)){
-                    VertexItem *item;
-                    item = (VertexItem*)MEM_callocN(sizeof(VertexItem), "VertexItem");
-                    item->onEdge = TRUE;
-                    item->edge1 = e;
-                    item->edge2 = NULL;
-                    item->v = bevel_calc_aditional_vert(bm, bp, e, v);
-                    BLI_addtail(&av->vertices, item);
-                   }
+        // for (e = bmesh_disk_edge_next(edges[0], v); e != edges[0]; e = bmesh_disk_edge_next(e, v)) {
+        do {
+            //prev_e = e;
+            e = bmesh_disk_edge_next(e, v);
+            // point located beteween selecion edges
+            if (BMO_elem_flag_test(bm, e, EDGE_SELECTED)) {
+                BMFace *f;
+                BMIter iter;
+                BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
+                    BMLoop *l = f->l_first;
+                    BMEdge **ee = NULL;
+                    BLI_array_declare (ee);
+                    do {
+                        if ((l->e == e) && (find_selected_edge_in_face(bm, f, e, v) !=NULL )){
+                            if (!check_dublicated_vertex_item(av, f)) {
+                                VertexItem *item;
+                                item = (VertexItem*)MEM_callocN(sizeof(VertexItem), "VertexItem");
+                                item->onEdge = 0; // false
+                                item->edge1 = e;
+                                item->edge2 = find_selected_edge_in_face(bm, f, e, v);
+                                item->f = f;
+                                item->v = bevel_middle_vert(bm, bp,e, item->edge2, v);
+                                BLI_addtail(&av->vertices, item);
+                                av->count ++;
+                            }
+                        }
+                       l = l->next;
+                    } while (l != f->l_first);
+                }
             }
-        }
-    }
-
-    if (BLI_array_count(edges) > 1)
-    {
-        BMEdge *cur_e, *prev_e;
-        AdditionalVert *av;
-        av = (AdditionalVert*)MEM_callocN(sizeof(AdditionalVert), "AdditionalVert");
-        av->v = v;
-        av->vertices.first = av->vertices.last = NULL;
-        BLI_addtail(&bp->vertList, av);
-        e = edges[0];
-        cur_e = e;
-        do {
-            prev_e = cur_e;
-            cur_e = bmesh_disk_edge_next(cur_e, v);
-            if (!BMO_elem_flag_test(bm, cur_e, EDGE_SELECTED)){
+            if (!BMO_elem_flag_test(bm, e, EDGE_SELECTED)){
                 VertexItem *item;
                 item = (VertexItem*)MEM_callocN(sizeof(VertexItem), "VertexItem");
-                item->onEdge = TRUE;
-                item->edge1 = cur_e;
+                item->onEdge = 1; /* true */
+                item->edge1 = e;
                 item->edge2 = NULL;
-                item->v = bevel_calc_aditional_vert(bm, bp, cur_e, v);
+                item->f = NULL;
+                item->v = bevel_calc_aditional_vert(bm, bp, e, v);
                 BLI_addtail(&av->vertices, item);
-            }else {               
-                if ( BMO_elem_flag_test(bm, cur_e, EDGE_SELECTED) &&
-                     BMO_elem_flag_test(bm, prev_e, EDGE_SELECTED)){
-                    VertexItem *item;
-                    item = (VertexItem*)MEM_callocN(sizeof(VertexItem), "VertexItem");
-                    item->onEdge = FALSE;
-                    item->edge1 = cur_e;
-                    item->edge2 = prev_e;
-                    item->v = bevel_middle_vert(bm, bp, prev_e,cur_e, v);
-                    BLI_addtail(&av->vertices, item);
-                }
+                av->count ++;
             }
-        } while (e!= cur_e);
+        } while (e != edges[0]);
     }
+    BLI_array_free(edges);
 }
 
-// Build the polygons along the selected Edge
-void bevel_build_polygon(BMesh *bm, BevelParams *bp, BMEdge *e){
+//TODO rename it!
+AdditionalVert* get_additionalVert_by_vert(BevelParams *bp, BMVert *v)
+{
+    VertexItem *item;
+    AdditionalVert *av = NULL;
+    for (item = bp->vertList.first; item ; item = item->next){
+        if (item->v == v)
+            av = item;
+    }
+    return av;
+}
+
+/*
+* return 1 if face content e
+*/
+int is_edge_of_face (BMFace *f, BMEdge* e)
+{
+    int result  = 0;
+    BMLoop *l = f->l_first;
+    do {
+        if (l->e == e)
+            result = 1;
+        l = l->next;
+    } while  (l != f->l_first);
+    return result;
+}
+
+
+
+void rebuild_polygon(BMesh *bm, BevelParams *bp, BMFace *f)
+{
+    BMVert **vv = NULL; /* list vertex for new ngons */
+    BMLoop *l;
+    VertexItem *vItem;
+    AdditionalVert *av;
+    BLI_array_declare(vv);
+    int count;
+    l = f->l_first;
+    do {
+        av = get_additionalVert_by_vert(bp, l->v);
+        if (av != NULL){
+            for (vItem = av->vertices.first; vItem; vItem = vItem->next) {
+                // case 1, all point located in edges
+                if ((vItem->onEdge)&&(is_edge_of_face(f, vItem->edge1)))
+                    BLI_array_append(vv, vItem->v);
+                // case 2, point located between
+                if ((!vItem->onEdge) &&
+                        (is_edge_of_face(f, vItem->edge1)) &&
+                        (is_edge_of_face(f, vItem->edge2)))
+                    BLI_array_append(vv, vItem->v);
+            }
+        } else
+            BLI_array_append(vv, l->v);
+        l = l->next;
+    } while (l != f->l_first);
+
+    count = BLI_array_count(vv);
+    // TODO check normal
+    if (count > 0)
+        BM_face_create_ngon_vcloud(bm, vv, count, 0);
+    BLI_array_free(vv);
+}
+
+void bevel_build_polygon_arround_vertex(BMesh *bm, BevelParams *bp, BMVert *v)
+{
+    AdditionalVert *av = get_additionalVert_by_vert(bp, v);
+    VertexItem *vi;
+    BMVert **vv = NULL;
+    BLI_array_declare(vv);
+    if (av->count > 2) {
+        for (vi = av->vertices.first; vi; vi = vi->next)
+            BLI_array_append(vv, vi->v);
+        /* TODO check normal */
+        if (BLI_array_count(vv) > 0)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list