利用者:Koilz/29.11.13 wiki - Driver Reference

提供: wiki
移動先: 案内検索


Animation Tools: Drivers

Drivers

Graph Editor: Driver example.

Drivers can use properties, numbers, transformations, and scripts, to control the values of properties.

Using a F-Curve, the driver reads the value of the Driver Value and sets the value of the selected property it was added to.

So from this example, if the Driver Value is 2.0 the property will be 0.5.

The Driver Value is determined by Driver Variables or a Scripted Expression.

Most the settings for the drivers F-Curve are found in the Graph Editor.


Adding Drivers

To add a driver to a property, find the property you want to add driver to.

RMB Template-RMB.png on the property and select one of the following options:

Add Drivers
This will add drivers to the set of properies related to the selected one.
For example, it will add drivers to X, Y, and Z for Rotation.
Add Single Driver
This will add a single driver to the selected property.
Add Single Driver.

Drivers Panel

Graph Editor: Drivers: Drivers Panel.
This panel is for setting up the Driver Variables or Scripted Expression which determine the value of the Driver Value.

Driver Settings

Update Dependencies
This will force an update for the Driver Value dependencies.
Remove Driver
Removes the driver from the object.
Type
The type of calculation to use on the Driver Variables.
Average Value
Uses the the average value.
Sum Values
Uses the the sum.
Scripted Expression
Uses a Scripted Expression. See Expr.
This option does not use the variables, but they can be added to the scripted expression.
Minimum Value
Uses the lowest value.
Maximum Value
Uses the highest value.
Expr
Scripted Expression.
Here you can add real numbers, math operators, math functions, python properties, driver functions.
See Driver Expression below for some examples.
Show Debug Info
Shows the Driver Value.
The current value of the variables or scripted expression.
Add Variable
Adds a new Driver Variable.
Setup of a Single Property.
Transform Channel setup.
Distance setup.

Driver Variables

Name
Name to use for scripted expressions/functions.
No spaces or dots are allowed and must start with a letter.
Variable Type
The type of variable to use.
Single Property
Use the value from some RNA property.
For example, the Ambient shading color from a material.
First select the type of ID-block, then the ID of the ID-block, then copy and paste an RNA property (Ctrl+V).
ID-Type
The ID-Block type, example, Key, Image, Object, Material.
ID
The ID of the ID-Block type, example, Material.001.
RNA Path
The RNA id name of the propery, example, 'ambient' from material shading.
Transform Channel
Use one of the Transorm channels from an object or bone.
ID
ID of the object, example, Cube, Armature, Camera.
Bone
ID of the Armature bone, example, Bone, Bone.002, Arma.r.
This option is for armatures.
Type
Example, X Location, X Rotation, X Scale.
Space
World Space, Transform Space, Local Space.
Rotational Difference
Use the rotational difference between two objects or bones.
Distance
Use the distance between two objects or bones.
Value
Shows the value of the variable.


Driver Expression

Here are some examples of using the scripted expression Expr to set the Driver Value.

Object Rotation.

Object Rotation

Here two drivers have been added to the Cube, X Location and Y Location.

The scripted expressions are being used to set the object location.

X Location Expr
0+(sin(frame/8)*4)
(frame/8): is the current frame of the animation, divided by 8 to slow the rotation down.
(sin( )*4): This returns the sine of (frame/8), then multiplies by 4 for a bigger circle.
0+: is used to control the X Location offset of the rotation.
Y Location Expr
0+(cos(frame/8)*4)
(frame/8): is the current frame of the animation, divided by 8 to slow the rotation down.
(cos( )*4): This returns the cosine of (frame/8), then multiplies by 4 for a bigger circle.
0+: is used to control the Y Location offset of the rotation.

frame is the same as bpy.context.scene.frame_current.

Driver Namespace

There is a list of built in driver functions and properties.
These can be displayed via the python console.
>>> bpy.app.driver_namespace['
                              __builtins__']
                              __doc__']
                              __loader__']
                              __name__']
                              __package__']
                              acos']
                              acosh']
                              asin']
                              asinh']
                              atan']
                              atan2']
                              atanh']
                              bpy']
                              ceil']
                              copysign']
                              cos']
                              cosh']
                              ..
This script will add a function to the driver namespace, which can then be used in the expression driverFunc(frame).
import bpy

def driverFunc(val):

    return val * val    # return val squared

bpy.app.driver_namespace['driverFunc'] = driverFunc    # add function to driver_namespace

See Also

Links