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 "findrunningclipanimatorsjob_p.h"
5#include <Qt3DAnimation/private/handler_p.h>
6#include <Qt3DAnimation/private/managers_p.h>
7#include <Qt3DAnimation/private/animationlogging_p.h>
8#include <Qt3DAnimation/private/animationutils_p.h>
9#include <Qt3DAnimation/private/job_common_p.h>
10
11QT_BEGIN_NAMESPACE
12
13namespace Qt3DAnimation {
14namespace Animation {
15
16FindRunningClipAnimatorsJob::FindRunningClipAnimatorsJob()
17 : Qt3DCore::QAspectJob()
18 , m_handler(nullptr)
19{
20 SET_JOB_RUN_STAT_TYPE(this, JobTypes::FindRunningClipAnimator, 0)
21}
22
23void FindRunningClipAnimatorsJob::setDirtyClipAnimators(const QVector<HClipAnimator> &clipAnimatorHandles)
24{
25 m_clipAnimatorHandles = clipAnimatorHandles;
26}
27
28void FindRunningClipAnimatorsJob::run()
29{
30 Q_ASSERT(m_handler);
31
32 ClipAnimatorManager *clipAnimatorManager = m_handler->clipAnimatorManager();
33 for (const auto &clipAnimatorHandle : std::as_const(t&: m_clipAnimatorHandles)) {
34 ClipAnimator *clipAnimator = clipAnimatorManager->data(handle: clipAnimatorHandle);
35 Q_ASSERT(clipAnimator);
36 if (!clipAnimator->isEnabled())
37 continue;
38
39 const bool canRun = clipAnimator->canRun();
40 const bool running = clipAnimator->isRunning();
41 const bool seeking = clipAnimator->isSeeking();
42 m_handler->setClipAnimatorRunning(handle: clipAnimatorHandle, running: canRun && (seeking || running));
43
44 // TODO: Actually check if this is needed first, currently we re-build this every time
45 // canRun (or the normalized time) is true.
46 if (!canRun || !(seeking || running))
47 continue;
48
49 // The clip animator needs to know how to map fcurve values through to properties on QNodes.
50 // Now we know this animator can run, build the mapping table. Even though this could be
51 // done a little simpler in the non-blended case, we follow the same code path as the
52 // blended clip animator for consistency and ease of maintenance.
53 const ChannelMapper *mapper = m_handler->channelMapperManager()->lookupResource(id: clipAnimator->mapperId());
54 Q_ASSERT(mapper);
55 const QVector<ChannelMapping *> channelMappings = mapper->mappings();
56
57 const QVector<ChannelNameAndType> channelNamesAndTypes
58 = buildRequiredChannelsAndTypes(handler: m_handler, mapper);
59 const QVector<ComponentIndices> channelComponentIndices
60 = assignChannelComponentIndices(namesAndTypes: channelNamesAndTypes);
61
62 const AnimationClip *clip = m_handler->animationClipLoaderManager()->lookupResource(id: clipAnimator->clipId());
63 Q_ASSERT(clip);
64 const ClipFormat format = generateClipFormatIndices(targetChannels: channelNamesAndTypes,
65 targetIndices: channelComponentIndices,
66 clip);
67 clipAnimator->setClipFormat(format);
68
69 const QVector<MappingData> mappingData = buildPropertyMappings(channelMappings,
70 channelNamesAndTypes,
71 channelComponentIndices: format.formattedComponentIndices,
72 sourceClipMask: format.sourceClipMask);
73 clipAnimator->setMappingData(mappingData);
74 }
75
76 qCDebug(Jobs) << "Running clip animators =" << m_handler->runningClipAnimators();
77
78 // Clear the handles to process ready for next frame
79 m_clipAnimatorHandles.clear();
80}
81
82} // namespace Animation
83} // namespace Qt3DAnimation
84
85QT_END_NAMESPACE
86

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