mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
its working (FUCK)
This commit is contained in:
parent
8f4d146ba0
commit
0f485ccaa3
6 changed files with 221 additions and 11 deletions
95
DesktopVRIK/AsserHandler.cs
Normal file
95
DesktopVRIK/AsserHandler.cs
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
Kindly stolen from SDraw's leap motion mod. (MIT)
|
||||||
|
https://github.com/SDraw/ml_mods_cvr/blob/master/ml_lme/AssetsHandler.cs
|
||||||
|
|
||||||
|
*thank u sdraw, i wont be murderer now*
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace NAK.Melons.DesktopVRIK;
|
||||||
|
|
||||||
|
static class AssetsHandler
|
||||||
|
{
|
||||||
|
static readonly List<string> ms_assets = new List<string>()
|
||||||
|
{
|
||||||
|
"IKPose.assetbundle"
|
||||||
|
};
|
||||||
|
|
||||||
|
static Dictionary<string, AssetBundle> ms_loadedAssets = new Dictionary<string, AssetBundle>();
|
||||||
|
static Dictionary<string, Object> ms_loadedObjects = new Dictionary<string, Object>();
|
||||||
|
|
||||||
|
public static void Load()
|
||||||
|
{
|
||||||
|
Assembly l_assembly = Assembly.GetExecutingAssembly();
|
||||||
|
string l_assemblyName = l_assembly.GetName().Name;
|
||||||
|
|
||||||
|
foreach (string l_assetName in ms_assets)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Stream l_assetStream = l_assembly.GetManifestResourceStream(l_assemblyName + ".resources." + l_assetName);
|
||||||
|
if (l_assetStream != null)
|
||||||
|
{
|
||||||
|
MemoryStream l_memorySteam = new MemoryStream((int)l_assetStream.Length);
|
||||||
|
l_assetStream.CopyTo(l_memorySteam);
|
||||||
|
AssetBundle l_assetBundle = AssetBundle.LoadFromMemory(l_memorySteam.ToArray(), 0);
|
||||||
|
if (l_assetBundle != null)
|
||||||
|
{
|
||||||
|
l_assetBundle.hideFlags |= HideFlags.DontUnloadUnusedAsset;
|
||||||
|
ms_loadedAssets.Add(l_assetName, l_assetBundle);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
MelonLoader.MelonLogger.Warning("Unable to load bundled '" + l_assetName + "' asset");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
MelonLoader.MelonLogger.Warning("Unable to get bundled '" + l_assetName + "' asset stream");
|
||||||
|
}
|
||||||
|
catch (System.Exception e)
|
||||||
|
{
|
||||||
|
MelonLoader.MelonLogger.Warning("Unable to load bundled '" + l_assetName + "' asset, reason: " + e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object GetAsset(string p_name)
|
||||||
|
{
|
||||||
|
Object l_result = null;
|
||||||
|
if (ms_loadedObjects.ContainsKey(p_name))
|
||||||
|
{
|
||||||
|
l_result = UnityEngine.Object.Instantiate(ms_loadedObjects[p_name]);
|
||||||
|
//l_result.SetActive(true);
|
||||||
|
l_result.hideFlags |= HideFlags.DontUnloadUnusedAsset;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var l_pair in ms_loadedAssets)
|
||||||
|
{
|
||||||
|
if (l_pair.Value.Contains(p_name))
|
||||||
|
{
|
||||||
|
Object l_bundledObject = (Object)l_pair.Value.LoadAsset(p_name, typeof(Object));
|
||||||
|
if (l_bundledObject != null)
|
||||||
|
{
|
||||||
|
ms_loadedObjects.Add(p_name, l_bundledObject);
|
||||||
|
l_result = UnityEngine.Object.Instantiate(l_bundledObject);
|
||||||
|
//l_result.SetActive(true);
|
||||||
|
l_result.hideFlags |= HideFlags.DontUnloadUnusedAsset;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return l_result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Unload()
|
||||||
|
{
|
||||||
|
foreach (var l_pair in ms_loadedAssets)
|
||||||
|
UnityEngine.Object.Destroy(l_pair.Value);
|
||||||
|
ms_loadedAssets.Clear();
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,15 +16,28 @@ public class DesktopVRIK : MonoBehaviour
|
||||||
public static bool Setting_Enabled,
|
public static bool Setting_Enabled,
|
||||||
Setting_EnforceViewPosition,
|
Setting_EnforceViewPosition,
|
||||||
Setting_EmoteVRIK,
|
Setting_EmoteVRIK,
|
||||||
Setting_EmoteLookAtIK;
|
Setting_EmoteLookAtIK,
|
||||||
|
Setting_AllowRootSlipping,
|
||||||
|
Setting_TestIKPoseController;
|
||||||
public static float Setting_EmulateVRChatHipMovementWeight;
|
public static float Setting_EmulateVRChatHipMovementWeight;
|
||||||
|
|
||||||
public Transform viewpoint;
|
public Transform viewpoint;
|
||||||
public Vector3 initialCamPos;
|
public Vector3 initialCamPos;
|
||||||
|
|
||||||
|
Transform headIKTarget;
|
||||||
|
Transform avatarHeadBone;
|
||||||
|
|
||||||
|
RuntimeAnimatorController ikposeController;
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
|
ikposeController = (RuntimeAnimatorController)AssetsHandler.GetAsset("Assets/BundledAssets/IKPose/IKPose.controller");
|
||||||
|
// 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)
|
public void ChangeViewpointHandling(bool enabled)
|
||||||
|
@ -172,4 +185,105 @@ public class DesktopVRIK : MonoBehaviour
|
||||||
newTarget.transform.localRotation = Quaternion.identity;
|
newTarget.transform.localRotation = Quaternion.identity;
|
||||||
return newTarget.transform;
|
return newTarget.transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Setting_AllowRootSlipping)
|
||||||
|
{
|
||||||
|
//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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//VRChat hip movement emulation
|
||||||
|
if (Setting_EmulateVRChatHipMovementWeight != 0)
|
||||||
|
{
|
||||||
|
float angle = PlayerSetup.Instance.desktopCamera.transform.localEulerAngles.x;
|
||||||
|
if (angle > 180) angle -= 360;
|
||||||
|
float leanAmount = angle * (1 - MovementSystem.Instance.movementVector.magnitude) * 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Animator animator;
|
||||||
|
public Quaternion originalRotation;
|
||||||
|
public RuntimeAnimatorController runtimeAnimatorController;
|
||||||
|
|
||||||
|
public VRIK AlternativeCalibration(CVRAvatar avatar)
|
||||||
|
{
|
||||||
|
animator = avatar.GetComponent<Animator>();
|
||||||
|
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;
|
||||||
|
|
||||||
|
//force immediate calibration before animator decides to fuck us
|
||||||
|
VRIK vrik = avatar.gameObject.AddComponent<VRIK>();
|
||||||
|
vrik.AutoDetectReferences();
|
||||||
|
vrik.solver.SetToReferences(vrik.references);
|
||||||
|
vrik.solver.Initiate(vrik.transform);
|
||||||
|
|
||||||
|
if (Setting_TestIKPoseController)
|
||||||
|
{
|
||||||
|
//Destroy(vrik);
|
||||||
|
return vrik;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Generic VRIK calibration shit
|
||||||
|
|
||||||
|
vrik.fixTransforms = true;
|
||||||
|
vrik.solver.plantFeet = false;
|
||||||
|
vrik.solver.locomotion.weight = 0f;
|
||||||
|
vrik.solver.locomotion.angleThreshold = 30f;
|
||||||
|
vrik.solver.locomotion.maxLegStretch = 0.75f;
|
||||||
|
//nuke weights
|
||||||
|
vrik.solver.spine.headClampWeight = 0f;
|
||||||
|
vrik.solver.spine.minHeadHeight = 0f;
|
||||||
|
vrik.solver.spine.pelvisPositionWeight = 0f;
|
||||||
|
vrik.solver.leftArm.positionWeight = 0f;
|
||||||
|
vrik.solver.leftArm.rotationWeight = 0f;
|
||||||
|
vrik.solver.rightArm.positionWeight = 0f;
|
||||||
|
vrik.solver.rightArm.rotationWeight = 0f;
|
||||||
|
vrik.solver.leftLeg.positionWeight = 0f;
|
||||||
|
vrik.solver.leftLeg.rotationWeight = 0f;
|
||||||
|
vrik.solver.rightLeg.positionWeight = 0f;
|
||||||
|
vrik.solver.rightLeg.rotationWeight = 0f;
|
||||||
|
vrik.solver.IKPositionWeight = 0f;
|
||||||
|
|
||||||
|
//ChilloutVR specific
|
||||||
|
BodySystem.TrackingLeftArmEnabled = false;
|
||||||
|
BodySystem.TrackingRightArmEnabled = false;
|
||||||
|
BodySystem.TrackingLeftLegEnabled = false;
|
||||||
|
BodySystem.TrackingRightLegEnabled = false;
|
||||||
|
IKSystem.Instance.headAnchorRotationOffset = Vector3.zero;
|
||||||
|
IKSystem.Instance.headAnchorPositionOffset = Vector3.zero;
|
||||||
|
|
||||||
|
//Custom funky AF head ik shit
|
||||||
|
headIKTarget.position = avatarHeadBone.position;
|
||||||
|
headIKTarget.rotation = Quaternion.identity;
|
||||||
|
VRIKCalibrator.CalibrateHead(vrik, headIKTarget.transform, IKSystem.Instance.headAnchorPositionOffset, IKSystem.Instance.headAnchorRotationOffset);
|
||||||
|
headIKTarget.localRotation = Quaternion.identity;
|
||||||
|
|
||||||
|
if (vrik != null)
|
||||||
|
{
|
||||||
|
vrik.onPreSolverUpdate.AddListener(new UnityAction(this.AlternativeOnPreSolverUpdate));
|
||||||
|
}
|
||||||
|
|
||||||
|
avatar.transform.rotation = originalRotation;
|
||||||
|
IKSystem.Instance.ResetIK();
|
||||||
|
|
||||||
|
return vrik;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -8,6 +8,14 @@
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="resources\IKPose.assetbundle" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="resources\IKPose.assetbundle" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="0Harmony">
|
<Reference Include="0Harmony">
|
||||||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\0Harmony.dll</HintPath>
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\0Harmony.dll</HintPath>
|
||||||
|
|
|
@ -105,8 +105,6 @@ class IKSystemPatches
|
||||||
{
|
{
|
||||||
if (IKSystem.Instance.animator != null && IKSystem.Instance.animator.avatar != null && IKSystem.Instance.animator.avatar.isHuman)
|
if (IKSystem.Instance.animator != null && IKSystem.Instance.animator.avatar != null && IKSystem.Instance.animator.avatar.isHuman)
|
||||||
{
|
{
|
||||||
IKSystem.Instance.animator.enabled = false;
|
|
||||||
|
|
||||||
//why the fuck does this fix bad armatures and heels in ground ??? (this one is suprisingly not because of Default Robot Kyle) ... (Fuck you Default Robot Kyle)
|
//why the fuck does this fix bad armatures and heels in ground ??? (this one is suprisingly not because of Default Robot Kyle) ... (Fuck you Default Robot Kyle)
|
||||||
if (____poseHandler == null)
|
if (____poseHandler == null)
|
||||||
{
|
{
|
||||||
|
@ -120,14 +118,8 @@ class IKSystemPatches
|
||||||
}
|
}
|
||||||
____poseHandler.SetHumanPose(ref ___humanPose);
|
____poseHandler.SetHumanPose(ref ___humanPose);
|
||||||
|
|
||||||
//need IKSystem to see VRIK component for setup
|
____vrik = DesktopVRIK.Instance.AlternativeCalibration(avatar);
|
||||||
if (____vrik == null)
|
IKSystem.Instance.ApplyAvatarScaleToIk(avatar.viewPosition.y);
|
||||||
{
|
|
||||||
____vrik = avatar.gameObject.AddComponent<VRIK>();
|
|
||||||
}
|
|
||||||
|
|
||||||
//now I calibrate DesktopVRIK
|
|
||||||
DesktopVRIK.Instance.CalibrateDesktopVRIK(avatar);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ public class DesktopVRIKMod : MelonMod
|
||||||
|
|
||||||
System.Collections.IEnumerator WaitForLocalPlayer()
|
System.Collections.IEnumerator WaitForLocalPlayer()
|
||||||
{
|
{
|
||||||
|
AssetsHandler.Load();
|
||||||
while (PlayerSetup.Instance == null)
|
while (PlayerSetup.Instance == null)
|
||||||
yield return null;
|
yield return null;
|
||||||
PlayerSetup.Instance.gameObject.AddComponent<DesktopVRIK>();
|
PlayerSetup.Instance.gameObject.AddComponent<DesktopVRIK>();
|
||||||
|
|
BIN
DesktopVRIK/resources/IKPose.assetbundle
Normal file
BIN
DesktopVRIK/resources/IKPose.assetbundle
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue