Skip to content

Commit

Permalink
Merge pull request #1129 from anatawa12/vrc-constraints-beta-support
Browse files Browse the repository at this point in the history
feat: minimal VRCConstraints support
  • Loading branch information
anatawa12 authored Aug 1, 2024
2 parents 35f0d06 + c2fb8f1 commit dda37c7
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
53 changes: 53 additions & 0 deletions Editor/APIInternal/ComponentInfos.VRCSDK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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<T> : ComponentInformation<T> 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<VRCWorldUpConstraintBase>
{
protected override void CollectDependency(VRCWorldUpConstraintBase component, ComponentDependencyCollector collector)
{
base.CollectDependency(component, collector);
collector.AddDependency(component.WorldUpTransform);
}
}

#endif
}
#endif
6 changes: 6 additions & 0 deletions Editor/com.anatawa12.avatar-optimizer.editor.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"VRCSDK3A.dll",
"VRCSDKBase-Editor.dll",
"VRCSDKBase.dll",
"VRC.SDK3.Dynamics.Constraint.dll",
"System.Memory.dll"
],
"autoReferenced": false,
Expand Down Expand Up @@ -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": "",
Expand Down
6 changes: 6 additions & 0 deletions Test~/Basic/ComponentWhitelistTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ public static IEnumerable<Type> 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",
};
}
}
Expand Down

0 comments on commit dda37c7

Please sign in to comment.