selectrandom mesh , temp using space key
authorShaul Kedem <shaul_kedem@yahoo.com>
Sat, 31 Jan 2009 23:57:04 +0000 (23:57 +0000)
committerShaul Kedem <shaul_kedem@yahoo.com>
Sat, 31 Jan 2009 23:57:04 +0000 (23:57 +0000)
source/blender/editors/mesh/editmesh_mods.c
source/blender/editors/mesh/mesh_intern.h
source/blender/editors/mesh/mesh_ops.c

index f7a1e153e55d7df0f42795b82c1436ad6bffc34e..ce3d2dc4b101c0087f5ab62579328c1bdecbd198 100644 (file)
@@ -3555,12 +3555,11 @@ void MESH_OT_select_less(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-void selectrandom_mesh(EditMesh *em) /* randomly selects a user-set % of vertices/edges/faces */
+void selectrandom_mesh(EditMesh *em, int randfac) /* randomly selects a user-set % of vertices/edges/faces */
 {
        EditVert *eve;
        EditEdge *eed;
        EditFace *efa;
-       static short randfac = 50;
 
        /* Get the percentage of vertices to randomly select as 'randfac' */
 // XXX if(button(&randfac,0, 100,"Percentage:")==0) return;
@@ -3598,6 +3597,37 @@ void selectrandom_mesh(EditMesh *em) /* randomly selects a user-set % of vertice
 //     if (EM_texFaceCheck())
 }
 
+static int selectrandom_mesh_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
+       
+       selectrandom_mesh(em, RNA_int_get(op->ptr,"percentage"));
+               
+       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
+       
+       return OPERATOR_FINISHED;       
+}
+
+void MESH_OT_selectrandom_mesh(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Select random mesh";
+       ot->idname= "MESH_OT_selectrandom_mesh";
+       
+       /* api callbacks */
+       ot->exec= selectrandom_mesh_exec;
+       ot->poll= ED_operator_editmesh;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER/*|OPTYPE_UNDO*/;
+       
+       /* props */
+
+       
+       RNA_def_int(ot->srna, "percentage", 50, 0, 100, "percentage", "", 0, 100);
+}
+
 void editmesh_select_by_material(EditMesh *em, int index) 
 {
        EditFace *efa;
index ac491c014385b6b17d6f03b9b72b5e6b5fd6acbc..64adc45aeeb17c9040b5c0382a677301e98035f9 100644 (file)
@@ -189,6 +189,7 @@ void MESH_OT_shortest_path_select(struct wmOperatorType *ot);
 void MESH_OT_similar_vertex_select(struct wmOperatorType *ot);
 void MESH_OT_similar_edge_select(struct wmOperatorType *ot);
 void MESH_OT_similar_face_select(struct wmOperatorType *ot);
+void MESH_OT_selectrandom_mesh(struct wmOperatorType *ot);
 
 extern EditEdge *findnearestedge(ViewContext *vc, int *dist);
 extern void EM_automerge(int update);
index 029dbcf6afe44a2126e60d3308c9d3580456571f..40fa6917564f55fe54537cd0d2abff825f5d5453 100644 (file)
@@ -113,6 +113,7 @@ void ED_operatortypes_mesh(void)
        WM_operatortype_append(MESH_OT_select_non_manifold);
        WM_operatortype_append(MESH_OT_selectconnected_mesh_all);
        WM_operatortype_append(MESH_OT_selectconnected_mesh);
+       WM_operatortype_append(MESH_OT_selectrandom_mesh);
        WM_operatortype_append(MESH_OT_hide_mesh);
        WM_operatortype_append(MESH_OT_reveal_mesh);
        WM_operatortype_append(MESH_OT_consistant_normals);
@@ -182,7 +183,9 @@ void ED_keymap_mesh(wmWindowManager *wm)
        RNA_boolean_set(WM_keymap_add_item(keymap, "MESH_OT_selectconnected_mesh", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "deselect", 1);
        
        RNA_float_set(WM_keymap_add_item(keymap, "MESH_OT_select_linked_flat_faces", FKEY, KM_PRESS, (KM_CTRL|KM_SHIFT|KM_ALT), 0)->ptr,"sharpness",135.0);
-       RNA_float_set(WM_keymap_add_item(keymap, "MESH_OT_select_sharp_edges", SKEY, KM_PRESS, (KM_CTRL|KM_SHIFT|KM_ALT), 0)->ptr,"sharpness",135.0);           
+       RNA_float_set(WM_keymap_add_item(keymap, "MESH_OT_select_sharp_edges", SKEY, KM_PRESS, (KM_CTRL|KM_SHIFT|KM_ALT), 0)->ptr,"sharpness",135.0);
+       
+       WM_keymap_add_item(keymap, "MESH_OT_selectrandom_mesh", SPACEKEY, KM_PRESS, 0, 0);
        
        /* temp hotkeys! */
        WM_keymap_add_item(keymap, "MESH_OT_similar_vertex_select", GKEY, KM_PRESS, KM_SHIFT, 0);