summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-03-20 15:13:49 +0000
committerSean Harmer <sean.harmer@kdab.com>2017-03-25 14:23:32 +0000
commit6af77603f97cf4f4dc68b3f18e89e930d547afdc (patch)
tree5f40ccb484308a6563b28e559522d4d36e930c9c /src
parent1929b3e48c0a327e7a741275d6d4847b72ddf704 (diff)
Add function assignChannelComponentIndices
This iterates through the channel description and assigns channel component indices in ascending order. The next step will be to use this in conjunction with the channel description with the layout of channels in each clip to generate the format indices that will allow us to quickly map from the clip's raw ClipResults to ClipResults formatted in the layotu used by the blend tree/animator. Change-Id: I04dd5a21ca8355529118cfb2b05f4904e43ef0e2 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/animation/backend/animationutils.cpp76
-rw-r--r--src/animation/backend/animationutils_p.h6
2 files changed, 59 insertions, 23 deletions
diff --git a/src/animation/backend/animationutils.cpp b/src/animation/backend/animationutils.cpp
index d79b412fd..f65f828fc 100644
--- a/src/animation/backend/animationutils.cpp
+++ b/src/animation/backend/animationutils.cpp
@@ -49,11 +49,41 @@
#include <QtCore/qvariant.h>
#include <Qt3DAnimation/private/animationlogging_p.h>
+#include <numeric>
+
QT_BEGIN_NAMESPACE
namespace Qt3DAnimation {
namespace Animation {
+int componentsForType(int type)
+{
+ int componentCount = 1;
+ switch (type) {
+ case QVariant::Double:
+ componentCount = 1;
+ break;
+
+ case QVariant::Vector2D:
+ componentCount = 2;
+ break;
+
+ case QVariant::Vector3D:
+ componentCount = 3;
+ break;
+
+ case QVariant::Vector4D:
+ case QVariant::Quaternion:
+ componentCount = 4;
+ break;
+
+ default:
+ qWarning() << "Unhandled animation type";
+ }
+
+ return componentCount;
+}
+
ClipEvaluationData evaluationDataForClip(AnimationClipLoader *clip,
const AnimatorEvaluationData &animatorData)
{
@@ -135,29 +165,7 @@ ComponentIndices channelComponentsToIndicesHelper(const Channel &channel,
int offset,
const QVector<char> &suffixes)
{
- int expectedComponentCount = 1;
- switch (dataType) {
- case QVariant::Double:
- expectedComponentCount = 1;
- break;
-
- case QVariant::Vector2D:
- expectedComponentCount = 2;
- break;
-
- case QVariant::Vector3D:
- expectedComponentCount = 3;
- break;
-
- case QVariant::Vector4D:
- case QVariant::Quaternion:
- expectedComponentCount = 4;
- break;
-
- default:
- qWarning() << "Unhandled animation type";
- }
-
+ const int expectedComponentCount = componentsForType(dataType);
const int actualComponentCount = channel.channelComponents.size();
if (actualComponentCount != expectedComponentCount) {
qWarning() << "Data type expects" << expectedComponentCount
@@ -366,6 +374,28 @@ QVector<ChannelNameAndType> buildRequiredChannelsAndTypes(Handler *handler,
return namesAndTypes;
}
+QVector<ComponentIndices> assignChannelComponentIndices(const QVector<ChannelNameAndType> &namesAndTypes)
+{
+ QVector<ComponentIndices> channelComponentIndices;
+ channelComponentIndices.reserve(namesAndTypes.size());
+
+ int baseIndex = 0;
+ for (const auto &entry : namesAndTypes) {
+ // Populate indices in order
+ const int componentCount = componentsForType(entry.type);
+ ComponentIndices indices(componentCount);
+ std::iota(indices.begin(), indices.end(), baseIndex);
+
+ // Append to the results
+ channelComponentIndices.push_back(indices);
+
+ // Increment baseIndex
+ baseIndex += componentCount;
+ }
+
+ return channelComponentIndices;
+}
+
QVector<Qt3DCore::QNodeId> gatherValueNodesToEvaluate(Handler *handler,
Qt3DCore::QNodeId blendTreeRootId)
{
diff --git a/src/animation/backend/animationutils_p.h b/src/animation/backend/animationutils_p.h
index dd600c207..809f4eca0 100644
--- a/src/animation/backend/animationutils_p.h
+++ b/src/animation/backend/animationutils_p.h
@@ -136,6 +136,9 @@ inline bool isFinalFrame(double localTime,
}
Q_AUTOTEST_EXPORT
+int componentsForType(int type);
+
+Q_AUTOTEST_EXPORT
ClipEvaluationData evaluationDataForClip(AnimationClipLoader *clip,
const AnimatorEvaluationData &animatorData);
@@ -174,6 +177,9 @@ QVector<ChannelNameAndType> buildRequiredChannelsAndTypes(Handler *handler,
const ChannelMapper *mapper);
Q_AUTOTEST_EXPORT
+QVector<ComponentIndices> assignChannelComponentIndices(const QVector<ChannelNameAndType> &namesAndTypes);
+
+Q_AUTOTEST_EXPORT
double localTimeFromGlobalTime(double t_global, double t_start_global,
double playbackRate, double duration,
int loopCount, int &currentLoop);