浏览代码

last changes for feedback

/validation-tool
Wesley Mareovich Smith 4 年前
当前提交
7bd43093
共有 3 个文件被更改,包括 149 次插入93 次删除
  1. 60
      com.unity.perception/Editor/Character/CharacterTooling.cs
  2. 147
      com.unity.perception/Editor/Character/CharacterToolingLibrary.cs
  3. 35
      com.unity.perception/Editor/Character/CharacterToolingUI.cs

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


{
public class CharacterTooling : MonoBehaviour
{
/// <summary>
/// Bool function used for testing to make sure the target character has the required 15 starting bones
/// </summary>
/// <param name="selection">target character selected</param>
/// <param name="failed">Dictionary return if of Human Bones that tracks they are prsent or missing</param>
/// <returns></returns>
public bool CharacterRequiredBones(GameObject selection, out Dictionary<HumanBone, bool> failed)
{
var result = AvatarRequiredBones(selection);

failed.Add(boneKey, boneValue);
}
if (failed.Count == 0)
return true;
return false;
return failed.Count == 0;
/// <summary>
/// Ensures there is pose data in the parent and child game objects of a character by checking for pos and rot
/// </summary>
/// <param name="gameObject">Target character selected</param>
/// <param name="failedGameObjects">List of game objects that don't have nay pose data</param>
/// <returns></returns>
public bool CharacterPoseData(GameObject gameObject, out List<GameObject> failedGameObjects)
{
failedGameObjects = new List<GameObject>();

for (int p = 0; p < componentsParent.Length; p++)
{
if (componentsParent[p].GetType() == typeof(Transform))
var pos = componentsParent[p].transform.position;
var rot = componentsParent[p].transform.rotation.eulerAngles;
if (pos == null || rot == null)
var pos = componentsParent[p].transform.position;
var rot = componentsParent[p].transform.rotation.eulerAngles;
if (pos == null || rot == null)
{
failedGameObjects.Add(componentsParent[p].gameObject);
}
failedGameObjects.Add(componentsParent[p].gameObject);
if (componentsChild[c].GetType() == typeof(Transform))
var pos = componentsChild[c].transform.position;
var rot = componentsChild[c].transform.rotation.eulerAngles;
if (pos == null || rot == null)
var pos = componentsChild[c].transform.position;
var rot = componentsChild[c].transform.rotation.eulerAngles;
if (pos == null || rot == null)
{
failedGameObjects.Add(componentsChild[c].gameObject);
}
failedGameObjects.Add(componentsChild[c].gameObject);
if (failedGameObjects.Count == 0)
return true;
return false;
return failedGameObjects.Count == 0;
public bool CharacterCreateNose(GameObject selection, bool drawRays = false)
/// <summary>
/// Bool function to make create a new prefab Character with nose and ear joints
/// </summary>
/// <param name="selection"></param>
/// <param name="drawRays"></param>
/// <param name="savePath"></param>
/// <returns></returns>
public bool CharacterCreateNose(GameObject selection, bool drawRays = false, string savePath = "Assets/")
var model = AvatarCreateNose(selection, drawRays);
var model = AvatarCreateNoseEars(selection, savePath, drawRays);
if(model.name.Contains("Failed"))
{

var nose = false;
var earRight = false;
var earLeft = false;
for (int i = 0; i < jointLabels.Length; i++)
{

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


"RightFoot",
};
/// <summary>
/// Checks the selected character fbx or prefab to make sure the required bones defined bu the strong [] RequiredBones
/// </summary>
/// <param name="selection">GameObject selected by the user in the editor</param>
/// <returns>Dictionary of the Human Bone and bool to track presence</returns>
var animator = selection.GetComponentInChildren<Animator>();
var bone = new HumanBone();

return result;
}
public static GameObject AvatarCreateNose (GameObject selection, bool drawRays = false)
/// <summary>
/// Based on the selection of a fbx or prefab character will find the location of the nose, left ear, and right ear joints
/// based on eye and the center head locations.
/// </summary>
/// <param name="selection"> fbx or prefab selection</param>
/// <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)
if (selection == null)
{
Debug.LogWarning("Selected Game Object is null or missing");
return new GameObject("Failed");
}
selection = (GameObject)PrefabUtility.InstantiatePrefab(selection);
var animator = selection.GetComponentInChildren<Animator>();
var skinnedMeshRenderer = selection.GetComponentInChildren<SkinnedMeshRenderer>();

rayRightEye.origin = rightEye.position;
rayRightEye.direction = directionRight * eyeDistance;
for (double i = 0; i < distanceCheck; i += 0.01)
for (var i = 0f; i < distanceCheck; i += 0.01f)
{
var point = Convert.ToSingle(i);
var pointR = rayRightEye.GetPoint(point);

rayNoseBack.origin = faceCenter;
rayNoseBack.direction = Vector3.back * distanceCheck;
for (double i = 0; i < distanceCheck; i += 0.01)
for (var i = 0f; i < distanceCheck; i += 0.01f)
var point = Convert.ToSingle(i);
var pointH = rayHead.GetPoint(point);
var pointF = rayNoseBack.GetPoint(point);
var pointH = rayHead.GetPoint(i);
var pointF = rayNoseBack.GetPoint(i);
var distanceZ = Math.Abs(pointH.z - pointF.z);

for (int v = 0; v < verticies.Length; v++)
{
for (double c = eyeDistance / 2; c < distanceCheck; c += 0.001)
for (var c = eyeDistance / 2; c < distanceCheck; c += 0.001f)
var point = Convert.ToSingle(c);
var pointNoseRay = noseRayFor.GetPoint(point);
var pointNoseRay = noseRayFor.GetPoint(c);
var pointVert = verticies[v];
var distHeadZ = Math.Abs(pointNoseRay.z - pointVert.z);
var distHeadX = Math.Abs(pointNoseRay.x - pointVert.x);

nosePos = pointNoseRay;
Debug.Log("Found Nose: " + nosePos);
}
else if(nosePos == Vector3.zero)

nosePos = pointNoseRay;
Debug.Log("Found Nose: " + nosePos);
}
}
}

for (int v = 0; v < verticies.Length; v++)
{
for (double c = eyeDistance / 2; c < distanceCheck; c += 0.001)
for (var c = eyeDistance / 2; c < distanceCheck; c += 0.001f)
var point = Convert.ToSingle(c);
var pointEarRight = rayEarRight.GetPoint(point);
var pointEarLeft = rayEarLeft.GetPoint(point);
var pointEarRight = rayEarRight.GetPoint(c);
var pointEarLeft = rayEarLeft.GetPoint(c);
var pointVert = verticies[v];
var distEarRightY = Math.Abs(pointEarRight.y - pointVert.y);

DebugDrawRays(30f, distanceCheck, rightEye, leftEye, head, rayRightEye, rayLeftEye, faceCenter, earCenter);
}
return CreateNewCharacterPrefab(selection, nosePos, earRightPos, earLeftPos);
return CreateNewCharacterPrefab(selection, nosePos, earRightPos, earLeftPos, savePath);
/// <summary>
/// Drays the rays used to create the nose and ears
/// </summary>
/// <param name="duration">Duration of the ray being drawn</param>
/// <param name="distanceCheck">How far the ray goes</param>
/// <param name="rightEye">transform of the right eye</param>
/// <param name="leftEye">transform of the left eye</param>
/// <param name="head">transform of the head</param>
/// <param name="rayRightEye">ray from the right eye transform</param>
/// <param name="rayLeftEye">ray from the left eye transform</param>
/// <param name="faceCenter">center of face found from the eyes</param>
/// <param name="earCenter">center of eyes found from the center of the head</param>
public static void DebugDrawRays(float duration, float distanceCheck, Transform rightEye, Transform leftEye, Transform head,Ray rayRightEye, Ray rayLeftEye, Vector3 faceCenter, Vector3 earCenter)
{
Debug.DrawLine(rightEye.position, leftEye.position, Color.magenta, duration);

Debug.DrawRay(earCenter, Vector3.left, Color.green, duration);
}
public static GameObject CreateNewCharacterPrefab(GameObject selection, Vector3 nosePosition, Vector3 earRightPosition, Vector3 earLeftPosition)
/// <summary>
/// Grabs the positions for the nose and ears then creates the joint, adds labels, parents the joints to the head, then saves the prefab
/// </summary>
/// <param name="selection">target character</param>
/// <param name="nosePosition">Vector 3 position</param>
/// <param name="earRightPosition">Vector 3 position</param>
/// <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/")
List<Transform> children = new List<Transform>();
selection.GetComponentsInChildren(children);
var head = FindBodyPart("head", selection.transform);
if (savePath == string.Empty)
savePath = "Assets/";
foreach(var child in children)
var filePath = savePath + selection.name + ".prefab";
if (head != null)
if (child.name == "head")
if (nosePosition != Vector3.zero)
if (nosePosition != Vector3.zero)
{
var nose = new GameObject();
nose.transform.position = nosePosition;
nose.name = "nose";
nose.transform.SetParent(child);
var nose = new GameObject();
nose.transform.position = nosePosition;
nose.name = "nose";
nose.transform.SetParent(head);
AddJointLabel(nose);
}
AddJointLabel(nose);
}
if (earRightPosition != Vector3.zero)
{
var earRight = new GameObject();
earRight.transform.position = earRightPosition;
earRight.name = "earRight";
earRight.transform.SetParent(child);
if (earRightPosition != Vector3.zero)
{
var earRight = new GameObject();
earRight.transform.position = earRightPosition;
earRight.name = "earRight";
earRight.transform.SetParent(head);
AddJointLabel(earRight);
}
AddJointLabel(earRight);
}
if (earLeftPosition != Vector3.zero)
{
var earLeft = new GameObject();
earLeft.transform.position = earLeftPosition;
earLeft.name = "earLeft";
earLeft.transform.SetParent(child);
if (earLeftPosition != Vector3.zero)
{
var earLeft = new GameObject();
earLeft.transform.position = earLeftPosition;
earLeft.name = "earLeft";
earLeft.transform.SetParent(head);
AddJointLabel(earLeft);
}
AddJointLabel(earLeft);
}
}

}
private static Transform FindBodyPart(string name, Transform root)
{
var children = new List<Transform>();
root.GetComponentsInChildren(children);
foreach (var child in children)
{
if (child.name == name)
return child;
}
return null;
}
/// <summary>
/// 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>
private static void AddJointLabel(GameObject gameObject)
{
var jointLabel = gameObject.AddComponent<JointLabel>();

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


Running
}
private TestResults testResults = new TestResults();
private CharacterTooling contentTests = new CharacterTooling();
TestResults testResults = new TestResults();
CharacterTooling contentTests = new CharacterTooling();
private GameObject selection = null;
private int toolbarSelection = 0;
private bool drawFaceRays = false;
GameObject selection = null;
int toolbarSelection = 0;
bool drawFaceRays = false;
string savePath = string.Empty;
private void OnSelectionChange()
{

if (selection != null && selection.GetType() == typeof(GameObject))
{
EditorGUILayout.TextField("Selected Asset : ", selection.name);
savePath = EditorGUILayout.TextField("Prefab Save Location : ", savePath);
GUILayout.BeginHorizontal();
toolbarSelection = GUILayout.Toolbar(toolbarSelection, toolbarNames);

var failedPose = new List<GameObject>();
drawFaceRays = GUILayout.Toggle(drawFaceRays, "Draw Face Rays");
GUILayout.Label(string.Format("Create Ears and Noise: {0}", test), EditorStyles.boldLabel);
GUILayout.Label(string.Format("Create Ears and Nose: {0}", test), EditorStyles.boldLabel);
if(savePath != string.Empty)
test = contentTests.CharacterCreateNose(selection, drawFaceRays);
else
test = contentTests.CharacterCreateNose(selection, drawFaceRays, savePath);
test = contentTests.CharacterCreateNose(selection, drawFaceRays);
if (test)
testResults = TestResults.Pass;
if (!test)
testResults = TestResults.Fail;
testResults = test ? TestResults.Pass : TestResults.Fail;
}
break;

GUILayout.Label(string.Format("Required Bones Present : {0}", TestResults.Pass), EditorStyles.whiteLabel);
}
if (test)
testResults = TestResults.Pass;
if (!test)
testResults = TestResults.Fail;
testResults = test ? TestResults.Pass : TestResults.Fail;
}
if (GUILayout.Button("Validate Pose Data", GUILayout.Width(160)))

test = contentTests.CharacterPoseData(selection, out failedPose);
if (test)
testResults = TestResults.Pass;
if (!test)
testResults = TestResults.Fail;
testResults = test ? TestResults.Pass : TestResults.Fail;
}
break;

正在加载...
取消
保存