2D TO 2.5D

After Effects • Javascript

Info

This script allows you to sort on z-axis a 2D layer while keeping the pixel ratio of 1:1.
You need only a camera in your comp, a 2d layer flagged in 3d mode, and this code on the scale field:

fov = 2*(Math.atan((thisComp.height) / (2* thisComp.layer("Camera 1").cameraOption.zoom))); // "Camera 1" FOV
degreeFov = radiansToDegrees(fov); // Convert into degree
tanFov = Math.tan((degreeFov / 2) * Math.PI / 180); // Half of FOV vertical angle
distFromCam = -(transform.position[2]-thisComp.layer("Camera 1").transform.position[2]); // Layer Z distance from camera
scaleMul = distFromCam * tanFov / (thisComp.height / 2); // Scaling factor
transform.scale*-scaleMul

How It Works