I’ve this requirement where I should map the rotation ( of a single axis ) of a bone to a slider. That is, when the bone is in the rest position ( X rotation 0 ) this slider’s value must be zero. And as the bone is rotated along the X axis the slider’s value must also increase. And by the time the bone hits the designated angle, say -39 degrees, the slider should hit a value of one.
I tried to implement this with drivers where the slider’s value is driven by the x axis rotation angle of the driving bone. And to map the value, I’ve put together a script. This script works perfectly when the both the driven and the driver have linear, non rotational values but when I try to use it in the current scenario, it doesn’t seem to work.
Well, it works, but not as I’d like it to work. For instance, even when the bone is rotated one full circle, it produces a driver value of only 0.167.
It seems obvious to me that rotation couldn’t be handled as easy as this. And I would very much like to know how at all it could be handled.
This also happens to be my first python/blender code ( and no, it’s not entirely mine. I got the core logic somewhere in the internet ) so I’m shooting a bit in the dark here, haha. Here’s the code. This is specifically made for ranges where the maximum input range is lesser in value than the minimum input range ( as in a range of 0 to -32 )
import bpy from mathutils import noise from math import * def rngFndrD( drvrRst,drvrFin,oLwrLmt,oUprLmt,drvrInpt): if drvrRst >= drvrInpt >= drvrFin: if drvrRst == drvrFin: return None if oLwrLmt == oUprLmt: return None #check reversed input range reverseInput = False oldMin = min( drvrRst, drvrFin ) oldMax = max( drvrRst, drvrFin ) if not oldMin == drvrRst: reverseInput = True #check reversed output range reverseOutput = False newMin = min( oLwrLmt, oUprLmt ) newMax = max( oLwrLmt, oUprLmt ) if not newMin == oLwrLmt : reverseOutput = True portion = (drvrInpt-oldMin)*(newMax-newMin)/(oldMax-oldMin) if reverseInput: portion = (oldMax-drvrInpt)*(newMax-newMin)/(oldMax-oldMin) result = portion + newMin if reverseOutput: result = newMax - portion return result else: #To handle input values greater than or lesser than the input range if drvrRst > drvrFin: if drvrInpt > drvrRst: return oLwrLmt else: return oUprLmt else: if drvrInpt < drvrRst: return oLwrLmt else: return oUprLmt bpy.app.driver_namespace['rngFndrD'] = rngFndrD
I know that it could be a pain to go through another person’s code so any help regarding this would be much appreciated a lot.