Collada: refactorings.

pull/835/head
Kim Kulling 2016-03-15 21:17:38 +01:00
parent d89e7943ad
commit 644d6a9a67
1 changed files with 12 additions and 12 deletions

View File

@ -1156,13 +1156,13 @@ void ColladaLoader::CreateAnimation( aiScene* pScene, const ColladaParser& pPars
float nextTime = 1e20f;
for( std::vector<Collada::ChannelEntry>::iterator it = entries.begin(); it != entries.end(); ++it)
{
Collada::ChannelEntry& e = *it;
Collada::ChannelEntry& channelElement = *it;
// find the next time value larger than the current
size_t pos = 0;
while( pos < e.mTimeAccessor->mCount)
while( pos < channelElement.mTimeAccessor->mCount)
{
float t = ReadFloat( *e.mTimeAccessor, *e.mTimeData, pos, 0);
const float t = ReadFloat( *channelElement.mTimeAccessor, *channelElement.mTimeData, pos, 0);
if( t > time)
{
nextTime = std::min( nextTime, t);
@ -1174,17 +1174,17 @@ void ColladaLoader::CreateAnimation( aiScene* pScene, const ColladaParser& pPars
// https://github.com/assimp/assimp/issues/458
// Sub-sample axis-angle channels if the delta between two consecutive
// key-frame angles is >= 180 degrees.
if (transforms[e.mTransformIndex].mType == Collada::TF_ROTATE && e.mSubElement == 3 && pos > 0 && pos < e.mTimeAccessor->mCount) {
float cur_key_angle = ReadFloat(*e.mValueAccessor, *e.mValueData, pos, 0);
float last_key_angle = ReadFloat(*e.mValueAccessor, *e.mValueData, pos - 1, 0);
float cur_key_time = ReadFloat(*e.mTimeAccessor, *e.mTimeData, pos, 0);
float last_key_time = ReadFloat(*e.mTimeAccessor, *e.mTimeData, pos - 1, 0);
float last_eval_angle = last_key_angle + (cur_key_angle - last_key_angle) * (time - last_key_time) / (cur_key_time - last_key_time);
float delta = std::fabs(cur_key_angle - last_eval_angle);
if (transforms[channelElement.mTransformIndex].mType == Collada::TF_ROTATE && channelElement.mSubElement == 3 && pos > 0 && pos < channelElement.mTimeAccessor->mCount) {
const float cur_key_angle = ReadFloat(*channelElement.mValueAccessor, *channelElement.mValueData, pos, 0);
const float last_key_angle = ReadFloat(*channelElement.mValueAccessor, *channelElement.mValueData, pos - 1, 0);
const float cur_key_time = ReadFloat(*channelElement.mTimeAccessor, *channelElement.mTimeData, pos, 0);
const float last_key_time = ReadFloat(*channelElement.mTimeAccessor, *channelElement.mTimeData, pos - 1, 0);
const float last_eval_angle = last_key_angle + (cur_key_angle - last_key_angle) * (time - last_key_time) / (cur_key_time - last_key_time);
const float delta = std::fabs(cur_key_angle - last_eval_angle);
if (delta >= 180.0f) {
int subSampleCount = static_cast<int>(floorf(delta / 90.0f));
const int subSampleCount = static_cast<int>(floorf(delta / 90.0f));
if (cur_key_time != time) {
float nextSampleTime = time + (cur_key_time - time) / subSampleCount;
const float nextSampleTime = time + (cur_key_time - time) / subSampleCount;
nextTime = std::min(nextTime, nextSampleTime);
}
}