Skip to content

Commit

Permalink
SCALEKEYS chunk for PSA
Browse files Browse the repository at this point in the history
  • Loading branch information
floxay committed Apr 30, 2022
1 parent d794697 commit 74842bd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
34 changes: 31 additions & 3 deletions CUE4Parse-Conversion/Animations/AnimExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void DoExportPsa(CAnimSet anim, int seqIdx)
framesCount += sequence.NumFrames;
}

var requireConfig = false;
var requireConfig = false; // TODO

int keysCount = framesCount * numBones;
keyHdr.DataCount = keysCount;
Expand Down Expand Up @@ -174,9 +174,37 @@ private void DoExportPsa(CAnimSet anim, int seqIdx)
// importer will always read "SCALEKEYS" chunk.
if (Constants.PSA_VERSION >= 20090127)
{
scaleKeysHdr.DataCount = 0;
scaleKeysHdr.DataSize = 16; // sizeof(VScaleAnimKey) = FVector + float
keysCount = framesCount * numBones;
scaleKeysHdr.DataCount = keysCount;
scaleKeysHdr.DataSize = Constants.VScaleAnimKey_SIZE;
Ar.SerializeChunkHeader(scaleKeysHdr, "SCALEKEYS");
for (i = 0; i < numAnims; i++)
{
var sequence = anim.Sequences[i];
for (int frame = 0; frame < sequence.NumFrames; frame++)
{
for (int boneIndex = 0; boneIndex < numBones; boneIndex++)
{
var boneScale = FVector.OneVector;

if (frame < sequence.Tracks[boneIndex].KeyScale.Length)
boneScale = sequence.Tracks[boneIndex].KeyScale[frame];

var key = new VScaleAnimKey
{
ScaleVector = boneScale,
Time = 1
};
key.Serialize(Ar);
keysCount--;

// check for user error
if (sequence.Tracks[boneIndex].KeyScale.Length == 0)
requireConfig = true;
}
}
}
Trace.Assert(keysCount == 0);
}

// psa file is done
Expand Down
17 changes: 17 additions & 0 deletions CUE4Parse-Conversion/Animations/PSA/VScaleAnimKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using CUE4Parse.UE4.Objects.Core.Math;
using CUE4Parse.UE4.Writers;

namespace CUE4Parse_Conversion.Animations.PSA
{
public class VScaleAnimKey
{
public FVector ScaleVector;
public float Time;

public void Serialize(FArchiveWriter Ar)
{
ScaleVector.Serialize(Ar);
Ar.Write(Time);
}
}
}
1 change: 1 addition & 0 deletions CUE4Parse-Conversion/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Constants
public const int VJointPosPsk_SIZE = 4 * 4 + 3 * 4 + 4 + 3 * 4;
public const int FNamedBoneBinary_SIZE = 64 + 3 * 4 + VJointPosPsk_SIZE;
public const int VQuatAnimKey_SIZE = 3 * 4 + 4 * 4 + 4;
public const int VScaleAnimKey_SIZE = 3 * 4 + 4;

public const int DXT_BITS_PER_PIXEL = 4;

Expand Down

1 comment on commit 74842bd

@Tectors
Copy link
Contributor

@Tectors Tectors commented on 74842bd May 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include this in curves

Please sign in to comment.