diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2018-03-02 11:01:49 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2018-03-02 11:01:49 +0300 |
commit | a9509a2f8a9abfdd12bb21153879af05924db2b5 (patch) | |
tree | a6eb35d466368a847c7d21ae4c82847c0bd4a8c8 /source/blender/blenkernel | |
parent | ff74357da09d5060d61d247f75dbb01e91ca3bb9 (diff) |
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.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 5d8053e0036..06817133382 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -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; } } |