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 "qskeleton.h" |
5 | #include "qskeleton_p.h" |
6 | #include <Qt3DCore/qjoint.h> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | namespace Qt3DCore { |
11 | |
12 | QSkeletonPrivate::QSkeletonPrivate() |
13 | : QAbstractSkeletonPrivate() |
14 | , m_rootJoint(nullptr) |
15 | { |
16 | m_type = Skeleton; |
17 | } |
18 | |
19 | /*! |
20 | \qmltype Skeleton |
21 | \inqmlmodule Qt3D.Core |
22 | \inherits AbstractSkeleton |
23 | \instantiates Qt3DCore::QSkeleton |
24 | \since 5.10 |
25 | \brief Holds the data for a skeleton to be used with skinned meshes. |
26 | |
27 | Use Skeleton if you wish to manually create the joints of a skeleton for |
28 | use with skinned meshes. This is mainly of use to people creating editors, |
29 | tooling, or dynamic skeletons. It is more common that a Qt 3D application |
30 | would simply consume an existing skeleton and skinned mesh as created in |
31 | a digital content creation tool such as Blender. For this use case, please |
32 | see SkeletonLoader. |
33 | */ |
34 | |
35 | /*! |
36 | \qmlproperty Joint Skeleton::rootJoint |
37 | |
38 | Holds the root joint of the hierarchy of joints forming the skeleton. |
39 | */ |
40 | |
41 | /*! |
42 | \class Qt3DCore::QSkeleton |
43 | \inmodule Qt3DCore |
44 | \inherits Qt3DCore::QAbstractSkeleton |
45 | \since 5.10 |
46 | \brief Holds the data for a skeleton to be used with skinned meshes. |
47 | |
48 | Use QSkeleton if you wish to manually create the joints of a skeleton for |
49 | use with skinned meshes. This is mainly of use to people creating editors, |
50 | tooling, or dynamic skeletons. It is more common that a Qt 3D application |
51 | would simply consume an existing skeleton and skinned mesh as created in |
52 | a digital content creation tool such as Blender. For this use case, please |
53 | see QSkeletonLoader. |
54 | */ |
55 | |
56 | /*! |
57 | Constructs a new QSkeleton with \a parent. |
58 | */ |
59 | QSkeleton::QSkeleton(Qt3DCore::QNode *parent) |
60 | : QAbstractSkeleton(*new QSkeletonPrivate, parent) |
61 | { |
62 | } |
63 | |
64 | /*! \internal */ |
65 | QSkeleton::~QSkeleton() |
66 | { |
67 | } |
68 | |
69 | /*! |
70 | \property Qt3DCore::QSkeleton::rootJoint |
71 | |
72 | Holds the root joint of the hierarchy of joints forming the skeleton. |
73 | */ |
74 | Qt3DCore::QJoint *QSkeleton::rootJoint() const |
75 | { |
76 | Q_D(const QSkeleton); |
77 | return d->m_rootJoint; |
78 | } |
79 | |
80 | void QSkeleton::setRootJoint(Qt3DCore::QJoint *rootJoint) |
81 | { |
82 | Q_D(QSkeleton); |
83 | if (d->m_rootJoint != rootJoint) { |
84 | if (d->m_rootJoint) |
85 | d->unregisterDestructionHelper(node: d->m_rootJoint); |
86 | |
87 | // We need to add it as a child of the current node if it has been declared inline |
88 | // Or not previously added as a child of the current node so that |
89 | // 1) The backend gets notified about it's creation |
90 | // 2) When the current node is destroyed, it gets destroyed as well |
91 | if (rootJoint && !rootJoint->parent()) |
92 | rootJoint->setParent(this); |
93 | d->m_rootJoint = rootJoint; |
94 | |
95 | // Ensures proper bookkeeping |
96 | if (d->m_rootJoint) |
97 | d->registerDestructionHelper(node: d->m_rootJoint, func: &QSkeleton::setRootJoint, d->m_rootJoint); |
98 | |
99 | emit rootJointChanged(rootJoint); |
100 | } |
101 | } |
102 | |
103 | } // namespace Qt3DCore |
104 | |
105 | QT_END_NAMESPACE |
106 | |
107 | #include "moc_qskeleton.cpp" |
108 | |