• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Calculation of the angle of the text and its transparency, under the influence of the animator

Contributor ,
Apr 29, 2024 Apr 29, 2024

Copy link to clipboard

Copied

Hi, I want to calculate the angle of a text layer and its transparency when an animator acts on it. I would like to do this dynamically, using a script or expressions.


The bounding box calculation is not suitable because the animator does not change the angle of the layer. Its points are not movable.

I understand that there is no direct way, but perhaps someone has ideas on this matter?

Harchenko_0-1714405613850.png

 

 

TOPICS
Expressions , Scripting

Views

580

Translate

Translate

Report

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 ,
Apr 29, 2024 Apr 29, 2024

Copy link to clipboard

Copied

A text animator will not rotate the entire line. You need to animate the Layer/Transform/Rotation property to rotate an entire word or line. This expression ties the Transform/Rotation property to the Transform/Opacity property, and you'll start seeing the layer when it rotates from -30º to horizontal:

 

r = transform.rotation;
linear(r, -30, 0, 0, 100);

 

If you want to tie the Layer/Animator/Rotation property to the layer Transorm/Opacity property to the text defined in the Advanced section of the Range Selector/Range options, add Opacity to the Layer/Animator and apply this expression to Layer/Animator 1/Opacity:

 

t = text.animator("Animator 1").selector("Range Selector 1").start
linear(t, 0, 100, 0, 100)

 

 

Votes

Translate

Translate

Report

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
Contributor ,
Apr 29, 2024 Apr 29, 2024

Copy link to clipboard

Copied

Hi, I appreciate your response. But it has nothing to do with my question

Votes

Translate

Translate

Report

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 ,
Apr 29, 2024 Apr 29, 2024

Copy link to clipboard

Copied

Those expressions will calculate the angle and make a move. If you want the angle from a layer's Animator's rotation property and also reveal the opacity value, add a text layer and add this expression to the source text. 

 

ref = thisComp.layer(index +1);
r = ref.rotation;
Arot = -ref.text.animator("Animator 1").selector("Range Selector 1").start *.01 * ref.text.animator("Animator 1").property.rotation;
tA = Arot.toFixed(2);
OPas = ref.opacity;
"Text Layter Properties" + "\r" +
"Rotation: " + r + "º" + "\r" +
"Animator Rotation: " + tA + "º" + "\r" +
"Opacity: " + OPas + "%";

 

You get this:

RickGerard_0-1714408052407.gif

You could also base the calculations on time and corner points of the text layer by using sourceRectAtTime(), setting different time values, and calculating the positions of the top-left corner vs the height and width over time.

 

It would help if you told us what you were trying to do.

 

 

Votes

Translate

Translate

Report

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
Contributor ,
Apr 29, 2024 Apr 29, 2024

Copy link to clipboard

Copied

Sorry, but you don't understand what I need: when the animator acts on a layer, it does not change the rotation of the layer.

I need to get the tilt angle of a text layer when a text animator acts on it.

The layer properties are not used there. Animator is an Expression Selector that does not return any values,
even if it’s not him, but the other 5 animators, and I want to get an inclination from the influence of the animators.

The animation is moving, the tilt is always changing, I don't need a static value.  Layer properties are not used.

Harchenko_1-1714412482430.png

 



Harchenko_0-1714412425369.png

 

Votes

Translate

Translate

Report

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
Contributor ,
Apr 29, 2024 Apr 29, 2024

Copy link to clipboard

Copied

Above, I also wrote that it is not possible to calculate the angle from the bounding box, because animators do not change the angle of the layer, the points remain in the same position, this is shown in the screenshot that I attached

Harchenko_0-1714414719242.png

 

Votes

Translate

Translate

Report

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 ,
Apr 29, 2024 Apr 29, 2024

Copy link to clipboard

Copied

You cannot use a Text layer Animator to rotate the entire line of text unless you set Layer/More Options/Anchor Point Grouping to Lines. If you are using that option for your ANGLE Screenshot, the angle value in the layer/Animator/ is the angle you will see when you multiply the Animator Angle value by the Start value multiplied by 0.01 (or divided by 100), as in my second expression. Here's another version of the current angle calculation that defines the angle by simply multiplying the Start and Rotation properties of the text animator:

 

src=thisComp.layer("ROTATE THIS TEXT");
maxAngle = src.text.animator("Animator 1").property.rotation;
angleCorrection = thisComp.layer("ROTATE THIS TEXT").text.animator("Animator 1").selector("Range Selector 1").start/100;
currentAngle = maxAngle * angleCorrection;

 

That expression will give you the current angle of the "ROTATE THIS TEXT" layer, regardless of how the Text Layer/Animator 1/Angle and the Text Layer/Animator 1/Range Selector 1/Start have been set or animated. 0º will always show when the /Animator/Range Selector/Start value is set to zero. For the expression to work, the Animator/Range Selector/Advanced/Units must be set to default "Percentage."

 

