diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2017-10-07 17:49:54 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2018-01-18 11:55:00 +0000 |
commit | b2b7616786af7041f9d1db15511df48c68847ad6 (patch) | |
tree | 99d052da5636891a52bfa58beab71f5f0dc41fa0 /tests | |
parent | 1ddff1b53ea19c965f187d947fdaed428d1ad05a (diff) |
Wrap up the format describing source clip and formatted results
We need more information that just the source indices to be able to
properly describe the transformation from the raw evaluation
results of a clip, through to the formatted layout later consumed by
the MappingData objects.
The playback of a QClipAnimator still works but it seems that the
process for properly blending animations is more complicated than
previously thought. We cannot simply assume a default value of 0 for
all channel components. If a clip has a channel missing but the user
has still requested that this channel be evaluated (by way of a mapping
or a subset of clips having matching channel data), then we must provide
sensible defaults for those channel components. This deficiency will be
dealt with in a following commit.
Change-Id: I7d7d0f7ce19c545629bb347e1132fc4ed6a59d0d
Reviewed-by: Christian Stromme <christian.stromme@qt.io>
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/animation/animationutils/tst_animationutils.cpp | 174 | ||||
-rw-r--r-- | tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp | 56 |
2 files changed, 162 insertions, 68 deletions
diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 5ec8c7d60..8469ed416 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -44,6 +44,7 @@ #include <QtGui/qvector4d.h> #include <QtGui/qquaternion.h> #include <QtGui/qcolor.h> +#include <QtCore/qbitarray.h> #include <qbackendnodetester.h> #include <testpostmanarbiter.h> @@ -64,6 +65,7 @@ Q_DECLARE_METATYPE(ClipAnimator *) Q_DECLARE_METATYPE(BlendedClipAnimator *) Q_DECLARE_METATYPE(QVector<ChannelNameAndType>) Q_DECLARE_METATYPE(QVector<AnimationCallbackAndValue>) +Q_DECLARE_METATYPE(ClipFormat) namespace { @@ -277,6 +279,7 @@ private Q_SLOTS: QTest::addColumn<QVector<ChannelMapping *>>("channelMappings"); QTest::addColumn<QVector<ChannelNameAndType>>("channelNamesAndTypes"); QTest::addColumn<QVector<ComponentIndices>>("channelComponentIndices"); + QTest::addColumn<QVector<QBitArray>>("sourceClipMask"); QTest::addColumn<QVector<MappingData>>("expectedResults"); // Single ChannelMapping @@ -316,6 +319,12 @@ private Q_SLOTS: = { rotationIndices, locationIndices, baseColorIndices, metalnessIndices, roughnessIndices }; + QVector<QBitArray> sourceClipMask = { QBitArray(4, true), + QBitArray(3, true), + QBitArray(3, true), + QBitArray(1, true), + QBitArray(1, true) }; + MappingData expectedMapping; expectedMapping.targetId = channelMapping->targetId(); expectedMapping.propertyName = channelMapping->propertyName(); @@ -328,6 +337,7 @@ private Q_SLOTS: << channelMappings << channelNamesAndTypes << channelComponentIndices + << sourceClipMask << expectedResults; } @@ -399,6 +409,12 @@ private Q_SLOTS: = { rotationIndices, locationIndices, baseColorIndices, metalnessIndices, roughnessIndices }; + QVector<QBitArray> sourceClipMask = { QBitArray(4, true), + QBitArray(3, true), + QBitArray(3, true), + QBitArray(1, true), + QBitArray(1, true) }; + MappingData expectedLocationMapping; expectedLocationMapping.targetId = locationMapping->targetId(); expectedLocationMapping.propertyName = locationMapping->propertyName(); @@ -441,6 +457,7 @@ private Q_SLOTS: << channelMappings << channelNamesAndTypes << channelComponentIndices + << sourceClipMask << expectedResults; } @@ -479,6 +496,19 @@ private Q_SLOTS: channelComponentIndices.push_back({ 33, 34, 35, 36 }); channelComponentIndices.push_back({ 37, 38, 39 }); + QVector<QBitArray> sourceClipMask = { QBitArray(3, true), + QBitArray(4, true), + QBitArray(3, true), + QBitArray(3, true), + QBitArray(4, true), + QBitArray(3, true), + QBitArray(3, true), + QBitArray(4, true), + QBitArray(3, true), + QBitArray(3, true), + QBitArray(4, true), + QBitArray(3, true) }; + QVector<MappingData> expectedResults; int componentIndicesIndex = 0; for (int i = 0; i < jointCount; ++i) { @@ -511,6 +541,7 @@ private Q_SLOTS: << channelMappings << channelNamesAndTypes << channelComponentIndices + << sourceClipMask << expectedResults; } } @@ -522,12 +553,14 @@ private Q_SLOTS: QFETCH(QVector<ChannelMapping *>, channelMappings); QFETCH(QVector<ChannelNameAndType>, channelNamesAndTypes); QFETCH(QVector<ComponentIndices>, channelComponentIndices); + QFETCH(QVector<QBitArray>, sourceClipMask); QFETCH(QVector<MappingData>, expectedResults); // WHEN const QVector<MappingData> actualResults = buildPropertyMappings(channelMappings, channelNamesAndTypes, - channelComponentIndices); + channelComponentIndices, + sourceClipMask); // THEN QCOMPARE(actualResults.size(), expectedResults.size()); @@ -2524,7 +2557,7 @@ private Q_SLOTS: QTest::addColumn<QVector<ChannelNameAndType>>("targetChannels"); QTest::addColumn<QVector<ComponentIndices>>("targetIndices"); QTest::addColumn<AnimationClip *>("clip"); - QTest::addColumn<ComponentIndices>("expectedResults"); + QTest::addColumn<ClipFormat>("expectedResults"); { QVector<ChannelNameAndType> targetChannels; @@ -2546,11 +2579,19 @@ private Q_SLOTS: clip->setSource(QUrl("qrc:/clip3.json")); clip->loadAnimation(); - ComponentIndices expectedResults = { 0, 1, 3, 2, // Rotation (y/z swapped in clip3.json) - 4, 6, 5, // Location (y/z swapped in clip3.json) - 7, 8, 9, // Base Color - 10, // Metalness - 11 }; // Roughness + ClipFormat expectedResults; + expectedResults.sourceClipIndices = { 0, 1, 3, 2, // Rotation (y/z swapped in clip3.json) + 4, 6, 5, // Location (y/z swapped in clip3.json) + 7, 8, 9, // Base Color + 10, // Metalness + 11 }; // Roughness + expectedResults.sourceClipMask = { QBitArray(4, true), + QBitArray(3, true), + QBitArray(3, true), + QBitArray(1, true), + QBitArray(1, true) }; + expectedResults.namesAndTypes = targetChannels; + expectedResults.formattedComponentIndices = targetIndices; QTest::newRow("rotation, location, pbr metal-rough") << targetChannels << targetIndices << clip << expectedResults; @@ -2576,11 +2617,19 @@ private Q_SLOTS: clip->setSource(QUrl("qrc:/clip3.json")); clip->loadAnimation(); - ComponentIndices expectedResults = { 4, 6, 5, // Location (y/z swapped in clip3.json) - 0, 1, 3, 2, // Rotation (y/z swapped in clip3.json) - 7, 8, 9, // Base Color - 10, // Metalness - 11 }; // Roughness + ClipFormat expectedResults; + expectedResults.sourceClipIndices = { 4, 6, 5, // Location (y/z swapped in clip3.json) + 0, 1, 3, 2, // Rotation (y/z swapped in clip3.json) + 7, 8, 9, // Base Color + 10, // Metalness + 11 }; // Roughness + expectedResults.sourceClipMask = { QBitArray(3, true), + QBitArray(4, true), + QBitArray(3, true), + QBitArray(1, true), + QBitArray(1, true) }; + expectedResults.namesAndTypes = targetChannels; + expectedResults.formattedComponentIndices = targetIndices; QTest::newRow("location, rotation, pbr metal-rough") << targetChannels << targetIndices << clip << expectedResults; @@ -2606,11 +2655,19 @@ private Q_SLOTS: clip->setSource(QUrl("qrc:/clip3.json")); clip->loadAnimation(); - ComponentIndices expectedResults = { 0, 1, 3, 2, // Rotation (y/z swapped in clip3.json) - 4, 6, 5, // Location (y/z swapped in clip3.json) - -1, -1, -1, // Albedo (missing from clip) - 10, // Metalness - 11 }; // Roughness + ClipFormat expectedResults; + expectedResults.sourceClipIndices = { 0, 1, 3, 2, // Rotation (y/z swapped in clip3.json) + 4, 6, 5, // Location (y/z swapped in clip3.json) + -1, -1, -1, // Albedo (missing from clip) + 10, // Metalness + 11 }; // Roughness + expectedResults.sourceClipMask = { QBitArray(4, true), + QBitArray(3, true), + QBitArray(3, false), + QBitArray(1, true), + QBitArray(1, true) }; + expectedResults.namesAndTypes = targetChannels; + expectedResults.formattedComponentIndices = targetIndices; QTest::newRow("rotation, location, albedo (missing), metal-rough") << targetChannels << targetIndices << clip << expectedResults; @@ -2636,11 +2693,19 @@ private Q_SLOTS: clip->setSource(QUrl("qrc:/clip3.json")); clip->loadAnimation(); - ComponentIndices expectedResults = { 4, 6, 5, // Location (y/z swapped in clip3.json) - 0, 1, 3, 2, // Rotation (y/z swapped in clip3.json) - -1, -1, -1, // Albedo (missing from clip) - 10, // Metalness - 11 }; // Roughness + ClipFormat expectedResults; + expectedResults.sourceClipIndices = { 4, 6, 5, // Location (y/z swapped in clip3.json) + 0, 1, 3, 2, // Rotation (y/z swapped in clip3.json) + -1, -1, -1, // Albedo (missing from clip) + 10, // Metalness + 11 }; // Roughness + expectedResults.sourceClipMask = { QBitArray(3, true), + QBitArray(4, true), + QBitArray(3, false), + QBitArray(1, true), + QBitArray(1, true) }; + expectedResults.namesAndTypes = targetChannels; + expectedResults.formattedComponentIndices = targetIndices; QTest::newRow("location, rotation, albedo (missing), metal-rough") << targetChannels << targetIndices << clip << expectedResults; @@ -2677,18 +2742,33 @@ private Q_SLOTS: clip->setSource(QUrl("qrc:/clip5.json")); clip->loadAnimation(); - ComponentIndices expectedResults = { 4, 6, 5, // Location, joint 0 (y/z swapped in clip5.json) - 0, 1, 3, 2, // Rotation, joint 0 (y/z swapped in clip5.json) - 7, 8, 9, // Scale, joint 0 - 14, 16, 15, // Location, joint 1 (y/z swapped in clip5.json) - 10, 11, 13, 12, // Rotation, joint 1 (y/z swapped in clip5.json) - 17, 18, 19, // Scale, joint 1 - 24, 26, 25, // Location, joint 2 (y/z swapped in clip5.json) - 20, 21, 23, 22, // Rotation, joint 2 (y/z swapped in clip5.json) - 27, 28, 29, // Scale, joint 2 - 34, 36, 35, // Location, joint 3 (y/z swapped in clip5.json) - 30, 31, 33, 32, // Rotation, joint 3 (y/z swapped in clip5.json) - 37, 38, 39 }; // Scale, joint 3 + ClipFormat expectedResults; + expectedResults.sourceClipIndices = { 4, 6, 5, // Location, joint 0 (y/z swapped in clip5.json) + 0, 1, 3, 2, // Rotation, joint 0 (y/z swapped in clip5.json) + 7, 8, 9, // Scale, joint 0 + 14, 16, 15, // Location, joint 1 (y/z swapped in clip5.json) + 10, 11, 13, 12, // Rotation, joint 1 (y/z swapped in clip5.json) + 17, 18, 19, // Scale, joint 1 + 24, 26, 25, // Location, joint 2 (y/z swapped in clip5.json) + 20, 21, 23, 22, // Rotation, joint 2 (y/z swapped in clip5.json) + 27, 28, 29, // Scale, joint 2 + 34, 36, 35, // Location, joint 3 (y/z swapped in clip5.json) + 30, 31, 33, 32, // Rotation, joint 3 (y/z swapped in clip5.json) + 37, 38, 39 }; // Scale, joint 3 + expectedResults.sourceClipMask = { QBitArray(3, true), + QBitArray(4, true), + QBitArray(3, true), + QBitArray(3, true), + QBitArray(4, true), + QBitArray(3, true), + QBitArray(3, true), + QBitArray(4, true), + QBitArray(3, true), + QBitArray(3, true), + QBitArray(4, true), + QBitArray(3, true) }; + expectedResults.namesAndTypes = targetChannels; + expectedResults.formattedComponentIndices = targetIndices; QTest::newRow("skeleton (SQT), 4 joints") << targetChannels << targetIndices << clip << expectedResults; @@ -2701,17 +2781,29 @@ private Q_SLOTS: QFETCH(QVector<ChannelNameAndType>, targetChannels); QFETCH(QVector<ComponentIndices>, targetIndices); QFETCH(AnimationClip *, clip); - QFETCH(ComponentIndices, expectedResults); + QFETCH(ClipFormat, expectedResults); // WHEN - const ComponentIndices actualResults = generateClipFormatIndices(targetChannels, - targetIndices, - clip); + const ClipFormat actualResults = generateClipFormatIndices(targetChannels, + targetIndices, + clip); // THEN - QCOMPARE(actualResults.size(), expectedResults.size()); - for (int i = 0; i < actualResults.size(); ++i) - QCOMPARE(actualResults[i], expectedResults[i]); + QCOMPARE(actualResults.sourceClipIndices.size(), expectedResults.sourceClipIndices.size()); + for (int i = 0; i < actualResults.sourceClipIndices.size(); ++i) + QCOMPARE(actualResults.sourceClipIndices[i], expectedResults.sourceClipIndices[i]); + + QCOMPARE(actualResults.sourceClipMask.size(), expectedResults.sourceClipMask.size()); + for (int i = 0; i < actualResults.sourceClipMask.size(); ++i) + QCOMPARE(actualResults.sourceClipMask[i], expectedResults.sourceClipMask[i]); + + QCOMPARE(actualResults.formattedComponentIndices.size(), expectedResults.formattedComponentIndices.size()); + for (int i = 0; i < actualResults.formattedComponentIndices.size(); ++i) + QCOMPARE(actualResults.formattedComponentIndices[i], expectedResults.formattedComponentIndices[i]); + + QCOMPARE(actualResults.namesAndTypes.size(), expectedResults.namesAndTypes.size()); + for (int i = 0; i < actualResults.namesAndTypes.size(); ++i) + QCOMPARE(actualResults.namesAndTypes[i], expectedResults.namesAndTypes[i]); // Cleanup delete clip; diff --git a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp index fcbc167ca..cc9d22556 100644 --- a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp +++ b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp @@ -41,6 +41,7 @@ using namespace Qt3DAnimation::Animation; Q_DECLARE_METATYPE(ClipBlendValue *) +Q_DECLARE_METATYPE(QVector<ClipFormat>) class tst_ClipBlendValue : public Qt3DCore::QBackendNodeTester { @@ -171,90 +172,91 @@ private Q_SLOTS: QTest::addColumn<ClipBlendValue *>("blendNode"); QTest::addColumn<QVector<int>>("indexes"); QTest::addColumn<QVector<Qt3DCore::QNodeId>>("animatorIds"); - QTest::addColumn<QVector<ComponentIndices>>("expectedFormatIndices"); + QTest::addColumn<QVector<ClipFormat>>("expectedClipFormat"); // Single entry { auto blendNode = new ClipBlendValue; QVector<Qt3DCore::QNodeId> animatorIds; - QVector<ComponentIndices> expectedFormatIndices; + QVector<ClipFormat> expectedClipFormat; const auto animatorId = Qt3DCore::QNodeId::createId(); animatorIds.push_back(animatorId); - ComponentIndices formatIndices = { 0, 1, 2 }; - expectedFormatIndices.push_back(formatIndices); + ClipFormat clipFormat; + clipFormat.sourceClipIndices = { 0, 1, 2 }; + expectedClipFormat.push_back(clipFormat); // Set data and indexes - blendNode->setFormatIndices(animatorId, formatIndices); + blendNode->setClipFormat(animatorId, clipFormat); QVector<int> indexes = QVector<int>() << 0; QTest::newRow("single entry") - << blendNode << indexes << animatorIds << expectedFormatIndices; + << blendNode << indexes << animatorIds << expectedClipFormat; } // No data { auto blendNode = new ClipBlendValue; QVector<Qt3DCore::QNodeId> animatorIds; - QVector<ComponentIndices> expectedFormatIndices; + QVector<ClipFormat> expectedClipFormat; auto animatorId = Qt3DCore::QNodeId::createId(); animatorIds.push_back(animatorId); - ComponentIndices formatIndices; - expectedFormatIndices.push_back(formatIndices); + ClipFormat clipFormat; + expectedClipFormat.push_back(clipFormat); // Don't set any data QVector<int> indexes = QVector<int>() << 0; QTest::newRow("no entries") - << blendNode << indexes << animatorIds << expectedFormatIndices; + << blendNode << indexes << animatorIds << expectedClipFormat; } // Multiple entries, ordered { auto blendNode = new ClipBlendValue; QVector<Qt3DCore::QNodeId> animatorIds; - QVector<ComponentIndices> expectedFormatIndices; + QVector<ClipFormat> expectedClipFormat; const int animatorCount = 10; for (int j = 0; j < animatorCount; ++j) { auto animatorId = Qt3DCore::QNodeId::createId(); animatorIds.push_back(animatorId); - ComponentIndices formatIndices; + ClipFormat clipFormat; for (int i = 0; i < j + 5; ++i) - formatIndices.push_back(i + j); - expectedFormatIndices.push_back(formatIndices); + clipFormat.sourceClipIndices.push_back(i + j); + expectedClipFormat.push_back(clipFormat); - blendNode->setFormatIndices(animatorId, formatIndices); + blendNode->setClipFormat(animatorId, clipFormat); } QVector<int> indexes(animatorCount); std::iota(indexes.begin(), indexes.end(), 0); QTest::newRow("multiple entries, ordered") - << blendNode << indexes << animatorIds << expectedFormatIndices; + << blendNode << indexes << animatorIds << expectedClipFormat; } // Multiple entries, unordered { auto blendNode = new ClipBlendValue; QVector<Qt3DCore::QNodeId> animatorIds; - QVector<ComponentIndices> expectedFormatIndices; + QVector<ClipFormat> expectedClipFormat; const int animatorCount = 10; for (int j = 0; j < animatorCount; ++j) { auto animatorId = Qt3DCore::QNodeId::createId(); animatorIds.push_back(animatorId); - ComponentIndices formatIndices; + ClipFormat clipFormat; for (int i = 0; i < j + 5; ++i) - formatIndices.push_back(i + j); - expectedFormatIndices.push_back(formatIndices); + clipFormat.sourceClipIndices.push_back(i + j); + expectedClipFormat.push_back(clipFormat); - blendNode->setFormatIndices(animatorId, formatIndices); + blendNode->setClipFormat(animatorId, clipFormat); } // Shuffle the animatorIds to randomise the lookups @@ -265,7 +267,7 @@ private Q_SLOTS: std::shuffle(indexes.begin(), indexes.end(), generator); QTest::newRow("multiple entries, unordered") - << blendNode << indexes << animatorIds << expectedFormatIndices; + << blendNode << indexes << animatorIds << expectedClipFormat; } } @@ -275,17 +277,17 @@ private Q_SLOTS: QFETCH(ClipBlendValue *, blendNode); QFETCH(QVector<int>, indexes); QFETCH(QVector<Qt3DCore::QNodeId>, animatorIds); - QFETCH(QVector<ComponentIndices>, expectedFormatIndices); + QFETCH(QVector<ClipFormat>, expectedClipFormat); for (int i = 0; i < indexes.size(); ++i) { // WHEN const int index = indexes[i]; - const ComponentIndices actualFormatIndices = blendNode->formatIndices(animatorIds[index]); + const ClipFormat actualClipFormat = blendNode->clipFormat(animatorIds[index]); // THEN - QCOMPARE(actualFormatIndices.size(), expectedFormatIndices[index].size()); - for (int j = 0; j < actualFormatIndices.size(); ++j) - QCOMPARE(actualFormatIndices[j], expectedFormatIndices[index][j]); + QCOMPARE(actualClipFormat.sourceClipIndices.size(), expectedClipFormat[index].sourceClipIndices.size()); + for (int j = 0; j < actualClipFormat.sourceClipIndices.size(); ++j) + QCOMPARE(actualClipFormat.sourceClipIndices[j], expectedClipFormat[index].sourceClipIndices[j]); } delete blendNode; |