| 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 | #include "clipblendvalue_p.h" |
| 5 | #include <Qt3DAnimation/qclipblendvalue.h> |
| 6 | #include <Qt3DAnimation/private/qclipblendvalue_p.h> |
| 7 | |
| 8 | QT_BEGIN_NAMESPACE |
| 9 | |
| 10 | namespace Qt3DAnimation { |
| 11 | namespace Animation { |
| 12 | |
| 13 | ClipBlendValue::ClipBlendValue() |
| 14 | : ClipBlendNode(ValueType) |
| 15 | { |
| 16 | } |
| 17 | |
| 18 | ClipBlendValue::~ClipBlendValue() |
| 19 | { |
| 20 | } |
| 21 | |
| 22 | void ClipBlendValue::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) |
| 23 | { |
| 24 | BackendNode::syncFromFrontEnd(frontEnd, firstTime); |
| 25 | const QClipBlendValue *node = qobject_cast<const QClipBlendValue *>(object: frontEnd); |
| 26 | if (!node) |
| 27 | return; |
| 28 | |
| 29 | m_clipId = Qt3DCore::qIdForNode(node: node->clip()); |
| 30 | } |
| 31 | |
| 32 | ClipResults ClipBlendValue::doBlend(const QList<ClipResults> &blendData) const |
| 33 | { |
| 34 | // Should never be called for the value node |
| 35 | Q_UNUSED(blendData); |
| 36 | Q_UNREACHABLE_RETURN(ClipResults()); |
| 37 | } |
| 38 | |
| 39 | double ClipBlendValue::duration() const |
| 40 | { |
| 41 | if (m_clipId.isNull()) |
| 42 | return 0.0; |
| 43 | AnimationClip *clip = m_handler->animationClipLoaderManager()->lookupResource(id: m_clipId); |
| 44 | Q_ASSERT(clip); |
| 45 | return clip->duration(); |
| 46 | } |
| 47 | |
| 48 | void ClipBlendValue::setClipFormat(Qt3DCore::QNodeId animatorId, const ClipFormat &formatIndices) |
| 49 | { |
| 50 | // Do we already have an entry for this animator? |
| 51 | const int animatorIndex = m_animatorIds.indexOf(t: animatorId); |
| 52 | if (animatorIndex == -1) { |
| 53 | // Nope, add it |
| 54 | m_animatorIds.push_back(t: animatorId); |
| 55 | m_clipFormats.push_back(t: formatIndices); |
| 56 | } else { |
| 57 | m_clipFormats[animatorIndex] = formatIndices; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | ClipFormat &ClipBlendValue::clipFormat(Qt3DCore::QNodeId animatorId) |
| 62 | { |
| 63 | const int animatorIndex = m_animatorIds.indexOf(t: animatorId); |
| 64 | return m_clipFormats[animatorIndex]; |
| 65 | } |
| 66 | |
| 67 | const ClipFormat &ClipBlendValue::clipFormat(Qt3DCore::QNodeId animatorId) const |
| 68 | { |
| 69 | const int animatorIndex = m_animatorIds.indexOf(t: animatorId); |
| 70 | return m_clipFormats[animatorIndex]; |
| 71 | } |
| 72 | |
| 73 | } // namespace Animation |
| 74 | } // namespace Qt3DAnimation |
| 75 | |
| 76 | QT_END_NAMESPACE |
| 77 |
