Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtquick3d-skinning.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2020 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
6
\title Vertex Skinning
7
\page quick3d-vertex-skinning
8
9
\section1 Introduction
10
11
Qt Quick 3D supports vertex skinning for skeletal animation of mesh geometries.
12
13
See the \l {Qt Quick 3D - Simple Skinning Example}{Simple Skinning Example} for a practical
14
demonstration of skeletal animation.
15
16
In most cases, application developers will not be using the skinning API manually. The normal workflow is to
17
use an external content creation tool to define the skeleton and the skin (this is sometimes also referred to
18
as \e rigging), and then use the \l {Balsam Asset Import Tool} to convert the asset to Qt Quick 3D's native format.
19
20
\section1 Defining a skeleton
21
22
The basis of skeletal animation is the \l {Skeleton}. This is an abstract representation of how the model
23
can move, inspired by how a physical skeleton works for vertebrates. The "bones" of the skeleton
24
is represented by a hierarchy of \l {Joint} nodes. These do not necessarily need to represent actual
25
bones, of course.
26
27
\qml
28
Skeleton {
29
id: qmlskeleton
30
Joint {
31
id: joint0
32
index: 0
33
skeletonRoot: qmlskeleton
34
Joint {
35
id: joint1
36
index: 1
37
skeletonRoot: qmlskeleton
38
}
39
Joint {
40
id: joint2
41
index: 2
42
skeletonRoot: qmlskeleton
43
}
44
45
}
46
}
47
\endqml
48
49
\section1 Connecting a skeleton to a model
50
51
To apply a skeleton to a model, set the model's \l {Model::skeleton}{skeleton} property:
52
53
\qml
54
Model {
55
skeleton: qmlskeleton
56
\endqml
57
\dots
58
59
In order for the skeleton to have an effect, the model's \l {Model::geometry}{geometry} needs to include
60
skinning information. This is done by including \l {QQuick3DGeometry::addAttribute}{vertex attributes} with
61
\c JointSemantic and \c WeightSemantic in the vertex buffer.
62
63
The \c JointSemantic attribute determines \e which of the joints in the skeleton can influence a
64
given vertex. This uses the index values specified by \l {Joint::index}{Joint.index}. Since this attribute
65
contains 4 indexes, a maximum of 4 joints can influence one vertex.
66
67
The \c WeightSemantic attribute describes the \e strength of the influence of those joints. It
68
contains four floating point values, each value determining the weight given to the joint with the
69
index at the corresponding position in the \c JointSemantic attribute.
70
71
For example, given the skeleton above, if a vertex has these attributes:
72
\table
73
\header
74
\li \c JointSemantic attribute
75
\li \c WeightSemantic attribute
76
\row
77
\li \c {QVector4D(2, 0, 0, 0)}
78
\li \c {QVector4D(1.0, 0.0, 0.0, 0.0)}
79
\endtable
80
that vertex will be 100% influenced by \e joint2, and it will move exactly as much as that
81
joint. The last three indexes in the \c JointSemantic attribute are ignored since the
82
corresponding weights are \c {0.0}.
83
84
As another example, with these attributes:
85
\table
86
\header
87
\li \c JointSemantic attribute
88
\li \c WeightSemantic attribute
89
\row
90
\li \c {QVector4D(1, 2, 0, 0)}
91
\li \c {QVector4D(0.5, 0.25, 0.0, 0.0)}
92
\endtable
93
the vertex will be moved by 50% of \e joint1's movement plus 25% of \e joint2's movement.
94
95
In addition, since the skeleton is an abstract representation, the model need to specify geometry
96
information for the joints. For performance reasons, this is not done by specifying the information
97
directly. Instead, \l {Model::inverseBindPoses}{Model.inverseBindPoses} contains the \e inverse of the
98
transformation matrix needed to move each joint to its initial position.
99
100
\section1 Animating the skeleton
101
102
Transforming a joint in a skeleton will move all vertexes connected to that joint. Since Joint
103
inheriths from \l {Node}, a skeleton can be animated simply by using standard \l[QtQuick QML]
104
{Animation}{QML animations}.
105
106
\qml
107
NumberAnimation {
108
target: joint1
109
property: "eulerRotation.z"
110
duration: 5000
111
from: -90
112
to: 90
113
running: true
114
}
115
\endqml
116
117
While it is possible to create complex animations by nesting \l
118
{SequentialAnimation}, \l {ParallelAnimation} and \l {NumberAnimation}, it is generally more
119
convenient to use \l {Qt Quick Timeline Overview}{timeline animations} for animating skinned models.
120
*/
qtquick3d
src
quick3d
doc
src
qtquick3d-skinning.qdoc
Generated on
for Qt by
1.14.0