Maintain scaling ratio of non-free axes in Maintain Volume T48079 fix.

This is probably a better way to handle it: instead of totally
discarding scaling of non-free axes, keep the ratio between them.
Basically the logic of the constraint is now that it rescales the
object uniformly in the non-free axis plane in order to force the
total volume change to the desired value.
This commit is contained in:
Alexander Gavrilov 2018-03-02 11:01:49 +03:00
parent ff74357da0
commit a9509a2f8a
Notes: blender-bot 2023-02-14 07:18:54 +01:00
Referenced by issue #57793, Maintain Volume constraint appears to have no effect in 2.79
Referenced by issue #57376, 2.79 -> 2.8 Maintain Volume constraint unexpected behaviour.
1 changed files with 10 additions and 9 deletions

View File

@ -1926,28 +1926,29 @@ static void samevolume_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *
bSameVolumeConstraint *data = con->data;
float volume = data->volume;
float fac = 1.0f;
float fac = 1.0f, total_scale;
float obsize[3];
mat4_to_size(obsize, cob->matrix);
/* calculate normalizing scale factor for non-essential values */
if (obsize[data->flag] != 0)
fac = sqrtf(volume / obsize[data->flag]);
total_scale = obsize[0] * obsize[1] * obsize[2];
if (total_scale != 0)
fac = sqrtf(volume / total_scale);
/* apply scaling factor to the channels not being kept */
switch (data->flag) {
case SAMEVOL_X:
mul_v3_fl(cob->matrix[1], fac / obsize[1]);
mul_v3_fl(cob->matrix[2], fac / obsize[2]);
mul_v3_fl(cob->matrix[1], fac);
mul_v3_fl(cob->matrix[2], fac);
break;
case SAMEVOL_Y:
mul_v3_fl(cob->matrix[0], fac / obsize[0]);
mul_v3_fl(cob->matrix[2], fac / obsize[2]);
mul_v3_fl(cob->matrix[0], fac);
mul_v3_fl(cob->matrix[2], fac);
break;
case SAMEVOL_Z:
mul_v3_fl(cob->matrix[0], fac / obsize[0]);
mul_v3_fl(cob->matrix[1], fac / obsize[1]);
mul_v3_fl(cob->matrix[0], fac);
mul_v3_fl(cob->matrix[1], fac);
break;
}
}