6
$\begingroup$

I have a shapekey driven by a bone. I want to configure the shapekey's driver such that scaling the bone to 0.3 results in a shapekey value of 1, and scaling the bone to 1 results in a shapekey value of 0.

In other words:

Shapekey range: 0 - 1

Bone scale range: 1 - 0.3

I'm sure this is simple, but everything I've tried hasn't worked.


For Hulifier's solution, here is how it looks in my particular use case:

Normalize 2 numbers to 0 - 1 range in Blender

$\endgroup$

2 Answers 2

8
$\begingroup$

$$\frac{v-s}{k-s}$$

  • s = Range start.
  • k = Range end.
  • v = Value.

The result is a value between 0 and 1 if v is inside the range.

In your case:

  • s = 1.
  • k = 0.3.
  • v = the bone scale.
$\endgroup$
1
  • $\begingroup$ Wow, it worked perfectly!!! Thank you so much!! I have updated my original question with an image of the solution (for my particular use case). $\endgroup$ Commented Apr 22, 2022 at 21:14
3
$\begingroup$

Although slightly more time consuming to set up, you can also do this with just the F-Curve of the driver since it's a simple value mapping.
Doing it this way will make your rig more lightweight than using a Python expression since the graph curve will be evaluated anyway.

The images and shortcut keys below are for Blender 2.79, but work the same on 2.80 and up.

  • Set the driver type to Sum Values.
  • Make a Transform Channel variable for the Local X Scale of the bone (easier to understand than having to write the property explicitly down to .scale[0]).
  • So the values of all variables of the driver (just one variable, in this case) will be summed, and the result will be used as the input "frame" (the time) within the F-Curve of the driver. Let's edit the F-Curve to change how it maps the input.

Driver variable

  • Set the curve extrapolation mode (Shift+E) to Constant Extrapolation.

  • Select both keyframes and press (T) for the Keyframe Interpolation dialog, set them to Linear keys (instead of the default of Bezier), which are faster to process.

  • Place one keyframe on frame 0.3, value 1.0.

First keyframe

  • The other keyframe goes on frame 1.0, value 0.0.

Second keyframe

So when the input is 0.3 you get an output of 1.0, when the input is 1.0 you get an output of 0.0.

PS you can use the View tab to place the 2D cursor with precision and use the (I) key to create new keyframes on the driver curve at that cursor location.

$\endgroup$
3
  • 1
    $\begingroup$ Thanks so much for this great solution!!!! I find it very intuitive and used it to drive the values of the shapekeys on my character. Since I want to scale the bone in any axis to drive the shapekey, I right-clicked the bone's Scale channel and chose "Copy as New Driver", then on the shapekey I chose "Paste Driver" and followed your instructions. I've also added a "Limit Scale" constraint (with "Affect Transform" checked) to the control bone to avoid overshooting my scale values (although the Range Min/Max settings of the shapekey itself prevent keyframing values outside of the 0-1 range). $\endgroup$ Commented Apr 25, 2022 at 17:48
  • 1
    $\begingroup$ @Copperplate good call, the Limit Scale should make it more intuitive for the animator (even if it'll be yourself). PS the driver value is also limited by the graph curve, it's that Shift + E constant extrapolation part (if the input is less than 0.3 then the output stays at 1.0, and if the input is bigger than 1.0 it stays at zero). BTW, I said "use the (T) dialog to set the keyframes as Linear instead of the default of Bezier", but Bezier keys have their uses too, like adding some easing to the driver -- might be useful with some shape keys that require soft nuanced changes. Good luck! $\endgroup$
    – R. Navega
    Commented Apr 26, 2022 at 18:46
  • $\begingroup$ Thanks for that additional info! Strangely, the "Driver Value" within the Drivers' window shows as if it exceeds the min/max threshold set by the graph curve, however you are right that it actually doesn't exceed it, because increasing / decreasing the thresholds within the shapekey's "Range Min/Max" settings have no effect (unless the extrapolation of the driver curve is set to something other than Constant). Not sure if the behavior is like that in Blender 2.79 but in Blender 3.1 at least... I now know not to trust the Driver Value! :-) $\endgroup$ Commented Apr 27, 2022 at 19:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .