Commit aa51d19c authored by VAN TOLL Wouter's avatar VAN TOLL Wouter

Removed a lot of duplicate code related to the PlasticMan and RocketBox characters.

parent fe7857c8
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GetMemberPositionRocketBox : MonoBehaviour
{
private List<string> ListMember;
public int id=-1; // Id of the virtual human
// Use this for initialization
void Start()
{
InitList();
}
// Update is called once per frame
void Update()
{
}
void InitList()
{
ListMember = new List<string>();
// Head
ListMember.Add("Bip01 HeadNub");
ListMember.Add("Bip01 Neck");
ListMember.Add("Bip01 MNoseNub");
ListMember.Add("Bip01 LMasseterNub");
ListMember.Add("Bip01 RMasseterNub");
// Left arm
ListMember.Add("Bip01 L Clavicle");
ListMember.Add("Bip01 L UpperArm");
ListMember.Add("Bip01 L Forearm");
ListMember.Add("Bip01 L Hand");
ListMember.Add("Bip01 L Finger2Nub");
// Right arm
ListMember.Add("Bip01 R Clavicle");
ListMember.Add("Bip01 R UpperArm");
ListMember.Add("Bip01 R Forearm");
ListMember.Add("Bip01 R Hand");
ListMember.Add("Bip01 R Finger2Nub");
//Left Leg
ListMember.Add("Bip01 L Thigh");
ListMember.Add("Bip01 L Calf");
ListMember.Add("Bip01 L Foot");
ListMember.Add("Bip01 L Toe0Nub");
//Right Leg
ListMember.Add("Bip01 R Thigh");
ListMember.Add("Bip01 R Calf");
ListMember.Add("Bip01 R Foot");
ListMember.Add("Bip01 R Toe0Nub");
}
void RecursiveFindPositionChild(Transform parent, string childName, List<double> Box)
{
foreach (Transform child in parent)
{
if (child.name == childName)
{
Camera Cam = Camera.main;
Vector3 PosW = child.gameObject.transform.position;
Vector3 PosC = Cam.WorldToScreenPoint(PosW);
if (CheckOutsideCamera(PosW, PosC))
{
Box[0] = Mathf.Min((float)Box[0], PosC.x);
Box[1] = Mathf.Min((float)Box[1], PosC.y);
Box[2] = Mathf.Max((float)Box[2], PosC.x);
Box[3] = Mathf.Max((float)Box[3], PosC.y);
}
}
else
{
RecursiveFindPositionChild(child, childName, Box);
}
}
}
private bool CheckOutsideCamera(Vector3 PosW, Vector3 PosC)
{
Camera Cam = Camera.main;
// checking if worldPoint isn't behind the camera:
if (Vector3.Dot(Cam.transform.forward, PosW - Cam.transform.position) >= 0)
{
Rect screen = new Rect(0, 0, Cam.pixelWidth, Cam.pixelWidth);
// checking if screenPoint is inside the screen area:
if (screen.Contains(PosC))
{
// screenPoint is a valid screen point
return true;
}
}
return false;
}
public List<double> GetBoundingBox()
{
List<double> res = new List<double> { Camera.main.pixelWidth, Camera.main.pixelHeight, 0, 0 };
foreach (string member in ListMember)
{
RecursiveFindPositionChild(gameObject.transform, member, res);
}
return res;
}
public void SetId(int id)
{
this.id = id;
}
public int GetId()
{
return id;
}
}
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
public abstract class GetMemberPosition : MonoBehaviour {
public class GetMemberPosition : MonoBehaviour {
protected List<string> ListMember;
// Id of the virtual human
public int ID { get; set; }
private List<string> ListMember;
private int id=-1; // Id of the virtual human
// Use this for initialization
void Start () {
InitList();
}
// Update is called once per frame
void Update () {
}
void InitList()
{
ListMember = new List<string>();
ListMember.Add("Plasticman:LeftWrist_End");
ListMember.Add("Plasticman:RightWrist_End");
ListMember.Add("Plasticman:LeftForeArm");
ListMember.Add("Plasticman:RightForeArm");
ListMember.Add("Plasticman:LeftFoot");
ListMember.Add("Plasticman:RightFoot");
ListMember.Add("PPlasticman:RFoot_End");
ListMember.Add("Plasticman:LFoot_End");
ListMember.Add("Plasticman:LeftLeg");
ListMember.Add("Plasticman:RightLeg");
ListMember.Add("Plasticman:Head_End");
}
protected abstract void InitList();
void RecursiveFindPositionChild(Transform parent, string childName, List<double> Box)
{
......@@ -48,7 +31,8 @@ public class GetMemberPosition : MonoBehaviour {
Box[2] = Mathf.Max((float)Box[2], PosC.x);
Box[3] = Mathf.Max((float)Box[3], PosC.y);
}
} else
}
else
{
RecursiveFindPositionChild(child, childName, Box);
}
......@@ -73,22 +57,11 @@ public class GetMemberPosition : MonoBehaviour {
public List<double> GetBoundingBox()
{
List<double> res = new List<double> { Camera.main.pixelWidth, Camera.main.pixelHeight,0,0};
foreach (string member in ListMember)
{
RecursiveFindPositionChild(gameObject.transform, member,res);
}
return res;
}
public void SetId(int id)
{
this.id = id;
}
public int GetId()
{
return id;
return res;
}
}
using System.Collections.Generic;
public class GetMemberPositionPlasticMan : GetMemberPosition
{
protected override void InitList()
{
ListMember = new List<string>
{
"Plasticman:LeftWrist_End",
"Plasticman:RightWrist_End",
"Plasticman:LeftForeArm",
"Plasticman:RightForeArm",
"Plasticman:LeftFoot",
"Plasticman:RightFoot",
"PPlasticman:RFoot_End",
"Plasticman:LFoot_End",
"Plasticman:LeftLeg",
"Plasticman:RightLeg",
"Plasticman:Head_End"
};
}
}
fileFormatVersion: 2
guid: 225c11207529a11479c9930319be91fa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections.Generic;
public class GetMemberPositionRocketBox : GetMemberPosition
{
protected override void InitList()
{
ListMember = new List<string>
{
// Head
"Bip01 HeadNub",
"Bip01 Neck",
"Bip01 MNoseNub",
"Bip01 LMasseterNub",
"Bip01 RMasseterNub",
// Left arm
"Bip01 L Clavicle",
"Bip01 L UpperArm",
"Bip01 L Forearm",
"Bip01 L Hand",
"Bip01 L Finger2Nub",
// Right arm
"Bip01 R Clavicle",
"Bip01 R UpperArm",
"Bip01 R Forearm",
"Bip01 R Hand",
"Bip01 R Finger2Nub",
//Left Leg
"Bip01 L Thigh",
"Bip01 L Calf",
"Bip01 L Foot",
"Bip01 L Toe0Nub",
//Right Leg
"Bip01 R Thigh",
"Bip01 R Calf",
"Bip01 R Foot",
"Bip01 R Toe0Nub"
};
}
}
This diff is collapsed.
......@@ -108,12 +108,12 @@ public class CamRecorder : MonoBehaviour {
if (human.GetComponent<GetMemberPosition>() != null)
{
Pos = human.GetComponent<GetMemberPosition>().GetBoundingBox();
Id = human.GetComponent<GetMemberPosition>().GetId();
Id = human.GetComponent<GetMemberPosition>().ID;
}
else if (human.GetComponent<GetMemberPositionRocketBox>() != null)
{
Pos = human.GetComponent<GetMemberPositionRocketBox>().GetBoundingBox();
Id = human.GetComponent<GetMemberPositionRocketBox>().GetId();
Id = human.GetComponent<GetMemberPositionRocketBox>().ID;
}
if (Pos != null)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment