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 "blendedclipanimator_p.h" |
5 | #include <Qt3DAnimation/qblendedclipanimator.h> |
6 | #include <Qt3DAnimation/qchannelmapper.h> |
7 | #include <Qt3DAnimation/qclock.h> |
8 | #include <Qt3DAnimation/qabstractclipblendnode.h> |
9 | #include <Qt3DAnimation/private/qblendedclipanimator_p.h> |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | namespace Qt3DAnimation { |
14 | namespace Animation { |
15 | |
16 | BlendedClipAnimator::BlendedClipAnimator() |
17 | : BackendNode(ReadWrite) |
18 | , m_running(false) |
19 | , m_lastGlobalTimeNS(0) |
20 | , m_lastLocalTime(0.0) |
21 | , m_currentLoop(0) |
22 | , m_loops(1) |
23 | , m_normalizedLocalTime(-1.0f) |
24 | , m_lastNormalizedLocalTime(-1.0) |
25 | { |
26 | } |
27 | |
28 | double BlendedClipAnimator::lastLocalTime() const |
29 | { |
30 | return m_lastLocalTime; |
31 | } |
32 | |
33 | void BlendedClipAnimator::setLastLocalTime(double lastLocalTime) |
34 | { |
35 | m_lastLocalTime = lastLocalTime; |
36 | } |
37 | |
38 | void BlendedClipAnimator::setLastNormalizedLocalTime(float normalizedTime) |
39 | { |
40 | m_lastNormalizedLocalTime = normalizedTime; |
41 | } |
42 | |
43 | void BlendedClipAnimator::setLastGlobalTimeNS(const qint64 &lastGlobalTimeNS) |
44 | { |
45 | m_lastGlobalTimeNS = lastGlobalTimeNS; |
46 | } |
47 | |
48 | qint64 BlendedClipAnimator::nsSincePreviousFrame(qint64 currentGlobalTimeNS) |
49 | { |
50 | return currentGlobalTimeNS - m_lastGlobalTimeNS; |
51 | } |
52 | |
53 | void BlendedClipAnimator::cleanup() |
54 | { |
55 | setEnabled(false); |
56 | m_handler = nullptr; |
57 | m_blendTreeRootId = Qt3DCore::QNodeId(); |
58 | m_mapperId = Qt3DCore::QNodeId(); |
59 | m_clockId = Qt3DCore::QNodeId(); |
60 | m_running = false; |
61 | m_lastGlobalTimeNS = 0; |
62 | m_lastLocalTime = 0.0; |
63 | m_currentLoop = 0; |
64 | m_loops = 1; |
65 | } |
66 | |
67 | void BlendedClipAnimator::setBlendTreeRootId(Qt3DCore::QNodeId blendTreeId) |
68 | { |
69 | m_blendTreeRootId = blendTreeId; |
70 | setDirty(Handler::BlendedClipAnimatorDirty); |
71 | } |
72 | |
73 | void BlendedClipAnimator::setMapperId(Qt3DCore::QNodeId mapperId) |
74 | { |
75 | m_mapperId = mapperId; |
76 | setDirty(Handler::BlendedClipAnimatorDirty); |
77 | } |
78 | |
79 | void BlendedClipAnimator::setClockId(Qt3DCore::QNodeId clockId) |
80 | { |
81 | m_clockId = clockId; |
82 | setDirty(Handler::BlendedClipAnimatorDirty); |
83 | } |
84 | |
85 | void BlendedClipAnimator::setRunning(bool running) |
86 | { |
87 | m_running = running; |
88 | setDirty(Handler::BlendedClipAnimatorDirty); |
89 | } |
90 | |
91 | |
92 | Qt3DCore::QNodeId BlendedClipAnimator::blendTreeRootId() const |
93 | { |
94 | return m_blendTreeRootId; |
95 | } |
96 | |
97 | void BlendedClipAnimator::setNormalizedLocalTime(float normalizedTime, bool allowMarkDirty) |
98 | { |
99 | m_normalizedLocalTime = normalizedTime; |
100 | if (isValidNormalizedTime(t: m_normalizedLocalTime) && allowMarkDirty) |
101 | setDirty(Handler::BlendedClipAnimatorDirty); |
102 | } |
103 | |
104 | void BlendedClipAnimator::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) |
105 | { |
106 | BackendNode::syncFromFrontEnd(frontEnd, firstTime); |
107 | const QBlendedClipAnimator *node = qobject_cast<const QBlendedClipAnimator *>(object: frontEnd); |
108 | if (!node) |
109 | return; |
110 | |
111 | auto id = Qt3DCore::qIdForNode(node: node->blendTree()); |
112 | if (id != m_blendTreeRootId) |
113 | setBlendTreeRootId(id); |
114 | id = Qt3DCore::qIdForNode(node: node->channelMapper()); |
115 | if (m_mapperId != id) |
116 | setMapperId(id); |
117 | id = Qt3DCore::qIdForNode(node: node->clock()); |
118 | if (m_clockId != id) |
119 | setClockId(id); |
120 | |
121 | if (m_running != node->isRunning()) |
122 | setRunning(node->isRunning()); |
123 | if (m_loops != node->loopCount()) |
124 | m_loops = node->loopCount(); |
125 | if (!qFuzzyCompare(p1: m_normalizedLocalTime, p2: node->normalizedTime())) |
126 | setNormalizedLocalTime(normalizedTime: node->normalizedTime()); |
127 | |
128 | if (firstTime) |
129 | setDirty(Handler::BlendedClipAnimatorDirty); |
130 | } |
131 | |
132 | } // namespace Animation |
133 | } // namespace Qt3DAnimation |
134 | |
135 | QT_END_NAMESPACE |
136 | |