Thursday, January 7, 2010

IPO Drivers and PyDrivers

Join my Blender 3D forum, where you can network with other Blender friends and get your Blender 3D questions answered.

Download the blend file with the code for IPO Drivers and PyDrivers



With basic Blender animation, you create keyframes at different frames in your animation, and then Blender's IPO system fills in the blanks (the technical term is "interpolates") values for the frames in between. Sometimes you might want to base a particular part of the animation of one object, such as its location, rotation, or size, on the action of another object. This is where IPO drivers come into play. For even more sophisticated control, you can create a Python expression to do some really wild things. The purpose of this video is to introduce you to both IPO drivers and Python drivers (aka PyDrivers) so that you can really spice up your animations.

Steps:
1) Keep the default cube. Add Suzanne above the cube. Get rid of the 3D Transform widget, which gets in the way of this demonstration.

2) Go to the setup menu. Choose SR1-Animation. The animation setup is very convenient for animation. It consists of an outline window on the extreme left, a 3D window on the middle, and an IPO Curve Editor window on the right. Additionally, there is a timeline window under the 3D window and IPO Curve Editor window, and a Buttons window at the bottom.

3) Let's animate the monkey's movement along the X axis. We'll set the length of the animation to 50 frames by setting the End frame to 50. We're at Frame 1. Insert a Loc keyframe by pressing the I key and selecting Loc. Move to Frame 50. Note how the vertical green line in the IPO window moves to Frame 50 as well. Move the monkey 5 blender units to the right. Then press the I key and select Loc. Note that a curve is generated in the IPO window. We can't see all of it. To see all of it, from the View Menu of the IPO Curve Editor, select All. Alternatively, you could have pressed the Home key.

Interestingly, there are 3 curves that were created, corresponding to LocX, LocY, and LocZ. Left click on LocX. The highlighted curve a curvy line, from 0 to about 5, corresponding to the blender units on the X axis for the monkey's position. There are 2 dots that represent the end points of the curve, at frames 1 and 50. You placed the monkey at a specific X location on Frame 1 and Frame 50. Blender interpolates, in what's called a Bezier interpolation, the monkey's location for the frames in between. The monkey speeds up in the earlier frames, goes relatively constant, until the last 10 or so frames, where the monkey slows down.

An alternative interpolation method is called Linear. In this case, the monkey's speed is constant. Actually, Bezier is a more realistic type of interpolation. Feel free to experiment. To change to linear, select Curve - Interpolation Mode - Linear, from the IPO Editor Window. Press Alt-Shift-A to animate, which animates no matter where the cursor happens to be. Now the speed of the monkey is constant. Press Esc to end the animation.

Left Click on LocY. The monkey's Y location stays at roughly 3 blender units for the entire animation. Let's change that in the IPO Curves Editor window. To do that, select LocY. Press Tab to go to Edit mode. We're going to change the end Y location of the monkey. Right click to select the end point. Press the G key. Left click and drag to about 5 Blender units, giving a Bezier type curve in the Y direction. Press Alt-Shfit-A to animate. Now the monkey goes up in the Y direction as well as across in the X direction. Press Esc to end the animation.

The LocZ curve also was created. The Z position of the monkey stays at 0 no matter where we are. You won't see the Z location change in top view because we're looking down, in the negative Z direction. Press Num 1 to go to Front View. This time, we'll make the monkey jump up and down. Press Tab to go to Edit mode. We'll change the LocZ by adding a point on the curve. To do this, position the cursor about halfway between the beginning and the end and press Ctrl-Left Click. This creates a new point. Press the G key and drag the curve up 3 Blender units. Press Shift-Alt-A to animate. The monkey jumps up and down. Press Esc to end the animation.

4) Great! We've animated the monkey in 3 directions. Now suppose we want to make another object, like the cube, follow the monkey. If you shift-Left Click on LocX, LocY, and LocZ, you'll see that our animation is a bit complicated to copy. Select the cube. Trying to copy these curves is tedious. Also, if we change the monkey's animation, we'd have to redo the cube's animation. Very quickly, I think we'd give up.

This is where IPO drivers come into play. We want the cube to follow the monkey in the X direction no matter where the monkey goes. To do that, select the LocX channel (that's the technical name) in the IPO Curves Editor. We're going to add a driver. Click the Add Driver button. In the Ob: area, enter the name of the monkey mesh, Suzanne. There are 9 possible channels that can drive the cube. Select LocX. Note the dotted rectangle icon representing a driven LocX channel. Press Alt-Shift-A to animate. See how the cube follows the monkey across.

5) With a PyDriver, we can get even more cute. Suppose we want the cube to follow only at half the speed of the monkey in the X direction. Press the N key in the IPO Curves window to bring up the Transform Properties window. Press the little snake icon (I guess it's a python). You can enter a Python expression, in this case:

ob("Suzanne").LocX/2

Make sure you enter this exactly, observing the case. Otherwise, Python will give you an error message. Press Shift-Alt-A to animate. Note that the cube is only going half as fast as Suzanne in the X direction. Press Num7 to go to Top View. Press Shift-Alt-A to animate. The animation works the same way in top view. This would not work be possible with a simple IPO driver. You can animate multiple objects. Try doing a "monkey race" with different denominators for each monkey's speed relative to other monkeys. You can also animate rotation and scale. Imagine the possibilities. This animation can be used in the game engine, as your aliens and monsters fight each other.

I hope this has given you some ideas about how to animate your Blender projects. If you liked this, click the big Subscribe button in Youtube so you won't miss any of my Blender tutorials. Happy Blendering.