ADOBE AFTER EFFECTS: Forum Expressions Tutorials Podcasts Creative Cloud

How do I? Orient 2-D layers to 3-D camera data

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Dave TavernierHow do I? Orient 2-D layers to 3-D camera data
by on Apr 14, 2010 at 7:51:38 pm

after working in Cinema 4D, I save my project file to include 3-D camera data for after effects.
My question is, how do I orient 2-D layers in after effects to the 3-D camera data imported from cinema 4D? When I click on the 3-D icon in the aftereffects project the 2-D layers disappear from camera view. Is there a way to orient the new 2-D layers to the 3-D camera imported from cinema 4D?
In after effects I have a lens flare applied to a 2-D layer, I want the lens flare to interact correctly with the imported 3-D camera data but when I click on the 3-D icon the lens flare layer goes completely out of orientation. I am sure this is an easy fix but can't quite figure it out. Any help would be appreciated.
Thank you very much for your anticipated help, DT

Thanks a million,

Return to posts index

Tudor "Ted" JelescuRe: How do I? Orient 2-D layers to 3-D camera data
by on Apr 14, 2010 at 8:33:44 pm

If you need the 2D planes to always face the camera in 3D then:
right-click on the 3D layer you want to behave this way, choose "Transform", then "Auto-Orient". Select "Orient towards camera".
If you need to just position them in 3D space then you have to do it by moving the plane in 3D until it's in the right place - I do not think there's a quick way of doing it... or maybe there is- I just thought of this- if you bring a new camera in AE, parent the layer to it, and then copy and paste the imported camera data to the new camera layer, this should keep the 2d plane in front of the second camera; un parent and delete the second camera. You have now the 2d layer set in 3D space in front of the initial camera and you can move it wherever you need.
Lens Flare- this is not going to work in 3D space. The Lens Flare plugin works on 2d - even if you make the layer 3D you still have a 2d plane with a lens flare on it that's moving in 3D space and not a 3D lens flare effect. So you just need a 2d adjustment layer to animate a lens flare over the image.

Tudor "Ted" Jelescu
Senior VFX Artist
Bucharest, Romania

Return to posts index

Darby EdelenRe: How do I? Orient 2-D layers to 3-D camera data
by on Apr 15, 2010 at 6:49:10 pm

You have two issues to overcome.

The first problem is simple: your imported camera is probably not pointed in the direction that the default AE camera is when it's created. You need to move your 3D layers in front of the imported camera.

The second problem is a little more complicated. The Lens Flare effect needs to be applied to a 2D solid, but you want it's position to be based in 3D space. To do this you need to create a 3D null to act as the flare's center. Then apply the lens flare effect to a composition sized 2D solid. Add this expression to the lens flare's center:

l = thisComp.layer("Null 1"); //your lens null layer
l.toComp(l.anchorPoint); //transforms the null's 3D position to a 2D position

Make sure that your 3D null is visible by your imported camera or you won't see the lens flare. Also, this will result in the flare moving in front of the camera if the Null is actually behind the camera. In order to prevent this you need to apply another expression to the flare's brightness property:

c = thisComp.activeCamera; //active camera
l = thisComp.layer("Null 1"); //3d flare null
cv = c.toWorldVec([0,0,1]); //unit vector pointing down the z-axis of the camera
cp = c.toWorld([0,0,0]); //world position of the camera
p = l.toWorld(l.anchorPoint); //world position of the 3d flare null
v = p - cp; //a vector from the world position of the camera to the world position of the 3d flare null
z = dot(v, cv); //returns only the magnitude of the above vector that lies on the camera's z-axis
if(z > 0) value; //if the 3d null is in front of the camera then use the effect's brightness value
else 0; //otherwise clamp the brightness to 0

The above code will shut off the lens flare effect when the null moves behind the camera. You could alternatively change this code to adjust the brightness of the flare based on the distance from the camera:

maxdist = 5000; //distance from the camera at which the flare becomes invisible
maxbright = 150; //brightness of the flare when it's closest to the camera
c = thisComp.activeCamera;
l = thisComp.layer("Null 1");
cv = c.toWorldVec([0,0,1]);
cp = c.toWorld([0,0,0]);
p = l.toWorld(l.anchorPoint);
v = p - cp;
z = dot(v, cv);
if(z > 0) linear(z, 0, maxdist, maxbright, 0); //interpolate from 0 brightness at the maxdist to maxbright at 0 distance
else 0; //if the null is behind the camera clamp the brightness to 0

This is more than you asked for, but I like to be thorough :) Let me know if you have any questions.

Darby Edelen

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2016 All Rights Reserved