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

Creating Lines Connected to Objects Using createPath() in After Effects

by hfgraphic 2024. 7. 14.
반응형

createPath() is a function used in Adobe After Effects to create paths for shape layers using scripts. This function provides a method to define and modify the path of a shape. The createPath() function is primarily used in After Effects’ ExtendScript, which is based on JavaScript.

 

Here is a detailed explanation of the createPath() function:

var myPath = createPath(vertices, inTangents, outTangents, closed);

 

Parameters

 

1. vertices (Array of [Point]): An array of the main vertex points of the shape. Each point represents a corner of the shape.

2. inTangents (Array of [Point]): An array of incoming tangent points for each vertex. These values are used to set the control points of the Bezier curve.

3. outTangents (Array of [Point]): An array of outgoing tangent points for each vertex. These values are also used to set the control points of the Bezier curve.

4. closed (Boolean): A boolean value indicating whether the shape is closed. If true, the shape is closed; if false, it is open.

 

Return Value

 

Path: Returns a path object created according to the given parameters.

 

 

The Expression applied to the Line layer is as follows.

YS = thisComp.layer("Yellow Star").transform.position; OS = thisComp.layer("Orange Star").transform.position; GS = thisComp.layer("Green Star").transform.position; BS = thisComp.layer("Blue Star").transform.position;

var points = [
fromComp(YS), 
fromComp(OS), 
fromComp(GS), 
fromComp(BS)
];

var inTangent = [ [0,0], [0,0], [0,0], [0,0], ];
var outTangent = [ [0,0], [0,0], [0,0], [0,0], ];

createPath(points, inTangent, outTangent, false);

 

 

You can observe the line accurately following the stars as they move randomly up and down.

To add curves to a straight line, you can set the Tangents values by adding values to the inTangents and outTangents.

 

 

YS = thisComp.layer("Yellow Star").transform.position; OS = thisComp.layer("Orange Star").transform.position; GS = thisComp.layer("Green Star").transform.position; BS = thisComp.layer("Blue Star").transform.position;

var points = [
fromComp(YS), 
fromComp(OS), 
fromComp(GS), 
fromComp(BS)
];

var inTangent = [ [0,0], [-200,0], [-200,0], [0,0], ];
var outTangent = [ [0,0], [200,0], [200,0], [0,0], ];

createPath(points, inTangent, outTangent, false);
반응형