Fix #112580: Limit Constraint with 'Affect Transform' not working properly in 'World Space'

The problem is observed with the "Limit Distance" and "Limit Location"
constraints.

There is an incorrect usage of `td->mtx` and `td->smtx` when converting
`TransData` space from local to global.

In this case, the code is concatenating matrices instead of converting
the location component space.

Also, these matrices only inform the global transformation components
of rotation and scale. They do not include location.

Since the "Limit Distance" and "Limit Location" constraints only require
the location component, it is not necessary to convert the rotation and
scale components.

So, the solution is to convert the location component space instead of
concatenating matrices.

Pull Request: https://projects.blender.org/blender/blender/pulls/112601
This commit is contained in:
Germano Cavalcante
2023-10-06 17:14:25 +02:00
parent 0aa91a30dd
commit cf93c16775
4 changed files with 15 additions and 11 deletions

View File

@@ -239,7 +239,7 @@ void protectedSizeBits(short protectflag, float size[3])
/** \name Transform Limits
* \{ */
void constraintTransLim(const TransInfo *t, TransData *td)
void constraintTransLim(const TransInfo *t, const TransDataContainer *tc, TransData *td)
{
if (td->con) {
const bConstraintTypeInfo *ctiLoc = BKE_constraint_typeinfo_from_type(
@@ -292,8 +292,10 @@ void constraintTransLim(const TransInfo *t, TransData *td)
if (cti) {
/* do space conversions */
if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
/* just multiply by td->mtx (this should be ok) */
mul_m4_m3m4(cob.matrix, td->mtx, cob.matrix);
mul_m3_v3(td->mtx, cob.matrix[3]);
if (tc->use_local_mat) {
add_v3_v3(cob.matrix[3], tc->mat[3]);
}
}
else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
/* skip... incompatible spacetype */
@@ -311,8 +313,10 @@ void constraintTransLim(const TransInfo *t, TransData *td)
/* convert spaces again */
if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
/* just multiply by td->smtx (this should be ok) */
mul_m4_m3m4(cob.matrix, td->smtx, cob.matrix);
if (tc->use_local_mat) {
sub_v3_v3(cob.matrix[3], tc->mat[3]);
}
mul_m3_v3(td->smtx, cob.matrix[3]);
}
/* free targets list */
@@ -635,7 +639,7 @@ void ElementRotation_ex(const TransInfo *t,
add_v3_v3v3(td->loc, td->iloc, vec);
constraintTransLim(t, td);
constraintTransLim(t, tc, td);
}
/* rotation */
@@ -711,7 +715,7 @@ void ElementRotation_ex(const TransInfo *t,
add_v3_v3v3(td->loc, td->iloc, vec);
}
constraintTransLim(t, td);
constraintTransLim(t, tc, td);
/* rotation */
if ((t->flag & T_V3D_ALIGN) == 0) { /* Align mode doesn't rotate objects itself. */
@@ -1061,7 +1065,7 @@ void ElementResize(const TransInfo *t,
add_v3_v3v3(td->loc, td->iloc, vec);
}
constraintTransLim(t, td);
constraintTransLim(t, tc, td);
}
/** \} */

View File

@@ -66,7 +66,7 @@ bool transdata_check_local_center(const TransInfo *t, short around);
bool transform_mode_is_changeable(int mode);
void protectedTransBits(short protectflag, float vec[3]);
void protectedSizeBits(short protectflag, float size[3]);
void constraintTransLim(const TransInfo *t, TransData *td);
void constraintTransLim(const TransInfo *t, const TransDataContainer *tc, TransData *td);
void constraintSizeLim(const TransInfo *t, TransData *td);
/**
* Used by Transform Rotation and Transform Normal Rotation.

View File

@@ -149,7 +149,7 @@ static void ElementMirror(TransInfo *t, TransDataContainer *tc, TransData *td, i
add_v3_v3v3(td->loc, td->iloc, vec);
}
constraintTransLim(t, td);
constraintTransLim(t, tc, td);
}
}

View File

@@ -153,7 +153,7 @@ static void transdata_elem_translate(const TransInfo *t,
add_v3_v3v3(td->loc, td->iloc, tvec);
}
constraintTransLim(t, td);
constraintTransLim(t, tc, td);
}
static void transdata_elem_translate_fn(void *__restrict iter_data_v,