bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator...
authorJoseph Eagar <joeedh@gmail.com>
Thu, 6 Aug 2009 11:27:08 +0000 (11:27 +0000)
committerJoseph Eagar <joeedh@gmail.com>
Thu, 6 Aug 2009 11:27:08 +0000 (11:27 +0000)
source/blender/bmesh/intern/bmesh_opdefines.c
source/blender/bmesh/intern/bmesh_operators_private.h
source/blender/bmesh/operators/utils.c
source/blender/editors/mesh/bmesh_tools.c
source/blender/editors/mesh/editmesh_mods.c

index cef85b563f2202a7af18a1577d76c97fe26fed56..d88a10fc1a5da2706f62b46c20859e2c16b00cf0 100644 (file)
@@ -66,6 +66,30 @@ substitutions for "slot".
 note that slots default to being input slots.
 */
 
+/*
+  Vertex Smooth
+
+  Smoothes vertices by using a basic vertex averaging scheme.
+*/
+BMOpDefine def_vertexsmooth = {
+       "vertexsmooth",
+       {{BMOP_OPSLOT_ELEMENT_BUF, "verts"}, //input vertices
+        {BMOP_OPSLOT_INT, "mirror_clip_x"}, //set vertices close to the x axis before the operation to 0
+        {BMOP_OPSLOT_INT, "mirror_clip_y"}, //set vertices close to the y axis before the operation to 0
+        {BMOP_OPSLOT_INT, "mirror_clip_z"}, //set vertices close to the z axis before the operation to 0
+        {BMOP_OPSLOT_FLT, "clipdist"}, //clipping threshod for the above three slots
+       {0} /*null-terminating sentinel*/,
+       },
+       bmesh_vertexsmooth_exec,
+       0
+};
+
+/*
+  Right-Hand Faces
+
+  Computes an "outside" normal for the specified input faces.
+*/
+
 BMOpDefine def_righthandfaces = {
        "righthandfaces",
        {{BMOP_OPSLOT_ELEMENT_BUF, "faces"},
@@ -547,6 +571,7 @@ BMOpDefine *opdefines[] = {
        &def_edgerotate,
        &def_regionextend,
        &def_righthandfaces,
+       &def_vertexsmooth,
 };
 
 int bmesh_total_ops = (sizeof(opdefines) / sizeof(void*));
index 24f9143a9a36e7edc07766b0f4a64d071d3a55e8..f1e471ccf7953691ee4b745fa94bfe458cabbe6c 100644 (file)
@@ -40,5 +40,6 @@ void bmesh_reversefaces_exec(BMesh *bm, BMOperator *op);
 void bmesh_edgerotate_exec(BMesh *bm, BMOperator *op);
 void bmesh_regionextend_exec(BMesh *bm, BMOperator *op);
 void bmesh_righthandfaces_exec(BMesh *bm, BMOperator *op);
+void bmesh_vertexsmooth_exec(BMesh *bm, BMOperator *op);
 
 #endif
index 37d92073e26ae160641f72f6b4b56e8551f24e10..55ab3cc0405606eb1384aac76acbf4aecb0410e2 100644 (file)
@@ -317,3 +317,63 @@ void bmesh_righthandfaces_exec(BMesh *bm, BMOperator *op)
                }
        }
 }
+
+void bmesh_vertexsmooth_exec(BMesh *bm, BMOperator *op)
+{
+       BMOIter siter;
+       BMIter iter;
+       BMVert *v;
+       BMEdge *e;
+       V_DECLARE(cos);
+       float (*cos)[3] = NULL;
+       float *co, *co2, clipdist = BMO_Get_Float(op, "clipdist");
+       int i, j, clipx, clipy, clipz;
+       
+       clipx = BMO_Get_Int(op, "mirror_clip_x");
+       clipy = BMO_Get_Int(op, "mirror_clip_y");
+       clipz = BMO_Get_Int(op, "mirror_clip_z");
+
+       i = 0;
+       BMO_ITER(v, &siter, bm, op, "verts", BM_VERT) {
+               V_GROW(cos);
+               co = cos[i];
+               
+               j  = 0;
+               BM_ITER(e, &iter, bm, BM_EDGES_OF_VERT, v) {
+                       co2 = BM_OtherEdgeVert(e, v)->co;
+                       VECADD(co, co, co2);
+                       j += 1;
+               }
+               
+               if (!j) {
+                       VECCOPY(co, v->co);
+                       i++;
+                       continue;
+               }
+
+               co[0] /= (float)j;
+               co[1] /= (float)j;
+               co[2] /= (float)j;
+
+               co[0] = v->co[0]*0.5 + co[0]*0.5;
+               co[1] = v->co[1]*0.5 + co[1]*0.5;
+               co[2] = v->co[2]*0.5 + co[2]*0.5;
+               
+               if (clipx && fabs(v->co[0]) < clipdist)
+                       co[0] = 0.0f;
+               if (clipy && fabs(v->co[1]) < clipdist)
+                       co[1] = 0.0f;
+               if (clipz && fabs(v->co[2]) < clipdist)
+                       co[2] = 0.0f;
+
+               i++;
+       }
+
+       i = 0;
+       BMO_ITER(v, &siter, bm, op, "verts", BM_VERT) {
+               VECCOPY(v->co, cos[i]);
+               i++;
+       }
+
+       V_FREE(cos);
+}
index 269c9a4e972d3ab825b49847e509c5e25fcf41af..cba74f8d4393109b193583e2393128554d28652c 100644 (file)
@@ -134,7 +134,7 @@ void MESH_OT_subdivide(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
        /* properties */
-       RNA_def_int(ot->srna, "number_cuts", 1, 1, 10, "Number of Cuts", "", 1, INT_MAX);
+       RNA_def_int(ot->srna, "number_cuts", 1, 1, 20, "Number of Cuts", "", 1, INT_MAX);
        RNA_def_float(ot->srna, "fractal", 0.0, 0.0f, FLT_MAX, "Fractal", "Fractal randomness factor.", 0.0f, 1000.0f);
        RNA_def_float(ot->srna, "smoothness", 0.0f, 0.0f, 1000.0f, "Smoothness", "Smoothness factor.", 0.0f, FLT_MAX);
 }
