diff options
author | Sean Harmer <sh@theharmers.co.uk> | 2018-07-16 14:32:08 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2018-08-02 08:57:15 +0000 |
commit | 80a51b60c2f501a726b98e20eaba7f9551bee720 (patch) | |
tree | 43608ce96dc4725daac5cb2b332cae981fbce299 /src/animation/backend/gltfimporter.cpp | |
parent | 8b9f4b0936b131dad72f0ea8da1347957af20c6e (diff) |
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/gltfimporter.cpp')
-rw-r--r-- | src/animation/backend/gltfimporter.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/animation/backend/gltfimporter.cpp b/src/animation/backend/gltfimporter.cpp index d9c0cb9a6..e91dd5661 100644 --- a/src/animation/backend/gltfimporter.cpp +++ b/src/animation/backend/gltfimporter.cpp @@ -466,16 +466,15 @@ QHash<int, int> GLTFImporter::createNodeIndexToJointIndexMap(const Skin &skin) c return nodeIndexToJointIndexMap; } -QVector<Qt3DAnimation::Animation::Channel> GLTFImporter::createAnimationData(const QString &animationName) const +GLTFImporter::AnimationNameAndChannels GLTFImporter::createAnimationData(int animationIndex, const QString &animationName) const { - QVector<Qt3DAnimation::Animation::Channel> channels; + AnimationNameAndChannels nameAndChannels; if (m_animations.isEmpty()) { qCWarning(Jobs) << "File does not contain any animation data"; - return channels; + return nameAndChannels; } - int animationIndex = 0; - if (!animationName.isEmpty()) { + if (animationIndex == -1 && !animationName.isEmpty()) { for (int i = 0; i < m_animations.size(); ++i) { if (m_animations[i].name == animationName) { animationIndex = i; @@ -483,7 +482,13 @@ QVector<Qt3DAnimation::Animation::Channel> GLTFImporter::createAnimationData(con } } } + + if (animationIndex >= m_animations.size()) { + qCWarning(Jobs) << "Invalid animation index. Skipping."; + return nameAndChannels; + } const Animation &animation = m_animations[animationIndex]; + nameAndChannels.name = animation.name; // Create node index to joint index lookup tables for each skin QVector<QHash<int, int>> nodeIndexToJointIndexMaps; @@ -621,11 +626,11 @@ QVector<Qt3DAnimation::Animation::Channel> GLTFImporter::createAnimationData(con } // case 4 } - channels.push_back(outputChannel); + nameAndChannels.channels.push_back(outputChannel); ++channelIndex; } - return channels; + return nameAndChannels; } GLTFImporter::RawData GLTFImporter::accessorData(int accessorIndex, int index) const |