summaryrefslogtreecommitdiff
path: root/src/animation/backend/animationclip.cpp
diff options
context:
space:
mode:
authorSean Harmer <sh@theharmers.co.uk>2018-07-16 14:32:08 +0100
committerSean Harmer <sean.harmer@kdab.com>2018-08-02 08:57:15 +0000
commit80a51b60c2f501a726b98e20eaba7f9551bee720 (patch)
tree43608ce96dc4725daac5cb2b332cae981fbce299 /src/animation/backend/animationclip.cpp
parent8b9f4b0936b131dad72f0ea8da1347957af20c6e (diff)
downloadqt3d-80a51b60c2f501a726b98e20eaba7f9551bee720.tar.gz
Add support for loading specific animations from glTF 2 files
Can now specify source urls to QAnimationClipLoader with query parameters for animationIndex or animationName. Add a new manual test to demonstrate/test this by loading the 2nd animation from the Rigged-Simple.gltf file. Will followup with the same support for Qt 3D native json animation files. Change-Id: Icb66073f29b8471fe06e2e2e9c43720567dc9ee5 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/animation/backend/animationclip.cpp')
-rw-r--r--src/animation/backend/animationclip.cpp31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/animation/backend/animationclip.cpp b/src/animation/backend/animationclip.cpp
index e8f8f4552..cc0a91ce0 100644
--- a/src/animation/backend/animationclip.cpp
+++ b/src/animation/backend/animationclip.cpp
@@ -50,9 +50,13 @@
#include <QtCore/qjsonarray.h>
#include <QtCore/qjsondocument.h>
#include <QtCore/qjsonobject.h>
+#include <QtCore/qurlquery.h>
QT_BEGIN_NAMESPACE
+#define ANIMATION_INDEX_KEY QLatin1String("animationIndex")
+#define ANIMATION_NAME_KEY QLatin1String("animationName")
+
namespace Qt3DAnimation {
namespace Animation {
@@ -210,15 +214,36 @@ void AnimationClip::loadAnimationFromUrl()
return;
}
+ // Extract the animationName or animationIndex from the url query parameters.
+ // If both present, animationIndex wins.
+ int animationIndex = -1;
+ QString animationName;
+ if (m_source.hasQuery()) {
+ QUrlQuery query(m_source);
+ if (query.hasQueryItem(ANIMATION_INDEX_KEY)) {
+ bool ok = false;
+ int i = query.queryItemValue(ANIMATION_INDEX_KEY).toInt(&ok);
+ if (ok)
+ animationIndex = i;
+ }
+
+ if (animationIndex == -1 && query.hasQueryItem(ANIMATION_NAME_KEY)) {
+ animationName = query.queryItemValue(ANIMATION_NAME_KEY);
+ }
+
+ qCDebug(Jobs) << "animationIndex =" << animationIndex;
+ qCDebug(Jobs) << "animationName =" << animationName;
+ }
+
// TODO: Convert to plugins
// Load glTF or "native"
if (filePath.endsWith(QLatin1String("gltf"))) {
qCDebug(Jobs) << "Loading glTF animation from" << filePath;
GLTFImporter gltf;
gltf.load(&file);
- // TODO: Allow loading of a named animation from a file containing many
- m_name = gltf.animations().first().name;
- m_channels = gltf.createAnimationData();
+ auto nameAndChannels = gltf.createAnimationData(animationIndex, animationName);
+ m_name = nameAndChannels.name;
+ m_channels = nameAndChannels.channels;
} else if (filePath.endsWith(QLatin1String("json"))) {
// Native format
QByteArray animationData = file.readAll();