From c6327cd1f5cb2d14219b57ef58092f4697969e5d Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Thu, 1 Aug 2024 17:42:53 +0900 Subject: [PATCH 1/2] feat: minimal VRCConstraints support --- Editor/APIInternal/ComponentInfos.VRCSDK.cs | 53 +++++++++++++++++++ ...m.anatawa12.avatar-optimizer.editor.asmdef | 6 +++ Test~/Basic/ComponentWhitelistTest.cs | 6 +++ 3 files changed, 65 insertions(+) diff --git a/Editor/APIInternal/ComponentInfos.VRCSDK.cs b/Editor/APIInternal/ComponentInfos.VRCSDK.cs index 9b73fd4e5..704591bf8 100644 --- a/Editor/APIInternal/ComponentInfos.VRCSDK.cs +++ b/Editor/APIInternal/ComponentInfos.VRCSDK.cs @@ -14,6 +14,11 @@ using VRC.SDK3.Dynamics.PhysBone.Components; using VRC.SDKBase; +#if AAO_VRCSDK3_AVATARS_CONSTRAINTS +using VRC.Dynamics.ManagedTypes; +using VRC.SDK3.Dynamics.Constraint.Components; +#endif + namespace Anatawa12.AvatarOptimizer.APIInternal.VRCSDK { [ComponentInformation(typeof(VRCTestMarker))] @@ -497,5 +502,53 @@ protected override void CollectDependency(VRCHeadChop component, ComponentDepend } } #endif + +#if AAO_VRCSDK3_AVATARS_CONSTRAINTS + [ComponentInformation(typeof(VRCConstraintBase))] + [ComponentInformation(typeof(VRCParentConstraintBase))] + [ComponentInformation(typeof(VRCParentConstraint))] + [ComponentInformation(typeof(VRCPositionConstraintBase))] + [ComponentInformation(typeof(VRCPositionConstraint))] + [ComponentInformation(typeof(VRCRotationConstraintBase))] + [ComponentInformation(typeof(VRCRotationConstraint))] + [ComponentInformation(typeof(VRCScaleConstraintBase))] + [ComponentInformation(typeof(VRCScaleConstraint))] + internal class VRCConstraintInformation : ComponentInformation where T : VRCConstraintBase + { + protected override void CollectDependency(T component, ComponentDependencyCollector collector) + { + collector.AddDependency(component.transform, component) + .OnlyIfTargetCanBeEnable() + .EvenIfDependantDisabled(); + + foreach (var source in component.Sources) + collector.AddDependency(source.SourceTransform); + + // we may mark heavy behavior with complex rules but it's extremely difficult to implement + // so mark behavior for now + collector.MarkBehaviour(); + } + + protected override void CollectMutations(T component, ComponentMutationsCollector collector) + { + collector.TransformRotation(component.TargetTransform ? component.TargetTransform : component.transform); + } + } + + [ComponentInformation(typeof(VRCWorldUpConstraintBase))] + [ComponentInformation(typeof(VRCAimConstraintBase))] + [ComponentInformation(typeof(VRCAimConstraint))] + [ComponentInformation(typeof(VRCLookAtConstraintBase))] + [ComponentInformation(typeof(VRCLookAtConstraint))] + internal class VRCWorldUpConstraintInformation : VRCConstraintInformation + { + protected override void CollectDependency(VRCWorldUpConstraintBase component, ComponentDependencyCollector collector) + { + base.CollectDependency(component, collector); + collector.AddDependency(component.WorldUpTransform); + } + } + +#endif } #endif diff --git a/Editor/com.anatawa12.avatar-optimizer.editor.asmdef b/Editor/com.anatawa12.avatar-optimizer.editor.asmdef index 03ac570d3..54a0fd794 100644 --- a/Editor/com.anatawa12.avatar-optimizer.editor.asmdef +++ b/Editor/com.anatawa12.avatar-optimizer.editor.asmdef @@ -37,6 +37,7 @@ "VRCSDK3A.dll", "VRCSDKBase-Editor.dll", "VRCSDKBase.dll", + "VRC.SDK3.Dynamics.Constraint.dll", "System.Memory.dll" ], "autoReferenced": false, @@ -67,6 +68,11 @@ "expression": "3.5.2", "define": "AAO_VRCSDK3_AVATARS_ANIMATOR_PLAY_AUDIO" }, + { + "name": "com.vrchat.avatars", + "expression": "[3.6.2-constraints.3]", + "define": "AAO_VRCSDK3_AVATARS_CONSTRAINTS" + }, { "name": "com.vrmc.univrm", "expression": "", diff --git a/Test~/Basic/ComponentWhitelistTest.cs b/Test~/Basic/ComponentWhitelistTest.cs index 8fcb0f169..48b844177 100644 --- a/Test~/Basic/ComponentWhitelistTest.cs +++ b/Test~/Basic/ComponentWhitelistTest.cs @@ -109,6 +109,12 @@ public static IEnumerable KnownTypes() "VRC.SDK3.Dynamics.PhysBone.Components.VRCPhysBoneCollider", "VRC.SDK3.Dynamics.Contact.Components.VRCContactSender", "VRC.SDK3.Dynamics.Contact.Components.VRCContactReceiver", + "VRC.SDK3.Dynamics.Constraint.Components.VRCAimConstraint", + "VRC.SDK3.Dynamics.Constraint.Components.VRCLookAtConstraint", + "VRC.SDK3.Dynamics.Constraint.Components.VRCParentConstraint", + "VRC.SDK3.Dynamics.Constraint.Components.VRCPositionConstraint", + "VRC.SDK3.Dynamics.Constraint.Components.VRCRotationConstraint", + "VRC.SDK3.Dynamics.Constraint.Components.VRCScaleConstraint", }; } } From c2fb8f128b6ee398753abc124151f2cbc6a9cbed Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Thu, 1 Aug 2024 17:49:55 +0900 Subject: [PATCH 2/2] docs(changelog): Experimental VRCConstraints support --- CHANGELOG-PRERELEASE.md | 2 ++ CHANGELOG.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG-PRERELEASE.md b/CHANGELOG-PRERELEASE.md index 58a0eda64..fb2e3add8 100644 --- a/CHANGELOG-PRERELEASE.md +++ b/CHANGELOG-PRERELEASE.md @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog]. ## [Unreleased] ### Added +- Experimental VRCConstraints support `#1129` + - This only works for VRCSDK `3.6.2-constraints.3` and not works with other versions including future versions. ### Changed diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dcc99107..0fe9e118d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog]. ## [Unreleased] ### Added +- Experimental VRCConstraints support `#1129` + - This only works for VRCSDK `3.6.2-constraints.3` and not works with other versions including future versions. ### Changed