| 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 "qskeletonloader.h" |
| 5 | #include "qskeletonloader_p.h" |
| 6 | #include <Qt3DCore/qjoint.h> |
| 7 | |
| 8 | QT_BEGIN_NAMESPACE |
| 9 | |
| 10 | namespace Qt3DCore { |
| 11 | |
| 12 | QSkeletonLoaderPrivate::QSkeletonLoaderPrivate() |
| 13 | : QAbstractSkeletonPrivate() |
| 14 | , m_source() |
| 15 | , m_createJoints(false) |
| 16 | , m_status(QSkeletonLoader::NotReady) |
| 17 | , m_rootJoint(nullptr) |
| 18 | { |
| 19 | m_type = SkeletonLoader; |
| 20 | } |
| 21 | |
| 22 | void QSkeletonLoaderPrivate::setStatus(QSkeletonLoader::Status status) |
| 23 | { |
| 24 | Q_Q(QSkeletonLoader); |
| 25 | if (status != m_status) { |
| 26 | m_status = status; |
| 27 | const bool blocked = q->blockNotifications(block: true); |
| 28 | emit q->statusChanged(status: m_status); |
| 29 | q->blockNotifications(block: blocked); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | void QSkeletonLoaderPrivate::setRootJoint(QJoint *rootJoint) |
| 34 | { |
| 35 | Q_Q(QSkeletonLoader); |
| 36 | if (rootJoint == m_rootJoint) |
| 37 | return; |
| 38 | |
| 39 | if (m_rootJoint) |
| 40 | unregisterDestructionHelper(node: m_rootJoint); |
| 41 | |
| 42 | if (rootJoint && !rootJoint->parent()) |
| 43 | rootJoint->setParent(q); |
| 44 | |
| 45 | m_rootJoint = rootJoint; |
| 46 | |
| 47 | // Ensures proper bookkeeping |
| 48 | if (m_rootJoint) |
| 49 | registerPrivateDestructionHelper(node: m_rootJoint, func: &QSkeletonLoaderPrivate::setRootJoint); |
| 50 | |
| 51 | emit q->rootJointChanged(rootJoint: m_rootJoint); |
| 52 | } |
| 53 | |
| 54 | /*! |
| 55 | \qmltype SkeletonLoader |
| 56 | \inqmlmodule Qt3D.Core |
| 57 | \inherits AbstractSkeleton |
| 58 | \nativetype Qt3DCore::QSkeletonLoader |
| 59 | \since 5.10 |
| 60 | \brief Used to load a skeleton of joints from file. |
| 61 | |
| 62 | Use SkeletonLoader if you wish to load a whole skeleton from file rather |
| 63 | than creating the joints yourself using Skeleton and Joints. Creating a |
| 64 | skeleton and binding the vertices of a mesh to the skeleton is most easily |
| 65 | performed in a 3D digital content creation tool such as Blender. The |
| 66 | resulting skeleton and mesh can then be exported in a suitable format such |
| 67 | as glTF 2 for consumption by Qt 3D. |
| 68 | */ |
| 69 | |
| 70 | /*! |
| 71 | \qmlproperty url SkeletonLoader::source |
| 72 | |
| 73 | Holds the source url from which to load the skeleton. |
| 74 | */ |
| 75 | |
| 76 | /*! |
| 77 | \qmlproperty SkeletonLoader.Status SkeletonLoader::status |
| 78 | |
| 79 | Holds the current status of skeleton loading. |
| 80 | */ |
| 81 | |
| 82 | /*! |
| 83 | \class Qt3DCore::QSkeletonLoader |
| 84 | \inmodule Qt3DCore |
| 85 | \inherits Qt3DCore::QAbstractSkeleton |
| 86 | \since 5.10 |
| 87 | \brief Used to load a skeleton of joints from file. |
| 88 | |
| 89 | Use SkeletonLoader if you wish to load a whole skeleton from file rather |
| 90 | than creating the joints yourself using Skeleton and Joints. Creating a |
| 91 | skeleton and binding the vertices of a mesh to the skeleton is most easily |
| 92 | performed in a 3D digital content creation tool such as Blender. The |
| 93 | resulting skeleton and mesh can then be exported in a suitable format such |
| 94 | as glTF 2 for consumption by Qt 3D. |
| 95 | */ |
| 96 | |
| 97 | /*! |
| 98 | \enum Qt3DCore::QSkeletonLoader::Status |
| 99 | |
| 100 | This enum identifies the status of skeleton. |
| 101 | |
| 102 | \value NotReady The skeleton has not been loaded yet |
| 103 | \value Ready The skeleton was successfully loaded |
| 104 | \value Error An error occurred while loading the skeleton |
| 105 | */ |
| 106 | /*! |
| 107 | \property Qt3DCore::QSkeletonLoader::createJointsEnabled |
| 108 | |
| 109 | \brief A boolean to indicate whether createJoints is enabled or not. |
| 110 | */ |
| 111 | /*! |
| 112 | Constructs a new QSkeletonLoader with \a parent. |
| 113 | */ |
| 114 | QSkeletonLoader::QSkeletonLoader(Qt3DCore::QNode *parent) |
| 115 | : QAbstractSkeleton(*new QSkeletonLoaderPrivate, parent) |
| 116 | { |
| 117 | } |
| 118 | |
| 119 | /*! |
| 120 | Constructs a new QSkeletonLoader with \a parent and sets the \a source. |
| 121 | */ |
| 122 | QSkeletonLoader::QSkeletonLoader(const QUrl &source, QNode *parent) |
| 123 | : QAbstractSkeleton(*new QSkeletonLoaderPrivate, parent) |
| 124 | { |
| 125 | setSource(source); |
| 126 | } |
| 127 | |
| 128 | /*! \internal */ |
| 129 | QSkeletonLoader::QSkeletonLoader(QSkeletonLoaderPrivate &dd, Qt3DCore::QNode *parent) |
| 130 | : QAbstractSkeleton(dd, parent) |
| 131 | { |
| 132 | } |
| 133 | |
| 134 | /*! \internal */ |
| 135 | QSkeletonLoader::~QSkeletonLoader() |
| 136 | { |
| 137 | } |
| 138 | |
| 139 | /*! |
| 140 | \property Qt3DCore::QSkeletonLoader::source |
| 141 | |
| 142 | Holds the source url from which to load the skeleton. |
| 143 | */ |
| 144 | QUrl QSkeletonLoader::source() const |
| 145 | { |
| 146 | Q_D(const QSkeletonLoader); |
| 147 | return d->m_source; |
| 148 | } |
| 149 | |
| 150 | /*! |
| 151 | \property Qt3DCore::QSkeletonLoader::status |
| 152 | |
| 153 | Holds the current status of skeleton loading. |
| 154 | */ |
| 155 | QSkeletonLoader::Status QSkeletonLoader::status() const |
| 156 | { |
| 157 | Q_D(const QSkeletonLoader); |
| 158 | return d->m_status; |
| 159 | } |
| 160 | |
| 161 | /*! |
| 162 | Returns a boolean indicating whether CreateJoints |
| 163 | is enabled or not. |
| 164 | The default value is \c false. |
| 165 | */ |
| 166 | bool QSkeletonLoader::isCreateJointsEnabled() const |
| 167 | { |
| 168 | Q_D(const QSkeletonLoader); |
| 169 | return d->m_createJoints; |
| 170 | } |
| 171 | /*! |
| 172 | Returns the root joint of the hierarchy of joints forming the skeleton. |
| 173 | */ |
| 174 | Qt3DCore::QJoint *QSkeletonLoader::rootJoint() const |
| 175 | { |
| 176 | Q_D(const QSkeletonLoader); |
| 177 | return d->m_rootJoint; |
| 178 | } |
| 179 | |
| 180 | void QSkeletonLoader::setSource(const QUrl &source) |
| 181 | { |
| 182 | Q_D(QSkeletonLoader); |
| 183 | if (d->m_source == source) |
| 184 | return; |
| 185 | |
| 186 | d->m_source = source; |
| 187 | emit sourceChanged(source); |
| 188 | } |
| 189 | |
| 190 | void QSkeletonLoader::setCreateJointsEnabled(bool createJoints) |
| 191 | { |
| 192 | Q_D(QSkeletonLoader); |
| 193 | if (d->m_createJoints == createJoints) |
| 194 | return; |
| 195 | |
| 196 | d->m_createJoints = createJoints; |
| 197 | emit createJointsEnabledChanged(createJointsEnabled: createJoints); |
| 198 | } |
| 199 | |
| 200 | void QSkeletonLoader::setRootJoint(QJoint *rootJoint) |
| 201 | { |
| 202 | Q_D(QSkeletonLoader); |
| 203 | d->setRootJoint(rootJoint); |
| 204 | } |
| 205 | |
| 206 | } // namespace Qt3DCore |
| 207 | |
| 208 | QT_END_NAMESPACE |
| 209 | |
| 210 | #include "moc_qskeletonloader.cpp" |
| 211 | |