beautypg.com

Camera – Adobe After Effects CS4 User Manual

Page 691

background image

685

USING AFTER EFFECTS CS4

Expressions

Last updated 12/21/2009

Expression example: Create a bulge between two layers

This example expression synchronizes the Bulge Center argument of the Bulge effect in one layer with the position of
another layer. For example, you can create an effect that looks like a magnifying glass moving over a layer, with the
contents under the magnifying glass bulging as the lens (that is, the overlying layer) moves. This expression uses the

fromWorld

method, which makes the expression work correctly regardless of whether you move the magnifying glass

layer or the underlying layer. You can rotate or scale the underlying layer, and the expression stays intact.

You can also use other effects, such as Ripple, with this expression.

1

Start with two layers. Make one layer a magnifying glass or similar object with a hole in the middle and name it
Magnifier. (See “

Creating layers

” on page 138.)

2

Animate the position of the magnifying glass layer. (See

Motion paths

” on page 223.)

3

Apply the Bulge effect to the other layer. (See “

Apply an effect or animation preset

” on page 393.)

4

Select the Bulge Center property of the Bulge effect in the Timeline panel and choose Animation

> Add Expression,

or Alt-click (Windows) or Option-click (Mac OS) the stopwatch

button for the property.

5

Select the default expression text and type the following:

fromWorld(thisComp.layer("Magnifier").position)

Expression example: Fade opacity of a 3D layer based on distance from
camera

Apply the following expression to the Opacity property of a 3D layer:

startFade = 500; // Start fade 500 pixels from camera.
endFade = 1500; // End fade 1500 pixels from camera.
try{ // Check whether there's a camera.
C = thisComp.activeCamera.toWorld([0,0,0]);
}catch(err){ // No camera, so assume 50mm.
w = thisComp.width * thisComp.pixelAspect;
z = (w/2)/Math.tan(degreesToRadians(19.799));
C = [0,0,-z];
}
P = toWorld(anchorPoint);
d = length(C,P);
linear(d,startFade,endFade,100,0)

The fade starts at a distance of 500 pixels from the camera and is complete at 1500 pixels from the camera. The

linear

interpolation method is used to map distance values to opacity values.

More Help topics

Add, edit, and remove expressions

” on page 647

Create a camera layer and change camera settings

” on page 186

Expression example: Make a 3D layer invisible if facing away from camera

Apply the following expression to the Opacity property of a 3D layer:

if (toCompVec([0, 0, 1])[2] > 0 ) value else 0

Dan Ebberts explains this expression on his

MotionScript website

.

This manual is related to the following products: