Skip to content

Commit

Permalink
Added support for vrc head chop and vrc constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
rurre committed Aug 28, 2024
1 parent 0618fc5 commit e5a91c9
Show file tree
Hide file tree
Showing 9 changed files with 410 additions and 37 deletions.
12 changes: 4 additions & 8 deletions Editor/Data/PumkinsAvatarInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@
using Pumkin.DependencyChecker;
using UnityEngine;
using Pumkin.AvatarTools;
using VRC.SDK3.Dynamics.PhysBone.Components;
using System.Text;



#if(VRC_SDK_VRCSDK3 || VRC_SDK_VRCSDK2)
using UnityEditor;

#if VRC_SDK_VRCSDK3
using VRC.SDKBase;
using VRC.SDK3.Dynamics.PhysBone.Components;
using VRC.SDKBase.Validation.Performance;
using VRC.SDKBase.Validation.Performance.Stats;
#endif
#if PUMKIN_PBONES
using VRC.SDK3.Dynamics.PhysBone.Components;
#endif

namespace Pumkin.DataStructures
{
public class PumkinsAvatarInfo //Need to improve this class sometime when I overhaul the performance stats
Expand Down
16 changes: 12 additions & 4 deletions Editor/Data/PumkinsDataStructures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public enum Tab { Common, All } //All needs to be last
"physbonecollider",
"dynamicbone",
"dynamicbonecollider",
"vrc_avatardescriptor",
"vrcavatardescriptor",
"skinnedmeshrenderer",
"meshrenderer",
"particlesystem",
Expand All @@ -35,12 +33,22 @@ public enum Tab { Common, All } //All needs to be last
"light",
"contactreceiver",
"contactsender",
"aimconstraint",
"lookatconstraint",
"parentconstraint",
"positionconstraint",
"rotationconstraint",
"scaleconstraint",
"aimconstraint",
"lookatconstraint",
"vrcaimconstraint",
"vrclookatconstraint",
"vrcparentconstraint",
"vrcpositionconstraint",
"vrcrotationconstraint",
"vrcscaleconstraint",
"vrc_avatardescriptor",
"vrcavatardescriptor",
"vrcstation",
"vrcheadchop",
"other"
}
}
Expand Down
7 changes: 7 additions & 0 deletions Editor/Data/PumkinsTypeCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ internal static class PumkinsTypeCache
public static readonly Type VRC_SpatialAudioSource = TypeHelpers.GetTypeAnywhere("VRC.SDK3.Avatars.Components.VRCSpatialAudioSource");
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 VRCHeadChop = TypeHelpers.GetTypeAnywhere("VRC.SDK3.Avatars.Components.VRCHeadChop");
public static readonly Type VRCAimConstraint = TypeHelpers.GetTypeAnywhere("VRC.SDK3.Dynamics.Constraint.Components.VRCAimConstraint");
public static readonly Type VRCLookAtConstraint = TypeHelpers.GetTypeAnywhere("VRC.SDK3.Dynamics.Constraint.Components.VRCLookAtConstraint");
public static readonly Type VRCParentConstraint = TypeHelpers.GetTypeAnywhere("VRC.SDK3.Dynamics.Constraint.Components.VRCParentConstraint");
public static readonly Type VRCPositionConstraint = TypeHelpers.GetTypeAnywhere("VRC.SDK3.Dynamics.Constraint.Components.VRCPositionConstraint");
public static readonly Type VRCRotationConstraint = TypeHelpers.GetTypeAnywhere("VRC.SDK3.Dynamics.Constraint.Components.VRCRotationConstraint");
public static readonly Type VRCScaleConstraint = TypeHelpers.GetTypeAnywhere("VRC.SDK3.Dynamics.Constraint.Components.VRCScaleConstraint");

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");
Expand Down
88 changes: 82 additions & 6 deletions Editor/PumkinsAvatarTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,14 @@ enum ToolMenuActions
RemoveFinalIK_FbtBipedIK,
RemoveFinalIK_VRIK,
RemoveFinalIK_Grounder,
RemoveVRCStation
RemoveVRCStation,
RemoveVRCHeadChop,
RemoveVRCAimConstraint,
RemoveVRCLookAtConstraint,
RemoveVRCParentConstraint,
RemoveVRCPositionConstraint,
RemoveVRCRotationConstraint,
RemoveVRCScaleConstraint,
}

