mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 22:39:22 +00:00
fucked
This commit is contained in:
parent
41068ce3fb
commit
b4fb9e62e6
5 changed files with 220 additions and 76 deletions
|
@ -13,27 +13,23 @@ public class DesktopVRIK : MonoBehaviour
|
|||
{
|
||||
public static DesktopVRIK Instance;
|
||||
|
||||
public static bool Setting_Enabled,
|
||||
public static bool
|
||||
Setting_Enabled,
|
||||
Setting_EnforceViewPosition,
|
||||
Setting_EmoteVRIK,
|
||||
Setting_EmoteLookAtIK;
|
||||
public static float Setting_EmulateVRChatHipMovementWeight;
|
||||
public static float Setting_HipThrustMultiplier = 0.1f;
|
||||
Setting_EmoteLookAtIK,
|
||||
Setting_Internal_PlantFeet = true;
|
||||
|
||||
public static float
|
||||
Setting_BodyLeanWeight = 0.3f,
|
||||
Setting_BodyAngleLimit = 45f;
|
||||
|
||||
public Transform viewpoint;
|
||||
public Vector3 initialCamPos;
|
||||
|
||||
Transform headIKTarget;
|
||||
Transform avatarHeadBone;
|
||||
public Vector3 eyeOffset;
|
||||
|
||||
void Start()
|
||||
{
|
||||
Instance = this;
|
||||
// create the shared Head IK Target
|
||||
headIKTarget = new GameObject("[DesktopVRIK] Head IK Target").transform;
|
||||
headIKTarget.parent = PlayerSetup.Instance.transform;
|
||||
headIKTarget.localPosition = new Vector3(0f, 1.8f, 0f);
|
||||
headIKTarget.localRotation = Quaternion.identity;
|
||||
}
|
||||
|
||||
public void ChangeViewpointHandling(bool enabled)
|
||||
|
@ -45,51 +41,30 @@ public class DesktopVRIK : MonoBehaviour
|
|||
PlayerSetup.Instance.desktopCamera.transform.localPosition = Vector3.zero;
|
||||
return;
|
||||
}
|
||||
PlayerSetup.Instance.desktopCamera.transform.localPosition = initialCamPos;
|
||||
PlayerSetup.Instance.desktopCamera.transform.localPosition = eyeOffset;
|
||||
}
|
||||
|
||||
public void AlternativeOnPreSolverUpdate()
|
||||
{
|
||||
//this order matters, rotation offset will be choppy if avatar is not cenetered first
|
||||
|
||||
if (headIKTarget != null && avatarHeadBone != null)
|
||||
{
|
||||
headIKTarget.position = new Vector3(headIKTarget.position.x, avatarHeadBone.position.y, headIKTarget.position.z);
|
||||
}
|
||||
//set IK offsets (this is a really fucking weird way to do this)
|
||||
DesktopVRIK_Helper.Instance?.OnUpdateVRIK();
|
||||
|
||||
//Reset avatar offset (VRIK will literally make you walk away from root otherwise)
|
||||
IKSystem.vrik.transform.localPosition = Vector3.zero;
|
||||
IKSystem.vrik.transform.localRotation = Quaternion.identity;
|
||||
|
||||
float movementVector = (1 - MovementSystem.Instance.movementVector.magnitude);
|
||||
IKSystem.vrik.solver.spine.positionWeight = Setting_HipThrustMultiplier * movementVector;
|
||||
|
||||
//VRChat hip movement emulation
|
||||
if (Setting_EmulateVRChatHipMovementWeight != 0)
|
||||
{
|
||||
float angle = PlayerSetup.Instance.desktopCamera.transform.localEulerAngles.x;
|
||||
if (angle > 180) angle -= 360;
|
||||
float leanAmount = angle * movementVector * Setting_EmulateVRChatHipMovementWeight;
|
||||
Quaternion rotation = Quaternion.AngleAxis(leanAmount, IKSystem.Instance.avatar.transform.right);
|
||||
IKSystem.vrik.solver.AddRotationOffset(IKSolverVR.RotationOffset.Head, rotation);
|
||||
}
|
||||
|
||||
IKSystem.vrik.solver.plantFeet = true;
|
||||
IKSystem.vrik.solver.plantFeet = Setting_Internal_PlantFeet;
|
||||
}
|
||||
|
||||
public Animator animator;
|
||||
//public Quaternion originalRotation;
|
||||
public RuntimeAnimatorController runtimeAnimatorController;
|
||||
|
||||
public VRIK AlternativeCalibration(CVRAvatar avatar)
|
||||
{
|
||||
animator = avatar.GetComponent<Animator>();
|
||||
avatarHeadBone = animator.GetBoneTransform(HumanBodyBones.Head);
|
||||
Transform avatarHeadBone = animator.GetBoneTransform(HumanBodyBones.Head);
|
||||
|
||||
//Stuff to make bad armatures work (Fuck you Default Robot Kyle)
|
||||
avatar.transform.localPosition = Vector3.zero;
|
||||
//originalRotation = avatar.transform.rotation;
|
||||
//avatar.transform.rotation = Quaternion.identity;
|
||||
|
||||
//ikpose layer (specified by avatar author)
|
||||
int ikposeLayerIndex = animator.GetLayerIndex("IKPose");
|
||||
|
@ -114,12 +89,7 @@ public class DesktopVRIK : MonoBehaviour
|
|||
vrik.solver.locomotion.angleThreshold = 30f;
|
||||
vrik.solver.locomotion.maxLegStretch = 0.75f;
|
||||
//nuke weights
|
||||
vrik.solver.spine.headClampWeight = 1f;
|
||||
vrik.solver.spine.minHeadHeight = 0f;
|
||||
|
||||
//calm ur ass
|
||||
vrik.solver.spine.positionWeight = 0.1f;
|
||||
|
||||
vrik.solver.spine.pelvisPositionWeight = 0f;
|
||||
vrik.solver.leftArm.positionWeight = 0f;
|
||||
vrik.solver.leftArm.rotationWeight = 0f;
|
||||
|
@ -131,6 +101,19 @@ public class DesktopVRIK : MonoBehaviour
|
|||
vrik.solver.rightLeg.rotationWeight = 0f;
|
||||
vrik.solver.IKPositionWeight = 0f;
|
||||
|
||||
//calm ur ass
|
||||
vrik.solver.spine.positionWeight = 0f;
|
||||
|
||||
|
||||
//related to body & head rotation offset/limit
|
||||
vrik.solver.spine.headClampWeight = 1f;
|
||||
vrik.solver.spine.bodyRotStiffness = 0.8f;
|
||||
//makes chest between feet and head direction
|
||||
vrik.solver.spine.chestClampWeight = 0.5f;
|
||||
//needed to make head 1:1 with camera still
|
||||
vrik.solver.spine.neckStiffness = 1f;
|
||||
|
||||
|
||||
//ChilloutVR specific
|
||||
BodySystem.TrackingLeftArmEnabled = false;
|
||||
BodySystem.TrackingRightArmEnabled = false;
|
||||
|
@ -141,17 +124,19 @@ public class DesktopVRIK : MonoBehaviour
|
|||
IKSystem.Instance.headAnchorPositionOffset = Vector3.zero;
|
||||
|
||||
//Custom funky AF head ik shit
|
||||
foreach (Transform transform in headIKTarget)
|
||||
foreach (Transform transform in DesktopVRIK_Helper.Instance.ik_HeadFollower)
|
||||
{
|
||||
if (transform.name == "Head IK Target")
|
||||
{
|
||||
Destroy(transform.gameObject);
|
||||
}
|
||||
}
|
||||
headIKTarget.position = avatarHeadBone.position;
|
||||
headIKTarget.rotation = Quaternion.identity;
|
||||
VRIKCalibrator.CalibrateHead(vrik, headIKTarget.transform, IKSystem.Instance.headAnchorPositionOffset, IKSystem.Instance.headAnchorRotationOffset);
|
||||
headIKTarget.localRotation = Quaternion.identity;
|
||||
|
||||
DesktopVRIK_Helper.Instance.avatar_HeadBone = avatarHeadBone;
|
||||
DesktopVRIK_Helper.Instance.ik_HeadFollower.position = avatarHeadBone.position;
|
||||
DesktopVRIK_Helper.Instance.ik_HeadFollower.rotation = Quaternion.identity;
|
||||
VRIKCalibrator.CalibrateHead(vrik, DesktopVRIK_Helper.Instance.ik_HeadFollower.transform, IKSystem.Instance.headAnchorPositionOffset, IKSystem.Instance.headAnchorRotationOffset);
|
||||
DesktopVRIK_Helper.Instance.ik_HeadFollower.localRotation = Quaternion.identity;
|
||||
|
||||
//force immediate calibration before animator decides to fuck us
|
||||
vrik.solver.SetToReferences(vrik.references);
|
||||
|
@ -167,17 +152,23 @@ public class DesktopVRIK : MonoBehaviour
|
|||
}
|
||||
|
||||
//Find eyeoffset
|
||||
initialCamPos = PlayerSetup.Instance.desktopCamera.transform.localPosition;
|
||||
eyeOffset = PlayerSetup.Instance.desktopCamera.transform.localPosition;
|
||||
viewpoint = avatarHeadBone.Find("LocalHeadPoint");
|
||||
ChangeViewpointHandling(Setting_EnforceViewPosition);
|
||||
|
||||
if (vrik != null)
|
||||
//reset ikpose layer
|
||||
if (ikposeLayerIndex != -1)
|
||||
{
|
||||
vrik.onPreSolverUpdate.AddListener(new UnityAction(this.AlternativeOnPreSolverUpdate));
|
||||
animator.SetLayerWeight(ikposeLayerIndex, 0f);
|
||||
if (locoLayerIndex != -1)
|
||||
{
|
||||
animator.SetLayerWeight(locoLayerIndex, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
//avatar.transform.rotation = originalRotation;
|
||||
IKSystem.Instance.ResetIK();
|
||||
vrik?.onPreSolverUpdate.AddListener(new UnityAction(this.AlternativeOnPreSolverUpdate));
|
||||
|
||||
DesktopVRIK_Helper.Instance?.OnResetIK();
|
||||
|
||||
return vrik;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue