Blender Driver Scripted Expression Tutorials

13 Blender tips from the pros; 13 Blender tips from the pros. This is especially useful if your rig uses bones and drivers rather than exclusively relying on shape keys for phoneme shapes. The last (optional) step is to run a UI script to add a nice interface to the rig. Open the Blender Text Editor, and select rig_ui.py from the data list.

Blender may be free, but it isn’t just a tool for hobbyists. The powerful open-source 3D package is now used on a variety of professional projects, from the Blender Foundation’s own ‘open movies’ to illustrations, animated commercials and even visual effects work.

While the fundamentals of Blender are well covered by training materials available online, there is little information targeted specifically towards this new group of professional users.

To help you get the most from the software, we asked five of the world’s 8leading Blender artists to provide their tips for working quicker and smarter under real-world production conditions.

01. Don’t duplicate: instance instead

You can create and render vastly more complex scenes by using [Alt]+[D] instead of [Shift]+[D] to duplicate an object. The new object will share the same mesh data as the original, reducing memory usage. Even better, any changes made to one object will also be applied to the others, enabling you to update hundreds of objects at once. - Ian Hubert, 3D artist

02. Save time with flat projection

When you can get away with it, avoid UV mapping by using a quick-and-dirty flat projection on basic geometry. You can create complex, realistic objects in minutes. In most cases, the result will still look the same from a distance. - IH

03. Make use of Proportional Edit

Say you have a scene containing hundreds of individual objects: for example, rocks or plant geometry. To position each of them manually would take forever – so to speed up the process, use the Proportional Edit tool.

The length of scripted expression strings is limited to 256 characters. A misfeature rather than a bug, but something that I ran into and I don't know how to get. In this article I select Scripted Expression type and write 'foo()' in the Expression textbox. Also you can use variables in your driver. Blender, cycles, driver, node, python, script. Martes, 4 de agosto de 2015. Blender Cycles: Map Range Node for Materials. Some Tutorials about CG Concepts. Hi everybody! These are some interesting.

Select a single object and press [O] to turn on Proportional editing. Now press [G], [S] or [R] to respectively move, scale or rotate while simultaneously rolling the mouse wheel. You’ll see that all of the objects in the Proportional editing region (shown by a white circle) are affected. The mouse wheel changes the size of the region.

Proportional Edit can be set to many different Falloff types (shown by a rollout near the blue circle Proportional Edit button). Selecting Random will cause random translation, rotation and scaling of objects within the soft-selection region – useful for ‘messing up’ a scene to make it feel more organic.

Since this trick works across all visible scene layers, put any objects that you don’t want to affect into a separate layer, then simply turn that layer off. - James Neale, founding partner of Red Cartel

04. Use Pose Libraries for blocking

Pose Libraries are a great way to rough in animation, particularly for facial animation and lip sync. This is especially useful if your rig uses bones and drivers rather than exclusively relying on shape keys for phoneme shapes.

Blender Driver Scripted Expression Tutorials For Beginners

I like to make a bone group for my lip sync controls and use those controls to create my phonemes. Each phoneme gets saved as a pose in my character’s Pose Library ([Shift]+[L]).

When animating, select the bones in the lip sync bone group and press [Ctrl]+[L] to enter a library preview mode. You can then use your mouse’s scroll wheel or [Page Up]/[Page Down] to cycle through the poses in your library. Choose your pose and insert your keyframes. This works as your first rough pass on the lip sync to get the timing right.

On subsequent passes, you’re free to adjust the facial controls to add more personality to your animation. And because a Pose Library is just a special kind of action, you can easily append it to any scene. - Jason van Gumster, owner of Hand Turkey Studios

05. Use Network Render to set up an ad hoc renderfarm

Start by switching the render engine from Blender Render to Network Render. On your master node, choose Master from the Network Settings panel of Render Properties. When you click Start Service, you can view the status of the farm by opening a web browser on that machine and pointing it to http://localhost:8000. With the master node running, go to the other machines and set them up as slaves.

It’s the same steps as for the master node: just choose Slave from Network Settings instead of Master. Assuming the machines are on the same network, when you click Start Service, the slave node should automatically find the master.

To render, go to the machine you want to render from and set up your client by switching to Network Render and choosing Client from Network Settings. If you click the refresh button, the client should automatically find the master node.

Now you can render your animation on your ad hoc farm by clicking the Animation on network button in the Job Settings panel. - JvG

06. Use Damped Track for eye tracking

Blender’s Track To constraint is handy for making objects or bones point at a target. Unfortunately, it is also based on gimbal (or Euler) rotations, which can make it behave oddly.

Sometimes that behaviour is what you want (for turrets, for example) – but usually, it’s not (on eyes, for example): what you would like is for the object to take the most direct rotation path from its starting rotation to point at the target. Fortunately, Blender has a constraint that does exactly that: it’s called Damped Track.

In most cases, substituting Damped Track for Track To will give you the result you want. - NV

07. Use sculpting to fix errors in animation

One of the coolest uses for the sculpt tool was shown to me by animator and teacher Daniel Martinez Lara.

Instead of just sculpting static objects, you can use it to tweak the shape of characters as they move over time in order to polish animations. This enables you to fix deformations, add extra stretching or change the outline of a pose – things that are hard to do with bones, but easy to draw.

This only works in the very newest builds of Blender (2.56+). After animation is completed, go to Mesh Properties and locate the Shape Keys panel.

Select the Basic key selected from the list and click the plus icon to add a new shape key. Next, move the playhead to a frame you want to tweak, click the pin icon and enter sculpt mode.

For sculpting, I prefer to use the Grab tool for making larger shape changes, and then the Smooth tool to smooth out problem areas.

Once you are happy with your changes, exit sculpt mode and play with the shape Value slider. Hover your cursor over the slider and press the [I] key to insert keyframes to animate the effect in and out over time. - William Reynish, animator on Big Buck Bunny and Sintel

08. Feed Compositor nodes to the VSE via scene strips

When using Blender for motion graphics, there’s some cool handshaking you can do between the Node Editor and Video Sequence Editor.

If a shot requires more involved effects than the VSE can provide, switch to the Compositing screen layout and create a new empty scene (I like to name the scene after the shot).

Use the Image input node to bring your clip into the Node Editor, adjusting the start and end frames in the node and the scene as necessary.

From this point, you can add whatever cool compositing effects you want. When you switch back to the Video Editing screen (it should still be in your editing scene), replace your shot by adding a scene strip in the VSE for your compositing scene.

As a bonus, if you delete all of the screen layouts except for Compositing and Video Editing, you can quickly bounce between your composite scene and your editing session using [Ctrl]+[left arrow] and [Ctrl]+[right arrow]. - JvG

09. Put colour into shadows and global illumination

By default in Blender, shadows and GI are black. This doesn’t always give the best result. If you look at Pixar’s work, for example, the shadow is usually a darker, more saturated version of the diffuse colour.

You can achieve this effect in the compositor by specifying your layer to output a separate GI and shadow pass. Use the Mix node set to multiply your shadow/GI with a colour of choice, them Mix that back into your render pass for best effect.

We sometimes render a scene (Scene01) with no GI or shadows at all, and an identical copy of that same scene (Scene02) to get just the GI and shadows layers by themselves. Use the compositor back in Scene01 to composite those layers from Scene02, using the colour picker inside the Mix node set to Multiply or Add to achieve the shadow colour we need. - JN

10. Use Only Insert Available when autokeying

Blender, like many 3D applications, has a feature that will automatically insert keyframes when you move an object or bone. Blender calls this feature Auto Keyframing or ‘autokey’. I prefer animating this way because it saves on keystrokes, and because otherwise I sometimes forget to key part of a pose I’ve been working on.

The drawback of using autokey is that it also sets keys on things you aren’t intending to animate. For example, if I tweak the position of the camera or lights, and then tweak them again later on at a different frame, this will result in them being animated, even if I don’t want it to be. Fortunately, Blender offers a way to solve this: Only Insert Available. With this option toggled on, autokey will only set keys on things that are already animated. The first time you key something, you have to do it manually, but from then on the process is automatic.

This lets you treat manual keying as way of telling Blender, “I want this to be animated.” From then on, Blender takes care of the rest with autokey. - Nathan Vegdahl is a freelance 3D artist

11. Set up master files to grade large projects

Most large animation projects require you to keep track of many individual shots and grade them consistently at the end. You can use the Blender sequencer and compositor to do this.

Blender Driver Scripted Expression Tutorials Free

First, start an empty .blend file. This will be your master file. Link in every scene you need from the individual .blend shot files and place them in order along the timeline of the sequencer in the master file. (This helps the editor, since the Blender sequencer produces an OpenGL version of each scene, making it easy to see the latest work from each scene in real time.)

You can now set the look and feel for each section of the animation. Select a group of shots that must have the same visual properties, and group those nodes together inside the master file, calling the group ‘Master Comp’ or something suitably witty. Go to each of the original individual shot files and link back to the Master
Comp group.

Now whenever any of the artists updates their work (for example, to update an asset, the animation, lighting, or scene-specific compositing) they only have to tell the person in charge of the master file to reload their particular scene, and the same global feel will be preserved.

Since the master file controls both the edit and the global composite group (the grade), rendering via that master file enables you to render the entire project with the exact edit decision list and composite gamut required. - JN

12. Set up Fake users to manage remote collaboration

Red Cartel often collaborates with artists working remotely outside the studio. To keep the pipeline as smooth as possible, we use Blender’s excellent library systems. Data transfer for large scene files takes a long time, so for animators, we ask them to save out their Blender
scene with unique names for their character/camera actions.

If they then delete all the relevant working geometry and specify their most recent action as having a Fake user (the F button next to that action inside Dopesheet/Action Editor), that datablock is retained inside the empty .blend file.

This reduces the file size enormously, making it much quicker to transfer over the internet. Once uploaded, our local artists simply append or link that data into the latest render scene in order to get the remote artist’s updated animation.

We use Dropbox (dropbox.com) heavily for this, and since the master edit/composite file refers to the Dropbox folder for each remote artist, all the latest animations are ‘automagically’ updated in the edit. - JN

13. Use Rigify for rapid rigging

Rigify is an incredibly useful tool for getting characters rigged in a jiffy. Instead of spending days setting up a rig by hand, adding constraints, scripts and controllers, it makes the entire process a five-minute affair.

Rigify is actually a plug-in, but it’s distributed with the latest releases of Blender. (I’m using version 2.56.) Before you can use it, you need to enable it by selecting File > User Preferences > Add-Ons and locating Rigify in the list. Click the check mark.

Blender Driver Scripted Expression Tutorial

Next, add the ‘meta-rig’ (the default initial rig you will use to create your own custom set-up) via Add > Armature > Human (Meta-Rig). Position and scale this to match your character.

Enter Edit mode, and tweak the proportions further until all the bones line up with your mesh. Remember to use X-Axis Mirror in the Armature tools panel.

Go back to Object mode, and locate the Rigify Buttons panel in Armature Properties. Click Generate to create your final rig and discard the meta-rig. Parent your mesh to your generated rig and select With Automatic Weights in the popup.

The last (optional) step is to run a UI script to add a nice interface to the rig. Open the Blender Text Editor, and select rig_ui.py from the data list. Press Run Script in the header, and look in the info panel [N] in the 3D view. You’ll have a nice list of context-sensitive controls for bones. - WR

PROCEDURAL / Random Generative Modeling Technique, David Miller s script that bind Python function into Blender s Driver: David, I hope you don t mind .

As Mike Pan says, in the regular Python you would use a stable value like location and use it as a seed. This allows to get a random-like but predictable result.

seed obj.location.x obj.location.y obj.location.z

result random.Random seed . random

If the seed remains the same, you will get the same result.

By default in Python, the current time is used as the seed. That s why the results are different each frame.

If you need to do it in a driver

Driver

You will have less control, but it s possible too :

It gives you a result between 0.0 and 1.0, using Perlin noise by default. Imagine it as a value from a Clouds-type texture at a given pixel position. You have to provide the position as a tuple x,y,z.

Then you can multiply the result by whatever you want.

Video embedded Variations: Blender drivers for randomizing object the new Object Info node and its random number output could be an alternative to the driver.

Blender 3D: Noob to Pro/Making exe. If you use random Python module in your game, The graphics driver shuts off OpenGL acceleration for screensavers.

Doc:2.4/Manual/Animation/Editors/Ipo/Drivers Log in So you can e.g. use the X location of a driver to or using random values at each animation.

User:Hjaarnio/Manual/Animation/Editors/Graph For example you could use the X location of a driver to Hjaarnio/Manual/Animation/Editors/Graph/Drivers.

Update: New in Blender 2.64 For randomizing material properties, the new Object Info node and its random number output could be an alternative to the driver.

Module Noise. source code. The Blender.Noise submodule. Noise and Turbulence. This module can be used to generate noise of various types. This can be used for terrain.

Page status reviewing guidelines

This page is a copy of the same page in 2.4 manual, need to be updated