readonly static string SCALE_RULER_DUMMY_NAME = "_PumkinsScaleRuler";
Expand Down Expand Up @@ -289,6 +296,13 @@ public bool CopierHasSelections
FinalIKExists && Settings.bCopier_finalIK_copy,
Settings.bCopier_other_copy,
#if VRC_SDK_VRCSDK3
Settings.bCopier_vrcAimConstraint_copy,
Settings.bCopier_vrcLookAtConstraint_copy,
Settings.bCopier_vrcParentConstraint_copy,
Settings.bCopier_vrcPositionConstraint_copy,
Settings.bCopier_vrcRotationConstraint_copy,
Settings.bCopier_vrcScaleConstraint_copy,
Settings.bCopier_vrcHeadChop_copy,
Settings.bCopier_contactSender_copy,
Settings.bCopier_contactReceiver_copy
#endif
Expand Down Expand Up @@ -328,6 +342,13 @@ public bool CopierHasSelections
Settings.bCopier_vrcStations_copy,
Settings.bCopier_contactSender_copy,
Settings.bCopier_contactReceiver_copy,
Settings.bCopier_vrcAimConstraint_copy,
Settings.bCopier_vrcLookAtConstraint_copy,
Settings.bCopier_vrcParentConstraint_copy,
Settings.bCopier_vrcPositionConstraint_copy,
Settings.bCopier_vrcRotationConstraint_copy,
Settings.bCopier_vrcScaleConstraint_copy,
Settings.bCopier_vrcHeadChop_copy,
#endif
Settings.bCopier_other_copy,
Settings.bCopier_finalIK_copy
Expand Down Expand Up @@ -1284,6 +1305,16 @@ void CopyComponents(CopyInstance inst)
}
}
catch(Exception ex) { Log("_Failed to copy VRC Stations: " + ex.Message, LogType.Error); }

try
{
if(Settings.bCopier_vrcHeadChop_copy && CopierTabs.ComponentIsInSelectedTab("vrcheadchop", Settings._copier_selectedTab))
{
GenericCopier.CopyComponent(PumkinsTypeCache.VRCHeadChop, inst, Settings.bCopier_vrcHeadChop_createObjects, false, Settings.bCopier_vrcHeadChop_fixReferences, false,
inst.ignoredTransforms);
}
}
catch(Exception ex) { Log("_Failed to copy VRC HeadChop components: " + ex.Message, LogType.Error); }
#endif
}

Expand Down Expand Up @@ -1329,38 +1360,83 @@ void CopyComponents(CopyInstance inst)
try
{
if(Settings.bCopier_lookAtConstraint_copy && CopierTabs.ComponentIsInSelectedTab<LookAtConstraint>(Settings._copier_selectedTab))
LegacyCopier.CopyAllLookAtConstraints(objFrom, objTo, Settings.bCopier_aimConstraint_createObjects, inst.ignoredTransforms);
LegacyCopier.CopyAllLookAtConstraints(objFrom, objTo, Settings.bCopier_lookAtConstraint_createObjects, inst.ignoredTransforms);
}
catch(Exception ex) { Log("_Failed to copy Look At Constraints: " + ex.Message, LogType.Error); }

