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#include <Qt3DCore/qpropertyupdatedchange.h>
40
41QT_BEGIN_NAMESPACE
42
43namespace Qt3DAnimation {
44
45QAnimationClipLoaderPrivate::QAnimationClipLoaderPrivate()
46 : QAbstractAnimationClipPrivate()
47 , m_source()
48 , m_status(QAnimationClipLoader::NotReady)
49{
50}
51
52void QAnimationClipLoaderPrivate::setStatus(QAnimationClipLoader::Status status)
53{
54 Q_Q(QAnimationClipLoader);
55 if (status != m_status) {
56 m_status = status;
57 const bool blocked = q->blockNotifications(true);
58 emit q->statusChanged(m_status);
59 q->blockNotifications(blocked);
60 }
61}
62
63/*!
64 \enum Qt3DAnimation::QAnimationClipLoader::Status
65
66 This enum identifies the status of animation clip.
67
68 \value NotReady The clip has not been loaded yet
69 \value Ready The clip was successfully loaded
70 \value Error An error occurred while loading the clip
71*/
72/*!
73 \property Qt3DAnimation::QAnimationClipLoader::status
74
75 This property contains the status of the animation clip.
76*/
77/*!
78 \property Qt3DAnimation::QAnimationClipLoader::source
79
80 Holds the source URL from which to load the animation clip. Currently
81 glTF2 and the native Qt 3D json animation file formats are supported.
82
83 In the case where a file contains multiple animations, it is possible
84 to select which animation should be loaded by way of query parameters
85 on the source url. The accepted query parameters are animationIndex and
86 animationName. If both are specified, animationName is ignored.
87
88 If a file contains only a single animation, there is no need to specify
89 the animationIndex or animationName. We simply use the one available
90 animation.
91*/
92/*!
93 \class Qt3DAnimation::QAnimationClipLoader
94 \inherits QAbstractAnimationClip
95 \inmodule Qt3DAnimation
96 \brief Enables loading key frame animation data from a file.
97*/
98
99QAnimationClipLoader::QAnimationClipLoader(Qt3DCore::QNode *parent)
100 : QAbstractAnimationClip(*new QAnimationClipLoaderPrivate, parent)
101{
102}
103
104QAnimationClipLoader::QAnimationClipLoader(const QUrl &source,
105 Qt3DCore::QNode *parent)
106 : QAbstractAnimationClip(*new QAnimationClipLoaderPrivate, parent)
107{
108 setSource(source);
109}
110
111QAnimationClipLoader::QAnimationClipLoader(QAnimationClipLoaderPrivate &dd, Qt3DCore::QNode *parent)
112 : QAbstractAnimationClip(dd, parent)
113{
114}
115
116QAnimationClipLoader::~QAnimationClipLoader()
117{
118}
119
120QUrl QAnimationClipLoader::source() const
121{
122 Q_D(const QAnimationClipLoader);
123 return d->m_source;
124}
125
126/*!
127 Returns the status of the animation clip.
128*/
129QAnimationClipLoader::Status QAnimationClipLoader::status() const
130{
131 Q_D(const QAnimationClipLoader);
132 return d->m_status;
133}
134
135void QAnimationClipLoader::setSource(const QUrl &source)
136{
137 Q_D(QAnimationClipLoader);
138 if (d->m_source == source)
139 return;
140
141 d->m_source = source;
142 emit sourceChanged(source);
143}
144
145/*!
146 \internal
147*/
148void QAnimationClipLoader::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change)
149{
150 Q_D(QAnimationClipLoader);
151 if (change->type() == Qt3DCore::PropertyUpdated) {
152 const Qt3DCore::QPropertyUpdatedChangePtr e = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(change);
153 if (e->propertyName() == QByteArrayLiteral("status"))
154 d->setStatus(static_cast<QAnimationClipLoader::Status>(e->value().toInt()));
155 }
156}
157
158Qt3DCore::QNodeCreatedChangeBasePtr QAnimationClipLoader::createNodeCreationChange() const
159{
160 auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QAnimationClipLoaderData>::create(this);
161 auto &data = creationChange->data;
162 Q_D(const QAnimationClipLoader);
163 data.source = d->m_source;
164 return creationChange;
165}
166
167} // namespace Qt3DAnimation
168
169QT_END_NAMESPACE
170