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 "qlerpclipblend.h"
5#include "qlerpclipblend_p.h"
6
7QT_BEGIN_NAMESPACE
8
9namespace Qt3DAnimation {
10
11/*!
12 \qmltype LerpClipBlend
13 \instantiates Qt3DAnimation::QLerpClipBlend
14 \inqmlmodule Qt3D.Animation
15
16 \brief Performs a linear interpolation of two animation clips based on a
17 normalized factor.
18
19 \since 5.9
20
21 LerpClipBlend can be useful to create advanced animation effects based on
22 individual animation clips. For instance, given a player character,, lerp
23 blending could be used to combine a walking animation clip with an injured
24 animation clip based on a blend factor that increases the more the player
25 gets injured. This would then allow with blend factor == 0 to have a non
26 injured walking player, with blend factor == 1 a fully injured player, with
27 blend factor == 0.5 a partially walking and injured player.
28
29 \sa BlendedClipAnimator
30*/
31
32/*!
33 \class Qt3DAnimation::QLerpClipBlend
34 \inmodule Qt3DAnimation
35 \inherits Qt3DAnimation::QAbstractClipBlendNode
36
37 \brief Performs a linear interpolation of two animation clips based on a
38 normalized factor.
39
40 \since 5.9
41
42 QLerpClipBlend can be useful to create advanced animation effects based on
43 individual animation clips. For instance, given a player character, lerp
44 blending could be used to combine a walking animation clip with an injured
45 animation clip based on a blend factor that increases the more the player
46 gets injured. This would then allow with blend factor == 0 to have a non
47 injured walking player, with blend factor == 1 a fully injured player, with
48 blend factor == 0.5 a partially walking and injured player.
49
50 \sa QBlendedClipAnimator
51*/
52
53QLerpClipBlendPrivate::QLerpClipBlendPrivate()
54 : QAbstractClipBlendNodePrivate()
55 , m_startClip(nullptr)
56 , m_endClip(nullptr)
57 , m_blendFactor(0.0f)
58{
59}
60
61QLerpClipBlend::QLerpClipBlend(Qt3DCore::QNode *parent)
62 : QAbstractClipBlendNode(*new QLerpClipBlendPrivate(), parent)
63{
64}
65
66QLerpClipBlend::QLerpClipBlend(QLerpClipBlendPrivate &dd, Qt3DCore::QNode *parent)
67 : QAbstractClipBlendNode(dd, parent)
68{
69}
70
71QLerpClipBlend::~QLerpClipBlend()
72{
73}
74
75/*!
76 \qmlproperty real LerpClipBlend::blendFactor
77
78 Specifies the blending factor between 0 and 1 to control the blending of
79 two animation clips.
80*/
81/*!
82 \property QLerpClipBlend::blendFactor
83
84 Specifies the blending factor between 0 and 1 to control the blending of
85 two animation clips.
86 */
87float QLerpClipBlend::blendFactor() const
88{
89 Q_D(const QLerpClipBlend);
90 return d->m_blendFactor;
91}
92
93/*!
94 \qmlproperty AbstractClipBlendNode LerpClipBlend::startClip
95
96 Holds the sub-tree that should be used as the start clip for this
97 lerp blend node. That is, the clip returned by this blend node when
98 the blendFactor is set to a value of 0.
99*/
100/*!
101 \property QLerpClipBlend::startClip
102
103 Holds the sub-tree that should be used as the start clip for this
104 lerp blend node. That is, the clip returned by this blend node when
105 the blendFactor is set to a value of 0.
106*/
107Qt3DAnimation::QAbstractClipBlendNode *QLerpClipBlend::startClip() const
108{
109 Q_D(const QLerpClipBlend);
110 return d->m_startClip;
111}
112
113/*!
114 \qmlproperty AbstractClipBlendNode LerpClipBlend::endClip
115
116 Holds the sub-tree that should be used as the end clip for this
117 lerp blend node. That is, the clip returned by this blend node when
118 the blendFactor is set to a value of 1.
119*/
120/*!
121 \property QLerpClipBlend::endClip
122
123 Holds the sub-tree that should be used as the start clip for this
124 lerp blend node. That is, the clip returned by this blend node when
125 the blendFactor is set to a value of 1.
126*/
127Qt3DAnimation::QAbstractClipBlendNode *QLerpClipBlend::endClip() const
128{
129 Q_D(const QLerpClipBlend);
130 return d->m_endClip;
131}
132
133void QLerpClipBlend::setBlendFactor(float blendFactor)
134{
135 Q_D(QLerpClipBlend);
136
137 if (d->m_blendFactor == blendFactor)
138 return;
139
140 d->m_blendFactor = blendFactor;
141 emit blendFactorChanged(blendFactor);
142}
143
144void QLerpClipBlend::setStartClip(Qt3DAnimation::QAbstractClipBlendNode *startClip)
145{
146 Q_D(QLerpClipBlend);
147 if (d->m_startClip == startClip)
148 return;
149
150 if (d->m_startClip)
151 d->unregisterDestructionHelper(node: d->m_startClip);
152
153 if (startClip && !startClip->parent())
154 startClip->setParent(this);
155 d->m_startClip = startClip;
156
157 // Ensures proper bookkeeping
158 if (d->m_startClip)
159 d->registerDestructionHelper(node: d->m_startClip, func: &QLerpClipBlend::setStartClip, d->m_startClip);
160 emit startClipChanged(startClip);
161}
162
163void QLerpClipBlend::setEndClip(Qt3DAnimation::QAbstractClipBlendNode *endClip)
164{
165 Q_D(QLerpClipBlend);
166 if (d->m_endClip == endClip)
167 return;
168
169 if (d->m_endClip)
170 d->unregisterDestructionHelper(node: d->m_endClip);
171
172 if (endClip && !endClip->parent())
173 endClip->setParent(this);
174 d->m_endClip = endClip;
175
176 // Ensures proper bookkeeping
177 if (d->m_endClip)
178 d->registerDestructionHelper(node: d->m_endClip, func: &QLerpClipBlend::setEndClip, d->m_endClip);
179 emit endClipChanged(endClip);
180}
181
182} // Qt3DAnimation
183
184QT_END_NAMESPACE
185
186#include "moc_qlerpclipblend.cpp"
187

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