UniVRM/Assets/VRM10/vrmlib/Runtime/ModelExtensionsForValidation.cs
ousttrue d53942a7bd merge vrm10
* MeshUtility を UniGLTF 下に移動
* Assets/VRM10 を追加
* JsonSchemaからのコード生成 UniGLTF/Editor/Generator を追加
2021-01-07 13:37:24 +09:00

73 lines
2.2 KiB
C#

using System;
using System.Linq;
namespace VrmLib
{
public static class ModelExtensionsForValidation
{
public static void Validate(this Model model, Node node, string message)
{
if (node is null)
{
throw new ArgumentNullException(message);
}
if (!model.Nodes.Contains(node))
{
throw new ArgumentException($"{message}: node found in nodes");
}
}
public static void Validate(this Model model)
{
foreach (var node in model.Root.Traverse().Skip(1))
{
model.Validate(node, "nodes must Contains node");
}
foreach (var skin in model.Skins)
{
foreach (var joint in skin.Joints)
{
model.Validate(joint, "nodes must Contatins joint");
}
}
if (model.Vrm != null)
{
if (model.Vrm.ExpressionManager != null)
{
foreach (var b in model.Vrm.ExpressionManager.ExpressionList)
{
foreach (var v in b.MorphTargetBinds)
{
model.Validate(v.Node, "MorphTargetBindValue.Node is null");
}
}
}
if (model.Vrm.FirstPerson != null)
{
foreach (var a in model.Vrm.FirstPerson.Annotations)
{
model.Validate(a.Node, "FirstPersonMeshAnnotation.Node is null");
}
}
var humanDict = model.Root.Traverse()
.Where(x => x.HumanoidBone.HasValue)
.ToDictionary(x => x.HumanoidBone.Value, x => x);
foreach (var required in new[]{
HumanoidBones.hips,
})
{
if (!humanDict.ContainsKey(required))
{
throw new Exception($"no {required}");
}
}
}
}
}
}