From 7cdff272efb94a6670d584261f04cbb6d197fa0e Mon Sep 17 00:00:00 2001 From: junichi_hirose Date: Fri, 12 Oct 2018 17:10:08 +0900 Subject: [PATCH] create transformMeshTable before LoadBlendShapeMaster --- Scripts/Format/VRMImporterContext.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Scripts/Format/VRMImporterContext.cs b/Scripts/Format/VRMImporterContext.cs index 5c96f7596..4be74a047 100644 --- a/Scripts/Format/VRMImporterContext.cs +++ b/Scripts/Format/VRMImporterContext.cs @@ -114,12 +114,21 @@ namespace VRM BlendShapeAvatar = ScriptableObject.CreateInstance(); BlendShapeAvatar.name = "BlendShape"; + var transformMeshTable = new Dictionary(); + foreach (var transform in Root.transform.Traverse()) + { + if (transform.GetSharedMesh() != null) + { + transformMeshTable.Add(transform.GetSharedMesh(), transform); + } + } + var blendShapeList = GLTF.extensions.VRM.blendShapeMaster.blendShapeGroups; if (blendShapeList != null && blendShapeList.Count > 0) { foreach (var x in blendShapeList) { - BlendShapeAvatar.Clips.Add(LoadBlendShapeBind(x)); + BlendShapeAvatar.Clips.Add(LoadBlendShapeBind(x, transformMeshTable)); } } @@ -128,7 +137,7 @@ namespace VRM proxy.BlendShapeAvatar = BlendShapeAvatar; } - BlendShapeClip LoadBlendShapeBind(glTF_VRM_BlendShapeGroup group) + BlendShapeClip LoadBlendShapeBind(glTF_VRM_BlendShapeGroup group, Dictionary transformMeshTable) { var asset = ScriptableObject.CreateInstance(); var groupName = group.name; @@ -151,7 +160,7 @@ namespace VRM asset.Values = group.binds.Select(x => { var mesh = Meshes[x.mesh].Mesh; - var node = Root.transform.Traverse().First(y => y.GetSharedMesh() == mesh); + var node = transformMeshTable[mesh]; var relativePath = UniGLTF.UnityExtensions.RelativePathFrom(node, Root.transform); return new BlendShapeBinding {