=bmesh= build modifier works now, also made scanfill thread-safe
authorJoseph Eagar <joeedh@gmail.com>
Sat, 16 Apr 2011 23:58:49 +0000 (23:58 +0000)
committerJoseph Eagar <joeedh@gmail.com>
Sat, 16 Apr 2011 23:58:49 +0000 (23:58 +0000)
14 files changed:
source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/editderivedbmesh.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenlib/BLI_scanfill.h
source/blender/blenlib/BLI_threads.h
source/blender/blenlib/intern/scanfill.c
source/blender/blenlib/intern/threads.c
source/blender/bmesh/operators/mesh_conv.c
source/blender/editors/mesh/knifetool.c
source/blender/editors/uvedit/uvedit_unwrap_ops.c
source/blender/makesdna/DNA_modifier_types.h
source/blender/modifiers/intern/MOD_build.c
source/blender/modifiers/intern/MOD_displace.c
source/blender/windowmanager/intern/wm_gesture.c

index 1610b510dac844682b5069f9191532ab8bdfbe19..b314264829c5e72dc0c6144b8e9eb085f8eff47a 100644 (file)
@@ -946,6 +946,8 @@ void filldisplist(ListBase *dispbase, ListBase *to, int flipnormal)
                totvert= 0;
                nextcol= 0;
                