try
{
if(Settings.bCopier_parentConstraint_copy && CopierTabs.ComponentIsInSelectedTab<ParentConstraint>(Settings._copier_selectedTab))
LegacyCopier.CopyAllParentConstraints(objFrom, objTo, Settings.bCopier_aimConstraint_createObjects, inst.ignoredTransforms);
LegacyCopier.CopyAllParentConstraints(objFrom, objTo, Settings.bCopier_parentConstraint_createObjects, inst.ignoredTransforms);
}
catch(Exception ex) { Log("_Failed to copy Parent Constraints: " + ex.Message, LogType.Error); }

try
{
if(Settings.bCopier_positionConstraint_copy && CopierTabs.ComponentIsInSelectedTab<PositionConstraint>(Settings._copier_selectedTab))
LegacyCopier.CopyAllPositionConstraints(objFrom, objTo, Settings.bCopier_aimConstraint_createObjects, inst.ignoredTransforms);
LegacyCopier.CopyAllPositionConstraints(objFrom, objTo, Settings.bCopier_positionConstraint_createObjects, inst.ignoredTransforms);
}
catch(Exception ex) { Log("_Failed to copy Position Constraints: " + ex.Message, LogType.Error); }

try
{
if(Settings.bCopier_rotationConstraint_copy && CopierTabs.ComponentIsInSelectedTab<RotationConstraint>(Settings._copier_selectedTab))
LegacyCopier.CopyAllRotationConstraints(objFrom, objTo, Settings.bCopier_aimConstraint_createObjects, inst.ignoredTransforms);
LegacyCopier.CopyAllRotationConstraints(objFrom, objTo, Settings.bCopier_rotationConstraint_createObjects, inst.ignoredTransforms);
}
catch(Exception ex) { Log("_Failed to copy Rotation Constraints: " + ex.Message, LogType.Error); }

try
{
if(Settings.bCopier_scaleConstraint_copy && CopierTabs.ComponentIsInSelectedTab<ScaleConstraint>(Settings._copier_selectedTab))
LegacyCopier.CopyAllScaleConstraints(objFrom, objTo, Settings.bCopier_aimConstraint_createObjects, inst.ignoredTransforms);
LegacyCopier.CopyAllScaleConstraints(objFrom, objTo, Settings.bCopier_scaleConstraint_createObjects, inst.ignoredTransforms);
}
catch(Exception ex) { Log("_Failed to copy Scale Constraints: " + ex.Message, LogType.Error); }

#if VRC_SDK_VRCSDK3

try
{
if(Settings.bCopier_vrcAimConstraint_copy && CopierTabs.ComponentIsInSelectedTab(PumkinsTypeCache.VRCAimConstraint, Settings._copier_selectedTab))
GenericCopier.CopyComponent(PumkinsTypeCache.VRCAimConstraint, inst, Settings.bCopier_vrcAimConstraint_createObjects, false, true, false, inst.ignoredTransforms);
}
catch(Exception ex) { Log("_Failed to copy VRC Aim Constraints: " + ex.Message, LogType.Error); }

try
{
if(Settings.bCopier_vrcLookAtConstraint_copy && CopierTabs.ComponentIsInSelectedTab(PumkinsTypeCache.VRCLookAtConstraint, Settings._copier_selectedTab))
GenericCopier.CopyComponent(PumkinsTypeCache.VRCLookAtConstraint, inst, Settings.bCopier_vrcLookAtConstraint_createObjects, false, true, false, inst.ignoredTransforms);
}
catch(Exception ex) { Log("_Failed to copy VRC Look At Constraints: " + ex.Message, LogType.Error); }

try
{
if(Settings.bCopier_vrcParentConstraint_copy && CopierTabs.ComponentIsInSelectedTab(PumkinsTypeCache.VRCParentConstraint, Settings._copier_selectedTab))
GenericCopier.CopyComponent(PumkinsTypeCache.VRCParentConstraint, inst, Settings.bCopier_vrcParentConstraint_createObjects, false, true, false, inst.ignoredTransforms);
}
catch(Exception ex) { Log("_Failed to copy VRC Parent Constraints: " + ex.Message, LogType.Error); }

