1/****************************************************************************
2**
3** Copyright (C) 2019 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 "abstractevaluateclipanimatorjob_p.h"
38#include <Qt3DCore/private/qaspectjob_p.h>
39#include <Qt3DCore/private/qaspectmanager_p.h>
40#include <Qt3DCore/private/qskeleton_p.h>
41#include <Qt3DAnimation/qabstractclipanimator.h>
42
43QT_BEGIN_NAMESPACE
44
45namespace Qt3DAnimation {
46namespace Animation {
47
48class AbstractEvaluateClipAnimatorJobPrivate : public Qt3DCore::QAspectJobPrivate
49{
50public:
51 AbstractEvaluateClipAnimatorJobPrivate() { }
52 ~AbstractEvaluateClipAnimatorJobPrivate() override { }
53
54 void postFrame(Qt3DCore::QAspectManager *manager) override;
55
56 AnimationRecord m_record;
57 QVector<AnimationCallbackAndValue> m_callbacks;
58};
59
60AbstractEvaluateClipAnimatorJob::AbstractEvaluateClipAnimatorJob()
61 : Qt3DCore::QAspectJob(*new AbstractEvaluateClipAnimatorJobPrivate)
62{
63}
64
65void AbstractEvaluateClipAnimatorJob::setPostFrameData(const AnimationRecord &record, const QVector<AnimationCallbackAndValue> &callbacks)
66{
67 auto mainThreadCB = callbacks;
68 mainThreadCB.erase(abegin: std::remove_if(first: mainThreadCB.begin(), last: mainThreadCB.end(), pred: [](const AnimationCallbackAndValue &callback) {
69 if (callback.flags.testFlag(flag: QAnimationCallback::OnThreadPool)) {
70 // call these now and remove them from the list
71 callback.callback->valueChanged(value: callback.value);
72 return true;
73 }
74 return false;
75 }), aend: mainThreadCB.end());
76 // Should now only have callbacks to be called on main thread
77
78 Q_D(AbstractEvaluateClipAnimatorJob);
79 d->m_record = record;
80 d->m_callbacks = mainThreadCB;
81}
82
83void AbstractEvaluateClipAnimatorJobPrivate::postFrame(Qt3DCore::QAspectManager *manager)
84{
85 if (m_record.animatorId.isNull())
86 return;
87
88 for (auto targetData : qAsConst(t&: m_record.targetChanges)) {
89 Qt3DCore::QNode *node = manager->lookupNode(id: targetData.targetId);
90 if (node)
91 node->setProperty(name: targetData.propertyName, value: targetData.value);
92 }
93
94 for (auto skeletonData : qAsConst(t&: m_record.skeletonChanges)) {
95 Qt3DCore::QAbstractSkeleton *node = qobject_cast<Qt3DCore::QAbstractSkeleton *>(object: manager->lookupNode(id: skeletonData.first));
96 if (node) {
97 auto d = Qt3DCore::QAbstractSkeletonPrivate::get(q: node);
98 d->m_localPoses = skeletonData.second;
99 d->update();
100 }
101 }
102
103 QAbstractClipAnimator *animator = qobject_cast<QAbstractClipAnimator *>(object: manager->lookupNode(id: m_record.animatorId));
104 if (animator) {
105 if (isValidNormalizedTime(t: m_record.normalizedTime))
106 animator->setNormalizedTime(m_record.normalizedTime);
107 if (m_record.finalFrame)
108 animator->setRunning(false);
109 }
110
111 for (const AnimationCallbackAndValue &callback: qAsConst(t&: m_callbacks)) {
112 if (callback.callback)
113 callback.callback->valueChanged(value: callback.value);
114 }
115
116 m_record = {};
117}
118
119} // Animation
120} // Qt3DAnimation
121
122QT_END_NAMESPACE
123

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