mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-09 06:04:03 +00:00
lottie: improve the compatiblity
merge the scene with more accurate condition to allow the evenodd pathes among the lottie render tree.
This commit is contained in:
parent
4e5ff3ea9a
commit
558a9991de
4 changed files with 20 additions and 16 deletions
|
@ -167,12 +167,8 @@ void LottieBuilder::updateTransform(LottieLayer* layer, float frameNo)
|
||||||
|
|
||||||
_updateTransform(transform, frameNo, layer->autoOrient, matrix, layer->cache.opacity, exps);
|
_updateTransform(transform, frameNo, layer->autoOrient, matrix, layer->cache.opacity, exps);
|
||||||
|
|
||||||
if (parent) {
|
if (parent) layer->cache.matrix = parent->cache.matrix * matrix;
|
||||||
if (!identity((const Matrix*) &parent->cache.matrix)) {
|
|
||||||
if (identity((const Matrix*) &matrix)) layer->cache.matrix = parent->cache.matrix;
|
|
||||||
else layer->cache.matrix = parent->cache.matrix * matrix;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
layer->cache.frameNo = frameNo;
|
layer->cache.frameNo = frameNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,25 +178,30 @@ void LottieBuilder::updateTransform(LottieGroup* parent, LottieObject** child, f
|
||||||
auto transform = static_cast<LottieTransform*>(*child);
|
auto transform = static_cast<LottieTransform*>(*child);
|
||||||
if (!transform) return;
|
if (!transform) return;
|
||||||
|
|
||||||
|
Matrix m;
|
||||||
uint8_t opacity;
|
uint8_t opacity;
|
||||||
|
|
||||||
if (parent->mergeable()) {
|
if (parent->mergeable()) {
|
||||||
if (!ctx->transform) ctx->transform = (Matrix*)malloc(sizeof(Matrix));
|
if (ctx->transform) {
|
||||||
|
_updateTransform(transform, frameNo, false, m, opacity, exps);
|
||||||
|
*ctx->transform *= m;
|
||||||
|
} else {
|
||||||
|
ctx->transform = new Matrix;
|
||||||
_updateTransform(transform, frameNo, false, *ctx->transform, opacity, exps);
|
_updateTransform(transform, frameNo, false, *ctx->transform, opacity, exps);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->merging = nullptr;
|
ctx->merging = nullptr;
|
||||||
|
|
||||||
Matrix matrix;
|
if (!_updateTransform(transform, frameNo, false, m, opacity, exps)) return;
|
||||||
if (!_updateTransform(transform, frameNo, false, matrix, opacity, exps)) return;
|
|
||||||
|
|
||||||
ctx->propagator->transform(PP(ctx->propagator)->transform() * matrix);
|
ctx->propagator->transform(PP(ctx->propagator)->transform() * m);
|
||||||
ctx->propagator->opacity(MULTIPLY(opacity, PP(ctx->propagator)->opacity));
|
ctx->propagator->opacity(MULTIPLY(opacity, PP(ctx->propagator)->opacity));
|
||||||
|
|
||||||
//FIXME: preserve the stroke width. too workaround, need a better design.
|
//FIXME: preserve the stroke width. too workaround, need a better design.
|
||||||
if (P(ctx->propagator)->rs.strokeWidth() > 0.0f) {
|
if (P(ctx->propagator)->rs.strokeWidth() > 0.0f) {
|
||||||
auto denominator = sqrtf(matrix.e11 * matrix.e11 + matrix.e12 * matrix.e12);
|
auto denominator = sqrtf(m.e11 * m.e11 + m.e12 * m.e12);
|
||||||
if (denominator > 1.0f) ctx->propagator->stroke(ctx->propagator->strokeWidth() / denominator);
|
if (denominator > 1.0f) ctx->propagator->stroke(ctx->propagator->strokeWidth() / denominator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ struct RenderContext
|
||||||
~RenderContext()
|
~RenderContext()
|
||||||
{
|
{
|
||||||
PP(propagator)->unref();
|
PP(propagator)->unref();
|
||||||
free(transform);
|
delete(transform);
|
||||||
delete(roundness);
|
delete(roundness);
|
||||||
delete(offsetPath);
|
delete(offsetPath);
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,10 @@ struct RenderContext
|
||||||
this->repeaters = rhs.repeaters;
|
this->repeaters = rhs.repeaters;
|
||||||
if (rhs.roundness) this->roundness = new LottieRoundnessModifier(rhs.roundness->r);
|
if (rhs.roundness) this->roundness = new LottieRoundnessModifier(rhs.roundness->r);
|
||||||
if (rhs.offsetPath) this->offsetPath = new LottieOffsetModifier(rhs.offsetPath->offset, rhs.offsetPath->miterLimit, rhs.offsetPath->join);
|
if (rhs.offsetPath) this->offsetPath = new LottieOffsetModifier(rhs.offsetPath->offset, rhs.offsetPath->miterLimit, rhs.offsetPath->join);
|
||||||
|
if (rhs.transform) {
|
||||||
|
transform = new Matrix;
|
||||||
|
*transform = *rhs.transform;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -426,7 +426,7 @@ void LottieGroup::prepare(LottieObject::Type type)
|
||||||
|
|
||||||
/* Figure out if this group is a simple path drawing.
|
/* Figure out if this group is a simple path drawing.
|
||||||
In that case, the rendering context can be sharable with the parent's. */
|
In that case, the rendering context can be sharable with the parent's. */
|
||||||
if (allowMerge && (child->type == LottieObject::Group || !child->mergeable())) allowMerge = false;
|
if (allowMerge && !child->mergeable()) allowMerge = false;
|
||||||
|
|
||||||
//Figure out this group has visible contents
|
//Figure out this group has visible contents
|
||||||
switch (child->type) {
|
switch (child->type) {
|
||||||
|
|
|
@ -544,8 +544,7 @@ struct LottieTransform : LottieObject
|
||||||
|
|
||||||
bool mergeable() override
|
bool mergeable() override
|
||||||
{
|
{
|
||||||
if (!opacity.frames && opacity.value == 255) return true;
|
return true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LottieProperty* property(uint16_t ix) override
|
LottieProperty* property(uint16_t ix) override
|
||||||
|
|
Loading…
Add table
Reference in a new issue