| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). | 
| 4 | ** Contact: http://www.qt-project.org/legal | 
| 5 | ** | 
| 6 | ** This file is part of the Qt3D module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU Lesser General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the | 
| 21 | ** packaging of this file. Please review the following information to | 
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | 
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. | 
| 24 | ** | 
| 25 | ** GNU General Public License Usage | 
| 26 | ** Alternatively, this file may be used under the terms of the GNU | 
| 27 | ** General Public License version 2.0 or later as published by the Free | 
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in | 
| 29 | ** the packaging of this file. Please review the following information to | 
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be | 
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. | 
| 32 | ** | 
| 33 | ** $QT_END_LICENSE$ | 
| 34 | ** | 
| 35 | ****************************************************************************/ | 
| 36 |  | 
| 37 | #include "qanimationcliploader.h" | 
| 38 | #include "qanimationcliploader_p.h" | 
| 39 |  | 
| 40 | QT_BEGIN_NAMESPACE | 
| 41 |  | 
| 42 | namespace Qt3DAnimation { | 
| 43 |  | 
| 44 | QAnimationClipLoaderPrivate::QAnimationClipLoaderPrivate() | 
| 45 |     : QAbstractAnimationClipPrivate() | 
| 46 |     , m_source() | 
| 47 |     , m_status(QAnimationClipLoader::NotReady) | 
| 48 | { | 
| 49 | } | 
| 50 |  | 
| 51 | void QAnimationClipLoaderPrivate::setStatus(QAnimationClipLoader::Status status) | 
| 52 | { | 
| 53 |     Q_Q(QAnimationClipLoader); | 
| 54 |     if (status != m_status) { | 
| 55 |         m_status = status; | 
| 56 |         const bool blocked = q->blockNotifications(block: true); | 
| 57 |         emit q->statusChanged(status: m_status); | 
| 58 |         q->blockNotifications(block: blocked); | 
| 59 |     } | 
| 60 | } | 
| 61 |  | 
| 62 | /*! | 
| 63 |     \enum Qt3DAnimation::QAnimationClipLoader::Status | 
| 64 |  | 
| 65 |     This enum identifies the status of animation clip. | 
| 66 |  | 
| 67 |     \value NotReady              The clip has not been loaded yet | 
| 68 |     \value Ready                 The clip was successfully loaded | 
| 69 |     \value Error                 An error occurred while loading the clip | 
| 70 | */ | 
| 71 | /*! | 
| 72 |     \property Qt3DAnimation::QAnimationClipLoader::status | 
| 73 |  | 
| 74 |     This property contains the status of the animation clip. | 
| 75 | */ | 
| 76 | /*! | 
| 77 |     \property Qt3DAnimation::QAnimationClipLoader::source | 
| 78 |  | 
| 79 |     Holds the source URL from which to load the animation clip. Currently | 
| 80 |     glTF2 and the native Qt 3D json animation file formats are supported. | 
| 81 |  | 
| 82 |     In the case where a file contains multiple animations, it is possible | 
| 83 |     to select which animation should be loaded by way of query parameters | 
| 84 |     on the source url. The accepted query parameters are animationIndex and | 
| 85 |     animationName. If both are specified, animationName is ignored. | 
| 86 |  | 
| 87 |     If a file contains only a single animation, there is no need to specify | 
| 88 |     the animationIndex or animationName. We simply use the one available | 
| 89 |     animation. | 
| 90 | */ | 
| 91 | /*! | 
| 92 |     \class Qt3DAnimation::QAnimationClipLoader | 
| 93 |     \inherits QAbstractAnimationClip | 
| 94 |     \inmodule Qt3DAnimation | 
| 95 |     \brief Enables loading key frame animation data from a file. | 
| 96 | */ | 
| 97 |  | 
| 98 | QAnimationClipLoader::QAnimationClipLoader(Qt3DCore::QNode *parent) | 
| 99 |     : QAbstractAnimationClip(*new QAnimationClipLoaderPrivate, parent) | 
| 100 | { | 
| 101 | } | 
| 102 |  | 
| 103 | QAnimationClipLoader::QAnimationClipLoader(const QUrl &source, | 
| 104 |                                            Qt3DCore::QNode *parent) | 
| 105 |     : QAbstractAnimationClip(*new QAnimationClipLoaderPrivate, parent) | 
| 106 | { | 
| 107 |     setSource(source); | 
| 108 | } | 
| 109 |  | 
| 110 | QAnimationClipLoader::QAnimationClipLoader(QAnimationClipLoaderPrivate &dd, Qt3DCore::QNode *parent) | 
| 111 |     : QAbstractAnimationClip(dd, parent) | 
| 112 | { | 
| 113 | } | 
| 114 |  | 
| 115 | // TODO Unused remove in Qt6 | 
| 116 | void QAnimationClipLoader::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &) | 
| 117 | { | 
| 118 | } | 
| 119 |  | 
| 120 | QAnimationClipLoader::~QAnimationClipLoader() | 
| 121 | { | 
| 122 | } | 
| 123 |  | 
| 124 | QUrl QAnimationClipLoader::source() const | 
| 125 | { | 
| 126 |     Q_D(const QAnimationClipLoader); | 
| 127 |     return d->m_source; | 
| 128 | } | 
| 129 |  | 
| 130 | /*! | 
| 131 |     Returns the status of the animation clip. | 
| 132 | */ | 
| 133 | QAnimationClipLoader::Status QAnimationClipLoader::status() const | 
| 134 | { | 
| 135 |     Q_D(const QAnimationClipLoader); | 
| 136 |     return d->m_status; | 
| 137 | } | 
| 138 |  | 
| 139 | void QAnimationClipLoader::setSource(const QUrl &source) | 
| 140 | { | 
| 141 |     Q_D(QAnimationClipLoader); | 
| 142 |     if (d->m_source == source) | 
| 143 |         return; | 
| 144 |  | 
| 145 |     d->m_source = source; | 
| 146 |     emit sourceChanged(source); | 
| 147 | } | 
| 148 |  | 
| 149 | Qt3DCore::QNodeCreatedChangeBasePtr QAnimationClipLoader::createNodeCreationChange() const | 
| 150 | { | 
| 151 |     auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QAnimationClipLoaderData>::create(arguments: this); | 
| 152 |     auto &data = creationChange->data; | 
| 153 |     Q_D(const QAnimationClipLoader); | 
| 154 |     data.source = d->m_source; | 
| 155 |     return creationChange; | 
| 156 | } | 
| 157 |  | 
| 158 | } // namespace Qt3DAnimation | 
| 159 |  | 
| 160 | QT_END_NAMESPACE | 
| 161 |  |