Transform: axis support for shear tool

This commit is contained in:
Campbell Barton 2018-10-16 21:52:30 +11:00
parent 345175082b
commit 5b9ab20fe4
4 changed files with 37 additions and 8 deletions

View File

@ -144,6 +144,7 @@ int BIF_countTransformOrientation(const struct bContext *C);
#define P_MIRROR_DUMMY (P_MIRROR | (1 << 9))
#define P_PROPORTIONAL (1 << 1)
#define P_AXIS (1 << 2)
#define P_AXIS_ORTHO (1 << 16)
#define P_SNAP (1 << 3)
#define P_GEO_SNAP (P_SNAP | (1 << 4))
#define P_ALIGN_SNAP (P_GEO_SNAP | (1 << 5))

View File

@ -2174,6 +2174,10 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
RNA_property_float_set_array(op->ptr, prop, t->axis);
}
if ((prop = RNA_struct_find_property(op->ptr, "axis_ortho"))) {
RNA_property_float_set_array(op->ptr, prop, t->axis_ortho);
}
if ((prop = RNA_struct_find_property(op->ptr, "mirror"))) {
RNA_property_boolean_set(op->ptr, prop, (t->flag & T_MIRROR) != 0);
}
@ -2394,6 +2398,11 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
copy_v3_v3(t->axis_orig, t->axis);
}
if ((prop = RNA_struct_find_property(op->ptr, "axis_ortho")) && RNA_property_is_set(op->ptr, prop)) {
RNA_property_float_get_array(op->ptr, prop, t->axis_ortho);
normalize_v3(t->axis_ortho);
}
/* Constraint init from operator */
if ((prop = RNA_struct_find_property(op->ptr, "constraint_axis")) && RNA_property_is_set(op->ptr, prop)) {
bool constraint_axis[3];
@ -3328,6 +3337,15 @@ static void initShear(TransInfo *t)
t->num.unit_type[0] = B_UNIT_NONE; /* Don't think we have any unit here? */
t->flag |= T_NO_CONSTRAINT;
if (is_zero_v3(t->axis)) {
negate_v3_v3(t->axis, t->viewinv[2]);
normalize_v3(t->axis);
}
if (is_zero_v3(t->axis_ortho)) {
copy_v3_v3(t->axis_ortho, t->viewinv[0]);
normalize_v3(t->axis_ortho);
}
}
static eRedrawFlag handleEventShear(TransInfo *t, const wmEvent *event)
@ -3367,15 +3385,12 @@ static eRedrawFlag handleEventShear(TransInfo *t, const wmEvent *event)
static void applyShear(TransInfo *t, const int UNUSED(mval[2]))
{
float vec[3];
float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3];
float smat[3][3], tmat[3][3], totmat[3][3], axismat[3][3], axismat_inv[3][3];
float value;
int i;
char str[UI_MAX_DRAW_STR];
const bool is_local_center = transdata_check_local_center(t, t->around);
copy_m3_m4(persmat, t->viewmat);
invert_m3_m3(persinv, persmat);
value = t->values[0];
snapGridIncrement(t, &value);
@ -3405,8 +3420,13 @@ static void applyShear(TransInfo *t, const int UNUSED(mval[2]))
else
smat[0][1] = value;
mul_m3_m3m3(tmat, smat, persmat);
mul_m3_m3m3(totmat, persinv, tmat);
copy_v3_v3(axismat_inv[0], t->axis_ortho);
copy_v3_v3(axismat_inv[2], t->axis);
cross_v3_v3v3(axismat_inv[1], axismat_inv[0], axismat_inv[2]);
invert_m3_m3(axismat, axismat_inv);
mul_m3_m3m3(tmat, smat, axismat);
mul_m3_m3m3(totmat, axismat_inv, tmat);
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
TransData *td = tc->data;

View File

@ -516,6 +516,7 @@ typedef struct TransInfo {
float auto_values[4];
float axis[3];
float axis_orig[3]; /* TransCon can change 'axis', store the original value here */
float axis_ortho[3];
bool remove_on_cancel; /* remove elements if operator is canceled */

View File

@ -552,6 +552,14 @@ void Transform_Properties(struct wmOperatorType *ot, int flags)
RNA_def_property_ui_text(prop, "Axis", "The axis around which the transformation occurs");
}
if (flags & P_AXIS_ORTHO) {
prop = RNA_def_property(ot->srna, "axis_ortho", PROP_FLOAT, PROP_DIRECTION);
RNA_def_property_array(prop, 3);
/* Make this not hidden when there's a nice axis selection widget */
RNA_def_property_flag(prop, PROP_HIDDEN);
RNA_def_property_ui_text(prop, "Axis", "The orthogonal axis around which the transformation occurs");
}
if (flags & P_CONSTRAINT) {
RNA_def_boolean_vector(ot->srna, "constraint_axis", 3, NULL, "Constraint Axis", "");
prop = RNA_def_property(ot->srna, "constraint_orientation", PROP_ENUM, PROP_NONE);
@ -834,8 +842,7 @@ static void TRANSFORM_OT_shear(struct wmOperatorType *ot)
WM_operatortype_props_advanced_begin(ot);
Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT);
// XXX Shear axis?
Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_AXIS | P_AXIS_ORTHO);
}
static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot)