Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
0

Add intermediate vertices on a shape with a script

New Here ,
Dec 02, 2021 Dec 02, 2021

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

TOPICS
Expressions , How to , Scripting
398
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 02, 2021 Dec 02, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 02, 2021 Dec 02, 2021

Thank you very much for your answer. I suppose that I need to re-build my project šŸ™‚ 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 02, 2021 Dec 02, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 03, 2021 Dec 03, 2021

Thank you very much for your interesting article!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 04, 2021 Dec 04, 2021
LATEST

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).

Mathias Mƶhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines