mirror of https://github.com/procxx/kepka.git
QtLottie: Fix SpatialProperty interpolation.
This commit is contained in:
parent
d1518da1ad
commit
9b7e3dc3ec
|
@ -1 +1 @@
|
||||||
Subproject commit 57e54b3d5839431d935899c111f63daec3f53c30
|
Subproject commit 1d23bd35d1e540d7c1aaf7ff88db22d914f4947c
|
|
@ -70,6 +70,7 @@ struct EasingSegment {
|
||||||
T startValue;
|
T startValue;
|
||||||
T endValue;
|
T endValue;
|
||||||
BezierEasing easing;
|
BezierEasing easing;
|
||||||
|
QPainterPath bezier;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -98,7 +99,7 @@ public:
|
||||||
|
|
||||||
if (m_easingCurves.length() > 1) {
|
if (m_easingCurves.length() > 1) {
|
||||||
postprocessEasingCurve(
|
postprocessEasingCurve(
|
||||||
m_easingCurves.at(m_easingCurves.length() - 2),
|
m_easingCurves[m_easingCurves.length() - 2],
|
||||||
(*previous).toObject(),
|
(*previous).toObject(),
|
||||||
fromExpression);
|
fromExpression);
|
||||||
}
|
}
|
||||||
|
@ -107,7 +108,7 @@ public:
|
||||||
}
|
}
|
||||||
finalizeEasingCurves();
|
finalizeEasingCurves();
|
||||||
if (m_easingCurves.length() > 0) {
|
if (m_easingCurves.length() > 0) {
|
||||||
const EasingSegment<T> &last = m_easingCurves.last();
|
EasingSegment<T> &last = m_easingCurves.last();
|
||||||
if (last.state == EasingSegmentState::Complete) {
|
if (last.state == EasingSegmentState::Complete) {
|
||||||
postprocessEasingCurve(
|
postprocessEasingCurve(
|
||||||
last,
|
last,
|
||||||
|
@ -159,7 +160,7 @@ protected:
|
||||||
// The end value has to be hand picked to the
|
// The end value has to be hand picked to the
|
||||||
// previous easing segment, as the json data does
|
// previous easing segment, as the json data does
|
||||||
// not contain end values for segments
|
// not contain end values for segments
|
||||||
prevEase.endFrame = easing.startFrame - 1;
|
prevEase.endFrame = easing.startFrame;
|
||||||
if (prevEase.state == EasingSegmentState::Incomplete) {
|
if (prevEase.state == EasingSegmentState::Incomplete) {
|
||||||
prevEase.endValue = easing.startValue;
|
prevEase.endValue = easing.startValue;
|
||||||
prevEase.state = EasingSegmentState::Complete;
|
prevEase.state = EasingSegmentState::Complete;
|
||||||
|
@ -262,7 +263,7 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void postprocessEasingCurve(
|
virtual void postprocessEasingCurve(
|
||||||
const EasingSegment<T> &easing,
|
EasingSegment<T> &easing,
|
||||||
const QJsonObject keyframe,
|
const QJsonObject keyframe,
|
||||||
bool fromExpression) {
|
bool fromExpression) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void postprocessEasingCurve(
|
virtual void postprocessEasingCurve(
|
||||||
const EasingSegment<QPointF> &easing,
|
EasingSegment<QPointF> &easing,
|
||||||
const QJsonObject keyframe,
|
const QJsonObject keyframe,
|
||||||
bool fromExpression) override {
|
bool fromExpression) override {
|
||||||
// No need to parse further incomplete keyframes (i.e. last keyframes)
|
// No need to parse further incomplete keyframes (i.e. last keyframes)
|
||||||
|
@ -99,8 +99,8 @@ public:
|
||||||
c1 += s;
|
c1 += s;
|
||||||
c2 += e;
|
c2 += e;
|
||||||
|
|
||||||
m_bezierPath.moveTo(s);
|
easing.bezier.moveTo(s);
|
||||||
m_bezierPath.cubicTo(c1, c2, e);
|
easing.bezier.cubicTo(c1, c2, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool update(int frame) override
|
virtual bool update(int frame) override
|
||||||
|
@ -111,20 +111,22 @@ public:
|
||||||
int adjustedFrame = qBound(m_startFrame, frame, m_endFrame);
|
int adjustedFrame = qBound(m_startFrame, frame, m_endFrame);
|
||||||
if (const EasingSegment<QPointF> *easing = getEasingSegment(adjustedFrame)) {
|
if (const EasingSegment<QPointF> *easing = getEasingSegment(adjustedFrame)) {
|
||||||
if (easing->state == EasingSegmentState::Complete) {
|
if (easing->state == EasingSegmentState::Complete) {
|
||||||
qreal progress = ((adjustedFrame - m_startFrame) * 1.0) / (m_endFrame - m_startFrame);
|
int length = (easing->endFrame - easing->startFrame);
|
||||||
|
qreal progress = (length > 0)
|
||||||
|
? ((adjustedFrame - easing->startFrame) * 1.0) / length
|
||||||
|
: 1.;
|
||||||
qreal easedValue = easing->easing.valueForProgress(progress);
|
qreal easedValue = easing->easing.valueForProgress(progress);
|
||||||
m_value = m_bezierPath.pointAtPercent(easedValue);
|
m_value = easing->bezier.pointAtPercent(easedValue);
|
||||||
} else {
|
} else {
|
||||||
// In case of incomplete easing we should just take the final point.
|
// In case of incomplete easing we should just take the final point.
|
||||||
m_value = m_bezierPath.pointAtPercent(1.);
|
//m_value = m_bezierPath.pointAtPercent(1.);
|
||||||
|
m_value = easing->endValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
QPainterPath m_bezierPath;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
Loading…
Reference in New Issue