diff options
Diffstat (limited to 'src/animation')
-rw-r--r-- | src/animation/backend/animationutils.cpp | 24 | ||||
-rw-r--r-- | src/animation/backend/fcurve.cpp | 52 | ||||
-rw-r--r-- | src/animation/frontend/qabstractclipanimator.cpp | 2 | ||||
-rw-r--r-- | src/animation/frontend/qchannelmapping.cpp | 9 |
4 files changed, 71 insertions, 16 deletions
diff --git a/src/animation/backend/animationutils.cpp b/src/animation/backend/animationutils.cpp index ef6aec058..c12ad99f7 100644 --- a/src/animation/backend/animationutils.cpp +++ b/src/animation/backend/animationutils.cpp @@ -46,6 +46,7 @@ #include <QtGui/qvector3d.h> #include <QtGui/qvector4d.h> #include <QtGui/qquaternion.h> +#include <QtGui/qcolor.h> #include <QtCore/qvariant.h> #include <Qt3DAnimation/private/animationlogging_p.h> @@ -60,6 +61,7 @@ int componentsForType(int type) { int componentCount = 1; switch (type) { + case QMetaType::Float: case QVariant::Double: componentCount = 1; break; @@ -69,6 +71,7 @@ int componentsForType(int type) break; case QVariant::Vector3D: + case QVariant::Color: componentCount = 3; break; @@ -149,15 +152,21 @@ ComponentIndices channelComponentsToIndices(const Channel &channel, int dataType #if defined Q_COMPILER_UNIFORM_INIT static const QVector<char> standardSuffixes = { 'X', 'Y', 'Z', 'W' }; static const QVector<char> quaternionSuffixes = { 'W', 'X', 'Y', 'Z' }; + static const QVector<char> colorSuffixes = { 'R', 'G', 'B' }; #else static const QVector<char> standardSuffixes = (QVector<char>() << 'X' << 'Y' << 'Z' << 'W'); static const QVector<char> quaternionSuffixes = (QVector<char>() << 'W' << 'X' << 'Y' << 'Z'); + static const QVector<char> colorSuffixes = (QVector<char>() << 'R' << 'G' << 'B'); #endif - if (dataType != QVariant::Quaternion) - return channelComponentsToIndicesHelper(channel, dataType, offset, standardSuffixes); - else + switch (dataType) { + case QVariant::Quaternion: return channelComponentsToIndicesHelper(channel, dataType, offset, quaternionSuffixes); + case QVariant::Color: + return channelComponentsToIndicesHelper(channel, dataType, offset, colorSuffixes); + default: + return channelComponentsToIndicesHelper(channel, dataType, offset, standardSuffixes); + } } ComponentIndices channelComponentsToIndicesHelper(const Channel &channel, @@ -229,6 +238,7 @@ QVector<Qt3DCore::QSceneChangePtr> preparePropertyChanges(Qt3DCore::QNodeId anim // Build the new value from the channel/fcurve evaluation results QVariant v; switch (mappingData.type) { + case QMetaType::Float: case QVariant::Double: { v = QVariant::fromValue(channelResults[mappingData.channelIndices[0]]); break; @@ -268,6 +278,14 @@ QVector<Qt3DCore::QSceneChangePtr> preparePropertyChanges(Qt3DCore::QNodeId anim break; } + case QVariant::Color: { + const QColor color = QColor::fromRgbF(channelResults[mappingData.channelIndices[0]], + channelResults[mappingData.channelIndices[1]], + channelResults[mappingData.channelIndices[2]]); + v = QVariant::fromValue(color); + break; + } + default: qWarning() << "Unhandled animation type"; continue; diff --git a/src/animation/backend/fcurve.cpp b/src/animation/backend/fcurve.cpp index 809949472..4a2cf30fd 100644 --- a/src/animation/backend/fcurve.cpp +++ b/src/animation/backend/fcurve.cpp @@ -60,12 +60,35 @@ float FCurve::evaluateAtTime(float localTime) const return m_keyframes.last().value; } else { // Find keyframes that sandwich the requested localTime - int keyframe0 = m_rangeFinder.findLowerBound(localTime); - - BezierEvaluator evaluator(m_localTimes[keyframe0], m_keyframes[keyframe0], - m_localTimes[keyframe0 + 1], m_keyframes[keyframe0 + 1]); - return evaluator.valueForTime(localTime); + const int idx = m_rangeFinder.findLowerBound(localTime); + + const float t0 = m_localTimes[idx]; + const float t1 = m_localTimes[idx + 1]; + const Keyframe &keyframe0(m_keyframes[idx]); + const Keyframe &keyframe1(m_keyframes[idx + 1]); + + switch (keyframe0.interpolation) { + case QKeyFrame::ConstantInterpolation: + qWarning("Constant interpolation not implemented yet"); + break; + case QKeyFrame::LinearInterpolation: + if (localTime >= t0 && localTime <= t1 && t1 > t0) { + float t = (localTime - t0) / (t1 - t0); + return (1 - t) * keyframe0.value + t * keyframe1.value; + } + break; + case QKeyFrame::BezierInterpolation: + { + BezierEvaluator evaluator(t0, keyframe0, t1, keyframe1); + return evaluator.valueForTime(localTime); + } + default: + qWarning("Unknown interpolation type %d", keyframe0.interpolation); + break; + } } + + return m_keyframes.first().value; } float FCurve::startTime() const @@ -103,16 +126,21 @@ void FCurve::read(const QJsonObject &json) float localTime = keyframeCoords.at(0).toDouble(); Keyframe keyframe; - keyframe.interpolation = QKeyFrame::BezierInterpolation; keyframe.value = keyframeCoords.at(1).toDouble(); - const QJsonArray leftHandle = keyframeData[QLatin1String("leftHandle")].toArray(); - keyframe.leftControlPoint[0] = leftHandle.at(0).toDouble(); - keyframe.leftControlPoint[1] = leftHandle.at(1).toDouble(); + if (keyframeData.contains(QLatin1String("leftHandle"))) { + keyframe.interpolation = QKeyFrame::BezierInterpolation; + + const QJsonArray leftHandle = keyframeData[QLatin1String("leftHandle")].toArray(); + keyframe.leftControlPoint[0] = leftHandle.at(0).toDouble(); + keyframe.leftControlPoint[1] = leftHandle.at(1).toDouble(); - const QJsonArray rightHandle = keyframeData[QLatin1String("rightHandle")].toArray(); - keyframe.rightControlPoint[0] = rightHandle.at(0).toDouble(); - keyframe.rightControlPoint[1] = rightHandle.at(1).toDouble(); + const QJsonArray rightHandle = keyframeData[QLatin1String("rightHandle")].toArray(); + keyframe.rightControlPoint[0] = rightHandle.at(0).toDouble(); + keyframe.rightControlPoint[1] = rightHandle.at(1).toDouble(); + } else { + keyframe.interpolation = QKeyFrame::LinearInterpolation; + } appendKeyframe(localTime, keyframe); } diff --git a/src/animation/frontend/qabstractclipanimator.cpp b/src/animation/frontend/qabstractclipanimator.cpp index 0d215b470..c75b92d47 100644 --- a/src/animation/frontend/qabstractclipanimator.cpp +++ b/src/animation/frontend/qabstractclipanimator.cpp @@ -54,7 +54,7 @@ QAbstractClipAnimatorPrivate::QAbstractClipAnimatorPrivate() } /*! - \qmltype AbsractClipAnimator + \qmltype AbstractClipAnimator \instantiates Qt3DAnimation::QAbstractClipAnimator \inqmlmodule Qt3D.Animation \since 5.9 diff --git a/src/animation/frontend/qchannelmapping.cpp b/src/animation/frontend/qchannelmapping.cpp index b3d3816a0..faa77f5db 100644 --- a/src/animation/frontend/qchannelmapping.cpp +++ b/src/animation/frontend/qchannelmapping.cpp @@ -74,6 +74,15 @@ void QChannelMappingPrivate::updatePropertyNameAndType() QMetaProperty mp = mo->property(propertyIndex); propertyName = mp.name(); type = mp.userType(); + if (type == QMetaType::QVariant) { + QVariant currentValue = m_target->property(mp.name()); + if (currentValue.isValid()) { + type = currentValue.userType(); + } else { + qWarning("QChannelMapping: Attempted to target QVariant property with no value set. " + "Set a value first in order to be able to determine the type."); + } + } } if (m_type != type) { |