| 1 | // Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QT3DANIMATION_ANIMATION_CLIPBLENDNODE_P_H |
| 5 | #define QT3DANIMATION_ANIMATION_CLIPBLENDNODE_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists for the convenience |
| 12 | // of other Qt classes. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <Qt3DCore/qnodeid.h> |
| 19 | #include <Qt3DAnimation/private/backendnode_p.h> |
| 20 | #include <Qt3DAnimation/private/managers_p.h> |
| 21 | |
| 22 | QT_BEGIN_NAMESPACE |
| 23 | |
| 24 | namespace Qt3DAnimation { |
| 25 | |
| 26 | namespace Animation { |
| 27 | |
| 28 | class ClipBlendNodeManager; |
| 29 | |
| 30 | class Q_AUTOTEST_EXPORT ClipBlendNode : public BackendNode |
| 31 | { |
| 32 | public: |
| 33 | ~ClipBlendNode(); |
| 34 | |
| 35 | enum BlendType { |
| 36 | NoneBlendType, |
| 37 | LerpBlendType, |
| 38 | AdditiveBlendType, |
| 39 | ValueType |
| 40 | }; |
| 41 | |
| 42 | void setClipBlendNodeManager(ClipBlendNodeManager *manager); |
| 43 | inline ClipBlendNodeManager *clipBlendNodeManager() const { return m_manager; } |
| 44 | |
| 45 | BlendType blendType() const; |
| 46 | |
| 47 | void blend(Qt3DCore::QNodeId animatorId); |
| 48 | |
| 49 | void setClipResults(Qt3DCore::QNodeId animatorId, const ClipResults &clipResults); |
| 50 | ClipResults clipResults(Qt3DCore::QNodeId animatorId) const; |
| 51 | |
| 52 | virtual QList<Qt3DCore::QNodeId> allDependencyIds() const = 0; |
| 53 | virtual QList<Qt3DCore::QNodeId> currentDependencyIds() const = 0; |
| 54 | virtual double duration() const = 0; |
| 55 | |
| 56 | protected: |
| 57 | explicit ClipBlendNode(BlendType blendType); |
| 58 | virtual ClipResults doBlend(const QList<ClipResults> &blendData) const = 0; |
| 59 | |
| 60 | private: |
| 61 | ClipBlendNodeManager *m_manager; |
| 62 | BlendType m_blendType; |
| 63 | |
| 64 | // Store the results of evaluations indexed by animator id |
| 65 | QList<Qt3DCore::QNodeId> m_animatorIds; |
| 66 | QList<ClipResults> m_clipResults; |
| 67 | }; |
| 68 | |
| 69 | template<typename Backend, typename Frontend> |
| 70 | class ClipBlendNodeFunctor : public Qt3DCore::QBackendNodeMapper |
| 71 | { |
| 72 | public: |
| 73 | explicit ClipBlendNodeFunctor(Handler *handler, ClipBlendNodeManager *manager) |
| 74 | : m_handler(handler) |
| 75 | , m_manager(manager) |
| 76 | { |
| 77 | } |
| 78 | |
| 79 | Qt3DCore::QBackendNode *create(Qt3DCore::QNodeId id) const final |
| 80 | { |
| 81 | if (m_manager->containsNode(id)) |
| 82 | return static_cast<Backend *>(m_manager->lookupNode(id)); |
| 83 | Backend *backend = new Backend(); |
| 84 | backend->setClipBlendNodeManager(m_manager); |
| 85 | backend->setHandler(m_handler); |
| 86 | m_manager->appendNode(id, node: backend); |
| 87 | return backend; |
| 88 | } |
| 89 | |
| 90 | Qt3DCore::QBackendNode *get(Qt3DCore::QNodeId id) const final |
| 91 | { |
| 92 | return m_manager->lookupNode(id); |
| 93 | } |
| 94 | |
| 95 | void destroy(Qt3DCore::QNodeId id) const final |
| 96 | { |
| 97 | m_manager->releaseNode(id); |
| 98 | } |
| 99 | |
| 100 | private: |
| 101 | Handler *m_handler; |
| 102 | ClipBlendNodeManager *m_manager; |
| 103 | }; |
| 104 | |
| 105 | } // Animation |
| 106 | |
| 107 | } // Qt3DAnimation |
| 108 | |
| 109 | QT_END_NAMESPACE |
| 110 | |
| 111 | #endif // QT3DANIMATION_ANIMATION_CLIPBLENDNODE_P_H |
| 112 |
