1 | // Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qabstractanimationclip.h" |
5 | #include "qabstractanimationclip_p.h" |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | namespace Qt3DAnimation { |
10 | |
11 | QAbstractAnimationClipPrivate::QAbstractAnimationClipPrivate() |
12 | : Qt3DCore::QNodePrivate() |
13 | , m_duration(0.0f) |
14 | { |
15 | } |
16 | |
17 | void QAbstractAnimationClipPrivate::setDuration(float duration) |
18 | { |
19 | if (qFuzzyCompare(p1: duration, p2: m_duration)) |
20 | return; |
21 | |
22 | Q_Q(QAbstractAnimationClip); |
23 | bool wasBlocked = q->blockNotifications(block: true); |
24 | m_duration = duration; |
25 | emit q->durationChanged(duration); |
26 | q->blockNotifications(block: wasBlocked); |
27 | } |
28 | |
29 | /*! |
30 | \class Qt3DAnimation::QAbstractAnimationClip |
31 | \inherits Qt3DCore::QNode |
32 | |
33 | \inmodule Qt3DAnimation |
34 | \since 5.9 |
35 | |
36 | \brief QAbstractAnimationClip is the base class for types providing key frame animation data. |
37 | |
38 | To utilise the key frame animation framework in the Qt 3D Animation module |
39 | the animator component in use needs to be provided with the key frame animation data. The |
40 | animation data is provided by one of the concrete subclasses of QAbstractAnimationClip: |
41 | |
42 | \list |
43 | \li Qt3DAnimation::QAnimationClip |
44 | \li Qt3DAnimation::QAnimationClipLoader |
45 | \endlist |
46 | |
47 | QAnimationClip should be used when you want to create the animation data |
48 | programmatically within your application. The actual data is set with a |
49 | QAnimationClipData value type. |
50 | |
51 | If you are loading baked animation data from a file, e.g. as created by an |
52 | artist, then use the QAnimationClipLoader class and set its \c source property. |
53 | |
54 | Once the animation clip has been populated with data using the above |
55 | methods, the read-only duration property will be updated by the Qt 3D Animation |
56 | backend. |
57 | |
58 | The typical usage of animation clips is: |
59 | |
60 | \code |
61 | auto animator = new QClipAnimator(); |
62 | auto clip = new QAnimationClipLoader(); |
63 | clip->setSource(QUrl::fromLocalFile("bounce.json")); |
64 | animator->setClip(clip); |
65 | animator->setChannelMapper(...); |
66 | animator->setRunning(true); |
67 | \endcode |
68 | |
69 | Animation clips are also used as the leaf node values in animation blend trees: |
70 | |
71 | \code |
72 | // Create leaf nodes of blend tree |
73 | auto slideClipValue = new QClipBlendValue( |
74 | new QAnimationClipLoader(QUrl::fromLocalFile("slide.json"))); |
75 | auto bounceClipValue = new QClipBlendValue( |
76 | new QAnimationClipLoader(QUrl::fromLocalFile("bounce.json"))); |
77 | |
78 | // Create blend tree inner node |
79 | auto additiveNode = new QAdditiveClipBlend(); |
80 | additiveNode->setBaseClip(slideClipValue); |
81 | additiveNode->setAdditiveClip(bounceClipValue); |
82 | additiveNode->setAdditiveFactor(0.5f); |
83 | |
84 | // Run the animator |
85 | auto animator = new QBlendedClipAnimator(); |
86 | animator->setBlendTree(additiveNode); |
87 | animator->setChannelMapper(...); |
88 | animator->setRunning(true); |
89 | \endcode |
90 | |
91 | \sa Qt3DAnimation::QAnimationClip, Qt3DAnimation::QAnimationClipLoader |
92 | */ |
93 | |
94 | /*! |
95 | \internal |
96 | */ |
97 | QAbstractAnimationClip::QAbstractAnimationClip(QAbstractAnimationClipPrivate &dd, |
98 | Qt3DCore::QNode *parent) |
99 | : Qt3DCore::QNode(dd, parent) |
100 | { |
101 | } |
102 | |
103 | /*! |
104 | Destroys this animation clip. |
105 | */ |
106 | QAbstractAnimationClip::~QAbstractAnimationClip() |
107 | { |
108 | } |
109 | |
110 | /*! |
111 | \property QAbstractAnimationClip::duration |
112 | |
113 | Holds the duration of the animation clip in seconds. Gets updated once the |
114 | animation data is provided to Qt 3D using one of the concrete subclasses. |
115 | */ |
116 | float QAbstractAnimationClip::duration() const |
117 | { |
118 | Q_D(const QAbstractAnimationClip); |
119 | return d->m_duration; |
120 | } |
121 | |
122 | } // namespace Qt3DAnimation |
123 | |
124 | QT_END_NAMESPACE |
125 | |
126 | #include "moc_qabstractanimationclip.cpp" |
127 | |