+               BLI_begin_edgefill();
+               
                dl= dispbase->first;
                while(dl) {
        
index e60179101de00fffb5bb0279983886e17ec440df..3db70d918b13c1df329418b44110a6f1e9e19b47 100644 (file)
@@ -182,6 +182,7 @@ static void BMEdit_RecalcTesselation_intern(BMEditMesh *tm)
                /*don't consider two-edged faces*/
                if (f->len < 3) continue;
                
+               BLI_begin_edgefill();
                /*scanfill time*/
                l = BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f);
                for (j=0; l; l=BMIter_Step(&liter), j++) {
index 85da641fa23b61f5b4892e0832abb00810e3e2f8..f424f9b580c568482504a44f9ce97b0650eb25fd 100644 (file)
@@ -2265,7 +2265,8 @@ int mesh_recalcTesselation(CustomData *fdata,
        for (i=0; i<totpoly; i++, mp++) {
                if (mp->totloop > 2) {          
                        ml = mloop + mp->loopstart;
-
+                       
+                       BLI_begin_edgefill();
                        firstv = NULL;
                        lastv = NULL;
                        for (j=0; j<mp->totloop; j++, ml++) {
index e2f102c20eb6d52ac51bb511d512d0362a564cb8..b0ed92711329f213ecf50edc90e7e492822e4139 100644 (file)
@@ -53,6 +53,8 @@ extern "C" {
 /* scanfill.c: used in displist only... */
 struct EditVert *BLI_addfillvert(float *vec);
 struct EditEdge *BLI_addfilledge(struct EditVert *v1, struct EditVert *v2);
+
+int BLI_begin_edgefill(void);
 int BLI_edgefill(int mat_nr);
 void BLI_end_edgefill(void);
 
index 5bf5423d312c548fc0368b8672f793786282ab94..e0959b88a5f8cf963b52d4e400bd6d8d12a7c2fd 100644 (file)
@@ -71,6 +71,7 @@ int           BLI_system_thread_count(void); /* gets the number of threads the system can
 #define LOCK_CUSTOM1   3
 #define LOCK_RCACHE            4
 #define LOCK_OPENGL            5
+#define LOCK_SCANFILL  6
 
 void   BLI_lock_thread(int type);
 void   BLI_unlock_thread(int type);
index 2ad3d4e930e3660cb642d59de995b82820b04f23..5894597ed477686abae36b0010d277c7bafda371 100644 (file)
@@ -44,6 +44,7 @@
 #include "BLI_math.h"
 #include "BLI_scanfill.h"
 #include "BLI_utildefines.h"
+#include "BLI_threads.h"
 
 /* callbacks for errors and interrupts and some goo */
 static void (*BLI_localErrorCallBack)(const char*) = NULL;
@@ -202,6 +203,8 @@ void BLI_end_edgefill(void)
        fillvertbase.first= fillvertbase.last= 0;
        filledgebase.first= filledgebase.last= 0;
        fillfacebase.first= fillfacebase.last= 0;
+       
+       BLI_unlock_thread(LOCK_SCANFILL);       
 }
 
 /* ****  FILL ROUTINES *************************** */
@@ -765,6 +768,12 @@ static void scanfill(PolyFill *pf, int mat_nr)
 }
 
 
+int BLI_begin_edgefill(void)
+{
+       BLI_lock_thread(LOCK_SCANFILL);
+
+       return 1;
+}
 
 int BLI_edgefill(int mat_nr)
 {
@@ -804,7 +813,7 @@ int BLI_edgefill(int mat_nr)
 
                eve = fillvertbase.first;
                
-               if (1) { //BMESH_TODO) {
+               if (1 && eve->next && eve->next->next && eve->next->next->next) { //BMESH_TODO) {
                        /*use shortest diagonal for quad*/
                        sub_v3_v3v3(vec1, eve->co, eve->next->next->co);
                        sub_v3_v3v3(vec2, eve->next->co, eve->next->next->next->co);
index 7b59a7905aa290da3f185a7165d9aa04f5d32dfb..937e4ee06db16fa1f5d617d8fafd49970bd37c2a 100644 (file)
@@ -114,6 +114,7 @@ static pthread_mutex_t _viewer_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t _custom1_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t _rcache_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t _opengl_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t _scanfill_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_t mainid;
 static int thread_levels= 0;   /* threads can be invoked inside threads */
 
@@ -349,6 +350,8 @@ void BLI_lock_thread(int type)
                pthread_mutex_lock(&_rcache_lock);
        else if (type==LOCK_OPENGL)
                pthread_mutex_lock(&_opengl_lock);
+       else if (type == LOCK_SCANFILL) 
+               pthread_mutex_lock(&_scanfill_lock);
 }
 
 void BLI_unlock_thread(int type)
@@ -365,6 +368,8 @@ void BLI_unlock_thread(int type)
                pthread_mutex_unlock(&_rcache_lock);
        else if(type==LOCK_OPENGL)
                pthread_mutex_unlock(&_opengl_lock);
+       else if(type == LOCK_SCANFILL)
+               pthread_mutex_unlock(&_scanfill_lock);
 }
 
 /* Mutex Locks */
index fc9ecfadbe2c755f48c8a748b670182f99884e4e..0e8102e538cbcfd013d45ae8aab94296159550c6 100644 (file)
@@ -431,6 +431,7 @@ void bmesh_to_mesh_exec(BMesh *bm, BMOperator *op) {
                        EditVert *eve, *lasteve = NULL, *firsteve = NULL;
                        EditFace *efa;
                        
+                       BLI_begin_edgefill();
                        i = 0;
                        BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, f) {
                                eve = BLI_addfillvert(l->v->co);
@@ -478,6 +479,7 @@ void bmesh_to_mesh_exec(BMesh *bm, BMOperator *op) {
                        EditFace *efa;
                        BMLoop *ls[3];
                        
+                       BLI_begin_edgefill();
                        BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, f) {
                                eve = BLI_addfillvert(l->v->co);
                                eve->tmp.p = l;
index 5c36d548bff79f7faa1e867d147a5b4b06fbd866..1632e2cd97e3fbe87938bd5a03f93c4f6997c921 100755 (executable)
@@ -1451,6 +1451,8 @@ void knifenet_fill_faces(knifetool_opdata *kcd)
                if (face_nets[i].first)
                        BMO_SetFlag(bm, f, DEL);
                
+               BLI_begin_edgefill();
+               
                for (entry=face_nets[i].first; entry; entry=entry->next) {
                        if (!BLI_smallhash_haskey(hash, (intptr_t)entry->kfe->v1)) {
                                eve = BLI_addfillvert(entry->kfe->v1->v->co);
index 56fd04e8360f32a274bae1de9ea8010cf6436f32..3ff12d715838f94c91e3e3abe48565578440c24c 100644 (file)
@@ -207,6 +207,8 @@ static ParamHandle *construct_param_handle(Scene *scene, BMEditMesh *em,
                key = (ParamKey)efa;
 
                /*scanfill time!*/
+               BLI_begin_edgefill();
+               
                firstv = lastv = NULL;
                BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) {
                        int i;
index 62f14d4b8fe00b5b3cb3fc738870fe375cd81e8b..d0661cea8bc672d1c9de9b978367a63262fa4b0f 100644 (file)
@@ -311,6 +311,7 @@ enum {
        MOD_DISP_DIR_Z,
        MOD_DISP_DIR_NOR,
        MOD_DISP_DIR_RGB_XYZ,
+       MOD_DISP_TANGENT,
 };
 
 /* DisplaceModifierData->texmapping */
index b2817aa11eae8c6722a009180ad8b2f9614728de..7cb9c1b7c19089844bd20a10aae6fff4d620ebb5 100644 (file)
@@ -85,10 +85,12 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
        DerivedMesh *dm = derivedData;
        DerivedMesh *result;
        BuildModifierData *bmd = (BuildModifierData*) md;
-       int i;
-       int numFaces, numEdges;
+       int i, j, k;
+       int numFaces, numEdges, numLoops;
        int *vertMap, *edgeMap, *faceMap;
        float frac;
+       MPoly *mpoly, *mpolys, *mpolyd;
+       MLoop *mld, *mloops, *mls, *mloopd;
        GHashIterator *hashIter;
        /* maps vert indices in old mesh to indices in new mesh */
        GHash *vertHash = BLI_ghash_new(BLI_ghashutil_inthash,
@@ -96,11 +98,18 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
        /* maps edge indices in new mesh to indices in old mesh */
        GHash *edgeHash = BLI_ghash_new(BLI_ghashutil_inthash,
                                        BLI_ghashutil_intcmp, "build ed apply gh");
+       GHash *edgeHash2 = BLI_ghash_new(BLI_ghashutil_inthash,
+                                       BLI_ghashutil_intcmp, "build ed apply gh");
 
        const int maxVerts= dm->getNumVerts(dm);
        const int maxEdges= dm->getNumEdges(dm);
-       const int maxFaces= dm->getNumTessFaces(dm);
-
+       const int maxFaces= dm->getNumFaces(dm);
+       
+       if (!CDDM_Check(dm)) {
+               result = CDDM_copy(dm, 0);
+               dm = result;
+       }
+       
        vertMap = MEM_callocN(sizeof(*vertMap) * maxVerts, "build modifier vertMap");
        for(i = 0; i < maxVerts; ++i) vertMap[i] = i;
        edgeMap = MEM_callocN(sizeof(*edgeMap) * maxEdges, "build modifier edgeMap");
@@ -116,11 +125,15 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
        }
        CLAMP(frac, 0.0f, 1.0f);
 
-       numFaces = dm->getNumTessFaces(dm) * frac;
+       numFaces = dm->getNumFaces(dm) * frac;
        numEdges = dm->getNumEdges(dm) * frac;
 
        /* if there's at least one face, build based on faces */
        if(numFaces) {
+               MPoly *mpoly, *mp;
+               MLoop *ml, *mloop;
+               MEdge *medge;
+               
                if(bmd->randomize)
                        BLI_array_randomize(faceMap, sizeof(*faceMap),
                                                maxFaces, bmd->seed);
@@ -128,37 +141,41 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
                /* get the set of all vert indices that will be in the final mesh,
                * mapped to the new indices
                */
+               numLoops = 0;
+               mpoly = CDDM_get_polys(dm);
+               mloop = CDDM_get_loops(dm);
                for(i = 0; i < numFaces; ++i) {
-                       MFace mf;
-                       dm->getTessFace(dm, faceMap[i], &mf);
-
-                       if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v1)))
-                               BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(mf.v1),
-                                       SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
-                       if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v2)))
-                               BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(mf.v2),
-                                       SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
-                       if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v3)))
-                               BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(mf.v3),
-                                       SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
-                       if(mf.v4 && !BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v4)))
-                               BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(mf.v4),
-                                       SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+                       mp = mpoly + faceMap[i];
+                       ml = mloop + mp->loopstart;
+
+                       for (j=0; j<mp->totloop; j++, ml++) {
+                               if (!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(ml->v)))
+                                       BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(ml->v), 
+                                               SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+                       }
+                       
+                       numLoops += mp->totloop;
                }
 
                /* get the set of edges that will be in the new mesh (i.e. all edges
                * that have both verts in the new mesh)
                */
