Select mirror multiple axis support

Previously you could only select mirror on X axis,
now support mirroring on multiple axis as well as more than one
(for mesh and lattice data).
This commit is contained in:
Campbell Barton 2016-01-07 20:54:17 +11:00
parent 9e3ae79a54
commit eed28a1db8
5 changed files with 47 additions and 25 deletions

@ -129,8 +129,9 @@ bool BMBVH_EdgeVisible(struct BMBVHTree *tree, struct BMEdge *e,
struct ARegion *ar, struct View3D *v3d, struct Object *obedit);
/* editmesh_select.c */
void EDBM_select_mirrored(struct BMEditMesh *em, bool extend,
int *r_totmirr, int *r_totfail);
void EDBM_select_mirrored(
struct BMEditMesh *em, const int axis, const bool extend,
int *r_totmirr, int *r_totfail);
void EDBM_automerge(struct Scene *scene, struct Object *ob, bool update, const char hflag);
bool EDBM_backbuf_border_init(struct ViewContext *vc, short xmin, short ymin, short xmax, short ymax);

@ -74,8 +74,9 @@
/* ****************************** MIRROR **************** */
void EDBM_select_mirrored(BMEditMesh *em, bool extend,
int *r_totmirr, int *r_totfail)
void EDBM_select_mirrored(
BMEditMesh *em, const int axis, const bool extend,
int *r_totmirr, int *r_totfail)
{
Mesh *me = (Mesh *)em->ob->data;
BMesh *bm = em->bm;
@ -106,7 +107,7 @@ void EDBM_select_mirrored(BMEditMesh *em, bool extend,
}
}
EDBM_verts_mirror_cache_begin(em, 0, true, true, use_topology);
EDBM_verts_mirror_cache_begin(em, axis, true, true, use_topology);
if (!extend)
EDBM_flag_disable_all(em, BM_ELEM_SELECT);
@ -3019,12 +3020,18 @@ static int edbm_select_mirror_exec(bContext *C, wmOperator *op)
{
Object *obedit = CTX_data_edit_object(C);
BMEditMesh *em = BKE_editmesh_from_object(obedit);
bool extend = RNA_boolean_get(op->ptr, "extend");
const int axis_flag = RNA_enum_get(op->ptr, "axis");
const bool extend = RNA_boolean_get(op->ptr, "extend");
if (em->bm->totvert && em->bm->totvertsel) {
int totmirr, totfail;
EDBM_select_mirrored(em, extend, &totmirr, &totfail);
for (int axis = 0; axis < 3; axis++) {
if ((1 << axis) & axis_flag) {
EDBM_select_mirrored(em, axis, extend, &totmirr, &totfail);
}
}
if (totmirr) {
EDBM_selectmode_flush(em);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
@ -3051,6 +3058,8 @@ void MESH_OT_select_mirror(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* props */
RNA_def_enum_flag(ot->srna, "axis", rna_enum_axis_flag_xyz_items, (1 << 0), "Axis", "");
RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the existing selection");
}

@ -246,21 +246,17 @@ void LATTICE_OT_select_random(wmOperatorType *ot)
/* -------------------------------------------------------------------- */
/* Select Mirror Operator */
static int lattice_select_mirror_exec(bContext *C, wmOperator *op)
static void ed_lattice_select_mirrored(Lattice *lt, const int axis, const bool extend)
{
Object *obedit = CTX_data_edit_object(C);
Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
const bool extend = RNA_boolean_get(op->ptr, "extend");
const int axis = RNA_enum_get(op->ptr, "axis");
bool flip_uvw[3] = {false};
int tot, i;
const int tot = lt->pntsu * lt->pntsv * lt->pntsw;
int i;
BPoint *bp;
BLI_bitmap *selpoints;
tot = lt->pntsu * lt->pntsv * lt->pntsw;
bool flip_uvw[3] = {false};
flip_uvw[axis] = true;
/* we could flip this too */
if (!extend) {
lt->actbp = LT_ACTBP_NONE;
}
@ -287,6 +283,20 @@ static int lattice_select_mirror_exec(bContext *C, wmOperator *op)
MEM_freeN(selpoints);
}
static int lattice_select_mirror_exec(bContext *C, wmOperator *op)
{
Object *obedit = CTX_data_edit_object(C);
Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
const int axis_flag = RNA_enum_get(op->ptr, "axis");
const bool extend = RNA_boolean_get(op->ptr, "extend");
for (int axis = 0; axis < 3; axis++) {
if ((1 << axis) & axis_flag) {
ed_lattice_select_mirrored(lt, axis, extend);
}
}
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
@ -308,7 +318,7 @@ void LATTICE_OT_select_mirror(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* props */
RNA_def_enum(ot->srna, "axis", rna_enum_axis_xyz_items, 0, "Axis", "");
RNA_def_enum_flag(ot->srna, "axis", rna_enum_axis_flag_xyz_items, (1 << 0), "Axis", "");
RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection");
}

@ -116,6 +116,8 @@ extern EnumPropertyItem rna_enum_gpencil_sculpt_brush_items[];
extern EnumPropertyItem rna_enum_axis_xy_items[];
extern EnumPropertyItem rna_enum_axis_xyz_items[];
extern EnumPropertyItem rna_enum_axis_flag_xyz_items[];
extern EnumPropertyItem rna_enum_symmetrize_direction_items[];
extern EnumPropertyItem rna_enum_texture_type_items[];

@ -268,6 +268,13 @@ EnumPropertyItem rna_enum_axis_xyz_items[] = {
{0, NULL, 0, NULL, NULL}
};
EnumPropertyItem rna_enum_axis_flag_xyz_items[] = {
{(1 << 0), "X", 0, "X", ""},
{(1 << 1), "Y", 0, "Y", ""},
{(1 << 2), "Z", 0, "Z", ""},
{0, NULL, 0, NULL, NULL}
};
#ifdef RNA_RUNTIME
#include "DNA_particle_types.h"
@ -4097,13 +4104,6 @@ static void rna_def_modifier_meshcache(BlenderRNA *brna)
{0, NULL, 0, NULL, NULL}
};
static EnumPropertyItem prop_flip_axis_flag_items[] = {
{(1 << 0), "X", 0, "X", ""},
{(1 << 1), "Y", 0, "Y", ""},
{(1 << 2), "Z", 0, "Z", ""},
{0, NULL, 0, NULL, NULL}
};
StructRNA *srna;
PropertyRNA *prop;
@ -4168,7 +4168,7 @@ static void rna_def_modifier_meshcache(BlenderRNA *brna)
prop = RNA_def_property(srna, "flip_axis", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "flip_axis");
RNA_def_property_enum_items(prop, prop_flip_axis_flag_items);
RNA_def_property_enum_items(prop, rna_enum_axis_flag_xyz_items);
RNA_def_property_flag(prop, PROP_ENUM_FLAG);
RNA_def_property_ui_text(prop, "Flip Axis", "");
RNA_def_property_update(prop, 0, "rna_Modifier_update");