@@ -1506,7 +1506,7 @@ static int edge_rotate_selected(bContext *C, wmOperator *op)
        EDBM_InitOpf(em, &bmop, op, "edgerotate edges=%e ccw=%d", eed, ccw);
        BMO_Exec_Op(em->bm, &bmop);
 
-       BMO_HeaderFlag_Slot(em->bm, &bmop, "edgeout", BM_SELECT);
+       BMO_HeaderFlag_Buffer(em->bm, &bmop, "edgeout", BM_SELECT);
 
        if (!EDBM_FinishOp(em, &bmop, op, 1))
                return OPERATOR_CANCELLED;
@@ -1680,3 +1680,68 @@ void MESH_OT_normals_make_consistent(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "inside", 0, "Inside", "");
 }
 
+
+
+static int do_smooth_vertex(bContext *C, wmOperator *op)
+{
+       Scene *scene = CTX_data_scene(C);
+       Object *obedit= CTX_data_edit_object(C);
+       BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh;
+       ModifierData *md;
+       int mirrx=0, mirry=0, mirrz=0;
+       int i, repeat;
+
+       /* if there is a mirror modifier with clipping, flag the verts that
+        * are within tolerance of the plane(s) of reflection 
+        */
+       for(md=obedit->modifiers.first; md; md=md->next) {
+               if(md->type==eModifierType_Mirror) {
+                       MirrorModifierData *mmd = (MirrorModifierData*) md;     
+               
+                       if(mmd->flag & MOD_MIR_CLIPPING) {
+                               if (mmd->flag & MOD_MIR_AXIS_X)
+                                       mirrx = 1;
+                               if (mmd->flag & MOD_MIR_AXIS_Y)
+                                       mirry = 1;
+                               if (mmd->flag & MOD_MIR_AXIS_Z)
+                                       mirrz = 1;
+                       }
+               }
+       }
+
+       repeat = RNA_int_get(op->ptr,"repeat");
+       if (!repeat)
+               repeat = 1;
+       
+       for (i=0; i<repeat; i++) {
+               if (!EDBM_CallOpf(em, op, "vertexsmooth verts=%hv mirror_clip_x=%d mirror_clip_y=%d mirror_clip_z=%d",
+                                 BM_SELECT, mirrx, mirry, mirrz))
+               {
+                       return OPERATOR_CANCELLED;
+               }
+       }
+
+       //BMESH_TODO: need to handle the x-axis editing option here properly.
+       //should probably make a helper function for that? I dunno.
+
+       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); //TODO is this needed ?
+
+       return OPERATOR_FINISHED;
+}      
+       
+void MESH_OT_vertices_smooth(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Smooth Vertex";
+       ot->idname= "MESH_OT_vertices_smooth";
+       
+       /* api callbacks */
+       ot->exec= do_smooth_vertex;
+       ot->poll= ED_operator_editmesh;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       RNA_def_int(ot->srna, "repeat", 1, 1, 200, "How many times to smooth the mesh", "", 1, INT_MAX);
+}
index 97c72dc49ca30c18be3fe8a732582dfbb3722a75..5265b5ffd80d60d53089682091e4360297ae0d56 100644 (file)
@@ -2874,12 +2874,9 @@ void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, wmOperator *o
 
 /* **************** VERTEX DEFORMS *************** */
 
-static int smooth_vertex(bContext *C, wmOperator *op)
+/*scene is needed for some tool settings*/
+static void smooth_vertex(EditMesh *em, Object *obedit, Scene *scene)
 {
-#if 0 //BMESH_TODO
-       Scene *scene= CTX_data_scene(C);
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
        EditVert *eve, *eve_mir = NULL;
        EditEdge *eed;
        float *adror, *adr, fac;
@@ -2888,7 +2885,6 @@ static int smooth_vertex(bContext *C, wmOperator *op)
        ModifierData *md;
 
        if(em==NULL) {
-               BKE_mesh_end_editmesh(obedit->data, em);
                return OPERATOR_CANCELLED;
        }
 
@@ -3010,28 +3006,6 @@ static int smooth_vertex(bContext *C, wmOperator *op)
        MEM_freeN(adror);
 
        recalc_editnormals(em);
-
-       BKE_mesh_end_editmesh(obedit->data, em);
-
-       DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
-
-#endif
-       return OPERATOR_FINISHED;
-}
-
-void MESH_OT_vertices_smooth(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Smooth Vertex";
-       ot->idname= "MESH_OT_vertices_smooth";
-       
-       /* api callbacks */
-       ot->exec= smooth_vertex;
-       ot->poll= ED_operator_editmesh;
-       
-       /* flags */
-       ot->flag= OPTYPE_UNDO;
 }
 
 void vertexnoise(Object *obedit, EditMesh *em)