summaryrefslogtreecommitdiffstats
path: root/src/core/transforms/qskeletonloader.cpp
blob: 8175d73a689406b1dff00230735a78d8fc2fc018 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qskeletonloader.h"
#include "qskeletonloader_p.h"
#include <Qt3DCore/qjoint.h>

QT_BEGIN_NAMESPACE

namespace Qt3DCore {

QSkeletonLoaderPrivate::QSkeletonLoaderPrivate()
    : QAbstractSkeletonPrivate()
    , m_source()
    , m_createJoints(false)
    , m_status(QSkeletonLoader::NotReady)
    , m_rootJoint(nullptr)
{
    m_type = SkeletonLoader;
}

void QSkeletonLoaderPrivate::setStatus(QSkeletonLoader::Status status)
{
    Q_Q(QSkeletonLoader);
    if (status != m_status) {
        m_status = status;
        const bool blocked = q->blockNotifications(true);
        emit q->statusChanged(m_status);
        q->blockNotifications(blocked);
    }
}

void QSkeletonLoaderPrivate::setRootJoint(QJoint *rootJoint)
{
    Q_Q(QSkeletonLoader);
    if (rootJoint == m_rootJoint)
        return;

    if (m_rootJoint)
        unregisterDestructionHelper(m_rootJoint);

    if (rootJoint && !rootJoint->parent())
        rootJoint->setParent(q);

    m_rootJoint = rootJoint;

    // Ensures proper bookkeeping
    if (m_rootJoint)
        registerPrivateDestructionHelper(m_rootJoint, &QSkeletonLoaderPrivate::setRootJoint);

    emit q->rootJointChanged(m_rootJoint);
}

/*!
    \qmltype SkeletonLoader
    \inqmlmodule Qt3D.Core
    \inherits AbstractSkeleton
    \instantiates Qt3DCore::QSkeletonLoader
    \since 5.10
    \brief Used to load a skeleton of joints from file.

    Use SkeletonLoader if you wish to load a whole skeleton from file rather
    than creating the joints yourself using Skeleton and Joints. Creating a
    skeleton and binding the vertices of a mesh to the skeleton is most easily
    performed in a 3D digital content creation tool such as Blender. The
    resulting skeleton and mesh can then be exported in a suitable format such
    as glTF 2 for consumption by Qt 3D.
*/

/*!
    \qmlproperty url SkeletonLoader::source

    Holds the source url from which to load the skeleton.
*/

/*!
    \qmlproperty SkeletonLoader.Status SkeletonLoader::status

    Holds the current status of skeleton loading.
*/

/*!
    \class Qt3DCore::QSkeletonLoader
    \inmodule Qt3DCore
    \inherits Qt3DCore::QAbstractSkeleton
    \since 5.10
    \brief Used to load a skeleton of joints from file.

    Use SkeletonLoader if you wish to load a whole skeleton from file rather
    than creating the joints yourself using Skeleton and Joints. Creating a
    skeleton and binding the vertices of a mesh to the skeleton is most easily
    performed in a 3D digital content creation tool such as Blender. The
    resulting skeleton and mesh can then be exported in a suitable format such
    as glTF 2 for consumption by Qt 3D.
*/

/*!
    \enum QSkeletonLoader::Status

    This enum identifies the status of skeleton.

    \value NotReady              The skeleton has not been loaded yet
    \value Ready                 The skeleton was successfully loaded
    \value Error                 An error occurred while loading the skeleton
*/
/*!
    \property Qt3DCore::QSkeletonLoader::createJointsEnabled

    \brief A boolean to indicate whether createJoints is enabled or not.
*/
/*!
    Constructs a new QSkeletonLoader with \a parent.
*/
QSkeletonLoader::QSkeletonLoader(Qt3DCore::QNode *parent)
    : QAbstractSkeleton(*new QSkeletonLoaderPrivate, parent)
{
}

/*!
    Constructs a new QSkeletonLoader with \a parent and sets the \a source.
*/
QSkeletonLoader::QSkeletonLoader(const QUrl &source, QNode *parent)
    : QAbstractSkeleton(*new QSkeletonLoaderPrivate, parent)
{
    setSource(source);
}

/*! \internal */
QSkeletonLoader::QSkeletonLoader(QSkeletonLoaderPrivate &dd, Qt3DCore::QNode *parent)
    : QAbstractSkeleton(dd, parent)
{
}

/*! \internal */
QSkeletonLoader::~QSkeletonLoader()
{
}

/*!
    \property Qt3DCore::QSkeletonLoader::source

    Holds the source url from which to load the skeleton.
*/
QUrl QSkeletonLoader::source() const
{
    Q_D(const QSkeletonLoader);
    return d->m_source;
}

/*!
    \property Qt3DCore::QSkeletonLoader::status

    Holds the current status of skeleton loading.
*/
QSkeletonLoader::Status QSkeletonLoader::status() const
{
    Q_D(const QSkeletonLoader);
    return d->m_status;
}

/*!
    Returns a boolean indicating whether CreateJoints
    is enabled or not.
    The default value is \c false.
*/
bool QSkeletonLoader::isCreateJointsEnabled() const
{
    Q_D(const QSkeletonLoader);
    return d->m_createJoints;
}
/*!
    Returns the root joint of the hierarchy of joints forming the skeleton.
*/
Qt3DCore::QJoint *QSkeletonLoader::rootJoint() const
{
    Q_D(const QSkeletonLoader);
    return d->m_rootJoint;
}

void QSkeletonLoader::setSource(const QUrl &source)
{
    Q_D(QSkeletonLoader);
    if (d->m_source == source)
        return;

    d->m_source = source;
    emit sourceChanged(source);
}

void QSkeletonLoader::setCreateJointsEnabled(bool createJoints)
{
    Q_D(QSkeletonLoader);
    if (d->m_createJoints == createJoints)
        return;

    d->m_createJoints = createJoints;
    emit createJointsEnabledChanged(createJoints);
}

void QSkeletonLoader::setRootJoint(QJoint *rootJoint)
{
    Q_D(QSkeletonLoader);
    d->setRootJoint(rootJoint);
}

} // namespace Qt3DCore

QT_END_NAMESPACE

#include "moc_qskeletonloader.cpp"