fix: bones whose name exactly matches prefix+suffix incorrectly match their parent (?) (#724)

Closes: #712
This commit is contained in:
bd_ 2024-03-03 02:19:53 -08:00 committed by GitHub
parent f6ac07e1cd
commit 7b21517bac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 13 deletions

View File

@ -1,10 +1,14 @@
using System.Collections.Generic;
#region
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
#endregion
namespace nadena.dev.modular_avatar.core.editor
{
internal class HeuristicBoneMapper
@ -320,7 +324,9 @@ namespace nadena.dev.modular_avatar.core.editor
foreach (Transform child in src.transform)
{
var childName = child.gameObject.name;
if (childName.StartsWith(config.prefix) && childName.EndsWith(config.suffix))
if (childName.StartsWith(config.prefix) && childName.EndsWith(config.suffix)
&& childName.Length >
config.prefix.Length + config.suffix.Length)
{
var targetObjectName = childName.Substring(config.prefix.Length,
childName.Length - config.prefix.Length - config.suffix.Length);

View File

@ -22,6 +22,12 @@
* SOFTWARE.
*/
#region
#if MA_VRCSDK3_AVATARS
using VRC.Dynamics;
using VRC.SDK3.Dynamics.PhysBone.Components;
#endif
using System;
using System.Collections.Generic;
using System.Linq;
@ -30,17 +36,14 @@ using nadena.dev.modular_avatar.editor.ErrorReporting;
using UnityEditor;
using UnityEngine;
using UnityEngine.Animations;
#if MA_VRCSDK3_AVATARS
using VRC.Dynamics;
using VRC.SDK3.Dynamics.PhysBone.Components;
#endif
using Object = UnityEngine.Object;
#endregion
namespace nadena.dev.modular_avatar.core.editor
{
internal class MergeArmatureHook
internal class
MergeArmatureHook
{
private const float DuplicatedBoneMaxSqrDistance = 0.001f * 0.001f;
@ -149,7 +152,7 @@ namespace nadena.dev.modular_avatar.core.editor
foreach (var next in mergeArmatures)
{
UnityEngine.Object.DestroyImmediate(next);
Object.DestroyImmediate(next);
}
void TopoLoop(ModularAvatarMergeArmature config)
@ -372,7 +375,9 @@ namespace nadena.dev.modular_avatar.core.editor
GameObject childNewParent = mergedSrcBone;
bool shouldZip = false;
if (childName.StartsWith(config.prefix) && childName.EndsWith(config.suffix))
if (childName.StartsWith(config.prefix) && childName.EndsWith(config.suffix)
&& childName.Length > config.prefix.Length +
config.suffix.Length)
{
var targetObjectName = childName.Substring(config.prefix.Length,
childName.Length - config.prefix.Length - config.suffix.Length);

View File

@ -75,7 +75,8 @@ namespace nadena.dev.modular_avatar.core
var pointer = mergeTarget.Get(this).transform;
foreach (var segment in segments)
{
if (!segment.StartsWith(prefix) || !segment.EndsWith(suffix)) return null;
if (!segment.StartsWith(prefix) || !segment.EndsWith(suffix)
|| segment.Length == prefix.Length + suffix.Length) return null;
var targetObjectName = segment.Substring(prefix.Length,
segment.Length - prefix.Length - suffix.Length);
pointer = pointer.Find(targetObjectName);
@ -88,7 +89,8 @@ namespace nadena.dev.modular_avatar.core
{
var childName = bone.gameObject.name;
if (!childName.StartsWith(prefix) || !childName.EndsWith(suffix)) return null;
if (!childName.StartsWith(prefix) || !childName.EndsWith(suffix)
|| childName.Length == prefix.Length + suffix.Length) return null;
var targetObjectName = childName.Substring(prefix.Length,
childName.Length - prefix.Length - suffix.Length);
return baseParent.Find(targetObjectName);