mirror of
https://github.com/4sval/FModel.git
synced 2026-04-14 05:26:42 -05:00
keep bones in rest pos if there's no track for them
This commit is contained in:
parent
3f6e46ef82
commit
a5cbc5b9f5
|
|
@ -145,7 +145,7 @@
|
|||
<PackageReference Include="NVorbis" Version="0.10.5" />
|
||||
<PackageReference Include="Oodle.NET" Version="1.0.1" />
|
||||
<PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.1" />
|
||||
<PackageReference Include="OpenTK" Version="4.7.5" />
|
||||
<PackageReference Include="OpenTK" Version="4.7.7" />
|
||||
<PackageReference Include="RestSharp" Version="108.0.3" />
|
||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
|
|
|
|||
|
|
@ -88,19 +88,24 @@ public class CUE4ParseViewModel : ViewModel
|
|||
{
|
||||
get
|
||||
{
|
||||
if (_snooper != null) return _snooper;
|
||||
|
||||
return Application.Current.Dispatcher.Invoke(delegate
|
||||
{
|
||||
return _snooper ??= new Snooper(
|
||||
new GameWindowSettings { RenderFrequency = Snooper.GetMaxRefreshFrequency() },
|
||||
var scale = ImGuiController.GetDpiScale();
|
||||
var htz = Snooper.GetMaxRefreshFrequency();
|
||||
return _snooper = new Snooper(
|
||||
new GameWindowSettings { RenderFrequency = htz, UpdateFrequency = htz },
|
||||
new NativeWindowSettings
|
||||
{
|
||||
Size = new OpenTK.Mathematics.Vector2i(
|
||||
Convert.ToInt32(SystemParameters.MaximizedPrimaryScreenWidth * .75 * ImGuiController.GetDpiScale()),
|
||||
Convert.ToInt32(SystemParameters.MaximizedPrimaryScreenHeight * .85 * ImGuiController.GetDpiScale())),
|
||||
Convert.ToInt32(SystemParameters.MaximizedPrimaryScreenWidth * .75 * scale),
|
||||
Convert.ToInt32(SystemParameters.MaximizedPrimaryScreenHeight * .85 * scale)),
|
||||
NumberOfSamples = Constants.SAMPLES_COUNT,
|
||||
WindowBorder = WindowBorder.Resizable,
|
||||
Flags = ContextFlags.ForwardCompatible,
|
||||
Profile = ContextProfile.Core,
|
||||
Vsync = VSyncMode.Adaptive,
|
||||
APIVersion = new Version(4, 6),
|
||||
StartVisible = false,
|
||||
StartFocused = false,
|
||||
|
|
|
|||
|
|
@ -142,10 +142,6 @@ public class Animation : IDisposable
|
|||
}
|
||||
}
|
||||
ImGui.EndMenu();
|
||||
}
|
||||
if (ImGui.MenuItem("Additive", false))
|
||||
{
|
||||
|
||||
}
|
||||
if (ImGui.MenuItem("Save"))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,8 +7,13 @@ public class BoneIndice
|
|||
public string LoweredParentBoneName;
|
||||
public bool IsRoot => BoneIndex == 0 && ParentBoneIndex == -1 && string.IsNullOrEmpty(LoweredParentBoneName);
|
||||
|
||||
public int TrackIndex = -1;
|
||||
public int ParentTrackIndex = -1; // bone index of the first tracked parent bone
|
||||
public bool HasTrack => TrackIndex > -1;
|
||||
public bool HasParentTrack => ParentTrackIndex > -1;
|
||||
public int TrackedBoneIndex = -1;
|
||||
public int TrackedParentBoneIndex = -1; // bone index of the first tracked parent bone
|
||||
public bool IsTracked => TrackedBoneIndex > -1;
|
||||
public bool IsParentTracked => TrackedParentBoneIndex > -1;
|
||||
|
||||
public bool IsNative => BoneIndex == TrackedBoneIndex;
|
||||
public bool IsParentNative => ParentBoneIndex == TrackedParentBoneIndex; // always true?
|
||||
|
||||
public override string ToString() => $"Mesh Ref '{BoneIndex}' is Skel Ref '{TrackedBoneIndex}' ({IsNative}, {IsParentNative})";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,36 +88,36 @@ public class Skeleton : IDisposable
|
|||
var originalTransform = BonesTransformByIndex[boneIndices.BoneIndex];
|
||||
_animatedBonesTransform[s][boneIndices.BoneIndex] = new Transform[sequence.NumFrames];
|
||||
|
||||
if (!boneIndices.HasTrack)
|
||||
var trackedBoneIndex = boneIndices.TrackedBoneIndex;
|
||||
if (sequence.OriginalSequence.FindTrackForBoneIndex(trackedBoneIndex) < 0)
|
||||
{
|
||||
for (int frame = 0; frame < _animatedBonesTransform[s][boneIndices.BoneIndex].Length; frame++)
|
||||
{
|
||||
_animatedBonesTransform[s][boneIndices.BoneIndex][frame] = new Transform
|
||||
{
|
||||
Relation = boneIndices.HasParentTrack ?
|
||||
originalTransform.LocalMatrix * _animatedBonesTransform[s][boneIndices.ParentTrackIndex][frame].Matrix :
|
||||
Relation = boneIndices.IsParentTracked ?
|
||||
originalTransform.LocalMatrix * _animatedBonesTransform[s][boneIndices.TrackedParentBoneIndex][frame].Matrix :
|
||||
originalTransform.Relation
|
||||
};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var trackIndex = boneIndices.TrackIndex;
|
||||
for (int frame = 0; frame < _animatedBonesTransform[s][boneIndices.BoneIndex].Length; frame++)
|
||||
{
|
||||
var boneOrientation = originalTransform.Rotation;
|
||||
var bonePosition = originalTransform.Position;
|
||||
var boneScale = originalTransform.Scale;
|
||||
|
||||
sequence.Tracks[trackIndex].GetBonePosition(frame, sequence.NumFrames, false, ref bonePosition, ref boneOrientation);
|
||||
if (frame < sequence.Tracks[trackIndex].KeyScale.Length)
|
||||
boneScale = sequence.Tracks[trackIndex].KeyScale[frame];
|
||||
sequence.Tracks[trackedBoneIndex].GetBonePosition(frame, sequence.NumFrames, false, ref bonePosition, ref boneOrientation);
|
||||
if (frame < sequence.Tracks[trackedBoneIndex].KeyScale.Length)
|
||||
boneScale = sequence.Tracks[trackedBoneIndex].KeyScale[frame];
|
||||
|
||||
switch (anim.BoneModes[trackIndex])
|
||||
switch (anim.BoneModes[trackedBoneIndex])
|
||||
{
|
||||
case EBoneTranslationRetargetingMode.Skeleton when !rotationOnly:
|
||||
{
|
||||
var targetTransform = sequence.RetargetBasePose?[trackIndex] ?? anim.BonePositions[trackIndex];
|
||||
var targetTransform = sequence.RetargetBasePose?[trackedBoneIndex] ?? anim.BonePositions[trackedBoneIndex];
|
||||
bonePosition = targetTransform.Translation;
|
||||
break;
|
||||
}
|
||||
|
|
@ -126,7 +126,7 @@ public class Skeleton : IDisposable
|
|||
var sourceTranslationLength = (originalTransform.Position / Constants.SCALE_DOWN_RATIO).Size();
|
||||
if (sourceTranslationLength > UnrealMath.KindaSmallNumber)
|
||||
{
|
||||
var targetTranslationLength = sequence.RetargetBasePose?[trackIndex].Translation.Size() ?? anim.BonePositions[trackIndex].Translation.Size();
|
||||
var targetTranslationLength = sequence.RetargetBasePose?[trackedBoneIndex].Translation.Size() ?? anim.BonePositions[trackedBoneIndex].Translation.Size();
|
||||
bonePosition.Scale(targetTranslationLength / sourceTranslationLength);
|
||||
}
|
||||
break;
|
||||
|
|
@ -135,7 +135,7 @@ public class Skeleton : IDisposable
|
|||
{
|
||||
// can't tell if it's working or not
|
||||
var sourceSkelTrans = originalTransform.Position / Constants.SCALE_DOWN_RATIO;
|
||||
var refPoseTransform = sequence.RetargetBasePose?[trackIndex] ?? anim.BonePositions[trackIndex];
|
||||
var refPoseTransform = sequence.RetargetBasePose?[trackedBoneIndex] ?? anim.BonePositions[trackedBoneIndex];
|
||||
|
||||
boneOrientation = boneOrientation * FQuat.Conjugate(originalTransform.Rotation) * refPoseTransform.Rotation;
|
||||
bonePosition += refPoseTransform.Translation - sourceSkelTrans;
|
||||
|
|
@ -146,7 +146,7 @@ public class Skeleton : IDisposable
|
|||
case EBoneTranslationRetargetingMode.OrientAndScale when !rotationOnly:
|
||||
{
|
||||
var sourceSkelTrans = originalTransform.Position / Constants.SCALE_DOWN_RATIO;
|
||||
var targetSkelTrans = sequence.RetargetBasePose?[trackIndex].Translation ?? anim.BonePositions[trackIndex].Translation;
|
||||
var targetSkelTrans = sequence.RetargetBasePose?[trackedBoneIndex].Translation ?? anim.BonePositions[trackedBoneIndex].Translation;
|
||||
|
||||
if (!sourceSkelTrans.Equals(targetSkelTrans))
|
||||
{
|
||||
|
|
@ -167,12 +167,12 @@ public class Skeleton : IDisposable
|
|||
}
|
||||
|
||||
// revert FixRotationKeys
|
||||
if (trackIndex > 0) boneOrientation.Conjugate();
|
||||
if (trackedBoneIndex > 0) boneOrientation.Conjugate();
|
||||
bonePosition *= Constants.SCALE_DOWN_RATIO;
|
||||
|
||||
_animatedBonesTransform[s][boneIndices.BoneIndex][frame] = new Transform
|
||||
{
|
||||
Relation = boneIndices.HasParentTrack ? _animatedBonesTransform[s][boneIndices.ParentTrackIndex][frame].Matrix : originalTransform.Relation,
|
||||
Relation = boneIndices.IsParentTracked ? _animatedBonesTransform[s][boneIndices.TrackedParentBoneIndex][frame].Matrix : originalTransform.Relation,
|
||||
Rotation = boneOrientation,
|
||||
Position = rotationOnly ? originalTransform.Position : bonePosition,
|
||||
Scale = sequence.bAdditive ? FVector.OneVector : boneScale
|
||||
|
|
@ -194,7 +194,7 @@ public class Skeleton : IDisposable
|
|||
if (!BonesIndicesByLoweredName.TryGetValue(info.Name.Text.ToLower(), out var boneIndices))
|
||||
continue;
|
||||
|
||||
boneIndices.TrackIndex = trackIndex;
|
||||
boneIndices.TrackedBoneIndex = trackIndex;
|
||||
var parentTrackIndex = info.ParentIndex;
|
||||
|
||||
do
|
||||
|
|
@ -202,16 +202,16 @@ public class Skeleton : IDisposable
|
|||
if (parentTrackIndex < 0) break;
|
||||
info = anim.TrackBonesInfo[parentTrackIndex];
|
||||
if (boneIndices.LoweredParentBoneName.Equals(info.Name.Text, StringComparison.OrdinalIgnoreCase) && // same parent (name based)
|
||||
BonesIndicesByLoweredName.TryGetValue(info.Name.Text.ToLower(), out var parentBoneIndices) && parentBoneIndices.HasTrack)
|
||||
boneIndices.ParentTrackIndex = parentBoneIndices.BoneIndex;
|
||||
BonesIndicesByLoweredName.TryGetValue(info.Name.Text.ToLower(), out var parentBoneIndices) && parentBoneIndices.IsTracked)
|
||||
boneIndices.TrackedParentBoneIndex = parentBoneIndices.BoneIndex;
|
||||
else parentTrackIndex = info.ParentIndex;
|
||||
} while (!boneIndices.HasParentTrack);
|
||||
} while (!boneIndices.IsParentTracked);
|
||||
}
|
||||
|
||||
// fix parent of untracked bones
|
||||
foreach ((var boneName, var boneIndices) in BonesIndicesByLoweredName)
|
||||
{
|
||||
if (boneIndices.IsRoot || boneIndices.HasTrack && boneIndices.HasParentTrack) // assuming root bone always has a track
|
||||
if (boneIndices.IsRoot || boneIndices.IsTracked && boneIndices.IsParentTracked) // assuming root bone always has a track
|
||||
continue;
|
||||
|
||||
#if DEBUG
|
||||
|
|
@ -222,9 +222,9 @@ public class Skeleton : IDisposable
|
|||
do
|
||||
{
|
||||
var parentBoneIndices = BonesIndicesByLoweredName[loweredParentBoneName];
|
||||
if (parentBoneIndices.HasParentTrack || parentBoneIndices.IsRoot) boneIndices.ParentTrackIndex = parentBoneIndices.BoneIndex;
|
||||
if (parentBoneIndices.IsParentTracked || parentBoneIndices.IsRoot) boneIndices.TrackedParentBoneIndex = parentBoneIndices.BoneIndex;
|
||||
else loweredParentBoneName = parentBoneIndices.LoweredParentBoneName;
|
||||
} while (!boneIndices.HasParentTrack);
|
||||
} while (!boneIndices.IsParentTracked);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -232,8 +232,8 @@ public class Skeleton : IDisposable
|
|||
{
|
||||
foreach (var boneIndices in BonesIndicesByLoweredName.Values)
|
||||
{
|
||||
boneIndices.TrackIndex = -1;
|
||||
boneIndices.ParentTrackIndex = -1;
|
||||
boneIndices.TrackedBoneIndex = -1;
|
||||
boneIndices.TrackedParentBoneIndex = -1;
|
||||
}
|
||||
|
||||
if (!full) return;
|
||||
|
|
|
|||
|
|
@ -156,7 +156,8 @@ public class Snooper : GameWindow
|
|||
if (!IsVisible || ImGui.GetIO().WantTextInput)
|
||||
return;
|
||||
|
||||
Renderer.CameraOp.Modify(KeyboardState, (float) e.Time);
|
||||
var delta = (float) e.Time;
|
||||
Renderer.CameraOp.Modify(KeyboardState, delta);
|
||||
|
||||
if (KeyboardState.IsKeyPressed(Keys.Space))
|
||||
Renderer.Options.Tracker.IsPaused = !Renderer.Options.Tracker.IsPaused;
|
||||
|
|
@ -233,7 +234,7 @@ public class Snooper : GameWindow
|
|||
public static int GetMaxRefreshFrequency()
|
||||
{
|
||||
var rf = 60;
|
||||
DEVMODE vDevMode = new DEVMODE();
|
||||
var vDevMode = new DEVMODE();
|
||||
var i = 0;
|
||||
while (EnumDisplaySettings(null, i, ref vDevMode))
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user