Drivers are used to control the animation of one property based on the value of another. This means that their animated value is not controlled by the frame number, but rather by any specified channel. Drivers can take their effects from single properties, differences in rotation, or scripted Python expressions which can be edited inside the UI controls.

For example you could use the X location of a driver to control the colors RGB curves of a material, use the rotation of a driver to control the scale of an object, use the scale of a driver to control the shape through shape keys of a mesh/curve/etc., use a python function to control a constraint s influence, and much much more

One key usage of drivers is in character animation: for example, you can add object drivers to the relative shape keys of a face. Then, you manipulate the expressions of your character just by moving these drivers objects which are set unrenderable, of course.. A bit like using the NLA, but even more friendly. See Driven Shape Keys.

Although their interface and function is similar to that of an F-curve, they sit outside Actions, alongside them in the animation system hierarchy. Drivers are evaluated after Actions, so any F-Curve animation that may be in Actions on the data block will be overridden by the effects of a Driver.

A driven curve is not controlled by time yes, we insist, but it s very important to understand this. It s rather its driver s property changes that control where along the X axis of the curve its value is to be taken i.e. the curve now maps the driver s property value to the curve s property value.

By default, there is a 1 to 1 mapping between the input value, and the output value, defined by a Generator F-Curve Modifier. You can create a custom mapping by deleting this modifier and entering keyframes into the graph area by pressing Ctrl LMB.

To create a driver, find the desired attribute you want to drive, in the properties panel. This will be the attribute that will be driven by another attribute.

RMB on the channel and select one of the following options:

This will create drivers for channels related to the selected one. For example, it will add drivers to the X, Y, and Z translate.

This will just add a single driver to the selected channel.

After you have created a driver, you need to specify how that channel will be driven, and by what.

The driver editor is located in the Graph Editor. You can switch from the F-Curve Editor view to the Driver view using the menu on the header.

The Driver editor displays all driver in the current scene. They are listed in the Channel pane on the left side.

If you have multiple drivers in the scene, you can toggle their visibility in the graph area. Also, you need to select the specific channel to begin editing it.

The driver s properties are located in the Properties Panel on the right side. This panel is hidden, by default - you can open it by hitting N.

Refreshes the drivers connections.

There are several different driver types that define how the input value of the driver is calculated:

Takes the highest value of the user variables.

Takes the lowest value of the user variables.

Takes the sum of user variables

Averages the values of the user variables

Computes a value based on a simple python expression, which can also make use of user variables. see below

User Variables are what produce the input values for a driver. You need at least one variable, unless you are using a scripted expression. When using a single variable, all the driver types listed above, except scripted expression, will produce the same value.

Use the Single Property type to call an arbitrary unique datablock from anything within the scene. This can be anything from the intensity of a lamp, to the color of a texture

This type allow you to control curves through an object s transform properties – hence, one driver can control separately up to nine curves the three components of its location, rotation and scale.

Select the channel you want to drive.

In the OB field that appears, enter the name of the chosen driver object.

Unless your driver is an armature, you have only one choice in the Driver type drop-down list, Object.

Scripted

Select in the second drop-down list the property you want to drive your curve Loc X, Scale Z, etc..

Choose the space in which the driver s tranform channels are evaluated

Now, your curve is no more directly controlled by the time, but rather by the value of the property you chose. The values are in Blender Units.

In this example, we are going to control the size of the well-known monkey head Suzanne with the Y-location of the Empty driver. So, we Add Driver to the three ScaleX, ScaleY and ScaleZ channel of the Suzanne object as usual, if there is no curve yet, it is automatically created. Note that for now, there is no curve, so Blender applies a one-to-one mapping, as if there was virtual unitary gradient linear curves materialized as yellow dashed lines in the pictures below. This also illustrates that you can use the same driver property here, the Y location for several different drivers

Note that the Curve Editor window is pinned to Suzanne s F-Curve which allows us to select and grab the Empty object while keeping under our eyes the curve it drives..

The empty driver at Y 1.0 gives Suzanne a scale of 1.0

With driver at Y 2.0, driven s scale at 2.0

And driver at Y -2.0, driven s scale at Oh, I think you got it.

Now, we can use curves on drivers to get more complex behavior than the basic one-to-one mapping. Below, we have the same scene as above, but the ScaleY channel now has a pseudo-sinusoidal curve, oscillating between 1.0 and -1.0 values on a one-frame period, created with three control points and the Cyclic extrapolation E. This means that, while the X and Z components of Suzanne s scale are still directly controlled by the Y location of Empty, the Y scale component now cyclically varies between 1.0 and -1.0, as the following pictures illustrate.

