Copy link to clipboard
Copied
Hello everybody,
I know how to read the position values of the vertices on a path, but I'm trying to figure out how to automatically add intermediate points on a mask shape with a script.
In other words, as shown in the attached image, I need to start from a simple shape with 2 or 3 vertices (fig.1) and with a script, automatically add further vertices (fig.2).
I tought to add with a script, a pointOnPath expression on the mask path layer, and programmatically change the percentage value to store the values into an Array and finally re-create the mask path using the stored data. I didn't try it but it should work, however I'd like to ask you if there's a different and "smart" approach without reading the expression from the script. So, is there a "pointOnPath" alternative on extendscript? Thank you very much
Copy link to clipboard
Copied
AFAIK there's no such simple function in the shape object for scripting. retrieving the info would likely not work due to how expressions evaluate and don't create persistent values. If at all you'd likely need a lot of extra code that forces the evaluation and fetches the result at a given frame. so all things considered, it might be better to just re-create the entire BĆØzier math and do your own calculations.
Mylenium
Copy link to clipboard
Copied
Thank you very much for your answer. I suppose that I need to re-build my project š
Copy link to clipboard
Copied
There is a cool and fast way to calculate bezier points, called "forward difference method".
I've recreated it in Python, but should be doable in JS pretty easy, too:
https://github.com/mrtnRitter/fastCubicBezier
If you need to solve the bezier (finding x for given y of vice versa), use Newton-Raphson method. It usual just took me 4 iterations until the precision was high enough.
*Martin
Copy link to clipboard
Copied
Thank you very much for your interesting article!
Copy link to clipboard
Copied
I can confirm what Mylenium said: There is no function like pointOnPath in scripting. So if you don't do it with expressions, you need to implement it yourself, unfortunately.
Also note that if you use it for curves, you don't just need to calculate the points, but also their bezier handles (unless you use auto-bezier curves).