diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2019-05-05 13:25:43 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2019-05-06 19:03:26 +0300 |
commit | 1854cccad7c31a6b8235faf980ffdd6a80163e02 (patch) | |
tree | e2ae8c4b8b358ce8a2035fd8be36ee6c4f3f01b7 /source/blender/blenkernel/intern/fcurve.c | |
parent | 11d2c0b6f41cf0fdc6d95cbed5bfb02e7feb4256 (diff) |
Drivers: add an Average Scale option to the Transform Channel driver vars.
Unlike location and rotation, there is a meaningful definition of
overall/average scaling via the total change in the volume. This
adds an option to retrieve that via a single driver variable,
instead of having to use three and an expression.
Using the determinant to compute the volume scaling also allows
detecting flipping due to negative scale - this is impossible
to do via the three variable approach.
The volume_scale functions are added purely for code readability:
'volume scale factor' is easier to understand than determinant.
Differential Revision: https://developer.blender.org/D4803
Diffstat (limited to 'source/blender/blenkernel/intern/fcurve.c')
-rw-r--r-- | source/blender/blenkernel/intern/fcurve.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 8c95e4c7ff3..e2d0a479792 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -1707,6 +1707,11 @@ static float dvar_eval_transChan(ChannelDriver *driver, DriverVar *dvar) /* not valid channel */ return 0.0f; } + else if (dtar->transChan == DTAR_TRANSCHAN_SCALE_AVG) { + /* Cubic root of the change in volume, equal to the geometric mean + * of scale over all three axes unless the matrix includes shear. */ + return cbrtf(mat4_to_volume_scale(mat)); + } else if (dtar->transChan >= DTAR_TRANSCHAN_SCALEX) { /* Extract scale, and choose the right axis, * inline 'mat4_to_size'. */ |