浏览代码

fixing null ref

/validation-tool
Wesley Mareovich Smith 3 年前
当前提交
e414262f
共有 6 个文件被更改,包括 207 次插入177 次删除
  1. 15
      com.unity.perception/Editor/Character/CharacterTooling.cs
  2. 41
      com.unity.perception/Editor/Character/CharacterToolingLibrary.cs
  3. 21
      com.unity.perception/Tests/Editor/CharacterToolingTests.cs
  4. 147
      com.unity.perception/Editor/Character/CharacterToolingUI.cs
  5. 160
      com.unity.perception/Editor/Character/ModelTestUI.cs
  6. 0
      /com.unity.perception/Editor/Character/CharacterToolingUI.cs.meta

15
com.unity.perception/Editor/Character/CharacterTooling.cs


{
public class CharacterTooling : MonoBehaviour
{
public bool CharacterRequiredBones(Animator animator, out Dictionary<HumanBone, bool> failed)
public bool CharacterRequiredBones(GameObject selection, out Dictionary<HumanBone, bool> failed)
var result = AvatarRequiredBones(animator);
var result = AvatarRequiredBones(selection);
failed = new Dictionary<HumanBone, bool>();
for (int i = 0; i < result.Count; i++)

return false;
}
public bool CharacterCreateNose(GameObject selection, Animator animator, SkinnedMeshRenderer skinnedMeshRenderer, bool drawRays = false)
public bool CharacterCreateNose(GameObject selection, bool drawRays = false)
var model = AvatarCreateNose(selection, animator, skinnedMeshRenderer, drawRays);
var model = AvatarCreateNose(selection, drawRays);
if(model.name.Contains("Failed"))
{
GameObject.DestroyImmediate(model);
return false;
}
var jointLabels = model.GetComponentsInChildren<JointLabel>();
var nose = false;
var earRight = false;

41
com.unity.perception/Editor/Character/CharacterToolingLibrary.cs


"RightFoot",
};
public static Dictionary<HumanBone, bool> AvatarRequiredBones(Animator animator)
public static Dictionary<HumanBone, bool> AvatarRequiredBones(GameObject selection)
selection = (GameObject)PrefabUtility.InstantiatePrefab(selection);
var animator = selection.GetComponentInChildren<Animator>();
var bone = new HumanBone();
if (animator == null)
{
Debug.LogWarning("Animator and/or the Skinned Mesh Renderer are missing or can't be found!");
result.Add(bone, false);
GameObject.DestroyImmediate(selection);
return result;
}
var human = animator.avatar.humanDescription.human;
var totalBones = 0;

{
if(human[h].humanName == RequiredBones[b])
{
var bone = new HumanBone();
if (human[h].boneName != null)
{
bone.boneName = human[h].boneName;

}
}
}
GameObject.DestroyImmediate(selection);
public static GameObject AvatarCreateNose (GameObject selection, Animator animator, SkinnedMeshRenderer skinnedMeshRenderer, bool drawRays = false)
public static GameObject AvatarCreateNose (GameObject selection, bool drawRays = false)
selection = (GameObject)PrefabUtility.InstantiatePrefab(selection);
var animator = selection.GetComponentInChildren<Animator>();
var skinnedMeshRenderer = selection.GetComponentInChildren<SkinnedMeshRenderer>();
if (animator == null || skinnedMeshRenderer == null)
{
Debug.LogWarning("Animator and/or the Skinned Mesh Renderer are missing or can't be found!");
return new GameObject("Failed");
}
var human = animator.avatar.humanDescription.human;
var skeleton = animator.avatar.humanDescription.skeleton;
var verticies = skinnedMeshRenderer.sharedMesh.vertices;

var leftEye = animator.GetBoneTransform(HumanBodyBones.RightEye);
var rightEye = animator.GetBoneTransform(HumanBodyBones.LeftEye);
var faceCenter = Vector3.zero;
var earCenter = Vector3.zero;
var nosePos = Vector3.zero;

if(leftEye == null || rightEye == null)
{
Debug.LogWarning("Eye positions are null, unable to position nose joint!");
return new GameObject("Failed");
}
else
{

public static GameObject CreateNewCharacterPrefab(GameObject selection, Vector3 nosePosition, Vector3 earRightPosition, Vector3 earLeftPosition)
{
var root = (GameObject)PrefabUtility.InstantiatePrefab(selection);
if(root == null)
root = Object.Instantiate(selection);
root.GetComponentsInChildren(children);
selection.GetComponentsInChildren(children);
foreach(var child in children)
{

}
}
var model = PrefabUtility.SaveAsPrefabAsset(root, "Assets/" + root.name + ".prefab");
var model = PrefabUtility.SaveAsPrefabAsset(selection, "Assets/" + selection.name + ".prefab");
return model;
}

