mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +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
e5d55d0651
commit
93cb33fb8e
4 changed files with 20 additions and 16 deletions
|
@ -150,12 +150,8 @@ void LottieBuilder::updateTransform(LottieLayer* layer, float frameNo)
|
|||
|
||||
_updateTransform(transform, frameNo, matrix, layer->cache.opacity, layer->autoOrient, tween, exps);
|
||||
|
||||
if (parent) {
|
||||
if (!tvg::identity((const Matrix*) &parent->cache.matrix)) {
|
||||
if (tvg::identity((const Matrix*) &matrix)) layer->cache.matrix = parent->cache.matrix;
|
||||
else layer->cache.matrix = parent->cache.matrix * matrix;
|
||||
}
|
||||
}
|
||||
if (parent) layer->cache.matrix = parent->cache.matrix * matrix;
|
||||
|
||||
layer->cache.frameNo = frameNo;
|
||||
}
|
||||
|
||||
|
@ -165,25 +161,30 @@ void LottieBuilder::updateTransform(LottieGroup* parent, LottieObject** child, f
|
|||
auto transform = static_cast<LottieTransform*>(*child);
|
||||
if (!transform) return;
|
||||
|
||||
Matrix m;
|
||||
uint8_t opacity;
|
||||
|
||||
if (parent->mergeable()) {
|
||||
if (!ctx->transform) ctx->transform = tvg::malloc<Matrix*>(sizeof(Matrix));
|
||||
if (ctx->transform) {
|
||||
_updateTransform(transform, frameNo, m, opacity, false, tween, exps);
|
||||
*ctx->transform *= m;
|
||||
} else {
|
||||
ctx->transform = new Matrix;
|
||||
_updateTransform(transform, frameNo, *ctx->transform, opacity, false, tween, exps);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->merging = nullptr;
|
||||
|
||||
Matrix matrix;
|
||||
if (!_updateTransform(transform, frameNo, matrix, opacity, false, tween, exps)) return;
|
||||
if (!_updateTransform(transform, frameNo, m, opacity, false, tween, exps)) return;
|
||||
|
||||
ctx->propagator->transform(ctx->propagator->transform() * matrix);
|
||||
ctx->propagator->transform(ctx->propagator->transform() * m);
|
||||
ctx->propagator->opacity(MULTIPLY(opacity, PAINT(ctx->propagator)->opacity));
|
||||
|
||||
//FIXME: preserve the stroke width. too workaround, need a better design.
|
||||
if (SHAPE(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->strokeWidth(ctx->propagator->strokeWidth() / denominator);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ struct RenderContext
|
|||
~RenderContext()
|
||||
{
|
||||
propagator->unref(false);
|
||||
tvg::free(transform);
|
||||
delete(transform);
|
||||
delete(roundness);
|
||||
delete(offset);
|
||||
}
|
||||
|
@ -92,6 +92,10 @@ struct RenderContext
|
|||
offset = new LottieOffsetModifier(rhs.offset->offset, rhs.offset->miterLimit, rhs.offset->join);
|
||||
update(offset);
|
||||
}
|
||||
if (rhs.transform) {
|
||||
transform = new Matrix;
|
||||
*transform = *rhs.transform;
|
||||
}
|
||||
}
|
||||
|
||||
void update(LottieModifier* next)
|
||||
|
|
|
@ -551,7 +551,7 @@ void LottieGroup::prepare(LottieObject::Type type)
|
|||
|
||||
/* Figure out if this group is a simple path drawing.
|
||||
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
|
||||
switch (child->type) {
|
||||
|
|
|
@ -569,8 +569,7 @@ struct LottieTransform : LottieObject
|
|||
|
||||
bool mergeable() override
|
||||
{
|
||||
if (!opacity.frames && opacity.value == 255) return true;
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
LottieProperty* property(uint16_t ix) override
|
||||
|
|
Loading…
Add table
Reference in a new issue