From 7182f89a518482c4d943ea532c2249883b8037ef Mon Sep 17 00:00:00 2001 From: Tammo Hinrichs Date: Thu, 24 Aug 2017 14:40:53 +0200 Subject: [PATCH 1/4] FBX importer: Use actual min/max of animation keyframes when start/stop time is missing --- code/FBXConverter.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index ebe7ac4e6..ae98d24fd 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -2368,8 +2368,13 @@ void Converter::ConvertAnimationStack( const AnimationStack& st ) int64_t start_time = st.LocalStart(); int64_t stop_time = st.LocalStop(); - double start_timeF = CONVERT_FBX_TIME( start_time ); - double stop_timeF = CONVERT_FBX_TIME( stop_time ); + bool has_local_startstop = start_time != 0 || stop_time != 0; + if ( !has_local_startstop ) { + // no time range given, so accept every keyframe and use the actual min/max time + // the +/- 20000 is a safety because GenerateNodeAnimations uses an epsilon of 10000 + start_time = INT64_MIN + 20000; + stop_time = INT64_MAX - 20000; + } try { for( const NodeMap::value_type& kv : node_map ) { @@ -2401,27 +2406,23 @@ void Converter::ConvertAnimationStack( const AnimationStack& st ) return; } - //adjust relative timing for animation - { - double start_fps = start_timeF * anim_fps; + double start_time_fps = has_local_startstop ? (CONVERT_FBX_TIME(start_time) * anim_fps) : min_time; + double stop_time_fps = has_local_startstop ? (CONVERT_FBX_TIME(stop_time) * anim_fps) : max_time; - for ( unsigned int c = 0; c < anim->mNumChannels; c++ ) - { - aiNodeAnim* channel = anim->mChannels[ c ]; - for ( uint32_t i = 0; i < channel->mNumPositionKeys; i++ ) - channel->mPositionKeys[ i ].mTime -= start_fps; - for ( uint32_t i = 0; i < channel->mNumRotationKeys; i++ ) - channel->mRotationKeys[ i ].mTime -= start_fps; - for ( uint32_t i = 0; i < channel->mNumScalingKeys; i++ ) - channel->mScalingKeys[ i ].mTime -= start_fps; - } - - max_time -= min_time; + // adjust relative timing for animation + for ( unsigned int c = 0; c < anim->mNumChannels; c++ ) { + aiNodeAnim* channel = anim->mChannels[ c ]; + for ( uint32_t i = 0; i < channel->mNumPositionKeys; i++ ) + channel->mPositionKeys[ i ].mTime -= start_time_fps; + for ( uint32_t i = 0; i < channel->mNumRotationKeys; i++ ) + channel->mRotationKeys[ i ].mTime -= start_time_fps; + for ( uint32_t i = 0; i < channel->mNumScalingKeys; i++ ) + channel->mScalingKeys[ i ].mTime -= start_time_fps; } // for some mysterious reason, mDuration is simply the maximum key -- the // validator always assumes animations to start at zero. - anim->mDuration = ( stop_timeF - start_timeF ) * anim_fps; + anim->mDuration = stop_time_fps - start_time_fps; anim->mTicksPerSecond = anim_fps; } From 80489963a15de3eea59810dbdbdeabdd6c103501 Mon Sep 17 00:00:00 2001 From: Tammo Hinrichs Date: Thu, 24 Aug 2017 17:18:54 +0200 Subject: [PATCH 2/4] FBX importer: don't rely ont INT64_MIN / ..MAX macros --- code/FBXConverter.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index ae98d24fd..bbf0e4e11 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -2371,9 +2371,9 @@ void Converter::ConvertAnimationStack( const AnimationStack& st ) bool has_local_startstop = start_time != 0 || stop_time != 0; if ( !has_local_startstop ) { // no time range given, so accept every keyframe and use the actual min/max time - // the +/- 20000 is a safety because GenerateNodeAnimations uses an epsilon of 10000 - start_time = INT64_MIN + 20000; - stop_time = INT64_MAX - 20000; + // the numbers are INT64_MIN/MAX, the 20000 is for safety because GenerateNodeAnimations uses an epsilon of 10000 + start_time = -9223372036854775807i64 + 20000; + stop_time = 9223372036854775807i64 - 20000; } try { From 9a12b6ef0bbff90a69030a2cfa7a8b8756b904b5 Mon Sep 17 00:00:00 2001 From: Tammo Hinrichs Date: Fri, 25 Aug 2017 11:17:07 +0200 Subject: [PATCH 3/4] FBX importer: Back to INT64_MIN but include also. --- code/FBXConverter.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index bbf0e4e11..d6b21daed 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -61,6 +61,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include + namespace Assimp { namespace FBX { @@ -2371,9 +2373,9 @@ void Converter::ConvertAnimationStack( const AnimationStack& st ) bool has_local_startstop = start_time != 0 || stop_time != 0; if ( !has_local_startstop ) { // no time range given, so accept every keyframe and use the actual min/max time - // the numbers are INT64_MIN/MAX, the 20000 is for safety because GenerateNodeAnimations uses an epsilon of 10000 - start_time = -9223372036854775807i64 + 20000; - stop_time = 9223372036854775807i64 - 20000; + // the 20000 is for safety because GenerateNodeAnimations uses an epsilon of 10000 + start_time = INT64_MIN + 20000; + stop_time = INT64_MAX - 20000; } try { From 12a28d33ce205c9ed61fa14e5687e679f820d6e4 Mon Sep 17 00:00:00 2001 From: Tammo Hinrichs Date: Fri, 25 Aug 2017 12:14:03 +0200 Subject: [PATCH 4/4] FBX importer: try a constant again (ll suffix this time) --- code/FBXConverter.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index d6b21daed..f53ae0218 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -61,8 +61,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include - namespace Assimp { namespace FBX { @@ -2373,9 +2371,9 @@ void Converter::ConvertAnimationStack( const AnimationStack& st ) bool has_local_startstop = start_time != 0 || stop_time != 0; if ( !has_local_startstop ) { // no time range given, so accept every keyframe and use the actual min/max time - // the 20000 is for safety because GenerateNodeAnimations uses an epsilon of 10000 - start_time = INT64_MIN + 20000; - stop_time = INT64_MAX - 20000; + // the numbers are INT64_MIN/MAX, the 20000 is for safety because GenerateNodeAnimations uses an epsilon of 10000 + start_time = -9223372036854775807ll + 20000; + stop_time = 9223372036854775807ll - 20000; } try {