Revision: 18868 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18868 Author: joeedh Date: 2009-02-08 18:01:28 +0100 (Sun, 08 Feb 2009)
Log Message: ----------- alt-ctrl leftmouse (e.g. current knife) now uses bmesh edge subdivide! wa-hoo! basically I had to add some slots to the subdivide operator so it could accept custom percentags for splitting edges. also put some commonly passed-around paramters into a struct, so i don't have to constantly keep changing a dozen function signatures Modified Paths: -------------- branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c branches/bmesh/blender/source/blender/bmesh/operators/triangulateop.c branches/bmesh/blender/source/blender/editors/mesh/editmesh_loop.c branches/bmesh/blender/source/blender/editors/mesh/mesh_ops.c Modified: branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h =================================================================== --- branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h 2009-02-08 14:56:43 UTC (rev 18867) +++ branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h 2009-02-08 17:01:28 UTC (rev 18868) @@ -62,6 +62,7 @@ void BMO_Set_Float(struct BMOperator *op, int slotcode, float f); void BMO_Set_Int(struct BMOperator *op, int slotcode, int i); void BMO_Set_PntBuf(struct BMOperator *op, int slotcode, void *p, int len); +void BMO_Set_FltBuf(BMOperator *op, int slotcode, float *p, int len); void BMO_Set_Pnt(struct BMOperator *op, int slotcode, void *p); void BMO_Set_Vec(struct BMOperator *op, int slotcode, float *vec); void BMO_SetFlag(struct BMesh *bm, void *element, int flag); @@ -161,7 +162,7 @@ BMOP_ESUBDIVIDE_CUSTOMFILL_FACES, BMOP_ESUBDIVIDE_CUSTOMFILL_PATTERNS, - BMOP_ESUBDIVIDE_PERCENT_VERTS, + BMOP_ESUBDIVIDE_PERCENT_EDGES, BMOP_ESUBDIVIDE_PERCENT_VALUES, BMOP_ESUBDIVIDE_TOTSLOT, Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c =================================================================== --- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c 2009-02-08 14:56:43 UTC (rev 18867) +++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c 2009-02-08 17:01:28 UTC (rev 18868) @@ -42,7 +42,7 @@ BMOP_OPSLOT_PNT_BUF, BMOP_OPSLOT_PNT_BUF, BMOP_OPSLOT_PNT_BUF, - BMOP_OPSLOT_FLT}, + BMOP_OPSLOT_FLT_BUF}, esubdivide_exec, BMOP_ESUBDIVIDE_TOTSLOT, 0 Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c =================================================================== --- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c 2009-02-08 14:56:43 UTC (rev 18867) +++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c 2009-02-08 17:01:28 UTC (rev 18868) @@ -212,6 +212,15 @@ op->slots[slotcode].len = len; } +void BMO_Set_FltBuf(BMOperator *op, int slotcode, float *p, int len) +{ + if( !(op->slots[slotcode].slottype == BMOP_OPSLOT_FLT_BUF) ) + return; + + op->slots[slotcode].data.p = p; + op->slots[slotcode].len = len; +} + void BMO_Set_Pnt(BMOperator *op, int slotcode, void *p) { if( !(op->slots[slotcode].slottype == BMOP_OPSLOT_PNT) ) Modified: branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c =================================================================== --- branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c 2009-02-08 14:56:43 UTC (rev 18867) +++ branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c 2009-02-08 17:01:28 UTC (rev 18868) @@ -21,6 +21,8 @@ #define SUBD_SPLIT 1 +#define EDGE_PERCENT 2 + /*I don't think new faces are flagged, currently, but better safe than sorry.*/ #define FACE_NEW 2 @@ -48,12 +50,12 @@ */ /* calculates offset for co, based on fractal, sphere or smooth settings */ -static void alter_co(float *co, BMEdge *edge, float rad, int flag, float perc, +static void alter_co(float *co, BMEdge *edge, subdparams *params, float perc, BMVert *vsta, BMVert *vend) { float vec1[3], fac; - if(flag & B_SMOOTH) { + if(params->flag & B_SMOOTH) { /* we calculate an offset vector vec1[], to be added to *co */ float len, fac, nor[3], nor1[3], nor2[3]; @@ -77,23 +79,23 @@ vec1[1]+= fac*nor2[1]; vec1[2]+= fac*nor2[2]; - vec1[0]*= rad*len; - vec1[1]*= rad*len; - vec1[2]*= rad*len; + vec1[0]*= params->rad*len; + vec1[1]*= params->rad*len; + vec1[2]*= params->rad*len; co[0] += vec1[0]; co[1] += vec1[1]; co[2] += vec1[2]; } else { - if(rad > 0.0) { /* subdivide sphere */ + if(params->rad > 0.0) { /* subdivide sphere */ Normalize(co); - co[0]*= rad; - co[1]*= rad; - co[2]*= rad; + co[0]*= params->rad; + co[1]*= params->rad; + co[2]*= params->rad; } - else if(rad< 0.0) { /* fractal subdivide */ - fac= rad* VecLenf(vsta->co, vend->co); + else if(params->rad< 0.0) { /* fractal subdivide */ + fac= params->rad* VecLenf(vsta->co, vend->co); vec1[0]= fac*(float)(0.5-BLI_drand()); vec1[1]= fac*(float)(0.5-BLI_drand()); vec1[2]= fac*(float)(0.5-BLI_drand()); @@ -106,18 +108,18 @@ /* assumes in the edge is the correct interpolated vertices already */ /* percent defines the interpolation, rad and flag are for special options */ /* results in new vertex with correct coordinate, vertex normal and weight group info */ -static BMVert *bm_subdivide_edge_addvert(BMesh *bm, BMEdge *edge, float rad, - int flag, float percent, BMEdge **out, - BMVert *vsta, BMVert *vend) +static BMVert *bm_subdivide_edge_addvert(BMesh *bm, BMEdge *edge, + subdparams *params, float percent, + BMEdge **out,BMVert *vsta,BMVert *vend) { BMVert *ev; // float co[3]; ev = BM_Split_Edge(bm, edge->v1, edge, out, percent, 1); - if (flag & SELTYPE_INNER) BM_Select_Vert(bm, ev, 1); + if (params->flag & SELTYPE_INNER) BM_Select_Vert(bm, ev, 1); /* offset for smooth or sphere or fractal */ - alter_co(ev->co, edge, rad, flag, percent, vsta, vend); + alter_co(ev->co, edge, params, percent, vsta, vend); #if 0 //TODO /* clip if needed by mirror modifier */ @@ -138,48 +140,33 @@ } static BMVert *subdivideedgenum(BMesh *bm, BMEdge *edge, - int curpoint, int totpoint, float rad, - int flag, BMEdge **newe, - BMVert *vsta, BMVert *vend) + int curpoint, int totpoint, subdparams *params, + BMEdge **newe, BMVert *vsta, BMVert *vend) { BMVert *ev; float percent; - if (flag & (B_PERCENTSUBD) && totpoint == 1) - /*I guess the idea is vertices store what - percent to use?*/ - //percent=(float)(edge->tmp.l)/32768.0f; - percent= 1.0; //edge->tmp.fp; + if (BMO_TestFlag(bm, edge, EDGE_PERCENT) && totpoint == 1) + percent= *((float*)BLI_ghash_lookup(params->percenthash,edge)); else { percent= 1.0f/(float)(totpoint+1-curpoint); } - /*{ - float co[3], co2[3]; - VecSubf(co, edge->v2->co, edge->v1->co); - VecMulf(co, 1.0f/(float)(totpoint+1-curpoint)); - VecAddf(co2, edge->v1->co, co); -*/ - ev= bm_subdivide_edge_addvert(bm, edge, rad, flag, percent, - newe, vsta, vend); - -/* VECCOPY(ev->co, co2); - } -*/ + ev= bm_subdivide_edge_addvert(bm, edge, params, percent, + newe, vsta, vend); return ev; } -static void bm_subdivide_multicut(BMesh *bm, BMEdge *edge, float rad, - int flag, int numcuts, +static void bm_subdivide_multicut(BMesh *bm, BMEdge *edge, subdparams *params, BMVert *vsta, BMVert *vend) { BMEdge *eed = edge, *newe; BMVert *v; - int i; + int i, numcuts = params->numcuts; for(i=0;i<numcuts;i++) { - v = subdivideedgenum(bm, eed, i, numcuts, rad, - flag, &newe, vsta, vend); + v = subdivideedgenum(bm, eed, i, params->numcuts, params, + &newe, vsta, vend); BMO_SetFlag(bm, v, SUBD_SPLIT); BMO_SetFlag(bm, eed, SUBD_SPLIT); } @@ -199,28 +186,28 @@ v4---v0---v1 */ -static void q_1edge_split(BMesh *bm, BMFace *face, BMVert **vlist, int numcuts, - int flag, float rad) { +static void q_1edge_split(BMesh *bm, BMFace *face, + BMVert **verts, subdparams *params) { BMFace *nf; - int i, add; + int i, add, numcuts = params->numcuts; /*if it's odd, the middle face is a quad, otherwise it's a triangle*/ if (numcuts % 2==0) { add = 2; for (i=0; i<numcuts; i++) { if (i == numcuts/2) add -= 1; - BM_Connect_Verts(bm, vlist[i], vlist[numcuts+add], + BM_Connect_Verts(bm, verts[i], verts[numcuts+add], &nf); } } else { add = 2; for (i=0; i<numcuts; i++) { - BM_Connect_Verts(bm, vlist[i], vlist[numcuts+add], + BM_Connect_Verts(bm, verts[i], verts[numcuts+add], &nf); if (i == numcuts/2) { add -= 1; - BM_Connect_Verts(bm, vlist[i], - vlist[numcuts+add], + BM_Connect_Verts(bm, verts[i], + verts[numcuts+add], &nf); } } @@ -246,13 +233,14 @@ */ -static void q_2edge_op_split(BMesh *bm, BMFace *face, BMVert **vlist, - int numcuts, int flag, float rad) { +static void q_2edge_op_split(BMesh *bm, BMFace *face, BMVert **verts, + subdparams *params) +{ BMFace *nf; - int i; + int i, numcuts = params->numcuts; for (i=0; i<numcuts; i++) { - BM_Connect_Verts(bm, vlist[i],vlist[(numcuts-i-1)+numcuts+2], + BM_Connect_Verts(bm, verts[i],verts[(numcuts-i-1)+numcuts+2], &nf); } } @@ -272,16 +260,17 @@ v7-v0--v1-v2 */ -static void q_2edge_split(BMesh *bm, BMFace *face, BMVert **vlist, - int numcuts, int flag, float rad) { +static void q_2edge_split(BMesh *bm, BMFace *face, BMVert **verts, + subdparams *params) +{ BMFace *nf; - int i; + int i, numcuts = params->numcuts; for (i=0; i<numcuts; i++) { - BM_Connect_Verts(bm, vlist[i], vlist[numcuts+(numcuts-i)], + BM_Connect_Verts(bm, verts[i], verts[numcuts+(numcuts-i)], &nf); } - BM_Connect_Verts(bm, vlist[numcuts*2+3], vlist[numcuts*2+1], &nf); + BM_Connect_Verts(bm, verts[numcuts*2+3], verts[numcuts*2+1], &nf); } subdpattern q_2edge = { @@ -300,25 +289,26 @@ v9-v0--v1-v2 */ -static void q_3edge_split(BMesh *bm, BMFace *face, BMVert **vlist, - int numcuts, int flag, float rad) { +static void q_3edge_split(BMesh *bm, BMFace *face, BMVert **verts, + subdparams *params) +{ BMFace *nf; - int i, add=0; + int i, add=0, numcuts = params->numcuts; for (i=0; i<numcuts; i++) { if (i == numcuts/2) { if (numcuts % 2 != 0) { - BM_Connect_Verts(bm, vlist[numcuts-i-1+add], - vlist[i+numcuts+1], &nf); + BM_Connect_Verts(bm, verts[numcuts-i-1+add], + verts[i+numcuts+1], &nf); } add = numcuts*2+2; } - BM_Connect_Verts(bm, vlist[numcuts-i-1+add], - vlist[i+numcuts+1], &nf); + BM_Connect_Verts(bm, verts[numcuts-i-1+add], + verts[i+numcuts+1], &nf); } for (i=0; i<numcuts/2+1; i++) { - BM_Connect_Verts(bm, vlist[i],vlist[(numcuts-i)+numcuts*2+1], + BM_Connect_Verts(bm, verts[i],verts[(numcuts-i)+numcuts*2+1], &nf); } } @@ -340,27 +330,30 @@ it goes from bottom up */ -static void q_4edge_split(BMesh *bm, BMFace *face, BMVert **vlist, int numcuts, - int flag, float rad) { @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs