Skip to content

Commit

Permalink
New hsv() driver
Browse files Browse the repository at this point in the history
Adding hsv(h, s, v, 0) driver and updating documentation along with sample project
  • Loading branch information
John Einselen VF committed Oct 21, 2021
1 parent af535d5 commit e151b8e
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 6 deletions.
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# VF-BlenderDriverFunctions
# VF Driver Functions
Functions for use in Blender channel drivers.

Installation and usage:
- Download the .py file
- Open up Blender preferences
- Install the addon
- Enable the addon


## Installation and usage:
- Download the desired driver
- [VF_curveAtTime.py](https://raw.githubusercontent.com/jeinselenVF/VF-BlenderDriverFunctions/main/VF_curveAtTime.py)
- [VF_hsv.py](https://raw.githubusercontent.com/jeinselenVF/VF-BlenderDriverFunctions/main/VF_hsv.py)
- [VF_wiggle.py](https://raw.githubusercontent.com/jeinselenVF/VF-BlenderDriverFunctions/main/VF_wiggle.py)
- Open up Blender Preferences > Add-ons
- Install and enable the add-on
- Add a driver to any channel via keyboard shortcut (usually "D"), context menu (right-click), or directly (typing "#" and then the function)



## curveAtTime
This driver function is intended to mimic Adobe After Effect's "valueAtTime" expression, returning the value of an animated channel from the specified point in time.

Expand Down Expand Up @@ -37,6 +42,19 @@ Note that Blender's time sampling doesn't allow references to an object's transf
- Note how the current frame value is multiplied by 0.5 to slow down time


## hsv
Converts from HSV value inputs to RGB value outputs. Because drivers are designed for individual channel usage, the specific red (`0`), green (`1`), or blue (`2`) channel output must be selected.

The following example uses the `X`, `Y`, and `Z` positions of a controller null to drive the `hue`, `sat`, and `val` variables within the driver, and the same driver setup is copied across all three `r`, `g`, and `b` input channels in both the material, updating the fourth value (`0`, `1`, or `2`) to match the channel index.

```javascript
hsv(hue, sat, val, 0)
```

Download the example project: [hsv.blend](images/hsv.blend.zip)

![screen capture of the Blender interface showing both the controller null and the driver function applied to the red channel of an affected object](images/hsv.png)

## wiggle
Designed to mimic Adobe After Effect's "wiggle" expression with similar frequency (colloquially known as wiggles per second) and octave settings.

Expand Down
48 changes: 48 additions & 0 deletions VF_hsv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
bl_info = {
"name": "VF Driver HSV",
"author": "John Einselen - Vectorform LLC",
"version": (0, 1),
"blender": (2, 80, 0),
"location": "Channel driver -> hsv(0.1, 0.5, 1.0, 0)",
"description": "Adds hsv(hue, saturation, value, RGB channel output) driver function",
"warning": "inexperienced developer, use at your own risk",
"wiki_url": "",
"tracker_url": "",
"category": "Rigging"}

# Thanks for the help:
# https://blender.stackexchange.com/questions/71305/how-to-make-an-addon-with-custom-driver-function
# https://blender.stackexchange.com/questions/80034/hsv-to-rgb-conversion

# Example usage:
# hsv2r(0.5, 1, 1, 0)
# this will convert HSV input values into RGB output values, and return the first (red) channel

import bpy
from colorsys import hsv_to_rgb
from bpy.app.handlers import persistent
from bpy.app import driver_namespace as dns

def hsv(h, s, v, c):
color = hsv_to_rgb(h, s, v)
if c < 0.5:
return color[0]
elif c < 1.5:
return color[1]
else:
return color[2]

@persistent
def load_handler(dummy):
dns = bpy.app.driver_namespace
dns["hsv"] = hsv

def register():
load_handler(None)
bpy.app.handlers.load_post.append(load_handler)

def unregister():
bpy.app.handlers.load_post.remove(load_handler)

if __name__ == "__main__":
register()
Binary file added images/hsv.blend.zip
Binary file not shown.
Binary file added images/hsv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e151b8e

Please sign in to comment.