diff options
author | Joseph Eagar <joeedh@gmail.com> | 2011-04-17 03:58:49 +0400 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2011-04-17 03:58:49 +0400 |
commit | 489eaaa46d35d60feec16166cd6ba52674e945dd (patch) | |
tree | fca30982a61bf400e5ac6fd56c1e69fe92915135 /source | |
parent | a141cea6febe753d8d6109611581f9de34458739 (diff) |
=bmesh= build modifier works now, also made scanfill thread-safe
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/displist.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/editderivedbmesh.c | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 3 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_scanfill.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_threads.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/scanfill.c | 11 | ||||
-rw-r--r-- | source/blender/blenlib/intern/threads.c | 5 | ||||
-rw-r--r-- | source/blender/bmesh/operators/mesh_conv.c | 2 | ||||
-rwxr-xr-x | source/blender/editors/mesh/knifetool.c | 2 | ||||
-rw-r--r-- | source/blender/editors/uvedit/uvedit_unwrap_ops.c | 2 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_modifier_types.h | 1 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_build.c | 136 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_displace.c | 3 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_gesture.c | 1 |
14 files changed, 115 insertions, 57 deletions
diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index 1610b510dac..b314264829c 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -946,6 +946,8 @@ void filldisplist(ListBase *dispbase, ListBase *to, int flipnormal) totvert= 0; nextcol= 0; + BLI_begin_edgefill(); + dl= dispbase->first; while(dl) { diff --git a/source/blender/blenkernel/intern/editderivedbmesh.c b/source/blender/blenkernel/intern/editderivedbmesh.c index e60179101de..3db70d918b1 100644 --- a/source/blender/blenkernel/intern/editderivedbmesh.c +++ b/source/blender/blenkernel/intern/editderivedbmesh.c @@ -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++) { diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 85da641fa23..f424f9b580c 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -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++) { diff --git a/source/blender/blenlib/BLI_scanfill.h b/source/blender/blenlib/BLI_scanfill.h index e2f102c20eb..b0ed9271132 100644 --- a/source/blender/blenlib/BLI_scanfill.h +++ b/source/blender/blenlib/BLI_scanfill.h @@ -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); diff --git a/source/blender/blenlib/BLI_threads.h b/source/blender/blenlib/BLI_threads.h index 5bf5423d312..e0959b88a5f 100644 --- a/source/blender/blenlib/BLI_threads.h +++ b/source/blender/blenlib/BLI_threads.h @@ -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); diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c index 2ad3d4e930e..5894597ed47 100644 --- a/source/blender/blenlib/intern/scanfill.c +++ b/source/blender/blenlib/intern/scanfill.c @@ -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); diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c index 7b59a7905aa..937e4ee06db 100644 --- a/source/blender/blenlib/intern/threads.c +++ b/source/blender/blenlib/intern/threads.c @@ -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 */ diff --git a/source/blender/bmesh/operators/mesh_conv.c b/source/blender/bmesh/operators/mesh_conv.c index fc9ecfadbe2..0e8102e538c 100644 --- a/source/blender/bmesh/operators/mesh_conv.c +++ b/source/blender/bmesh/operators/mesh_conv.c @@ -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; diff --git a/source/blender/editors/mesh/knifetool.c b/source/blender/editors/mesh/knifetool.c index 5c36d548bff..1632e2cd97e 100755 --- a/source/blender/editors/mesh/knifetool.c +++ b/source/blender/editors/mesh/knifetool.c @@ -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); diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c index 56fd04e8360..3ff12d71583 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c @@ -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; diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 62f14d4b8fe..d0661cea8bc 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -311,6 +311,7 @@ enum { MOD_DISP_DIR_Z, MOD_DISP_DIR_NOR, MOD_DISP_DIR_RGB_XYZ, + MOD_DISP_TANGENT, }; /* DisplaceModifierData->texmapping */ diff --git a/source/blender/modifiers/intern/MOD_build.c b/source/blender/modifiers/intern/MOD_build.c index b2817aa11ea..7cb9c1b7c19 100644 --- a/source/blender/modifiers/intern/MOD_build.c +++ b/source/blender/modifiers/intern/MOD_build.c @@ -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; } diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c index 3ac615d2fc7..deec5a44da8 100644 --- a/source/blender/modifiers/intern/MOD_displace.c +++ b/source/blender/modifiers/intern/MOD_displace.c @@ -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; diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c index de4afa79448..5ce7a3a0328 100644 --- a/source/blender/windowmanager/intern/wm_gesture.c +++ b/source/blender/windowmanager/intern/wm_gesture.c @@ -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]; |