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
11QT_BEGIN_NAMESPACE
12
13namespace Qt3DAnimation {
14namespace Animation {
15
16BlendedClipAnimator::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
28double BlendedClipAnimator::lastLocalTime() const
29{
30 return m_lastLocalTime;
31}
32
33void BlendedClipAnimator::setLastLocalTime(double lastLocalTime)
34{
35 m_lastLocalTime = lastLocalTime;
36}
37
38void BlendedClipAnimator::setLastNormalizedLocalTime(float normalizedTime)
39{
40 m_lastNormalizedLocalTime = normalizedTime;
41}
42
43void BlendedClipAnimator::setLastGlobalTimeNS(const qint64 &lastGlobalTimeNS)
44{
45 m_lastGlobalTimeNS = lastGlobalTimeNS;
46}
47
48qint64 BlendedClipAnimator::nsSincePreviousFrame(qint64 currentGlobalTimeNS)
49{
50 return currentGlobalTimeNS - m_lastGlobalTimeNS;
51}
52
53void 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
67void BlendedClipAnimator::setBlendTreeRootId(Qt3DCore::QNodeId blendTreeId)
68{
69 m_blendTreeRootId = blendTreeId;
70 setDirty(Handler::BlendedClipAnimatorDirty);
71}
72
73void BlendedClipAnimator::setMapperId(Qt3DCore::QNodeId mapperId)
74{
75 m_mapperId = mapperId;
76 setDirty(Handler::BlendedClipAnimatorDirty);
77}
78
79void BlendedClipAnimator::setClockId(Qt3DCore::QNodeId clockId)
80{
81 m_clockId = clockId;
82 setDirty(Handler::BlendedClipAnimatorDirty);
83}
84
85void BlendedClipAnimator::setRunning(bool running)
86{
87 m_running = running;
88 setDirty(Handler::BlendedClipAnimatorDirty);
89}
90
91
92Qt3DCore::QNodeId BlendedClipAnimator::blendTreeRootId() const
93{
94 return m_blendTreeRootId;
95}
96
97void BlendedClipAnimator::setNormalizedLocalTime(float normalizedTime, bool allowMarkDirty)
98{
99 m_normalizedLocalTime = normalizedTime;
100 if (isValidNormalizedTime(t: m_normalizedLocalTime) && allowMarkDirty)
101 setDirty(Handler::BlendedClipAnimatorDirty);
102}
103
104void 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
135QT_END_NAMESPACE
136

source code of qt3d/src/animation/backend/blendedclipanimator.cpp