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 "qarmature.h" |
5 | #include "qarmature_p.h" |
6 | #include <Qt3DCore/qabstractskeleton.h> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | namespace Qt3DCore { |
11 | |
12 | QArmaturePrivate::QArmaturePrivate() |
13 | : Qt3DCore::QComponentPrivate() |
14 | , m_skeleton(nullptr) |
15 | { |
16 | } |
17 | |
18 | /*! |
19 | \qmltype Armature |
20 | \inqmlmodule Qt3D.Core |
21 | \inherits Component3D |
22 | \instantiates Qt3DCore::QArmature |
23 | \since 5.10 |
24 | \brief Used to calculate skinning transform matrices and set them on shaders. |
25 | |
26 | The Armature component is aggregated by entities to give them the ability to |
27 | calculate the palette of skinning transform matrices needed to properly |
28 | render skinned meshes. |
29 | |
30 | Each vertex in a skinned mesh is associated (bound) to up to 4 joints in a |
31 | skeleton. For each joint affecting a vertex the mesh also provides a weight |
32 | which determines the level of influence of the corresponding joint. The |
33 | skinning palette used for performing the transformation of skinned vertices |
34 | is provided by the Armature and is calculated from the joints contained in |
35 | the referenced skeleton. |
36 | |
37 | Updating the local transform of a joint results in the skinning matrices |
38 | being recalculated and the skinned mesh vertices bound to that joint moving |
39 | accordingly. |
40 | */ |
41 | |
42 | /*! |
43 | \qmlproperty AbstractSkeleton Armature::skeleton |
44 | |
45 | Holds the skeleton used to calculate the skinning transform matrix palette. |
46 | */ |
47 | |
48 | /*! |
49 | \class Qt3DCore::QArmature |
50 | \inmodule Qt3DCore |
51 | \inherits Qt3DCore::QComponent |
52 | \since 5.10 |
53 | \brief Used to calculate skinning transform matrices and set them on shaders. |
54 | |
55 | The Armature component is aggregated by entities to give them the ability to |
56 | calculate the palette of skinning transform matrices needed to properly |
57 | render skinned meshes. |
58 | |
59 | Each vertex in a skinned mesh is associated (bound) to up to 4 joints in a |
60 | skeleton. For each joint affecting a vertex the mesh also provides a weight |
61 | which determines the level of influence of the corresponding joint. The |
62 | skinning palette used for performing the transformation of skinned vertices |
63 | is provided by the Armature and is calculated from the joints contained in |
64 | the referenced skeleton. |
65 | |
66 | Updating the local transform of a joint results in the skinning matrices |
67 | being recalculated and the skinned mesh vertices bound to that joint moving |
68 | accordingly. |
69 | */ |
70 | |
71 | /*! |
72 | Constructs a new QArmature with \a parent. |
73 | */ |
74 | QArmature::QArmature(Qt3DCore::QNode *parent) |
75 | : Qt3DCore::QComponent(*new QArmaturePrivate, parent) |
76 | { |
77 | } |
78 | |
79 | /*! \internal */ |
80 | QArmature::QArmature(QArmaturePrivate &dd, Qt3DCore::QNode *parent) |
81 | : Qt3DCore::QComponent(dd, parent) |
82 | { |
83 | } |
84 | |
85 | /*! \internal */ |
86 | QArmature::~QArmature() |
87 | { |
88 | } |
89 | |
90 | /*! |
91 | \property Qt3DCore::QArmature::skeleton |
92 | |
93 | Holds the skeleton used to calculate the skinning transform matrix palette. |
94 | */ |
95 | Qt3DCore::QAbstractSkeleton *QArmature::skeleton() const |
96 | { |
97 | Q_D(const QArmature); |
98 | return d->m_skeleton; |
99 | } |
100 | |
101 | void QArmature::setSkeleton(Qt3DCore::QAbstractSkeleton *skeleton) |
102 | { |
103 | Q_D(QArmature); |
104 | if (d->m_skeleton != skeleton) { |
105 | if (d->m_skeleton) |
106 | d->unregisterDestructionHelper(node: d->m_skeleton); |
107 | |
108 | // We need to add it as a child of the current node if it has been declared inline |
109 | // Or not previously added as a child of the current node so that |
110 | // 1) The backend gets notified about it's creation |
111 | // 2) When the current node is destroyed, it gets destroyed as well |
112 | if (skeleton && !skeleton->parent()) |
113 | skeleton->setParent(this); |
114 | d->m_skeleton = skeleton; |
115 | |
116 | // Ensures proper bookkeeping |
117 | if (d->m_skeleton) |
118 | d->registerDestructionHelper(node: d->m_skeleton, func: &QArmature::setSkeleton, d->m_skeleton); |
119 | |
120 | emit skeletonChanged(skeleton); |
121 | } |
122 | } |
123 | |
124 | } // namespace Qt3DCore |
125 | |
126 | QT_END_NAMESPACE |
127 | |
128 | #include "moc_qarmature.cpp" |
129 | |