summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/animation/backend/fcurve.cpp19
-rw-r--r--tests/auto/animation/animationutils/animationutils.qrc1
-rw-r--r--tests/auto/animation/animationutils/clip4.json65
-rw-r--r--tests/auto/animation/animationutils/tst_animationutils.cpp22
4 files changed, 100 insertions, 7 deletions
diff --git a/src/animation/backend/fcurve.cpp b/src/animation/backend/fcurve.cpp
index 56145c726..4a2cf30fd 100644
--- a/src/animation/backend/fcurve.cpp
+++ b/src/animation/backend/fcurve.cpp
@@ -126,16 +126,21 @@ void FCurve::read(const QJsonObject &json)
float localTime = keyframeCoords.at(0).toDouble();
Keyframe keyframe;
- keyframe.interpolation = QKeyFrame::BezierInterpolation;
keyframe.value = keyframeCoords.at(1).toDouble();
- const QJsonArray leftHandle = keyframeData[QLatin1String("leftHandle")].toArray();
- keyframe.leftControlPoint[0] = leftHandle.at(0).toDouble();
- keyframe.leftControlPoint[1] = leftHandle.at(1).toDouble();
+ if (keyframeData.contains(QLatin1String("leftHandle"))) {
+ keyframe.interpolation = QKeyFrame::BezierInterpolation;
- const QJsonArray rightHandle = keyframeData[QLatin1String("rightHandle")].toArray();
- keyframe.rightControlPoint[0] = rightHandle.at(0).toDouble();
- keyframe.rightControlPoint[1] = rightHandle.at(1).toDouble();
+ const QJsonArray leftHandle = keyframeData[QLatin1String("leftHandle")].toArray();
+ keyframe.leftControlPoint[0] = leftHandle.at(0).toDouble();
+ keyframe.leftControlPoint[1] = leftHandle.at(1).toDouble();
+
+ const QJsonArray rightHandle = keyframeData[QLatin1String("rightHandle")].toArray();
+ keyframe.rightControlPoint[0] = rightHandle.at(0).toDouble();
+ keyframe.rightControlPoint[1] = rightHandle.at(1).toDouble();
+ } else {
+ keyframe.interpolation = QKeyFrame::LinearInterpolation;
+ }
appendKeyframe(localTime, keyframe);
}
diff --git a/tests/auto/animation/animationutils/animationutils.qrc b/tests/auto/animation/animationutils/animationutils.qrc
index bbcd96524..ddaeab7f1 100644
--- a/tests/auto/animation/animationutils/animationutils.qrc
+++ b/tests/auto/animation/animationutils/animationutils.qrc
@@ -3,5 +3,6 @@
<file>clip1.json</file>
<file>clip2.json</file>
<file>clip3.json</file>
+ <file>clip4.json</file>
</qresource>
</RCC>
diff --git a/tests/auto/animation/animationutils/clip4.json b/tests/auto/animation/animationutils/clip4.json
new file mode 100644
index 000000000..0915294cd
--- /dev/null
+++ b/tests/auto/animation/animationutils/clip4.json
@@ -0,0 +1,65 @@
+{
+ "animations": [
+ {
+ "animationName": "LinearTranslation",
+ "channels": [
+ {
+ "channelComponents": [
+ {
+ "channelComponentName": "Location X",
+ "keyFrames": [
+ {
+ "coords": [
+ 0.0,
+ 0.0
+ ]
+ },
+ {
+ "coords": [
+ 10.0,
+ 5.0
+ ]
+ }
+ ]
+ },
+ {
+ "channelComponentName": "Location Y",
+ "keyFrames": [
+ {
+ "coords": [
+ 0.0,
+ 0.0
+ ]
+ },
+ {
+ "coords": [
+ 10.0,
+ -2.0
+ ]
+ }
+ ]
+ },
+ {
+ "channelComponentName": "Location Z",
+ "keyFrames": [
+ {
+ "coords": [
+ 0.0,
+ 0.0
+ ]
+ },
+ {
+ "coords": [
+ 10.0,
+ 6.0
+ ]
+ }
+ ]
+ }
+ ],
+ "channelName": "Location"
+ }
+ ]
+ }
+ ]
+}
diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp
index fea110856..4c97cf7e5 100644
--- a/tests/auto/animation/animationutils/tst_animationutils.cpp
+++ b/tests/auto/animation/animationutils/tst_animationutils.cpp
@@ -1186,6 +1186,28 @@ private Q_SLOTS:
<< handler << clip << localTime << expectedResults;
expectedResults.clear();
}
+ {
+ // a clip with linear interpolation
+ handler = new Handler();
+ clip = createAnimationClipLoader(handler, QUrl("qrc:/clip4.json"));
+ localTime = clip->duration();
+ expectedResults = QVector<float>() << 5.0 << -2.0f << 6.0f;
+
+ QTest::newRow("clip4.json, linear, t = duration")
+ << handler << clip << localTime << expectedResults;
+ expectedResults.clear();
+ }
+ {
+ // a clip with linear interpolation
+ handler = new Handler();
+ clip = createAnimationClipLoader(handler, QUrl("qrc:/clip4.json"));
+ localTime = clip->duration() / 2.0f;
+ expectedResults = QVector<float>() << 2.5f << -1.0f << 3.0f;
+
+ QTest::newRow("clip4.json, linear, t = duration/2")
+ << handler << clip << localTime << expectedResults;
+ expectedResults.clear();
+ }
}
void checkEvaluateClipAtLocalTime()