From c33039d682bb92ab795fa323eaae80230f4aa3ab Mon Sep 17 00:00:00 2001 From: jamesgk Date: Thu, 11 May 2017 11:04:23 -0700 Subject: [PATCH] GLTF exporter: convert animation time from ticks to seconds --- code/glTFExporter.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/code/glTFExporter.cpp b/code/glTFExporter.cpp index 53ab3df19..1fbd17d1b 100644 --- a/code/glTFExporter.cpp +++ b/code/glTFExporter.cpp @@ -840,7 +840,7 @@ void glTFExporter::ExportMetadata() asset.generator = buffer; } -inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref& animRef, Ref& buffer, const aiNodeAnim* nodeChannel) +inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref& animRef, Ref& buffer, const aiNodeAnim* nodeChannel, float ticksPerSecond) { // Loop over the data and check to see if it exactly matches an existing buffer. // If yes, then reference the existing corresponding accessor. @@ -867,8 +867,9 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, RefmNumPositionKeys / numKeyframes; + // mTime is measured in ticks, but GLTF time is measured in seconds, so convert. // Check if we have to cast type here. e.g. uint16_t() - timeData[i] = nodeChannel->mPositionKeys[frameIndex].mTime; + timeData[i] = nodeChannel->mPositionKeys[frameIndex].mTime / ticksPerSecond; } Ref timeAccessor = ExportData(mAsset, animId, buffer, numKeyframes, &timeData[0], AttribType::SCALAR, AttribType::SCALAR, ComponentType_FLOAT); @@ -949,7 +950,7 @@ void glTFExporter::ExportAnimations() Ref animRef = mAsset->animations.Create(name); /******************* Parameters ********************/ - ExtractAnimationData(*mAsset, name, animRef, bufferRef, nodeChannel); + ExtractAnimationData(*mAsset, name, animRef, bufferRef, nodeChannel, anim->mTicksPerSecond); for (unsigned int j = 0; j < 3; ++j) { std::string channelType;