From 53d3cd3e5ec23a6ac4ba8d5015c4ec5c30f09a42 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 17 Jul 2020 15:51:21 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=9C=E3=83=BC=E3=83=B3=E5=90=8D=E9=87=8D?= =?UTF-8?q?=E8=A4=87=E3=82=92=E8=AD=A6=E5=91=8A=E3=81=AB=E4=B8=8B=E3=81=92?= =?UTF-8?q?=E3=80=82=E8=87=AA=E5=8B=95=E3=83=AA=E3=83=8D=E3=83=BC=E3=83=A0?= =?UTF-8?q?=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UniVRM/Editor/Format/VRMEditorExporter.cs | 55 +++++++++++++++++++ .../UniVRM/Editor/Format/VRMExportSettings.cs | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/Assets/VRM/UniVRM/Editor/Format/VRMEditorExporter.cs b/Assets/VRM/UniVRM/Editor/Format/VRMEditorExporter.cs index 5386cc2f1..3bb10dce9 100644 --- a/Assets/VRM/UniVRM/Editor/Format/VRMEditorExporter.cs +++ b/Assets/VRM/UniVRM/Editor/Format/VRMEditorExporter.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text; using UniGLTF; using UnityEditor; using UnityEngine; @@ -109,6 +110,26 @@ namespace VRM smr.sharedMesh = copyMesh; } + static void ForceUniqueName(Transform transform, Dictionary nameCount) + { + for (int i = 2; i < 5000; ++i) + { + var sb = new StringBuilder(); + sb.Append(transform.name); + sb.Append('_'); + sb.Append(i); + var newName = sb.ToString(); + if (!nameCount.ContainsKey(newName)) + { + Debug.LogWarningFormat("force rename {0} => {1}", transform.name, newName); + transform.name = newName; + nameCount.Add(newName, 1); + return; + } + } + throw new Exception("?"); + } + /// /// /// @@ -123,6 +144,40 @@ namespace VRM target = GameObject.Instantiate(target); destroy.Add(target); + { + // copy元 + var animator = settings.Source.GetComponent(); + var beforeTransforms = settings.Source.GetComponentsInChildren(); + // copy先 + var afterTransforms = target.GetComponentsInChildren(); + // copy先のhumanoidBoneのリストを得る + var bones = (HumanBodyBones[])Enum.GetValues(typeof(HumanBodyBones)); + var humanTransforms = bones + .Where(x => x != HumanBodyBones.LastBone) + .Select(x => animator.GetBoneTransform(x)) + .Where(x => x != null) + .Select(x => afterTransforms[Array.IndexOf(beforeTransforms, x)]) // copy 先を得る + .ToArray(); + + var nameCount = target.GetComponentsInChildren() + .GroupBy(x => x.name) + .ToDictionary(x => x.Key, x => x.Count()); + foreach (var t in target.GetComponentsInChildren()) + { + if (humanTransforms.Contains(t)) + { + // keep original name + continue; + } + + if (nameCount[t.name] > 1) + { + // 重複するボーン名をリネームする + ForceUniqueName(t, nameCount); + } + } + } + // 正規化 if (settings.PoseFreeze) { diff --git a/Assets/VRM/UniVRM/Editor/Format/VRMExportSettings.cs b/Assets/VRM/UniVRM/Editor/Format/VRMExportSettings.cs index 3c9f9bd76..66a08d077 100644 --- a/Assets/VRM/UniVRM/Editor/Format/VRMExportSettings.cs +++ b/Assets/VRM/UniVRM/Editor/Format/VRMExportSettings.cs @@ -186,7 +186,7 @@ namespace VRM if (DuplicateBoneNameExists()) { - yield return Validation.Error("Find duplicate Bone names. Please check model's bone names. "); + yield return Validation.Warning("Find duplicate Bone names. Please check model's bone names. "); } if (string.IsNullOrEmpty(Title))