21
com.unity.perception/Tests/Editor/CharacterToolingTests.cs


[Test, TestCaseSource(typeof(AssetCollection), "GameObject")]
public void CreateEarsNoseJoints(GameObject gameObject)
{
var test = contentTests.CharacterCreateNose(gameObject, gameObject.GetComponentInChildren<Animator>(),
gameObject.GetComponentInChildren<SkinnedMeshRenderer>(), true);
var test = contentTests.CharacterCreateNose(gameObject, true);
}
[Test, TestCaseSource(typeof(AssetCollection), "GameObject")]
public void CharacterBones(GameObject gameObject)
{
var failedBones = new Dictionary<HumanBone, bool>();
var test = contentTests.CharacterRequiredBones(gameObject, out failedBones);
Assert.True(test, "Character is missing required bones");
}
[Test, TestCaseSource(typeof(AssetCollection), "GameObject")]
public void CharacterPoseData(GameObject gameObject)
{
var failedPose = new List<GameObject>();
var test = contentTests.CharacterPoseData(gameObject, out failedPose);
Assert.True(test, "Character is missing Pose Data");
}
public void AssetListCreation()

147
com.unity.perception/Editor/Character/CharacterToolingUI.cs


using System.Collections.Generic;
using UnityEditor;
using UnityEngine.Perception.Content;
using MenuItem = UnityEditor.MenuItem;
using UnityEngine;
using static UnityEngine.Perception.Content.CharacterValidation;
using System.Linq;
public class CharacterToolingUI : EditorWindow
{
private static string[] toolbarNames = null;
private enum TestResults
{
Inconclusive,
Pass,
Fail,
Running
}
private TestResults testResults = new TestResults();
private CharacterTooling contentTests = new CharacterTooling();
private GameObject selection = null;
private int toolbarSelection = 0;
private bool drawFaceRays = false;
private void OnSelectionChange()
{
selection = Selection.activeGameObject;
}
private void OnInspectorUpdate()
{
Repaint();
selection = Selection.activeGameObject;
}
[MenuItem("Window/Perception Character Tool")]
static void Init()
{
toolbarNames = new string[] { "Keypoints", "Validation" };
CharacterToolingUI window = (CharacterToolingUI)GetWindow(typeof(CharacterToolingUI));
window.autoRepaintOnSceneChange = true;
window.Show();
}
private void OnGUI()
{
if (selection != null && selection.GetType() == typeof(GameObject))
{
EditorGUILayout.TextField("Selected Asset : ", selection.name);
GUILayout.BeginHorizontal();
toolbarSelection = GUILayout.Toolbar(toolbarSelection, toolbarNames);
GUILayout.EndHorizontal();
switch (toolbarSelection)
{
case 0:
GUILayout.Label("Character Tools", EditorStyles.whiteLargeLabel);
var test = false;
var failedBones = new Dictionary<HumanBone, bool>();
var failedPose = new List<GameObject>();
drawFaceRays = GUILayout.Toggle(drawFaceRays, "Draw Face Rays");
GUILayout.Label(string.Format("Create Ears and Noise: {0}", test), EditorStyles.boldLabel);
if (GUILayout.Button("Create Nose and Ears", GUILayout.Width(160)))
{
testResults = TestResults.Running;
test = contentTests.CharacterCreateNose(selection, drawFaceRays);
if (test)
testResults = TestResults.Pass;
if (!test)
testResults = TestResults.Fail;
}
break;
case 1:
GUILayout.Label("Character Validation", EditorStyles.whiteLargeLabel);
GUILayout.Label(string.Format("Validation for Character : {0}", testResults), EditorStyles.whiteLabel);
var animator = selection.GetComponentInChildren<Animator>();
if (animator != null)
{
GUILayout.Label(string.Format("Character is Human: {0}", animator.avatar.isHuman), EditorStyles.boldLabel);
GUILayout.Label(string.Format("Character is Valid: {0}", animator.avatar.isValid), EditorStyles.boldLabel);
}
if (GUILayout.Button("Validate Bones", GUILayout.Width(160)))
{
testResults = TestResults.Running;
test = contentTests.CharacterRequiredBones(selection, out failedBones);
if (failedBones.Count > 0)
{
for (int i = 0; i < RequiredBones.Length; i++)
{
for (int b = 0; b < failedBones.Count; b++)
{
var bone = failedBones.ElementAt(i);
var boneKey = bone.Key;
var boneValue = bone.Value;
if (RequiredBones[i] == boneKey.humanName)
{
GUILayout.Label(string.Format("Bone {0}: {1}", RequiredBones[i], "Missing"), EditorStyles.boldLabel);
}
}
}
}
else if (failedBones.Count == 0)
{
GUILayout.Label(string.Format("Required Bones Present : {0}", TestResults.Pass), EditorStyles.whiteLabel);
}
if (test)
testResults = TestResults.Pass;
if (!test)
testResults = TestResults.Fail;
}
if (GUILayout.Button("Validate Pose Data", GUILayout.Width(160)))
{
testResults = TestResults.Running;
test = contentTests.CharacterPoseData(selection, out failedPose);
if (test)
testResults = TestResults.Pass;
if (!test)
testResults = TestResults.Fail;
}
break;
}
}
}
}

