- fbx: read framerate and output it in aiAnimation::mTicksPerSecond.

pull/14/head
Alexander Gessler 2012-08-25 17:31:15 +02:00
parent d881bb9cdc
commit 375c4b4242
2 changed files with 68 additions and 11 deletions

View File

@ -1544,10 +1544,67 @@ private:
} }
// ------------------------------------------------------------------------------------------------
// get the number of fps for a FrameRate enumerated value
static double FrameRateToDouble(FileGlobalSettings::FrameRate fp, double customFPSVal = -1.0)
{
switch(fp) {
case FileGlobalSettings::FrameRate_DEFAULT:
return 1.0;
case FileGlobalSettings::FrameRate_120:
return 120.0;
case FileGlobalSettings::FrameRate_100:
return 100.0;
case FileGlobalSettings::FrameRate_60:
return 60.0;
case FileGlobalSettings::FrameRate_50:
return 50.0;
case FileGlobalSettings::FrameRate_48:
return 48.0;
case FileGlobalSettings::FrameRate_30:
case FileGlobalSettings::FrameRate_30_DROP:
return 30.0;
case FileGlobalSettings::FrameRate_NTSC_DROP_FRAME:
case FileGlobalSettings::FrameRate_NTSC_FULL_FRAME:
return 29.9700262;
case FileGlobalSettings::FrameRate_PAL:
return 25.0;
case FileGlobalSettings::FrameRate_CINEMA:
return 24.0;
case FileGlobalSettings::FrameRate_1000:
return 1000.0;
case FileGlobalSettings::FrameRate_CINEMA_ND:
return 23.976;
case FileGlobalSettings::FrameRate_CUSTOM:
return customFPSVal;
}
ai_assert(false);
return -1.0f;
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// convert animation data to aiAnimation et al // convert animation data to aiAnimation et al
void ConvertAnimations() void ConvertAnimations()
{ {
// first of all determine framerate
const FileGlobalSettings::FrameRate fps = doc.GlobalSettings().TimeMode();
const float custom = doc.GlobalSettings().CustomFrameRate();
anim_fps = FrameRateToDouble(fps, custom);
const std::vector<const AnimationStack*>& animations = doc.AnimationStacks(); const std::vector<const AnimationStack*>& animations = doc.AnimationStacks();
BOOST_FOREACH(const AnimationStack* stack, animations) { BOOST_FOREACH(const AnimationStack* stack, animations) {
ConvertAnimationStack(*stack); ConvertAnimationStack(*stack);
@ -1677,7 +1734,7 @@ private:
// for some mysterious reason, mDuration is simply the maximum key -- the // for some mysterious reason, mDuration is simply the maximum key -- the
// validator always assumes animations to start at zero. // validator always assumes animations to start at zero.
anim->mDuration = max_time /*- min_time */; anim->mDuration = max_time /*- min_time */;
anim->mTicksPerSecond = 1.0; anim->mTicksPerSecond = anim_fps;
} }
@ -2282,8 +2339,8 @@ private:
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void InterpolateKeys(aiVectorKey* valOut,const KeyTimeList& keys, const KeyFrameListList& inputs, void InterpolateKeys(aiVectorKey* valOut,const KeyTimeList& keys, const KeyFrameListList& inputs,
const bool geom, const bool geom,
double& maxTime, double& max_time,
double& minTime) double& min_time)
{ {
ai_assert(keys.size()); ai_assert(keys.size());
@ -2331,11 +2388,11 @@ private:
} }
} }
// magic value to convert fbx times to milliseconds // magic value to convert fbx times to seconds
valOut->mTime = CONVERT_FBX_TIME(time); valOut->mTime = CONVERT_FBX_TIME(time) * anim_fps;
minTime = std::min(minTime, valOut->mTime); min_time = std::min(min_time, valOut->mTime);
maxTime = std::max(maxTime, valOut->mTime); max_time = std::max(max_time, valOut->mTime);
valOut->mValue.x = result[0]; valOut->mValue.x = result[0];
valOut->mValue.y = result[1]; valOut->mValue.y = result[1];
@ -2386,7 +2443,7 @@ private:
} }
else { else {
for (size_t i = 0; i < times.size(); ++i) { for (size_t i = 0; i < times.size(); ++i) {
out_quat[i].mTime = CONVERT_FBX_TIME(times[i]); out_quat[i].mTime = CONVERT_FBX_TIME(times[i]) * anim_fps;
out_quat[i].mValue = def_rotation; out_quat[i].mValue = def_rotation;
} }
} }
@ -2396,7 +2453,7 @@ private:
} }
else { else {
for (size_t i = 0; i < times.size(); ++i) { for (size_t i = 0; i < times.size(); ++i) {
out_scale[i].mTime = CONVERT_FBX_TIME(times[i]); out_scale[i].mTime = CONVERT_FBX_TIME(times[i]) * anim_fps;
out_scale[i].mValue = def_scale; out_scale[i].mValue = def_scale;
} }
} }
@ -2406,7 +2463,7 @@ private:
} }
else { else {
for (size_t i = 0; i < times.size(); ++i) { for (size_t i = 0; i < times.size(); ++i) {
out_translation[i].mTime = CONVERT_FBX_TIME(times[i]); out_translation[i].mTime = CONVERT_FBX_TIME(times[i]) * anim_fps;
out_translation[i].mValue = def_translate; out_translation[i].mValue = def_translate;
} }
} }
@ -2565,6 +2622,7 @@ private:
typedef std::map<std::string, bool> NodeNameMap; typedef std::map<std::string, bool> NodeNameMap;
NodeNameMap node_names; NodeNameMap node_names;
double anim_fps;
aiScene* const out; aiScene* const out;
const FBX::Document& doc; const FBX::Document& doc;

View File

@ -1150,7 +1150,6 @@ public:
FrameRate_1000 = 12, FrameRate_1000 = 12,
FrameRate_CINEMA_ND = 13, FrameRate_CINEMA_ND = 13,
FrameRate_CUSTOM = 14, FrameRate_CUSTOM = 14,
FrameRate_TIME_MODE_COUNT = 15,
FrameRate_MAX// end-of-enum sentinel FrameRate_MAX// end-of-enum sentinel
}; };