Linking Animation Data


It's good to start simple, but the bread and butter job of expressions is to link animation data when, for whatever reason, the other means of linking data will not do. Other linking methods all have their place, but have their limitations as well:

  • Parenting is a great way to link translation data between layers, but not if you want to exclude part of the datafor example, to include position but not rotationor if you want to link translation data to properties, such as brushes and effects positions, that are tied to effects rather than the layer itself.

  • Pre-composing allows you to group layers, but not to link their actual data in more sophisticated ways.

  • Copying and pasting keyframes is possible and will even allow you to copy data from one property over to a completely different property, but the link is not "live." If anything changes with the source, you have to recopy to the target, and you cannot easily scale or offset the result, nor go from a one-channel to a multiple-channel property or vice versa. Furthermore, this method has a high possibility of user error and is largely outmoded by the expressions pickwhip (Figure 10.3).

    Figure 10.3. The pickwhip in action: Set it by dragging from the pickwhip item to the target property.


None of these methods lets you do more complex relationships, such as setting up a nonlinear relationship between two sets of values (for example, doubling or squaring the keyframe values).

Following are some practical examples of linking data via expressions, with explanations of what is really going on so that you can devise your own practical applications. These examples save you from having to type code by leveraging use of the pickwhip, a nifty tool for grabbing bits of data and turning them effortlessly into useful bits of code (which you've already seen used with Parenting and Post Render Actions).

Tracking Brushes and Effects

Chapters 7, "Rotoscoping and Paint," and 8, "Effective Motion Tracking," alluded to a method for combining paint tools and the tracker. The problem is a simple one: How to apply tracker data to a brush to automatically paint out an element in motion?

The only one of the above alternatives to expressions that could work in this case would be copying the attach point of the tracker, highlighting the Position value of the brush in question, and pasting, but what if the result doesn't look quite right and you need to retrack it?

The simpler, more flexible solution is to use the pickwhip, and in cases where you are setting up a one-to-one relationship between two properties, that is all you need. I'll show you some less straightforward cases in a minute.

Figure 10.4 shows a clip of a plane landing in the distance; let's say that this plane needs to be painted out to be replaced with a 3D model of a flying saucer. The Track Type could be set to Raw because I'm applying the tracking data via expressions only. The attach point can be offset so that it sits at the center of the airplane, although offsetting it is also simple, as you'll see.

Figure 10.4. A raw track of the plane has been generated. The dips and swirls in the motion are due to the shot having been taken with a hand-held camera. The camera Track Type is set to Raw.


Having tracked the plane, I return to the first frame and use the Clone Stamp tool to eliminate the plane on that frame by painting over it with surrounding cloud cover (any adjacent area of the same frame works). I can use a nice big brush (100 or more pixels) to eliminate the plane by clicking once in roughly the same place as I placed the attach point (the center of the airplane). Best in this case is to clone out the unwanted object in one stroke, so that you only have to join the tracker to that one, but it's possible to repeat this step.

With the layer highlighted in the timeline, I press UU to expose the tracker and brush data. I set an expression on the Position of the brush, then drag the pickwhipthe swirly icon in the center of the threeup to where I see the words, "attach point."

Geek Alert: Unpacking Syntax

Okay, so you're not satisfied until you understand that little piece of code you just grabbed, although you're wary of delving into code. Take a closer look at the syntax of that brush stroke:

 motionTracker("Tracker 1")("Track Point 1"). attachPoint 

This works similarly to how pathnames work in Unix or Windows: Starting at the left, motionTracker contains Tracker 1, which has a Track Point 1, which in turn contains the property you're after, the attach point.

What's up with the parentheses, the quotations, and the dot? Parentheses in JavaScript contain arguments, which are specifics needed to clarify settings, in this case, telling After Effects which point, in which tracker, you're after. The motionTracker property is unusual in that it needs two sets of arguments, each in its own set of parentheses. The dot works the same way a forward slash would in Unix (or a back slash in Windows): It identifies the next level down in the hierarchy, like looking inside a folder.

Keywords in expressions use inter-caps, so that a keyword is made of two words with no spaces. For example, motion tracker and attach point, end up as motionTracker and attachPoint, respectively.


Done. The resulting expression looks something like

 motionTracker("Tracker 1")("Track Point 1"). attachPoint 

But why sweat the syntax? I've just set up an automatic link between these two properties, and with the pickwhip, I can always grab available data in this manner.

Offsetting an Element

Now let's say that instead of painting out the plane, I want to add a flying saucer tracking it from a higher altitude and left of frame. I could apply the tracker to a null and parent the repositioned element to that, but it would be simpler to offset the same expression I just used, now applied to the Position value of the saucer. To start, I again pickwhip from the saucer's Position to the track's attach point.

Offsets are quite intuitive even to people who don't understand JavaScript very well. Perhaps you want to offset a value by 100. What would you add at the end of the default expression text? That's right, 100. Try it on a Position value and it workskind of. The object moves 100 pixels, but on the X axis only.

Position is an array, a property with multiple values. A 2D Position property has two values, X and Y, and a 3D layer's Position would add a third (as would Anchor Point and Rotation, which otherwise has one value). So while offsetting and scaling values is simpleyou use the basic math operators (+, -, *, /)things get slightly less straightforward with arraysbut only slightly.

An array value is written in expressions as [x, y] for a 2D value or [x, y, z] for 3D. So if you want to mute a Position keyframe at the center of a 720, 540 frame, you enter [360, 270] (half each value), and if you want to offset each value by negative one hundred (-100), you add -[100, 100] after the pickwhip data to add the offset (Figure 10.5). If you needed to mix a positive and negative offset of 100, that would be simple too: instead, add + [-100, 100] or +[100, -100] and so on.

Figure 10.5. The Position value of a Paint stroke is a two-dimensional array; the highlighted text shows how to perform a simple offset of such an array.


Yes, this is quick and dirty; the goal here is to offer you the low-hanging fruit, the things you do all the time with expressions that are easy to pick up. A more elegant way of setting a constant position at the center of the frame would be

 [thisComp.width/2, thisComp.height/2]  

because this expression would adjust itself to any composition size. There are typically many ways to write any expression; the simplest (with the fewest lines or operations) that applies to the greatest number of variables (such as changes in the comp size) is typically the preferable one, as with all coding.

One Channel Only

Okay, now suppose you need to link something on one axis only: say, heads-up display pointers that move up and down along the left and bottom edges of the frame, tracking the enemy craft (not a typical effects scenario, but one that easily demonstrates what I'm after). This time what you want to do is keep the value of one axis in a static position, and to apply your track to the other axis.

This gives you the opportunity to learn a useful new bit of syntax. You know how to write an array, but how do you identify one portion of the array? Like this

 [position[0], position[1]] 

Whoa, more brackets. Once again, you're expressing position as two values separated by a comma in brackets, but the values themselves are identified by trailing numbers in brackets. The numerical order starts at 0, not 1, because this is how programming languages generally work.

So, to keep the existing value on the X axis and the track on the Y axis, you would enter position[0] (or a static value, like 400) before the comma and pickwhip the Y value to the Y value of the attach point. That's right, not only can you pickwhip to the attach point, but if you drag the pickwhip instead to just one of its valuesthe second one, in this caseyou get the code linking you only to that value (Figure 10.6). Once again, the pickwhip has saved you from typing in some gnarly code, but you need to know the simple stuff.

Figure 10.6. You can pickwhip from a single channel of an array (a property with multiple values) to the corresponding single channel of a separate array.


To do the same on the other axis, just reverse the steps, pick-whipping before the comma and entering position[1] following it.

This rather trivial example has hopefully elucidated a powerful concept, of using expressions to apply data to one channel only. This is the first example we've examined that would truly be impossible without expressionsnone of the alternative methods offer a method to apply animation data to only one channel of a property.

Building Your Own Controls

Here's another really cool, really basic thing you can do with expressions: link effects controls to properties to allow you to control them in the Effects Control window. It's incredibly simple, too.

The effects found within the Expression Controls sub-category don't do anything until you attach an expression to them. That's all they're for, to offer you a user interface for adjusting your expressions values on the fly. The one you'll most often use is likely Slider Control, but look carefully at the other five, as each produces a different result (Figure 10.7).

Figure 10.7. Here's the full array of available expression controls, all applied to a single layer. These look familiar because they are standard to other effects as well. Each generates a unique type of data: Angle generates radians and degrees, Checkbox is a Boolean, Color three values between 0 and 255, Layer a layer in the current comp, and Point an array of two values. Only Slider generates a single floating point number.


Anyhow, for now, say you want to make yourself a zoom control slider for a 3D camera. You may never have needed to do this, but it hardly mattersit won't be long before you think of another property you want to attach to a slider, and once you see how easy it is, you'll be actively looking for opportunities to use this.

You can't apply effects to a camera, so you need to apply the slider to a different layer, and it hardly matters which one. The slider will affect only a layer containing an expression pointing to it. The normal method would be to put it on a null or adjustment layer named Controls or something similar so that it's easy to find later.

To the Controls layer you apply Slider Control. Now to be really organized you might as well rename this control something intuitive and unique, such as Zoomer, by highlighting the effect name and pressing the Return key, then typing in the new name. It's important to do all of your renaming before applying an expression, because, lamentably, expressions do not auto-update their contents to reflect changed target names, so they will break, generate an error, and disable themselves.

Now the easy part: Apply an expression to the Zoom property of the camera, and pickwhip to the Zoomer property. You can even pickwhip up to the Effects Control window instead of revealing it in the timeline. The zoom will snap to the value shown on the slider, which by default is 0, so your camera position now needs to be adjusted.

You can raise the slider to zoom in, but the 0 to 100 range is probably not going to be sufficient. This can be changed by context-clicking on the Zoomer value, choosing Edit Value, and then setting new Slider Range values (Figure 10.8).

Figure 10.8. Slider range values can be set anywhere between the specified maximum and minimum values, not only for the Expression Slider but any effect.


In this case, however, there's an alternative. Say that you want the zoom to increment logarithmically, by powers of 2. That means the slider value is multiplied by itself, and you probably now know how to set the expression to do this. You take the existing pickwhip path, copy it, add a * symbol directly after the original version, and then paste in the copy. Voila, it's multiplied by itself, and the zoom control feels more like a real zoom.



Adobe After Effects 6. 5 Studio Techniques
Adobe After Effects 6.5 Studio Techniques
ISBN: 0321316207
EAN: 2147483647
Year: 2006
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net