=bmesh= build modifier works now, also made scanfill thread-safe
This commit is contained in:
@@ -946,6 +946,8 @@ void filldisplist(ListBase *dispbase, ListBase *to, int flipnormal)
|
||||
totvert= 0;
|
||||
nextcol= 0;
|
||||
|
||||
BLI_begin_edgefill();
|
||||
|
||||
dl= dispbase->first;
|
||||
while(dl) {
|
||||
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -311,6 +311,7 @@ enum {
|
||||
MOD_DISP_DIR_Z,
|
||||
MOD_DISP_DIR_NOR,
|
||||
MOD_DISP_DIR_RGB_XYZ,
|
||||
MOD_DISP_TANGENT,
|
||||
};
|
||||
|
||||
/* DisplaceModifierData->texmapping */
|
||||
|
||||
@@ -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);
|
||||
mp = mpoly + faceMap[i];
|
||||
ml = mloop + mp->loopstart;
|
||||
|
||||
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)));
|
||||
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);
|
||||
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)))
|
||||
BLI_ghash_insert(edgeHash,
|
||||
SET_INT_IN_POINTER(BLI_ghash_size(edgeHash)), SET_INT_IN_POINTER(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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user