본문 바로가기
After Effects(English ver)

Drawing a Line in 3D Space Using fromComp() in After Effects

by hfgraphic 2024. 7. 8.
반응형

The fromComp() function is one of the functions used in Adobe After Effects’ expression language. This function is used to convert specific values from the composition coordinate system to another coordinate system.

 

Function Description

 

fromComp(point)

 

point: The coordinates of the point to be converted from the composition coordinate system. This can be a 2D vector ([x, y]) or a 3D vector ([x, y, z]).

 

This function converts the given point from the composition coordinate system to the layer coordinate system. The composition coordinate system refers to the coordinates based on the size of the entire composition, while the layer coordinate system refers to the coordinates within a specific layer.

 

To demonstrate how to use this, I have prepared some layers. First, I create two Shape layers in the form of circles. Then, I add a new empty Shape layer and apply a Stroke to it. This results in a total of three prepared Shape layers.

 

Click the stopwatch icon while holding Alt (or Option on Mac) and type in your expression. createPath() is a method for creating paths in a Shape layer.

 

createPath(points = [], inTangents = [], outTangents = [], isClosed = false, matrix = undefined)

 

The meanings of each parameter are as follows:

 

points: An array of points that define the path. Each point can be represented as 2D or 3D coordinates.

inTangents: An array of in-tangent vectors for each point. These define the shape of the Bezier curve.

outTangents: An array of out-tangent vectors for each point. These also define the shape of the Bezier curve.

isClosed: A boolean value indicating whether the path is closed. If true, the path is closed; if false, it is open.

matrix: (Optional) A transformation matrix. You can specify a transformation matrix to apply to the path. The default value is undefined.

 

As written above, there is no problem with 2D coordinates, but you may notice that lines do not align correctly when using 3D coordinates in a Shape layer. Since the composition coordinates are 2D, the Z-axis in 3D coordinates is not taken into account. To solve this issue, you need to first convert the 3D coordinates to composition coordinates and then pass them to the A-B Line layer coordinates.

 

First, I converted the 3D coordinates of the A and B layers to the current composition coordinate system using the toComp() method and assigned these values to a and b. Then, I converted these coordinates to the layer coordinate system where the line will be drawn.

Learn more about toComp() in detail

 

 

It can be seen that 3D coordinates can also be applied without any issues.

 

The fromComp() function can be very useful in After Effects when coordinate conversion is needed. It allows for precise alignment of coordinates when creating complex animations or effects.

반응형