+               medge = CDDM_get_edges(dm);
                for(i = 0; i < maxEdges; ++i) {
-                       MEdge me;
-                       dm->getEdge(dm, i, &me);
-
-                       if(BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v1))
-                                               && BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v2)))
-                               BLI_ghash_insert(edgeHash,
-                                       SET_INT_IN_POINTER(BLI_ghash_size(edgeHash)), SET_INT_IN_POINTER(i));
+                       MEdge *me = medge + i;
+
+                       if(BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me->v1))
+                                               && BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me->v2)))
+                       {
+                               j = BLI_ghash_size(edgeHash);
+                               
+                               BLI_ghash_insert(edgeHash, SET_INT_IN_POINTER(j), SET_INT_IN_POINTER(i));
+                               BLI_ghash_insert(edgeHash2, SET_INT_IN_POINTER(i), SET_INT_IN_POINTER(j));
+                       }
                }
        } else if(numEdges) {
+               MEdge *medge, *me;
+               
                if(bmd->randomize)
                        BLI_array_randomize(edgeMap, sizeof(*edgeMap),
                                                maxEdges, bmd->seed);
@@ -166,26 +183,27 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
                /* get the set of all vert indices that will be in the final mesh,
                * mapped to the new indices
                */
+               medge = CDDM_get_edges(dm);
                for(i = 0; i < numEdges; ++i) {
-                       MEdge me;
-                       dm->getEdge(dm, edgeMap[i], &me);
+                       me = medge + edgeMap[i];
 
-                       if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v1)))
-                               BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(me.v1),
+                       if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me->v1)))
+                               BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(me->v1),
                                        SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