The empty driver at Y 1.0 gives Suzanne a scale of 1.0, 1.0, 1.0

With driver at Y 1.25, driven s scale at 1.25, 0.0, 1.25

And driver at Y -2.0, driven s scale at -2.0, 1.0, -2.0.

Rotational difference works only on bones, but are nearly the same as object ones.

You set up a bone driver by entering in the OB field an armature s name, and then selecting the Pose option in the Driver type drop-down list. Then enter the bone s name in the BO field that appears, and select its property to be used.

Note the following specificities:

The transformations are evaluated in the bone s space i.e. parent bone s transformations, as well as whole object s ones, have no effects.

When using the rotation as driver property, you ll find a limitation: the evaluated bone s rotation is always mapped into a -180, 180 range which means that if you e.g. rotate your bone over the 180 value, the driven object will jump back to its -180 X-curve-position.

You have an extra driver property: Rotation Difference takes the name of another bone, and uses as driver the angle s value between the two bones.

Distance mode simply takes the distance between two objects or bones

Python expression drivers or pydrivers for short allow you to use one-line Python expressions as input for a channel, instead of using a property of another object, like standard drivers do. An expression in programming is any combination of symbols that can be evaluated to a definite value.

You do not directly control the value of the curve with these pydrivers, but rather, as with the other driver types, you control where along the X axis the curve value should be taken.

To set up an expression driver, change the driver type to Scripted Expression – it will display a standard text field where you can type your Python expression.

These drivers open up many interesting possibilities: you can use mathematical functions and more general programming to drive object animations. The only restriction is that the pydriver expression itself must return a real number when evaluated, and not e.g. a string or something else.

Examples would be using sines or cosines to make objects oscillate around a given point, or using random values at each animation frame to change some material attribute, like diffuse rgb, alpha, etc.

Note that pydriver evaluation is equivalent to what the builtin eval function does, with the restriction that pydriver expressions must return real numbers any type of number that can be automatically cast to a float.

We ve already told the basics: there is a text field where you can type an expression in Python. Here are some examples of valid expressions:

Expressions with numbers and operators: 4.5 8.9 7.0 - 2 / 3.0

Expressions also with variables:

Available data: bpy.data.scenes Scene. frame_start the start frame

A little math: sin frame the sine of the current frame

The variables added below the expression field, via their names set in the name field

Pydrivers use their own global dictionary that is cached and only gets recreated when any expression fails. In this dictionary, a few modules are pre-imported, so that they can be used inside pydriver expressions.

All from builtin the default builtin module

The current frame number also for in-between frames, not only in integer numbers as frame

Adding functions and variables to the namespace

You can create your own functions and add your own variables without the restriction of the one-line Python expression.

Acces to the namespace available to the drivers is achieved via bpy.app.driver_namespace, a read-only dictionary edited in-place. It is reset on file load and in new files, so rerunning the script that edits the namespace is necessary.

Example of adding custom function in a script run from the text editor or python console:

def driverFunc val : return val val bpy.app.driver_namespace driverFunc driverFunc

All drivers can access this function from the expression directly.

driverFunc frame the defined function with current frame as input value

Let s say we want to give our Suzanne a perfect two BU radius circle movement in the XY plane. This is not easy to achieve with standard curves, as you have to create perfect sinusoidal ones for those who lost their math, a perfect circle in a Cartesian plane is obtained with x sin t and y cos t. So let s use Python drivers:

The sin and cos math functions take as input a radian value i.e. a cycle takes 2π frames to complete, and output a value in range -1.0, 1.0. So, to get a 2BU radius circle fully walked in 50 frames, we have to use the following Python expression:

For LocX: 2.0 sin bpy.context.scene.frame_current pi/25

For LocY: 2.0 cos bpy.context.scene.frame_current pi/25

Now, Suzanne will go in endless circles around the world s origin if you want to make it turn around another point, just add an offset to the above expressions, or drive dLoc curves.

In the above example, we did not use F-curves.

You can also get a perfect circular movement by using a NURBS circle curve as a path

I would like a driver that gives different result when duplicating the object but stays constant on frame update, transformations, etc noise.random gets updated on.

How do I create a driver with a random value and apply that driver to How do I create a driver that creates a random but laminar random driver blender.