code cleanup: bmesh subdivide code - BM_mesh_esubdivideflag() & "esubd" bmesh operato...
authorCampbell Barton <ideasman42@gmail.com>
Mon, 23 Apr 2012 03:43:02 +0000 (03:43 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 23 Apr 2012 03:43:02 +0000 (03:43 +0000)
since we will eventually have python bmesh operator access better expose this as multiple booleans.

remove remaining editbutflag's

source/blender/bmesh/intern/bmesh_opdefines.c
source/blender/bmesh/intern/bmesh_operator_api.h
source/blender/bmesh/intern/bmesh_operators.h
source/blender/bmesh/operators/bmo_primitive.c
source/blender/bmesh/operators/bmo_subdivide.c
source/blender/bmesh/operators/bmo_subdivide.h
source/blender/editors/include/ED_mesh.h
source/blender/editors/mesh/editmesh_loopcut.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/mesh/mesh_intern.h

index f850f6aa46af6b8a6c630ce8c5509ba3be81d616..4b5c67c86715ba054b0e312bde9540b47cce1780 100644 (file)
@@ -694,10 +694,9 @@ static BMOpDefine bmo_triangulate_def = {
 static BMOpDefine bmo_esubd_def = {
        "esubd",
        {{BMO_OP_SLOT_ELEMENT_BUF, "edges"},
-        {BMO_OP_SLOT_INT, "numcuts"},
         {BMO_OP_SLOT_FLT, "smooth"},
         {BMO_OP_SLOT_FLT, "fractal"},
-        {BMO_OP_SLOT_INT, "beauty"},
+        {BMO_OP_SLOT_INT, "numcuts"},
         {BMO_OP_SLOT_INT, "seed"},
         {BMO_OP_SLOT_MAPPING, "custompatterns"},
         {BMO_OP_SLOT_MAPPING, "edgepercents"},
@@ -707,9 +706,10 @@ static BMOpDefine bmo_esubd_def = {
         {BMO_OP_SLOT_ELEMENT_BUF, "outsplit"},
         {BMO_OP_SLOT_ELEMENT_BUF, "geomout"}, /* contains all output geometr */
 
-        {BMO_OP_SLOT_INT,  "quadcornertype"}, //quad corner type, see bmesh_operators.h
-        {BMO_OP_SLOT_BOOL, "gridfill"}, //fill in fully-selected faces with a grid
-        {BMO_OP_SLOT_BOOL, "singleedge"}, //tessellate the case of one edge selected in a quad or triangle
+        {BMO_OP_SLOT_INT,  "quadcornertype"}, /* quad corner type, see bmesh_operators.h */
+        {BMO_OP_SLOT_BOOL, "use_gridfill"},   /* fill in fully-selected faces with a grid */
+        {BMO_OP_SLOT_BOOL, "use_singleedge"}, /* tessellate the case of one edge selected in a quad or triangle */
+        {BMO_OP_SLOT_BOOL, "use_sphere"},     /* for making new primitives only */
 
         {0} /* null-terminating sentinel */,
        },
index bf66388fb9e9f514877c274e848b9b8a9771d1b0..b5e6534de3e3ee63af4dd89b0762fb001b469365 100644 (file)
@@ -242,7 +242,7 @@ int BMO_op_callf(BMesh *bm, const char *fmt, ...);
 int BMO_op_initf(BMesh *bm, BMOperator *op, const char *fmt, ...);
 
 /* va_list version, used to implement the above two functions,
- * plus EDBM_op_callf in bmeshutils.c. */
+ * plus EDBM_op_callf in editmesh_utils.c. */
 int BMO_op_vinitf(BMesh *bm, BMOperator *op, const char *fmt, va_list vlist);
 
 /* test whether a named slot exists */
index af62e4d2b29bea722971ce6fbe1d6b0abb9f3dc6..52e2018eeefa6008605a61d74f0fb0e2e339a132 100644 (file)
@@ -90,9 +90,12 @@ extern int bmesh_total_ops;
 
 struct Object;
 
-void BM_mesh_esubdivideflag(struct Object *obedit, BMesh *bm, int flag, float smooth,
-                            float fractal, int beauty, int numcuts, int seltype,
-                            int cornertype, int singleedge, int gridfill, int seed);
+void BM_mesh_esubdivide(BMesh *bm, const char edge_hflag,
+                        float smooth, float fractal,
+                        int numcuts,
+                        int seltype, int cornertype,
+                        const short use_singleedge, const short use_gridfill,
+                        int seed);
 
 #include "intern/bmesh_operator_api_inline.h"
 
index e526e2eaca0d3068a5c50f8af31212866933a6af..fc0e34cf2f6bca3bd79bd374f8b412798c4c8486 100644 (file)
@@ -428,8 +428,13 @@ void bmo_create_icosphere_exec(BMesh *bm, BMOperator *op)
                BMOperator bmop;
 
                BMO_op_initf(bm, &bmop,
-                            "esubd edges=%fe smooth=%f numcuts=%i gridfill=%b beauty=%i",
-                            EDGE_MARK, dia, (1 << (subdiv-1)) - 1, TRUE, B_SPHERE);
+                            "esubd edges=%fe "
+                            "smooth=%f "
+                            "numcuts=%i "
+                            "use_gridfill=%b use_sphere=%b",
+                            EDGE_MARK, dia, (1 << (subdiv-1)) - 1,
+                            TRUE, TRUE);
+
                BMO_op_exec(bm, &bmop);
                BMO_slot_buffer_flag_enable(bm, &bmop, "geomout", BM_VERT, VERT_MARK);
                BMO_slot_buffer_flag_enable(bm, &bmop, "geomout", BM_EDGE, EDGE_MARK);
index e2f00e3187fcbe847acbe163401da0876a31917f..2f198992eb6b317e84a1db372bf07e9af9d2850d 100644 (file)
@@ -111,7 +111,7 @@ static void alter_co(BMesh *bm, BMVert *v, BMEdge *UNUSED(origed), const SubDPar
        copy_v3_v3(co, v->co);
        copy_v3_v3(prev_co, co);
 
-       if (params->beauty & B_SMOOTH) {
+       if (params->use_smooth) {
                /* we calculate an offset vector vec1[], to be added to *co */
                float len, nor[3], nor1[3], nor2[3], smooth = params->smooth;
 
@@ -136,12 +136,12 @@ static void alter_co(BMesh *bm, BMVert *v, BMEdge *UNUSED(origed), const SubDPar
 
                add_v3_v3(co, tvec);
        }
-       else if (params->beauty & B_SPHERE) { /* subdivide sphere */
+       else if (params->use_sphere) { /* subdivide sphere */
                normalize_v3(co);
                mul_v3_fl(co, params->smooth);
        }
 
-       if (params->beauty & B_FRACTAL) {
+       if (params->use_fractal) {
                float len = len_v3v3(vsta->co, vend->co);
                float vec2[3] = {0.0f, 0.0f, 0.0f}, co2[3];
 
@@ -690,7 +690,7 @@ void bmo_esubd_exec(BMesh *bm, BMOperator *op)
        BLI_array_declare(edges);
        BLI_array_declare(verts);
        float smooth, fractal;
-       int beauty, cornertype, singleedge, gridfill;
+       int use_sphere, cornertype, use_singleedge, use_gridfill;
        int skey, seed, i, j, matched, a, b, numcuts, totesel;
        
        BMO_slot_buffer_flag_enable(bm, op, "edges", BM_EDGE, SUBD_SPLIT);
@@ -699,10 +699,11 @@ void bmo_esubd_exec(BMesh *bm, BMOperator *op)
        seed = BMO_slot_int_get(op, "seed");
        smooth = BMO_slot_float_get(op, "smooth");
        fractal = BMO_slot_float_get(op, "fractal");
-       beauty = BMO_slot_int_get(op, "beauty");
        cornertype = BMO_slot_int_get(op, "quadcornertype");
-       singleedge = BMO_slot_bool_get(op, "singleedge");
-       gridfill = BMO_slot_bool_get(op, "gridfill");
+
+       use_singleedge = BMO_slot_bool_get(op, "use_singleedge");
+       use_gridfill   = BMO_slot_bool_get(op, "use_gridfill");
+       use_sphere     = BMO_slot_bool_get(op, "use_sphere");
        
        BLI_srandom(seed);
        
@@ -720,7 +721,7 @@ void bmo_esubd_exec(BMesh *bm, BMOperator *op)
                        break;
        }
        
-       if (singleedge) {
+       if (use_singleedge) {
                patterns[0] = &quad_1edge;
                patterns[2] = &tri_1edge;
        }
@@ -729,7 +730,7 @@ void bmo_esubd_exec(BMesh *bm, BMOperator *op)
                patterns[2] = NULL;
        }
 
-       if (gridfill) {
+       if (use_gridfill) {
                patterns[3] = &quad_4edge;
                patterns[5] = &tri_3edge;
        }
@@ -755,7 +756,9 @@ void bmo_esubd_exec(BMesh *bm, BMOperator *op)
        params.smooth = smooth;
        params.seed = seed;
        params.fractal = fractal;
-       params.beauty = beauty;
+       params.use_smooth  = (smooth  != 0.0f);
+       params.use_fractal = (fractal != 0.0f);
+       params.use_sphere  = use_sphere;
        params.origkey = skey;
        params.off[0] = (float)BLI_drand() * 200.0f;
        params.off[1] = (float)BLI_drand() * 200.0f;
@@ -1023,25 +1026,35 @@ void bmo_esubd_exec(BMesh *bm, BMOperator *op)
 }
 
 /* editmesh-emulating function */
-void BM_mesh_esubdivideflag(Object *UNUSED(obedit), BMesh *bm, int flag, float smooth,
-                            float fractal, int beauty, int numcuts,
-                            int seltype, int cornertype, int singleedge,
-                            int gridfill, int seed)
+void BM_mesh_esubdivide(BMesh *bm, const char edge_hflag,
+                        float smooth, float fractal,
+                        int numcuts,
+                        int seltype, int cornertype,
+                        const short use_singleedge, const short use_gridfill,
+                        int seed)
 {
        BMOperator op;
        
-       BMO_op_initf(bm, &op, "esubd edges=%he smooth=%f fractal=%f "
-                    "beauty=%i numcuts=%i quadcornertype=%i singleedge=%b "
-                    "gridfill=%b seed=%i",
-                    flag, smooth, fractal, beauty, numcuts,
-                    cornertype, singleedge, gridfill, seed);
+       /* use_sphere isnt exposed here since its only used for new primitives */
+       BMO_op_initf(bm, &op,
+                    "esubd edges=%he "
+                    "smooth=%f fractal=%f "
+                    "numcuts=%i "
+                    "quadcornertype=%i "
+                    "use_singleedge=%b use_gridfill=%b "
+                    "seed=%i",
+                    edge_hflag,
+                    smooth, fractal,
+                    numcuts,
+                    cornertype,
+                    use_singleedge, use_gridfill,
+                    seed);
        
        BMO_op_exec(bm, &op);
        
        if (seltype == SUBDIV_SELECT_INNER) {
                BMOIter iter;
                BMElem *ele;
-               // int i;
 
                for (ele = BMO_iter_new(&iter, bm, &op, "outinner", BM_EDGE | BM_VERT); ele; ele = BMO_iter_step(&iter)) {
                        BM_elem_select_set(bm, ele, TRUE);
@@ -1050,7 +1063,6 @@ void BM_mesh_esubdivideflag(Object *UNUSED(obedit), BMesh *bm, int flag, float s
        else if (seltype == SUBDIV_SELECT_LOOPCUT) {
                BMOIter iter;
                BMElem *ele;
-               // int i;
                
                /* deselect input */
                BM_mesh_elem_hflag_disable_all(bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT, FALSE);
index 1d9021d9756d52c3a6ee860597eff7df5db7da73..cc6ced8bfaad1c4e3835c6be1ef8246ca544ac9f 100644 (file)
@@ -31,7 +31,10 @@ typedef struct SubDParams {
        int numcuts;
        float smooth;
        float fractal;
-       int beauty;
+       //int beauty;
+       short use_smooth;
+       short use_sphere;
+       short use_fractal;
        int seed;
        int origkey; /* shapekey holding displaced vertex coordinates for current geometry */
        BMOperator *op;
index 06e837b37bd83b35cc873ab10678751fc6eda499..6a6da0cfa2610312fd73c4d1cf275bebae4149f7 100644 (file)
@@ -71,16 +71,10 @@ struct Material;
 struct Object;
 struct rcti;
 
-/* editbutflag */
-#define B_SMOOTH            8
-#define B_FRACTAL           0x2000
-#define B_SPHERE            0x4000
-
 intptr_t    mesh_octree_table(struct Object *ob, struct BMEditMesh *em, float *co, char mode);
 int         mesh_mirrtopo_table(struct Object *ob, char mode);
 
-/* bmeshutils.c */
-
+/* editmesh_utils.c */
 
 /* retrieves mirrored cache vert, or NULL if there isn't one.
  * note: calling this without ensuring the mirror cache state
@@ -282,11 +276,6 @@ void ED_mesh_mirrtopo_free(MirrTopoStore_t *mesh_topo_store);
 #define SUBDIV_SELECT_INNER_SEL 2
 #define SUBDIV_SELECT_LOOPCUT   3
 
-/* edge subdivide corner cut types */
-#define SUBDIV_CORNER_PATH      0
-#define SUBDIV_CORNER_INNERVERT 1
-#define SUBDIV_CORNER_FAN       2
-
 #ifdef __cplusplus
 }
 #endif
index 45a975e5d529068997463521fb9bca994a851f81..d7201394855f69ec7e58f7edf6d353cea501f3bf 100644 (file)
@@ -313,10 +313,11 @@ static void ringsel_finish(bContext *C, wmOperator *op)
                edgering_sel(lcd, cuts, 1);
                
                if (lcd->do_cut) {
-                       BM_mesh_esubdivideflag(lcd->ob, em->bm, BM_ELEM_SELECT, 0.0f,
-                                              0.0f, 0, cuts, SUBDIV_SELECT_LOOPCUT,
-                                              SUBD_PATH, 0, FALSE, 0);
-                       
+                       BM_mesh_esubdivide(em->bm, BM_ELEM_SELECT,
+                                          0.0f, 0.0f,
+                                          cuts,
+                                          SUBDIV_SELECT_LOOPCUT, SUBD_PATH, 0, FALSE, 0);
+
                        /* force edge slide to edge select mode in in face select mode */
                        if (em->selectmode & SCE_SELECT_FACE) {
                                if (em->selectmode == SCE_SELECT_FACE)
index da475f9bdf448364d02fc951071425e86d422630..67f387946d5e2f6bf0fcbd35e1efab63f9d0afe0 100644 (file)
@@ -87,25 +87,19 @@ static int edbm_subdivide_exec(bContext *C, wmOperator *op)
        int cuts = RNA_int_get(op->ptr, "number_cuts");
        float smooth = 0.292f * RNA_float_get(op->ptr, "smoothness");
        float fractal = RNA_float_get(op->ptr, "fractal") / 2.5f;
-       int flag = 0;
 
-       if (smooth != 0.0f)
-               flag |= B_SMOOTH;
-       if (fractal != 0.0f)
-               flag |= B_FRACTAL;
-       
        if (RNA_boolean_get(op->ptr, "quadtri") && 
            RNA_enum_get(op->ptr, "quadcorner") == SUBD_STRAIGHT_CUT)
        {
                RNA_enum_set(op->ptr, "quadcorner", SUBD_INNERVERT);
        }
        
-       BM_mesh_esubdivideflag(obedit, em->bm, BM_ELEM_SELECT,
-                              smooth, fractal,
-                              flag,
-                              cuts, 0, RNA_enum_get(op->ptr, "quadcorner"),
-                              RNA_boolean_get(op->ptr, "quadtri"),
-                              TRUE, RNA_int_get(op->ptr, "seed"));
+       BM_mesh_esubdivide(em->bm, BM_ELEM_SELECT,
+                          smooth, fractal,
+                          cuts,
+                          SUBDIV_SELECT_ORIG, RNA_enum_get(op->ptr, "quadcorner"),
+                          RNA_boolean_get(op->ptr, "quadtri"), TRUE,
+                          RNA_int_get(op->ptr, "seed"));
 
        EDBM_update_generic(C, em, TRUE);
 
@@ -2741,10 +2735,9 @@ static int edbm_knife_cut_exec(bContext *C, wmOperator *op)
        if (mode == KNIFE_MIDPOINT) numcuts = 1;
        BMO_slot_int_set(&bmop, "numcuts", numcuts);
 
-       BMO_slot_int_set(&bmop, "flag", 0);
        BMO_slot_int_set(&bmop, "quadcornertype", SUBD_STRAIGHT_CUT);
-       BMO_slot_bool_set(&bmop, "singleedge", FALSE);
-       BMO_slot_bool_set(&bmop, "gridfill", FALSE);
+       BMO_slot_bool_set(&bmop, "use_singleedge", FALSE);
+       BMO_slot_bool_set(&bmop, "use_gridfill", FALSE);
 
        BMO_slot_float_set(&bmop, "radius", 0);
        
index 772e80fff6912661d381adcc8493f475ea49991f..27b1cb6ad545b4ffcafd43ebeb9814c49e7dc383 100644 (file)
@@ -49,7 +49,7 @@ struct wmKeyMap;
 struct wmOperator;
 struct wmOperatorType;
 
-/* ******************** bmeshutils.c */
+/* ******************** editmesh_utils.c */
 
 /*
  * ok: the EDBM module is for editmode bmesh stuff.  in contrast, the