parallax: add 3d depth to a multi-layered image

Learn how to move layer along the Z axis to add depth to your composition without affecting the proportion of the original image

12-00

1. Setup

Start by importing your multi-layered AI or PSD (choose to import as composition, not rasterized footage), or create your 2D artwork directly in AE.
Then turn on for each layer the 3D layer toggle and add a camera to your comp.

12-01

2. Expression writing

First thing to notice is, when creating a new camera, is

camera.position[2] = cameraOption.zoom = cameraOption.focusDistance
Any layer positioned at [0,0,0] will be exactly at the same place and will keep the same proportions when looking through the camera.

Distance to Camera

13-01

note that the absolute distance between the camera and the object along the Z axis is z + d

  • Add an expression on the scale scale property of any of the layer
var z = thisComp.activeCamera.cameraOption.zoom;
var d = position[2];
scale * ((d + z) / z)

Note that the first line of code instruct to retrieve the active camera zoom value.

  • Copy the expression
  • Reveal the scale property of all the layers in 3d space: select the layers and type’s’
  • paste the expression

Now when moving a layer along the Z axis, it will look as if nothing happens, but if you select the top view, you can see its actual position. You will still be able to scale up/down any layer.

You might be interested by Paul Tuersley’s Multiplane script that automates this method plus automatically distribute layers along Z axis.

12-04

DON’T FORGET
build your own presets collection to speed up your workflow
Click icon below to download the AE preset (rename .key to .zip after download)

download

Advertisements

Car Rig

Learn how to create a simple but effective car rig

12-00

1. Setup

this simple car rig will automate the rotation of the wheels and the orientation of the car along the motion path. You can use your own car model imported from Photoshop or Illustrator, or create it directly in AE with shape layers. Make sure that each wheels are on a separate layer, and that anchor point is centered.

The simplest hierarchy would be 3 layers:

  • Car body
  • Front wheel
  • Rear wheel

Start by creating the road to be used as a motion path; again, the easiest way would be to create it directly in after effects using shape layers, but you can also import an external file. Doing so will require an extra step, you need to create a mask to outline the curves of the road.

12-01

2. Drive!

  • Create a new Null Object(“Drive”)
  • Copy the position property of the front wheel to the Null Object(“Drive”)
  • Use the pick whip to link all the car layers to the Null Object(“Drive”)
  • Copy the road path from your shape layer or the mask outline to the position property of the Null Object(“Drive”). Make sure you copy the Path and not the object/mask to the position property.

Because the motion path moves the object along its anchor point, we need to offset the Y position of half the diameter of the wheel.

  • Add an expression to the Null Object(“Drive”)

If you used a Shape layer, it is easy, you need to get the diameter from the ellipse shape property:

var d = thisComp.layer(“wheel_F”).content(“Ellipse 1”).content(“Ellipse Path 1”).size[0];

If you imported the layer and don’t know the exact diameter, the easiest will be to create an Effect > Expression Controls > Slider Control, and adjust manually.

var d = effect(“Slider Control”)(“Slider”);

End the expression code with:

[value[0],value[1]-d/2]

We only want to affect the Y position (second value in the array) by half of the diameter (-d/2)

3. Orientation

If you toggle on Transform > Auto-orient > Along the path, you can see that the result are more than unexpected. It orients the front wheel, without taking into consideration the rest of the car.

We will solve this problem with an expression on the Null Object(“Drive”) comparing values over time.

  • Remove Auto-Orient if you toggled it on
  • Add an Effect > Expression Controls > Slider Control to Null Object(“Drive”) and rename it to offset.
  • Add an expression to Null Object(“Drive”).rotation; first store the new controller value and convert decimals to Frames for more flexibility*:
var offset = framesToTime(effect(“offset (in frames)”)(“Slider”));

*time is evaluated in seconds in expressions, not in frames

  • Create 2 variables to store the positions at current time and past time
var from = transform.position;
var to = transform.position.valueAtTime(time-offset);
  • The last part of the expression evaluates the distance between the 2 wheels; if you don’t understand it, please review the previous topic Line Connectors
radiansToDegrees( Math.atan2( from[1]-to[1], from[0]-to[0] ) )
  • Adjust manually the slider(“offset”) so that the rear wheel touches the ground (in positive values)*

*This value depends on the speed (time between the start/end keyframes of the position animation) and the distance travelled in pixels. It should be possible to accumulate values over time to evaluate it, but honestly, it is easier and faster this way.

This setup is not perfect, you will notice sometimes the rear wheel does not stick exactly to the road when the road distortion is heavier. It has to do with the distance between the 2 wheels being forced to always stay the same, despite the distance travelled. But the viewer should not even notice it so why bother? You can still adjust manually if it is really noticeable.

12-02

4. Wheels rotation

  • Use the pick whip to link the rotation of the rear wheel with the front wheel

Geometry: circumference ?

12-03

  • Add an expression to the rotation to store the variables
var d = content(“Ellipse 1”).content(“Ellipse Path 1”).size[0];
var p = thisComp.layer(“Drive”).transform.position;
  • Write the expression result : 360º / Circumference * Position

360 / (Math.PI*d) * p[0]

This expression evaluates the rotation speed (360/C) and uses X Position to know how many pixels the car travelled. You can check out CreativeCow Vehicle rig for a more in depth explanation.

12-04

DON’T FORGET
build your own presets collection to speed up your workflow
Click icon below to download the AE project (rename .key to .zip after download)

download

Errors ?

Learn how to deal with errors

1. AE CC 2015 (13.5)

Finally, Adobe decides to change the way expression errors are handled in AE, expressions toggle is no longer disabled if expression is not valid. Instead it displays a warning message and a warning icon next to the expression; clicking on it allows to access the error message.

It will also handle temporary errors; for example in the previous topic Subtitle track from an external file, when using markers, we created an if/else condition to avoid looking for marker 0.

{ if (m == 1) {“”} else

This is no longer required, as it will not disable the expression because of a unique event.

Read the official Adobe blog post here : http://blogs.adobe.com/aftereffects/2015/06/changes-to-expressions-in-after-effects-cc-2015-13-5.html

2. And before 2015 ?

To prevent unique or specific errors, you could make a set of if/else conditions; but if something is missing, for example applying the color expression from topic Color Palette / Swatches without having the color swatches in the timeline (or forgot to rename the layer to “colors”), that would not prevent from disabling the expression.

try {code} catch(err) {code}
acts like a conditional statement;
It tests the block of code for errors, if no errors it is executed,
if errors are found it will execute the alternate code specified in the catch(err)

read more about javascript errors here : JavaScript try/catch/finally Statement

3. Reactivate

Let’s say you deleted by mistake a master layer to your expressions, then they all are deactivated; even a Cmd+Z won’t bring them back to life. Oh yeah, you know what I am talking about, revealing all expressions to re-enable them one by one while lashing yourself and cursing the world you live in!

ActivateDisabledExpressions is a free script that will save your life; it will look for the disabled expressions and batch – reactivate them.

If you have a few bucks to spend, I highly recommend to Paul Tuersley’s ExpressEdit 2, a great script that can find disabled expressions, but also can be used as an expression library to save your codes, search for specified and batch apply expressions to selected layers.