fix division by zero

pull/2626/head
Mike Samsonov 2019-08-29 10:44:56 +01:00
parent 4029fe5e46
commit b271091c64
1 changed files with 5 additions and 0 deletions

View File

@ -1130,6 +1130,7 @@ void glTF2Importer::ImportAnimations(glTF2::Asset& r)
// Use the latest keyframe for the duration of the animation // Use the latest keyframe for the duration of the animation
double maxDuration = 0; double maxDuration = 0;
unsigned int maxNumberOfKeys = 0;
for (unsigned int j = 0; j < ai_anim->mNumChannels; ++j) { for (unsigned int j = 0; j < ai_anim->mNumChannels; ++j) {
auto chan = ai_anim->mChannels[j]; auto chan = ai_anim->mChannels[j];
if (chan->mNumPositionKeys) { if (chan->mNumPositionKeys) {
@ -1137,21 +1138,25 @@ void glTF2Importer::ImportAnimations(glTF2::Asset& r)
if (lastPosKey.mTime > maxDuration) { if (lastPosKey.mTime > maxDuration) {
maxDuration = lastPosKey.mTime; maxDuration = lastPosKey.mTime;
} }
maxNumberOfKeys = std::max(maxNumberOfKeys, chan->mNumPositionKeys);
} }
if (chan->mNumRotationKeys) { if (chan->mNumRotationKeys) {
auto lastRotKey = chan->mRotationKeys[chan->mNumRotationKeys - 1]; auto lastRotKey = chan->mRotationKeys[chan->mNumRotationKeys - 1];
if (lastRotKey.mTime > maxDuration) { if (lastRotKey.mTime > maxDuration) {
maxDuration = lastRotKey.mTime; maxDuration = lastRotKey.mTime;
} }
maxNumberOfKeys = std::max(maxNumberOfKeys, chan->mNumRotationKeys);
} }
if (chan->mNumScalingKeys) { if (chan->mNumScalingKeys) {
auto lastScaleKey = chan->mScalingKeys[chan->mNumScalingKeys - 1]; auto lastScaleKey = chan->mScalingKeys[chan->mNumScalingKeys - 1];
if (lastScaleKey.mTime > maxDuration) { if (lastScaleKey.mTime > maxDuration) {
maxDuration = lastScaleKey.mTime; maxDuration = lastScaleKey.mTime;
} }
maxNumberOfKeys = std::max(maxNumberOfKeys, chan->mNumScalingKeys);
} }
} }
ai_anim->mDuration = maxDuration; ai_anim->mDuration = maxDuration;
ai_anim->mTicksPerSecond = (maxNumberOfKeys > 0 && maxDuration > 0) ? (maxNumberOfKeys / (maxDuration/1000)) : 30;
mScene->mAnimations[i] = ai_anim; mScene->mAnimations[i] = ai_anim;
} }