MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / OptimizeCurve

Function OptimizeCurve

Source/Engine/Tools/ModelTool/ModelTool.cpp:895–941  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

893
894template<typename T>
895void 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
943void* MeshOptAllocate(size_t size)
944{

Callers 1

ImportModelMethod · 0.85

Calls 8

NearEqualFunction · 0.50
GetKeyframesMethod · 0.45
CountMethod · 0.45
LastMethod · 0.45
AddMethod · 0.45
RemoveAtMethod · 0.45
GetDefaultValueMethod · 0.45
SetKeyframesMethod · 0.45

Tested by

no test coverage detected