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 "qskeleton.h"
41#include "qskeleton_p.h"
42#include <Qt3DCore/qjoint.h>
43#include <Qt3DCore/private/qskeletoncreatedchange_p.h>
44
45QT_BEGIN_NAMESPACE
46
47namespace Qt3DCore {
48
49QSkeletonPrivate::QSkeletonPrivate()
50 : QAbstractSkeletonPrivate()
51 , m_rootJoint(nullptr)
52{
53 m_type = QSkeletonCreatedChangeBase::Skeleton;
54}
55
56/*!
57 \qmltype Skeleton
58 \inqmlmodule Qt3D.Core
59 \inherits AbstractSkeleton
60 \instantiates Qt3DCore::QSkeleton
61 \since 5.10
62 \brief Holds the data for a skeleton to be used with skinned meshes.
63
64 Use Skeleton if you wish to manually create the joints of a skeleton for
65 use with skinned meshes. This is mainly of use to people creating editors,
66 tooling, or dynamic skeletons. It is more common that a Qt 3D application
67 would simply consume an existing skeleton and skinned mesh as created in
68 a digital content creation tool such as Blender. For this use case, please
69 see SkeletonLoader.
70*/
71
72/*!
73 \qmlproperty Joint Skeleton::rootJoint
74
75 Holds the root joint of the hierarchy of joints forming the skeleton.
76*/
77
78/*!
79 \class Qt3DCore::QSkeleton
80 \inmodule Qt3DCore
81 \inherits Qt3DCore::QAbstractSkeleton
82 \since 5.10
83 \brief Holds the data for a skeleton to be used with skinned meshes.
84
85 Use QSkeleton if you wish to manually create the joints of a skeleton for
86 use with skinned meshes. This is mainly of use to people creating editors,
87 tooling, or dynamic skeletons. It is more common that a Qt 3D application
88 would simply consume an existing skeleton and skinned mesh as created in
89 a digital content creation tool such as Blender. For this use case, please
90 see QSkeletonLoader.
91*/
92
93/*!
94 Constructs a new QSkeleton with \a parent.
95*/
96QSkeleton::QSkeleton(Qt3DCore::QNode *parent)
97 : QAbstractSkeleton(*new QSkeletonPrivate, parent)
98{
99}
100
101/*! \internal */
102QSkeleton::~QSkeleton()
103{
104}
105
106/*!
107 \property Qt3DCore::QSkeleton::rootJoint
108
109 Holds the root joint of the hierarchy of joints forming the skeleton.
110*/
111Qt3DCore::QJoint *QSkeleton::rootJoint() const
112{
113 Q_D(const QSkeleton);
114 return d->m_rootJoint;
115}
116
117void QSkeleton::setRootJoint(Qt3DCore::QJoint *rootJoint)
118{
119 Q_D(QSkeleton);
120 if (d->m_rootJoint != rootJoint) {
121 if (d->m_rootJoint)
122 d->unregisterDestructionHelper(node: d->m_rootJoint);
123
124 // We need to add it as a child of the current node if it has been declared inline
125 // Or not previously added as a child of the current node so that
126 // 1) The backend gets notified about it's creation
127 // 2) When the current node is destroyed, it gets destroyed as well
128 if (rootJoint && !rootJoint->parent())
129 rootJoint->setParent(this);
130 d->m_rootJoint = rootJoint;
131
132 // Ensures proper bookkeeping
133 if (d->m_rootJoint)
134 d->registerDestructionHelper(node: d->m_rootJoint, func: &QSkeleton::setRootJoint, d->m_rootJoint);
135
136 emit rootJointChanged(rootJoint);
137 }
138}
139
140/*! \internal */
141Qt3DCore::QNodeCreatedChangeBasePtr QSkeleton::createNodeCreationChange() const
142{
143 auto creationChange = QSkeletonCreatedChangePtr<QSkeletonData>::create(arguments: this);
144 auto &data = creationChange->data;
145 Q_D(const QSkeleton);
146 data.rootJointId = qIdForNode(node: d->m_rootJoint);
147 return creationChange;
148}
149
150} // namespace Qt3DCore
151
152QT_END_NAMESPACE
153

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