summaryrefslogtreecommitdiffstats
path: root/src/animation
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-10-08 10:59:02 +0100
committerSean Harmer <sean.harmer@kdab.com>2018-01-19 14:24:17 +0000
commit44aeb43834675a4d6b19bee88e267464ca7ad1f4 (patch)
tree5edced239bbd6795e2102a3d769b10c0192a9c60 /src/animation
parent16d1c5d08e3c1bbcc2990d0331389eed5a304b21 (diff)
Add a function to calculate the default value for missing channels
Change-Id: Ic7bee59324da81fe2e467fd940029706297fc286 Reviewed-by: Christian Stromme <christian.stromme@qt.io> Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/animation')
-rw-r--r--src/animation/backend/animationutils.cpp69
-rw-r--r--src/animation/backend/animationutils_p.h3
2 files changed, 72 insertions, 0 deletions
diff --git a/src/animation/backend/animationutils.cpp b/src/animation/backend/animationutils.cpp
index 3096a2647..8652c7df1 100644
--- a/src/animation/backend/animationutils.cpp
+++ b/src/animation/backend/animationutils.cpp
@@ -88,6 +88,16 @@ int componentsForType(int type)
return componentCount;
}
+inline QVector<float> valueToVector(const QVector3D &value)
+{
+ return { value.x(), value.y(), value.z() };
+}
+
+inline QVector<float> valueToVector(const QQuaternion &value)
+{
+ return { value.scalar(), value.x(), value.y(), value.z() };
+}
+
ClipEvaluationData evaluationDataForClip(AnimationClip *clip,
const AnimatorEvaluationData &animatorData)
{
@@ -779,6 +789,65 @@ ClipResults evaluateBlendTree(Handler *handler,
return blendTreeRootNode->clipResults(animatorId);
}
+QVector<float> defaultValueForChannel(Handler *handler,
+ const ChannelNameAndType &channelDescription)
+{
+ QVector<float> result;
+
+ // Does the channel repesent a joint in a skeleton or is it a general channel?
+ ChannelMappingManager *mappingManager = handler->channelMappingManager();
+ const ChannelMapping *mapping = mappingManager->lookupResource(channelDescription.mappingId);
+ switch (mapping->mappingType()) {
+ case ChannelMapping::SkeletonMappingType: {
+ // Default channel values for a joint in a skeleton, should be taken
+ // from the default pose of the joint itself. I.e. if a joint is not
+ // explicitly animated, then it should retain it's initial rest pose.
+ Skeleton *skeleton = mapping->skeleton();
+ const int jointIndex = channelDescription.jointIndex;
+ switch (channelDescription.jointTransformComponent) {
+ case Translation:
+ result = valueToVector(skeleton->jointTranslation(jointIndex));
+ break;
+
+ case Rotation:
+ result = valueToVector(skeleton->jointRotation(jointIndex));
+ break;
+
+ case Scale:
+ result = valueToVector(skeleton->jointScale(jointIndex));
+ break;
+
+ case NoTransformComponent:
+ Q_UNREACHABLE();
+ break;
+ }
+ break;
+ }
+
+ case ChannelMapping::ChannelMappingType:
+ case ChannelMapping::CallbackMappingType: {
+ // Do our best to provide a sensible default value.
+ if (channelDescription.type == QMetaType::QQuaternion) {
+ result = valueToVector(QQuaternion()); // (1, 0, 0, 0)
+ break;
+ }
+
+ if (channelDescription.name.toLower() == QLatin1String("scale")) {
+ result = valueToVector(QVector3D(1.0f, 1.0f, 1.0f));
+ break;
+ }
+
+ // Everything else gets all zeros
+ const int componentCount = componentsForType(channelDescription.type);
+ result = QVector<float>(componentCount, 0.0f);
+ break;
+ }
+
+ }
+
+ return result;
+}
+
} // Animation
} // Qt3DAnimation
diff --git a/src/animation/backend/animationutils_p.h b/src/animation/backend/animationutils_p.h
index 915a91bca..6a1b18936 100644
--- a/src/animation/backend/animationutils_p.h
+++ b/src/animation/backend/animationutils_p.h
@@ -335,6 +335,9 @@ ClipResults evaluateBlendTree(Handler *handler,
BlendedClipAnimator *animator,
Qt3DCore::QNodeId blendNodeId);
+Q_AUTOTEST_EXPORT
+QVector<float> defaultValueForChannel(Handler *handler, const ChannelNameAndType &channelDescription);
+
} // Animation
} // Qt3DAnimation