Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

同名メッシュが100以上あるときにも対応 #586

Merged
merged 2 commits into from
Oct 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 14 additions & 24 deletions Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,40 +312,30 @@ public virtual void ParseJson(string json, IStorage storage)
}
}

static string MakeUniqueName(string name, HashSet<string> used)
{
for (var i = 0; i < 100; ++i)
{
name = $"{name}_{i}";
if (!used.Contains(name))
{
return name;
}
}

throw new Exception("hobo arienai");
}

void FixUnique()
{
var used = new HashSet<string>();
foreach (var mesh in GLTF.meshes)
{
if (string.IsNullOrEmpty(mesh.name))
{
mesh.name = Guid.NewGuid().ToString();
mesh.name = "mesh_" + Guid.NewGuid().ToString("N");
used.Add(mesh.name);
}
var lname = mesh.name.ToLower();
if (used.Contains(lname))
else
{
// rename
var uname = MakeUniqueName(lname, used);
Debug.LogWarning($"same name: {lname} => {uname}");
mesh.name = uname;
lname = uname;
}
var lname = mesh.name.ToLower();
if (used.Contains(lname))
{
// rename
var uname = lname + "_" + Guid.NewGuid().ToString("N");
Debug.LogWarning($"same name: {lname} => {uname}");
mesh.name = uname;
lname = uname;
}

used.Add(lname);
used.Add(lname);
}
}
}

Expand Down