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 "updateskinningpalettejob_p.h"
38#include <Qt3DRender/private/nodemanagers_p.h>
39#include <Qt3DRender/private/managers_p.h>
40#include <Qt3DRender/private/handle_types_p.h>
41#include <Qt3DRender/private/job_common_p.h>
42
43QT_BEGIN_NAMESPACE
44
45namespace Qt3DRender {
46namespace Render {
47
48UpdateSkinningPaletteJob::UpdateSkinningPaletteJob()
49 : Qt3DCore::QAspectJob()
50 , m_nodeManagers(nullptr)
51 , m_root()
52{
53 SET_JOB_RUN_STAT_TYPE(this, JobTypes::UpdateSkinningPalette, 0)
54}
55
56UpdateSkinningPaletteJob::~UpdateSkinningPaletteJob()
57{
58}
59
60void UpdateSkinningPaletteJob::run()
61{
62 auto armatureManager = m_nodeManagers->armatureManager();
63 if (armatureManager->count() == 0)
64 return;
65
66 // TODO: Decompose this job across several jobs, say one per skeleton so
67 // that it can be done in parallel
68
69 // Update the local pose transforms of JointInfo's in Skeletons from
70 // the set of dirty joints.
71 for (const auto &jointHandle : qAsConst(t&: m_dirtyJoints)) {
72 Joint *joint = m_nodeManagers->jointManager()->data(handle: jointHandle);
73 Q_ASSERT(joint);
74 Skeleton *skeleton = m_nodeManagers->skeletonManager()->data(handle: joint->owningSkeleton());
75 Q_ASSERT(skeleton);
76 if (skeleton->isEnabled() && joint->isEnabled())
77 skeleton->setLocalPose(jointHandle, localPose: joint->localPose());
78 }
79
80 // Find all the armature components and update their skinning palettes
81 QVector<HArmature> dirtyArmatures;
82 m_root->traverse(operation: [&dirtyArmatures](Entity *entity) {
83 const auto armatureHandle = entity->componentHandle<Armature>();
84 if (!armatureHandle.isNull() && !dirtyArmatures.contains(t: armatureHandle))
85 dirtyArmatures.push_back(t: armatureHandle);
86 });
87
88 // Update the skeleton for each dirty armature
89 auto skeletonManager = m_nodeManagers->skeletonManager();
90 for (const auto &armatureHandle : qAsConst(t&: dirtyArmatures)) {
91 auto armature = armatureManager->data(handle: armatureHandle);
92 Q_ASSERT(armature);
93
94 auto skeletonId = armature->skeletonId();
95 auto skeleton = skeletonManager->lookupResource(id: skeletonId);
96 Q_ASSERT(skeleton);
97
98 const QVector<QMatrix4x4> skinningPalette = skeleton->calculateSkinningMatrixPalette();
99 armature->skinningPaletteUniform().setData(skinningPalette);
100 }
101}
102
103} // namespace Render
104} // namespace Qt3DRender
105
106QT_END_NAMESPACE
107

source code of qt3d/src/render/jobs/updateskinningpalettejob.cpp