If the property you want to drive is on the same layer, you can use src=thisLayer instead of src=thisComp.Layer("Layer Name") or src=thisComp.layer(index + 1) for the first layer below, or src=thisComp.layer(index - 1) for the first layer above the current layer.

 

What is the design goal? What are you trying to drive with the angle value? 

Votes

Translate

Translate

Report

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
Contributor ,
Apr 30, 2024 Apr 30, 2024

Copy link to clipboard

Copied

Hi Rick,
I appreciate your desire to help me, but this has nothing to do with what I'm asking. 

There are no properties that I could refer to, Expression Selector creates an animation on the expression, the Range Start, End properties are not used there.

Even if I used something else, I need to get the actual angle of the layer in space, the text layer could be affected by 5 animators with the rotation property changed.

What I need, I wrote from the very beginning, is a way to get the angle of the text layer when animators act on it and its Bounding Box does not change

bandicam-2024-04-30-12-38-55-650.gif

 

Votes

Translate

Translate

Report

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 ,
Apr 30, 2024 Apr 30, 2024

Copy link to clipboard

Copied

That's probably a hopeless case. In order to know how each animator affects a letter or word you would need to figure in the fall-offs and associated settings, potential other factors and of course for the rendered glyphs themselves you would need to account for baseline shift, em box size, spacing etc. to figure out where a pixel of the text or for that matter even a line is and derive any further info from it to calculate an angle. Rinse and repeat for any other property you need to calculate the effective value of. I can see no easy way to do it. You would have to re-create everything inside of the expressions and this could end up with a hundred lines of extra code and things being very slow.

 

Mylenium

Votes

Translate

Translate

Report

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
Contributor ,
Apr 30, 2024 Apr 30, 2024

Copy link to clipboard

Copied

I don't need to know how each animator affects, I need to get the angle of the layer taking into account these effects.

If there are many animators working on a layer, I don't need a lot of code to calculate its size in pixels, because there is a Bounding Box.

I'm guessing there is some kind of mathematical solution to do this.

After effects itself calculates the angle of the animators, I marked the points for this on the screenshot, but there is no API way to get their data

Harchenko_0-1714470938482.png

 



Votes

Translate

Translate

Report

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 ,
Apr 30, 2024 Apr 30, 2024

Copy link to clipboard

Copied

I think you misunderstand the problem. The data is not exposed anywhere and one would need to re-calculate it for every letter, word or whatever including the influences and cumulative values of each animator. This has nothing to do with the bounding box nor do the values necessarily linearly add up. You may be able to figure things out for a single animator, but as soon as you add a second one e.g. to add soem randomness to a fixed value, things get infinitely more complicated.

 

Mylenium

Votes

Translate

Translate

Report

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
Contributor ,
Apr 30, 2024 Apr 30, 2024

Copy link to clipboard

Copied

We have opposite opinions because it seems to me that you are complicating the task. Anyway, thanks for sharing your thoughts.

Votes

Translate

Translate

Report

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 ,
Apr 30, 2024 Apr 30, 2024

Copy link to clipboard

Copied

If you want to retrieve the angle of the text you must act on the data that is making the text move. If pressing the 'u' key twice does not reveal a rotation property that matches the angle of the text, you will have to retrieve all of the data from every animator that is acting on the text layer. As Mylenium said, combining everything that influences the layer in the proper order to calculate the angle is going to get complicated because of the render order. 

The only other way you could generate the angle would be to use sourceRectAtTime() to get the size of the text box and combine that with any scale factors acting on the size of the text before any animation takes place, and then calculate the angle of the hypotenuse and compare the change from the original box size to the current bounding box size. That would be a lot more code than I'm willing to fiddle with for an answer to a forum post. Dan Elberts could probably do it, but it would take me a lot of trial and error to get it working if I had a copy of your project files showing the problem.

 

Sharing the expression in your Expression Selector or better yet, sharing a simplified comp that shows the problem, we may be able to help you figure it out. 

 

It would also help if we knew how you were going to use the angle information. What do you want to drive with that value?  

Votes

Translate

Translate

Report

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
Contributor ,
Apr 30, 2024 Apr 30, 2024

Copy link to clipboard

Copied

I need a solution that does not depend on the number of animators. I'm sure that the animator's property is being read, this is a dead-end path and thinking in this way will not lead anywhere.

I'm guessing the angle can be obtained by getting the sourceRectAtTime data, but I don't understand the math because angles don't rotate,
when there is the influence of animators and simply calculating by angles will not give results.

For example, you can create a frame for text that will move behind it, although this is not the task that I am pursuing, my goal is simply to get an angle

