1/****************************************************************************
2**
3** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#include "blendedclipanimator_p.h"
38#include <Qt3DAnimation/qblendedclipanimator.h>
39#include <Qt3DAnimation/qchannelmapper.h>
40#include <Qt3DAnimation/qclock.h>
41#include <Qt3DAnimation/qabstractclipblendnode.h>
42#include <Qt3DAnimation/private/qblendedclipanimator_p.h>
43
44QT_BEGIN_NAMESPACE
45
46namespace Qt3DAnimation {
47namespace Animation {
48
49BlendedClipAnimator::BlendedClipAnimator()
50 : BackendNode(ReadWrite)
51 , m_running(false)
52 , m_lastGlobalTimeNS(0)
53 , m_lastLocalTime(0.0)
54 , m_currentLoop(0)
55 , m_loops(1)
56 , m_normalizedLocalTime(-1.0f)
57 , m_lastNormalizedLocalTime(-1.0)
58{
59}
60
61double BlendedClipAnimator::lastLocalTime() const
62{
63 return m_lastLocalTime;
64}
65
66void BlendedClipAnimator::setLastLocalTime(double lastLocalTime)
67{
68 m_lastLocalTime = lastLocalTime;
69}
70
71void BlendedClipAnimator::setLastNormalizedLocalTime(float normalizedTime)
72{
73 m_lastNormalizedLocalTime = normalizedTime;
74}
75
76void BlendedClipAnimator::setLastGlobalTimeNS(const qint64 &lastGlobalTimeNS)
77{
78 m_lastGlobalTimeNS = lastGlobalTimeNS;
79}
80
81qint64 BlendedClipAnimator::nsSincePreviousFrame(qint64 currentGlobalTimeNS)
82{
83 return currentGlobalTimeNS - m_lastGlobalTimeNS;
84}
85
86void BlendedClipAnimator::cleanup()
87{
88 setEnabled(false);
89 m_handler = nullptr;
90 m_blendTreeRootId = Qt3DCore::QNodeId();
91 m_mapperId = Qt3DCore::QNodeId();
92 m_clockId = Qt3DCore::QNodeId();
93 m_running = false;
94 m_lastGlobalTimeNS = 0;
95 m_lastLocalTime = 0.0;
96 m_currentLoop = 0;
97 m_loops = 1;
98}
99
100void BlendedClipAnimator::setBlendTreeRootId(Qt3DCore::QNodeId blendTreeId)
101{
102 m_blendTreeRootId = blendTreeId;
103 setDirty(Handler::BlendedClipAnimatorDirty);
104}
105
106void BlendedClipAnimator::setMapperId(Qt3DCore::QNodeId mapperId)
107{
108 m_mapperId = mapperId;
109 setDirty(Handler::BlendedClipAnimatorDirty);
110}
111
112void BlendedClipAnimator::setClockId(Qt3DCore::QNodeId clockId)
113{
114 m_clockId = clockId;
115 setDirty(Handler::BlendedClipAnimatorDirty);
116}
117
118void BlendedClipAnimator::setRunning(bool running)
119{
120 m_running = running;
121 setDirty(Handler::BlendedClipAnimatorDirty);
122}
123
124
125Qt3DCore::QNodeId BlendedClipAnimator::blendTreeRootId() const
126{
127 return m_blendTreeRootId;
128}
129
130void BlendedClipAnimator::setNormalizedLocalTime(float normalizedTime, bool allowMarkDirty)
131{
132 m_normalizedLocalTime = normalizedTime;
133 if (isValidNormalizedTime(t: m_normalizedLocalTime) && allowMarkDirty)
134 setDirty(Handler::BlendedClipAnimatorDirty);
135}
136
137void BlendedClipAnimator::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
138{
139 BackendNode::syncFromFrontEnd(frontEnd, firstTime);
140 const QBlendedClipAnimator *node = qobject_cast<const QBlendedClipAnimator *>(object: frontEnd);
141 if (!node)
142 return;
143
144 auto id = Qt3DCore::qIdForNode(node: node->blendTree());
145 if (id != m_blendTreeRootId)
146 setBlendTreeRootId(id);
147 id = Qt3DCore::qIdForNode(node: node->channelMapper());
148 if (m_mapperId != id)
149 setMapperId(id);
150 id = Qt3DCore::qIdForNode(node: node->clock());
151 if (m_clockId != id)
152 setClockId(id);
153
154 if (m_running != node->isRunning())
155 setRunning(node->isRunning());
156 if (m_loops != node->loopCount())
157 m_loops = node->loopCount();
158 if (!qFuzzyCompare(p1: m_normalizedLocalTime, p2: node->normalizedTime()))
159 setNormalizedLocalTime(normalizedTime: node->normalizedTime());
160
161 if (firstTime)
162 setDirty(Handler::BlendedClipAnimatorDirty);
163}
164
165} // namespace Animation
166} // namespace Qt3DAnimation
167
168QT_END_NAMESPACE
169

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