Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
IKT: big update for IK 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
knah committed May 29, 2022
1 parent 68440e0 commit 583b4e2
Show file tree
Hide file tree
Showing 18 changed files with 1,036 additions and 1,892 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ jobs:
token: ${{ secrets.LibsRepositoryToken }}
path: Libs

- name: Checkout IKTweaks/FinalIK
uses: actions/checkout@v2
with:
repository: knah/IKTweaks-FinalIK
token: ${{ secrets.IKTRepositoryToken }}
path: IKTweaks/FinalIK

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
Expand Down
106 changes: 106 additions & 0 deletions IKTweaks/AnimationsHandler.cs
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();
}
}
26 changes: 0 additions & 26 deletions IKTweaks/BundleHolder.cs

This file was deleted.

26 changes: 26 additions & 0 deletions IKTweaks/CachedSolver.cs
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;
}
}
}
Loading

0 comments on commit 583b4e2

Please sign in to comment.