Wednesday, July 6, 2011

GSoC11 - An easy way to create expressions...

In case you missed my commit the other day, I've recently committed a new feature which makes it easier to set up "expressions".


Expressions (otherwise known as "Scripted Expression" drivers) basically provide a way to control some property programmically, either using some mathematical formula to procedurally generate animation, or perhaps to set up some kind of driver (one property's value "drives" another).

As seen in the screenshots above, to add an expression to a property:
1) Simply click on any numeric field to start editing its value as text, and delete the initial text
2) Type the '#' character to tell Blender you're about to enter an expression. If you don't Blender will think that you just want the expression evaluated immediately (i.e. the old, type Python code in a button to calculate a value)
3) Type in your expression. This can be any valid Python statement which can be evaluated a number
4) Press Enter, and a new Scripted Expression driver is created for this property!

Some examples of valid expressions:
#sin(frame)
#cos(frame)
#frame
#frame/5
#my_own_function_registered_for_driver_use(1, 2, 3)     <--- see section on "Using Custom Functions in Driver Expressions"

About this "frame" thing...
With expressions, I've assumed that it's quite common for you to want to specify the expression in terms of the current frame. In a bid to make these expressions tidier to look at (and easier to type), a driver variable named "frame" is created automatically for new expressions created this way, so that it's possible to just type #frame and have a working driver.

Future work
Eventually, I hope to include some functionality which will be able to detect where you've used some common identifiers like this in your expressions, and create driver variables for these. However, since there are some other things I need to get on to, it may be a while before I get around to this unless there is sufficient interest in this for me to reprioritise this earlier.

8 comments:

  1. Finally, an even better implementation that 2.49x. Very nicely done, cant wait for your branch to be merged into trunk!! Thank you!

    ReplyDelete
  2. I would love to be able to use expressions in Blender in a similar fashion to After Effects!

    ReplyDelete
  3. Great!!!! You Rock! Simply Expression in Blender! I dream!

    ReplyDelete
  4. Very nice. I am still lost in 2.5x, and the pydrivers area confuses me quite a lot… This seems very handy !

    ReplyDelete
  5. this expression sin(frame) works fine in animation
    but not in game run
    how can i do something like that while running in game?
    please help me

    ReplyDelete
  6. give some more exaple of simple expression

    ReplyDelete