diff --git a/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs b/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs
index e1cc1ad69..cbeec73b3 100644
--- a/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs
+++ b/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs
@@ -20,7 +20,7 @@ namespace UniGLTF
///
/// GLTF importer
///
- public class ImporterContext: IDisposable
+ public class ImporterContext : IDisposable
{
#region MeasureTime
bool m_showSpeedLog
@@ -261,7 +261,7 @@ namespace UniGLTF
ParseJson(Encoding.UTF8.GetString(jsonBytes.Array, jsonBytes.Offset, jsonBytes.Count),
new SimpleStorage(chunks[1].Bytes));
}
- catch(StackOverflowException ex)
+ catch (StackOverflowException ex)
{
throw new Exception("[UniVRM Import Error] json parsing failed, nesting is too deep.\n" + ex);
}
@@ -301,6 +301,8 @@ namespace UniGLTF
// Version Compatibility
RestoreOlderVersionValues();
+ FixUnique();
+
// parepare byte buffer
//GLTF.baseDir = System.IO.Path.GetDirectoryName(Path);
foreach (var buffer in GLTF.buffers)
@@ -309,6 +311,39 @@ namespace UniGLTF
}
}
+ static string MakeUniqueName(string name, HashSet 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();
+ foreach (var mesh in GLTF.meshes)
+ {
+ var lname = mesh.name.ToLower();
+ if (used.Contains(lname))
+ {
+ // rename
+ var uname = MakeUniqueName(lname, used);
+ Debug.LogWarning($"same name: {lname} => {uname}");
+ mesh.name = uname;
+ lname = uname;
+ }
+
+ used.Add(lname);
+ }
+ }
+
void RestoreOlderVersionValues()
{
var parsed = UniJSON.JsonParser.Parse(Json);
@@ -374,7 +409,7 @@ namespace UniGLTF
#region Load. Build unity objects
public bool EnableLoadBalancing;
-
+
///
/// ReadAllBytes, Parse, Create GameObject
///
@@ -636,7 +671,7 @@ namespace UniGLTF
}
yield return null;
}
-
+
IEnumerator BuildMesh(MeshImporter.MeshContext x, int i)
{
using (MeasureTime("BuildMesh"))
@@ -644,7 +679,7 @@ namespace UniGLTF
MeshWithMaterials meshWithMaterials;
if (EnableLoadBalancing)
{
- var buildMesh = MeshImporter.BuildMeshCoroutine(this, x);
+ var buildMesh = MeshImporter.BuildMeshCoroutine(this, x);
yield return buildMesh;
meshWithMaterials = buildMesh.Current as MeshWithMaterials;
}
@@ -733,9 +768,9 @@ namespace UniGLTF
yield return null;
}
-#endregion
+ #endregion
-#region Imported
+ #region Imported
public GameObject Root;
public List Nodes = new List();
@@ -784,7 +819,7 @@ namespace UniGLTF
{
foreach (var x in Meshes)
{
- foreach(var y in x.Renderers)
+ foreach (var y in x.Renderers)
{
y.enabled = true;
}
@@ -862,11 +897,11 @@ namespace UniGLTF
var loaded = assetPath.LoadAsset();
// replace component reference
- foreach(var mesh in Meshes)
+ foreach (var mesh in Meshes)
{
- foreach(var r in mesh.Renderers)
+ foreach (var r in mesh.Renderers)
{
- for(int i=0; i