From c7d15b7c5e044f40167f4a79be8bf4f569c6b8be Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Thu, 16 Mar 2017 13:26:41 +0000 Subject: Add function to recursively calculate duration of a blend tree The resulting duration is independent of which animators the blend tree is associated with so this can be implemented as a simple set of virtual functions in the concrete classes. The value node simply returns the duration of the contained clip; the additive node returns the duration of the base node; and the lerp node lerps the durations of the start and end nodes. Change-Id: Ib6edea3fa495885493fa72d44437fea5a8c5a446 Reviewed-by: Paul Lemire Reviewed-by: Mike Krus --- .../additiveclipblend/tst_additiveclipblend.cpp | 60 +++++++++++++++++++++ .../animation/clipblendnode/tst_clipblendnode.cpp | 2 + .../tst_clipblendnodemanager.cpp | 2 + .../clipblendvalue/tst_clipblendvalue.cpp | 28 ++++++++++ .../animation/lerpclipblend/tst_lerpclipblend.cpp | 62 ++++++++++++++++++++++ 5 files changed, 154 insertions(+) (limited to 'tests') diff --git a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp index 2cc707fa5..7ec327cdc 100644 --- a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp +++ b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp @@ -37,9 +37,45 @@ using namespace Qt3DAnimation::Animation; +namespace { + +class TestClipBlendNode : public ClipBlendNode +{ +public: + TestClipBlendNode(double duration) + : ClipBlendNode(ClipBlendNode::LerpBlendType) + , m_duration(duration) + {} + + float blend(float, float) const Q_DECL_FINAL { return 0.0f; } + + QVector dependencyIds() const Q_DECL_FINAL + { + return QVector(); + } + + using ClipBlendNode::setClipResults; + + double duration() const Q_DECL_FINAL { return m_duration; } + + double m_duration; +}; + +} // anonymous + class tst_AdditiveClipBlend : public Qt3DCore::QBackendNodeTester { Q_OBJECT +public: + TestClipBlendNode *createTestBlendNode(Handler *handler, + double duration) + { + auto id = Qt3DCore::QNodeId::createId(); + TestClipBlendNode *node = new TestClipBlendNode(duration); + setPeerId(node, id); + handler->clipBlendNodeManager()->appendNode(id, node); + return node; + } private Q_SLOTS: @@ -201,6 +237,30 @@ private Q_SLOTS: QCOMPARE(actualIds[0], baseClipId); QCOMPARE(actualIds[1], anotherAdditiveClipId); } + + void checkDuration() + { + // GIVEN + auto handler = new Handler(); + const double expectedDuration = 123.5; + const double baseNodeDuration = expectedDuration; + const double additiveNodeDuration = 5.0; + + auto baseNode = createTestBlendNode(handler, baseNodeDuration); + auto additiveNode = createTestBlendNode(handler, additiveNodeDuration); + + AdditiveClipBlend blendNode; + blendNode.setHandler(handler); + blendNode.setClipBlendNodeManager(handler->clipBlendNodeManager()); + blendNode.setBaseClipId(baseNode->peerId()); + blendNode.setAdditiveClipId(additiveNode->peerId()); + + // WHEN + double actualDuration = blendNode.duration(); + + // THEN + QCOMPARE(actualDuration, expectedDuration); + } }; QTEST_MAIN(tst_AdditiveClipBlend) diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp index bc736ebb8..22d020c47 100644 --- a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp +++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp @@ -61,6 +61,8 @@ public: } using ClipBlendNode::setClipResults; + + double duration() const Q_DECL_FINAL { return 0.0f; } }; } // anonymous diff --git a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp index 6721401ee..8a3d0972f 100644 --- a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp +++ b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp @@ -55,6 +55,8 @@ public: { return QVector(); } + + double duration() const Q_DECL_FINAL { return 0.0f; } }; } // anonymous diff --git a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp index c23d98672..12eaf1a3c 100644 --- a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp +++ b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp @@ -40,6 +40,16 @@ using namespace Qt3DAnimation::Animation; class tst_ClipBlendValue : public Qt3DCore::QBackendNodeTester { Q_OBJECT +public: + AnimationClipLoader *createAnimationClipLoader(Handler *handler, + double duration) + { + auto clipId = Qt3DCore::QNodeId::createId(); + AnimationClipLoader *clip = handler->animationClipLoaderManager()->getOrCreateResource(clipId); + setPeerId(clip, clipId); + clip->setDuration(duration); + return clip; + } private Q_SLOTS: void checkInitialState() @@ -134,6 +144,24 @@ private Q_SLOTS: QCOMPARE(actualIds.size(), 1); QCOMPARE(actualIds[0], anotherClipId); } + + void checkDuration() + { + // GIVEN + auto handler = new Handler(); + const double expectedDuration = 123.5; + auto clip = createAnimationClipLoader(handler, expectedDuration); + ClipBlendValue clipNode; + clipNode.setHandler(handler); + clipNode.setClipBlendNodeManager(handler->clipBlendNodeManager()); + clipNode.setClipId(clip->peerId()); + + // WHEN + double actualDuration = clipNode.duration(); + + // THEN + QCOMPARE(actualDuration, expectedDuration); + } }; QTEST_MAIN(tst_ClipBlendValue) diff --git a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp index 34c52ff53..6dac3c8d9 100644 --- a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp +++ b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp @@ -37,9 +37,45 @@ using namespace Qt3DAnimation::Animation; +namespace { + +class TestClipBlendNode : public ClipBlendNode +{ +public: + TestClipBlendNode(double duration) + : ClipBlendNode(ClipBlendNode::LerpBlendType) + , m_duration(duration) + {} + + float blend(float, float) const Q_DECL_FINAL { return 0.0f; } + + QVector dependencyIds() const Q_DECL_FINAL + { + return QVector(); + } + + using ClipBlendNode::setClipResults; + + double duration() const Q_DECL_FINAL { return m_duration; } + + double m_duration; +}; + +} // anonymous + class tst_LerpClipBlend : public Qt3DCore::QBackendNodeTester { Q_OBJECT +public: + TestClipBlendNode *createTestBlendNode(Handler *handler, + double duration) + { + auto id = Qt3DCore::QNodeId::createId(); + TestClipBlendNode *node = new TestClipBlendNode(duration); + setPeerId(node, id); + handler->clipBlendNodeManager()->appendNode(id, node); + return node; + } private Q_SLOTS: @@ -171,6 +207,32 @@ private Q_SLOTS: QCOMPARE(actualIds[0], startClipId); QCOMPARE(actualIds[1], anotherEndClipId); } + + void checkDuration() + { + // GIVEN + auto handler = new Handler(); + const double startNodeDuration = 10.0; + const double endNodeDuration = 20.0; + const float blendFactor = 0.25f; + const double expectedDuration = 12.5; + + auto startNode = createTestBlendNode(handler, startNodeDuration); + auto endNode = createTestBlendNode(handler, endNodeDuration); + + LerpClipBlend blendNode; + blendNode.setHandler(handler); + blendNode.setClipBlendNodeManager(handler->clipBlendNodeManager()); + blendNode.setStartClipId(startNode->peerId()); + blendNode.setEndClipId(endNode->peerId()); + blendNode.setBlendFactor(blendFactor); + + // WHEN + double actualDuration = blendNode.duration(); + + // THEN + QCOMPARE(actualDuration, expectedDuration); + } }; QTEST_MAIN(tst_LerpClipBlend) -- cgit v1.2.3