extrude handles loop customdata properly, also added a BM_Face_CopyShared function...
authorJoseph Eagar <joeedh@gmail.com>
Sat, 14 Feb 2009 11:58:52 +0000 (11:58 +0000)
committerJoseph Eagar <joeedh@gmail.com>
Sat, 14 Feb 2009 11:58:52 +0000 (11:58 +0000)
source/blender/bmesh/bmesh.h
source/blender/bmesh/intern/bmesh_construct.c
source/blender/bmesh/operators/extrudeops.c

index 54ec9f321af1007904855c49f08051429d9f79dc..42e41a0270f544e63485ea7dfdd53ed19ef08df9 100644 (file)
@@ -144,7 +144,7 @@ typedef struct BMEdge {
        struct BMNode d1, d2;
        struct BMLoop *loop;
        void *data;
-       float crease, bweight;                                                                          /*make these custom data.... no really, please....*/
+       float crease, bweight; /*make these custom data.... no really, please....*/
 } BMEdge;
 
 typedef struct BMLoop  {
@@ -180,6 +180,8 @@ struct BMVert *BM_Make_Vert(struct BMesh *bm, float co[3], struct BMVert *exampl
 struct BMEdge *BM_Make_Edge(struct BMesh *bm, struct BMVert *v1, struct BMVert *v2, struct BMEdge *example, int nodouble);
 struct BMFace *BM_Make_Quadtriangle(struct BMesh *bm, struct BMVert **verts, BMEdge **edges, int len, struct BMFace *example, int nodouble);
 struct BMFace *BM_Make_Ngon(struct BMesh *bm, struct BMVert *v1, struct BMVert *v2, struct BMEdge **edges, int len, int nodouble);
+/*copies loop data from adjacent faces*/
+void BM_Face_CopyShared(BMesh *bm, BMFace *f);
 void BM_Copy_Attributes(struct BMesh *source_mesh, struct BMesh *target_mesh, void *source, void *target);
 void BM_remove_tagged_faces(struct BMesh *bm, int flag);
 void BM_remove_tagged_edges(struct BMesh *bm, int flag);
index 29a5c3290889c7a6f2246e9b2058ed72ac383421..d302a85ec7289566a8e8bd6a68fbdefece77c4b9 100644 (file)
 #include "bmesh.h"
 #include "bmesh_private.h"
 
+/*prototypes*/
+static void bm_copy_loop_attributes(BMesh *source_mesh, BMesh *target_mesh,
+                                    BMLoop *source_loop, BMLoop *target_loop);
+
 /*
  * BM_CONSTRUCT.C
  *
@@ -170,6 +174,29 @@ BMFace *BM_Make_Quadtriangle(BMesh *bm, BMVert **verts, BMEdge **edges, int len,
        return f;
 }
 
+
+/*copies face data from shared adjacent faces*/
+void BM_Face_CopyShared(BMesh *bm, BMFace *f) {
+       BMIter iter;
+       BMLoop *l, *l2;
+
+       if (!f) return;
+
+       l=BMIter_New(&iter, bm, BM_LOOPS_OF_FACE, f);
+       for (; l; l=BMIter_Step(&iter)) {
+               l2 = l->radial.next->data;
+               
+               if (l2 && l2 != l) {
+                       if (l2->v == l->v) {
+                               bm_copy_loop_attributes(bm, bm, l2, l);
+                       } else {
+                               l2 = (BMLoop*) l2->head.next;
+                               bm_copy_loop_attributes(bm, bm, l2, l);
+                       }
+               }
+       }
+}
+
 /*
  * BMESH MAKE NGON
  *
@@ -196,7 +223,7 @@ BMFace *BM_Make_Ngon(BMesh *bm, BMVert *v1, BMVert *v2, BMEdge **edges, int len,
                                verts[i] = edges[i]->v1;
                        } else if(!BMO_TestFlag(bm, edges[i]->v2, BM_EDGEVERT)) {
                                BMO_SetFlag(bm, edges[i]->v2, BM_EDGEVERT);
-                               verts[i] =      edges[i]->v2;
+                               verts[i] = edges[i]->v2;
                        }
                }
                
@@ -211,9 +238,10 @@ BMFace *BM_Make_Ngon(BMesh *bm, BMVert *v1, BMVert *v2, BMEdge **edges, int len,
                if(len > VERT_BUF_SIZE)
                        MEM_freeN(verts);
        }
-               
-       if((!f) && (!overlap))
+
+       if((!f) && (!overlap)) {
                f = bmesh_mf(bm, v1, v2, edges, len);
+       }
 
        return f;
 }
index 599d1611392400f2e55a37c554f3b7aa456bbd76..eca8332c917306eaa085eaa0a91e62c9ee1f8c3d 100644 (file)
@@ -19,6 +19,7 @@ void extrude_edge_context_exec(BMesh *bm, BMOperator *op)
        BMOIter siter;
        BMIter iter, fiter;
        BMEdge *edge, *newedge;
+       BMLoop *l, *l2;
        BMVert *verts[4];
        BMFace *f;
        int totflagged, rlen;
@@ -65,6 +66,28 @@ void extrude_edge_context_exec(BMesh *bm, BMOperator *op)
                
                //not sure what to do about example face, pass NULL for now.
                f = BM_Make_Quadtriangle(bm, verts, NULL, 4, NULL, 0);          
+
+               /*copy attributes*/
+               l=BMIter_New(&iter, bm, BM_LOOPS_OF_FACE, f);
+               for (; l; l=BMIter_Step(&iter)) {
+                       l2 = l->radial.next->data;
+                       
+                       if (l2 && l2 != l) {
+                               /*copy data*/
+                               if (l2->v == l->v) {
+                                       BM_Copy_Attributes(bm, bm, l2, l);
+                                       l2 = (BMLoop*) l2->head.next;
+                                       l = (BMLoop*) l->head.next;
+                                       BM_Copy_Attributes(bm, bm, l2, l);
+                               } else {
+                                       l2 = (BMLoop*) l2->head.next;
+                                       BM_Copy_Attributes(bm, bm, l2, l);
+                                       l2 = (BMLoop*) l2->head.prev;
+                                       l = (BMLoop*) l->head.next;
+                                       BM_Copy_Attributes(bm, bm, l2, l);
+                               }
+                       }
+               }
        }
        
        /*cleanup*/