Skip to content

Commit

Permalink
Merge pull request #531 from ousttrue/fix/exporter_validation_nullcheck
Browse files Browse the repository at this point in the history
Fix/exporter validation nullcheck
  • Loading branch information
ousttrue authored Aug 28, 2020
2 parents 8f0e54f + e909081 commit 26936c1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
5 changes: 5 additions & 0 deletions Assets/VRM/UniVRM/Editor/Format/VRMExporterWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,11 @@ void OnWizardUpdate()
m_validations.Clear();
m_validations.AddRange(Validate());
m_validations.AddRange(VRMSpringBoneValidator.Validate(ExportRoot));
var firstPerson = ExportRoot.GetComponent<VRMFirstPerson>();
if (firstPerson != null)
{
m_validations.AddRange(firstPerson.Validate());
}
var hasError = m_validations.Any(x => !x.CanExport);
m_IsValid = !hasError && !MetaHasError;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public enum VRMExporterWizardMessages
[LangMsg(Languages.en, "Animator.avatar is not humanoid. Please change model's AnimationType to humanoid")]
AVATAR_IS_NOT_HUMANOID,

[LangMsg(Languages.ja, "humanoid設定に顎が含まれている。FBX importer の rig 設定に戻って設定を解除することをおすすめします")]
[LangMsg(Languages.ja, "humanoid設定に顎が含まれている。FBX importer の rig 設定で顎ボーンの割り当てを確認できます")]
[LangMsg(Languages.en, "Jaw bone is included. It may not what you intended. Please check the humanoid avatar setting screen")]
JAW_BONE_IS_INCLUDED,

Expand Down
31 changes: 30 additions & 1 deletion Assets/VRM/UniVRM/Editor/SpringBone/VRMSpringBoneValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,48 @@ public static IEnumerable<Validation> Validate(GameObject root)
yield break;
}

var hierarchy = root.GetComponentsInChildren<Transform>();

Dictionary<Transform, List<VRMSpringBone>> rootMap = new Dictionary<Transform, List<VRMSpringBone>>();

foreach (var sb in root.GetComponentsInChildren<VRMSpringBone>())
{
foreach (var springRoot in sb.RootBones)
for (int i = 0; i < sb.RootBones.Count; ++i)
{
var springRoot = sb.RootBones[i];
if (springRoot == null)
{
yield return Validation.Error($"{sb.name}.RootBones[{i}] is null");
continue;
}
if (!hierarchy.Contains(springRoot))
{
yield return Validation.Error($"{sb.name}.RootBones[{i}] is out of hierarchy");
continue;
}

if (!rootMap.TryGetValue(springRoot, out List<VRMSpringBone> list))
{
list = new List<VRMSpringBone>();
rootMap.Add(springRoot, list);
}
list.Add(sb);
}

for (int i = 0; i < sb.ColliderGroups.Length; ++i)
{
var c = sb.ColliderGroups[i];
if (c == null)
{
yield return Validation.Error($"{sb.name}.ColliderGroups[{i}] is null");
continue;
}
if (!hierarchy.Contains(c.transform))
{
yield return Validation.Error($"{sb.name}.ColliderGroups[{i}] is out of hierarchy");
continue;
}
}
}

foreach (var kv in rootMap)
Expand Down
16 changes: 11 additions & 5 deletions Assets/VRM/UniVRM/Scripts/FirstPerson/VRMFirstPerson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,23 @@ public Mesh SharedMesh
[SerializeField]
public List<RendererFirstPersonFlags> Renderers = new List<RendererFirstPersonFlags>();

static IEnumerable<Transform> Traverse(Transform parent)
public IEnumerable<Validation> Validate()
{
yield return parent;
var hierarchy = GetComponentsInChildren<Transform>();

foreach (Transform child in parent)
for (int i = 0; i < Renderers.Count; ++i)
{
foreach (var x in Traverse(child))
var r = Renderers[i];
if (r.Renderer == null)
{
yield return x;
yield return Validation.Error($"{name}.Renderers[{i}].Renderer is null");
}
if (!hierarchy.Contains(r.Renderer.transform))
{
yield return Validation.Error($"{name}.Renderers[{i}].Renderer is out of hierarchy");
}
}
yield break;
}

public void CopyTo(GameObject _dst, Dictionary<Transform, Transform> map)
Expand Down

0 comments on commit 26936c1

Please sign in to comment.