Add null JSON checks.

This commit is contained in:
Masataka SUMI
2022-03-15 20:48:34 +09:00
parent 14fcc1c251
commit f70f9e8202

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using UniGLTF;
using UniGLTF.Extensions.VRMC_vrm;
using UniJSON;
@@ -66,19 +67,22 @@ namespace UniVRM10
// VRM1
// firstPersonBoneOffset は廃止されます。LookAt.OffsetFromHeadBone を使ってください。
// firstPersonBone は廃止されます。Head 固定です。
MeshAnnotations = new System.Collections.Generic.List<MeshAnnotation>(),
MeshAnnotations = new List<MeshAnnotation>(),
};
if (vrm0.TryGet("meshAnnotations", out JsonNode meshAnnotations))
if (vrm0.TryGet("meshAnnotations", out var meshAnnotationArrayNode))
{
foreach (var x in meshAnnotations.ArrayItems())
foreach (var x in meshAnnotationArrayNode.ArrayItems())
{
var renderNodeIndex = FindRenderNodeIndexFromMeshIndex(gltf, x["mesh"].GetInt32());
if (!x.TryGet("mesh", out var meshIndexNode)) continue;
if (!x.TryGet("firstPersonFlag", out var firstPersonFlagNode)) continue;
var renderNodeIndex = FindRenderNodeIndexFromMeshIndex(gltf, meshIndexNode.GetInt32());
if (renderNodeIndex.HasValue)
{
firstPerson.MeshAnnotations.Add(new MeshAnnotation
{
Node = renderNodeIndex.Value,
Type = MigrateFirstPersonType(x["firstPersonFlag"]),
Type = MigrateFirstPersonType(firstPersonFlagNode),
});
}
}