1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
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 https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qclipanimator.h" |
41 | #include "qclipanimator_p.h" |
42 | #include <Qt3DAnimation/qabstractanimationclip.h> |
43 | #include <Qt3DAnimation/qchannelmapper.h> |
44 | #include <Qt3DAnimation/qclock.h> |
45 | |
46 | QT_BEGIN_NAMESPACE |
47 | |
48 | namespace Qt3DAnimation { |
49 | |
50 | QClipAnimatorPrivate::QClipAnimatorPrivate() |
51 | : Qt3DAnimation::QAbstractClipAnimatorPrivate() |
52 | , m_clip(nullptr) |
53 | { |
54 | } |
55 | |
56 | bool QClipAnimatorPrivate::canPlay() const |
57 | { |
58 | if (m_clip && m_mapper) |
59 | return true; |
60 | |
61 | qWarning("ClipAnimators need a clip and a mapper to be played" ); |
62 | return false; |
63 | } |
64 | |
65 | /*! |
66 | \qmltype ClipAnimator |
67 | \instantiates Qt3DAnimation::QClipAnimator |
68 | \inqmlmodule Qt3D.Animation |
69 | \since 5.9 |
70 | |
71 | \brief ClipAnimator is a component providing simple animation playback capabilities. |
72 | |
73 | An instance of ClipAnimator can be aggregated by an Entity to add the ability to play back |
74 | animation clips and to apply the calculated animation values to properties of QObjects. |
75 | |
76 | The animation key frame data is provided via the clip property. This can be created |
77 | programmatically with AnimationClip or loaded from file with AnimationClipLoader. |
78 | |
79 | In order to apply the values played back from the channels of data in the animation clip, the |
80 | clip animator needs to have a ChannelMapper object assigned to the channelMapper property. |
81 | |
82 | The properties for controlling the animator are provided by the AbstractClipAnimator base |
83 | class. |
84 | |
85 | \sa {Qt3DAnimation::QAbstractClipAnimator}{AbstractClipAnimator}, {Qt3DAnimation::QAbstractAnimationClip}{AbstractAnimationClip}, {Qt3DAnimation::QChannelMapper}{ChannelMapper}, {Qt3DAnimation::QBlendedClipAnimator}{BlendedClipAnimator} |
86 | */ |
87 | |
88 | /*! |
89 | \class Qt3DAnimation::QClipAnimator |
90 | \inherits Qt3DAnimation::QAbstractClipAnimator |
91 | |
92 | \inmodule Qt3DAnimation |
93 | \since 5.9 |
94 | |
95 | \brief QClipAnimator is a component providing simple animation playback capabilities. |
96 | |
97 | An instance of QClipAnimator can be aggregated by a QEntity to add the ability to play back |
98 | animation clips and to apply the calculated animation values to properties of QObjects. |
99 | |
100 | The animation key frame data is provided via the clip property. This can be created |
101 | programmatically with QAnimationClip or loaded from file with QAnimationClipLoader. |
102 | |
103 | In order to apply the values played back from the channels of data in the animation clip, the |
104 | clip animator needs to have a QChannelMapper object assigned to the channelMapper property. |
105 | |
106 | The properties for controlling the animator are provided by the QAbstractClipAnimator base |
107 | class. |
108 | |
109 | \sa QAbstractClipAnimator, QAbstractAnimationClip, QChannelMapper, QBlendedClipAnimator |
110 | */ |
111 | |
112 | QClipAnimator::QClipAnimator(Qt3DCore::QNode *parent) |
113 | : Qt3DAnimation::QAbstractClipAnimator(*new QClipAnimatorPrivate, parent) |
114 | { |
115 | } |
116 | |
117 | /*! \internal */ |
118 | QClipAnimator::QClipAnimator(QClipAnimatorPrivate &dd, Qt3DCore::QNode *parent) |
119 | : Qt3DAnimation::QAbstractClipAnimator(dd, parent) |
120 | { |
121 | } |
122 | |
123 | QClipAnimator::~QClipAnimator() |
124 | { |
125 | } |
126 | |
127 | /*! |
128 | \qmlproperty var Qt3D.Animation::ClipAnimator::clip |
129 | |
130 | This property holds the animation clip which contains the key frame data to be played back. |
131 | The key frame data can be specified in either an AnimationClip or AnimationClipLoader. |
132 | */ |
133 | /*! |
134 | \property QClipAnimator::clip |
135 | |
136 | This property holds the animation clip which contains the key frame data to be played back. |
137 | The key frame data can be specified in either a QAnimationClip or QAnimationClipLoader. |
138 | */ |
139 | QAbstractAnimationClip *QClipAnimator::clip() const |
140 | { |
141 | Q_D(const QClipAnimator); |
142 | return d->m_clip; |
143 | } |
144 | |
145 | void QClipAnimator::setClip(QAbstractAnimationClip *clip) |
146 | { |
147 | Q_D(QClipAnimator); |
148 | if (d->m_clip == clip) |
149 | return; |
150 | |
151 | if (d->m_clip) |
152 | d->unregisterDestructionHelper(d->m_clip); |
153 | |
154 | if (clip && !clip->parent()) |
155 | clip->setParent(this); |
156 | d->m_clip = clip; |
157 | |
158 | // Ensures proper bookkeeping |
159 | if (d->m_clip) |
160 | d->registerDestructionHelper(d->m_clip, &QClipAnimator::setClip, d->m_clip); |
161 | emit clipChanged(clip); |
162 | } |
163 | |
164 | /*! \internal */ |
165 | Qt3DCore::QNodeCreatedChangeBasePtr QClipAnimator::createNodeCreationChange() const |
166 | { |
167 | auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QClipAnimatorData>::create(this); |
168 | auto &data = creationChange->data; |
169 | Q_D(const QClipAnimator); |
170 | data.clipId = Qt3DCore::qIdForNode(d->m_clip); |
171 | data.mapperId = Qt3DCore::qIdForNode(d->m_mapper); |
172 | data.clockId = Qt3DCore::qIdForNode(d->m_clock); |
173 | data.running = d->m_running; |
174 | data.loops = d->m_loops; |
175 | data.normalizedTime = d->m_normalizedTime; |
176 | return creationChange; |
177 | } |
178 | |
179 | } // namespace Qt3DAnimation |
180 | |
181 | QT_END_NAMESPACE |
182 | |