Skip to content

Commit

Permalink
Merge pull request #735 from anatawa12/finalik
Browse files Browse the repository at this point in the history
minimum Finalik support
  • Loading branch information
anatawa12 authored Nov 21, 2023
2 parents b9bf821 + 4a0ccbe commit c779bc2
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 60 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
61 changes: 61 additions & 0 deletions Editor/APIInternal/ComponentInfos.DynamicBone.cs
Original file line number Diff line number Diff line change
@@ -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<Component>, 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<MonoBehaviour>)((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<Transform> GetAffectedTransforms(dynamic dynamicBone)
{
var ignores = new HashSet<Transform>(dynamicBone.m_Exclusions);
var queue = new Queue<Transform>();
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<Component>, IExternalMarker
{
protected override void CollectDependency(Component component, ComponentDependencyCollector collector)
{
}
}
}
3 changes: 3 additions & 0 deletions Editor/APIInternal/ComponentInfos.DynamicBone.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 0 additions & 60 deletions Editor/APIInternal/ComponentInfos.Externals.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using Anatawa12.AvatarOptimizer.API;
using UnityEngine;

Expand All @@ -14,65 +13,6 @@ internal interface IExternalMarker
{
}

#region Dynamic Bones

[ComponentInformationWithGUID("f9ac8d30c6a0d9642a11e5be4c440740", 11500000)]
internal class DynamicBoneInformation : ComponentInformation<Component>, 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<MonoBehaviour>)((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<Transform> GetAffectedTransforms(dynamic dynamicBone)
{
var ignores = new HashSet<Transform>(dynamicBone.m_Exclusions);
var queue = new Queue<Transform>();
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<Component>, IExternalMarker
{
protected override void CollectDependency(Component component, ComponentDependencyCollector collector)
{
}
}

#endregion

#region Satania's KiseteneEx Components

[ComponentInformationWithGUID("e78466b6bcd24e5409dca557eb81d45b", 11500000)] // KiseteneComponent
Expand Down
51 changes: 51 additions & 0 deletions Editor/APIInternal/ComponentInfos.FinalIK.cs
Original file line number Diff line number Diff line change
@@ -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<Component>, 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);
}
}
}
3 changes: 3 additions & 0 deletions Editor/APIInternal/ComponentInfos.FinalIK.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c779bc2

Please sign in to comment.