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 "qabstractanimationclip.h"
38#include "qabstractanimationclip_p.h"
39
40QT_BEGIN_NAMESPACE
41
42namespace Qt3DAnimation {
43
44QAbstractAnimationClipPrivate::QAbstractAnimationClipPrivate()
45 : Qt3DCore::QNodePrivate()
46 , m_duration(0.0f)
47{
48}
49
50void QAbstractAnimationClipPrivate::setDuration(float duration)
51{
52 if (qFuzzyCompare(p1: duration, p2: m_duration))
53 return;
54
55 Q_Q(QAbstractAnimationClip);
56 bool wasBlocked = q->blockNotifications(block: true);
57 m_duration = duration;
58 emit q->durationChanged(duration);
59 q->blockNotifications(block: wasBlocked);
60}
61
62/*!
63 \class Qt3DAnimation::QAbstractAnimationClip
64 \inherits Qt3DCore::QNode
65
66 \inmodule Qt3DAnimation
67 \since 5.9
68
69 \brief QAbstractAnimationClip is the base class for types providing key frame animation data.
70
71 To utilise the key frame animation framework in the Qt 3D Animation module
72 the animator component in use needs to be provided with the key frame animation data. The
73 animation data is provided by one of the concrete subclasses of QAbstractAnimationClip:
74
75 \list
76 \li Qt3DAnimation::QAnimationClip
77 \li Qt3DAnimation::QAnimationClipLoader
78 \endlist
79
80 QAnimationClip should be used when you want to create the animation data
81 programmatically within your application. The actual data is set with a
82 QAnimationClipData value type.
83
84 If you are loading baked animation data from a file, e.g. as created by an
85 artist, then use the QAnimationClipLoader class and set its \c source property.
86
87 Once the animation clip has been populated with data using the above
88 methods, the read-only duration property will be updated by the Qt 3D Animation
89 backend.
90
91 The typical usage of animation clips is:
92
93 \code
94 auto animator = new QClipAnimator();
95 auto clip = new QAnimationClipLoader();
96 clip->setSource(QUrl::fromLocalFile("bounce.json"));
97 animator->setClip(clip);
98 animator->setChannelMapper(...);
99 animator->setRunning(true);
100 \endcode
101
102 Animation clips are also used as the leaf node values in animation blend trees:
103
104 \code
105 // Create leaf nodes of blend tree
106 auto slideClipValue = new QClipBlendValue(
107 new QAnimationClipLoader(QUrl::fromLocalFile("slide.json")));
108 auto bounceClipValue = new QClipBlendValue(
109 new QAnimationClipLoader(QUrl::fromLocalFile("bounce.json")));
110
111 // Create blend tree inner node
112 auto additiveNode = new QAdditiveClipBlend();
113 additiveNode->setBaseClip(slideClipValue);
114 additiveNode->setAdditiveClip(bounceClipValue);
115 additiveNode->setAdditiveFactor(0.5f);
116
117 // Run the animator
118 auto animator = new QBlendedClipAnimator();
119 animator->setBlendTree(additiveNode);
120 animator->setChannelMapper(...);
121 animator->setRunning(true);
122 \endcode
123
124 \sa Qt3DAnimation::QAnimationClip, Qt3DAnimation::QAnimationClipLoader
125*/
126
127/*!
128 \internal
129*/
130QAbstractAnimationClip::QAbstractAnimationClip(QAbstractAnimationClipPrivate &dd,
131 Qt3DCore::QNode *parent)
132 : Qt3DCore::QNode(dd, parent)
133{
134}
135
136// TODO Unused remove in Qt6
137void QAbstractAnimationClip::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &)
138{
139}
140
141/*!
142 Destroys this animation clip.
143*/
144QAbstractAnimationClip::~QAbstractAnimationClip()
145{
146}
147
148/*!
149 \property QAbstractAnimationClip::duration
150
151 Holds the duration of the animation clip in seconds. Gets updated once the
152 animation data is provided to Qt 3D using one of the concrete subclasses.
153*/
154float QAbstractAnimationClip::duration() const
155{
156 Q_D(const QAbstractAnimationClip);
157 return d->m_duration;
158}
159
160} // namespace Qt3DAnimation
161
162QT_END_NAMESPACE
163

source code of qt3d/src/animation/frontend/qabstractanimationclip.cpp