Skip to content

Commit

Permalink
Fixed world sdk and physbones not getting detected
Browse files Browse the repository at this point in the history
  • Loading branch information
rurre committed Apr 4, 2023
1 parent d23b473 commit d65bc91
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 276 deletions.
10 changes: 2 additions & 8 deletions Editor/Callbacks/AvatarUploadHider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,16 @@
using System.Linq;
using UnityEditor;
using UnityEngine;

#if VRC_SDK_VRCSDK2 || (VRC_SDK_VRCSDK3 && !UDON)
using VRC.Core;
using VRC.SDKBase.Editor.BuildPipeline;
using VRC.SDKBase;
#endif

#if VRC_SDK_VRCSDK3 && !UDON
using VRC.SDKBase.Editor.BuildPipeline;
using VRC_AvatarDescriptor = VRC.SDK3.Avatars.Components.VRCAvatarDescriptor;
#elif VRC_SDK_VRCSDK2
using VRC_AvatarDescriptor = VRCSDK2.VRC_AvatarDescriptor;
#endif

namespace Pumkin.AvatarTools.Callbacks
{
#if VRC_SDK_VRCSDK2 || (VRC_SDK_VRCSDK3 && !UDON)
#if VRC_SDK_VRCSDK3 && !UDON
class AvatarUploadHider : IVRCSDKPreprocessAvatarCallback
{
public int callbackOrder => 0;
Expand Down
11 changes: 1 addition & 10 deletions Editor/Copiers/LegacyCopier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,11 @@
using UnityEngine.Animations;
using Object = UnityEngine.Object;

#if VRC_SDK_VRCSDK2 || VRC_SDK_VRCSDK3
using VRC.Core;
using VRC.SDKBase;
#endif
#if (VRC_SDK_VRCSDK2 || VRC_SDK_VRCSDK3) && PUMKIN_PBONES
#if VRC_SDK_VRCSDK3 && !UDON
using VRC.SDK3.Dynamics.PhysBone.Components;
using VRC.SDK3.Dynamics.Contact.Components;
#endif
#if VRC_SDK_VRCSDK3 && !UDON
using VRC_AvatarDescriptor = VRC.SDK3.Avatars.Components.VRCAvatarDescriptor;
using VRC_SpatialAudioSource = VRC.SDK3.Avatars.Components.VRCSpatialAudioSource;
#elif VRC_SDK_VRCSDK2
using VRC_AvatarDescriptor = VRCSDK2.VRC_AvatarDescriptor;
using VRC_SpatialAudioSource = VRCSDK2.VRC_SpatialAudioSource;
#endif

namespace Pumkin.AvatarTools.Copiers
Expand Down
4 changes: 2 additions & 2 deletions Editor/Data/PumkinsStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace Pumkin.DataStructures
[ExecuteInEditMode, InitializeOnLoad] //needed for string singleton
public class Strings : SingletonScriptableObject<Strings>
{
public const string TOOLS_VERSION_STRING = "1.3.5";
public const double toolsVersion = 1.35;
public const string TOOLS_VERSION_STRING = "1.3.7";
public const double toolsVersion = 1.37;

public const string POSE_EDITOR_VERSION_NUMBER = "0.1.3b - Work in Progress";
public const string LINK_GITHUB = "https://github.com/rurre/PumkinsAvatarTools/";
Expand Down
48 changes: 13 additions & 35 deletions Editor/Data/PumkinsTypeCache.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using Pumkin.HelperFunctions;
#if PUMKIN_PBONES
using VRC.SDK3.Dynamics.PhysBone.Components;
using VRC.SDK3.Dynamics.Contact.Components;
#endif

namespace Pumkin.DataStructures
{
Expand All @@ -12,52 +8,34 @@ namespace Pumkin.DataStructures
/// </summary>
internal static class PumkinsTypeCache
{

#if VRC_SDK_VRCSDK2
public static readonly Type VRC_AvatarDescriptor = TypeHelpers.GetTypeAnywhere("VRCSDK2.VRC_AvatarDescriptor");
public static readonly Type VRC_SpatialAudioSource = TypeHelpers.GetTypeAnywhere("VRCSDK2.VRC_SpatialAudioSource");
#elif VRC_SDK_VRCSDK3 && !UDON
public static readonly Type VRC_AvatarDescriptor = TypeHelpers.GetTypeAnywhere("VRC.SDK3.Avatars.Components.VRCAvatarDescriptor");
public static readonly Type VRC_AvatarDescriptor = TypeHelpers.GetTypeAnywhere("VRC.SDK3.Avatars.Components.VRCAvatarDescriptor");
public static readonly Type VRC_SpatialAudioSource = TypeHelpers.GetTypeAnywhere("VRC.SDK3.Avatars.Components.VRCSpatialAudioSource");
#else
public static readonly Type VRC_AvatarDescriptor = null;
public static readonly Type VRC_SpatialAudioSource = null;
#endif
public static readonly Type ContactReceiver = TypeHelpers.GetTypeAnywhere("VRC.SDK3.Dynamics.Contact.Components.VRCContactReceiver");
public static readonly Type ContactSender = TypeHelpers.GetTypeAnywhere("VRC.SDK3.Dynamics.Contact.Components.VRCContactSender");

public static readonly Type PhysBone = TypeHelpers.GetTypeAnywhere("VRC.SDK3.Dynamics.PhysBone.Components.VRCPhysBone");
public static readonly Type PhysBoneCollider = TypeHelpers.GetTypeAnywhere("VRC.SDK3.Dynamics.PhysBone.Components.VRCPhysBoneCollider");

public static readonly Type PipelineManager = TypeHelpers.GetTypeAnywhere("VRC.Core.PipelineManager");
public static readonly Type VRC_AvatarDescriptor_LipSyncStyle = TypeHelpers.GetTypeAnywhere("VRC.SDKBase.VRC_AvatarDescriptor+LipSyncStyle");
public static readonly Type VRC_AvatarDescriptor_Viseme = TypeHelpers.GetTypeAnywhere("VRC.SDKBase.VRC_AvatarDescriptor+Viseme");
public static readonly Type VRC_SpacialAudioSource = TypeHelpers.GetTypeAnywhere("VRC.SDKBase.VRC_SpatialAudioSource");
public static readonly Type VRC_IKFollower = TypeHelpers.GetTypeAnywhere("VRC.SDKBase.VRC_IKFollower");
public static readonly Type ONSPAudioSource = TypeHelpers.GetTypeAnywhere("ONSPAudioSource");
public static readonly Type VRCStation = TypeHelpers.GetTypeAnywhere("VRC.SDK3.Avatars.Components.VRCStation");
#if PUMKIN_PBONES
public static readonly Type ContactReceiver = typeof(VRCContactReceiver);
public static readonly Type ContactSender = typeof(VRCContactSender);

public static readonly Type PhysBone = typeof(VRCPhysBone);
public static readonly Type PhysBoneCollider = typeof(VRCPhysBoneCollider);
#else
public static readonly Type ContactReceiver = null;
public static readonly Type ContactSender = null;

public static readonly Type PhysBone = null;
public static readonly Type PhysBoneCollider = null;
#endif
public static readonly Type DynamicBone = TypeHelpers.GetTypeAnywhere("DynamicBone");
public static readonly Type DynamicBoneCollider = TypeHelpers.GetTypeAnywhere("DynamicBoneCollider");
public static readonly Type DynamicBoneColliderBase = TypeHelpers.GetTypeAnywhere("DynamicBoneColliderBase");
public static readonly Type DynamicBonePlaneCollider = TypeHelpers.GetTypeAnywhere("DynamicBonePlaneCollider");

public static readonly Type CCDIK = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.CCDIK");
public static readonly Type LimbIK = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.");
public static readonly Type RotationLimit = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.LimbIK");
public static readonly Type FABRIK = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.FABRIK");
public static readonly Type AimIK = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.AimIK");
public static readonly Type FullBodyBipedIK = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.FullBodyBipedIK");
public static readonly Type VRIK = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.VRIK");
public static readonly Type CCDIK = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.CCDIK");
public static readonly Type LimbIK = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.");
public static readonly Type RotationLimit = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.LimbIK");
public static readonly Type FABRIK = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.FABRIK");
public static readonly Type AimIK = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.AimIK");
public static readonly Type FullBodyBipedIK = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.FullBodyBipedIK");
public static readonly Type VRIK = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.VRIK");
public static readonly Type Grounder = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.Grounder");

public static readonly Type VRMSpringBone = TypeHelpers.GetTypeAnywhere("VRM.VRMSpringBone");
}
}
2 changes: 1 addition & 1 deletion Editor/Dependencies/_DependencyChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static PumkinsSDKVersion GetVRCSDKVersion()
static bool GetPhysBones()
{
Debug.Log("<color=blue>PumkinsAvatarTools</color>: Checking for PhysBones and Contacts in project...");
if(AppDomain.CurrentDomain.GetAssemblies().Any(ass => ass.FullName.StartsWith("VRC.Dynamics,")))
if(AppDomain.CurrentDomain.GetAssemblies().Any(ass => ass.FullName.StartsWith("VRC.Dynamics")))
{
Debug.Log("<color=blue>PumkinsAvatarTools</color>: Found PhysBones and Contacts in project!");
return true;
Expand Down
8 changes: 4 additions & 4 deletions Editor/Helpers/PumkinsHelperFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.Animations;
#if VRC_SDK_VRCSDK2 || (VRC_SDK_VRCSDK3 && !UDON)
#if VRC_SDK_VRCSDK3 && !UDON
using VRC.Core;
using VRC.SDKBase;
#endif
Expand Down Expand Up @@ -279,7 +279,7 @@ public static void DrawPropertyArraysHorizontalWithDeleteAndAdd(SerializedProper
}
}

#if VRC_SDK_VRCSDK2 || (VRC_SDK_VRCSDK3 && !UDON)
#if VRC_SDK_VRCSDK3
/// <summary>
/// Destroys the avatar descriptor and pipeline manager components if they're present on the avatar
/// </summary>
Expand All @@ -288,8 +288,8 @@ public static void DestroyAvatarDescriptorAndPipeline(GameObject avatar)
if(!avatar)
return;

var desc = avatar.GetComponent<VRC_AvatarDescriptor>();
var pipe = avatar.GetComponent<PipelineManager>();
var desc = avatar.GetComponent(PumkinsTypeCache.VRC_AvatarDescriptor);
var pipe = avatar.GetComponent(PumkinsTypeCache.PipelineManager);

DestroyAppropriate(desc);
DestroyAppropriate(pipe);
Expand Down
44 changes: 27 additions & 17 deletions Editor/Presets/PumkinsCameraPreset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
using Pumkin.DataStructures;
using Pumkin.Dependencies;
using Pumkin.HelperFunctions;
using Pumkin.PoseEditor;
using System;
using UnityEditor;
using UnityEngine;
#if VRC_SDK_VRCSDK2 || (VRC_SDK_VRCSDK3 && !UDON)
using VRC.SDKBase;
#endif

namespace Pumkin.Presets
{
[Serializable]
public class PumkinsCameraPreset : PumkinPreset
{
#if VRC_SDK_VRCSDK2 || (VRC_SDK_VRCSDK3 && !UDON)
#if VRC_SDK_VRCSDK3
public enum CameraOffsetMode { Viewpoint, AvatarRoot, Transform }
public CameraOffsetMode offsetMode = CameraOffsetMode.Viewpoint;
#else
Expand Down Expand Up @@ -59,14 +55,15 @@ public override bool ApplyPreset(GameObject avatar)
Transform dummy = null;
try
{
#if VRC_SDK_VRCSDK2 || (VRC_SDK_VRCSDK3 && !UDON)
#if VRC_SDK_VRCSDK3 && !UDON
if(offsetMode == CameraOffsetMode.Viewpoint)
{
dummy = new GameObject("Dummy").transform;
var desc = avatar.GetComponent<VRC_AvatarDescriptor>();
var desc = avatar.GetComponent(PumkinsTypeCache.VRC_AvatarDescriptor);
if(desc)
{
dummy.localPosition = desc.transform.position + desc.ViewPosition;
dynamic descriptor = Convert.ChangeType(desc, PumkinsTypeCache.VRC_AvatarDescriptor);
dummy.localPosition = desc.transform.position + descriptor.ViewPosition;
cam.transform.localPosition = positionOffset + dummy.transform.localPosition;
cam.transform.localEulerAngles = rotationAnglesOffset + dummy.transform.localEulerAngles;
}
Expand Down Expand Up @@ -152,9 +149,9 @@ public bool SavePreset(GameObject referenceObject, Camera camera, bool overwrite
CalculateOffsets(referenceObject.transform.root, camera);
else if(p.offsetMode == CameraOffsetMode.Transform)
CalculateOffsets(referenceObject.transform, camera);
#if VRC_SDK_VRCSDK2 || (VRC_SDK_VRCSDK3 && !UDON)
#if VRC_SDK_VRCSDK3 && !UDON
else
CalculateOffsets(PumkinsAvatarTools.SelectedAvatar.GetComponent<VRC_AvatarDescriptor>(), camera);
CalculateOffsets(PumkinsAvatarTools.SelectedAvatar.GetComponent(PumkinsTypeCache.VRC_AvatarDescriptor), camera);
#endif
p.positionOffset = positionOffset;
p.rotationAnglesOffset = rotationAnglesOffset;
Expand Down Expand Up @@ -301,11 +298,11 @@ public override string ToString()
return name;
}

#if VRC_SDK_VRCSDK2 || (VRC_SDK_VRCSDK3 && !UDON)
#if VRC_SDK_VRCSDK3
/// <summary>
/// Returns position and rotation offsets from viewpoint to camera
/// </summary>
public void CalculateOffsets(VRC_AvatarDescriptor desc, Camera cam)
public void CalculateOffsets(Component desc, Camera cam)
{
if(!desc || !cam)
return;
Expand Down Expand Up @@ -334,8 +331,10 @@ public static void ApplyPositionAndRotationWithViewpointFocus(GameObject avatar,
try
{
dummy = new GameObject("Dummy").transform;
var desc = avatar.GetComponent<VRC_AvatarDescriptor>();
dummy.localPosition = desc.ViewPosition + desc.gameObject.transform.position;
var desc = avatar.GetComponent(PumkinsTypeCache.VRC_AvatarDescriptor);

dynamic descriptor = Convert.ChangeType(desc, PumkinsTypeCache.VRC_AvatarDescriptor);
dummy.localPosition = descriptor.ViewPosition + desc.gameObject.transform.position;

cam.transform.localPosition = position + dummy.transform.position;
cam.transform.localEulerAngles = rotationAngles + dummy.transform.eulerAngles;
Expand All @@ -358,14 +357,25 @@ public static void ApplyPositionAndRotationWithViewpointFocus(GameObject avatar,
/// Gets camera offsets from viewpoint and returns a SerialTransform
/// </summary>
/// <returns>SerialTransform only holds values, it doesn't reference a real transform</returns>
public static SerialTransform GetOffsetsFromViewpoint(VRC_AvatarDescriptor desc, Camera cam)
public static SerialTransform GetOffsetsFromViewpoint(Component desc, Camera cam)
{
dynamic descriptor;
try
{
descriptor = Convert.ChangeType(desc, PumkinsTypeCache.VRC_AvatarDescriptor);
}
catch(Exception ex)
{
Debug.LogException(ex);
return null;
}

SerialTransform offsets = new SerialTransform();
Transform dummy = null;
try
{
dummy = new GameObject("Dummy").transform;
dummy.localPosition = desc.ViewPosition + desc.gameObject.transform.position;
dummy.localPosition = descriptor.ViewPosition + desc.gameObject.transform.position;

offsets.localPosition = cam.transform.localPosition - dummy.localPosition;
offsets.localEulerAngles = cam.transform.localEulerAngles - dummy.localEulerAngles;
Expand All @@ -388,7 +398,7 @@ public static SerialTransform GetOffsetsFromViewpoint(VRC_AvatarDescriptor desc,
/// <returns>SerialTransform only holds values, it doesn't reference a real transform</returns>
public static SerialTransform GetCameraOffsetFromViewpoint(GameObject avatar, Camera cam)
{
VRC_AvatarDescriptor desc = avatar.GetComponent<VRC_AvatarDescriptor>();
Component desc = avatar.GetComponent(PumkinsTypeCache.VRC_AvatarDescriptor);
SerialTransform offsets = null;

if(desc)
Expand Down
Loading

0 comments on commit d65bc91

Please sign in to comment.