try
{
if(Settings.bCopier_vrcPositionConstraint_copy && CopierTabs.ComponentIsInSelectedTab(PumkinsTypeCache.VRCPositionConstraint, Settings._copier_selectedTab))
GenericCopier.CopyComponent(PumkinsTypeCache.VRCPositionConstraint, inst, Settings.bCopier_vrcPositionConstraint_createObjects, false, true, false, inst.ignoredTransforms);
}
catch(Exception ex) { Log("_Failed to copy VRC Position Constraints: " + ex.Message, LogType.Error); }

try
{
if(Settings.bCopier_vrcRotationConstraint_copy && CopierTabs.ComponentIsInSelectedTab(PumkinsTypeCache.VRCRotationConstraint, Settings._copier_selectedTab))
GenericCopier.CopyComponent(PumkinsTypeCache.VRCRotationConstraint, inst, Settings.bCopier_vrcRotationConstraint_createObjects, false, true, false, inst.ignoredTransforms);
}
catch(Exception ex) { Log("_Failed to copy VRC Rotation Constraints: " + ex.Message, LogType.Error); }

try
{
if(Settings.bCopier_vrcScaleConstraint_copy && CopierTabs.ComponentIsInSelectedTab(PumkinsTypeCache.VRCScaleConstraint, Settings._copier_selectedTab))
GenericCopier.CopyComponent(PumkinsTypeCache.VRCScaleConstraint, inst, Settings.bCopier_vrcScaleConstraint_createObjects, false, true, false, inst.ignoredTransforms);
}
catch(Exception ex) { Log("_Failed to copy VRC Scale Constraints: " + ex.Message, LogType.Error); }
#endif

try
{
if(Settings.bCopier_joints_copy && CopierTabs.ComponentIsInSelectedTab<Joint>(Settings._copier_selectedTab))
Expand Down
22 changes: 22 additions & 0 deletions Editor/PumkinsAvatarTools_MainFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,28 @@ void DoAction(GameObject avatar, ToolMenuActions action)
case ToolMenuActions.RemoveScaleConstraint:
LegacyDestroyer.DestroyAllComponentsOfType(SelectedAvatar, typeof(ScaleConstraint), false);
break;

case ToolMenuActions.RemoveVRCAimConstraint:
LegacyDestroyer.DestroyAllComponentsOfType(SelectedAvatar, PumkinsTypeCache.VRCAimConstraint, false);
break;
case ToolMenuActions.RemoveVRCLookAtConstraint:
LegacyDestroyer.DestroyAllComponentsOfType(SelectedAvatar, PumkinsTypeCache.VRCLookAtConstraint, false);
break;
case ToolMenuActions.RemoveVRCParentConstraint:
LegacyDestroyer.DestroyAllComponentsOfType(SelectedAvatar, PumkinsTypeCache.VRCParentConstraint, false);
break;
case ToolMenuActions.RemoveVRCPositionConstraint:
LegacyDestroyer.DestroyAllComponentsOfType(SelectedAvatar, PumkinsTypeCache.VRCPositionConstraint, false);
break;
case ToolMenuActions.RemoveVRCRotationConstraint:
LegacyDestroyer.DestroyAllComponentsOfType(SelectedAvatar, PumkinsTypeCache.VRCRotationConstraint, false);
break;
case ToolMenuActions.RemoveVRCScaleConstraint:
LegacyDestroyer.DestroyAllComponentsOfType(SelectedAvatar, PumkinsTypeCache.VRCScaleConstraint, false);
break;
case ToolMenuActions.RemoveVRCHeadChop:
LegacyDestroyer.DestroyAllComponentsOfType(SelectedAvatar, PumkinsTypeCache.VRCHeadChop, false);
break;
case ToolMenuActions.RemoveCameras:
LegacyDestroyer.DestroyAllComponentsOfType(SelectedAvatar, typeof(Camera), false);
break;
Expand Down
Loading

0 comments on commit e5a91c9

Please sign in to comment.