diff --git a/CHANGELOG-PRERELEASE.md b/CHANGELOG-PRERELEASE.md index 794f27ce5..4ccfcfcae 100644 --- a/CHANGELOG-PRERELEASE.md +++ b/CHANGELOG-PRERELEASE.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog]. - PhysBone Optimization `#733` - Unnessesary isAnimated is now unconfigured - Floor Colliders with same configuration will be merged to one floor collider +- Minimum Support for FinalIK `#735` ### Changed diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f3ee3a6d..5be6172a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ The format is based on [Keep a Changelog]. - PhysBone Optimization `#733` - Unnessesary isAnimated is now unconfigured - Floor Colliders with same configuration will be merged to one floor collider +- Minimum Support for FinalIK `#735` ### Changed - All logs passed to ErrorReport is now shown on the console log `#643` diff --git a/Editor/APIInternal/ComponentInfos.DynamicBone.cs b/Editor/APIInternal/ComponentInfos.DynamicBone.cs new file mode 100644 index 000000000..7e28e80ea --- /dev/null +++ b/Editor/APIInternal/ComponentInfos.DynamicBone.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; +using Anatawa12.AvatarOptimizer.API; +using UnityEngine; + +namespace Anatawa12.AvatarOptimizer.APIInternal.Externals +{ + [ComponentInformationWithGUID("f9ac8d30c6a0d9642a11e5be4c440740", 11500000)] + internal class DynamicBoneInformation : ComponentInformation, IExternalMarker + { + protected override void CollectDependency(Component component, ComponentDependencyCollector collector) + { + collector.MarkHeavyBehaviour(); + + foreach (var transform in GetAffectedTransforms(component)) + { + collector.AddDependency(transform, component) + .EvenIfDependantDisabled() + .OnlyIfTargetCanBeEnable(); + collector.AddDependency(transform); + } + + foreach (var collider in (IReadOnlyList)((dynamic)component).m_Colliders) + { + // DynamicBone ignores enabled/disabled of Collider Component AFAIK + collector.AddDependency(collider); + } + } + + protected override void CollectMutations(Component component, ComponentMutationsCollector collector) + { + foreach (var transform in GetAffectedTransforms(component)) + collector.TransformRotation(transform); + } + + private static IEnumerable GetAffectedTransforms(dynamic dynamicBone) + { + var ignores = new HashSet(dynamicBone.m_Exclusions); + var queue = new Queue(); + Transform root = dynamicBone.m_Root; + queue.Enqueue(root ? root : (Transform)dynamicBone.transform); + + while (queue.Count != 0) + { + var transform = queue.Dequeue(); + yield return transform; + + foreach (var child in transform.DirectChildrenEnumerable()) + if (!ignores.Contains(child)) + queue.Enqueue(child); + } + } + } + + [ComponentInformationWithGUID("baedd976e12657241bf7ff2d1c685342", 11500000)] + internal class DynamicBoneColliderInformation : ComponentInformation, IExternalMarker + { + protected override void CollectDependency(Component component, ComponentDependencyCollector collector) + { + } + } +} \ No newline at end of file diff --git a/Editor/APIInternal/ComponentInfos.DynamicBone.cs.meta b/Editor/APIInternal/ComponentInfos.DynamicBone.cs.meta new file mode 100644 index 000000000..e5b821cf9 --- /dev/null +++ b/Editor/APIInternal/ComponentInfos.DynamicBone.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 141e8d70d6004da6ad46df6529ede586 +timeCreated: 1700527632 \ No newline at end of file diff --git a/Editor/APIInternal/ComponentInfos.Externals.cs b/Editor/APIInternal/ComponentInfos.Externals.cs index be105eeb3..4b722eec9 100644 --- a/Editor/APIInternal/ComponentInfos.Externals.cs +++ b/Editor/APIInternal/ComponentInfos.Externals.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using Anatawa12.AvatarOptimizer.API; using UnityEngine; @@ -14,65 +13,6 @@ internal interface IExternalMarker { } - #region Dynamic Bones - - [ComponentInformationWithGUID("f9ac8d30c6a0d9642a11e5be4c440740", 11500000)] - internal class DynamicBoneInformation : ComponentInformation, IExternalMarker - { - protected override void CollectDependency(Component component, ComponentDependencyCollector collector) - { - collector.MarkHeavyBehaviour(); - - foreach (var transform in GetAffectedTransforms(component)) - { - collector.AddDependency(transform, component) - .EvenIfDependantDisabled() - .OnlyIfTargetCanBeEnable(); - collector.AddDependency(transform); - } - - foreach (var collider in (IReadOnlyList)((dynamic)component).m_Colliders) - { - // DynamicBone ignores enabled/disabled of Collider Component AFAIK - collector.AddDependency(collider); - } - } - - protected override void CollectMutations(Component component, ComponentMutationsCollector collector) - { - foreach (var transform in GetAffectedTransforms(component)) - collector.TransformRotation(transform); - } - - private static IEnumerable GetAffectedTransforms(dynamic dynamicBone) - { - var ignores = new HashSet(dynamicBone.m_Exclusions); - var queue = new Queue(); - Transform root = dynamicBone.m_Root; - queue.Enqueue(root ? root : (Transform)dynamicBone.transform); - - while (queue.Count != 0) - { - var transform = queue.Dequeue(); - yield return transform; - - foreach (var child in transform.DirectChildrenEnumerable()) - if (!ignores.Contains(child)) - queue.Enqueue(child); - } - } - } - - [ComponentInformationWithGUID("baedd976e12657241bf7ff2d1c685342", 11500000)] - internal class DynamicBoneColliderInformation : ComponentInformation, IExternalMarker - { - protected override void CollectDependency(Component component, ComponentDependencyCollector collector) - { - } - } - - #endregion - #region Satania's KiseteneEx Components [ComponentInformationWithGUID("e78466b6bcd24e5409dca557eb81d45b", 11500000)] // KiseteneComponent diff --git a/Editor/APIInternal/ComponentInfos.FinalIK.cs b/Editor/APIInternal/ComponentInfos.FinalIK.cs new file mode 100644 index 000000000..1e559a19d --- /dev/null +++ b/Editor/APIInternal/ComponentInfos.FinalIK.cs @@ -0,0 +1,51 @@ +using Anatawa12.AvatarOptimizer.API; +using UnityEditor; +using UnityEngine; + +namespace Anatawa12.AvatarOptimizer.APIInternal.Externals +{ + // Currently implements ComponentInfo with low information so I assume all references are dependency and + // All transforms will be rotated. + + [ComponentInformationWithGUID("36737232c1e1646399fa0c8cbc087280", 11500000)] // "IKExecutionOrder" + [ComponentInformationWithGUID("bfac4fa329d1f4f23814af71a247c14b", 11500000)] // "VRIK", + [ComponentInformationWithGUID("a70e525c82ce9413fa4d940ad7fcf1db", 11500000)] // "FullBodyBipedIK" + [ComponentInformationWithGUID("4db3c450680fd4c809d5ad90a2f24e5f", 11500000)] // "LimbIK" + [ComponentInformationWithGUID("5013856973b27429d937d256dc082f2e", 11500000)] // "AimIK" + [ComponentInformationWithGUID("6d406d8b892f54ccaa5b0ef4de59944a", 11500000)] // "BipedIK" + [ComponentInformationWithGUID("65ace204533ef4c24ac80f11ef8ee8ea", 11500000)] // "GrounderIK" + [ComponentInformationWithGUID("6c72e1df647af4c0098866e944a04b01", 11500000)] // "GrounderFBBIK" + [ComponentInformationWithGUID("b7bc22c0304fa3d4086a2e8e451894ef", 11500000)] // "GrounderVRIK" + [ComponentInformationWithGUID("9823e47edf1dd40c29dfe0ba019f33a6", 11500000)] // "GrounderQuadruped" + [ComponentInformationWithGUID("e561d2b0d3d2241fd9bc4929a8f64b7f", 11500000)] // "TwistRelaxer" + [ComponentInformationWithGUID("a48af8ef2fd147446af3c65186a1cd9e", 11500000)] // "ShoulderRotator" + [ComponentInformationWithGUID("e6c4fa4d3ae33fb44b29d48945f7a129", 11500000)] // "FBBIKArmBending" + [ComponentInformationWithGUID("ebbd066464934494f896947690872ad4", 11500000)] // "FBBIKHeadEffector" + [ComponentInformationWithGUID("52af154b35b9e48af96507346dc649ba", 11500000)] // "FABRIK" + [ComponentInformationWithGUID("52af154b35b9e48af96507346dc649ba", 11500000)] // "FABRIK" + [ComponentInformationWithGUID("c9a2b10b17d604bb2a4d1bff880fc61a", 11500000)] // "FABRIKChain" + [ComponentInformationWithGUID("6fb82f19cc3ce412892b525300de1141", 11500000)] // "FABRIKRoot" + [ComponentInformationWithGUID("98b9a1a9e9a934b23a7db351dd9ec69e", 11500000)] // "CCDIK" + [ComponentInformationWithGUID("197a3a7b95f0e4ac48f171363db95b5b", 11500000)] // "RotationLimit" + [ComponentInformationWithGUID("484718f2c4ab849829491782b508958a", 11500000)] // "RotationLimitHinge" + [ComponentInformationWithGUID("dae00b1bdc58d499396776ce508a5078", 11500000)] // "RotationLimitPolygonal" + [ComponentInformationWithGUID("2ccb80eac3b2b4909a63c818e38ae6b8", 11500000)] // "RotationLimitSpline" + internal class FinalIKInformation : ComponentInformation, IExternalMarker + { + protected override void CollectDependency(Component component, ComponentDependencyCollector collector) + { + using (var serialized = new SerializedObject(component)) + foreach (var property in serialized.ObjectReferenceProperties()) + if (property.objectReferenceValue is Component c) + collector.AddDependency(c); + } + + protected override void CollectMutations(Component component, ComponentMutationsCollector collector) + { + using (var serialized = new SerializedObject(component)) + foreach (var property in serialized.ObjectReferenceProperties()) + if (property.objectReferenceValue is Transform t) + collector.TransformRotation(t); + } + } +} diff --git a/Editor/APIInternal/ComponentInfos.FinalIK.cs.meta b/Editor/APIInternal/ComponentInfos.FinalIK.cs.meta new file mode 100644 index 000000000..97d9a9dd1 --- /dev/null +++ b/Editor/APIInternal/ComponentInfos.FinalIK.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 78f3579c1d4e4d1e87d0449c4c9be7b8 +timeCreated: 1700528003 \ No newline at end of file