Page MenuHome

Drivers: add lerp and clamp functions to namespace.
ClosedPublic

Authored by Alexander Gavrilov (angavrilov) on Jul 4 2020, 12:22 PM.

Details

Summary

Implementation of lerp without a function requires repeating one of
the arguments, which is not ideal. To avoid that, add a new function
to the driver namespace; in addition, provide a function for clamping
between 0 and 1 to support easy clamped lerp.

The function implementations are added to mathutils, since the driver
namespace already imports some utilities from there. As an aside, add
the round function to the pylike expression subset.

Diff Detail

Repository
rB Blender

Event Timeline

Alexander Gavrilov (angavrilov) requested review of this revision.Jul 4 2020, 12:22 PM

In general this seems OK, although adding float functions directly to mathutils that don't operate on mathutils types seems odd.

I'd rather make this a separate module, although currently we don't have an obvious place for it to go.
We could make it a submodule of mathutils, we'd need to find a good name though.


Note that round could go in as-is.

Added optional arguments to clamp, and a smoothstep function to make this even more versatile.

Campbell Barton (campbellbarton) requested changes to this revision.EditedJul 16 2020, 3:17 AM

Discussed this with @Bastien Montagne (mont29) and we think it would be best to make this a standalone module, bl_math - where Blender spesific math functions can go, unrelated to mathutils. This can be added to ./source/blender/python/generic.

This revision now requires changes to proceed.Jul 16 2020, 3:17 AM
Campbell Barton (campbellbarton) requested changes to this revision.Jul 16 2020, 2:14 PM

LGTM, only minor changes requested.

source/blender/python/generic/bl_math_py_api.c
38–40
58

_PyArg_ParseTupleAndKeywordsFast could be used to speed up argument parsing.

This revision now requires changes to proceed.Jul 16 2020, 2:14 PM
source/blender/blenlib/intern/expr_pylike_eval.c
349–353

Is clamping with a single argument common?

I'd assume this would clamp between zero and a maximum.

If this isn't already standard behavior elsewhere, it's probably best not to include it.

This revision is now accepted and ready to land.Jul 21 2020, 12:28 PM
source/blender/python/generic/bl_math_py_api.c
35

Normally we don't have blank space here (to avoid these sections taking up too much vertical space.)