diff options
Diffstat (limited to 'source/blender/editors/transform/transform_constraints.c')
-rw-r--r-- | source/blender/editors/transform/transform_constraints.c | 167 |
1 files changed, 78 insertions, 89 deletions
diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index 84eac3bbf8f..5e2a8be8db0 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -50,6 +50,7 @@ #include "UI_resources.h" #include "transform.h" +#include "transform_orientations.h" #include "transform_snap.h" /* Own include. */ @@ -100,24 +101,6 @@ static void constraint_plane_calc(TransInfo *t, float r_plane[4]) r_plane[3] = -dot_v3v3(r_plane, t->center_global); } -static void constraintValuesFinal(TransInfo *t, float vec[3]) -{ - int mode = t->con.mode; - if (mode & CON_APPLY) { - float nval = (t->flag & T_NULL_ONE) ? 1.0f : 0.0f; - - if ((mode & CON_AXIS0) == 0) { - vec[0] = nval; - } - if ((mode & CON_AXIS1) == 0) { - vec[1] = nval; - } - if ((mode & CON_AXIS2) == 0) { - vec[2] = nval; - } - } -} - void constraintNumInput(TransInfo *t, float vec[3]) { int mode = t->con.mode; @@ -163,41 +146,6 @@ void constraintNumInput(TransInfo *t, float vec[3]) } } -static void postConstraintChecks(TransInfo *t, float vec[3]) -{ - mul_m3_v3(t->spacemtx_inv, vec); - - transform_snap_increment(t, vec); - - if (t->flag & T_NULL_ONE) { - if (!(t->con.mode & CON_AXIS0)) { - vec[0] = 1.0f; - } - - if (!(t->con.mode & CON_AXIS1)) { - vec[1] = 1.0f; - } - - if (!(t->con.mode & CON_AXIS2)) { - vec[2] = 1.0f; - } - } - - if (applyNumInput(&t->num, vec)) { - constraintNumInput(t, vec); - removeAspectRatio(t, vec); - } - - /* If `t->values` is operator param, use that directly but not if snapping is forced */ - if (t->flag & T_INPUT_IS_VALUES_FINAL && (t->tsnap.status & SNAP_FORCED) == 0) { - copy_v3_v3(vec, t->values); - constraintValuesFinal(t, vec); - /* inverse transformation at the end */ - } - - mul_m3_v3(t->spacemtx, vec); -} - static void viewAxisCorrectCenter(const TransInfo *t, float t_con_center[3]) { if (t->spacetype == SPACE_VIEW3D) { @@ -336,7 +284,9 @@ static void constraint_snap_plane_to_edge(const TransInfo *t, const float plane[ * Snap to the nearest point between the snap point and the line that * intersects the face plane with the constraint plane. */ -static void constraint_snap_plane_to_face(const TransInfo *t, const float plane[4], float r_out[3]) +static void UNUSED_FUNCTION(constraint_snap_plane_to_face(const TransInfo *t, + const float plane[4], + float r_out[3])) { float face_plane[4], isect_orig[3], isect_dir[3]; const float *face_snap_point = t->tsnap.snapPoint; @@ -432,15 +382,22 @@ static void applyAxisConstraintVec( { copy_v3_v3(out, in); if (!td && t->con.mode & CON_APPLY) { + bool is_snap_to_point = false, is_snap_to_edge = false, is_snap_to_face = false; mul_m3_v3(t->con.pmtx, out); - bool is_snap_to_edge = false, is_snap_to_face = false; + if (activeSnap(t)) { - is_snap_to_edge = (t->tsnap.snapElem & SCE_SNAP_MODE_EDGE) != 0; - is_snap_to_face = (t->tsnap.snapElem & SCE_SNAP_MODE_FACE) != 0; + if (validSnap(t)) { + is_snap_to_edge = (t->tsnap.snapElem & SCE_SNAP_MODE_EDGE) != 0; + is_snap_to_face = (t->tsnap.snapElem & SCE_SNAP_MODE_FACE) != 0; + is_snap_to_point = !is_snap_to_edge && !is_snap_to_face; + } + else if (t->tsnap.snapElem & SCE_SNAP_MODE_GRID) { + is_snap_to_point = true; + } } /* With snap points, a projection is alright, no adjustments needed. */ - if (!validSnap(t) || is_snap_to_edge || is_snap_to_face) { + if (!is_snap_to_point || is_snap_to_edge || is_snap_to_face) { const int dims = getConstraintSpaceDimension(t); if (dims == 2) { if (!is_zero_v3(out)) { @@ -451,7 +408,8 @@ static void applyAxisConstraintVec( constraint_snap_plane_to_edge(t, plane, out); } else if (is_snap_to_face) { - constraint_snap_plane_to_face(t, plane, out); + /* Disabled, as it has not proven to be really useful. (See T82386). */ + // constraint_snap_plane_to_face(t, plane, out); } else { /* View alignment correction. */ @@ -470,7 +428,8 @@ static void applyAxisConstraintVec( else if (t->con.mode & CON_AXIS1) { copy_v3_v3(c, t->spacemtx[1]); } - else if (t->con.mode & CON_AXIS2) { + else { + BLI_assert(t->con.mode & CON_AXIS2); copy_v3_v3(c, t->spacemtx[2]); } @@ -486,7 +445,6 @@ static void applyAxisConstraintVec( } } } - postConstraintChecks(t, out); } } @@ -733,31 +691,46 @@ void setLocalConstraint(TransInfo *t, int mode, const char text[]) * ftext is a format string passed to BLI_snprintf. It will add the name of * the orientation where %s is (logically). */ -void setUserConstraint(TransInfo *t, short orientation, int mode, const char ftext[]) +void setUserConstraint(TransInfo *t, int mode, const char ftext[]) { char text[256]; + short orientation = t->orient[t->orient_curr].type; + if (orientation == V3D_ORIENT_CUSTOM_MATRIX) { + /* Use the real value of the "orient_type". */ + orientation = t->orient[0].type; + } + const char *spacename = transform_orientations_spacename_get(t, orientation); BLI_snprintf(text, sizeof(text), ftext, spacename); - switch (orientation) { - case V3D_ORIENT_LOCAL: - setLocalConstraint(t, mode, text); - break; - case V3D_ORIENT_NORMAL: - if (checkUseAxisMatrix(t)) { - setAxisMatrixConstraint(t, mode, text); + if (t->modifiers & (MOD_CONSTRAINT_SELECT | MOD_CONSTRAINT_PLANE)) { + /* Force the orientation of the active object. + * Although possible, it is not convenient to use the local or axis constraint + * with the modifier to select constraint. + * This also follows the convention of older versions. */ + setConstraint(t, mode, text); + } + else { + switch (orientation) { + case V3D_ORIENT_LOCAL: + setLocalConstraint(t, mode, text); + break; + case V3D_ORIENT_NORMAL: + if (checkUseAxisMatrix(t)) { + setAxisMatrixConstraint(t, mode, text); + break; + } + ATTR_FALLTHROUGH; + case V3D_ORIENT_GLOBAL: + case V3D_ORIENT_VIEW: + case V3D_ORIENT_CURSOR: + case V3D_ORIENT_GIMBAL: + case V3D_ORIENT_CUSTOM_MATRIX: + case V3D_ORIENT_CUSTOM: + default: { + setConstraint(t, mode, text); break; } - ATTR_FALLTHROUGH; - case V3D_ORIENT_GLOBAL: - case V3D_ORIENT_VIEW: - case V3D_ORIENT_CURSOR: - case V3D_ORIENT_GIMBAL: - case V3D_ORIENT_CUSTOM_MATRIX: - case V3D_ORIENT_CUSTOM: - default: { - setConstraint(t, mode, text); - break; } } t->con.mode |= CON_USER; @@ -990,12 +963,10 @@ void stopConstraint(TransInfo *t) void initSelectConstraint(TransInfo *t) { if (t->orient_curr == 0) { - t->orient_curr = 1; - transform_orientations_current_set(t, t->orient_curr); + transform_orientations_current_set(t, 1); } - short orientation = t->orient[t->orient_curr].type; - setUserConstraint(t, orientation, CON_APPLY | CON_SELECT, "%s"); + setUserConstraint(t, CON_APPLY | CON_SELECT, "%s"); setNearestAxis(t); } @@ -1083,16 +1054,34 @@ static void setNearestAxis3d(TransInfo *t) } if (len[0] <= len[1] && len[0] <= len[2]) { - t->con.mode |= CON_AXIS0; - BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" along %s X axis"), t->spacename); + if (t->modifiers & MOD_CONSTRAINT_PLANE) { + t->con.mode |= (CON_AXIS1 | CON_AXIS2); + BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" locking %s X axis"), t->spacename); + } + else { + t->con.mode |= CON_AXIS0; + BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" along %s X axis"), t->spacename); + } } else if (len[1] <= len[0] && len[1] <= len[2]) { - t->con.mode |= CON_AXIS1; - BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" along %s Y axis"), t->spacename); + if (t->modifiers & MOD_CONSTRAINT_PLANE) { + t->con.mode |= (CON_AXIS0 | CON_AXIS2); + BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" locking %s Y axis"), t->spacename); + } + else { + t->con.mode |= CON_AXIS1; + BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" along %s Y axis"), t->spacename); + } } else if (len[2] <= len[1] && len[2] <= len[0]) { - t->con.mode |= CON_AXIS2; - BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" along %s Z axis"), t->spacename); + if (t->modifiers & MOD_CONSTRAINT_PLANE) { + t->con.mode |= (CON_AXIS0 | CON_AXIS1); + BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" locking %s Z axis"), t->spacename); + } + else { + t->con.mode |= CON_AXIS2; + BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" along %s Z axis"), t->spacename); + } } } |