From c86804db1fee1c747ad3a237d571a88ada10f479 Mon Sep 17 00:00:00 2001 From: bd_ Date: Thu, 9 Nov 2023 17:25:13 +0900 Subject: [PATCH] fix: ESO selects the last hips candidate, when it should pick the first (#520) Fixes: #509 --- Editor/EasySetupOutfit.cs | 6 +++- SetupUnitTests.ps1 | 1 + SetupUnitTests.ps1.meta | 7 +++++ ...ureConfusion.meta => EasySetupOutfit.meta} | 0 .../ArmatureConfusionTest.cs | 0 .../ArmatureConfusionTest.cs.meta | 0 .../EasySetupOutfit/PreferFirstHipsMatch.cs | 29 ++++++++++++++++++ .../PreferFirstHipsMatch.cs.meta | 3 ++ .../README.md | 0 .../README.md.meta | 0 .../material.mat | 0 .../material.mat.meta | 0 .../shapell.fbx | Bin .../shapell.fbx.meta | 0 14 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 SetupUnitTests.ps1 create mode 100644 SetupUnitTests.ps1.meta rename UnitTests~/{ArmatureConfusion.meta => EasySetupOutfit.meta} (100%) rename UnitTests~/{ArmatureConfusion => EasySetupOutfit}/ArmatureConfusionTest.cs (100%) rename UnitTests~/{ArmatureConfusion => EasySetupOutfit}/ArmatureConfusionTest.cs.meta (100%) create mode 100644 UnitTests~/EasySetupOutfit/PreferFirstHipsMatch.cs create mode 100644 UnitTests~/EasySetupOutfit/PreferFirstHipsMatch.cs.meta rename UnitTests~/{ArmatureConfusion => EasySetupOutfit}/README.md (100%) rename UnitTests~/{ArmatureConfusion => EasySetupOutfit}/README.md.meta (100%) rename UnitTests~/{ArmatureConfusion => EasySetupOutfit}/material.mat (100%) rename UnitTests~/{ArmatureConfusion => EasySetupOutfit}/material.mat.meta (100%) rename UnitTests~/{ArmatureConfusion => EasySetupOutfit}/shapell.fbx (100%) rename UnitTests~/{ArmatureConfusion => EasySetupOutfit}/shapell.fbx.meta (100%) diff --git a/Editor/EasySetupOutfit.cs b/Editor/EasySetupOutfit.cs index e73b268c..dd73a749 100644 --- a/Editor/EasySetupOutfit.cs +++ b/Editor/EasySetupOutfit.cs @@ -302,7 +302,7 @@ namespace nadena.dev.modular_avatar.core.editor return true; } - private static bool FindBones(Object obj, out GameObject avatarRoot, out GameObject avatarHips, + internal static bool FindBones(Object obj, out GameObject avatarRoot, out GameObject avatarHips, out GameObject outfitHips) { avatarHips = outfitHips = null; @@ -361,8 +361,12 @@ namespace nadena.dev.modular_avatar.core.editor if (tempHip.name.Contains(avatarHips.name)) { outfitHips = tempHip.gameObject; + // Prefer the first hips we find + break; } } + + if (outfitHips != null) break; } hipsCandidates.Add(avatarHips.name); diff --git a/SetupUnitTests.ps1 b/SetupUnitTests.ps1 new file mode 100644 index 00000000..ed38ea39 --- /dev/null +++ b/SetupUnitTests.ps1 @@ -0,0 +1 @@ + new-item -itemtype symboliclink -value UnitTests~ -Path UnitTests \ No newline at end of file diff --git a/SetupUnitTests.ps1.meta b/SetupUnitTests.ps1.meta new file mode 100644 index 00000000..abfde939 --- /dev/null +++ b/SetupUnitTests.ps1.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: eda33529cf6a43e4c84f0ce4832a0800 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnitTests~/ArmatureConfusion.meta b/UnitTests~/EasySetupOutfit.meta similarity index 100% rename from UnitTests~/ArmatureConfusion.meta rename to UnitTests~/EasySetupOutfit.meta diff --git a/UnitTests~/ArmatureConfusion/ArmatureConfusionTest.cs b/UnitTests~/EasySetupOutfit/ArmatureConfusionTest.cs similarity index 100% rename from UnitTests~/ArmatureConfusion/ArmatureConfusionTest.cs rename to UnitTests~/EasySetupOutfit/ArmatureConfusionTest.cs diff --git a/UnitTests~/ArmatureConfusion/ArmatureConfusionTest.cs.meta b/UnitTests~/EasySetupOutfit/ArmatureConfusionTest.cs.meta similarity index 100% rename from UnitTests~/ArmatureConfusion/ArmatureConfusionTest.cs.meta rename to UnitTests~/EasySetupOutfit/ArmatureConfusionTest.cs.meta diff --git a/UnitTests~/EasySetupOutfit/PreferFirstHipsMatch.cs b/UnitTests~/EasySetupOutfit/PreferFirstHipsMatch.cs new file mode 100644 index 00000000..c0416e43 --- /dev/null +++ b/UnitTests~/EasySetupOutfit/PreferFirstHipsMatch.cs @@ -0,0 +1,29 @@ +using System.Reflection; +using modular_avatar_tests; +using nadena.dev.modular_avatar.core.editor; +using NUnit.Framework; +using UnityEngine; +using VRC.SDK3.Avatars.Components; + +public class PreferFirstHipsMatch : TestBase +{ + [Test] + public void SetupHeuristicPrefersFirstHipsMatch() + { + var root = CreatePrefab("shapell.fbx"); + root.AddComponent(); + var root_hips = root.GetComponent().GetBoneTransform(HumanBodyBones.Hips).gameObject; + var root_armature = root_hips.transform.parent.gameObject; + var root_secondary = CreateChild(root, "PBC"); + var root_alt_hips = CreateChild(root_secondary, "Hips"); + + var outfit = CreateChild(root, "Outfit"); + var outfit_armature = CreateChild(outfit, "Armature"); + var outfit_hips = CreateChild(outfit_armature, "Hips"); + + Assert.IsTrue(EasySetupOutfit.FindBones(outfit, out var det_av_root, out var det_av_hips, out var det_outfit_hips)); + Assert.AreSame(root, det_av_root); + Assert.AreSame(root_hips, det_av_hips); + Assert.AreSame(outfit_hips, det_outfit_hips); + } +} \ No newline at end of file diff --git a/UnitTests~/EasySetupOutfit/PreferFirstHipsMatch.cs.meta b/UnitTests~/EasySetupOutfit/PreferFirstHipsMatch.cs.meta new file mode 100644 index 00000000..6ae56478 --- /dev/null +++ b/UnitTests~/EasySetupOutfit/PreferFirstHipsMatch.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9041d36a92ec4079804fb918c3a9b3d1 +timeCreated: 1699511111 \ No newline at end of file diff --git a/UnitTests~/ArmatureConfusion/README.md b/UnitTests~/EasySetupOutfit/README.md similarity index 100% rename from UnitTests~/ArmatureConfusion/README.md rename to UnitTests~/EasySetupOutfit/README.md diff --git a/UnitTests~/ArmatureConfusion/README.md.meta b/UnitTests~/EasySetupOutfit/README.md.meta similarity index 100% rename from UnitTests~/ArmatureConfusion/README.md.meta rename to UnitTests~/EasySetupOutfit/README.md.meta diff --git a/UnitTests~/ArmatureConfusion/material.mat b/UnitTests~/EasySetupOutfit/material.mat similarity index 100% rename from UnitTests~/ArmatureConfusion/material.mat rename to UnitTests~/EasySetupOutfit/material.mat diff --git a/UnitTests~/ArmatureConfusion/material.mat.meta b/UnitTests~/EasySetupOutfit/material.mat.meta similarity index 100% rename from UnitTests~/ArmatureConfusion/material.mat.meta rename to UnitTests~/EasySetupOutfit/material.mat.meta diff --git a/UnitTests~/ArmatureConfusion/shapell.fbx b/UnitTests~/EasySetupOutfit/shapell.fbx similarity index 100% rename from UnitTests~/ArmatureConfusion/shapell.fbx rename to UnitTests~/EasySetupOutfit/shapell.fbx diff --git a/UnitTests~/ArmatureConfusion/shapell.fbx.meta b/UnitTests~/EasySetupOutfit/shapell.fbx.meta similarity index 100% rename from UnitTests~/ArmatureConfusion/shapell.fbx.meta rename to UnitTests~/EasySetupOutfit/shapell.fbx.meta