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 "lerpclipblend_p.h" |
5 | #include <Qt3DAnimation/qlerpclipblend.h> |
6 | #include <Qt3DAnimation/private/qlerpclipblend_p.h> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | namespace Qt3DAnimation { |
11 | |
12 | namespace Animation { |
13 | |
14 | LerpClipBlend::LerpClipBlend() |
15 | : ClipBlendNode(ClipBlendNode::LerpBlendType) |
16 | , m_startClipId() |
17 | , m_endClipId() |
18 | , m_blendFactor(0.0f) |
19 | { |
20 | } |
21 | |
22 | LerpClipBlend::~LerpClipBlend() |
23 | { |
24 | } |
25 | |
26 | void LerpClipBlend::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) |
27 | { |
28 | BackendNode::syncFromFrontEnd(frontEnd, firstTime); |
29 | const QLerpClipBlend *node = qobject_cast<const QLerpClipBlend *>(object: frontEnd); |
30 | if (!node) |
31 | return; |
32 | |
33 | m_blendFactor = node->blendFactor(); |
34 | m_startClipId = Qt3DCore::qIdForNode(node: node->startClip()); |
35 | m_endClipId = Qt3DCore::qIdForNode(node: node->endClip()); |
36 | } |
37 | |
38 | ClipResults LerpClipBlend::doBlend(const QList<ClipResults> &blendData) const |
39 | { |
40 | Q_ASSERT(blendData.size() == 2); |
41 | Q_ASSERT(blendData[0].size() == blendData[1].size()); |
42 | const qsizetype elementCount = blendData.first().size(); |
43 | ClipResults blendResults(elementCount); |
44 | |
45 | for (qsizetype i = 0; i < elementCount; ++i) |
46 | blendResults[i] = (1.0f - m_blendFactor) * blendData[0][i] + (m_blendFactor * blendData[1][i]); |
47 | |
48 | return blendResults; |
49 | } |
50 | |
51 | double LerpClipBlend::duration() const |
52 | { |
53 | ClipBlendNode *startNode = clipBlendNodeManager()->lookupNode(id: m_startClipId); |
54 | const double startNodeDuration = startNode ? startNode->duration() : 0.0; |
55 | |
56 | ClipBlendNode *endNode = clipBlendNodeManager()->lookupNode(id: m_endClipId); |
57 | const double endNodeDuration = endNode ? endNode->duration() : 0.0; |
58 | |
59 | return (1.0 - static_cast<double>(m_blendFactor)) * startNodeDuration + static_cast<double>(m_blendFactor) * endNodeDuration; |
60 | } |
61 | |
62 | } // Animation |
63 | |
64 | } // Qt3DAnimation |
65 | |
66 | QT_END_NAMESPACE |
67 |