operator to select pos/neg verts on any axis relative to the active vertex

- useful to select the center verts of a model without having to attempt to border select
- useful for selecting one half or a model
This commit is contained in:
Campbell Barton
2009-11-05 18:29:48 +00:00
parent 1196947a98
commit aec92ddc51
4 changed files with 78 additions and 0 deletions

View File

@@ -303,6 +303,7 @@ class VIEW3D_MT_select_edit_mesh(bpy.types.Menu):
layout.itemO("mesh.edges_select_sharp", text="Sharp Edges")
layout.itemO("mesh.faces_select_linked_flat", text="Linked Flat Faces")
layout.itemO("mesh.faces_select_interior", text="Interior Faces")
layout.itemO("mesh.select_axis", text="Side of Active")
layout.itemS()

View File

@@ -7197,3 +7197,78 @@ void MESH_OT_faces_shade_flat(wmOperatorType *ot)
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
/* TODO - some way to select on an arbitrary axis */
static int select_axis_exec(bContext *C, wmOperator *op)
{
Object *obedit= CTX_data_edit_object(C);
EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
int axis= RNA_int_get(op->ptr, "axis");
int mode= RNA_enum_get(op->ptr, "mode"); /* -1==aligned, 0==neg, 1==pos*/
EditSelection *ese = em->selected.last;
if(ese==NULL)
return OPERATOR_CANCELLED;
if(ese->type==EDITVERT) {
EditVert *ev;
EditVert *act_vert= (EditVert*)ese->data;
float value= act_vert->co[axis];
float limit= CTX_data_tool_settings(C)->doublimit; // XXX
if(mode==0) value -= limit;
else if (mode==1) value += limit;
for(ev=em->verts.first;ev;ev=ev->next) {
if(!ev->h) {
switch(mode) {
case -1: /* aligned */
if(fabs(ev->co[axis] - value) < limit)
ev->f |= SELECT;
break;
case 0: /* neg */
if(ev->co[axis] > value)
ev->f |= SELECT;
break;
case 1: /* pos */
if(ev->co[axis] < value)
ev->f |= SELECT;
break;
}
}
}
}
EM_select_flush(em);
WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
return OPERATOR_FINISHED;
}
void MESH_OT_select_axis(wmOperatorType *ot)
{
static EnumPropertyItem axis_mode_items[] = {
{0, "POSITIVE", 0, "Positive Axis", ""},
{1, "NEGATIVE", 0, "Negative Axis", ""},
{-1, "ALIGNED", 0, "Aligned Axis", ""},
{0, NULL, 0, NULL, NULL}};
/* identifiers */
ot->name= "Select Axis";
ot->description= "Select all data in the mesh on a single axis.";
ot->idname= "MESH_OT_select_axis";
/* api callbacks */
ot->exec= select_axis_exec;
ot->poll= ED_operator_editmesh;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* properties */
RNA_def_enum(ot->srna, "mode", axis_mode_items, 0, "Axis Mode", "Axis side to use when selecting");
RNA_def_int(ot->srna, "axis", 0, 0, 2, "Axis", "Select the axis to compare each vertex on", 0, 2);
}

View File

@@ -217,6 +217,7 @@ void MESH_OT_edge_rotate(struct wmOperatorType *ot);
void MESH_OT_select_vertex_path(struct wmOperatorType *ot);
void MESH_OT_loop_to_region(struct wmOperatorType *ot);
void MESH_OT_region_to_loop(struct wmOperatorType *ot);
void MESH_OT_select_axis(struct wmOperatorType *ot);
void MESH_OT_uvs_rotate(struct wmOperatorType *ot);
void MESH_OT_uvs_mirror(struct wmOperatorType *ot);

View File

@@ -109,6 +109,7 @@ void ED_operatortypes_mesh(void)
WM_operatortype_append(MESH_OT_select_vertex_path);
WM_operatortype_append(MESH_OT_loop_to_region);
WM_operatortype_append(MESH_OT_region_to_loop);
WM_operatortype_append(MESH_OT_select_axis);
WM_operatortype_append(MESH_OT_uvs_rotate);
WM_operatortype_append(MESH_OT_uvs_mirror);