diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/resources/animation.cpp | 16 | ||||
-rw-r--r-- | scene/resources/animation.h | 2 |
2 files changed, 14 insertions, 4 deletions
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<TransformKey> &t0,const TKey<TransformKey> &t1, const TKey<TransformKey> &t2, float p_alowed_linear_err,float p_alowed_angular_err,float p_max_optimizable_angle) { +bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0,const TKey<TransformKey> &t1, const TKey<TransformKey> &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<TransformKey> &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<TransformKey> first_erased; + Vector3 norm; + for(int i=1;i<tt->transforms.size()-1;i++) { TKey<TransformKey> &t0 = tt->transforms[i-1]; TKey<TransformKey> &t1 = tt->transforms[i]; TKey<TransformKey> &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<TransformKey> &t0,const TKey<TransformKey> &t1, const TKey<TransformKey> &t2, float p_alowed_linear_err,float p_alowed_angular_err,float p_max_optimizable_angle); + bool _transform_track_optimize_key(const TKey<TransformKey> &t0,const TKey<TransformKey> &t1, const TKey<TransformKey> &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: |