Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale keys export with PSA (SCALEKEYS chunk) #44

Merged
merged 1 commit into from
May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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