summaryrefslogtreecommitdiffstats
path: root/src/animation/frontend/qabstractanimationclip.cpp
blob: 329ae0181e9f12cd17ca9b2d07ac4dce8f8154dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/****************************************************************************
**
** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt3D module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:COMM$
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** $QT_END_LICENSE$
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
****************************************************************************/

#include "qabstractanimationclip.h"
#include "qabstractanimationclip_p.h"

QT_BEGIN_NAMESPACE

namespace Qt3DAnimation {

QAbstractAnimationClipPrivate::QAbstractAnimationClipPrivate()
    : Qt3DCore::QNodePrivate()
    , m_duration(0.0f)
{
}

void QAbstractAnimationClipPrivate::setDuration(float duration)
{
    if (qFuzzyCompare(duration, m_duration))
        return;

    Q_Q(QAbstractAnimationClip);
    bool wasBlocked = q->blockNotifications(true);
    m_duration = duration;
    emit q->durationChanged(duration);
    q->blockNotifications(wasBlocked);
}

/*!
    \class Qt3DAnimation::QAbstractAnimationClip
    \inherits Qt3DCore::QNode

    \inmodule Qt3DAnimation
    \since 5.9

    \brief QAbstractAnimationClip is the base class for types providing key frame animation data.

    To utilise the key frame animation framework in the Qt 3D Animation module
    the animator component in use needs to be provided with the key frame animation data. The
    animation data is provided by one of the concrete subclasses of QAbstractAnimationClip:

    \list
    \li Qt3DAnimation::QAnimationClip
    \li Qt3DAnimation::QAnimationClipLoader
    \endlist

    QAnimationClip should be used when you want to create the animation data
    programmatically within your application. The actual data is set with a
    QAnimationClipData value type.

    If you are loading baked animation data from a file, e.g. as created by an
    artist, then use the QAnimationClipLoader class and set its \c source property.

    Once the animation clip has been populated with data using the above
    methods, the read-only duration property will be updated by the Qt 3D Animation
    backend.

    The typical usage of animation clips is:

    \code
    auto animator = new QClipAnimator();
    auto clip = new QAnimationClipLoader();
    clip->setSource(QUrl::fromLocalFile("bounce.json"));
    animator->setClip(clip);
    animator->setChannelMapper(...);
    animator->setRunning(true);
    \endcode

    Animation clips are also used as the leaf node values in animation blend trees:

    \code
    // Create leaf nodes of blend tree
    auto slideClipValue = new QClipBlendValue(
        new QAnimationClipLoader(QUrl::fromLocalFile("slide.json")));
    auto bounceClipValue = new QClipBlendValue(
        new QAnimationClipLoader(QUrl::fromLocalFile("bounce.json")));

    // Create blend tree inner node
    auto additiveNode = new QAdditiveClipBlend();
    additiveNode->setBaseClip(slideClipValue);
    additiveNode->setAdditiveClip(bounceClipValue);
    additiveNode->setAdditiveFactor(0.5f);

    // Run the animator
    auto animator = new QBlendedClipAnimator();
    animator->setBlendTree(additiveNode);
    animator->setChannelMapper(...);
    animator->setRunning(true);
    \endcode

    \sa Qt3DAnimation::QAnimationClip, Qt3DAnimation::QAnimationClipLoader
*/

/*!
    \internal
*/
QAbstractAnimationClip::QAbstractAnimationClip(QAbstractAnimationClipPrivate &dd,
                                               Qt3DCore::QNode *parent)
    : Qt3DCore::QNode(dd, parent)
{
}

// TODO Unused remove in Qt6
void QAbstractAnimationClip::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &)
{
}

/*!
    Destroys this animation clip.
*/
QAbstractAnimationClip::~QAbstractAnimationClip()
{
}

/*!
    \property QAbstractAnimationClip::duration

    Holds the duration of the animation clip in seconds. Gets updated once the
    animation data is provided to Qt 3D using one of the concrete subclasses.
*/
float QAbstractAnimationClip::duration() const
{
    Q_D(const QAbstractAnimationClip);
    return d->m_duration;
}

} // namespace Qt3DAnimation

QT_END_NAMESPACE