-                       if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v2)))
-                               BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(me.v2),
+                       if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me->v2)))
+                               BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(me->v2),
                                        SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
                }
 
                /* get the set of edges that will be in the new mesh
                */
                for(i = 0; i < numEdges; ++i) {
-                       MEdge me;
-                       dm->getEdge(dm, edgeMap[i], &me);
-
-                       BLI_ghash_insert(edgeHash, SET_INT_IN_POINTER(BLI_ghash_size(edgeHash)),
+                       j = BLI_ghash_size(edgeHash);
+                       
+                       BLI_ghash_insert(edgeHash, SET_INT_IN_POINTER(j),
                                         SET_INT_IN_POINTER(edgeMap[i]));
+                       BLI_ghash_insert(edgeHash2,  SET_INT_IN_POINTER(edgeMap[i]),
+                                                        SET_INT_IN_POINTER(j));
                }
        } else {
                int numVerts = dm->getNumVerts(dm) * frac;
@@ -205,7 +223,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
        * the mesh
        */
        result = CDDM_from_template(dm, BLI_ghash_size(vertHash),
-                                       BLI_ghash_size(edgeHash), numFaces, 0, 0);
+                                       BLI_ghash_size(edgeHash), 0, numLoops, numFaces);
 
        /* copy the vertices across */
        for(    hashIter = BLI_ghashIterator_new(vertHash);
@@ -241,38 +259,48 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
                *dest = source;
        }
 
+       mpolys = CDDM_get_polys(dm);
+       mpolyd = CDDM_get_polys(result);
+       mloops = CDDM_get_loops(dm);
+       mloopd = mld = CDDM_get_loops(result);
+       
        /* copy the faces across, remapping indices */
+       k = 0;
        for(i = 0; i < numFaces; ++i) {
-               MFace source;
-               MFace *dest;
-               int orig_v4;
-               
-               dm->getTessFace(dm, faceMap[i], &source);
-               dest = CDDM_get_tessface(result, i);
-               
-               orig_v4 = source.v4;
-               
-               source.v1 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v1)));
-               source.v2 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v2)));
-               source.v3 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v3)));
-               if(source.v4)
-                       source.v4 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v4)));
+               MPoly *source;
+               MPoly *dest;
                
+               source = mpolys + faceMap[i];
+               dest = mpolyd + i;
                DM_copy_face_data(dm, result, faceMap[i], i, 1);
-               *dest = source;
                
-               test_index_face(dest, &result->faceData, i, (orig_v4 ? 4 : 3));
+               *dest = *source;
+               dest->loopstart = k;
+               
+               DM_copy_loop_data(dm, result, source->loopstart, dest->loopstart, dest->totloop);
+
+               mls = mloops + source->loopstart;
+               for (j=0; j<source->totloop; j++, k++, mls++, mld++) {
+                       mld->v = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(mls->v)));
+                       mld->e = GET_INT_FROM_POINTER(BLI_ghash_lookup(edgeHash2, SET_INT_IN_POINTER(mls->e)));
+               }
        }
 
        CDDM_calc_normals(result);
        
        BLI_ghash_free(vertHash, NULL, NULL);
        BLI_ghash_free(edgeHash, NULL, NULL);
+       BLI_ghash_free(edgeHash2, NULL, NULL);
        
        MEM_freeN(vertMap);
        MEM_freeN(edgeMap);
        MEM_freeN(faceMap);
        
+       if (dm != derivedData) {
+               dm->needsFree = 1;
+               dm->release(dm);
+       }
+       
        return result;
 }
 
index 3ac615d2fc77fe7c3f8481596d76dfb8756bd419..deec5a44da80fa10202139bbbe765a7fe96c037d 100644 (file)
@@ -270,7 +270,8 @@ static void displaceModifier_do(
        tex_co = MEM_callocN(sizeof(*tex_co) * numVerts,
                                 "displaceModifier_do tex_co");
        get_texture_coords(dmd, ob, dm, vertexCos, tex_co, numVerts);
-
+       
+       
        for(i = 0; i < numVerts; ++i) {
                TexResult texres;
                float delta = 0, strength = dmd->strength;
index de4afa794487ba32ae703e4ef21c517ef1643c42..5ce7a3a0328a3a9bd6ee2dd4d3b6d3cf1beccffd 100644 (file)
@@ -237,6 +237,7 @@ static void draw_filled_lasso(wmGesture *gt)
        short *lasso= (short *)gt->customdata;
        int i;
        
+       BLI_begin_edgefill();
        for (i=0; i<gt->points; i++, lasso+=2) {
                float co[3];