Merge pull request #1263 from jamesgk/gltf-export

GLTF exporter: convert animation time from ticks to seconds
pull/1269/head
Alexander Gessler 2017-05-15 09:12:57 +02:00 committed by GitHub
commit ab45dc79fa
1 changed files with 4 additions and 3 deletions

View File

@ -840,7 +840,7 @@ void glTFExporter::ExportMetadata()
asset.generator = buffer; asset.generator = buffer;
} }
inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref<Animation>& animRef, Ref<Buffer>& buffer, const aiNodeAnim* nodeChannel) inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref<Animation>& animRef, Ref<Buffer>& buffer, const aiNodeAnim* nodeChannel, float ticksPerSecond)
{ {
// Loop over the data and check to see if it exactly matches an existing buffer. // Loop over the data and check to see if it exactly matches an existing buffer.
// If yes, then reference the existing corresponding accessor. // If yes, then reference the existing corresponding accessor.
@ -867,8 +867,9 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref<Animati
timeData.resize(numKeyframes); timeData.resize(numKeyframes);
for (size_t i = 0; i < numKeyframes; ++i) { for (size_t i = 0; i < numKeyframes; ++i) {
size_t frameIndex = i * nodeChannel->mNumPositionKeys / numKeyframes; size_t frameIndex = i * nodeChannel->mNumPositionKeys / 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() // 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<Accessor> timeAccessor = ExportData(mAsset, animId, buffer, numKeyframes, &timeData[0], AttribType::SCALAR, AttribType::SCALAR, ComponentType_FLOAT); Ref<Accessor> timeAccessor = ExportData(mAsset, animId, buffer, numKeyframes, &timeData[0], AttribType::SCALAR, AttribType::SCALAR, ComponentType_FLOAT);
@ -949,7 +950,7 @@ void glTFExporter::ExportAnimations()
Ref<Animation> animRef = mAsset->animations.Create(name); Ref<Animation> animRef = mAsset->animations.Create(name);
/******************* Parameters ********************/ /******************* Parameters ********************/
ExtractAnimationData(*mAsset, name, animRef, bufferRef, nodeChannel); ExtractAnimationData(*mAsset, name, animRef, bufferRef, nodeChannel, anim->mTicksPerSecond);
for (unsigned int j = 0; j < 3; ++j) { for (unsigned int j = 0; j < 3; ++j) {
std::string channelType; std::string channelType;