1/****************************************************************************
2**
3** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
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 https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qarmature.h"
41#include "qarmature_p.h"
42#include <Qt3DCore/qabstractskeleton.h>
43
44QT_BEGIN_NAMESPACE
45
46namespace Qt3DCore {
47
48QArmaturePrivate::QArmaturePrivate()
49 : Qt3DCore::QComponentPrivate()
50 , m_skeleton(nullptr)
51{
52}
53
54/*!
55 \qmltype Armature
56 \inqmlmodule Qt3D.Core
57 \inherits Component3D
58 \instantiates Qt3DCore::QArmature
59 \since 5.10
60 \brief Used to calculate skinning transform matrices and set them on shaders.
61
62 The Armature component is aggregated by entities to give them the ability to
63 calculate the palette of skinning transform matrices needed to properly
64 render skinned meshes.
65
66 Each vertex in a skinned mesh is associated (bound) to up to 4 joints in a
67 skeleton. For each joint affecting a vertex the mesh also provides a weight
68 which determines the level of influence of the corresponding joint. The
69 skinning palette used for performing the transformation of skinned vertices
70 is provided by the Armature and is calculated from the joints contained in
71 the referenced skeleton.
72
73 Updating the local transform of a joint results in the skinning matrices
74 being recalculated and the skinned mesh vertices bound to that joint moving
75 accordingly.
76*/
77
78/*!
79 \qmlproperty AbstractSkeleton Armature::skeleton
80
81 Holds the skeleton used to calculate the skinning transform matrix palette.
82*/
83
84/*!
85 \class Qt3DCore::QArmature
86 \inmodule Qt3DCore
87 \inherits Qt3DCore::QComponent
88 \since 5.10
89 \brief Used to calculate skinning transform matrices and set them on shaders.
90
91 The Armature component is aggregated by entities to give them the ability to
92 calculate the palette of skinning transform matrices needed to properly
93 render skinned meshes.
94
95 Each vertex in a skinned mesh is associated (bound) to up to 4 joints in a
96 skeleton. For each joint affecting a vertex the mesh also provides a weight
97 which determines the level of influence of the corresponding joint. The
98 skinning palette used for performing the transformation of skinned vertices
99 is provided by the Armature and is calculated from the joints contained in
100 the referenced skeleton.
101
102 Updating the local transform of a joint results in the skinning matrices
103 being recalculated and the skinned mesh vertices bound to that joint moving
104 accordingly.
105*/
106
107/*!
108 Constructs a new QArmature with \a parent.
109*/
110QArmature::QArmature(Qt3DCore::QNode *parent)
111 : Qt3DCore::QComponent(*new QArmaturePrivate, parent)
112{
113}
114
115/*! \internal */
116QArmature::QArmature(QArmaturePrivate &dd, Qt3DCore::QNode *parent)
117 : Qt3DCore::QComponent(dd, parent)
118{
119}
120
121/*! \internal */
122QArmature::~QArmature()
123{
124}
125
126/*!
127 \property Qt3DCore::QArmature::skeleton
128
129 Holds the skeleton used to calculate the skinning transform matrix palette.
130*/
131Qt3DCore::QAbstractSkeleton *QArmature::skeleton() const
132{
133 Q_D(const QArmature);
134 return d->m_skeleton;
135}
136
137void QArmature::setSkeleton(Qt3DCore::QAbstractSkeleton *skeleton)
138{
139 Q_D(QArmature);
140 if (d->m_skeleton != skeleton) {
141 if (d->m_skeleton)
142 d->unregisterDestructionHelper(node: d->m_skeleton);
143
144 // We need to add it as a child of the current node if it has been declared inline
145 // Or not previously added as a child of the current node so that
146 // 1) The backend gets notified about it's creation
147 // 2) When the current node is destroyed, it gets destroyed as well
148 if (skeleton && !skeleton->parent())
149 skeleton->setParent(this);
150 d->m_skeleton = skeleton;
151
152 // Ensures proper bookkeeping
153 if (d->m_skeleton)
154 d->registerDestructionHelper(node: d->m_skeleton, func: &QArmature::setSkeleton, d->m_skeleton);
155
156 emit skeletonChanged(skeleton);
157 }
158}
159
160/*! \internal */
161Qt3DCore::QNodeCreatedChangeBasePtr QArmature::createNodeCreationChange() const
162{
163 auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QArmatureData>::create(arguments: this);
164 auto &data = creationChange->data;
165 Q_D(const QArmature);
166 data.skeletonId = qIdForNode(node: d->m_skeleton);
167 return creationChange;
168}
169
170} // namespace Qt3DCore
171
172QT_END_NAMESPACE
173

source code of qt3d/src/core/transforms/qarmature.cpp