Small animation performance improvements

This commit is contained in:
Jeremy Pritts 2023-06-06 21:25:02 -04:00
parent ccbaa530c8
commit 1278cc664d
3 changed files with 21 additions and 49 deletions

View File

@ -71,9 +71,9 @@ namespace AssetRipper.Processing.AnimationClips
private void ProcessStreams(IReadOnlyList<StreamedFrame> streamFrames, IAnimationClipBindingConstant bindings, IReadOnlyDictionary<uint, string> tos, float sampleRate)
{
float[] curveValues = new float[4];
float[] inSlopeValues = new float[4];
float[] outSlopeValues = new float[4];
Span<float> curveValues = stackalloc float[4] { 0, 0, 0, 0 };
Span<float> inSlopeValues = stackalloc float[4] { 0, 0, 0, 0 };
Span<float> outSlopeValues = stackalloc float[4] { 0, 0, 0, 0 };
float interval = 1.0f / sampleRate;
// first (index [0]) stream frame is for slope calculation for the first real frame (index [1])
@ -114,7 +114,11 @@ namespace AssetRipper.Processing.AnimationClips
}
else if (binding.CustomType == (byte)BindingCustomType.None)
{
if (frameIndex0) { curveIndex = GetNextCurve(frame, curveIndex); continue; }
if (frameIndex0)
{
curveIndex = GetNextCurve(frame, curveIndex);
continue;
}
AddDefaultCurve(binding, path, frame.Time, frame.Curves[curveIndex].Value);
curveIndex = GetNextCurve(frame, curveIndex);
}
@ -135,7 +139,7 @@ namespace AssetRipper.Processing.AnimationClips
{
DenseClip dense = clip.DenseClip;
int streamCount = (int)clip.StreamedClip.CurveCount;
float[] slopeValues = new float[4]; // no slopes - 0 values
ReadOnlySpan<float> slopeValues = stackalloc float[4] { 0, 0, 0, 0 }; // no slopes - 0 values
for (int frameIndex = 0; frameIndex < dense.FrameCount; frameIndex++)
{
float time = frameIndex / dense.SampleRate;
@ -169,7 +173,7 @@ namespace AssetRipper.Processing.AnimationClips
{
int streamCount = (int)clip.StreamedClip.CurveCount;
int denseCount = (int)clip.DenseClip.CurveCount;
float[] slopeValues = new float[4]; // no slopes - 0 values
ReadOnlySpan<float> slopeValues = stackalloc float[4] { 0, 0, 0, 0 }; // no slopes - 0 values
// only first and last frames
float time = 0.0f;
@ -233,8 +237,8 @@ namespace AssetRipper.Processing.AnimationClips
}
}
private void AddTransformCurve(float time, TransformType transType, IReadOnlyList<float> curveValues,
IReadOnlyList<float> inSlopeValues, IReadOnlyList<float> outSlopeValues, int offset, string path)
private void AddTransformCurve(float time, TransformType transType, ReadOnlySpan<float> curveValues,
ReadOnlySpan<float> inSlopeValues, ReadOnlySpan<float> outSlopeValues, int offset, string path)
{
switch (transType)
{

View File

@ -1,5 +1,5 @@
using AssetRipper.SourceGenerated.Subclasses.BlendTreeNodeConstant;
using AssetRipper.SourceGenerated.Subclasses.Vector2f;
using System.Numerics;
using BlendTreeType = AssetRipper.SourceGenerated.Enums.BlendTreeType_1;
namespace AssetRipper.SourceGenerated.Extensions
@ -22,13 +22,13 @@ namespace AssetRipper.SourceGenerated.Extensions
return 0.0f;
}
public static Vector2f GetPosition(this IBlendTreeNodeConstant constant, int index)
public static Vector2 GetPosition(this IBlendTreeNodeConstant constant, int index)
{
if (constant.Has_Blend2dData() && constant.GetBlendType() != BlendTreeType.Simple1D && constant.GetBlendType() != BlendTreeType.Direct)
{
return constant.Blend2dData.Data.ChildPositionArray[index];
}
return new();
return default;
}
public static float GetMinThreshold(this IBlendTreeNodeConstant constant)

View File

@ -1,5 +1,10 @@
namespace AssetRipper.SourceGenerated.Extensions.Enums.AnimationClip.GenericBinding
using AssetRipper.SourceGenerated.NativeEnums.Global;
namespace AssetRipper.SourceGenerated.Extensions.Enums.AnimationClip.GenericBinding
{
/// <summary>
/// Based on <see cref="BindType"/>
/// </summary>
public enum BindingCustomType : byte
{
None = 0,
@ -30,40 +35,3 @@
MeshFilter = 41,
}
}
/*BindType
kUnbound 0x0
kBindTransformPosition 0x1
kBindTransformRotation 0x2
kBindTransformScale 0x3
kBindTransformEuler 0x4
kMinSinglePropertyBinding 0x5
kBindFloat 0x5
kBindFloatToBool 0x6
kBindGameObjectActive 0x7
kBindMuscle 0x8
kBindScriptObjectReference 0x9
kBindFloatToInt 0xa
kBindDiscreteInt 0xb
kBlendShapeWeightBinding 0x14
kRendererMaterialPPtrBinding 0x15
kRendererMaterialPropertyBinding 0x16
kSpriteRendererPPtrBinding 0x17
kMonoBehaviourPropertyBinding 0x18
kLightPropertyBinding 0x19
kRendererOtherPropertyBinding 0x1a
kParticleSystemPropertyBindings 0x1b
kRectTransformPropertyBindings 0x1c
kLineRendererPropertyBindings 0x1d
kTrailRendererPropertyBindings 0x1e
kPositionConstraintPropertyBindings 0x1f
kRotationConstraintPropertyBindings 0x20
kScaleConstraintPropertyBindings 0x21
kAimConstraintPropertyBindings 0x22
kParentConstraintPropertyBindings 0x23
kLookAtConstraintPropertyBindings 0x24
kCameraPropertyBindings 0x25
kVisualEffectPropertyBindings 0x26
kParticleForceFieldPropertyBinding 0x27
kUserDefinedBinding 0x28
kMeshFilterBinding 0x29
kAllBindingCount 0x2a */