浏览代码

adding fixes and changes to the UI

/validation-tool
Wesley Mareovich Smith 3 年前
当前提交
06b938d1
共有 3 个文件被更改,包括 73 次插入73 次删除
  1. 11
      com.unity.perception/Editor/Character/CharacterTooling.cs
  2. 86
      com.unity.perception/Editor/Character/CharacterToolingLibrary.cs
  3. 49
      com.unity.perception/Editor/Character/CharacterToolingUI.cs

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


{
var model = AvatarCreateNoseEars(selection, savePath, drawRays);
if(model.name.Contains("Failed"))
if (model.name.Contains("Failed"))
else return true;
}
var jointLabels = model.GetComponentsInChildren<JointLabel>();
public bool ValidateNoseAndEars(GameObject selection)
{
var jointLabels = selection.GetComponentsInChildren<JointLabel>();
var nose = false;
var earRight = false;
var earLeft = false;

if (nose && earRight && earLeft)
return true;
return false;
else return false;
}
}
}

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


public static Dictionary<HumanBone, bool> AvatarRequiredBones(GameObject selection)
{
var result = new Dictionary<HumanBone, bool>();
selection = (GameObject)PrefabUtility.InstantiatePrefab(selection);
var selectionInstance = (GameObject)PrefabUtility.InstantiatePrefab(selection);
if (selectionInstance != null)
selection = selectionInstance;
var animator = selection.GetComponentInChildren<Animator>();
var bone = new HumanBone();

return new GameObject("Failed");
}
selection = (GameObject)PrefabUtility.InstantiatePrefab(selection);
var selectionInstance = (GameObject)PrefabUtility.InstantiatePrefab(selection);
if (selectionInstance != null)
selection = selectionInstance;
var animator = selection.GetComponentInChildren<Animator>();
var skinnedMeshRenderer = selection.GetComponentInChildren<SkinnedMeshRenderer>();

var rayEarLeft = new Ray();
var rayEarRight = new Ray();
var foundRightEar = false;
var foundLeftEar = false;
if(leftEye == null || rightEye == null)
{
Debug.LogWarning("Eye positions are null, unable to position nose joint!");

rayRightEye.origin = rightEye.position;
rayRightEye.direction = directionRight * eyeDistance;
// Find the center of the face
var point = Convert.ToSingle(i);
var pointR = rayRightEye.GetPoint(point);
var pointL = rayLeftEye.GetPoint(point);
var pointR = rayRightEye.GetPoint(i);
var pointL = rayLeftEye.GetPoint(i);
var distanceX = Math.Abs(pointR.x - pointL.x);
var distanceY = Math.Abs(pointR.y - pointL.y);

rayNoseBack.origin = faceCenter;
rayNoseBack.direction = Vector3.back * distanceCheck;
// Find the ear center which can be used to go left and right to find the edge of the mesh for the ear
for (var i = 0f; i < distanceCheck; i += 0.01f)
{
var pointH = rayHead.GetPoint(i);

if (distanceZ < 0.01)
if (distanceZ < 0.01f)
var points = new List<Vector3>();
// Find the position of the nose
for (int v = 0; v < verticies.Length; v++)
{
for (var c = eyeDistance / 2; c < distanceCheck; c += 0.001f)

var distHeadZ = Math.Abs(pointNoseRay.z - pointVert.z);
var distHeadX = Math.Abs(pointNoseRay.x - pointVert.x);
var def = 0.003f;
var offset = pointVert - pointNoseRay;
var len = offset.sqrMagnitude;
if (distHeadZ < 0.0001 && distHeadX < 0.001)
if(len < def * def || len < def)
else if(nosePos == Vector3.zero)
{
if (distHeadZ < 0.001 && distHeadX < 0.001)
{
nosePos = pointNoseRay;
}
}
// Find both the left and right ear from the ear center
for (int v = 0; v < verticies.Length; v++)
{
for (var c = eyeDistance / 2; c < distanceCheck; c += 0.001f)

var pointVert = verticies[v];
var distEarRightY = Math.Abs(pointEarRight.y - pointVert.y);
var distEarRightX = Math.Abs(pointEarRight.x - pointVert.x);
var distEarLeftY = Math.Abs(pointEarLeft.y - pointVert.y);
var distEarLeftX = Math.Abs(pointEarLeft.x - pointVert.x);
var def = 0.09f;
var offsetR = pointVert - pointEarRight;
// Need to fix the left offset because of negative numbers
var offsetL = pointVert - pointEarLeft;
var lenR = offsetR.sqrMagnitude;
var lenL = offsetL.sqrMagnitude;
if (distEarRightY < 0.001 && distEarRightX < 0.0001)
if (lenR < def * def || lenR < def)
foundRightEar = true;
if (distEarLeftY < 0.001 && distEarLeftX < 0.0001)
if (lenL < def * def || lenL < def)
foundLeftEar = true;
}
if (!foundRightEar)
{
if (distEarRightY < 0.01 && distEarRightX < 0.001)
{
earRightPos = pointEarRight;
}
}
if (!foundLeftEar)
{
if (distEarLeftY < 0.001 && distEarLeftX < 0.001)
{
earLeftPos = pointEarLeft;
}
}
}
}

}
}
var model = PrefabUtility.SaveAsPrefabAsset(selection, "Assets/" + selection.name + ".prefab");
var model = PrefabUtility.SaveAsPrefabAsset(selection, filePath);
private static Transform FindBodyPart(string name, Transform root)
static Transform FindBodyPart(string name, Transform root)
{
var children = new List<Transform>();
root.GetComponentsInChildren(children);

if (child.name == name)
if (child.name == name || child.name.Contains("head"))
return child;
}

/// remove the template from the template data
/// </summary>
/// <param name="gameObject">target cgameobject from the joint</param>
private static void AddJointLabel(GameObject gameObject)
static void AddJointLabel(GameObject gameObject)
{
var jointLabel = gameObject.AddComponent<JointLabel>();
var data = new JointLabel.TemplateData();

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


Running
}
TestResults testResults = new TestResults();
CharacterTooling contentTests = new CharacterTooling();
TestResults m_testResults = new TestResults();
CharacterTooling m_contentTests = new CharacterTooling();
GameObject selection = null;
int toolbarSelection = 0;

{
case 0:
GUILayout.Label("Character Tools", EditorStyles.whiteLargeLabel);
var test = false;
var test = true;
var status = "Unknown";
var checkForJoints = m_contentTests.ValidateNoseAndEars(selection);
GUILayout.Label(string.Format("Ears and Nose status: {0}", status), EditorStyles.boldLabel);
testResults = TestResults.Running;
if(savePath != string.Empty)
test = contentTests.CharacterCreateNose(selection, drawFaceRays);
else
test = contentTests.CharacterCreateNose(selection, drawFaceRays, savePath);
m_testResults = TestResults.Running;
if (!checkForJoints)
{
if (savePath == string.Empty)
test = m_contentTests.CharacterCreateNose(selection, drawFaceRays);
else
test = m_contentTests.CharacterCreateNose(selection, drawFaceRays, savePath);
testResults = test ? TestResults.Pass : TestResults.Fail;
m_testResults = test ? TestResults.Fail : TestResults.Pass;
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";
}
else if(checkForJoints)
{
status = "Joints have already been created on this Asset";
}
Repaint();
}
break;

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

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

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

正在加载...
取消
保存