From b0c339e9d03042d6e09359e564e8b321105c044e Mon Sep 17 00:00:00 2001 From: nekobako Date: Sat, 30 Sep 2023 15:20:10 +0900 Subject: [PATCH] chore: remove PhysBone pruning as it is no longer needed --- .../Editor/MergeArmatureHook.cs | 62 ------------------- 1 file changed, 62 deletions(-) diff --git a/Packages/nadena.dev.modular-avatar/Editor/MergeArmatureHook.cs b/Packages/nadena.dev.modular-avatar/Editor/MergeArmatureHook.cs index ef915bd8..f7c0e7bb 100644 --- a/Packages/nadena.dev.modular-avatar/Editor/MergeArmatureHook.cs +++ b/Packages/nadena.dev.modular-avatar/Editor/MergeArmatureHook.cs @@ -32,7 +32,6 @@ using UnityEngine; using UnityEngine.Animations; using VRC.Dynamics; using VRC.SDK3.Dynamics.PhysBone.Components; -using Object = UnityEngine.Object; namespace nadena.dev.modular_avatar.core.editor { @@ -46,9 +45,6 @@ namespace nadena.dev.modular_avatar.core.editor private PathMappings PathMappings => frameworkContext.Extension() .PathMappings; - private HashSet mergedObjects = new HashSet(); - private HashSet thisPassAdded = new HashSet(); - internal void OnPreprocessAvatar(ndmf.BuildContext context, GameObject avatarGameObject) { this.frameworkContext = context; @@ -162,10 +158,7 @@ namespace nadena.dev.modular_avatar.core.editor BuildReport.ReportingObject(config, () => { - mergedObjects.Clear(); - thisPassAdded.Clear(); MergeArmature(config, target); - PruneDuplicatePhysBones(); UnityEngine.Object.DestroyImmediate(config); }); } @@ -236,8 +229,6 @@ namespace nadena.dev.modular_avatar.core.editor RecursiveMerge(mergeArmature, mergeArmature.gameObject, mergeTargetObject, true); _activeRetargeter.FixupAnimations(); - - thisPassAdded.UnionWith(_activeRetargeter.AddedGameObjects.Select(x => x.transform)); } /** @@ -255,12 +246,6 @@ namespace nadena.dev.modular_avatar.core.editor return; } - if (zipMerge) - { - mergedObjects.Add(src.transform); - thisPassAdded.Add(src.transform); - } - bool retain = HasAdditionalComponents(src) || !zipMerge; zipMerge = zipMerge && src.GetComponent() == null; @@ -302,7 +287,6 @@ namespace nadena.dev.modular_avatar.core.editor BoneDatabase.AddMergedBone(mergedSrcBone.transform); BoneDatabase.RetainMergedBone(mergedSrcBone.transform); PathMappings.MarkTransformLookthrough(mergedSrcBone); - thisPassAdded.Add(mergedSrcBone.transform); } src.transform.SetParent(mergedSrcBone.transform, true); @@ -357,51 +341,5 @@ namespace nadena.dev.modular_avatar.core.editor { return physBones.Any(x => target.IsChildOf(x.GetRootTransform()) && !x.ignoreTransforms.Any(target.IsChildOf)); } - - Transform FindOriginalParent(Transform merged) - { - while (merged != null && thisPassAdded.Contains(merged)) merged = merged.parent; - return merged; - } - - /** - * Sometimes outfit authors copy the entire armature, including PhysBones components. If we merge these and - * end up with multiple PB components referencing the same target, PB refuses to animate the bone. So detect - * and prune this case. - * - * TODO - detect duplicate colliders, contacts, et - these can cause perf issues but usually not quite as large - * of a correctness issue. - */ - private void PruneDuplicatePhysBones() - { - foreach (var obj in mergedObjects) - { - if (obj.GetComponent() == null) continue; - var baseObj = FindOriginalParent(obj); - if (baseObj == null || baseObj.GetComponent() == null) continue; - - HashSet baseTargets = new HashSet(); - foreach (var component in baseObj.GetComponents()) - { - var target = component.rootTransform == null ? baseObj.transform : component.rootTransform; - baseTargets.Add(target); - } - - foreach (var component in obj.GetComponents()) - { - var target = component.rootTransform == null - ? baseObj.transform - : FindOriginalParent(component.rootTransform); - if (baseTargets.Contains(target)) - { - Object.DestroyImmediate(component); - } - else - { - BoneDatabase.RetainMergedBone(component.transform); - } - } - } - } } } \ No newline at end of file