uv sculpting now functional on bmesh
authorAntony Riakiotakis <kalast@gmail.com>
Mon, 6 Feb 2012 21:00:50 +0000 (21:00 +0000)
committerAntony Riakiotakis <kalast@gmail.com>
Mon, 6 Feb 2012 21:00:50 +0000 (21:00 +0000)
source/blender/editors/mesh/bmeshutils.c
source/blender/editors/sculpt_paint/sculpt_uv.c
source/blender/editors/uvedit/uvedit_ops.c

index f938a2de9c16790e439763227b98e95dce5e4e5a..d295011b6b50957ad5b70b60d0bdeade316ba4f2 100644 (file)
@@ -782,8 +782,7 @@ UvElementMap *EDBM_make_uv_element_map(BMEditMesh *em, int selected, int do_isla
        BMFace **stack;
        int stacksize = 0;
 
-       BM_ElemIndex_Ensure(em->bm, BM_VERT);
-       BM_ElemIndex_Ensure(em->bm, BM_FACE);
+       BM_ElemIndex_Ensure(em->bm, BM_VERT | BM_FACE);
 
        totverts = em->bm->totvert;
        totuv = 0;
@@ -801,7 +800,7 @@ UvElementMap *EDBM_make_uv_element_map(BMEditMesh *em, int selected, int do_isla
        if (!element_map) {
                return NULL;
        }
-
+       element_map->totalUVs = totuv;
        element_map->vert = (UvElement**)MEM_callocN(sizeof(*element_map->vert)*totverts, "UvElementVerts");
        buf = element_map->buf = (UvElement*)MEM_callocN(sizeof(*element_map->buf)*totuv, "UvElement");
 
@@ -881,111 +880,6 @@ UvElementMap *EDBM_make_uv_element_map(BMEditMesh *em, int selected, int do_isla
                i++;
        }
 
-
-       ////////////////////
-
-       /*
-       EditVert *ev;
-       EditFace *efa;
-
-       UvElementMap *vmap;
-       UvElement *buf;
-       UvElement *islandbuf;
-       MTFace *tf;
-       unsigned int a;
-       int     i,j, totuv, nverts, nislands = 0, islandbufsize = 0;
-       unsigned int *map;
-       EditFace **stack;
-       int stacksize = 0;
-
-       for(ev = em->verts.first, i = 0; ev; ev = ev->next, i++)
-               ev->tmp.l = i;
-
-       totuv = 0;
-
-       for(efa = em->faces.first; efa; efa = efa->next)
-               if (!selected || ((!efa->h) && (efa->f & SELECT)))
-                       totuv += (efa->v4)? 4: 3;
-
-       if (totuv == 0)
-               return NULL;
-
-       vmap = (UvElementMap *)MEM_callocN(sizeof(*vmap), "UvVertElementMap");
-       if (!vmap)
-               return NULL;
-
-       vmap->vert = (UvElement**)MEM_callocN(sizeof(*vmap->vert)*em->totvert, "UvElementVerts");
-       buf = vmap->buf = (UvElement*)MEM_callocN(sizeof(*vmap->buf)*totuv, "UvElement");
-
-       if (!vmap->vert || !vmap->buf) {
-               EDBM_free_uv_element_map(vmap);
-               return NULL;
-       }
-
-       vmap->totalUVs = totuv;
-
-       for(efa = em->faces.first; efa; a++, efa = efa->next) {
-               if (!selected || ((!efa->h) && (efa->f & SELECT))) {
-                       nverts = (efa->v4)? 4: 3;
-
-                       for(i = 0; i<nverts; i++) {
-                               buf->tfindex = i;
-                               buf->face = efa;
-                               buf->separate = 0;
-                               buf->island = INVALID_ISLAND;
-
-                               buf->next = vmap->vert[(*(&efa->v1 + i))->tmp.l];
-                               vmap->vert[(*(&efa->v1 + i))->tmp.l] = buf;
-
-                               buf++;
-                       }
-               }
-
-               efa->tmp.l = INVALID_ISLAND;
-       }
-
-       for(a = 0, ev = em->verts.first; ev; a++, ev = ev->next) {
-               UvElement *newvlist = NULL, *vlist = vmap->vert[a];
-               UvElement *iterv, *v, *lastv, *next;
-               float *uv, *uv2;
-
-               while(vlist) {
-                       v= vlist;
-                       vlist= vlist->next;
-                       v->next= newvlist;
-                       newvlist= v;
-
-                       efa = v->face;
-                       tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-                       uv = tf->uv[v->tfindex];
-
-                       lastv= NULL;
-                       iterv= vlist;
-
-                       while(iterv) {
-                               next= iterv->next;
-                               efa = iterv->face;
-                               tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-                               uv2 = tf->uv[iterv->tfindex];
-
-                               if (fabsf(uv[0]-uv2[0]) < STD_UV_CONNECT_LIMIT && fabsf(uv[1]-uv2[1]) < STD_UV_CONNECT_LIMIT) {
-                                       if (lastv) lastv->next = next;
-                                       else vlist = next;
-                                       iterv->next = newvlist;
-                                       newvlist = iterv;
-                               }
-                               else
-                                       lastv = iterv;
-
-                               iterv = next;
-                       }
-
-                       newvlist->separate = 1;
-               }
-
-               vmap->vert[a] = newvlist;
-       }
-*/
        if (do_islands) {
                /* at this point, every UvElement in vert points to a UvElement sharing the same vertex. Now we should sort uv's in islands. */
                int *island_number;
index 228183d3d8acfc50d14d4a3fe4477a46222cd4c2..e89007b2480168772e7ddea306e96963fd040b72 100644 (file)
@@ -209,15 +209,15 @@ void HC_relaxation_iteration_uv(BMEditMesh *em, UvSculptData *sculptdata, float
                        sculptdata->uv[i].uv[1] = (1.0-strength)*sculptdata->uv[i].uv[1] + strength*(tmp_uvdata[i].p[1] - 0.5f*(tmp_uvdata[i].b[1] + tmp_uvdata[i].sum_b[1]/tmp_uvdata[i].ncounter));
 
                        for(element = sculptdata->uv[i].element; element; element = element->next){
-#if 0 /* BMESH_TODO */
-                               MTFace *mt;
+                               MLoopUV *luv;
+                               BMLoop *l;
+
                                if(element->separate && element != sculptdata->uv[i].element)
                                        break;
-                               mt = CustomData_em_get(&em->fdata, element->face->data, CD_MTFACE);
-                               copy_v2_v2(mt->uv[element->tfindex], sculptdata->uv[i].uv);
-#else
-                               (void)em;
-#endif /* BMESH_TODO */
+
+                               l = BMIter_AtIndex(em->bm, BM_LOOPS_OF_FACE, element->face, element->tfindex);
+                               luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
+                               copy_v2_v2(luv->uv, sculptdata->uv[i].uv);
                        }
                }
        }
@@ -273,15 +273,15 @@ static void laplacian_relaxation_iteration_uv(BMEditMesh *em, UvSculptData *scul
                        sculptdata->uv[i].uv[1] = (1.0-strength)*sculptdata->uv[i].uv[1] + strength*tmp_uvdata[i].p[1];
 
                        for(element = sculptdata->uv[i].element; element; element = element->next){
-#if 0 /* BMESH_TODO */
-                               MTFace *mt;
+                               MLoopUV *luv;
+                               BMLoop *l;
+
                                if(element->separate && element != sculptdata->uv[i].element)
                                        break;
-                               mt = CustomData_em_get(&em->fdata, element->face->data, CD_MTFACE);
-                               copy_v2_v2(mt->uv[element->tfindex], sculptdata->uv[i].uv);
-#else
-                               (void)em;
-#endif /* BMESH_TODO */
+
+                               l = BMIter_AtIndex(em->bm, BM_LOOPS_OF_FACE, element->face, element->tfindex);
+                               luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
+                               copy_v2_v2(luv->uv, sculptdata->uv[i].uv);
                        }
                }
        }
@@ -349,13 +349,15 @@ static void uv_sculpt_stroke_apply(bContext *C, wmOperator *op, wmEvent *event,
                                sculptdata->uv[i].uv[1] -= strength*diff[1]*0.001;
 
                                for(element = sculptdata->uv[i].element; element; element = element->next){
-#if 0 /* BMESH_TODO*/
-                                       MTFace *mt;
+                                       MLoopUV *luv;
+                                       BMLoop *l;
+
                                        if(element->separate && element != sculptdata->uv[i].element)
                                                break;
-                                       mt = CustomData_em_get(&bm->fdata, element->face->data, CD_MTFACE);
-                                       copy_v2_v2(mt->uv[element->tfindex], sculptdata->uv[i].uv);
-#endif
+
+                                       l = BMIter_AtIndex(em->bm, BM_LOOPS_OF_FACE, element->face, element->tfindex);
+                                       luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
+                                       copy_v2_v2(luv->uv, sculptdata->uv[i].uv);
                                }
                        }
                }
