diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2017-01-27 11:24:13 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-01-29 09:39:42 +0000 |
commit | c576a24d4fac9cdbd05aa264bf75050ca2ef0a94 (patch) | |
tree | 30db5220dd04f73cbf42bced6490e6c1ac6eda02 | |
parent | d121ad34f93afd91c2bd97aeb1b9b74a67122825 (diff) |
Add backend nodes for the blend nodes
Also adds a ClipBlendNode manager in the backend to have polymorphism and a
proper tree structure
Change-Id: I64e03d4d31acece6d924e15ec8b3b7565e14168c
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r-- | src/animation/backend/backend.pri | 9 | ||||
-rw-r--r-- | src/animation/backend/clipblendnode.cpp | 167 | ||||
-rw-r--r-- | src/animation/backend/clipblendnode_p.h | 106 | ||||
-rw-r--r-- | src/animation/backend/lerpblend.cpp | 79 | ||||
-rw-r--r-- | src/animation/backend/lerpblend_p.h | 82 | ||||
-rw-r--r-- | src/animation/backend/managers.cpp | 80 | ||||
-rw-r--r-- | src/animation/backend/managers_p.h | 17 | ||||
-rw-r--r-- | tests/auto/animation/animation.pro | 5 | ||||
-rw-r--r-- | tests/auto/animation/clipblendnode/clipblendnode.pro | 11 | ||||
-rw-r--r-- | tests/auto/animation/clipblendnode/tst_clipblendnode.cpp | 225 | ||||
-rw-r--r-- | tests/auto/animation/clipblendnodemanager/clipblendnodemanager.pro | 11 | ||||
-rw-r--r-- | tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp | 175 | ||||
-rw-r--r-- | tests/auto/animation/lerpblend/lerpblend.pro | 11 | ||||
-rw-r--r-- | tests/auto/animation/lerpblend/tst_lerpblend.cpp | 119 |
14 files changed, 1094 insertions, 3 deletions
diff --git a/src/animation/backend/backend.pri b/src/animation/backend/backend.pri index 5bbf5a3ed..30fa92d0d 100644 --- a/src/animation/backend/backend.pri +++ b/src/animation/backend/backend.pri @@ -19,7 +19,9 @@ HEADERS += \ $$PWD/channelmapping_p.h \ $$PWD/channelmapper_p.h \ $$PWD/findrunningclipanimatorsjob_p.h \ - $$PWD/evaluateclipanimatorjob_p.h + $$PWD/evaluateclipanimatorjob_p.h \ + $$PWD/clipblendnode_p.h \ + $$PWD/lerpblend_p.h SOURCES += \ $$PWD/animationclip.cpp \ @@ -35,4 +37,7 @@ SOURCES += \ $$PWD/channelmapping.cpp \ $$PWD/channelmapper.cpp \ $$PWD/findrunningclipanimatorsjob.cpp \ - $$PWD/evaluateclipanimatorjob.cpp + $$PWD/evaluateclipanimatorjob.cpp \ + $$PWD/clipblendnode.cpp \ + $$PWD/lerpblend.cpp \ + $$PWD/managers.cpp diff --git a/src/animation/backend/clipblendnode.cpp b/src/animation/backend/clipblendnode.cpp new file mode 100644 index 000000000..cd2c1701f --- /dev/null +++ b/src/animation/backend/clipblendnode.cpp @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "clipblendnode_p.h" +#include <Qt3DAnimation/qclipblendnodecreatedchange.h> +#include <Qt3DAnimation/qanimationclip.h> +#include <Qt3DAnimation/private/managers_p.h> +#include <Qt3DCore/qpropertynoderemovedchange.h> +#include <Qt3DCore/qpropertynodeaddedchange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { + +namespace Animation { + +ClipBlendNode::ClipBlendNode(BlendType blendType) + : m_manager(nullptr) + , m_blendType(blendType) +{ +} + +ClipBlendNode::~ClipBlendNode() +{ +} + +Qt3DCore::QNodeId ClipBlendNode::parentId() const +{ + return m_parentId; +} + +Qt3DCore::QNodeIdVector ClipBlendNode::childrenIds() const +{ + return m_childrenIds; +} + +Qt3DCore::QNodeIdVector ClipBlendNode::clipIds() const +{ + return m_clipIds; +} + +void ClipBlendNode::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) +{ + switch (e->type()) { + + case Qt3DCore::PropertyValueAdded: { + Qt3DCore::QPropertyNodeAddedChangePtr change = qSharedPointerCast<Qt3DCore::QPropertyNodeAddedChange>(e); + if (change->metaObject()->inherits(&QAbstractClipBlendNode::staticMetaObject)) + addChildId(change->addedNodeId()); + else if (change->metaObject()->inherits(&QAnimationClip::staticMetaObject)) + m_clipIds.push_back(change->addedNodeId()); + break; + } + + case Qt3DCore::PropertyValueRemoved: { + Qt3DCore::QPropertyNodeRemovedChangePtr change = qSharedPointerCast<Qt3DCore::QPropertyNodeRemovedChange>(e); + if (change->metaObject()->inherits(&QAbstractClipBlendNode::staticMetaObject)) + removeChildId(change->removedNodeId()); + else if (change->metaObject()->inherits(&QAnimationClip::staticMetaObject)) + m_clipIds.removeOne(change->removedNodeId()); + break; + } + + default: + break; + } + + Qt3DCore::QBackendNode::sceneChangeEvent(e); +} + +void ClipBlendNode::setClipBlendNodeManager(ClipBlendNodeManager *manager) +{ + m_manager = manager; +} + +ClipBlendNodeManager *ClipBlendNode::clipBlendNodeManager() const +{ + return m_manager; +} + +void ClipBlendNode::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) +{ + const auto creationChange = qSharedPointerCast<QClipBlendNodeCreatedChangeBase>(change); + setParentId(creationChange->parentClipBlendNodeId()); + m_clipIds = creationChange->clips(); +} + +void ClipBlendNode::setParentId(Qt3DCore::QNodeId parentId) +{ + if (parentId != m_parentId) { + // We already had a parent, tell it to abandon us + if (!m_parentId.isNull()) { + ClipBlendNode *parent = m_manager->lookupNode(m_parentId); + if (parent != nullptr) + parent->m_childrenIds.removeAll(peerId()); + } + m_parentId = parentId; + ClipBlendNode *parent = m_manager->lookupNode(m_parentId); + if (parent != nullptr && !parent->m_childrenIds.contains(peerId())) + parent->m_childrenIds.append(peerId()); + } +} + +void ClipBlendNode::addChildId(Qt3DCore::QNodeId childId) +{ + if (!m_childrenIds.contains(childId)) { + ClipBlendNode *child = m_manager->lookupNode(childId); + if (child != nullptr) { + m_childrenIds.push_back(childId); + child->m_parentId = peerId(); + } + } +} + +void ClipBlendNode::removeChildId(Qt3DCore::QNodeId childId) +{ + if (m_childrenIds.contains(childId)) { + ClipBlendNode *child = m_manager->lookupNode(childId); + if (child != nullptr) + child->m_parentId = Qt3DCore::QNodeId(); + m_childrenIds.removeAll(childId); + } +} + +ClipBlendNode::BlendType Animation::ClipBlendNode::blendType() const +{ + return m_blendType; +} + +} // Animation + +} // Qt3DAnimation + +QT_END_NAMESPACE diff --git a/src/animation/backend/clipblendnode_p.h b/src/animation/backend/clipblendnode_p.h new file mode 100644 index 000000000..e4756ee67 --- /dev/null +++ b/src/animation/backend/clipblendnode_p.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DANIMATION_ANIMATION_CLIPBLENDNODE_P_H +#define QT3DANIMATION_ANIMATION_CLIPBLENDNODE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DCore/qnodeid.h> +#include <Qt3DCore/qbackendnode.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { + +namespace Animation { + +class ClipBlendNodeManager; + +class Q_AUTOTEST_EXPORT ClipBlendNode : public Qt3DCore::QBackendNode +{ +public: + ~ClipBlendNode(); + + enum BlendType { + NoneBlendType, + LerpBlendType + }; + + void setClipBlendNodeManager(ClipBlendNodeManager *manager); + + ClipBlendNodeManager *clipBlendNodeManager() const; + BlendType blendType() const; + Qt3DCore::QNodeId parentId() const; + Qt3DCore::QNodeIdVector childrenIds() const; + Qt3DCore::QNodeIdVector clipIds() const; + + void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_OVERRIDE; + +protected: + explicit ClipBlendNode(BlendType blendType); + void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_OVERRIDE; + +private: + void setParentId(Qt3DCore::QNodeId parentId); + void addChildId(Qt3DCore::QNodeId childId); + void removeChildId(Qt3DCore::QNodeId childId); + + // Can either contain clips or nothing (tree of other blend nodes) + Qt3DCore::QNodeIdVector m_clipIds; + + Qt3DCore::QNodeId m_parentId; + Qt3DCore::QNodeIdVector m_childrenIds; + ClipBlendNodeManager *m_manager; + BlendType m_blendType; +}; + +} // Animation + +} // Qt3DAnimation + +QT_END_NAMESPACE + +#endif // QT3DANIMATION_ANIMATION_CLIPBLENDNODE_P_H diff --git a/src/animation/backend/lerpblend.cpp b/src/animation/backend/lerpblend.cpp new file mode 100644 index 000000000..29261aadf --- /dev/null +++ b/src/animation/backend/lerpblend.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "lerpblend_p.h" +#include <Qt3DAnimation/qclipblendnodecreatedchange.h> +#include <Qt3DAnimation/private/qlerpblend_p.h> +#include <Qt3DCore/qpropertyupdatedchange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { + +namespace Animation { + +LerpBlend::LerpBlend() + : ClipBlendNode(ClipBlendNode::LerpBlendType) + , m_blendFactor(0.0f) +{ +} + +LerpBlend::~LerpBlend() +{ +} + +void LerpBlend::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) +{ + if (e->type() == Qt3DCore::PropertyUpdated) { + Qt3DCore::QPropertyUpdatedChangePtr change = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e); + if (change->propertyName() == QByteArrayLiteral("blendFactor")) + m_blendFactor = change->value().toFloat(); + } +} + +void LerpBlend::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) +{ + ClipBlendNode::initializeFromPeer(change); + const auto creationChangeData = qSharedPointerCast<Qt3DAnimation::QClipBlendNodeCreatedChange<Qt3DAnimation::QLerpBlendData>>(change); + const Qt3DAnimation::QLerpBlendData cloneData = creationChangeData->data; + m_blendFactor = cloneData.blendFactor; +} + +} // Animation + +} // Qt3DAnimation + +QT_END_NAMESPACE diff --git a/src/animation/backend/lerpblend_p.h b/src/animation/backend/lerpblend_p.h new file mode 100644 index 000000000..e30f57694 --- /dev/null +++ b/src/animation/backend/lerpblend_p.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DANIMATION_ANIMATION_LERPBLEND_P_H +#define QT3DANIMATION_ANIMATION_LERPBLEND_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DAnimation/private/clipblendnode_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { + +namespace Animation { + +class Q_AUTOTEST_EXPORT LerpBlend : public ClipBlendNode +{ +public: + LerpBlend(); + ~LerpBlend(); + + inline float blendFactor() const { return m_blendFactor; } + +public: + void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_FINAL; + +private: + void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL; + + float m_blendFactor; +}; + +} // Animation + +} // Qt3DAnimation + +QT_END_NAMESPACE + +#endif // QT3DANIMATION_ANIMATION_LERPBLEND_P_H diff --git a/src/animation/backend/managers.cpp b/src/animation/backend/managers.cpp new file mode 100644 index 000000000..7c35c1d47 --- /dev/null +++ b/src/animation/backend/managers.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "managers_p.h" +#include <Qt3DAnimation/private/clipblendnode_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { +namespace Animation { + +ClipBlendNodeManager::ClipBlendNodeManager() +{ +} + +ClipBlendNodeManager::~ClipBlendNodeManager() +{ + qDeleteAll(m_nodes); +} + +bool ClipBlendNodeManager::containsNode(Qt3DCore::QNodeId id) const +{ + return m_nodes.contains(id); +} + +void ClipBlendNodeManager::appendNode(Qt3DCore::QNodeId id, ClipBlendNode *node) +{ + m_nodes.insert(id, node); +} + +ClipBlendNode *ClipBlendNodeManager::lookupNode(Qt3DCore::QNodeId id) const +{ + return m_nodes.value(id, nullptr); +} + +void ClipBlendNodeManager::releaseNode(Qt3DCore::QNodeId id) +{ + delete m_nodes.take(id); +} + +} // namespace Animation +} // namespace Qt3DAnimation + +QT_END_NAMESPACE diff --git a/src/animation/backend/managers_p.h b/src/animation/backend/managers_p.h index eb34ee5cd..42484921f 100644 --- a/src/animation/backend/managers_p.h +++ b/src/animation/backend/managers_p.h @@ -66,6 +66,8 @@ QT_BEGIN_NAMESPACE namespace Qt3DAnimation { namespace Animation { +class ClipBlendNode; + class AnimationClipManager : public Qt3DCore::QResourceManager< AnimationClip, Qt3DCore::QNodeId, @@ -126,6 +128,21 @@ public: ChannelMapperManager() {} }; +class Q_AUTOTEST_EXPORT ClipBlendNodeManager +{ +public: + ClipBlendNodeManager(); + ~ClipBlendNodeManager(); + + bool containsNode(Qt3DCore::QNodeId id) const; + void appendNode(Qt3DCore::QNodeId id, ClipBlendNode *node); + ClipBlendNode *lookupNode(Qt3DCore::QNodeId id) const; + void releaseNode(Qt3DCore::QNodeId id); + +private: + QHash<Qt3DCore::QNodeId, ClipBlendNode *> m_nodes; +}; + } // namespace Animation } // namespace Qt3DAnimation diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index 3dfe89824..6c3c38692 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -21,5 +21,8 @@ qtConfig(private_tests) { conductedclipanimator \ channelmapper \ channelmapping \ - qlerpblend + qlerpblend \ + clipblendnodemanager \ + clipblendnode \ + lerpblend } diff --git a/tests/auto/animation/clipblendnode/clipblendnode.pro b/tests/auto/animation/clipblendnode/clipblendnode.pro new file mode 100644 index 000000000..40af4e53d --- /dev/null +++ b/tests/auto/animation/clipblendnode/clipblendnode.pro @@ -0,0 +1,11 @@ +TEMPLATE = app + +TARGET = tst_clipblendnode + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += tst_clipblendnode.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp new file mode 100644 index 000000000..c045c2112 --- /dev/null +++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp @@ -0,0 +1,225 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Paul Lemire <paul.lemire350@gmail.com> +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtTest/QTest> +#include <Qt3DAnimation/qlerpblend.h> +#include <Qt3DAnimation/qanimationclip.h> +#include <Qt3DAnimation/private/qabstractclipblendnode_p.h> +#include <Qt3DAnimation/private/clipblendnode_p.h> +#include <Qt3DAnimation/private/managers_p.h> +#include <Qt3DCore/qpropertyupdatedchange.h> +#include <Qt3DCore/qpropertynodeaddedchange.h> +#include <Qt3DCore/qpropertynoderemovedchange.h> +#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h> +#include "qbackendnodetester.h" + +namespace { + +class TestClipBlendNode : public Qt3DAnimation::Animation::ClipBlendNode +{ +public: + TestClipBlendNode() + : Qt3DAnimation::Animation::ClipBlendNode(Qt3DAnimation::Animation::ClipBlendNode::LerpBlendType) + {} +}; + +} // anonymous + +class tst_ClipBlendNode : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + + void checkInitialState() + { + // GIVEN + TestClipBlendNode backendClipBlendNode; + + // THEN + QCOMPARE(backendClipBlendNode.isEnabled(), false); + QVERIFY(backendClipBlendNode.peerId().isNull()); + QCOMPARE(backendClipBlendNode.clipIds(), Qt3DCore::QNodeIdVector()); + QCOMPARE(backendClipBlendNode.parentId(), Qt3DCore::QNodeId()); + QCOMPARE(backendClipBlendNode.childrenIds(), Qt3DCore::QNodeIdVector()); + QVERIFY(backendClipBlendNode.clipBlendNodeManager() == nullptr); + QCOMPARE(backendClipBlendNode.blendType(), Qt3DAnimation::Animation::ClipBlendNode::LerpBlendType); + } + + void checkInitializeFromPeer() + { + // GIVEN + Qt3DAnimation::QLerpBlend clipBlendNode; + Qt3DAnimation::QAnimationClip clip; + clipBlendNode.addClip(&clip); + + QCoreApplication::processEvents(); + + { + // WHEN + Qt3DAnimation::Animation::ClipBlendNodeManager manager; + TestClipBlendNode backendClipBlendNode; + backendClipBlendNode.setClipBlendNodeManager(&manager); + simulateInitialization(&clipBlendNode, &backendClipBlendNode); + + // THEN + QCOMPARE(backendClipBlendNode.isEnabled(), true); + QCOMPARE(backendClipBlendNode.peerId(), clipBlendNode.id()); + QCOMPARE(backendClipBlendNode.clipIds().size(), 1); + QCOMPARE(backendClipBlendNode.clipIds().first(), clip.id()); + QCOMPARE(backendClipBlendNode.parentId(), Qt3DCore::QNodeId()); + QCOMPARE(backendClipBlendNode.childrenIds().size(), 0); + QCOMPARE(backendClipBlendNode.clipBlendNodeManager(), &manager); + QCOMPARE(backendClipBlendNode.blendType(), Qt3DAnimation::Animation::ClipBlendNode::LerpBlendType); + } + { + // WHEN + Qt3DAnimation::Animation::ClipBlendNodeManager manager; + TestClipBlendNode backendClipBlendNode; + clipBlendNode.setEnabled(false); + backendClipBlendNode.setClipBlendNodeManager(&manager); + simulateInitialization(&clipBlendNode, &backendClipBlendNode); + + // THEN + QCOMPARE(backendClipBlendNode.peerId(), clipBlendNode.id()); + QCOMPARE(backendClipBlendNode.isEnabled(), false); + } + } + + void checkSceneChangeEvents() + { + // GIVEN + TestClipBlendNode backendClipBlendNode; + Qt3DAnimation::Animation::ClipBlendNodeManager manager; + backendClipBlendNode.setClipBlendNodeManager(&manager); + { + // WHEN + const bool newValue = false; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("enabled"); + change->setValue(newValue); + backendClipBlendNode.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendClipBlendNode.isEnabled(), newValue); + } + { + // WHEN + Qt3DAnimation::QAnimationClip clip; + // To geneate the type_info in the QNodePrivate of clip + Qt3DCore::QNodeCreatedChangeGenerator generator(&clip); + + const auto addedChange = Qt3DCore::QPropertyNodeAddedChangePtr::create(Qt3DCore::QNodeId(), &clip); + backendClipBlendNode.sceneChangeEvent(addedChange); + + // THEN + QCOMPARE(backendClipBlendNode.clipIds().size(), 1); + QCOMPARE(backendClipBlendNode.clipIds().first(), clip.id()); + + // WHEN + const auto removedChange = Qt3DCore::QPropertyNodeRemovedChangePtr::create(Qt3DCore::QNodeId(), &clip); + backendClipBlendNode.sceneChangeEvent(removedChange); + + // THEN + QCOMPARE(backendClipBlendNode.clipIds().size(), 0); + } + { + // WHEN + Qt3DAnimation::QLerpBlend clipBlendChild; + // Will be destroyed when manager is destroyed + TestClipBlendNode *backenChildClipBlendNode = new TestClipBlendNode(); + backendClipBlendNode.setClipBlendNodeManager(&manager); + manager.appendNode(clipBlendChild.id(), backenChildClipBlendNode); + + // To geneate the type_info in the QNodePrivate of clipBlendChild + Qt3DCore::QNodeCreatedChangeGenerator generator(&clipBlendChild); + const auto addChange = Qt3DCore::QPropertyNodeAddedChangePtr::create(Qt3DCore::QNodeId(), &clipBlendChild); + backendClipBlendNode.sceneChangeEvent(addChange); + + // THEN + QCOMPARE(backendClipBlendNode.childrenIds().size(), 1); + QCOMPARE(backendClipBlendNode.childrenIds().first(), clipBlendChild.id()); + + // WHEN + const auto removedChange = Qt3DCore::QPropertyNodeRemovedChangePtr::create(Qt3DCore::QNodeId(), &clipBlendChild); + backendClipBlendNode.sceneChangeEvent(removedChange); + + // THEN + QCOMPARE(backendClipBlendNode.childrenIds().size(), 0); + } + } + + void checkParentInitialization() + { + // GIVEN + TestClipBlendNode *backendClipBlendNode = new TestClipBlendNode(); + TestClipBlendNode *backendChildClipBlendNode = new TestClipBlendNode(); + Qt3DAnimation::QLerpBlend clipBlendParent; + Qt3DAnimation::QLerpBlend childClipBlend(&clipBlendParent); + Qt3DAnimation::Animation::ClipBlendNodeManager manager; + backendClipBlendNode->setClipBlendNodeManager(&manager); + backendChildClipBlendNode->setClipBlendNodeManager(&manager); + + // THEN + QCOMPARE(backendClipBlendNode->parentId(), Qt3DCore::QNodeId()); + QCOMPARE(backendClipBlendNode->childrenIds().size(), 0); + QCOMPARE(backendChildClipBlendNode->parentId(), Qt3DCore::QNodeId()); + QCOMPARE(backendChildClipBlendNode->childrenIds().size(), 0); + + // WHEN + manager.appendNode(clipBlendParent.id(), backendClipBlendNode); + manager.appendNode(childClipBlend.id(), backendChildClipBlendNode); + simulateInitialization(&clipBlendParent, backendClipBlendNode); + simulateInitialization(&childClipBlend, backendChildClipBlendNode); + + // THEN + QCOMPARE(backendClipBlendNode->parentId(), Qt3DCore::QNodeId()); + QCOMPARE(backendClipBlendNode->childrenIds().size(), 1); + QCOMPARE(backendClipBlendNode->childrenIds().first(), childClipBlend.id()); + QCOMPARE(backendChildClipBlendNode->parentId(), clipBlendParent.id()); + QCOMPARE(backendChildClipBlendNode->childrenIds().size(), 0); + + // WHEN + // To geneate the type_info in the QNodePrivate of clipBlendChild + Qt3DCore::QNodeCreatedChangeGenerator generator(&childClipBlend); + const auto removedChange = Qt3DCore::QPropertyNodeRemovedChangePtr::create(Qt3DCore::QNodeId(), &childClipBlend); + backendClipBlendNode->sceneChangeEvent(removedChange); + + // THEN + QCOMPARE(backendClipBlendNode->parentId(), Qt3DCore::QNodeId()); + QCOMPARE(backendClipBlendNode->childrenIds().size(), 0); + QCOMPARE(backendChildClipBlendNode->parentId(), Qt3DCore::QNodeId()); + QCOMPARE(backendChildClipBlendNode->childrenIds().size(), 0); + } + +}; + +QTEST_MAIN(tst_ClipBlendNode) + +#include "tst_clipblendnode.moc" diff --git a/tests/auto/animation/clipblendnodemanager/clipblendnodemanager.pro b/tests/auto/animation/clipblendnodemanager/clipblendnodemanager.pro new file mode 100644 index 000000000..6a874004b --- /dev/null +++ b/tests/auto/animation/clipblendnodemanager/clipblendnodemanager.pro @@ -0,0 +1,11 @@ +TEMPLATE = app + +TARGET = tst_clipblendnodemanager + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += tst_clipblendnodemanager.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp new file mode 100644 index 000000000..2cf549f7e --- /dev/null +++ b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp @@ -0,0 +1,175 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Paul Lemire <paul.lemire350@gmail.com> +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtTest/QTest> +#include <QObject> +#include <QSignalSpy> +#include <Qt3DAnimation/private/managers_p.h> +#include <Qt3DAnimation/private/clipblendnode_p.h> + +namespace { + +int deadCount = 0; + +class TestClipBlendNode : public Qt3DAnimation::Animation::ClipBlendNode +{ +public: + TestClipBlendNode() + : Qt3DAnimation::Animation::ClipBlendNode(Qt3DAnimation::Animation::ClipBlendNode::NoneBlendType) + {} + + ~TestClipBlendNode() + { + deadCount += 1; + } +}; + +} // anonymous + +class tst_ClipBlendNodeManager : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void checkCointainsNode() + { + // GIVEN + Qt3DAnimation::Animation::ClipBlendNodeManager manager; + const Qt3DCore::QNodeId nodeId = Qt3DCore::QNodeId::createId(); + + // THEN + QVERIFY(manager.containsNode(nodeId) == false); + + // WHEN + TestClipBlendNode *node = new TestClipBlendNode(); + manager.appendNode(nodeId, node); + + // THEN + QVERIFY(manager.containsNode(nodeId)); + } + + void checkAppendNode() + { + // GIVEN + Qt3DAnimation::Animation::ClipBlendNodeManager manager; + const Qt3DCore::QNodeId nodeId = Qt3DCore::QNodeId::createId(); + const Qt3DCore::QNodeId nodeId2 = Qt3DCore::QNodeId::createId(); + TestClipBlendNode *node = new TestClipBlendNode(); + TestClipBlendNode *node2 = new TestClipBlendNode(); + + // WHEN + manager.appendNode(nodeId, node); + manager.appendNode(nodeId2, node2); + + // THEN + QVERIFY(manager.containsNode(nodeId)); + QVERIFY(manager.containsNode(nodeId2)); + } + + void checkLookupNode() + { + // GIVEN + Qt3DAnimation::Animation::ClipBlendNodeManager manager; + const Qt3DCore::QNodeId nodeId = Qt3DCore::QNodeId::createId(); + const Qt3DCore::QNodeId nodeId2 = Qt3DCore::QNodeId::createId(); + TestClipBlendNode *node = new TestClipBlendNode(); + TestClipBlendNode *node2 = new TestClipBlendNode(); + + // WHEN + manager.appendNode(nodeId, node); + manager.appendNode(nodeId2, node2); + Qt3DAnimation::Animation::ClipBlendNode *lookedUpNode = manager.lookupNode(nodeId); + + // THEN + QCOMPARE(lookedUpNode, node); + + // WHEN + lookedUpNode = manager.lookupNode(nodeId2); + + // THEN + QCOMPARE(lookedUpNode, node2); + + // WHEN + lookedUpNode = manager.lookupNode(Qt3DCore::QNodeId::createId()); + + // THEN + QVERIFY(lookedUpNode == nullptr); + } + + void checkReleaseNode() + { + // GIVEN + Qt3DAnimation::Animation::ClipBlendNodeManager manager; + const Qt3DCore::QNodeId nodeId = Qt3DCore::QNodeId::createId(); + TestClipBlendNode *node = new TestClipBlendNode(); + deadCount = 0; + + // WHEN + manager.appendNode(nodeId, node); + + // THEN + QCOMPARE(deadCount, 0); + + // WHEN + manager.releaseNode(nodeId); + + // THEN + QCOMPARE(deadCount, 1); + } + + void checkDestruction() + { + // GIVEN + const Qt3DCore::QNodeId nodeId = Qt3DCore::QNodeId::createId(); + const Qt3DCore::QNodeId nodeId2 = Qt3DCore::QNodeId::createId(); + TestClipBlendNode *node = new TestClipBlendNode(); + TestClipBlendNode *node2 = new TestClipBlendNode(); + + // WHEN + { + Qt3DAnimation::Animation::ClipBlendNodeManager manager; + deadCount = 0; + + // WHEN + manager.appendNode(nodeId, node); + manager.appendNode(nodeId2, node2); + + // THEN + QCOMPARE(deadCount, 0); + } + + // THEN + QCOMPARE(deadCount, 2); + } +}; + +QTEST_MAIN(tst_ClipBlendNodeManager) + +#include "tst_clipblendnodemanager.moc" diff --git a/tests/auto/animation/lerpblend/lerpblend.pro b/tests/auto/animation/lerpblend/lerpblend.pro new file mode 100644 index 000000000..bc2cc383b --- /dev/null +++ b/tests/auto/animation/lerpblend/lerpblend.pro @@ -0,0 +1,11 @@ +TEMPLATE = app + +TARGET = tst_lerpblend + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += tst_lerpblend.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/lerpblend/tst_lerpblend.cpp b/tests/auto/animation/lerpblend/tst_lerpblend.cpp new file mode 100644 index 000000000..9d758e7c4 --- /dev/null +++ b/tests/auto/animation/lerpblend/tst_lerpblend.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Paul Lemire <paul.lemire350@gmail.com> +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtTest/QTest> +#include <Qt3DAnimation/qlerpblend.h> +#include <Qt3DAnimation/qanimationclip.h> +#include <Qt3DAnimation/private/qlerpblend_p.h> +#include <Qt3DAnimation/private/lerpblend_p.h> +#include <Qt3DCore/qpropertyupdatedchange.h> +#include "qbackendnodetester.h" + +class tst_LerpBlend : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + + void checkInitialState() + { + // GIVEN + Qt3DAnimation::Animation::LerpBlend backendLerpBlend; + + // THEN + QCOMPARE(backendLerpBlend.isEnabled(), false); + QVERIFY(backendLerpBlend.peerId().isNull()); + QCOMPARE(backendLerpBlend.blendFactor(), 0.0f); + } + + void checkInitializeFromPeer() + { + // GIVEN + Qt3DAnimation::QLerpBlend lerpBlend; + Qt3DAnimation::QAnimationClip clip; + lerpBlend.setBlendFactor(0.8f); + lerpBlend.addClip(&clip); + + { + // WHEN + Qt3DAnimation::Animation::LerpBlend backendLerpBlend; + simulateInitialization(&lerpBlend, &backendLerpBlend); + + // THEN + QCOMPARE(backendLerpBlend.isEnabled(), true); + QCOMPARE(backendLerpBlend.peerId(), lerpBlend.id()); + QCOMPARE(backendLerpBlend.blendFactor(), 0.8f); + QCOMPARE(backendLerpBlend.clipIds().size(), 1); + QCOMPARE(backendLerpBlend.clipIds().first(), clip.id()); + } + { + // WHEN + Qt3DAnimation::Animation::LerpBlend backendLerpBlend; + lerpBlend.setEnabled(false); + simulateInitialization(&lerpBlend, &backendLerpBlend); + + // THEN + QCOMPARE(backendLerpBlend.peerId(), lerpBlend.id()); + QCOMPARE(backendLerpBlend.isEnabled(), false); + } + } + + void checkSceneChangeEvents() + { + // GIVEN + Qt3DAnimation::Animation::LerpBlend backendLerpBlend; + { + // WHEN + const bool newValue = false; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("enabled"); + change->setValue(newValue); + backendLerpBlend.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendLerpBlend.isEnabled(), newValue); + } + { + // WHEN + const float newValue = 0.883f; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("blendFactor"); + change->setValue(QVariant::fromValue(newValue)); + backendLerpBlend.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendLerpBlend.blendFactor(), newValue); + } + } + +}; + +QTEST_MAIN(tst_LerpBlend) + +#include "tst_lerpblend.moc" |