160
com.unity.perception/Editor/Character/ModelTestUI.cs


using System.Collections.Generic;
using UnityEditor;
using UnityEngine.Perception.Content;
using MenuItem = UnityEditor.MenuItem;
using UnityEngine;
using static UnityEngine.Perception.Content.CharacterValidation;
using System.Linq;
public class AssetValidation : EditorWindow
{
private static string[] toolbarNames = null;
private enum TestResults
{
Inconclusive,
Pass,
Fail,
Running
}
private TestResults testResults = new TestResults();
private CharacterTooling contentTests = new CharacterTooling();
private int toolbarSelection = 0;
private GameObject selection = null;
private Animator animator = null;
private SkinnedMeshRenderer skinnedMeshRenderer = null;
private bool drawFaceRays = false;
private void OnSelectionChange()
{
UpdateSelection();
}
private void OnInspectorUpdate()
{
Repaint();
UpdateSelection();
}
[MenuItem("Window/Character Tool")]
static void Init()
{
toolbarNames = new string[] { "Character", "Validation" };
AssetValidation window = (AssetValidation)GetWindow(typeof(AssetValidation));
window.autoRepaintOnSceneChange = true;
window.Show();
}
private void OnGUI()
{
if (selection != null)
{
EditorGUILayout.TextField("Selected Asset : ", selection.name);
GUILayout.BeginHorizontal();
toolbarSelection = GUILayout.Toolbar(toolbarSelection, toolbarNames);
GUILayout.EndHorizontal();
switch (toolbarSelection)
{
case 0:
GUILayout.Label("Character Tools", EditorStyles.whiteLargeLabel);
drawFaceRays = GUILayout.Toggle(drawFaceRays, "Draw Face Rays");
var failedBones = new Dictionary<HumanBone, bool>();
var failedPose = new List<GameObject>();
if (GUILayout.Button("Create Nose and Ears", GUILayout.Width(160)))
{
testResults = TestResults.Running;
var test = contentTests.CharacterCreateNose(selection, animator, skinnedMeshRenderer, drawFaceRays);
if (test)
testResults = TestResults.Pass;
if (!test)
testResults = TestResults.Fail;
}
break;
case 1:
GUILayout.Label("Character Validation", EditorStyles.whiteLargeLabel);
GUILayout.Label(string.Format("Validation for Character : {0}", testResults), EditorStyles.whiteLabel);
if (animator != null)
{
GUILayout.Label(string.Format("Character is Human: {0}", animator.avatar.isHuman), EditorStyles.boldLabel);
GUILayout.Label(string.Format("Character is Valid: {0}", animator.avatar.isValid), EditorStyles.boldLabel);
}
if (GUILayout.Button("Validate Bones", GUILayout.Width(160)))
{
testResults = TestResults.Running;
var test = contentTests.CharacterRequiredBones(animator, out failedBones);
if (failedBones.Count > 0)
{
for (int i = 0; i < RequiredBones.Length; i++)
{
for (int b = 0; b < failedBones.Count; b++)
{
var bone = failedBones.ElementAt(i);
var boneKey = bone.Key;
var boneValue = bone.Value;
if (RequiredBones[i] == boneKey.humanName)
{
GUILayout.Label(string.Format("Bone {0}: {1}", RequiredBones[i], "Missing"), EditorStyles.boldLabel);
}
}
}
}
else if (failedBones.Count == 0)
{
GUILayout.Label(string.Format("Required Bones Present : {0}", TestResults.Pass), EditorStyles.whiteLabel);
}
if (test)
testResults = TestResults.Pass;
if (!test)
testResults = TestResults.Fail;
}
if (GUILayout.Button("Validate Pose Data", GUILayout.Width(160)))
{
testResults = TestResults.Running;
var test = contentTests.CharacterPoseData(selection, out failedPose);
if (test)
testResults = TestResults.Pass;
if (!test)
testResults = TestResults.Fail;
}
break;
}
}
}
private void UpdateSelection()
{
selection = Selection.activeGameObject;
if (selection != null)
{
animator = selection.GetComponentInChildren<Animator>();
skinnedMeshRenderer = selection.GetComponentInChildren<SkinnedMeshRenderer>();
}
}
}

/com.unity.perception/Editor/Character/ModelTestUI.cs.meta → /com.unity.perception/Editor/Character/CharacterToolingUI.cs.meta

正在加载...
取消
保存