Creating a custom constraint or driver

Hi,

I need some custom functionality in Blender to do the following.

I want to move a bone in my rig based on multiple inputs (each input is a float number). My code will figure out how to move the bone based on configuration of these inputs. These configurations are created by a user. For example, if input A=0.5 and input B=0.5 my bone should be in T1 position, but if A=1 and B=1 then bone position is T2. Custom functionality will then interpolate between different configurations.

I have written a node for Maya to do this but I was wondering how should I do this in Blender. Is it just a Python addon? Or I need to write extension in C? In Maya, Plugins are categorized neatly based on the type of the node. But I am not sure what I am supposed to start with to build this in Blender.

Could anyone please point in the right direction?

Hey maulik13,

You should not code it in C, as C already has all the functionality included which is easily reachable with python code. If you want to code add-ons or constraints or drivers, python is your best choice.

Now, for the coding of the custom driver/constraint itself, it seems to me that this already exists in blender. You can ‘drive’ (almost) everything here. What you explain, driving a bone in between two extremes according to user input, seems to me already implemented. I would definitely do thorough research into other parts of this forum/community to make sure you’re not wasting any valuable time in re-writing already existing code.

regards

hewi

the wiki on python drivers might be a good start

Thank you for your replies. I have looked at the documentation for “driver” and tried it as well. But it seems I am not able to use it to achieve what I need. Here is an example of what I need.

I have three inputs A, B and C (from custom attributes) and they should influence bone’s transformation like this:
If
A=1
B=2
C=3
Then bone.translation = [3,3,3]
If
A=2
B=3
C=2
Then bone.translation = [5,6,5]

When A, B and C go from 1,2,3 to 2,3,2 bone translation should interpolate between [3,3,3] and [5,6,5]

With drivers, I cannot split inputs to have different mappings like in the example above.

I would prefer to do this in Python to save development time. Could anyone point to a reference about how the constraint system works in Blender and how can I build my own?

Pyconstraints never made the 2.4x–>2.5x jump so there’s not a whole lot you can do there short of coding them up yourself.Back in the day I did something similar (to shake out the bugs in pydrivers) so it is possible to drive pydrivers through custom attributes:https://vimeo.com/17201210

I can also use existing constraints, but then I need to write some logic to drive the constraints. In Maya I would create a node network with nodes for condition, matrix multiplication, vector math etc to build the logic. And the output of this network will be fed to the bones of my rig.

How do I write logic and calculation in Blender to drive bones? If it is a script how is this script always called when my inputs change?