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 "findrunningclipanimatorsjob_p.h"
38#include <Qt3DAnimation/private/handler_p.h>
39#include <Qt3DAnimation/private/managers_p.h>
40#include <Qt3DAnimation/private/animationlogging_p.h>
41#include <Qt3DAnimation/private/animationutils_p.h>
42#include <Qt3DAnimation/private/job_common_p.h>
43
44QT_BEGIN_NAMESPACE
45
46namespace Qt3DAnimation {
47namespace Animation {
48
49FindRunningClipAnimatorsJob::FindRunningClipAnimatorsJob()
50 : Qt3DCore::QAspectJob()
51 , m_handler(nullptr)
52{
53 SET_JOB_RUN_STAT_TYPE(this, JobTypes::FindRunningClipAnimator, 0)
54}
55
56void FindRunningClipAnimatorsJob::setDirtyClipAnimators(const QVector<HClipAnimator> &clipAnimatorHandles)
57{
58 m_clipAnimatorHandles = clipAnimatorHandles;
59}
60
61void FindRunningClipAnimatorsJob::run()
62{
63 Q_ASSERT(m_handler);
64
65 ClipAnimatorManager *clipAnimatorManager = m_handler->clipAnimatorManager();
66 for (const auto &clipAnimatorHandle : qAsConst(t&: m_clipAnimatorHandles)) {
67 ClipAnimator *clipAnimator = clipAnimatorManager->data(handle: clipAnimatorHandle);
68 Q_ASSERT(clipAnimator);
69 if (!clipAnimator->isEnabled())
70 continue;
71
72 const bool canRun = clipAnimator->canRun();
73 const bool running = clipAnimator->isRunning();
74 const bool seeking = clipAnimator->isSeeking();
75 m_handler->setClipAnimatorRunning(handle: clipAnimatorHandle, running: canRun && (seeking || running));
76
77 // TODO: Actually check if this is needed first, currently we re-build this every time
78 // canRun (or the normalized time) is true.
79 if (!canRun || !(seeking || running))
80 continue;
81
82 // The clip animator needs to know how to map fcurve values through to properties on QNodes.
83 // Now we know this animator can run, build the mapping table. Even though this could be
84 // done a little simpler in the non-blended case, we follow the same code path as the
85 // blended clip animator for consistency and ease of maintenance.
86 const ChannelMapper *mapper = m_handler->channelMapperManager()->lookupResource(id: clipAnimator->mapperId());
87 Q_ASSERT(mapper);
88 const QVector<ChannelMapping *> channelMappings = mapper->mappings();
89
90 const QVector<ChannelNameAndType> channelNamesAndTypes
91 = buildRequiredChannelsAndTypes(handler: m_handler, mapper);
92 const QVector<ComponentIndices> channelComponentIndices
93 = assignChannelComponentIndices(namesAndTypes: channelNamesAndTypes);
94
95 const AnimationClip *clip = m_handler->animationClipLoaderManager()->lookupResource(id: clipAnimator->clipId());
96 Q_ASSERT(clip);
97 const ClipFormat format = generateClipFormatIndices(targetChannels: channelNamesAndTypes,
98 targetIndices: channelComponentIndices,
99 clip);
100 clipAnimator->setClipFormat(format);
101
102 const QVector<MappingData> mappingData = buildPropertyMappings(channelMappings,
103 channelNamesAndTypes,
104 channelComponentIndices: format.formattedComponentIndices,
105 sourceClipMask: format.sourceClipMask);
106 clipAnimator->setMappingData(mappingData);
107 }
108
109 qCDebug(Jobs) << "Running clip animators =" << m_handler->runningClipAnimators();
110
111 // Clear the handles to process ready for next frame
112 m_clipAnimatorHandles.clear();
113}
114
115} // namespace Animation
116} // namespace Qt3DAnimation
117
118QT_END_NAMESPACE
119

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