@@ -389,13 +391,15 @@ static void uv_sculpt_stroke_apply(bContext *C, wmOperator *op, wmEvent *event,
                        sculptdata->uv[uvindex].uv[1] = sculptdata->initial_stroke->initialSelection[i].initial_uv[1] + strength*diff[1];
 
                        for(element = sculptdata->uv[uvindex].element; element; element = element->next){
-#if 0 /* BMESH_TODO */
-                               MTFace *mt;
+                               MLoopUV *luv;
+                               BMLoop *l;
+
                                if(element->separate && element != sculptdata->uv[uvindex].element)
                                        break;
-                               mt = CustomData_em_get(&em->fdata, element->face->data, CD_MTFACE);
-                               copy_v2_v2(mt->uv[element->tfindex], sculptdata->uv[uvindex].uv);
-#endif /* BMESH_TODO */
+
+                               l = BMIter_AtIndex(em->bm, BM_LOOPS_OF_FACE, element->face, element->tfindex);
+                               luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
+                               copy_v2_v2(luv->uv, sculptdata->uv[uvindex].uv);
                        }
                }
        }
@@ -471,11 +475,15 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, wmEvent
                int counter = 0, i;
                ARegion *ar= CTX_wm_region(C);
                float co[2];
-               EditFace *efa;
+               BMFace *efa;
+               MLoopUV *luv;
+               BMLoop *l;
+               BMIter iter, liter;
+
                UvEdge *edges;
                GHash *edgeHash;
                GHashIterator* ghi;