Votes

Translate

Translate

Report

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 ,
Apr 30, 2024 Apr 30, 2024

Copy link to clipboard

Copied

The only thing I can think of would be kind of a hack, but it seems like you could use the negative time trick, and use an expression for source text that sets your text to a string of underscore characters when time is less than zero. Then use a sampleImage() expression (with time set to -1, say) to find the bottom-most pixel with non-zero alpha at each end of the text and use that to calculate the angle. It would be a pain to set up, but it might give you an acceptable result.

Votes

Translate

Translate

Report

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 ,
Apr 30, 2024 Apr 30, 2024

Copy link to clipboard

Copied

We still don't know how you are going to use the angle value. 

 

SourceRectAtTime() will give you the size of the box so you can calculate the hypotenuse angle. You can use the change in X for the top left as the Opposite side of the triangle. The change in y will give you the base. With the Base and the Opposing side known, you can calculate the Angle of the hypotenuse.  The math is now simple. 

x =400;
y = 800;
radiansToDegrees(Math.atan2(x, y))

The only hard part of the code would be retrieving the size of the text area before an expression has acted on it. Maybe just set a keyframe at the start of the layer and use that value as the starting size. 

 

I don't have time to fiddle with that kind of calculation right now, but that is how you would use sourceRectAtTime() to calculate the angle.

Votes

Translate

Translate

Report

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
Contributor ,
May 01, 2024 May 01, 2024

Copy link to clipboard

Copied

Animators don't change the corners of the Bounding Box; they can resize it, but they don't rotate it. Therefore it is impossible to obtain the angle.

Harchenko_0-1714571290178.png

 

Votes

Translate

Translate

Report

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 ,
May 01, 2024 May 01, 2024

Copy link to clipboard

Copied

This expression will give you the angle of the text layer based only on the size of the frame around the text. I didn't go so far as to give you positive and negative rotation and calculate angles above 90º, but it should be possible. 

ref = thisComp.layer(index + 1);
sW = ref.sourceRectAtTime(inPoint).width;
sH = ref.sourceRectAtTime(inPoint).height;
cur = ref.sourceRectAtTime();
curSize = [cur.height, cur.width];
x = curSize[0];
y = curSize[1];
t = x - y;
strt = sH - sW;
end = sW - sH;
angl = linear(t, strt, end, 0, 90);
v = angl.toFixed(2);
v + "º"

The calculations assume that the text layer is horizontal at the start of the animation. If not, the workaround would probably require a recursive expression that looks for the timeline's minimum and maximum x and y values. If the comp is more than a couple of seconds long, the recursive searching for values could drastically increase render time. 

 

Again, how are you going to use this generated value? I just used it to control a text layer that is accurate to 2 decimal points.

 

I would bet if we could see your project, someone would be able to figure out how to generate that angle value accurately.

RickGerard_1-1714577302435.gif

 

 

Votes

Translate

Translate

Report

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
Contributor ,
May 01, 2024 May 01, 2024

Copy link to clipboard

Copied

Thanks Rick Gerard, this is starting to look like what I need.
I achieved something similar, but my result was worse.

And I can’t understand how to look for the opposite value of the angle, because when the animator acts, the frame becomes larger and smaller and its changes, regardless of the plus or minus, have the same size.

I am attaching a file with the animator that I use

Votes

Translate

Translate

Report

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 ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

When you add Expression Selectors to a Text layer, things get very strange. Based on the calculations, they can act on a property like Rotation in your Animator 3/Expression Selector property. The values in the expression selector don't change, nor do the values in the property (Rotation) change, and they are not registered on the graph editor. If you disable the expression in Animator 3/Expression Selector 1, unlink the three properties, then drag only the first (x) variable, and the line of text will rotate. 

 

To tell the truth, I have not spent much time fiddling with expression selectors because they don't return usable data. If you replace the existing expression with time * 50, the layer will rotate from zero to 90º in 2 seconds if the rotation value is set to 90º. Set rotation to 360º, and the layer will rotate a full turn in 2 seconds. It doesn't matter what the comp's frame rate is.

 

The expression used in Animator 3 will not do anything if added to any transform property. I'm not sure where you got the code, and I don't know how it works, but it could be modified and applied directly to the rotation property, and things should work fine. 

 

Maybe Dan Ebberts can figure it out. I can't. I would have just added a simple move and decay expression directly to the rotation property.

 

 

Votes

Translate

Translate

Report

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
Contributor ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

LATEST

Hi, thank you very much for your another great answer. This expression cannot be applied to the rotation property, because it works with the indices of the text layer and each letter, word or line will have a bounce effect and it will all work evenly.

Therefore, the task is not easy,
because I want to find a universal solution for any type of animator, not this one specifically

Votes

Translate

Translate

Report

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