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

After Effects toWorld() Expression 3D Coordinate Transformation

by hfgraphic 2024. 6. 25.
반응형

In Adobe After Effects, the toWorld() function is a very useful function for transforming the position of an object in 3D space. This function converts the local coordinates of a 3D layer to world coordinates. Below is a detailed explanation of the toWorld() function.

 

Function Definition

toWorld(point)
  • Parameters : point: An array in the format [x, y, z], representing the local coordinates of the layer. For 2D layers, an array in the format [x, y] can be used.Return ValueReturns the position in world coordinates as an array in the format [x, y, z]

Basic Usage Example

var globalPosition = thisLayer.toWorld(thisLayer.anchorPoint);

 

Usage in a 2D Layer

var globalPosition2D = thisLayer.toWorld([100, 100]);

 

Usage in a 3D Layer

var globalPosition3D = thisLayer.toWorld([100, 100, 100]);

 

 

I will create a shape layer.

 

After creating a Shape Layer, there are some points to be careful about when applying it. Since the created shape is also in layer coordinates, to align it to the center of the current layer, you should set the position of the shape within the Shape Layer to (0, 0) instead of adjusting the layer’s position.

 

I created a Null Object and applied the Wiggle() expression to its position value. Then, I connected the Optical Flare to the position of the created Shape Layer. By converting the randomly moving position value of the Null Object to 3D world coordinates using toWorld(), I pass it to the position of the created Shape Layer.

 

I created a Null Object and applied the Wiggle() expression to its position value. Then, I connected the Optical Flare to the position of the created Shape Layer. By converting the randomly moving position value of the Null Object to 3D world coordinates using toWorld(), I pass it to the position of the created Shape Layer.

 

The toWorld() function can be useful in various scenarios. For example, it is useful for adjusting the positional relationship between multiple layers or matching the position of a specific layer to another layer.

 

Example: Calculating the distance between two layers

 

Here is an example of calculating the distance between two 3D layers.

var layer1 = thisComp.layer("Layer 1");
var layer2 = thisComp.layer("Layer 2");
var pos1 = layer1.toWorld(layer1.anchorPoint);
var pos2 = layer2.toWorld(layer2.anchorPoint);
var distance = length(pos1, pos2);

 

The toWorld() function is a powerful tool in After Effects for converting a layer’s local coordinates to world coordinates. By using this function, you can accurately calculate positions in 3D space, which is very helpful for complex animations and layout work.

 

This process is carried out as follows:

 

1. Local Coordinate Calculation: First, the local coordinates [x, y, z] passed to the function are based on the layer’s coordinate system. For 2D layers, an array in the format [x, y] is used.

2. Applying the Layer Transformation Matrix: The toWorld() function applies the layer’s transformation matrix (position, rotation, scale, anchor point, etc.) to convert the local coordinates to the composition’s coordinate system. This process considers all transformations (translation, rotation, scaling, etc.) of the layer.

3. Considering Parent Layers: If the layer has a parent layer, the parent’s transformations are also applied. This ensures that the final world coordinates take into account the influence of the parent layer.

4. Returning the Final World Coordinates: After the transformation process, the final calculated world coordinates are returned as an array in the format [x, y, z].

 

Thanks to this process, the toWorld() function is extremely useful for understanding and adjusting the precise positional relationships between objects in 3D space.

 

반응형