-               MTFace *mt;
+
                int do_island_optimization = !(ts->uv_sculpt_settings & UV_SCULPT_ALL_ISLANDS);
                int island_index = 0;
                /* Holds, for each UvElement in elementMap, a pointer to its unique uv.*/
@@ -562,29 +570,28 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, wmEvent
                                                        ;
                                                continue;
                                        }
-#if 0 /* BMESH_TODO */
+
                                        efa = element->face;
-                                       mt = CustomData_em_get(&bm->fdata, efa->data, CD_MTFACE);
+                                       l = BMIter_AtIndex(em->bm, BM_LOOPS_OF_FACE, element->face, element->tfindex);
+                                       luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
 
                                        counter++;
                                        data->uv[counter].element = element;
                                        data->uv[counter].flag = 0;
-                                       data->uv[counter].uv = mt->uv[element->tfindex];
-#else
-                                       (void)efa;
-                                       (void)mt;
-#endif /* BMESH_TODO */
+                                       data->uv[counter].uv = luv->uv;
                                }
                                /* pointer arithmetic to the rescue, as always :)*/
                                uniqueUv[element - data->elementMap->buf] = counter;
                        }
                }
 
-#if 0 /* BMESH_TODO */
+
                /* Now, on to generate our uv connectivity data */
-               for(efa = em->faces.first, counter = 0; efa; efa = efa->next){
-                       int nverts = efa->v4 ? 4 : 3;
-                       for(i = 0; i < nverts; i++){
+               counter = 0;
+               BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) {
+                       int nverts = efa->len;
+                       i = 0;
+                       BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) {
                                int offset1, itmp1 = get_uv_element_offset_from_face(data->elementMap, efa, i, island_index, do_island_optimization);
                                int offset2, itmp2 = get_uv_element_offset_from_face(data->elementMap, efa, (i+1)%nverts, island_index, do_island_optimization);
 
@@ -616,9 +623,9 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, wmEvent
                                        BLI_ghash_insert(edgeHash, &edges[counter], &edges[counter].flag);
                                }
                                counter++;
+                               i++;
                        }
                }
-#endif /* BMESH_TODO */
 
                MEM_freeN(uniqueUv);
 
@@ -659,7 +666,7 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, wmEvent
                }
 
                /* Allocate initial selection for grab tool */
-               if(data->tool){
+               if(data->tool == UV_SCULPT_TOOL_GRAB){
                        float radius, radius_root;
                        UvSculptData *sculptdata = (UvSculptData *)op->customdata;
                        SpaceImage *sima;
index 5c21fa6c1c1d827217d49a68048e0ce8e4cc86f8..264777c20edaea4b67ab8fa165684fa99f039ab9 100644 (file)
@@ -939,15 +939,12 @@ static UvMapVert *uv_vertex_map_get(UvVertMap *vmap, BMFace *efa, int a)
 
 UvElement *ED_get_uv_element(UvElementMap *map, BMFace *efa, int index)
 {
-       BMLoop *loop = efa->loops.first;
+       BMLoop *l;
        UvElement *element;
 
-       while (index >= 0) {
-               loop = loop->next;
-               index--;
-       }
+       l = BMIter_AtIndex(NULL, BM_LOOPS_OF_FACE, efa, index);
 
-       element = map->vert[BM_GetIndex(loop->v)];
+       element = map->vert[BM_GetIndex(l->v)];
 
        for(; element; element = element->next)
                if(element->face == efa)