Revision: 22255
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22255
Author:   joeedh
Date:     2009-08-06 13:27:08 +0200 (Thu, 06 Aug 2009)

Log Message:
-----------
bmeshafied vertex smooth, and also added a 'repeat' option :) since the last 
operator panel works after this last 2.5 merge, yayscons/scons.py 
BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators_private.h
    branches/bmesh/blender/source/blender/bmesh/operators/utils.c
    branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c
    branches/bmesh/blender/source/blender/editors/mesh/editmesh_mods.c

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c        
2009-08-06 11:20:00 UTC (rev 22254)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c        
2009-08-06 11:27:08 UTC (rev 22255)
@@ -66,6 +66,30 @@
 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 @@
        &def_edgerotate,
        &def_regionextend,
        &def_righthandfaces,
+       &def_vertexsmooth,
 };
 
 int bmesh_total_ops = (sizeof(opdefines) / sizeof(void*));

Modified: 
branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators_private.h
===================================================================
--- 
branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators_private.h    
    2009-08-06 11:20:00 UTC (rev 22254)
+++ 
branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators_private.h    
    2009-08-06 11:27:08 UTC (rev 22255)
@@ -40,5 +40,6 @@
 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

Modified: branches/bmesh/blender/source/blender/bmesh/operators/utils.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/utils.c       
2009-08-06 11:20:00 UTC (rev 22254)
+++ branches/bmesh/blender/source/blender/bmesh/operators/utils.c       
2009-08-06 11:27:08 UTC (rev 22255)
@@ -317,3 +317,63 @@
                }
        }
 }
+
+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);
+}

Modified: branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c    
2009-08-06 11:20:00 UTC (rev 22254)
+++ branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c    
2009-08-06 11:27:08 UTC (rev 22255)
@@ -134,7 +134,7 @@
        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 @@
        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 @@
        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);
+}

Modified: branches/bmesh/blender/source/blender/editors/mesh/editmesh_mods.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/mesh/editmesh_mods.c  
2009-08-06 11:20:00 UTC (rev 22254)
+++ branches/bmesh/blender/source/blender/editors/mesh/editmesh_mods.c  
2009-08-06 11:27:08 UTC (rev 22255)
@@ -2874,12 +2874,9 @@
 
 /* **************** 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 @@
        ModifierData *md;
 
        if(em==NULL) {
-               BKE_mesh_end_editmesh(obedit->data, em);
                return OPERATOR_CANCELLED;
        }
 
@@ -3010,30 +3006,8 @@
        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)
 {
        Material *ma;


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to