From 0018be92539f9ac4a104765adccaa0f2c744ea9d Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Tue, 15 Mar 2022 21:29:29 +0900 Subject: [PATCH] refactor --- .../Migration/MigrationVrmFirstPersonAndLookAt.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Assets/VRM10/Runtime/Migration/MigrationVrmFirstPersonAndLookAt.cs b/Assets/VRM10/Runtime/Migration/MigrationVrmFirstPersonAndLookAt.cs index 61cf83d86..04a95be36 100644 --- a/Assets/VRM10/Runtime/Migration/MigrationVrmFirstPersonAndLookAt.cs +++ b/Assets/VRM10/Runtime/Migration/MigrationVrmFirstPersonAndLookAt.cs @@ -65,6 +65,17 @@ namespace UniVRM10 return FirstPersonType.auto; } + private static int? MigrateFirstPersonMeshIndex(JsonNode vrm0, string key, glTF gltf) + { + if (vrm0.TryGet(key, out var meshIndexNode)) + { + var meshIndex = meshIndexNode.GetInt32(); + return FindRenderNodeIndexFromMeshIndex(gltf, meshIndex); + } + + return default; + } + public static (LookAt, FirstPerson) Migrate(glTF gltf, JsonNode vrm0) { // VRM1 @@ -93,9 +104,7 @@ namespace UniVRM10 { foreach (var x in meshAnnotationArrayNode.ArrayItems()) { - if (!x.TryGet("mesh", out var meshIndexNode)) continue; - - var renderNodeIndex = FindRenderNodeIndexFromMeshIndex(gltf, meshIndexNode.GetInt32()); + var renderNodeIndex = MigrateFirstPersonMeshIndex(x, "mesh", gltf); if (renderNodeIndex.HasValue) { firstPerson.MeshAnnotations.Add(new MeshAnnotation