mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-15 07:00:10 -05:00
Merge pull request #510 from ousttrue/feature/springbone_validation
* implement SpringBone validation #474
This commit is contained in:
commit
3bbeb96fbd
|
|
@ -700,6 +700,7 @@ namespace VRM
|
|||
|
||||
m_validations.Clear();
|
||||
m_validations.AddRange(Validate());
|
||||
m_validations.AddRange(VRMSpringBoneValidator.Validate(ExportRoot));
|
||||
var hasError = m_validations.Any(x => !x.CanExport);
|
||||
m_IsValid = !hasError && !MetaHasError;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VRM
|
||||
{
|
||||
static class VRMSpringBoneValidator
|
||||
{
|
||||
// https://github.com/vrm-c/UniVRM/issues/474
|
||||
public static IEnumerable<Validation> Validate(GameObject root)
|
||||
{
|
||||
if (root == null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
Dictionary<Transform, List<VRMSpringBone>> rootMap = new Dictionary<Transform, List<VRMSpringBone>>();
|
||||
|
||||
foreach (var sb in root.GetComponentsInChildren<VRMSpringBone>())
|
||||
{
|
||||
foreach (var springRoot in sb.RootBones)
|
||||
{
|
||||
if (!rootMap.TryGetValue(springRoot, out List<VRMSpringBone> list))
|
||||
{
|
||||
list = new List<VRMSpringBone>();
|
||||
rootMap.Add(springRoot, list);
|
||||
}
|
||||
list.Add(sb);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var kv in rootMap)
|
||||
{
|
||||
if (kv.Value.Count > 1)
|
||||
{
|
||||
// * GameObjectが複数回ルートとして指定されてる(SpringBoneが同じでも別でも)
|
||||
var list = string.Join(", ", kv.Value.Select(x => string.IsNullOrEmpty(x.m_comment) ? x.name : x.m_comment));
|
||||
yield return Validation.Warning($"{kv.Key} found multiple. {list}");
|
||||
}
|
||||
|
||||
var rootInRootMap = new Dictionary<Transform, List<Transform>>();
|
||||
foreach (var child in kv.Key.GetComponentsInChildren<Transform>())
|
||||
{
|
||||
// * Rootから子をだどって、別のRootが現れる
|
||||
if (child == kv.Key)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!rootMap.ContainsKey(child))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!rootInRootMap.TryGetValue(kv.Key, out List<Transform> rootInRoot))
|
||||
{
|
||||
rootInRoot = new List<Transform>();
|
||||
rootInRootMap.Add(kv.Key, rootInRoot);
|
||||
}
|
||||
rootInRoot.Add(child);
|
||||
}
|
||||
foreach (var rootList in rootInRootMap)
|
||||
{
|
||||
var list = string.Join(", ", rootList.Value.Select(x => x.name));
|
||||
yield return Validation.Warning($"{rootList.Key} hierarchy contains other root: {list}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: dc588ccd280c0e2429d1d3cc3db5d950
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in New Issue
Block a user