From 55b34e05b3d735a84e1af9833e19c0b816c18252 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 30 Jun 2015 11:28:43 -0300 Subject: -some changes by okam --- scene/resources/animation.cpp | 16 +++++++++++++--- scene/resources/animation.h | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'scene') diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 9d668a5716..afd4dc5304 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -1718,7 +1718,7 @@ void Animation::clear() { -bool Animation::_transform_track_optimize_key(const TKey &t0,const TKey &t1, const TKey &t2, float p_alowed_linear_err,float p_alowed_angular_err,float p_max_optimizable_angle) { +bool Animation::_transform_track_optimize_key(const TKey &t0,const TKey &t1, const TKey &t2, float p_alowed_linear_err,float p_alowed_angular_err,float p_max_optimizable_angle,const Vector3& p_norm) { real_t c = (t1.time-t0.time)/(t2.time-t0.time); @@ -1754,6 +1754,9 @@ bool Animation::_transform_track_optimize_key(const TKey &t0,const return false; //beyond allowed error for colinearity } + if (p_norm!=Vector3() && Math::acos(pd.normalized().dot(p_norm))>p_alowed_angular_err) + return false; + t[0] = (d1-d0)/(d2-d0); } } @@ -1905,16 +1908,21 @@ void Animation::_transform_track_optimize(int p_idx,float p_alowed_linear_err,fl bool prev_erased=false; TKey first_erased; + Vector3 norm; + for(int i=1;itransforms.size()-1;i++) { TKey &t0 = tt->transforms[i-1]; TKey &t1 = tt->transforms[i]; TKey &t2 = tt->transforms[i+1]; - bool erase = _transform_track_optimize_key(t0,t1,t2,p_alowed_linear_err,p_alowed_angular_err,p_max_optimizable_angle); + bool erase = _transform_track_optimize_key(t0,t1,t2,p_alowed_linear_err,p_alowed_angular_err,p_max_optimizable_angle,norm); + if (erase && !prev_erased) { + norm=(t2.value.loc-t1.value.loc).normalized(); + } - if (prev_erased && !_transform_track_optimize_key(t0,first_erased,t2,p_alowed_linear_err,p_alowed_angular_err,p_max_optimizable_angle)) { + if (prev_erased && !_transform_track_optimize_key(t0,first_erased,t2,p_alowed_linear_err,p_alowed_angular_err,p_max_optimizable_angle,norm)) { //avoid error to go beyond first erased key erase=false; } @@ -1932,9 +1940,11 @@ void Animation::_transform_track_optimize(int p_idx,float p_alowed_linear_err,fl } else { prev_erased=false; + norm=Vector3(); } + // print_line(itos(i)+" could be eliminated: "+rtos(tr)); //} } diff --git a/scene/resources/animation.h b/scene/resources/animation.h index d4042646fb..256826a4bb 100644 --- a/scene/resources/animation.h +++ b/scene/resources/animation.h @@ -204,7 +204,7 @@ private: return idxr; } - bool _transform_track_optimize_key(const TKey &t0,const TKey &t1, const TKey &t2, float p_alowed_linear_err,float p_alowed_angular_err,float p_max_optimizable_angle); + bool _transform_track_optimize_key(const TKey &t0,const TKey &t1, const TKey &t2, float p_alowed_linear_err,float p_alowed_angular_err,float p_max_optimizable_angle,const Vector3& p_norm); void _transform_track_optimize(int p_idx, float p_allowed_err=0.05, float p_alowed_angular_err=0.01,float p_max_optimizable_angle=Math_PI*0.125); protected: -- cgit v1.2.3