Skip to content

Commit

Permalink
Merge branch 'master' into gltf_mesh_morph_animations
Browse files Browse the repository at this point in the history
  • Loading branch information
vcebollada authored Oct 1, 2019
2 parents 42ff3f1 + 09d80ff commit 6550b1d
Showing 1 changed file with 2 additions and 39 deletions.
41 changes: 2 additions & 39 deletions code/glTF2/glTF2Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1255,45 +1255,8 @@ void glTF2Importer::ImportAnimations(glTF2::Asset& r)
}
}

ai_anim->mDuration = static_cast<double>(maxNumberOfKeys - 1u); /// According the documentation in anim.h the mDuration units are ticks.
ai_anim->mTicksPerSecond = (maxNumberOfKeys > 0 && maxDuration > 0) ? ((maxNumberOfKeys-1u) / (maxDuration / 1000.0)) : 30.0;

// Set all the times of the keys in ticks.

const float kMsToTicks = ai_anim->mTicksPerSecond / 1000.f;

for (unsigned int j = 0; j < ai_anim->mNumChannels; ++j) {
auto chan = ai_anim->mChannels[j];
if (0u != chan->mNumPositionKeys) {
for (unsigned int k = 0u; k < chan->mNumPositionKeys; ++k)
{
chan->mPositionKeys[k].mTime *= kMsToTicks;
}
}
if (0u != chan->mNumRotationKeys) {
for (unsigned int k = 0u; k < chan->mNumRotationKeys; ++k)
{
chan->mRotationKeys[k].mTime *= kMsToTicks;
}
}
if (0u != chan->mNumScalingKeys) {
for (unsigned int k = 0u; k < chan->mNumScalingKeys; ++k)
{
chan->mScalingKeys[k].mTime *= kMsToTicks;
}
}
}

for (unsigned int j = 0; j < ai_anim->mNumMorphMeshChannels; ++j) {
const auto* const chan = ai_anim->mMorphMeshChannels[j];

if (0u != chan->mNumKeys) {
for (unsigned int k = 0u; k < chan->mNumKeys; ++k)
{
chan->mKeys[k].mTime = static_cast<double>(k);
}
}
}
ai_anim->mDuration = maxDuration;
ai_anim->mTicksPerSecond = 1000.0;

mScene->mAnimations[i] = ai_anim;
}
Expand Down

0 comments on commit 6550b1d

Please sign in to comment.