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

Understanding the After Effects Expression: toComp()

by hfgraphic 2024. 6. 20.
반응형
 

The toComp() function is a method used in Adobe After Effects' expressions feature, which is utilized to convert a layer's local coordinates to composition coordinates. This method is particularly useful when working in 3D space and is commonly used when you need to convert a layer's position or a point to composition coordinates. Here is a detailed explanation of toComp().

 

Basic Usage

 

toComp(point, t=time)

 

point: An array representing the point to be converted [x, y, z] (3D space) or [x, y] (2D space)

t: An optional parameter specifying the particular time at which to perform the conversion. The default is the current time.

 

In a 2D layer, this expression converts the position [100, 200] of myLayer to composition coordinates:

 

myLayer.toComp([100, 200])

 

In a 3D layer, this expression converts the position [100, 200, 300] of my3DLayer to composition coordinates.

 

my3DLayer.toComp([100, 200, 300])

 

 

I encountered an issue where the position of the Optical Flare becomes misaligned when I link it to a Null's Position and then parent the Null to another layer. This happens because the Position values of the Null change, affecting the Optical Flare's position. To solve this, I used the toComp() expression.

 

First, link the position of the Optical Flare to the Null's Position.

 

When you parent the linked Null to the Circle layer, you can see that the position of the Optical Flare becomes misaligned.

 

To solve this issue, I applied the toComp() function. First, select the layer you want to match the position to, then use the toComp([desired position values]) method. In this example, I used the origin point of the Null's coordinates, which is [0, 0].

 

Apply the same method to the other side as well. By using toComp(), you can resolve the issue of misaligned position values caused by the Parent layer.

 

Application

The toComp() function can be applied in various situations. For example, it can be used when you need to align precisely with another layer or point, or when you need to place a graphic element at a specific location.

Example Project

Here is a simple example project using toComp():

Fixing the End Point of a Layer to Another Layer

 

targetLayer = thisComp.layer("Target Layer");
fromPoint = [thisLayer.width, thisLayer.height];
toPoint = thisLayer.toComp(fromPoint);
targetLayer.position = toPoint;
 

This expression sets the bottom-right corner of the current layer to the position of the Target Layer.

Notes

  • When used in 3D space, make sure to include the Z coordinate.
  • If you do not specify the time argument (t), the coordinates will be converted for the current time by default.

Using the toComp() function in this way can make complex animation tasks in After Effects much easier to handle.

 
 
반응형