8000 lottie: modifier chaining enhanced by mgrudzinska · Pull Request #3515 · thorvg/thorvg · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

lottie: modifier chaining enhanced #3515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

lottie: modifier chaining enhanced #3515

wants to merge 3 commits into from

Conversation

mgrudzinska
Copy link
Collaborator
@mgrudzinska mgrudzinska commented Jun 9, 2025

Previously, the rounding modifier was always applied
first, which led to incorrect results when a different
modifier order was expected.
This update removes that limitation and enables modifiers
to be applied in any order.

Additionally, the code now prevents an infinite loop that
occurred when the rounded corners modifier was applied
multiple times (a cycle where next was set to this).

&

Enables applying modifiers to rectangles in any order,
with the exception that if roundness is the first modifier,
it can be applied before the rectangle’s path is constructed.

&

Refactoring ellipse/polygon/star update to prepare for
chained modifiers.

before:
Zrzut ekranu 2025-06-12 o 01 02 14

after (only after #3556 is applied):
Zrzut ekranu 2025-06-12 o 01 01 02

samples:
star_or.json
star_ro.json
path_or.json
path_ro.json

@mgrudzinska mgrudzinska self-assigned this Jun 9, 2025
@mgrudzinska mgrudzinska added enhancement Improve features lottie Lottie animation labels Jun 9, 2025
@hermet hermet requested a review from Copilot June 10, 2025 10:28
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@mgrudzinska mgrudzinska marked this pull request as ready for review June 11, 2025 23:18
@mgrudzinska mgrudzinska requested a review from hermet June 11, 2025 23:38
@mgrudzinska mgrudzinska marked this pull request as draft June 11, 2025 23:45
@mgrudzinska mgrudzinska marked this pull request as ready for review June 11, 2025 23:45
Copy link
Member
@hermet hermet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check comments:
For optimal maintenance and size, how about replacing all LineTo usage with CubicTo?
Then we wouldn't need additional line handling in certain cases.

@mgrudzinska
Copy link
Collaborator Author
mgrudzinska commented Jun 16, 2025

Please check comments: For optimal maintenance and size, how about replacing all LineTo usage with CubicTo? Then we wouldn't need additional line handling in certain cases.

@hermet please check now. I removed support for 'lineTo' everywhere I could. but since we have polygons and rectangles, it was not possible to remove all lineTo cases.

Previously, the rounding modifier was always applied
first, which led to incorrect results when a different
modifier order was expected.
This update removes that limitation and enables modifiers
to be applied in any order.

Additionally, the code now prevents an infinite loop that
occurred when the rounded corners modifier was applied
multiple times (a cycle where next was set to this).
Enables applying modifiers to rectangles in any order,
with the exception that if roundness is the first modifier,
it can be applied before the rectangle’s path is constructed.
Refactoring ellipse/polygon/star update to prepare for
chained modifiers.
@mgrudzinska
Copy link
Collaborator Author

@hermet please check now. I removed support for 'lineTo' everywhere I could. but since we have polygons and rectangles, it was not possible to remove all lineTo cases.

the above is outdated already.
this pr contains changes only with chaining - as a result if #3556 is not applied, samples with the very first modifier other than the round corners may render wrong/not at all.

Type type;
bool chained = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable looks an unnecessary complexity. doesn't mean a valid next chained?

Copy link
Collaborator Author
@mgrudzinska mgrudzinska Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hermet can you please rephrase this sentence: "doesn't mean a valid next chained?"?
I introduced it to handle cases a->b->...->a

current chain add inside decorate
a b a->chaining = true; return b->a
b->a c b->chaining = true; return c->b->a
c->b->a a a->chaining == true; return c->b->a
without chaining check:
c->b->a a c->chaining = true; return a->c->b->a->.... - CYCLE

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, Do you have any sample where the exception occurs at line 53?

@@ -391,9 +391,9 @@ static void _repeat(LottieGroup* parent, Shape* path, RenderContext* ctx)
}


void LottieBuilder::appendRect(Shape* shape, Point& pos, Point& size, float r, bool clockwise, RenderContext* ctx)
void LottieBuilder::appendRect(Shape* shape, Point& pos, Point& size, float r, bool clockwise, RenderContext* ctx, LottieModifier* modifier)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please double-check if possible to use ctx rather than an additional parameter.

@@ -417,38 +418,56 @@ void LottieBuilder::updateRect(LottieGroup* parent, LottieObject** child, float
auto size = rect->size(frameNo, tween, exps);
auto pos = rect->position(frameNo, tween, exps) - size * 0.5f;
auto r = rect->radius(frameNo, tween, exps);
auto modifier = ctx->modifier;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--


if (r == 0.0f) {
if (ctx->roundness) ctx->roundness->modifyRect(size, r);
//roundness is the first modifier -> it can be applied before the shape's path is established
Copy link
Member
@hermet hermet Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be delegated to the relying modifier itself, allowing it to properly handle the logic internally by receiving the current shape target.

ie:
//modifies could query the target type (rect, ellipse, path, polystar, etc)
modifyPath(... LottieShape* target)

you could also improve all the if-else condition other places with the above approach.


//just in the order.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather change the method concept, Please consider modifying the callers.

Type type;
bool chained = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, Do you have any sample where the exception occurs at line 53?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve features lottie Lottie animation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0