CPSC 324, Spring 2004
Lab 8: Blender Curves and Animation
IN THIS LAB, we return to Blender. The main topic of the lab is animation. However, animation is closely related to curves, so we will start with a look at how curves are used in modeling. And since text in blender is very similar to curves, the lab also covers text.
Text
You can add text to a Blender scene by using the "Text" command in the "Add" menu. The text object will show up as the word "Text" displayed in Blender's default font. As with any object, the text is in edit mode when it is first added. When a text object is in edit mode, you can edit it by typing characters. You can hit return to start a new line of text. You can delete characters with the backspace key. You can use the arrow keys (but not the mouse) to move around inside the text. Don't forget to hit TAB to get out of Edit Mode! Once out of edit mode, you can scale, rotate, and translate a text object just like any other object. You can also add materials and textures.
You can do even more with text by using the Edit Buttons. Hit F9, or click on the little Edit Buttons icon, to see the Edit Buttons at the bottom of the screen. The Edit Buttons apply to the currently selected object, and what buttons are available depends on the type of object that is selected. Reminder: Select an object by right-clicking it; you should not be in Edit Mode. When a text object is selected, the Edit Buttons will include a variety of buttons that can be used to modify the text:
The buttons on the lower right of this picture can be used to make the text into a 3D-object. The number button labeled "Ext1" can be used to add thickness to the text object. (This might not be visible in the World Window, if you are still looking at text straight on, but it will be visible if you rotate the view.) The button labeled "Ext2" will add a "bevel" along the edges of the letters, which gives the edges a rounded appearance. (Adding a bevel also adds to the thickness.) If you have a bevel, the button labeled "BevResol" will increase the resolution, or smoothness, of the bevel. (Hint: To get a better idea of the effect of these buttons, hit the "Z" key in the World Window to get a "solid" view of the objects in the scene. Hit the "Z" key again to return to the standard wireframe view.) The "Width" button in this group of buttons controls the width of individual characters.
In the group of six buttons on the left side of the image, the "Spacing" button controls horizontal distance between letters. The "Linedist" button controls vertical spacing between lines, if there are multiple lines in the text object. The "Shear" button is used to slant the letters. Looking higher, the "Left", "Right", "Middle", and "Flush" buttons control the justification of multiple lines of text. For example, "right justification" means that the lines are moved so that their right ends line up.
Above the justification buttons, you will find the "Load Font" button, which can be used to load new fonts. Blender can use any Postscript Type 1 font. I have made some fonts available in the folder /home/cs324/blender/fonts. When you click the "Load Font" button, the World Window will change to a File Window. Find the font file, click it, and hit return (or just click it with the middle mouse button). Fonts that have already been loaded can be selected from the pop-up-menu-button above the "Load Font" button.
Bonus Info: Simple Landscapes. Here is how to make a simple "hilly" landscape like the one in the picture above: Add a Mesh/Plane object to the scene, and scale it up to be fairly large. Make sure that you are in Edit Mode and that all four vertices of the plane are selected. Go to the Edit Buttons, and find the button named "Fract Subd" (meaning "Fractal Subdivide"), and hit it a few times. (You will be asked to confirm a "Rand Fact" of 10 each time.) Then, hit the "Set Smooth" button to avoid having a jagged landscape. Try adding a smooth blue plane that cuts through the landscaped plane, to get an appearance of land and water!
Curves
Blender supports two types of curves for modeling: Bezier curves and NURBS curves. For now, we will stick with Bezier curves. Blender always fills in the interiors of closed curves. Just as with text objects, you can give the curve object a thickness in the third dimension. Text objects are actually very similar to curves. In fact, you can convert a text object into a curve and then edit it the same way you would any curve. (However, there is no way to convert it back to a text object.)
To get a curve to work with, you can just add a Bezier curve to your scene, using the command Add/Curve/Bezier Curve. You will get a short curve with a point on each end. To edit the shape of the curve or the number of points on the curve, you have to work on it in edit mode. In edit mode, each point has two attached handles. You can select and drag the point to move the point itself. You can also select and drag a handle to change the shape of the curve. Remember: Use right-click to select and shift-right-click to add to a selection. Use the "B" key followed by left-click-and-drag to "box select" a group of points. Use the "G" key to initiate a drag operation -- even when the thing you want to drag is one of the handles of a Bezier curve. (Note: You see the points and handles only when the curve is in edit mode.)
To add points, select one of the points at the end of the curve by right-clicking it. You will add new points at that endpoint of the curve. After right-clicking the endpoint, you can then CONTROL-click with the left mouse button to add new points joined onto that end of the curve. After adding as many points as you want, hit the "C" key to close the curve by connecting the endpoints. Then, you can shape the curve by moving the points and adjusting the handles. Note that a simple way to get a closed curve with a given number of points is to add a Bezier Circle to the scene, instead of a simple Bezier curve.
The handles on a Bezier curve. come in several styles. Select a control point and hit the "H" key. You will now be able to drag each handle separately to make corners on the curve. Hit "H" again to return to the default mode, in which the two handles are forced to make a straight line. If you select a control point and hit the "V" key, it will turn into a corner vertex, where the handles always point along a line to the next control point; this lets you make polygons easily. If you select two or more control points in a row, and go to the Edit Buttons, you can use the "Subdivide" button to add new control points between the selected points.
If you have a closed curve and hit the "Z" key for a shaded view, you will see that the curve is filled in. (You also have to leave edit mode to see the shading!) Now, while you are editing the curve in edit mode, try adding a Bezier Circle to the scene. When you add a new curve while you are in edit mode for another curve, it is not added as a separate object. Instead, it becomes part of a single, multi-part curve. Position the circle so that it lies entirely within your original curve. Scale it if necessary. Now, when you leave edit mode and hit the Z key, you will see that Blender only fills in the area between the curves. So, using multi-part curves, it's possible to create fancy shapes with holes in them.
You can add a third dimension to a curve, just as you can for text. Leave edit mode. Make sure that the curve is selected. Go to the Edit buttons, and use the buttons named "Ext1", "Ext2", and "BevResolv". For the curve object shown, "Ext1" has been used to add thickness, but there is no beveling.
Although a text object is not a curve, you can convert it to a curve. To do this, select the text object and hit ALT-C. You will get a pop-up that lets you convert the text to a curve. One reason for doing this is that you can then enter edit mode and edit the vertices on the individual letters. Also in Edit mode, you can add more curves that become part of the same multi-part curve object. For example, for the picture shown at the left, I started with a text object (using the "linotext" font), and converted it into a curve. I entered edit mode and added a Bezier curve. I added two points to this curve before hitting "C" to close it. I selected each point on the curve and hit "V" to make it into a simple corner vertex. I dragged the four points to make the new curve into a rectangle that surrounded the text. I then added some thickness and beveling. The beveling closes off the hole made by the text in the rectangle, so it looks engraved.
Tracking
It can be difficult to aim a spotlight or a camera at an object, especially if that object is moving during an animatin. One easy way to do it is to use "tracking." When one object tracks another, the tracking object rotates to keep the same face pointed at the object that is being tracked.
Suppose that you want a spotlight to shine directly on some object. Select the spotlight by right-clicking it. Then SHIFT-right-click the object that you want the light to shine on. This adds the object to the selection. (It is important that you do this in the right order. The object that you right-click first will track the object that you shift-right-click second.) Now, hit CONTROL-T. This is the command for setting up a tracking relationship between two objects. You will be asked to verify that you want to set up tracking. This will make the spot light point at the object. Whenever you move the object, the light will turn to follow it. If you animate the object, the spotlight will follow the object as it moves.
If you try to make a camera track an object, you will find that the camera rotates when you move the object, but the camera doesn't point directly at the object. This is because a camera starts out with some rotation already applied to it. To make it point directly at the object, you have to delete this extra rotation. To do this, select the camera by right-clicking it, and hit ALT-R. This is the command for resetting the rotation of an object to zero. Once you do this, the camera should point directly at the object that it is tracking.
You can clear tracking by selecting the object that is doing the tracking and hitting ALT-T.
Sometimes, you want to make a light or camera point at a position where there is no object. You can achieve this by adding an empty object to the scene and setting the light or camera to track the empty object. Add an empty object to the scene by using the Add/Empty command. It will appear as a set of xyz-axes. You can move an empty object just like any other object. You can also animate it. A nice trick is to animate an empty object that is being tracked by a camera or light.
Animation
Blender is designed to do animations. When working with animations, you see only one frame at a time in the World Window. Frames are numbered 1, 2, 3, ... Which frame is visible is controlled by the frames button, as shown at right, which just displays the current frame number. It can be found at the top-right end of the buttons window. You can change the current frame with the arrow keys. The left and right arrow keys move to the previous or to the next frame. The up and down arrow keys increment and decrement the frame number by 10. Shift-left-arrow will return you to frame one. You can also click-and-drag on the frames button to change the frame. And, perhaps most conveniently, you chan shift-click the frames button if you want to type in a particular frame number. If you hit ALT-A while the World Window is selected, the frames will be played in sequence until you hit ESC.
To animate an object, you just have to assign it different positions, sizes, and/or rotations in different frames. You don't have to assign a separate value for each frame. If you assign a value for frame number 1 and frame number 30, for example, Blender will interpolate values for frames 2 through 29. A frame to which you explicitely assign values is called a key frame, and animation that uses key frames is called key frame animation. You can have as many key frames as you want, and each animated object can use different key frames if you want.
To set up a key frame for an object, go to that frame, using the "frames button" that was mentioned above. Set up the object's size, position, and rotation as you want it to appear in that frame. Then hit the "I" key. (The "I" stands for "insert key frame.") You will see the pop-up dialog shown at the right. Just click on the type of data you want to animate. If you are just animating the size of the object, click "Size." If you are animating size, position, and orientation, click "LocRotSize." The bottom entry in the menu is for animating the shape of an object in edit mode. The "Layer" entry can be used to make an object appear or disappear by moving it from one layer to another (assuming that one of those layers is not turned on).
Bonus Info: Layers. You can use layers to organize your work in blender. These are not layers in the sense of being stacked up to make the final view. Objects in different layers are all mixed together in the final image. Layers in blender are used to organize your work. You might set up your lights in one layer and your objects in another layer, for example. You can turn layers on and off using the group of 20 little buttons near the left end of a World Window. Use a SHIFT-click to activate more than one layer at a time. You can also activate layers with CTRL-1, CTRL-2, etc -- or with SHIFT-CTRL-1, SHIFT-CTRL-2, etc to activate multiple layers. To move an object to a particular layer, select the object and hit the "m" key. To have an animation, you need at least two key frames, so go to a different frame, move or otherwise change the object, and use the "I" key again to insert another key frame. Once you've done this, you can use the arrow keys to move from frame to frame. You should see the object's animation. If you want more key frames, just repeat the process.
Warning: Once an object has been animated, it gets is transformation from the animation data. This transformation is applied every time the frame number is changed. You might change the object in one frame, but the change will not be permanent unless you use the "I" key to insert new animation data. In particular, if you are setting up an animation, don't forget to hit the "I" key before changing the frame number!
You can animate cameras and lights in the same way as any other objects. If you are animating the camera, you will want to preview the animation in the camera view (Keypad-0).
Animated Materials
You can also animate material properties of objects. To do this, go to the desired key frame, select an object, make sure the Material Buttons are selected (F5), and point the mouse at the Material Buttons Window. Hit the "I" key. With the mouse over the Material Buttons, you will get a different Insert Key menu, as shown to the right. To animate the color of an object, select "RGB" from this menu. The "Alpha" entry allows you to animate the degree of transparency of the object. (The alpha value of an object can be set using the slider named "Alpha" in the Materials Buttons -- but note that you also have to turn on the option named "ZTransp" for transparency to work properly. The "ZTransp" option button can be found just to the right of the "Alpha" slider.) The remaining entries animate more advanced features of materials and textures that we might return to in a later lab.
Of course, to get an animation, you still have to go to another frame, change the object's material properties, and insert a new materials key. To preview a color animation, use the "Z" key to switch from wireframe mode to shaded mode in the World Window.
You can animate the brightness or color of a light in a similar way: Select the light, activate the Lamp Buttons (F4), point to the Lamp Buttons with the mouse, and hit the "I" key.
Path Animation
It's possible to make an object move along a curve. A curve used in this way is called a "path" in blender, and the technique is called path animation. You can make a Bezier curve into a path. To do this, select the curve, go to the Animation Buttons (F7), and turn on the "CurvePath" option. One way to get circular motion is to make an object move along a Bezier circle. There is also a special type of object called a Path that can be used for path animation. To add a Path to a scene, use Add/Curve/Path. The path has control points that can be used to adjust the shape of the path. A Path object comes with the "CurvePath" option already turned on.
An object will follow a path if the path is set to be the "parent" of the object. To make one object the parent of another, select the child object by right-clicking it, then shift-right-click the parent object (the curve in this case), and hit CONTROL-P. You will be asked to confirm that you want to make a parent. You can clear a parent relationship by selecting the child object and hitting ALT-P. Parenting is used for other operations besides path animation. For parenting to a path, this might not be exactly what you want: The object will follow the shape of the curve as the animation is played, but it will not actually be on the curve. However, you can easily drag it into position on the curve.
Try it. Add a Path object to the scene. Before leaving edit mode, drag some of its control points around to change its shape. Then hit TAB to leave edit mode. Add a cube to the scene and parent it to the curve. (Right-click the cube, then SHIFT-right-click the curve, in that order, then hit SHIFT-CTRL-P and confirm that you want to make a parent.) Hit the arrow keys to change the frame number and you will see that the cube moves. If you select the path, go to the Animation Buttons, and turn on the "CurveFollow" option, then the cube will get its orientation from the path. As it follows the path, it will rotate so that it is always facing along the direction of the path. (If you have applied a rotation to the cube, that rotation will be added to the rotation it gets from the path. You can clear the cube's built-in rotation by selecting it and hitting ALT-R.)
You can apply path animation to a camera. Parent the camera to the path using SHIFT-CTRL-P, and the camera will follow the path. This technique can be used to make "fly-through" animations. It's possible that you want the camera to point in the direction of the curve: Just select the curve, and turn on the "CurveFollow" option in the Animation Buttons. For a fly-through you will probably want to clear the camera's built in rotation so that it points straight ahead along the curve: Select the camera, and hit ALT-R. You could use the same technique to make an airplane fly along a path. This technique is used in the sample file /home/cs324/blender/flythrough.blend. On the other hand, you might want the camera to move along the path but to track another object. There is nothing to stop you from applying both tracking and path animation to the camera. This is done in the file /home/cs324/blender/bounce.blend.
The length of the path -- the number of frames that it takes for an object to move along the path -- is set for a Bezier curve using the "PathLen:" button, which you will find next to the "CurvePath" toggle in the Animation Buttons.
Saving an Animation
An animation can consist of a large number of frames, so you have to think about the disk space occupied by all those frames. Blender allows you to save animations in several different formats. One option is to save all the frames in separate files. This can be useful for further processing, but when you publish your animation, you want it all in one file. Blender can do this for you. Blender can save animations in Microsoft's AVI format. It can make two types of AVI files: "AVI Raw" and "AVI Jpeg." AVI Raw files are uncompressed and are huge. You should avoid them. AVI Jpeg files use JPEG compression and are a more reasonable size. Unfortunately, old versions of Microsoft's Media Player cannot deal with AVI Jpeg.
To save an animation in Blender, you must work in the Display Buttons (F10). The first thing to do is to set up a name for the file or files that will contain the animation. This is done by filling in the label at the upper right corner of the World Buttons. Click on this label if you want to enter a new value. A "//" at the beginning of the name refers to the current directory (that is, the directory from which Blender was run). You could also enter a full path name. If you want to create an AVI file, for example, you might put "//myanim.avi" in this label. If you are going to store the frames in separate files, it is advisable to put the files in a subdirectory. Blender will use the name that you specify and tack "0001", "0002", "0003", "0004",.... on to the file names. For example, the setting "//frames/pic" shown here in the example means that the frames will be stored in a subdirectory named frames in the current directory and that the individual frame files will be named "pic0001", "pic002", and so on. The other animation controls are found on the right side of the Display Buttons:
Near the middle of this picture is the pop-up menu that is used to select the format of the output. Here, it is set to "AVI Jpeg." If you want to save the frames in separate files, use plain "Jpeg" as the format. For an animation, you might want to turn down the "Quality" to reduce the image size. You can also set the number of frames per second for an AVI file using the "Frs/sec" button. The "SizeX" and "SizeY" buttons control the image size. The "Sta" and "End" buttons are used to set the starting and ending frame number for the animation. Here, with Sta set to 1 and End to 150, you will get an animation with 150 frames. (The Sta and End values also affect the preview animation that you see when you hit ALT-A in the World Window.) You might want to check the settings of some of the other Display Buttons ("Shadows" and "OSA" at least). When you have everything set up, click the ANIM button, and Blender will render the animation. When the rendering is done, you can get Blender to show you the finished animation by clicking on the "Play" button. The animation will play until you hit the ESCAPE key.
Here are links to AVI Jpeg animations produced in this way from the sample files bounce.blend and flythrough.blend:
bounce.avi (1.6 megabytes, 150 frames)
flythrough.avi (2.5 megabytes, 300 frames)
This lab has not exhausted the topic of animation in blender, but you should have plenty to work with for now. We will return to animation in a future lab.
Exercises
Exercise 1. Use blender to create an attractive still image that uses either text or curves or both, and add the image to your Web site along with a short explanation of how you made it. Pay attention to the lighting of your scene, and don't forget to use antialiasing when you render it.
Exercise 2. Make an interesting blender animation that uses either path animation or tracking or both. Create an AVI Jpeg animation file, and put a link to it on your Web site. Also, render two or three individual frames from the animation and post them on your web site.