浏览代码

template change and feedback fixes

/validation-tool
Wesley Mareovich Smith 4 年前
当前提交
ba3e8eff
共有 4 个文件被更改,包括 54 次插入49 次删除
  1. 4
      com.unity.perception/Editor/Character/CharacterTooling.cs
  2. 32
      com.unity.perception/Editor/Character/CharacterToolingLibrary.cs
  3. 54
      com.unity.perception/Editor/Character/CharacterToolingUI.cs
  4. 13
      com.unity.perception/Tests/Editor/CharacterToolingTests.cs

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


/// <param name="drawRays"></param>
/// <param name="savePath"></param>
/// <returns></returns>
public bool CharacterCreateNose(GameObject selection, bool drawRays = false, string savePath = "Assets/")
public bool CharacterCreateNose(GameObject selection, Object keypointTemplate, bool drawRays = false, string savePath = "Assets/")
var model = AvatarCreateNoseEars(selection, savePath, drawRays);
var model = AvatarCreateNoseEars(selection, keypointTemplate, savePath, drawRays);
if (model.name.Contains("Failed"))
{

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


/// <param name="savePath">Path where the new created prefab will be saved too</param>
/// <param name="drawRays">Shows the rays on how the joint posiitons are found</param>
/// <returns></returns>
public static GameObject AvatarCreateNoseEars (GameObject selection, string savePath, bool drawRays = false)
public static GameObject AvatarCreateNoseEars (GameObject selection, Object keypointTemplate, string savePath, bool drawRays = false)
{
if (selection == null)
{

DebugDrawRays(30f, distanceCheck, rightEye, leftEye, head, rayRightEye, rayLeftEye, faceCenter, earCenter);
}
return CreateNewCharacterPrefab(selection, nosePos, earRightPos, earLeftPos, savePath);
return CreateNewCharacterPrefab(selection, nosePos, earRightPos, earLeftPos, keypointTemplate, savePath);
}
/// <summary>

/// <param name="earLeftPosition">Vector 3 position</param>
/// <param name="savePath">Save path for the creation of a new prefab</param>
/// <returns></returns>
public static GameObject CreateNewCharacterPrefab(GameObject selection, Vector3 nosePosition, Vector3 earRightPosition, Vector3 earLeftPosition, string savePath = "Assets/")
public static GameObject CreateNewCharacterPrefab(GameObject selection, Vector3 nosePosition, Vector3 earRightPosition, Vector3 earLeftPosition, Object keypointTemplate, string savePath = "Assets/")
{
var head = FindBodyPart("head", selection.transform);

nose.name = "nose";
nose.transform.SetParent(head);
AddJointLabel(nose);
AddJointLabel(nose, keypointTemplate);
}
if (earRightPosition != Vector3.zero)

earRight.name = "earRight";
earRight.transform.SetParent(head);
AddJointLabel(earRight);
AddJointLabel(earRight, keypointTemplate);
}
if (earLeftPosition != Vector3.zero)

earLeft.name = "earLeft";
earLeft.transform.SetParent(head);
AddJointLabel(earLeft);
AddJointLabel(earLeft, keypointTemplate);
}
}

/// Add a joint label and add the template data for the joint, uses base CocoKeypointTemplate in perception since the plan is to
/// remove the template from the template data
/// </summary>
/// <param name="gameObject">target cgameobject from the joint</param>
static void AddJointLabel(GameObject gameObject)
/// <param name="gameObject">target gameobject from the joint</param>
/// <param name="keypointTemplate">selected keypoint template from the UI, if blank it will grab the example CocoKeypointTemplate</param>
static void AddJointLabel(GameObject gameObject, Object keypointTemplate)
var asset = new Object();
var template = AssetDatabase.GetAllAssetPaths().Where(o => o.EndsWith("CocoKeypointTemplate.asset", StringComparison.OrdinalIgnoreCase)).ToList();
foreach (string o in template)
var exampleTemplate = AssetDatabase.GetAllAssetPaths().Where(o => o.EndsWith("CocoKeypointTemplate.asset", StringComparison.OrdinalIgnoreCase)).ToList();
if (keypointTemplate == null)
if (o.Contains("com.unity.perception"))
foreach (string o in exampleTemplate)
asset = AssetDatabase.LoadAssetAtPath<Object>(o);
if (o.Contains("com.unity.perception"))
{
keypointTemplate = AssetDatabase.LoadAssetAtPath<Object>(o);
}
data.template = (KeypointTemplate)asset;
data.template = (KeypointTemplate)keypointTemplate;
jointLabel.templateInformation = new List<JointLabel.TemplateData>();
jointLabel.templateInformation.Add(data);
}

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


