mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-11 05:19:14 -05:00
ForceTransformUniqueName を使う
This commit is contained in:
@@ -91,8 +91,13 @@ namespace UniHumanoid
|
||||
public bool hasTranslationDoF;
|
||||
public BoneLimit[] human;
|
||||
|
||||
public HumanDescription ToHumanDescription(Transform root)
|
||||
public HumanDescription ToHumanDescription(Transform root, bool forceRename)
|
||||
{
|
||||
if (forceRename)
|
||||
{
|
||||
ForceTransformUniqueName.Process(root);
|
||||
}
|
||||
|
||||
var transforms = root.GetComponentsInChildren<Transform>();
|
||||
var skeletonBones = new SkeletonBone[transforms.Length];
|
||||
var index = 0;
|
||||
@@ -128,9 +133,7 @@ namespace UniHumanoid
|
||||
|
||||
public Avatar CreateAvatar(Transform root)
|
||||
{
|
||||
// force unique name
|
||||
ForceTransformUniqueName.Validate(root);
|
||||
return AvatarBuilder.BuildHumanAvatar(root.gameObject, ToHumanDescription(root));
|
||||
return AvatarBuilder.BuildHumanAvatar(root.gameObject, ToHumanDescription(root, true));
|
||||
}
|
||||
|
||||
public Avatar CreateAvatarAndSetup(Transform root)
|
||||
|
||||
@@ -9,24 +9,6 @@ namespace UniGLTF.Utils
|
||||
HashSet<string> m_uniqueNameSet = new HashSet<string>();
|
||||
int m_counter = 1;
|
||||
|
||||
public static bool Validate(Transform root)
|
||||
{
|
||||
HashSet<string> uniqueNameSet = new HashSet<string>();
|
||||
var transforms = root.GetComponentsInChildren<Transform>();
|
||||
foreach (var t in transforms)
|
||||
{
|
||||
if (uniqueNameSet.Contains(t.name))
|
||||
{
|
||||
UniGLTFLogger.Warning($"duplicate name: {t.name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
uniqueNameSet.Add(t.name);
|
||||
}
|
||||
}
|
||||
return uniqueNameSet.Count == transforms.Length;
|
||||
}
|
||||
|
||||
public static void Process(Transform root)
|
||||
{
|
||||
var uniqueName = new ForceTransformUniqueName();
|
||||
@@ -37,6 +19,13 @@ namespace UniGLTF.Utils
|
||||
}
|
||||
}
|
||||
|
||||
private void DoRename(Transform t, string newName)
|
||||
{
|
||||
UniGLTFLogger.Warning($"force rename !!: {t.name} => {newName}");
|
||||
t.name = newName;
|
||||
m_uniqueNameSet.Add(newName);
|
||||
}
|
||||
|
||||
public void RenameIfDupName(Transform t)
|
||||
{
|
||||
if (!m_uniqueNameSet.Contains(t.name))
|
||||
@@ -58,9 +47,7 @@ namespace UniGLTF.Utils
|
||||
var newName = $"{t.parent.name}-{t.name}";
|
||||
if (!m_uniqueNameSet.Contains(newName))
|
||||
{
|
||||
UniGLTFLogger.Warning($"force rename !!: {t.name} => {newName}");
|
||||
t.name = newName;
|
||||
m_uniqueNameSet.Add(newName);
|
||||
DoRename(t, newName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -72,9 +59,7 @@ namespace UniGLTF.Utils
|
||||
var newName = $"{t.name}{m_counter++}";
|
||||
if (!m_uniqueNameSet.Contains(newName))
|
||||
{
|
||||
UniGLTFLogger.Warning($"force rename: {t.name} => {newName}", t);
|
||||
t.name = newName;
|
||||
m_uniqueNameSet.Add(newName);
|
||||
DoRename(t, newName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user