| 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 "qadditiveclipblend.h" |
| 5 | #include "qadditiveclipblend_p.h" |
| 6 | |
| 7 | QT_BEGIN_NAMESPACE |
| 8 | |
| 9 | namespace Qt3DAnimation { |
| 10 | |
| 11 | |
| 12 | /*! |
| 13 | \qmltype AdditiveClipBlend |
| 14 | \nativetype Qt3DAnimation::QAdditiveClipBlend |
| 15 | \inqmlmodule Qt3D.Animation |
| 16 | |
| 17 | \since 5.9 |
| 18 | |
| 19 | \brief Performs an additive blend of two animation clips based on an additive factor. |
| 20 | |
| 21 | QAdditiveClipBlend can be useful to create advanced animation effects based on |
| 22 | individual animation clips. For example, if you: |
| 23 | |
| 24 | \list |
| 25 | \li set the baseClip property to a normal walk cycle animation clip and |
| 26 | \li set the additiveClip property to a shaking head difference clip, |
| 27 | \endlist |
| 28 | |
| 29 | then adjusting the additiveFactor property will control how much of the additiveClip gets added |
| 30 | on to the baseClip. This has he effect that with an additiveFactor of zero, this blend node will |
| 31 | yield the original walk cycle clip. With an additiveFactor of 1, it will yield the walk cycle |
| 32 | including a shaking head animation. |
| 33 | |
| 34 | The blending operation implemented by this class is: |
| 35 | |
| 36 | \badcode |
| 37 | resultClip = baseClip + additiveFactor * additiveClip |
| 38 | \endcode |
| 39 | |
| 40 | There is nothing stopping you from using values for the additiveFacor property outside the 0 to |
| 41 | 1 range, but please be aware that the input animation clips may not be authored in such a way |
| 42 | for this to make sense. |
| 43 | |
| 44 | \sa BlendedClipAnimator |
| 45 | */ |
| 46 | |
| 47 | /*! |
| 48 | \class Qt3DAnimation::QAdditiveClipBlend |
| 49 | \inherits Qt3DAnimation::QAbstractClipBlendNode |
| 50 | |
| 51 | \inmodule Qt3DAnimation |
| 52 | \since 5.9 |
| 53 | |
| 54 | \brief Performs an additive blend of two animation clips based on an additive factor. |
| 55 | |
| 56 | QAdditiveClipBlend can be useful to create advanced animation effects based on |
| 57 | individual animation clips. For example, if you: |
| 58 | |
| 59 | \list |
| 60 | \li set the baseClip property to a normal walk cycle animation clip and |
| 61 | \li set the additiveClip property to a shaking head difference clip, |
| 62 | \endlist |
| 63 | |
| 64 | then adjusting the additiveFactor property will control how much of the additiveClip gets added |
| 65 | on to the baseClip. This has he effect that with an additiveFactor of zero, this blend node will |
| 66 | yield the original walk cycle clip. With an additiveFactor of 1, it will yield the walk cycle |
| 67 | including a shaking head animation. |
| 68 | |
| 69 | The blending operation implemented by this class is: |
| 70 | |
| 71 | \badcode |
| 72 | resultClip = baseClip + additiveFactor * additiveClip |
| 73 | \endcode |
| 74 | |
| 75 | There is nothing stopping you from using values for the additiveFacor property outside the 0 to |
| 76 | 1 range, but please be aware that the input animation clips may not be authored in such a way |
| 77 | for this to make sense. |
| 78 | |
| 79 | \sa QBlendedClipAnimator |
| 80 | */ |
| 81 | |
| 82 | QAdditiveClipBlendPrivate::QAdditiveClipBlendPrivate() |
| 83 | : QAbstractClipBlendNodePrivate() |
| 84 | , m_baseClip(nullptr) |
| 85 | , m_additiveClip(nullptr) |
| 86 | , m_additiveFactor(0.0f) |
| 87 | { |
| 88 | } |
| 89 | |
| 90 | QAdditiveClipBlend::QAdditiveClipBlend(Qt3DCore::QNode *parent) |
| 91 | : QAbstractClipBlendNode(*new QAdditiveClipBlendPrivate(), parent) |
| 92 | { |
| 93 | } |
| 94 | |
| 95 | QAdditiveClipBlend::QAdditiveClipBlend(QAdditiveClipBlendPrivate &dd, Qt3DCore::QNode *parent) |
| 96 | : QAbstractClipBlendNode(dd, parent) |
| 97 | { |
| 98 | } |
| 99 | |
| 100 | QAdditiveClipBlend::~QAdditiveClipBlend() |
| 101 | { |
| 102 | } |
| 103 | |
| 104 | /*! |
| 105 | \qmlproperty real Qt3D.Animation::AdditiveClipBlend::additiveFactor |
| 106 | |
| 107 | Specifies the blending factor, typically between 0 and 1, to control the blending of |
| 108 | two animation clips. |
| 109 | */ |
| 110 | /*! |
| 111 | \property Qt3DAnimation::QAdditiveClipBlend::additiveFactor |
| 112 | |
| 113 | Specifies the blending factor, typically between 0 and 1, to control the blending of |
| 114 | two animation clips. |
| 115 | */ |
| 116 | float QAdditiveClipBlend::additiveFactor() const |
| 117 | { |
| 118 | Q_D(const QAdditiveClipBlend); |
| 119 | return d->m_additiveFactor; |
| 120 | } |
| 121 | |
| 122 | /*! |
| 123 | \qmlproperty AbstractClipBlendNode Qt3D.Animation::AdditiveClipBlend::baseClip |
| 124 | |
| 125 | This property holds the base animation clip. When the additiveFactor is zero the \a baseClip will |
| 126 | also be the resulting clip of this blend node. |
| 127 | */ |
| 128 | /*! |
| 129 | \property Qt3DAnimation::QAdditiveClipBlend::baseClip |
| 130 | |
| 131 | This property holds the base animation clip. When the additiveFactor |
| 132 | is zero the baseClip will also be the resulting clip of this blend node. |
| 133 | */ |
| 134 | QAbstractClipBlendNode *QAdditiveClipBlend::baseClip() const |
| 135 | { |
| 136 | Q_D(const QAdditiveClipBlend); |
| 137 | return d->m_baseClip; |
| 138 | } |
| 139 | |
| 140 | /*! |
| 141 | \qmlproperty AbstractClipBlendNode Qt3D.Animation::AdditiveClipBlend::additiveClip |
| 142 | |
| 143 | This property holds the additive clip to be blended with the baseClip. The amount of blending |
| 144 | is controlled by the additiveFactor property. |
| 145 | */ |
| 146 | /*! |
| 147 | \property Qt3DAnimation::QAdditiveClipBlend::additiveClip |
| 148 | |
| 149 | This property holds the additive clip to be blended with the baseClip. The amount of blending |
| 150 | is controlled by the additiveFactor property. |
| 151 | */ |
| 152 | QAbstractClipBlendNode *QAdditiveClipBlend::additiveClip() const |
| 153 | { |
| 154 | Q_D(const QAdditiveClipBlend); |
| 155 | return d->m_additiveClip; |
| 156 | } |
| 157 | |
| 158 | void QAdditiveClipBlend::setAdditiveFactor(float additiveFactor) |
| 159 | { |
| 160 | Q_D(QAdditiveClipBlend); |
| 161 | if (d->m_additiveFactor == additiveFactor) |
| 162 | return; |
| 163 | |
| 164 | d->m_additiveFactor = additiveFactor; |
| 165 | emit additiveFactorChanged(additiveFactor); |
| 166 | } |
| 167 | |
| 168 | void QAdditiveClipBlend::setBaseClip(QAbstractClipBlendNode *baseClip) |
| 169 | { |
| 170 | Q_D(QAdditiveClipBlend); |
| 171 | if (d->m_baseClip == baseClip) |
| 172 | return; |
| 173 | |
| 174 | if (d->m_baseClip) |
| 175 | d->unregisterDestructionHelper(node: d->m_baseClip); |
| 176 | |
| 177 | if (baseClip && !baseClip->parent()) |
| 178 | baseClip->setParent(this); |
| 179 | d->m_baseClip = baseClip; |
| 180 | |
| 181 | // Ensures proper bookkeeping |
| 182 | if (d->m_baseClip) |
| 183 | d->registerDestructionHelper(node: d->m_baseClip, func: &QAdditiveClipBlend::setBaseClip, d->m_baseClip); |
| 184 | |
| 185 | emit baseClipChanged(baseClip); |
| 186 | } |
| 187 | |
| 188 | void QAdditiveClipBlend::setAdditiveClip(QAbstractClipBlendNode *additiveClip) |
| 189 | { |
| 190 | Q_D(QAdditiveClipBlend); |
| 191 | if (d->m_additiveClip == additiveClip) |
| 192 | return; |
| 193 | |
| 194 | if (d->m_additiveClip) |
| 195 | d->unregisterDestructionHelper(node: d->m_additiveClip); |
| 196 | |
| 197 | if (additiveClip && !additiveClip->parent()) |
| 198 | additiveClip->setParent(this); |
| 199 | d->m_additiveClip = additiveClip; |
| 200 | |
| 201 | // Ensures proper bookkeeping |
| 202 | if (d->m_additiveClip) |
| 203 | d->registerDestructionHelper(node: d->m_additiveClip, func: &QAdditiveClipBlend::setAdditiveClip, d->m_additiveClip); |
| 204 | emit additiveClipChanged(additiveClip); |
| 205 | } |
| 206 | |
| 207 | } // Qt3DAnimation |
| 208 | |
| 209 | QT_END_NAMESPACE |
| 210 | |
| 211 | #include "moc_qadditiveclipblend.cpp" |
| 212 | |