Skip to content

Commit bd55063

Browse files
authored
Merge pull request #259 from Earu/studio/maxframe-and-model-keyvalues
Add Studio_MaxFrame and model keyvalue text
2 parents 0c2aa5f + 10d3e10 commit bd55063

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎Source.Common/BoneSetup.cs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,26 @@ private void AddSequenceLayers(Span<Vector3> pos, Span<Quaternion> q, MStudioSeq
14331433
}
14341434
}
14351435

1436+
public static int Studio_MaxFrame(StudioHdr studioHdr, int sequence, ReadOnlySpan<float> poseParameter) {
1437+
MStudioAnimDesc[] panim = ArrayPool<MStudioAnimDesc>.Shared.Rent(4);
1438+
Span<float> weight = stackalloc float[4];
1439+
1440+
MStudioSeqDesc seqdesc = studioHdr.Seqdesc(sequence);
1441+
Studio_SeqAnims(studioHdr, seqdesc, sequence, poseParameter, panim, weight);
1442+
1443+
float maxFrame = 0;
1444+
for (int i = 0; i < 4; i++) {
1445+
if (weight[i] > 0)
1446+
maxFrame += panim[i].NumFrames * weight[i];
1447+
}
1448+
ArrayPool<MStudioAnimDesc>.Shared.Return(panim);
1449+
1450+
if (maxFrame > 1)
1451+
maxFrame -= 1;
1452+
1453+
return (int)(maxFrame + 0.01);
1454+
}
1455+
14361456
public static double Studio_Duration(StudioHdr studioHdr, int sequence, ReadOnlySpan<float> poseParameter) {
14371457
MStudioSeqDesc seqdesc = studioHdr.Seqdesc(sequence);
14381458
float cps = Studio_CPS(studioHdr, seqdesc, sequence, poseParameter);

‎Source.Common/Studio.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3113,6 +3113,8 @@ public MStudioPoseParamDesc LocalPoseParameter(int i)
31133113
public string SurfaceProp() => Studio.ProduceASCIIString(ref surfacePropCache, Data.Span[SurfacePropIndex..]);
31143114
public int KeyValueIndex;
31153115
public int KeyValueSize;
3116+
string? keyValueTextCache;
3117+
public string? KeyValueText() => KeyValueSize != 0 ? Studio.ProduceASCIIString(ref keyValueTextCache, Data.Span.Slice(KeyValueIndex, KeyValueSize)) : null;
31163118

31173119
public int NumLocalIKAutoplayLocks;
31183120
public int LocalIKAutoplayLockIndex;

‎Source.Engine/ModelInfo.cs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,14 @@ public bool IsModelVertexLit(Model? model) {
292292
}
293293

294294
public ReadOnlySpan<char> GetModelKeyValueText(Model? model) {
295-
throw new NotImplementedException();
295+
if (model == null || model.Type != ModelType.Studio)
296+
return null;
297+
298+
StudioHeader? studioHdr = mdlCache.GetStudioHdr(model.Studio);
299+
if (studioHdr == null)
300+
return null;
301+
302+
return studioHdr.KeyValueText();
296303
}
297304

298305
public float GetModelRadius(Model? model) => model?.Radius ?? 0;

0 commit comments

Comments
 (0)