This repository has been archived by the owner on May 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,036 additions
and
1,892 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using System; | ||
using System.Linq; | ||
using UnhollowerBaseLib; | ||
using UnityEngine; | ||
|
||
namespace IKTweaks | ||
{ | ||
internal class AnimationsHandler | ||
{ | ||
private readonly Il2CppStructArray<float> myMuscles = new(HumanTrait.MuscleCount); | ||
private readonly HumanPoseHandler myPoseHandler; | ||
private readonly Transform myHips; | ||
private readonly CachedSolver mySolver; | ||
|
||
public AnimationsHandler(HumanPoseHandler poseHandler, Transform hips, in CachedSolver solver) | ||
{ | ||
myPoseHandler = poseHandler; | ||
myHips = hips; | ||
mySolver = solver; | ||
} | ||
|
||
internal void ResetBonePositions(bool onlySpine, bool hasLegTargets) | ||
{ | ||
if (mySolver.Solver.IKPositionWeight < 0.9f) return; | ||
|
||
myHips.get_position_Injected(out var hipPos); | ||
myHips.get_rotation_Injected(out var hipRot); | ||
|
||
myPoseHandler.GetHumanPose(out var bodyPos, out var bodyRot, myMuscles); | ||
|
||
for (var i = 0; i < myMuscles.Count; i++) | ||
{ | ||
var currentMask = ourBoneResetMasks[i]; | ||
if (onlySpine && currentMask != BoneResetMask.Spine) continue; | ||
if (!hasLegTargets && (currentMask == BoneResetMask.LeftLeg || currentMask == BoneResetMask.RightLeg)) continue; | ||
|
||
if (IkTweaksSettings.IgnoreAnimationsModeParsed == IgnoreAnimationsMode.All) | ||
{ | ||
myMuscles[i] *= currentMask == BoneResetMask.Never ? 1 : 0; | ||
continue; | ||
} | ||
|
||
switch (currentMask) | ||
{ | ||
case BoneResetMask.Never: | ||
break; | ||
case BoneResetMask.Spine: | ||
myMuscles[i] *= 1 - mySolver.Spine.pelvisPositionWeight; | ||
break; | ||
case BoneResetMask.LeftArm: | ||
myMuscles[i] *= 1 - mySolver.LeftArm.positionWeight; | ||
break; | ||
case BoneResetMask.RightArm: | ||
myMuscles[i] *= 1 - mySolver.RightArm.positionWeight; | ||
break; | ||
case BoneResetMask.LeftLeg: | ||
myMuscles[i] *= 1 - mySolver.LeftLeg.positionWeight; | ||
break; | ||
case BoneResetMask.RightLeg: | ||
myMuscles[i] *= 1 - mySolver.RightLeg.positionWeight; | ||
break; | ||
default: | ||
throw new ArgumentOutOfRangeException(); | ||
} | ||
} | ||
|
||
myPoseHandler.SetHumanPose(ref bodyPos, ref bodyRot, myMuscles); | ||
|
||
myHips.position = hipPos; | ||
myHips.rotation = hipRot; | ||
} | ||
|
||
|
||
private enum BoneResetMask | ||
{ | ||
Never, | ||
Spine, | ||
LeftArm, | ||
RightArm, | ||
LeftLeg, | ||
RightLeg, | ||
} | ||
|
||
private static readonly string[] ourNeverBones = { "Index", "Thumb", "Middle", "Ring", "Little", "Jaw", "Eye" }; | ||
private static readonly string[] ourArmBones = { "Arm", "Forearm", "Hand", "Shoulder" }; | ||
private static readonly string[] ourLegBones = { "Leg", "Foot", "Toes" }; | ||
|
||
private static BoneResetMask JudgeBone(string name) | ||
{ | ||
if (ourNeverBones.Any(name.Contains)) | ||
return BoneResetMask.Never; | ||
|
||
if (ourArmBones.Any(name.Contains)) | ||
{ | ||
return name.Contains("Left") ? BoneResetMask.LeftArm : BoneResetMask.RightArm; | ||
} | ||
|
||
if (ourLegBones.Any(name.Contains)) | ||
return name.Contains("Left") ? BoneResetMask.LeftLeg : BoneResetMask.RightLeg; | ||
|
||
return BoneResetMask.Spine; | ||
} | ||
|
||
private static readonly BoneResetMask[] ourBoneResetMasks = HumanTrait.MuscleName.Select(JudgeBone).ToArray(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using RootMotion.FinalIK; | ||
|
||
namespace IKTweaks | ||
{ | ||
public struct CachedSolver | ||
{ | ||
public readonly IKSolverVR Solver; | ||
public readonly IKSolverVR.Spine Spine; | ||
public readonly IKSolverVR.Leg LeftLeg; | ||
public readonly IKSolverVR.Leg RightLeg; | ||
public readonly IKSolverVR.Arm LeftArm; | ||
public readonly IKSolverVR.Arm RightArm; | ||
public readonly IKSolverVR.Locomotion Locomotion; | ||
|
||
public CachedSolver(IKSolverVR solver) | ||
{ | ||
Solver = solver; | ||
Spine = solver.spine; | ||
LeftArm = solver.leftArm; | ||
LeftLeg = solver.leftLeg; | ||
RightArm = solver.rightArm; | ||
RightLeg = solver.rightLeg; | ||
Locomotion = solver.locomotion; | ||
} | ||
} | ||
} |
Oops, something went wrong.