Copy link to clipboard
Copied
I have a layer with multiple shapes in it.
How to find the bounding box of a shape made out of bezier curves, like this one:
I can see vertices and tangents info inside value property, but nothing similar to
Copy link to clipboard
Copied
Just to check, but are you saying you can't use SourceRectAtTime().width:
thisComp.layer("Shape Layer 1").sourceRectAtTime().width
Because I just did a quick check using expressions, and it worked for me. So I think I might be misunderstanding.
Copy link to clipboard
Copied
That works for a layer bounding box, I'm asking about an individual shape bounding box
Copy link to clipboard
Copied
and I looking for JSX API solution to put the code into an extension, rather that an expression
Copy link to clipboard
Copied
That makes more sense, but a little beyond me. Have you seen this excellent resource:
https://ae-scripting.docsforadobe.dev/other/shape/
If I am reading that correctly, you can point to a shape. Whether you can get to a bounding box after that I'm not sure.
Copy link to clipboard
Copied
if you can't find a method to it, then you may write a function do do so
- get the specific shape
- get all it's points positions
- get the min and max of all the x values
- get the min and max of all the y values
- lastly the min x and y is the the top left corner of the bounding box, and the max x and y is the bottom right
Copy link to clipboard
Copied
That will only work for convex shapes, not for concave ones, as you see on the image.
Copy link to clipboard
Copied
Honestly I didn't try it, but I believe logically it would get the bounding box of the shape even if it's a flat line. Unless ae scripting has limitations to prevent this logic from happening.
I'll give it a try.
Copy link to clipboard
Copied
Convave shapes do not always touch their bounding box with their vertices, they touch them with Bezier curves between vetrices, which requires a fair amount of math to figure out, I'm trying to avoid doing that.
Copy link to clipboard
Copied
Ok got your point
Copy link to clipboard
Copied
In fact, your logic doesn't always work for convex shapes either:
Copy link to clipboard
Copied
Do you need a scrit to read the value just once. Or an expression to continuously update?
Copy link to clipboard
Copied
When you create null on path (Trace) this is the expression applied to the null position.
var pathLayer = thisComp.layer("Shape Layer 1");
var progress = thisLayer.effect("Pseudo/ADBE Trace Path")("Pseudo/ADBE Trace Path-0001")/100;
var pathToTrace = pathLayer("ADBE Root Vectors Group")(1)("ADBE Vectors Group")(1)("ADBE Vector Shape");
pathLayer.toComp(pathToTrace.pointOnPath(progress));
In the same way, you may sample a number of values to collect positions on the path, then get the Min and Max out of the collected data.
Here is the expression and a screenshot of the setup
var minOrMax = effect("Minimum")("Checkbox");
var pathLayer = thisComp.layer("Shape Layer 1");
var pathToTrace = pathLayer("ADBE Root Vectors Group")(1)("ADBE Vectors Group")(1)("ADBE Vector Shape");
var steps = effect("Samples number (integer)")("Slider"); // to get a whole number
var stepSize = (1/steps);
var xCollection = [];
var yCollection = [];
for (var i = 0; i < steps; i++){
var sampledPoint = pathLayer.toComp(pathToTrace.pointOnPath(stepSize * i));
xCollection.push(sampledPoint[0]);
yCollection.push(sampledPoint[1]);
}
var minX = Math.min.apply(null, xCollection);
var maxX = Math.max.apply(null, xCollection);
var minY = Math.min.apply(null, yCollection);
var maxY = Math.max.apply(null, yCollection);
var minimum = [minX,minY];
var maximum = [maxX,maxY];
if (minOrMax == true) {var selection = minimum} else {var selection = maximum;}
selection;
Copy link to clipboard
Copied
Sorry I forgot to remove the integer text from the comment and slider name, it's not required at all