using UnityEngine;
using static UnityEngine.Perception.Content.CharacterValidation;
using System.Linq;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.UI;
private enum TestResults
{
Inconclusive,
Pass,
Fail,
Running
}
TestResults m_testResults = new TestResults();
public Object keypointTemplate;
bool apiResult = false;
string status = "Unknown";
private void OnSelectionChange()
{

{
EditorGUILayout.TextField("Selected Asset : ", selection.name);
savePath = EditorGUILayout.TextField("Prefab Save Location : ", savePath);
GUILayout.Label("Keypoint Template : ", EditorStyles.whiteLargeLabel);
keypointTemplate = EditorGUILayout.ObjectField(keypointTemplate, typeof(KeypointTemplate), true, GUILayout.MaxWidth(500));
GUILayout.BeginHorizontal();
toolbarSelection = GUILayout.Toolbar(toolbarSelection, toolbarNames);

{
case 0:
GUILayout.Label("Character Tools", EditorStyles.whiteLargeLabel);
var test = true;
var status = "Unknown";
if (checkForJoints)
status = "Joints already exist";
GUILayout.Label(string.Format("Create Ears and Nose: {0}", test), EditorStyles.boldLabel);
GUILayout.Label(string.Format("Create Ears and Nose: {0}", apiResult), EditorStyles.boldLabel);
m_testResults = TestResults.Running;
test = m_contentTests.CharacterCreateNose(selection, drawFaceRays);
apiResult = m_contentTests.CharacterCreateNose(selection, keypointTemplate, drawFaceRays);
test = m_contentTests.CharacterCreateNose(selection, drawFaceRays, savePath);
m_testResults = test ? TestResults.Fail : TestResults.Pass;
apiResult = m_contentTests.CharacterCreateNose(selection, keypointTemplate, drawFaceRays, savePath);
if (test)
status = "Ear and Nose Joints have been created on the Asset";
else if (!test)
status = "Failed to create the Ear and Nose Joints";
if (apiResult)
status = "Ear and Nose joints created";
else if (!apiResult)
status = "Failed to create the Ear and Nose joints";
Repaint();
}
break;

GUILayout.Label("Character Validation", EditorStyles.whiteLargeLabel);
GUILayout.Label(string.Format("Validation for Character : {0}", m_testResults), EditorStyles.whiteLabel);
GUILayout.Label(string.Format("Validation for Character : {0}", apiResult), EditorStyles.whiteLabel);
var animator = selection.GetComponentInChildren<Animator>();

if (GUILayout.Button("Validate Bones", GUILayout.Width(160)))
{
m_testResults = TestResults.Running;
test = m_contentTests.CharacterRequiredBones(selection, out failedBones);
apiResult = m_contentTests.CharacterRequiredBones(selection, out failedBones);
if (failedBones.Count > 0)
{

}
else if (failedBones.Count == 0)
{
GUILayout.Label(string.Format("Required Bones Present : {0}", TestResults.Pass), EditorStyles.whiteLabel);
GUILayout.Label(string.Format("Required Bones Present : {0}", apiResult), EditorStyles.whiteLabel);
m_testResults = test ? TestResults.Pass : TestResults.Fail;
m_testResults = TestResults.Running;
test = m_contentTests.CharacterPoseData(selection, out failedPose);
m_testResults = test ? TestResults.Pass : TestResults.Fail;
apiResult = m_contentTests.CharacterPoseData(selection, out failedPose);
}
break;

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


[Test, TestCaseSource(typeof(AssetCollection), "GameObject")]
public void CreateEarsNoseJoints(GameObject gameObject)
{
var model = contentTests.CharacterCreateNose(gameObject, true);
var exampleTemplate = AssetDatabase.GetAllAssetPaths().Where(o => o.EndsWith("CocoKeypointTemplate.asset", StringComparison.OrdinalIgnoreCase)).ToList();
var template = new UnityEngine.Object();
foreach (string o in exampleTemplate)
{
if (o.Contains("com.unity.perception"))
{
template = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(o);
}
}
var model = contentTests.CharacterCreateNose(gameObject, template, true);
var validate = false;
if (model)
validate = contentTests.ValidateNoseAndEars(gameObject);

正在加载...
取消
保存