| 893 | |
| 894 | template<typename T> |
| 895 | void OptimizeCurve(LinearCurve<T>& curve) |
| 896 | { |
| 897 | auto& oldKeyframes = curve.GetKeyframes(); |
| 898 | const int32 keyCount = oldKeyframes.Count(); |
| 899 | typename LinearCurve<T>::KeyFrameCollection newKeyframes(keyCount); |
| 900 | bool lastWasEqual = false; |
| 901 | |
| 902 | for (int32 i = 0; i < keyCount; i++) |
| 903 | { |
| 904 | bool isEqual = false; |
| 905 | const auto& curKey = oldKeyframes[i]; |
| 906 | if (i > 0) |
| 907 | { |
| 908 | const auto& prevKey = newKeyframes.Last(); |
| 909 | isEqual = Math::NearEqual(prevKey.Value, curKey.Value); |
| 910 | } |
| 911 | |
| 912 | // More than two keys in a row are equal, remove the middle key by replacing it with this one |
| 913 | if (lastWasEqual && isEqual) |
| 914 | { |
| 915 | auto& prevKey = newKeyframes.Last(); |
| 916 | prevKey = curKey; |
| 917 | continue; |
| 918 | } |
| 919 | |
| 920 | newKeyframes.Add(curKey); |
| 921 | lastWasEqual = isEqual; |
| 922 | } |
| 923 | |
| 924 | // Special case if animation has only two the same keyframes after cleaning |
| 925 | if (newKeyframes.Count() == 2 && Math::NearEqual(newKeyframes[0].Value, newKeyframes[1].Value)) |
| 926 | { |
| 927 | newKeyframes.RemoveAt(1); |
| 928 | } |
| 929 | |
| 930 | // Special case if animation has only one identity keyframe (does not introduce any animation) |
| 931 | if (newKeyframes.Count() == 1 && Math::NearEqual(newKeyframes[0].Value, curve.GetDefaultValue())) |
| 932 | { |
| 933 | newKeyframes.RemoveAt(0); |
| 934 | } |
| 935 | |
| 936 | // Update keyframes if size changed |
| 937 | if (keyCount != newKeyframes.Count()) |
| 938 | { |
| 939 | curve.SetKeyframes(newKeyframes); |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | void* MeshOptAllocate(size_t size) |
| 944 | { |
no test coverage detected